Objective
Rewrite the core XDP packet filtering routine in raw eBPF assembly to eliminate LLVM compiler overhead and push packet-drop latency toward the nanosecond range.
Motivation
The current C-compiled eBPF path goes through the LLVM backend, which introduces:
- Unpredictable register allocation
- Missed optimization opportunities at the instruction level
- Occasional redundant bounds checks inserted by LLVM
For the hot path (IPv4 header parse → source IP lookup in icmp_banned → XDP_DROP), hand-written eBPF ASM gives deterministic instruction counts and exact control over every register.
Scope
1. Isolate the drop/routing function
Extract the logic that:
- Reads the incoming packet via
xdp_md context (data / data_end pointers)
- Parses the Ethernet + IPv4 headers
- Looks up
ip->saddr in BPF_MAP_TYPE_LRU_HASH (icmp_banned)
- Returns
XDP_DROP on a hit, XDP_PASS or redirects otherwise
2. Translate to raw eBPF ASM
Use explicit eBPF register semantics:
r1 — xdp_md *ctx on entry
r0 — return value (XDP_DROP = 1, XDP_PASS = 2)
r2–r5 — scratch / helper arguments
r6–r9 — callee-saved across helper calls
r10 — read-only frame pointer
Every instruction must be commented with its register role and purpose.
3. Pass the kernel verifier
- All memory accesses via
data/data_end must include explicit bounds checks before each load.
- No unbounded loops.
- Stack usage ≤ 512 bytes.
- Helper calls (
bpf_map_lookup_elem) must follow the standard calling convention.
4. Rust control-plane integration
- The ASM object must be loadable by aya (
EbpfLoader) alongside the existing C-compiled sections.
- No changes to the map definitions or Rust-side accessors.
Expected output
A fully commented eBPF ASM implementation of the ICMP/DDoS filtering function, validated by the Linux verifier, integrated into the existing build system (build.rs), with benchmarks showing instruction-count reduction vs the LLVM-compiled baseline.
Labels
enhancement performance ebpf xdp
Objective
Rewrite the core XDP packet filtering routine in raw eBPF assembly to eliminate LLVM compiler overhead and push packet-drop latency toward the nanosecond range.
Motivation
The current C-compiled eBPF path goes through the LLVM backend, which introduces:
For the hot path (IPv4 header parse → source IP lookup in
icmp_banned→XDP_DROP), hand-written eBPF ASM gives deterministic instruction counts and exact control over every register.Scope
1. Isolate the drop/routing function
Extract the logic that:
xdp_mdcontext (data/data_endpointers)ip->saddrinBPF_MAP_TYPE_LRU_HASH(icmp_banned)XDP_DROPon a hit,XDP_PASSor redirects otherwise2. Translate to raw eBPF ASM
Use explicit eBPF register semantics:
r1—xdp_md *ctxon entryr0— return value (XDP_DROP = 1,XDP_PASS = 2)r2–r5— scratch / helper argumentsr6–r9— callee-saved across helper callsr10— read-only frame pointerEvery instruction must be commented with its register role and purpose.
3. Pass the kernel verifier
data/data_endmust include explicit bounds checks before each load.bpf_map_lookup_elem) must follow the standard calling convention.4. Rust control-plane integration
EbpfLoader) alongside the existing C-compiled sections.Expected output
A fully commented eBPF ASM implementation of the ICMP/DDoS filtering function, validated by the Linux verifier, integrated into the existing build system (
build.rs), with benchmarks showing instruction-count reduction vs the LLVM-compiled baseline.Labels
enhancementperformanceebpfxdp