mirror of
https://github.com/tailscale/tailscale.git
synced 2026-11-20 00:31:17 -08:00
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 <[email protected]>
This commit is contained in:
1 parent
90feb626cd
commit
6a92f86ace
4 files changed
+15
-16
No files matched your search
@@ -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
|
||||
}
|
||||
|
||||
@@ -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].
|
||||
//
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in new issue
Block a user