controlknobs.go 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. // Copyright (c) Tailscale Inc & AUTHORS
  2. // SPDX-License-Identifier: BSD-3-Clause
  3. // Package controlknobs contains client options configurable from control which can be turned on
  4. // or off. The ability to turn options on and off is for incrementally adding features in.
  5. package controlknobs
  6. import (
  7. "sync/atomic"
  8. "tailscale.com/syncs"
  9. "tailscale.com/tailcfg"
  10. "tailscale.com/types/opt"
  11. )
  12. // Knobs is the set of knobs that the control plane's coordination server can
  13. // adjust at runtime.
  14. type Knobs struct {
  15. // DisableUPnP indicates whether to attempt UPnP mapping.
  16. DisableUPnP atomic.Bool
  17. // DisableDRPO is whether control says to disable the
  18. // DERP route optimization (Issue 150).
  19. DisableDRPO atomic.Bool
  20. // KeepFullWGConfig is whether we should disable the lazy wireguard
  21. // programming and instead give WireGuard the full netmap always, even for
  22. // idle peers.
  23. KeepFullWGConfig atomic.Bool
  24. // RandomizeClientPort is whether control says we should randomize
  25. // the client port.
  26. RandomizeClientPort atomic.Bool
  27. // OneCGNAT is whether the the node should make one big CGNAT route
  28. // in the OS rather than one /32 per peer.
  29. OneCGNAT syncs.AtomicValue[opt.Bool]
  30. // ForceBackgroundSTUN forces netcheck STUN queries to keep
  31. // running in magicsock, even when idle.
  32. ForceBackgroundSTUN atomic.Bool
  33. // DisableDeltaUpdates is whether the node should not process
  34. // incremental (delta) netmap updates and should treat all netmap
  35. // changes as "full" ones as tailscaled did in 1.48.x and earlier.
  36. DisableDeltaUpdates atomic.Bool
  37. // PeerMTUEnable is whether the node should do peer path MTU discovery.
  38. PeerMTUEnable atomic.Bool
  39. // DisableDNSForwarderTCPRetries is whether the DNS forwarder should
  40. // skip retrying truncated queries over TCP.
  41. DisableDNSForwarderTCPRetries atomic.Bool
  42. // SilentDisco is whether the node should suppress disco heartbeats to its
  43. // peers.
  44. SilentDisco atomic.Bool
  45. // LinuxForceIPTables is whether the node should use iptables for Linux
  46. // netfiltering, unless overridden by the user.
  47. LinuxForceIPTables atomic.Bool
  48. // LinuxForceNfTables is whether the node should use nftables for Linux
  49. // netfiltering, unless overridden by the user.
  50. LinuxForceNfTables atomic.Bool
  51. // SeamlessKeyRenewal is whether to enable the alpha functionality of
  52. // renewing node keys without breaking connections.
  53. // http://go/seamless-key-renewal
  54. SeamlessKeyRenewal atomic.Bool
  55. // ProbeUDPLifetime is whether the node should probe UDP path lifetime on
  56. // the tail end of an active direct connection in magicsock.
  57. ProbeUDPLifetime atomic.Bool
  58. // AppCStoreRoutes is whether the node should store RouteInfo to StateStore
  59. // if it's an app connector.
  60. AppCStoreRoutes atomic.Bool
  61. // UserDialUseRoutes is whether tsdial.Dialer.UserDial should use routes to determine
  62. // how to dial the destination address. When true, it also makes the DNS forwarder
  63. // use UserDial instead of SystemDial when dialing resolvers.
  64. UserDialUseRoutes atomic.Bool
  65. // DisableSplitDNSWhenNoCustomResolvers indicates that the node's DNS manager
  66. // should not adopt a split DNS configuration even though the Config of the
  67. // resolver only contains routes that do not specify custom resolver(s), hence
  68. // all DNS queries can be safely sent to the upstream DNS resolver and the
  69. // node's DNS forwarder doesn't need to handle all DNS traffic.
  70. // This is for now (2024-06-06) an iOS-specific battery life optimization,
  71. // and this knob allows us to disable the optimization remotely if needed.
  72. DisableSplitDNSWhenNoCustomResolvers atomic.Bool
  73. }
  74. // UpdateFromNodeAttributes updates k (if non-nil) based on the provided self
  75. // node attributes (Node.Capabilities).
  76. func (k *Knobs) UpdateFromNodeAttributes(capMap tailcfg.NodeCapMap) {
  77. if k == nil {
  78. return
  79. }
  80. has := capMap.Contains
  81. var (
  82. keepFullWG = has(tailcfg.NodeAttrDebugDisableWGTrim)
  83. disableDRPO = has(tailcfg.NodeAttrDebugDisableDRPO)
  84. disableUPnP = has(tailcfg.NodeAttrDisableUPnP)
  85. randomizeClientPort = has(tailcfg.NodeAttrRandomizeClientPort)
  86. disableDeltaUpdates = has(tailcfg.NodeAttrDisableDeltaUpdates)
  87. oneCGNAT opt.Bool
  88. forceBackgroundSTUN = has(tailcfg.NodeAttrDebugForceBackgroundSTUN)
  89. peerMTUEnable = has(tailcfg.NodeAttrPeerMTUEnable)
  90. dnsForwarderDisableTCPRetries = has(tailcfg.NodeAttrDNSForwarderDisableTCPRetries)
  91. silentDisco = has(tailcfg.NodeAttrSilentDisco)
  92. forceIPTables = has(tailcfg.NodeAttrLinuxMustUseIPTables)
  93. forceNfTables = has(tailcfg.NodeAttrLinuxMustUseNfTables)
  94. seamlessKeyRenewal = has(tailcfg.NodeAttrSeamlessKeyRenewal)
  95. probeUDPLifetime = has(tailcfg.NodeAttrProbeUDPLifetime)
  96. appCStoreRoutes = has(tailcfg.NodeAttrStoreAppCRoutes)
  97. userDialUseRoutes = has(tailcfg.NodeAttrUserDialUseRoutes)
  98. disableSplitDNSWhenNoCustomResolvers = has(tailcfg.NodeAttrDisableSplitDNSWhenNoCustomResolvers)
  99. )
  100. if has(tailcfg.NodeAttrOneCGNATEnable) {
  101. oneCGNAT.Set(true)
  102. } else if has(tailcfg.NodeAttrOneCGNATDisable) {
  103. oneCGNAT.Set(false)
  104. }
  105. k.KeepFullWGConfig.Store(keepFullWG)
  106. k.DisableDRPO.Store(disableDRPO)
  107. k.DisableUPnP.Store(disableUPnP)
  108. k.RandomizeClientPort.Store(randomizeClientPort)
  109. k.OneCGNAT.Store(oneCGNAT)
  110. k.ForceBackgroundSTUN.Store(forceBackgroundSTUN)
  111. k.DisableDeltaUpdates.Store(disableDeltaUpdates)
  112. k.PeerMTUEnable.Store(peerMTUEnable)
  113. k.DisableDNSForwarderTCPRetries.Store(dnsForwarderDisableTCPRetries)
  114. k.SilentDisco.Store(silentDisco)
  115. k.LinuxForceIPTables.Store(forceIPTables)
  116. k.LinuxForceNfTables.Store(forceNfTables)
  117. k.SeamlessKeyRenewal.Store(seamlessKeyRenewal)
  118. k.ProbeUDPLifetime.Store(probeUDPLifetime)
  119. k.AppCStoreRoutes.Store(appCStoreRoutes)
  120. k.UserDialUseRoutes.Store(userDialUseRoutes)
  121. k.DisableSplitDNSWhenNoCustomResolvers.Store(disableSplitDNSWhenNoCustomResolvers)
  122. }
  123. // AsDebugJSON returns k as something that can be marshalled with json.Marshal
  124. // for debug.
  125. func (k *Knobs) AsDebugJSON() map[string]any {
  126. if k == nil {
  127. return nil
  128. }
  129. return map[string]any{
  130. "DisableUPnP": k.DisableUPnP.Load(),
  131. "DisableDRPO": k.DisableDRPO.Load(),
  132. "KeepFullWGConfig": k.KeepFullWGConfig.Load(),
  133. "RandomizeClientPort": k.RandomizeClientPort.Load(),
  134. "OneCGNAT": k.OneCGNAT.Load(),
  135. "ForceBackgroundSTUN": k.ForceBackgroundSTUN.Load(),
  136. "DisableDeltaUpdates": k.DisableDeltaUpdates.Load(),
  137. "PeerMTUEnable": k.PeerMTUEnable.Load(),
  138. "DisableDNSForwarderTCPRetries": k.DisableDNSForwarderTCPRetries.Load(),
  139. "SilentDisco": k.SilentDisco.Load(),
  140. "LinuxForceIPTables": k.LinuxForceIPTables.Load(),
  141. "LinuxForceNfTables": k.LinuxForceNfTables.Load(),
  142. "SeamlessKeyRenewal": k.SeamlessKeyRenewal.Load(),
  143. "ProbeUDPLifetime": k.ProbeUDPLifetime.Load(),
  144. "AppCStoreRoutes": k.AppCStoreRoutes.Load(),
  145. "UserDialUseRoutes": k.UserDialUseRoutes.Load(),
  146. "DisableSplitDNSWhenNoCustomResolvers": k.DisableSplitDNSWhenNoCustomResolvers.Load(),
  147. }
  148. }