zerotier.h 70 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549
  1. /*
  2. * Copyright (c)2013-2020 ZeroTier, Inc.
  3. *
  4. * Use of this software is governed by the Business Source License included
  5. * in the LICENSE.TXT file in the project's root directory.
  6. *
  7. * Change Date: 2024-01-01
  8. *
  9. * On the date above, in accordance with the Business Source License, use
  10. * of this software will be governed by version 2.0 of the Apache License.
  11. */
  12. /****/
  13. /*
  14. * This defines the external C API for the ZeroTier network hypervisor.
  15. */
  16. #ifndef ZT_ZEROTIER_API_H
  17. #define ZT_ZEROTIER_API_H
  18. #if defined(_WIN32) || defined(_WIN64)
  19. #include <WinSock2.h>
  20. #include <WS2tcpip.h>
  21. #include <Windows.h>
  22. #else
  23. #include <arpa/inet.h>
  24. #include <netinet/in.h>
  25. #include <sys/types.h>
  26. #include <sys/socket.h>
  27. #endif
  28. #include <stdint.h>
  29. #include <stdlib.h>
  30. #ifdef __cplusplus
  31. extern "C" {
  32. #endif
  33. /* This symbol may be defined to anything we need to put in front of API function prototypes. */
  34. #ifndef ZT_SDK_API
  35. #define ZT_SDK_API
  36. #endif
  37. /* ---------------------------------------------------------------------------------------------------------------- */
  38. /**
  39. * Default primary UDP port for devices running a ZeroTier endpoint
  40. */
  41. #define ZT_DEFAULT_PORT 9993
  42. /**
  43. * IP protocol number for naked IP encapsulation (this is not currently used)
  44. */
  45. #define ZT_DEFAULT_IP_PROTOCOL 193
  46. /**
  47. * Ethernet type for naked Ethernet encapsulation (this is not currently used)
  48. */
  49. #define ZT_DEFAULT_ETHERNET_PROTOCOL 0x9993
  50. /**
  51. * Size of a standard I/O buffer as returned by getBuffer().
  52. */
  53. #define ZT_BUF_SIZE 16384
  54. /**
  55. * Minimum Ethernet MTU allowed on virtual (not physical) networks
  56. */
  57. #define ZT_MIN_MTU 1280
  58. /**
  59. * Maximum Ethernet MTU allowed on virtual (not physical) networks
  60. */
  61. #define ZT_MAX_MTU 10000
  62. /**
  63. * Minimum allowed physical UDP MTU (smaller values are clipped to this)
  64. */
  65. #define ZT_MIN_UDP_MTU 1400
  66. /**
  67. * Default UDP payload size NOT including UDP and IP overhead
  68. *
  69. * This is small enough for PPPoE and for Google Cloud's bizarrely tiny MTUs.
  70. * A payload size corresponding to the default 2800 byte virtual MTU fits
  71. * into two packets of less than or equal to this size.
  72. */
  73. #define ZT_DEFAULT_UDP_MTU 1432
  74. /**
  75. * Maximum physical payload size that can ever be used
  76. */
  77. #define ZT_MAX_UDP_PHYSPAYLOAD 10100
  78. /**
  79. * Headroom for max physical MTU
  80. */
  81. #define ZT_MAX_UDP_HEADROOM 224
  82. /**
  83. * Maximum payload MTU for UDP packets
  84. */
  85. #define ZT_MAX_UDP_MTU (ZT_MAX_UDP_PHYSPAYLOAD + ZT_MAX_UDP_HEADROOM)
  86. /**
  87. * Maximum length of network short name
  88. */
  89. #define ZT_MAX_NETWORK_SHORT_NAME_LENGTH 127
  90. /**
  91. * Maximum number of pushed routes on a network (via ZT in-band mechanisms)
  92. */
  93. #define ZT_MAX_NETWORK_ROUTES 64
  94. /**
  95. * Maximum number of statically assigned IP addresses (via ZT in-band mechanisms)
  96. */
  97. #define ZT_MAX_ZT_ASSIGNED_ADDRESSES 32
  98. /**
  99. * Maximum number of "specialists" on a network -- bridges, etc.
  100. *
  101. * A specialist is a node tagged with some special role like acting as
  102. * a promiscuous bridge, open relay, administrator, etc.
  103. */
  104. #define ZT_MAX_NETWORK_SPECIALISTS 256
  105. /**
  106. * Rules engine revision ID, which specifies rules engine capabilities
  107. */
  108. #define ZT_RULES_ENGINE_REVISION 1
  109. /**
  110. * Maximum number of base (non-capability) network rules
  111. */
  112. #define ZT_MAX_NETWORK_RULES 1024
  113. /**
  114. * Maximum number of capabilities per network per member
  115. */
  116. #define ZT_MAX_NETWORK_CAPABILITIES 128
  117. /**
  118. * Maximum number of tags per network per member
  119. */
  120. #define ZT_MAX_NETWORK_TAGS 128
  121. /**
  122. * Maximum number of direct network paths to a given peer
  123. *
  124. * Note that dual-stack configs may end up resulting in both IPv6 and IPv4
  125. * paths existing. This gives enough headroom for multipath configs with
  126. * dual stacks across the board.
  127. */
  128. #define ZT_MAX_PEER_NETWORK_PATHS 16
  129. /**
  130. * Maximum number of rules per capability object
  131. *
  132. * Capabilities normally contain only a few rules. The rules in a capability
  133. * should be short and to the point.
  134. */
  135. #define ZT_MAX_CAPABILITY_RULES 64
  136. /**
  137. * Maximum number of certificates of ownership to assign to a single network member
  138. *
  139. * Network members can have more than four IPs, etc., but right now there
  140. * is a protocol limit on how many COOs can be assigned. If your config needs
  141. * more than four authenticated IPs per node you may have personal problems.
  142. */
  143. #define ZT_MAX_CERTIFICATES_OF_OWNERSHIP 4
  144. /**
  145. * Packet characteristics flag: packet direction, 1 if inbound 0 if outbound
  146. */
  147. #define ZT_RULE_PACKET_CHARACTERISTICS_INBOUND 0x8000000000000000ULL
  148. /**
  149. * Packet characteristics flag: multicast or broadcast destination MAC
  150. */
  151. #define ZT_RULE_PACKET_CHARACTERISTICS_MULTICAST 0x4000000000000000ULL
  152. /**
  153. * Packet characteristics flag: broadcast destination MAC
  154. */
  155. #define ZT_RULE_PACKET_CHARACTERISTICS_BROADCAST 0x2000000000000000ULL
  156. /**
  157. * Packet characteristics flag: sending IP address has a certificate of ownership
  158. */
  159. #define ZT_RULE_PACKET_CHARACTERISTICS_SENDER_IP_AUTHENTICATED 0x1000000000000000ULL
  160. /**
  161. * Packet characteristics flag: sending MAC address has a certificate of ownership
  162. */
  163. #define ZT_RULE_PACKET_CHARACTERISTICS_SENDER_MAC_AUTHENTICATED 0x0800000000000000ULL
  164. /**
  165. * Packet characteristics flag: TCP left-most reserved bit
  166. */
  167. #define ZT_RULE_PACKET_CHARACTERISTICS_TCP_RESERVED_0 0x0000000000000800ULL
  168. /**
  169. * Packet characteristics flag: TCP middle reserved bit
  170. */
  171. #define ZT_RULE_PACKET_CHARACTERISTICS_TCP_RESERVED_1 0x0000000000000400ULL
  172. /**
  173. * Packet characteristics flag: TCP right-most reserved bit
  174. */
  175. #define ZT_RULE_PACKET_CHARACTERISTICS_TCP_RESERVED_2 0x0000000000000200ULL
  176. /**
  177. * Packet characteristics flag: TCP NS flag
  178. */
  179. #define ZT_RULE_PACKET_CHARACTERISTICS_TCP_NS 0x0000000000000100ULL
  180. /**
  181. * Packet characteristics flag: TCP CWR flag
  182. */
  183. #define ZT_RULE_PACKET_CHARACTERISTICS_TCP_CWR 0x0000000000000080ULL
  184. /**
  185. * Packet characteristics flag: TCP ECE flag
  186. */
  187. #define ZT_RULE_PACKET_CHARACTERISTICS_TCP_ECE 0x0000000000000040ULL
  188. /**
  189. * Packet characteristics flag: TCP URG flag
  190. */
  191. #define ZT_RULE_PACKET_CHARACTERISTICS_TCP_URG 0x0000000000000020ULL
  192. /**
  193. * Packet characteristics flag: TCP ACK flag
  194. */
  195. #define ZT_RULE_PACKET_CHARACTERISTICS_TCP_ACK 0x0000000000000010ULL
  196. /**
  197. * Packet characteristics flag: TCP PSH flag
  198. */
  199. #define ZT_RULE_PACKET_CHARACTERISTICS_TCP_PSH 0x0000000000000008ULL
  200. /**
  201. * Packet characteristics flag: TCP RST flag
  202. */
  203. #define ZT_RULE_PACKET_CHARACTERISTICS_TCP_RST 0x0000000000000004ULL
  204. /**
  205. * Packet characteristics flag: TCP SYN flag
  206. */
  207. #define ZT_RULE_PACKET_CHARACTERISTICS_TCP_SYN 0x0000000000000002ULL
  208. /**
  209. * Packet characteristics flag: TCP FIN flag
  210. */
  211. #define ZT_RULE_PACKET_CHARACTERISTICS_TCP_FIN 0x0000000000000001ULL
  212. /* ---------------------------------------------------------------------------------------------------------------- */
  213. /**
  214. * Identity type codes (must be the same as Identity.hpp).
  215. */
  216. enum ZT_IdentityType
  217. {
  218. ZT_IDENTITY_TYPE_C25519 = 0, /* C25519/Ed25519 */
  219. ZT_IDENTITY_TYPE_P384 = 1 /* Combined C25519/NIST-P-384 key */
  220. };
  221. /**
  222. * ZeroTier identity (address plus keys)
  223. */
  224. typedef void ZT_Identity;
  225. /**
  226. * Locator is a signed list of endpoints
  227. */
  228. typedef void ZT_Locator;
  229. /**
  230. * Full identity fingerprint with address and 384-bit hash of public key(s)
  231. */
  232. typedef struct
  233. {
  234. /**
  235. * Short address (only least significant 40 bits are used)
  236. */
  237. uint64_t address;
  238. /**
  239. * 384-bit hash of identity public key(s)
  240. */
  241. uint8_t hash[48];
  242. } ZT_Fingerprint;
  243. /**
  244. * Maximum length of string fields in identification certificates
  245. */
  246. #define ZT_IDENTIFICATION_CERTIFICATE_MAX_STRING_LENGTH 127
  247. /**
  248. * Maximum length of a signature
  249. */
  250. #define ZT_IDENTIFICATION_CERTIFICATE_MAX_SIGNATURE_SIZE 256
  251. /**
  252. * Flag indicating that the nodes in the subject are a set of roots
  253. */
  254. #define ZT_IDENTIFICATION_CERTIFICATE_FLAG_ROOT_SET 0x0000000000000001ULL
  255. /**
  256. * Information about a real world entity.
  257. */
  258. typedef struct
  259. {
  260. char country[ZT_IDENTIFICATION_CERTIFICATE_MAX_STRING_LENGTH + 1];
  261. char organization[ZT_IDENTIFICATION_CERTIFICATE_MAX_STRING_LENGTH + 1];
  262. char unit[ZT_IDENTIFICATION_CERTIFICATE_MAX_STRING_LENGTH + 1];
  263. char locality[ZT_IDENTIFICATION_CERTIFICATE_MAX_STRING_LENGTH + 1];
  264. char province[ZT_IDENTIFICATION_CERTIFICATE_MAX_STRING_LENGTH + 1];
  265. char streetAddress[ZT_IDENTIFICATION_CERTIFICATE_MAX_STRING_LENGTH + 1];
  266. char postalCode[ZT_IDENTIFICATION_CERTIFICATE_MAX_STRING_LENGTH + 1];
  267. char commonName[ZT_IDENTIFICATION_CERTIFICATE_MAX_STRING_LENGTH + 1];
  268. char serialNo[ZT_IDENTIFICATION_CERTIFICATE_MAX_STRING_LENGTH + 1];
  269. char email[ZT_IDENTIFICATION_CERTIFICATE_MAX_STRING_LENGTH + 1];
  270. char url[ZT_IDENTIFICATION_CERTIFICATE_MAX_STRING_LENGTH + 1];
  271. } ZT_IdentificationCertificate_Name;
  272. /**
  273. * Identity and optional locator for a node
  274. */
  275. typedef struct
  276. {
  277. /**
  278. * Identity (never NULL)
  279. */
  280. const ZT_Identity *identity;
  281. /**
  282. * Locator or NULL if not specified
  283. */
  284. const ZT_Locator *locator;
  285. } ZT_IdentificationCertificate_Node;
  286. /**
  287. * ID and primary controller for a network
  288. */
  289. typedef struct
  290. {
  291. /**
  292. * Network ID
  293. */
  294. uint64_t id;
  295. /**
  296. * Full fingerprint of primary controller
  297. */
  298. ZT_Fingerprint controller;
  299. } ZT_IdentificationCertificate_Network;
  300. /**
  301. * Identification certificate subject
  302. */
  303. typedef struct
  304. {
  305. /**
  306. * Identities and optional locators of nodes
  307. */
  308. ZT_IdentificationCertificate_Node *nodes;
  309. /**
  310. * Networks owned by this entity
  311. */
  312. ZT_IdentificationCertificate_Network *networks;
  313. /**
  314. * Number of nodes
  315. */
  316. unsigned int nodeCount;
  317. /**
  318. * Number of networks
  319. */
  320. unsigned int networkCount;
  321. /**
  322. * Information about owner of items.
  323. */
  324. ZT_IdentificationCertificate_Name name;
  325. } ZT_IdentificationCertificate_Subject;
  326. /**
  327. * Identification certificate
  328. *
  329. * This is designed so it could be converted to/from an X509 format
  330. * for interoperability with X509 systems. OCSP could be implemented
  331. * too, though it would probably require the development of an OCSP
  332. * proxy server that queried the issuer via the ZeroTier protocol.
  333. */
  334. typedef struct
  335. {
  336. /**
  337. * Serial number, a SHA384 hash of this certificate.
  338. */
  339. uint8_t serialNo[48];
  340. /**
  341. * Certificate version
  342. */
  343. unsigned int version;
  344. /**
  345. * Maximum path length from this certificate toward further certificates.
  346. *
  347. * Subjects may sign other certificates whose path lengths are less than
  348. * this value. A value of zero indicates that no identification certificates
  349. * may be signed (not a CA).
  350. */
  351. unsigned int maxPathLength;
  352. /**
  353. * Flags indicating certificate usage and any other attributes.
  354. */
  355. uint64_t flags;
  356. /**
  357. * Valid time range: not before, not after.
  358. *
  359. * In ZeroTier the not before field is also the certificate issued time
  360. * and timestamp.
  361. */
  362. int64_t validity[2];
  363. /**
  364. * Subject of certificate
  365. */
  366. ZT_IdentificationCertificate_Subject subject;
  367. /**
  368. * Issuer node identity and public key(s).
  369. */
  370. const ZT_Identity *issuer;
  371. /**
  372. * Issuer information
  373. */
  374. ZT_IdentificationCertificate_Name issuerName;
  375. /**
  376. * URLs that can be consulted for updates to this certificate.
  377. */
  378. const char *const *updateUrls;
  379. /**
  380. * Number of update URLs
  381. */
  382. unsigned int updateUrlCount;
  383. /**
  384. * Size of signature in bytes.
  385. */
  386. unsigned int signatureSize;
  387. /**
  388. * Signature by issuer (algorithm determined by identity type).
  389. */
  390. uint8_t signature[ZT_IDENTIFICATION_CERTIFICATE_MAX_SIGNATURE_SIZE];
  391. } ZT_IdentificationCertificate;
  392. /**
  393. * Credential type IDs
  394. */
  395. enum ZT_CredentialType
  396. {
  397. ZT_CREDENTIAL_TYPE_NULL = 0,
  398. ZT_CREDENTIAL_TYPE_COM = 1,
  399. ZT_CREDENTIAL_TYPE_CAPABILITY = 2,
  400. ZT_CREDENTIAL_TYPE_TAG = 3,
  401. ZT_CREDENTIAL_TYPE_COO = 4,
  402. ZT_CREDENTIAL_TYPE_REVOCATION = 6
  403. };
  404. /**
  405. * Endpoint address and protocol types
  406. *
  407. * Most of these are not currently implemented and are just reserved
  408. * for future use.
  409. */
  410. enum ZT_EndpointType
  411. {
  412. ZT_ENDPOINT_TYPE_NIL = 0, // Nil/empty endpoint
  413. ZT_ENDPOINT_TYPE_ZEROTIER = 1, // ZeroTier relaying (address+fingerprint)
  414. ZT_ENDPOINT_TYPE_ETHERNET = 2, // Ethernet with ethertype 0x9993
  415. ZT_ENDPOINT_TYPE_WIFI_DIRECT = 3, // Ethernet using WiFi direct
  416. ZT_ENDPOINT_TYPE_BLUETOOTH = 4, // Bluetooth (same address type as Ethernet)
  417. ZT_ENDPOINT_TYPE_IP = 5, // Naked IP (protocol 193)
  418. ZT_ENDPOINT_TYPE_IP_UDP = 6, // IP/UDP
  419. ZT_ENDPOINT_TYPE_IP_TCP = 7, // IP/TCP
  420. ZT_ENDPOINT_TYPE_IP_HTTP = 8 // IP/HTTP encapsulation
  421. };
  422. /**
  423. * Flag indicating that VL1 tracing should be generated
  424. */
  425. #define ZT_TRACE_FLAG_VL1 0x01
  426. /**
  427. * Flag indicating that VL2 (virtual network) tracing should be generated
  428. */
  429. #define ZT_TRACE_FLAG_VL2 0x02
  430. /**
  431. * Flag indicating that VL2 network filter tracing should be generated (separate because this can be very verbose)
  432. */
  433. #define ZT_TRACE_FLAG_VL2_FILTER 0x04
  434. /**
  435. * Flag indicating that VL2 multicast propagation should be reported
  436. */
  437. #define ZT_TRACE_FLAG_VL2_MULTICAST 0x08
  438. /**
  439. * Trace event types
  440. *
  441. * All trace event structures start with a size and type.
  442. */
  443. enum ZT_TraceEventType
  444. {
  445. ZT_TRACE_UNEXPECTED_ERROR = 0,
  446. ZT_TRACE_VL1_RESETTING_PATHS_IN_SCOPE = 1,
  447. ZT_TRACE_VL1_TRYING_NEW_PATH = 2,
  448. ZT_TRACE_VL1_LEARNED_NEW_PATH = 3,
  449. ZT_TRACE_VL1_INCOMING_PACKET_DROPPED = 4,
  450. ZT_TRACE_VL2_OUTGOING_FRAME_DROPPED = 100,
  451. ZT_TRACE_VL2_INCOMING_FRAME_DROPPED = 101,
  452. ZT_TRACE_VL2_NETWORK_CONFIG_REQUESTED = 102,
  453. ZT_TRACE_VL2_NETWORK_FILTER = 103
  454. };
  455. /**
  456. * Trace VL1 packet drop reasons
  457. */
  458. enum ZT_TracePacketDropReason
  459. {
  460. ZT_TRACE_PACKET_DROP_REASON_UNSPECIFIED = 0,
  461. ZT_TRACE_PACKET_DROP_REASON_PEER_TOO_OLD = 1,
  462. ZT_TRACE_PACKET_DROP_REASON_MALFORMED_PACKET = 2,
  463. ZT_TRACE_PACKET_DROP_REASON_MAC_FAILED = 3,
  464. ZT_TRACE_PACKET_DROP_REASON_RATE_LIMIT_EXCEEDED = 4,
  465. ZT_TRACE_PACKET_DROP_REASON_INVALID_OBJECT = 5,
  466. ZT_TRACE_PACKET_DROP_REASON_INVALID_COMPRESSED_DATA = 6,
  467. ZT_TRACE_PACKET_DROP_REASON_UNRECOGNIZED_VERB = 7,
  468. ZT_TRACE_PACKET_DROP_REASON_REPLY_NOT_EXPECTED = 8
  469. };
  470. /**
  471. * Trace VL2 frame drop reasons
  472. */
  473. enum ZT_TraceFrameDropReason
  474. {
  475. ZT_TRACE_FRAME_DROP_REASON_UNSPECIFIED = 0,
  476. ZT_TRACE_FRAME_DROP_REASON_BRIDGING_NOT_ALLOWED_REMOTE = 1,
  477. ZT_TRACE_FRAME_DROP_REASON_BRIDGING_NOT_ALLOWED_LOCAL = 2,
  478. ZT_TRACE_FRAME_DROP_REASON_MULTICAST_DISABLED = 3,
  479. ZT_TRACE_FRAME_DROP_REASON_BROADCAST_DISABLED = 4,
  480. ZT_TRACE_FRAME_DROP_REASON_FILTER_BLOCKED = 5,
  481. ZT_TRACE_FRAME_DROP_REASON_FILTER_BLOCKED_AT_BRIDGE_REPLICATION = 6,
  482. ZT_TRACE_FRAME_DROP_REASON_PERMISSION_DENIED = 7
  483. };
  484. /**
  485. * Reasons for credential rejection
  486. */
  487. enum ZT_TraceCredentialRejectionReason
  488. {
  489. ZT_TRACE_CREDENTIAL_REJECTION_REASON_SIGNATURE_VERIFICATION_FAILED = 1,
  490. ZT_TRACE_CREDENTIAL_REJECTION_REASON_REVOKED = 2,
  491. ZT_TRACE_CREDENTIAL_REJECTION_REASON_OLDER_THAN_LATEST = 3,
  492. ZT_TRACE_CREDENTIAL_REJECTION_REASON_INVALID = 4
  493. };
  494. #define ZT_TRACE_FIELD_TYPE "t"
  495. #define ZT_TRACE_FIELD_CODE_LOCATION "c"
  496. #define ZT_TRACE_FIELD_ENDPOINT "e"
  497. #define ZT_TRACE_FIELD_OLD_ENDPOINT "oe"
  498. #define ZT_TRACE_FIELD_NEW_ENDPOINT "ne"
  499. #define ZT_TRACE_FIELD_TRIGGER_FROM_ENDPOINT "te"
  500. #define ZT_TRACE_FIELD_TRIGGER_FROM_PACKET_ID "ti"
  501. #define ZT_TRACE_FIELD_TRIGGER_FROM_PACKET_VERB "tv"
  502. #define ZT_TRACE_FIELD_TRIGGER_FROM_PEER_FINGERPRINT_HASH "tp"
  503. #define ZT_TRACE_FIELD_MESSAGE "m"
  504. #define ZT_TRACE_FIELD_RESET_ADDRESS_SCOPE "rs"
  505. #define ZT_TRACE_FIELD_IDENTITY_FINGERPRINT_HASH "f"
  506. #define ZT_TRACE_FIELD_PACKET_ID "p"
  507. #define ZT_TRACE_FIELD_PACKET_VERB "v"
  508. #define ZT_TRACE_FIELD_PACKET_HOPS "h"
  509. #define ZT_TRACE_FIELD_NETWORK_ID "n"
  510. #define ZT_TRACE_FIELD_REASON "r"
  511. #define ZT_TRACE_FIELD_SOURCE_MAC "sm"
  512. #define ZT_TRACE_FIELD_DEST_MAC "dm"
  513. #define ZT_TRACE_FIELD_ETHERTYPE "et"
  514. #define ZT_TRACE_FIELD_VLAN_ID "vlid"
  515. #define ZT_TRACE_FIELD_FRAME_LENGTH "fl"
  516. #define ZT_TRACE_FIELD_FRAME_DATA "fd"
  517. #define ZT_TRACE_FIELD_FLAG_CREDENTIAL_REQUEST_SENT "crs"
  518. #define ZT_TRACE_FIELD_PRIMARY_RULE_SET_LOG "rL"
  519. #define ZT_TRACE_FIELD_MATCHING_CAPABILITY_RULE_SET_LOG "caRL"
  520. #define ZT_TRACE_FIELD_MATCHING_CAPABILITY_ID "caID"
  521. #define ZT_TRACE_FIELD_MATCHING_CAPABILITY_TIMESTAMP "caTS"
  522. #define ZT_TRACE_FIELD_SOURCE_ZT_ADDRESS "sz"
  523. #define ZT_TRACE_FIELD_DEST_ZT_ADDRESS "dz"
  524. #define ZT_TRACE_FIELD_RULE_FLAG_NOTEE "rNT"
  525. #define ZT_TRACE_FIELD_RULE_FLAG_INBOUND "rIN"
  526. #define ZT_TRACE_FIELD_RULE_FLAG_ACCEPT "rACC"
  527. #define ZT_TRACE_FIELD_CREDENTIAL_ID "crID"
  528. #define ZT_TRACE_FIELD_CREDENTIAL_TYPE "crT"
  529. #define ZT_TRACE_FIELD_CREDENTIAL_TIMESTAMP "crTS"
  530. /**
  531. * Function return code: OK (0) or error results
  532. *
  533. * Use ZT_ResultCode_isFatal() to check for a fatal error. If a fatal error
  534. * occurs, the node should be considered to not be working correctly. These
  535. * indicate serious problems like an inaccessible data store or a compile
  536. * problem.
  537. */
  538. enum ZT_ResultCode
  539. {
  540. /**
  541. * Operation completed normally
  542. */
  543. ZT_RESULT_OK = 0,
  544. /* Fatal errors (>100, <1000) */
  545. /**
  546. * Ran out of memory
  547. */
  548. ZT_RESULT_FATAL_ERROR_OUT_OF_MEMORY = 100,
  549. /**
  550. * Data store is not writable or has failed
  551. */
  552. ZT_RESULT_FATAL_ERROR_DATA_STORE_FAILED = 101,
  553. /**
  554. * Internal error fatal to the instance
  555. */
  556. ZT_RESULT_FATAL_ERROR_INTERNAL = 102,
  557. /* Non-fatal errors (>1000) */
  558. /**
  559. * Network ID not valid
  560. */
  561. ZT_RESULT_ERROR_NETWORK_NOT_FOUND = 1000,
  562. /**
  563. * The requested operation is not supported on this version or build
  564. */
  565. ZT_RESULT_ERROR_UNSUPPORTED_OPERATION = 1001,
  566. /**
  567. * The requested operation was given a bad parameter or was called in an invalid state
  568. */
  569. ZT_RESULT_ERROR_BAD_PARAMETER = 1002,
  570. /**
  571. * A credential or other object was supplied that failed cryptographic signature or integrity check
  572. */
  573. ZT_RESULT_ERROR_INVALID_CREDENTIAL = 1003,
  574. /**
  575. * An object collides with another object in some way (meaning is object-specific)
  576. */
  577. ZT_RESULT_ERROR_COLLIDING_OBJECT = 1004,
  578. /**
  579. * An internal error occurred, but one that is not fatal to the whole instance
  580. */
  581. ZT_RESULT_ERROR_INTERNAL = 1005
  582. };
  583. /**
  584. * Macro to check for a fatal error result code
  585. *
  586. * @param x Result code
  587. * @return True if result code indicates a fatal error
  588. */
  589. #define ZT_ResultCode_isFatal(x) ((((int)(x)) >= 100)&&(((int)(x)) < 1000))
  590. /**
  591. * Status codes sent to status update callback when things happen
  592. */
  593. enum ZT_Event
  594. {
  595. /**
  596. * Node has been initialized
  597. *
  598. * This is the first event generated, and is always sent. It may occur
  599. * before Node's constructor returns.
  600. *
  601. * Meta-data: none
  602. */
  603. ZT_EVENT_UP = 0,
  604. /**
  605. * Node appears offline
  606. *
  607. * This indicates that the node doesn't seem to be able to reach anything,
  608. * or hasn't for a while. It's not a hard instantaneous thing.
  609. *
  610. * Meta-data: none
  611. */
  612. ZT_EVENT_OFFLINE = 1,
  613. /**
  614. * Node appears online
  615. *
  616. * This indicates that the node was offline but now seems to be able to
  617. * reach something. Like OFFLINE it's not a hard instantaneous thing but
  618. * more of an indicator for UI reporting purposes.
  619. *
  620. * Meta-data: none
  621. */
  622. ZT_EVENT_ONLINE = 2,
  623. /**
  624. * Node is shutting down
  625. *
  626. * This is generated within Node's destructor when it is being shut down.
  627. * It's done for convenience in case you want to clean up anything during
  628. * node shutdown in your node event handler.
  629. *
  630. * Meta-data: none
  631. */
  632. ZT_EVENT_DOWN = 3,
  633. // 4 once signaled identity collision but this is no longer an error
  634. /**
  635. * Trace (debugging) message
  636. *
  637. * These events are only generated if this is a TRACE-enabled build.
  638. * This is for local debug traces, not remote trace diagnostics.
  639. *
  640. * Meta-data: struct of type ZT_Trace_*
  641. */
  642. ZT_EVENT_TRACE = 5,
  643. /**
  644. * VERB_USER_MESSAGE received
  645. *
  646. * These are generated when a VERB_USER_MESSAGE packet is received via
  647. * ZeroTier VL1. This can be used for below-VL2 in-band application
  648. * specific signaling over the ZeroTier protocol.
  649. *
  650. * It's up to you to ensure that you handle these in a way that does
  651. * not introduce a remote security vulnerability into your app! If
  652. * your USER_MESSAGE code has a buffer overflow or other vulnerability
  653. * then your app will be vulnerable and this is not ZT's fault. :)
  654. *
  655. * Meta-data: ZT_UserMessage structure
  656. */
  657. ZT_EVENT_USER_MESSAGE = 6
  658. };
  659. /**
  660. * User message used with ZT_EVENT_USER_MESSAGE
  661. *
  662. * These are direct VL1 P2P messages for application use. Encryption and
  663. * authentication in the ZeroTier protocol will guarantee the origin
  664. * address and message content, but you are responsible for any other
  665. * levels of authentication or access control that are required. Any node
  666. * in the world can send you a user message! (Unless your network is air
  667. * gapped.)
  668. *
  669. * Pointers to id and data might not remain valid after the event is
  670. * received.
  671. */
  672. typedef struct
  673. {
  674. /**
  675. * Identity of sender
  676. */
  677. const ZT_Identity *id;
  678. /**
  679. * User message type ID
  680. */
  681. uint64_t typeId;
  682. /**
  683. * User message data
  684. */
  685. const void *data;
  686. /**
  687. * Length of data in bytes
  688. */
  689. unsigned int length;
  690. } ZT_UserMessage;
  691. /**
  692. * Current node status
  693. */
  694. typedef struct
  695. {
  696. /**
  697. * 40-bit ZeroTier address of this node
  698. */
  699. uint64_t address;
  700. /**
  701. * Actual identity object for this node
  702. */
  703. const ZT_Identity *identity;
  704. /**
  705. * Public identity in string-serialized form (safe to send to others)
  706. *
  707. * This pointer will remain valid as long as the node exists.
  708. */
  709. const char *publicIdentity;
  710. /**
  711. * Full identity including secret key in string-serialized form
  712. *
  713. * This pointer will remain valid as long as the node exists.
  714. */
  715. const char *secretIdentity;
  716. /**
  717. * True if some kind of connectivity appears available
  718. */
  719. int online;
  720. } ZT_NodeStatus;
  721. /**
  722. * Virtual network status codes
  723. */
  724. enum ZT_VirtualNetworkStatus
  725. {
  726. /**
  727. * Waiting for network configuration (also means revision == 0)
  728. */
  729. ZT_NETWORK_STATUS_REQUESTING_CONFIGURATION = 0,
  730. /**
  731. * Configuration received and we are authorized
  732. */
  733. ZT_NETWORK_STATUS_OK = 1,
  734. /**
  735. * Netconf master told us 'nope'
  736. */
  737. ZT_NETWORK_STATUS_ACCESS_DENIED = 2,
  738. /**
  739. * Netconf master exists, but this virtual network does not
  740. */
  741. ZT_NETWORK_STATUS_NOT_FOUND = 3
  742. };
  743. /**
  744. * Virtual network type codes
  745. */
  746. enum ZT_VirtualNetworkType
  747. {
  748. /**
  749. * Private networks are authorized via certificates of membership
  750. */
  751. ZT_NETWORK_TYPE_PRIVATE = 0,
  752. /**
  753. * Public networks have no access control -- they'll always be AUTHORIZED
  754. */
  755. ZT_NETWORK_TYPE_PUBLIC = 1
  756. };
  757. /**
  758. * The type of a virtual network rules table entry
  759. *
  760. * These must be from 0 to 63 since the most significant two bits of each
  761. * rule type are NOT (MSB) and AND/OR.
  762. *
  763. * Each rule is composed of zero or more MATCHes followed by an ACTION.
  764. * An ACTION with no MATCHes is always taken.
  765. */
  766. enum ZT_VirtualNetworkRuleType
  767. {
  768. // 0 to 15 reserved for actions
  769. /**
  770. * Drop frame
  771. */
  772. ZT_NETWORK_RULE_ACTION_DROP = 0,
  773. /**
  774. * Accept and pass frame
  775. */
  776. ZT_NETWORK_RULE_ACTION_ACCEPT = 1,
  777. /**
  778. * Forward a copy of this frame to an observer (by ZT address)
  779. */
  780. ZT_NETWORK_RULE_ACTION_TEE = 2,
  781. /**
  782. * Exactly like TEE but mandates ACKs from observer
  783. */
  784. ZT_NETWORK_RULE_ACTION_WATCH = 3,
  785. /**
  786. * Drop and redirect this frame to another node (by ZT address)
  787. */
  788. ZT_NETWORK_RULE_ACTION_REDIRECT = 4,
  789. /**
  790. * Stop evaluating rule set (drops unless there are capabilities, etc.)
  791. */
  792. ZT_NETWORK_RULE_ACTION_BREAK = 5,
  793. /**
  794. * Place a matching frame in the specified QoS bucket
  795. */
  796. ZT_NETWORK_RULE_ACTION_PRIORITY = 6,
  797. /**
  798. * Maximum ID for an ACTION, anything higher is a MATCH
  799. */
  800. ZT_NETWORK_RULE_ACTION__MAX_ID = 15,
  801. // 16 to 63 reserved for match criteria
  802. ZT_NETWORK_RULE_MATCH_SOURCE_ZEROTIER_ADDRESS = 24,
  803. ZT_NETWORK_RULE_MATCH_DEST_ZEROTIER_ADDRESS = 25,
  804. ZT_NETWORK_RULE_MATCH_VLAN_ID = 26,
  805. ZT_NETWORK_RULE_MATCH_VLAN_PCP = 27,
  806. ZT_NETWORK_RULE_MATCH_VLAN_DEI = 28,
  807. ZT_NETWORK_RULE_MATCH_MAC_SOURCE = 29,
  808. ZT_NETWORK_RULE_MATCH_MAC_DEST = 30,
  809. ZT_NETWORK_RULE_MATCH_IPV4_SOURCE = 31,
  810. ZT_NETWORK_RULE_MATCH_IPV4_DEST = 32,
  811. ZT_NETWORK_RULE_MATCH_IPV6_SOURCE = 33,
  812. ZT_NETWORK_RULE_MATCH_IPV6_DEST = 34,
  813. ZT_NETWORK_RULE_MATCH_IP_TOS = 35,
  814. ZT_NETWORK_RULE_MATCH_IP_PROTOCOL = 36,
  815. ZT_NETWORK_RULE_MATCH_ETHERTYPE = 37,
  816. ZT_NETWORK_RULE_MATCH_ICMP = 38,
  817. ZT_NETWORK_RULE_MATCH_IP_SOURCE_PORT_RANGE = 39,
  818. ZT_NETWORK_RULE_MATCH_IP_DEST_PORT_RANGE = 40,
  819. ZT_NETWORK_RULE_MATCH_CHARACTERISTICS = 41,
  820. ZT_NETWORK_RULE_MATCH_FRAME_SIZE_RANGE = 42,
  821. ZT_NETWORK_RULE_MATCH_RANDOM = 43,
  822. ZT_NETWORK_RULE_MATCH_TAGS_DIFFERENCE = 44,
  823. ZT_NETWORK_RULE_MATCH_TAGS_BITWISE_AND = 45,
  824. ZT_NETWORK_RULE_MATCH_TAGS_BITWISE_OR = 46,
  825. ZT_NETWORK_RULE_MATCH_TAGS_BITWISE_XOR = 47,
  826. ZT_NETWORK_RULE_MATCH_TAGS_EQUAL = 48,
  827. ZT_NETWORK_RULE_MATCH_TAG_SENDER = 49,
  828. ZT_NETWORK_RULE_MATCH_TAG_RECEIVER = 50,
  829. ZT_NETWORK_RULE_MATCH_INTEGER_RANGE = 51,
  830. /**
  831. * Maximum ID allowed for a MATCH entry in the rules table
  832. */
  833. ZT_NETWORK_RULE_MATCH__MAX_ID = 63
  834. };
  835. /**
  836. * Network flow rule
  837. *
  838. * Rules are stored in a table in which one or more match entries is followed
  839. * by an action. If more than one match precedes an action, the rule is
  840. * the AND of all matches. An action with no match is always taken since it
  841. * matches anything. If nothing matches, the default action is DROP.
  842. *
  843. * This is designed to be a more memory-efficient way of storing rules than
  844. * a wide table, yet still fast and simple to access in code.
  845. */
  846. typedef struct
  847. {
  848. /**
  849. * Type and flags
  850. *
  851. * Bits are: NOTTTTTT
  852. *
  853. * N - If true, sense of match is inverted (no effect on actions)
  854. * O - If true, result is ORed with previous instead of ANDed (no effect on actions)
  855. * T - Rule or action type
  856. *
  857. * AND with 0x3f to get type, 0x80 to get NOT bit, and 0x40 to get OR bit.
  858. */
  859. uint8_t t;
  860. /**
  861. * Union containing the value of this rule -- which field is used depends on 't'
  862. */
  863. union {
  864. /**
  865. * IPv6 address in big-endian / network byte order and netmask bits
  866. */
  867. struct {
  868. uint8_t ip[16];
  869. uint8_t mask;
  870. } ipv6;
  871. /**
  872. * IPv4 address in big-endian / network byte order
  873. */
  874. struct {
  875. uint32_t ip;
  876. uint8_t mask;
  877. } ipv4;
  878. /**
  879. * Integer range match in packet payload
  880. *
  881. * This allows matching of ranges of integers up to 64 bits wide where
  882. * the range is +/- INT32_MAX. It's packed this way so it fits in 16
  883. * bytes and doesn't enlarge the overall size of this union.
  884. */
  885. struct {
  886. uint64_t start; // integer range start
  887. uint32_t end; // end of integer range (relative to start, inclusive, 0 for equality w/start)
  888. uint16_t idx; // index in packet of integer
  889. uint8_t format; // bits in integer (range 1-64, ((format&63)+1)) and endianness (MSB 1 for little, 0 for big)
  890. } intRange;
  891. /**
  892. * Packet characteristic flags being matched
  893. */
  894. uint64_t characteristics;
  895. /**
  896. * IP port range -- start-end inclusive -- host byte order
  897. */
  898. uint16_t port[2];
  899. /**
  900. * 40-bit ZeroTier address (in least significant bits, host byte order)
  901. */
  902. uint64_t zt;
  903. /**
  904. * 0 = never, UINT32_MAX = always
  905. */
  906. uint32_t randomProbability;
  907. /**
  908. * 48-bit Ethernet MAC address in big-endian order
  909. */
  910. uint8_t mac[6];
  911. /**
  912. * VLAN ID in host byte order
  913. */
  914. uint16_t vlanId;
  915. /**
  916. * VLAN PCP (least significant 3 bits)
  917. */
  918. uint8_t vlanPcp;
  919. /**
  920. * VLAN DEI (single bit / boolean)
  921. */
  922. uint8_t vlanDei;
  923. /**
  924. * Ethernet type in host byte order
  925. */
  926. uint16_t etherType;
  927. /**
  928. * IP protocol
  929. */
  930. uint8_t ipProtocol;
  931. /**
  932. * IP type of service a.k.a. DSCP field
  933. */
  934. struct {
  935. uint8_t mask;
  936. uint8_t value[2];
  937. } ipTos;
  938. /**
  939. * Ethernet packet size in host byte order (start-end, inclusive)
  940. */
  941. uint16_t frameSize[2];
  942. /**
  943. * ICMP type and code
  944. */
  945. struct {
  946. uint8_t type; // ICMP type, always matched
  947. uint8_t code; // ICMP code if matched
  948. uint8_t flags; // flag 0x01 means also match code, otherwise only match type
  949. } icmp;
  950. /**
  951. * For tag-related rules
  952. */
  953. struct {
  954. uint32_t id;
  955. uint32_t value;
  956. } tag;
  957. /**
  958. * Destinations for TEE and REDIRECT
  959. */
  960. struct {
  961. uint64_t address;
  962. uint32_t flags;
  963. uint16_t length;
  964. } fwd;
  965. /**
  966. * Quality of Service (QoS) bucket we want a frame to be placed in
  967. */
  968. uint8_t qosBucket;
  969. } v;
  970. } ZT_VirtualNetworkRule;
  971. /**
  972. * A route to be pushed on a virtual network
  973. */
  974. typedef struct
  975. {
  976. /**
  977. * Target network / netmask bits (in port field) or NULL or 0.0.0.0/0 for default
  978. */
  979. struct sockaddr_storage target;
  980. /**
  981. * Gateway IP address (port ignored) or NULL (family == 0) for LAN-local (no gateway)
  982. */
  983. struct sockaddr_storage via;
  984. /**
  985. * Route flags
  986. */
  987. uint16_t flags;
  988. /**
  989. * Route metric
  990. */
  991. uint16_t metric;
  992. } ZT_VirtualNetworkRoute;
  993. /**
  994. * An Ethernet multicast group
  995. */
  996. typedef struct
  997. {
  998. /**
  999. * MAC address (least significant 48 bits)
  1000. */
  1001. uint64_t mac;
  1002. /**
  1003. * Additional distinguishing information (usually zero)
  1004. */
  1005. unsigned long adi;
  1006. } ZT_MulticastGroup;
  1007. /**
  1008. * Virtual network configuration update type
  1009. */
  1010. enum ZT_VirtualNetworkConfigOperation
  1011. {
  1012. /**
  1013. * Network is coming up (either for the first time or after service restart)
  1014. */
  1015. ZT_VIRTUAL_NETWORK_CONFIG_OPERATION_UP = 1,
  1016. /**
  1017. * Network configuration has been updated
  1018. */
  1019. ZT_VIRTUAL_NETWORK_CONFIG_OPERATION_CONFIG_UPDATE = 2,
  1020. /**
  1021. * Network is going down (not permanently)
  1022. */
  1023. ZT_VIRTUAL_NETWORK_CONFIG_OPERATION_DOWN = 3,
  1024. /**
  1025. * Network is going down permanently (leave/delete)
  1026. */
  1027. ZT_VIRTUAL_NETWORK_CONFIG_OPERATION_DESTROY = 4
  1028. };
  1029. /**
  1030. * Virtual network configuration
  1031. */
  1032. typedef struct
  1033. {
  1034. /**
  1035. * 64-bit ZeroTier network ID
  1036. */
  1037. uint64_t nwid;
  1038. /**
  1039. * Ethernet MAC (48 bits) that should be assigned to port
  1040. */
  1041. uint64_t mac;
  1042. /**
  1043. * Network name (from network configuration master)
  1044. */
  1045. char name[ZT_MAX_NETWORK_SHORT_NAME_LENGTH + 1];
  1046. /**
  1047. * Network configuration request status
  1048. */
  1049. enum ZT_VirtualNetworkStatus status;
  1050. /**
  1051. * Network type
  1052. */
  1053. enum ZT_VirtualNetworkType type;
  1054. /**
  1055. * Maximum interface MTU
  1056. */
  1057. unsigned int mtu;
  1058. /**
  1059. * If nonzero, this port is allowed to bridge to other networks
  1060. *
  1061. * This is informational. If this is false (0), bridged packets will simply
  1062. * be dropped and bridging won't work.
  1063. */
  1064. int bridge;
  1065. /**
  1066. * If nonzero, this network supports and allows broadcast (ff:ff:ff:ff:ff:ff) traffic
  1067. */
  1068. int broadcastEnabled;
  1069. /**
  1070. * Revision number as reported by controller or 0 if still waiting for config
  1071. */
  1072. unsigned long netconfRevision;
  1073. /**
  1074. * Number of assigned addresses
  1075. */
  1076. unsigned int assignedAddressCount;
  1077. /**
  1078. * ZeroTier-assigned addresses (in sockaddr_storage structures)
  1079. *
  1080. * For IP, the port number of the sockaddr_XX structure contains the number
  1081. * of bits in the address netmask. Only the IP address and port are used.
  1082. * Other fields like interface number can be ignored.
  1083. *
  1084. * This is only used for ZeroTier-managed address assignments sent by the
  1085. * virtual network's configuration master.
  1086. */
  1087. struct sockaddr_storage assignedAddresses[ZT_MAX_ZT_ASSIGNED_ADDRESSES];
  1088. /**
  1089. * Number of ZT-pushed routes
  1090. */
  1091. unsigned int routeCount;
  1092. /**
  1093. * Routes (excluding those implied by assigned addresses and their masks)
  1094. */
  1095. ZT_VirtualNetworkRoute routes[ZT_MAX_NETWORK_ROUTES];
  1096. } ZT_VirtualNetworkConfig;
  1097. /**
  1098. * A list of networks
  1099. */
  1100. typedef struct
  1101. {
  1102. ZT_VirtualNetworkConfig *networks;
  1103. unsigned long networkCount;
  1104. } ZT_VirtualNetworkList;
  1105. /**
  1106. * Address where this node could be reached via an external interface
  1107. */
  1108. typedef struct
  1109. {
  1110. /**
  1111. * IP and port as would be reachable by external nodes
  1112. */
  1113. struct sockaddr_storage address;
  1114. /**
  1115. * If nonzero this address is static and can be incorporated into this node's Locator
  1116. */
  1117. int permanent;
  1118. } ZT_InterfaceAddress;
  1119. /**
  1120. * Variant type for storing possible path endpoints or peer contact points.
  1121. */
  1122. typedef struct
  1123. {
  1124. /**
  1125. * Endpoint type, which determines what field in the union 'a' applies.
  1126. */
  1127. enum ZT_EndpointType type;
  1128. union {
  1129. /**
  1130. * Socket address generic buffer
  1131. */
  1132. struct sockaddr_storage ss;
  1133. /**
  1134. * Socket address header, for all ZT_ENDPOINT_TYPE_IP types
  1135. */
  1136. struct sockaddr sa;
  1137. /**
  1138. * IPv4 address, for all ZT_ENDPOINT_TYPE_IP types if family is AF_INET
  1139. */
  1140. struct sockaddr_in sa_in;
  1141. /**
  1142. * IPv6 address, for all ZT_ENDPOINT_TYPE_IP types if family is AF_INET6
  1143. */
  1144. struct sockaddr_in6 sa_in6;
  1145. /**
  1146. * MAC address (least significant 48 bites) for ZT_ENDPOINT_TYPE_ETHERNET and other MAC addressed types
  1147. */
  1148. uint64_t mac;
  1149. /**
  1150. * ZeroTier node address and identity fingerprint for ZT_ENDPOINT_TYPE_ZEROTIER
  1151. */
  1152. ZT_Fingerprint fp;
  1153. } value;
  1154. } ZT_Endpoint;
  1155. /**
  1156. * Network path to a peer
  1157. */
  1158. typedef struct
  1159. {
  1160. /**
  1161. * Path endpoint
  1162. */
  1163. ZT_Endpoint endpoint;
  1164. /**
  1165. * Time of last send in milliseconds or 0 for never
  1166. */
  1167. int64_t lastSend;
  1168. /**
  1169. * Time of last receive in milliseconds or 0 for never
  1170. */
  1171. int64_t lastReceive;
  1172. /**
  1173. * Is path alive?
  1174. */
  1175. int alive;
  1176. /**
  1177. * Is path preferred?
  1178. */
  1179. int preferred;
  1180. } ZT_Path;
  1181. /**
  1182. * Peer information
  1183. */
  1184. typedef struct
  1185. {
  1186. /**
  1187. * ZeroTier address (40 bits)
  1188. */
  1189. uint64_t address;
  1190. /**
  1191. * Peer identity
  1192. */
  1193. const ZT_Identity *identity;
  1194. /**
  1195. * SHA-384 of identity public key(s)
  1196. */
  1197. ZT_Fingerprint fingerprint;
  1198. /**
  1199. * Remote major version or -1 if not known
  1200. */
  1201. int versionMajor;
  1202. /**
  1203. * Remote minor version or -1 if not known
  1204. */
  1205. int versionMinor;
  1206. /**
  1207. * Remote revision or -1 if not known
  1208. */
  1209. int versionRev;
  1210. /**
  1211. * Last measured latency in milliseconds or -1 if unknown
  1212. */
  1213. int latency;
  1214. /**
  1215. * If non-zero this peer is a root
  1216. */
  1217. int root;
  1218. /**
  1219. * Number of networks in which this peer is authenticated
  1220. */
  1221. unsigned int networkCount;
  1222. /**
  1223. * Network IDs for networks (array size: networkCount)
  1224. */
  1225. uint64_t *networks;
  1226. /**
  1227. * Number of paths (size of paths[])
  1228. */
  1229. unsigned int pathCount;
  1230. /**
  1231. * Known network paths to peer (array size: pathCount).
  1232. *
  1233. * These are direct paths only. Endpoints can also describe indirect paths,
  1234. * but those would not appear here. Right now those can only be relaying via
  1235. * a root.
  1236. */
  1237. ZT_Path *paths;
  1238. /**
  1239. * Size of locator in bytes or 0 if none
  1240. */
  1241. unsigned int locatorSize;
  1242. /**
  1243. * Serialized locator or NULL if none
  1244. */
  1245. const void *locator;
  1246. } ZT_Peer;
  1247. /**
  1248. * List of peers
  1249. */
  1250. typedef struct
  1251. {
  1252. ZT_Peer *peers;
  1253. unsigned long peerCount;
  1254. } ZT_PeerList;
  1255. /**
  1256. * ZeroTier core state objects
  1257. */
  1258. enum ZT_StateObjectType
  1259. {
  1260. /**
  1261. * Null object -- ignored
  1262. */
  1263. ZT_STATE_OBJECT_NULL = 0,
  1264. /**
  1265. * Public address and public key
  1266. *
  1267. * Object ID: (unused)
  1268. * Canonical path: <HOME>/identity.public
  1269. * Persistence: required
  1270. */
  1271. ZT_STATE_OBJECT_IDENTITY_PUBLIC = 1,
  1272. /**
  1273. * Full identity with secret key
  1274. *
  1275. * Object ID: (unused)
  1276. * Canonical path: <HOME>/identity.secret
  1277. * Persistence: required, should be stored with restricted permissions e.g. mode 0600 on *nix
  1278. */
  1279. ZT_STATE_OBJECT_IDENTITY_SECRET = 2,
  1280. /**
  1281. * This node's locator
  1282. *
  1283. * Object ID: (unused)
  1284. * Canonical path: <HOME>/locator
  1285. * Persistence: optional
  1286. */
  1287. ZT_STATE_OBJECT_LOCATOR = 3,
  1288. /**
  1289. * Peer and related state
  1290. *
  1291. * Object ID: peer address
  1292. * Canonical path: <HOME>/peers.d/<ID> (10-digit address)
  1293. * Persistence: optional, can be cleared at any time
  1294. */
  1295. ZT_STATE_OBJECT_PEER = 5,
  1296. /**
  1297. * Network configuration
  1298. *
  1299. * Object ID: network ID
  1300. * Canonical path: <HOME>/networks.d/<NETWORKID>.conf (16-digit hex ID)
  1301. * Persistence: required if network memberships should persist
  1302. */
  1303. ZT_STATE_OBJECT_NETWORK_CONFIG = 6,
  1304. /**
  1305. * Root list
  1306. *
  1307. * Object ID: (unused)
  1308. * Canonical path: <HOME>/roots
  1309. * Persistence: required if root settings should persist
  1310. */
  1311. ZT_STATE_OBJECT_ROOTS = 7
  1312. };
  1313. /**
  1314. * An instance of a ZeroTier One node (opaque)
  1315. */
  1316. typedef void ZT_Node;
  1317. /* ---------------------------------------------------------------------------------------------------------------- */
  1318. /**
  1319. * Callback called to update virtual network port configuration
  1320. *
  1321. * This can be called at any time to update the configuration of a virtual
  1322. * network port. The parameter after the network ID specifies whether this
  1323. * port is being brought up, updated, brought down, or permanently deleted.
  1324. *
  1325. * This in turn should be used by the underlying implementation to create
  1326. * and configure tap devices at the OS (or virtual network stack) layer.
  1327. *
  1328. * The supplied config pointer is not guaranteed to remain valid, so make
  1329. * a copy if you want one.
  1330. *
  1331. * This should not call multicastSubscribe() or other network-modifying
  1332. * methods, as this could cause a deadlock in multithreaded or interrupt
  1333. * driven environments.
  1334. */
  1335. typedef void (*ZT_VirtualNetworkConfigFunction)(
  1336. ZT_Node *, /* Node */
  1337. void *, /* User ptr */
  1338. void *, /* Thread ptr */
  1339. uint64_t, /* Network ID */
  1340. void **, /* Modifiable network user PTR */
  1341. enum ZT_VirtualNetworkConfigOperation, /* Config operation */
  1342. const ZT_VirtualNetworkConfig *); /* Network configuration */
  1343. /**
  1344. * Function to send a frame out to a virtual network port
  1345. *
  1346. * Parameters: (1) node, (2) user ptr, (3) network ID, (4) source MAC,
  1347. * (5) destination MAC, (6) ethertype, (7) VLAN ID, (8) frame data,
  1348. * (9) frame length.
  1349. */
  1350. typedef void (*ZT_VirtualNetworkFrameFunction)(
  1351. ZT_Node *, /* Node */
  1352. void *, /* User ptr */
  1353. void *, /* Thread ptr */
  1354. uint64_t, /* Network ID */
  1355. void **, /* Modifiable network user PTR */
  1356. uint64_t, /* Source MAC */
  1357. uint64_t, /* Destination MAC */
  1358. unsigned int, /* Ethernet type */
  1359. unsigned int, /* VLAN ID (0 for none) */
  1360. const void *, /* Frame data */
  1361. unsigned int); /* Frame length */
  1362. /**
  1363. * Callback for events
  1364. *
  1365. * Events are generated when the node's status changes in a significant way
  1366. * and on certain non-fatal errors and events of interest. The final void
  1367. * parameter points to event meta-data. The type of event meta-data (and
  1368. * whether it is present at all) is event type dependent. See the comments
  1369. * in the definition of ZT_Event.
  1370. */
  1371. typedef void (*ZT_EventCallback)(
  1372. ZT_Node *, /* Node */
  1373. void *, /* User ptr */
  1374. void *, /* Thread ptr */
  1375. enum ZT_Event, /* Event type */
  1376. const void *); /* Event payload (if applicable) */
  1377. /**
  1378. * Callback for storing and/or publishing state information
  1379. *
  1380. * See ZT_StateObjectType docs for information about each state object type
  1381. * and when and if it needs to be persisted.
  1382. *
  1383. * An object of length -1 is sent to indicate that an object should be
  1384. * deleted.
  1385. */
  1386. typedef void (*ZT_StatePutFunction)(
  1387. ZT_Node *, /* Node */
  1388. void *, /* User ptr */
  1389. void *, /* Thread ptr */
  1390. enum ZT_StateObjectType, /* State object type */
  1391. const uint64_t [2], /* State object ID (if applicable) */
  1392. const void *, /* State object data */
  1393. int); /* Length of data or -1 to delete */
  1394. /**
  1395. * Callback for retrieving stored state information
  1396. *
  1397. * This function should return the number of bytes actually stored to the
  1398. * buffer or -1 if the state object was not found. The buffer itself should
  1399. * be set to point to the data, and the last result parameter must point to
  1400. * a function that will be used to free the buffer when the core is done
  1401. * with it. This is very often just a pointer to free().
  1402. */
  1403. typedef int (*ZT_StateGetFunction)(
  1404. ZT_Node *, /* Node */
  1405. void *, /* User ptr */
  1406. void *, /* Thread ptr */
  1407. enum ZT_StateObjectType, /* State object type */
  1408. const uint64_t [2], /* State object ID (if applicable) */
  1409. void **, /* Result parameter: data */
  1410. void (**)(void *)); /* Result parameter: data free function */
  1411. /**
  1412. * Function to send a ZeroTier packet out over the physical wire (L2/L3)
  1413. *
  1414. * If there is only one local socket, the local socket can be ignored.
  1415. * If the local socket is -1, the packet should be sent out from all
  1416. * bound local sockets or a random bound local socket.
  1417. *
  1418. * If TTL is nonzero, packets should have their IP TTL value set to this
  1419. * value if possible. If this is not possible it is acceptable to ignore
  1420. * this value and send anyway with normal or default TTL.
  1421. *
  1422. * The function must return zero on success and may return any error code
  1423. * on failure. Note that success does not (of course) guarantee packet
  1424. * delivery. It only means that the packet appears to have been sent.
  1425. */
  1426. typedef int (*ZT_WirePacketSendFunction)(
  1427. ZT_Node *, /* Node */
  1428. void *, /* User ptr */
  1429. void *, /* Thread ptr */
  1430. int64_t, /* Local socket */
  1431. const struct sockaddr_storage *, /* Remote address */
  1432. const void *, /* Packet data */
  1433. unsigned int, /* Packet length */
  1434. unsigned int); /* TTL or 0 to use default */
  1435. /**
  1436. * Function to initiate HTTP requests
  1437. *
  1438. * The supplied HTTP request identifier is an opaque pointer that must
  1439. * be returned via ZT_Node_processHttpResponse(). If this handler is
  1440. * implemented then ZT_Node_processHttpResponse() must be called for
  1441. * each call made by the core to this. This function itself does not
  1442. * return any error code; use processHttpResponse() for that. It may
  1443. * be called directly from inside the implementation of this.
  1444. */
  1445. typedef void (*ZT_HTTPRequestFunction)(
  1446. ZT_Node *, /* Node */
  1447. void *, /* User ptr */
  1448. void *, /* Thread ptr */
  1449. void *, /* HTTP request identifier */
  1450. const char *, /* HTTP method (GET, HEAD, etc.) */
  1451. const char *, /* URL */
  1452. const char **, /* Header names, NULL terminated */
  1453. const char **, /* Header values, NULL terminated */
  1454. const void *, /* Request body or NULL if none */
  1455. unsigned int, /* Length of request body in bytes */
  1456. unsigned int); /* Flags */
  1457. /**
  1458. * Function to check whether a path should be used for ZeroTier traffic
  1459. *
  1460. * Parameters:
  1461. * (1) Node
  1462. * (2) User pointer
  1463. * (3) ZeroTier address or 0 for none/any
  1464. * (4) Full identity or NULL for none/any
  1465. * (5) Local socket or -1 if unknown
  1466. * (6) Remote address
  1467. *
  1468. * This function must return nonzero (true) if the path should be used.
  1469. *
  1470. * If no path check function is specified, ZeroTier will still exclude paths
  1471. * that overlap with ZeroTier-assigned and managed IP address blocks. But the
  1472. * use of a path check function is recommended to ensure that recursion does
  1473. * not occur in cases where addresses are assigned by the OS or managed by
  1474. * an out of band mechanism like DHCP. The path check function should examine
  1475. * all configured ZeroTier interfaces and check to ensure that the supplied
  1476. * addresses will not result in ZeroTier traffic being sent over a ZeroTier
  1477. * interface (recursion).
  1478. */
  1479. typedef int (*ZT_PathCheckFunction)(
  1480. ZT_Node *, /* Node */
  1481. void *, /* User ptr */
  1482. void *, /* Thread ptr */
  1483. uint64_t, /* ZeroTier address */
  1484. const ZT_Identity *, /* Full identity of node */
  1485. int64_t, /* Local socket or -1 if unknown */
  1486. const struct sockaddr_storage *); /* Remote address */
  1487. /**
  1488. * Function to get physical addresses for ZeroTier peers
  1489. *
  1490. * Parameters:
  1491. * (1) Node
  1492. * (2) User pointer
  1493. * (3) ZeroTier address (least significant 40 bits)
  1494. * (4) Identity in string form
  1495. * (5) Desired address family or -1 for any
  1496. * (6) Buffer to fill with result
  1497. *
  1498. * If provided this function will be occasionally called to get physical
  1499. * addresses that might be tried to reach a ZeroTier address. It must
  1500. * return a nonzero (true) value if the result buffer has been filled
  1501. * with an address.
  1502. */
  1503. typedef int (*ZT_PathLookupFunction)(
  1504. ZT_Node *, /* Node */
  1505. void *, /* User ptr */
  1506. void *, /* Thread ptr */
  1507. uint64_t, /* ZeroTier address (40 bits) */
  1508. const ZT_Identity *, /* Full identity of node */
  1509. int, /* Desired ss_family or -1 for any */
  1510. struct sockaddr_storage *); /* Result buffer */
  1511. /* ---------------------------------------------------------------------------------------------------------------- */
  1512. /**
  1513. * Structure for configuring ZeroTier core callback functions
  1514. */
  1515. struct ZT_Node_Callbacks
  1516. {
  1517. /**
  1518. * REQUIRED: Function to store and/or replicate state objects
  1519. */
  1520. ZT_StatePutFunction statePutFunction;
  1521. /**
  1522. * REQUIRED: Function to retrieve state objects from an object store
  1523. */
  1524. ZT_StateGetFunction stateGetFunction;
  1525. /**
  1526. * REQUIRED: Function to send packets over the physical wire
  1527. */
  1528. ZT_WirePacketSendFunction wirePacketSendFunction;
  1529. /**
  1530. * RECOMMENDED: Function to initiate HTTP requests
  1531. */
  1532. ZT_HTTPRequestFunction httpRequestFunction;
  1533. /**
  1534. * REQUIRED: Function to inject frames into a virtual network's TAP
  1535. */
  1536. ZT_VirtualNetworkFrameFunction virtualNetworkFrameFunction;
  1537. /**
  1538. * REQUIRED: Function to be called when virtual networks are configured or changed
  1539. */
  1540. ZT_VirtualNetworkConfigFunction virtualNetworkConfigFunction;
  1541. /**
  1542. * REQUIRED: Function to be called to notify external code of important events
  1543. */
  1544. ZT_EventCallback eventCallback;
  1545. /**
  1546. * OPTIONAL: Function to check whether a given physical path should be used for ZeroTier traffic
  1547. */
  1548. ZT_PathCheckFunction pathCheckFunction;
  1549. /**
  1550. * RECOMMENDED: Function to look up paths to ZeroTier nodes
  1551. */
  1552. ZT_PathLookupFunction pathLookupFunction;
  1553. };
  1554. /* ---------------------------------------------------------------------------------------------------------------- */
  1555. /**
  1556. * Get a buffer for reading data to be passed back into the core via one of the processX() functions
  1557. *
  1558. * The size of the returned buffer is 16384 bytes (ZT_BUF_SIZE).
  1559. *
  1560. * Buffers retrieved with this method MUST be returned to the core via either one of the processX()
  1561. * functions (with isZtBuffer set to true) or freeBuffer(). Buffers should not be freed directly using free().
  1562. *
  1563. * @return Pointer to I/O buffer
  1564. */
  1565. ZT_SDK_API void *ZT_getBuffer();
  1566. /**
  1567. * Free an unused buffer obtained via getBuffer
  1568. *
  1569. * @param b Buffer to free
  1570. */
  1571. ZT_SDK_API void ZT_freeBuffer(void *b);
  1572. /**
  1573. * Free a query result buffer
  1574. *
  1575. * Use this to free the return values of listNetworks(), listPeers(), and
  1576. * other query functions that return allocated structures or buffers.
  1577. *
  1578. * @param qr Query result buffer
  1579. */
  1580. ZT_SDK_API void ZT_freeQueryResult(void *qr);
  1581. /* ---------------------------------------------------------------------------------------------------------------- */
  1582. /**
  1583. * Create a new ZeroTier node
  1584. *
  1585. * This will attempt to load its identity via the state get function in the
  1586. * callback struct. If that fails it will generate a new identity and store
  1587. * it. Identity generation can take anywhere from a few hundred milliseconds
  1588. * to a few seconds depending on your CPU speed.
  1589. *
  1590. * @param node Result: pointer is set to new node instance on success
  1591. * @param uptr User pointer to pass to functions/callbacks
  1592. * @param tptr Thread pointer to pass to functions/callbacks resulting from this call
  1593. * @param callbacks Callback function configuration
  1594. * @param now Current clock in milliseconds
  1595. * @return OK (0) or error code if a fatal error condition has occurred
  1596. */
  1597. ZT_SDK_API enum ZT_ResultCode ZT_Node_new(
  1598. ZT_Node **node,
  1599. void *uptr,
  1600. void *tptr,
  1601. const struct ZT_Node_Callbacks *callbacks,
  1602. int64_t now);
  1603. /**
  1604. * Delete a node and free all resources it consumes
  1605. *
  1606. * If you are using multiple threads, all other threads must be shut down
  1607. * first. This can crash if processXXX() methods are in progress.
  1608. *
  1609. * @param node Node to delete
  1610. * @param tptr Thread pointer to pass to functions/callbacks resulting from this call
  1611. */
  1612. ZT_SDK_API void ZT_Node_delete(
  1613. ZT_Node *node,
  1614. void *tptr);
  1615. /**
  1616. * Process a packet received from the physical wire
  1617. *
  1618. * @param node Node instance
  1619. * @param tptr Thread pointer to pass to functions/callbacks resulting from this call
  1620. * @param now Current clock in milliseconds
  1621. * @param localSocket Local socket (you can use 0 if only one local socket is bound and ignore this)
  1622. * @param remoteAddress Origin of packet
  1623. * @param packetData Packet data
  1624. * @param packetLength Packet length
  1625. * @param isZtBuffer If non-zero then packetData is a buffer obtained with ZT_getBuffer()
  1626. * @param nextBackgroundTaskDeadline Value/result: set to deadline for next call to processBackgroundTasks()
  1627. * @return OK (0) or error code if a fatal error condition has occurred
  1628. */
  1629. ZT_SDK_API enum ZT_ResultCode ZT_Node_processWirePacket(
  1630. ZT_Node *node,
  1631. void *tptr,
  1632. int64_t now,
  1633. int64_t localSocket,
  1634. const struct sockaddr_storage *remoteAddress,
  1635. const void *packetData,
  1636. unsigned int packetLength,
  1637. int isZtBuffer,
  1638. volatile int64_t *nextBackgroundTaskDeadline);
  1639. /**
  1640. * Process a frame from a virtual network port (tap)
  1641. *
  1642. * @param node Node instance
  1643. * @param tptr Thread pointer to pass to functions/callbacks resulting from this call
  1644. * @param now Current clock in milliseconds
  1645. * @param nwid ZeroTier 64-bit virtual network ID
  1646. * @param sourceMac Source MAC address (least significant 48 bits)
  1647. * @param destMac Destination MAC address (least significant 48 bits)
  1648. * @param etherType 16-bit Ethernet frame type
  1649. * @param vlanId 10-bit VLAN ID or 0 if none
  1650. * @param frameData Frame payload data
  1651. * @param frameLength Frame payload length
  1652. * @param isZtBuffer If non-zero then packetData is a buffer obtained with ZT_getBuffer()
  1653. * @param nextBackgroundTaskDeadline Value/result: set to deadline for next call to processBackgroundTasks()
  1654. * @return OK (0) or error code if a fatal error condition has occurred
  1655. */
  1656. ZT_SDK_API enum ZT_ResultCode ZT_Node_processVirtualNetworkFrame(
  1657. ZT_Node *node,
  1658. void *tptr,
  1659. int64_t now,
  1660. uint64_t nwid,
  1661. uint64_t sourceMac,
  1662. uint64_t destMac,
  1663. unsigned int etherType,
  1664. unsigned int vlanId,
  1665. const void *frameData,
  1666. unsigned int frameLength,
  1667. int isZtBuffer,
  1668. volatile int64_t *nextBackgroundTaskDeadline);
  1669. /**
  1670. * Process a response from HTTP requests initiated via API callback
  1671. *
  1672. * @param node Node instance
  1673. * @param tptr Thread pointer to pass to functions/callbacks resulting from this call
  1674. * @param now Current clock in milliseconds
  1675. * @param requestId Opaque pointer provided via the requesting callback
  1676. * @param responseCode HTTP response code (e.g. 200, 500)
  1677. * @param headerNames HTTP header names, terminated by a NULL pointer
  1678. * @param headerValues HTTP header values corresponding with each name
  1679. * @param body Response body or NULL if none
  1680. * @param bodySize Size of response body in bytes
  1681. * @param flags Response flags
  1682. * @return OK (0) or error code if a fatal error condition has occurred
  1683. */
  1684. ZT_SDK_API enum ZT_ResultCode ZT_Node_processHTTPResponse(
  1685. ZT_Node *node,
  1686. void *tptr,
  1687. int64_t now,
  1688. void *requestId,
  1689. int responseCode,
  1690. const char **headerNames,
  1691. const char **headerValues,
  1692. const void *body,
  1693. unsigned int bodySize,
  1694. unsigned int flags);
  1695. /**
  1696. * Perform periodic background operations
  1697. *
  1698. * @param node Node instance
  1699. * @param tptr Thread pointer to pass to functions/callbacks resulting from this call
  1700. * @param now Current clock in milliseconds
  1701. * @param nextBackgroundTaskDeadline Value/result: set to deadline for next call to processBackgroundTasks()
  1702. * @return OK (0) or error code if a fatal error condition has occurred
  1703. */
  1704. ZT_SDK_API enum ZT_ResultCode ZT_Node_processBackgroundTasks(
  1705. ZT_Node *node,
  1706. void *tptr,
  1707. int64_t now,
  1708. volatile int64_t *nextBackgroundTaskDeadline);
  1709. /**
  1710. * Join a network
  1711. *
  1712. * This may generate calls to the port config callback before it returns,
  1713. * or these may be differed if a netconf is not available yet.
  1714. *
  1715. * If we are already a member of the network, nothing is done and OK is
  1716. * returned.
  1717. *
  1718. * @param node Node instance
  1719. * @param nwid 64-bit ZeroTier network ID
  1720. * @param fingerprintHash If non-NULL this is the full fingerprint of the controller
  1721. * @param uptr An arbitrary pointer to associate with this network (default: NULL)
  1722. * @param tptr Thread pointer to pass to functions/callbacks resulting from this call
  1723. * @return OK (0) or error code if a fatal error condition has occurred
  1724. */
  1725. ZT_SDK_API enum ZT_ResultCode ZT_Node_join(
  1726. ZT_Node *node,
  1727. uint64_t nwid,
  1728. const ZT_Fingerprint *controllerFingerprint,
  1729. void *uptr,
  1730. void *tptr);
  1731. /**
  1732. * Leave a network
  1733. *
  1734. * If a port has been configured for this network this will generate a call
  1735. * to the port config callback with a NULL second parameter to indicate that
  1736. * the port is now deleted.
  1737. *
  1738. * The uptr parameter is optional and is NULL by default. If it is not NULL,
  1739. * the pointer it points to is set to this network's uptr on success.
  1740. *
  1741. * @param node Node instance
  1742. * @param nwid 64-bit network ID
  1743. * @param uptr Target pointer is set to uptr (if not NULL)
  1744. * @param tptr Thread pointer to pass to functions/callbacks resulting from this call
  1745. * @return OK (0) or error code if a fatal error condition has occurred
  1746. */
  1747. ZT_SDK_API enum ZT_ResultCode ZT_Node_leave(
  1748. ZT_Node *node,
  1749. uint64_t nwid,
  1750. void **uptr,
  1751. void *tptr);
  1752. /**
  1753. * Subscribe to an Ethernet multicast group
  1754. *
  1755. * ADI stands for additional distinguishing information. This defaults to zero
  1756. * and is rarely used. Right now its only use is to enable IPv4 ARP to scale,
  1757. * and this must be done.
  1758. *
  1759. * For IPv4 ARP, the implementation must subscribe to 0xffffffffffff (the
  1760. * broadcast address) but with an ADI equal to each IPv4 address in host
  1761. * byte order. This converts ARP from a non-scalable broadcast protocol to
  1762. * a scalable multicast protocol with perfect address specificity.
  1763. *
  1764. * If this is not done, ARP will not work reliably.
  1765. *
  1766. * Multiple calls to subscribe to the same multicast address will have no
  1767. * effect. It is perfectly safe to do this.
  1768. *
  1769. * This does not generate an update call to networkConfigCallback().
  1770. *
  1771. * @param node Node instance
  1772. * @param tptr Thread pointer to pass to functions/callbacks resulting from this call
  1773. * @param nwid 64-bit network ID
  1774. * @param multicastGroup Ethernet multicast or broadcast MAC (least significant 48 bits)
  1775. * @param multicastAdi Multicast ADI (least significant 32 bits only, use 0 if not needed)
  1776. * @return OK (0) or error code if a fatal error condition has occurred
  1777. */
  1778. ZT_SDK_API enum ZT_ResultCode ZT_Node_multicastSubscribe(
  1779. ZT_Node *node,
  1780. void *tptr,
  1781. uint64_t nwid,
  1782. uint64_t multicastGroup,
  1783. unsigned long multicastAdi);
  1784. /**
  1785. * Unsubscribe from an Ethernet multicast group (or all groups)
  1786. *
  1787. * If multicastGroup is zero (0), this will unsubscribe from all groups. If
  1788. * you are not subscribed to a group this has no effect.
  1789. *
  1790. * This does not generate an update call to networkConfigCallback().
  1791. *
  1792. * @param node Node instance
  1793. * @param nwid 64-bit network ID
  1794. * @param multicastGroup Ethernet multicast or broadcast MAC (least significant 48 bits)
  1795. * @param multicastAdi Multicast ADI (least significant 32 bits only, use 0 if not needed)
  1796. * @return OK (0) or error code if a fatal error condition has occurred
  1797. */
  1798. ZT_SDK_API enum ZT_ResultCode ZT_Node_multicastUnsubscribe(
  1799. ZT_Node *node,
  1800. uint64_t nwid,
  1801. uint64_t multicastGroup,
  1802. unsigned long multicastAdi);
  1803. /**
  1804. * Designate a peer as a root, adding if not already known
  1805. *
  1806. * ZeroTier does not take possession of the 'id' object. It still must be
  1807. * deleted if it was allocated.
  1808. *
  1809. * @param node Node instance
  1810. * @param tptr Thread pointer to pass to functions/callbacks resulting from this call
  1811. * @param id Identity of root to add
  1812. * @return OK (0) or error code if an error condition has occurred
  1813. */
  1814. ZT_SDK_API enum ZT_ResultCode ZT_Node_addRoot(
  1815. ZT_Node *node,
  1816. void *tptr,
  1817. const ZT_Identity *id);
  1818. /**
  1819. * Un-designate a peer as a root
  1820. *
  1821. * This doesn't fully remove the peer from the peer list. It just removes
  1822. * its root trust flag. If there is no longer any need to communicate with it
  1823. * it may gradually time out and be removed.
  1824. *
  1825. * The removeRoot() only takes an address since the identity is by definition
  1826. * already known and pinned.
  1827. *
  1828. * @param node Node instance
  1829. * @param tptr Thread pointer to pass to functions/callbacks resulting from this call
  1830. * @param address ZeroTier address to remove
  1831. * @return OK (0) or error code if an error condition has occurred
  1832. */
  1833. ZT_SDK_API enum ZT_ResultCode ZT_Node_removeRoot(
  1834. ZT_Node *node,
  1835. void *tptr,
  1836. const uint64_t address);
  1837. /**
  1838. * Get this node's 40-bit ZeroTier address
  1839. *
  1840. * @param node Node instance
  1841. * @return ZeroTier address (least significant 40 bits of 64-bit int)
  1842. */
  1843. ZT_SDK_API uint64_t ZT_Node_address(ZT_Node *node);
  1844. /**
  1845. * Get this node's identity
  1846. *
  1847. * The identity pointer returned by this function need not and should not be
  1848. * freed with ZT_Identity_delete(). It's valid until the node is deleted.
  1849. *
  1850. * @param node Node instance
  1851. * @return Identity
  1852. */
  1853. ZT_SDK_API const ZT_Identity *ZT_Node_identity(ZT_Node *node);
  1854. /**
  1855. * Get the status of this node
  1856. *
  1857. * @param node Node instance
  1858. * @param status Buffer to fill with current node status
  1859. */
  1860. ZT_SDK_API void ZT_Node_status(
  1861. ZT_Node *node,
  1862. ZT_NodeStatus *status);
  1863. /**
  1864. * Get a list of known peer nodes
  1865. *
  1866. * The pointer returned here must be freed with freeQueryResult()
  1867. * when you are done with it.
  1868. *
  1869. * @param node Node instance
  1870. * @return List of known peers or NULL on failure
  1871. */
  1872. ZT_SDK_API ZT_PeerList *ZT_Node_peers(ZT_Node *node);
  1873. /**
  1874. * Get the status of a virtual network
  1875. *
  1876. * The pointer returned here must be freed with freeQueryResult()
  1877. * when you are done with it.
  1878. *
  1879. * @param node Node instance
  1880. * @param nwid 64-bit network ID
  1881. * @return Network configuration or NULL if we are not a member of this network
  1882. */
  1883. ZT_SDK_API ZT_VirtualNetworkConfig *ZT_Node_networkConfig(
  1884. ZT_Node *node,
  1885. uint64_t nwid);
  1886. /**
  1887. * Enumerate and get status of all networks
  1888. *
  1889. * @param node Node instance
  1890. * @return List of networks or NULL on failure
  1891. */
  1892. ZT_SDK_API ZT_VirtualNetworkList *ZT_Node_networks(ZT_Node *node);
  1893. /**
  1894. * Set the network-associated user-defined pointer for a given network
  1895. *
  1896. * This will have no effect if the network ID is not recognized.
  1897. *
  1898. * @param node Node instance
  1899. * @param nwid Network ID
  1900. * @param ptr New network-associated pointer
  1901. */
  1902. ZT_SDK_API void ZT_Node_setNetworkUserPtr(
  1903. ZT_Node *node,
  1904. uint64_t nwid,
  1905. void *ptr);
  1906. /**
  1907. * Set external interface addresses where this node could be reached
  1908. *
  1909. * @param node Node instance
  1910. * @param addrs Addresses
  1911. * @param addrCount Number of items in addrs[]
  1912. */
  1913. ZT_SDK_API void ZT_Node_setInterfaceAddresses(
  1914. ZT_Node *node,
  1915. const ZT_InterfaceAddress *addrs,
  1916. unsigned int addrCount);
  1917. /**
  1918. * Add a peer directly by supplying its identity
  1919. *
  1920. * This does not authorize the peer on a network (only the network's
  1921. * controller can do that) or otherwise give it special privileges. It
  1922. * also doesn't guarantee it will be contacted. It just adds it to the
  1923. * internal peer data set if it is not already present.
  1924. *
  1925. * @param node Node instance
  1926. * @param tptr Thread pointer to pass to functions/callbacks resulting from this call
  1927. * @param id Identity of peer to add
  1928. * @return OK (0) or error code
  1929. */
  1930. ZT_SDK_API enum ZT_ResultCode ZT_Node_addPeer(
  1931. ZT_Node *node,
  1932. void *tptr,
  1933. const ZT_Identity *id);
  1934. /**
  1935. * Attempt to contact a peer at an explicit endpoint address.
  1936. *
  1937. * If the fingerprint structure's hash is all zeroes, the peer is
  1938. * looked up only by address.
  1939. *
  1940. * This can only fail if the peer was not found.
  1941. *
  1942. * Note that this can immediately (before this returns) result in
  1943. * calls to the send packet functions supplied to the core.
  1944. *
  1945. * @param node Node instance
  1946. * @param tptr Thread pointer to pass to functions/callbacks resulting from this call
  1947. * @param fp Fingerprint (or only address)
  1948. * @param endpoint Endpoint
  1949. * @param retries If greater than zero, try this many times
  1950. * @return Boolean: non-zero on success, zero if peer was not found
  1951. */
  1952. ZT_SDK_API int ZT_Node_tryPeer(
  1953. ZT_Node *node,
  1954. void *tptr,
  1955. const ZT_Fingerprint *fp,
  1956. const ZT_Endpoint *endpoint,
  1957. int retries);
  1958. /**
  1959. * Send a VERB_USER_MESSAGE to another ZeroTier node
  1960. *
  1961. * There is no delivery guarantee here. Failure can occur if the message is
  1962. * too large or if dest is not a valid ZeroTier address.
  1963. *
  1964. * @param node Node instance
  1965. * @param tptr Thread pointer to pass to functions/callbacks resulting from this call
  1966. * @param dest Destination ZeroTier address
  1967. * @param typeId VERB_USER_MESSAGE type ID
  1968. * @param data Payload data to attach to user message
  1969. * @param len Length of data in bytes
  1970. * @return Boolean: non-zero on success, zero on failure
  1971. */
  1972. ZT_SDK_API int ZT_Node_sendUserMessage(
  1973. ZT_Node *node,
  1974. void *tptr,
  1975. uint64_t dest,
  1976. uint64_t typeId,
  1977. const void *data,
  1978. unsigned int len);
  1979. /**
  1980. * Set a network controller instance for this node
  1981. *
  1982. * Normal nodes should not need to use this. This is for nodes with
  1983. * special compiled-in support for acting as network configuration
  1984. * masters / controllers.
  1985. *
  1986. * The supplied instance must be a C++ object that inherits from the
  1987. * NetworkConfigMaster base class in node/. No type checking is performed,
  1988. * so a pointer to anything else will result in a crash.
  1989. *
  1990. * @param node ZertTier One node
  1991. * @param networkConfigMasterInstance Instance of NetworkConfigMaster C++ class or NULL to disable
  1992. * @return OK (0) or error code if a fatal error condition has occurred
  1993. */
  1994. ZT_SDK_API void ZT_Node_setController(
  1995. ZT_Node *node,
  1996. void *networkConfigMasterInstance);
  1997. /* ---------------------------------------------------------------------------------------------------------------- */
  1998. /**
  1999. * Generate a new identity
  2000. *
  2001. * Due to a small amount of proof of work this can be a time consuming and CPU
  2002. * intensive operation. It takes less than a second on most desktop-class systems
  2003. * but can take longer on e.g. phones.
  2004. *
  2005. * @param type Type of identity to generate
  2006. * @return New identity or NULL on error
  2007. */
  2008. ZT_SDK_API ZT_Identity *ZT_Identity_new(enum ZT_IdentityType type);
  2009. /**
  2010. * Create a new identity object from a string-serialized identity
  2011. *
  2012. * @param idStr Identity in string format
  2013. * @return Identity object or NULL if the supplied identity string was not valid
  2014. */
  2015. ZT_SDK_API ZT_Identity *ZT_Identity_fromString(const char *idStr);
  2016. /**
  2017. * Validate this identity
  2018. *
  2019. * This can be slightly time consuming due to address derivation (work) checking.
  2020. *
  2021. * @return Non-zero if identity is valid
  2022. */
  2023. ZT_SDK_API int ZT_Identity_validate(const ZT_Identity *id);
  2024. /**
  2025. * Sign a data object with this identity
  2026. *
  2027. * The identity must have a private key or this will fail.
  2028. *
  2029. * @param id Identity to use to sign
  2030. * @param data Data to sign
  2031. * @param len Length of data
  2032. * @param signature Buffer to store signature
  2033. * @param signatureBufferLength Length of buffer (must be at least 96 bytes)
  2034. * @return Length of signature in bytes or 0 on failure.
  2035. */
  2036. ZT_SDK_API unsigned int ZT_Identity_sign(
  2037. const ZT_Identity *id,
  2038. const void *data,
  2039. unsigned int len,
  2040. void *signature,
  2041. unsigned int signatureBufferLength);
  2042. /**
  2043. * Verify a signature
  2044. *
  2045. * @param id Identity to use to verify
  2046. * @param data Data to verify
  2047. * @param len Length of data
  2048. * @param signature Signature to check
  2049. * @param sigLen Length of signature in bytes
  2050. * @return Non-zero if signature is valid
  2051. */
  2052. ZT_SDK_API int ZT_Identity_verify(
  2053. const ZT_Identity *id,
  2054. const void *data,
  2055. unsigned int len,
  2056. const void *signature,
  2057. unsigned int sigLen);
  2058. /**
  2059. * Get identity type
  2060. *
  2061. * @param id Identity to query
  2062. * @return Identity type code
  2063. */
  2064. ZT_SDK_API enum ZT_IdentityType ZT_Identity_type(const ZT_Identity *id);
  2065. /**
  2066. * Convert an identity to its string representation
  2067. *
  2068. * @param id Identity to convert
  2069. * @param buf Buffer to store identity (should be at least about 1024 bytes in length)
  2070. * @param capacity Capacity of buffer
  2071. * @param includePrivate If true include the private key if present
  2072. * @return Pointer to buf or NULL on overflow or other error
  2073. */
  2074. ZT_SDK_API char *ZT_Identity_toString(
  2075. const ZT_Identity *id,
  2076. char *buf,
  2077. int capacity,
  2078. int includePrivate);
  2079. /**
  2080. * Check whether this identity object also holds a private key
  2081. *
  2082. * @param id Identity to query
  2083. * @return Non-zero if a private key is held
  2084. */
  2085. ZT_SDK_API int ZT_Identity_hasPrivate(const ZT_Identity *id);
  2086. /**
  2087. * Get the ZeroTier address associated with this identity
  2088. *
  2089. * @param id Identity to query
  2090. * @return ZeroTier address (only least significant 40 bits are meaningful, rest will be 0)
  2091. */
  2092. ZT_SDK_API uint64_t ZT_Identity_address(const ZT_Identity *id);
  2093. /**
  2094. * Get this identity's full fingerprint
  2095. *
  2096. * @param id Identity to query
  2097. * @return Pointer to fingerprint (remains valid as long as identity itself is valid)
  2098. */
  2099. ZT_SDK_API const ZT_Fingerprint *ZT_Identity_fingerprint(const ZT_Identity *id);
  2100. /**
  2101. * Delete an identity and free associated memory
  2102. *
  2103. * This should only be used with identities created via Identity_new
  2104. * and Identity_fromString().
  2105. *
  2106. * @param id Identity to delete
  2107. */
  2108. ZT_SDK_API void ZT_Identity_delete(ZT_Identity *id);
  2109. /* ---------------------------------------------------------------------------------------------------------------- */
  2110. /**
  2111. * Convert an endpoint to a string
  2112. *
  2113. * @param ep Endpoint structure
  2114. * @param buf Buffer to store string (recommended size: 256)
  2115. * @param capacity Capacity of buffer
  2116. * @return String or NULL on error
  2117. */
  2118. ZT_SDK_API char *ZT_Endpoint_toString(
  2119. const ZT_Endpoint *ep,
  2120. char *buf,
  2121. int capacity);
  2122. /**
  2123. * Parse an endpoint as a string
  2124. *
  2125. * This will automatically detect IP addresses in IP/port format. If one
  2126. * of these is specified rather than a fully specified endpoint it will be
  2127. * parsed as an IP/UDP endpoint.
  2128. *
  2129. * @param ep Endpoint structure to populate
  2130. * @param str String representation of endpoint
  2131. * @return OK (0) or error code
  2132. */
  2133. ZT_SDK_API int ZT_Endpoint_fromString(
  2134. ZT_Endpoint *ep,
  2135. const char *str);
  2136. /* ---------------------------------------------------------------------------------------------------------------- */
  2137. /**
  2138. * Create and sign a new locator
  2139. *
  2140. * @param ts Locator timestamp
  2141. * @param endpoints List of endpoints to store in locator
  2142. * @param endpointCount Number of endpoints (maximum: 8)
  2143. * @param signer Identity to sign locator (must include private key)
  2144. * @return Locator or NULL on error (too many endpoints or identity does not have private key)
  2145. */
  2146. ZT_SDK_API ZT_Locator *ZT_Locator_create(
  2147. int64_t ts,
  2148. const ZT_Endpoint *endpoints,
  2149. unsigned int endpointCount,
  2150. const ZT_Identity *signer);
  2151. /**
  2152. * Decode a serialized locator
  2153. *
  2154. * @param data Data to deserialize
  2155. * @param len Length of data
  2156. * @return Locator or NULL if data is not valid
  2157. */
  2158. ZT_SDK_API ZT_Locator *ZT_Locator_unmarshal(
  2159. const void *data,
  2160. unsigned int len);
  2161. /**
  2162. * Decode a locator from string format
  2163. *
  2164. * @param str String format locator
  2165. * @return Locator or NULL if string is not valid
  2166. */
  2167. ZT_SDK_API ZT_Locator *ZT_Locator_fromString(const char *str);
  2168. /**
  2169. * Serialize this locator into a buffer
  2170. *
  2171. * @param loc Locator to serialize
  2172. * @param buf Buffer to store bytes
  2173. * @param bufSize Size of buffer in bytes (needs to be at least 2048 bytes in size)
  2174. * @return Number of bytes stored to buf or -1 on error such as buffer too small
  2175. */
  2176. ZT_SDK_API int ZT_Locator_marshal(const ZT_Locator *loc,void *buf,unsigned int bufSize);
  2177. /**
  2178. * Get this locator in string format
  2179. *
  2180. * @param loc Locator
  2181. * @param buf Buffer to store string
  2182. * @param capacity Capacity of buffer in bytes (recommended size: 4096)
  2183. * @return Pointer to buffer or NULL if an error occurs
  2184. */
  2185. ZT_SDK_API char *ZT_Locator_toString(
  2186. const ZT_Locator *loc,
  2187. char *buf,
  2188. int capacity);
  2189. /**
  2190. * Get a pointer to the fingerprint of this locator's signer.
  2191. *
  2192. * The returned pointer remains valid as long as the Locator is not deleted.
  2193. *
  2194. * @param loc Locator to query
  2195. * @return Pointer to fingerprint of signer
  2196. */
  2197. ZT_SDK_API const ZT_Fingerprint *ZT_Locator_fingerprint(const ZT_Locator *loc);
  2198. /**
  2199. * Get a locator's timestamp
  2200. *
  2201. * @param loc Locator to query
  2202. * @return Locator timestamp in milliseconds since epoch
  2203. */
  2204. ZT_SDK_API int64_t ZT_Locator_timestamp(const ZT_Locator *loc);
  2205. /**
  2206. * Get the number of endpoints in this locator
  2207. *
  2208. * @param loc Locator to query
  2209. * @return Number of endpoints
  2210. */
  2211. ZT_SDK_API unsigned int ZT_Locator_endpointCount(const ZT_Locator *loc);
  2212. /**
  2213. * Get a pointer to an endpoint in a locator
  2214. *
  2215. * The returned pointer remains valid as long as the Locator is not deleted.
  2216. *
  2217. * @param ep Endpoint number from 0 to 1 - endpointCount()
  2218. * @return Endpoint or NULL if out of bounds
  2219. */
  2220. ZT_SDK_API const ZT_Endpoint *ZT_Locator_endpoint(const ZT_Locator *loc,const unsigned int ep);
  2221. /**
  2222. * Verify this locator's signature
  2223. *
  2224. * @param signer Signing identity
  2225. * @return Non-zero if locator is valid
  2226. */
  2227. ZT_SDK_API int ZT_Locator_verify(const ZT_Locator *loc,const ZT_Identity *signer);
  2228. /**
  2229. * Delete a locator
  2230. *
  2231. * @param loc Locator to delete
  2232. */
  2233. ZT_SDK_API void ZT_Locator_delete(ZT_Locator *loc);
  2234. /* ---------------------------------------------------------------------------------------------------------------- */
  2235. /**
  2236. * Get ZeroTier One version
  2237. *
  2238. * @param major Result: major version
  2239. * @param minor Result: minor version
  2240. * @param revision Result: revision
  2241. * @param build Result: build number
  2242. */
  2243. ZT_SDK_API void ZT_version(
  2244. int *major,
  2245. int *minor,
  2246. int *revision,
  2247. int *build);
  2248. /* ---------------------------------------------------------------------------------------------------------------- */
  2249. #ifdef __cplusplus
  2250. }
  2251. #endif
  2252. #endif