Skip to content

feat(gateway): Share edge uplinks with NAT without restart outages - #745

Merged
privateip merged 1 commit into
mainfrom
feat/issue-717-gateway-dispatch
Oct 6, 2026
Merged

privateip merged 1 commit into
mainfrom
feat/issue-717-gateway-dispatch

Conversation

@privateip

@privateip privateip commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A gateway restart detaches its XDP programs from the uplinks, which cuts egress for an egress shard on the same node and bounces every link.

The gateway now runs from the node's shared XDP dispatcher by default, as the shard already can, so the two share each uplink and either can restart or be turned off without touching the other's traffic.

The old chained mode is removed. No production node runs the gateway or a chained shard, so nothing changes there, and a node that did must upgrade both binaries together.

Test plan

  • Gateway and shard on one uplink: a gateway restart under egress traffic keeps the uplink's program and loses no requests
  • A shard restart leaves the gateway ready
  • Turning the gateway off withdraws only its own VIP routes and leaves egress working
  • A gateway set to direct mode refuses an uplink the shard is using

Fixes #717
Fixes #710

🤖 Generated with Claude Code

The gateway attaches edge_lb and edge_return to its uplinks itself, unpinned, so a restart detaches them, bounces every uplink, and cuts egress for a shard chained behind it through the gateway's own xdp_chain map (#710). #742 and #743 put the egress shard on the node's shared dispatcher; this moves the gateway onto it too and retires chain mode, so the two share an uplink and either can restart without touching the other's traffic.

- edgedsr.c includes the dispatcher's header and passes every packet it does not claim to the later slots with dispatch_next, in place of xdp_chain and its tail call. Attached directly, the programs hold their own empty copies of the dispatcher maps, so an unclaimed packet passes to the kernel as before.
- edgeattach.Load takes the dispatcher's maps as MapReplacements and never pins, recreates or unpins them.
- GALACTIC_GATEWAY_XDP_ATTACH defaults to dispatch: the gateway fills slots 0 and 1, renews both leases, and keeps the dispatcher on the public targets with the public role and on the internal targets with the return role, through xdpattach.DispatchSet. direct attaches the programs as before, after releasing an idle dispatcher, and refuses to start while another datapath's slot is live there.
- An internal interface that resolves to a public one is refused at startup and dropped from the return set on a later re-resolve, since edge_return forwards anything sourced from a VIP.
- GALACTIC_GATEWAY_DATAPATH_ENABLED=false loads nothing, empties the gateway's slots, and makes NetworkGatewayReconciler withdraw this node's VIP advertisements and report DatapathDisabled without driving the engine. The public interface and SRv6 address are not required while it is off.
- Chain mode is gone: natattach's chain code, galactic-nat's waitForChain/keepChain, the chained overlay and its placement test. GALACTIC_NAT_XDP_ATTACH=chain is read as dispatch with a warning. Nothing in infra uses the overlay.
- xdpattach.ReleaseIdleDispatcher and ClearDispatcherSlots replace the NAT-only helpers, so both binaries release and empty slots the same way.
- A disabled gateway withdraws its VIPs on every reconcile, so it matches its own advertisements exactly by their rule label, "<rule>-<node>-v4/-v6", and never claims another node's whose name shares the suffix ("edge1" against "pop-edge1"), which would turn the old suffix match into a delete/recreate loop. Unlabelled legacy advertisements keep the suffix match.
- edgeattach.Load removes the retired /sys/fs/bpf/galactic-edge/xdp_chain pin, so it no longer keeps an old shard program loaded or lets a shard not yet upgraded install itself into a map no datapath runs.
- A setup step that fails after the gateway joined the dispatcher stops its leases and empties its slots before the process exits.
- The gateway architecture and configuration docs, the NAT and node-label docs, the overview docs, AGENTS.md, the lab NAT README and the manifest comments describe the dispatcher in place of xdp_chain, and the NAT doc says a node that ran chain mode upgrades the gateway and the shard together.

Root tests run the gateway and the shard on one veth uplink and show a gateway restart leaves the root program and the shard's coverage in place, and that a direct-mode gateway refuses an uplink the shard runs on. edgedsr's tests show an unclaimed packet reaches the shard's slot and a claimed one never does. The containerlab lab ran both on dfw-worker2 in dispatch mode: egress passed with the gateway in front, a gateway restart under traffic kept the root program and lost no requests, a NAT restart kept the gateway ready, and turning the gateway off emptied only its slots.

Fixes #717
Fixes #710

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@privateip privateip self-assigned this Oct 6, 2026
@privateip

Copy link
Copy Markdown
Contributor Author

Lab run on the containerlab lab, dfw-worker2, with images built from this branch's code (3376c25 differs only by the advertisement-label match, the retired-pin removal and the setup cleanup, which have their own tests). The gateway ran in dispatch mode with bond0 public and bond1 internal, next to the egress shard in dispatch mode.

  1. Every uplink ran one xdp_dispatch program. bond0's members carried the public and egress roles, bond1's the return and egress roles. verify:nat-datapath (NAT66 and NAT64) and verify:nat-local passed with the gateway in front, so packets it does not claim reach the shard.
  2. Gateway restart under egress traffic at 2 requests per second for 90 seconds: the root program stayed id 189277 on all four uplinks, and 180 of 180 requests succeeded. The shard and the NetworkGateway both stayed healthy.
  3. Shard restart: the gateway pod stayed ready in all 40 one-second samples, the root program did not change, and egress passed afterwards.
  4. GALACTIC_GATEWAY_DATAPATH_ENABLED=false emptied dispatcher slots 0 and 1 and left the shard's slot 2. The pod stayed ready, the NetworkGateway reported DatapathDisabled, and egress passed. Turning it back on refilled both slots on the same root program.
  5. Restore: turning the gateway off and removing it, then direct mode on the shard, released the dispatcher from every uplink, and the main image attached normally.

Direct-mode refusal of an uplink the shard uses is covered by TestAttachDirect_RefusesAnUplinkTheShardRunsOn, which runs as root against real veth pairs. The root-gated tests for every touched package pass under -race locally, and the Unit Tests (root) job runs them in CI.

@privateip
privateip marked this pull request as ready for review October 6, 2026 11:33
@privateip
privateip requested a review from a team as a code owner October 6, 2026 11:34
@privateip
privateip enabled auto-merge October 6, 2026 11:34
@privateip

Copy link
Copy Markdown
Contributor Author

Code-reviewer: merge. No blocking findings; four non-blocking items fixed before push (exact advertisement match by rule label, retired xdp_chain pin removal, cleanup on setup failure, docs). RAN: review of changes and diff.

Adversary: hold, could not run root-only eBPF tests (skip without root) and CI was pending. One warning: removing the xdp_chain pin needs an upgrade-order note; the NAT doc already says chain-mode nodes upgrade both binaries together, and the PR body now documents this. RAN: go build/vet, go test of touched packages (BPF tests skipped as non-root), kustomize builds, stale-reference greps.

Conventions-reviewer: hold on rollout reach (the gateway default flip and chain removal) and merge order with #597. The author confirmed the gateway is deployed on no production node and no production shard uses chain mode, and earlier decided stale drafts (#597, #580, #613) rebase onto this work. RAN: gh pr view, diff stat, open-PR collision check, kustomize builds of both bases.

No findings were applied (nothing to apply).

CI green: Build, E2E Tests, Lint, Unit Tests, Unit Tests (root), license/cla, and all image publish jobs passed. All checks passed successfully on 3376c25.

Merge method: merge. Auto-merge enabled and will complete once a code owner approves. The base branch ruleset requires one code-owner approval of the last push, so the PR will merge after approval.

@privateip
privateip disabled auto-merge October 6, 2026 14:15
@privateip
privateip merged commit 851adaf into main Oct 6, 2026
14 checks passed
@privateip
privateip deleted the feat/issue-717-gateway-dispatch branch October 6, 2026 14:15
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.

Decouple gateway and NAT XDP attachment Gateway restart detaches XDP from uplinks

2 participants