derp: fix meshing accounting edge case bug

If a peer is connected to multiple nodes in a region (so
multiForwarder is in use) and then a node restarts and re-sends all
its additions, this bug about whether an element is in the
multiForwarder could cause a one-time flip in the which peer node we
forward to.  Note a huge deal, but not written as intended.

Thanks to @lewgun for the bug report in #2141.

Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
Brad Fitzpatrick 2021-08-21 19:50:50 -07:00
parent fab296536c
commit f35b8c3ead
2 changed files with 2 additions and 1 deletions

View File

@ -1275,7 +1275,7 @@ func (s *Server) AddPacketForwarder(dst key.Public, fwd PacketForwarder) {
return
}
if m, ok := prev.(multiForwarder); ok {
if _, ok := m[fwd]; !ok {
if _, ok := m[fwd]; ok {
// Duplicate registration of same forwarder in set; ignore.
return
}

View File

@ -712,6 +712,7 @@ func TestForwarderRegistration(t *testing.T) {
// Adding a dup for a user.
wantCounter(&s.multiForwarderCreated, 0)
s.AddPacketForwarder(u1, testFwd(100))
s.AddPacketForwarder(u1, testFwd(100)) // dup to trigger dup path
want(map[key.Public]PacketForwarder{
u1: multiForwarder{
testFwd(1): 1,