From 2ff54f9d124e58f3f815755317f0e2c7e80f4d24 Mon Sep 17 00:00:00 2001 From: Jordan Whited Date: Wed, 15 Nov 2023 16:30:50 -0800 Subject: [PATCH] wgengine/magicsock: move trustBestAddrUntil forward on non-disco rx (#10274) This is gated behind the silent disco control knob, which is still in its infancy. Prior to this change disco pong reception was the only event that could move trustBestAddrUntil forward, so even though we weren't heartbeating, we would kick off discovery pings every trustUDPAddrDuration and mirror to DERP. Updates #540 Signed-off-by: Jordan Whited --- wgengine/magicsock/endpoint.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/wgengine/magicsock/endpoint.go b/wgengine/magicsock/endpoint.go index 4e9e91a38..06298ad1f 100644 --- a/wgengine/magicsock/endpoint.go +++ b/wgengine/magicsock/endpoint.go @@ -239,14 +239,22 @@ func (de *endpoint) initFakeUDPAddr() { func (de *endpoint) noteRecvActivity(ipp netip.AddrPort) { now := mono.Now() - // TODO(raggi): this probably applies relatively equally well to disco - // managed endpoints, but that would be a less conservative change. if de.isWireguardOnly { de.mu.Lock() de.bestAddr.AddrPort = ipp de.bestAddrAt = now de.trustBestAddrUntil = now.Add(5 * time.Second) de.mu.Unlock() + } else { + // TODO(jwhited): subject to change as part of silent disco effort. + // Necessary when heartbeat is disabled for the endpoint, otherwise we + // kick off discovery disco pings every trustUDPAddrDuration and mirror + // to DERP. + de.mu.Lock() + if de.heartbeatDisabled && de.bestAddr.AddrPort == ipp { + de.trustBestAddrUntil = now.Add(trustUDPAddrDuration) + } + de.mu.Unlock() } elapsed := now.Sub(de.lastRecv.LoadAtomic())