policy/v2: pin exit routes out of UsePrimary

Exit routes have no HA election; UsePrimary could only drop them.

Updates #3562
This commit is contained in:
Kristoffer Dalby committed 2026-11-05 12:32:04 +01:00
1 parent 6a1f8d1579
commit fc10729278
3 files changed
+9 -2

No files matched your search

+4
View File
@@ -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),
+2 -1
View File
@@ -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) &&
+3 -1
View File
@@ -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
}