This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
devopscritical PriorityID: envoy-gateway-ebpf-nat64-stateless-ingress

Envoy Gateway Stateless eBPF NAT64 Dual-Stack Ingress Standard

Enforces deterministic, stateless RFC 6052 / RFC 7915 algorithmic IPv6-to-IPv4 header synthesis via eBPF XDP programs at Envoy Gateway edge nodes. Eliminates netfilter conntrack exhaustion and dual-stack core routing complexity by mapping IPv4 targets into the Well-Known 64:ff9b::/96 prefix prior to envoy listener processing, guaranteeing O(1) memory consumption and linear scaling.

Prohibited Anti-Pattern: Stateful Netfilter Conntrack NAT64 and Complex Internal Dual-Stack Routing Under Ingress Load

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Envoy Gateway Stateless eBPF NAT64 Dual-Stack Ingress Standard - Enforces deterministic, stateless RFC 6052 / RFC 7915 algorithmic IPv6-to-IPv4 header synthesis via eBPF XDP programs at Envoy Gateway edge nodes. Eliminates netfilter conntrack exhaustion and dual-stack core routing complexity by mapping IPv4 targets into the Well-Known 64:ff9b::/96 prefix prior to envoy listener processing, guaranteeing O(1) memory consumption and linear scaling.
globs: k8s/**/*.yaml, deploy/**/*.yaml, infrastructure/**/*.tf, bpf/**/*.c, gateway/**/*.yaml
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/envoy-gateway-ebpf-nat64-stateless-ingress"
---

# Envoy Gateway Stateless eBPF NAT64 Dual-Stack Ingress Standard

> **Severity**: CRITICAL | **Category**: devops
> **Anti-Pattern Warning**: Stateful Netfilter Conntrack NAT64 and Complex Internal Dual-Stack Routing Under Ingress Load

## System Constraints
You are a Principal Infrastructure & Network Architect enforcing Envoy Gateway eBPF NAT64 Dual-Stack Ingress Standards. You must reject any configuration that uses stateful Linux conntrack NAT (iptables/nftables) or mandates dual-stack IP addressing throughout inner cluster workloads. Ensure all ingress traffic normalization happens statelessly in XDP/eBPF using algorithmic address mapping (RFC 6052 / RFC 7915) before reaching Envoy data-plane workers.

## Strict Guidelines
- Engineers MUST ALWAYS configure XDP eBPF hook programs on external ingress interfaces to statelessly translate IPv6 packets to IPv4 using RFC 6052 Well-Known (64:ff9b::/96) or Network-Specific prefixes.
- Engineers MUST NOT rely on Linux netfilter, iptables, or nftables stateful NAT (MASQUERADE, SNAT/DNAT conntrack modules) for cluster ingress NAT64 translation.
- Engineers MUST ensure cluster mesh and internal pod networks remain single-stack (IPv6-only or pure IPv4) rather than dual-stack, delegating all translation boundaries strictly to Envoy Gateway eBPF edge programs.
- XDP translation programs MUST recalculate L3 IPv4 checksums using incremental updates (RFC 1624) and handle TCP/UDP pseudo-header checksum differential adjustments statelessly without keeping flow-state memory tables.
- EnvoyProxy Custom Resources MUST explicitly bind to the translated address space and preserve original client IP metadata by attaching PROXY protocol v2 headers or X-Forwarded-For via Envoy's downstream proxy filter chain.
- Non-translatable packets (such as IPv6 fragments where total size exceeds IPv4 MTU minus 20 bytes) MUST generate stateless ICMPv6 Type 2 (Packet Too Big) responses directly within the eBPF layer.

## Bad vs Good Implementations
### Stateful conntrack NAT64 script vs. Stateless eBPF XDP NAT64 C Program

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Allocates stateful connection tracking entries inside an eBPF hash map or kernel conntrack table. Under heavy traffic or asymmetric UDP floods, this causes table exhaustion, dropped packets, and latency degradation.
```c
/* ANTI-PATTERN: Relying on netfilter conntrack state tables for NAT64 translation */
#include <linux/types.h>
#include <linux/bpf.h>
#include <bpf/bpf_helpers.h>

struct bpf_map_def SEC("maps") conntrack_table = {
    .type = BPF_MAP_TYPE_HASH,
    .key_size = sizeof(__u64),
    .value_size = sizeof(__u64),
    .max_entries = 65536, /* Vulnerable to state exhaustion DDoS */
};

SEC("tc")
int stateful_nat64(struct __sk_buff *skb) {
    __u64 key = skb->remote_ip4;
    __u64 *entry = bpf_map_lookup_elem(&conntrack_table, &key);
    if (!entry) {
        // Allocating flow state per connection exhausts memory under SYN flood
        bpf_map_update_elem(&conntrack_table, &key, &key, BPF_ANY);
    }
    return 0;
}
```

#### Production Standard (Correct)
> **Standard**: Operates strictly in the XDP driver layer with zero connection state tracking. Packets destined to 64:ff9b::/96 are deterministically converted to IPv4 using algorithmic header translation in O(1) time and forwarded without conntrack table bloat.
```c
/* PRODUCTION INVARIANT: Algorithmic Stateless RFC 7915 / RFC 6052 Translation in XDP */
#include <linux/bpf.h>
#include <linux/if_ether.h>
#include <linux/ip.h>
#include <linux/ipv6.h>
#include <linux/in.h>
#include <bpf/bpf_helpers.h>

#define NAT64_PREFIX_0 0x0064ff9b /* 64:ff9b:: in big endian prefix */

SEC("xdp")
int xdp_stateless_nat64(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 != __constant_htons(ETH_P_IPV6))
        return XDP_PASS;

    struct ipv6hdr *ip6 = (struct ipv6hdr *)(eth + 1);
    if ((void *)(ip6 + 1) > data_end)
        return XDP_PASS;

    /* Match RFC 6052 Well-Known Prefix (64:ff9b::/96) */
    if (ip6->daddr.s6_addr32[0] != __constant_htonl(NAT64_PREFIX_0) ||
        ip6->daddr.s6_addr32[1] != 0 ||
        ip6->daddr.s6_addr32[2] != 0)
        return XDP_PASS;

    /* Algorithmic extraction of embedded IPv4 destination */
    __u32 target_ip4 = ip6->daddr.s6_addr32[3];

    /* Stateless header modification to IPv4 without map lookups */
    if (bpf_xdp_adjust_head(ctx, (int)(sizeof(struct ipv6hdr) - sizeof(struct iphdr))))
        return XDP_DROP;

    /* Reload pointers after adjustment */
    data = (void *)(long)ctx->data;
    data_end = (void *)(long)ctx->data_end;
    eth = data;
    if ((void *)(eth + 1) > data_end)
        return XDP_DROP;

    eth->h_proto = __constant_htons(ETH_P_IP);
    struct iphdr *ip4 = (struct iphdr *)(eth + 1);
    if ((void *)(ip4 + 1) > data_end)
        return XDP_DROP;

    ip4->version = 4;
    ip4->ihl = 5;
    ip4->ttl = 64;
    ip4->daddr = target_ip4;
    ip4->check = 0; /* Recalculated statelessly via hardware checksum offload */

    return XDP_TX;
}
```

### Envoy Gateway EnvoyProxy Dual-Stack vs Stateless IPv6 Ingress Configuration

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Requiring dual-stack service configurations internally doubles IPAM exhaustion risks, multiplies routing rule complexity, and relies on kernel-level kube-proxy conntrack for pod-to-pod pathing.
```yaml
# ANTI-PATTERN: Dual-stack internal mesh listeners creating multi-path routing overhead
apiVersion: gateway.envoyproxy.io/v1alpha1
kind: EnvoyProxy
metadata:
  name: ingress-proxy
  namespace: envoy-gateway-system
spec:
  provider:
    type: Kubernetes
    kubernetes:
      envoyService:
        ipFamilies:
          - IPv4
          - IPv6
        ipFamilyPolicy: RequireDualStack # Forces dual-stack routing in internal networks
```

#### Production Standard (Correct)
> **Standard**: Directs ingress through a pure single-stack paradigm. Envoy binds cleanly while eBPF handles incoming IPv4 synthesis statelessly using standard prefixes, keeping internal routing simple, performant, and immune to conntrack depletion.
```yaml
# PRODUCTION INVARIANT: Envoy Gateway with Single-Stack Engine + eBPF Front-End
apiVersion: gateway.envoyproxy.io/v1alpha1
kind: EnvoyProxy
metadata:
  name: ingress-proxy
  namespace: envoy-gateway-system
spec:
  telemetry:
    accessLog:
      settings:
        - format:
            text: "[%START_TIME%] %DOWNSTREAM_REMOTE_ADDRESS% %REQ(:METHOD)% %REQ(X-FORWARDED-FOR)%"
  provider:
    type: Kubernetes
    kubernetes:
      envoyService:
        ipFamilies:
          - IPv6
        ipFamilyPolicy: SingleStack
        annotations:
          ebpf.io/nat64-stateless-mode: "rfc6052-xdp-direct"
          ebpf.io/nat64-prefix: "64:ff9b::/96"
```

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: Envoy Gateway Stateless eBPF NAT64 Dual-Stack Ingress Standard

Envoy Gateway Stateless eBPF NAT64 Dual-Stack Ingress Standard defines an industrial-grade behavioral standard for devops engineering. Enforces deterministic, stateless RFC 6052 / RFC 7915 algorithmic IPv6-to-IPv4 header synthesis via eBPF XDP programs at Envoy Gateway edge nodes. Eliminates netfilter conntrack exhaustion and dual-stack core routing complexity by mapping IPv4 targets into the Well-Known 64:ff9b::/96 prefix prior to envoy listener processing, guaranteeing O(1) memory consumption and linear scaling. 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: Stateful Netfilter Conntrack NAT64 and Complex Internal Dual-Stack Routing Under Ingress Load 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 DriftStateful Netfilter Conntrack NAT64 and Complex Internal Dual-Stack Routing Under Ingress LoadCritical
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 configure XDP eBPF hook programs on external ingress interfaces to statelessly translate IPv6 packets to IPv4 using RFC 6052 Well-Known (64

Engineers MUST ALWAYS configure XDP eBPF hook programs on external ingress interfaces to statelessly translate IPv6 packets to IPv4 using RFC 6052 Well-Known (64:ff9b::/96) or Network-Specific prefixes.

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 rely on Linux netfilter, iptables, or nftables stateful NAT (MASQUERADE, SNAT/DNAT conntrack modules) for cluster ingress NAT64 translation.

Engineers MUST NOT rely on Linux netfilter, iptables, or nftables stateful NAT (MASQUERADE, SNAT/DNAT conntrack modules) for cluster ingress NAT64 translation.

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 ensure cluster mesh and internal pod networks remain single-stack (IPv6-only or pure IPv4) rather than dual-stack, delegating all translation boundaries strictly to Envoy Gateway eBPF edge programs.

Engineers MUST ensure cluster mesh and internal pod networks remain single-stack (IPv6-only or pure IPv4) rather than dual-stack, delegating all translation boundaries strictly to Envoy Gateway eBPF edge programs.

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

XDP translation programs MUST recalculate L3 IPv4 checksums using incremental updates (RFC 1624) and handle TCP/UDP pseudo-header checksum differential adjustments statelessly without keeping flow-state memory tables.

XDP translation programs MUST recalculate L3 IPv4 checksums using incremental updates (RFC 1624) and handle TCP/UDP pseudo-header checksum differential adjustments statelessly without keeping flow-state memory tables.

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

EnvoyProxy Custom Resources MUST explicitly bind to the translated address space and preserve original client IP metadata by attaching PROXY protocol v2 headers or X-Forwarded-For via Envoy's downstream proxy filter chain.

EnvoyProxy Custom Resources MUST explicitly bind to the translated address space and preserve original client IP metadata by attaching PROXY protocol v2 headers or X-Forwarded-For via Envoy's downstream proxy filter chain.

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

Non-translatable packets (such as IPv6 fragments where total size exceeds IPv4 MTU minus 20 bytes) MUST generate stateless ICMPv6 Type 2 (Packet Too Big) responses directly within the eBPF layer.

Non-translatable packets (such as IPv6 fragments where total size exceeds IPv4 MTU minus 20 bytes) MUST generate stateless ICMPv6 Type 2 (Packet Too Big) responses directly within the eBPF layer.

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 Envoy Gateway Stateless eBPF NAT64 Dual-Stack Ingress Standard critical for AI coding assistants?

Enforces deterministic, stateless RFC 6052 / RFC 7915 algorithmic IPv6-to-IPv4 header synthesis via eBPF XDP programs at Envoy Gateway edge nodes. Eliminates netfilter conntrack exhaustion and dual-stack core routing complexity by mapping IPv4 targets into the Well-Known 64:ff9b::/96 prefix prior to envoy listener processing, guaranteeing O(1) memory consumption and linear scaling. 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 (Stateful Netfilter Conntrack NAT64 and Complex Internal Dual-Stack Routing Under Ingress Load) 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

Envoy