-
Notifications
You must be signed in to change notification settings - Fork 872
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
OR'ing vlans impossible in tcpdump filter #158
Comments
Submitted by guy_harris This is documented behavior. To quote the pcap-filter man page:
Note the sentence emphasized in "******"; that might not be stated as clearly as it should be, but it means, for better or worse, that "vlan 2 or vlan 3" means "this packet is a VLAN-in-VLAN packet, with the outer VLAN being VLAN 2 and the inner VLAN being VLAN 3". This was done in order to allow deeper checks, e.g. for fields in the IP or transport layer headers, to properly find those headers. It's not the best way to do that, as:
but the best way to do it requires some additional capabilities in the BPF interpreter or an increase in the complexity of the BPF code generated. It might be possible to come up with a hack so that "vlan N and vlan M" tests VLAN headers at two different levels (doing it at the same level would result in a filter that matches no packets unless N = M) and "vlan N or vlan M" tests VLAN headers at the same level. |
Submitted by spp2 So it seems that I have to use some kind of workaround, which does what I need, tcpdump -d 'vlan and ether[14:2]&0xfff=0x2 or ether[14:2]&0xfff=0x3' |
From the code (gencode.c:7857): This comment, commited by @guyharris in 2005 explains this issue very well. yacc parsers the bpf from left to right without saving the state, and doesn't provide a tree of some kind, which would allow an easy solution. @guyharris says that OR'ing vlans in the current parsing methodology is impossible. But there might be a solution, if GCC used yacc in previous version to parse C code, a state can be saved. We simply want yacc to parse parenthesis, and using them to increment the offset, and with each 'OR' it encounters, resetting the offset to it's last state. Let me explain: tcpdump -d 'vlan and (vlan or arp) or ip'
As it seems to me, this will solve the issue, and would allow OR'ing vlans. What do you say? |
------- Blind-Carbon-Copy From: Michael Richardson mcr@sandelman.ca Please take this discussion to the tcpdump-workers list. shohamp writes:
------- End of Blind-Carbon-Copy |
I did, no one answered. I guess, as expected, that not so many people are interested in OR'ing vlans. it's a pretty rare use-case. |
Some things require time to be done well. |
And when time has passed and still no answer?.. |
Firstly, I hope, that everyone agrees on the fact that the compiled BPF doesn't match the presumed semantics of an "OR", even though I understand yacc contraints. Am I really the only one to be interested in those cases?
Such vlan filters are easily used everyday with Network Instruments' Observer, Regards,Stephane Peters. |
Is the point that a custom parser could handle this better than a flex+yacc parser? |
I am wondering if a simple solution was considered. What about separating the two functions of the vlan primitive into two primitives: I think this approach would be much clearer, The current one is a little bit obscure and unintuitive. |
My point is that a Flex+{Bison,BYACC} parser that generates a protocol tree in pass 1 and generates code from the protocol tree in pass 2 might handle this better, so that, for example,
would mean "VLAN-encapsulated IPv4 or VLAN-encapsulated IPX" rather than "VLAN-encapsulated IPv4 or doubly-VLAN-encapsulated IPv6". It might also be possible to do so without having a two-pass parser (not counting the optimizer passes). The question is whether doing that would change the meaning of filters for which the current semantics are useful and intended. If not, we could probably get away with that. |
If |
Converted from SourceForge issue 3469486, submitted by spp2
There is a small bug I have seen while trying to filter on several VLANs;
I'm unable to specify more than one VLAN.
Obviously, some variable keeps incrementing by mistake;
the first check is made against bytes 12,13 (= Tag Type) then 14,15 (vlan id) for the first VLAN,
but the next check is made against bytes 16,17 for the tag type, then 18,19 for the next VLAN,
and so on.
Here is an example:
tcpdump -d vlan 2 or vlan 3
(000) ldh 12 jeq #0x8100 jt 2 jf 5
(002) ldh 14 and #0xfff
(004) jeq #0x2 jt 10 jf 5
(005) ldh 16 jeq #0x8100 jt 7 jf 11
(007) ldh 18 and #0xfff
(009) jeq #0x3 jt 10 jf 11
(010) ret #96
(011) ret #0
... everything is correct with only one VLAN :
tcpdump -d vlan 2
(000) ldh 12 jeq #0x8100 jt 2 jf 6
(002) ldh 14 and #0xfff
(004) jeq #0x2 jt 5 jf 6
(005) ret #96
(006) ret #0
First tried with argus (of Qosient) and libpcap 0.8, same problem:
argus -X -b - vlan 2
(000) ldh 12 jeq #0x8100 jt 2 jf 6
(002) ldh 14 and #0xfff
(004) jeq #0x2 jt 5 jf 6
(005) ret #96
(006) ret #0
I have compiled libpcap-1.2.1, same behavior.
Hope this helps.
Regards,
Stephane Peters.
The text was updated successfully, but these errors were encountered: