-
Notifications
You must be signed in to change notification settings - Fork 458
Description
This code generates BPF code for packet filters defined in the PacketCapture CRD: https://github.com/antrea-io/antrea/blob/main/pkg/agent/packetcapture/capture/bpf.go. The code is tested using manually-generated test cases: https://github.com/antrea-io/antrea/blob/main/pkg/agent/packetcapture/capture/bpf_test.go. This approach is tedious and error-prone, and limits the amount of testing we can do.
Given that the code attempts to mimic the BPF generation done by tcpdump, we should consider the following approach:
- ask AI to generate comprehensive test inputs
- use tcpdump to generate reference BPF code for the inputs
- use our own code (PacketCapture implementation) to generate the BPF code:
antrea/pkg/agent/packetcapture/capture/bpf.go
Lines 375 to 379 in 930b29f
// compilePacketFilter acts as the main entry point for BPF filter generation. // It inspects the IP family specified in the CRD and dispatches the request // to the unified compiler with the appropriate protocol-specific handler // (ipv4Handler for IPv4, ipv6Handler for IPv6). func compilePacketFilter(packetSpec *crdv1alpha1.Packet, srcIP, dstIP net.IP, direction crdv1alpha1.CaptureDirection) []bpf.Instruction { - compare the generated BPF for equality
- in case of difference, analyze whether the generated BPF is incorrect or equivalent for our purposes
- if possible, update our own BPF generation to match the tcpdump one
- commit all test cases and run them as part of CI
More background on the PacketCapture feature: https://github.com/antrea-io/antrea/blob/main/docs/packetcapture-guide.md
The reason for having our own BPF generation code is to avoid pulling in impractical runtime dependencies (e.g., libraries using libpcap and requiring cgo). In contrast, it is perfectly fine to use tcpdump offline to generate test cases.