This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
devopscritical PriorityID: ebpf-tc-ingress-w3c-tracecontext-injection

Kernel-Level W3C TraceContext Ingress Injection via eBPF TC

Enforces deterministic W3C TraceContext propagation at the eBPF Traffic Control (TC) ingress hook prior to socket layer demuxing and userspace runtime consumption. Guarantees end-to-end distributed tracing across heterogeneous service mesh runtimes by eliminating userspace decoding blind spots, preserving BPF verifier packet-boundary invariants, and preventing payload corruption.

Prohibited Anti-Pattern: Userspace-Only Context Extraction Causing Observability Gaps and Corrupt Ingress Header Slices

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Kernel-Level W3C TraceContext Ingress Injection via eBPF TC - Enforces deterministic W3C TraceContext propagation at the eBPF Traffic Control (TC) ingress hook prior to socket layer demuxing and userspace runtime consumption. Guarantees end-to-end distributed tracing across heterogeneous service mesh runtimes by eliminating userspace decoding blind spots, preserving BPF verifier packet-boundary invariants, and preventing payload corruption.
globs: bpf/**/*.c, bpf/**/*.h, src/network/**/*.c, src/collector/**/*.go, src/agent/**/*.rs
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/ebpf-tc-ingress-w3c-tracecontext-injection"
---

# Kernel-Level W3C TraceContext Ingress Injection via eBPF TC

> **Severity**: CRITICAL | **Category**: devops
> **Anti-Pattern Warning**: Userspace-Only Context Extraction Causing Observability Gaps and Corrupt Ingress Header Slices

## System Constraints
You are a Principal Systems & Observability Engineer enforcing eBPF Traffic Control (TC) ingress W3C TraceContext injection. Mandate kernel-level trace preservation, strict BPF verifier boundary checks on packet mutation, accurate L4 checksum recalculation, and seamless fallback when headers exceed maximum transmission units.

## Strict Guidelines
- Engineers MUST ALWAYS reload and re-verify data and data_end pointers immediately after invoking bpf_skb_adjust_room to satisfy the BPF verifier's memory safety rules.
- Engineers MUST NOT overwrite existing valid W3C traceparent headers; injection MUST only occur when no traceparent carrier is present on the ingress stream or when wrapping raw transport streams.
- Code SHOULD utilize bpf_l4_csum_replace and bpf_l3_csum_replace to recompute transport and IP checksums dynamically after header adjustment, avoiding packet drops at the OS stack.
- Services MUST emit fallback telemetry over a BPF perf buffer or ring buffer whenever headroom expansion fails due to skb_is_nonlinear or MTU violations.
- Components NEVER assume fixed transport header offsets; engineers MUST parse IP and TCP option lengths dynamically before executing carrier injection.

## Bad vs Good Implementations
### Kernel TC Ingress W3C Injection with Dynamic Offset & Verifier Bounds

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Fails to re-evaluate data/data_end after altering skb headroom with bpf_skb_adjust_room, resulting in immediate BPF verifier rejection. Omits bounds checks, skips L3/L4 checksum recomputation, and assumes fixed header offsets.
```c
#include <linux/bpf.h>
#include <bpf/bpf_helpers.h>
#include <linux/pkt_cls.h>

SEC("tc")
int bad_tc_ingress_trace(struct __sk_buff *skb) {
    void *data = (void *)(long)skb->data;
    void *data_end = (void *)(long)skb->data_end;
    
    // Blind adjustment without verifier re-validation and checksum update
    bpf_skb_adjust_room(skb, 55, BPF_ADJ_ROOM_NET, 0);
    
    // CRITICAL BUG: data pointer is invalid after adjust_room, triggers verifier crash
    char *payload = (char *)data + 54;
    payload[0] = '0'; // Corrupts memory and dereferences unverified memory
    
    return TC_ACT_OK;
}
```

#### Production Standard (Correct)
> **Standard**: Adheres to kernel verifier requirements by re-evaluating skb->data and skb->data_end pointers following packet restructuring. Safely verifies L2-L4 boundaries before dereferencing and incrementally recalculates the IP checksum.
```c
#include <linux/bpf.h>
#include <bpf/bpf_helpers.h>
#include <linux/if_ether.h>
#include <linux/ip.h>
#include <linux/tcp.h>
#include <linux/pkt_cls.h>

#define W3C_TRACEPARENT_LEN 55

SEC("tc/ingress")
int tc_ingress_w3c_inject(struct __sk_buff *skb) {
    void *data = (void *)(long)skb->data;
    void *data_end = (void *)(long)skb->data_end;
    
    struct ethhdr *eth = data;
    if ((void *)(eth + 1) > data_end)
        return TC_ACT_OK;
        
    if (eth->h_proto != __constant_htons(ETH_P_IP))
        return TC_ACT_OK;
        
    struct iphdr *iph = (void *)(eth + 1);
    if ((void *)(iph + 1) > data_end || iph->protocol != IPPROTO_TCP)
        return TC_ACT_OK;
        
    __u32 ip_hl = iph->ihl * 4;
    struct tcphdr *tcph = (void *)((char *)iph + ip_hl);
    if ((void *)(tcph + 1) > data_end)
        return TC_ACT_OK;
        
    // Expand room at transport payload boundary
    if (bpf_skb_adjust_room(skb, W3C_TRACEPARENT_LEN, BPF_ADJ_ROOM_NET, 0) < 0)
        return TC_ACT_OK;
        
    // Reload pointers to satisfy BPF verifier invariants
    data = (void *)(long)skb->data;
    data_end = (void *)(long)skb->data_end;
    
    eth = data;
    if ((void *)(eth + 1) > data_end)
        return TC_ACT_SHOT;
        
    iph = (void *)(eth + 1);
    if ((void *)(iph + 1) > data_end)
        return TC_ACT_SHOT;
        
    // Update IPv4 total length field and incremental checksum
    __u16 old_tot_len = iph->tot_len;
    __u16 new_tot_len = __constant_htons(__constant_ntohs(old_tot_len) + W3C_TRACEPARENT_LEN);
    bpf_l3_csum_replace(skb, sizeof(struct ethhdr) + offsetof(struct iphdr, check), old_tot_len, new_tot_len, sizeof(new_tot_len));
    
    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: Kernel-Level W3C TraceContext Ingress Injection via eBPF TC

Kernel-Level W3C TraceContext Ingress Injection via eBPF TC defines an industrial-grade behavioral standard for devops engineering. Enforces deterministic W3C TraceContext propagation at the eBPF Traffic Control (TC) ingress hook prior to socket layer demuxing and userspace runtime consumption. Guarantees end-to-end distributed tracing across heterogeneous service mesh runtimes by eliminating userspace decoding blind spots, preserving BPF verifier packet-boundary invariants, and preventing payload corruption. 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: Userspace-Only Context Extraction Causing Observability Gaps and Corrupt Ingress Header Slices 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 DriftUserspace-Only Context Extraction Causing Observability Gaps and Corrupt Ingress Header SlicesCritical
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 reload and re-verify data and data_end pointers immediately after invoking bpf_skb_adjust_room to satisfy the BPF verifier's memory safety rules.

Engineers MUST ALWAYS reload and re-verify data and data_end pointers immediately after invoking bpf_skb_adjust_room to satisfy the BPF verifier's memory safety rules.

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 overwrite existing valid W3C traceparent headers

Engineers MUST NOT overwrite existing valid W3C traceparent headers; injection MUST only occur when no traceparent carrier is present on the ingress stream or when wrapping raw transport streams.

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 SHOULD utilize bpf_l4_csum_replace and bpf_l3_csum_replace to recompute transport and IP checksums dynamically after header adjustment, avoiding packet drops at the OS stack.

Code SHOULD utilize bpf_l4_csum_replace and bpf_l3_csum_replace to recompute transport and IP checksums dynamically after header adjustment, avoiding packet drops at the OS 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.
4

Services MUST emit fallback telemetry over a BPF perf buffer or ring buffer whenever headroom expansion fails due to skb_is_nonlinear or MTU violations.

Services MUST emit fallback telemetry over a BPF perf buffer or ring buffer whenever headroom expansion fails due to skb_is_nonlinear or MTU violations.

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

Components NEVER assume fixed transport header offsets

Components NEVER assume fixed transport header offsets; engineers MUST parse IP and TCP option lengths dynamically before executing carrier injection.

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 Kernel-Level W3C TraceContext Ingress Injection via eBPF TC critical for AI coding assistants?

Enforces deterministic W3C TraceContext propagation at the eBPF Traffic Control (TC) ingress hook prior to socket layer demuxing and userspace runtime consumption. Guarantees end-to-end distributed tracing across heterogeneous service mesh runtimes by eliminating userspace decoding blind spots, preserving BPF verifier packet-boundary invariants, and preventing payload corruption. 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 (Userspace-Only Context Extraction Causing Observability Gaps and Corrupt Ingress Header Slices) 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

Kernel-Level