summaryrefslogtreecommitdiffhomepage
path: root/control/controlknobs/controlknobs.go
diff options
context:
space:
mode:
authorjulianknodt <julianknodt@gmail.com>2021-06-22 15:29:01 -0700
committerJulian Knodt <julianknodt@gmail.com>2021-07-15 15:22:12 -0700
commit1bb6abc604c1c798ea3aa2ea539273f0967089d8 (patch)
tree9f91a80f2c3d0683572778e07a61a8b727d9d4d4 /control/controlknobs/controlknobs.go
parent236eb4d04d33c43b0d73fb7372353cb26b62421b (diff)
downloadtailscale-1bb6abc604c1c798ea3aa2ea539273f0967089d8.tar.xz
tailscale-1bb6abc604c1c798ea3aa2ea539273f0967089d8.zip
net/portmapper: add upnp port mapping
Add in UPnP portmapping, using goupnp library in order to get the UPnP client and run the portmapping functions. This rips out anywhere where UPnP used to be in portmapping, and has a flow separate from PMP and PCP. RELNOTE=portmapper now supports UPnP mappings Fixes #682 Updates #2109 Signed-off-by: julianknodt <julianknodt@gmail.com>
Diffstat (limited to 'control/controlknobs/controlknobs.go')
-rw-r--r--control/controlknobs/controlknobs.go41
1 files changed, 41 insertions, 0 deletions
diff --git a/control/controlknobs/controlknobs.go b/control/controlknobs/controlknobs.go
new file mode 100644
index 000000000..884c0f8dd
--- /dev/null
+++ b/control/controlknobs/controlknobs.go
@@ -0,0 +1,41 @@
+// Copyright (c) 2021 Tailscale Inc & AUTHORS All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// 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 (
+ "os"
+ "strconv"
+ "sync/atomic"
+
+ "tailscale.com/types/opt"
+)
+
+// disableUPnP indicates whether to attempt UPnP mapping.
+var disableUPnP atomic.Value
+
+func init() {
+ v, _ := strconv.ParseBool(os.Getenv("TS_DISABLE_UPNP"))
+ var toStore opt.Bool
+ toStore.Set(v)
+ disableUPnP.Store(toStore)
+}
+
+// DisableUPnP reports the last reported value from control
+// whether UPnP portmapping should be disabled.
+func DisableUPnP() opt.Bool {
+ v, _ := disableUPnP.Load().(opt.Bool)
+ return v
+}
+
+// SetDisableUPnP will set whether UPnP connections are permitted or not,
+// intended to be set from control.
+func SetDisableUPnP(v opt.Bool) {
+ old, ok := disableUPnP.Load().(opt.Bool)
+ if !ok || old != v {
+ disableUPnP.Store(v)
+ }
+}