Skip to content

Packet Processing Pipeline

Packets flow through 16 ordered stages. Order is by cost: cheapest checks run first. Each stage can be independently enabled/disabled via configuration. Five stages support freplace hot-patching — alternative implementations can be attached at runtime without unloading the XDP program (kernel ≥ 5.11, CONFIG_DEBUG_INFO_BTF=y).

Stage table

#StageCostAction
0MAC filter~10 nsL2 allowlist/blocklist (8 MAC entries)
1Packet parse~60 nsEth, VLAN (802.1Q/802.1ad/QinQ), IP, extension headers, TCP/UDP
2SYNPROXY~200 nsCookie generation (SplitMix64), SYN-ACK rewrite, XDP_TX response
3Panic circuit breaker~5 nsPer-CPU probabilistic drop under PPS overload
4Global detection~30 nsEntropy spoofing (16 buckets) + SYN/FIN ratio, window-based
5Bloom filter~15 ns3-hash probabilistic whitelist membership check, skips HASH lookup on miss
6Whitelist HASH~40 nsPer-IP bypass flags — full bypass exits pipeline immediately
7Ban check~40 nsSingle-IP ban + LPM trie subnet ban (v4 + v6)
8L3 validation~20 nsIPv4 bogon (7 ranges) + IPv6 bogon (6 ranges)
9L4 validation~15 nsTCP flag validation (5 bogus combos) + L4 header bounds
10UDP amplification~100 nsDNS QR-bit check + 8-port configurable generic reflection
11L7 signatures~200 ns16-slot pattern matching (port + proto + offset + mask)
12IP stats lookup~50 nsLRU_HASH lookup or create (100K entries, auto-eviction)
13Per-pkt tracking~10 nsTTL sampling, packet size sampling, entropy bucket increment
14Connection tracking~30 nsBlind SYN-ACK / blind RST detection, per-IP SYN timestamp
15Rate limiting~50 nsThreshold scoring (additive) or token bucket, ban insertion

Kernel feature gates

Some stages require specific kernel features:

StageRequirementWhy
SYNPROXYKernel ≥ 5.15Bounded loops in BPF (synproxy_timeout_sec walk)
Bloom filterKernel ≥ 5.4BPF array map as Bloom filter words
freplace stagesKernel ≥ 5.11 + CONFIG_DEBUG_INFO_BTF=yBTF-based function replacement
Panic breakerKernel ≥ 5.3Per-CPU map support
LPM trie (subnet ban)Kernel ≥ 4.20Longest-prefix-match map type

freplace stages

The following stages are __attribute__((noinline)) BPF subprograms with BTF type info. A freplace program with SEC("freplace/stage_<name>") can replace them at runtime:

Stagefreplace targetDefault location
Ban checkstage_ban_checkopenshield.bpf.c
Rate limitstage_rate_limitopenshield.bpf.c
Connection trackstage_conn_trackopenshield.bpf.c
UDP amplificationstage_amp_checkopenshield.bpf.c
L7 filterstage_l7_filteropenshield.bpf.c

A working example replacement for stage_ban_check is provided in ebpf/modules/ban_check_freplace.c — it adds ringbuf event emission on every ban hit while preserving the default drop behavior.

Architecture · Detection Methods