PF_RING icon indicating copy to clipboard operation
PF_RING copied to clipboard

libpcap BPF - vlan tags different in ZC / non-ZC modes

Open markabey opened this issue 10 years ago • 1 comments

If using libpcap with a filter for vlan, there are 2 ways to make the correct BPF. The linux kernel strips the vlan tag off, and sticks info about it in metadata. This makes a BPF like below. Note it looks back into the metadata (-4048). This works correctly when collecting packets in non-ZC mode, but does not work in ZC mode (as kernel is not involved)

$$  sudo tcpdump.linux -i eth0 -d "vlan"
(000) ldb      [-4048]
(001) jeq      #0x1             jt 2    jf 3
(002) ret      #65535
(003) ret      #0

The other method is where libpcap is expecting correct packets directly into it, and so it looks 12 bytes into the packet for the vlan tag (0x8100). This works correctly in ZC mode, as we get the raw packets, however it does not work in non-ZC mode as the linux kernel strips the tags.

$$  sudo tcpdump.pfring -i eth0 -d "vlan"
(000) ldh      [12]
(001) jeq      #0x8100          jt 2    jf 3
(002) ret      #65535
(003) ret      #0

I see this with the latest pfring 6.5 (tcpdump 4.7.4/libpcap 1.7.4) as well as with older ones like 6.0.3 (libpcap 1.1.1)

Could the pfring libpcap be modified, so that when given a non-ZC device, and on linux, it makes the linux kernel compatible BPF? This affects all BPFs on linux where any incoming traffic has vlan tags.

It also doesn't account for 0x9100 vlan tags.

markabey avatar Oct 04 '16 09:10 markabey

@markabey thank you for the hint! However pf_ring is just calling pcap_compile, I guess something changed in the pcap_compile implementation since v.0.8. I will investigate more, if you want to help with this you are welcome.

cardigliano avatar Oct 06 '16 16:10 cardigliano