mirror of
https://github.com/tailscale/tailscale.git
synced 2025-04-16 03:31:39 +00:00
wgengine/magicsock: fix bug in peerMap.upsertEndpoint
Found by inspection by David Crawshaw while investigating tailscale/corp#3016. Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
This commit is contained in:
parent
16870cb754
commit
9da22dac3d
@ -168,16 +168,14 @@ func (m *peerMap) forEachEndpointWithDiscoKey(dk key.DiscoPublic, f func(ep *end
|
|||||||
// upsertEndpoint stores endpoint in the peerInfo for
|
// upsertEndpoint stores endpoint in the peerInfo for
|
||||||
// ep.publicKey, and updates indexes. m must already have a
|
// ep.publicKey, and updates indexes. m must already have a
|
||||||
// tailcfg.Node for ep.publicKey.
|
// tailcfg.Node for ep.publicKey.
|
||||||
func (m *peerMap) upsertEndpoint(ep *endpoint) {
|
func (m *peerMap) upsertEndpoint(ep *endpoint, oldDiscoKey key.DiscoPublic) {
|
||||||
pi := m.byNodeKey[ep.publicKey]
|
pi := m.byNodeKey[ep.publicKey]
|
||||||
if pi == nil {
|
if pi == nil {
|
||||||
pi = newPeerInfo(ep)
|
pi = newPeerInfo(ep)
|
||||||
m.byNodeKey[ep.publicKey] = pi
|
m.byNodeKey[ep.publicKey] = pi
|
||||||
} else {
|
} else {
|
||||||
old := pi.ep
|
if oldDiscoKey != ep.discoKey {
|
||||||
pi.ep = ep
|
delete(m.nodesOfDisco[oldDiscoKey], ep.publicKey)
|
||||||
if old.discoKey != ep.discoKey {
|
|
||||||
delete(m.nodesOfDisco[old.discoKey], ep.publicKey)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !ep.discoKey.IsZero() {
|
if !ep.discoKey.IsZero() {
|
||||||
@ -2306,8 +2304,9 @@ func (c *Conn) SetNetworkMap(nm *netmap.NetworkMap) {
|
|||||||
// handle full set updates.
|
// handle full set updates.
|
||||||
for _, n := range nm.Peers {
|
for _, n := range nm.Peers {
|
||||||
if ep, ok := c.peerMap.endpointForNodeKey(n.Key); ok {
|
if ep, ok := c.peerMap.endpointForNodeKey(n.Key); ok {
|
||||||
|
oldDiscoKey := ep.discoKey
|
||||||
ep.updateFromNode(n)
|
ep.updateFromNode(n)
|
||||||
c.peerMap.upsertEndpoint(ep) // maybe update discokey mappings in peerMap
|
c.peerMap.upsertEndpoint(ep, oldDiscoKey) // maybe update discokey mappings in peerMap
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2347,7 +2346,7 @@ func (c *Conn) SetNetworkMap(nm *netmap.NetworkMap) {
|
|||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
ep.updateFromNode(n)
|
ep.updateFromNode(n)
|
||||||
c.peerMap.upsertEndpoint(ep)
|
c.peerMap.upsertEndpoint(ep, key.DiscoPublic{})
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the set of nodes changed since the last SetNetworkMap, the
|
// If the set of nodes changed since the last SetNetworkMap, the
|
||||||
|
@ -1142,7 +1142,7 @@ func TestDiscoMessage(t *testing.T) {
|
|||||||
c.peerMap.upsertEndpoint(&endpoint{
|
c.peerMap.upsertEndpoint(&endpoint{
|
||||||
publicKey: n.Key,
|
publicKey: n.Key,
|
||||||
discoKey: n.DiscoKey,
|
discoKey: n.DiscoKey,
|
||||||
})
|
}, key.DiscoPublic{})
|
||||||
|
|
||||||
const payload = "why hello"
|
const payload = "why hello"
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user