controlknobs.go 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. "slices"
  8. "sync/atomic"
  9. "tailscale.com/syncs"
  10. "tailscale.com/tailcfg"
  11. "tailscale.com/types/opt"
  12. )
  13. // Knobs is the set of knobs that the control plane's coordination server can
  14. // adjust at runtime.
  15. type Knobs struct {
  16. // DisableUPnP indicates whether to attempt UPnP mapping.
  17. DisableUPnP atomic.Bool
  18. // DisableDRPO is whether control says to disable the
  19. // DERP route optimization (Issue 150).
  20. DisableDRPO atomic.Bool
  21. // KeepFullWGConfig is whether we should disable the lazy wireguard
  22. // programming and instead give WireGuard the full netmap always, even for
  23. // idle peers.
  24. KeepFullWGConfig atomic.Bool
  25. // RandomizeClientPort is whether control says we should randomize
  26. // the client port.
  27. RandomizeClientPort atomic.Bool
  28. // OneCGNAT is whether the the node should make one big CGNAT route
  29. // in the OS rather than one /32 per peer.
  30. OneCGNAT syncs.AtomicValue[opt.Bool]
  31. // ForceBackgroundSTUN forces netcheck STUN queries to keep
  32. // running in magicsock, even when idle.
  33. ForceBackgroundSTUN atomic.Bool
  34. // DisableDeltaUpdates is whether the node should not process
  35. // incremental (delta) netmap updates and should treat all netmap
  36. // changes as "full" ones as tailscaled did in 1.48.x and earlier.
  37. DisableDeltaUpdates atomic.Bool
  38. // PeerMTUEnable is whether the node should do peer path MTU discovery.
  39. PeerMTUEnable atomic.Bool
  40. // DisableDNSForwarderTCPRetries is whether the DNS forwarder should
  41. // skip retrying truncated queries over TCP.
  42. DisableDNSForwarderTCPRetries atomic.Bool
  43. // SilentDisco is whether the node should suppress disco heartbeats to its
  44. // peers.
  45. SilentDisco atomic.Bool
  46. // LinuxForceIPTables is whether the node should use iptables for Linux
  47. // netfiltering, unless overridden by the user.
  48. LinuxForceIPTables atomic.Bool
  49. // LinuxForceNfTables is whether the node should use nftables for Linux
  50. // netfiltering, unless overridden by the user.
  51. LinuxForceNfTables atomic.Bool
  52. // SeamlessKeyRenewal is whether to enable the alpha functionality of
  53. // renewing node keys without breaking connections.
  54. // http://go/seamless-key-renewal
  55. SeamlessKeyRenewal atomic.Bool
  56. // ProbeUDPLifetime is whether the node should probe UDP path lifetime on
  57. // the tail end of an active direct connection in magicsock.
  58. ProbeUDPLifetime atomic.Bool
  59. }
  60. // UpdateFromNodeAttributes updates k (if non-nil) based on the provided self
  61. // node attributes (Node.Capabilities).
  62. func (k *Knobs) UpdateFromNodeAttributes(selfNodeAttrs []tailcfg.NodeCapability, capMap tailcfg.NodeCapMap) {
  63. if k == nil {
  64. return
  65. }
  66. has := func(attr tailcfg.NodeCapability) bool {
  67. _, ok := capMap[attr]
  68. return ok || slices.Contains(selfNodeAttrs, attr)
  69. }
  70. var (
  71. keepFullWG = has(tailcfg.NodeAttrDebugDisableWGTrim)
  72. disableDRPO = has(tailcfg.NodeAttrDebugDisableDRPO)
  73. disableUPnP = has(tailcfg.NodeAttrDisableUPnP)
  74. randomizeClientPort = has(tailcfg.NodeAttrRandomizeClientPort)
  75. disableDeltaUpdates = has(tailcfg.NodeAttrDisableDeltaUpdates)
  76. oneCGNAT opt.Bool
  77. forceBackgroundSTUN = has(tailcfg.NodeAttrDebugForceBackgroundSTUN)
  78. peerMTUEnable = has(tailcfg.NodeAttrPeerMTUEnable)
  79. dnsForwarderDisableTCPRetries = has(tailcfg.NodeAttrDNSForwarderDisableTCPRetries)
  80. silentDisco = has(tailcfg.NodeAttrSilentDisco)
  81. forceIPTables = has(tailcfg.NodeAttrLinuxMustUseIPTables)
  82. forceNfTables = has(tailcfg.NodeAttrLinuxMustUseNfTables)
  83. seamlessKeyRenewal = has(tailcfg.NodeAttrSeamlessKeyRenewal)
  84. probeUDPLifetime = has(tailcfg.NodeAttrProbeUDPLifetime)
  85. )
  86. if has(tailcfg.NodeAttrOneCGNATEnable) {
  87. oneCGNAT.Set(true)
  88. } else if has(tailcfg.NodeAttrOneCGNATDisable) {
  89. oneCGNAT.Set(false)
  90. }
  91. k.KeepFullWGConfig.Store(keepFullWG)
  92. k.DisableDRPO.Store(disableDRPO)
  93. k.DisableUPnP.Store(disableUPnP)
  94. k.RandomizeClientPort.Store(randomizeClientPort)
  95. k.OneCGNAT.Store(oneCGNAT)
  96. k.ForceBackgroundSTUN.Store(forceBackgroundSTUN)
  97. k.DisableDeltaUpdates.Store(disableDeltaUpdates)
  98. k.PeerMTUEnable.Store(peerMTUEnable)
  99. k.DisableDNSForwarderTCPRetries.Store(dnsForwarderDisableTCPRetries)
  100. k.SilentDisco.Store(silentDisco)
  101. k.LinuxForceIPTables.Store(forceIPTables)
  102. k.LinuxForceNfTables.Store(forceNfTables)
  103. k.SeamlessKeyRenewal.Store(seamlessKeyRenewal)
  104. k.ProbeUDPLifetime.Store(probeUDPLifetime)
  105. }
  106. // AsDebugJSON returns k as something that can be marshalled with json.Marshal
  107. // for debug.
  108. func (k *Knobs) AsDebugJSON() map[string]any {
  109. if k == nil {
  110. return nil
  111. }
  112. return map[string]any{
  113. "DisableUPnP": k.DisableUPnP.Load(),
  114. "DisableDRPO": k.DisableDRPO.Load(),
  115. "KeepFullWGConfig": k.KeepFullWGConfig.Load(),
  116. "RandomizeClientPort": k.RandomizeClientPort.Load(),
  117. "OneCGNAT": k.OneCGNAT.Load(),
  118. "ForceBackgroundSTUN": k.ForceBackgroundSTUN.Load(),
  119. "DisableDeltaUpdates": k.DisableDeltaUpdates.Load(),
  120. "PeerMTUEnable": k.PeerMTUEnable.Load(),
  121. "DisableDNSForwarderTCPRetries": k.DisableDNSForwarderTCPRetries.Load(),
  122. "SilentDisco": k.SilentDisco.Load(),
  123. "LinuxForceIPTables": k.LinuxForceIPTables.Load(),
  124. "LinuxForceNfTables": k.LinuxForceNfTables.Load(),
  125. "SeamlessKeyRenewal": k.SeamlessKeyRenewal.Load(),
  126. "ProbeUDPLifetime": k.ProbeUDPLifetime.Load(),
  127. }
  128. }