XDP Packet Processing

Packet Rewriting ve Load Balancing

Paket modifikasyonu ve L4 load balancing - XDP’nin gerçek gücü.

Packet Rewriting

xdp-tutorial: packet02-rewriting/

Öğrenecekleriniz:

  • MAC address swap (XDP_TX için gerekli)
  • IP address swap (NAT)
  • bpf_xdp_adjust_head / bpf_xdp_adjust_tail - paket boyutunu değiştirme
  • Checksum yeniden hesaplama - IP ve L4 checksum güncelleme

MAC Swap Pattern

static __always_inline void swap_mac(struct ethhdr *eth) {
    __u8 tmp[ETH_ALEN];
    __builtin_memcpy(tmp, eth->h_source, ETH_ALEN);
    __builtin_memcpy(eth->h_source, eth->h_dest, ETH_ALEN);
    __builtin_memcpy(eth->h_dest, tmp, ETH_ALEN);
}

Redirect ve L4 Load Balancing

Lab: XDP Load Balancer

Bu lab’da öğrenecekleriniz:

  • NAT (Network Address Translation) kavramı
  • Connection tracking (5-tuple: src_ip, dst_ip, src_port, dst_port, protocol)
  • Hash ile backend seçimi
  • bpf_fib_lookup helper - routing table’dan MAC/interface çözümleme
  • IP/MAC rewriting
  • XDP_REDIRECT - başka bir interface’e yönlendirme

Load Balancer Akışı

Client -> XDP Program -> Backend Server
  1. Parse: src/dst IP, port
  2. Lookup: Connection table (varsa -> mevcut backend)
  3. Select: Hash(5-tuple) % backend_count (yoksa -> yeni backend)
  4. Rewrite: dst_ip = backend_ip, dst_mac = backend_mac
  5. Redirect: XDP_REDIRECT ile backend interface'e gönder

xdp-tutorial karşılığı: packet03-redirecting/

Okuma: Unimog - Cloudflare’s Edge Load Balancer - production XDP/L4 LB mimarisi.