Constants.hpp 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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 "../include/ZeroTierCore.h"
  16. #include "OS.hpp"
  17. #if __has_include("version.h")
  18. #include "version.h"
  19. #else /* dummy values for use inside IDEs, etc. */
  20. #define ZEROTIER_ONE_VERSION_MAJOR 255
  21. #define ZEROTIER_ONE_VERSION_MINOR 255
  22. #define ZEROTIER_ONE_VERSION_REVISION 255
  23. #define ZEROTIER_ONE_VERSION_BUILD 255
  24. #endif
  25. /**
  26. * Length of a ZeroTier address in bytes
  27. */
  28. #define ZT_ADDRESS_LENGTH 5
  29. /**
  30. * Addresses beginning with this byte are reserved for the joy of in-band signaling
  31. */
  32. #define ZT_ADDRESS_RESERVED_PREFIX 0xff
  33. /**
  34. * Maximum DNS or URL name size for an Endpoint (set so that max marshaled endpoint size is 64 bytes)
  35. */
  36. #define ZT_ENDPOINT_MAX_NAME_SIZE 61
  37. /**
  38. * Size of an identity hash (SHA384)
  39. */
  40. #define ZT_IDENTITY_HASH_SIZE 48
  41. /**
  42. * Default virtual network MTU (not physical)
  43. */
  44. #define ZT_DEFAULT_MTU 2800
  45. /**
  46. * Maximum number of packet fragments we'll support (protocol limit: 16)
  47. */
  48. #define ZT_MAX_PACKET_FRAGMENTS 12
  49. /**
  50. * Size of RX queue in packets
  51. */
  52. #define ZT_RX_QUEUE_SIZE 32
  53. /**
  54. * Size of TX queue in packets
  55. */
  56. #define ZT_TX_QUEUE_SIZE 32
  57. /**
  58. * Length of peer shared secrets (256-bit, do not change)
  59. */
  60. #define ZT_PEER_SECRET_KEY_LENGTH 32
  61. /**
  62. * Minimum delay between timer task checks to prevent thrashing
  63. */
  64. #define ZT_MIN_TIMER_TASK_INTERVAL 500
  65. /**
  66. * Maximum delay between timer task checks (should be a fraction of smallest housekeeping interval)
  67. */
  68. #define ZT_MAX_TIMER_TASK_INTERVAL 5000
  69. /**
  70. * How often most internal cleanup and housekeeping tasks are performed
  71. */
  72. #define ZT_HOUSEKEEPING_PERIOD 120000
  73. /**
  74. * How often network housekeeping is performed
  75. *
  76. * Note that this affects how frequently we re-request network configurations
  77. * from network controllers if we haven't received one yet.
  78. */
  79. #define ZT_NETWORK_HOUSEKEEPING_PERIOD 15000
  80. /**
  81. * Delay between WHOIS retries in ms
  82. */
  83. #define ZT_WHOIS_RETRY_DELAY 500
  84. /**
  85. * Transmit queue entry timeout
  86. */
  87. #define ZT_TRANSMIT_QUEUE_TIMEOUT 5000
  88. /**
  89. * Receive queue entry timeout
  90. */
  91. #define ZT_RECEIVE_QUEUE_TIMEOUT 5000
  92. /**
  93. * Maximum number of ZT hops allowed (this is not IP hops/TTL)
  94. *
  95. * The protocol allows up to 7, but we limit it to something smaller.
  96. */
  97. #define ZT_RELAY_MAX_HOPS 4
  98. /**
  99. * Period between keepalives sent to paths if no other traffic has been sent
  100. *
  101. * See https://conferences.sigcomm.org/imc/2010/papers/p260.pdf for
  102. * some real world data on NAT UDP timeouts. From the paper: "the
  103. * lowest measured timeout when a binding has seen bidirectional
  104. * traffic is 54 sec." 30 seconds is faster than really necessary.
  105. */
  106. #define ZT_PATH_KEEPALIVE_PERIOD 30000
  107. /**
  108. * Timeout for path aliveness (measured from last receive)
  109. */
  110. #define ZT_PATH_ACTIVITY_TIMEOUT ((ZT_PATH_KEEPALIVE_PERIOD * 2) + 5000)
  111. /**
  112. * Delay between full HELLO messages between peers
  113. */
  114. #define ZT_PEER_PING_PERIOD 60000
  115. /**
  116. * Timeout for overall peer activity (measured from last receive)
  117. */
  118. #define ZT_PEER_ALIVE_TIMEOUT ((ZT_PEER_PING_PERIOD * 2) + 5000)
  119. /**
  120. * Timeout for overall peer activity (measured from last receive)
  121. */
  122. #define ZT_PEER_ACTIVITY_TIMEOUT (ZT_PEER_PING_PERIOD + 5000)
  123. /**
  124. * Maximum interval between sort/prioritize of paths for a peer
  125. */
  126. #define ZT_PEER_PRIORITIZE_PATHS_INTERVAL 5000
  127. /**
  128. * Delay between requests for updated network autoconf information
  129. *
  130. * Don't lengthen this as it affects things like QoS / uptime monitoring
  131. * via ZeroTier Central. This is the heartbeat, basically.
  132. */
  133. #define ZT_NETWORK_AUTOCONF_DELAY 60000
  134. /**
  135. * Sanity limit on maximum bridge routes
  136. *
  137. * If the number of bridge routes exceeds this, we cull routes from the
  138. * bridges with the most MACs behind them until it doesn't. This is a
  139. * sanity limit to prevent memory-filling DOS attacks, nothing more. No
  140. * physical LAN has anywhere even close to this many nodes. Note that this
  141. * does not limit the size of ZT virtual LANs, only bridge routing.
  142. */
  143. #define ZT_MAX_BRIDGE_ROUTES 16777216
  144. /**
  145. * If there is no known L2 bridging route, spam to up to this many active bridges
  146. */
  147. #define ZT_MAX_BRIDGE_SPAM 32
  148. /**
  149. * Interval between direct path pushes in milliseconds if we don't have a path
  150. */
  151. #define ZT_DIRECT_PATH_PUSH_INTERVAL 30000
  152. /**
  153. * Interval between direct path pushes in milliseconds if we already have a path
  154. */
  155. #define ZT_DIRECT_PATH_PUSH_INTERVAL_HAVEPATH 120000
  156. /**
  157. * Maximum number of paths per IP scope (e.g. global, link-local) and family (e.g. v4/v6)
  158. */
  159. #define ZT_PUSH_DIRECT_PATHS_MAX_PER_SCOPE_AND_FAMILY 4
  160. /**
  161. * WHOIS rate limit (we allow these to be pretty fast)
  162. */
  163. #define ZT_PEER_WHOIS_RATE_LIMIT 100
  164. /**
  165. * General rate limit for other kinds of rate-limited packets (HELLO, credential request, etc.) both inbound and outbound
  166. */
  167. #define ZT_PEER_GENERAL_RATE_LIMIT 500
  168. /**
  169. * Don't do expensive identity validation more often than this
  170. *
  171. * IPv4 and IPv6 address prefixes are hashed down to 14-bit (0-16383) integers
  172. * using the first 24 bits for IPv4 or the first 48 bits for IPv6. These are
  173. * then rate limited to one identity validation per this often milliseconds.
  174. */
  175. #if (defined(__amd64) || defined(__amd64__) || defined(__x86_64) || defined(__x86_64__) || defined(__AMD64) || defined(__AMD64__) || defined(_M_X64) || defined(_M_AMD64))
  176. // AMD64 machines can do anywhere from one every 50ms to one every 10ms. This provides plenty of margin.
  177. #define ZT_IDENTITY_VALIDATION_SOURCE_RATE_LIMIT 2000
  178. #else
  179. #if (defined(__i386__) || defined(__i486__) || defined(__i586__) || defined(__i686__) || defined(_M_IX86) || defined(_X86_) || defined(__I86__))
  180. // 32-bit Intel machines usually average about one every 100ms
  181. #define ZT_IDENTITY_VALIDATION_SOURCE_RATE_LIMIT 5000
  182. #else
  183. // This provides a safe margin for ARM, MIPS, etc. that usually average one every 250-400ms
  184. #define ZT_IDENTITY_VALIDATION_SOURCE_RATE_LIMIT 10000
  185. #endif
  186. #endif
  187. /**
  188. * Size of a buffer to store either a C25519 or an ECC P-384 signature
  189. *
  190. * This must be large enough to hold all signature types.
  191. */
  192. #define ZT_SIGNATURE_BUFFER_SIZE 96
  193. // Internal cryptographic algorithm IDs (these match relevant identity types)
  194. #define ZT_CRYPTO_ALG_C25519 0
  195. #define ZT_CRYPTO_ALG_P384 1
  196. // Exceptions thrown in core ZT code
  197. #define ZT_EXCEPTION_OUT_OF_BOUNDS 100
  198. #define ZT_EXCEPTION_OUT_OF_MEMORY 101
  199. #define ZT_EXCEPTION_PRIVATE_KEY_REQUIRED 102
  200. #define ZT_EXCEPTION_INVALID_ARGUMENT 103
  201. #define ZT_EXCEPTION_INVALID_SERIALIZED_DATA_INVALID_TYPE 200
  202. #define ZT_EXCEPTION_INVALID_SERIALIZED_DATA_OVERFLOW 201
  203. #define ZT_EXCEPTION_INVALID_SERIALIZED_DATA_INVALID_CRYPTOGRAPHIC_TOKEN 202
  204. #define ZT_EXCEPTION_INVALID_SERIALIZED_DATA_BAD_ENCODING 203
  205. /* Ethernet frame types that might be relevant to us */
  206. #define ZT_ETHERTYPE_IPV4 0x0800
  207. #define ZT_ETHERTYPE_ARP 0x0806
  208. #define ZT_ETHERTYPE_IPV6 0x86dd
  209. #endif