Constants.hpp 5.6 KB

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