Repository navigation
feat(gateway): Deliver load-balanced flows to a backend on the same node - #1527
Conversation
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.
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.
|
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
left a comment
There was a problem hiding this comment.
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_localcompares the first 64 bits of the backend uSID withencap_src; on no match,resolve_fib_and_write_ethruns with the same arguments as before.TestEdgeLB_RemoteBackendIsNotLocalpins that a remote backend never counts as local. - Older gateways:
status.localDeliveryisomitempty, 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
localDeliverytolocal_deliveriesandusid_ingresscounters moving together. - Add a root BPF case where
encap_srcand 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.
|
Took the off-by-default route in 1b6b059 and c48b58a:
Not done here: tying |
ecv
left a comment
There was a problem hiding this comment.
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.
1b6b059adds 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_ingressdelivering the handed-up packet. - Consider tying
localDeliverytolocal_deliveriesandusid_ingresscounters moving together, so a filter that is attached but not decapsulating does not report true.
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.localDeliveryonly withGALACTIC_GATEWAY_LOCAL_DELIVERY=true, and then only once its SRv6 address is the node's locator address andusid_ingressis attached to its public interface. Core serves a listener backend on a gateway's node only while that gateway reports it and isReady. 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
task lint,task buildandtask test:unitpass, plus the listener and controller envtests