ipn: remove enforceDefaults option from PrefsFromBytes

The Mac client was using it, but it had the effect of the `RouteAll`
("Use Tailscale subnets") pref always being enabled at startup,
regardless of the persisted value.

enforceDefaults was added to handle cases from ~2 years ago where
we ended up with persisted `"RouteAll": false` values in the keychain,
but that should no longer be a concern. New users will get the default
of it being enabled via `NewPrefs`.

There will be a corresponding Mac client change to stop passing in
enforceDefaults.

For #3962

Signed-off-by: Mihai Parparita <mihai@tailscale.com>
pull/4580/head
Mihai Parparita 3 years ago committed by GitHub
parent 87ba528ae0
commit 316523cc1e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1617,7 +1617,7 @@ func (b *LocalBackend) loadStateLocked(key ipn.StateKey, prefs *ipn.Prefs) (err
case err != nil:
return fmt.Errorf("backend prefs: store.ReadState(%q): %v", key, err)
}
b.prefs, err = ipn.PrefsFromBytes(bs, false)
b.prefs, err = ipn.PrefsFromBytes(bs)
if err != nil {
b.logf("using backend prefs for %q", key)
return fmt.Errorf("PrefsFromBytes: %v", err)

@ -584,10 +584,8 @@ func (p *Prefs) SetExitNodeIP(s string, st *ipnstate.Status) error {
return err
}
// PrefsFromBytes deserializes Prefs from a JSON blob. If
// enforceDefaults is true, Prefs.RouteAll and Prefs.AllowSingleHosts
// are forced on.
func PrefsFromBytes(b []byte, enforceDefaults bool) (*Prefs, error) {
// PrefsFromBytes deserializes Prefs from a JSON blob.
func PrefsFromBytes(b []byte) (*Prefs, error) {
p := NewPrefs()
if len(b) == 0 {
return p, nil
@ -603,10 +601,6 @@ func PrefsFromBytes(b []byte, enforceDefaults bool) (*Prefs, error) {
log.Printf("Prefs parse: %v: %v\n", err, b)
}
}
if enforceDefaults {
p.RouteAll = true
p.AllowSingleHosts = true
}
return p, err
}
@ -625,7 +619,7 @@ func LoadPrefs(filename string) (*Prefs, error) {
// to log in again. (better than crashing)
return nil, os.ErrNotExist
}
p, err := PrefsFromBytes(data, false)
p, err := PrefsFromBytes(data)
if err != nil {
return nil, fmt.Errorf("LoadPrefs(%q) decode: %w", filename, err)
}

@ -302,7 +302,7 @@ func checkPrefs(t *testing.T, p Prefs) {
if p.Equals(p2) {
t.Fatalf("p == p2\n")
}
p2b, err = PrefsFromBytes(p2.ToBytes(), false)
p2b, err = PrefsFromBytes(p2.ToBytes())
if err != nil {
t.Fatalf("PrefsFromBytes(p2) failed\n")
}

Loading…
Cancel
Save