Index

Free, with Google

Keep going, free.

A free account opens lessons 2 and 3 of every track, 33 more lessons, and keeps your progress and review cards on every device.

Start free with Google

A chalk plan

Open everything on chalk.

Every lesson, board, video, lab and paper, and the full review decks. Yearly is $39/year.

See plansStart free instead

Module 04 · Networking · The whole trip · about 16 min to read

Watch: Routing: how a packet finds any house on earth
▶ VideoPlay it as a journeyTutor comes with a plan

Programs inside the kernel: eBPF and XDP

The Parcel's Journey
The Parcel's Journey · Open board

: 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.

Lesson 39 of 44 in Networking

The rest of this lesson is part of a plan.

A plan opens every lesson, board, video, lab and paper on chalk. Yearly is $39/year.

See plansAlready a member? Sign in

Or start free: a free account opens lessons 2 and 3 of every track.

In this lesson

  • The problem: you cannot add a rule to the kernel
  • eBPF: a small program the kernel agrees to run
  • The hook: where the program is attached
  • The verifier: the kernel reads your program first
  • XDP: the hook at the front gate
  • A map: memory that the program and you share
  • What real systems do with this
  • Three modes of XDP
  • The budget XDP is aiming at
  • The program as I wrote it
  • What the verifier does not do
  • Where real tools sit
  • Limits of what was measured

Terms it explains: eBPF program, hook, verifier, XDP, map, Cilium, Cloudflare, Observability tools.

Related paper

Review Networking