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

eBPF XDP Hardware-Offloaded Line-Rate Drop Standard

Enforces pre-stack packet processing at the physical NIC driver (XDP_DRV) and hardware-offloaded (XDP_OFFLOAD) tiers to neutralize volumetric L4 amplification vectors at true wire speed. Precludes Linux network stack socket buffer (sk_buff) allocation overhead by mandating strict packet pointer bounds verifications, lockless map evaluations, and early XDP_DROP verdicts.

Prohibited Anti-Pattern: Deferring volumetric DDoS filtering to socket-layer firewalls or userspace daemons after kernel sk_buff allocation.

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: eBPF XDP Hardware-Offloaded Line-Rate Drop Standard - Enforces pre-stack packet processing at the physical NIC driver (XDP_DRV) and hardware-offloaded (XDP_OFFLOAD) tiers to neutralize volumetric L4 amplification vectors at true wire speed. Precludes Linux network stack socket buffer (sk_buff) allocation overhead by mandating strict packet pointer bounds verifications, lockless map evaluations, and early XDP_DROP verdicts.
globs: bpf/**/*.c, bpf/**/*.h, src/bpf/**/*.c, pkg/ebpf/**/*.go, deploy/xdp/**/*.yaml
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/ebpf-xdp-hardware-offloaded-line-rate-drop-standard"
---

# eBPF XDP Hardware-Offloaded Line-Rate Drop Standard

> **Severity**: CRITICAL | **Category**: devops
> **Anti-Pattern Warning**: Deferring volumetric DDoS filtering to socket-layer firewalls or userspace daemons after kernel sk_buff allocation.

## System Constraints
You are a Principal Infrastructure & Kernel Architect enforcing the eBPF XDP Hardware-Offloaded Line-Rate Drop Standard. volumetric L4 reflection attacks (e.g., DNS, NTP, CLDAP amplification) must be dropped before the kernel allocates an sk_buff descriptor. Ensure every XDP program conforms to the strict kernel verifier bounds check guarantees, avoids non-offloadable kernel helper invocations, leverages lock-free BPF maps (BPF_MAP_TYPE_PERCPU_ARRAY or BPF_MAP_TYPE_ARRAY), and returns XDP_DROP deterministically at line rate.

## Strict Guidelines
- Engineers MUST ALWAYS verify packet bounds before dereferencing any network protocol header (pointer + sizeof(header) <= data_end) to satisfy kernel verifier linear memory safety.
- Engineers MUST NOT utilize sk_buff-dependent features, unbounded loops, or lock-heavy structures (e.g., BPF_MAP_TYPE_HASH with dynamic bucket locks) inside line-rate packet filter paths.
- Programs targeted for XDP_OFFLOAD MUST avoid helper functions not supported by SmartNIC hardware execution units (e.g., bpf_trace_printk, bpf_ringbuf_output).
- Code MUST re-validate data_end boundaries after any packet manipulation or encapsulation stripping prior to subsequent field reads.
- Loaders MUST prioritize loading XDP programs in native driver mode (XDP_DRV) or hardware offload mode (XDP_OFFLOAD), falling back to generic mode (XDP_SKB) only in virtualized testing environments with explicit warnings.
- Drop metrics MUST be recorded using lockless per-CPU arrays or hardware counters to eliminate cache-line contention across multi-queue NIC architectures.

## Bad vs Good Implementations
### Kernel-Level XDP Vector Filter with Safe Bounds Check and Line-Rate Drop

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Accessing packet pointers without explicit boundary checks against ctx->data_end violates kernel verifier safety rules and causes verification failure. Returning XDP_PASS forces Linux kernel memory allocation (sk_buff) and socket queue scheduling for amplification traffic, exhausting host CPU cycles and defeating mitigation.
```c
#include <linux/bpf.h>
#include <linux/if_ether.h>
#include <linux/ip.h>
#include <linux/udp.h>
#include <bpf/bpf_helpers.h>

// ANTI-PATTERN: Incomplete bounds checks, dangerous pointer arithmetic,
// and attempting userspace delivery or allocation for dropped attack traffic.
SEC("xdp")
int bad_xdp_filter(struct xdp_md *ctx) {
    void *data = (void *)(long)ctx->data;
    void *data_end = (void *)(long)ctx->data_end;
    
    struct ethhdr *eth = data;
    // VULNERABILITY: Missing safety bound validation against data_end!
    // Kernel verifier will reject or crash on unchecked direct access.
    if (eth->h_proto == __constant_htons(ETH_P_IP)) {
        struct iphdr *ip = data + sizeof(*eth);
        if (ip->protocol == IPPROTO_UDP) {
            struct udphdr *udp = (void *)ip + (ip->ihl * 4);
            // Insecure lookup & passing packet up to network stack anyway
            if (udp->source == __constant_htons(53) || udp->source == __constant_htons(123)) {
                // BPF_PASS allocates sk_buff, inducing CPU starvation during a 40Gbps+ flood
                return XDP_PASS;
            }
        }
    }
    return XDP_PASS;
}
```

#### Production Standard (Correct)
> **Standard**: Enforces strict monotonic boundary checks before dereferencing each protocol layer (Ethernet, IPv4, UDP). Confirmed reflection attacks are dropped immediately via XDP_DROP at the NIC driver/offload ring buffer, completely bypassing sk_buff memory allocation and tracking telemetry via per-CPU arrays to avoid memory lock contention.
```c
#include <linux/bpf.h>
#include <linux/if_ether.h>
#include <linux/ip.h>
#include <linux/udp.h>
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_endian.h>

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

SEC("xdp")
int xdp_drop_reflection_vector(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_PASS;

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

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

    if (ip->protocol != IPPROTO_UDP)
        return XDP_PASS;

    __u32 ip_hdr_len = ip->ihl * 4;
    if (ip_hdr_len < sizeof(struct iphdr))
        return XDP_DROP;

    struct udphdr *udp = (void *)ip + ip_hdr_len;
    if ((void *)(udp + 1) > data_end)
        return XDP_PASS;

    // Match well-known reflection source ports: DNS (53), NTP (123), CLDAP (389)
    __u16 src_port = bpf_ntohs(udp->source);
    if (src_port == 53 || src_port == 123 || src_port == 389) {
        __u32 key = 0;
        __u64 *count = bpf_map_lookup_elem(&drop_counters, &key);
        if (count)
            *count += 1;
        // Zero-copy immediate drop at NIC driver tier before sk_buff allocation
        return XDP_DROP;
    }

    return XDP_PASS;
}

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

Architectural Specification & Invariant Rationale

Architectural Invariant Design: eBPF XDP Hardware-Offloaded Line-Rate Drop Standard

eBPF XDP Hardware-Offloaded Line-Rate Drop Standard defines an industrial-grade behavioral standard for devops engineering. Enforces pre-stack packet processing at the physical NIC driver (XDP_DRV) and hardware-offloaded (XDP_OFFLOAD) tiers to neutralize volumetric L4 amplification vectors at true wire speed. Precludes Linux network stack socket buffer (sk_buff) allocation overhead by mandating strict packet pointer bounds verifications, lockless map evaluations, and early XDP_DROP verdicts. 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: Deferring volumetric DDoS filtering to socket-layer firewalls or userspace daemons after kernel sk_buff allocation. 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 DriftDeferring volumetric DDoS filtering to socket-layer firewalls or userspace daemons after kernel sk_buff allocation.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 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 verify packet bounds before dereferencing any network protocol header (pointer + sizeof(header) <= data_end) to satisfy kernel verifier linear memory safety.

Engineers MUST ALWAYS verify packet bounds before dereferencing any network protocol header (pointer + sizeof(header) <= data_end) to satisfy kernel verifier linear memory safety.

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 utilize sk_buff-dependent features, unbounded loops, or lock-heavy structures (e.g., BPF_MAP_TYPE_HASH with dynamic bucket locks) inside line-rate packet filter paths.

Engineers MUST NOT utilize sk_buff-dependent features, unbounded loops, or lock-heavy structures (e.g., BPF_MAP_TYPE_HASH with dynamic bucket locks) inside line-rate packet filter paths.

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

Programs targeted for XDP_OFFLOAD MUST avoid helper functions not supported by SmartNIC hardware execution units (e.g., bpf_trace_printk, bpf_ringbuf_output).

Programs targeted for XDP_OFFLOAD MUST avoid helper functions not supported by SmartNIC hardware execution units (e.g., bpf_trace_printk, bpf_ringbuf_output).

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

Code MUST re-validate data_end boundaries after any packet manipulation or encapsulation stripping prior to subsequent field reads.

Code MUST re-validate data_end boundaries after any packet manipulation or encapsulation stripping prior to subsequent field reads.

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

Loaders MUST prioritize loading XDP programs in native driver mode (XDP_DRV) or hardware offload mode (XDP_OFFLOAD), falling back to generic mode (XDP_SKB) only in virtualized testing environments with explicit warnings.

Loaders MUST prioritize loading XDP programs in native driver mode (XDP_DRV) or hardware offload mode (XDP_OFFLOAD), falling back to generic mode (XDP_SKB) only in virtualized testing environments with explicit warnings.

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

Drop metrics MUST be recorded using lockless per-CPU arrays or hardware counters to eliminate cache-line contention across multi-queue NIC architectures.

Drop metrics MUST be recorded using lockless per-CPU arrays or hardware counters to eliminate cache-line contention across multi-queue NIC architectures.

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 Line-Rate Drop Standard critical for AI coding assistants?

Enforces pre-stack packet processing at the physical NIC driver (XDP_DRV) and hardware-offloaded (XDP_OFFLOAD) tiers to neutralize volumetric L4 amplification vectors at true wire speed. Precludes Linux network stack socket buffer (sk_buff) allocation overhead by mandating strict packet pointer bounds verifications, lockless map evaluations, and early XDP_DROP verdicts. 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 (Deferring volumetric DDoS filtering to socket-layer firewalls or userspace daemons after kernel sk_buff allocation.) 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