This file is automatically read by Claude Code at the start of each session to understand the project context.
xdpcap is a high-performance packet capture tool using XDP/eBPF that captures only packet headers (L2-L4), not payload data.
- Language: Go 1.21+
- eBPF: XDP program written in C, compiled with clang
- Libraries:
github.com/cilium/ebpf- eBPF program loading and map managementgithub.com/google/gopacket- pcap file writinggithub.com/spf13/cobra- CLI frameworkgopkg.in/yaml.v3- Configuration parsing
xdpcap/
├── cmd/xdpcap/main.go # CLI entry point
├── internal/
│ ├── config/config.go # YAML config parsing
│ ├── capture/capture.go # eBPF loading, ring buffer reader
│ ├── capture/xdpcap_bpf.go # Stub for non-Linux (bpf2go generates real one)
│ └── writer/pcap.go # Time-rotated pcap writer
├── bpf/xdpcap.c # XDP/eBPF program (C)
├── configs/xdpcap.yaml.example # Example configuration
├── Makefile
└── README.md
- Header capture: Max 512 bytes per packet (L2-L7 headers including HTTP, TLS, DNS)
- Flow filtering: Hash map lookup to exclude specified flows from capture
- Ring buffer: Zero-copy transfer from kernel to userspace
- Time-based rotation: Configurable pcap file rotation interval
- XDP_PASS: Non-intrusive, always passes packets through
sudo apt-get install -y clang llvm libbpf-dev linux-tools-common linux-tools-$(uname -r)
# Or: sudo make deps-systemmake deps-system # Install system build dependencies (requires sudo)
make deps # Download Go module dependencies
make vmlinux # Generate vmlinux.h from kernel BTF
make generate # Compile eBPF and generate Go bindings (Linux only)
make build # Build Go binary
make all # Both generate and build
make install # Install to /usr/local/binDefault config location: /etc/xdpcap/xdpcap.yaml
Key config fields:
interface: Network interface to capture fromoutput_dir: Directory for pcap filesrotation_interval: How often to rotate files (e.g., "5m")exclude_flows: List of flows to exclude from capture
- The
internal/capture/xdpcap_bpf.gostub is for non-Linux development - On Linux,
go generatecreatesxdpcap_bpfel.gowith real eBPF bindings - eBPF program requires Linux kernel 5.8+ for ring buffer support