From 7b7ff1f2e41d516ab1486ad38d4fe48bb5928b78 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Fri, 15 Oct 2021 14:40:49 -0700 Subject: [PATCH] wgengine/magicsock: start removing endpointForDiscoKey It's not valid to assume that a discokey is globally unique. This removes the first two of the four callers. Updates #3088 Signed-off-by: Brad Fitzpatrick (cherry picked from commit 82fa15fa3b3c80f4e42ec0f261b02d2d6dab5303) --- wgengine/magicsock/magicsock.go | 15 +++++++++++---- wgengine/pendopen.go | 2 +- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/wgengine/magicsock/magicsock.go b/wgengine/magicsock/magicsock.go index fd2bb9e35..369e79273 100644 --- a/wgengine/magicsock/magicsock.go +++ b/wgengine/magicsock/magicsock.go @@ -109,6 +109,13 @@ func (m *peerMap) nodeCount() int { return len(m.byNodeKey) } +// anyEndpointForDiscoKey reports whether there exists any +// peers in the netmap with dk as their DiscoKey. +func (m *peerMap) anyEndpointForDiscoKey(dk tailcfg.DiscoKey) bool { + _, ok := m.byDiscoKey[dk] + return ok +} + // endpointForDiscoKey returns the endpoint for dk, or nil // if dk is not known to us. func (m *peerMap) endpointForDiscoKey(dk tailcfg.DiscoKey) (ep *endpoint, ok bool) { @@ -831,12 +838,12 @@ func (c *Conn) SetNetInfoCallback(fn func(*tailcfg.NetInfo)) { } } -// LastRecvActivityOfDisco describes the time we last got traffic from +// LastRecvActivityOfNodeKey describes the time we last got traffic from // this endpoint (updated every ~10 seconds). -func (c *Conn) LastRecvActivityOfDisco(dk tailcfg.DiscoKey) string { +func (c *Conn) LastRecvActivityOfNodeKey(nk tailcfg.NodeKey) string { c.mu.Lock() defer c.mu.Unlock() - de, ok := c.peerMap.endpointForDiscoKey(dk) + de, ok := c.peerMap.endpointForNodeKey(nk) if !ok { return "never" } @@ -2171,7 +2178,7 @@ func (c *Conn) SetNetworkMap(nm *netmap.NetworkMap) { // discokeys might have changed in the above. Discard unused cached keys. for discoKey := range c.sharedDiscoKey { - if _, ok := c.peerMap.endpointForDiscoKey(discoKey); !ok { + if !c.peerMap.anyEndpointForDiscoKey(discoKey) { delete(c.sharedDiscoKey, discoKey) } } diff --git a/wgengine/pendopen.go b/wgengine/pendopen.go index 5d51ff3ae..574c73435 100644 --- a/wgengine/pendopen.go +++ b/wgengine/pendopen.go @@ -231,7 +231,7 @@ func (e *userspaceEngine) onOpenTimeout(flow flowtrack.Tuple) { e.logf("open-conn-track: timeout opening %v to node %v; online=%v, lastRecv=%v", flow, n.Key.ShortString(), online, - e.magicConn.LastRecvActivityOfDisco(n.DiscoKey)) + e.magicConn.LastRecvActivityOfNodeKey(n.Key)) } func durFmt(t time.Time) string {