Constants.hpp 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. /*
  2. * Copyright (c)2013-2020 ZeroTier, Inc.
  3. *
  4. * Use of this software is governed by the Business Source License included
  5. * in the LICENSE.TXT file in the project's root directory.
  6. *
  7. * Change Date: 2024-01-01
  8. *
  9. * On the date above, in accordance with the Business Source License, use
  10. * of this software will be governed by version 2.0 of the Apache License.
  11. */
  12. /****/
  13. #ifndef ZT_CONSTANTS_HPP
  14. #define ZT_CONSTANTS_HPP
  15. #include "zerotier.h"
  16. #include "OS.hpp"
  17. #if __has_include("version.h")
  18. #include "version.h"
  19. #endif
  20. /**
  21. * Version bit packed into four 16-bit fields in a 64-bit unsigned integer.
  22. */
  23. #define ZT_VERSION_PACKED ( \
  24. ((uint64_t)ZEROTIER_VERSION_MAJOR << 48U) | \
  25. ((uint64_t)ZEROTIER_VERSION_MINOR << 32U) | \
  26. ((uint64_t)ZEROTIER_VERSION_REVISION << 16U) | \
  27. ((uint64_t)ZEROTIER_VERSION_BUILD) )
  28. /**
  29. * Length of a ZeroTier address in bytes
  30. */
  31. #define ZT_ADDRESS_LENGTH 5
  32. /**
  33. * Length of a ZeroTier address in digits
  34. */
  35. #define ZT_ADDRESS_LENGTH_HEX 10
  36. /**
  37. * Addresses beginning with this byte are reserved for the joy of in-band signaling
  38. */
  39. #define ZT_ADDRESS_RESERVED_PREFIX 0xff
  40. /**
  41. * Bit mask for addresses against a uint64_t
  42. */
  43. #define ZT_ADDRESS_MASK 0xffffffffffULL
  44. /**
  45. * Size of an identity fingerprint hash (SHA384) in bytes
  46. */
  47. #define ZT_FINGERPRINT_HASH_SIZE 48
  48. /**
  49. * Default virtual network MTU (not physical)
  50. */
  51. #define ZT_DEFAULT_MTU 2800
  52. /**
  53. * Maximum number of packet fragments we'll support (11 is the maximum that will fit in a Buf)
  54. */
  55. #define ZT_MAX_PACKET_FRAGMENTS 11
  56. /**
  57. * Anti-DOS limit on the maximum incoming fragments per path
  58. */
  59. #define ZT_MAX_INCOMING_FRAGMENTS_PER_PATH 16
  60. /**
  61. * Sanity limit on the maximum size of a network config object
  62. */
  63. #define ZT_MAX_NETWORK_CONFIG_BYTES 131072
  64. /**
  65. * Length of symmetric keys
  66. */
  67. #define ZT_SYMMETRIC_KEY_SIZE 48
  68. /**
  69. * Time limit for ephemeral keys: 30 minutes.
  70. */
  71. #define ZT_SYMMETRIC_KEY_TTL 1800000
  72. /**
  73. * Maximum number of messages per symmetric key.
  74. */
  75. #define ZT_SYMMETRIC_KEY_TTL_MESSAGES 2147483648
  76. /**
  77. * Normal delay between processBackgroundTasks calls.
  78. */
  79. #define ZT_TIMER_TASK_INTERVAL 2000
  80. /**
  81. * How often most internal cleanup and housekeeping tasks are performed
  82. */
  83. #define ZT_HOUSEKEEPING_PERIOD 300000
  84. /**
  85. * How often network housekeeping is performed
  86. *
  87. * Note that this affects how frequently we re-request network configurations
  88. * from network controllers if we haven't received one yet.
  89. */
  90. #define ZT_NETWORK_HOUSEKEEPING_PERIOD 30000
  91. /**
  92. * Delay between WHOIS retries in ms
  93. */
  94. #define ZT_WHOIS_RETRY_DELAY 500
  95. /**
  96. * Maximum number of ZT hops allowed (this is not IP hops/TTL)
  97. *
  98. * The protocol allows up to 7, but we limit it to something smaller.
  99. */
  100. #define ZT_RELAY_MAX_HOPS 4
  101. /**
  102. * Period between keepalives sent to paths if no other traffic has been sent.
  103. *
  104. * The average NAT timeout is 60-120s, but there exist NATs in the wild with timeouts
  105. * as short as 30s. Come in just under 30s and we should be fine.
  106. */
  107. #define ZT_PATH_KEEPALIVE_PERIOD 28000
  108. /**
  109. * Timeout for path alive-ness (measured from last receive)
  110. */
  111. #define ZT_PATH_ALIVE_TIMEOUT ((ZT_PATH_KEEPALIVE_PERIOD * 2) + 5000)
  112. /**
  113. * Maximum number of queued endpoints to try per "pulse."
  114. */
  115. #define ZT_NAT_T_PORT_SCAN_MAX 16
  116. /**
  117. * Minimum interval between attempts to reach a given physical endpoint
  118. */
  119. #define ZT_PATH_MIN_TRY_INTERVAL ZT_PATH_KEEPALIVE_PERIOD
  120. /**
  121. * Delay between calls to the pulse() method in Peer for each peer
  122. */
  123. #define ZT_PEER_PULSE_INTERVAL 8000
  124. /**
  125. * Interval between HELLOs to peers.
  126. */
  127. #define ZT_PEER_HELLO_INTERVAL 120000
  128. /**
  129. * Timeout for peers being alive
  130. */
  131. #define ZT_PEER_ALIVE_TIMEOUT ((ZT_PEER_HELLO_INTERVAL * 2) + 5000)
  132. /**
  133. * Global timeout for peers in milliseconds
  134. *
  135. * This is global as in "entire world," and this value is 30 days. In this
  136. * code the global timeout is used to determine when to ignore cached
  137. * peers and their identity<>address mappings.
  138. */
  139. #define ZT_PEER_GLOBAL_TIMEOUT 2592000000LL
  140. /**
  141. * Interval between sort/prioritize of paths for a peer
  142. */
  143. #define ZT_PEER_PRIORITIZE_PATHS_INTERVAL 5000
  144. /**
  145. * Number of previous endpoints to cache in peer records.
  146. */
  147. #define ZT_PEER_ENDPOINT_CACHE_SIZE 8
  148. /**
  149. * Delay between requests for updated network autoconf information
  150. *
  151. * Don't lengthen this as it affects things like QoS / uptime monitoring
  152. * via ZeroTier Central. This is the heartbeat, basically.
  153. */
  154. #define ZT_NETWORK_AUTOCONF_DELAY 60000
  155. /**
  156. * Sanity limit on maximum bridge routes
  157. *
  158. * If the number of bridge routes exceeds this, we cull routes from the
  159. * bridges with the most MACs behind them until it doesn't. This is a
  160. * sanity limit to prevent memory-filling DOS attacks, nothing more. No
  161. * physical LAN has anywhere even close to this many nodes. Note that this
  162. * does not limit the size of ZT virtual LANs, only bridge routing.
  163. */
  164. #define ZT_MAX_BRIDGE_ROUTES 16777216
  165. /**
  166. * WHOIS rate limit (we allow these to be pretty fast)
  167. */
  168. #define ZT_PEER_WHOIS_RATE_LIMIT 100
  169. /**
  170. * General rate limit for other kinds of rate-limited packets (HELLO, credential request, etc.) both inbound and outbound
  171. */
  172. #define ZT_PEER_GENERAL_RATE_LIMIT 500
  173. /**
  174. * Rate limit for responses to short probes to prevent amplification attacks
  175. */
  176. #define ZT_PEER_PROBE_RESPONSE_RATE_LIMIT 5000
  177. /**
  178. * Size of a buffer to store either a C25519 or an ECC P-384 signature
  179. *
  180. * This must be large enough to hold all signature types, which right now is
  181. * Curve25519 EDDSA and NIST P-384 ECDSA.
  182. */
  183. #define ZT_SIGNATURE_BUFFER_SIZE 96
  184. /* Ethernet frame types that might be relevant to us */
  185. #define ZT_ETHERTYPE_IPV4 0x0800
  186. #define ZT_ETHERTYPE_ARP 0x0806
  187. #define ZT_ETHERTYPE_IPV6 0x86dd
  188. #endif