ipn/ipnlocal: simplify pickNewAutoExitNode

(*profileManager).CurrentPrefs() is always valid. Additionally, there's no value in cloning
and passing the full ipn.Prefs when editing preferences. Instead, ipn.MaskedPrefs should
only have ExitNodeID set.

Updates tailscale/corp#29969

Signed-off-by: Nick Khyl <nickk@tailscale.com>
This commit is contained in:
Nick Khyl
2025-07-02 19:16:39 -05:00
committed by Nick Khyl
parent 1a2185b1ee
commit 56d772bd63

View File

@@ -5835,23 +5835,16 @@ func (b *LocalBackend) pickNewAutoExitNode() {
unlock := b.lockAndGetUnlock()
defer unlock()
prefs := b.pm.CurrentPrefs()
if !prefs.Valid() {
b.logf("[unexpected]: received tailnet exit node ID pref change callback but current prefs are nil")
return
}
prefsClone := prefs.AsStruct()
newSuggestion, err := b.suggestExitNodeLocked(nil)
if err != nil {
b.logf("setAutoExitNodeID: %v", err)
return
}
if prefsClone.ExitNodeID == newSuggestion.ID {
if b.pm.CurrentPrefs().ExitNodeID() == newSuggestion.ID {
return
}
prefsClone.ExitNodeID = newSuggestion.ID
_, err = b.editPrefsLockedOnEntry(&ipn.MaskedPrefs{
Prefs: *prefsClone,
Prefs: ipn.Prefs{ExitNodeID: newSuggestion.ID},
ExitNodeIDSet: true,
}, unlock)
if err != nil {