Skip to content

feat(ebpf): Forward gateway and NAT traffic on tagged transport sides - #1540

Merged
privateip merged 4 commits into
epic/1399-vlan-transportfrom
feat/issue-1403
Nov 30, 2026
Merged

privateip merged 4 commits into
epic/1399-vlan-transportfrom
feat/issue-1403

Conversation

@privateip

@privateip privateip commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1403

Summary

The gateway and NAT can now forward traffic when either transport side uses an 802.1Q tag. Before this change, a tagged side could not attach in native XDP mode, and packets routed into a tagged side were dropped. A tagged side's hooks now always run in generic mode on its VLAN device, and packets leaving through a tagged side carry exactly that side's tag. Nodes without VLANs behave as before.

Test plan

  • Build, lint and unit tests pass.
  • Real-kernel root tests pass in native and generic host modes. They cover gateway ingress, backend replies, same-node delivery, and NAT66 and NAT64 both ways, in every tagged/untagged combination, plus isolation from a second VLAN on the same parent.
  • The root suite passed for every changed package. Locally, 8 unchanged packages failed for container-only reasons, so CI's root job is the reference.
  • The lab rows are deferred to Automate configurable tagged and untagged transport acceptance #1405.

The claim of a same-node delivery on the public VLAN is checked in #1539. Open PR #597 edits the same NAT files, and #1537, #1538 and #1539 overlap the transport contract and interface resolution. By the epic coordinator's decision, whichever PR lands second rebases. A follow-up comment has the details.

Rollback

Revert the PR and restart the gateway and NAT pods. An older release refuses a native attach to a tagged side, as it did before.

A VLAN netdevice has no native XDP. Generic XDP on it runs after the
kernel has matched the frame's VLAN ID and removed the tag, whatever the
parent's receive VLAN offload. A tagged transport side's hooks therefore
run there, isolated per VLAN, without parsing a tag.

xdpmode.ForLink gives a VLAN netdevice generic mode and every other
interface the host's mode. xdpattach attaches and checks each interface
in that mode, and skips the native support check for a VLAN netdevice.
The dispatcher's ModeFor applies the same rule to its links, migrations
and coverage. The host-wide mode claim is unchanged.
bpf_fib_lookup names the VLAN netdevice for a route through a tagged
side, and a native XDP redirect to a VLAN netdevice transmits nothing.
edgedsr.c and nat.c now look the egress interface up in a vlan_egress
map. For a tagged side's VLAN netdevice they push exactly that side's
802.1Q tag and leave through its lower device, with XDP_TX when the
lower device is the ingress interface.

The vlanegress package fills the map from netlink, for the configured
sides only: the gateway's public and internal interfaces, and the NAT
shard's resolved uplinks. Both sync it at startup and on every netlink
change. Its Lowers interface matches the shared transport resolution's
VLANLower, which can replace FromNetlink.

Root tests cover the gateway ingress and DSR return in all four
public/fabric combinations, on a NIC and a bond fabric parent, attached
directly and through the dispatcher, in native and generic host modes.
Further root tests cover:
- isolation of a second VLAN and untagged traffic on the public parent;
- the XDP_TX push;
- the neighbour fallback staying in the VLAN context;
- the NAT66 forward push.
The contract now states that a tagged side's gateway and NAT hooks run on
its VLAN netdevice in generic mode. It also describes the vlan_egress
transmit tagging, the generic-mode cost on native hosts that #1405 and
#1406 measure, Q1 and Q3 as resolved, and Q8 as not supported.

The XDP attach mode guide states the per-interface rule. The gateway and
NAT configuration guides explain how to name a tagged side.
@privateip privateip self-assigned this Nov 30, 2026
@privateip

Copy link
Copy Markdown
Contributor Author

Design

Before this change, edge_lb, edge_return and nat_ingress failed on a tagged (802.1Q) transport side:

This PR does three things:

  1. Hook placement. A VLAN netdevice now always attaches in generic mode. Every other interface keeps the host mode (xdpmode.ForLink, used by xdpattach and the dispatcher's ModeFor). By the time generic XDP runs on the VLAN netdevice, the kernel has matched the VLAN ID and removed the tag. Each side's hook therefore sees only its own VLAN, whatever the parent's receive VLAN offload, and neither the programs nor the dispatcher parse a tag. The host-wide mode claim from Let operators force a host-wide XDP attach mode for generic-mode testing #1534 is unchanged.

  2. Transmit. edgedsr.c and nat.c gain a vlan_egress map from a VLAN ifindex to its lower ifindex and VID. When bpf_fib_lookup returns a mapped VLAN netdevice, leave_via pushes exactly one 802.1Q tag and redirects to the lower device, or uses XDP_TX when the lower device is the ingress. The new package internal/plumbing/ebpf/vlanegress fills the map from netlink, for the configured sides only. galactic-gateway (public and internal interfaces) and galactic-nat (resolved uplinks) sync it at startup and on every netlink change. The Lowers interface matches transport.Set.VLANLower from Reconcile transport configuration and lifecycle with diagnostics #1404, so that package can replace vlanegress.FromNetlink.

  3. Docs. The contract records the decision:

    docs/operations/xdp-attach-mode.md states the per-interface rule, and the gateway and NAT configuration guides say how to name a tagged side.

The device-bound VLAN metadata kfunc was rejected: the kernel keeps device-bound programs out of program arrays, which the dispatcher and the NAT tail calls need, and the kfunc does not work in generic mode. Requiring VLAN receive offload off was also rejected: on veth the sender decides where the tag goes, so the receiver can't enforce it.

Validation

Real-kernel root tests, run as root in a privileged container on kernel 7.3.3. Each runs in both host modes (GALACTIC_XDP_MODE limits a run to one):

  • TestVLANTransport_GatewayPaths (edgeattach): gateway ingress and DSR return in all four public/fabric combinations, on a NIC and an active-backup bond fabric parent, with direct attachment and through the dispatcher. 22 cases. Captures with PACKET_AUXDATA show exactly the egress side's tag, or none, and never the ingress side's. A native redirect to a bond master transmits in both modes.
  • TestVLANTransport_OtherVLANNotClaimed: VIP traffic on a second VLAN of the public parent, or untagged on the parent, is not claimed. Checked with the sender's transmit VLAN offload on and off.
  • TestVLANTransport_TagPushWithXDPTX: tag push with XDP_TX when the lower device is the ingress.
  • TestVLANTransport_ColdNeighborFallsBackInVLANContext: the XDP_PASS neighbour fallback from the public VLAN leaves the fabric VLAN with only the fabric tag.
  • TestNatIngress_ForwardToTaggedUplinkPushesTheTag (natprog): NAT66 forward to a tagged uplink pushes one tag, for both XDP_REDIRECT and XDP_TX.

Negative control: with vlan_egress left empty, every native case that routes into a tagged side fails, as #1401 Q4 predicts. The generic cases still pass.

Unit tests: xdpmode.ForLink, vlanegress.FromNetlink validation (802.1ad, stacked, ID 0, missing link), and the native support check skipping VLAN netdevices.

Check Result
task build Passed
task lint Passed
task test:unit Passed
task test:unit-root Passed for every changed package; 8 unchanged packages failed in the local privileged container

The 8 local test:unit-root failures are in packages this PR does not touch: cni/tap, edge/hostattach, gc, hostgw, installer, egressroutemap, nldump and vrf. They come from the container, which has no iptables, interrupts netlink dumps under load and keeps a preexisting main-table default route. CI's root job is the reference.

Lab rows are deferred to the #1405 end-of-epic pass, under #1399's decision. NAT forwarding is covered by program test runs, not by live attachment in each host mode. No hardware qualification is claimed.

Compatibility and rollback

  • A node with no VLAN netdevice in its gateway or NAT configuration behaves as before: every hook keeps the host mode, and vlan_egress stays empty.
  • The new vlan_egress map is created on first load; no existing pinned map changes layout.
  • Rollback: revert, then restart galactic-gateway and galactic-nat. An older release refuses native attach to a tagged side, as before this change.

@privateip privateip changed the title Forward gateway and NAT traffic on 802.1Q-tagged transport sides feat(ebpf): Forward gateway and NAT traffic on tagged transport sides Nov 30, 2026
The NAT root test now runs NAT66 and NAT64, outbound and return,
between a tagged public uplink and a tagged fabric uplink on one parent.
Each translated packet must leave through the parent with exactly the
egress side's tag.

A gateway root test covers same-node delivery on a tagged public side.
edge_lb hands the encapsulated packet to the kernel, and the packet must
continue in the public VLAN netdevice's receive path with no tag.

The gateway's startup log now names each tagged side by its configured
interface. It no longer infers the side from the position of the
interface's ifindex.
@privateip

Copy link
Copy Markdown
Contributor Author

Tests added at a032ee5, run as root in a privileged container on kernel 7.3.3:

  • TestNatIngress_TaggedUplinksPushTheirTag replaces the NAT66-only test. It runs NAT66 outbound and return and NAT64 outbound and return between tagged public VLAN 101 and tagged fabric VLAN 202 on one parent. Every leg leaves through the parent with exactly the egress side's tag. NAT66 outbound also covers XDP_TX from the parent and XDP_REDIRECT from an unrelated interface.
  • TestVLANTransport_LocalDeliveryStaysOnThePublicVLAN runs in both host modes. With a tagged public side and a local backend, edge_lb hands the encapsulated packet up with XDP_PASS. A capture on the public VLAN netdevice, which taps after its generic XDP hook, sees the packet there untagged and addressed to the local uSID. local_deliveries reads 1, and nothing leaves through the fabric. The usid_ingress claim on that VLAN netdevice is checked in feat(transport): Pick and check VLAN transport interfaces per node #1539.

The startup log nit from review is fixed: each tagged side is now named by its configured interface.

@privateip
privateip marked this pull request as ready for review November 30, 2026 19:43
@privateip
privateip requested a review from a team as a code owner November 30, 2026 19:43
@privateip
privateip merged commit 705dede into epic/1399-vlan-transport Nov 30, 2026
28 checks passed
@privateip

Copy link
Copy Markdown
Contributor Author

Review at a032ee5. Two reviewers ran: the adversarial re-review voted merge, with every earlier finding confirmed fixed. The conventions review held on two landing-order decisions, for #597 and for #1537 to #1539. The epic coordinator settled both: whichever PR lands second rebases. I fixed its remaining body finding. CI is green, including Unit Tests (root), which ran every new VLAN transport root test. Marking ready with auto-merge.

@privateip
privateip deleted the feat/issue-1403 branch November 30, 2026 19:43
privateip added a commit that referenced this pull request Dec 2, 2026
feat(ebpf): Forward gateway and NAT traffic on tagged transport sides
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant