Skip to content

Compare Antrea BPF generation for PacketCapture to tcpdump / libpcap #7701

@antoninbas

Description

@antoninbas

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:

  1. ask AI to generate comprehensive test inputs
  2. use tcpdump to generate reference BPF code for the inputs
  3. use our own code (PacketCapture implementation) to generate the BPF code:
    // 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 {
  4. compare the generated BPF for equality
  5. in case of difference, analyze whether the generated BPF is incorrect or equivalent for our purposes
  6. if possible, update our own BPF generation to match the tcpdump one
  7. 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.

Metadata

Metadata

Assignees

Labels

area/ops/packetcaptureIssues or PRs related to the PacketCapture featurearea/testIssues or PRs related to unit and integration tests.kind/taskCategorizes issue or PR as related to a routine task that needs to be performedlfx-mentorshipIssues which have been proposed for the LFX Mentorship program

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions