libpcap
libpcap copied to clipboard
Optimizer does not completely remove leading noop statements
When creating a simple filter for ICMP type 42, starting at the IPv4 layer:
filtertest IPv4 'icmp[icmptype] = 42'
we end up with a dangling instruction at the start:
(000) ld #0x0
(001) ldb [9]
(002) jeq #0x1 jt 3 jf 9
(003) ldh [6]
(004) jset #0x1fff jt 9 jf 5
...
This loads a constant 0, and then obviously overwrites it with the IP protocol number ([9]
).
The pre-optimized code, from filtertest -O IPv4 'icmp[icmptype] = 42'
, makes it a little more clear what could be happening:
(000) ld #0x0
(001) jeq #0x0 jt 2 jf 23
(002) ld #0x0
(003) jeq #0x0 jt 4 jf 23
(004) ldb [9]
My guess is it's trying to generate code to look at a link type, and since there is no link type, it's just generating "load 0, if 0, load 0, if 0". Unfortunately the optimizer fails to completely optimize this away.
I've tried this with 5bfcce9665b3e793656c0706211adfbd8c85ce87 since I know there was some recent optimizer work.
Unsurprisingly, the same happens with DLT_IPv6 - filtertest IPv6 'icmp6[icmptype] = 160'