LinuxEthernetTap.cpp 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560
  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: 2025-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. #ifdef __GNUC__
  14. #pragma GCC diagnostic ignored "-Wrestrict"
  15. #endif
  16. #include "../node/Constants.hpp"
  17. #ifdef __LINUX__
  18. #include "../node/Utils.hpp"
  19. #include "../node/Mutex.hpp"
  20. #include "../node/Dictionary.hpp"
  21. #include "OSUtils.hpp"
  22. #include "LinuxEthernetTap.hpp"
  23. #include "LinuxNetLink.hpp"
  24. #include <stdint.h>
  25. #include <stdio.h>
  26. #include <stdlib.h>
  27. #include <string.h>
  28. #include <unistd.h>
  29. #include <signal.h>
  30. #include <fcntl.h>
  31. #include <errno.h>
  32. #include <sys/types.h>
  33. #include <sys/stat.h>
  34. #include <sys/ioctl.h>
  35. #include <sys/wait.h>
  36. #include <sys/select.h>
  37. #include <netinet/in.h>
  38. #include <net/if_arp.h>
  39. #include <arpa/inet.h>
  40. #include <linux/if.h>
  41. #include <linux/if_tun.h>
  42. #include <linux/if_addr.h>
  43. #include <linux/if_ether.h>
  44. #include <ifaddrs.h>
  45. #include <algorithm>
  46. #include <utility>
  47. #include <string>
  48. #ifndef IFNAMSIZ
  49. #define IFNAMSIZ 16
  50. #endif
  51. #define ZT_TAP_BUF_SIZE 16384
  52. // ff:ff:ff:ff:ff:ff with no ADI
  53. static const ZeroTier::MulticastGroup _blindWildcardMulticastGroup(ZeroTier::MAC(0xff),0);
  54. namespace ZeroTier {
  55. static const char _base32_chars[32] = { 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','2','3','4','5','6','7' };
  56. static void _base32_5_to_8(const uint8_t *in,char *out)
  57. {
  58. out[0] = _base32_chars[(in[0]) >> 3];
  59. out[1] = _base32_chars[(in[0] & 0x07) << 2 | (in[1] & 0xc0) >> 6];
  60. out[2] = _base32_chars[(in[1] & 0x3e) >> 1];
  61. out[3] = _base32_chars[(in[1] & 0x01) << 4 | (in[2] & 0xf0) >> 4];
  62. out[4] = _base32_chars[(in[2] & 0x0f) << 1 | (in[3] & 0x80) >> 7];
  63. out[5] = _base32_chars[(in[3] & 0x7c) >> 2];
  64. out[6] = _base32_chars[(in[3] & 0x03) << 3 | (in[4] & 0xe0) >> 5];
  65. out[7] = _base32_chars[(in[4] & 0x1f)];
  66. }
  67. LinuxEthernetTap::LinuxEthernetTap(
  68. const char *homePath,
  69. const MAC &mac,
  70. unsigned int mtu,
  71. unsigned int metric,
  72. uint64_t nwid,
  73. const char *friendlyName,
  74. void (*handler)(void *,void *,uint64_t,const MAC &,const MAC &,unsigned int,unsigned int,const void *,unsigned int),
  75. void *arg) :
  76. _handler(handler),
  77. _arg(arg),
  78. _nwid(nwid),
  79. _mac(mac),
  80. _homePath(homePath),
  81. _mtu(mtu),
  82. _fd(0),
  83. _enabled(true)
  84. {
  85. static std::mutex s_tapCreateLock;
  86. char procpath[128],nwids[32];
  87. struct stat sbuf;
  88. // Create only one tap at a time globally.
  89. std::lock_guard<std::mutex> tapCreateLock(s_tapCreateLock);
  90. // Make sure Linux netlink is initialized.
  91. (void)LinuxNetLink::getInstance();
  92. OSUtils::ztsnprintf(nwids,sizeof(nwids),"%.16llx",nwid);
  93. _fd = ::open("/dev/net/tun",O_RDWR);
  94. if (_fd <= 0) {
  95. _fd = ::open("/dev/tun",O_RDWR);
  96. if (_fd <= 0)
  97. throw std::runtime_error(std::string("could not open TUN/TAP device: ") + strerror(errno));
  98. }
  99. struct ifreq ifr;
  100. memset(&ifr,0,sizeof(ifr));
  101. // Restore device names from legacy devicemap, but for new devices we use a base32-based
  102. // canonical device name.
  103. std::map<std::string,std::string> globalDeviceMap;
  104. FILE *devmapf = fopen((_homePath + ZT_PATH_SEPARATOR_S + "devicemap").c_str(),"r");
  105. if (devmapf) {
  106. char buf[256];
  107. while (fgets(buf,sizeof(buf),devmapf)) {
  108. char *x = (char *)0;
  109. char *y = (char *)0;
  110. char *saveptr = (char *)0;
  111. for(char *f=Utils::stok(buf,"\r\n=",&saveptr);(f);f=Utils::stok((char *)0,"\r\n=",&saveptr)) {
  112. if (!x) x = f;
  113. else if (!y) y = f;
  114. else break;
  115. }
  116. if ((x)&&(y)&&(x[0])&&(y[0]))
  117. globalDeviceMap[x] = y;
  118. }
  119. fclose(devmapf);
  120. }
  121. bool recalledDevice = false;
  122. std::map<std::string,std::string>::const_iterator gdmEntry = globalDeviceMap.find(nwids);
  123. if (gdmEntry != globalDeviceMap.end()) {
  124. Utils::scopy(ifr.ifr_name,sizeof(ifr.ifr_name),gdmEntry->second.c_str());
  125. OSUtils::ztsnprintf(procpath,sizeof(procpath),"/proc/sys/net/ipv4/conf/%s",ifr.ifr_name);
  126. recalledDevice = (stat(procpath,&sbuf) != 0);
  127. }
  128. if (!recalledDevice) {
  129. #ifdef __SYNOLOGY__
  130. int devno = 50;
  131. do {
  132. OSUtils::ztsnprintf(ifr.ifr_name,sizeof(ifr.ifr_name),"eth%d",devno++);
  133. OSUtils::ztsnprintf(procpath,sizeof(procpath),"/proc/sys/net/ipv4/conf/%s",ifr.ifr_name);
  134. } while (stat(procpath,&sbuf) == 0); // try zt#++ until we find one that does not exist
  135. #else
  136. uint64_t trial = 0; // incremented in the very unlikely event of a name collision with another network
  137. do {
  138. const uint64_t nwid40 = (nwid ^ (nwid >> 24)) + trial++;
  139. uint8_t tmp2[5];
  140. char tmp3[11];
  141. tmp2[0] = (uint8_t)((nwid40 >> 32) & 0xff);
  142. tmp2[1] = (uint8_t)((nwid40 >> 24) & 0xff);
  143. tmp2[2] = (uint8_t)((nwid40 >> 16) & 0xff);
  144. tmp2[3] = (uint8_t)((nwid40 >> 8) & 0xff);
  145. tmp2[4] = (uint8_t)(nwid40 & 0xff);
  146. tmp3[0] = 'z';
  147. tmp3[1] = 't';
  148. _base32_5_to_8(tmp2,tmp3 + 2);
  149. tmp3[10] = (char)0;
  150. memcpy(ifr.ifr_name,tmp3,11);
  151. OSUtils::ztsnprintf(procpath,sizeof(procpath),"/proc/sys/net/ipv4/conf/%s",ifr.ifr_name);
  152. } while (stat(procpath,&sbuf) == 0);
  153. #endif
  154. }
  155. ifr.ifr_flags = IFF_TAP | IFF_NO_PI;
  156. if (ioctl(_fd,TUNSETIFF,(void *)&ifr) < 0) {
  157. ::close(_fd);
  158. throw std::runtime_error("unable to configure TUN/TAP device for TAP operation");
  159. }
  160. ::ioctl(_fd,TUNSETPERSIST,0); // valgrind may generate a false alarm here
  161. _dev = ifr.ifr_name;
  162. ::fcntl(_fd,F_SETFD,fcntl(_fd,F_GETFD) | FD_CLOEXEC);
  163. (void)::pipe(_shutdownSignalPipe);
  164. for(unsigned int t=0;t<2;++t) {
  165. _tapReaderThread[t] = std::thread([this, t]{
  166. fd_set readfds,nullfds;
  167. int n,nfds,r;
  168. void *buf = nullptr;
  169. std::vector<void *> buffers;
  170. if (t == 0) {
  171. struct ifreq ifr;
  172. memset(&ifr,0,sizeof(ifr));
  173. strcpy(ifr.ifr_name,_dev.c_str());
  174. const int sock = socket(AF_INET,SOCK_DGRAM,0);
  175. if (sock <= 0)
  176. return;
  177. if (ioctl(sock,SIOCGIFFLAGS,(void *)&ifr) < 0) {
  178. ::close(sock);
  179. printf("WARNING: ioctl() failed setting up Linux tap device (bring interface up)\n");
  180. return;
  181. }
  182. ifr.ifr_flags |= IFF_UP;
  183. if (ioctl(sock,SIOCSIFFLAGS,(void *)&ifr) < 0) {
  184. ::close(sock);
  185. printf("WARNING: ioctl() failed setting up Linux tap device (bring interface up)\n");
  186. return;
  187. }
  188. // Some kernel versions seem to require you to yield while the device comes up
  189. // before they will accept MTU and MAC. For others it doesn't matter, but is
  190. // harmless. This was moved to the worker thread though so as not to block the
  191. // main ZeroTier loop.
  192. usleep(500000);
  193. ifr.ifr_ifru.ifru_hwaddr.sa_family = ARPHRD_ETHER;
  194. _mac.copyTo(ifr.ifr_ifru.ifru_hwaddr.sa_data,6);
  195. if (ioctl(sock,SIOCSIFHWADDR,(void *)&ifr) < 0) {
  196. ::close(sock);
  197. printf("WARNING: ioctl() failed setting up Linux tap device (set MAC)\n");
  198. return;
  199. }
  200. ifr.ifr_ifru.ifru_mtu = (int)_mtu;
  201. if (ioctl(sock,SIOCSIFMTU,(void *)&ifr) < 0) {
  202. ::close(sock);
  203. printf("WARNING: ioctl() failed setting up Linux tap device (set MTU)\n");
  204. return;
  205. }
  206. fcntl(_fd,F_SETFL,O_NONBLOCK);
  207. ::close(sock);
  208. } else {
  209. usleep(1500000);
  210. }
  211. FD_ZERO(&readfds);
  212. FD_ZERO(&nullfds);
  213. nfds = (int)std::max(_shutdownSignalPipe[0],_fd) + 1;
  214. r = 0;
  215. for(;;) {
  216. FD_SET(_shutdownSignalPipe[0],&readfds);
  217. FD_SET(_fd,&readfds);
  218. select(nfds,&readfds,&nullfds,&nullfds,(struct timeval *)0);
  219. if (FD_ISSET(_shutdownSignalPipe[0],&readfds)) // writes to shutdown pipe terminate thread
  220. break;
  221. if (FD_ISSET(_fd,&readfds)) {
  222. for(;;) { // read until there are no more packets, then return to outer select() loop
  223. if (!buf) {
  224. // To reduce use of the mutex, we keep a local buffer vector and
  225. // swap (which is a pointer swap) with the global one when it's
  226. // empty. This retrieves a batch of buffers to use.
  227. if (buffers.empty()) {
  228. std::lock_guard<std::mutex> l(_buffers_l);
  229. buffers.swap(_buffers);
  230. }
  231. if (buffers.empty()) {
  232. buf = malloc(ZT_TAP_BUF_SIZE);
  233. if (!buf)
  234. break;
  235. } else {
  236. buf = buffers.back();
  237. buffers.pop_back();
  238. }
  239. }
  240. n = (int)::read(_fd,reinterpret_cast<uint8_t *>(buf) + r,ZT_TAP_BUF_SIZE - r);
  241. if (n > 0) {
  242. // Some tap drivers like to send the ethernet frame and the
  243. // payload in two chunks, so handle that by accumulating
  244. // data until we have at least a frame.
  245. r += n;
  246. if (r > 14) {
  247. if (r > ((int)_mtu + 14)) // sanity check for weird TAP behavior on some platforms
  248. r = _mtu + 14;
  249. if (_enabled) {
  250. _tapq.post(std::pair<void *,int>(buf,r));
  251. buf = nullptr;
  252. }
  253. r = 0;
  254. }
  255. } else {
  256. r = 0;
  257. break;
  258. }
  259. }
  260. }
  261. }
  262. });
  263. }
  264. _tapProcessorThread = std::thread([this] {
  265. MAC to,from;
  266. std::pair<void *,int> qi;
  267. while (_tapq.get(qi)) {
  268. uint8_t *const b = reinterpret_cast<uint8_t *>(qi.first);
  269. if (b) {
  270. to.setTo(b, 6);
  271. from.setTo(b + 6, 6);
  272. unsigned int etherType = Utils::ntoh(((const uint16_t *)b)[6]);
  273. _handler(_arg, nullptr, _nwid, from, to, etherType, 0, (const void *)(b + 14),(unsigned int)(qi.second - 14));
  274. {
  275. std::lock_guard<std::mutex> l(_buffers_l);
  276. if (_buffers.size() < 128)
  277. _buffers.push_back(qi.first);
  278. else free(qi.first);
  279. }
  280. } else break;
  281. }
  282. });
  283. }
  284. LinuxEthernetTap::~LinuxEthernetTap()
  285. {
  286. (void)::write(_shutdownSignalPipe[1],"\0",1); // causes reader thread(s) to exit
  287. _tapq.post(std::pair<void *,int>(nullptr,0)); // causes processor thread to exit
  288. ::close(_fd);
  289. ::close(_shutdownSignalPipe[0]);
  290. ::close(_shutdownSignalPipe[1]);
  291. _tapReaderThread[0].join();
  292. _tapReaderThread[1].join();
  293. _tapProcessorThread.join();
  294. for(std::vector<void *>::iterator i(_buffers.begin());i!=_buffers.end();++i)
  295. free(*i);
  296. std::vector< std::pair<void *,int> > dv(_tapq.drain());
  297. for(std::vector< std::pair<void *,int> >::iterator i(dv.begin());i!=dv.end();++i) {
  298. if (i->first)
  299. free(i->first);
  300. }
  301. }
  302. void LinuxEthernetTap::setEnabled(bool en)
  303. {
  304. _enabled = en;
  305. }
  306. bool LinuxEthernetTap::enabled() const
  307. {
  308. return _enabled;
  309. }
  310. static bool ___removeIp(const std::string &_dev,const InetAddress &ip)
  311. {
  312. LinuxNetLink::getInstance().removeAddress(ip, _dev.c_str());
  313. return true;
  314. }
  315. bool LinuxEthernetTap::addIps(std::vector<InetAddress> ips)
  316. {
  317. #ifdef __SYNOLOGY__
  318. std::string filepath = "/etc/sysconfig/network-scripts/ifcfg-"+_dev;
  319. std::string cfg_contents = "DEVICE="+_dev+"\nBOOTPROTO=static";
  320. int ip4=0,ip6=0,ip4_tot=0,ip6_tot=0;
  321. for(int i=0; i<(int)ips.size(); i++) {
  322. if (ips[i].isV4())
  323. ip4_tot++;
  324. else
  325. ip6_tot++;
  326. }
  327. // Assemble and write contents of ifcfg-dev file
  328. for(int i=0; i<(int)ips.size(); i++) {
  329. if (ips[i].isV4()) {
  330. char iptmp[64],iptmp2[64];
  331. std::string numstr4 = ip4_tot > 1 ? std::to_string(ip4) : "";
  332. cfg_contents += "\nIPADDR"+numstr4+"="+ips[i].toIpString(iptmp)
  333. + "\nNETMASK"+numstr4+"="+ips[i].netmask().toIpString(iptmp2)+"\n";
  334. ip4++;
  335. } else {
  336. char iptmp[64],iptmp2[64];
  337. std::string numstr6 = ip6_tot > 1 ? std::to_string(ip6) : "";
  338. cfg_contents += "\nIPV6ADDR"+numstr6+"="+ips[i].toIpString(iptmp)
  339. + "\nNETMASK"+numstr6+"="+ips[i].netmask().toIpString(iptmp2)+"\n";
  340. ip6++;
  341. }
  342. }
  343. OSUtils::writeFile(filepath.c_str(), cfg_contents.c_str(), cfg_contents.length());
  344. // Finally, add IPs
  345. for(int i=0; i<(int)ips.size(); i++){
  346. LinuxNetLink::getInstance().addAddress(ips[i], _dev.c_str());
  347. }
  348. return true;
  349. #endif // __SYNOLOGY__
  350. return false;
  351. }
  352. bool LinuxEthernetTap::addIp(const InetAddress &ip)
  353. {
  354. if (!ip)
  355. return false;
  356. std::vector<InetAddress> allIps(ips());
  357. if (std::binary_search(allIps.begin(),allIps.end(),ip))
  358. return true;
  359. // Remove and reconfigure if address is the same but netmask is different
  360. for(std::vector<InetAddress>::iterator i(allIps.begin());i!=allIps.end();++i) {
  361. if (i->ipsEqual(ip))
  362. ___removeIp(_dev,*i);
  363. }
  364. LinuxNetLink::getInstance().addAddress(ip, _dev.c_str());
  365. return true;
  366. }
  367. bool LinuxEthernetTap::removeIp(const InetAddress &ip)
  368. {
  369. if (!ip)
  370. return true;
  371. std::vector<InetAddress> allIps(ips());
  372. if (std::find(allIps.begin(),allIps.end(),ip) != allIps.end()) {
  373. if (___removeIp(_dev,ip))
  374. return true;
  375. }
  376. return false;
  377. }
  378. std::vector<InetAddress> LinuxEthernetTap::ips() const
  379. {
  380. struct ifaddrs *ifa = (struct ifaddrs *)0;
  381. if (getifaddrs(&ifa))
  382. return std::vector<InetAddress>();
  383. std::vector<InetAddress> r;
  384. struct ifaddrs *p = ifa;
  385. while (p) {
  386. if ((!strcmp(p->ifa_name,_dev.c_str()))&&(p->ifa_addr)&&(p->ifa_netmask)&&(p->ifa_addr->sa_family == p->ifa_netmask->sa_family)) {
  387. switch(p->ifa_addr->sa_family) {
  388. case AF_INET: {
  389. struct sockaddr_in *sin = (struct sockaddr_in *)p->ifa_addr;
  390. struct sockaddr_in *nm = (struct sockaddr_in *)p->ifa_netmask;
  391. r.push_back(InetAddress(&(sin->sin_addr.s_addr),4,Utils::countBits((uint32_t)nm->sin_addr.s_addr)));
  392. } break;
  393. case AF_INET6: {
  394. struct sockaddr_in6 *sin = (struct sockaddr_in6 *)p->ifa_addr;
  395. struct sockaddr_in6 *nm = (struct sockaddr_in6 *)p->ifa_netmask;
  396. uint32_t b[4];
  397. memcpy(b,nm->sin6_addr.s6_addr,sizeof(b));
  398. r.push_back(InetAddress(sin->sin6_addr.s6_addr,16,Utils::countBits(b[0]) + Utils::countBits(b[1]) + Utils::countBits(b[2]) + Utils::countBits(b[3])));
  399. } break;
  400. }
  401. }
  402. p = p->ifa_next;
  403. }
  404. if (ifa)
  405. freeifaddrs(ifa);
  406. std::sort(r.begin(),r.end());
  407. r.erase(std::unique(r.begin(),r.end()),r.end());
  408. return r;
  409. }
  410. void LinuxEthernetTap::put(const MAC &from,const MAC &to,unsigned int etherType,const void *data,unsigned int len)
  411. {
  412. char putBuf[ZT_MAX_MTU + 64];
  413. if ((_fd > 0)&&(len <= _mtu)&&(_enabled)) {
  414. to.copyTo(putBuf,6);
  415. from.copyTo(putBuf + 6,6);
  416. *((uint16_t *)(putBuf + 12)) = htons((uint16_t)etherType);
  417. memcpy(putBuf + 14,data,len);
  418. len += 14;
  419. (void)::write(_fd,putBuf,len);
  420. }
  421. }
  422. std::string LinuxEthernetTap::deviceName() const
  423. {
  424. return _dev;
  425. }
  426. void LinuxEthernetTap::setFriendlyName(const char *friendlyName)
  427. {
  428. }
  429. void LinuxEthernetTap::scanMulticastGroups(std::vector<MulticastGroup> &added,std::vector<MulticastGroup> &removed)
  430. {
  431. char *ptr,*ptr2;
  432. unsigned char mac[6];
  433. std::vector<MulticastGroup> newGroups;
  434. int fd = ::open("/proc/net/dev_mcast",O_RDONLY);
  435. if (fd > 0) {
  436. char buf[131072];
  437. int n = (int)::read(fd,buf,sizeof(buf));
  438. if ((n > 0)&&(n < (int)sizeof(buf))) {
  439. buf[n] = (char)0;
  440. for(char *l=strtok_r(buf,"\r\n",&ptr);(l);l=strtok_r((char *)0,"\r\n",&ptr)) {
  441. int fno = 0;
  442. char *devname = (char *)0;
  443. char *mcastmac = (char *)0;
  444. for(char *f=strtok_r(l," \t",&ptr2);(f);f=strtok_r((char *)0," \t",&ptr2)) {
  445. if (fno == 1)
  446. devname = f;
  447. else if (fno == 4)
  448. mcastmac = f;
  449. ++fno;
  450. }
  451. if ((devname)&&(!strcmp(devname,_dev.c_str()))&&(mcastmac)&&(Utils::unhex(mcastmac,mac,6) == 6))
  452. newGroups.push_back(MulticastGroup(MAC(mac,6),0));
  453. }
  454. }
  455. ::close(fd);
  456. }
  457. std::vector<InetAddress> allIps(ips());
  458. for(std::vector<InetAddress>::iterator ip(allIps.begin());ip!=allIps.end();++ip)
  459. newGroups.push_back(MulticastGroup::deriveMulticastGroupForAddressResolution(*ip));
  460. std::sort(newGroups.begin(),newGroups.end());
  461. newGroups.erase(std::unique(newGroups.begin(),newGroups.end()),newGroups.end());
  462. for(std::vector<MulticastGroup>::iterator m(newGroups.begin());m!=newGroups.end();++m) {
  463. if (!std::binary_search(_multicastGroups.begin(),_multicastGroups.end(),*m))
  464. added.push_back(*m);
  465. }
  466. for(std::vector<MulticastGroup>::iterator m(_multicastGroups.begin());m!=_multicastGroups.end();++m) {
  467. if (!std::binary_search(newGroups.begin(),newGroups.end(),*m))
  468. removed.push_back(*m);
  469. }
  470. _multicastGroups.swap(newGroups);
  471. }
  472. void LinuxEthernetTap::setMtu(unsigned int mtu)
  473. {
  474. if (_mtu != mtu) {
  475. _mtu = mtu;
  476. int sock = socket(AF_INET,SOCK_DGRAM,0);
  477. if (sock > 0) {
  478. struct ifreq ifr;
  479. memset(&ifr,0,sizeof(ifr));
  480. ifr.ifr_ifru.ifru_mtu = (int)mtu;
  481. ioctl(sock,SIOCSIFMTU,(void *)&ifr);
  482. close(sock);
  483. }
  484. }
  485. }
  486. } // namespace ZeroTier
  487. #endif // __LINUX__