eBPF, XDP and AF_XDP


1. NIC -> Kernel
2. Kernel process it layer by layer
3. Sub-systems tunnel, traffic shaping, IPSec, NAT, Packet filter
4. enqueued to socket receive queue. 
5. wake up user space process
6. copy data to user space process

eBPF, XDP and AF_XDP are Kernel Feature for high speed packet processing


 * [eBPF](https://ebpf.io/what-is-ebpf/) (extended Berkeley Packet Filter) is a kind of virtual machine that runs sandboxed programs inside the Linux kernel.

- TCP Dump uses BPF. 

- Not tied specifically to networking

- in kernel verifiers. No endless loop. no access to invalid memory. 

Instructions

- RFC by IETF defines instruction set

- VM + limited instruction set

- JIT

Program Types

1. XDP

2. socket filtering, kprobe, tc schedular (action, classifiers), performance events

3. tracing: function entry, function exit, modify return value

4. cgroups, light weight tunnels

5. TCP stream parsing ( kernel assisted TLS and KCM = kernel connection machine. IP multiplex)

$ bpftool prog

$ clang target bpf

eBPF maps

1. K-v store

2. hash, array, radix-tree, bloom filter

3. _per_cpu variants for multi-processor efficiency

Use cases

1. device driver for DPDK, VPP and related user plane frameworks

2. load balancer (e.g. dnsdist)

3. software switch (e.g. vSwitch)

4. DoS protection filter

5. Intrusion Detection Systems (e.g. Suricata)

6. eupf = eBPF + AF_XDP for accelerated 5G UPF

* [XDP](https://docs.cilium.io/en/latest/bpf/progtypes/#xdp) (eXpress Data Path) is a framework for eBPF that enables high-performance programmable packet processing in the Linux kernel

Kernel 4.18
XDP_DROP : DoS. Drop at line rate. similar to disconnect cable. 
XDP_PASS : Slow Path OR other NIC. use case like netfilter. 
XDP_TX : 
XDP_REDIRECT

Register eBPF program to XDP hook

* [AF_XDP](https://www.kernel.org/doc/html/next/networking/af_xdp.html) is an *address family* that is optimized for high-performance packet processing. It allows in-kernel XDP eBPF programs to efficiently pass packets to userspace via memory-mapped ring buffers.

XDP Socket
Operates on raw packet
Memory mapped Rx/Tx Ring. so zero copy. It is at network interface card interrupt receive level. receive queue of network card. Morden NIC has many receive queues. one for each CPU. based on connection.  it can edit the packet.no read/write. as no copy between user space and kernel space. 
Single socket for RX+Tx. Not possible
descriptor points to memory 

eBPF program will decide go to AF_XDP or not. 

AF_XDP can also generate pcap. 

Ref:
github.com/xdp-project/xdp-tools
github.com/xdp-project/xdp-tutorial
qmonnet.github.io/whirl-offload/2021/09/23/bpftool-features-thread
https://media.ccc.de/v/osmodevcon2024-204-introduction-to-xdp-ebpf-and-afxdp

XDP is close to DPDK. But DPDK is faster. 

0 comments:

Post a Comment