From 3a3b64301ee1e24e5c637766648d88e611faf5bf Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Fri, 10 Apr 2020 08:42:34 -0700 Subject: [PATCH] wgengine: quiet some engine reconfig logging, make more consistent Updates #282 Signed-off-by: Brad Fitzpatrick --- ipn/local.go | 10 +++++----- wgengine/userspace.go | 10 +++++----- wgengine/wgengine.go | 6 ++++++ 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/ipn/local.go b/ipn/local.go index eafc06722..671e873b6 100644 --- a/ipn/local.go +++ b/ipn/local.go @@ -610,6 +610,8 @@ func (b *LocalBackend) SetPrefs(new *Prefs) { cli := b.c b.mu.Unlock() + b.logf("SetPrefs: %v\n", new.Pretty()) + if cli != nil && !oldHi.Equal(newHi) { cli.SetHostinfo(newHi) } @@ -620,7 +622,6 @@ func (b *LocalBackend) SetPrefs(new *Prefs) { b.authReconfig() } - b.logf("SetPrefs: %v\n", new.Pretty()) b.send(Notify{Prefs: new}) } @@ -657,7 +658,6 @@ func (b *LocalBackend) authReconfig() { b.logf("authReconfig: skipping because !WantRunning.\n") return } - b.logf("Configuring wireguard connection.\n") uflags := controlclient.UDefault if uc.RouteAll { @@ -674,7 +674,6 @@ func (b *LocalBackend) authReconfig() { if uc.AllowSingleHosts { uflags |= controlclient.UAllowSingleHosts } - b.logf("reconfig: ra=%v dns=%v 0x%02x\n", uc.RouteAll, uc.CorpDNS, uflags) dns := nm.DNS dom := nm.DNSDomains @@ -688,9 +687,10 @@ func (b *LocalBackend) authReconfig() { } err = b.e.Reconfig(cfg, dom) - if err != nil { - b.logf("reconfig: %v", err) + if err == wgengine.ErrNoChanges { + return } + b.logf("authReconfig: ra=%v dns=%v 0x%02x: %v\n", uc.RouteAll, uc.CorpDNS, uflags, err) } func (b *LocalBackend) enterState(newState State) { diff --git a/wgengine/userspace.go b/wgengine/userspace.go index 512617835..136519f6e 100644 --- a/wgengine/userspace.go +++ b/wgengine/userspace.go @@ -311,7 +311,6 @@ func (e *userspaceEngine) pinger(peerKey wgcfg.Key, ips []wgcfg.IP) { // the traditional wireguard config format. On the other hand, wireguard // itself doesn't use the traditional 'dns =' setting either. func (e *userspaceEngine) Reconfig(cfg *wgcfg.Config, dnsDomains []string) error { - e.logf("Reconfig(): configuring userspace wireguard engine.\n") e.wgLock.Lock() defer e.wgLock.Unlock() @@ -330,9 +329,10 @@ func (e *userspaceEngine) Reconfig(cfg *wgcfg.Config, dnsDomains []string) error rc := uapi + "\x00" + strings.Join(dnsDomains, "\x00") if rc == e.lastReconfig { - e.logf("...unchanged config, skipping.\n") - return nil + return ErrNoChanges } + + e.logf("wgengine: Reconfig: configuring userspace wireguard engine") e.lastReconfig = rc e.lastCfg = cfg.Copy() @@ -374,7 +374,7 @@ func (e *userspaceEngine) Reconfig(cfg *wgcfg.Config, dnsDomains []string) error // just what's absolutely needed (the set of actual routes). rss := rs.OnlyRelevantParts() if rss != e.lastRoutes { - e.logf("Reconfiguring router. la=%v dns=%v dom=%v; new routes: %v\n", + e.logf("wgengine: Reconfig: reconfiguring router. la=%v dns=%v dom=%v; new routes: %v", rs.LocalAddr, rs.DNS, rs.DNSDomains, rss) e.lastRoutes = rss err = e.router.SetRoutes(rs) @@ -383,7 +383,7 @@ func (e *userspaceEngine) Reconfig(cfg *wgcfg.Config, dnsDomains []string) error } } - e.logf("Reconfig() done.\n") + e.logf("wgengine: Reconfig done") return nil } diff --git a/wgengine/wgengine.go b/wgengine/wgengine.go index 3974a1244..518abfce1 100644 --- a/wgengine/wgengine.go +++ b/wgengine/wgengine.go @@ -5,6 +5,7 @@ package wgengine import ( + "errors" "fmt" "time" @@ -92,6 +93,9 @@ type Router interface { Close() error } +// ErrNoChanges is returned by Engine.Reconfig if no changes were made. +var ErrNoChanges = errors.New("no changes made to Engine config") + // Engine is the Tailscale WireGuard engine interface. type Engine interface { // Reconfig reconfigures WireGuard and makes sure it's running. @@ -102,6 +106,8 @@ type Engine interface { // // This is called whenever the tailcontrol (control plane) // sends an updated network map. + // + // The returned error is ErrNoChanges if no changes were made. Reconfig(cfg *wgcfg.Config, dnsDomains []string) error // GetFilter returns the current packet filter, if any.