Node.cpp 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091
  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. #include "Constants.hpp"
  14. #include "SharedPtr.hpp"
  15. #include "Node.hpp"
  16. #include "NetworkController.hpp"
  17. #include "Topology.hpp"
  18. #include "Address.hpp"
  19. #include "Identity.hpp"
  20. #include "SelfAwareness.hpp"
  21. #include "Network.hpp"
  22. #include "Trace.hpp"
  23. #include "Locator.hpp"
  24. #include "Expect.hpp"
  25. #include "VL1.hpp"
  26. #include "VL2.hpp"
  27. #include "Buf.hpp"
  28. namespace ZeroTier {
  29. namespace {
  30. // Structure containing all the core objects for a ZeroTier node to reduce memory allocations.
  31. struct _NodeObjects
  32. {
  33. ZT_INLINE _NodeObjects(RuntimeEnvironment *const RR, void *const tPtr) :
  34. t(RR),
  35. expect(),
  36. vl2(RR),
  37. vl1(RR),
  38. sa(RR),
  39. topology(RR, tPtr)
  40. {
  41. RR->t = &t;
  42. RR->expect = &expect;
  43. RR->vl2 = &vl2;
  44. RR->vl1 = &vl1;
  45. RR->sa = &sa;
  46. RR->topology = &topology;
  47. }
  48. Trace t;
  49. Expect expect;
  50. VL2 vl2;
  51. VL1 vl1;
  52. SelfAwareness sa;
  53. Topology topology;
  54. };
  55. struct _sortPeerPtrsByAddress
  56. {
  57. ZT_INLINE bool operator()(const SharedPtr< Peer > &a, const SharedPtr< Peer > &b) const
  58. { return (a->address() < b->address()); }
  59. };
  60. } // anonymous namespace
  61. Node::Node(
  62. void *uPtr,
  63. void *tPtr,
  64. const struct ZT_Node_Callbacks *callbacks,
  65. int64_t now) :
  66. m_RR(this),
  67. RR(&m_RR),
  68. m_objects(nullptr),
  69. m_cb(*callbacks),
  70. m_uPtr(uPtr),
  71. m_networks(),
  72. m_lastPeerPulse(0),
  73. m_lastHousekeepingRun(0),
  74. m_lastNetworkHousekeepingRun(0),
  75. m_now(now),
  76. m_online(false)
  77. {
  78. ZT_SPEW("starting up...");
  79. // Load this node's identity.
  80. uint64_t idtmp[2];
  81. idtmp[0] = 0;
  82. idtmp[1] = 0;
  83. Vector< uint8_t > data(stateObjectGet(tPtr, ZT_STATE_OBJECT_IDENTITY_SECRET, idtmp));
  84. bool haveIdentity = false;
  85. if (!data.empty()) {
  86. data.push_back(0); // zero-terminate string
  87. if (RR->identity.fromString((const char *)data.data())) {
  88. RR->identity.toString(false, RR->publicIdentityStr);
  89. RR->identity.toString(true, RR->secretIdentityStr);
  90. haveIdentity = true;
  91. ZT_SPEW("loaded identity %s", RR->identity.toString().c_str());
  92. }
  93. }
  94. // Generate a new identity if we don't have one.
  95. if (!haveIdentity) {
  96. RR->identity.generate(Identity::C25519);
  97. RR->identity.toString(false, RR->publicIdentityStr);
  98. RR->identity.toString(true, RR->secretIdentityStr);
  99. idtmp[0] = RR->identity.address();
  100. idtmp[1] = 0;
  101. stateObjectPut(tPtr, ZT_STATE_OBJECT_IDENTITY_SECRET, idtmp, RR->secretIdentityStr, (unsigned int)strlen(RR->secretIdentityStr));
  102. stateObjectPut(tPtr, ZT_STATE_OBJECT_IDENTITY_PUBLIC, idtmp, RR->publicIdentityStr, (unsigned int)strlen(RR->publicIdentityStr));
  103. ZT_SPEW("no pre-existing identity found, created %s", RR->identity.toString().c_str());
  104. } else {
  105. idtmp[0] = RR->identity.address();
  106. idtmp[1] = 0;
  107. data = stateObjectGet(tPtr, ZT_STATE_OBJECT_IDENTITY_PUBLIC, idtmp);
  108. if ((data.empty()) || (memcmp(data.data(), RR->publicIdentityStr, strlen(RR->publicIdentityStr)) != 0))
  109. stateObjectPut(tPtr, ZT_STATE_OBJECT_IDENTITY_PUBLIC, idtmp, RR->publicIdentityStr, (unsigned int)strlen(RR->publicIdentityStr));
  110. }
  111. // 2X hash our identity private key(s) to obtain a symmetric key for encrypting
  112. // locally cached data at rest (as a defense in depth measure). This is not used
  113. // for any network level encryption or authentication.
  114. uint8_t tmph[ZT_SHA384_DIGEST_SIZE];
  115. RR->identity.hashWithPrivate(tmph);
  116. SHA384(tmph, tmph, ZT_SHA384_DIGEST_SIZE);
  117. RR->localCacheSymmetric.init(tmph);
  118. Utils::burn(tmph, ZT_SHA384_DIGEST_SIZE);
  119. // Generate a random sort order for privileged ports for use in NAT-t algorithms.
  120. for (unsigned int i = 0; i < 1023; ++i)
  121. RR->randomPrivilegedPortOrder[i] = (uint16_t)(i + 1);
  122. for (unsigned int i = 0; i < 512; ++i) {
  123. uint64_t rn = Utils::random();
  124. const unsigned int a = (unsigned int)rn % 1023;
  125. const unsigned int b = (unsigned int)(rn >> 32U) % 1023;
  126. if (a != b) {
  127. const uint16_t tmp = RR->randomPrivilegedPortOrder[a];
  128. RR->randomPrivilegedPortOrder[a] = RR->randomPrivilegedPortOrder[b];
  129. RR->randomPrivilegedPortOrder[b] = tmp;
  130. }
  131. }
  132. // This constructs all the components of the ZeroTier core within a single contiguous memory container,
  133. // which reduces memory fragmentation and may improve cache locality.
  134. ZT_SPEW("initializing subsystem objects...");
  135. m_objects = new _NodeObjects(RR, tPtr);
  136. ZT_SPEW("node initialized!");
  137. postEvent(tPtr, ZT_EVENT_UP);
  138. }
  139. Node::~Node()
  140. {
  141. ZT_SPEW("node destructor run");
  142. m_networks_l.lock();
  143. m_networks_l.unlock();
  144. m_networks.clear();
  145. m_networks_l.lock();
  146. m_networks_l.unlock();
  147. if (m_objects)
  148. delete (_NodeObjects *)m_objects;
  149. // Let go of cached Buf objects. If other nodes happen to be running in this
  150. // same process space new Bufs will be allocated as needed, but this is almost
  151. // never the case. Calling this here saves RAM if we are running inside something
  152. // that wants to keep running after tearing down its ZeroTier core instance.
  153. Buf::freePool();
  154. }
  155. void Node::shutdown(void *tPtr)
  156. {
  157. ZT_SPEW("explicit shutdown() called");
  158. postEvent(tPtr, ZT_EVENT_DOWN);
  159. if (RR->topology)
  160. RR->topology->saveAll(tPtr);
  161. }
  162. ZT_ResultCode Node::processWirePacket(
  163. void *tPtr,
  164. int64_t now,
  165. int64_t localSocket,
  166. const struct sockaddr_storage *remoteAddress,
  167. SharedPtr< Buf > &packetData,
  168. unsigned int packetLength,
  169. volatile int64_t *nextBackgroundTaskDeadline)
  170. {
  171. m_now = now;
  172. RR->vl1->onRemotePacket(tPtr, localSocket, (remoteAddress) ? InetAddress::NIL : *asInetAddress(remoteAddress), packetData, packetLength);
  173. return ZT_RESULT_OK;
  174. }
  175. ZT_ResultCode Node::processVirtualNetworkFrame(
  176. void *tPtr,
  177. int64_t now,
  178. uint64_t nwid,
  179. uint64_t sourceMac,
  180. uint64_t destMac,
  181. unsigned int etherType,
  182. unsigned int vlanId,
  183. SharedPtr< Buf > &frameData,
  184. unsigned int frameLength,
  185. volatile int64_t *nextBackgroundTaskDeadline)
  186. {
  187. m_now = now;
  188. SharedPtr< Network > nw(this->network(nwid));
  189. if (nw) {
  190. RR->vl2->onLocalEthernet(tPtr, nw, MAC(sourceMac), MAC(destMac), etherType, vlanId, frameData, frameLength);
  191. return ZT_RESULT_OK;
  192. } else {
  193. return ZT_RESULT_ERROR_NETWORK_NOT_FOUND;
  194. }
  195. }
  196. ZT_ResultCode Node::processBackgroundTasks(
  197. void *tPtr,
  198. int64_t now,
  199. volatile int64_t *nextBackgroundTaskDeadline)
  200. {
  201. m_now = now;
  202. Mutex::Lock bl(m_backgroundTasksLock);
  203. try {
  204. // Call peer pulse() method of all peers every ZT_PEER_PULSE_INTERVAL.
  205. if ((now - m_lastPeerPulse) >= ZT_PEER_PULSE_INTERVAL) {
  206. m_lastPeerPulse = now;
  207. ZT_SPEW("running pulse() on each peer...");
  208. try {
  209. Vector< SharedPtr< Peer > > allPeers, rootPeers;
  210. RR->topology->getAllPeers(allPeers, rootPeers);
  211. bool online = false;
  212. for (Vector< SharedPtr< Peer > >::iterator p(allPeers.begin()); p != allPeers.end(); ++p) {
  213. const bool isRoot = std::find(rootPeers.begin(), rootPeers.end(), *p) != rootPeers.end();
  214. (*p)->pulse(tPtr, now, isRoot);
  215. online |= ((isRoot || rootPeers.empty()) && (*p)->directlyConnected(now));
  216. }
  217. RR->topology->rankRoots();
  218. if (m_online.exchange(online) != online)
  219. postEvent(tPtr, online ? ZT_EVENT_ONLINE : ZT_EVENT_OFFLINE);
  220. } catch (...) {
  221. return ZT_RESULT_FATAL_ERROR_INTERNAL;
  222. }
  223. }
  224. // Perform network housekeeping and possibly request new certs and configs every ZT_NETWORK_HOUSEKEEPING_PERIOD.
  225. if ((now - m_lastNetworkHousekeepingRun) >= ZT_NETWORK_HOUSEKEEPING_PERIOD) {
  226. m_lastHousekeepingRun = now;
  227. ZT_SPEW("running networking housekeeping...");
  228. RWMutex::RLock l(m_networks_l);
  229. for (Map< uint64_t, SharedPtr< Network > >::const_iterator i(m_networks.begin()); i != m_networks.end(); ++i) {
  230. i->second->doPeriodicTasks(tPtr, now);
  231. }
  232. }
  233. // Clean up other stuff every ZT_HOUSEKEEPING_PERIOD.
  234. if ((now - m_lastHousekeepingRun) >= ZT_HOUSEKEEPING_PERIOD) {
  235. m_lastHousekeepingRun = now;
  236. ZT_SPEW("running housekeeping...");
  237. // Clean up any old local controller auth memoizations. This is an
  238. // optimization for network controllers to know whether to accept
  239. // or trust nodes without doing an extra cert check.
  240. m_localControllerAuthorizations_l.lock();
  241. for (Map< p_LocalControllerAuth, int64_t >::iterator i(m_localControllerAuthorizations.begin()); i != m_localControllerAuthorizations.end();) { // NOLINT(hicpp-use-auto,modernize-use-auto)
  242. if ((i->second - now) > (ZT_NETWORK_AUTOCONF_DELAY * 3))
  243. m_localControllerAuthorizations.erase(i++);
  244. else ++i;
  245. }
  246. m_localControllerAuthorizations_l.unlock();
  247. RR->topology->doPeriodicTasks(tPtr, now);
  248. RR->sa->clean(now);
  249. }
  250. *nextBackgroundTaskDeadline = now + ZT_TIMER_TASK_INTERVAL;
  251. } catch (...) {
  252. return ZT_RESULT_FATAL_ERROR_INTERNAL;
  253. }
  254. return ZT_RESULT_OK;
  255. }
  256. ZT_ResultCode Node::join(
  257. uint64_t nwid,
  258. const ZT_Fingerprint *controllerFingerprint,
  259. void *uptr,
  260. void *tptr)
  261. {
  262. Fingerprint fp;
  263. if (controllerFingerprint) {
  264. fp = *controllerFingerprint;
  265. ZT_SPEW("joining network %.16llx with fingerprint %s", nwid, fp.toString().c_str());
  266. } else {
  267. ZT_SPEW("joining network %.16llx", nwid);
  268. }
  269. RWMutex::Lock l(m_networks_l);
  270. SharedPtr< Network > &nw = m_networks[nwid];
  271. if (nw)
  272. return ZT_RESULT_OK;
  273. nw.set(new Network(RR, tptr, nwid, fp, uptr, nullptr));
  274. return ZT_RESULT_OK;
  275. }
  276. ZT_ResultCode Node::leave(
  277. uint64_t nwid,
  278. void **uptr,
  279. void *tptr)
  280. {
  281. ZT_SPEW("leaving network %.16llx", nwid);
  282. ZT_VirtualNetworkConfig ctmp;
  283. m_networks_l.lock();
  284. Map< uint64_t, SharedPtr< Network > >::iterator nwi(m_networks.find(nwid)); // NOLINT(hicpp-use-auto,modernize-use-auto)
  285. if (nwi == m_networks.end()) {
  286. m_networks_l.unlock();
  287. return ZT_RESULT_OK;
  288. }
  289. SharedPtr< Network > nw(nwi->second);
  290. m_networks.erase(nwi);
  291. m_networks_l.unlock();
  292. if (uptr)
  293. *uptr = *nw->userPtr();
  294. nw->externalConfig(&ctmp);
  295. RR->node->configureVirtualNetworkPort(tptr, nwid, uptr, ZT_VIRTUAL_NETWORK_CONFIG_OPERATION_DESTROY, &ctmp);
  296. nw->destroy();
  297. nw.zero();
  298. uint64_t tmp[2];
  299. tmp[0] = nwid;
  300. tmp[1] = 0;
  301. RR->node->stateObjectDelete(tptr, ZT_STATE_OBJECT_NETWORK_CONFIG, tmp);
  302. return ZT_RESULT_OK;
  303. }
  304. ZT_ResultCode Node::multicastSubscribe(
  305. void *tPtr,
  306. uint64_t nwid,
  307. uint64_t multicastGroup,
  308. unsigned long multicastAdi)
  309. {
  310. ZT_SPEW("multicast subscribe to %s:%lu", MAC(multicastGroup).toString().c_str(), multicastAdi);
  311. const SharedPtr< Network > nw(this->network(nwid));
  312. if (nw) {
  313. nw->multicastSubscribe(tPtr, MulticastGroup(MAC(multicastGroup), (uint32_t)(multicastAdi & 0xffffffff)));
  314. return ZT_RESULT_OK;
  315. } else return ZT_RESULT_ERROR_NETWORK_NOT_FOUND;
  316. }
  317. ZT_ResultCode Node::multicastUnsubscribe(
  318. uint64_t nwid,
  319. uint64_t multicastGroup,
  320. unsigned long multicastAdi)
  321. {
  322. ZT_SPEW("multicast unsubscribe from %s:%lu", MAC(multicastGroup).toString().c_str(), multicastAdi);
  323. const SharedPtr< Network > nw(this->network(nwid));
  324. if (nw) {
  325. nw->multicastUnsubscribe(MulticastGroup(MAC(multicastGroup), (uint32_t)(multicastAdi & 0xffffffff)));
  326. return ZT_RESULT_OK;
  327. } else return ZT_RESULT_ERROR_NETWORK_NOT_FOUND;
  328. }
  329. ZT_ResultCode Node::addRoot(
  330. void *tPtr,
  331. const ZT_Identity *id)
  332. {
  333. return (RR->topology->addRoot(tPtr, *reinterpret_cast<const Identity *>(id))) ? ZT_RESULT_OK : ZT_RESULT_ERROR_BAD_PARAMETER;
  334. }
  335. ZT_ResultCode Node::removeRoot(
  336. void *tPtr,
  337. const uint64_t address)
  338. {
  339. RR->topology->removeRoot(tPtr, Address(address));
  340. return ZT_RESULT_OK;
  341. }
  342. uint64_t Node::address() const
  343. {
  344. return RR->identity.address().toInt();
  345. }
  346. void Node::status(ZT_NodeStatus *status) const
  347. {
  348. status->address = RR->identity.address().toInt();
  349. status->identity = reinterpret_cast<const ZT_Identity *>(&RR->identity);
  350. status->publicIdentity = RR->publicIdentityStr;
  351. status->secretIdentity = RR->secretIdentityStr;
  352. status->online = m_online ? 1 : 0;
  353. }
  354. ZT_PeerList *Node::peers() const
  355. {
  356. Vector< SharedPtr< Peer > > peers;
  357. RR->topology->getAllPeers(peers);
  358. std::sort(peers.begin(), peers.end(), _sortPeerPtrsByAddress());
  359. const unsigned int bufSize =
  360. sizeof(ZT_PeerList) +
  361. (sizeof(ZT_Peer) * peers.size()) +
  362. ((sizeof(ZT_Path) * ZT_MAX_PEER_NETWORK_PATHS) * peers.size()) +
  363. (sizeof(Identity) * peers.size()) +
  364. (ZT_LOCATOR_MARSHAL_SIZE_MAX * peers.size());
  365. char *buf = (char *)malloc(bufSize);
  366. if (!buf)
  367. return nullptr;
  368. Utils::zero(buf, bufSize);
  369. ZT_PeerList *pl = reinterpret_cast<ZT_PeerList *>(buf);
  370. buf += sizeof(ZT_PeerList);
  371. pl->peers = reinterpret_cast<ZT_Peer *>(buf);
  372. buf += sizeof(ZT_Peer) * peers.size();
  373. ZT_Path *peerPath = reinterpret_cast<ZT_Path *>(buf);
  374. buf += (sizeof(ZT_Path) * ZT_MAX_PEER_NETWORK_PATHS) * peers.size();
  375. Identity *identities = reinterpret_cast<Identity *>(buf);
  376. buf += sizeof(Identity) * peers.size();
  377. uint8_t *locatorBuf = reinterpret_cast<uint8_t *>(buf);
  378. const int64_t now = m_now;
  379. pl->peerCount = 0;
  380. for (Vector< SharedPtr< Peer > >::iterator pi(peers.begin()); pi != peers.end(); ++pi) {
  381. ZT_Peer *const p = pl->peers + pl->peerCount;
  382. p->address = (*pi)->address().toInt();
  383. identities[pl->peerCount] = (*pi)->identity(); // need to make a copy in case peer gets deleted
  384. p->identity = identities + pl->peerCount;
  385. p->fingerprint.address = p->address;
  386. Utils::copy< ZT_FINGERPRINT_HASH_SIZE >(p->fingerprint.hash, (*pi)->identity().fingerprint().hash);
  387. if ((*pi)->remoteVersionKnown()) {
  388. p->versionMajor = (int)(*pi)->remoteVersionMajor();
  389. p->versionMinor = (int)(*pi)->remoteVersionMinor();
  390. p->versionRev = (int)(*pi)->remoteVersionRevision();
  391. } else {
  392. p->versionMajor = -1;
  393. p->versionMinor = -1;
  394. p->versionRev = -1;
  395. }
  396. p->latency = (*pi)->latency();
  397. p->root = RR->topology->isRoot((*pi)->identity()) ? 1 : 0;
  398. p->networkCount = 0;
  399. // TODO: enumerate network memberships
  400. Vector< SharedPtr< Path > > paths;
  401. (*pi)->getAllPaths(paths);
  402. p->pathCount = (unsigned int)paths.size();
  403. p->paths = peerPath;
  404. for (Vector< SharedPtr< Path > >::iterator path(paths.begin()); path != paths.end(); ++path) {
  405. ZT_Path *const pp = peerPath++;
  406. pp->endpoint.type = ZT_ENDPOINT_TYPE_IP_UDP; // only type supported right now
  407. Utils::copy< sizeof(sockaddr_storage) >(&pp->endpoint.value.ss, &((*path)->address().as.ss));
  408. pp->lastSend = (*path)->lastOut();
  409. pp->lastReceive = (*path)->lastIn();
  410. pp->alive = (*path)->alive(now) ? 1 : 0;
  411. pp->preferred = (p->pathCount == 0) ? 1 : 0;
  412. }
  413. const SharedPtr< const Locator > loc((*pi)->locator());
  414. if (loc) {
  415. const int ls = loc->marshal(locatorBuf);
  416. if (ls > 0) {
  417. p->locatorSize = (unsigned int)ls;
  418. p->locator = locatorBuf;
  419. locatorBuf += ls;
  420. }
  421. }
  422. ++pl->peerCount;
  423. }
  424. return pl;
  425. }
  426. ZT_VirtualNetworkConfig *Node::networkConfig(uint64_t nwid) const
  427. {
  428. SharedPtr< Network > nw(network(nwid));
  429. if (nw) {
  430. ZT_VirtualNetworkConfig *const nc = (ZT_VirtualNetworkConfig *)::malloc(sizeof(ZT_VirtualNetworkConfig));
  431. nw->externalConfig(nc);
  432. return nc;
  433. }
  434. return nullptr;
  435. }
  436. ZT_VirtualNetworkList *Node::networks() const
  437. {
  438. RWMutex::RLock l(m_networks_l);
  439. char *const buf = (char *)::malloc(sizeof(ZT_VirtualNetworkList) + (sizeof(ZT_VirtualNetworkConfig) * m_networks.size()));
  440. if (!buf)
  441. return nullptr;
  442. ZT_VirtualNetworkList *nl = (ZT_VirtualNetworkList *)buf; // NOLINT(modernize-use-auto,hicpp-use-auto)
  443. nl->networks = (ZT_VirtualNetworkConfig *)(buf + sizeof(ZT_VirtualNetworkList));
  444. nl->networkCount = 0;
  445. for (Map< uint64_t, SharedPtr< Network > >::const_iterator i(m_networks.begin()); i != m_networks.end(); ++i) // NOLINT(modernize-use-auto,modernize-loop-convert,hicpp-use-auto)
  446. i->second->externalConfig(&(nl->networks[nl->networkCount++]));
  447. return nl;
  448. }
  449. void Node::setNetworkUserPtr(
  450. uint64_t nwid,
  451. void *ptr)
  452. {
  453. SharedPtr< Network > nw(network(nwid));
  454. if (nw)
  455. *(nw->userPtr()) = ptr;
  456. }
  457. void Node::setInterfaceAddresses(
  458. const ZT_InterfaceAddress *addrs,
  459. unsigned int addrCount)
  460. {
  461. Mutex::Lock _l(m_localInterfaceAddresses_m);
  462. m_localInterfaceAddresses.clear();
  463. for (unsigned int i = 0; i < addrCount; ++i) {
  464. bool dupe = false;
  465. for (unsigned int j = 0; j < i; ++j) {
  466. if (*(reinterpret_cast<const InetAddress *>(&addrs[j].address)) == *(reinterpret_cast<const InetAddress *>(&addrs[i].address))) {
  467. dupe = true;
  468. break;
  469. }
  470. }
  471. if (!dupe)
  472. m_localInterfaceAddresses.push_back(addrs[i]);
  473. }
  474. }
  475. ZT_ResultCode Node::addPeer(
  476. void *tptr,
  477. const ZT_Identity *identity)
  478. {
  479. if (!identity)
  480. return ZT_RESULT_ERROR_BAD_PARAMETER;
  481. SharedPtr< Peer > peer(RR->topology->peer(tptr, reinterpret_cast<const Identity *>(identity)->address()));
  482. if (!peer) {
  483. peer.set(new Peer(RR));
  484. peer->init(*reinterpret_cast<const Identity *>(identity));
  485. peer = RR->topology->add(tptr, peer);
  486. }
  487. return (peer->identity() == *reinterpret_cast<const Identity *>(identity)) ? ZT_RESULT_OK : ZT_RESULT_ERROR_COLLIDING_OBJECT;
  488. }
  489. int Node::tryPeer(
  490. void *tptr,
  491. const ZT_Fingerprint *fp,
  492. const ZT_Endpoint *endpoint,
  493. int retries)
  494. {
  495. if ((!fp) || (!endpoint))
  496. return 0;
  497. const SharedPtr< Peer > peer(RR->topology->peer(tptr, fp->address, true));
  498. if ((peer) && (peer->identity().fingerprint().bestSpecificityEquals(*fp))) {
  499. peer->contact(tptr, m_now, Endpoint(*endpoint), std::min(retries, 1));
  500. return 1;
  501. }
  502. return 0;
  503. }
  504. int Node::sendUserMessage(
  505. void *tptr,
  506. uint64_t dest,
  507. uint64_t typeId,
  508. const void *data,
  509. unsigned int len)
  510. {
  511. try {
  512. if (RR->identity.address().toInt() != dest) {
  513. // TODO
  514. /*
  515. Packet outp(Address(dest),RR->identity.address(),Packet::VERB_USER_MESSAGE);
  516. outp.append(typeId);
  517. outp.append(data,len);
  518. outp.compress();
  519. RR->sw->send(tptr,outp,true);
  520. */
  521. return 1;
  522. }
  523. } catch (...) {}
  524. return 0;
  525. }
  526. void Node::setController(void *networkControllerInstance)
  527. {
  528. RR->localNetworkController = reinterpret_cast<NetworkController *>(networkControllerInstance);
  529. if (networkControllerInstance)
  530. RR->localNetworkController->init(RR->identity, this);
  531. }
  532. // Methods used only within the core ----------------------------------------------------------------------------------
  533. Vector< uint8_t > Node::stateObjectGet(void *const tPtr, ZT_StateObjectType type, const uint64_t id[2])
  534. {
  535. Vector< uint8_t > r;
  536. if (m_cb.stateGetFunction) {
  537. void *data = nullptr;
  538. void (*freeFunc)(void *) = nullptr;
  539. int l = m_cb.stateGetFunction(
  540. reinterpret_cast<ZT_Node *>(this),
  541. m_uPtr,
  542. tPtr,
  543. type,
  544. id,
  545. &data,
  546. &freeFunc);
  547. if ((l > 0) && (data) && (freeFunc)) {
  548. r.assign(reinterpret_cast<const uint8_t *>(data), reinterpret_cast<const uint8_t *>(data) + l);
  549. freeFunc(data);
  550. }
  551. }
  552. return r;
  553. }
  554. bool Node::shouldUsePathForZeroTierTraffic(void *tPtr, const Identity &id, const int64_t localSocket, const InetAddress &remoteAddress)
  555. {
  556. {
  557. RWMutex::RLock l(m_networks_l);
  558. for (Map< uint64_t, SharedPtr< Network > >::iterator i(m_networks.begin()); i != m_networks.end(); ++i) { // NOLINT(hicpp-use-auto,modernize-use-auto,modernize-loop-convert)
  559. for (unsigned int k = 0, j = i->second->config().staticIpCount; k < j; ++k) {
  560. if (i->second->config().staticIps[k].containsAddress(remoteAddress))
  561. return false;
  562. }
  563. }
  564. }
  565. if (m_cb.pathCheckFunction) {
  566. return (m_cb.pathCheckFunction(
  567. reinterpret_cast<ZT_Node *>(this),
  568. m_uPtr,
  569. tPtr,
  570. id.address().toInt(),
  571. (const ZT_Identity *)&id,
  572. localSocket,
  573. reinterpret_cast<const struct sockaddr_storage *>(&remoteAddress)) != 0);
  574. }
  575. return true;
  576. }
  577. bool Node::externalPathLookup(void *tPtr, const Identity &id, int family, InetAddress &addr)
  578. {
  579. if (m_cb.pathLookupFunction) {
  580. return (m_cb.pathLookupFunction(
  581. reinterpret_cast<ZT_Node *>(this),
  582. m_uPtr,
  583. tPtr,
  584. id.address().toInt(),
  585. reinterpret_cast<const ZT_Identity *>(&id),
  586. family,
  587. reinterpret_cast<sockaddr_storage *>(&addr)) == ZT_RESULT_OK);
  588. }
  589. return false;
  590. }
  591. bool Node::localControllerHasAuthorized(const int64_t now, const uint64_t nwid, const Address &addr) const
  592. {
  593. m_localControllerAuthorizations_l.lock();
  594. const int64_t *const at = m_localControllerAuthorizations.get(p_LocalControllerAuth(nwid, addr));
  595. m_localControllerAuthorizations_l.unlock();
  596. if (at)
  597. return ((now - *at) < (ZT_NETWORK_AUTOCONF_DELAY * 3));
  598. return false;
  599. }
  600. // Implementation of NetworkController::Sender ------------------------------------------------------------------------
  601. void Node::ncSendConfig(uint64_t nwid, uint64_t requestPacketId, const Address &destination, const NetworkConfig &nc, bool sendLegacyFormatConfig)
  602. {
  603. m_localControllerAuthorizations_l.lock();
  604. m_localControllerAuthorizations[p_LocalControllerAuth(nwid, destination)] = now();
  605. m_localControllerAuthorizations_l.unlock();
  606. if (destination == RR->identity.address()) {
  607. SharedPtr< Network > n(network(nwid));
  608. if (!n)
  609. return;
  610. n->setConfiguration((void *)0, nc, true);
  611. } else {
  612. Dictionary dconf;
  613. if (nc.toDictionary(dconf)) {
  614. uint64_t configUpdateId = Utils::random();
  615. if (!configUpdateId)
  616. ++configUpdateId;
  617. Vector< uint8_t > ddata;
  618. dconf.encode(ddata);
  619. // TODO
  620. /*
  621. unsigned int chunkIndex = 0;
  622. while (chunkIndex < totalSize) {
  623. const unsigned int chunkLen = std::min(totalSize - chunkIndex,(unsigned int)(ZT_PROTO_MAX_PACKET_LENGTH - (ZT_PACKET_IDX_PAYLOAD + 256)));
  624. Packet outp(destination,RR->identity.address(),(requestPacketId) ? Packet::VERB_OK : Packet::VERB_NETWORK_CONFIG);
  625. if (requestPacketId) {
  626. outp.append((unsigned char)Packet::VERB_NETWORK_CONFIG_REQUEST);
  627. outp.append(requestPacketId);
  628. }
  629. const unsigned int sigStart = outp.size();
  630. outp.append(nwid);
  631. outp.append((uint16_t)chunkLen);
  632. outp.append((const void *)(dconf->data() + chunkIndex),chunkLen);
  633. outp.append((uint8_t)0); // no flags
  634. outp.append((uint64_t)configUpdateId);
  635. outp.append((uint32_t)totalSize);
  636. outp.append((uint32_t)chunkIndex);
  637. uint8_t sig[256];
  638. const unsigned int siglen = RR->identity.sign(reinterpret_cast<const uint8_t *>(outp.data()) + sigStart,outp.size() - sigStart,sig,sizeof(sig));
  639. outp.append((uint8_t)1);
  640. outp.append((uint16_t)siglen);
  641. outp.append(sig,siglen);
  642. outp.compress();
  643. RR->sw->send((void *)0,outp,true);
  644. chunkIndex += chunkLen;
  645. }
  646. */
  647. }
  648. }
  649. }
  650. void Node::ncSendRevocation(const Address &destination, const Revocation &rev)
  651. {
  652. if (destination == RR->identity.address()) {
  653. SharedPtr< Network > n(network(rev.networkId()));
  654. if (!n) return;
  655. n->addCredential(nullptr, RR->identity, rev);
  656. } else {
  657. // TODO
  658. /*
  659. Packet outp(destination,RR->identity.address(),Packet::VERB_NETWORK_CREDENTIALS);
  660. outp.append((uint8_t)0x00);
  661. outp.append((uint16_t)0);
  662. outp.append((uint16_t)0);
  663. outp.append((uint16_t)1);
  664. rev.serialize(outp);
  665. outp.append((uint16_t)0);
  666. RR->sw->send((void *)0,outp,true);
  667. */
  668. }
  669. }
  670. void Node::ncSendError(uint64_t nwid, uint64_t requestPacketId, const Address &destination, NetworkController::ErrorCode errorCode)
  671. {
  672. if (destination == RR->identity.address()) {
  673. SharedPtr< Network > n(network(nwid));
  674. if (!n) return;
  675. switch (errorCode) {
  676. case NetworkController::NC_ERROR_OBJECT_NOT_FOUND:
  677. case NetworkController::NC_ERROR_INTERNAL_SERVER_ERROR:
  678. n->setNotFound();
  679. break;
  680. case NetworkController::NC_ERROR_ACCESS_DENIED:
  681. n->setAccessDenied();
  682. break;
  683. default:
  684. break;
  685. }
  686. } else if (requestPacketId) {
  687. // TODO
  688. /*
  689. Packet outp(destination,RR->identity.address(),Packet::VERB_ERROR);
  690. outp.append((unsigned char)Packet::VERB_NETWORK_CONFIG_REQUEST);
  691. outp.append(requestPacketId);
  692. switch(errorCode) {
  693. //case NetworkController::NC_ERROR_OBJECT_NOT_FOUND:
  694. //case NetworkController::NC_ERROR_INTERNAL_SERVER_ERROR:
  695. default:
  696. outp.append((unsigned char)Packet::ERROR_OBJ_NOT_FOUND);
  697. break;
  698. case NetworkController::NC_ERROR_ACCESS_DENIED:
  699. outp.append((unsigned char)Packet::ERROR_NETWORK_ACCESS_DENIED_);
  700. break;
  701. }
  702. outp.append(nwid);
  703. RR->sw->send((void *)0,outp,true);
  704. */
  705. } // else we can't send an ERROR() in response to nothing, so discard
  706. }
  707. } // namespace ZeroTier
  708. // C API --------------------------------------------------------------------------------------------------------------
  709. extern "C" {
  710. // These macros make the idiom of passing buffers to outside code via the API work properly even
  711. // if the first address of Buf does not overlap with its data field, since the C++ standard does
  712. // not absolutely guarantee this.
  713. #define _ZT_PTRTOBUF(p) ((ZeroTier::Buf *)( ((uintptr_t)(p)) - ((uintptr_t)&(((ZeroTier::Buf *)0)->unsafeData[0])) ))
  714. #define _ZT_BUFTOPTR(b) ((void *)(&((b)->unsafeData[0])))
  715. void *ZT_getBuffer()
  716. {
  717. // When external code requests a Buf, grab one from the pool (or freshly allocated)
  718. // and return it with its reference count left at zero. It's the responsibility of
  719. // external code to bring it back via freeBuffer() or one of the processX() calls.
  720. // When this occurs it's either sent back to the pool with Buf's delete operator or
  721. // wrapped in a SharedPtr<> to be passed into the core.
  722. try {
  723. return _ZT_BUFTOPTR(new ZeroTier::Buf());
  724. } catch (...) {
  725. return nullptr; // can only happen on out of memory condition
  726. }
  727. }
  728. void ZT_freeBuffer(void *b)
  729. {
  730. if (b)
  731. delete _ZT_PTRTOBUF(b);
  732. }
  733. void ZT_freeQueryResult(void *qr)
  734. {
  735. if (qr)
  736. free(qr);
  737. }
  738. enum ZT_ResultCode ZT_Node_new(ZT_Node **node, void *uptr, void *tptr, const struct ZT_Node_Callbacks *callbacks, int64_t now)
  739. {
  740. *node = (ZT_Node *)0;
  741. try {
  742. *node = reinterpret_cast<ZT_Node *>(new ZeroTier::Node(uptr, tptr, callbacks, now));
  743. return ZT_RESULT_OK;
  744. } catch (std::bad_alloc &exc) {
  745. return ZT_RESULT_FATAL_ERROR_OUT_OF_MEMORY;
  746. } catch (std::runtime_error &exc) {
  747. return ZT_RESULT_FATAL_ERROR_DATA_STORE_FAILED;
  748. } catch (...) {
  749. return ZT_RESULT_ERROR_INTERNAL;
  750. }
  751. }
  752. void ZT_Node_delete(ZT_Node *node, void *tPtr)
  753. {
  754. try {
  755. reinterpret_cast<ZeroTier::Node *>(node)->shutdown(tPtr);
  756. delete (reinterpret_cast<ZeroTier::Node *>(node));
  757. } catch (...) {}
  758. }
  759. enum ZT_ResultCode ZT_Node_processWirePacket(
  760. ZT_Node *node,
  761. void *tptr,
  762. int64_t now,
  763. int64_t localSocket,
  764. const struct sockaddr_storage *remoteAddress,
  765. const void *packetData,
  766. unsigned int packetLength,
  767. int isZtBuffer,
  768. volatile int64_t *nextBackgroundTaskDeadline)
  769. {
  770. try {
  771. ZeroTier::SharedPtr< ZeroTier::Buf > buf((isZtBuffer) ? _ZT_PTRTOBUF(packetData) : new ZeroTier::Buf(packetData, packetLength & ZT_BUF_MEM_MASK));
  772. return reinterpret_cast<ZeroTier::Node *>(node)->processWirePacket(tptr, now, localSocket, remoteAddress, buf, packetLength, nextBackgroundTaskDeadline);
  773. } catch (std::bad_alloc &exc) {
  774. return ZT_RESULT_FATAL_ERROR_OUT_OF_MEMORY;
  775. } catch (...) {
  776. // "OK" since invalid packets are simply dropped, but the system is still up.
  777. // We should never make it here, but if we did that would be the interpretation.
  778. return ZT_RESULT_OK;
  779. }
  780. }
  781. enum ZT_ResultCode ZT_Node_processVirtualNetworkFrame(
  782. ZT_Node *node,
  783. void *tptr,
  784. int64_t now,
  785. uint64_t nwid,
  786. uint64_t sourceMac,
  787. uint64_t destMac,
  788. unsigned int etherType,
  789. unsigned int vlanId,
  790. const void *frameData,
  791. unsigned int frameLength,
  792. int isZtBuffer,
  793. volatile int64_t *nextBackgroundTaskDeadline)
  794. {
  795. try {
  796. ZeroTier::SharedPtr< ZeroTier::Buf > buf((isZtBuffer) ? _ZT_PTRTOBUF(frameData) : new ZeroTier::Buf(frameData, frameLength & ZT_BUF_MEM_MASK));
  797. return reinterpret_cast<ZeroTier::Node *>(node)->processVirtualNetworkFrame(tptr, now, nwid, sourceMac, destMac, etherType, vlanId, buf, frameLength, nextBackgroundTaskDeadline);
  798. } catch (std::bad_alloc &exc) {
  799. return ZT_RESULT_FATAL_ERROR_OUT_OF_MEMORY;
  800. } catch (...) {
  801. return ZT_RESULT_ERROR_INTERNAL;
  802. }
  803. }
  804. enum ZT_ResultCode ZT_Node_processBackgroundTasks(ZT_Node *node, void *tptr, int64_t now, volatile int64_t *nextBackgroundTaskDeadline)
  805. {
  806. try {
  807. return reinterpret_cast<ZeroTier::Node *>(node)->processBackgroundTasks(tptr, now, nextBackgroundTaskDeadline);
  808. } catch (std::bad_alloc &exc) {
  809. return ZT_RESULT_FATAL_ERROR_OUT_OF_MEMORY;
  810. } catch (...) {
  811. return ZT_RESULT_ERROR_INTERNAL;
  812. }
  813. }
  814. enum ZT_ResultCode ZT_Node_join(ZT_Node *node, uint64_t nwid, const ZT_Fingerprint *controllerFingerprint, void *uptr, void *tptr)
  815. {
  816. try {
  817. return reinterpret_cast<ZeroTier::Node *>(node)->join(nwid, controllerFingerprint, uptr, tptr);
  818. } catch (std::bad_alloc &exc) {
  819. return ZT_RESULT_FATAL_ERROR_OUT_OF_MEMORY;
  820. } catch (...) {
  821. return ZT_RESULT_ERROR_INTERNAL;
  822. }
  823. }
  824. enum ZT_ResultCode ZT_Node_leave(ZT_Node *node, uint64_t nwid, void **uptr, void *tptr)
  825. {
  826. try {
  827. return reinterpret_cast<ZeroTier::Node *>(node)->leave(nwid, uptr, tptr);
  828. } catch (std::bad_alloc &exc) {
  829. return ZT_RESULT_FATAL_ERROR_OUT_OF_MEMORY;
  830. } catch (...) {
  831. return ZT_RESULT_ERROR_INTERNAL;
  832. }
  833. }
  834. enum ZT_ResultCode ZT_Node_multicastSubscribe(ZT_Node *node, void *tptr, uint64_t nwid, uint64_t multicastGroup, unsigned long multicastAdi)
  835. {
  836. try {
  837. return reinterpret_cast<ZeroTier::Node *>(node)->multicastSubscribe(tptr, nwid, multicastGroup, multicastAdi);
  838. } catch (std::bad_alloc &exc) {
  839. return ZT_RESULT_FATAL_ERROR_OUT_OF_MEMORY;
  840. } catch (...) {
  841. return ZT_RESULT_ERROR_INTERNAL;
  842. }
  843. }
  844. enum ZT_ResultCode ZT_Node_multicastUnsubscribe(ZT_Node *node, uint64_t nwid, uint64_t multicastGroup, unsigned long multicastAdi)
  845. {
  846. try {
  847. return reinterpret_cast<ZeroTier::Node *>(node)->multicastUnsubscribe(nwid, multicastGroup, multicastAdi);
  848. } catch (std::bad_alloc &exc) {
  849. return ZT_RESULT_FATAL_ERROR_OUT_OF_MEMORY;
  850. } catch (...) {
  851. return ZT_RESULT_ERROR_INTERNAL;
  852. }
  853. }
  854. enum ZT_ResultCode ZT_Node_addRoot(ZT_Node *node, void *tptr, const ZT_Identity *id)
  855. {
  856. try {
  857. return reinterpret_cast<ZeroTier::Node *>(node)->addRoot(tptr, id);
  858. } catch (std::bad_alloc &exc) {
  859. return ZT_RESULT_FATAL_ERROR_OUT_OF_MEMORY;
  860. } catch (...) {
  861. return ZT_RESULT_ERROR_INTERNAL;
  862. }
  863. }
  864. enum ZT_ResultCode ZT_Node_removeRoot(ZT_Node *node, void *tptr, const uint64_t address)
  865. {
  866. try {
  867. return reinterpret_cast<ZeroTier::Node *>(node)->removeRoot(tptr, address);
  868. } catch (std::bad_alloc &exc) {
  869. return ZT_RESULT_FATAL_ERROR_OUT_OF_MEMORY;
  870. } catch (...) {
  871. return ZT_RESULT_ERROR_INTERNAL;
  872. }
  873. }
  874. uint64_t ZT_Node_address(ZT_Node *node)
  875. {
  876. return reinterpret_cast<ZeroTier::Node *>(node)->address();
  877. }
  878. const ZT_Identity *ZT_Node_identity(ZT_Node *node)
  879. {
  880. return (const ZT_Identity *)(&(reinterpret_cast<ZeroTier::Node *>(node)->identity()));
  881. }
  882. void ZT_Node_status(ZT_Node *node, ZT_NodeStatus *status)
  883. {
  884. try {
  885. reinterpret_cast<ZeroTier::Node *>(node)->status(status);
  886. } catch (...) {}
  887. }
  888. ZT_PeerList *ZT_Node_peers(ZT_Node *node)
  889. {
  890. try {
  891. return reinterpret_cast<ZeroTier::Node *>(node)->peers();
  892. } catch (...) {
  893. return (ZT_PeerList *)0;
  894. }
  895. }
  896. ZT_VirtualNetworkConfig *ZT_Node_networkConfig(ZT_Node *node, uint64_t nwid)
  897. {
  898. try {
  899. return reinterpret_cast<ZeroTier::Node *>(node)->networkConfig(nwid);
  900. } catch (...) {
  901. return (ZT_VirtualNetworkConfig *)0;
  902. }
  903. }
  904. ZT_VirtualNetworkList *ZT_Node_networks(ZT_Node *node)
  905. {
  906. try {
  907. return reinterpret_cast<ZeroTier::Node *>(node)->networks();
  908. } catch (...) {
  909. return (ZT_VirtualNetworkList *)0;
  910. }
  911. }
  912. int ZT_Node_tryPeer(
  913. ZT_Node *node,
  914. void *tptr,
  915. const ZT_Fingerprint *fp,
  916. const ZT_Endpoint *endpoint,
  917. int retries)
  918. {
  919. try {
  920. return reinterpret_cast<ZeroTier::Node *>(node)->tryPeer(tptr, fp, endpoint, retries);
  921. } catch (...) {
  922. return 0;
  923. }
  924. }
  925. void ZT_Node_setNetworkUserPtr(ZT_Node *node, uint64_t nwid, void *ptr)
  926. {
  927. try {
  928. reinterpret_cast<ZeroTier::Node *>(node)->setNetworkUserPtr(nwid, ptr);
  929. } catch (...) {}
  930. }
  931. void ZT_Node_setInterfaceAddresses(ZT_Node *node, const ZT_InterfaceAddress *addrs, unsigned int addrCount)
  932. {
  933. try {
  934. reinterpret_cast<ZeroTier::Node *>(node)->setInterfaceAddresses(addrs, addrCount);
  935. } catch (...) {}
  936. }
  937. enum ZT_ResultCode ZT_Node_addPeer(
  938. ZT_Node *node,
  939. void *tptr,
  940. const ZT_Identity *id)
  941. {
  942. try {
  943. return reinterpret_cast<ZeroTier::Node *>(node)->addPeer(tptr, id);
  944. } catch (...) {
  945. return ZT_RESULT_ERROR_INTERNAL;
  946. }
  947. }
  948. int ZT_Node_sendUserMessage(ZT_Node *node, void *tptr, uint64_t dest, uint64_t typeId, const void *data, unsigned int len)
  949. {
  950. try {
  951. return reinterpret_cast<ZeroTier::Node *>(node)->sendUserMessage(tptr, dest, typeId, data, len);
  952. } catch (...) {
  953. return 0;
  954. }
  955. }
  956. void ZT_Node_setController(ZT_Node *node, void *networkControllerInstance)
  957. {
  958. try {
  959. reinterpret_cast<ZeroTier::Node *>(node)->setController(networkControllerInstance);
  960. } catch (...) {}
  961. }
  962. void ZT_version(int *major, int *minor, int *revision, int *build)
  963. {
  964. if (major)
  965. *major = ZEROTIER_VERSION_MAJOR;
  966. if (minor)
  967. *minor = ZEROTIER_VERSION_MINOR;
  968. if (revision)
  969. *revision = ZEROTIER_VERSION_REVISION;
  970. if (build)
  971. *build = ZEROTIER_VERSION_BUILD;
  972. }
  973. } // extern "C"