Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem when Filtering Vlan Id #1169

Open
Andlui9 opened this issue Mar 31, 2023 · 8 comments
Open

Problem when Filtering Vlan Id #1169

Andlui9 opened this issue Mar 31, 2023 · 8 comments

Comments

@Andlui9
Copy link

Andlui9 commented Mar 31, 2023

I just came across the following situation: if I try to filter a certain vlan using this type of filter, it doesn't work:

tcpdump -i ens160 'ether[14:2] & 0x0fff == 1000'

My goal is to filter vlan id 1000 (and a few more), but for now, getting 1000 would help me a lot.

The hex content of the packet is:

14:44:38.538563 00:0c:29:11:d2:89 > 78:98:e8:91:5c:2a, ethertype 802.1Q (0x8100), length 354: vlan 1000, p 0, ethertype IPv4 (0x0800), 100.100.0.1.67 > 100.100.0.67.68: BOOTP/DHCP, Reply, length 308
	0x0000:  7898 e891 5c2a 000c 2911 d289 8100 03e8  x...\*..).......
	0x0010:  0800 4510 0150 0000 0000 8011 7081 6464  ..E..P......p.dd
	0x0020:  0001 6464 0043 0043 0044 013c 47f8 0201  ..dd.C.C.D.<G...
	0x0030:  0600 bea5 c226 0a8a 0000 0000 0000 6464  .....&........dd
	0x0040:  0043 0000 0000 0000 0000 7898 e891 5c2a  .C........x...\*
	0x0050:  0000 0000 0000 0000 0000 0000 0000 0000  ................
	0x0060:  0000 0000 0000 0000 0000 0000 0000 0000  ................
	0x0070:  0000 0000 0000 0000 0000 0000 0000 0000  ................
	0x0080:  0000 0000 0000 0000 0000 0000 0000 0000  ................
	0x0090:  0000 0000 0000 0000 0000 0000 0000 0000  ................
	0x00a0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
	0x00b0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
	0x00c0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
	0x00d0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
	0x00e0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
	0x00f0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
	0x0100:  0000 0000 0000 0000 0000 0000 0000 0000  ................
	0x0110:  0000 0000 0000 0000 0000 6382 5363 3501  ..........c.Sc5.
	0x0120:  0236 0464 6400 0133 0400 0000 3c3a 0400  .6.dd..3....<:..
	0x0130:  0000 1e3b 0400 0000 3403 0464 6400 0101  ...;....4..dd...
	0x0140:  04ff ffff 0006 0808 0808 0808 0804 0452  ...............R
	0x0150:  1001 0c46 4854 5443 3045 4338 4134 4302  ...FHTTC0EC8A4C.
	0x0160:  00ff                                     ..

In my tests, using the command "tcpdump -XX -c 1 -i ens160 'ether[11] == 0x89'" I noticed that up to position 11 it manages to apply the filter perfectly, as can be seen below:

tcpdump: verbose output suppressed, use -v[v]... for full protocol decode
listening on ens160, link-type EN10MB (Ethernet), snapshot length 262144 bytes
14:47:27.205677 IP 100.100.0.1.bootps > 100.100.0.102.bootpc: BOOTP/DHCP, Reply, length 308
	0x0000:  7898 e891 5c2a 000c 2911 d289 8100 03e8  x...\*..).......
	0x0010:  0800 4510 0150 0000 0000 8011 705e 6464  ..E..P......p^dd
	0x0020:  0001 6464 0066 0043 0044 013c d3b0 0201  ..dd.f.C.D.<....
	0x0030:  0600 eef2 0532 0b33 0000 0000 0000 6464  .....2.3......dd
	0x0040:  0066 0000 0000 0000 0000 7898 e891 5c2a  .f........x...\*
	0x0050:  0000 0000 0000 0000 0000 0000 0000 0000  ................
	0x0060:  0000 0000 0000 0000 0000 0000 0000 0000  ................
	0x0070:  0000 0000 0000 0000 0000 0000 0000 0000  ................
	0x0080:  0000 0000 0000 0000 0000 0000 0000 0000  ................
	0x0090:  0000 0000 0000 0000 0000 0000 0000 0000  ................
	0x00a0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
	0x00b0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
	0x00c0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
	0x00d0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
	0x00e0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
	0x00f0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
	0x0100:  0000 0000 0000 0000 0000 0000 0000 0000  ................
	0x0110:  0000 0000 0000 0000 0000 6382 5363 3501  ..........c.Sc5.
	0x0120:  0236 0464 6400 0133 0400 0000 3c3a 0400  .6.dd..3....<:..
	0x0130:  0000 1e3b 0400 0000 3403 0464 6400 0101  ...;....4..dd...
	0x0140:  04ff ffff 0006 0808 0808 0808 0804 0452  ...............R
	0x0150:  1001 0c46 4854 5443 3045 4338 4134 4302  ...FHTTC0EC8A4C.
	0x0160:  00ff                                     ..

However, when advancing to position 12 ("tcpdump -XX -c 1 -i ens160 'ether[12] == 0x81'"), it does not work:

tcpdump: verbose output suppressed, use -v[v]... for full protocol decode
listening on ens160, link-type EN10MB (Ethernet), snapshot length 262144 bytes

What I noticed is as if he "ignored" the information between position 12 and 15, and, in fact, when using position 12 ("tcpdump -XX -i ens160 -c 1 'ether[12:2] == 0x0800'"), he is apparently "looking" at position 16:

tcpdump: verbose output suppressed, use -v[v]... for full protocol decode
listening on ens160, link-type EN10MB (Ethernet), snapshot length 262144 bytes
14:52:50.553308 IP 0.0.0.0.bootpc > 255.255.255.255.bootps: BOOTP/DHCP, Request from 78:98:e8:91:5c:2a (oui Unknown), length 323
	0x0000:  ffff ffff ffff 7898 e891 5c2a 8100 03e8  ......x...\*....
	0x0010:  0800 4500 015f 0000 0000 4011 798f 0000  ..E.._....@.y...
	0x0020:  0000 ffff ffff 0044 0043 014b d595 0101  .......D.C.K....
	0x0030:  0600 6d48 f14c 0c76 0000 0000 0000 0000  ..mH.L.v........
	0x0040:  0000 0000 0000 0000 0000 7898 e891 5c2a  ..........x...\*
	0x0050:  0000 0000 0000 0000 0000 0000 0000 0000  ................
	0x0060:  0000 0000 0000 0000 0000 0000 0000 0000  ................
	0x0070:  0000 0000 0000 0000 0000 0000 0000 0000  ................
	0x0080:  0000 0000 0000 0000 0000 0000 0000 0000  ................
	0x0090:  0000 0000 0000 0000 0000 0000 0000 0000  ................
	0x00a0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
	0x00b0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
	0x00c0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
	0x00d0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
	0x00e0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
	0x00f0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
	0x0100:  0000 0000 0000 0000 0000 0000 0000 0000  ................
	0x0110:  0000 0000 0000 0000 0000 6382 5363 3501  ..........c.Sc5.
	0x0120:  013d 0701 7898 e891 5c2a 3902 0240 9101  .=..x...\*9..@..
	0x0130:  0137 0b01 0306 0c0f 1c21 2a2b 79f9 3c0c  .7.......!*+y.<.
	0x0140:  6473 6c66 6f72 756d 2e6f 7267 0c10 4449  dslforum.org..DI
	0x0150:  525f 3834 3145 5f52 5438 3139 3746 5210  R_841E_RT8197FR.
	0x0160:  010c 4648 5454 4330 4543 3841 3443 0200  ..FHTTC0EC8A4C..
	0x0170:  ff                                       .

I'm using Debian 11, and the application versions are: tcpdump, 4.99.0 and libpcap, 1.10.0 (with TPACKET_V3).

@infrastation infrastation transferred this issue from the-tcpdump-group/tcpdump Mar 31, 2023
@infrastation
Copy link
Member

This might be a duplicate of an earlier bug specific to Linux VLAN handling. Does the problem reproduce when you filter packet from a file rather than from a live capture? Does it reproduce using libpcap 1.10.3?

@Andlui9
Copy link
Author

Andlui9 commented Mar 31, 2023

I ran the tests here, updated it, luckily I had the latest versions in the backports repository, but unfortunately it didn't have a positive effect.

However, the file test gave a positive result, I first generated a file like this:

tcpdump -XX -c 1000 -n -e -i ens160 -w test.pcap

and then I used the following filtering:

tcpdump -XX -c 1 -i ens160 -r test.pcap 'ether[14:2] & 0xfff == 1000'

the result was this:

reading from file test.pcap, link-type EN10MB (Ethernet), snapshot length 262144
15:43:19.057899 IP 0.0.0.0.bootpc > 255.255.255.255.bootps: BOOTP/DHCP, Request from 78:98:e8:91:5c:2a (oui Unknown), length 323
	0x0000:  ffff ffff ffff 7898 e891 5c2a 8100 03e8  ......x...\*....
	0x0010:  0800 4500 015f 0000 0000 4011 798f 0000  ..E.._....@.y...
	0x0020:  0000 ffff ffff 0044 0043 014b 2623 0101  .......D.C.K&#..
	0x0030:  0600 10ce f165 184a 0000 0000 0000 0000  .....e.J........
	0x0040:  0000 0000 0000 0000 0000 7898 e891 5c2a  ..........x...\*
	0x0050:  0000 0000 0000 0000 0000 0000 0000 0000  ................
	0x0060:  0000 0000 0000 0000 0000 0000 0000 0000  ................
	0x0070:  0000 0000 0000 0000 0000 0000 0000 0000  ................
	0x0080:  0000 0000 0000 0000 0000 0000 0000 0000  ................
	0x0090:  0000 0000 0000 0000 0000 0000 0000 0000  ................
	0x00a0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
	0x00b0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
	0x00c0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
	0x00d0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
	0x00e0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
	0x00f0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
	0x0100:  0000 0000 0000 0000 0000 0000 0000 0000  ................
	0x0110:  0000 0000 0000 0000 0000 6382 5363 3501  ..........c.Sc5.
	0x0120:  013d 0701 7898 e891 5c2a 3902 0240 9101  .=..x...\*9..@..
	0x0130:  0137 0b01 0306 0c0f 1c21 2a2b 79f9 3c0c  .7.......!*+y.<.
	0x0140:  6473 6c66 6f72 756d 2e6f 7267 0c10 4449  dslforum.org..DI
	0x0150:  525f 3834 3145 5f52 5438 3139 3746 5210  R_841E_RT8197FR.
	0x0160:  010c 4648 5454 4330 4543 3841 3443 0200  ..FHTTC0EC8A4C..
	0x0170:  ff                                       .

Current versions are:

tcpdump, 4.99.3
libpcap, 1.10.3 (with TPACKET_V3)

@Andlui9
Copy link
Author

Andlui9 commented Apr 13, 2023

Any progress on this issue?

@infrastation
Copy link
Member

At the time there are some other problems requiring attention, so this may take time to resolve. Please have patience. Meanwhile you are welcome to provide exact steps to reproduce the problem (Linux distribution and version, network interface configuration, whether it reproduces using the current libpcap master branch).

@Andlui9
Copy link
Author

Andlui9 commented Apr 14, 2023

I left the procedure I did very detailed in the history of the problem report, anyone can reproduce it.

Anyway, we wait and thank you for your attention.

@fenner
Copy link
Collaborator

fenner commented May 9, 2023

During a live capture, the Linux kernel stores the VLAN tag information somewhere else, not in the packet data. libpcap does know about this quirk and builds the filter appropriately if you use the vlan 1000 filter. You can see the difference if you run tcpdump -d vlan 1000, which looks at offsets 12 and 14 into the packet, and tcpdump -i <ethernet interface> -d vlan 1000, which loads special kernel pseudo-offsets vlanp and vlan_tci.

All of your observations (e.g., when using position 12...he is apparently "looking" at position 16) are consistent with this Linux kernel behavior.

One idea - that may not be helpful - is that you could request that tcpdump add an option to not load the filter into the kernel, and only do userland filtering. That way, the filter could skip the kernel quirks altogether (and also of course lose the speed advantage of running in the kernel).

@Andlui9
Copy link
Author

Andlui9 commented May 9, 2023

Hi, @fenner

I even looked for a way to make tcpdump not load this filter, without success so far.

@fenner
Copy link
Collaborator

fenner commented May 9, 2023

I even looked for a way to make tcpdump not load this filter, without success so far.

It turns out to be more complex than I remembered: you need to introduce a mechanism in libpcap to skip trying to install the filter in the kernel (in pcap_setfilter_linux(), make sure that can_filter_in_kernel = 0) and use that mechanism in tcpdump. Neither one of those mechanism currently exists; neither one seems particularly difficult to implement; "just" need to decide on the API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants