NetconEthernetTap.cpp 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086
  1. /*
  2. * ZeroTier One - Network Virtualization Everywhere
  3. * Copyright (C) 2011-2015 ZeroTier, Inc.
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. * --
  19. *
  20. * ZeroTier may be used and distributed under the terms of the GPLv3, which
  21. * are available at: http://www.gnu.org/licenses/gpl-3.0.html
  22. *
  23. * If you would like to embed ZeroTier into a commercial application or
  24. * redistribute it in a modified binary form, please contact ZeroTier Networks
  25. * LLC. Start here: http://www.zerotier.com/
  26. */
  27. #ifdef ZT_ENABLE_NETCON
  28. #include <algorithm>
  29. #include <utility>
  30. #include <dlfcn.h>
  31. #include "NetconEthernetTap.hpp"
  32. #include "../node/Utils.hpp"
  33. #include "../osdep/OSUtils.hpp"
  34. #include "../osdep/Phy.hpp"
  35. #include "lwip/tcp_impl.h"
  36. #include "netif/etharp.h"
  37. #include "lwip/ip.h"
  38. #include "lwip/ip_addr.h"
  39. #include "lwip/ip_frag.h"
  40. #include "lwip/tcp.h"
  41. #include "LWIPStack.hpp"
  42. #include "NetconService.hpp"
  43. #include "Intercept.h"
  44. #include "NetconUtilities.hpp"
  45. #define APPLICATION_POLL_FREQ 1
  46. namespace ZeroTier {
  47. NetconEthernetTap::NetconEthernetTap(
  48. const char *homePath,
  49. const MAC &mac,
  50. unsigned int mtu,
  51. unsigned int metric,
  52. uint64_t nwid,
  53. const char *friendlyName,
  54. void (*handler)(void *,uint64_t,const MAC &,const MAC &,unsigned int,unsigned int,const void *,unsigned int),
  55. void *arg) :
  56. _phy(this,false,true),
  57. _unixListenSocket((PhySocket *)0),
  58. _handler(handler),
  59. _arg(arg),
  60. _nwid(nwid),
  61. _mac(mac),
  62. _homePath(homePath),
  63. _mtu(mtu),
  64. _enabled(true),
  65. _run(true)
  66. {
  67. char sockPath[4096];
  68. Utils::snprintf(sockPath,sizeof(sockPath),"/tmp/.ztnc_%.16llx",(unsigned long long)nwid);
  69. _dev = sockPath;
  70. lwipstack = new LWIPStack("ext/bin/lwip/liblwip.so"); // ext/bin/liblwip.so.debug for debug symbols
  71. if(!lwipstack) // TODO double check this check
  72. throw std::runtime_error("unable to load lwip lib.");
  73. lwipstack->lwip_init();
  74. _unixListenSocket = _phy.unixListen(sockPath,(void *)this);
  75. if (!_unixListenSocket)
  76. throw std::runtime_error(std::string("unable to bind to ")+sockPath);
  77. _thread = Thread::start(this);
  78. }
  79. NetconEthernetTap::~NetconEthernetTap()
  80. {
  81. _run = false;
  82. _phy.whack();
  83. _phy.whack();
  84. Thread::join(_thread);
  85. _phy.close(_unixListenSocket,false);
  86. delete lwipstack;
  87. }
  88. void NetconEthernetTap::setEnabled(bool en)
  89. {
  90. _enabled = en;
  91. }
  92. bool NetconEthernetTap::enabled() const
  93. {
  94. return _enabled;
  95. }
  96. bool NetconEthernetTap::addIp(const InetAddress &ip)
  97. {
  98. Mutex::Lock _l(_ips_m);
  99. if (std::find(_ips.begin(),_ips.end(),ip) == _ips.end()) {
  100. _ips.push_back(ip);
  101. std::sort(_ips.begin(),_ips.end());
  102. if (ip.isV4()) {
  103. // Set IP
  104. static ip_addr_t ipaddr, netmask, gw;
  105. IP4_ADDR(&gw,192,168,0,1);
  106. ipaddr.addr = *((u32_t *)ip.rawIpData());
  107. netmask.addr = *((u32_t *)ip.netmask().rawIpData());
  108. // Set up the lwip-netif for LWIP's sake
  109. lwipstack->netif_add(&interface,&ipaddr, &netmask, &gw, NULL, tapif_init, lwipstack->_ethernet_input);
  110. interface.state = this;
  111. interface.output = lwipstack->_etharp_output;
  112. _mac.copyTo(interface.hwaddr, 6);
  113. interface.mtu = _mtu;
  114. interface.name[0] = 't';
  115. interface.name[1] = 'p';
  116. interface.linkoutput = low_level_output;
  117. interface.hwaddr_len = 6;
  118. interface.flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_IGMP;
  119. lwipstack->netif_set_default(&interface);
  120. lwipstack->netif_set_up(&interface);
  121. }
  122. }
  123. return true;
  124. }
  125. bool NetconEthernetTap::removeIp(const InetAddress &ip)
  126. {
  127. Mutex::Lock _l(_ips_m);
  128. std::vector<InetAddress>::iterator i(std::find(_ips.begin(),_ips.end(),ip));
  129. if (i == _ips.end())
  130. return false;
  131. _ips.erase(i);
  132. if (ip.isV4()) {
  133. // TODO: dealloc from LWIP
  134. }
  135. return true;
  136. }
  137. std::vector<InetAddress> NetconEthernetTap::ips() const
  138. {
  139. Mutex::Lock _l(_ips_m);
  140. return _ips;
  141. }
  142. void NetconEthernetTap::put(const MAC &from,const MAC &to,unsigned int etherType,const void *data,unsigned int len)
  143. {
  144. struct pbuf *p,*q;
  145. if (!_enabled)
  146. return;
  147. struct eth_hdr ethhdr;
  148. from.copyTo(ethhdr.src.addr, 6);
  149. to.copyTo(ethhdr.dest.addr, 6);
  150. ethhdr.type = Utils::hton((uint16_t)etherType);
  151. // We allocate a pbuf chain of pbufs from the pool.
  152. p = lwipstack->pbuf_alloc(PBUF_RAW, len+sizeof(struct eth_hdr), PBUF_POOL);
  153. if (p != NULL) {
  154. const char *dataptr = reinterpret_cast<const char *>(data);
  155. // First pbuf gets ethernet header at start
  156. q = p;
  157. if (q->len < sizeof(ethhdr)) {
  158. fprintf(stderr,"_put(): Dropped packet: first pbuf smaller than ethernet header\n");
  159. return;
  160. }
  161. memcpy(q->payload,&ethhdr,sizeof(ethhdr));
  162. memcpy(q->payload + sizeof(ethhdr),dataptr,q->len - sizeof(ethhdr));
  163. dataptr += q->len - sizeof(ethhdr);
  164. // Remaining pbufs (if any) get rest of data
  165. while ((q = q->next)) {
  166. memcpy(q->payload,dataptr,q->len);
  167. dataptr += q->len;
  168. }
  169. } else {
  170. fprintf(stderr, "_put(): Dropped packet: no pbufs available\n");
  171. return;
  172. }
  173. {
  174. Mutex::Lock _l2(lwipstack->_lock);
  175. if(interface.input(p, &interface) != ERR_OK) {
  176. fprintf(stderr, "_put(): Error while RXing packet (netif->input)\n");
  177. }
  178. }
  179. }
  180. std::string NetconEthernetTap::deviceName() const
  181. {
  182. return _dev;
  183. }
  184. void NetconEthernetTap::setFriendlyName(const char *friendlyName)
  185. {
  186. }
  187. void NetconEthernetTap::scanMulticastGroups(std::vector<MulticastGroup> &added,std::vector<MulticastGroup> &removed)
  188. {
  189. std::vector<MulticastGroup> newGroups;
  190. Mutex::Lock _l(_multicastGroups_m);
  191. // TODO: get multicast subscriptions from LWIP
  192. std::vector<InetAddress> allIps(ips());
  193. for(std::vector<InetAddress>::iterator ip(allIps.begin());ip!=allIps.end();++ip)
  194. newGroups.push_back(MulticastGroup::deriveMulticastGroupForAddressResolution(*ip));
  195. std::sort(newGroups.begin(),newGroups.end());
  196. std::unique(newGroups.begin(),newGroups.end());
  197. for(std::vector<MulticastGroup>::iterator m(newGroups.begin());m!=newGroups.end();++m) {
  198. if (!std::binary_search(_multicastGroups.begin(),_multicastGroups.end(),*m))
  199. added.push_back(*m);
  200. }
  201. for(std::vector<MulticastGroup>::iterator m(_multicastGroups.begin());m!=_multicastGroups.end();++m) {
  202. if (!std::binary_search(newGroups.begin(),newGroups.end(),*m))
  203. removed.push_back(*m);
  204. }
  205. _multicastGroups.swap(newGroups);
  206. }
  207. TcpConnection *NetconEthernetTap::getConnectionByPCB(struct tcp_pcb *pcb)
  208. {
  209. for(size_t i=0; i<tcp_connections.size(); i++) {
  210. if(tcp_connections[i]->pcb == pcb)
  211. return tcp_connections[i];
  212. }
  213. return NULL;
  214. }
  215. TcpConnection *NetconEthernetTap::getConnectionByTheirFD(PhySocket *sock, int fd)
  216. {
  217. for(size_t i=0; i<tcp_connections.size(); i++) {
  218. if(tcp_connections[i]->perceived_fd == fd && tcp_connections[i]->rpcSock == sock)
  219. return tcp_connections[i];
  220. }
  221. return NULL;
  222. }
  223. /*
  224. * Closes a TcpConnection and associated LWIP PCB strcuture.
  225. */
  226. void NetconEthernetTap::closeConnection(TcpConnection *conn)
  227. {
  228. //fprintf(stderr, "closeConnection(): closing: conn->type = %d, fd=%d\n", conn->type, _phy.getDescriptor(conn->sock));
  229. lwipstack->_tcp_arg(conn->pcb, NULL);
  230. lwipstack->_tcp_sent(conn->pcb, NULL);
  231. lwipstack->_tcp_recv(conn->pcb, NULL);
  232. lwipstack->_tcp_err(conn->pcb, NULL);
  233. lwipstack->_tcp_poll(conn->pcb, NULL, 0);
  234. lwipstack->_tcp_close(conn->pcb);
  235. close(_phy.getDescriptor(conn->dataSock));
  236. close(conn->their_fd);
  237. _phy.close(conn->dataSock);
  238. for(int i=0; i<tcp_connections.size(); i++) {
  239. if(tcp_connections[i] == conn) {
  240. tcp_connections.erase(tcp_connections.begin() + i);
  241. }
  242. }
  243. delete conn;
  244. }
  245. void NetconEthernetTap::closeClient(PhySocket *sock)
  246. {
  247. for(int i=0; i<rpc_sockets.size(); i++) {
  248. if(rpc_sockets[i] == sock)
  249. rpc_sockets.erase(rpc_sockets.begin() + i);
  250. }
  251. close(_phy.getDescriptor(sock));
  252. _phy.close(sock);
  253. }
  254. void NetconEthernetTap::closeAll()
  255. {
  256. while(rpc_sockets.size())
  257. closeClient(rpc_sockets.front());
  258. while(tcp_connections.size())
  259. closeConnection(tcp_connections.front());
  260. }
  261. #define ZT_LWIP_TCP_TIMER_INTERVAL 10
  262. void NetconEthernetTap::threadMain()
  263. throw()
  264. {
  265. fprintf(stderr, "_threadMain()\n");
  266. uint64_t prev_tcp_time = 0;
  267. uint64_t prev_etharp_time = 0;
  268. fprintf(stderr, "- MEM_SIZE = %dM\n", MEM_SIZE / (1024*1024));
  269. fprintf(stderr, "- TCP_SND_BUF = %dK\n", TCP_SND_BUF / 1024);
  270. fprintf(stderr, "- MEMP_NUM_PBUF = %d\n", MEMP_NUM_PBUF);
  271. fprintf(stderr, "- MEMP_NUM_TCP_PCB = %d\n", MEMP_NUM_TCP_PCB);
  272. fprintf(stderr, "- MEMP_NUM_TCP_PCB_LISTEN = %d\n", MEMP_NUM_TCP_PCB_LISTEN);
  273. fprintf(stderr, "- MEMP_NUM_TCP_SEG = %d\n", MEMP_NUM_TCP_SEG);
  274. fprintf(stderr, "- PBUF_POOL_SIZE = %d\n", PBUF_POOL_SIZE);
  275. fprintf(stderr, "- TCP_SND_QUEUELEN = %d\n", TCP_SND_QUEUELEN);
  276. fprintf(stderr, "- IP_REASSEMBLY = %d\n", IP_REASSEMBLY);
  277. fprintf(stderr, "- TCP_WND = %d\n", TCP_WND);
  278. fprintf(stderr, "- TCP_MSS = %d\n", TCP_MSS);
  279. fprintf(stderr, "- ARP_TMR_INTERVAL = %d\n", ARP_TMR_INTERVAL);
  280. fprintf(stderr, "- TCP_TMR_INTERVAL = %d\n", TCP_TMR_INTERVAL);
  281. fprintf(stderr, "- IP_TMR_INTERVAL = %d\n", IP_TMR_INTERVAL);
  282. // Main timer loop
  283. while (_run) {
  284. uint64_t now = OSUtils::now();
  285. uint64_t since_tcp = now - prev_tcp_time;
  286. uint64_t since_etharp = now - prev_etharp_time;
  287. uint64_t tcp_remaining = ZT_LWIP_TCP_TIMER_INTERVAL;
  288. uint64_t etharp_remaining = ARP_TMR_INTERVAL;
  289. if (since_tcp >= ZT_LWIP_TCP_TIMER_INTERVAL) {
  290. prev_tcp_time = now;
  291. lwipstack->tcp_tmr();
  292. } else {
  293. tcp_remaining = ZT_LWIP_TCP_TIMER_INTERVAL - since_tcp;
  294. }
  295. if (since_etharp >= ARP_TMR_INTERVAL) {
  296. prev_etharp_time = now;
  297. lwipstack->etharp_tmr();
  298. } else {
  299. etharp_remaining = ARP_TMR_INTERVAL - since_etharp;
  300. }
  301. _phy.poll((unsigned long)std::min(tcp_remaining,etharp_remaining));
  302. }
  303. closeAll();
  304. // TODO: cleanup -- destroy LWIP state, kill any clients, unload .so, etc.
  305. }
  306. void NetconEthernetTap::phyOnUnixClose(PhySocket *sock,void **uptr)
  307. {
  308. //fprintf(stderr, "phyOnUnixClose() CLOSING: %d\n", _phy.getDescriptor(sock));
  309. //closeClient(sock);
  310. // FIXME:
  311. }
  312. /*
  313. * Handles data on a client's data buffer. Data is sent to LWIP to be enqueued.
  314. */
  315. void NetconEthernetTap::phyOnFileDescriptorActivity(PhySocket *sock,void **uptr,bool readable,bool writable)
  316. {
  317. if(readable) {
  318. TcpConnection *conn = (TcpConnection*)*uptr;
  319. Mutex::Lock _l(lwipstack->_lock);
  320. handle_write(conn);
  321. }
  322. else {
  323. fprintf(stderr, "phyOnFileDescriptorActivity(): PhySocket not readable\n");
  324. }
  325. }
  326. // Unused -- no UDP or TCP from this thread/Phy<>
  327. void NetconEthernetTap::phyOnDatagram(PhySocket *sock,void **uptr,const struct sockaddr *from,void *data,unsigned long len) {}
  328. void NetconEthernetTap::phyOnTcpConnect(PhySocket *sock,void **uptr,bool success) {}
  329. void NetconEthernetTap::phyOnTcpAccept(PhySocket *sockL,PhySocket *sockN,void **uptrL,void **uptrN,const struct sockaddr *from) {}
  330. void NetconEthernetTap::phyOnTcpClose(PhySocket *sock,void **uptr) {}
  331. void NetconEthernetTap::phyOnTcpData(PhySocket *sock,void **uptr,void *data,unsigned long len) {}
  332. void NetconEthernetTap::phyOnTcpWritable(PhySocket *sock,void **uptr) {}
  333. /*
  334. * Add a new PhySocket for the client connection
  335. */
  336. void NetconEthernetTap::phyOnUnixAccept(PhySocket *sockL,PhySocket *sockN,void **uptrL,void **uptrN) {
  337. rpc_sockets.push_back(sockN);
  338. }
  339. /*
  340. * Processes incoming data on a client-specific RPC connection
  341. */
  342. void NetconEthernetTap::phyOnUnixData(PhySocket *sock,void **uptr,void *data,unsigned long len)
  343. {
  344. unsigned char *buf = (unsigned char*)data;
  345. switch(buf[0])
  346. {
  347. case RPC_SOCKET:
  348. fprintf(stderr, "RPC_SOCKET\n");
  349. struct socket_st socket_rpc;
  350. memcpy(&socket_rpc, &buf[1], sizeof(struct socket_st));
  351. handle_socket(sock, uptr, &socket_rpc);
  352. break;
  353. case RPC_LISTEN:
  354. fprintf(stderr, "RPC_LISTEN\n");
  355. struct listen_st listen_rpc;
  356. memcpy(&listen_rpc, &buf[1], sizeof(struct listen_st));
  357. handle_listen(sock, uptr, &listen_rpc);
  358. break;
  359. case RPC_BIND:
  360. fprintf(stderr, "RPC_BIND\n");
  361. struct bind_st bind_rpc;
  362. memcpy(&bind_rpc, &buf[1], sizeof(struct bind_st));
  363. handle_bind(sock, uptr, &bind_rpc);
  364. break;
  365. case RPC_KILL_INTERCEPT:
  366. fprintf(stderr, "RPC_KILL_INTERCEPT\n");
  367. //scloseClient(sock);
  368. break;
  369. case RPC_CONNECT:
  370. fprintf(stderr, "RPC_CONNECT\n");
  371. struct connect_st connect_rpc;
  372. memcpy(&connect_rpc, &buf[1], sizeof(struct connect_st));
  373. handle_connect(sock, uptr, &connect_rpc);
  374. break;
  375. case RPC_FD_MAP_COMPLETION:
  376. fprintf(stderr, "RPC_FD_MAP_COMPLETION\n");
  377. handle_retval(sock, uptr, buf);
  378. break;
  379. default:
  380. break;
  381. }
  382. }
  383. /*
  384. * Send a return value to the client for an RPC
  385. */
  386. int NetconEthernetTap::send_return_value(TcpConnection *conn, int retval, int _errno = 0)
  387. {
  388. if(conn) {
  389. int n = send_return_value(_phy.getDescriptor(conn->rpcSock), retval, _errno);
  390. if(n > 0)
  391. conn->pending = false;
  392. else {
  393. fprintf(stderr, "Unable to send return value to the intercept. Closing connection\n");
  394. closeConnection(conn);
  395. }
  396. return n;
  397. }
  398. return -1;
  399. }
  400. int NetconEthernetTap::send_return_value(int fd, int retval, int _errno = 0)
  401. {
  402. int sz = sizeof(char) + sizeof(retval) + sizeof(errno);
  403. char retmsg[sz];
  404. memset(&retmsg, '\0', sizeof(retmsg));
  405. retmsg[0]=RPC_RETVAL;
  406. memcpy(&retmsg[1], &retval, sizeof(retval));
  407. memcpy(&retmsg[1]+sizeof(retval), &_errno, sizeof(_errno));
  408. return write(fd, &retmsg, sz);
  409. }
  410. /*------------------------------------------------------------------------------
  411. --------------------------------- LWIP callbacks -------------------------------
  412. ------------------------------------------------------------------------------*/
  413. // NOTE: these are called from within LWIP, meaning that lwipstack->_lock is ALREADY
  414. // locked in this case!
  415. /*
  416. * Callback from LWIP for when a connection has been accepted and the PCB has been
  417. * put into an ACCEPT state.
  418. *
  419. * A socketpair is created, one end is kept and wrapped into a PhySocket object
  420. * for use in the main ZT I/O loop, and one end is sent to the client. The client
  421. * is then required to tell the service what new file descriptor it has allocated
  422. * for this connection. After the mapping is complete, the accepted socket can be
  423. * used.
  424. *
  425. * @param associated service state object
  426. * @param newly allocated PCB
  427. * @param error code
  428. * @return ERR_OK if everything is ok, -1 otherwise
  429. [ ] EAGAIN or EWOULDBLOCK - The socket is marked nonblocking and no connections are present
  430. to be accepted. POSIX.1-2001 allows either error to be returned for
  431. this case, and does not require these constants to have the same value,
  432. so a portable application should check for both possibilities.
  433. [ ] EBADF - The descriptor is invalid.
  434. [i] ECONNABORTED - A connection has been aborted.
  435. [i] EFAULT - The addr argument is not in a writable part of the user address space.
  436. [ ] EINTR - The system call was interrupted by a signal that was caught before a valid connection arrived; see signal(7).
  437. [ ] EINVAL - Socket is not listening for connections, or addrlen is invalid (e.g., is negative).
  438. [ ] EINVAL - (accept4()) invalid value in flags.
  439. [ ] EMFILE - The per-process limit of open file descriptors has been reached.
  440. [ ] ENFILE - The system limit on the total number of open files has been reached.
  441. [ ] ENOBUFS, ENOMEM - Not enough free memory. This often means that the memory allocation is
  442. limited by the socket buffer limits, not by the system memory.
  443. [i] ENOTSOCK - The descriptor references a file, not a socket.
  444. [i] EOPNOTSUPP - The referenced socket is not of type SOCK_STREAM.
  445. [ ] EPROTO - Protocol error.
  446. *
  447. */
  448. err_t NetconEthernetTap::nc_accept(void *arg, struct tcp_pcb *newpcb, err_t err)
  449. {
  450. fprintf(stderr, "nc_accept()\n");
  451. Larg *l = (Larg*)arg;
  452. TcpConnection *conn = l->conn;
  453. NetconEthernetTap *tap = l->tap;
  454. int larg_fd = tap->_phy.getDescriptor(conn->dataSock);
  455. if(conn) {
  456. ZT_PHY_SOCKFD_TYPE fds[2];
  457. socketpair(PF_LOCAL, SOCK_STREAM, 0, fds);
  458. TcpConnection *new_tcp_conn = new TcpConnection();
  459. new_tcp_conn->dataSock = tap->_phy.wrapSocket(fds[0], new_tcp_conn);
  460. new_tcp_conn->rpcSock = conn->rpcSock;
  461. new_tcp_conn->pcb = newpcb;
  462. new_tcp_conn->their_fd = fds[1];
  463. tap->tcp_connections.push_back(new_tcp_conn);
  464. int send_fd = tap->_phy.getDescriptor(conn->rpcSock);
  465. int n = write(larg_fd, "z", 1); // accept() in library waits for this byte
  466. if(n > 0) {
  467. if(sock_fd_write(send_fd, fds[1]) > 0) {
  468. new_tcp_conn->pending = true;
  469. }
  470. else {
  471. fprintf(stderr, "nc_accept(%d): unable to send fd to client\n", larg_fd);
  472. }
  473. }
  474. else {
  475. fprintf(stderr, "nc_accept(%d): error writing signal byte (send_fd = %d, perceived_fd = %d)\n", larg_fd, send_fd, fds[1]);
  476. return -1;
  477. }
  478. tap->lwipstack->_tcp_arg(newpcb, new Larg(tap, new_tcp_conn));
  479. tap->lwipstack->_tcp_recv(newpcb, nc_recved);
  480. tap->lwipstack->_tcp_err(newpcb, nc_err);
  481. tap->lwipstack->_tcp_sent(newpcb, nc_sent);
  482. tap->lwipstack->_tcp_poll(newpcb, nc_poll, 0.5);
  483. tcp_accepted(conn->pcb); // Let lwIP know that it can queue additional incoming connections
  484. return ERR_OK;
  485. }
  486. else {
  487. fprintf(stderr, "nc_accept(%d): can't locate Connection object for PCB.\n", larg_fd);
  488. }
  489. return -1;
  490. }
  491. /*
  492. * Callback from LWIP for when data is available to be read from the network.
  493. *
  494. * Data is in the form of a linked list of struct pbufs, it is then recombined and
  495. * send to the client over the associated unix socket.
  496. *
  497. * @param associated service state object
  498. * @param allocated PCB
  499. * @param chain of pbufs
  500. * @param error code
  501. * @return ERR_OK if everything is ok, -1 otherwise
  502. *
  503. */
  504. err_t NetconEthernetTap::nc_recved(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err)
  505. {
  506. fprintf(stderr, "nc_recved()\n");
  507. Larg *l = (Larg*)arg;
  508. int n;
  509. struct pbuf* q = p;
  510. if(!l->conn) {
  511. fprintf(stderr, "nc_recved(): no connection object\n");
  512. return ERR_OK; // ?
  513. }
  514. if(p == NULL) {
  515. if(l->conn) {
  516. fprintf(stderr, "nc_recved(): closing connection\n");
  517. l->tap->closeConnection(l->conn);
  518. }
  519. else {
  520. fprintf(stderr, "nc_recved(): can't locate connection via (arg)\n");
  521. }
  522. return err;
  523. }
  524. q = p;
  525. while(p != NULL) { // Cycle through pbufs and write them to the socket
  526. if(p->len <= 0)
  527. break; // ?
  528. if((n = l->tap->_phy.streamSend(l->conn->dataSock,p->payload, p->len)) > 0) {
  529. if(n < p->len) {
  530. fprintf(stderr, "nc_recved(): unable to write entire pbuf to buffer\n");
  531. }
  532. l->tap->lwipstack->_tcp_recved(tpcb, n); // TODO: would it be more efficient to call this once at the end?
  533. }
  534. else {
  535. fprintf(stderr, "nc_recved(): No data written to intercept buffer\n");
  536. }
  537. p = p->next;
  538. }
  539. l->tap->lwipstack->_pbuf_free(q); // free pbufs
  540. return ERR_OK;
  541. }
  542. /*
  543. * Callback from LWIP when an internal error is associtated with the given (arg)
  544. *
  545. * Since the PCB related to this error might no longer exist, only its perviously
  546. * associated (arg) is provided to us.
  547. *
  548. * @param associated service state object
  549. * @param error code
  550. *
  551. */
  552. void NetconEthernetTap::nc_err(void *arg, err_t err)
  553. {
  554. Larg *l = (Larg*)arg;
  555. fprintf(stderr, "larg = %x, nc_err() = %d\n", l, err);
  556. if(l->conn) {
  557. switch(err)
  558. {
  559. // FIXME: Check if connection is pending first?
  560. case ERR_MEM:
  561. l->tap->send_return_value(l->conn, -1, ENOMEM);
  562. break;
  563. case ERR_BUF:
  564. // FIXME: From user's perspective, this is the same as an ENOMEM error. I think.
  565. l->tap->send_return_value(l->conn, -1, ENOMEM);
  566. break;
  567. case ERR_TIMEOUT:
  568. l->tap->send_return_value(l->conn, -1, ETIMEDOUT);
  569. break;
  570. case ERR_RTE:
  571. l->tap->send_return_value(l->conn, -1, ENETUNREACH);
  572. break;
  573. case ERR_INPROGRESS:
  574. l->tap->send_return_value(l->conn, -1, EINPROGRESS);
  575. break;
  576. case ERR_VAL:
  577. l->tap->send_return_value(l->conn, -1, EINVAL);
  578. break;
  579. case ERR_WOULDBLOCK:
  580. l->tap->send_return_value(l->conn, -1, EWOULDBLOCK);
  581. break;
  582. case ERR_USE:
  583. l->tap->send_return_value(l->conn, -1, EADDRINUSE);
  584. break;
  585. case ERR_ISCONN:
  586. l->tap->send_return_value(l->conn, -1, EISCONN);
  587. break;
  588. // FIXME: Below are errors which don't have a standard errno correlate
  589. case ERR_ABRT:
  590. l->tap->send_return_value(l->conn, -1, -1);
  591. break;
  592. case ERR_RST:
  593. l->tap->send_return_value(l->conn, -1, -1);
  594. break;
  595. case ERR_CLSD:
  596. l->tap->send_return_value(l->conn, -1, -1);
  597. break;
  598. case ERR_CONN:
  599. l->tap->send_return_value(l->conn, -1, -1);
  600. break;
  601. case ERR_ARG:
  602. l->tap->send_return_value(l->conn, -1, -1);
  603. break;
  604. case ERR_IF:
  605. l->tap->send_return_value(l->conn, -1, -1);
  606. break;
  607. default:
  608. break;
  609. }
  610. fprintf(stderr, "nc_err(): closing connection\n");
  611. l->tap->closeConnection(l->conn);
  612. }
  613. else {
  614. fprintf(stderr, "nc_err(): can't locate connection object for PCB\n");
  615. }
  616. }
  617. /*
  618. * Callback from LWIP to do whatever work we might need to do.
  619. *
  620. * @param associated service state object
  621. * @param PCB we're polling on
  622. * @return ERR_OK if everything is ok, -1 otherwise
  623. *
  624. */
  625. err_t NetconEthernetTap::nc_poll(void* arg, struct tcp_pcb *tpcb)
  626. {
  627. uint64_t now = OSUtils::now();
  628. //fprintf(stderr, "nc_poll(): now = %u\n", now);
  629. //fprintf(stderr, "nc_poll\n");
  630. Larg *l = (Larg*)arg;
  631. TcpConnection *conn = l->conn;
  632. NetconEthernetTap *tap = l->tap;
  633. if(conn && conn->idx) // if valid connection and non-zero index (indicating data present)
  634. tap->handle_write(conn);
  635. return ERR_OK;
  636. }
  637. /*
  638. * Callback from LWIP to signal that 'len' bytes have successfully been sent.
  639. * As a result, we should put our socket back into a notify-on-readability state
  640. * since there is now room on the PCB buffer to write to.
  641. *
  642. * NOTE: This could be used to track the amount of data sent by a connection.
  643. *
  644. * @param associated service state object
  645. * @param relevant PCB
  646. * @param length of data sent
  647. * @return ERR_OK if everything is ok, -1 otherwise
  648. *
  649. */
  650. err_t NetconEthernetTap::nc_sent(void* arg, struct tcp_pcb *tpcb, u16_t len)
  651. {
  652. Larg *l = (Larg*)arg;
  653. if(len) {
  654. //fprintf(stderr, "ACKING len = %d, setting read-notify = true, (sndbuf = %d)\n", len, l->conn->pcb->snd_buf);
  655. l->tap->_phy.setNotifyReadable(l->conn->dataSock, true);
  656. //uint64_t now = OSUtils::now();
  657. //fprintf(stderr, "nc_sent(): now = %u\n", now);
  658. l->tap->_phy.whack();
  659. //l->tap->handle_write(l->conn);
  660. }
  661. return ERR_OK;
  662. }
  663. /*
  664. * Callback from LWIP which sends a return value to the client to signal that
  665. * a connection was established for this PCB
  666. *
  667. * @param associated service state object
  668. * @param relevant PCB
  669. * @param error code
  670. * @return ERR_OK if everything is ok, -1 otherwise
  671. *
  672. */
  673. err_t NetconEthernetTap::nc_connected(void *arg, struct tcp_pcb *tpcb, err_t err)
  674. {
  675. //fprintf(stderr, "nc_connected\n");
  676. Larg *l = (Larg*)arg;
  677. l->tap->send_return_value(l->conn, err);
  678. return ERR_OK;
  679. }
  680. /*------------------------------------------------------------------------------
  681. ----------------------------- RPC Handler functions ----------------------------
  682. ------------------------------------------------------------------------------*/
  683. /*
  684. * Handles an RPC to bind an LWIP PCB to a given address and port
  685. *
  686. * @param Client that is making the RPC
  687. * @param structure containing the data and parameters for this client's RPC
  688. *
  689. [ ] EACCES - The address is protected, and the user is not the superuser.
  690. [X] EADDRINUSE - The given address is already in use.
  691. [X] EBADF - sockfd is not a valid descriptor.
  692. [X] EINVAL - The socket is already bound to an address.
  693. [ ] ENOTSOCK - sockfd is a descriptor for a file, not a socket.
  694. [ ] The following errors are specific to UNIX domain (AF_UNIX) sockets:
  695. [ ] EACCES - Search permission is denied on a component of the path prefix. (See also path_resolution(7).)
  696. [ ] EADDRNOTAVAIL - A nonexistent interface was requested or the requested address was not local.
  697. [ ] EFAULT - addr points outside the user's accessible address space.
  698. [ ] EINVAL - The addrlen is wrong, or the socket was not in the AF_UNIX family.
  699. [ ] ELOOP - Too many symbolic links were encountered in resolving addr.
  700. [ ] ENAMETOOLONG - s addr is too long.
  701. [ ] ENOENT - The file does not exist.
  702. [X] ENOMEM - Insufficient kernel memory was available.
  703. [ ] ENOTDIR - A component of the path prefix is not a directory.
  704. [ ] EROFS - The socket inode would reside on a read-only file system.
  705. */
  706. void NetconEthernetTap::handle_bind(PhySocket *sock, void **uptr, struct bind_st *bind_rpc)
  707. {
  708. struct sockaddr_in *connaddr;
  709. connaddr = (struct sockaddr_in *) &bind_rpc->addr;
  710. int conn_port = lwipstack->ntohs(connaddr->sin_port);
  711. ip_addr_t conn_addr;
  712. conn_addr.addr = *((u32_t *)_ips[0].rawIpData());
  713. TcpConnection *conn = getConnectionByTheirFD(sock, bind_rpc->sockfd);
  714. if(conn) {
  715. if(conn->pcb->state == CLOSED){
  716. int err = lwipstack->tcp_bind(conn->pcb, &conn_addr, conn_port);
  717. if(err != ERR_OK) {
  718. int ip = connaddr->sin_addr.s_addr;
  719. unsigned char d[4];
  720. d[0] = ip & 0xFF;
  721. d[1] = (ip >> 8) & 0xFF;
  722. d[2] = (ip >> 16) & 0xFF;
  723. d[3] = (ip >> 24) & 0xFF;
  724. fprintf(stderr, "handle_bind(): error binding to %d.%d.%d.%d : %d\n", d[0],d[1],d[2],d[3], conn_port);
  725. if(err == ERR_USE)
  726. send_return_value(conn, -1, EADDRINUSE);
  727. if(err == ERR_MEM)
  728. send_return_value(conn, -1, ENOMEM); // FIXME: Likely won't happen
  729. if(err == ERR_BUF)
  730. send_return_value(conn, -1, ENOMEM);
  731. }
  732. else {
  733. send_return_value(conn, ERR_OK, ERR_OK); // Success
  734. }
  735. }
  736. else {
  737. fprintf(stderr, "handle_bind(): PCB not in CLOSED state. Ignoring BIND request.\n");
  738. send_return_value(conn, -1, EINVAL);
  739. }
  740. }
  741. else {
  742. fprintf(stderr, "handle_bind(): can't locate connection for PCB\n");
  743. send_return_value(conn, -1, EBADF); // FIXME: This makes no sense
  744. }
  745. }
  746. /*
  747. * Handles an RPC to put an LWIP PCB into LISTEN mode
  748. *
  749. * @param Client that is making the RPC
  750. * @param structure containing the data and parameters for this client's RPC
  751. *
  752. [ ] EADDRINUSE - Another socket is already listening on the same port.
  753. [X] EBADF - The argument sockfd is not a valid descriptor.
  754. [ ] ENOTSOCK - The argument sockfd is not a socket.
  755. [ ] EOPNOTSUPP - The socket is not of a type that supports the listen() operation.
  756. */
  757. void NetconEthernetTap::handle_listen(PhySocket *sock, void **uptr, struct listen_st *listen_rpc)
  758. {
  759. TcpConnection *conn = getConnectionByTheirFD(sock, listen_rpc->sockfd);
  760. if(conn) {
  761. if(conn->pcb->state == LISTEN) {
  762. fprintf(stderr, "handle_listen(): PCB is already in listening state.\n");
  763. return;
  764. }
  765. struct tcp_pcb* listening_pcb = lwipstack->tcp_listen(conn->pcb);
  766. if(listening_pcb != NULL) {
  767. conn->pcb = listening_pcb;
  768. lwipstack->tcp_accept(listening_pcb, nc_accept);
  769. lwipstack->tcp_arg(listening_pcb, new Larg(this, conn));
  770. /* we need to wait for the client to send us the fd allocated on their end
  771. for this listening socket */
  772. conn->pending = true;
  773. send_return_value(conn, ERR_OK, ERR_OK);
  774. }
  775. else {
  776. fprintf(stderr, "handle_listen(): unable to allocate memory for new listening PCB\n");
  777. send_return_value(conn, -1, ENOMEM); // FIXME: This does not have an equivalent errno value
  778. }
  779. }
  780. else {
  781. fprintf(stderr, "handle_listen(): can't locate connection for PCB\n");
  782. send_return_value(conn, -1, EBADF);
  783. }
  784. }
  785. /**
  786. * Handles a return value (client's perceived fd) and completes a mapping
  787. * so that we know what connection an RPC call should be associated with.
  788. *
  789. * @param Client that is making the RPC
  790. * @param structure containing the data and parameters for this client's RPC
  791. *
  792. */
  793. void NetconEthernetTap::handle_retval(PhySocket *sock, void **uptr, unsigned char* buf)
  794. {
  795. TcpConnection *conn = (TcpConnection*)*uptr;
  796. if(conn->pending) {
  797. memcpy(&(conn->perceived_fd), &buf[1], sizeof(int));
  798. //fprintf(stderr, "handle_retval(): Mapping [our=%d -> their=%d]\n",
  799. //_phy.getDescriptor(conn->dataSock), conn->perceived_fd);
  800. conn->pending = false;
  801. }
  802. }
  803. /*
  804. * Handles an RPC to create a socket (LWIP PCB and associated socketpair)
  805. *
  806. * A socketpair is created, one end is kept and wrapped into a PhySocket object
  807. * for use in the main ZT I/O loop, and one end is sent to the client. The client
  808. * is then required to tell the service what new file descriptor it has allocated
  809. * for this connection. After the mapping is complete, the socket can be used.
  810. *
  811. * @param Client that is making the RPC
  812. * @param structure containing the data and parameters for this client's RPC
  813. *
  814. TODO: set errno appropriately
  815. [ ] EACCES - Permission to create a socket of the specified type and/or protocol is denied.
  816. [?] EAFNOSUPPORT - The implementation does not support the specified address family.
  817. [?] EINVAL - Unknown protocol, or protocol family not available.
  818. [?] EINVAL - Invalid flags in type.
  819. [ ] EMFILE - Process file table overflow.
  820. [ ] ENFILE - The system limit on the total number of open files has been reached.
  821. [X] ENOBUFS or ENOMEM - Insufficient memory is available. The socket cannot be created until sufficient resources are freed.
  822. [ ] EPROTONOSUPPORT - The protocol type or the specified protocol is not supported within this domain.
  823. */
  824. void NetconEthernetTap::handle_socket(PhySocket *sock, void **uptr, struct socket_st* socket_rpc)
  825. {
  826. struct tcp_pcb *newpcb = lwipstack->tcp_new();
  827. if(newpcb != NULL) {
  828. ZT_PHY_SOCKFD_TYPE fds[2];
  829. socketpair(PF_LOCAL, SOCK_STREAM, 0, fds);
  830. TcpConnection *new_conn = new TcpConnection();
  831. new_conn->dataSock = _phy.wrapSocket(fds[0], new_conn);
  832. *uptr = new_conn;
  833. new_conn->rpcSock = sock;
  834. new_conn->pcb = newpcb;
  835. new_conn->their_fd = fds[1];
  836. tcp_connections.push_back(new_conn);
  837. sock_fd_write(_phy.getDescriptor(sock), fds[1]);
  838. // Once the client tells us what its fd is for the other end, we can then complete the mapping
  839. new_conn->pending = true;
  840. }
  841. else {
  842. int rpc_fd = _phy.getDescriptor(sock);
  843. sock_fd_write(rpc_fd, -1); // Send a bad fd, to signal error
  844. fprintf(stderr, "handle_socket(): Memory not available for new PCB\n");
  845. if(send_return_value(rpc_fd, -1, ENOMEM) < 0) {
  846. fprintf(stderr, "handle_socket(): Unable to send return value\n");
  847. }
  848. }
  849. }
  850. /*
  851. * Handles an RPC to connect to a given address and port
  852. *
  853. * @param Client that is making the RPC
  854. * @param structure containing the data and parameters for this client's RPC
  855. --- Error handling in this method will only catch problems which are immeidately
  856. apprent. Some errors will need to be caught in the nc_connected(0 callback
  857. [i] EACCES - For UNIX domain sockets, which are identified by pathname: Write permission is denied ...
  858. [ ] EACCES, EPERM - The user tried to connect to a broadcast address without having the socket broadcast flag enabled ...
  859. [i] EADDRINUSE - Local address is already in use.
  860. [?] EAFNOSUPPORT - The passed address didn't have the correct address family in its sa_family field.
  861. [ ] EAGAIN - No more free local ports or insufficient entries in the routing cache.
  862. [ ] EALREADY - The socket is nonblocking and a previous connection attempt has not yet been completed.
  863. [ ] EBADF - The file descriptor is not a valid index in the descriptor table.
  864. [ ] ECONNREFUSED - No-one listening on the remote address.
  865. [i] EFAULT - The socket structure address is outside the user's address space.
  866. [ ] EINPROGRESS - The socket is nonblocking and the connection cannot be completed immediately.
  867. [ ] EINTR - The system call was interrupted by a signal that was caught.
  868. [X] EISCONN - The socket is already connected.
  869. [?] ENETUNREACH - Network is unreachable.
  870. [ ] ENOTSOCK - The file descriptor is not associated with a socket.
  871. [ ] ETIMEDOUT - Timeout while attempting connection.
  872. *
  873. */
  874. void NetconEthernetTap::handle_connect(PhySocket *sock, void **uptr, struct connect_st* connect_rpc)
  875. {
  876. TcpConnection *conn = (TcpConnection*)*uptr;
  877. struct sockaddr_in *connaddr;
  878. connaddr = (struct sockaddr_in *) &connect_rpc->__addr;
  879. int conn_port = lwipstack->ntohs(connaddr->sin_port);
  880. ip_addr_t conn_addr = convert_ip((struct sockaddr_in *)&connect_rpc->__addr);
  881. if(conn != NULL) {
  882. lwipstack->tcp_sent(conn->pcb, nc_sent); // FIXME: Move?
  883. lwipstack->tcp_recv(conn->pcb, nc_recved);
  884. lwipstack->tcp_err(conn->pcb, nc_err);
  885. lwipstack->tcp_poll(conn->pcb, nc_poll, APPLICATION_POLL_FREQ);
  886. lwipstack->tcp_arg(conn->pcb, new Larg(this, conn));
  887. int err = 0;
  888. if((err = lwipstack->tcp_connect(conn->pcb,&conn_addr,conn_port, nc_connected)) < 0)
  889. {
  890. if(err == ERR_USE) {
  891. send_return_value(conn, -1, EISCONN); // Already in use
  892. return;
  893. }
  894. if(err == ERR_VAL) {
  895. send_return_value(conn, -1, EAFNOSUPPORT); // FIXME: Invalid arguments?
  896. return;
  897. }
  898. if(err == ERR_RTE) {
  899. send_return_value(conn, -1, ENETUNREACH); // FIXME: Host unreachable
  900. return;
  901. }
  902. if(err == ERR_BUF)
  903. {
  904. // FIXME
  905. }
  906. if(err == ERR_MEM)
  907. {
  908. // FIXME: return value originates from tcp_enqueue_flags()
  909. }
  910. // We should only return a value if failure happens immediately
  911. // Otherwise, we still need to wait for a callback from lwIP.
  912. // - This is because an ERR_OK from tcp_connect() only verifies
  913. // that the SYN packet was enqueued onto the stack properly,
  914. // that's it!
  915. // - Most instances of a retval for a connect() should happen
  916. // in the nc_connect() and nc_err() callbacks!
  917. fprintf(stderr, "handle_connect(): unable to connect\n");
  918. send_return_value(conn, -1, err); // FIXME: Only catch unhandled errors
  919. }
  920. // Everything seems to be ok, but we don't have enough info to retval
  921. conn->pending=true;
  922. }
  923. else {
  924. fprintf(stderr, "could not locate PCB based on their fd\n");
  925. }
  926. }
  927. void NetconEthernetTap::handle_write(TcpConnection *conn)
  928. {
  929. float max = (float)TCP_SND_BUF;
  930. int r;
  931. if(!conn) {
  932. fprintf(stderr, "handle_write(): could not locate connection for this fd\n");
  933. return;
  934. }
  935. if(conn->idx < max) {
  936. int sndbuf = conn->pcb->snd_buf; // How much we are currently allowed to write to the connection
  937. /* PCB send buffer is full,turn off readability notifications for the
  938. corresponding PhySocket until nc_sent() is called and confirms that there is
  939. now space on the buffer */
  940. if(sndbuf == 0) {
  941. _phy.setNotifyReadable(conn->dataSock, false);
  942. lwipstack->_tcp_output(conn->pcb);
  943. return;
  944. }
  945. int read_fd = _phy.getDescriptor(conn->dataSock);
  946. if((r = read(read_fd, (&conn->buf)+conn->idx, sndbuf)) > 0) {
  947. conn->idx += r;
  948. /* Writes data pulled from the client's socket buffer to LWIP. This merely sends the
  949. * data to LWIP to be enqueued and eventually sent to the network. */
  950. if(r > 0) {
  951. int sz;
  952. // NOTE: this assumes that lwipstack->_lock is locked, either
  953. // because we are in a callback or have locked it manually.
  954. int err = lwipstack->_tcp_write(conn->pcb, &conn->buf, r, TCP_WRITE_FLAG_COPY);
  955. if(err != ERR_OK) {
  956. fprintf(stderr, "handle_write(): error while writing to PCB\n");
  957. return;
  958. }
  959. else {
  960. sz = (conn->idx)-r;
  961. if(sz) {
  962. memmove(&conn->buf, (conn->buf+r), sz);
  963. }
  964. conn->idx -= r;
  965. return;
  966. }
  967. }
  968. else {
  969. fprintf(stderr, "handle_write(): LWIP stack full\n");
  970. return;
  971. }
  972. }
  973. }
  974. }
  975. } // namespace ZeroTier
  976. #endif // ZT_ENABLE_NETCON