ipn/ipnlocal: route extra WireGuard AllowedIPs through the route manager
The conn25 extension's ExtraWireGuardAllowedIPs hook (Transit IPs) was only appended to wgcfg.Config.Peers in authReconfig. Now that outbound peer selection comes from the route manager's outbound table via the engine's PeerByIPPacketFunc (which, when installed, replaces wireguard-go's AllowedIPs trie lookup entirely) and lazily created peers get their allowed IPs from the route manager via the engine's peer config func, those extras never reached either path: outbound packets to Transit IPs matched no peer, and lazily created peers didn't accept inbound Transit IP sources. Teach the route manager a per-peer set of extra allowed IPs, staged by Mutation.SetExtraAllowedIPs. They appear in the outbound table and in PeerAllowedIPs (so both outbound routing and per-peer allowed source prefixes see them) but are excluded from the OS route set, preserving the hook's contract that the extras reach WireGuard but not the OS routing table. authReconfig now feeds the hook's results into the route manager and incrementally syncs any changed peers to the WireGuard device; the append to cfg.Peers remains only so Reconfig's full per-peer device sync doesn't strip the extras from active peers, and goes away with Config.Peers. Updates #12542 Change-Id: I06c8fa30929fbf8fe171a2d34c47c6fcc3abfa16 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
committed by
Brad Fitzpatrick
parent
aff605d163
commit
6a635c4e55
+15
-2
@@ -6155,10 +6155,23 @@ func (b *LocalBackend) authReconfigLocked() {
|
||||
}
|
||||
rcfg := b.routerConfigLocked(cfg, prefs, nm)
|
||||
|
||||
// Add these extra Allowed IPs after router configuration, because the expected
|
||||
// extension (features/conn25), does not want these routes installed on the OS.
|
||||
// Push each peer's extra WireGuard-only allowed IPs (the conn25
|
||||
// extension's Transit IPs) into the route manager, which feeds
|
||||
// them to WireGuard via the outbound peer lookup and the per-peer
|
||||
// allowed source prefixes (including for lazily created peers)
|
||||
// while keeping them out of the OS route set, because the
|
||||
// expected extension (features/conn25) does not want these routes
|
||||
// installed on the OS. This runs after routerConfigLocked above
|
||||
// for the same reason: rcfg is derived from cfg.Peers, which must
|
||||
// not yet include the extras.
|
||||
// See also [Hooks.ExtraWireGuardAllowedIPs].
|
||||
if extraAllowedIPsFn, ok := b.extHost.hooks.ExtraWireGuardAllowedIPs.GetOk(); ok {
|
||||
for k := range cn.updateRouteManagerExtras(extraAllowedIPsFn) {
|
||||
b.e.SyncDevicePeer(k)
|
||||
}
|
||||
// Also append the extras to cfg.Peers so the full SyncPeers
|
||||
// in Reconfig below doesn't strip them from active peers.
|
||||
// This loop goes away when cfg.Peers does.
|
||||
for i := range cfg.Peers {
|
||||
extras := extraAllowedIPsFn(cfg.Peers[i].PublicKey)
|
||||
cfg.Peers[i].AllowedIPs = extras.AppendTo(cfg.Peers[i].AllowedIPs)
|
||||
|
||||
Reference in New Issue
Block a user