ZeroTierCore.h 58 KB

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