summaryrefslogtreecommitdiffhomepage
path: root/control/controlknobs/controlknobs.go
diff options
context:
space:
mode:
authorMaisem Ali <maisem@tailscale.com>2023-09-18 08:52:22 -0700
committerMaisem Ali <maisem@gmail.com>2023-09-18 12:00:34 -0700
commit19a9d9037f9770adb2cc4b812aeb1f1ff02da5af (patch)
treec24f783d7e43919f34d2717e0936975b0a243f8e /control/controlknobs/controlknobs.go
parent4da0689c2c78b647951eeced9b005fe5f5948ad7 (diff)
downloadtailscale-19a9d9037f9770adb2cc4b812aeb1f1ff02da5af.tar.xz
tailscale-19a9d9037f9770adb2cc4b812aeb1f1ff02da5af.zip
tailcfg: add NodeCapMap
Like PeerCapMap, add a field to `tailcfg.Node` which provides a map of Capability to raw JSON messages which are deferred to be parsed later by the application code which cares about the specific capabilities. This effectively allows us to prototype new behavior without having to commit to a schema in tailcfg, and it also opens up the possibilities to develop custom behavior in tsnet applications w/o having to plumb through application specific data in the MapResponse. Updates #4217 Signed-off-by: Maisem Ali <maisem@tailscale.com>
Diffstat (limited to 'control/controlknobs/controlknobs.go')
-rw-r--r--control/controlknobs/controlknobs.go44
1 files changed, 18 insertions, 26 deletions
diff --git a/control/controlknobs/controlknobs.go b/control/controlknobs/controlknobs.go
index 50b0298a9..4d57b30a3 100644
--- a/control/controlknobs/controlknobs.go
+++ b/control/controlknobs/controlknobs.go
@@ -6,6 +6,7 @@
package controlknobs
import (
+ "slices"
"sync/atomic"
"tailscale.com/syncs"
@@ -48,39 +49,30 @@ type Knobs struct {
// UpdateFromNodeAttributes updates k (if non-nil) based on the provided self
// node attributes (Node.Capabilities).
-func (k *Knobs) UpdateFromNodeAttributes(selfNodeAttrs []tailcfg.NodeCapability) {
+func (k *Knobs) UpdateFromNodeAttributes(selfNodeAttrs []tailcfg.NodeCapability, capMap tailcfg.NodeCapMap) {
if k == nil {
return
}
+ has := func(attr tailcfg.NodeCapability) bool {
+ _, ok := capMap[attr]
+ return ok || slices.Contains(selfNodeAttrs, attr)
+ }
var (
- keepFullWG bool
- disableDRPO bool
- disableUPnP bool
- randomizeClientPort bool
- disableDeltaUpdates bool
+ keepFullWG = has(tailcfg.NodeAttrDebugDisableWGTrim)
+ disableDRPO = has(tailcfg.NodeAttrDebugDisableDRPO)
+ disableUPnP = has(tailcfg.NodeAttrDisableUPnP)
+ randomizeClientPort = has(tailcfg.NodeAttrRandomizeClientPort)
+ disableDeltaUpdates = has(tailcfg.NodeAttrDisableDeltaUpdates)
oneCGNAT opt.Bool
- forceBackgroundSTUN bool
+ forceBackgroundSTUN = has(tailcfg.NodeAttrDebugForceBackgroundSTUN)
)
- for _, attr := range selfNodeAttrs {
- switch attr {
- case tailcfg.NodeAttrDebugDisableWGTrim:
- keepFullWG = true
- case tailcfg.NodeAttrDebugDisableDRPO:
- disableDRPO = true
- case tailcfg.NodeAttrDisableUPnP:
- disableUPnP = true
- case tailcfg.NodeAttrRandomizeClientPort:
- randomizeClientPort = true
- case tailcfg.NodeAttrOneCGNATEnable:
- oneCGNAT.Set(true)
- case tailcfg.NodeAttrOneCGNATDisable:
- oneCGNAT.Set(false)
- case tailcfg.NodeAttrDebugForceBackgroundSTUN:
- forceBackgroundSTUN = true
- case tailcfg.NodeAttrDisableDeltaUpdates:
- disableDeltaUpdates = true
- }
+
+ if has(tailcfg.NodeAttrOneCGNATEnable) {
+ oneCGNAT.Set(true)
+ } else if has(tailcfg.NodeAttrOneCGNATDisable) {
+ oneCGNAT.Set(false)
}
+
k.KeepFullWGConfig.Store(keepFullWG)
k.DisableDRPO.Store(disableDRPO)
k.DisableUPnP.Store(disableUPnP)