Home » eBPF Networking: XDP, TC, Cilium, Socket Filtering และ Kernel Bypass
eBPF Networking: XDP, TC, Cilium, Socket Filtering และ Kernel Bypass
eBPF Networking: XDP, TC, Cilium, Socket Filtering และ Kernel Bypass
eBPF (extended Berkeley Packet Filter) เป็นเทคโนโลยีที่ปฏิวัติ Linux networking โดยให้ run programs ใน kernel โดยไม่ต้องเปลี่ยน kernel code XDP (eXpress Data Path) ประมวลผล packets ที่ driver level ก่อนเข้า kernel stack, TC (Traffic Control) ให้ programmable packet processing ที่ kernel level, Cilium ใช้ eBPF สำหรับ Kubernetes networking + security, Socket Filtering กรอง traffic ที่ socket level และ Kernel Bypass ข้าม kernel stack เพื่อ performance สูงสุด
Traditional Linux networking stack ผ่าน หลาย layers ก่อนถึง application: NIC → driver → kernel netfilter/iptables → TCP/IP stack → socket → app แต่ละ layer เพิ่ม latency eBPF ให้ inject custom code ที่จุดต่างๆ ของ stack → process packets เร็วกว่า iptables 10×, XDP process ที่ driver level = near line-rate performance
eBPF Overview
| Feature |
รายละเอียด |
| คืออะไร |
Virtual machine ใน Linux kernel ที่ run sandboxed programs safely |
| Safety |
eBPF verifier ตรวจสอบทุก program ก่อน load (no crashes, no infinite loops) |
| Hook Points |
XDP, TC, socket, tracepoint, kprobe, cgroup — attach ได้หลายจุด |
| Maps |
Key-value data structures สำหรับ share data ระหว่าง eBPF programs และ userspace |
| JIT Compilation |
eBPF bytecode compiled เป็น native machine code → near-native performance |
| Languages |
เขียนด้วย C (compiled by clang/LLVM) หรือ Rust (Aya framework) |
| Use Cases |
Networking, security, observability, tracing, load balancing |
XDP (eXpress Data Path)
| Feature |
รายละเอียด |
| คืออะไร |
eBPF hook ที่ NIC driver level — process packets ก่อนเข้า kernel network stack |
| Performance |
10-20 million packets/sec per core (near line-rate สำหรับ 10G/25G NICs) |
| Actions |
XDP_PASS (ส่งต่อ), XDP_DROP (drop ทันที), XDP_TX (bounce back), XDP_REDIRECT |
| DDoS Protection |
Drop malicious packets ที่ driver level → ไม่กิน CPU ของ kernel stack |
| Load Balancing |
L4 load balancing ที่ XDP level (Facebook Katran, Cloudflare) |
| Modes |
Native (driver support, fastest), Generic (any NIC, slower), Offloaded (NIC hardware) |
TC (Traffic Control) with eBPF
| Feature |
รายละเอียด |
| คืออะไร |
eBPF programs attached ที่ TC (traffic control) layer — after XDP, before netfilter |
| Ingress/Egress |
Attach ได้ทั้ง ingress (incoming) และ egress (outgoing) — XDP ได้แค่ ingress |
| Full sk_buff |
Access full socket buffer (sk_buff) — มี metadata มากกว่า XDP (xdp_buff) |
| Use Cases |
Policy enforcement, packet mangling, connection tracking, NAT |
| Cilium |
Cilium ใช้ TC eBPF programs สำหรับ Kubernetes pod-to-pod networking |
| Replace iptables |
TC eBPF replace iptables rules → faster, more scalable, programmable |
Cilium
| Feature |
รายละเอียด |
| คืออะไร |
eBPF-based Kubernetes CNI plugin — networking, security, observability |
| CNI |
Replace kube-proxy + iptables ด้วย eBPF → faster pod networking |
| Network Policy |
L3/L4/L7 network policies (HTTP, gRPC, Kafka-aware filtering) |
| Service Mesh |
Sidecar-less service mesh ด้วย eBPF (ไม่ต้อง Envoy sidecar) |
| Hubble |
Network observability platform (flow visibility, service map, DNS monitoring) |
| Tetragon |
Security observability + runtime enforcement (eBPF-based) |
| ClusterMesh |
Multi-cluster connectivity (pod-to-pod across clusters) |
| Adoption |
Google GKE, AWS EKS, Azure AKS — default CNI ใน major clouds |
Socket Filtering
| Feature |
รายละเอียด |
| SO_ATTACH_BPF |
Attach eBPF filter ที่ socket → filter packets ก่อนถึง application |
| cgroup/sock |
eBPF ที่ cgroup level — control socket creation, bind, connect per cgroup |
| sk_msg |
eBPF redirect messages ระหว่าง sockets (socket-level load balancing) |
| Use Cases |
Container-level filtering, socket redirect (bypass kernel stack), access control |
| Sockmap |
eBPF map สำหรับ socket redirect → skip TCP/IP stack สำหรับ local connections |
eBPF vs Traditional Approaches
| Feature |
iptables |
eBPF/XDP |
| Performance |
O(n) rule matching (linear scan) |
O(1) hash-based lookup (eBPF maps) |
| Scalability |
ช้าลงเมื่อ rules เยอะ (10K+ rules = slow) |
Constant performance ไม่ว่า rules จะเยอะแค่ไหน |
| Programmability |
Fixed match/action model |
Full programmable (C/Rust code ใน kernel) |
| Observability |
Limited (counters per rule) |
Rich metrics, tracing, flow visibility |
| Update |
ต้อง flush + reload rules (disruptive) |
Atomic map updates (no downtime) |
| L7 Awareness |
ไม่มี (L3/L4 only) |
L7 protocol parsing (HTTP, DNS, gRPC) |
Kernel Bypass Technologies
| Technology |
How |
Performance |
| DPDK |
Poll-mode driver ใน userspace → bypass kernel entirely |
สูงสุด (80M+ pps) แต่ dedicated cores |
| XDP |
eBPF ที่ driver level → almost bypass kernel stack |
สูงมาก (20M+ pps) + flexible |
| AF_XDP |
Zero-copy socket ที่ส่ง XDP packets ไป userspace directly |
สูง (bridge ระหว่าง XDP + userspace) |
| io_uring |
Async I/O ที่ลด system call overhead |
ปานกลาง-สูง (general purpose) |
ทิ้งท้าย: eBPF = Programmable Linux Kernel Networking
eBPF Networking eBPF: sandboxed programs ใน kernel — safe, fast, programmable (JIT compiled) XDP: process packets at driver level (10-20M pps) — DDoS protection, L4 load balancing TC: eBPF at traffic control — ingress/egress, replace iptables, Cilium uses this Cilium: eBPF-based K8s CNI — network policy, service mesh (sidecar-less), Hubble observability Socket: cgroup/sock filtering, sockmap redirect — container-level control vs iptables: O(1) vs O(n), programmable, L7-aware, atomic updates, better observability Kernel Bypass: DPDK (fastest, dedicated), XDP (fast + flexible), AF_XDP (zero-copy to userspace)
อ่านเพิ่มเติมเกี่ยวกับ Service Mesh Istio Envoy Linkerd และ Container Networking Docker Kubernetes CNI ที่ siamlancard.com หรือจาก icafeforex.com และ siam2r.com