Architectural Invariant Design: Zero-Copy Driver-Level Ingress Rate Limiting with eBPF/XDP and AF_XDP
Zero-Copy Driver-Level Ingress Rate Limiting with eBPF/XDP and AF_XDP defines an industrial-grade behavioral standard for devops engineering. Enforces strict native/driver-mode XDP hook execution and UMEM ring buffer memory safety for AF_XDP zero-copy ingress filtering. Eliminates kernel SKB allocations during volumetric Layer 4 DDoS attacks by dropping abusive packets directly at the NIC ring buffer before kernel stack traversal. Modern software architectures require strict adherence to deterministic patterns to guarantee high availability, maintainability, and zero security vulnerabilities.
Hazard Analysis: What Breaks Without This Rule
The following failure modes have been cataloged from hundreds of hours of production code reviews where AI assistants produced non-compliant implementations:
| Failure Mode | AI Symptom (The Anti-Pattern) | Severity | Production Impact & Remedy |
|---|---|---|---|
| AI Hallucination & Deprecation Drift | Falling Back to Generic XDP Mode and Copying Packets During Layer 4 Flood Ingress | Critical | Violating this industrial standard introduces regression bugs, security risks, and unexpected runtime failures in production. Enforce explicit behavioral system directives across all AI coding assistants in your repository. |
| Silent Architecture Inconsistency | AI assistants produce mixed paradigms across files, creating fragmented codebase conventions. | Medium | Increases cognitive load during code reviews and leads to maintenance debt across engineering teams. Pin project conventions in .cursor/rules, CLAUDE.md, and AGENTS.md so all team agents follow identical guardrails. |
Step-by-Step Production Directives
Each rule constraint below is injected into the AI agent's system prompt to establish deterministic boundaries:
Engineers MUST ALWAYS verify XDP hook attachment in native/driver mode (XDP_FLAGS_DRV_MODE)
Engineers MUST ALWAYS verify XDP hook attachment in native/driver mode (XDP_FLAGS_DRV_MODE); generic SKB mode (XDP_FLAGS_SKB_MODE) is strictly forbidden in production as it allocates struct sk_buff prior to eBPF execution.
Engineers MUST ALWAYS implement complete cursor bounds validation (data + offset <= data_end) before dereferencing any byte of Ethernet, IPv4/IPv6, UDP, or TCP headers to satisfy the BPF verifier.
Engineers MUST ALWAYS implement complete cursor bounds validation (data + offset <= data_end) before dereferencing any byte of Ethernet, IPv4/IPv6, UDP, or TCP headers to satisfy the BPF verifier.
Engineers MUST use lockless BPF_MAP_TYPE_PERCPU_ARRAY or per-CPU BPF_MAP_TYPE_LRU_HASH for token-bucket rate state to avoid CPU cache-line bouncing and lock contention under multi-gigabit traffic rates.
Engineers MUST use lockless BPF_MAP_TYPE_PERCPU_ARRAY or per-CPU BPF_MAP_TYPE_LRU_HASH for token-bucket rate state to avoid CPU cache-line bouncing and lock contention under multi-gigabit traffic rates.
Engineers MUST immediately return XDP_DROP or redirect legitimate packets via bpf_redirect_map into AF_XDP (XSKMAP) using XDP_ZEROCOPY
Engineers MUST immediately return XDP_DROP or redirect legitimate packets via bpf_redirect_map into AF_XDP (XSKMAP) using XDP_ZEROCOPY; copying packets to user space via XDP_COPY is prohibited for high-volume pipelines.
Engineers MUST configure UMEM chunks with page-aligned sizes (e.g., 2048 or 4096 bytes) and ensure that packet metadata manipulation complies with XSK UMEM headroom specifications.
Engineers MUST configure UMEM chunks with page-aligned sizes (e.g., 2048 or 4096 bytes) and ensure that packet metadata manipulation complies with XSK UMEM headroom specifications.
Engineers MUST ensure BPF tail calls and maps are pre-allocated with BPF_F_NO_PREALLOC omitted or explicitly tested against high allocation latency under low-memory kernel conditions.
Engineers MUST ensure BPF tail calls and maps are pre-allocated with BPF_F_NO_PREALLOC omitted or explicitly tested against high allocation latency under low-memory kernel conditions.
Frequently Asked Technical Questions
Common questions developers face when configuring AI coding assistants for this stack:
Q:Why is Zero-Copy Driver-Level Ingress Rate Limiting with eBPF/XDP and AF_XDP critical for AI coding assistants?
Enforces strict native/driver-mode XDP hook execution and UMEM ring buffer memory safety for AF_XDP zero-copy ingress filtering. Eliminates kernel SKB allocations during volumetric Layer 4 DDoS attacks by dropping abusive packets directly at the NIC ring buffer before kernel stack traversal. Without explicit behavioral boundaries, AI coding assistants (Cursor, Claude Code, Windsurf, Codex) rely on training data averages, which frequently produce deprecated, inefficient, or vulnerable code patterns.
Q:How does adopting this rule prevent AI hallucinations?
This rule explicitly declares what the AI must avoid (Falling Back to Generic XDP Mode and Copying Packets During Layer 4 Flood Ingress) and prescribes verified positive examples. Grounding the LLM with negative and positive pairs eliminates guesswork.
Q:Which AI coding environments are supported?
This specification is multi-platform compatible: Cursor (.cursor/rules/*.mdc & .cursorrules), Anthropic Claude Code (CLAUDE.md), Windsurf (.windsurfrules), Codex / Cline (AGENTS.md), and GitHub Copilot (.github/copilot-instructions.md).
Q:Can I combine this rule with other technology stacks?
Yes. Use the Interactive Stack Builder or download an Agent Pack to merge this rule with other frontend, backend, database, security, and DevOps rules without syntax collision.