wgengine/magicsock: don't call setAddrToDiscoLocked on DERP ping

Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
Brad Fitzpatrick 2021-10-16 07:43:48 -07:00
parent 569f70abfd
commit f55c2bccf5
1 changed files with 4 additions and 2 deletions

View File

@ -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++