This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
devopscritical PriorityID: ebpf-xdp-hardware-offloaded-ddos-drop-standard

eBPF XDP Hardware-Offloaded DDoS Early-Drop Standard

Guarantees wire-speed packet filtering and unroutable packet mitigation directly inside the NIC driver (Native XDP) or SmartNIC silicon (Offloaded XDP) prior to socket buffer (sk_buff) allocation. Eliminates CPU cache invalidation and page allocation starvation under line-rate volumetric DDoS floods by enforcing strictly bounded pointer validation, memory-safe map access, and zero-allocation SYN/ACK validation.

Prohibited Anti-Pattern: Processing Ingress Packets via Generic SKB/tc Hook or Unchecked Pointer Arithmetic Causing CPU Core Exhaustion Under Volumetric Floods

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: eBPF XDP Hardware-Offloaded DDoS Early-Drop Standard - Guarantees wire-speed packet filtering and unroutable packet mitigation directly inside the NIC driver (Native XDP) or SmartNIC silicon (Offloaded XDP) prior to socket buffer (sk_buff) allocation. Eliminates CPU cache invalidation and page allocation starvation under line-rate volumetric DDoS floods by enforcing strictly bounded pointer validation, memory-safe map access, and zero-allocation SYN/ACK validation.
globs: src/bpf/**/*.bpf.c, src/bpf/**/*.h, bpf/**/*.c, kernel/**/*.c
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/ebpf-xdp-hardware-offloaded-ddos-drop-standard"
---

# eBPF XDP Hardware-Offloaded DDoS Early-Drop Standard

> **Severity**: CRITICAL | **Category**: devops
> **Anti-Pattern Warning**: Processing Ingress Packets via Generic SKB/tc Hook or Unchecked Pointer Arithmetic Causing CPU Core Exhaustion Under Volumetric Floods

## System Constraints
You are a Principal Systems Engineer and Kernel Security Architect enforcing the eBPF XDP Hardware-Offloaded DDoS Early-Drop Standard. Mandate zero sk_buff allocations for illegitimate traffic, strict verifier-friendly pointer boundary checks, direct packet access without dynamic memory allocation, and compliance with hardware-offloadable BPF instruction subsets.

## Strict Guidelines
- Engineers MUST ALWAYS enforce strict verifier boundary checks (data + offset > data_end) before dereferencing any byte of Ethernet, IP, or TCP/UDP headers.
- Engineers MUST NOT rely on standard generic XDP (skb-mode) in high-throughput production paths; attach modes MUST target native driver (XDP_FLAGS_DRV_MODE) or SmartNIC hardware offload (XDP_FLAGS_HW_MODE).
- Code MUST strictly avoid unsupported helper functions, tail-calls exceeding hardware limits, or packet resizing when targeting SmartNIC XDP hardware offload.
- Programs MUST drop unroutable, malformed, or blacklisted packets immediately returning XDP_DROP at wire-speed without pushing metrics through BPF perf rings for every single packet.
- Engineers MUST use BPF_MAP_TYPE_PERCPU_ARRAY or BPF_MAP_TYPE_LRU_HASH for rate counters to eliminate cross-core lock contention and cache-line bouncing during multi-gigabit ingress floods.
- Components NEVER parse layer 4 payloads before verifying that IP fragment offsets are zero and header lengths fall within total frame boundaries.

## Bad vs Good Implementations
### XDP Packet Parsing and Early-Drop Invariant

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Fails verifier bounds checks on data_end before dereferencing eth, ip, and tcp headers, which prevents eBPF loading or causes memory access violations. Calling tracing helpers (bpf_trace_printk) on every dropped packet introduces severe CPU stalls and ring-buffer lock exhaustion, completely defeating wire-speed mitigation.
```c
#include <linux/bpf.h>
#include <bpf/bpf_helpers.h>
#include <linux/if_ether.h>
#include <linux/ip.h>
#include <linux/tcp.h>

SEC("xdp")
int ddos_filter(struct xdp_md *ctx) {
    void *data = (void *)(long)ctx->data;
    void *data_end = (void *)(long)ctx->data_end;
    
    // ANTI-PATTERN: Direct dereference without verifier safety guards
    struct ethhdr *eth = data;
    struct iphdr *ip = (void *)(eth + 1);
    struct tcphdr *tcp = (void *)(ip + 1);
    
    // Allocating dynamic perf buffer per-drop exhausts kernel memory at 40Gbps+
    if (tcp->syn && !tcp->ack) {
        bpf_trace_printk("SYN flood detected from IP: %x\n", ip->saddr);
        return XDP_DROP;
    }
    
    return XDP_PASS;
}
```

#### Production Standard (Correct)
> **Standard**: Implements rigorous pointer arithmetic validation against data_end for every header layer before access, satisfies verifier safety proofs, uses hardware/driver-compatible arithmetic, and aggregates statistics using a contention-free per-CPU map instead of expensive trace-logging.
```c
#include <linux/bpf.h>
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_endian.h>
#include <linux/if_ether.h>
#include <linux/ip.h>
#include <linux/tcp.h>

struct {
    __uint(type, BPF_MAP_TYPE_PERCPU_ARRAY);
    __uint(max_entries, 1);
    __type(key, __u32);
    __type(value, __u64);
} drop_counter SEC(".maps");

SEC("xdp")
int ddos_filter(struct xdp_md *ctx) {
    void *data = (void *)(long)ctx->data;
    void *data_end = (void *)(long)ctx->data_end;

    struct ethhdr *eth = data;
    if ((void *)(eth + 1) > data_end)
        return XDP_DROP;

    if (eth->h_proto != __bpf_constant_htons(ETH_P_IP))
        return XDP_PASS;

    struct iphdr *ip = (void *)(eth + 1);
    if ((void *)(ip + 1) > data_end)
        return XDP_DROP;

    if (ip->protocol == IPPROTO_TCP) {
        struct tcphdr *tcp = (void *)((__u8 *)ip + (ip->ihl * 4));
        if ((void *)(tcp + 1) > data_end)
            return XDP_DROP;

        // Drop SYN floods without ACK at wire speed prior to SKB allocation
        if (tcp->syn && !tcp->ack) {
            __u32 key = 0;
            __u64 *count = bpf_map_lookup_elem(&drop_counter, &key);
            if (count)
                *count += 1;
            return XDP_DROP;
        }
    }

    return XDP_PASS;
}

char _license[] SEC("license") = "GPL";
```

Recommended MCP Servers (mcp-serverlist.com)

Equip agent with system tools to verify code for this stack.

Recommended Agent Skills (askills.dev)

Ready-to-use executable skill functions tailored to this stack.

Architectural Specification & Invariant Rationale

Architectural Invariant Design: eBPF XDP Hardware-Offloaded DDoS Early-Drop Standard

eBPF XDP Hardware-Offloaded DDoS Early-Drop Standard defines an industrial-grade behavioral standard for devops engineering. Guarantees wire-speed packet filtering and unroutable packet mitigation directly inside the NIC driver (Native XDP) or SmartNIC silicon (Offloaded XDP) prior to socket buffer (sk_buff) allocation. Eliminates CPU cache invalidation and page allocation starvation under line-rate volumetric DDoS floods by enforcing strictly bounded pointer validation, memory-safe map access, and zero-allocation SYN/ACK validation. Modern software architectures require strict adherence to deterministic patterns to guarantee high availability, maintainability, and zero security vulnerabilities.

Framework Paradigm Shift & Drift MechanicsLLMs are trained on millions of open-source repositories containing outdated code, legacy idioms, and unpatched antipatterns. When coding assistants generate implementations for this stack, they default to common statistical tokens: Processing Ingress Packets via Generic SKB/tc Hook or Unchecked Pointer Arithmetic Causing CPU Core Exhaustion Under Volumetric Floods Without an explicit system instruction file, developers spend hours debugging silent failures.
Failure Modes & Production Blast Radius

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 ModeAI Symptom (The Anti-Pattern)SeverityProduction Impact & Remedy
AI Hallucination & Deprecation DriftProcessing Ingress Packets via Generic SKB/tc Hook or Unchecked Pointer Arithmetic Causing CPU Core Exhaustion Under Volumetric FloodsCritical
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 InconsistencyAI 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.
Architectural Directives in Detail

Step-by-Step Production Directives

Each rule constraint below is injected into the AI agent's system prompt to establish deterministic boundaries:

1

Engineers MUST ALWAYS enforce strict verifier boundary checks (data + offset > data_end) before dereferencing any byte of Ethernet, IP, or TCP/UDP headers.

Engineers MUST ALWAYS enforce strict verifier boundary checks (data + offset > data_end) before dereferencing any byte of Ethernet, IP, or TCP/UDP headers.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
2

Engineers MUST NOT rely on standard generic XDP (skb-mode) in high-throughput production paths

Engineers MUST NOT rely on standard generic XDP (skb-mode) in high-throughput production paths; attach modes MUST target native driver (XDP_FLAGS_DRV_MODE) or SmartNIC hardware offload (XDP_FLAGS_HW_MODE).

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
3

Code MUST strictly avoid unsupported helper functions, tail-calls exceeding hardware limits, or packet resizing when targeting SmartNIC XDP hardware offload.

Code MUST strictly avoid unsupported helper functions, tail-calls exceeding hardware limits, or packet resizing when targeting SmartNIC XDP hardware offload.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
4

Programs MUST drop unroutable, malformed, or blacklisted packets immediately returning XDP_DROP at wire-speed without pushing metrics through BPF perf rings for every single packet.

Programs MUST drop unroutable, malformed, or blacklisted packets immediately returning XDP_DROP at wire-speed without pushing metrics through BPF perf rings for every single packet.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
5

Engineers MUST use BPF_MAP_TYPE_PERCPU_ARRAY or BPF_MAP_TYPE_LRU_HASH for rate counters to eliminate cross-core lock contention and cache-line bouncing during multi-gigabit ingress floods.

Engineers MUST use BPF_MAP_TYPE_PERCPU_ARRAY or BPF_MAP_TYPE_LRU_HASH for rate counters to eliminate cross-core lock contention and cache-line bouncing during multi-gigabit ingress floods.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
6

Components NEVER parse layer 4 payloads before verifying that IP fragment offsets are zero and header lengths fall within total frame boundaries.

Components NEVER parse layer 4 payloads before verifying that IP fragment offsets are zero and header lengths fall within total frame boundaries.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
Technical Questions & Answers

Frequently Asked Technical Questions

Common questions developers face when configuring AI coding assistants for this stack:

Q:Why is eBPF XDP Hardware-Offloaded DDoS Early-Drop Standard critical for AI coding assistants?

Guarantees wire-speed packet filtering and unroutable packet mitigation directly inside the NIC driver (Native XDP) or SmartNIC silicon (Offloaded XDP) prior to socket buffer (sk_buff) allocation. Eliminates CPU cache invalidation and page allocation starvation under line-rate volumetric DDoS floods by enforcing strictly bounded pointer validation, memory-safe map access, and zero-allocation SYN/ACK validation. 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 (Processing Ingress Packets via Generic SKB/tc Hook or Unchecked Pointer Arithmetic Causing CPU Core Exhaustion Under Volumetric Floods) 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.

Open Specification · CC BY 4.0·Free for Personal, Team & Commercial In-Repo Use

Citation & Open Source Attribution Guidelines

This specification is licensed under Creative Commons Attribution 4.0 International (CC BY 4.0). You are completely free to adapt and share this rule in your workspace. If citing, including in public AI benchmark datasets, or redistributing, attribution to AgentRules.org is required.

1 Rule in Stack

eBPF