Skip to contentSkip to conversation

Linux, tcpdump and vlan

DISCUSSION andrei radulescu-banu 6 participants 14 messages Jul 18, 2007 – Jul 20, 2007

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Dear kernel networking gurus,

I am trying to understand why tcpdump does not work properly for vlan packets on linux. Here is the existing behavior, observed with:
- kernel 2.6.16,
- e1000 driver
- libpcap 0.9.6
- tcpdump 3.9.6

The e1000 driver has two modes when handling vlan frames:
(A) Default mode, when
- on rx, the mac includes vlan headers
- on tx, the mac expects tx frames to include vlan headers.
(B) Vlan hw accelerated mode, when:
- on rx, the mac does not include vlan headers, and instead passes vlan tag information in the status field of the ring buffer
- on tx, the mac expects no vlan headers, and instead expects vlan tag information to be passed in the status field of the ring buffer

If no vlan interfaces are used, the e1000 driver configures the mac in default mode (A). The system will only receive vlan traffic, and not transmit any. Tcpdump then gets the entire rx vlan buffers, and displays them correctly.

Suppose now that at least one vlan interface is used - say eth0 is the main physical interface, and eth0.2 is an interface created on vlan id 2. The e1000 driver then switches to vlan hw accelerated mode (B). Furthermore, even if set promiscuous, the e1000 will filter out any rx vlan frames of id other than 2, which breaks tcpdump (bug 1).

Suppose in our scenario with eth0 and eth0.2 we're running tcpdump on eth0 - which uses a packet socket. The rx vlan frames with id 2 are then assigned by the driver to eth0.2, and are therefore not passed to the packet socket and to tcpdump (bug 2). The tx vlan frames on eth0.2 are passed to the packet socket without any vlan information, and tcpdump does not display the vlan header (bug 3)

In conclusion, here is the buglist:
1). If set promiscuous, the e1000 should disable any vlan rx filtering, so that it can receive vlan frames of other vlan id's. Other ethernet drivers probably need fixed as well.
2). The packet layer should change the rx skb device from the vlan 'fake' device (eth0.2) to the corresponding physical device (eth0), so when we run tcpdump on eth0 we see all vlan-tagged and non-vlan-tagged frames 3). The packet socket layer should insert the vlan tag header before passing frames to the upper layer, so tcpdump can display them.

Open issue:
4). What is the expected behavior when running 'tcpdump -I eth0.2'? Perhaps the packet socket should silently display all frames on eth0, so running 'tcpdump -i eth0' is equivalent to 'tcpdump -i eth0.2'

Thoughts? Comments? Please cc [email protected], I am not subscribed.

Andrei Radulescu-Banu
Brix Networks

      ____________________________________________________________________________________

Luggage? GPS? Comic books?
Check out fitting gifts for grads at Yahoo! Search
http://search.yahoo.com/search?fr=oni_on_mail&p=graduation+gifts&cs=bz

#1 lore raw
Quoted 6 lines · andrei radulescu-banu

[...]

In conclusion, here is the buglist:
1). If set promiscuous, the e1000 should disable any vlan rx filtering, so that it can receive vlan frames of other vlan id's. Other ethernet drivers probably need fixed as well.
2). The packet layer should change the rx skb device from the vlan 'fake' device (eth0.2) to the corresponding physical device (eth0), so when we run tcpdump on eth0 we see all vlan-tagged and non-vlan-tagged frames 3). The packet socket layer should insert the vlan tag header before passing frames to the upper layer, so tcpdump can display them.

Put another way, once you enable VLAN header stripping, you won't see the headers for *any* VLAN, not only for those you're actually running locally. This is also a problem for devices like macvlan, where it would be desirable to make use of hardware VLAN accerlation. I was thinking about storing the information somewhere in the packets meta-data on both RX and TX paths, that would also allow tcpdump to properly display packets.

I have planned to look into this when I find some time. Your suggestion of disabling VLAN acceleration in promiscous mode sounds like a reasonable solution until then ..

#2 lore raw
Quoted 8 lines · Patrick McHardy
Quoted 6 lines · andrei radulescu-banu

[...]

In conclusion, here is the buglist: 1). If set promiscuous, the e1000 should disable any vlan rx filtering, so that it can receive vlan frames of other vlan id's. Other ethernet drivers probably need fixed as well.
2). The packet layer should change the rx skb device from the vlan 'fake' device (eth0.2) to the corresponding physical device (eth0), so when we run tcpdump on eth0 we see all vlan-tagged and non-vlan-tagged frames 3). The packet socket layer should insert the vlan tag header before passing frames to the upper layer, so tcpdump can display them.

Quoted 9 lines

Put another way, once you enable VLAN header stripping, you won't see the headers for *any* VLAN, not only for those you're actually running locally. This is also a problem for devices like macvlan, where it would be desirable to make use of hardware VLAN accerlation. I was thinking about storing the information somewhere in the packets meta-data on both RX and TX paths, that would also allow tcpdump to properly display packets.

MAC-VLAN could gather this information based on it's parent device (ie, if parent-dev has VID 7, then add VID 7 to the meta data. There would be no need for any driver changes I think.

Other than TCP-dump, or some other raw protocol that wants to see the VLAN header in user-space, I can't think of what use this would be, however. And, if you just disable VLAN accel in the NIC (see below), that would make this mac-vlan hackery not needed at all?

Quoted 4 lines

I have planned to look into this when I find some time. Your suggestion of disabling VLAN acceleration in promiscous mode sounds like a reasonable solution until then ..

I think a better method would be to allow disabling VLAN HW accel for a NIC with ethtool. Then, the packets will be received by the software stack with the vlan header intact. Something sniffing on the physical dev will automatically get the VLAN header.

Thanks,
Ben

Signature · 1 line
Ben Greear <[email protected]> Candela Technologies Inc  http://www.candelatech.com
#3 lore raw
Quoted 12 lines · Ben Greear
Quoted 9 lines · Patrick McHardy

Put another way, once you enable VLAN header stripping, you won't see the headers for *any* VLAN, not only for those you're actually running locally. This is also a problem for devices like macvlan, where it would be desirable to make use of hardware VLAN accerlation. I was thinking about storing the information somewhere in the packets meta-data on both RX and TX paths, that would also allow tcpdump to properly display packets.

Quoted 3 lines

MAC-VLAN could gather this information based on it's parent device (ie, if parent-dev has VID 7, then add VID 7 to the meta data. There would be no need for any driver changes I think.

Its actually more a problem on the RX path. VLAN acceleration works (at least with some drivers) by enabling HW header striping and using the VLAN ID for an immediate lookup in the VLAN devices configured on that device. So if the VLAN is not configured on the real device but something like macvlan, it will get the packet without a header and without any indication that this was a VLAN packet. This is also what causes the tcpdump problem.

On the TX path, it could simply use the CB, but this is actually also wrong (for both macvlan and real devices) since qdiscs have ownership of the skb in between, and at least netem *does* modify the CB, breaking VLAN.

Quoted 4 lines

Other than TCP-dump, or some other raw protocol that wants to see the VLAN header in user-space, I can't think of what use this would be, however. And, if you just disable VLAN accel in the NIC (see below), that would make this mac-vlan hackery not needed at all?

Optimizations for macvlan are not too important, I agree. But for tcpdump I consider it a bug.

Quoted 5 lines
Quoted 4 lines

I have planned to look into this when I find some time. Your suggestion of disabling VLAN acceleration in promiscous mode sounds like a reasonable solution until then ..

Quoted 7 lines

I think a better method would be to allow disabling VLAN HW accel for a NIC with
ethtool. Then, the packets will be received by the software stack with the vlan
header intact. Something sniffing on the physical dev will automatically get the
VLAN header.

That would also be fine. But considering that the TX path is problematic too, a clean solution for all of this would be to store the VLAN id in the skb. And we do have some holes to plug currently :)

#4 lore raw
Quoted 21 lines · Patrick McHardy
Quoted 13 lines · Ben Greear
Quoted 10 lines · Patrick McHardy

Put another way, once you enable VLAN header stripping, you won't see the headers for *any* VLAN, not only for those you're actually running locally. This is also a problem for devices like macvlan, where it would be desirable to make use of hardware VLAN accerlation. I was thinking about storing the information somewhere in the packets meta-data on both RX and TX paths, that would also allow tcpdump to properly display packets.

Quoted 4 lines

MAC-VLAN could gather this information based on it's parent device (ie, if parent-dev has VID 7, then add VID 7 to the meta data. There would be no need for any driver changes I think.

Quoted 8 lines

Its actually more a problem on the RX path. VLAN acceleration works (at least with some drivers) by enabling HW header striping and using the VLAN ID for an immediate lookup in the VLAN devices configured on that device. So if the VLAN is not configured on the real device but something like macvlan, it will get the packet without a header and without any indication that this was a VLAN packet. This is also what causes the tcpdump problem.

This reminded me of something:

If we are using VLAN HW-Accel, then the skb hits the mac-vlan check with the skb->dev == vlan-device. So, in this case, we can put mac-vlans on top of 802.1Q VLANs.

But, if we are not using VLAN hw-accel, the skb hits the mac-vlan check with skb->dev == ethernet-device. In this case, we could NOT have the mac-vlan on top of the 802.1Q VLAN, but we can have a MAC-VLAN on the raw ethernet and we could add 802.1Q vlans on top of the mac-vlan. This is because the .1Q vlan will only be found once we go into the protocol handler logic, which is necessarily after the MAC-VLAN check logic.

Unless I am confused in my conjecture above, this is likely to confuse others who try to mix and match MAC-VLANs and 802.1Q VLANs.

Quoted 15 lines
Quoted 5 lines
Quoted 5 lines

I have planned to look into this when I find some time. Your suggestion of disabling VLAN acceleration in promiscous mode sounds like a reasonable solution until then ..

Quoted 8 lines

I think a better method would be to allow disabling VLAN HW accel for a NIC with
ethtool. Then, the packets will be received by the software stack with the vlan
header intact. Something sniffing on the physical dev will automatically get the
VLAN header.

Quoted 5 lines

That would also be fine. But considering that the TX path is problematic too, a clean solution for all of this would be to store the VLAN id in the skb. And we do have some holes to plug currently :)

With VLAN HW accel disabled, the skb will have the VLAN header in it by the time it hits the ethX interface, so sniffing there should still show the header. It won't show when sniffing the VLAN device, but I think that is OK.

Thanks,
Ben

Signature · 1 line
Ben Greear <[email protected]> Candela Technologies Inc  http://www.candelatech.com
#5 lore raw
Quoted 27 lines · Ben Greear
Quoted 8 lines · Patrick McHardy

Its actually more a problem on the RX path. VLAN acceleration works (at least with some drivers) by enabling HW header striping and using the VLAN ID for an immediate lookup in the VLAN devices configured on that device. So if the VLAN is not configured on the real device but something like macvlan, it will get the packet without a header and without any indication that this was a VLAN packet. This is also what causes the tcpdump problem.

This reminded me of something:

If we are using VLAN HW-Accel, then the skb hits the mac-vlan check with the skb->dev == vlan-device.
So, in this case, we can put mac-vlans on top of 802.1Q VLANs.

But, if we are not using VLAN hw-accel, the skb hits the mac-vlan check with skb->dev == ethernet-device.
In this case, we could NOT have the mac-vlan on top of the 802.1Q VLAN, but we can have a MAC-VLAN
on the raw ethernet and we could add 802.1Q vlans on top of the mac-vlan. This is because the
.1Q vlan will only be found once we go into the protocol handler logic, which is necessarily after the
MAC-VLAN check logic.

Quoted 3 lines

Unless I am confused in my conjecture above, this is likely to confuse others who try to mix and
match MAC-VLANs and 802.1Q VLANs.

The current code doesn't use hardware acceleration and works fine in all combinations where only vlan *or* macvlan devices are used on the underlying device.

If you mix them macvlan won't get to see vlan headers anymore, same as for tcpdump, bridge devices, or anything else that might care. A bridge eating VLAN headers should be a clearer indication of a bug than an inaccurate tcpdump ..

The real problem is that the device removes the header for all vlans, not only for those that are configured on the device. This is a result of how the hardware works. But since we don't have the data available later, we can't even fix it up in software.

#6 lore raw
In reply to Patrick McHardy
Quoted 4 lines · Patrick McHardy

Your suggestion of disabling VLAN acceleration in promiscous mode sounds like a reasonable solution until then ..

From a user perspective:

I'm not sure promiscous mode is related to the problem. Tcpdump without promiscous mode makes perfect sense.

I don't know very well VLAN code internals, but I think the VLAN # is used for looking up the interface, so presenting the "original" packet on the trunk device would IMHO involve some skb cloning, and perhaps some ethtool option could probably control that.

Not sure about untagged frames vs. tagged frames with the default VLAN id - can the hardware at all differentiate between them?

Or, perhaps it should be left (almost) as is - with "software" VLANs the traffic always goes through the master interface, but with "accelerated" mode it only goes through logical interfaces and doesn't show up on master? Probably with exception of invalid VLANs, which could be injected back to master (because no logical device exists)?

Signature · 1 line
Krzysztof Halasa
#7 lore raw
Quoted 21 lines · On Thu, 19 Jul 2007 15:28:46 +0200 Krzysztof Halasa <[email protected]> wrote:
Quoted 2 lines · Patrick McHardy

Your suggestion of disabling VLAN acceleration in promiscous mode sounds like a reasonable solution until then ..

From a user perspective:

I'm not sure promiscous mode is related to the problem. Tcpdump without promiscous mode makes perfect sense.

I don't know very well VLAN code internals, but I think the VLAN # is used for looking up the interface, so presenting the "original" packet on the trunk device would IMHO involve some skb cloning, and perhaps some ethtool option could probably control that.

Not sure about untagged frames vs. tagged frames with the default VLAN id - can the hardware at all differentiate between them?

Quoted 6 lines

Or, perhaps it should be left (almost) as is - with "software" VLANs the traffic always goes through the master interface, but with "accelerated" mode it only goes through logical interfaces and doesn't show up on master? Probably with exception of invalid VLANs, which could be injected back to master (because no logical device exists)?

I don't claim to be a VLAN expert but there are really three cases for handling tagged frames

1) non-accelerated device
* all frames show in promiscious mode
* tag is part of the frame that shows up
in tcpdump, and then gets stripped by the 8021q module.
2) rx tag stripping device
* all frames show in promiscious mode
* tag is in skb but NOT passed to tcpdump
3) rx vlan acceleration
* only frames that for vlan's that are registered show up in promisicous mode
* tag is in skb but NOT passed to tcpdump

Unfortunately, the tag is lost as part of the VLAN acceleration process so it is not a simple matter of changing code in AF_PACKET receive to restore the tag.

#8 lore raw
Quoted 10 lines · Stephen Hemminger
Quoted 7 lines · On Thu, 19 Jul 2007 15:28:46 +0200 Krzysztof Halasa <[email protected]> wrote:
Quoted 2 lines

Your suggestion of disabling VLAN acceleration in promiscous mode sounds like a reasonable solution until then ..

From a user perspective:

I'm not sure promiscous mode is related to the problem. Tcpdump without promiscous mode makes perfect sense.

Good point.

Quoted 11 lines
Quoted 11 lines

I don't know very well VLAN code internals, but I think the VLAN # is used for looking up the interface, so presenting the "original" packet on the trunk device would IMHO involve some skb cloning, and perhaps some ethtool option could probably control that.

Not sure about untagged frames vs. tagged frames with the default VLAN id - can the hardware at all differentiate between them?

Quoted 6 lines
Quoted 6 lines

Or, perhaps it should be left (almost) as is - with "software" VLANs the traffic always goes through the master interface, but with "accelerated" mode it only goes through logical interfaces and doesn't show up on master? Probably with exception of invalid VLANs, which could be injected back to master (because no logical device exists)?

The last case is the problematic one, the tag might be gone.

Quoted 15 lines

I don't claim to be a VLAN expert but there are really three cases for handling tagged frames

1) non-accelerated device
* all frames show in promiscious mode
* tag is part of the frame that shows up
in tcpdump, and then gets stripped by the 8021q module.
2) rx tag stripping device
* all frames show in promiscious mode
* tag is in skb but NOT passed to tcpdump
3) rx vlan acceleration
* only frames that for vlan's that are registered show up in promisicous mode
* tag is in skb but NOT passed to tcpdump

Quoted 3 lines

Unfortunately, the tag is lost as part of the VLAN acceleration process so it is not a simple matter of changing code in AF_PACKET receive to restore the tag.

I think case 2) is not correct, the tag is stripped and is not in the skb. Check out sky2 for example :)

        if (sky2->vlgrp && (status & GMR_FS_VLAN)) {
                vlan_hwaccel_receive_skb(skb,

                                         sky2->vlgrp,
                                         be16_to_cpu(sky2->rx_tag));

The tag it uses for the lookup comes from the descriptor. I don't know any examples for case 3), but I would expect that the header is also removed.

Anyway, I think what we should do is store the VLAN tag in the skb meta data. That would not only allow tcpdump to reconstruct it, it would also fix the invalid use of skb->cb on the TX path. It would also fix the bridge eating VLAN headers case (bridge on eth0 + eth1, additionally eth0.1 on eth0 using vlan RX accerlation with header stripping) and would allow to simply forward the vlan tag to the outgoing device in case it supports hardware accererated vlan tagging.

#9 lore raw
In reply to Stephen Hemminger
Quoted 4 lines · Stephen Hemminger

1) non-accelerated device
* all frames show in promiscious mode
* tag is part of the frame that shows up
in tcpdump, and then gets stripped by the 8021q module.

Sure. It's IMHO good and working, modulo the tag being removed on the master device (optional cloning or something, IIRC).

Quoted 7 lines

2) rx tag stripping device
* all frames show in promiscious mode
* tag is in skb but NOT passed to tcpdump
3) rx vlan acceleration
* only frames that for vlan's that are registered show up in promisicous mode
* tag is in skb but NOT passed to tcpdump

I wasn't aware of devices doing 3. Aren't we able to tell them to receive all packets anyway (even unknown VLANs#)?

Quoted 3 lines

Unfortunately, the tag is lost as part of the VLAN acceleration process so it is not a simple matter of changing code in AF_PACKET receive to restore the tag.

I'm not sure if we really want it. If needed we can disable acceleration, can't we? While accelerated we can see the packets (without tags) on logical devices.

However seeing unknown tags on master device (with tcpdump etc) would certainly be useful.

Signature · 1 line
Krzysztof Halasa
#10 lore raw
Quoted 18 lines · On Thu, 19 Jul 2007 16:23:48 +0200 Krzysztof Halasa <[email protected]> wrote:
Quoted 4 lines · Stephen Hemminger

1) non-accelerated device
* all frames show in promiscious mode
* tag is part of the frame that shows up
in tcpdump, and then gets stripped by the 8021q module.

Sure. It's IMHO good and working, modulo the tag being removed on the master device (optional cloning or something, IIRC).

Quoted 7 lines

2) rx tag stripping device
* all frames show in promiscious mode
* tag is in skb but NOT passed to tcpdump
3) rx vlan acceleration
* only frames that for vlan's that are registered show up in promisicous mode
* tag is in skb but NOT passed to tcpdump

Quoted 2 lines

I wasn't aware of devices doing 3. Aren't we able to tell them to receive all packets anyway (even unknown VLANs#)?

See NETIF_F_HW_VLAN_FILTER (e1000, etc).

Quoted 7 lines
Quoted 3 lines

Unfortunately, the tag is lost as part of the VLAN acceleration process so it is not a simple matter of changing code in AF_PACKET receive to restore the tag.

I'm not sure if we really want it. If needed we can disable acceleration, can't we? While accelerated we can see the packets (without tags) on logical devices.

Not at runtime, acceleration is always on if you compile kernel with vlan support. That is a design mistake as far as I can tell.

Quoted 2 lines

However seeing unknown tags on master device (with tcpdump etc) would certainly be useful.

Only in promiscuous mode. In some sense tag is part of the mac address.

#12 lore raw
In reply to Krzysztof Halasa
Quoted 18 lines · On Thu, 19 Jul 2007 16:23:48 +0200 Krzysztof Halasa <[email protected]> wrote:
Quoted 4 lines · Stephen Hemminger

1) non-accelerated device
* all frames show in promiscious mode
* tag is part of the frame that shows up
in tcpdump, and then gets stripped by the 8021q module.

Sure. It's IMHO good and working, modulo the tag being removed on the master device (optional cloning or something, IIRC).

Quoted 7 lines

2) rx tag stripping device
* all frames show in promiscious mode
* tag is in skb but NOT passed to tcpdump
3) rx vlan acceleration
* only frames that for vlan's that are registered show up in promisicous mode
* tag is in skb but NOT passed to tcpdump

Quoted 2 lines

I wasn't aware of devices doing 3. Aren't we able to tell them to receive all packets anyway (even unknown VLANs#)?

See NETIF_F_HW_VLAN_FILTER (e1000, etc).

Quoted 7 lines
Quoted 3 lines

Unfortunately, the tag is lost as part of the VLAN acceleration process so it is not a simple matter of changing code in AF_PACKET receive to restore the tag.

I'm not sure if we really want it. If needed we can disable acceleration, can't we? While accelerated we can see the packets (without tags) on logical devices.

Not at runtime, acceleration is always on if you compile kernel with vlan support. That is a design mistake as far as I can tell.

Quoted 2 lines

However seeing unknown tags on master device (with tcpdump etc) would certainly be useful.

Only in promiscuous mode. In some sense tag is part of the mac address.

#11 lore raw
In reply to Stephen Hemminger
Quoted 2 lines · Stephen Hemminger

Not at runtime, acceleration is always on if you compile kernel with vlan support. That is a design mistake as far as I can tell.

I think so.

Quoted 4 lines
Quoted 2 lines

However seeing unknown tags on master device (with tcpdump etc) would certainly be useful.

Only in promiscuous mode. In some sense tag is part of the mac address.

Well, in "some sense" maybe, though the MAC address is rather strictly defined to be a 6-octet value. I can live with promiscous anyway, it's really minor issue.

Signature · 1 line
Krzysztof Halasa
#13 lore raw
In reply to andrei radulescu-banu
Quoted 10 lines · andrei radulescu-banu

Dear kernel networking gurus,

I am trying to understand why tcpdump does not work properly for vlan packets on linux. Here is the existing behavior, observed with:
- kernel 2.6.16,
- e1000 driver
- libpcap 0.9.6
- tcpdump 3.9.6

Quoted 7 lines

The e1000 driver has two modes when handling vlan frames:
(A) Default mode, when
- on rx, the mac includes vlan headers
- on tx, the mac expects tx frames to include vlan headers.
(B) Vlan hw accelerated mode, when:
- on rx, the mac does not include vlan headers, and instead passes vlan tag information in the status field of the ring buffer
- on tx, the mac expects no vlan headers, and instead expects vlan tag information to be passed in the status field of the ring buffer

I have seen similar behaviour. Once the kernel is compiled with VLAN support the e1000 driver drops the vlan tag completely even when no vlans are configured on that port. I would consider this beeing a bug that enableing a kernel option changes behaviour even if the feature is not in use.

As i was tracing dot1qinq i could actually see that only the outer vlan tag was beeing dropped.

Flo

Signature · 3 lines
Florian Lohoff                  [email protected]             +49-171-2280134
	Those who would give up a little freedom to get a little 
          security shall soon have neither - Benjamin Franklin