Architectural Invariant Design: eBPF XDP Line-Rate Rate-Limiting & Lockless Map Invariants
eBPF XDP Line-Rate Rate-Limiting & Lockless Map Invariants defines an industrial-grade behavioral standard for devops engineering. Enforces lockless eBPF LRU/Per-CPU map synchronization and atomic token bucket rate-limiting at the XDP driver hook to preserve host kernel CPU headroom during volumetric L4 DDoS attacks. Prohibits global spinlocks, non-per-cpu allocations, and blocking user-space batch synchronization operations that induce softirq tail drops. 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 | Global BPF Hash Map Mutations Under Volumetric L4 Ingress Inducing Softirq Saturation and Driver Ring Buffer Drops | 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 use BPF_MAP_TYPE_LRU_PERCPU_HASH or BPF_MAP_TYPE_PERCPU_ARRAY for high-frequency tracking maps to prevent cross-core cache-line bouncing and global spinlock contention.
Engineers MUST ALWAYS use BPF_MAP_TYPE_LRU_PERCPU_HASH or BPF_MAP_TYPE_PERCPU_ARRAY for high-frequency tracking maps to prevent cross-core cache-line bouncing and global spinlock contention.
Engineers MUST ALWAYS implement lockless token bucket rate limiting using __sync_fetch_and_add or atomic compare-and-swap primitives over raw 64-bit integer state when updating shared flow counters.
Engineers MUST ALWAYS implement lockless token bucket rate limiting using __sync_fetch_and_add or atomic compare-and-swap primitives over raw 64-bit integer state when updating shared flow counters.
Engineers MUST NOT invoke bpf_map_update_elem from the XDP fast path with BPF_NOEXIST on standard BPF_MAP_TYPE_HASH when facing spoofed-IP volumetric attacks
Engineers MUST NOT invoke bpf_map_update_elem from the XDP fast path with BPF_NOEXIST on standard BPF_MAP_TYPE_HASH when facing spoofed-IP volumetric attacks; use LRU maps to avoid dynamic slab memory allocations.
Code MUST return XDP_DROP immediately at the earliest possible verification boundary (after minimal header parsing) when ingress packet metrics exceed configured token bucket capacities.
Code MUST return XDP_DROP immediately at the earliest possible verification boundary (after minimal header parsing) when ingress packet metrics exceed configured token bucket capacities.
Services MUST synchronize state from kernel to user space using BPF_MAP_LOOKUP_AND_DELETE_BATCH or ring buffers (BPF_MAP_TYPE_RINGBUF) rather than executing individual synchronous syscall lookups per flow.
Services MUST synchronize state from kernel to user space using BPF_MAP_LOOKUP_AND_DELETE_BATCH or ring buffers (BPF_MAP_TYPE_RINGBUF) rather than executing individual synchronous syscall lookups per flow.
Components NEVER execute unbounded packet-walking loops
Components NEVER execute unbounded packet-walking loops; loops must be bounded with #pragma unroll or verifier-bounded induction variables with static upper limits (<= 64).
Frequently Asked Technical Questions
Common questions developers face when configuring AI coding assistants for this stack:
Q:Why is eBPF XDP Line-Rate Rate-Limiting & Lockless Map Invariants critical for AI coding assistants?
Enforces lockless eBPF LRU/Per-CPU map synchronization and atomic token bucket rate-limiting at the XDP driver hook to preserve host kernel CPU headroom during volumetric L4 DDoS attacks. Prohibits global spinlocks, non-per-cpu allocations, and blocking user-space batch synchronization operations that induce softirq tail drops. 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 (Global BPF Hash Map Mutations Under Volumetric L4 Ingress Inducing Softirq Saturation and Driver Ring Buffer Drops) 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.