ZeroTierOne.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  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 result buffer
  85. */
  86. struct ZT1_Node_PhysicalAddress
  87. {
  88. /**
  89. * Physical address type
  90. */
  91. enum {
  92. ZT1_Node_PhysicalAddress_TYPE_NULL = 0, /* none/invalid */
  93. ZT1_Node_PhysicalAddress_TYPE_IPV4 = 1, /* 32-bit IPv4 address (and port) */
  94. ZT1_Node_PhysicalAddress_TYPE_IPV6 = 2, /* 128-bit IPv6 address (and port) */
  95. ZT1_Node_PhysicalAddress_TYPE_ETHERNET = 3 /* 48-bit Ethernet MAC address */
  96. } type;
  97. /**
  98. * Address in raw binary form -- length depends on type
  99. */
  100. unsigned char bits[16];
  101. /**
  102. * Port or netmask bits (for IPV4 and IPV6)
  103. */
  104. unsigned int port;
  105. /**
  106. * Address in canonical human-readable form
  107. */
  108. char ascii[64];
  109. /**
  110. * Zone index identifier (thing after % on IPv6 link-local addresses only)
  111. */
  112. char zoneIndex[16];
  113. };
  114. /**
  115. * Network path result buffer
  116. */
  117. struct ZT1_Node_PhysicalPath
  118. {
  119. /**
  120. * Physical path type
  121. */
  122. enum { /* These must be numerically the same as type in Path.hpp */
  123. ZT1_Node_PhysicalPath_TYPE_NULL = 0, /* none/invalid */
  124. ZT1_Node_PhysicalPath_TYPE_UDP = 1, /* UDP association */
  125. ZT1_Node_PhysicalPath_TYPE_TCP_OUT = 2, /* outgoing TCP tunnel using pseudo-SSL */
  126. ZT1_Node_PhysicalPath_TYPE_TCP_IN = 3, /* incoming TCP tunnel using pseudo-SSL */
  127. ZT1_Node_PhysicalPath_TYPE_ETHERNET = 4 /* raw ethernet frames over trusted backplane */
  128. } type;
  129. /**
  130. * Physical address of endpoint
  131. */
  132. struct ZT1_Node_PhysicalAddress address;
  133. /**
  134. * Time since last send in milliseconds or -1 for never
  135. */
  136. long lastSend;
  137. /**
  138. * Time since last receive in milliseconds or -1 for never
  139. */
  140. long lastReceive;
  141. /**
  142. * Time since last ping in milliseconds or -1 for never
  143. */
  144. long lastPing;
  145. /**
  146. * Is path active/connected? Non-fixed active paths may be garbage collected over time.
  147. */
  148. bool active;
  149. /**
  150. * Is path fixed? (i.e. not learned, static)
  151. */
  152. bool fixed;
  153. };
  154. /**
  155. * Peer status result buffer
  156. */
  157. struct ZT1_Node_Peer
  158. {
  159. /**
  160. * Remote peer version: major.minor.revision (or empty if unknown)
  161. */
  162. char remoteVersion[16];
  163. /**
  164. * ZeroTier address of peer as 10-digit hex string
  165. */
  166. char address[16];
  167. /**
  168. * ZeroTier address in least significant 40 bits of 64-bit integer
  169. */
  170. uint64_t rawAddress;
  171. /**
  172. * Last measured latency in milliseconds or zero if unknown
  173. */
  174. unsigned int latency;
  175. /**
  176. * Array of network paths to peer
  177. */
  178. struct ZT1_Node_PhysicalPath *paths;
  179. /**
  180. * Number of paths (size of paths[])
  181. */
  182. unsigned int numPaths;
  183. };
  184. /**
  185. * List of peers
  186. */
  187. struct ZT1_Node_PeerList
  188. {
  189. struct ZT1_Node_Peer *peers;
  190. unsigned int numPeers;
  191. };
  192. /**
  193. * Network status result buffer
  194. */
  195. struct ZT1_Node_Network
  196. {
  197. /**
  198. * 64-bit network ID
  199. */
  200. uint64_t nwid;
  201. /**
  202. * 64-bit network ID in hex form
  203. */
  204. char nwidHex[32];
  205. /**
  206. * Short network name
  207. */
  208. char name[256];
  209. /**
  210. * Longer network description
  211. */
  212. char description[4096];
  213. /**
  214. * Device name (system-dependent)
  215. */
  216. char device[256];
  217. /**
  218. * Status code in string format
  219. */
  220. char statusStr[64];
  221. /**
  222. * Ethernet MAC address of this endpoint in string form
  223. */
  224. char macStr[32];
  225. /**
  226. * Ethernet MAC address of this endpoint on the network in raw binary form
  227. */
  228. unsigned char mac[6];
  229. /**
  230. * Age of configuration in milliseconds or -1 if never refreshed
  231. */
  232. long configAge;
  233. /**
  234. * Assigned layer-3 IPv4 and IPv6 addresses
  235. *
  236. * Note that PhysicalAddress also supports other address types, but this
  237. * list will only list IP address assignments. The port field will contain
  238. * the number of bits in the netmask -- e.g. 192.168.1.1/24.
  239. */
  240. struct ZT1_Node_PhysicalAddress *ips;
  241. /**
  242. * Number of layer-3 IPs (size of ips[])
  243. */
  244. unsigned int numIps;
  245. /**
  246. * Network status code
  247. */
  248. enum { /* Must be same as Status in Network.hpp */
  249. ZT1_Node_Network_INITIALIZING = 0,
  250. ZT1_Node_Network_WAITING_FOR_FIRST_AUTOCONF = 1,
  251. ZT1_Node_Network_OK = 2,
  252. ZT1_Node_Network_ACCESS_DENIED = 3,
  253. ZT1_Node_Network_NOT_FOUND = 4,
  254. ZT1_Node_Network_INITIALIZATION_FAILED = 5,
  255. ZT1_Node_Network_NO_MORE_DEVICES = 6
  256. } status;
  257. /**
  258. * True if traffic on network is enabled
  259. */
  260. bool enabled;
  261. /**
  262. * Is this a private network? If false, network lacks access control.
  263. */
  264. bool isPrivate;
  265. };
  266. /**
  267. * Return buffer for list of networks
  268. */
  269. struct ZT1_Node_NetworkList
  270. {
  271. struct ZT1_Node_Network *networks;
  272. unsigned int numNetworks;
  273. };
  274. /* ------------------------------------------------------------------------ */
  275. /* ZeroTier One C API */
  276. /* ------------------------------------------------------------------------ */
  277. /* coming soon... */
  278. #endif