debugknobs.go 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. //go:build !ios
  5. // +build !ios
  6. package magicsock
  7. import (
  8. "os"
  9. "strconv"
  10. )
  11. // Various debugging and experimental tweakables, set by environment
  12. // variable.
  13. var (
  14. // logPacketDests prints the known addresses for a peer every time
  15. // they change, in the legacy (non-discovery) endpoint code only.
  16. logPacketDests, _ = strconv.ParseBool(os.Getenv("TS_DEBUG_LOG_PACKET_DESTS"))
  17. // debugDisco prints verbose logs of active discovery events as
  18. // they happen.
  19. debugDisco, _ = strconv.ParseBool(os.Getenv("TS_DEBUG_DISCO"))
  20. // debugOmitLocalAddresses removes all local interface addresses
  21. // from magicsock's discovered local endpoints. Used in some tests.
  22. debugOmitLocalAddresses, _ = strconv.ParseBool(os.Getenv("TS_DEBUG_OMIT_LOCAL_ADDRS"))
  23. // debugUseDerpRoute temporarily (2020-03-22) controls whether DERP
  24. // reverse routing is enabled (Issue 150). It will become always true
  25. // later.
  26. debugUseDerpRouteEnv = os.Getenv("TS_DEBUG_ENABLE_DERP_ROUTE")
  27. debugUseDerpRoute, _ = strconv.ParseBool(debugUseDerpRouteEnv)
  28. // logDerpVerbose logs all received DERP packets, including their
  29. // full payload.
  30. logDerpVerbose, _ = strconv.ParseBool(os.Getenv("TS_DEBUG_DERP"))
  31. // debugReSTUNStopOnIdle unconditionally enables the "shut down
  32. // STUN if magicsock is idle" behavior that normally only triggers
  33. // on mobile devices, lowers the shutdown interval, and logs more
  34. // verbosely about idle measurements.
  35. debugReSTUNStopOnIdle, _ = strconv.ParseBool(os.Getenv("TS_DEBUG_RESTUN_STOP_ON_IDLE"))
  36. // debugAlwaysDERP disables the use of UDP, forcing all peer communication over DERP.
  37. debugAlwaysDERP, _ = strconv.ParseBool(os.Getenv("TS_DEBUG_ALWAYS_USE_DERP"))
  38. )
  39. // inTest reports whether the running program is a test that set the
  40. // IN_TS_TEST environment variable.
  41. //
  42. // Unlike the other debug tweakables above, this one needs to be
  43. // checked every time at runtime, because tests set this after program
  44. // startup.
  45. func inTest() bool {
  46. inTest, _ := strconv.ParseBool(os.Getenv("IN_TS_TEST"))
  47. return inTest
  48. }