ipn: clean up Prefs logging at start

Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
Brad Fitzpatrick 2020-11-04 10:24:33 -08:00 committed by Brad Fitzpatrick
parent 6bcb466096
commit 4f4e84236a
4 changed files with 48 additions and 8 deletions

View File

@ -91,9 +91,14 @@ func (p *Persist) Pretty() string {
if !p.PrivateNodeKey.IsZero() { if !p.PrivateNodeKey.IsZero() {
nk = p.PrivateNodeKey.Public() 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}", return fmt.Sprintf("Persist{lm=%v, o=%v, n=%v u=%#v}",
mk.ShortString(), ok.ShortString(), nk.ShortString(), ss(mk), ss(ok), ss(nk), p.LoginName)
p.LoginName)
} }
// Direct is the client that connects to a tailcontrol server for a node. // Direct is the client that connects to a tailcontrol server for a node.

View File

@ -419,7 +419,9 @@ func (b *LocalBackend) Start(opts Options) error {
b.serverURL = b.prefs.ControlURL b.serverURL = b.prefs.ControlURL
hostinfo.RoutableIPs = append(hostinfo.RoutableIPs, b.prefs.AdvertiseRoutes...) hostinfo.RoutableIPs = append(hostinfo.RoutableIPs, b.prefs.AdvertiseRoutes...)
hostinfo.RequestTags = append(hostinfo.RequestTags, b.prefs.AdvertiseTags...) 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) applyPrefsToHostinfo(hostinfo, b.prefs)
b.notify = opts.Notify 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 // If the frontend (e.g. on Windows) supplied the
// optional/legacy machine key then it's used as the // optional/legacy machine key then it's used as the
// value instead of making up a new one. // 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() b.prefs = prefs.Clone()
if err := b.initMachineKeyLocked(); err != nil { if err := b.initMachineKeyLocked(); err != nil {
return fmt.Errorf("initMachineKeyLocked: %w", err) return fmt.Errorf("initMachineKeyLocked: %w", err)
@ -839,13 +841,13 @@ func (b *LocalBackend) loadStateLocked(key StateKey, prefs *Prefs, legacyPath st
if prefs != nil { if prefs != nil {
// Backend owns the state, but frontend is trying to migrate // Backend owns the state, but frontend is trying to migrate
// state into the backend. // 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 { if err := b.store.WriteState(key, prefs.ToBytes()); err != nil {
return fmt.Errorf("store.WriteState: %v", err) return fmt.Errorf("store.WriteState: %v", err)
} }
} }
b.logf("Using backend prefs") b.logf("using backend prefs")
bs, err := b.store.ReadState(key) bs, err := b.store.ReadState(key)
if err != nil { if err != nil {
if errors.Is(err, ErrStateNotExist) { if errors.Is(err, ErrStateNotExist) {
@ -857,11 +859,11 @@ func (b *LocalBackend) loadStateLocked(key StateKey, prefs *Prefs, legacyPath st
} }
b.prefs = NewPrefs() b.prefs = NewPrefs()
} else { } else {
b.logf("Imported state from relaynode for %q", key) b.logf("imported prefs from relaynode for %q: %v", key, b.prefs.Pretty())
} }
} else { } else {
b.prefs = NewPrefs() 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 { if err := b.initMachineKeyLocked(); err != nil {
return fmt.Errorf("initMachineKeyLocked: %w", err) return fmt.Errorf("initMachineKeyLocked: %w", err)
@ -874,6 +876,7 @@ func (b *LocalBackend) loadStateLocked(key StateKey, prefs *Prefs, legacyPath st
if err != nil { if err != nil {
return fmt.Errorf("PrefsFromBytes: %v", err) return fmt.Errorf("PrefsFromBytes: %v", err)
} }
b.logf("backend prefs for %q: %s", key, b.prefs.Pretty())
if err := b.initMachineKeyLocked(); err != nil { if err := b.initMachineKeyLocked(); err != nil {
return fmt.Errorf("initMachineKeyLocked: %w", err) return fmt.Errorf("initMachineKeyLocked: %w", err)
} }

View File

@ -152,9 +152,15 @@ func (p *Prefs) pretty(goos string) string {
if len(p.AdvertiseRoutes) > 0 || p.NoSNAT { if len(p.AdvertiseRoutes) > 0 || p.NoSNAT {
fmt.Fprintf(&sb, "snat=%v ", !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" { if goos == "linux" {
fmt.Fprintf(&sb, "nf=%v ", p.NetfilterMode) 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 { if p.Persist != nil {
sb.WriteString(p.Persist.Pretty()) sb.WriteString(p.Persist.Pretty())
} else { } else {

View File

@ -326,6 +326,32 @@ func TestPrefsPretty(t *testing.T) {
"windows", "windows",
"Prefs{ra=false dns=false want=true server=true Persist=nil}", "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 { for i, tt := range tests {
got := tt.p.pretty(tt.os) got := tt.p.pretty(tt.os)