Node.cpp 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036
  1. /*
  2. * Copyright (c)2019 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: 2023-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. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include <stdarg.h>
  16. #include <string.h>
  17. #include <stdint.h>
  18. #include "Constants.hpp"
  19. #include "SharedPtr.hpp"
  20. #include "Node.hpp"
  21. #include "RuntimeEnvironment.hpp"
  22. #include "NetworkController.hpp"
  23. #include "Switch.hpp"
  24. #include "Multicaster.hpp"
  25. #include "Topology.hpp"
  26. #include "Buffer.hpp"
  27. #include "Packet.hpp"
  28. #include "Address.hpp"
  29. #include "Identity.hpp"
  30. #include "SelfAwareness.hpp"
  31. #include "Network.hpp"
  32. #include "Trace.hpp"
  33. #include "ScopedPtr.hpp"
  34. #include "Locator.hpp"
  35. namespace ZeroTier {
  36. /****************************************************************************/
  37. /* Public Node interface (C++, exposed via CAPI bindings) */
  38. /****************************************************************************/
  39. Node::Node(void *uptr,void *tptr,const struct ZT_Node_Callbacks *callbacks,int64_t now) :
  40. _RR(this),
  41. RR(&_RR),
  42. _uPtr(uptr),
  43. _networks(8),
  44. _now(now),
  45. _lastPing(0),
  46. _lastHousekeepingRun(0),
  47. _lastNetworkHousekeepingRun(0),
  48. _lastDynamicRootUpdate(0),
  49. _online(false)
  50. {
  51. memcpy(&_cb,callbacks,sizeof(ZT_Node_Callbacks));
  52. memset(_expectingRepliesToBucketPtr,0,sizeof(_expectingRepliesToBucketPtr));
  53. memset(_expectingRepliesTo,0,sizeof(_expectingRepliesTo));
  54. memset(_lastIdentityVerification,0,sizeof(_lastIdentityVerification));
  55. uint64_t idtmp[2];
  56. idtmp[0] = 0; idtmp[1] = 0;
  57. char tmp[2048];
  58. int n = stateObjectGet(tptr,ZT_STATE_OBJECT_IDENTITY_SECRET,idtmp,tmp,sizeof(tmp) - 1);
  59. if (n > 0) {
  60. tmp[n] = (char)0;
  61. if (RR->identity.fromString(tmp)) {
  62. RR->identity.toString(false,RR->publicIdentityStr);
  63. RR->identity.toString(true,RR->secretIdentityStr);
  64. } else {
  65. n = -1;
  66. }
  67. }
  68. if (n <= 0) {
  69. RR->identity.generate(Identity::C25519);
  70. RR->identity.toString(false,RR->publicIdentityStr);
  71. RR->identity.toString(true,RR->secretIdentityStr);
  72. idtmp[0] = RR->identity.address().toInt(); idtmp[1] = 0;
  73. stateObjectPut(tptr,ZT_STATE_OBJECT_IDENTITY_SECRET,idtmp,RR->secretIdentityStr,(unsigned int)strlen(RR->secretIdentityStr));
  74. stateObjectPut(tptr,ZT_STATE_OBJECT_IDENTITY_PUBLIC,idtmp,RR->publicIdentityStr,(unsigned int)strlen(RR->publicIdentityStr));
  75. } else {
  76. idtmp[0] = RR->identity.address().toInt(); idtmp[1] = 0;
  77. n = stateObjectGet(tptr,ZT_STATE_OBJECT_IDENTITY_PUBLIC,idtmp,tmp,sizeof(tmp) - 1);
  78. if ((n > 0)&&(n < (int)sizeof(RR->publicIdentityStr))&&(n < (int)sizeof(tmp))) {
  79. if (memcmp(tmp,RR->publicIdentityStr,n))
  80. stateObjectPut(tptr,ZT_STATE_OBJECT_IDENTITY_PUBLIC,idtmp,RR->publicIdentityStr,(unsigned int)strlen(RR->publicIdentityStr));
  81. }
  82. }
  83. char *m = (char *)0;
  84. try {
  85. const unsigned long ts = sizeof(Trace) + (((sizeof(Trace) & 0xf) != 0) ? (16 - (sizeof(Trace) & 0xf)) : 0);
  86. const unsigned long sws = sizeof(Switch) + (((sizeof(Switch) & 0xf) != 0) ? (16 - (sizeof(Switch) & 0xf)) : 0);
  87. const unsigned long mcs = sizeof(Multicaster) + (((sizeof(Multicaster) & 0xf) != 0) ? (16 - (sizeof(Multicaster) & 0xf)) : 0);
  88. const unsigned long topologys = sizeof(Topology) + (((sizeof(Topology) & 0xf) != 0) ? (16 - (sizeof(Topology) & 0xf)) : 0);
  89. const unsigned long sas = sizeof(SelfAwareness) + (((sizeof(SelfAwareness) & 0xf) != 0) ? (16 - (sizeof(SelfAwareness) & 0xf)) : 0);
  90. m = reinterpret_cast<char *>(::malloc(16 + ts + sws + mcs + topologys + sas));
  91. if (!m)
  92. throw std::bad_alloc();
  93. RR->rtmem = m;
  94. while (((uintptr_t)m & 0xf) != 0) ++m;
  95. RR->t = new (m) Trace(RR);
  96. m += ts;
  97. RR->sw = new (m) Switch(RR);
  98. m += sws;
  99. RR->mc = new (m) Multicaster(RR);
  100. m += mcs;
  101. RR->topology = new (m) Topology(RR,RR->identity);
  102. m += topologys;
  103. RR->sa = new (m) SelfAwareness(RR);
  104. } catch ( ... ) {
  105. if (RR->sa) RR->sa->~SelfAwareness();
  106. if (RR->topology) RR->topology->~Topology();
  107. if (RR->mc) RR->mc->~Multicaster();
  108. if (RR->sw) RR->sw->~Switch();
  109. if (RR->t) RR->t->~Trace();
  110. ::free(m);
  111. throw;
  112. }
  113. postEvent(tptr,ZT_EVENT_UP);
  114. }
  115. Node::~Node()
  116. {
  117. {
  118. Mutex::Lock _l(_networks_m);
  119. _networks.clear(); // destroy all networks before shutdown
  120. }
  121. if (RR->sa) RR->sa->~SelfAwareness();
  122. if (RR->topology) RR->topology->~Topology();
  123. if (RR->mc) RR->mc->~Multicaster();
  124. if (RR->sw) RR->sw->~Switch();
  125. if (RR->t) RR->t->~Trace();
  126. ::free(RR->rtmem);
  127. }
  128. ZT_ResultCode Node::processWirePacket(
  129. void *tptr,
  130. int64_t now,
  131. int64_t localSocket,
  132. const struct sockaddr_storage *remoteAddress,
  133. const void *packetData,
  134. unsigned int packetLength,
  135. volatile int64_t *nextBackgroundTaskDeadline)
  136. {
  137. _now = now;
  138. RR->sw->onRemotePacket(tptr,localSocket,*(reinterpret_cast<const InetAddress *>(remoteAddress)),packetData,packetLength);
  139. return ZT_RESULT_OK;
  140. }
  141. ZT_ResultCode Node::processVirtualNetworkFrame(
  142. void *tptr,
  143. int64_t now,
  144. uint64_t nwid,
  145. uint64_t sourceMac,
  146. uint64_t destMac,
  147. unsigned int etherType,
  148. unsigned int vlanId,
  149. const void *frameData,
  150. unsigned int frameLength,
  151. volatile int64_t *nextBackgroundTaskDeadline)
  152. {
  153. _now = now;
  154. SharedPtr<Network> nw(this->network(nwid));
  155. if (nw) {
  156. RR->sw->onLocalEthernet(tptr,nw,MAC(sourceMac),MAC(destMac),etherType,vlanId,frameData,frameLength);
  157. return ZT_RESULT_OK;
  158. } else {
  159. return ZT_RESULT_ERROR_NETWORK_NOT_FOUND;
  160. }
  161. }
  162. // This is passed as the argument to the DNS request handler and
  163. // aggregates results.
  164. struct _processBackgroundTasks_dnsResultAccumulator
  165. {
  166. _processBackgroundTasks_dnsResultAccumulator(const Str &n) : dnsName(n) {}
  167. Str dnsName;
  168. std::vector<Str> txtRecords;
  169. };
  170. static const ZT_DNSRecordType s_txtRecordType[1] = { ZT_DNS_RECORD_TXT };
  171. struct _processBackgroundTasks_eachRootName
  172. {
  173. ZT_Node_Callbacks *cb;
  174. Node *n;
  175. void *uPtr;
  176. void *tPtr;
  177. bool updateAll;
  178. ZT_ALWAYS_INLINE bool operator()(const Str &dnsName,const Locator &loc)
  179. {
  180. if ((strchr(dnsName.c_str(),'.'))&&((updateAll)||(!loc))) {
  181. _processBackgroundTasks_dnsResultAccumulator *dnsReq = new _processBackgroundTasks_dnsResultAccumulator(dnsName);
  182. cb->dnsResolver(reinterpret_cast<ZT_Node *>(n),uPtr,tPtr,s_txtRecordType,1,dnsName.c_str(),(uintptr_t)dnsReq);
  183. }
  184. return true;
  185. }
  186. };
  187. struct _processBackgroundTasks_ping_eachRoot
  188. {
  189. Hashtable< void *,bool > roots;
  190. int64_t now;
  191. void *tPtr;
  192. bool online;
  193. ZT_ALWAYS_INLINE bool operator()(const SharedPtr<Peer> &peer,const std::vector<InetAddress> &addrs)
  194. {
  195. unsigned int v4SendCount = 0,v6SendCount = 0;
  196. peer->ping(tPtr,now,v4SendCount,v6SendCount);
  197. for(std::vector<InetAddress>::const_iterator a(addrs.begin());a!=addrs.end();++a) {
  198. if ( ((a->isV4())&&(v4SendCount == 0)) || ((a->isV6())&&(v6SendCount == 0)) )
  199. peer->sendHELLO(tPtr,-1,*a,now);
  200. }
  201. if (!online)
  202. online = ((now - peer->lastReceive()) <= ((ZT_PEER_PING_PERIOD * 2) + 5000));
  203. roots.set((void *)peer.ptr(),true);
  204. return true;
  205. }
  206. };
  207. struct _processBackgroundTasks_ping_eachPeer
  208. {
  209. int64_t now;
  210. void *tPtr;
  211. Hashtable< void *,bool > *roots;
  212. ZT_ALWAYS_INLINE bool operator()(const SharedPtr<Peer> &peer)
  213. {
  214. if (!roots->contains((void *)peer.ptr())) {
  215. unsigned int v4SendCount = 0,v6SendCount = 0;
  216. peer->ping(tPtr,now,v4SendCount,v6SendCount);
  217. }
  218. return true;
  219. }
  220. };
  221. ZT_ResultCode Node::processBackgroundTasks(void *tptr,int64_t now,volatile int64_t *nextBackgroundTaskDeadline)
  222. {
  223. _now = now;
  224. Mutex::Lock bl(_backgroundTasksLock);
  225. // Initialize these on first call so these things happen just a few seconds after
  226. // startup, since right at startup things are likely to not be ready to communicate
  227. // at all yet.
  228. if (_lastNetworkHousekeepingRun <= 0)
  229. _lastNetworkHousekeepingRun = now - (ZT_NETWORK_HOUSEKEEPING_PERIOD / 3);
  230. if (_lastHousekeepingRun <= 0)
  231. _lastHousekeepingRun = now;
  232. if ((now - _lastPing) >= ZT_PEER_PING_PERIOD) {
  233. _lastPing = now;
  234. try {
  235. // Periodically refresh locators for dynamic roots from their DNS names.
  236. if (_cb.dnsResolver) {
  237. _processBackgroundTasks_eachRootName cr;
  238. cr.cb = &_cb;
  239. cr.n = this;
  240. cr.uPtr = _uPtr;
  241. cr.tPtr = tptr;
  242. if ((now - _lastDynamicRootUpdate) >= ZT_DYNAMIC_ROOT_UPDATE_PERIOD) {
  243. _lastDynamicRootUpdate = now;
  244. cr.updateAll = true;
  245. } else {
  246. cr.updateAll = false;
  247. }
  248. RR->topology->eachRootName(cr);
  249. }
  250. // Ping each root explicitly no matter what
  251. _processBackgroundTasks_ping_eachRoot rf;
  252. rf.now = now;
  253. rf.tPtr = tptr;
  254. rf.online = false;
  255. RR->topology->eachRoot(rf);
  256. // Ping peers that are active and we want to keep alive
  257. _processBackgroundTasks_ping_eachPeer pf;
  258. pf.now = now;
  259. pf.tPtr = tptr;
  260. pf.roots = &rf.roots;
  261. RR->topology->eachPeer(pf);
  262. // Update online status based on whether we can reach a root
  263. if (rf.online != _online) {
  264. _online = rf.online;
  265. postEvent(tptr,_online ? ZT_EVENT_ONLINE : ZT_EVENT_OFFLINE);
  266. }
  267. } catch ( ... ) {
  268. return ZT_RESULT_FATAL_ERROR_INTERNAL;
  269. }
  270. }
  271. if ((now - _lastNetworkHousekeepingRun) >= ZT_NETWORK_HOUSEKEEPING_PERIOD) {
  272. _lastHousekeepingRun = now;
  273. {
  274. Mutex::Lock l(_networks_m);
  275. Hashtable< uint64_t,SharedPtr<Network> >::Iterator i(_networks);
  276. uint64_t *nwid = (uint64_t *)0;
  277. SharedPtr<Network> *network = (SharedPtr<Network> *)0;
  278. while (i.next(nwid,network)) {
  279. (*network)->doPeriodicTasks(tptr,now);
  280. }
  281. }
  282. RR->t->updateMemoizedSettings();
  283. }
  284. if ((now - _lastHousekeepingRun) >= ZT_HOUSEKEEPING_PERIOD) {
  285. _lastHousekeepingRun = now;
  286. try {
  287. // Clean up any old local controller auth memoizations. This is an
  288. // optimization for network controllers to know whether to accept
  289. // or trust nodes without doing an extra cert check.
  290. {
  291. _localControllerAuthorizations_m.lock();
  292. Hashtable< _LocalControllerAuth,int64_t >::Iterator i(_localControllerAuthorizations);
  293. _LocalControllerAuth *k = (_LocalControllerAuth *)0;
  294. int64_t *v = (int64_t *)0;
  295. while (i.next(k,v)) {
  296. if ((*v - now) > (ZT_NETWORK_AUTOCONF_DELAY * 3)) {
  297. _localControllerAuthorizations.erase(*k);
  298. }
  299. }
  300. _localControllerAuthorizations_m.unlock();
  301. }
  302. RR->topology->doPeriodicTasks(now);
  303. RR->sa->clean(now);
  304. RR->mc->clean(now);
  305. } catch ( ... ) {
  306. return ZT_RESULT_FATAL_ERROR_INTERNAL;
  307. }
  308. }
  309. try {
  310. *nextBackgroundTaskDeadline = now + (int64_t)std::max(std::min((unsigned long)ZT_MAX_TIMER_TASK_INTERVAL,RR->sw->doTimerTasks(tptr,now)),(unsigned long)ZT_MIN_TIMER_TASK_INTERVAL);
  311. } catch ( ... ) {
  312. return ZT_RESULT_FATAL_ERROR_INTERNAL;
  313. }
  314. return ZT_RESULT_OK;
  315. }
  316. void Node::processDNSResult(
  317. void *tptr,
  318. uintptr_t dnsRequestID,
  319. const char *name,
  320. enum ZT_DNSRecordType recordType,
  321. const void *result,
  322. unsigned int resultLength,
  323. int resultIsString)
  324. {
  325. if (dnsRequestID) {
  326. _processBackgroundTasks_dnsResultAccumulator *const acc = reinterpret_cast<_processBackgroundTasks_dnsResultAccumulator *>(dnsRequestID);
  327. if (recordType == ZT_DNS_RECORD_TXT) {
  328. if (result)
  329. acc->txtRecords.emplace_back(reinterpret_cast<const char *>(result));
  330. } else if (recordType == ZT_DNS_RECORD__END_OF_RESULTS) {
  331. Locator loc;
  332. if (loc.decodeTxtRecords(acc->dnsName,acc->txtRecords.begin(),acc->txtRecords.end())) {
  333. RR->topology->setRoot(acc->dnsName,loc);
  334. delete acc;
  335. }
  336. }
  337. }
  338. }
  339. ZT_ResultCode Node::join(uint64_t nwid,void *uptr,void *tptr)
  340. {
  341. Mutex::Lock _l(_networks_m);
  342. SharedPtr<Network> &nw = _networks[nwid];
  343. if (!nw)
  344. nw = SharedPtr<Network>(new Network(RR,tptr,nwid,uptr,(const NetworkConfig *)0));
  345. return ZT_RESULT_OK;
  346. }
  347. ZT_ResultCode Node::leave(uint64_t nwid,void **uptr,void *tptr)
  348. {
  349. ZT_VirtualNetworkConfig ctmp;
  350. void **nUserPtr = (void **)0;
  351. {
  352. Mutex::Lock _l(_networks_m);
  353. SharedPtr<Network> *nw = _networks.get(nwid);
  354. RR->sw->removeNetworkQoSControlBlock(nwid);
  355. if (!nw)
  356. return ZT_RESULT_OK;
  357. if (uptr)
  358. *uptr = (*nw)->userPtr();
  359. (*nw)->externalConfig(&ctmp);
  360. (*nw)->destroy();
  361. nUserPtr = (*nw)->userPtr();
  362. }
  363. if (nUserPtr)
  364. RR->node->configureVirtualNetworkPort(tptr,nwid,nUserPtr,ZT_VIRTUAL_NETWORK_CONFIG_OPERATION_DESTROY,&ctmp);
  365. {
  366. Mutex::Lock _l(_networks_m);
  367. _networks.erase(nwid);
  368. }
  369. uint64_t tmp[2];
  370. tmp[0] = nwid; tmp[1] = 0;
  371. RR->node->stateObjectDelete(tptr,ZT_STATE_OBJECT_NETWORK_CONFIG,tmp);
  372. return ZT_RESULT_OK;
  373. }
  374. ZT_ResultCode Node::multicastSubscribe(void *tptr,uint64_t nwid,uint64_t multicastGroup,unsigned long multicastAdi)
  375. {
  376. SharedPtr<Network> nw(this->network(nwid));
  377. if (nw) {
  378. nw->multicastSubscribe(tptr,MulticastGroup(MAC(multicastGroup),(uint32_t)(multicastAdi & 0xffffffff)));
  379. return ZT_RESULT_OK;
  380. } else return ZT_RESULT_ERROR_NETWORK_NOT_FOUND;
  381. }
  382. ZT_ResultCode Node::multicastUnsubscribe(uint64_t nwid,uint64_t multicastGroup,unsigned long multicastAdi)
  383. {
  384. SharedPtr<Network> nw(this->network(nwid));
  385. if (nw) {
  386. nw->multicastUnsubscribe(MulticastGroup(MAC(multicastGroup),(uint32_t)(multicastAdi & 0xffffffff)));
  387. return ZT_RESULT_OK;
  388. } else return ZT_RESULT_ERROR_NETWORK_NOT_FOUND;
  389. }
  390. ZT_RootList *Node::listRoots(int64_t now)
  391. {
  392. return RR->topology->apiRoots(now);
  393. }
  394. enum ZT_ResultCode Node::setRoot(const char *name,const void *locator,unsigned int locatorSize)
  395. {
  396. try {
  397. Locator loc;
  398. if ((locator)&&(locatorSize > 0)&&(locatorSize < 65535)) {
  399. ScopedPtr< Buffer<65536> > locbuf(new Buffer<65536>());
  400. locbuf->append(locator,locatorSize);
  401. loc.deserialize(*locbuf,0);
  402. if (!loc.verify())
  403. return ZT_RESULT_ERROR_BAD_PARAMETER;
  404. }
  405. Str n;
  406. if ((!name)||(strlen(name) == 0)) {
  407. if (!loc)
  408. return ZT_RESULT_ERROR_BAD_PARAMETER; /* no name and no locator */
  409. char tmp[16];
  410. loc.id().address().toString(tmp);
  411. n = tmp;
  412. } else {
  413. n = name;
  414. }
  415. return RR->topology->setRoot(n,loc) ? ZT_RESULT_OK : ZT_RESULT_OK_IGNORED;
  416. } catch ( ... ) {
  417. return ZT_RESULT_ERROR_BAD_PARAMETER;
  418. }
  419. }
  420. enum ZT_ResultCode Node::removeRoot(const char *name)
  421. {
  422. try {
  423. if (name)
  424. RR->topology->removeRoot(Str(name));
  425. } catch ( ... ) {}
  426. return ZT_RESULT_OK;
  427. }
  428. uint64_t Node::address() const
  429. {
  430. return RR->identity.address().toInt();
  431. }
  432. void Node::status(ZT_NodeStatus *status) const
  433. {
  434. status->address = RR->identity.address().toInt();
  435. status->publicIdentity = RR->publicIdentityStr;
  436. status->secretIdentity = RR->secretIdentityStr;
  437. status->online = _online ? 1 : 0;
  438. }
  439. struct _sortPeerPtrsByAddress { inline bool operator()(const SharedPtr<Peer> &a,const SharedPtr<Peer> &b) const { return (a->address() < b->address()); } };
  440. ZT_PeerList *Node::peers() const
  441. {
  442. std::vector< SharedPtr<Peer> > peers;
  443. RR->topology->getAllPeers(peers);
  444. std::sort(peers.begin(),peers.end(),_sortPeerPtrsByAddress());
  445. char *buf = (char *)::malloc(sizeof(ZT_PeerList) + (sizeof(ZT_Peer) * peers.size()));
  446. if (!buf)
  447. return (ZT_PeerList *)0;
  448. ZT_PeerList *pl = (ZT_PeerList *)buf;
  449. pl->peers = (ZT_Peer *)(buf + sizeof(ZT_PeerList));
  450. pl->peerCount = 0;
  451. for(std::vector< SharedPtr<Peer> >::iterator pi(peers.begin());pi!=peers.end();++pi) {
  452. ZT_Peer *p = &(pl->peers[pl->peerCount++]);
  453. p->address = (*pi)->address().toInt();
  454. p->hadAggregateLink = 0;
  455. if ((*pi)->remoteVersionKnown()) {
  456. p->versionMajor = (*pi)->remoteVersionMajor();
  457. p->versionMinor = (*pi)->remoteVersionMinor();
  458. p->versionRev = (*pi)->remoteVersionRevision();
  459. } else {
  460. p->versionMajor = -1;
  461. p->versionMinor = -1;
  462. p->versionRev = -1;
  463. }
  464. p->latency = (*pi)->latency(_now);
  465. if (p->latency >= 0xffff)
  466. p->latency = -1;
  467. p->role = RR->topology->isRoot((*pi)->identity()) ? ZT_PEER_ROLE_PLANET : ZT_PEER_ROLE_LEAF;
  468. const int64_t now = _now;
  469. std::vector< SharedPtr<Path> > paths((*pi)->paths(_now));
  470. SharedPtr<Path> bestp((*pi)->getAppropriatePath(_now,false));
  471. p->hadAggregateLink |= (*pi)->hasAggregateLink();
  472. p->pathCount = 0;
  473. for(std::vector< SharedPtr<Path> >::iterator path(paths.begin());path!=paths.end();++path) {
  474. memcpy(&(p->paths[p->pathCount].address),&((*path)->address()),sizeof(struct sockaddr_storage));
  475. p->paths[p->pathCount].lastSend = (*path)->lastOut();
  476. p->paths[p->pathCount].lastReceive = (*path)->lastIn();
  477. p->paths[p->pathCount].trustedPathId = RR->topology->getOutboundPathTrust((*path)->address());
  478. p->paths[p->pathCount].alive = (*path)->alive(now) ? 1 : 0;
  479. p->paths[p->pathCount].preferred = ((*path) == bestp) ? 1 : 0;
  480. p->paths[p->pathCount].latency = (float)(*path)->latency();
  481. p->paths[p->pathCount].packetDelayVariance = (*path)->packetDelayVariance();
  482. p->paths[p->pathCount].throughputDisturbCoeff = (*path)->throughputDisturbanceCoefficient();
  483. p->paths[p->pathCount].packetErrorRatio = (*path)->packetErrorRatio();
  484. p->paths[p->pathCount].packetLossRatio = (*path)->packetLossRatio();
  485. p->paths[p->pathCount].stability = (*path)->lastComputedStability();
  486. p->paths[p->pathCount].throughput = (*path)->meanThroughput();
  487. p->paths[p->pathCount].maxThroughput = (*path)->maxLifetimeThroughput();
  488. p->paths[p->pathCount].allocation = (float)(*path)->allocation() / (float)255;
  489. p->paths[p->pathCount].ifname = (*path)->getName();
  490. ++p->pathCount;
  491. }
  492. }
  493. return pl;
  494. }
  495. ZT_VirtualNetworkConfig *Node::networkConfig(uint64_t nwid) const
  496. {
  497. Mutex::Lock _l(_networks_m);
  498. const SharedPtr<Network> *nw = _networks.get(nwid);
  499. if (nw) {
  500. ZT_VirtualNetworkConfig *nc = (ZT_VirtualNetworkConfig *)::malloc(sizeof(ZT_VirtualNetworkConfig));
  501. (*nw)->externalConfig(nc);
  502. return nc;
  503. }
  504. return (ZT_VirtualNetworkConfig *)0;
  505. }
  506. ZT_VirtualNetworkList *Node::networks() const
  507. {
  508. Mutex::Lock _l(_networks_m);
  509. char *buf = (char *)::malloc(sizeof(ZT_VirtualNetworkList) + (sizeof(ZT_VirtualNetworkConfig) * _networks.size()));
  510. if (!buf)
  511. return (ZT_VirtualNetworkList *)0;
  512. ZT_VirtualNetworkList *nl = (ZT_VirtualNetworkList *)buf;
  513. nl->networks = (ZT_VirtualNetworkConfig *)(buf + sizeof(ZT_VirtualNetworkList));
  514. nl->networkCount = 0;
  515. Hashtable< uint64_t,SharedPtr<Network> >::Iterator i(*const_cast< Hashtable< uint64_t,SharedPtr<Network> > *>(&_networks));
  516. uint64_t *k = (uint64_t *)0;
  517. SharedPtr<Network> *v = (SharedPtr<Network> *)0;
  518. while (i.next(k,v))
  519. (*v)->externalConfig(&(nl->networks[nl->networkCount++]));
  520. return nl;
  521. }
  522. void Node::setNetworkUserPtr(uint64_t nwid,void *ptr)
  523. {
  524. Mutex::Lock _l(_networks_m);
  525. const SharedPtr<Network> *const nw = _networks.get(nwid);
  526. if (nw)
  527. *((*nw)->userPtr()) = ptr;
  528. }
  529. void Node::freeQueryResult(void *qr)
  530. {
  531. if (qr)
  532. ::free(qr);
  533. }
  534. void Node::setInterfaceAddresses(const ZT_InterfaceAddress *addrs,unsigned int addrCount)
  535. {
  536. Mutex::Lock _l(_localInterfaceAddresses_m);
  537. _localInterfaceAddresses.clear();
  538. for(unsigned int i=0;i<addrCount;++i) {
  539. if (Path::isAddressValidForPath(*(reinterpret_cast<const InetAddress *>(&addrs[i].address)))) {
  540. bool dupe = false;
  541. for(unsigned int j=0;j<i;++j) {
  542. if (*(reinterpret_cast<const InetAddress *>(&addrs[j].address)) == *(reinterpret_cast<const InetAddress *>(&addrs[i].address))) {
  543. dupe = true;
  544. break;
  545. }
  546. }
  547. if (!dupe)
  548. _localInterfaceAddresses.push_back(addrs[i]);
  549. }
  550. }
  551. }
  552. int Node::sendUserMessage(void *tptr,uint64_t dest,uint64_t typeId,const void *data,unsigned int len)
  553. {
  554. try {
  555. if (RR->identity.address().toInt() != dest) {
  556. Packet outp(Address(dest),RR->identity.address(),Packet::VERB_USER_MESSAGE);
  557. outp.append(typeId);
  558. outp.append(data,len);
  559. outp.compress();
  560. RR->sw->send(tptr,outp,true);
  561. return 1;
  562. }
  563. } catch ( ... ) {}
  564. return 0;
  565. }
  566. void Node::setController(void *networkControllerInstance)
  567. {
  568. RR->localNetworkController = reinterpret_cast<NetworkController *>(networkControllerInstance);
  569. if (networkControllerInstance)
  570. RR->localNetworkController->init(RR->identity,this);
  571. }
  572. /****************************************************************************/
  573. /* Node methods used only within node/ */
  574. /****************************************************************************/
  575. bool Node::shouldUsePathForZeroTierTraffic(void *tPtr,const Address &ztaddr,const int64_t localSocket,const InetAddress &remoteAddress)
  576. {
  577. if (!Path::isAddressValidForPath(remoteAddress))
  578. return false;
  579. {
  580. Mutex::Lock _l(_networks_m);
  581. Hashtable< uint64_t,SharedPtr<Network> >::Iterator i(_networks);
  582. uint64_t *k = (uint64_t *)0;
  583. SharedPtr<Network> *v = (SharedPtr<Network> *)0;
  584. while (i.next(k,v)) {
  585. if ((*v)->hasConfig()) {
  586. for(unsigned int k=0;k<(*v)->config().staticIpCount;++k) {
  587. if ((*v)->config().staticIps[k].containsAddress(remoteAddress))
  588. return false;
  589. }
  590. }
  591. }
  592. }
  593. return ( (_cb.pathCheckFunction) ? (_cb.pathCheckFunction(reinterpret_cast<ZT_Node *>(this),_uPtr,tPtr,ztaddr.toInt(),localSocket,reinterpret_cast<const struct sockaddr_storage *>(&remoteAddress)) != 0) : true);
  594. }
  595. ZT_ResultCode Node::setPhysicalPathConfiguration(const struct sockaddr_storage *pathNetwork, const ZT_PhysicalPathConfiguration *pathConfig)
  596. {
  597. RR->topology->setPhysicalPathConfiguration(pathNetwork,pathConfig);
  598. return ZT_RESULT_OK;
  599. }
  600. void Node::ncSendConfig(uint64_t nwid,uint64_t requestPacketId,const Address &destination,const NetworkConfig &nc,bool sendLegacyFormatConfig)
  601. {
  602. _localControllerAuthorizations_m.lock();
  603. _localControllerAuthorizations[_LocalControllerAuth(nwid,destination)] = now();
  604. _localControllerAuthorizations_m.unlock();
  605. if (destination == RR->identity.address()) {
  606. SharedPtr<Network> n(network(nwid));
  607. if (!n) return;
  608. n->setConfiguration((void *)0,nc,true);
  609. } else {
  610. ScopedPtr< Dictionary<ZT_NETWORKCONFIG_DICT_CAPACITY> > dconf(new Dictionary<ZT_NETWORKCONFIG_DICT_CAPACITY>());
  611. if (nc.toDictionary(*dconf,sendLegacyFormatConfig)) {
  612. uint64_t configUpdateId = Utils::random();
  613. if (!configUpdateId) ++configUpdateId;
  614. const unsigned int totalSize = dconf->sizeBytes();
  615. unsigned int chunkIndex = 0;
  616. while (chunkIndex < totalSize) {
  617. const unsigned int chunkLen = std::min(totalSize - chunkIndex,(unsigned int)(ZT_PROTO_MAX_PACKET_LENGTH - (ZT_PACKET_IDX_PAYLOAD + 256)));
  618. Packet outp(destination,RR->identity.address(),(requestPacketId) ? Packet::VERB_OK : Packet::VERB_NETWORK_CONFIG);
  619. if (requestPacketId) {
  620. outp.append((unsigned char)Packet::VERB_NETWORK_CONFIG_REQUEST);
  621. outp.append(requestPacketId);
  622. }
  623. const unsigned int sigStart = outp.size();
  624. outp.append(nwid);
  625. outp.append((uint16_t)chunkLen);
  626. outp.append((const void *)(dconf->data() + chunkIndex),chunkLen);
  627. outp.append((uint8_t)0); // no flags
  628. outp.append((uint64_t)configUpdateId);
  629. outp.append((uint32_t)totalSize);
  630. outp.append((uint32_t)chunkIndex);
  631. uint8_t sig[256];
  632. const unsigned int siglen = RR->identity.sign(reinterpret_cast<const uint8_t *>(outp.data()) + sigStart,outp.size() - sigStart,sig,sizeof(sig));
  633. outp.append((uint8_t)1);
  634. outp.append((uint16_t)siglen);
  635. outp.append(sig,siglen);
  636. outp.compress();
  637. RR->sw->send((void *)0,outp,true);
  638. chunkIndex += chunkLen;
  639. }
  640. }
  641. }
  642. }
  643. void Node::ncSendRevocation(const Address &destination,const Revocation &rev)
  644. {
  645. if (destination == RR->identity.address()) {
  646. SharedPtr<Network> n(network(rev.networkId()));
  647. if (!n) return;
  648. n->addCredential((void *)0,RR->identity.address(),rev);
  649. } else {
  650. Packet outp(destination,RR->identity.address(),Packet::VERB_NETWORK_CREDENTIALS);
  651. outp.append((uint8_t)0x00);
  652. outp.append((uint16_t)0);
  653. outp.append((uint16_t)0);
  654. outp.append((uint16_t)1);
  655. rev.serialize(outp);
  656. outp.append((uint16_t)0);
  657. RR->sw->send((void *)0,outp,true);
  658. }
  659. }
  660. void Node::ncSendError(uint64_t nwid,uint64_t requestPacketId,const Address &destination,NetworkController::ErrorCode errorCode)
  661. {
  662. if (destination == RR->identity.address()) {
  663. SharedPtr<Network> n(network(nwid));
  664. if (!n) return;
  665. switch(errorCode) {
  666. case NetworkController::NC_ERROR_OBJECT_NOT_FOUND:
  667. case NetworkController::NC_ERROR_INTERNAL_SERVER_ERROR:
  668. n->setNotFound();
  669. break;
  670. case NetworkController::NC_ERROR_ACCESS_DENIED:
  671. n->setAccessDenied();
  672. break;
  673. default: break;
  674. }
  675. } else if (requestPacketId) {
  676. Packet outp(destination,RR->identity.address(),Packet::VERB_ERROR);
  677. outp.append((unsigned char)Packet::VERB_NETWORK_CONFIG_REQUEST);
  678. outp.append(requestPacketId);
  679. switch(errorCode) {
  680. //case NetworkController::NC_ERROR_OBJECT_NOT_FOUND:
  681. //case NetworkController::NC_ERROR_INTERNAL_SERVER_ERROR:
  682. default:
  683. outp.append((unsigned char)Packet::ERROR_OBJ_NOT_FOUND);
  684. break;
  685. case NetworkController::NC_ERROR_ACCESS_DENIED:
  686. outp.append((unsigned char)Packet::ERROR_NETWORK_ACCESS_DENIED_);
  687. break;
  688. }
  689. outp.append(nwid);
  690. RR->sw->send((void *)0,outp,true);
  691. } // else we can't send an ERROR() in response to nothing, so discard
  692. }
  693. } // namespace ZeroTier
  694. /****************************************************************************/
  695. /* CAPI bindings */
  696. /****************************************************************************/
  697. extern "C" {
  698. enum ZT_ResultCode ZT_Node_new(ZT_Node **node,void *uptr,void *tptr,const struct ZT_Node_Callbacks *callbacks,int64_t now)
  699. {
  700. *node = (ZT_Node *)0;
  701. try {
  702. *node = reinterpret_cast<ZT_Node *>(new ZeroTier::Node(uptr,tptr,callbacks,now));
  703. return ZT_RESULT_OK;
  704. } catch (std::bad_alloc &exc) {
  705. return ZT_RESULT_FATAL_ERROR_OUT_OF_MEMORY;
  706. } catch (std::runtime_error &exc) {
  707. return ZT_RESULT_FATAL_ERROR_DATA_STORE_FAILED;
  708. } catch ( ... ) {
  709. return ZT_RESULT_FATAL_ERROR_INTERNAL;
  710. }
  711. }
  712. void ZT_Node_delete(ZT_Node *node)
  713. {
  714. try {
  715. delete (reinterpret_cast<ZeroTier::Node *>(node));
  716. } catch ( ... ) {}
  717. }
  718. enum ZT_ResultCode ZT_Node_processWirePacket(
  719. ZT_Node *node,
  720. void *tptr,
  721. int64_t now,
  722. int64_t localSocket,
  723. const struct sockaddr_storage *remoteAddress,
  724. const void *packetData,
  725. unsigned int packetLength,
  726. volatile int64_t *nextBackgroundTaskDeadline)
  727. {
  728. try {
  729. return reinterpret_cast<ZeroTier::Node *>(node)->processWirePacket(tptr,now,localSocket,remoteAddress,packetData,packetLength,nextBackgroundTaskDeadline);
  730. } catch (std::bad_alloc &exc) {
  731. return ZT_RESULT_FATAL_ERROR_OUT_OF_MEMORY;
  732. } catch ( ... ) {
  733. return ZT_RESULT_OK; // "OK" since invalid packets are simply dropped, but the system is still up
  734. }
  735. }
  736. enum ZT_ResultCode ZT_Node_processVirtualNetworkFrame(
  737. ZT_Node *node,
  738. void *tptr,
  739. int64_t now,
  740. uint64_t nwid,
  741. uint64_t sourceMac,
  742. uint64_t destMac,
  743. unsigned int etherType,
  744. unsigned int vlanId,
  745. const void *frameData,
  746. unsigned int frameLength,
  747. volatile int64_t *nextBackgroundTaskDeadline)
  748. {
  749. try {
  750. return reinterpret_cast<ZeroTier::Node *>(node)->processVirtualNetworkFrame(tptr,now,nwid,sourceMac,destMac,etherType,vlanId,frameData,frameLength,nextBackgroundTaskDeadline);
  751. } catch (std::bad_alloc &exc) {
  752. return ZT_RESULT_FATAL_ERROR_OUT_OF_MEMORY;
  753. } catch ( ... ) {
  754. return ZT_RESULT_FATAL_ERROR_INTERNAL;
  755. }
  756. }
  757. enum ZT_ResultCode ZT_Node_processBackgroundTasks(ZT_Node *node,void *tptr,int64_t now,volatile int64_t *nextBackgroundTaskDeadline)
  758. {
  759. try {
  760. return reinterpret_cast<ZeroTier::Node *>(node)->processBackgroundTasks(tptr,now,nextBackgroundTaskDeadline);
  761. } catch (std::bad_alloc &exc) {
  762. return ZT_RESULT_FATAL_ERROR_OUT_OF_MEMORY;
  763. } catch ( ... ) {
  764. return ZT_RESULT_FATAL_ERROR_INTERNAL;
  765. }
  766. }
  767. void ZT_Node_processDNSResult(
  768. ZT_Node *node,
  769. void *tptr,
  770. uintptr_t dnsRequestID,
  771. const char *name,
  772. enum ZT_DNSRecordType recordType,
  773. const void *result,
  774. unsigned int resultLength,
  775. int resultIsString)
  776. {
  777. try {
  778. reinterpret_cast<ZeroTier::Node *>(node)->processDNSResult(tptr,dnsRequestID,name,recordType,result,resultLength,resultIsString);
  779. } catch ( ... ) {}
  780. }
  781. enum ZT_ResultCode ZT_Node_join(ZT_Node *node,uint64_t nwid,void *uptr,void *tptr)
  782. {
  783. try {
  784. return reinterpret_cast<ZeroTier::Node *>(node)->join(nwid,uptr,tptr);
  785. } catch (std::bad_alloc &exc) {
  786. return ZT_RESULT_FATAL_ERROR_OUT_OF_MEMORY;
  787. } catch ( ... ) {
  788. return ZT_RESULT_FATAL_ERROR_INTERNAL;
  789. }
  790. }
  791. enum ZT_ResultCode ZT_Node_leave(ZT_Node *node,uint64_t nwid,void **uptr,void *tptr)
  792. {
  793. try {
  794. return reinterpret_cast<ZeroTier::Node *>(node)->leave(nwid,uptr,tptr);
  795. } catch (std::bad_alloc &exc) {
  796. return ZT_RESULT_FATAL_ERROR_OUT_OF_MEMORY;
  797. } catch ( ... ) {
  798. return ZT_RESULT_FATAL_ERROR_INTERNAL;
  799. }
  800. }
  801. enum ZT_ResultCode ZT_Node_multicastSubscribe(ZT_Node *node,void *tptr,uint64_t nwid,uint64_t multicastGroup,unsigned long multicastAdi)
  802. {
  803. try {
  804. return reinterpret_cast<ZeroTier::Node *>(node)->multicastSubscribe(tptr,nwid,multicastGroup,multicastAdi);
  805. } catch (std::bad_alloc &exc) {
  806. return ZT_RESULT_FATAL_ERROR_OUT_OF_MEMORY;
  807. } catch ( ... ) {
  808. return ZT_RESULT_FATAL_ERROR_INTERNAL;
  809. }
  810. }
  811. enum ZT_ResultCode ZT_Node_multicastUnsubscribe(ZT_Node *node,uint64_t nwid,uint64_t multicastGroup,unsigned long multicastAdi)
  812. {
  813. try {
  814. return reinterpret_cast<ZeroTier::Node *>(node)->multicastUnsubscribe(nwid,multicastGroup,multicastAdi);
  815. } catch (std::bad_alloc &exc) {
  816. return ZT_RESULT_FATAL_ERROR_OUT_OF_MEMORY;
  817. } catch ( ... ) {
  818. return ZT_RESULT_FATAL_ERROR_INTERNAL;
  819. }
  820. }
  821. ZT_RootList *ZT_Node_listRoots(ZT_Node *node,int64_t now)
  822. {
  823. try {
  824. return reinterpret_cast<ZeroTier::Node *>(node)->listRoots(now);
  825. } catch ( ... ) {
  826. return nullptr;
  827. }
  828. }
  829. enum ZT_ResultCode ZT_Node_setRoot(ZT_Node *node,const char *name,const void *locator,unsigned int locatorSize)
  830. {
  831. try {
  832. return reinterpret_cast<ZeroTier::Node *>(node)->setRoot(name,locator,locatorSize);
  833. } catch (std::bad_alloc &exc) {
  834. return ZT_RESULT_FATAL_ERROR_OUT_OF_MEMORY;
  835. } catch ( ... ) {
  836. return ZT_RESULT_FATAL_ERROR_INTERNAL;
  837. }
  838. }
  839. enum ZT_ResultCode ZT_Node_removeRoot(ZT_Node *node,const char *name)
  840. {
  841. try {
  842. return reinterpret_cast<ZeroTier::Node *>(node)->removeRoot(name);
  843. } catch (std::bad_alloc &exc) {
  844. return ZT_RESULT_FATAL_ERROR_OUT_OF_MEMORY;
  845. } catch ( ... ) {
  846. return ZT_RESULT_FATAL_ERROR_INTERNAL;
  847. }
  848. }
  849. uint64_t ZT_Node_address(ZT_Node *node)
  850. {
  851. return reinterpret_cast<ZeroTier::Node *>(node)->address();
  852. }
  853. void ZT_Node_status(ZT_Node *node,ZT_NodeStatus *status)
  854. {
  855. try {
  856. reinterpret_cast<ZeroTier::Node *>(node)->status(status);
  857. } catch ( ... ) {}
  858. }
  859. ZT_PeerList *ZT_Node_peers(ZT_Node *node)
  860. {
  861. try {
  862. return reinterpret_cast<ZeroTier::Node *>(node)->peers();
  863. } catch ( ... ) {
  864. return (ZT_PeerList *)0;
  865. }
  866. }
  867. ZT_VirtualNetworkConfig *ZT_Node_networkConfig(ZT_Node *node,uint64_t nwid)
  868. {
  869. try {
  870. return reinterpret_cast<ZeroTier::Node *>(node)->networkConfig(nwid);
  871. } catch ( ... ) {
  872. return (ZT_VirtualNetworkConfig *)0;
  873. }
  874. }
  875. ZT_VirtualNetworkList *ZT_Node_networks(ZT_Node *node)
  876. {
  877. try {
  878. return reinterpret_cast<ZeroTier::Node *>(node)->networks();
  879. } catch ( ... ) {
  880. return (ZT_VirtualNetworkList *)0;
  881. }
  882. }
  883. void ZT_Node_setNetworkUserPtr(ZT_Node *node,uint64_t nwid,void *ptr)
  884. {
  885. try {
  886. reinterpret_cast<ZeroTier::Node *>(node)->setNetworkUserPtr(nwid,ptr);
  887. } catch ( ... ) {}
  888. }
  889. void ZT_Node_freeQueryResult(ZT_Node *node,void *qr)
  890. {
  891. try {
  892. reinterpret_cast<ZeroTier::Node *>(node)->freeQueryResult(qr);
  893. } catch ( ... ) {}
  894. }
  895. void ZT_Node_setInterfaceAddresses(ZT_Node *node,const ZT_InterfaceAddress *addrs,unsigned int addrCount)
  896. {
  897. try {
  898. reinterpret_cast<ZeroTier::Node *>(node)->setInterfaceAddresses(addrs,addrCount);
  899. } catch ( ... ) {}
  900. }
  901. int ZT_Node_sendUserMessage(ZT_Node *node,void *tptr,uint64_t dest,uint64_t typeId,const void *data,unsigned int len)
  902. {
  903. try {
  904. return reinterpret_cast<ZeroTier::Node *>(node)->sendUserMessage(tptr,dest,typeId,data,len);
  905. } catch ( ... ) {
  906. return 0;
  907. }
  908. }
  909. void ZT_Node_setController(ZT_Node *node,void *networkControllerInstance)
  910. {
  911. try {
  912. reinterpret_cast<ZeroTier::Node *>(node)->setController(networkControllerInstance);
  913. } catch ( ... ) {}
  914. }
  915. enum ZT_ResultCode ZT_Node_setPhysicalPathConfiguration(ZT_Node *node,const struct sockaddr_storage *pathNetwork,const ZT_PhysicalPathConfiguration *pathConfig)
  916. {
  917. try {
  918. return reinterpret_cast<ZeroTier::Node *>(node)->setPhysicalPathConfiguration(pathNetwork,pathConfig);
  919. } catch ( ... ) {
  920. return ZT_RESULT_FATAL_ERROR_INTERNAL;
  921. }
  922. }
  923. void ZT_version(int *major,int *minor,int *revision)
  924. {
  925. if (major) *major = ZEROTIER_ONE_VERSION_MAJOR;
  926. if (minor) *minor = ZEROTIER_ONE_VERSION_MINOR;
  927. if (revision) *revision = ZEROTIER_ONE_VERSION_REVISION;
  928. }
  929. } // extern "C"