diff --git a/control/controlclient/direct.go b/control/controlclient/direct.go index 84d14d67b..99d46ffb8 100644 --- a/control/controlclient/direct.go +++ b/control/controlclient/direct.go @@ -1129,8 +1129,17 @@ func (c *Direct) sendMapRequest(ctx context.Context, maxPolls int, readOnly bool c.lastPrintMap = now c.logf("[v1] new network map[%d]:\n%s", i, nm.VeryConcise()) } + newPersist := persist.AsStruct() + newPersist.NodeID = nm.SelfNode.StableID + newPersist.UserProfile = nm.UserProfiles[nm.User] c.mu.Lock() + // If we are the ones who last updated persist, then we can update it + // again. Otherwise, we should not touch it. + if persist == c.persist { + c.persist = newPersist.View() + persist = c.persist + } c.expiry = &nm.Expiry c.mu.Unlock() diff --git a/ipn/ipnlocal/local.go b/ipn/ipnlocal/local.go index 2d23761f2..10b18a88c 100644 --- a/ipn/ipnlocal/local.go +++ b/ipn/ipnlocal/local.go @@ -1009,13 +1009,8 @@ func (b *LocalBackend) setClientStatus(st controlclient.Status) { } // Perform all mutations of prefs based on the netmap here. - if st.NetMap != nil { - if b.updatePersistFromNetMapLocked(st.NetMap, prefs) { - prefsChanged = true - } - } - // Prefs will be written out if stale; this is not safe unless locked or cloned. if prefsChanged { + // Prefs will be written out if stale; this is not safe unless locked or cloned. if err := b.pm.SetPrefs(prefs.View()); err != nil { b.logf("Failed to save new controlclient state: %v", err) } @@ -3962,28 +3957,9 @@ func hasCapability(nm *netmap.NetworkMap, cap string) bool { return false } -func (b *LocalBackend) updatePersistFromNetMapLocked(nm *netmap.NetworkMap, prefs *ipn.Prefs) (changed bool) { - if nm == nil || nm.SelfNode == nil { - return - } - up := nm.UserProfiles[nm.User] - if prefs.Persist.UserProfile.ID != up.ID { - // If the current profile doesn't match the - // network map's user profile, then we need to - // update the persisted UserProfile to match. - prefs.Persist.UserProfile = up - changed = true - } - if prefs.Persist.NodeID == "" { - // If the current profile doesn't have a NodeID, - // then we need to update the persisted NodeID to - // match. - prefs.Persist.NodeID = nm.SelfNode.StableID - changed = true - } - return changed -} - +// setNetMapLocked updates the LocalBackend state to reflect the newly +// received nm. If nm is nil, it resets all configuration as though +// Tailscale is turned off. func (b *LocalBackend) setNetMapLocked(nm *netmap.NetworkMap) { b.dialer.SetNetMap(nm) var login string