Programs inside the kernel: eBPF and XDP

: one parcel travelling from a laptop to a server. This lesson puts a small program at the very first stop of the last stretch, before the parcel reaches the server’s shelf.
In the winter of 1993, at the USENIX conference in San Diego, Steven McCanne and Van Jacobson of Lawrence Berkeley Laboratory presented “The BSD Packet Filter: A New Architecture for User-level Packet Capture”.
Their problem was a tool like tcpdump. It shows you the packets on a wire, but you usually want only some of them, for example the ones for one port. The old way copied every packet from the kernel to the tool and let the tool throw most of them away. That copying cost a lot. Their idea was to send the question into the kernel instead. A small program, the filter, runs inside the kernel on each packet. Only the packets that pass are copied out. The paper says its filter machine is register based, and its abstract claims it runs up to 20 times faster than the design before it.
That idea is still alive. Today it is called eBPF, and it runs far more than packet filters.
By the end of this lesson you will be able to say what an eBPF program is, why the kernel lets it run safely, and why XDP can drop a packet before the kernel has spent any work on it. You will also have seen a real XDP program run on this machine.
Think of a housing society, as in From the wire to your accept(): sockets and the receive path. The guard at the gate sees every parcel first. Today the gate guard has a rule card from the society. The rest of the lesson uses only the real words.
Before you start. From the wire to your accept(): sockets and the receive path followed one packet from the network card’s ring buffer, through a batch read, to the socket’s receive buffer, and showed that the kernel does a lot of work per packet before your program sees it. The wall that remembers: nftables and conntrack showed nftables, a wall inside the kernel that judges packets by rules and keeps a memory of conversations. Processes, Threads & the Kernel gave you the kernel as the one program that owns the hardware, and every other program asks it for help through system calls.
