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

Optimizer does not completely remove leading noop statements #1266

Open
fenner opened this issue Feb 2, 2024 · 0 comments
Open

Optimizer does not completely remove leading noop statements #1266

fenner opened this issue Feb 2, 2024 · 0 comments
Labels
BPF related optimizer Issues with the filter compiler's optimizer

Comments

@fenner
Copy link
Collaborator

fenner commented Feb 2, 2024

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 5bfcce9 since I know there was some recent optimizer work.

Unsurprisingly, the same happens with DLT_IPv6 - filtertest IPv6 'icmp6[icmptype] = 160'

@fenner fenner added the optimizer Issues with the filter compiler's optimizer label Feb 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BPF related optimizer Issues with the filter compiler's optimizer
Development

No branches or pull requests

2 participants