zerotier.h 69 KB

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