promote local routes recording to be before editprefs to avoid calling it when we didn't want to.

This commit is contained in:
Kevin Liang 2024-03-15 20:03:22 +00:00
parent 34b49b5793
commit 4d40443ccd
2 changed files with 13 additions and 7 deletions

View File

@ -3137,6 +3137,18 @@ func (b *LocalBackend) checkFunnelEnabledLocked(p *ipn.Prefs) error {
return nil
}
func (b *LocalBackend) PatchPrefsHandler(mp *ipn.MaskedPrefs) (ipn.PrefsView, error) {
// 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()
if mp.AdvertiseRoutesSet {
routeInfo.Local = mp.AdvertiseRoutes
b.pm.SetCurrentRoutes(routeInfo)
//newp.AdvertiseRoutes = b.pm.CurrentRoutes.AsArray() (sort of thing)
}
return b.EditPrefs(mp)
}
func (b *LocalBackend) EditPrefs(mp *ipn.MaskedPrefs) (ipn.PrefsView, error) {
b.mu.Lock()
if mp.EggSet {
@ -3224,12 +3236,6 @@ 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

View File

@ -1378,7 +1378,7 @@ func (h *Handler) servePrefs(w http.ResponseWriter, r *http.Request) {
return
}
var err error
prefs, err = h.b.EditPrefs(mp)
prefs, err = h.b.PatchPrefsHandler(mp)
if err != nil {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusBadRequest)