feature/conn25,ipn/ipnext,ipn/ipnlocal: add ExtraRouterConfigRoutes hook
conn25 needs to add routes to the operating system to direct handling of the addresses in the magic IP range to the tailscale0 TUN and tailscaled. The way we do this for exit nodes and VIP services is that we add routes to the Routes field of router.Config, and then the config is passed to the WireGuard engine Reconfig. conn25 is implemented as an ipnext.Extension and so this commit adds a hook to ipnext.Hooks to allow any extension to provide routes to the config. The hook if provided is called in routerConfigLocked, similarly to exit nodes and VIP services. Fixes tailscale/corp#38123 Signed-off-by: Fran Bull <fran@tailscale.com>
This commit is contained in:
@@ -418,6 +418,18 @@ type Hooks struct {
|
||||
// new hooks that fit into the new architecture that make use of new
|
||||
// WireGuard APIs.
|
||||
ExtraWireGuardAllowedIPs feature.Hook[func(key.NodePublic) views.Slice[netip.Prefix]]
|
||||
|
||||
// ExtraRouterConfigRoutes returns a view of prefixes to append to [router.Config.Routes].
|
||||
//
|
||||
// Routes goes through the WireGuard engine which makes efforts to avoid
|
||||
// unnecessary reconfiguration by checking that things have actually changed.
|
||||
// So implementors should make sure that the order of the prefixes is stable
|
||||
// and that we don't have duplicate entries.
|
||||
//
|
||||
// The returned slice should not be mutated by the extension after it is returned.
|
||||
//
|
||||
// The hook is called with LocalBackend's mutex locked.
|
||||
ExtraRouterConfigRoutes feature.Hook[func() views.Slice[netip.Prefix]]
|
||||
}
|
||||
|
||||
// FilterHooks contains hooks that extensions can use to customize the packet
|
||||
|
||||
@@ -5667,6 +5667,11 @@ func (b *LocalBackend) routerConfigLocked(cfg *wgcfg.Config, prefs ipn.PrefsView
|
||||
}
|
||||
}
|
||||
|
||||
// Get any extra Routes an extension may want installed.
|
||||
if extensionRoutesFx, ok := b.extHost.hooks.ExtraRouterConfigRoutes.GetOk(); ok {
|
||||
rs.Routes = extensionRoutesFx().AppendTo(rs.Routes)
|
||||
}
|
||||
|
||||
return rs
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user