What Is XDP and Where It Runs in the Network Stack
XDP runs eBPF programs on packets inside the NIC driver, before the kernel builds an skb. See the hook point, the five verdicts and the three attach modes.

When a packet arrives, the Linux network stack normally spends real work on it before your code ever sees it: it allocates a socket buffer, parses headers, runs netfilter and finds a route. If you only want to drop a flood of unwanted packets, that work is wasted. XDP, the eXpress Data Path, moves the decision to the earliest point software can reach, inside the network driver, before any of that allocation happens. This post explains where that hook sits, what an XDP program can decide, the three modes it can run in and what it cannot do. It uses Linux 6.12 and builds on the idea of eBPF programs and maps from the previous post in this cluster.
The hook point
A receive path on a typical NIC goes like this: the card writes the packet into a receive ring in memory with DMA, raises an interrupt or is polled by NAPI, and the driver builds a kernel object called an sk_buff, or skb, that carries the packet and a large amount of metadata through the rest of the stack.
XDP runs before the skb exists. The driver calls your eBPF program with a lightweight context, struct xdp_md, that points straight at the packet bytes in the receive buffer. If the program says drop, the driver recycles the buffer and nothing else happens, so no skb was ever built.
NIC -> DMA to rx ring -> driver NAPI poll
|
[ XDP program ] <- runs here, on raw frame
|
XDP_PASS -> build skb -> tc ingress -> netfilter -> routing -> socket
XDP_DROP -> recycle buffer
XDP_TX / XDP_REDIRECT -> transmit without the stackThe kernel BPF documentation and the xdp-project tutorial describe this placement, and it is the reason XDP is fast: the per-packet cost is a function call plus whatever your program does.
The context
An XDP program receives a pointer to struct xdp_md, defined in linux/bpf.h:
| Field | Meaning |
|---|---|
data | Start of the packet (an address, stored as a 32-bit integer) |
data_end | One byte past the end |
data_meta | Start of optional metadata the driver or program can place before data |
ingress_ifindex | Interface index the packet arrived on |
rx_queue_index | Receive queue the packet came in on |
The program gets raw bytes starting at the Ethernet header. It is responsible for checking that each header it reads lies inside [data, data_end), a rule the verifier enforces.
The five verdicts
An XDP program returns one of five actions, from enum xdp_action:
| Action | What happens |
|---|---|
XDP_PASS | Continue into the normal network stack |
XDP_DROP | Discard the frame at the driver |
XDP_TX | Send the frame back out of the interface it arrived on |
XDP_REDIRECT | Send it to another interface, a CPU or an AF_XDP socket |
XDP_ABORTED | Drop and signal an error through the xdp_exception tracepoint |
XDP_ABORTED is what a program returns on an error path, so that a bug shows up in tracing instead of silently dropping traffic. A program that falls off the end with an undefined value is rejected by the verifier.
Three attach modes
The same program can be attached in three ways, and they differ a lot in speed and in what hardware they need.
Native (driver) mode,
xdpdrv. The driver itself calls the program in its receive path. This is the fast mode, and it needs driver support. Many common drivers support it, includingmlx5,ixgbe,i40e,ice,bnxtandveth, and the kernel's XDP driver support list is the place to check yours.Generic mode,
xdpgeneric. The kernel runs the program after the skb is built, in the core receive path, for drivers with no native support. It works on any interface, which makes it good for development, but you lose the main benefit, because the skb allocation has already happened.Offload mode,
xdpoffload. A smart NIC runs the program on the card. It needs a NIC and driver that support it, such as Netronome devices, and is not common.
With iproute2 you choose the mode in the attach command:
ip link set dev eth0 xdpdrv obj prog.o sec xdp
ip link set dev eth0 xdpgeneric obj prog.o sec xdp
ip link set dev eth0 xdp offIf you use plain xdp the kernel tries native mode and falls back to generic. Adding xdpdrv forces native and returns an error if the driver cannot do it, which is the safer choice in production because you find out immediately instead of running slowly.
To see what is attached, ip link show prints a program id on the interface:
ip link show dev eth02: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 xdp qdisc fq_codel state UP mode DEFAULT group default qlen 1000
link/ether 52:54:00:12:34:56 brd ff:ff:ff:ff:ff:ff
prog/xdp id 87 The word xdp in the flags line, and prog/xdp id 87 below it, show a program is loaded in driver mode. In generic mode the flags show xdpgeneric. The id will differ on your machine.
How XDP differs from other early hooks
Linux has several places to intercept a packet, and XDP is the earliest. Traffic control (tc) with a cls_bpf classifier runs after the skb is built, which costs more but gives the program an skb with parsed metadata, the ability to attach on egress, and helpers that touch routing and checksums. A socket filter runs even later, on one socket's receive path, and only decides what that socket sees. Netfilter hooks, used by nftables and iptables, sit in the middle of the IP stack and see connection tracking state.
The practical rule is to place a decision at the earliest hook that still has the information the decision needs. Dropping by source address or port needs only the headers, so XDP is enough. Deciding by connection state needs conntrack, so netfilter is the earliest useful point. Matching traffic for one socket belongs at the socket. Pushing a decision earlier than its information allows leads to programs that reimplement half of the stack in maps.
A second difference is who pays. An XDP program runs in the driver's softirq context on the CPU that is handling that receive queue, so a slow program slows packet processing for that queue and, if it runs long enough, causes drops in the NIC ring. Keep XDP code short and bounded.
What XDP can and cannot do
XDP is a good fit for work that is decided from packet headers alone: dropping a flood, steering flows, load balancing and counting. It has real limits.
No skb metadata. There is no socket, no routing decision, no conntrack state, because none of that exists yet. A program that needs connection tracking must keep its own state in maps.
Receive side only. XDP sees ingress. Egress hooks are a job for traffic control, covered in a later post in this cluster.
Small, verified programs. The verifier and the 512-byte stack limit what logic fits.
Frame limits. Historically a packet had to fit one page, which restricted jumbo frames. Since Linux 5.18 multi-buffer XDP lets a program see frames split across several buffers, but only drivers that support it and programs that declare the
xdp.fragssection can use it.Driver dependence. Features such as
XDP_REDIRECTand zero-copy sockets depend on the specific driver.
When to choose XDP
Choose XDP when the work is per-packet, header-based and high-volume, and when running it before the stack saves meaningful CPU. Typical cases are protection against floods, simple firewalls, stateless load balancing and packet sampling. If your logic needs the full stack, such as TLS state or socket lookups, a later hook like traffic control or a socket-level program is a better fit.

