XDP (eXpress Data Path) is a high-performance networking feature built into the Linux kernel that lets you process network packets as soon as they arrive at a network interface, before the kernel’s normal network stack even sees them. You attach a small program (usually written in C and compiled to eBPF bytecode) to a network driver, and that program can drop, pass, redirect, or modify packets at line rate. This article explains what XDP is, how it works, where it comes from, and how it compares to other packet-processing methods.
Background: Why XDP Was Created
Traditional Linux packet processing goes through a long path: the network interface card (NIC) receives a packet, copies it into kernel memory, runs through protocol handlers (IP, TCP/UDP), and eventually delivers it to a user-space application via a socket. This path involves multiple memory copies, context switches, and CPU interrupts, which limits throughput to a few million packets per second on a typical server. For years, developers worked around this by using kernel modules or specialized frameworks like DPDK (Data Plane Development Kit) that bypass the kernel entirely. DPDK gives raw speed but requires dedicating entire CPU cores to polling and managing network hardware directly, which is complex and less flexible.
XDP was introduced to provide a middle ground: the speed of kernel bypass without losing the safety and programmability of the kernel. It was first proposed in 2016 by Tom Herbert at the Linux Plumbers Conference, and the initial implementation was merged into the Linux kernel in version 4.8 (released October 2016). The core idea is to run eBPF (extended Berkeley Packet Filter) programs at the earliest possible point in the receive path—right after the NIC driver receives the packet, before any memory allocation or protocol processing. This gives the program the ability to make fast decisions while still being safe (the kernel verifies the program before loading) and flexible (the program can be updated without rebooting).
How XDP Works
XDP programs are written in C (or other languages that compile to eBPF) and attached to a network interface. When a packet arrives, the NIC driver calls the XDP program with a pointer to the packet’s data in kernel memory. The program can then return one of several actions:
- XDP_PASS – the packet is passed to the normal kernel network stack for further processing.
- XDP_DROP – the packet is discarded immediately, freeing the memory without further processing.
- XDP_TX – the packet is transmitted back out the same interface it came in on (useful for load balancers or firewalls).
- XDP_REDIRECT – the packet is sent to another interface or to a user-space socket via AF_XDP.
- XDP_ABORTED – the program encountered an error and the packet is dropped (and an error is logged).
The key to XDP’s speed is that it runs before the kernel allocates a socket buffer (skb) or does any protocol parsing. The packet is still in the NIC’s ring buffer, and the program can inspect the raw bytes directly. This avoids the overhead of allocating memory and copying data, which is often the bottleneck in traditional processing.
XDP also supports batching: the driver can process multiple packets per interrupt, and the program can use maps (key-value stores) to share state between packets and between CPU cores. This allows for efficient load balancing, DDoS filtering, and custom forwarding logic.
XDP vs. Other Packet Processing Methods
To understand XDP’s place, it helps to compare it with the alternatives:
- Kernel network stack – full-featured but slow; good for general-purpose networking.
- DPDK – user-space polling, very fast but requires dedicating cores and writing custom drivers; not integrated with the kernel.
- AF_PACKET / PF_RING – user-space access to raw packets, but still goes through the kernel and has significant overhead.
- eBPF with tc (traffic control) – similar to XDP but runs later in the stack, after the packet has been allocated; slightly slower but has access to more metadata.
XDP sits between the kernel stack and DPDK in both speed and complexity. It can achieve millions of packets per second per core (often 10-20 million on modern hardware), which is far faster than the kernel stack (usually 1-2 million pps) but not quite as fast as DPDK (which can exceed 20 million pps with dedicated cores). However, XDP is easier to deploy because it uses the standard kernel interfaces and doesn’t require dedicated cores or custom drivers.
Common Uses and Real-World Examples
XDP is used in production systems for several purposes:
- DDoS mitigation – dropping malicious packets at line rate before they hit the application. For example, Cloudflare uses XDP in their edge servers to filter out attack traffic.
- Load balancing – redirecting packets to different backends based on IP or port, using XDP_REDIRECT. Facebook uses XDP for their load balancer (Katran).
- Firewalling – simple stateless filtering with XDP_DROP, which is faster than iptables for high-volume rules.
- Monitoring and statistics – counting packets and bytes with XDP programs and maps, without affecting throughput.
- Custom forwarding – building specialized routers or switches that forward packets between interfaces with minimal latency.
Another common use is AF_XDP sockets, which allow user-space applications to receive packets directly from the NIC via XDP_REDIRECT, bypassing the kernel stack. This is used by high-performance network applications like packet capture tools and custom protocol stacks.
How to Choose: When to Use XDP
XDP is not a silver bullet. Consider it when you need very high packet rates (millions per second) and your processing logic is simple (e.g., drop, forward, count). It is ideal for:
- Filtering traffic at line rate (DDoS protection, network ACLs).
- Load balancing at scale.
- Custom packet processing that doesn’t require complex state or TCP/IP stack features.
Avoid XDP if you need to perform complex protocol parsing, maintain TCP connections, or use kernel features like conntrack or NAT. For those, the regular kernel stack or a combination of XDP and tc is better. Also note that XDP requires a NIC driver that supports it; most modern drivers (Intel, Mellanox, Broadcom) do, but older or virtualized devices may not. If your NIC doesn’t support native XDP, you can use generic XDP (which runs in the kernel’s receive path but with less performance) or a software fallback.
Common Problems and Misconceptions
One common misconception is that XDP is the same as DPDK. While both aim for high performance, XDP runs in the kernel and is safe (programs are verified), whereas DPDK runs in user space and requires more control over hardware. Another misconception is that XDP can do everything the kernel stack does—it cannot; it only sees raw packets and has no TCP/IP stack logic.
Common problems when using XDP include:
- Compatibility – not all drivers support native XDP; check your driver’s documentation.
- Complexity – writing eBPF programs requires knowledge of C and eBPF constraints (no loops, limited stack size).
- Debugging – tracing XDP programs is harder than user-space code; use bpf tracepoints and tools like bpftool.
- Performance tuning – to get maximum speed, you need to configure RSS (Receive Side Scaling) to spread packets across cores, and use busy-polling or XDP’s built-in batching.
Another issue is that XDP programs run in a restricted environment: they cannot call arbitrary kernel functions, and the verifier may reject complex programs. However, the eBPF ecosystem has grown, and many helpers are now available for common tasks like checksumming and tunnel encapsulation.
Frequently Asked Questions
Is XDP the same as eBPF?
No. eBPF is the technology that allows safe, sandboxed programs to run in the kernel. XDP is one of the many hooks where an eBPF program can be attached. Other hooks include kprobes, tracepoints, and tc. So XDP uses eBPF, but eBPF is not limited to XDP.
What is the difference between XDP and DPDK?
DPDK bypasses the kernel entirely and runs in user space, giving maximum control and speed but requiring dedicated CPU cores and custom drivers. XDP runs inside the kernel, is safer (programs are verified), and doesn’t require dedicating cores. XDP is slower than DPDK in absolute terms but much faster than the normal kernel stack and easier to deploy.
Can XDP handle TCP traffic?
Yes, XDP can see TCP packets (as raw IP packets), but it doesn’t understand TCP state. If you need to track connections or modify TCP flows, you need to use the kernel stack or combine XDP with tc. XDP is best for L3/L4 filtering and forwarding, not for L4 stateful processing.
Do I need special hardware to use XDP?
You need a network interface card (NIC) that supports native XDP. Most modern NICs from Intel, Mellanox, and Broadcom do. If your NIC doesn’t support it, you can still use generic XDP (which runs in the kernel’s software path) but with lower performance. Check your driver’s documentation for XDP support.
Is XDP production-ready?
Yes, XDP has been used in production by major companies like Cloudflare, Facebook, and Netflix for several years. It is considered stable in the Linux kernel, and the eBPF tooling (libbpf, bpftool) is mature. However, you should test thoroughly in your environment because driver-specific behavior can vary.
What is AF_XDP?
AF_XDP is a socket type that allows user-space applications to receive packets directly from the NIC via XDP_REDIRECT, bypassing the kernel stack. It provides a zero-copy path for high-performance packet processing in user space, while still using the kernel’s driver and XDP program. It’s often used for custom protocol stacks and high-speed packet capture.
Related
General steps for current mainstream versions; menus can differ by device and version. See the disclaimer or report an error.
More in this bed
- Secure a Samsung Galaxy After a Zero-Day Disclosure
- What to Check Before Installing Linux Alongside Windows
- Fix OEM Activation Error 0xc004c060 in Windows 10
- Why Does My App Run One Query for the List and One per Item?
- Fix Google Chrome Has Stopped Working
- Fix Apps Not Downloading From Play Store