Skip to content

feat(gateway): Deliver load-balanced flows to a backend on the same node - #1527

Merged
privateip merged 6 commits into
mainfrom
fix/issue-1526
Nov 30, 2026
Merged

privateip merged 6 commits into
mainfrom
fix/issue-1526

Conversation

@privateip

@privateip privateip commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A gateway dropped every load-balanced flow whose backend ran on the gateway's own node, so core never used such a backend, and a public listener whose backends all sit on gateway nodes served nothing. The gateway can now hand those flows to the backend through its own node's uplink, which decapsulates and delivers them as it does a flow from another gateway.

Local delivery is off by default. A gateway reports status.localDelivery only with GALACTIC_GATEWAY_LOCAL_DELIVERY=true, and then only once its SRv6 address is the node's locator address and usid_ingress is attached to its public interface. Core serves a listener backend on a gateway's node only while that gateway reports it and is Ready. With the switch off, or on an older gateway, core leaves that node's backends out, as it does today. The containerlab gateway turns the switch on.

Fixes #1526.

Test plan

  • Datapath tests: a local backend's flow, for an IPv6 and an IPv4 client, leaves for the kernel framed as it arrived with the outer header to the backend, and counts as a local delivery; a remote backend never does
  • Datapath test: an encapsulation source that differs from the backend uSID in bits 48 to 63 is remote, and one that differs only from bit 64 on is local
  • Core serves a gateway node's backend while its gateway reports local delivery and excludes it again when the report goes away
  • The switch is off by default and set from the environment or the flag
  • task lint, task build and task test:unit pass, plus the listener and controller envtests
  • Lab: the listener test's local-delivery case answers every flow over both families and protocols. Required before the switch is turned on anywhere outside the lab.

When Maglev picked a backend on the gateway's own node, edge_lb
encapsulated the packet to that node's uSID and looked the route up.
The lookup met the discard route for the node's own locator, and every
such flow was dropped as fib_unreachable.

edge_lb now treats a backend whose uSID shares the first 64 bits, the
Block and Node ID, of its encapsulation source as local. It pushes the
outer header as before but hands the packet to the kernel, framed as it
arrived, without the lookup. The uplink's usid_ingress claims it by its
locator, applies the backend's VIP translation row and delivers it, as
it does a packet from another gateway. Replies are unchanged. These
packets count in a new local_deliveries map, exported as
galactic_edge_local_deliveries_total.

The gateway reports status.localDelivery on its NetworkGateway while it
can deliver this way: its encapsulation source is its node's locator
address, always when derived from its BGPRouter and for a configured
source only when it shares that router's Block and Node ID, and
usid_ingress is attached to its public interface, every member for a
bond (attach.IngressAttachedTo). The attachment is checked on every
status write, since galactic-cni may attach after the gateway starts.
Core never served an Edge listener backend on a node a NetworkGateway
targets, because that gateway dropped every flow Maglev sent to it.
Where every node that can host a listener backend also runs a gateway,
nothing served and the listener's addresses were never advertised.

A backend on a gateway's node now serves while that gateway reports
status.localDelivery and is Ready, and is excluded, with
LocalBackendsExcluded, otherwise. Requiring Ready keeps a stopped or
failed gateway's old report from serving its node's backends. A gateway
that predates local delivery never reports it, so a mixed-version
rollout keeps excluding those backends. The listener controller
re-decides its listeners when a gateway's report or readiness changes.
@privateip privateip self-assigned this Nov 30, 2026
A gateway with a configured SRv6 encapsulation source compared it
against its node's BGPRouter once, at startup. A router that was not
readable yet left local delivery off until the gateway restarted, and
core kept excluding the node's listener backends meanwhile.

The comparison now runs from the LocalDelivery check itself: a true
answer is kept, and a false one is asked again at most every 30
seconds, with a 5-second limit on each read.
The Phase 0 listener proof recorded what happened when the VIP was
pinned to the backend's own node, because the gateway dropped every
such flow. With local delivery that case must answer like the remote
one: every UDP and TCP flow over both families, counted by the
backend's own gateway. It still records the gateway's drops.
@privateip
privateip marked this pull request as ready for review November 30, 2026 12:09
@privateip
privateip requested a review from a team as a code owner November 30, 2026 12:09
@privateip
privateip enabled auto-merge November 30, 2026 12:09
@privateip

Copy link
Copy Markdown
Contributor Author

Review record for this PR. An independent pre-push code review found no code defects. Its warnings were fixed before the PR opened: the gateway verifies usid_ingress is attached on its public interface before reporting localDelivery, core requires the gateway to be Ready as well, and controller, predicate and attach tests were added.

First pass: pr-adversary held with no defect found. It could not verify the root BPF tests or the lab locally, and raised two warnings: a one-shot locator check and stale status after a gateway dies. pr-conventions-reviewer held on decisions (ordering against #845, base not in its object store, rollout and lab) plus a nit on an em dash.

Fixes: 08f1610 re-checks the node locator (keeps true, re-asks every 30s) and removes the em dash. dafd0b1 makes the lab proof's local-delivery case a hard assertion. The stale-status warning is kept with reasoning: pinned XDP links run for the 120s dispatcher lease, after which every VIP on the node stops being served, so the flag adds no listener-specific failure.

Second pass: pr-rereviewer returned merge, confirming the fixes and the stale-status reasoning. pr-conventions-reviewer held again, re-raising only decisions the human already resolved (#1527 lands before draft PR #845; the gateway-before/after-core rollout is safe because an older gateway never reports status.localDelivery). Its commit-subject nit was a miscount: the subject is 72 characters, the repo limit.

CI: every check passed on dafd0b1, including Unit Tests (root) and E2E Tests, so the kernel verifier accepts the datapath change and the local and remote datapath tests pass on a real kernel.

Not run: the lab proof. It is deferred by decision to a follow-up run before #1511's failover tests, and the last test-plan item stays unchecked.

Auto-merge is enabled with the merge method, the only one the ruleset allows. The ruleset requires one approving review from a code owner and approval of the last push, so the PR waits for a human approval.

@ecv ecv left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Request changes: run the lab local-delivery case first.

Cross-node delivery is unchanged. But there is no switch to keep local delivery off: a gateway built from this PR reports localDelivery: true once its locator check passes and usid_ingress is attached, which is immediate with a derived SRv6 address. Core then routes that node's own backends through the gateway. The step that has to work for those flows is usid_ingress claiming the handed-up packet and delivering it to the backend. No test in CI covers that step, it is the one the earlier lab run showed failing, and the PR says the lab case was not run. If it fails, those flows are black-holed on every node that deploys this.

  • Remote path: backend_is_local compares the first 64 bits of the backend uSID with encap_src; on no match, resolve_fib_and_write_eth runs with the same arguments as before. TestEdgeLB_RemoteBackendIsNotLocal pins that a remote backend never counts as local.
  • Older gateways: status.localDelivery is omitempty, and core excludes a gateway node's backends unless the flag is true and the gateway is Ready, so mixed versions are safe.
  • Tests: Unit Tests (root) loads the program on a real kernel and covers edge_lb's IPv4 and IPv6 output (framing, outer header, counters). It stops at edge_lb's output.

To approve: post the lab case result (tests/edgeconformance/listener_test.go, both families, TCP and UDP), or add an off-by-default flag so the first deployment can stay off.

Follow-ups:

  • The attach check proves the filter is present, not that decapsulation works. Consider tying localDelivery to local_deliveries and usid_ingress counters moving together.
  • Add a root BPF case where encap_src and the backend uSID share the first 64 bits' Block and Node ID but differ after them, to pin the comparison width.

Add a root BPF case for an encapsulation source that matches the
backend uSID's first 48 bits but not bits 48 to 63, which must take the
FIB lookup, and one that differs only from bit 64 on, which must be
delivered locally.
Add GALACTIC_GATEWAY_LOCAL_DELIVERY (--gateway-local-delivery), off by
default. Off, the gateway never reports status.localDelivery, so core
keeps leaving this node's backends out of Edge listeners, as it does for
an older gateway. On, the gateway reports it once its SRv6 address is
the node's locator address and usid_ingress is attached to its public
interface, as before.

This lets a first deployment ship without routing a node's own backends
through its gateway, and turns local delivery on per node once the lab
case has passed. The containerlab gateway turns it on, since the
listener conformance test requires local delivery.
@privateip

Copy link
Copy Markdown
Contributor Author

Took the off-by-default route in 1b6b059 and c48b58a:

  • GALACTIC_GATEWAY_LOCAL_DELIVERY (--gateway-local-delivery), default false. Off, the gateway never reports status.localDelivery, so core keeps excluding the node's backends, matching an older gateway. A node's flows reach usid_ingress only after an operator turns the switch on for that node.
  • The containerlab gateway sets it to true, so the listener conformance case runs with local delivery. That lab run is still a box on the PR, and it gates turning the switch on anywhere else.
  • Added TestEdgeLB_LocalComparisonWidth: an encap source that differs from the backend uSID in bits 48 to 63 takes the FIB lookup, and one that differs only from bit 64 on is delivered locally.

Not done here: tying localDelivery to local_deliveries and usid_ingress counters moving together. That needs traffic to prove anything, so I'd rather do it as a follow-up once the lab case has a baseline.

@privateip
privateip requested review from a team and ecv November 30, 2026 14:30

@ecv ecv left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve.

The hold is met. GALACTIC_GATEWAY_LOCAL_DELIVERY defaults to false, and while it is off the gateway never reports status.localDelivery, so core keeps leaving that node's backends out, as it does for an older gateway. Only the lab overlay turns it on. Turning it off rolls it back on the next status write.

  • 1b6b059 adds the root BPF case where the backend uSID shares the first 64 bits but differs after them, pinning the comparison width.
  • The config default, flag and env binding are tested in internal/config/gateway_test.go.

Follow-ups:

  • Turn the switch on for a deployment only after the lab local-delivery case (both families, TCP and UDP) has passed; it is still the only check of usid_ingress delivering the handed-up packet.
  • Consider tying localDelivery to local_deliveries and usid_ingress counters moving together, so a filter that is attached but not decapsulating does not report true.

@privateip
privateip merged commit c504549 into main Nov 30, 2026
28 checks passed
@privateip
privateip deleted the fix/issue-1526 branch November 30, 2026 14:44
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.

Deliver gateway VIP flows to a backend on the gateway's own node

2 participants