zerotier.h 72 KB

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