Skip to content

perf: rewrite critical XDP ICMP/DDoS filter in native eBPF assembly (ASM) #146

Description

@redlemonbe

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_bannedXDP_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:

  • r1xdp_md *ctx on entry
  • r0 — return value (XDP_DROP = 1, XDP_PASS = 2)
  • r2r5 — scratch / helper arguments
  • r6r9 — 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions