mirror of
https://github.com/tailscale/tailscale.git
synced 2026-11-25 19:21:18 -08:00
ipn/ipnlocal: reconcile blueprint routes into AdvertiseRoutes
When the netmap's SelfNode carries a BlueprintConfig with non-empty Routes, treat those routes as the source of truth for the local Prefs.AdvertiseRoutes. tailscale set --advertise-routes is already rejected for blueprint-bound nodes (see cmd/tailscale/cli/blueprint_lock.go) so the prefs slot is effectively under the blueprint's control; rewriting it from the netmap is the right thing to do. Reconciliation runs at the tail of setNetMapLocked. When it spots a delta, it persists the new prefs via b.pm.SetPrefs, refreshes b.hostinfo through the existing applyPrefsToHostinfoLocked path, and pushes the new Hostinfo to controlclient via doSetHostinfoFilterServices. The result is that the admin Machines page sees the freshly-advertised subnets within one map-poll of an ACL save touching the blueprint's serves.ipsets -- no leave/rejoin required. Updates #cleanup Signed-off-by: Kabir Sikand <[email protected]>
This commit is contained in:
1 parent
0fdc0dc6c9
commit
6d016c0c33
1 file changed
+58
@@ -6717,6 +6717,64 @@ func (b *LocalBackend) setNetMapLocked(nm *netmap.NetworkMap) {
|
||||
b.discardDiskCacheLocked()
|
||||
}
|
||||
}
|
||||
|
||||
// For blueprint-bound nodes, the control plane sends the
|
||||
// blueprint's projected AdvertiseRoutes inside Node.BlueprintConfig.
|
||||
// Reconcile our local prefs against that projection so the next
|
||||
// Hostinfo we send back upstream reports the right RoutableIPs.
|
||||
// tailscale set --advertise-routes is rejected on bound nodes (see
|
||||
// cmd/tailscale/cli/blueprint_lock.go) so overwriting prefs here
|
||||
// does not stomp on user intent.
|
||||
b.reconcileBlueprintRoutesLocked(nm)
|
||||
}
|
||||
|
||||
// reconcileBlueprintRoutesLocked syncs Prefs.AdvertiseRoutes with the
|
||||
// BlueprintConfig.Routes carried by the netmap's SelfNode for a
|
||||
// blueprint-bound node. It is a no-op for non-bound nodes or when the
|
||||
// routes already match. On a change it persists the new prefs,
|
||||
// refreshes Hostinfo, and asks controlclient to push the updated
|
||||
// Hostinfo so the route advertisement reaches the server without
|
||||
// waiting for the next external prefs edit.
|
||||
//
|
||||
// b.mu must be held.
|
||||
func (b *LocalBackend) reconcileBlueprintRoutesLocked(nm *netmap.NetworkMap) {
|
||||
if nm == nil || !nm.SelfNode.Valid() {
|
||||
return
|
||||
}
|
||||
cfg := nm.SelfNode.BlueprintConfig()
|
||||
if !cfg.Valid() {
|
||||
return
|
||||
}
|
||||
want := cfg.Routes().AsSlice()
|
||||
cur := b.pm.CurrentPrefs()
|
||||
if slicesEqualPrefixes(cur.AdvertiseRoutes().AsSlice(), want) {
|
||||
return
|
||||
}
|
||||
newp := cur.AsStruct()
|
||||
newp.AdvertiseRoutes = append([]netip.Prefix(nil), want...)
|
||||
b.logf("blueprint %q: reconciled AdvertiseRoutes from BlueprintConfig (%d route(s))",
|
||||
cur.BlueprintID(), len(want))
|
||||
if err := b.pm.SetPrefs(newp.View(), b.pm.CurrentProfile().NetworkProfile()); err != nil {
|
||||
b.logf("blueprint reconcile: persist prefs: %v", err)
|
||||
return
|
||||
}
|
||||
if b.hostinfo == nil {
|
||||
b.hostinfo = new(tailcfg.Hostinfo)
|
||||
}
|
||||
b.applyPrefsToHostinfoLocked(b.hostinfo, newp.View())
|
||||
b.goTracker.Go(b.doSetHostinfoFilterServices)
|
||||
}
|
||||
|
||||
func slicesEqualPrefixes(a, b []netip.Prefix) bool {
|
||||
if len(a) != len(b) {
|
||||
return false
|
||||
}
|
||||
for i := range a {
|
||||
if a[i] != b[i] {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
var hookSetNetMapLockedDrive feature.Hook[func(*LocalBackend, *netmap.NetworkMap)]
|
||||
|
||||
Reference in new issue
Block a user