Constants.hpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  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 "../include/ZeroTierOne.h"
  16. //
  17. // This include file also auto-detects and canonicalizes some environment
  18. // information defines:
  19. //
  20. // __LINUX__
  21. // __APPLE__
  22. // __BSD__ (OSX also defines this)
  23. // __UNIX_LIKE__ (Linux, BSD, etc.)
  24. // __WINDOWS__
  25. //
  26. // Also makes sure __BYTE_ORDER is defined reasonably.
  27. //
  28. #ifndef ZT_INLINE
  29. #define ZT_INLINE inline
  30. #endif
  31. #define restrict
  32. // Hack: make sure __GCC__ is defined on old GCC compilers
  33. #ifndef __GCC__
  34. #if defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1) || defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2) || defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4)
  35. #define __GCC__
  36. #endif
  37. #endif
  38. #if defined(__linux__) || defined(linux) || defined(__LINUX__) || defined(__linux)
  39. #ifndef __LINUX__
  40. #define __LINUX__
  41. #endif
  42. #ifndef __UNIX_LIKE__
  43. #define __UNIX_LIKE__
  44. #endif
  45. #include <endian.h>
  46. #if (defined(__amd64) || defined(__amd64__) || defined(__x86_64) || defined(__x86_64__) || defined(__AMD64) || defined(__AMD64__) || defined(_M_X64) || defined(__aarch64__))
  47. #define OIDC_SUPPORTED 1
  48. #else
  49. #define OIDC_SUPPORTED 0
  50. #endif
  51. #endif
  52. #ifdef __APPLE__
  53. #define OIDC_SUPPORTED 1
  54. #define likely(x) __builtin_expect((x),1)
  55. #define unlikely(x) __builtin_expect((x),0)
  56. #include <TargetConditionals.h>
  57. #ifndef __UNIX_LIKE__
  58. #define __UNIX_LIKE__
  59. #endif
  60. #ifndef __BSD__
  61. #define __BSD__
  62. #endif
  63. #include <machine/endian.h>
  64. #endif
  65. #if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
  66. #define OIDC_SUPPORTED 0
  67. #ifndef __UNIX_LIKE__
  68. #define __UNIX_LIKE__
  69. #endif
  70. #ifndef __BSD__
  71. #define __BSD__
  72. #endif
  73. #include <machine/endian.h>
  74. #ifndef __BYTE_ORDER
  75. #define __BYTE_ORDER _BYTE_ORDER
  76. #define __LITTLE_ENDIAN _LITTLE_ENDIAN
  77. #define __BIG_ENDIAN _BIG_ENDIAN
  78. #endif
  79. #endif
  80. #if defined(_WIN32) || defined(_WIN64)
  81. #define OIDC_SUPPORTED 1
  82. #ifndef __WINDOWS__
  83. #define __WINDOWS__
  84. #endif
  85. #ifndef NOMINMAX
  86. #define NOMINMAX
  87. #endif
  88. #pragma warning(disable : 4290)
  89. #pragma warning(disable : 4996)
  90. #pragma warning(disable : 4101)
  91. #undef __UNIX_LIKE__
  92. #undef __BSD__
  93. #include <winsock2.h>
  94. #include <windows.h>
  95. #endif
  96. #ifdef __NetBSD__
  97. #ifndef RTF_MULTICAST
  98. #define RTF_MULTICAST 0x20000000
  99. #endif
  100. #endif
  101. #if (defined(__amd64) || defined(__amd64__) || defined(__x86_64) || defined(__x86_64__) || defined(__AMD64) || defined(__AMD64__) || defined(_M_X64))
  102. #define ZT_ARCH_X64 1
  103. #include <xmmintrin.h>
  104. #include <emmintrin.h>
  105. #include <immintrin.h>
  106. #endif
  107. #if (defined(__ARM_NEON) || defined(__ARM_NEON__) || defined(ZT_ARCH_ARM_HAS_NEON))
  108. #if (defined(__APPLE__) && !defined(__LP64__)) || (defined(__ANDROID__) && defined(__arm__))
  109. #ifdef ZT_ARCH_ARM_HAS_NEON
  110. #undef ZT_ARCH_ARM_HAS_NEON
  111. #endif
  112. #else
  113. #ifndef ZT_ARCH_ARM_HAS_NEON
  114. #define ZT_ARCH_ARM_HAS_NEON 1
  115. #endif
  116. #include <arm_neon.h>
  117. /*#include <arm_acle.h>*/
  118. #endif
  119. #endif
  120. // Define ZT_NO_TYPE_PUNNING to disable reckless casts on anything other than x86/x64.
  121. #if (!(defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64) || defined(_M_AMD64) || defined(_M_X64) || defined(i386) || defined(__i386) || defined(__i386__) || defined(__i486__) || defined(__i586__) || defined(__i686__) || defined(_M_IX86) || defined(__X86__) || defined(_X86_) || defined(__I86__) || defined(__INTEL__) || defined(__386)))
  122. #ifndef ZT_NO_TYPE_PUNNING
  123. #define ZT_NO_TYPE_PUNNING 1
  124. #endif
  125. #endif
  126. #ifdef ZT_NO_TYPE_PUNNING
  127. #ifndef ZT_NO_UNALIGNED_ACCESS
  128. #define ZT_NO_UNALIGNED_ACCESS 1
  129. #endif
  130. #endif
  131. // Assume little endian if not defined
  132. #if (defined(__APPLE__) || defined(__WINDOWS__)) && (!defined(__BYTE_ORDER))
  133. #undef __BYTE_ORDER
  134. #undef __LITTLE_ENDIAN
  135. #undef __BIG_ENDIAN
  136. #define __BIG_ENDIAN 4321
  137. #define __LITTLE_ENDIAN 1234
  138. #define __BYTE_ORDER 1234
  139. #endif
  140. #ifdef __WINDOWS__
  141. #define ZT_PATH_SEPARATOR '\\'
  142. #define ZT_PATH_SEPARATOR_S "\\"
  143. #define ZT_EOL_S "\r\n"
  144. #else
  145. #define ZT_PATH_SEPARATOR '/'
  146. #define ZT_PATH_SEPARATOR_S "/"
  147. #define ZT_EOL_S "\n"
  148. #endif
  149. #ifndef __BYTE_ORDER
  150. #include <endian.h>
  151. #endif
  152. #if (defined(__GNUC__) && (__GNUC__ >= 3)) || (defined(__INTEL_COMPILER) && (__INTEL_COMPILER >= 800)) || defined(__clang__)
  153. #ifndef likely
  154. #define likely(x) __builtin_expect((x),1)
  155. #endif
  156. #ifndef unlikely
  157. #define unlikely(x) __builtin_expect((x),0)
  158. #endif
  159. #else
  160. #ifndef likely
  161. #define likely(x) (x)
  162. #endif
  163. #ifndef unlikely
  164. #define unlikely(x) (x)
  165. #endif
  166. #endif
  167. #ifdef __WINDOWS__
  168. #define ZT_PACKED_STRUCT(D) __pragma(pack(push,1)) D __pragma(pack(pop))
  169. #else
  170. #define ZT_PACKED_STRUCT(D) D __attribute__((packed))
  171. #endif
  172. /**
  173. * Length of a ZeroTier address in bytes
  174. */
  175. #define ZT_ADDRESS_LENGTH 5
  176. /**
  177. * Length of a hexadecimal ZeroTier address
  178. */
  179. #define ZT_ADDRESS_LENGTH_HEX 10
  180. /**
  181. * Size of symmetric key (only the first 32 bits are used for some ciphers)
  182. */
  183. #define ZT_SYMMETRIC_KEY_SIZE 48
  184. /**
  185. * Addresses beginning with this byte are reserved for the joy of in-band signaling
  186. */
  187. #define ZT_ADDRESS_RESERVED_PREFIX 0xff
  188. /**
  189. * Default MTU used for Ethernet tap device
  190. */
  191. #define ZT_DEFAULT_MTU 2800
  192. /**
  193. * Maximum number of packet fragments we'll support (protocol max: 16)
  194. */
  195. #define ZT_MAX_PACKET_FRAGMENTS 7
  196. /**
  197. * Size of RX queue
  198. */
  199. #define ZT_RX_QUEUE_SIZE 32
  200. /**
  201. * Size of TX queue
  202. */
  203. #define ZT_TX_QUEUE_SIZE 32
  204. /**
  205. * Minimum delay between timer task checks to prevent thrashing
  206. */
  207. #define ZT_CORE_TIMER_TASK_GRANULARITY 60
  208. /**
  209. * How often Topology::clean() and Network::clean() and similar are called, in ms
  210. */
  211. #define ZT_HOUSEKEEPING_PERIOD 30000
  212. /**
  213. * Delay between WHOIS retries in ms
  214. */
  215. #define ZT_WHOIS_RETRY_DELAY 500
  216. /**
  217. * Transmit queue entry timeout
  218. */
  219. #define ZT_TRANSMIT_QUEUE_TIMEOUT 5000
  220. /**
  221. * Receive queue entry timeout
  222. */
  223. #define ZT_RECEIVE_QUEUE_TIMEOUT 5000
  224. /**
  225. * Maximum number of ZT hops allowed (this is not IP hops/TTL)
  226. *
  227. * The protocol allows up to 7, but we limit it to something smaller.
  228. */
  229. #define ZT_RELAY_MAX_HOPS 3
  230. /**
  231. * Expire time for multicast 'likes' and indirect multicast memberships in ms
  232. */
  233. #define ZT_MULTICAST_LIKE_EXPIRE 600000
  234. /**
  235. * Period for multicast LIKE announcements
  236. */
  237. #define ZT_MULTICAST_ANNOUNCE_PERIOD 60000
  238. /**
  239. * Delay between explicit MULTICAST_GATHER requests for a given multicast channel
  240. */
  241. #define ZT_MULTICAST_EXPLICIT_GATHER_DELAY (ZT_MULTICAST_LIKE_EXPIRE / 10)
  242. /**
  243. * Timeout for outgoing multicasts
  244. *
  245. * This is how long we wait for explicit or implicit gather results.
  246. */
  247. #define ZT_MULTICAST_TRANSMIT_TIMEOUT 5000
  248. /**
  249. * Delay between checks of peer pings, etc., and also related housekeeping tasks
  250. */
  251. #define ZT_PING_CHECK_INVERVAL 5000
  252. /**
  253. * How often the local.conf file is checked for changes (service, should be moved there)
  254. */
  255. #define ZT_LOCAL_CONF_FILE_CHECK_INTERVAL 10000
  256. /**
  257. * How frequently to send heartbeats over in-use paths
  258. */
  259. #define ZT_PATH_HEARTBEAT_PERIOD 14000
  260. /**
  261. * Do not accept HELLOs over a given path more often than this
  262. */
  263. #define ZT_PATH_HELLO_RATE_LIMIT 1000
  264. /**
  265. * Delay between full-fledge pings of directly connected peers
  266. */
  267. #define ZT_PEER_PING_PERIOD 60000
  268. /**
  269. * Paths are considered expired if they have not sent us a real packet in this long
  270. */
  271. #define ZT_PEER_PATH_EXPIRATION ((ZT_PEER_PING_PERIOD * 4) + 3000)
  272. /**
  273. * How often to retry expired paths that we're still remembering
  274. */
  275. #define ZT_PEER_EXPIRED_PATH_TRIAL_PERIOD (ZT_PEER_PING_PERIOD * 10)
  276. /**
  277. * Outgoing packets are only used for QoS/ACK statistical sampling if their
  278. * packet ID is divisible by this integer. This is to provide a mechanism for
  279. * both peers to agree on which packets need special treatment without having
  280. * to exchange information. Changing this value would be a breaking change and
  281. * would necessitate a protocol version upgrade. Since each incoming and
  282. * outgoing packet ID is checked against this value its evaluation is of the
  283. * form:
  284. *
  285. * (id & (divisor - 1)) == 0, thus the divisor must be a power of 2.
  286. *
  287. * This value is set at (16) so that given a normally-distributed RNG output
  288. * we will sample 1/16th (or ~6.25%) of packets.
  289. */
  290. #define ZT_QOS_ACK_DIVISOR 0x2
  291. /**
  292. * Time horizon for VERB_QOS_MEASUREMENT and VERB_ACK packet processing cutoff
  293. */
  294. #define ZT_QOS_ACK_CUTOFF_TIME 30000
  295. /**
  296. * Maximum number of VERB_QOS_MEASUREMENT and VERB_ACK packets allowed to be
  297. * processed within cutoff time. Separate totals are kept for each type but
  298. * the limit is the same for both.
  299. *
  300. * This limits how often this peer will compute statistical estimates
  301. * of various QoS measures from a VERB_QOS_MEASUREMENT or VERB_ACK packets to
  302. * CUTOFF_LIMIT times per CUTOFF_TIME milliseconds per peer to prevent
  303. * this from being useful for DOS amplification attacks.
  304. */
  305. #define ZT_QOS_ACK_CUTOFF_LIMIT 128
  306. /**
  307. * Minimum acceptable size for a VERB_QOS_MEASUREMENT packet
  308. */
  309. #define ZT_QOS_MIN_PACKET_SIZE (8 + 1)
  310. /**
  311. * Maximum acceptable size for a VERB_QOS_MEASUREMENT packet
  312. */
  313. #define ZT_QOS_MAX_PACKET_SIZE 1400
  314. /**
  315. * How many ID:sojourn time pairs are in a single QoS packet
  316. */
  317. #define ZT_QOS_TABLE_SIZE ((ZT_QOS_MAX_PACKET_SIZE * 8) / (64 + 16))
  318. /**
  319. * Maximum number of outgoing packets we monitor for QoS information
  320. */
  321. #define ZT_QOS_MAX_OUTSTANDING_RECORDS (1024 * 16)
  322. /**
  323. * Interval used for rate-limiting the computation of path quality estimates.
  324. */
  325. #define ZT_QOS_COMPUTE_INTERVAL 1000
  326. /**
  327. * Number of samples to consider when processing real-time path statistics
  328. */
  329. #define ZT_QOS_SHORTTERM_SAMPLE_WIN_SIZE 32
  330. /**
  331. * Max allowable time spent in any queue (in ms)
  332. */
  333. #define ZT_AQM_TARGET 5
  334. /**
  335. * Time period where the time spent in the queue by a packet should fall below.
  336. * target at least once. (in ms)
  337. */
  338. #define ZT_AQM_INTERVAL 100
  339. /**
  340. * The number of bytes that each queue is allowed to send during each DRR cycle.
  341. * This approximates a single-byte-based fairness queuing scheme.
  342. */
  343. #define ZT_AQM_QUANTUM ZT_DEFAULT_MTU
  344. /**
  345. * The maximum total number of packets that can be queued among all
  346. * active/inactive, old/new queues.
  347. */
  348. #define ZT_AQM_MAX_ENQUEUED_PACKETS 1024
  349. /**
  350. * Number of QoS queues (buckets)
  351. */
  352. #define ZT_AQM_NUM_BUCKETS 9
  353. /**
  354. * All unspecified traffic is put in this bucket. Anything in a bucket with a
  355. * smaller value is de-prioritized. Anything in a bucket with a higher value is
  356. prioritized over other traffic.
  357. */
  358. #define ZT_AQM_DEFAULT_BUCKET 0
  359. /**
  360. * Timeout for overall peer activity (measured from last receive)
  361. */
  362. #ifndef ZT_SDK
  363. #define ZT_PEER_ACTIVITY_TIMEOUT 500000
  364. #else
  365. #define ZT_PEER_ACTIVITY_TIMEOUT 30000
  366. #endif
  367. /**
  368. * General rate limit timeout for multiple packet types (HELLO, etc.)
  369. */
  370. #define ZT_PEER_GENERAL_INBOUND_RATE_LIMIT 500
  371. /**
  372. * General limit for max RTT for requests over the network
  373. */
  374. #define ZT_GENERAL_RTT_LIMIT 5000
  375. /**
  376. * Delay between requests for updated network autoconf information
  377. *
  378. * Don't lengthen this as it affects things like QoS / uptime monitoring
  379. * via ZeroTier Central. This is the heartbeat, basically.
  380. */
  381. #define ZT_NETWORK_AUTOCONF_DELAY 60000
  382. /**
  383. * Minimum interval between attempts by relays to unite peers
  384. *
  385. * When a relay gets a packet destined for another peer, it sends both peers
  386. * a RENDEZVOUS message no more than this often. This instructs the peers
  387. * to attempt NAT-t and gives each the other's corresponding IP:port pair.
  388. */
  389. #define ZT_MIN_UNITE_INTERVAL 30000
  390. /**
  391. * How often should peers try memorized or statically defined paths?
  392. */
  393. #define ZT_TRY_MEMORIZED_PATH_INTERVAL 30000
  394. /**
  395. * Sanity limit on maximum bridge routes
  396. *
  397. * If the number of bridge routes exceeds this, we cull routes from the
  398. * bridges with the most MACs behind them until it doesn't. This is a
  399. * sanity limit to prevent memory-filling DOS attacks, nothing more. No
  400. * physical LAN has anywhere even close to this many nodes. Note that this
  401. * does not limit the size of ZT virtual LANs, only bridge routing.
  402. */
  403. #define ZT_MAX_BRIDGE_ROUTES 67108864
  404. /**
  405. * If there is no known L2 bridging route, spam to up to this many active bridges
  406. */
  407. #define ZT_MAX_BRIDGE_SPAM 32
  408. /**
  409. * Interval between direct path pushes in milliseconds
  410. */
  411. #define ZT_DIRECT_PATH_PUSH_INTERVAL 15000
  412. /**
  413. * Interval between direct path pushes in milliseconds if we already have a path
  414. */
  415. #define ZT_DIRECT_PATH_PUSH_INTERVAL_HAVEPATH 120000
  416. /**
  417. * Time horizon for push direct paths cutoff
  418. */
  419. #define ZT_PUSH_DIRECT_PATHS_CUTOFF_TIME 30000
  420. /**
  421. * Drainage constants for VERB_ECHO rate-limiters
  422. */
  423. #define ZT_ECHO_CUTOFF_LIMIT ((1000 / ZT_CORE_TIMER_TASK_GRANULARITY) * ZT_MAX_PEER_NETWORK_PATHS)
  424. #define ZT_ECHO_DRAINAGE_DIVISOR (1000 / ZT_ECHO_CUTOFF_LIMIT)
  425. /**
  426. * Drainage constants for VERB_QOS rate-limiters
  427. */
  428. #define ZT_QOS_CUTOFF_LIMIT ((1000 / ZT_CORE_TIMER_TASK_GRANULARITY) * ZT_MAX_PEER_NETWORK_PATHS)
  429. #define ZT_QOS_DRAINAGE_DIVISOR (1000 / ZT_QOS_CUTOFF_LIMIT)
  430. /**
  431. * Drainage constants for VERB_ACK rate-limiters
  432. */
  433. #define ZT_ACK_CUTOFF_LIMIT 128
  434. #define ZT_ACK_DRAINAGE_DIVISOR (1000 / ZT_ACK_CUTOFF_LIMIT)
  435. #define ZT_BOND_DEFAULT_REFRCTORY_PERIOD 8000
  436. #define ZT_BOND_MAX_REFRACTORY_PERIOD 600000
  437. /**
  438. * Maximum number of direct path pushes within cutoff time
  439. *
  440. * This limits response to PUSH_DIRECT_PATHS to CUTOFF_LIMIT responses
  441. * per CUTOFF_TIME milliseconds per peer to prevent this from being
  442. * useful for DOS amplification attacks.
  443. */
  444. #define ZT_PUSH_DIRECT_PATHS_CUTOFF_LIMIT 8
  445. /**
  446. * Maximum number of paths per IP scope (e.g. global, link-local) and family (e.g. v4/v6)
  447. */
  448. #define ZT_PUSH_DIRECT_PATHS_MAX_PER_SCOPE_AND_FAMILY 8
  449. /**
  450. * Time horizon for VERB_NETWORK_CREDENTIALS cutoff
  451. */
  452. #define ZT_PEER_CREDENTIALS_CUTOFF_TIME 60000
  453. /**
  454. * Maximum number of VERB_NETWORK_CREDENTIALS within cutoff time
  455. */
  456. #define ZT_PEER_CREDENTIALS_CUTOFF_LIMIT 15
  457. /**
  458. * WHOIS rate limit (we allow these to be pretty fast)
  459. */
  460. #define ZT_PEER_WHOIS_RATE_LIMIT 100
  461. /**
  462. * General rate limit for other kinds of rate-limited packets (HELLO, credential request, etc.) both inbound and outbound
  463. */
  464. #define ZT_PEER_GENERAL_RATE_LIMIT 1000
  465. /**
  466. * Minimum allowed amount of time between flow/path optimizations (anti-flapping)
  467. */
  468. #define ZT_BOND_OPTIMIZE_INTERVAL 15000
  469. /**
  470. * Maximum number of flows allowed before we start forcibly forgetting old ones
  471. */
  472. #define ZT_FLOW_MAX_COUNT (1024 * 64)
  473. /**
  474. * How often we emit a bond summary for each bond
  475. */
  476. #define ZT_BOND_STATUS_INTERVAL 30000
  477. /**
  478. * How long before we consider a path to be dead in the general sense. This is
  479. * used while searching for default or alternative paths to try in the absence
  480. * of direct guidance from the user or a selection policy.
  481. */
  482. #define ZT_BOND_FAILOVER_DEFAULT_INTERVAL 5000
  483. /**
  484. * Anything below this value gets into thrashing territory since we divide
  485. * this value by ZT_BOND_ECHOS_PER_FAILOVER_INTERVAL to send ECHOs often.
  486. */
  487. #define ZT_BOND_FAILOVER_MIN_INTERVAL 250
  488. /**
  489. * How many times per failover interval that an ECHO is sent. This should be
  490. * at least 2. Anything more then 4 starts to increase overhead significantly.
  491. */
  492. #define ZT_BOND_ECHOS_PER_FAILOVER_INTERVAL 4
  493. /**
  494. * A defensive timer to prevent path quality metrics from being
  495. * processed too often.
  496. */
  497. #define ZT_BOND_BACKGROUND_TASK_MIN_INTERVAL ZT_CORE_TIMER_TASK_GRANULARITY
  498. /**
  499. * How often a bonding policy's background tasks are processed,
  500. * some need more frequent attention than others.
  501. */
  502. #define ZT_BOND_ACTIVE_BACKUP_CHECK_INTERVAL ZT_CORE_TIMER_TASK_GRANULARITY
  503. /**
  504. * Time horizon for path negotiation paths cutoff
  505. */
  506. #define ZT_PATH_NEGOTIATION_CUTOFF_TIME 60000
  507. /**
  508. * Maximum number of path negotiations within cutoff time
  509. *
  510. * This limits response to PATH_NEGOTIATION to CUTOFF_LIMIT responses
  511. * per CUTOFF_TIME milliseconds per peer to prevent this from being
  512. * useful for DOS amplification attacks.
  513. */
  514. #define ZT_PATH_NEGOTIATION_CUTOFF_LIMIT 8
  515. /**
  516. * How many times a peer will attempt to petition another peer to synchronize its
  517. * traffic to the same path before giving up and surrendering to the other peer's preference.
  518. */
  519. #define ZT_PATH_NEGOTIATION_TRY_COUNT 3
  520. /**
  521. * How much greater the quality of a path should be before an
  522. * optimization procedure triggers a switch.
  523. */
  524. #define ZT_BOND_ACTIVE_BACKUP_OPTIMIZE_MIN_THRESHOLD 0.10
  525. /**
  526. * Artificially inflates the failover score for paths which meet
  527. * certain non-performance-related policy ranking criteria.
  528. */
  529. #define ZT_BOND_FAILOVER_HANDICAP_PREFERRED 500
  530. #define ZT_BOND_FAILOVER_HANDICAP_PRIMARY 1000
  531. #define ZT_BOND_FAILOVER_HANDICAP_NEGOTIATED 5000
  532. /**
  533. * An indicator that no flow is to be associated with the given packet
  534. */
  535. #define ZT_QOS_NO_FLOW -1
  536. /**
  537. * Don't do expensive identity validation more often than this
  538. *
  539. * IPv4 and IPv6 address prefixes are hashed down to 14-bit (0-16383) integers
  540. * using the first 24 bits for IPv4 or the first 48 bits for IPv6. These are
  541. * then rate limited to one identity validation per this often milliseconds.
  542. */
  543. #if (defined(__amd64) || defined(__amd64__) || defined(__x86_64) || defined(__x86_64__) || defined(__AMD64) || defined(__AMD64__) || defined(_M_X64) || defined(_M_AMD64))
  544. // AMD64 machines can do anywhere from one every 50ms to one every 10ms. This provides plenty of margin.
  545. #define ZT_IDENTITY_VALIDATION_SOURCE_RATE_LIMIT 2000
  546. #else
  547. #if (defined(__i386__) || defined(__i486__) || defined(__i586__) || defined(__i686__) || defined(_M_IX86) || defined(_X86_) || defined(__I86__))
  548. // 32-bit Intel machines usually average about one every 100ms
  549. #define ZT_IDENTITY_VALIDATION_SOURCE_RATE_LIMIT 5000
  550. #else
  551. // This provides a safe margin for ARM, MIPS, etc. that usually average one every 250-400ms
  552. #define ZT_IDENTITY_VALIDATION_SOURCE_RATE_LIMIT 10000
  553. #endif
  554. #endif
  555. /**
  556. * How long is a path or peer considered to have a trust relationship with us (for e.g. relay policy) since last trusted established packet?
  557. */
  558. #define ZT_TRUST_EXPIRATION 600000
  559. /**
  560. * Desired buffer size for UDP sockets (used in service and osdep but defined here)
  561. */
  562. #define ZT_UDP_DESIRED_BUF_SIZE 1048576
  563. /**
  564. * Desired / recommended min stack size for threads (used on some platforms to reset thread stack size)
  565. */
  566. #define ZT_THREAD_MIN_STACK_SIZE 1048576
  567. // Exceptions thrown in core ZT code
  568. #define ZT_EXCEPTION_OUT_OF_BOUNDS 100
  569. #define ZT_EXCEPTION_OUT_OF_MEMORY 101
  570. #define ZT_EXCEPTION_PRIVATE_KEY_REQUIRED 102
  571. #define ZT_EXCEPTION_INVALID_ARGUMENT 103
  572. #define ZT_EXCEPTION_INVALID_SERIALIZED_DATA_INVALID_TYPE 200
  573. #define ZT_EXCEPTION_INVALID_SERIALIZED_DATA_OVERFLOW 201
  574. #define ZT_EXCEPTION_INVALID_SERIALIZED_DATA_INVALID_CRYPTOGRAPHIC_TOKEN 202
  575. #define ZT_EXCEPTION_INVALID_SERIALIZED_DATA_BAD_ENCODING 203
  576. #endif