From fc10729278a5520e5ecb2b4d97f2214fe959c7dc Mon Sep 17 00:00:00 2001 From: Kristoffer Dalby Date: Wed, 4 Nov 2026 12:49:35 +0000 Subject: [PATCH] policy/v2: pin exit routes out of UsePrimary Exit routes have no HA election; UsePrimary could only drop them. Updates #3562 --- hscontrol/policy/v2/issue_3233_test.go | 4 ++++ hscontrol/policy/v2/policy.go | 3 ++- hscontrol/types/node.go | 4 +++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/hscontrol/policy/v2/issue_3233_test.go b/hscontrol/policy/v2/issue_3233_test.go index 7de1c48d5..3a9ee4d37 100644 --- a/hscontrol/policy/v2/issue_3233_test.go +++ b/hscontrol/policy/v2/issue_3233_test.go @@ -207,6 +207,10 @@ func TestViaInternetExitSteeringSurvivesUnrelatedRules(t *testing.T) { viaPeer := pm.ViaRoutesForPeer(aliceLaptop.View(), exitA.View()) require.Contains(t, viaPeer.Include, tsaddr.AllIPv4()) + for _, p := range exitRoutes { + require.NotContains(t, viaPeer.UsePrimary, p) + } + other := pm.ViaRoutesForPeer(aliceLaptop.View(), exitB.View()) for _, p := range exitRoutes { require.Equal(t, tt.wantExcluded, slices.Contains(other.Exclude, p), diff --git a/hscontrol/policy/v2/policy.go b/hscontrol/policy/v2/policy.go index 2eb275f82..5450cec4d 100644 --- a/hscontrol/policy/v2/policy.go +++ b/hscontrol/policy/v2/policy.go @@ -1838,7 +1838,8 @@ func (pm *PolicyManager) ViaRoutesForPeer(viewer, peer types.NodeView) types.Via // A non-via grant covering routes that a via grant included // defers to global HA primary election. Match by overlap so // a broader or narrower regular dst still catches the - // routes the via grant added to Include. + // routes the via grant added to Include. Exit routes have no + // election, so deferring would only drop them. for _, dstPrefix := range resolvedDstPrefixes[i] { for _, p := range result.Include { if !tsaddr.IsExitRoute(p) && dstPrefix.Overlaps(p) && diff --git a/hscontrol/types/node.go b/hscontrol/types/node.go index 1ed99a2ce..81271548b 100644 --- a/hscontrol/types/node.go +++ b/hscontrol/types/node.go @@ -72,12 +72,14 @@ type ViaRouteResult struct { // Include contains prefixes this peer should serve to this viewer (via-designated). Include []netip.Prefix // Exclude contains prefixes steered to OTHER peers (suppress from global primary). + // Two via grants can list one prefix in both; Include wins. Exclude []netip.Prefix // UsePrimary contains prefixes from [ViaRouteResult.Include] where a regular // (non-via) grant also covers the prefix. In these cases HA // primary election wins — only the primary router should get // the route in [tailcfg.Node.AllowedIPs]. When a prefix is NOT in [ViaRouteResult.UsePrimary], - // per-viewer via steering applies. + // per-viewer via steering applies. Exit routes have no election, so + // they are never here. UsePrimary []netip.Prefix }