summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDavid Crawshaw <crawshaw@tailscale.com>2020-04-02 11:18:39 +1100
committerDavid Crawshaw <crawshaw@tailscale.com>2020-04-02 11:19:05 +1100
commit58c65eeff44fffca75c22fcccd47daa8dfed9631 (patch)
tree52ef02e54ff84c8f09c0c48b83f9a0c35062ce36
parent48d7ee1c6a99fd4e240ad487a6cec0333e1b47fd (diff)
downloadtailscale-crawshaw/hostinfo.tar.xz
tailscale-crawshaw/hostinfo.zip
controlclient: do not send duplicate hostinfo/netinfocrawshaw/hostinfo
This should never happen, so log when it does so we can fix it. Signed-off-by: David Crawshaw <crawshaw@tailscale.com>
-rw-r--r--control/controlclient/auto.go14
-rw-r--r--control/controlclient/direct.go21
2 files changed, 26 insertions, 9 deletions
diff --git a/control/controlclient/auto.go b/control/controlclient/auto.go
index ce49ad0ec..831b736cb 100644
--- a/control/controlclient/auto.go
+++ b/control/controlclient/auto.go
@@ -496,7 +496,12 @@ func (c *Client) SetHostinfo(hi *tailcfg.Hostinfo) {
if hi == nil {
panic("nil Hostinfo")
}
- c.direct.SetHostinfo(hi)
+ if !c.direct.SetHostinfo(hi) {
+ c.logf("[unexpected] duplicate Hostinfo: %v", hi)
+ return
+ }
+ c.logf("Hostinfo: %v", hi)
+
// Send new Hostinfo to server
c.cancelMapSafely()
}
@@ -505,7 +510,12 @@ func (c *Client) SetNetInfo(ni *tailcfg.NetInfo) {
if ni == nil {
panic("nil NetInfo")
}
- c.direct.SetNetInfo(ni)
+ if !c.direct.SetNetInfo(ni) {
+ c.logf("[unexpected] duplicate NetInfo: %v", ni)
+ return
+ }
+ c.logf("NetInfo: %v", ni)
+
// Send new Hostinfo (which includes NetInfo) to server
c.cancelMapSafely()
}
diff --git a/control/controlclient/direct.go b/control/controlclient/direct.go
index a8c8b460f..56a8f30c0 100644
--- a/control/controlclient/direct.go
+++ b/control/controlclient/direct.go
@@ -17,6 +17,7 @@ import (
"log"
"net/http"
"os"
+ "reflect"
"strconv"
"strings"
"sync"
@@ -149,21 +150,24 @@ func NewHostinfo() *tailcfg.Hostinfo {
}
// SetHostinfo clones the provided Hostinfo and remembers it for the
-// next update.
-func (c *Direct) SetHostinfo(hi *tailcfg.Hostinfo) {
+// next update. It reports whether the Hostinfo has changed.
+func (c *Direct) SetHostinfo(hi *tailcfg.Hostinfo) bool {
if hi == nil {
panic("nil Hostinfo")
}
c.mu.Lock()
defer c.mu.Unlock()
- c.logf("Hostinfo: %v\n", hi)
+ if hi.Equal(c.hostinfo) {
+ return false
+ }
c.hostinfo = hi.Clone()
+ return true
}
// SetNetInfo clones the provided NetInfo and remembers it for the
-// next update.
-func (c *Direct) SetNetInfo(ni *tailcfg.NetInfo) {
+// next update. It reports whether the NetInfo has changed.
+func (c *Direct) SetNetInfo(ni *tailcfg.NetInfo) bool {
if ni == nil {
panic("nil NetInfo")
}
@@ -172,10 +176,13 @@ func (c *Direct) SetNetInfo(ni *tailcfg.NetInfo) {
if c.hostinfo == nil {
c.logf("[unexpected] SetNetInfo called with no HostInfo; ignoring NetInfo update: %+v", ni)
- return
+ return false
+ }
+ if reflect.DeepEqual(ni, c.hostinfo.NetInfo) {
+ return false
}
- c.logf("NetInfo: %v\n", ni)
c.hostinfo.NetInfo = ni.Clone()
+ return true
}
func (c *Direct) GetPersist() Persist {