controlknobs.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // Copyright (c) 2021 Tailscale Inc & AUTHORS All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. // Package controlknobs contains client options configurable from control which can be turned on
  5. // or off. The ability to turn options on and off is for incrementally adding features in.
  6. package controlknobs
  7. import (
  8. "os"
  9. "strconv"
  10. "sync/atomic"
  11. "tailscale.com/types/opt"
  12. )
  13. // disableUPnP indicates whether to attempt UPnP mapping.
  14. var disableUPnP atomic.Value
  15. func init() {
  16. v, _ := strconv.ParseBool(os.Getenv("TS_DISABLE_UPNP"))
  17. var toStore opt.Bool
  18. toStore.Set(v)
  19. disableUPnP.Store(toStore)
  20. }
  21. // DisableUPnP reports the last reported value from control
  22. // whether UPnP portmapping should be disabled.
  23. func DisableUPnP() opt.Bool {
  24. v, _ := disableUPnP.Load().(opt.Bool)
  25. return v
  26. }
  27. // SetDisableUPnP will set whether UPnP connections are permitted or not,
  28. // intended to be set from control.
  29. func SetDisableUPnP(v opt.Bool) {
  30. old, ok := disableUPnP.Load().(opt.Bool)
  31. if !ok || old != v {
  32. disableUPnP.Store(v)
  33. }
  34. }