From 6a92f86aceb2c1e5067eef53699c99fbbfbd4a2d Mon Sep 17 00:00:00 2001 From: Michael Ben-Ami Date: Mon, 16 Nov 2026 16:15:18 -0500 Subject: [PATCH] ipn/{ipnext,ipnlocal}: pass only node IDs to the ExtraWireGuardAllowedIPs hook The hook was given (node ID, node key) pairs, but its result is keyed by node ID, and its only implementation, conn25, now tracks connector transit IPs by node ID too. Drop the node key from the sequence. Updates tailscale/corp#51237 Signed-off-by: Michael Ben-Ami --- feature/conn25/conn25.go | 3 +-- ipn/ipnext/ipnext.go | 10 +++++----- ipn/ipnlocal/node_backend.go | 10 +++++----- ipn/ipnlocal/node_backend_test.go | 8 ++++---- 4 files changed, 15 insertions(+), 16 deletions(-) diff --git a/feature/conn25/conn25.go b/feature/conn25/conn25.go index 9b72c2b82..b1e5efe98 100644 --- a/feature/conn25/conn25.go +++ b/feature/conn25/conn25.go @@ -42,7 +42,6 @@ import ( "tailscale.com/tstime" "tailscale.com/types/appctype" "tailscale.com/types/dnstype" - "tailscale.com/types/key" "tailscale.com/types/logger" "tailscale.com/types/views" "tailscale.com/util/clientmetric" @@ -287,7 +286,7 @@ func (e *extension) installHooks(dph *datapathHandler) error { }) // Tell WireGuard what Transit IPs belong to which connector peers. - e.host.Hooks().ExtraWireGuardAllowedIPs.Set(func(peers iter.Seq2[tailcfg.NodeID, key.NodePublic]) map[tailcfg.NodeID][]netip.Prefix { + e.host.Hooks().ExtraWireGuardAllowedIPs.Set(func(peers iter.Seq[tailcfg.NodeID]) map[tailcfg.NodeID][]netip.Prefix { if !e.conn25.isConfigured() { return nil } diff --git a/ipn/ipnext/ipnext.go b/ipn/ipnext/ipnext.go index 9c00451b2..967b57fc7 100644 --- a/ipn/ipnext/ipnext.go +++ b/ipn/ipnext/ipnext.go @@ -22,7 +22,6 @@ import ( "tailscale.com/tsd" "tailscale.com/tstime" "tailscale.com/types/dnstype" - "tailscale.com/types/key" "tailscale.com/types/logger" "tailscale.com/types/mapx" "tailscale.com/types/netmap" @@ -466,9 +465,10 @@ type Hooks struct { // See [filter.Filter] for details on how these hooks are invoked. Filter FilterHooks - // ExtraWireGuardAllowedIPs is called with a sequence of peers whose - // extra AllowedIPs the caller wants (re)computed, and returns - // prefixes to append to those peers' AllowedIPs, keyed by node ID. + // ExtraWireGuardAllowedIPs is called with a sequence of the node IDs + // of peers whose extra AllowedIPs the caller wants (re)computed, and + // returns prefixes to append to those peers' AllowedIPs, keyed by + // node ID. // // The sequence is not necessarily all peers: callers may pass any // subset (such as only the peers changed by a netmap delta), and @@ -500,7 +500,7 @@ type Hooks struct { // TODO(#17858): This hook may not be needed and can possibly be replaced by // new hooks that fit into the new architecture that make use of new // WireGuard APIs. - ExtraWireGuardAllowedIPs feature.Hook[func(peers iter.Seq2[tailcfg.NodeID, key.NodePublic]) map[tailcfg.NodeID][]netip.Prefix] + ExtraWireGuardAllowedIPs feature.Hook[func(peers iter.Seq[tailcfg.NodeID]) map[tailcfg.NodeID][]netip.Prefix] // ExtraRouterConfigRoutes returns a view of prefixes to append to [router.Config.Routes]. // diff --git a/ipn/ipnlocal/node_backend.go b/ipn/ipnlocal/node_backend.go index 7766ddd12..f7a2537c3 100644 --- a/ipn/ipnlocal/node_backend.go +++ b/ipn/ipnlocal/node_backend.go @@ -1014,16 +1014,16 @@ func (nb *nodeBackend) updateRouteManagerPrefs(p routePrefs) routemanager.PeersW // updateRouteManagerExtras pushes extra WireGuard-only allowed IPs // into the route manager, obtained by calling fn (the // [ipnext.Hooks.ExtraWireGuardAllowedIPs] hook) with a sequence of -// the current peers. +// the current peers' node IDs. // // It returns the peers whose allowed source prefixes changed as a // result. -func (nb *nodeBackend) updateRouteManagerExtras(fn func(peers iter.Seq2[tailcfg.NodeID, key.NodePublic]) map[tailcfg.NodeID][]netip.Prefix) routemanager.PeersWithRouteChanges { +func (nb *nodeBackend) updateRouteManagerExtras(fn func(peers iter.Seq[tailcfg.NodeID]) map[tailcfg.NodeID][]netip.Prefix) routemanager.PeersWithRouteChanges { nb.mu.Lock() defer nb.mu.Unlock() - extras := fn(func(yield func(tailcfg.NodeID, key.NodePublic) bool) { - for id, p := range nb.peers { - if !yield(id, p.Key()) { + extras := fn(func(yield func(tailcfg.NodeID) bool) { + for id := range nb.peers { + if !yield(id) { return } } diff --git a/ipn/ipnlocal/node_backend_test.go b/ipn/ipnlocal/node_backend_test.go index d3aefd4de..ab042043f 100644 --- a/ipn/ipnlocal/node_backend_test.go +++ b/ipn/ipnlocal/node_backend_test.go @@ -652,10 +652,10 @@ func TestNodeBackendRouteManagerExtras(t *testing.T) { nb.SetNetMap(&netmap.NetworkMap{Peers: []tailcfg.NodeView{p1}}) transit := netip.MustParsePrefix("fe80::1234/128") - extrasFor := func(peers iter.Seq2[tailcfg.NodeID, key.NodePublic]) map[tailcfg.NodeID][]netip.Prefix { + extrasFor := func(peers iter.Seq[tailcfg.NodeID]) map[tailcfg.NodeID][]netip.Prefix { var extras map[tailcfg.NodeID][]netip.Prefix - for id, k := range peers { - if k == p1.Key() { + for id := range peers { + if id == p1.ID() { mak.Set(&extras, id, []netip.Prefix{transit}) } } @@ -681,7 +681,7 @@ func TestNodeBackendRouteManagerExtras(t *testing.T) { } // A hook that no longer returns extras removes them. - changed = nb.updateRouteManagerExtras(func(iter.Seq2[tailcfg.NodeID, key.NodePublic]) map[tailcfg.NodeID][]netip.Prefix { + changed = nb.updateRouteManagerExtras(func(iter.Seq[tailcfg.NodeID]) map[tailcfg.NodeID][]netip.Prefix { return nil }) if len(changed) != 1 {