control/controlknobs: move ForceBackgroundSTUN to controlknobs.Knobs

This is both more efficient (because the knobs' bool is only updated
whenever Node is changed, rarely) and also gets us one step closer to
removing a case of storing a netmap.NetworkMap in
magicsock. (eventually we want to phase out much of the use of that
type internally)

Updates #1909

Change-Id: I37e81789f94133175064fdc09984e4f3a431f1a1
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
pull/9358/head
Brad Fitzpatrick 8 months ago committed by Brad Fitzpatrick
parent 4e91cf20a8
commit 42072683d6

@ -1302,6 +1302,7 @@ func (ms *mapSession) setControlKnobsFromNodeAttrs(selfNodeAttrs []string) {
disableUPnP bool disableUPnP bool
randomizeClientPort bool randomizeClientPort bool
oneCGNAT opt.Bool oneCGNAT opt.Bool
forceBackgroundSTUN bool
) )
for _, attr := range selfNodeAttrs { for _, attr := range selfNodeAttrs {
switch attr { switch attr {
@ -1317,6 +1318,8 @@ func (ms *mapSession) setControlKnobsFromNodeAttrs(selfNodeAttrs []string) {
oneCGNAT.Set(true) oneCGNAT.Set(true)
case tailcfg.NodeAttrOneCGNATDisable: case tailcfg.NodeAttrOneCGNATDisable:
oneCGNAT.Set(false) oneCGNAT.Set(false)
case tailcfg.NodeAttrDebugForceBackgroundSTUN:
forceBackgroundSTUN = true
} }
} }
k.KeepFullWGConfig.Store(keepFullWG) k.KeepFullWGConfig.Store(keepFullWG)
@ -1324,6 +1327,7 @@ func (ms *mapSession) setControlKnobsFromNodeAttrs(selfNodeAttrs []string) {
k.DisableUPnP.Store(disableUPnP) k.DisableUPnP.Store(disableUPnP)
k.RandomizeClientPort.Store(randomizeClientPort) k.RandomizeClientPort.Store(randomizeClientPort)
k.OneCGNAT.Store(oneCGNAT) k.OneCGNAT.Store(oneCGNAT)
k.ForceBackgroundSTUN.Store(forceBackgroundSTUN)
} }
// ipForwardingBroken reports whether the system's IP forwarding is disabled // ipForwardingBroken reports whether the system's IP forwarding is disabled

@ -34,4 +34,8 @@ type Knobs struct {
// OneCGNAT is whether the the node should make one big CGNAT route // OneCGNAT is whether the the node should make one big CGNAT route
// in the OS rather than one /32 per peer. // in the OS rather than one /32 per peer.
OneCGNAT syncs.AtomicValue[opt.Bool] OneCGNAT syncs.AtomicValue[opt.Bool]
// ForceBackgroundSTUN forces netcheck STUN queries to keep
// running in magicsock, even when idle.
ForceBackgroundSTUN atomic.Bool
} }

@ -51,7 +51,6 @@ import (
"tailscale.com/types/logger" "tailscale.com/types/logger"
"tailscale.com/types/netmap" "tailscale.com/types/netmap"
"tailscale.com/types/nettype" "tailscale.com/types/nettype"
"tailscale.com/types/views"
"tailscale.com/util/clientmetric" "tailscale.com/util/clientmetric"
"tailscale.com/util/mak" "tailscale.com/util/mak"
"tailscale.com/util/ringbuffer" "tailscale.com/util/ringbuffer"
@ -2151,8 +2150,7 @@ func (c *Conn) shouldDoPeriodicReSTUNLocked() bool {
c.logf("magicsock: periodicReSTUN: idle for %v", idleFor.Round(time.Second)) c.logf("magicsock: periodicReSTUN: idle for %v", idleFor.Round(time.Second))
} }
if idleFor > sessionActiveTimeout { if idleFor > sessionActiveTimeout {
if c.netMap != nil && c.netMap.SelfNode.Valid() && if c.controlKnobs != nil && c.controlKnobs.ForceBackgroundSTUN.Load() {
views.SliceContains(c.netMap.SelfNode.Capabilities(), tailcfg.NodeAttrDebugForceBackgroundSTUN) {
// Overridden by control. // Overridden by control.
return true return true
} }

Loading…
Cancel
Save