From 46fffa32edc481510ecd85363a9a48516d4aabeb Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Sat, 16 Oct 2021 07:43:48 -0700 Subject: [PATCH] wgengine/magicsock: don't call setAddrToDiscoLocked on DERP ping Signed-off-by: Brad Fitzpatrick (cherry picked from commit f55c2bccf502e0987ff89b0fb9101f3c26f90b32) --- wgengine/magicsock/magicsock.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/wgengine/magicsock/magicsock.go b/wgengine/magicsock/magicsock.go index 2e34d5d11..13bfd308a 100644 --- a/wgengine/magicsock/magicsock.go +++ b/wgengine/magicsock/magicsock.go @@ -1873,6 +1873,8 @@ func (c *Conn) handlePingLocked(dm *disco.Ping, src netaddr.IPPort, di *discoInf di.lastPingFrom = src di.lastPingTime = time.Now() + isDerp := src.IP() == derpMagicIPAddr + // If we got a ping over DERP, then derpNodeSrc is non-zero and we reply // over DERP (in which case ipDst is also a DERP address). // But if the ping was over UDP (ipDst is not a DERP address), then dstKey @@ -1881,14 +1883,14 @@ func (c *Conn) handlePingLocked(dm *disco.Ping, src netaddr.IPPort, di *discoInf dstKey := derpNodeSrc // Remember this route if not present. - c.setAddrToDiscoLocked(src, di.discoKey) var numNodes int - if !derpNodeSrc.IsZero() { + if isDerp { if ep, ok := c.peerMap.endpointForNodeKey(derpNodeSrc); ok { ep.addCandidateEndpoint(src) numNodes = 1 } } else { + c.setAddrToDiscoLocked(src, di.discoKey) c.peerMap.forEachEndpointWithDiscoKey(di.discoKey, func(ep *endpoint) { ep.addCandidateEndpoint(src) numNodes++