2023-01-27 21:37:20 +00:00
|
|
|
// Copyright (c) Tailscale Inc & AUTHORS
|
|
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
2021-06-22 22:29:01 +00:00
|
|
|
|
|
|
|
// Package controlknobs contains client options configurable from control which can be turned on
|
|
|
|
// or off. The ability to turn options on and off is for incrementally adding features in.
|
|
|
|
package controlknobs
|
|
|
|
|
|
|
|
import (
|
2023-09-18 15:52:22 +00:00
|
|
|
"slices"
|
2022-08-04 04:51:02 +00:00
|
|
|
"sync/atomic"
|
|
|
|
|
2023-09-11 19:03:39 +00:00
|
|
|
"tailscale.com/syncs"
|
2023-09-12 19:36:53 +00:00
|
|
|
"tailscale.com/tailcfg"
|
2023-09-11 19:03:39 +00:00
|
|
|
"tailscale.com/types/opt"
|
2021-06-22 22:29:01 +00:00
|
|
|
)
|
|
|
|
|
2023-09-11 19:03:39 +00:00
|
|
|
// Knobs is the set of knobs that the control plane's coordination server can
|
|
|
|
// adjust at runtime.
|
|
|
|
type Knobs struct {
|
|
|
|
// DisableUPnP indicates whether to attempt UPnP mapping.
|
|
|
|
DisableUPnP atomic.Bool
|
2021-06-22 22:29:01 +00:00
|
|
|
|
2023-09-11 19:03:39 +00:00
|
|
|
// DisableDRPO is whether control says to disable the
|
|
|
|
// DERP route optimization (Issue 150).
|
|
|
|
DisableDRPO atomic.Bool
|
2021-06-22 22:29:01 +00:00
|
|
|
|
2023-09-11 19:03:39 +00:00
|
|
|
// KeepFullWGConfig is whether we should disable the lazy wireguard
|
|
|
|
// programming and instead give WireGuard the full netmap always, even for
|
|
|
|
// idle peers.
|
|
|
|
KeepFullWGConfig atomic.Bool
|
|
|
|
|
|
|
|
// RandomizeClientPort is whether control says we should randomize
|
|
|
|
// the client port.
|
|
|
|
RandomizeClientPort atomic.Bool
|
2021-06-22 22:29:01 +00:00
|
|
|
|
2023-09-11 19:03:39 +00:00
|
|
|
// OneCGNAT is whether the the node should make one big CGNAT route
|
|
|
|
// in the OS rather than one /32 per peer.
|
|
|
|
OneCGNAT syncs.AtomicValue[opt.Bool]
|
2023-09-12 00:53:21 +00:00
|
|
|
|
|
|
|
// ForceBackgroundSTUN forces netcheck STUN queries to keep
|
|
|
|
// running in magicsock, even when idle.
|
|
|
|
ForceBackgroundSTUN atomic.Bool
|
2023-09-02 02:28:00 +00:00
|
|
|
|
|
|
|
// DisableDeltaUpdates is whether the node should not process
|
|
|
|
// incremental (delta) netmap updates and should treat all netmap
|
|
|
|
// changes as "full" ones as tailscaled did in 1.48.x and earlier.
|
|
|
|
DisableDeltaUpdates atomic.Bool
|
2023-09-21 09:31:48 +00:00
|
|
|
|
|
|
|
// PeerMTUEnable is whether the node should do peer path MTU discovery.
|
|
|
|
PeerMTUEnable atomic.Bool
|
2023-09-07 20:27:50 +00:00
|
|
|
|
|
|
|
// DisableDNSForwarderTCPRetries is whether the DNS forwarder should
|
|
|
|
// skip retrying truncated queries over TCP.
|
|
|
|
DisableDNSForwarderTCPRetries atomic.Bool
|
2023-11-13 18:05:04 +00:00
|
|
|
|
|
|
|
// SilentDisco is whether the node should suppress disco heartbeats to its
|
|
|
|
// peers.
|
|
|
|
SilentDisco atomic.Bool
|
2021-06-22 22:29:01 +00:00
|
|
|
}
|
2023-09-12 04:44:38 +00:00
|
|
|
|
2023-09-12 19:36:53 +00:00
|
|
|
// UpdateFromNodeAttributes updates k (if non-nil) based on the provided self
|
|
|
|
// node attributes (Node.Capabilities).
|
2023-09-18 15:52:22 +00:00
|
|
|
func (k *Knobs) UpdateFromNodeAttributes(selfNodeAttrs []tailcfg.NodeCapability, capMap tailcfg.NodeCapMap) {
|
2023-09-12 19:36:53 +00:00
|
|
|
if k == nil {
|
|
|
|
return
|
|
|
|
}
|
2023-09-18 15:52:22 +00:00
|
|
|
has := func(attr tailcfg.NodeCapability) bool {
|
|
|
|
_, ok := capMap[attr]
|
|
|
|
return ok || slices.Contains(selfNodeAttrs, attr)
|
|
|
|
}
|
2023-09-12 19:36:53 +00:00
|
|
|
var (
|
2023-09-07 20:27:50 +00:00
|
|
|
keepFullWG = has(tailcfg.NodeAttrDebugDisableWGTrim)
|
|
|
|
disableDRPO = has(tailcfg.NodeAttrDebugDisableDRPO)
|
|
|
|
disableUPnP = has(tailcfg.NodeAttrDisableUPnP)
|
|
|
|
randomizeClientPort = has(tailcfg.NodeAttrRandomizeClientPort)
|
|
|
|
disableDeltaUpdates = has(tailcfg.NodeAttrDisableDeltaUpdates)
|
|
|
|
oneCGNAT opt.Bool
|
|
|
|
forceBackgroundSTUN = has(tailcfg.NodeAttrDebugForceBackgroundSTUN)
|
|
|
|
peerMTUEnable = has(tailcfg.NodeAttrPeerMTUEnable)
|
|
|
|
dnsForwarderDisableTCPRetries = has(tailcfg.NodeAttrDNSForwarderDisableTCPRetries)
|
2023-11-13 18:05:04 +00:00
|
|
|
silentDisco = has(tailcfg.NodeAttrSilentDisco)
|
2023-09-12 19:36:53 +00:00
|
|
|
)
|
2023-09-18 15:52:22 +00:00
|
|
|
|
|
|
|
if has(tailcfg.NodeAttrOneCGNATEnable) {
|
|
|
|
oneCGNAT.Set(true)
|
|
|
|
} else if has(tailcfg.NodeAttrOneCGNATDisable) {
|
|
|
|
oneCGNAT.Set(false)
|
2023-09-12 19:36:53 +00:00
|
|
|
}
|
2023-09-18 15:52:22 +00:00
|
|
|
|
2023-09-12 19:36:53 +00:00
|
|
|
k.KeepFullWGConfig.Store(keepFullWG)
|
|
|
|
k.DisableDRPO.Store(disableDRPO)
|
|
|
|
k.DisableUPnP.Store(disableUPnP)
|
|
|
|
k.RandomizeClientPort.Store(randomizeClientPort)
|
|
|
|
k.OneCGNAT.Store(oneCGNAT)
|
|
|
|
k.ForceBackgroundSTUN.Store(forceBackgroundSTUN)
|
|
|
|
k.DisableDeltaUpdates.Store(disableDeltaUpdates)
|
2023-09-21 09:31:48 +00:00
|
|
|
k.PeerMTUEnable.Store(peerMTUEnable)
|
2023-09-07 20:27:50 +00:00
|
|
|
k.DisableDNSForwarderTCPRetries.Store(dnsForwarderDisableTCPRetries)
|
2023-11-13 18:05:04 +00:00
|
|
|
k.SilentDisco.Store(silentDisco)
|
2023-09-12 19:36:53 +00:00
|
|
|
}
|
|
|
|
|
2023-09-12 04:44:38 +00:00
|
|
|
// AsDebugJSON returns k as something that can be marshalled with json.Marshal
|
|
|
|
// for debug.
|
|
|
|
func (k *Knobs) AsDebugJSON() map[string]any {
|
|
|
|
if k == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return map[string]any{
|
2023-09-07 20:27:50 +00:00
|
|
|
"DisableUPnP": k.DisableUPnP.Load(),
|
|
|
|
"DisableDRPO": k.DisableDRPO.Load(),
|
|
|
|
"KeepFullWGConfig": k.KeepFullWGConfig.Load(),
|
|
|
|
"RandomizeClientPort": k.RandomizeClientPort.Load(),
|
|
|
|
"OneCGNAT": k.OneCGNAT.Load(),
|
|
|
|
"ForceBackgroundSTUN": k.ForceBackgroundSTUN.Load(),
|
|
|
|
"DisableDeltaUpdates": k.DisableDeltaUpdates.Load(),
|
|
|
|
"PeerMTUEnable": k.PeerMTUEnable.Load(),
|
|
|
|
"DisableDNSForwarderTCPRetries": k.DisableDNSForwarderTCPRetries.Load(),
|
2023-11-13 18:05:04 +00:00
|
|
|
"SilentDisco": k.SilentDisco.Load(),
|
2023-09-12 04:44:38 +00:00
|
|
|
}
|
|
|
|
}
|