How We Used eBPF to Build Programmable Packet Filtering in Magic Firewall
Dec 6, 2021Chris J Arges

Summary
This post details the integration of eBPF with nftables within Cloudflare's Magic Firewall. It explains how eBPF programs can be loaded and executed within the kernel to provide advanced packet parsing and content matching capabilities beyond what nftables alone can offer. The post covers the technical challenges of bridging iptables' xt_bpf extension with nftables, the structure of netlink/netfilter messages required, and the process of compiling and loading eBPF programs using libraries like cilium's ebpf. This enables more sophisticated firewall rules for protocol validation and advanced field matching.
More from the Website Security & Threat Management trail
- We tested our own WAF with frontier AI models. Here’s what we found
- When scanners miss the attack: how Cloudflare Client-Side Security protects storefronts
- Introducing automatic remediation policies with Cloudflare CASB
- Introducing context-aware vulnerability discovery and remediation with Cloudflare Managed Defense and OpenAI Daybreak Models
- Introducing Adaptive Intelligence: undermining the economics of every bot attack