Constants.hpp 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. /*
  2. * ZeroTier One - Global Peer to Peer Ethernet
  3. * Copyright (C) 2012-2013 ZeroTier Networks LLC
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. * --
  19. *
  20. * ZeroTier may be used and distributed under the terms of the GPLv3, which
  21. * are available at: http://www.gnu.org/licenses/gpl-3.0.html
  22. *
  23. * If you would like to embed ZeroTier into a commercial application or
  24. * redistribute it in a modified binary form, please contact ZeroTier Networks
  25. * LLC. Start here: http://www.zerotier.com/
  26. */
  27. #ifndef _ZT_CONSTANTS_HPP
  28. #define _ZT_CONSTANTS_HPP
  29. // Assume these are little-endian, since we don't support old PPC MACs
  30. // and all newer Mac or Windows systems are either x86_32, x86_64, or
  31. // ARM in little-endian mode.
  32. #if defined(__APPLE__) || defined(_WIN32)
  33. #undef __BYTE_ORDER
  34. #undef __LITTLE_ENDIAN
  35. #undef __BIG_ENDIAN
  36. #define __BIG_ENDIAN 4321
  37. #define __LITTLE_ENDIAN 1234
  38. #define __BYTE_ORDER 1234
  39. #endif
  40. // Linux has endian.h, which should tell us
  41. #if defined(__linux__) || defined(linux) || defined(__LINUX__) || defined(__linux)
  42. #include <endian.h>
  43. #endif
  44. #ifndef __BYTE_ORDER
  45. error_no_byte_order_defined
  46. #endif
  47. #ifndef ZT_OSNAME
  48. error_no_ZT_OSNAME
  49. #endif
  50. #ifndef ZT_ARCH
  51. error_no_ZT_ARCH
  52. #endif
  53. #ifdef _WIN32
  54. #define ZT_PATH_SEPARATOR '\\'
  55. #define ZT_PATH_SEPARATOR_S "\\"
  56. #define ZT_EOL_S "\r\n"
  57. #else
  58. #define ZT_PATH_SEPARATOR '/'
  59. #define ZT_PATH_SEPARATOR_S "/"
  60. #define ZT_EOL_S "\n"
  61. #endif
  62. /**
  63. * Length of a ZeroTier address in bytes
  64. */
  65. #define ZT_ADDRESS_LENGTH 5
  66. /**
  67. * Addresses beginning with this byte are reserved for the joy of in-band signaling
  68. */
  69. #define ZT_ADDRESS_RESERVED_PREFIX 0xff
  70. /**
  71. * Default local UDP port
  72. */
  73. #define ZT_DEFAULT_UDP_PORT 8993
  74. /**
  75. * Default payload MTU for UDP packets
  76. *
  77. * In the future we might support UDP path MTU discovery, but for now we
  78. * set a maximum that is equal to 1500 minus 8 (for PPPoE overhead, common
  79. * in some markets) minus 48 (IPv6 UDP overhead).
  80. */
  81. #define ZT_UDP_DEFAULT_PAYLOAD_MTU 1444
  82. /**
  83. * MTU used for Ethernet tap device
  84. *
  85. * This is pretty much an unchangeable global constant. To make it change
  86. * across nodes would require logic to send ICMP packet too big messages,
  87. * which would complicate things. 1500 has been good enough on most LANs
  88. * for ages, so a larger MTU should be fine for the forseeable future. This
  89. * typically results in two UDP packets per single large frame. Experimental
  90. * results seem to show that this is good. Larger MTUs resulting in more
  91. * fragments seemed too brittle on slow/crummy links for no benefit.
  92. *
  93. * If this does change, also change it in tap.h in the tuntaposx code under
  94. * mac-tap.
  95. *
  96. * Overhead for a normal frame split into two packets:
  97. *
  98. * 1414 = 1444 (typical UDP MTU) - 28 (packet header) - 2 (ethertype)
  99. * 1428 = 1444 (typical UDP MTU) - 16 (fragment header)
  100. * SUM: 2842
  101. *
  102. * We use 2800, which leaves some room for other payload in other types of
  103. * messages such as multicast propagation or future support for bridging.
  104. */
  105. #define ZT_IF_MTU 2800
  106. /**
  107. * Maximum number of networks we can be a member of
  108. *
  109. * This is a safe value that's within the tap device limit on all known OSes.
  110. */
  111. #define ZT_MAX_NETWORK_MEMBERSHIPS 16
  112. /**
  113. * Maximum number of packet fragments we'll support
  114. *
  115. * The actual spec allows 16, but this is the most we'll support right
  116. * now. Packets with more than this many fragments are dropped.
  117. */
  118. #define ZT_MAX_PACKET_FRAGMENTS 3
  119. /**
  120. * Timeout for receipt of fragmented packets in ms
  121. *
  122. * Since there's no retransmits, this is just a really bad case scenario for
  123. * transit time. It's short enough that a DOS attack from exhausing buffers is
  124. * very unlikely, as the transfer rate would have to be fast enough to fill
  125. * system memory in this time.
  126. */
  127. #define ZT_FRAGMENTED_PACKET_RECEIVE_TIMEOUT 1500
  128. /**
  129. * First byte of MAC addresses derived from ZeroTier addresses
  130. *
  131. * This has the 0x02 bit set, which indicates a locally administrered
  132. * MAC address rather than one with a known HW ID.
  133. */
  134. #define ZT_MAC_FIRST_OCTET 0x32
  135. /**
  136. * How often Topology::clean() is called in ms
  137. */
  138. #define ZT_TOPOLOGY_CLEAN_PERIOD 300000
  139. /**
  140. * Delay between WHOIS retries in ms
  141. */
  142. #define ZT_WHOIS_RETRY_DELAY 500
  143. /**
  144. * Maximum identity WHOIS retries
  145. */
  146. #define ZT_MAX_WHOIS_RETRIES 3
  147. /**
  148. * Transmit queue entry timeout
  149. */
  150. #define ZT_TRANSMIT_QUEUE_TIMEOUT (ZT_WHOIS_RETRY_DELAY * (ZT_MAX_WHOIS_RETRIES + 1))
  151. /**
  152. * Receive queue entry timeout
  153. */
  154. #define ZT_RECEIVE_QUEUE_TIMEOUT (ZT_WHOIS_RETRY_DELAY * (ZT_MAX_WHOIS_RETRIES + 1))
  155. /**
  156. * Maximum number of ZT hops allowed
  157. *
  158. * The protocol allows up to 7, but we limit it to something smaller.
  159. */
  160. #define ZT_RELAY_MAX_HOPS 3
  161. /**
  162. * Breadth of tree for rumor mill multicast propagation
  163. */
  164. #define ZT_MULTICAST_PROPAGATION_BREADTH 4
  165. /**
  166. * Depth of tree for rumor mill multicast propagation
  167. *
  168. * The maximum number of peers who can receive a multicast is equal to
  169. * the sum of BREADTH^i where I is from 1 to DEPTH. This ignores the effect
  170. * of the rate limiting algorithm or bloom filter collisions.
  171. *
  172. * 7 results in a max of 21844 recipients for a given multicast.
  173. */
  174. #define ZT_MULTICAST_PROPAGATION_DEPTH 7
  175. /**
  176. * Length of circular ring buffer history of multicast packets
  177. */
  178. #define ZT_MULTICAST_DEDUP_HISTORY_LENGTH 4096
  179. /**
  180. * Expiration time in ms for multicast history items
  181. */
  182. #define ZT_MULTICAST_DEDUP_HISTORY_EXPIRE 8000
  183. /**
  184. * Period between announcements of all multicast 'likes' in ms
  185. *
  186. * Announcement occurs when a multicast group is locally joined, but all
  187. * memberships are periodically re-broadcast. If they're not they will
  188. * expire.
  189. */
  190. #define ZT_MULTICAST_LIKE_ANNOUNCE_ALL_PERIOD 120000
  191. /**
  192. * Expire time for multicast 'likes' in ms
  193. */
  194. #define ZT_MULTICAST_LIKE_EXPIRE ((ZT_MULTICAST_LIKE_ANNOUNCE_ALL_PERIOD * 2) + 1000)
  195. /**
  196. * Time between polls of local taps for multicast membership changes
  197. */
  198. #define ZT_MULTICAST_LOCAL_POLL_PERIOD 10000
  199. /**
  200. * Delay between scans of the topology active peer DB for peers that need ping
  201. */
  202. #define ZT_PING_CHECK_DELAY 7000
  203. /**
  204. * Delay between checks of network configuration fingerprint
  205. */
  206. #define ZT_NETWORK_FINGERPRINT_CHECK_DELAY 5000
  207. /**
  208. * Delay between pings (actually HELLOs) to direct links
  209. */
  210. #define ZT_PEER_DIRECT_PING_DELAY 120000
  211. /**
  212. * Period between rechecks of autoconfigure URL
  213. *
  214. * This is in the absence of an external message ordering a recheck.
  215. */
  216. #define ZT_AUTOCONFIGURE_INTERVAL 3600000
  217. /**
  218. * Period between autoconfigure attempts if no successful autoconfig
  219. */
  220. #define ZT_AUTOCONFIGURE_CHECK_DELAY 15000
  221. /**
  222. * Delay between updates of status file in home directory
  223. */
  224. #define ZT_STATUS_OUTPUT_PERIOD 120000
  225. /**
  226. * Minimum delay in Node service loop
  227. *
  228. * This is the shortest of the check delays/periods.
  229. */
  230. #define ZT_MIN_SERVICE_LOOP_INTERVAL ZT_NETWORK_FINGERPRINT_CHECK_DELAY
  231. /**
  232. * Activity timeout for links
  233. *
  234. * A link that hasn't spoken in this long is simply considered inactive.
  235. */
  236. #define ZT_PEER_LINK_ACTIVITY_TIMEOUT ((ZT_PEER_DIRECT_PING_DELAY * 2) + 1000)
  237. /**
  238. * Delay in ms between firewall opener packets to direct links
  239. *
  240. * This should be lower than the UDP conversation entry timeout in most
  241. * stateful firewalls.
  242. */
  243. #define ZT_FIREWALL_OPENER_DELAY 50000
  244. /**
  245. * IP hops (a.k.a. TTL) to set for firewall opener packets
  246. *
  247. * 2 should permit traversal of double-NAT configurations, such as from inside
  248. * a VM running behind local NAT on a host that is itself behind NAT.
  249. */
  250. #define ZT_FIREWALL_OPENER_HOPS 2
  251. /**
  252. * Delay sleep overshoot for detection of a probable sleep/wake event
  253. */
  254. #define ZT_SLEEP_WAKE_DETECTION_THRESHOLD 2000
  255. /**
  256. * Time to pause main service loop after sleep/wake detect
  257. */
  258. #define ZT_SLEEP_WAKE_SETTLE_TIME 5000
  259. /**
  260. * Minimum interval between attempts by relays to unite peers
  261. */
  262. #define ZT_MIN_UNITE_INTERVAL 30000
  263. /**
  264. * Delay in milliseconds between firewall opener and real packet for NAT-t
  265. */
  266. #define ZT_RENDEZVOUS_NAT_T_DELAY 500
  267. /**
  268. * Generate a new ownership verify secret on launch if older than this
  269. */
  270. #define ZT_OVS_GENERATE_NEW_IF_OLDER_THAN 86400000
  271. #endif