This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
devopscritical PriorityID: ebpf-tc-ringbuf-drop-safe-telemetry

eBPF TC Ring-Buffer Non-Blocking Drop-Safe Telemetry Pipeline Standard

Mandates zero-copy, non-blocking telemetry event streaming using kernel ring buffers (BPF_MAP_TYPE_RINGBUF) within Traffic Control (TC) hooks. Guarantees that packet ingestion and forwarding remain at line rate during telemetry buffer saturation by strictly isolating telemetry drops from network datapath verdicts.

Prohibited Anti-Pattern: Stalling or dropping network packets and leaking ring buffer allocations during telemetry ring buffer exhaustion

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: eBPF TC Ring-Buffer Non-Blocking Drop-Safe Telemetry Pipeline Standard - Mandates zero-copy, non-blocking telemetry event streaming using kernel ring buffers (BPF_MAP_TYPE_RINGBUF) within Traffic Control (TC) hooks. Guarantees that packet ingestion and forwarding remain at line rate during telemetry buffer saturation by strictly isolating telemetry drops from network datapath verdicts.
globs: **/*.bpf.c, **/*.bpf.h, **/*.c, pkg/ebpf/**/*.go, src/bpf/**/*.rs
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/ebpf-tc-ringbuf-drop-safe-telemetry"
---

# eBPF TC Ring-Buffer Non-Blocking Drop-Safe Telemetry Pipeline Standard

> **Severity**: CRITICAL | **Category**: devops
> **Anti-Pattern Warning**: Stalling or dropping network packets and leaking ring buffer allocations during telemetry ring buffer exhaustion

## System Constraints
You are a Principal Linux Kernel and Datapath Engineer enforcing strict architectural and performance guardrails for eBPF Traffic Control (TC) programs. All network datapath telemetry pipelines must be non-blocking, zero-copy, and completely drop-safe under microburst loads. Network datapath verdicts (e.g., TC_ACT_OK) must never be altered or degraded due to telemetry export backpressure or allocation failures.

## Strict Guidelines
- Engineers MUST ALWAYS check the return pointer of `bpf_ringbuf_reserve()` against NULL and branch gracefully without impeding the packet datapath.
- Engineers MUST NEVER return a restrictive TC verdict (e.g., `TC_ACT_SHOT`) solely because telemetry reservation or submission failed.
- Services MUST increment a lockless per-CPU counter (`BPF_MAP_TYPE_PERCPU_ARRAY`) when a telemetry drop occurs to maintain observability of dropped instrumentation events.
- Components MUST ALWAYS call `bpf_ringbuf_submit()` or `bpf_ringbuf_discard()` on all paths subsequent to a successful `bpf_ringbuf_reserve()` prior to exiting the TC hook.
- Engineers MUST configure ring buffer capacities as page-aligned powers of two (`2^N * PAGE_SIZE`) sizing them within bounded memory budgets to prevent host OOM conditions under ingress bursts.
- Code SHOULD prefer `bpf_ringbuf_reserve()` followed by direct field assignment and `bpf_ringbuf_submit()` over `bpf_ringbuf_output()` to eliminate redundant eBPF stack memory copying.

## Bad vs Good Implementations
### Handling Ring Buffer Saturation in TC Classifier Hook

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Failing to verify ring buffer availability or returning `TC_ACT_SHOT` on telemetry reservation failure causes datapath packet loss during monitoring buffer exhaustion. Allocating disproportionately large ring buffers wastes critical non-swappable vmalloc kernel memory.
```c
#include <linux/bpf.h>
#include <linux/pkt_cls.h>
#include <bpf/bpf_helpers.h>

struct event {
    __u32 src_ip;
    __u32 dst_ip;
    __u16 len;
};

struct {
    __uint(type, BPF_MAP_TYPE_RINGBUF);
    __uint(max_entries, 1 << 24); // Over-allocated memory
} telemetry_rb SEC(".maps");

SEC("tc")
int tc_telemetry_bad(struct __sk_buff *skb) {
    struct event *evt;

    // ANTI-PATTERN: Blindly reserving without null checks or failing the packet
    evt = bpf_ringbuf_reserve(&telemetry_rb, sizeof(*evt), 0);
    if (!evt) {
        // FATAL: Dropping datapath packet because telemetry buffer is saturated
        return TC_ACT_SHOT;
    }

    evt->src_ip = skb->remote_ip4;
    evt->dst_ip = skb->local_ip4;
    evt->len = skb->len;

    bpf_ringbuf_submit(evt, 0);
    return TC_ACT_OK;
}
```

#### Production Standard (Correct)
> **Standard**: The good pattern enforces non-blocking behavior: if `bpf_ringbuf_reserve` returns NULL under load, the event drop is recorded via a lockless per-CPU map, and the original packet continues through the TC datapath unharmed with `TC_ACT_OK`.
```c
#include <linux/bpf.h>
#include <linux/pkt_cls.h>
#include <bpf/bpf_helpers.h>

struct event {
    __u32 src_ip;
    __u32 dst_ip;
    __u16 len;
};

struct {
    __uint(type, BPF_MAP_TYPE_RINGBUF);
    __uint(max_entries, 1 << 20); // 1MB bounded budget
} telemetry_rb SEC(".maps");

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

SEC("tc")
int tc_telemetry_good(struct __sk_buff *skb) {
    struct event *evt;

    evt = bpf_ringbuf_reserve(&telemetry_rb, sizeof(*evt), 0);
    if (!evt) {
        // PRODUCTION GUARDRAIL: Account for telemetry drop without stalling packet flow
        __u32 key = 0;
        __u64 *drops = bpf_map_lookup_elem(&drop_counter, &key);
        if (drops) {
            (*drops)++;
        }
        // Datapath must proceed unaffected
        return TC_ACT_OK;
    }

    evt->src_ip = skb->remote_ip4;
    evt->dst_ip = skb->local_ip4;
    evt->len = skb->len;

    bpf_ringbuf_submit(evt, 0);
    return TC_ACT_OK;
}
```

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 TC Ring-Buffer Non-Blocking Drop-Safe Telemetry Pipeline Standard

eBPF TC Ring-Buffer Non-Blocking Drop-Safe Telemetry Pipeline Standard defines an industrial-grade behavioral standard for devops engineering. Mandates zero-copy, non-blocking telemetry event streaming using kernel ring buffers (BPF_MAP_TYPE_RINGBUF) within Traffic Control (TC) hooks. Guarantees that packet ingestion and forwarding remain at line rate during telemetry buffer saturation by strictly isolating telemetry drops from network datapath 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: Stalling or dropping network packets and leaking ring buffer allocations during telemetry ring buffer exhaustion 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 DriftStalling or dropping network packets and leaking ring buffer allocations during telemetry ring buffer exhaustionCritical
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 check the return pointer of `bpf_ringbuf_reserve()` against NULL and branch gracefully without impeding the packet datapath.

Engineers MUST ALWAYS check the return pointer of `bpf_ringbuf_reserve()` against NULL and branch gracefully without impeding the packet datapath.

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 NEVER return a restrictive TC verdict (e.g., `TC_ACT_SHOT`) solely because telemetry reservation or submission failed.

Engineers MUST NEVER return a restrictive TC verdict (e.g., `TC_ACT_SHOT`) solely because telemetry reservation or submission failed.

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

Services MUST increment a lockless per-CPU counter (`BPF_MAP_TYPE_PERCPU_ARRAY`) when a telemetry drop occurs to maintain observability of dropped instrumentation events.

Services MUST increment a lockless per-CPU counter (`BPF_MAP_TYPE_PERCPU_ARRAY`) when a telemetry drop occurs to maintain observability of dropped instrumentation events.

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

Components MUST ALWAYS call `bpf_ringbuf_submit()` or `bpf_ringbuf_discard()` on all paths subsequent to a successful `bpf_ringbuf_reserve()` prior to exiting the TC hook.

Components MUST ALWAYS call `bpf_ringbuf_submit()` or `bpf_ringbuf_discard()` on all paths subsequent to a successful `bpf_ringbuf_reserve()` prior to exiting the TC hook.

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 configure ring buffer capacities as page-aligned powers of two (`2^N * PAGE_SIZE`) sizing them within bounded memory budgets to prevent host OOM conditions under ingress bursts.

Engineers MUST configure ring buffer capacities as page-aligned powers of two (`2^N * PAGE_SIZE`) sizing them within bounded memory budgets to prevent host OOM conditions under ingress bursts.

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

Code SHOULD prefer `bpf_ringbuf_reserve()` followed by direct field assignment and `bpf_ringbuf_submit()` over `bpf_ringbuf_output()` to eliminate redundant eBPF stack memory copying.

Code SHOULD prefer `bpf_ringbuf_reserve()` followed by direct field assignment and `bpf_ringbuf_submit()` over `bpf_ringbuf_output()` to eliminate redundant eBPF stack memory copying.

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 TC Ring-Buffer Non-Blocking Drop-Safe Telemetry Pipeline Standard critical for AI coding assistants?

Mandates zero-copy, non-blocking telemetry event streaming using kernel ring buffers (BPF_MAP_TYPE_RINGBUF) within Traffic Control (TC) hooks. Guarantees that packet ingestion and forwarding remain at line rate during telemetry buffer saturation by strictly isolating telemetry drops from network datapath 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 (Stalling or dropping network packets and leaking ring buffer allocations during telemetry ring buffer exhaustion) 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