This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
devopscritical PriorityID: ebpf-tc-direct-host-routing-bypass-standard

eBPF TC Direct Host Routing & Conntrack Bypass Guardrail

Enforces eBPF direct host routing at the Traffic Control (tc) clsact hook to bypass the netfilter conntrack engine for east-west container traffic. Ensures encapsulation headers, socket translation metadata, and fib_lookup flags are strictly verified to maintain deterministic sub-millisecond p99 latency without dropping stateful packet context.

Prohibited Anti-Pattern: Routing Container East-West Traffic Through Netfilter Conntrack Stack and Default Veth Pair Queues

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: eBPF TC Direct Host Routing & Conntrack Bypass Guardrail - Enforces eBPF direct host routing at the Traffic Control (tc) clsact hook to bypass the netfilter conntrack engine for east-west container traffic. Ensures encapsulation headers, socket translation metadata, and fib_lookup flags are strictly verified to maintain deterministic sub-millisecond p99 latency without dropping stateful packet context.
globs: bpf/**/*.c, bpf/**/*.h, deploy/daemonset/**/*.yaml, pkg/datapath/**/*.go, config/cni/*.json
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/ebpf-tc-direct-host-routing-bypass-standard"
---

# eBPF TC Direct Host Routing & Conntrack Bypass Guardrail

> **Severity**: CRITICAL | **Category**: devops
> **Anti-Pattern Warning**: Routing Container East-West Traffic Through Netfilter Conntrack Stack and Default Veth Pair Queues

## System Constraints
You are a Principal Systems & Kernel Infrastructure Engineer enforcing the eBPF TC Direct Host Routing Bypass Standard. You must mandate that all east-west pod-to-pod network traffic leverages TC clsact BPF direct routing (`bpf_redirect_peer` / `bpf_redirect_neigh` and `bpf_fib_lookup`), completely circumventing standard netfilter connection tracking (`nf_conntrack`) bottlenecks and host veth backlog queue latency spikes.

## Strict Guidelines
- Engineers MUST ALWAYS attach eBPF programs to the `clsact` qdisc egress and ingress hooks on both container veth interfaces and physical host netdevices.
- Engineers MUST ALWAYS execute `bpf_fib_lookup()` with `BPF_FIB_LOOKUP_DIRECTNET` to perform direct routing decisions within the eBPF datapath prior to passing skb up the stack.
- Engineers MUST ALWAYS use `bpf_redirect_peer()` for container-to-host veth redirection to avoid queuing packets into the host kernel's per-CPU backlog queue via `netif_rx`.
- Engineers MUST NOT allow unencapsulated overlay or pod IP packets to enter standard netfilter chains (`PREROUTING`, `FORWARD`) unless explicit legacy L4/L7 inspection is declared.
- Programs MUST validate skb headroom via `bpf_skb_change_head()` and adjust network headers safely before initiating layer 2/3 redirects.
- Kernel configurations MUST verify that `net.ipv4.conf.all.forwarding=1` and `net.core.bpf_jit_enable=1` are asserted by CNI daemonset init containers.

## Bad vs Good Implementations
### TC BPF Direct Routing with FIB Lookup vs Kernel Stack Traversal

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Returning TC_ACT_OK defers packet routing to the host kernel's core IP stack, forcing east-west traffic through CPU-intensive netfilter connection tracking tables and host veth queues, degrading p99 latency under high packet rates.
```c
#include <linux/bpf.h>
#include <bpf/bpf_helpers.h>

SEC("tc/ingress")
int handle_ingress_slowpath(struct __sk_buff *skb) {
    // ANTI-PATTERN: Returning TC_ACT_OK hands the packet to the standard
    // host Linux networking stack, traversing nf_conntrack, iptables/nftables,
    // and injecting latency via netif_rx backlog queues for east-west traffic.
    return TC_ACT_OK;
}
```

#### Production Standard (Correct)
> **Standard**: Leverages `bpf_fib_lookup` and `bpf_redirect_peer` directly in the TC clsact hook, avoiding the host conntrack state machine and delivering deterministic sub-millisecond p99 packet transit directly between pod network namespaces.
```c
#include <linux/bpf.h>
#include <linux/pkt_cls.h>
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_endian.h>

struct {
    __uint(type, BPF_MAP_TYPE_DEVMAP_HASH);
    __uint(max_entries, 1024);
    __type(key, __u32);
    __type(value, __u32);
} node_port_map SEC(".maps");

SEC("tc/ingress")
int handle_ingress_fastpath(struct __sk_buff *skb) {
    struct bpf_fib_lookup fib_params = {};
    fib_params.family = 2; // AF_INET
    
    // Extract IP and populate lookup parameters from skb
    void *data = (void *)(long)skb->data;
    void *data_end = (void *)(long)skb->data_end;
    
    // Invariant: Direct routing bypass via FIB lookup
    int rc = bpf_fib_lookup(skb, &fib_params, sizeof(fib_params), BPF_FIB_LOOKUP_DIRECTNET);
    if (rc == BPF_FIB_LKUP_RET_SUCCESS) {
        // Redirect directly to destination network device peer interface
        return bpf_redirect_peer(fib_params.ifindex, 0);
    } else if (rc == BPF_FIB_LKUP_RET_NO_NEIGH) {
        return bpf_redirect_neigh(fib_params.ifindex, NULL, 0, 0);
    }
    
    // Fallback only when route resolution cannot be performed in-datapath
    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 Direct Host Routing & Conntrack Bypass Guardrail

eBPF TC Direct Host Routing & Conntrack Bypass Guardrail defines an industrial-grade behavioral standard for devops engineering. Enforces eBPF direct host routing at the Traffic Control (tc) clsact hook to bypass the netfilter conntrack engine for east-west container traffic. Ensures encapsulation headers, socket translation metadata, and fib_lookup flags are strictly verified to maintain deterministic sub-millisecond p99 latency without dropping stateful packet context. 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: Routing Container East-West Traffic Through Netfilter Conntrack Stack and Default Veth Pair Queues 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 DriftRouting Container East-West Traffic Through Netfilter Conntrack Stack and Default Veth Pair QueuesCritical
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 attach eBPF programs to the `clsact` qdisc egress and ingress hooks on both container veth interfaces and physical host netdevices.

Engineers MUST ALWAYS attach eBPF programs to the `clsact` qdisc egress and ingress hooks on both container veth interfaces and physical host netdevices.

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 execute `bpf_fib_lookup()` with `BPF_FIB_LOOKUP_DIRECTNET` to perform direct routing decisions within the eBPF datapath prior to passing skb up the stack.

Engineers MUST ALWAYS execute `bpf_fib_lookup()` with `BPF_FIB_LOOKUP_DIRECTNET` to perform direct routing decisions within the eBPF datapath prior to passing skb up the stack.

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

Engineers MUST ALWAYS use `bpf_redirect_peer()` for container-to-host veth redirection to avoid queuing packets into the host kernel's per-CPU backlog queue via `netif_rx`.

Engineers MUST ALWAYS use `bpf_redirect_peer()` for container-to-host veth redirection to avoid queuing packets into the host kernel's per-CPU backlog queue via `netif_rx`.

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

Engineers MUST NOT allow unencapsulated overlay or pod IP packets to enter standard netfilter chains (`PREROUTING`, `FORWARD`) unless explicit legacy L4/L7 inspection is declared.

Engineers MUST NOT allow unencapsulated overlay or pod IP packets to enter standard netfilter chains (`PREROUTING`, `FORWARD`) unless explicit legacy L4/L7 inspection is declared.

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

Programs MUST validate skb headroom via `bpf_skb_change_head()` and adjust network headers safely before initiating layer 2/3 redirects.

Programs MUST validate skb headroom via `bpf_skb_change_head()` and adjust network headers safely before initiating layer 2/3 redirects.

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

Kernel configurations MUST verify that `net.ipv4.conf.all.forwarding=1` and `net.core.bpf_jit_enable=1` are asserted by CNI daemonset init containers.

Kernel configurations MUST verify that `net.ipv4.conf.all.forwarding=1` and `net.core.bpf_jit_enable=1` are asserted by CNI daemonset init containers.

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 Direct Host Routing & Conntrack Bypass Guardrail critical for AI coding assistants?

Enforces eBPF direct host routing at the Traffic Control (tc) clsact hook to bypass the netfilter conntrack engine for east-west container traffic. Ensures encapsulation headers, socket translation metadata, and fib_lookup flags are strictly verified to maintain deterministic sub-millisecond p99 latency without dropping stateful packet context. 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 (Routing Container East-West Traffic Through Netfilter Conntrack Stack and Default Veth Pair Queues) 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