ZeroTierOne.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. /*
  2. * ZeroTier One - Global Peer to Peer Ethernet
  3. * Copyright (C) 2011-2014 ZeroTier Networks LLC
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. * --
  19. *
  20. * ZeroTier may be used and distributed under the terms of the GPLv3, which
  21. * are available at: http://www.gnu.org/licenses/gpl-3.0.html
  22. *
  23. * If you would like to embed ZeroTier into a commercial application or
  24. * redistribute it in a modified binary form, please contact ZeroTier Networks
  25. * LLC. Start here: http://www.zerotier.com/
  26. */
  27. /*
  28. * This defines the external C API for ZeroTier One, the core network
  29. * virtualization engine.
  30. */
  31. #ifndef ZT_ZEROTIERONE_H
  32. #define ZT_ZEROTIERONE_H
  33. #include <stdint.h>
  34. /* ------------------------------------------------------------------------ */
  35. /* Query result buffers */
  36. /* ------------------------------------------------------------------------ */
  37. /**
  38. * Node status result buffer
  39. */
  40. struct ZT1_Node_Status
  41. {
  42. /**
  43. * Public identity in string form
  44. */
  45. char publicIdentity[256];
  46. /**
  47. * ZeroTier address in 10-digit hex form
  48. */
  49. char address[16];
  50. /**
  51. * ZeroTier address in least significant 40 bits of 64-bit integer
  52. */
  53. uint64_t rawAddress;
  54. /**
  55. * Number of known peers (including supernodes)
  56. */
  57. unsigned int knownPeers;
  58. /**
  59. * Number of upstream supernodes
  60. */
  61. unsigned int supernodes;
  62. /**
  63. * Number of peers with active direct links
  64. */
  65. unsigned int directlyConnectedPeers;
  66. /**
  67. * Number of peers that have recently communicated with us
  68. */
  69. unsigned int alivePeers;
  70. /**
  71. * Success rate at establishing direct links (0.0 to 1.0, approximate)
  72. */
  73. float directLinkSuccessRate;
  74. /**
  75. * True if connectivity appears good
  76. */
  77. bool online;
  78. /**
  79. * True if running; all other fields are technically undefined if this is false
  80. */
  81. bool running;
  82. };
  83. /**
  84. * Physical address type
  85. */
  86. enum ZT1_Node_PhysicalAddressType {
  87. ZT1_Node_PhysicalAddress_TYPE_NULL = 0, /* none/invalid */
  88. ZT1_Node_PhysicalAddress_TYPE_IPV4 = 1, /* 32-bit IPv4 address (and port) */
  89. ZT1_Node_PhysicalAddress_TYPE_IPV6 = 2, /* 128-bit IPv6 address (and port) */
  90. ZT1_Node_PhysicalAddress_TYPE_ETHERNET = 3 /* 48-bit Ethernet MAC address */
  91. };
  92. /**
  93. * Physical address result buffer
  94. */
  95. struct ZT1_Node_PhysicalAddress
  96. {
  97. /**
  98. * Physical address type
  99. */
  100. enum ZT1_Node_PhysicalAddressType type;
  101. /**
  102. * Address in raw binary form -- length depends on type
  103. */
  104. unsigned char bits[16];
  105. /**
  106. * Port or netmask bits (for IPV4 and IPV6)
  107. */
  108. unsigned int port;
  109. /**
  110. * Address in canonical human-readable form
  111. */
  112. char ascii[64];
  113. /**
  114. * Zone index identifier (thing after % on IPv6 link-local addresses only)
  115. */
  116. char zoneIndex[16];
  117. };
  118. /**
  119. * Physical path type
  120. */
  121. enum ZT1_Node_PhysicalPathType { /* These must be numerically the same as type in Path.hpp */
  122. ZT1_Node_PhysicalPath_TYPE_NULL = 0, /* none/invalid */
  123. ZT1_Node_PhysicalPath_TYPE_UDP = 1, /* UDP association */
  124. ZT1_Node_PhysicalPath_TYPE_TCP_OUT = 2, /* outgoing TCP tunnel using pseudo-SSL */
  125. ZT1_Node_PhysicalPath_TYPE_TCP_IN = 3, /* incoming TCP tunnel using pseudo-SSL */
  126. ZT1_Node_PhysicalPath_TYPE_ETHERNET = 4 /* raw ethernet frames over trusted backplane */
  127. };
  128. /**
  129. * Network path result buffer
  130. */
  131. struct ZT1_Node_PhysicalPath
  132. {
  133. /**
  134. * Physical path type
  135. */
  136. enum ZT1_Node_PhysicalPathType type;
  137. /**
  138. * Physical address of endpoint
  139. */
  140. struct ZT1_Node_PhysicalAddress address;
  141. /**
  142. * Time since last send in milliseconds or -1 for never
  143. */
  144. long lastSend;
  145. /**
  146. * Time since last receive in milliseconds or -1 for never
  147. */
  148. long lastReceive;
  149. /**
  150. * Time since last ping in milliseconds or -1 for never
  151. */
  152. long lastPing;
  153. /**
  154. * Is path active/connected? Non-fixed active paths may be garbage collected over time.
  155. */
  156. bool active;
  157. /**
  158. * Is path fixed? (i.e. not learned, static)
  159. */
  160. bool fixed;
  161. };
  162. /**
  163. * What trust hierarchy role does this device have?
  164. */
  165. enum ZT1_Node_PeerRole {
  166. ZT1_Node_Peer_SUPERNODE = 0, // planetary supernode
  167. ZT1_Node_Peer_HUB = 1, // locally federated hub (coming soon)
  168. ZT1_Node_Peer_NODE = 2 // ordinary node
  169. };
  170. /**
  171. * Peer status result buffer
  172. */
  173. struct ZT1_Node_Peer
  174. {
  175. /**
  176. * Remote peer version: major.minor.revision (or empty if unknown)
  177. */
  178. char remoteVersion[16];
  179. /**
  180. * ZeroTier address of peer as 10-digit hex string
  181. */
  182. char address[16];
  183. /**
  184. * ZeroTier address in least significant 40 bits of 64-bit integer
  185. */
  186. uint64_t rawAddress;
  187. /**
  188. * Last measured latency in milliseconds or zero if unknown
  189. */
  190. unsigned int latency;
  191. /**
  192. * What trust hierarchy role does this device have?
  193. */
  194. enum ZT1_Node_PeerRole role;
  195. /**
  196. * Array of network paths to peer
  197. */
  198. struct ZT1_Node_PhysicalPath *paths;
  199. /**
  200. * Number of paths (size of paths[])
  201. */
  202. unsigned int numPaths;
  203. };
  204. /**
  205. * List of peers
  206. */
  207. struct ZT1_Node_PeerList
  208. {
  209. struct ZT1_Node_Peer *peers;
  210. unsigned int numPeers;
  211. };
  212. /**
  213. * Network status code
  214. */
  215. enum ZT1_Node_NetworkStatus {
  216. ZT1_Node_Network_INITIALIZING = 0,
  217. ZT1_Node_Network_WAITING_FOR_FIRST_AUTOCONF = 1,
  218. ZT1_Node_Network_OK = 2,
  219. ZT1_Node_Network_ACCESS_DENIED = 3,
  220. ZT1_Node_Network_NOT_FOUND = 4,
  221. ZT1_Node_Network_INITIALIZATION_FAILED = 5,
  222. ZT1_Node_Network_NO_MORE_DEVICES = 6
  223. };
  224. /**
  225. * Network status result buffer
  226. */
  227. struct ZT1_Node_Network
  228. {
  229. /**
  230. * 64-bit network ID
  231. */
  232. uint64_t nwid;
  233. /**
  234. * 64-bit network ID in hex form
  235. */
  236. char nwidHex[32];
  237. /**
  238. * Short network name
  239. */
  240. char name[256];
  241. /**
  242. * Longer network description
  243. */
  244. char description[4096];
  245. /**
  246. * Device name (system-dependent)
  247. */
  248. char device[256];
  249. /**
  250. * Status code in string format
  251. */
  252. char statusStr[64];
  253. /**
  254. * Ethernet MAC address of this endpoint in string form
  255. */
  256. char macStr[32];
  257. /**
  258. * Ethernet MAC address of this endpoint on the network in raw binary form
  259. */
  260. unsigned char mac[6];
  261. /**
  262. * Age of configuration in milliseconds or -1 if never refreshed
  263. */
  264. long configAge;
  265. /**
  266. * Assigned layer-3 IPv4 and IPv6 addresses
  267. *
  268. * Note that PhysicalAddress also supports other address types, but this
  269. * list will only list IP address assignments. The port field will contain
  270. * the number of bits in the netmask -- e.g. 192.168.1.1/24.
  271. */
  272. struct ZT1_Node_PhysicalAddress *ips;
  273. /**
  274. * Number of layer-3 IPs (size of ips[])
  275. */
  276. unsigned int numIps;
  277. /**
  278. * Network status code
  279. */
  280. enum ZT1_Node_NetworkStatus status;
  281. /**
  282. * True if traffic on network is enabled
  283. */
  284. bool enabled;
  285. /**
  286. * Is this a private network? If false, network lacks access control.
  287. */
  288. bool isPrivate;
  289. };
  290. /**
  291. * Return buffer for list of networks
  292. */
  293. struct ZT1_Node_NetworkList
  294. {
  295. struct ZT1_Node_Network *networks;
  296. unsigned int numNetworks;
  297. };
  298. /* ------------------------------------------------------------------------ */
  299. /* ZeroTier One C API */
  300. /* ------------------------------------------------------------------------ */
  301. /* coming soon... */
  302. #endif