0

I'm implementing a discovery mechanism to find out VLAN Id to tag the packet, i.e. a client device plugs in the network and it does not know the VLAN Id beforehand, all it knows is that it is connected to a trunk port of the L2 switch and that there is a DHCP server behind the switch.

So I'm considering to do the following:

  1. vid=2
  2. open SOCK_RAW socket for IPPROTO_UDP protocol
  3. construct a DHCPDISCOVER packet with the Ethernet header having VID=$vid
  4. send the packet
  5. wait for response. If received the response, parse the Ethernet header, extract vlan ID, and configure the interface (e.g. create VLAN sub-interface). Done.
  6. if no response, increment vid and go to step 2)

My question is: does it matter if I send every packet in its own thread, or I could simply do it in a loop, executing e.g. send_dhcp(...) 4K times?

Mark
  • 6,052
  • 8
  • 61
  • 129
  • 2
    It doesn't matter. – user253751 Nov 17 '21 at 19:11
  • Packets are not tagged with VLANs. Layer-2 frames on trunks have VLAN tags, but that has nothing to do with the packets that are the payload of the frames. Only frames on trunks have VLAN tags, but one VLAN on the trunk (native) will not have VLAN tags. Most end-devices do not understand trunks, but there are some servers that can be configured that way. – Ron Maupin Nov 17 '21 at 20:07
  • @RonMaupin, not sure I'm following your comment. Are you saying that end devices connected to the trunk don't need to be VLAN tagged? – Mark Nov 17 '21 at 21:02
  • No, I'm saying most end-devices do not understand trunks or VLAN tags.. Most end-devices (PCs, printers, servers, etc.) are connected to access links, not trunks. On a trunk, the frames in the native VLAN are not tagged, but the frames for any other VLANs are tagged. That way, on a trunk, the switches on either end of the trunk can separate the frames back to the correct VLANs, but frames on access interfaces are not tagged because an access interface only belongs to a single VLAN. – Ron Maupin Nov 18 '21 at 01:05

0 Answers0