From 3a652d7761cbe800860d10d7a568c5c423f809f3 Mon Sep 17 00:00:00 2001 From: James Tucker Date: Mon, 21 Aug 2023 15:48:17 -0700 Subject: [PATCH] wgengine/magicsock: clear endpoint state in noteConnectivityChange There are latency values stored in bestAddr and endpointState that are no longer applicable after a connectivity change and should be cleared out, following the documented behavior of the function. Updates #8999 Signed-off-by: James Tucker --- wgengine/magicsock/endpoint.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/wgengine/magicsock/endpoint.go b/wgengine/magicsock/endpoint.go index 10c58494a..64882cbd2 100644 --- a/wgengine/magicsock/endpoint.go +++ b/wgengine/magicsock/endpoint.go @@ -127,6 +127,14 @@ type endpointState struct { index int16 // index in nodecfg.Node.Endpoints; meaningless if lastGotPing non-zero } +// clear removes all derived / probed state from an endpointState. +func (s *endpointState) clear() { + *s = endpointState{ + index: s.index, + lastGotPing: s.lastGotPing, + } +} + // pongHistoryCount is how many pongReply values we keep per endpointState const pongHistoryCount = 64 @@ -865,7 +873,12 @@ func (de *endpoint) noteConnectivityChange() { de.mu.Lock() defer de.mu.Unlock() + de.bestAddr = addrLatency{} de.trustBestAddrUntil = 0 + + for k := range de.endpointState { + de.endpointState[k].clear() + } } // handlePongConnLocked handles a Pong message (a reply to an earlier ping).