This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
devopscritical PriorityID: ebpf-ringbuf-backpressure-loss-detection-standard

eBPF TCX/XDP Ring-Buffer Backpressure & Loss-Detection Standard

Regulates kernel-to-userspace event submission through adaptive pacing, reserve-commit paradigms, and sequence tracking to guarantee zero unmonitored network security drops during high-packet-rate bursts. Mandates monotonic loss counters and fallback dynamic sampling before buffer saturation compromises observability.

Prohibited Anti-Pattern: Blind bpf_ringbuf_output drops with missing per-CPU monotonic drop-counter accounting

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: eBPF TCX/XDP Ring-Buffer Backpressure & Loss-Detection Standard - Regulates kernel-to-userspace event submission through adaptive pacing, reserve-commit paradigms, and sequence tracking to guarantee zero unmonitored network security drops during high-packet-rate bursts. Mandates monotonic loss counters and fallback dynamic sampling before buffer saturation compromises observability.
globs: src/**/*.{c,h,rs,ts,go}, bpf/**/*.{c,h}, kernel/**/*.{c,h}, crates/ebpf-*/**/*.rs
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/ebpf-ringbuf-backpressure-loss-detection-standard"
---

# eBPF TCX/XDP Ring-Buffer Backpressure & Loss-Detection Standard

> **Severity**: CRITICAL | **Category**: devops
> **Anti-Pattern Warning**: Blind bpf_ringbuf_output drops with missing per-CPU monotonic drop-counter accounting

## System Constraints
You are a Principal Systems Engineer and Kernel Security Architect enforcing strict eBPF TCX/XDP Ring-Buffer Backpressure & Loss-Detection invariants. When designing eBPF programs and userspace ingestion pipelines, you must eliminate silent event drops, ensure memory zero-copy via reserve/submit lifecycles, enforce monotonic sequence auditing, and provide kernel-level adaptive throttling when ring buffers approach saturation.

## Strict Guidelines
- Engineers MUST ALWAYS use `bpf_ringbuf_reserve` and `bpf_ringbuf_submit` instead of `bpf_ringbuf_output` to avoid stack copies and verify space availability before data processing.
- Engineers MUST ALWAYS increment a dedicated per-CPU drop counter (BPF_MAP_TYPE_PERCPU_ARRAY) whenever `bpf_ringbuf_reserve` fails, guaranteeing unmonitored drops never occur.
- Programs MUST embed a monotonically increasing 64-bit sequence ID into every emitted packet header to enable userspace loss-gap detection.
- Kernel pipelines MUST implement dynamic sampling or backpressure pacing when ring-buffer usage crosses an 80% watermark to maintain auditability during microbursts.
- Userspace consumers MUST NEVER use blocking epoll indefinitely without periodically polling or synchronizing with per-CPU drop metric maps.
- Engineers MUST NOT discard ring-buffer reserve errors silently without setting an alertable telemetry flag in telemetry maps.

## Bad vs Good Implementations
### Ring-Buffer Reservation with Drop Auditing and Monotonic Sequence Pacing

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Using bpf_ringbuf_output copies data to the kernel stack first, risking stack overflow. Crucially, the return code is ignored: if the buffer is saturated, the event drops silently without updating drop counters or sequence IDs.
```c
#include <vmlinux.h>
#include <bpf/bpf_helpers.h>

struct event {
    __u32 sip;
    __u32 dip;
};

struct {
    __uint(type, BPF_MAP_TYPE_RINGBUF);
    __uint(max_entries, 1 << 24);
} events SEC(".maps");

SEC("tcx/ingress")
int tcx_bad_handler(struct __sk_buff *skb) {
    struct event evt = {};
    evt.sip = skb->remote_ip4;
    evt.dip = skb->local_ip4;

    /* Anti-pattern: Stack copy with bpf_ringbuf_output, drops are silent */
    bpf_ringbuf_output(&events, &evt, sizeof(evt), 0);
    return 0;
}
```

#### Production Standard (Correct)
> **Standard**: Implements zero-copy memory reservation via bpf_ringbuf_reserve, records a per-CPU monotonic sequence ID to track ordering, and atomically increments a loss counter upon reservation failure to guarantee zero silent drops.
```c
#include <vmlinux.h>
#include <bpf/bpf_helpers.h>

struct event {
    __u64 seq_id;
    __u32 sip;
    __u32 dip;
};

struct {
    __uint(type, BPF_MAP_TYPE_RINGBUF);
    __uint(max_entries, 1 << 24);
} events SEC(".maps");

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

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

SEC("tcx/ingress")
int tcx_good_handler(struct __sk_buff *skb) {
    __u32 idx = 0;
    __u64 *seq = bpf_map_lookup_elem(&seq_counters, &idx);
    if (!seq) return 0;
    __u64 current_seq = ++(*seq);

    struct event *evt = bpf_ringbuf_reserve(&events, sizeof(*evt), 0);
    if (!evt) {
        __u64 *drops = bpf_map_lookup_elem(&drop_counters, &idx);
        if (drops) {
            __sync_fetch_and_add(drops, 1);
        }
        return 0; /* Loss explicitly audited */
    }

    evt->seq_id = current_seq;
    evt->sip = skb->remote_ip4;
    evt->dip = skb->local_ip4;
    bpf_ringbuf_submit(evt, 0);
    return 0;
}
```

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 TCX/XDP Ring-Buffer Backpressure & Loss-Detection Standard

eBPF TCX/XDP Ring-Buffer Backpressure & Loss-Detection Standard defines an industrial-grade behavioral standard for devops engineering. Regulates kernel-to-userspace event submission through adaptive pacing, reserve-commit paradigms, and sequence tracking to guarantee zero unmonitored network security drops during high-packet-rate bursts. Mandates monotonic loss counters and fallback dynamic sampling before buffer saturation compromises observability. 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: Blind bpf_ringbuf_output drops with missing per-CPU monotonic drop-counter accounting 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 DriftBlind bpf_ringbuf_output drops with missing per-CPU monotonic drop-counter accountingCritical
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 use `bpf_ringbuf_reserve` and `bpf_ringbuf_submit` instead of `bpf_ringbuf_output` to avoid stack copies and verify space availability before data processing.

Engineers MUST ALWAYS use `bpf_ringbuf_reserve` and `bpf_ringbuf_submit` instead of `bpf_ringbuf_output` to avoid stack copies and verify space availability before data processing.

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 ALWAYS increment a dedicated per-CPU drop counter (BPF_MAP_TYPE_PERCPU_ARRAY) whenever `bpf_ringbuf_reserve` fails, guaranteeing unmonitored drops never occur.

Engineers MUST ALWAYS increment a dedicated per-CPU drop counter (BPF_MAP_TYPE_PERCPU_ARRAY) whenever `bpf_ringbuf_reserve` fails, guaranteeing unmonitored drops never occur.

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 MUST embed a monotonically increasing 64-bit sequence ID into every emitted packet header to enable userspace loss-gap detection.

Programs MUST embed a monotonically increasing 64-bit sequence ID into every emitted packet header to enable userspace loss-gap detection.

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

Kernel pipelines MUST implement dynamic sampling or backpressure pacing when ring-buffer usage crosses an 80% watermark to maintain auditability during microbursts.

Kernel pipelines MUST implement dynamic sampling or backpressure pacing when ring-buffer usage crosses an 80% watermark to maintain auditability during microbursts.

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

Userspace consumers MUST NEVER use blocking epoll indefinitely without periodically polling or synchronizing with per-CPU drop metric maps.

Userspace consumers MUST NEVER use blocking epoll indefinitely without periodically polling or synchronizing with per-CPU drop metric maps.

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

Engineers MUST NOT discard ring-buffer reserve errors silently without setting an alertable telemetry flag in telemetry maps.

Engineers MUST NOT discard ring-buffer reserve errors silently without setting an alertable telemetry flag in telemetry maps.

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 TCX/XDP Ring-Buffer Backpressure & Loss-Detection Standard critical for AI coding assistants?

Regulates kernel-to-userspace event submission through adaptive pacing, reserve-commit paradigms, and sequence tracking to guarantee zero unmonitored network security drops during high-packet-rate bursts. Mandates monotonic loss counters and fallback dynamic sampling before buffer saturation compromises observability. 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 (Blind bpf_ringbuf_output drops with missing per-CPU monotonic drop-counter accounting) 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