From 7fa9bf10dd12b668a43e1b01b9dede31d9327616 Mon Sep 17 00:00:00 2001 From: Fran Bull Date: Fri, 15 Mar 2024 11:39:10 -0700 Subject: [PATCH] update currentRoutes when set is used on tailscale cli --- ipn/ipnlocal/local.go | 7 +++++++ ipn/ipnlocal/profiles.go | 9 +++++++++ 2 files changed, 16 insertions(+) diff --git a/ipn/ipnlocal/local.go b/ipn/ipnlocal/local.go index 8a5736b6f..6c89e7a9e 100644 --- a/ipn/ipnlocal/local.go +++ b/ipn/ipnlocal/local.go @@ -3223,6 +3223,13 @@ func (b *LocalBackend) setPrefsLockedOnEntry(caller string, newp *ipn.Prefs) ipn if oldp.Valid() { newp.Persist = oldp.Persist().AsStruct() // caller isn't allowed to override this } + // we believe that for the purpose of figuring out advertisedRoutes setPrefsLockedOnEntry is _only_ called when + // up or set is used on the tailscale cli _not_ when we calculate the new advertisedRoutes field. + routeInfo := b.pm.CurrentRoutes() + routeInfo.Local = newp.AdvertiseRoutes + b.pm.SetCurrentRoutes(routeInfo) + //newp.AdvertiseRoutes = b.pm.CurrentRoutes.AsArray() (sort of thing) + // setExitNodeID returns whether it updated b.prefs, but // everything in this function treats b.prefs as completely new // anyway. No-op if no exit node resolution is needed. diff --git a/ipn/ipnlocal/profiles.go b/ipn/ipnlocal/profiles.go index 335d63930..befed45a5 100644 --- a/ipn/ipnlocal/profiles.go +++ b/ipn/ipnlocal/profiles.go @@ -47,6 +47,15 @@ func (pm *profileManager) dlogf(format string, args ...any) { pm.logf(format, args...) } +func (pm *profileManager) CurrentRoutes() *ipn.RouteInfo { + return pm.currentRoutes +} + +func (pm *profileManager) SetCurrentRoutes(in *ipn.RouteInfo) error { + pm.currentRoutes = in + return pm.WriteRoutesForCurrentProfile() +} + func (pm *profileManager) WriteState(id ipn.StateKey, val []byte) error { return ipn.WriteState(pm.store, id, val) }