From 4f4e84236a050479c2f236bab5915707c48629e3 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Wed, 4 Nov 2020 10:24:33 -0800 Subject: [PATCH] ipn: clean up Prefs logging at start Signed-off-by: Brad Fitzpatrick --- control/controlclient/direct.go | 9 +++++++-- ipn/local.go | 15 +++++++++------ ipn/prefs.go | 6 ++++++ ipn/prefs_test.go | 26 ++++++++++++++++++++++++++ 4 files changed, 48 insertions(+), 8 deletions(-) diff --git a/control/controlclient/direct.go b/control/controlclient/direct.go index 97d45d2d2..ef32789b9 100644 --- a/control/controlclient/direct.go +++ b/control/controlclient/direct.go @@ -91,9 +91,14 @@ func (p *Persist) Pretty() string { if !p.PrivateNodeKey.IsZero() { nk = p.PrivateNodeKey.Public() } + ss := func(k wgcfg.Key) string { + if k.IsZero() { + return "" + } + return k.ShortString() + } return fmt.Sprintf("Persist{lm=%v, o=%v, n=%v u=%#v}", - mk.ShortString(), ok.ShortString(), nk.ShortString(), - p.LoginName) + ss(mk), ss(ok), ss(nk), p.LoginName) } // Direct is the client that connects to a tailcontrol server for a node. diff --git a/ipn/local.go b/ipn/local.go index dcbff9857..ad11fe202 100644 --- a/ipn/local.go +++ b/ipn/local.go @@ -419,7 +419,9 @@ func (b *LocalBackend) Start(opts Options) error { b.serverURL = b.prefs.ControlURL hostinfo.RoutableIPs = append(hostinfo.RoutableIPs, b.prefs.AdvertiseRoutes...) hostinfo.RequestTags = append(hostinfo.RequestTags, b.prefs.AdvertiseTags...) - b.logf("Start: serverMode=%v; stateKey=%q; tags=%q; routes=%v; url=%v", b.inServerMode, b.stateKey, b.prefs.AdvertiseTags, b.prefs.AdvertiseRoutes, b.prefs.ControlURL) + if b.inServerMode || runtime.GOOS == "windows" { + b.logf("Start: serverMode=%v", b.inServerMode) + } applyPrefsToHostinfo(hostinfo, b.prefs) b.notify = opts.Notify @@ -827,7 +829,7 @@ func (b *LocalBackend) loadStateLocked(key StateKey, prefs *Prefs, legacyPath st // If the frontend (e.g. on Windows) supplied the // optional/legacy machine key then it's used as the // value instead of making up a new one. - b.logf("Using frontend prefs") + b.logf("using frontend prefs: %s", prefs.Pretty()) b.prefs = prefs.Clone() if err := b.initMachineKeyLocked(); err != nil { return fmt.Errorf("initMachineKeyLocked: %w", err) @@ -839,13 +841,13 @@ func (b *LocalBackend) loadStateLocked(key StateKey, prefs *Prefs, legacyPath st if prefs != nil { // Backend owns the state, but frontend is trying to migrate // state into the backend. - b.logf("Importing frontend prefs into backend store") + b.logf("importing frontend prefs into backend store; frontend prefs: %s", prefs.Pretty()) if err := b.store.WriteState(key, prefs.ToBytes()); err != nil { return fmt.Errorf("store.WriteState: %v", err) } } - b.logf("Using backend prefs") + b.logf("using backend prefs") bs, err := b.store.ReadState(key) if err != nil { if errors.Is(err, ErrStateNotExist) { @@ -857,11 +859,11 @@ func (b *LocalBackend) loadStateLocked(key StateKey, prefs *Prefs, legacyPath st } b.prefs = NewPrefs() } else { - b.logf("Imported state from relaynode for %q", key) + b.logf("imported prefs from relaynode for %q: %v", key, b.prefs.Pretty()) } } else { b.prefs = NewPrefs() - b.logf("Created empty state for %q", key) + b.logf("created empty state for %q: %s", key, b.prefs.Pretty()) } if err := b.initMachineKeyLocked(); err != nil { return fmt.Errorf("initMachineKeyLocked: %w", err) @@ -874,6 +876,7 @@ func (b *LocalBackend) loadStateLocked(key StateKey, prefs *Prefs, legacyPath st if err != nil { return fmt.Errorf("PrefsFromBytes: %v", err) } + b.logf("backend prefs for %q: %s", key, b.prefs.Pretty()) if err := b.initMachineKeyLocked(); err != nil { return fmt.Errorf("initMachineKeyLocked: %w", err) } diff --git a/ipn/prefs.go b/ipn/prefs.go index 8c1457e37..f3b63eeed 100644 --- a/ipn/prefs.go +++ b/ipn/prefs.go @@ -152,9 +152,15 @@ func (p *Prefs) pretty(goos string) string { if len(p.AdvertiseRoutes) > 0 || p.NoSNAT { fmt.Fprintf(&sb, "snat=%v ", !p.NoSNAT) } + if len(p.AdvertiseTags) > 0 { + fmt.Fprintf(&sb, "tags=%s ", strings.Join(p.AdvertiseTags, ",")) + } if goos == "linux" { fmt.Fprintf(&sb, "nf=%v ", p.NetfilterMode) } + if p.ControlURL != "" && p.ControlURL != "https://login.tailscale.com" { + fmt.Fprintf(&sb, "url=%q ", p.ControlURL) + } if p.Persist != nil { sb.WriteString(p.Persist.Pretty()) } else { diff --git a/ipn/prefs_test.go b/ipn/prefs_test.go index 21e8e7b44..8b95d87a4 100644 --- a/ipn/prefs_test.go +++ b/ipn/prefs_test.go @@ -326,6 +326,32 @@ func TestPrefsPretty(t *testing.T) { "windows", "Prefs{ra=false dns=false want=true server=true Persist=nil}", }, + { + Prefs{ + AllowSingleHosts: true, + WantRunning: true, + ControlURL: "http://localhost:1234", + AdvertiseTags: []string{"tag:foo", "tag:bar"}, + }, + "darwin", + `Prefs{ra=false dns=false want=true tags=tag:foo,tag:bar url="http://localhost:1234" Persist=nil}`, + }, + { + Prefs{ + Persist: &controlclient.Persist{}, + }, + "linux", + `Prefs{ra=false mesh=false dns=false want=false routes=[] nf=off Persist{lm=, o=, n= u=""}}`, + }, + { + Prefs{ + Persist: &controlclient.Persist{ + PrivateNodeKey: wgcfg.PrivateKey{1: 1}, + }, + }, + "linux", + `Prefs{ra=false mesh=false dns=false want=false routes=[] nf=off Persist{lm=, o=, n=[B1VKl] u=""}}`, + }, } for i, tt := range tests { got := tt.p.pretty(tt.os)