-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Add IPv6 filter tests and implement BPF ALU instruction conversion #11301
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
base: master
Are you sure you want to change the base?
Conversation
Co-authored-by: tomastigera <49207409+tomastigera@users.noreply.github.com>
88594e2 to
75aa8e0
Compare
| bpfAluAdd uint8 = 0x00 | ||
| bpfAluSub uint8 = 0x10 | ||
| bpfAluMul uint8 = 0x20 | ||
| bpfAluDiv uint8 = 0x30 | ||
| bpfAluOr uint8 = 0x40 | ||
| bpfAluAnd uint8 = 0x50 | ||
| bpfAluLsh uint8 = 0x60 | ||
| bpfAluRsh uint8 = 0x70 | ||
| bpfAluNeg uint8 = 0x80 | ||
| bpfAluMod uint8 = 0x90 | ||
| bpfAluXor uint8 = 0xa0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot implement classic bpf to ebpf instruction conversion in function cBPF2eBPF in the class bpfClassAlu branch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implemented in commit 53d385f. Added conversion for all 11 ALU operations (add, sub, mul, div, or, and, lsh, rsh, neg, mod, xor) with support for both immediate (K) and register (X) source operands. Also implemented scratch memory operations (ST, STX, LD MEM, LDX MEM) using stack-based emulation.
The protochain test still fails due to BPF verifier rejecting loop structures - this is a known limitation when converting classic BPF loops to eBPF.
…memory operations - Implemented all ALU operations (add, sub, mul, div, or, and, lsh, rsh, neg, mod, xor) - Added support for both immediate (K) and register (X) source operands - Implemented scratch memory operations (ST, STX, LD MEM, LDX MEM) - Classic BPF scratch memory M[0-15] is emulated using stack slots The protochain test still fails due to BPF verifier rejecting loop structures, which is a fundamental limitation when converting classic BPF loops to eBPF. Co-authored-by: tomastigera <49207409+tomastigera@users.noreply.github.com>
The existing
TestFilterfunction only validates BPF filter expressions against IPv4 packets. This adds equivalent coverage for IPv6 and implements classic BPF to eBPF instruction conversion to support advanced filter expressions.Changes
IPv6 Filter Tests
TestFilterIPv6function mirroring the IPv4 test structureBPF Instruction Conversion
cBPF2eBPFfunctionImplementation Details
bpfClassStandbpfClassStxconstants for store instruction classesKnown Limitations
The
ip6 protochaintest still fails due to BPF verifier rejecting loop structures, which is a fundamental limitation when converting classic BPF programs with loops to eBPF without bounded loop support.Addresses lines 29-144 of
felix/bpf/ut/filter_test.goand implements ALU conversion infelix/bpf/filter/filter.go.Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.