Node.cpp 32 KB

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