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 <james@tailscale.com>
pull/9004/head
James Tucker 1 year ago committed by James Tucker
parent 7364c6beec
commit 3a652d7761

@ -127,6 +127,14 @@ type endpointState struct {
index int16 // index in nodecfg.Node.Endpoints; meaningless if lastGotPing non-zero 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 // pongHistoryCount is how many pongReply values we keep per endpointState
const pongHistoryCount = 64 const pongHistoryCount = 64
@ -865,7 +873,12 @@ func (de *endpoint) noteConnectivityChange() {
de.mu.Lock() de.mu.Lock()
defer de.mu.Unlock() defer de.mu.Unlock()
de.bestAddr = addrLatency{}
de.trustBestAddrUntil = 0 de.trustBestAddrUntil = 0
for k := range de.endpointState {
de.endpointState[k].clear()
}
} }
// handlePongConnLocked handles a Pong message (a reply to an earlier ping). // handlePongConnLocked handles a Pong message (a reply to an earlier ping).

Loading…
Cancel
Save