Constants.hpp 19 KB

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