When handling millions of packets per second on single-core cloud instances, standard netfilter/iptables chains incur significant context-switching and sk_buff metadata allocation overhead. Attaching an eBPF program directly to the NIC driver's XDP hook processes frames before the kernel network stack even allocates socket buffers.
XDP Verdict Actions
XDP_DROP: Immediately recycle the RX descriptor ring page—ideal for DDoS mitigation.XDP_TX: Bounce the modified frame back out the arriving network interface.XDP_PASS: Hand the packet up to the normal Linux TCP/IP stack for socket delivery.
SEC("xdp")
int xdp_filter_prog(struct xdp_md *ctx) {
void *data = (void *)(long)ctx->data;
void *data_end = (void *)(long)ctx->data_end;
if (data + sizeof(struct ethhdr) > data_end)
return XDP_PASS;
return XDP_PASS;
}
With native driver support on VirtIO and Intel i40e NICs, XDP achieves sub-microsecond per-packet processing latency with minimal CPU utilization.