This BPF program implements multicast packet handling using XDP (eXpress Data Path) for high-performance network packet processing.
- Downstream capture (XDP on veth): Captures IGMP join/leave messages from downstream interfaces
- Upstream XDP: Broadcasts multicast data to subscribed interfaces
- Ring Buffer: Efficient event notification to userspace
- DevMap: Fast packet redirection to multiple interfaces
- Ubuntu 20.04+ (tested on Ubuntu 20.04, 22.04, 24.04)
- Linux kernel 5.4+ (for XDP and BPF features)
- Root privileges for loading BPF programs
# Install required packages
make install-deps
# Or manually:
sudo apt update
sudo apt install -y \
clang \
llvm \
libbpf-dev \
linux-headers-$(uname -r) \
build-essential \
libelf-dev \
bpftoolmake check-bpfIf BPF filesystem is not mounted:
sudo mount -t bpf bpf /sys/fs/bpfmakeThis will create multicast.bpf.o which contains the compiled BPF bytecode.
make multicast_usermake loadmake showmake unloadevents: Ring buffer for IGMP join/leave eventsfwd_map: DevMap for packet redirection to downstream interfaces (veth endpoints)
-
xdp_downstream: Attach to veth/downstream interfaces- Captures IGMP join/leave messages
- Reports events to userspace via ring buffer
- Drops IGMP packets after processing
-
xdp_upstream: Attach to main interface (e.g., eth0)- Identifies multicast packets
- Redirects to subscribed interfaces via devmap
- Passes through IGMP control packets
-
Netkit-specific programs have been removed in favor of a simpler veth/XDP flow.
# For veth/XDP:
sudo bpftool net attach xdp id <prog_id> dev <downstream_ifname># Attach to main interface
sudo bpftool net attach xdp id <prog_id> dev eth0- Header file not found: Ensure
linux-headers-$(uname -r)is installed - BPF verifier errors: Check kernel version compatibility
- Permission denied: Run with sudo/root privileges
- Interface not found: Verify interface names exist
- BPF verifier log not available: The verifier log at
/sys/kernel/debug/bpf/verifier_logis created dynamically when BPF programs are loaded. This is normal if you haven't loaded any BPF programs yet.
# Check BPF verifier log
sudo cat /sys/kernel/debug/bpf/verifier_log
# List loaded programs
sudo bpftool prog list
# Show program details
sudo bpftool prog show id <prog_id>
# Dump program bytecode
sudo bpftool prog dump xlated id <prog_id># Monitor kernel messages
sudo dmesg -w
# Check for BPF-related errors
sudo journalctl -f -k | grep -i bpf- Ring Buffer Size: Adjust
max_entriesin the events map based on expected event volume - DevMap Size: Set
MAX_SUBSbased on maximum expected subscribers - XDP Mode: Use native mode for best performance, fallback to generic mode if needed
- BPF programs run in kernel space with elevated privileges
- Validate all packet data to prevent potential exploits
- Use appropriate map permissions and access controls
- Monitor program behavior in production environments
GPL v2 - See the _license section in the BPF program.