ZeroTierOne.h 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155
  1. /*
  2. * ZeroTier One - Network Virtualization Everywhere
  3. * Copyright (C) 2011-2017 ZeroTier, Inc. https://www.zerotier.com/
  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. * You can be released from the requirements of the license by purchasing
  21. * a commercial license. Buying such a license is mandatory as soon as you
  22. * develop commercial closed-source software that incorporates or links
  23. * directly against ZeroTier software without disclosing the source code
  24. * of your own application.
  25. */
  26. /*
  27. * This defines the external C API for ZeroTier's core network virtualization
  28. * engine.
  29. */
  30. #ifndef ZT_ZEROTIERONE_H
  31. #define ZT_ZEROTIERONE_H
  32. #include <stdint.h>
  33. // For the struct sockaddr_storage structure
  34. #if defined(_WIN32) || defined(_WIN64)
  35. #include <WinSock2.h>
  36. #include <WS2tcpip.h>
  37. #include <Windows.h>
  38. #else /* not Windows */
  39. #include <arpa/inet.h>
  40. #include <netinet/in.h>
  41. #include <sys/types.h>
  42. #include <sys/socket.h>
  43. #endif /* Windows or not */
  44. #ifdef __cplusplus
  45. extern "C" {
  46. #endif
  47. /****************************************************************************/
  48. /* Core constants */
  49. /****************************************************************************/
  50. /**
  51. * Default UDP port for devices running a ZeroTier endpoint
  52. */
  53. #define ZT_DEFAULT_PORT 9993
  54. /**
  55. * Maximum MTU for ZeroTier virtual networks
  56. *
  57. * This is pretty much an unchangeable global constant. To make it change
  58. * across nodes would require logic to send ICMP packet too big messages,
  59. * which would complicate things. 1500 has been good enough on most LANs
  60. * for ages, so a larger MTU should be fine for the forseeable future. This
  61. * typically results in two UDP packets per single large frame. Experimental
  62. * results seem to show that this is good. Larger MTUs resulting in more
  63. * fragments seemed too brittle on slow/crummy links for no benefit.
  64. *
  65. * If this does change, also change it in tap.h in the tuntaposx code under
  66. * mac-tap.
  67. *
  68. * Overhead for a normal frame split into two packets:
  69. *
  70. * 1414 = 1444 (typical UDP MTU) - 28 (packet header) - 2 (ethertype)
  71. * 1428 = 1444 (typical UDP MTU) - 16 (fragment header)
  72. * SUM: 2842
  73. *
  74. * We use 2800, which leaves some room for other payload in other types of
  75. * messages such as multicast propagation or future support for bridging.
  76. */
  77. #define ZT_MAX_MTU 2800
  78. /**
  79. * Maximum length of network short name
  80. */
  81. #define ZT_MAX_NETWORK_SHORT_NAME_LENGTH 127
  82. /**
  83. * Maximum number of pushed routes on a network
  84. */
  85. #define ZT_MAX_NETWORK_ROUTES 32
  86. /**
  87. * Maximum number of statically assigned IP addresses per network endpoint using ZT address management (not DHCP)
  88. */
  89. #define ZT_MAX_ZT_ASSIGNED_ADDRESSES 16
  90. /**
  91. * Maximum number of "specialists" on a network -- bridges, relays, etc.
  92. */
  93. #define ZT_MAX_NETWORK_SPECIALISTS 256
  94. /**
  95. * Maximum number of multicast group subscriptions per network
  96. */
  97. #define ZT_MAX_NETWORK_MULTICAST_SUBSCRIPTIONS 4096
  98. /**
  99. * Rules engine revision ID, which specifies rules engine capabilities
  100. */
  101. #define ZT_RULES_ENGINE_REVISION 1
  102. /**
  103. * Maximum number of base (non-capability) network rules
  104. */
  105. #define ZT_MAX_NETWORK_RULES 1024
  106. /**
  107. * Maximum number of per-member capabilities per network
  108. */
  109. #define ZT_MAX_NETWORK_CAPABILITIES 128
  110. /**
  111. * Maximum number of per-member tags per network
  112. */
  113. #define ZT_MAX_NETWORK_TAGS 128
  114. /**
  115. * Maximum number of direct network paths to a given peer
  116. */
  117. #define ZT_MAX_PEER_NETWORK_PATHS 4
  118. /**
  119. * Maximum number of trusted physical network paths
  120. */
  121. #define ZT_MAX_TRUSTED_PATHS 16
  122. /**
  123. * Maximum number of rules per capability
  124. */
  125. #define ZT_MAX_CAPABILITY_RULES 64
  126. /**
  127. * Maximum number of certificates of ownership to assign to a single network member
  128. */
  129. #define ZT_MAX_CERTIFICATES_OF_OWNERSHIP 4
  130. /**
  131. * Global maximum length for capability chain of custody (including initial issue)
  132. */
  133. #define ZT_MAX_CAPABILITY_CUSTODY_CHAIN_LENGTH 7
  134. /**
  135. * Maximum number of hops in a ZeroTier circuit test
  136. *
  137. * This is more or less the max that can be fit in a given packet (with
  138. * fragmentation) and only one address per hop.
  139. */
  140. #define ZT_CIRCUIT_TEST_MAX_HOPS 256
  141. /**
  142. * Maximum number of addresses per hop in a circuit test
  143. */
  144. #define ZT_CIRCUIT_TEST_MAX_HOP_BREADTH 8
  145. /**
  146. * Circuit test report flag: upstream peer authorized in path (e.g. by network COM)
  147. */
  148. #define ZT_CIRCUIT_TEST_REPORT_FLAGS_UPSTREAM_AUTHORIZED_IN_PATH 0x0000000000000001ULL
  149. /**
  150. * Maximum number of cluster members (and max member ID plus one)
  151. */
  152. #define ZT_CLUSTER_MAX_MEMBERS 128
  153. /**
  154. * Maximum number of physical ZeroTier addresses a cluster member can report
  155. */
  156. #define ZT_CLUSTER_MAX_ZT_PHYSICAL_ADDRESSES 16
  157. /**
  158. * Maximum allowed cluster message length in bytes
  159. */
  160. #define ZT_CLUSTER_MAX_MESSAGE_LENGTH (1500 - 48)
  161. /**
  162. * Maximum value for link quality (min is 0)
  163. */
  164. #define ZT_PATH_LINK_QUALITY_MAX 0xff
  165. /**
  166. * Packet characteristics flag: packet direction, 1 if inbound 0 if outbound
  167. */
  168. #define ZT_RULE_PACKET_CHARACTERISTICS_INBOUND 0x8000000000000000ULL
  169. /**
  170. * Packet characteristics flag: multicast or broadcast destination MAC
  171. */
  172. #define ZT_RULE_PACKET_CHARACTERISTICS_MULTICAST 0x4000000000000000ULL
  173. /**
  174. * Packet characteristics flag: broadcast destination MAC
  175. */
  176. #define ZT_RULE_PACKET_CHARACTERISTICS_BROADCAST 0x2000000000000000ULL
  177. /**
  178. * Packet characteristics flag: sending IP address has a certificate of ownership
  179. */
  180. #define ZT_RULE_PACKET_CHARACTERISTICS_SENDER_IP_AUTHENTICATED 0x1000000000000000ULL
  181. /**
  182. * Packet characteristics flag: sending MAC address has a certificate of ownership
  183. */
  184. #define ZT_RULE_PACKET_CHARACTERISTICS_SENDER_MAC_AUTHENTICATED 0x0800000000000000ULL
  185. /**
  186. * Packet characteristics flag: TCP left-most reserved bit
  187. */
  188. #define ZT_RULE_PACKET_CHARACTERISTICS_TCP_RESERVED_0 0x0000000000000800ULL
  189. /**
  190. * Packet characteristics flag: TCP middle reserved bit
  191. */
  192. #define ZT_RULE_PACKET_CHARACTERISTICS_TCP_RESERVED_1 0x0000000000000400ULL
  193. /**
  194. * Packet characteristics flag: TCP right-most reserved bit
  195. */
  196. #define ZT_RULE_PACKET_CHARACTERISTICS_TCP_RESERVED_2 0x0000000000000200ULL
  197. /**
  198. * Packet characteristics flag: TCP NS flag
  199. */
  200. #define ZT_RULE_PACKET_CHARACTERISTICS_TCP_NS 0x0000000000000100ULL
  201. /**
  202. * Packet characteristics flag: TCP CWR flag
  203. */
  204. #define ZT_RULE_PACKET_CHARACTERISTICS_TCP_CWR 0x0000000000000080ULL
  205. /**
  206. * Packet characteristics flag: TCP ECE flag
  207. */
  208. #define ZT_RULE_PACKET_CHARACTERISTICS_TCP_ECE 0x0000000000000040ULL
  209. /**
  210. * Packet characteristics flag: TCP URG flag
  211. */
  212. #define ZT_RULE_PACKET_CHARACTERISTICS_TCP_URG 0x0000000000000020ULL
  213. /**
  214. * Packet characteristics flag: TCP ACK flag
  215. */
  216. #define ZT_RULE_PACKET_CHARACTERISTICS_TCP_ACK 0x0000000000000010ULL
  217. /**
  218. * Packet characteristics flag: TCP PSH flag
  219. */
  220. #define ZT_RULE_PACKET_CHARACTERISTICS_TCP_PSH 0x0000000000000008ULL
  221. /**
  222. * Packet characteristics flag: TCP RST flag
  223. */
  224. #define ZT_RULE_PACKET_CHARACTERISTICS_TCP_RST 0x0000000000000004ULL
  225. /**
  226. * Packet characteristics flag: TCP SYN flag
  227. */
  228. #define ZT_RULE_PACKET_CHARACTERISTICS_TCP_SYN 0x0000000000000002ULL
  229. /**
  230. * Packet characteristics flag: TCP FIN flag
  231. */
  232. #define ZT_RULE_PACKET_CHARACTERISTICS_TCP_FIN 0x0000000000000001ULL
  233. /**
  234. * A null/empty sockaddr (all zero) to signify an unspecified socket address
  235. */
  236. extern const struct sockaddr_storage ZT_SOCKADDR_NULL;
  237. /****************************************************************************/
  238. /* Structures and other types */
  239. /****************************************************************************/
  240. /**
  241. * Function return code: OK (0) or error results
  242. *
  243. * Use ZT_ResultCode_isFatal() to check for a fatal error. If a fatal error
  244. * occurs, the node should be considered to not be working correctly. These
  245. * indicate serious problems like an inaccessible data store or a compile
  246. * problem.
  247. */
  248. enum ZT_ResultCode
  249. {
  250. /**
  251. * Operation completed normally
  252. */
  253. ZT_RESULT_OK = 0,
  254. // Fatal errors (>0, <1000)
  255. /**
  256. * Ran out of memory
  257. */
  258. ZT_RESULT_FATAL_ERROR_OUT_OF_MEMORY = 1,
  259. /**
  260. * Data store is not writable or has failed
  261. */
  262. ZT_RESULT_FATAL_ERROR_DATA_STORE_FAILED = 2,
  263. /**
  264. * Internal error (e.g. unexpected exception indicating bug or build problem)
  265. */
  266. ZT_RESULT_FATAL_ERROR_INTERNAL = 3,
  267. // Non-fatal errors (>1000)
  268. /**
  269. * Network ID not valid
  270. */
  271. ZT_RESULT_ERROR_NETWORK_NOT_FOUND = 1000,
  272. /**
  273. * The requested operation is not supported on this version or build
  274. */
  275. ZT_RESULT_ERROR_UNSUPPORTED_OPERATION = 1001,
  276. /**
  277. * The requestion operation was given a bad parameter or was called in an invalid state
  278. */
  279. ZT_RESULT_ERROR_BAD_PARAMETER = 1002
  280. };
  281. /**
  282. * @param x Result code
  283. * @return True if result code indicates a fatal error
  284. */
  285. #define ZT_ResultCode_isFatal(x) ((((int)(x)) > 0)&&(((int)(x)) < 1000))
  286. /**
  287. * Status codes sent to status update callback when things happen
  288. */
  289. enum ZT_Event
  290. {
  291. /**
  292. * Node has been initialized
  293. *
  294. * This is the first event generated, and is always sent. It may occur
  295. * before Node's constructor returns.
  296. *
  297. * Meta-data: none
  298. */
  299. ZT_EVENT_UP = 0,
  300. /**
  301. * Node is offline -- network does not seem to be reachable by any available strategy
  302. *
  303. * Meta-data: none
  304. */
  305. ZT_EVENT_OFFLINE = 1,
  306. /**
  307. * Node is online -- at least one upstream node appears reachable
  308. *
  309. * Meta-data: none
  310. */
  311. ZT_EVENT_ONLINE = 2,
  312. /**
  313. * Node is shutting down
  314. *
  315. * This is generated within Node's destructor when it is being shut down.
  316. * It's done for convenience, since cleaning up other state in the event
  317. * handler may appear more idiomatic.
  318. *
  319. * Meta-data: none
  320. */
  321. ZT_EVENT_DOWN = 3,
  322. /**
  323. * Your identity has collided with another node's ZeroTier address
  324. *
  325. * This happens if two different public keys both hash (via the algorithm
  326. * in Identity::generate()) to the same 40-bit ZeroTier address.
  327. *
  328. * This is something you should "never" see, where "never" is defined as
  329. * once per 2^39 new node initializations / identity creations. If you do
  330. * see it, you're going to see it very soon after a node is first
  331. * initialized.
  332. *
  333. * This is reported as an event rather than a return code since it's
  334. * detected asynchronously via error messages from authoritative nodes.
  335. *
  336. * If this occurs, you must shut down and delete the node, delete the
  337. * identity.secret record/file from the data store, and restart to generate
  338. * a new identity. If you don't do this, you will not be able to communicate
  339. * with other nodes.
  340. *
  341. * We'd automate this process, but we don't think silently deleting
  342. * private keys or changing our address without telling the calling code
  343. * is good form. It violates the principle of least surprise.
  344. *
  345. * You can technically get away with not handling this, but we recommend
  346. * doing so in a mature reliable application. Besides, handling this
  347. * condition is a good way to make sure it never arises. It's like how
  348. * umbrellas prevent rain and smoke detectors prevent fires. They do, right?
  349. *
  350. * Meta-data: none
  351. */
  352. ZT_EVENT_FATAL_ERROR_IDENTITY_COLLISION = 4,
  353. /**
  354. * Trace (debugging) message
  355. *
  356. * These events are only generated if this is a TRACE-enabled build.
  357. *
  358. * Meta-data: C string, TRACE message
  359. */
  360. ZT_EVENT_TRACE = 5,
  361. /**
  362. * VERB_USER_MESSAGE received
  363. *
  364. * These are generated when a VERB_USER_MESSAGE packet is received via
  365. * ZeroTier VL1.
  366. *
  367. * Meta-data: ZT_UserMessage structure
  368. */
  369. ZT_EVENT_USER_MESSAGE = 6
  370. };
  371. /**
  372. * User message used with ZT_EVENT_USER_MESSAGE
  373. */
  374. typedef struct
  375. {
  376. /**
  377. * ZeroTier address of sender (least significant 40 bits)
  378. */
  379. uint64_t origin;
  380. /**
  381. * User message type ID
  382. */
  383. uint64_t typeId;
  384. /**
  385. * User message data (not including type ID)
  386. */
  387. const void *data;
  388. /**
  389. * Length of data in bytes
  390. */
  391. unsigned int length;
  392. } ZT_UserMessage;
  393. /**
  394. * Current node status
  395. */
  396. typedef struct
  397. {
  398. /**
  399. * 40-bit ZeroTier address of this node
  400. */
  401. uint64_t address;
  402. /**
  403. * Public identity in string-serialized form (safe to send to others)
  404. *
  405. * This pointer will remain valid as long as the node exists.
  406. */
  407. const char *publicIdentity;
  408. /**
  409. * Full identity including secret key in string-serialized form
  410. *
  411. * This pointer will remain valid as long as the node exists.
  412. */
  413. const char *secretIdentity;
  414. /**
  415. * True if some kind of connectivity appears available
  416. */
  417. int online;
  418. } ZT_NodeStatus;
  419. /**
  420. * Virtual network status codes
  421. */
  422. enum ZT_VirtualNetworkStatus
  423. {
  424. /**
  425. * Waiting for network configuration (also means revision == 0)
  426. */
  427. ZT_NETWORK_STATUS_REQUESTING_CONFIGURATION = 0,
  428. /**
  429. * Configuration received and we are authorized
  430. */
  431. ZT_NETWORK_STATUS_OK = 1,
  432. /**
  433. * Netconf master told us 'nope'
  434. */
  435. ZT_NETWORK_STATUS_ACCESS_DENIED = 2,
  436. /**
  437. * Netconf master exists, but this virtual network does not
  438. */
  439. ZT_NETWORK_STATUS_NOT_FOUND = 3,
  440. /**
  441. * Initialization of network failed or other internal error
  442. */
  443. ZT_NETWORK_STATUS_PORT_ERROR = 4,
  444. /**
  445. * ZeroTier core version too old
  446. */
  447. ZT_NETWORK_STATUS_CLIENT_TOO_OLD = 5
  448. };
  449. /**
  450. * Virtual network type codes
  451. */
  452. enum ZT_VirtualNetworkType
  453. {
  454. /**
  455. * Private networks are authorized via certificates of membership
  456. */
  457. ZT_NETWORK_TYPE_PRIVATE = 0,
  458. /**
  459. * Public networks have no access control -- they'll always be AUTHORIZED
  460. */
  461. ZT_NETWORK_TYPE_PUBLIC = 1
  462. };
  463. /**
  464. * The type of a virtual network rules table entry
  465. *
  466. * These must be from 0 to 63 since the most significant two bits of each
  467. * rule type are NOT (MSB) and AND/OR.
  468. *
  469. * Each rule is composed of zero or more MATCHes followed by an ACTION.
  470. * An ACTION with no MATCHes is always taken.
  471. */
  472. enum ZT_VirtualNetworkRuleType
  473. {
  474. // 0 to 15 reserved for actions
  475. /**
  476. * Drop frame
  477. */
  478. ZT_NETWORK_RULE_ACTION_DROP = 0,
  479. /**
  480. * Accept and pass frame
  481. */
  482. ZT_NETWORK_RULE_ACTION_ACCEPT = 1,
  483. /**
  484. * Forward a copy of this frame to an observer (by ZT address)
  485. */
  486. ZT_NETWORK_RULE_ACTION_TEE = 2,
  487. /**
  488. * Exactly like TEE but mandates ACKs from observer
  489. */
  490. ZT_NETWORK_RULE_ACTION_WATCH = 3,
  491. /**
  492. * Drop and redirect this frame to another node (by ZT address)
  493. */
  494. ZT_NETWORK_RULE_ACTION_REDIRECT = 4,
  495. /**
  496. * Stop evaluating rule set (drops unless there are capabilities, etc.)
  497. */
  498. ZT_NETWORK_RULE_ACTION_BREAK = 5,
  499. /**
  500. * Maximum ID for an ACTION, anything higher is a MATCH
  501. */
  502. ZT_NETWORK_RULE_ACTION__MAX_ID = 15,
  503. // 16 to 63 reserved for match criteria
  504. ZT_NETWORK_RULE_MATCH_SOURCE_ZEROTIER_ADDRESS = 24,
  505. ZT_NETWORK_RULE_MATCH_DEST_ZEROTIER_ADDRESS = 25,
  506. ZT_NETWORK_RULE_MATCH_VLAN_ID = 26,
  507. ZT_NETWORK_RULE_MATCH_VLAN_PCP = 27,
  508. ZT_NETWORK_RULE_MATCH_VLAN_DEI = 28,
  509. ZT_NETWORK_RULE_MATCH_MAC_SOURCE = 29,
  510. ZT_NETWORK_RULE_MATCH_MAC_DEST = 30,
  511. ZT_NETWORK_RULE_MATCH_IPV4_SOURCE = 31,
  512. ZT_NETWORK_RULE_MATCH_IPV4_DEST = 32,
  513. ZT_NETWORK_RULE_MATCH_IPV6_SOURCE = 33,
  514. ZT_NETWORK_RULE_MATCH_IPV6_DEST = 34,
  515. ZT_NETWORK_RULE_MATCH_IP_TOS = 35,
  516. ZT_NETWORK_RULE_MATCH_IP_PROTOCOL = 36,
  517. ZT_NETWORK_RULE_MATCH_ETHERTYPE = 37,
  518. ZT_NETWORK_RULE_MATCH_ICMP = 38,
  519. ZT_NETWORK_RULE_MATCH_IP_SOURCE_PORT_RANGE = 39,
  520. ZT_NETWORK_RULE_MATCH_IP_DEST_PORT_RANGE = 40,
  521. ZT_NETWORK_RULE_MATCH_CHARACTERISTICS = 41,
  522. ZT_NETWORK_RULE_MATCH_FRAME_SIZE_RANGE = 42,
  523. ZT_NETWORK_RULE_MATCH_RANDOM = 43,
  524. ZT_NETWORK_RULE_MATCH_TAGS_DIFFERENCE = 44,
  525. ZT_NETWORK_RULE_MATCH_TAGS_BITWISE_AND = 45,
  526. ZT_NETWORK_RULE_MATCH_TAGS_BITWISE_OR = 46,
  527. ZT_NETWORK_RULE_MATCH_TAGS_BITWISE_XOR = 47,
  528. ZT_NETWORK_RULE_MATCH_TAGS_EQUAL = 48,
  529. ZT_NETWORK_RULE_MATCH_TAG_SENDER = 49,
  530. ZT_NETWORK_RULE_MATCH_TAG_RECEIVER = 50,
  531. /**
  532. * Maximum ID allowed for a MATCH entry in the rules table
  533. */
  534. ZT_NETWORK_RULE_MATCH__MAX_ID = 63
  535. };
  536. /**
  537. * Network flow rule
  538. *
  539. * Rules are stored in a table in which one or more match entries is followed
  540. * by an action. If more than one match precedes an action, the rule is
  541. * the AND of all matches. An action with no match is always taken since it
  542. * matches anything. If nothing matches, the default action is DROP.
  543. *
  544. * This is designed to be a more memory-efficient way of storing rules than
  545. * a wide table, yet still fast and simple to access in code.
  546. */
  547. typedef struct
  548. {
  549. /**
  550. * Type and flags
  551. *
  552. * Bits are: NOTTTTTT
  553. *
  554. * N - If true, sense of match is inverted (no effect on actions)
  555. * O - If true, result is ORed with previous instead of ANDed (no effect on actions)
  556. * T - Rule or action type
  557. *
  558. * AND with 0x3f to get type, 0x80 to get NOT bit, and 0x40 to get OR bit.
  559. */
  560. uint8_t t;
  561. /**
  562. * Union containing the value of this rule -- which field is used depends on 't'
  563. */
  564. union {
  565. /**
  566. * IPv6 address in big-endian / network byte order and netmask bits
  567. */
  568. struct {
  569. uint8_t ip[16];
  570. uint8_t mask;
  571. } ipv6;
  572. /**
  573. * IPv4 address in big-endian / network byte order
  574. */
  575. struct {
  576. uint32_t ip;
  577. uint8_t mask;
  578. } ipv4;
  579. /**
  580. * Packet characteristic flags being matched
  581. */
  582. uint64_t characteristics;
  583. /**
  584. * IP port range -- start-end inclusive -- host byte order
  585. */
  586. uint16_t port[2];
  587. /**
  588. * 40-bit ZeroTier address (in least significant bits, host byte order)
  589. */
  590. uint64_t zt;
  591. /**
  592. * 0 = never, UINT32_MAX = always
  593. */
  594. uint32_t randomProbability;
  595. /**
  596. * 48-bit Ethernet MAC address in big-endian order
  597. */
  598. uint8_t mac[6];
  599. /**
  600. * VLAN ID in host byte order
  601. */
  602. uint16_t vlanId;
  603. /**
  604. * VLAN PCP (least significant 3 bits)
  605. */
  606. uint8_t vlanPcp;
  607. /**
  608. * VLAN DEI (single bit / boolean)
  609. */
  610. uint8_t vlanDei;
  611. /**
  612. * Ethernet type in host byte order
  613. */
  614. uint16_t etherType;
  615. /**
  616. * IP protocol
  617. */
  618. uint8_t ipProtocol;
  619. /**
  620. * IP type of service a.k.a. DSCP field
  621. */
  622. struct {
  623. uint8_t mask;
  624. uint8_t value[2];
  625. } ipTos;
  626. /**
  627. * Ethernet packet size in host byte order (start-end, inclusive)
  628. */
  629. uint16_t frameSize[2];
  630. /**
  631. * ICMP type and code
  632. */
  633. struct {
  634. uint8_t type; // ICMP type, always matched
  635. uint8_t code; // ICMP code if matched
  636. uint8_t flags; // flag 0x01 means also match code, otherwise only match type
  637. } icmp;
  638. /**
  639. * For tag-related rules
  640. */
  641. struct {
  642. uint32_t id;
  643. uint32_t value;
  644. } tag;
  645. /**
  646. * Destinations for TEE and REDIRECT
  647. */
  648. struct {
  649. uint64_t address;
  650. uint32_t flags;
  651. uint16_t length;
  652. } fwd;
  653. } v;
  654. } ZT_VirtualNetworkRule;
  655. typedef struct
  656. {
  657. /**
  658. * 128-bit ID (GUID) of this capability
  659. */
  660. uint64_t id[2];
  661. /**
  662. * Expiration time (measured vs. network config timestamp issued by controller)
  663. */
  664. uint64_t expiration;
  665. struct {
  666. uint64_t from;
  667. uint64_t to;
  668. } custody[ZT_MAX_CAPABILITY_CUSTODY_CHAIN_LENGTH];
  669. } ZT_VirtualNetworkCapability;
  670. /**
  671. * A route to be pushed on a virtual network
  672. */
  673. typedef struct
  674. {
  675. /**
  676. * Target network / netmask bits (in port field) or NULL or 0.0.0.0/0 for default
  677. */
  678. struct sockaddr_storage target;
  679. /**
  680. * Gateway IP address (port ignored) or NULL (family == 0) for LAN-local (no gateway)
  681. */
  682. struct sockaddr_storage via;
  683. /**
  684. * Route flags
  685. */
  686. uint16_t flags;
  687. /**
  688. * Route metric (not currently used)
  689. */
  690. uint16_t metric;
  691. } ZT_VirtualNetworkRoute;
  692. /**
  693. * An Ethernet multicast group
  694. */
  695. typedef struct
  696. {
  697. /**
  698. * MAC address (least significant 48 bits)
  699. */
  700. uint64_t mac;
  701. /**
  702. * Additional distinguishing information (usually zero)
  703. */
  704. unsigned long adi;
  705. } ZT_MulticastGroup;
  706. /**
  707. * Virtual network configuration update type
  708. */
  709. enum ZT_VirtualNetworkConfigOperation
  710. {
  711. /**
  712. * Network is coming up (either for the first time or after service restart)
  713. */
  714. ZT_VIRTUAL_NETWORK_CONFIG_OPERATION_UP = 1,
  715. /**
  716. * Network configuration has been updated
  717. */
  718. ZT_VIRTUAL_NETWORK_CONFIG_OPERATION_CONFIG_UPDATE = 2,
  719. /**
  720. * Network is going down (not permanently)
  721. */
  722. ZT_VIRTUAL_NETWORK_CONFIG_OPERATION_DOWN = 3,
  723. /**
  724. * Network is going down permanently (leave/delete)
  725. */
  726. ZT_VIRTUAL_NETWORK_CONFIG_OPERATION_DESTROY = 4
  727. };
  728. /**
  729. * What trust hierarchy role does this peer have?
  730. */
  731. enum ZT_PeerRole
  732. {
  733. ZT_PEER_ROLE_LEAF = 0, // ordinary node
  734. ZT_PEER_ROLE_MOON = 1, // moon root
  735. ZT_PEER_ROLE_PLANET = 2 // planetary root
  736. };
  737. /**
  738. * Vendor ID
  739. */
  740. enum ZT_Vendor
  741. {
  742. ZT_VENDOR_UNSPECIFIED = 0,
  743. ZT_VENDOR_ZEROTIER = 1
  744. };
  745. /**
  746. * Platform type
  747. */
  748. enum ZT_Platform
  749. {
  750. ZT_PLATFORM_UNSPECIFIED = 0,
  751. ZT_PLATFORM_LINUX = 1,
  752. ZT_PLATFORM_WINDOWS = 2,
  753. ZT_PLATFORM_MACOS = 3,
  754. ZT_PLATFORM_ANDROID = 4,
  755. ZT_PLATFORM_IOS = 5,
  756. ZT_PLATFORM_SOLARIS_SMARTOS = 6,
  757. ZT_PLATFORM_FREEBSD = 7,
  758. ZT_PLATFORM_NETBSD = 8,
  759. ZT_PLATFORM_OPENBSD = 9,
  760. ZT_PLATFORM_RISCOS = 10,
  761. ZT_PLATFORM_VXWORKS = 11,
  762. ZT_PLATFORM_FREERTOS = 12,
  763. ZT_PLATFORM_SYSBIOS = 13,
  764. ZT_PLATFORM_HURD = 14,
  765. ZT_PLATFORM_WEB = 15
  766. };
  767. /**
  768. * Architecture type
  769. */
  770. enum ZT_Architecture
  771. {
  772. ZT_ARCHITECTURE_UNSPECIFIED = 0,
  773. ZT_ARCHITECTURE_X86 = 1,
  774. ZT_ARCHITECTURE_X64 = 2,
  775. ZT_ARCHITECTURE_ARM32 = 3,
  776. ZT_ARCHITECTURE_ARM64 = 4,
  777. ZT_ARCHITECTURE_MIPS32 = 5,
  778. ZT_ARCHITECTURE_MIPS64 = 6,
  779. ZT_ARCHITECTURE_POWER32 = 7,
  780. ZT_ARCHITECTURE_POWER64 = 8,
  781. ZT_ARCHITECTURE_OPENRISC32 = 9,
  782. ZT_ARCHITECTURE_OPENRISC64 = 10,
  783. ZT_ARCHITECTURE_SPARC32 = 11,
  784. ZT_ARCHITECTURE_SPARC64 = 12,
  785. ZT_ARCHITECTURE_DOTNET_CLR = 13,
  786. ZT_ARCHITECTURE_JAVA_JVM = 14,
  787. ZT_ARCHITECTURE_WEB = 15
  788. };
  789. /**
  790. * Virtual network configuration
  791. */
  792. typedef struct
  793. {
  794. /**
  795. * 64-bit ZeroTier network ID
  796. */
  797. uint64_t nwid;
  798. /**
  799. * Ethernet MAC (48 bits) that should be assigned to port
  800. */
  801. uint64_t mac;
  802. /**
  803. * Network name (from network configuration master)
  804. */
  805. char name[ZT_MAX_NETWORK_SHORT_NAME_LENGTH + 1];
  806. /**
  807. * Network configuration request status
  808. */
  809. enum ZT_VirtualNetworkStatus status;
  810. /**
  811. * Network type
  812. */
  813. enum ZT_VirtualNetworkType type;
  814. /**
  815. * Maximum interface MTU
  816. */
  817. unsigned int mtu;
  818. /**
  819. * Recommended MTU to avoid fragmentation at the physical layer (hint)
  820. */
  821. unsigned int physicalMtu;
  822. /**
  823. * If nonzero, the network this port belongs to indicates DHCP availability
  824. *
  825. * This is a suggestion. The underlying implementation is free to ignore it
  826. * for security or other reasons. This is simply a netconf parameter that
  827. * means 'DHCP is available on this network.'
  828. */
  829. int dhcp;
  830. /**
  831. * If nonzero, this port is allowed to bridge to other networks
  832. *
  833. * This is informational. If this is false (0), bridged packets will simply
  834. * be dropped and bridging won't work.
  835. */
  836. int bridge;
  837. /**
  838. * If nonzero, this network supports and allows broadcast (ff:ff:ff:ff:ff:ff) traffic
  839. */
  840. int broadcastEnabled;
  841. /**
  842. * If the network is in PORT_ERROR state, this is the (negative) error code most recently reported
  843. */
  844. int portError;
  845. /**
  846. * Revision number as reported by controller or 0 if still waiting for config
  847. */
  848. unsigned long netconfRevision;
  849. /**
  850. * Number of assigned addresses
  851. */
  852. unsigned int assignedAddressCount;
  853. /**
  854. * ZeroTier-assigned addresses (in sockaddr_storage structures)
  855. *
  856. * For IP, the port number of the sockaddr_XX structure contains the number
  857. * of bits in the address netmask. Only the IP address and port are used.
  858. * Other fields like interface number can be ignored.
  859. *
  860. * This is only used for ZeroTier-managed address assignments sent by the
  861. * virtual network's configuration master.
  862. */
  863. struct sockaddr_storage assignedAddresses[ZT_MAX_ZT_ASSIGNED_ADDRESSES];
  864. /**
  865. * Number of ZT-pushed routes
  866. */
  867. unsigned int routeCount;
  868. /**
  869. * Routes (excluding those implied by assigned addresses and their masks)
  870. */
  871. ZT_VirtualNetworkRoute routes[ZT_MAX_NETWORK_ROUTES];
  872. } ZT_VirtualNetworkConfig;
  873. /**
  874. * A list of networks
  875. */
  876. typedef struct
  877. {
  878. ZT_VirtualNetworkConfig *networks;
  879. unsigned long networkCount;
  880. } ZT_VirtualNetworkList;
  881. /**
  882. * Physical network path to a peer
  883. */
  884. typedef struct
  885. {
  886. /**
  887. * Address of endpoint
  888. */
  889. struct sockaddr_storage address;
  890. /**
  891. * Time of last send in milliseconds or 0 for never
  892. */
  893. uint64_t lastSend;
  894. /**
  895. * Time of last receive in milliseconds or 0 for never
  896. */
  897. uint64_t lastReceive;
  898. /**
  899. * Is this a trusted path? If so this will be its nonzero ID.
  900. */
  901. uint64_t trustedPathId;
  902. /**
  903. * Path link quality from 0 to 255 (always 255 if peer does not support)
  904. */
  905. int linkQuality;
  906. /**
  907. * Is path expired?
  908. */
  909. int expired;
  910. /**
  911. * Is path preferred?
  912. */
  913. int preferred;
  914. } ZT_PeerPhysicalPath;
  915. /**
  916. * Peer status result buffer
  917. */
  918. typedef struct
  919. {
  920. /**
  921. * ZeroTier address (40 bits)
  922. */
  923. uint64_t address;
  924. /**
  925. * Remote major version or -1 if not known
  926. */
  927. int versionMajor;
  928. /**
  929. * Remote minor version or -1 if not known
  930. */
  931. int versionMinor;
  932. /**
  933. * Remote revision or -1 if not known
  934. */
  935. int versionRev;
  936. /**
  937. * Last measured latency in milliseconds or zero if unknown
  938. */
  939. unsigned int latency;
  940. /**
  941. * What trust hierarchy role does this device have?
  942. */
  943. enum ZT_PeerRole role;
  944. /**
  945. * Number of paths (size of paths[])
  946. */
  947. unsigned int pathCount;
  948. /**
  949. * Known network paths to peer
  950. */
  951. ZT_PeerPhysicalPath paths[ZT_MAX_PEER_NETWORK_PATHS];
  952. } ZT_Peer;
  953. /**
  954. * List of peers
  955. */
  956. typedef struct
  957. {
  958. ZT_Peer *peers;
  959. unsigned long peerCount;
  960. } ZT_PeerList;
  961. /**
  962. * ZeroTier circuit test configuration and path
  963. */
  964. typedef struct {
  965. /**
  966. * Test ID -- an arbitrary 64-bit identifier
  967. */
  968. uint64_t testId;
  969. /**
  970. * Timestamp -- sent with test and echoed back by each reporter
  971. */
  972. uint64_t timestamp;
  973. /**
  974. * Originator credential: network ID
  975. *
  976. * If this is nonzero, a network ID will be set for this test and
  977. * the originator must be its primary network controller. This is
  978. * currently the only authorization method available, so it must
  979. * be set to run a test.
  980. */
  981. uint64_t credentialNetworkId;
  982. /**
  983. * Hops in circuit test (a.k.a. FIFO for graph traversal)
  984. */
  985. struct {
  986. /**
  987. * Hop flags (currently unused, must be zero)
  988. */
  989. unsigned int flags;
  990. /**
  991. * Number of addresses in this hop (max: ZT_CIRCUIT_TEST_MAX_HOP_BREADTH)
  992. */
  993. unsigned int breadth;
  994. /**
  995. * 40-bit ZeroTier addresses (most significant 24 bits ignored)
  996. */
  997. uint64_t addresses[ZT_CIRCUIT_TEST_MAX_HOP_BREADTH];
  998. } hops[ZT_CIRCUIT_TEST_MAX_HOPS];
  999. /**
  1000. * Number of hops (max: ZT_CIRCUIT_TEST_MAX_HOPS)
  1001. */
  1002. unsigned int hopCount;
  1003. /**
  1004. * If non-zero, circuit test will report back at every hop
  1005. */
  1006. int reportAtEveryHop;
  1007. /**
  1008. * An arbitrary user-settable pointer
  1009. */
  1010. void *ptr;
  1011. /**
  1012. * Pointer for internal use -- initialize to zero and do not modify
  1013. */
  1014. void *_internalPtr;
  1015. } ZT_CircuitTest;
  1016. /**
  1017. * Circuit test result report
  1018. */
  1019. typedef struct {
  1020. /**
  1021. * Sender of report (current hop)
  1022. */
  1023. uint64_t current;
  1024. /**
  1025. * Previous hop
  1026. */
  1027. uint64_t upstream;
  1028. /**
  1029. * 64-bit test ID
  1030. */
  1031. uint64_t testId;
  1032. /**
  1033. * Timestamp from original test (echoed back at each hop)
  1034. */
  1035. uint64_t timestamp;
  1036. /**
  1037. * 64-bit packet ID of packet received by the reporting device
  1038. */
  1039. uint64_t sourcePacketId;
  1040. /**
  1041. * Flags
  1042. */
  1043. uint64_t flags;
  1044. /**
  1045. * ZeroTier protocol-level hop count of packet received by reporting device (>0 indicates relayed)
  1046. */
  1047. unsigned int sourcePacketHopCount;
  1048. /**
  1049. * Error code (currently unused, will be zero)
  1050. */
  1051. unsigned int errorCode;
  1052. /**
  1053. * Remote device vendor ID
  1054. */
  1055. enum ZT_Vendor vendor;
  1056. /**
  1057. * Remote device protocol compliance version
  1058. */
  1059. unsigned int protocolVersion;
  1060. /**
  1061. * Software major version
  1062. */
  1063. unsigned int majorVersion;
  1064. /**
  1065. * Software minor version
  1066. */
  1067. unsigned int minorVersion;
  1068. /**
  1069. * Software revision
  1070. */
  1071. unsigned int revision;
  1072. /**
  1073. * Platform / OS
  1074. */
  1075. enum ZT_Platform platform;
  1076. /**
  1077. * System architecture
  1078. */
  1079. enum ZT_Architecture architecture;
  1080. /**
  1081. * Local device address on which packet was received by reporting device
  1082. *
  1083. * This may have ss_family equal to zero (null address) if unspecified.
  1084. */
  1085. struct sockaddr_storage receivedOnLocalAddress;
  1086. /**
  1087. * Remote address from which reporter received the test packet
  1088. *
  1089. * This may have ss_family set to zero (null address) if unspecified.
  1090. */
  1091. struct sockaddr_storage receivedFromRemoteAddress;
  1092. /**
  1093. * Path link quality of physical path over which test was received
  1094. */
  1095. int receivedFromLinkQuality;
  1096. /**
  1097. * Next hops to which packets are being or will be sent by the reporter
  1098. *
  1099. * In addition to reporting back, the reporter may send the test on if
  1100. * there are more recipients in the FIFO. If it does this, it can report
  1101. * back the address(es) that make up the next hop and the physical address
  1102. * for each if it has one. The physical address being null/unspecified
  1103. * typically indicates that no direct path exists and the next packet
  1104. * will be relayed.
  1105. */
  1106. struct {
  1107. /**
  1108. * 40-bit ZeroTier address
  1109. */
  1110. uint64_t address;
  1111. /**
  1112. * Physical address or null address (ss_family == 0) if unspecified or unknown
  1113. */
  1114. struct sockaddr_storage physicalAddress;
  1115. } nextHops[ZT_CIRCUIT_TEST_MAX_HOP_BREADTH];
  1116. /**
  1117. * Number of next hops reported in nextHops[]
  1118. */
  1119. unsigned int nextHopCount;
  1120. } ZT_CircuitTestReport;
  1121. /**
  1122. * A cluster member's status
  1123. */
  1124. typedef struct {
  1125. /**
  1126. * This cluster member's ID (from 0 to 1-ZT_CLUSTER_MAX_MEMBERS)
  1127. */
  1128. unsigned int id;
  1129. /**
  1130. * Number of milliseconds since last 'alive' heartbeat message received via cluster backplane address
  1131. */
  1132. unsigned int msSinceLastHeartbeat;
  1133. /**
  1134. * Non-zero if cluster member is alive
  1135. */
  1136. int alive;
  1137. /**
  1138. * X, Y, and Z coordinates of this member (if specified, otherwise zero)
  1139. *
  1140. * What these mean depends on the location scheme being used for
  1141. * location-aware clustering. At present this is GeoIP and these
  1142. * will be the X, Y, and Z coordinates of the location on a spherical
  1143. * approximation of Earth where Earth's core is the origin (in km).
  1144. * They don't have to be perfect and need only be comparable with others
  1145. * to find shortest path via the standard vector distance formula.
  1146. */
  1147. int x,y,z;
  1148. /**
  1149. * Cluster member's last reported load
  1150. */
  1151. uint64_t load;
  1152. /**
  1153. * Number of peers
  1154. */
  1155. uint64_t peers;
  1156. /**
  1157. * Physical ZeroTier endpoints for this member (where peers are sent when directed here)
  1158. */
  1159. struct sockaddr_storage zeroTierPhysicalEndpoints[ZT_CLUSTER_MAX_ZT_PHYSICAL_ADDRESSES];
  1160. /**
  1161. * Number of physical ZeroTier endpoints this member is announcing
  1162. */
  1163. unsigned int numZeroTierPhysicalEndpoints;
  1164. } ZT_ClusterMemberStatus;
  1165. /**
  1166. * ZeroTier cluster status
  1167. */
  1168. typedef struct {
  1169. /**
  1170. * My cluster member ID (a record for 'self' is included in member[])
  1171. */
  1172. unsigned int myId;
  1173. /**
  1174. * Number of cluster members
  1175. */
  1176. unsigned int clusterSize;
  1177. /**
  1178. * Cluster member statuses
  1179. */
  1180. ZT_ClusterMemberStatus members[ZT_CLUSTER_MAX_MEMBERS];
  1181. } ZT_ClusterStatus;
  1182. /**
  1183. * An instance of a ZeroTier One node (opaque)
  1184. */
  1185. typedef void ZT_Node;
  1186. /****************************************************************************/
  1187. /* Callbacks used by Node API */
  1188. /****************************************************************************/
  1189. /**
  1190. * Callback called to update virtual network port configuration
  1191. *
  1192. * This can be called at any time to update the configuration of a virtual
  1193. * network port. The parameter after the network ID specifies whether this
  1194. * port is being brought up, updated, brought down, or permanently deleted.
  1195. *
  1196. * This in turn should be used by the underlying implementation to create
  1197. * and configure tap devices at the OS (or virtual network stack) layer.
  1198. *
  1199. * The supplied config pointer is not guaranteed to remain valid, so make
  1200. * a copy if you want one.
  1201. *
  1202. * This should not call multicastSubscribe() or other network-modifying
  1203. * methods, as this could cause a deadlock in multithreaded or interrupt
  1204. * driven environments.
  1205. *
  1206. * This must return 0 on success. It can return any OS-dependent error code
  1207. * on failure, and this results in the network being placed into the
  1208. * PORT_ERROR state.
  1209. */
  1210. typedef int (*ZT_VirtualNetworkConfigFunction)(
  1211. ZT_Node *, /* Node */
  1212. void *, /* User ptr */
  1213. void *, /* Thread ptr */
  1214. uint64_t, /* Network ID */
  1215. void **, /* Modifiable network user PTR */
  1216. enum ZT_VirtualNetworkConfigOperation, /* Config operation */
  1217. const ZT_VirtualNetworkConfig *); /* Network configuration */
  1218. /**
  1219. * Function to send a frame out to a virtual network port
  1220. *
  1221. * Parameters: (1) node, (2) user ptr, (3) network ID, (4) source MAC,
  1222. * (5) destination MAC, (6) ethertype, (7) VLAN ID, (8) frame data,
  1223. * (9) frame length.
  1224. */
  1225. typedef void (*ZT_VirtualNetworkFrameFunction)(
  1226. ZT_Node *, /* Node */
  1227. void *, /* User ptr */
  1228. void *, /* Thread ptr */
  1229. uint64_t, /* Network ID */
  1230. void **, /* Modifiable network user PTR */
  1231. uint64_t, /* Source MAC */
  1232. uint64_t, /* Destination MAC */
  1233. unsigned int, /* Ethernet type */
  1234. unsigned int, /* VLAN ID (0 for none) */
  1235. const void *, /* Frame data */
  1236. unsigned int); /* Frame length */
  1237. /**
  1238. * Callback for events
  1239. *
  1240. * Events are generated when the node's status changes in a significant way
  1241. * and on certain non-fatal errors and events of interest. The final void
  1242. * parameter points to event meta-data. The type of event meta-data (and
  1243. * whether it is present at all) is event type dependent. See the comments
  1244. * in the definition of ZT_Event.
  1245. */
  1246. typedef void (*ZT_EventCallback)(
  1247. ZT_Node *, /* Node */
  1248. void *, /* User ptr */
  1249. void *, /* Thread ptr */
  1250. enum ZT_Event, /* Event type */
  1251. const void *); /* Event payload (if applicable) */
  1252. /**
  1253. * Function to get an object from the data store
  1254. *
  1255. * Parameters: (1) object name, (2) buffer to fill, (3) size of buffer, (4)
  1256. * index in object to start reading, (5) result parameter that must be set
  1257. * to the actual size of the object if it exists.
  1258. *
  1259. * Object names can contain forward slash (/) path separators. They will
  1260. * never contain .. or backslash (\), so this is safe to map as a Unix-style
  1261. * path if the underlying storage permits. For security reasons we recommend
  1262. * returning errors if .. or \ are used.
  1263. *
  1264. * The function must return the actual number of bytes read. If the object
  1265. * doesn't exist, it should return -1. -2 should be returned on other errors
  1266. * such as errors accessing underlying storage.
  1267. *
  1268. * If the read doesn't fit in the buffer, the max number of bytes should be
  1269. * read. The caller may call the function multiple times to read the whole
  1270. * object.
  1271. */
  1272. typedef long (*ZT_DataStoreGetFunction)(
  1273. ZT_Node *, /* Node */
  1274. void *, /* User ptr */
  1275. void *, /* Thread ptr */
  1276. const char *,
  1277. void *,
  1278. unsigned long,
  1279. unsigned long,
  1280. unsigned long *);
  1281. /**
  1282. * Function to store an object in the data store
  1283. *
  1284. * Parameters: (1) node, (2) user ptr, (3) object name, (4) object data,
  1285. * (5) object size, (6) secure? (bool).
  1286. *
  1287. * If secure is true, the file should be set readable and writable only
  1288. * to the user running ZeroTier One. What this means is platform-specific.
  1289. *
  1290. * Name semantics are the same as the get function. This must return zero on
  1291. * success. You can return any OS-specific error code on failure, as these
  1292. * may be visible in logs or error messages and might aid in debugging.
  1293. *
  1294. * If the data pointer is null, this must be interpreted as a delete
  1295. * operation.
  1296. */
  1297. typedef int (*ZT_DataStorePutFunction)(
  1298. ZT_Node *,
  1299. void *,
  1300. void *, /* Thread ptr */
  1301. const char *,
  1302. const void *,
  1303. unsigned long,
  1304. int);
  1305. /**
  1306. * Function to send a ZeroTier packet out over the wire
  1307. *
  1308. * Parameters:
  1309. * (1) Node
  1310. * (2) User pointer
  1311. * (3) Local interface address
  1312. * (4) Remote address
  1313. * (5) Packet data
  1314. * (6) Packet length
  1315. * (7) Desired IP TTL or 0 to use default
  1316. *
  1317. * If there is only one local interface it is safe to ignore the local
  1318. * interface address. Otherwise if running with multiple interfaces, the
  1319. * correct local interface should be chosen by address unless NULL. If
  1320. * the ss_family field is zero (NULL address), a random or preferred
  1321. * default interface should be used.
  1322. *
  1323. * If TTL is nonzero, packets should have their IP TTL value set to this
  1324. * value if possible. If this is not possible it is acceptable to ignore
  1325. * this value and send anyway with normal or default TTL.
  1326. *
  1327. * The function must return zero on success and may return any error code
  1328. * on failure. Note that success does not (of course) guarantee packet
  1329. * delivery. It only means that the packet appears to have been sent.
  1330. */
  1331. typedef int (*ZT_WirePacketSendFunction)(
  1332. ZT_Node *, /* Node */
  1333. void *, /* User ptr */
  1334. void *, /* Thread ptr */
  1335. const struct sockaddr_storage *, /* Local address */
  1336. const struct sockaddr_storage *, /* Remote address */
  1337. const void *, /* Packet data */
  1338. unsigned int, /* Packet length */
  1339. unsigned int); /* TTL or 0 to use default */
  1340. /**
  1341. * Function to check whether a path should be used for ZeroTier traffic
  1342. *
  1343. * Paramters:
  1344. * (1) Node
  1345. * (2) User pointer
  1346. * (3) ZeroTier address or 0 for none/any
  1347. * (4) Local interface address
  1348. * (5) Remote address
  1349. *
  1350. * This function must return nonzero (true) if the path should be used.
  1351. *
  1352. * If no path check function is specified, ZeroTier will still exclude paths
  1353. * that overlap with ZeroTier-assigned and managed IP address blocks. But the
  1354. * use of a path check function is recommended to ensure that recursion does
  1355. * not occur in cases where addresses are assigned by the OS or managed by
  1356. * an out of band mechanism like DHCP. The path check function should examine
  1357. * all configured ZeroTier interfaces and check to ensure that the supplied
  1358. * addresses will not result in ZeroTier traffic being sent over a ZeroTier
  1359. * interface (recursion).
  1360. *
  1361. * Obviously this is not required in configurations where this can't happen,
  1362. * such as network containers or embedded.
  1363. */
  1364. typedef int (*ZT_PathCheckFunction)(
  1365. ZT_Node *, /* Node */
  1366. void *, /* User ptr */
  1367. void *, /* Thread ptr */
  1368. uint64_t, /* ZeroTier address */
  1369. const struct sockaddr_storage *, /* Local address */
  1370. const struct sockaddr_storage *); /* Remote address */
  1371. /**
  1372. * Function to get physical addresses for ZeroTier peers
  1373. *
  1374. * Parameters:
  1375. * (1) Node
  1376. * (2) User pointer
  1377. * (3) ZeroTier address (least significant 40 bits)
  1378. * (4) Desried address family or -1 for any
  1379. * (5) Buffer to fill with result
  1380. *
  1381. * If provided this function will be occasionally called to get physical
  1382. * addresses that might be tried to reach a ZeroTier address. It must
  1383. * return a nonzero (true) value if the result buffer has been filled
  1384. * with an address.
  1385. */
  1386. typedef int (*ZT_PathLookupFunction)(
  1387. ZT_Node *, /* Node */
  1388. void *, /* User ptr */
  1389. void *, /* Thread ptr */
  1390. uint64_t, /* ZeroTier address (40 bits) */
  1391. int, /* Desired ss_family or -1 for any */
  1392. struct sockaddr_storage *); /* Result buffer */
  1393. /****************************************************************************/
  1394. /* C Node API */
  1395. /****************************************************************************/
  1396. /**
  1397. * Structure for configuring ZeroTier core callback functions
  1398. */
  1399. struct ZT_Node_Callbacks
  1400. {
  1401. /**
  1402. * Struct version -- must currently be 0
  1403. */
  1404. long version;
  1405. /**
  1406. * REQUIRED: Function to get objects from persistent storage
  1407. */
  1408. ZT_DataStoreGetFunction dataStoreGetFunction;
  1409. /**
  1410. * REQUIRED: Function to store objects in persistent storage
  1411. */
  1412. ZT_DataStorePutFunction dataStorePutFunction;
  1413. /**
  1414. * REQUIRED: Function to send packets over the physical wire
  1415. */
  1416. ZT_WirePacketSendFunction wirePacketSendFunction;
  1417. /**
  1418. * REQUIRED: Function to inject frames into a virtual network's TAP
  1419. */
  1420. ZT_VirtualNetworkFrameFunction virtualNetworkFrameFunction;
  1421. /**
  1422. * REQUIRED: Function to be called when virtual networks are configured or changed
  1423. */
  1424. ZT_VirtualNetworkConfigFunction virtualNetworkConfigFunction;
  1425. /**
  1426. * REQUIRED: Function to be called to notify external code of important events
  1427. */
  1428. ZT_EventCallback eventCallback;
  1429. /**
  1430. * OPTIONAL: Function to check whether a given physical path should be used
  1431. */
  1432. ZT_PathCheckFunction pathCheckFunction;
  1433. /**
  1434. * OPTIONAL: Function to get hints to physical paths to ZeroTier addresses
  1435. */
  1436. ZT_PathLookupFunction pathLookupFunction;
  1437. };
  1438. /**
  1439. * Create a new ZeroTier One node
  1440. *
  1441. * Note that this can take a few seconds the first time it's called, as it
  1442. * will generate an identity.
  1443. *
  1444. * TODO: should consolidate function pointers into versioned structure for
  1445. * better API stability.
  1446. *
  1447. * @param node Result: pointer is set to new node instance on success
  1448. * @param uptr User pointer to pass to functions/callbacks
  1449. * @param tptr Thread pointer to pass to functions/callbacks resulting from this call
  1450. * @param callbacks Callback function configuration
  1451. * @param now Current clock in milliseconds
  1452. * @return OK (0) or error code if a fatal error condition has occurred
  1453. */
  1454. enum ZT_ResultCode ZT_Node_new(ZT_Node **node,void *uptr,void *tptr,const struct ZT_Node_Callbacks *callbacks,uint64_t now);
  1455. /**
  1456. * Delete a node and free all resources it consumes
  1457. *
  1458. * If you are using multiple threads, all other threads must be shut down
  1459. * first. This can crash if processXXX() methods are in progress.
  1460. *
  1461. * @param node Node to delete
  1462. */
  1463. void ZT_Node_delete(ZT_Node *node);
  1464. /**
  1465. * Process a packet received from the physical wire
  1466. *
  1467. * @param node Node instance
  1468. * @param tptr Thread pointer to pass to functions/callbacks resulting from this call
  1469. * @param now Current clock in milliseconds
  1470. * @param localAddress Local address, or point to ZT_SOCKADDR_NULL if unspecified
  1471. * @param remoteAddress Origin of packet
  1472. * @param packetData Packet data
  1473. * @param packetLength Packet length
  1474. * @param nextBackgroundTaskDeadline Value/result: set to deadline for next call to processBackgroundTasks()
  1475. * @return OK (0) or error code if a fatal error condition has occurred
  1476. */
  1477. enum ZT_ResultCode ZT_Node_processWirePacket(
  1478. ZT_Node *node,
  1479. void *tptr,
  1480. uint64_t now,
  1481. const struct sockaddr_storage *localAddress,
  1482. const struct sockaddr_storage *remoteAddress,
  1483. const void *packetData,
  1484. unsigned int packetLength,
  1485. volatile uint64_t *nextBackgroundTaskDeadline);
  1486. /**
  1487. * Process a frame from a virtual network port (tap)
  1488. *
  1489. * @param node Node instance
  1490. * @param tptr Thread pointer to pass to functions/callbacks resulting from this call
  1491. * @param now Current clock in milliseconds
  1492. * @param nwid ZeroTier 64-bit virtual network ID
  1493. * @param sourceMac Source MAC address (least significant 48 bits)
  1494. * @param destMac Destination MAC address (least significant 48 bits)
  1495. * @param etherType 16-bit Ethernet frame type
  1496. * @param vlanId 10-bit VLAN ID or 0 if none
  1497. * @param frameData Frame payload data
  1498. * @param frameLength Frame payload length
  1499. * @param nextBackgroundTaskDeadline Value/result: set to deadline for next call to processBackgroundTasks()
  1500. * @return OK (0) or error code if a fatal error condition has occurred
  1501. */
  1502. enum ZT_ResultCode ZT_Node_processVirtualNetworkFrame(
  1503. ZT_Node *node,
  1504. void *tptr,
  1505. uint64_t now,
  1506. uint64_t nwid,
  1507. uint64_t sourceMac,
  1508. uint64_t destMac,
  1509. unsigned int etherType,
  1510. unsigned int vlanId,
  1511. const void *frameData,
  1512. unsigned int frameLength,
  1513. volatile uint64_t *nextBackgroundTaskDeadline);
  1514. /**
  1515. * Perform periodic background operations
  1516. *
  1517. * @param node Node instance
  1518. * @param tptr Thread pointer to pass to functions/callbacks resulting from this call
  1519. * @param now Current clock in milliseconds
  1520. * @param nextBackgroundTaskDeadline Value/result: set to deadline for next call to processBackgroundTasks()
  1521. * @return OK (0) or error code if a fatal error condition has occurred
  1522. */
  1523. enum ZT_ResultCode ZT_Node_processBackgroundTasks(ZT_Node *node,void *tptr,uint64_t now,volatile uint64_t *nextBackgroundTaskDeadline);
  1524. /**
  1525. * Join a network
  1526. *
  1527. * This may generate calls to the port config callback before it returns,
  1528. * or these may be deffered if a netconf is not available yet.
  1529. *
  1530. * If we are already a member of the network, nothing is done and OK is
  1531. * returned.
  1532. *
  1533. * @param node Node instance
  1534. * @param nwid 64-bit ZeroTier network ID
  1535. * @param uptr An arbitrary pointer to associate with this network (default: NULL)
  1536. * @return OK (0) or error code if a fatal error condition has occurred
  1537. */
  1538. enum ZT_ResultCode ZT_Node_join(ZT_Node *node,uint64_t nwid,void *uptr,void *tptr);
  1539. /**
  1540. * Leave a network
  1541. *
  1542. * If a port has been configured for this network this will generate a call
  1543. * to the port config callback with a NULL second parameter to indicate that
  1544. * the port is now deleted.
  1545. *
  1546. * The uptr parameter is optional and is NULL by default. If it is not NULL,
  1547. * the pointer it points to is set to this network's uptr on success.
  1548. *
  1549. * @param node Node instance
  1550. * @param nwid 64-bit network ID
  1551. * @param uptr Target pointer is set to uptr (if not NULL)
  1552. * @return OK (0) or error code if a fatal error condition has occurred
  1553. */
  1554. enum ZT_ResultCode ZT_Node_leave(ZT_Node *node,uint64_t nwid,void **uptr,void *tptr);
  1555. /**
  1556. * Subscribe to an Ethernet multicast group
  1557. *
  1558. * ADI stands for additional distinguishing information. This defaults to zero
  1559. * and is rarely used. Right now its only use is to enable IPv4 ARP to scale,
  1560. * and this must be done.
  1561. *
  1562. * For IPv4 ARP, the implementation must subscribe to 0xffffffffffff (the
  1563. * broadcast address) but with an ADI equal to each IPv4 address in host
  1564. * byte order. This converts ARP from a non-scalable broadcast protocol to
  1565. * a scalable multicast protocol with perfect address specificity.
  1566. *
  1567. * If this is not done, ARP will not work reliably.
  1568. *
  1569. * Multiple calls to subscribe to the same multicast address will have no
  1570. * effect. It is perfectly safe to do this.
  1571. *
  1572. * This does not generate an update call to networkConfigCallback().
  1573. *
  1574. * @param node Node instance
  1575. * @param tptr Thread pointer to pass to functions/callbacks resulting from this call
  1576. * @param nwid 64-bit network ID
  1577. * @param multicastGroup Ethernet multicast or broadcast MAC (least significant 48 bits)
  1578. * @param multicastAdi Multicast ADI (least significant 32 bits only, use 0 if not needed)
  1579. * @return OK (0) or error code if a fatal error condition has occurred
  1580. */
  1581. enum ZT_ResultCode ZT_Node_multicastSubscribe(ZT_Node *node,void *tptr,uint64_t nwid,uint64_t multicastGroup,unsigned long multicastAdi);
  1582. /**
  1583. * Unsubscribe from an Ethernet multicast group (or all groups)
  1584. *
  1585. * If multicastGroup is zero (0), this will unsubscribe from all groups. If
  1586. * you are not subscribed to a group this has no effect.
  1587. *
  1588. * This does not generate an update call to networkConfigCallback().
  1589. *
  1590. * @param node Node instance
  1591. * @param nwid 64-bit network ID
  1592. * @param multicastGroup Ethernet multicast or broadcast MAC (least significant 48 bits)
  1593. * @param multicastAdi Multicast ADI (least significant 32 bits only, use 0 if not needed)
  1594. * @return OK (0) or error code if a fatal error condition has occurred
  1595. */
  1596. enum ZT_ResultCode ZT_Node_multicastUnsubscribe(ZT_Node *node,uint64_t nwid,uint64_t multicastGroup,unsigned long multicastAdi);
  1597. /**
  1598. * Add or update a moon
  1599. *
  1600. * Moons are persisted in the data store in moons.d/, so this can persist
  1601. * across invocations if the contents of moon.d are scanned and orbit is
  1602. * called for each on startup.
  1603. *
  1604. * @param node Node instance
  1605. * @param tptr Thread pointer to pass to functions/callbacks resulting from this call
  1606. * @param moonWorldId Moon's world ID
  1607. * @param moonSeed If non-zero, the ZeroTier address of any member of the moon to query for moon definition
  1608. * @param len Length of moonWorld in bytes
  1609. * @return Error if moon was invalid or failed to be added
  1610. */
  1611. enum ZT_ResultCode ZT_Node_orbit(ZT_Node *node,void *tptr,uint64_t moonWorldId,uint64_t moonSeed);
  1612. /**
  1613. * Remove a moon (does nothing if not present)
  1614. *
  1615. * @param node Node instance
  1616. * @param tptr Thread pointer to pass to functions/callbacks resulting from this call
  1617. * @param moonWorldId World ID of moon to remove
  1618. * @return Error if anything bad happened
  1619. */
  1620. enum ZT_ResultCode ZT_Node_deorbit(ZT_Node *node,void *tptr,uint64_t moonWorldId);
  1621. /**
  1622. * Get this node's 40-bit ZeroTier address
  1623. *
  1624. * @param node Node instance
  1625. * @return ZeroTier address (least significant 40 bits of 64-bit int)
  1626. */
  1627. uint64_t ZT_Node_address(ZT_Node *node);
  1628. /**
  1629. * Get the status of this node
  1630. *
  1631. * @param node Node instance
  1632. * @param status Buffer to fill with current node status
  1633. */
  1634. void ZT_Node_status(ZT_Node *node,ZT_NodeStatus *status);
  1635. /**
  1636. * Get a list of known peer nodes
  1637. *
  1638. * The pointer returned here must be freed with freeQueryResult()
  1639. * when you are done with it.
  1640. *
  1641. * @param node Node instance
  1642. * @return List of known peers or NULL on failure
  1643. */
  1644. ZT_PeerList *ZT_Node_peers(ZT_Node *node);
  1645. /**
  1646. * Get the status of a virtual network
  1647. *
  1648. * The pointer returned here must be freed with freeQueryResult()
  1649. * when you are done with it.
  1650. *
  1651. * @param node Node instance
  1652. * @param nwid 64-bit network ID
  1653. * @return Network configuration or NULL if we are not a member of this network
  1654. */
  1655. ZT_VirtualNetworkConfig *ZT_Node_networkConfig(ZT_Node *node,uint64_t nwid);
  1656. /**
  1657. * Enumerate and get status of all networks
  1658. *
  1659. * @param node Node instance
  1660. * @return List of networks or NULL on failure
  1661. */
  1662. ZT_VirtualNetworkList *ZT_Node_networks(ZT_Node *node);
  1663. /**
  1664. * Free a query result buffer
  1665. *
  1666. * Use this to free the return values of listNetworks(), listPeers(), etc.
  1667. *
  1668. * @param node Node instance
  1669. * @param qr Query result buffer
  1670. */
  1671. void ZT_Node_freeQueryResult(ZT_Node *node,void *qr);
  1672. /**
  1673. * Add a local interface address
  1674. *
  1675. * This is used to make ZeroTier aware of those local interface addresses
  1676. * that you wish to use for ZeroTier communication. This is optional, and if
  1677. * it is not used ZeroTier will rely upon upstream peers (and roots) to
  1678. * perform empirical address discovery and NAT traversal. But the use of this
  1679. * method is recommended as it improves peer discovery when both peers are
  1680. * on the same LAN.
  1681. *
  1682. * It is the responsibility of the caller to take care that these are never
  1683. * ZeroTier interface addresses, whether these are assigned by ZeroTier or
  1684. * are otherwise assigned to an interface managed by this ZeroTier instance.
  1685. * This can cause recursion or other undesirable behavior.
  1686. *
  1687. * This returns a boolean indicating whether or not the address was
  1688. * accepted. ZeroTier will only communicate over certain address types
  1689. * and (for IP) address classes.
  1690. *
  1691. * @param addr Local interface address
  1692. * @return Boolean: non-zero if address was accepted and added
  1693. */
  1694. int ZT_Node_addLocalInterfaceAddress(ZT_Node *node,const struct sockaddr_storage *addr);
  1695. /**
  1696. * Clear local interface addresses
  1697. */
  1698. void ZT_Node_clearLocalInterfaceAddresses(ZT_Node *node);
  1699. /**
  1700. * Send a VERB_USER_MESSAGE to another ZeroTier node
  1701. *
  1702. * There is no delivery guarantee here. Failure can occur if the message is
  1703. * too large or if dest is not a valid ZeroTier address.
  1704. *
  1705. * @param node Node instance
  1706. * @param tptr Thread pointer to pass to functions/callbacks resulting from this call
  1707. * @param dest Destination ZeroTier address
  1708. * @param typeId VERB_USER_MESSAGE type ID
  1709. * @param data Payload data to attach to user message
  1710. * @param len Length of data in bytes
  1711. * @return Boolean: non-zero on success, zero on failure
  1712. */
  1713. int ZT_Node_sendUserMessage(ZT_Node *node,void *tptr,uint64_t dest,uint64_t typeId,const void *data,unsigned int len);
  1714. /**
  1715. * Set a network configuration master instance for this node
  1716. *
  1717. * Normal nodes should not need to use this. This is for nodes with
  1718. * special compiled-in support for acting as network configuration
  1719. * masters / controllers.
  1720. *
  1721. * The supplied instance must be a C++ object that inherits from the
  1722. * NetworkConfigMaster base class in node/. No type checking is performed,
  1723. * so a pointer to anything else will result in a crash.
  1724. *
  1725. * @param node ZertTier One node
  1726. * @param networkConfigMasterInstance Instance of NetworkConfigMaster C++ class or NULL to disable
  1727. * @return OK (0) or error code if a fatal error condition has occurred
  1728. */
  1729. void ZT_Node_setNetconfMaster(ZT_Node *node,void *networkConfigMasterInstance);
  1730. /**
  1731. * Initiate a VL1 circuit test
  1732. *
  1733. * This sends an initial VERB_CIRCUIT_TEST and reports results back to the
  1734. * supplied callback until circuitTestEnd() is called. The supplied
  1735. * ZT_CircuitTest structure should be initially zeroed and then filled
  1736. * in with settings and hops.
  1737. *
  1738. * It is the caller's responsibility to call circuitTestEnd() and then
  1739. * to dispose of the test structure. Otherwise this node will listen
  1740. * for results forever.
  1741. *
  1742. * @param node Node instance
  1743. * @param tptr Thread pointer to pass to functions/callbacks resulting from this call
  1744. * @param test Test configuration
  1745. * @param reportCallback Function to call each time a report is received
  1746. * @return OK or error if, for example, test is too big for a packet or support isn't compiled in
  1747. */
  1748. enum ZT_ResultCode ZT_Node_circuitTestBegin(ZT_Node *node,void *tptr,ZT_CircuitTest *test,void (*reportCallback)(ZT_Node *, ZT_CircuitTest *,const ZT_CircuitTestReport *));
  1749. /**
  1750. * Stop listening for results to a given circuit test
  1751. *
  1752. * This does not free the 'test' structure. The caller may do that
  1753. * after calling this method to unregister it.
  1754. *
  1755. * Any reports that are received for a given test ID after it is
  1756. * terminated are ignored.
  1757. *
  1758. * @param node Node instance
  1759. * @param test Test configuration to unregister
  1760. */
  1761. void ZT_Node_circuitTestEnd(ZT_Node *node,ZT_CircuitTest *test);
  1762. /**
  1763. * Initialize cluster operation
  1764. *
  1765. * This initializes the internal structures and state for cluster operation.
  1766. * It takes two function pointers. The first is to a function that can be
  1767. * used to send data to cluster peers (mechanism is not defined by Node),
  1768. * and the second is to a function that can be used to get the location of
  1769. * a physical address in X,Y,Z coordinate space (e.g. as cartesian coordinates
  1770. * projected from the center of the Earth).
  1771. *
  1772. * Send function takes an arbitrary pointer followed by the cluster member ID
  1773. * to send data to, a pointer to the data, and the length of the data. The
  1774. * maximum message length is ZT_CLUSTER_MAX_MESSAGE_LENGTH (65535). Messages
  1775. * must be delivered whole and may be dropped or transposed, though high
  1776. * failure rates are undesirable and can cause problems. Validity checking or
  1777. * CRC is also not required since the Node validates the authenticity of
  1778. * cluster messages using cryptogrphic methods and will silently drop invalid
  1779. * messages.
  1780. *
  1781. * Address to location function is optional and if NULL geo-handoff is not
  1782. * enabled (in this case x, y, and z in clusterInit are also unused). It
  1783. * takes an arbitrary pointer followed by a physical address and three result
  1784. * parameters for x, y, and z. It returns zero on failure or nonzero if these
  1785. * three coordinates have been set. Coordinate space is arbitrary and can be
  1786. * e.g. coordinates on Earth relative to Earth's center. These can be obtained
  1787. * from latitutde and longitude with versions of the Haversine formula.
  1788. *
  1789. * See: http://stackoverflow.com/questions/1185408/converting-from-longitude-latitude-to-cartesian-coordinates
  1790. *
  1791. * Neither the send nor the address to location function should block. If the
  1792. * address to location function does not have a location for an address, it
  1793. * should return zero and then look up the address for future use since it
  1794. * will be called again in (typically) 1-3 minutes.
  1795. *
  1796. * Note that both functions can be called from any thread from which the
  1797. * various Node functions are called, and so must be thread safe if multiple
  1798. * threads are being used.
  1799. *
  1800. * @param node Node instance
  1801. * @param myId My cluster member ID (less than or equal to ZT_CLUSTER_MAX_MEMBERS)
  1802. * @param zeroTierPhysicalEndpoints Preferred physical address(es) for ZeroTier clients to contact this cluster member (for peer redirect)
  1803. * @param numZeroTierPhysicalEndpoints Number of physical endpoints in zeroTierPhysicalEndpoints[] (max allowed: 255)
  1804. * @param x My cluster member's X location
  1805. * @param y My cluster member's Y location
  1806. * @param z My cluster member's Z location
  1807. * @param sendFunction Function to be called to send data to other cluster members
  1808. * @param sendFunctionArg First argument to sendFunction()
  1809. * @param addressToLocationFunction Function to be called to get the location of a physical address or NULL to disable geo-handoff
  1810. * @param addressToLocationFunctionArg First argument to addressToLocationFunction()
  1811. * @return OK or UNSUPPORTED_OPERATION if this Node was not built with cluster support
  1812. */
  1813. enum ZT_ResultCode ZT_Node_clusterInit(
  1814. ZT_Node *node,
  1815. unsigned int myId,
  1816. const struct sockaddr_storage *zeroTierPhysicalEndpoints,
  1817. unsigned int numZeroTierPhysicalEndpoints,
  1818. int x,
  1819. int y,
  1820. int z,
  1821. void (*sendFunction)(void *,unsigned int,const void *,unsigned int),
  1822. void *sendFunctionArg,
  1823. int (*addressToLocationFunction)(void *,const struct sockaddr_storage *,int *,int *,int *),
  1824. void *addressToLocationFunctionArg);
  1825. /**
  1826. * Add a member to this cluster
  1827. *
  1828. * Calling this without having called clusterInit() will do nothing.
  1829. *
  1830. * @param node Node instance
  1831. * @param memberId Member ID (must be less than or equal to ZT_CLUSTER_MAX_MEMBERS)
  1832. * @return OK or error if clustering is disabled, ID invalid, etc.
  1833. */
  1834. enum ZT_ResultCode ZT_Node_clusterAddMember(ZT_Node *node,unsigned int memberId);
  1835. /**
  1836. * Remove a member from this cluster
  1837. *
  1838. * Calling this without having called clusterInit() will do nothing.
  1839. *
  1840. * @param node Node instance
  1841. * @param memberId Member ID to remove (nothing happens if not present)
  1842. */
  1843. void ZT_Node_clusterRemoveMember(ZT_Node *node,unsigned int memberId);
  1844. /**
  1845. * Handle an incoming cluster state message
  1846. *
  1847. * The message itself contains cluster member IDs, and invalid or badly
  1848. * addressed messages will be silently discarded.
  1849. *
  1850. * Calling this without having called clusterInit() will do nothing.
  1851. *
  1852. * @param node Node instance
  1853. * @param msg Cluster message
  1854. * @param len Length of cluster message
  1855. */
  1856. void ZT_Node_clusterHandleIncomingMessage(ZT_Node *node,const void *msg,unsigned int len);
  1857. /**
  1858. * Get the current status of the cluster from this node's point of view
  1859. *
  1860. * Calling this without clusterInit() or without cluster support will just
  1861. * zero out the structure and show a cluster size of zero.
  1862. *
  1863. * @param node Node instance
  1864. * @param cs Cluster status structure to fill with data
  1865. */
  1866. void ZT_Node_clusterStatus(ZT_Node *node,ZT_ClusterStatus *cs);
  1867. /**
  1868. * Set trusted paths
  1869. *
  1870. * A trusted path is a physical network (network/bits) over which both
  1871. * encryption and authentication can be skipped to improve performance.
  1872. * Each trusted path must have a non-zero unique ID that is the same across
  1873. * all participating nodes.
  1874. *
  1875. * We don't recommend using trusted paths at all unless you really *need*
  1876. * near-bare-metal performance. Even on a LAN authentication and encryption
  1877. * are never a bad thing, and anything that introduces an "escape hatch"
  1878. * for encryption should be treated with the utmost care.
  1879. *
  1880. * Calling with NULL pointers for networks and ids and a count of zero clears
  1881. * all trusted paths.
  1882. *
  1883. * @param node Node instance
  1884. * @param networks Array of [count] networks
  1885. * @param ids Array of [count] corresponding non-zero path IDs (zero path IDs are ignored)
  1886. * @param count Number of trusted paths-- values greater than ZT_MAX_TRUSTED_PATHS are clipped
  1887. */
  1888. void ZT_Node_setTrustedPaths(ZT_Node *node,const struct sockaddr_storage *networks,const uint64_t *ids,unsigned int count);
  1889. /**
  1890. * Get ZeroTier One version
  1891. *
  1892. * @param major Result: major version
  1893. * @param minor Result: minor version
  1894. * @param revision Result: revision
  1895. */
  1896. void ZT_version(int *major,int *minor,int *revision);
  1897. #ifdef __cplusplus
  1898. }
  1899. #endif
  1900. #endif