debugknobs.go 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // Copyright (c) Tailscale Inc & AUTHORS
  2. // SPDX-License-Identifier: BSD-3-Clause
  3. //go:build !ios && !js
  4. package magicsock
  5. import (
  6. "tailscale.com/envknob"
  7. )
  8. // Various debugging and experimental tweakables, set by environment
  9. // variable.
  10. var (
  11. // debugDisco prints verbose logs of active discovery events as
  12. // they happen.
  13. debugDisco = envknob.RegisterBool("TS_DEBUG_DISCO")
  14. // debugPeerMap prints verbose logs of changes to the peermap.
  15. debugPeerMap = envknob.RegisterBool("TS_DEBUG_MAGICSOCK_PEERMAP")
  16. // debugOmitLocalAddresses removes all local interface addresses
  17. // from magicsock's discovered local endpoints. Used in some tests.
  18. debugOmitLocalAddresses = envknob.RegisterBool("TS_DEBUG_OMIT_LOCAL_ADDRS")
  19. // debugUseDerpRoute temporarily (2020-03-22) controls whether DERP
  20. // reverse routing is enabled (Issue 150).
  21. debugUseDerpRoute = envknob.RegisterOptBool("TS_DEBUG_ENABLE_DERP_ROUTE")
  22. // logDerpVerbose logs all received DERP packets, including their
  23. // full payload.
  24. logDerpVerbose = envknob.RegisterBool("TS_DEBUG_DERP")
  25. // debugReSTUNStopOnIdle unconditionally enables the "shut down
  26. // STUN if magicsock is idle" behavior that normally only triggers
  27. // on mobile devices, lowers the shutdown interval, and logs more
  28. // verbosely about idle measurements.
  29. debugReSTUNStopOnIdle = envknob.RegisterBool("TS_DEBUG_RESTUN_STOP_ON_IDLE")
  30. // debugAlwaysDERP disables the use of UDP, forcing all peer communication over DERP.
  31. debugAlwaysDERP = envknob.RegisterBool("TS_DEBUG_ALWAYS_USE_DERP")
  32. // debugDERPAddr sets the derp address manually, overriding the DERP map from control.
  33. debugUseDERPAddr = envknob.RegisterString("TS_DEBUG_USE_DERP_ADDR")
  34. // debugDERPUseHTTP tells clients to connect to DERP via HTTP on port 3340 instead of
  35. // HTTPS on 443.
  36. debugUseDERPHTTP = envknob.RegisterBool("TS_DEBUG_USE_DERP_HTTP")
  37. // debugEnableSilentDisco disables the use of heartbeatTimer on the endpoint struct
  38. // and attempts to handle disco silently. See issue #540 for details.
  39. debugEnableSilentDisco = envknob.RegisterBool("TS_DEBUG_ENABLE_SILENT_DISCO")
  40. // debugSendCallMeUnknownPeer sends a CallMeMaybe to a non-existent destination every
  41. // time we send a real CallMeMaybe to test the PeerGoneNotHere logic.
  42. debugSendCallMeUnknownPeer = envknob.RegisterBool("TS_DEBUG_SEND_CALLME_UNKNOWN_PEER")
  43. // debugBindSocket prints extra debugging about socket rebinding in magicsock.
  44. debugBindSocket = envknob.RegisterBool("TS_DEBUG_MAGICSOCK_BIND_SOCKET")
  45. // debugRingBufferMaxSizeBytes overrides the default size of the endpoint
  46. // history ringbuffer.
  47. debugRingBufferMaxSizeBytes = envknob.RegisterInt("TS_DEBUG_MAGICSOCK_RING_BUFFER_MAX_SIZE_BYTES")
  48. // debugEnablePMTUD enables the peer MTU feature, which does path MTU
  49. // discovery on UDP connections between peers. Currently (2023-09-05)
  50. // this only turns on the don't fragment bit for the magicsock UDP
  51. // sockets.
  52. //
  53. //lint:ignore U1000 used on Linux/Darwin only
  54. debugEnablePMTUD = envknob.RegisterOptBool("TS_DEBUG_ENABLE_PMTUD")
  55. // debugPMTUD prints extra debugging about peer MTU path discovery.
  56. //
  57. //lint:ignore U1000 used on Linux/Darwin only
  58. debugPMTUD = envknob.RegisterBool("TS_DEBUG_PMTUD")
  59. // Hey you! Adding a new debugknob? Make sure to stub it out in the
  60. // debugknobs_stubs.go file too.
  61. )
  62. // inTest reports whether the running program is a test that set the
  63. // IN_TS_TEST environment variable.
  64. //
  65. // Unlike the other debug tweakables above, this one needs to be
  66. // checked every time at runtime, because tests set this after program
  67. // startup.
  68. func inTest() bool { return envknob.Bool("IN_TS_TEST") }