wgengine/magicsock: properly clean up peer disco maps (#20543)

Updates tailscale/corp#45124
Updates tailscale/corp#45128

Signed-off-by: Claus Lensbøl <claus@tailscale.com>
This commit is contained in:
Claus Lensbøl
2026-07-20 13:12:58 -04:00
committed by GitHub
parent be0e460a20
commit b14f7b7543
3 changed files with 110 additions and 2 deletions
+10 -2
View File
@@ -151,7 +151,11 @@ func (m *peerMap) upsertEndpoint(ep *endpoint, oldDiscoKey key.DiscoPublic) {
epDisco := ep.disco.Load()
if epDisco == nil || oldDiscoKey != epDisco.key {
delete(m.nodesOfDisco[oldDiscoKey], ep.publicKey)
s := m.nodesOfDisco[oldDiscoKey]
delete(s, ep.publicKey)
if len(s) == 0 {
delete(m.nodesOfDisco, oldDiscoKey)
}
}
if ep.isWireguardOnly {
// If the peer is a WireGuard only peer, add all of its endpoints.
@@ -214,7 +218,11 @@ func (m *peerMap) deleteEndpoint(ep *endpoint) {
pi := m.byNodeKey[ep.publicKey]
if epDisco != nil {
delete(m.nodesOfDisco[epDisco.key], ep.publicKey)
s := m.nodesOfDisco[epDisco.key]
delete(s, ep.publicKey)
if len(s) == 0 {
delete(m.nodesOfDisco, epDisco.key)
}
}
delete(m.byNodeKey, ep.publicKey)
if was, ok := m.byNodeID[ep.nodeID]; ok && was.ep == ep {