From f26025058075d91cd69ac892c373fd1d4d7f605d Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Mon, 30 Nov 2015 15:39:34 -0800 Subject: Simplify IP assignment logic in OSXEthernetTap, also fix for GitHub issue #249 --- osdep/OSXEthernetTap.cpp | 45 ++++++++++++++------------------------------- 1 file changed, 14 insertions(+), 31 deletions(-) diff --git a/osdep/OSXEthernetTap.cpp b/osdep/OSXEthernetTap.cpp index 6b6f360b..3e43cf95 100644 --- a/osdep/OSXEthernetTap.cpp +++ b/osdep/OSXEthernetTap.cpp @@ -143,7 +143,7 @@ static inline int _intl_getifmaddrs(struct _intl_ifmaddrs **pif) } free(buf); buf = NULL; - } + } } while (buf == NULL); for (next = buf; next < buf + needed; next += rtm->rtm_msglen) { @@ -475,37 +475,11 @@ bool OSXEthernetTap::enabled() const return _enabled; } -static bool ___removeIp(const std::string &_dev,const InetAddress &ip) -{ - long cpid = (long)vfork(); - if (cpid == 0) { - execl("/sbin/ifconfig","/sbin/ifconfig",_dev.c_str(),"inet",ip.toIpString().c_str(),"-alias",(const char *)0); - _exit(-1); - } else if (cpid > 0) { - int exitcode = -1; - waitpid(cpid,&exitcode,0); - return (exitcode == 0); - } - return false; // never reached, make compiler shut up about return value -} - bool OSXEthernetTap::addIp(const InetAddress &ip) { if (!ip) return false; - std::vector allIps(ips()); - if (std::binary_search(allIps.begin(),allIps.end(),ip)) - return true; - - // Remove and reconfigure if address is the same but netmask is different - for(std::vector::iterator i(allIps.begin());i!=allIps.end();++i) { - if ((i->ipsEqual(ip))&&(i->netmaskBits() != ip.netmaskBits())) { - if (___removeIp(_dev,*i)) - break; - } - } - long cpid = (long)vfork(); if (cpid == 0) { ::execl("/sbin/ifconfig","/sbin/ifconfig",_dev.c_str(),ip.isV4() ? "inet" : "inet6",ip.toString().c_str(),"alias",(const char *)0); @@ -524,9 +498,18 @@ bool OSXEthernetTap::removeIp(const InetAddress &ip) if (!ip) return true; std::vector allIps(ips()); - if (!std::binary_search(allIps.begin(),allIps.end(),ip)) { - if (___removeIp(_dev,ip)) - return true; + for(std::vector::iterator i(allIps.begin());i!=allIps.end();++i) { + if (*i == ip) { + long cpid = (long)vfork(); + if (cpid == 0) { + execl("/sbin/ifconfig","/sbin/ifconfig",_dev.c_str(),"inet",ip.toIpString().c_str(),"-alias",(const char *)0); + _exit(-1); + } else if (cpid > 0) { + int exitcode = -1; + waitpid(cpid,&exitcode,0); + return (exitcode == 0); + } + } } return false; } @@ -564,7 +547,7 @@ std::vector OSXEthernetTap::ips() const freeifaddrs(ifa); std::sort(r.begin(),r.end()); - std::unique(r.begin(),r.end()); + r.erase(std::unique(r.begin(),r.end()),r.end()); return r; } -- cgit v1.2.3 From c21882da9ce3dca08dc3ca096482ff69b7355e13 Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Mon, 30 Nov 2015 16:07:02 -0800 Subject: Put selftest back and turn off tracing in PortMapper. --- osdep/PortMapper.cpp | 2 +- selftest.cpp | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/osdep/PortMapper.cpp b/osdep/PortMapper.cpp index 5c017931..87c886c2 100644 --- a/osdep/PortMapper.cpp +++ b/osdep/PortMapper.cpp @@ -28,7 +28,7 @@ #ifdef ZT_USE_MINIUPNPC // Uncomment to dump debug messages -#define ZT_PORTMAPPER_TRACE 1 +//#define ZT_PORTMAPPER_TRACE 1 #include #include diff --git a/selftest.cpp b/selftest.cpp index e68f564c..4e9219b2 100644 --- a/selftest.cpp +++ b/selftest.cpp @@ -1096,7 +1096,7 @@ int main(int argc,char **argv) srand((unsigned int)time(0)); - /* + ///* r |= testSqliteNetworkController(); r |= testOther(); r |= testCrypto(); @@ -1106,17 +1106,19 @@ int main(int argc,char **argv) r |= testPhy(); r |= testResolver(); //r |= testHttp(); - */ + //*/ if (r) std::cout << std::endl << "SOMETHING FAILED!" << std::endl; + /* #ifdef ZT_USE_MINIUPNPC std::cout << std::endl; std::cout << "[portmapper] Starting port mapper and waiting forever... use CTRL+C to exit. (enable ZT_PORTMAPPER_TRACE in PortMapper.cpp for output)" << std::endl; PortMapper mapper(12345,"ZeroTier/__selftest"); Thread::sleep(0xffffffff); #endif + */ return r; } -- cgit v1.2.3 From d73edfea5654665a2b491c4570369d6410363db2 Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Mon, 30 Nov 2015 16:12:03 -0800 Subject: GitHub issue #257 --- .../ZeroTier One.app/Contents/MacOS/ZeroTier One | Bin 152736 -> 152736 bytes .../Contents/Resources/en.lproj/Window.nib | Bin 3723 -> 3616 bytes .../Contents/_CodeSignature/CodeResources | 4 ++-- .../src/MacGap/en.lproj/Window.xib | 16 ++++++++-------- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/ext/mac-ui-macgap1-wrapper/bin/ZeroTier One.app/Contents/MacOS/ZeroTier One b/ext/mac-ui-macgap1-wrapper/bin/ZeroTier One.app/Contents/MacOS/ZeroTier One index ba15bca9..8e38b861 100755 Binary files a/ext/mac-ui-macgap1-wrapper/bin/ZeroTier One.app/Contents/MacOS/ZeroTier One and b/ext/mac-ui-macgap1-wrapper/bin/ZeroTier One.app/Contents/MacOS/ZeroTier One differ diff --git a/ext/mac-ui-macgap1-wrapper/bin/ZeroTier One.app/Contents/Resources/en.lproj/Window.nib b/ext/mac-ui-macgap1-wrapper/bin/ZeroTier One.app/Contents/Resources/en.lproj/Window.nib index 69258da6..e7b174a1 100644 Binary files a/ext/mac-ui-macgap1-wrapper/bin/ZeroTier One.app/Contents/Resources/en.lproj/Window.nib and b/ext/mac-ui-macgap1-wrapper/bin/ZeroTier One.app/Contents/Resources/en.lproj/Window.nib differ diff --git a/ext/mac-ui-macgap1-wrapper/bin/ZeroTier One.app/Contents/_CodeSignature/CodeResources b/ext/mac-ui-macgap1-wrapper/bin/ZeroTier One.app/Contents/_CodeSignature/CodeResources index 14556923..5e334db0 100644 --- a/ext/mac-ui-macgap1-wrapper/bin/ZeroTier One.app/Contents/_CodeSignature/CodeResources +++ b/ext/mac-ui-macgap1-wrapper/bin/ZeroTier One.app/Contents/_CodeSignature/CodeResources @@ -39,7 +39,7 @@ hash - 7dgumnPDtoIzhi9QoaFhDvCo9ys= + aP0mIANPPnnTMmxYlELioz9ZO1I= optional @@ -82,7 +82,7 @@ hash - 7dgumnPDtoIzhi9QoaFhDvCo9ys= + aP0mIANPPnnTMmxYlELioz9ZO1I= optional diff --git a/ext/mac-ui-macgap1-wrapper/src/MacGap/en.lproj/Window.xib b/ext/mac-ui-macgap1-wrapper/src/MacGap/en.lproj/Window.xib index 2c46b79f..fa70acaa 100644 --- a/ext/mac-ui-macgap1-wrapper/src/MacGap/en.lproj/Window.xib +++ b/ext/mac-ui-macgap1-wrapper/src/MacGap/en.lproj/Window.xib @@ -13,22 +13,22 @@ - + - - + + - - - + - + - + + + -- cgit v1.2.3 From be44b15eacc7f34365d86e717e847b86000cbec4 Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Mon, 30 Nov 2015 16:15:23 -0800 Subject: Fix for GitHub issue #252 --- ext/installfiles/linux/DEBIAN/control.in | 1 + 1 file changed, 1 insertion(+) diff --git a/ext/installfiles/linux/DEBIAN/control.in b/ext/installfiles/linux/DEBIAN/control.in index d774b61e..dab6587f 100644 --- a/ext/installfiles/linux/DEBIAN/control.in +++ b/ext/installfiles/linux/DEBIAN/control.in @@ -3,6 +3,7 @@ Architecture: __ARCH__ Maintainer: ZeroTier, Inc. Priority: optional Version: __VERSION__ +Installed-Size: 1024 Homepage: https://github.com/zerotier/ZeroTierOne Description: ZeroTier One network virtualization service ZeroTier One is a fast, secure, and easy to use peer to peer network -- cgit v1.2.3 From 944fdfb65e260ed58a91097e42747ccb80c06f6f Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Mon, 30 Nov 2015 16:44:32 -0800 Subject: Low-impact sanity check against GitHub issue #247 -- will likely prevent other weird recursions too. --- service/OneService.cpp | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/service/OneService.cpp b/service/OneService.cpp index 3d027237..33fb26ac 100644 --- a/service/OneService.cpp +++ b/service/OneService.cpp @@ -340,6 +340,26 @@ public: static BackgroundSoftwareUpdateChecker backgroundSoftwareUpdateChecker; #endif // ZT_AUTO_UPDATE +static bool isBlacklistedLocalInterfaceForZeroTierTraffic(const char *ifn) +{ +#if defined(__linux__) || defined(linux) || defined(__LINUX__) || defined(__linux) + if ((ifn[0] == 'l')&&(ifn[1] == 'o')) return true; // loopback + if ((ifn[0] == 'z')&&(ifn[1] == 't')) return true; // sanity check: zt# + if ((ifn[0] == 't')&&(ifn[1] == 'u')&&(ifn[2] == 'n')) return true; // tun# is probably an OpenVPN tunnel or similar + if ((ifn[0] == 't')&&(ifn[1] == 'a')&&(ifn[2] == 'p')) return true; // tap# is probably an OpenVPN tunnel or similar +#endif + +#ifdef __APPLE__ + if ((ifn[0] == 'l')&&(ifn[1] == 'o')) return true; // loopback + if ((ifn[0] == 'z')&&(ifn[1] == 't')) return true; // sanity check: zt# + if ((ifn[0] == 't')&&(ifn[1] == 'u')&&(ifn[2] == 'n')) return true; // tun# is probably an OpenVPN tunnel or similar + if ((ifn[0] == 't')&&(ifn[1] == 'a')&&(ifn[2] == 'p')) return true; // tap# is probably an OpenVPN tunnel or similar + if ((ifn[0] == 'u')&&(ifn[1] == 't')&&(ifn[2] == 'u')&&(ifn[3] == 'n')) return true; // ... as is utun# +#endif + + return false; +} + static std::string _trimString(const std::string &s) { unsigned long end = (unsigned long)s.length(); @@ -753,7 +773,7 @@ public: if ((getifaddrs(&ifatbl) == 0)&&(ifatbl)) { struct ifaddrs *ifa = ifatbl; while (ifa) { - if ((ifa->ifa_name)&&(ifa->ifa_addr)) { + if ((ifa->ifa_name)&&(ifa->ifa_addr)&&(!isBlacklistedLocalInterfaceForZeroTierTraffic(ifa->ifa_name))) { bool isZT = false; for(std::vector::const_iterator d(ztDevices.begin());d!=ztDevices.end();++d) { if (*d == ifa->ifa_name) { -- cgit v1.2.3 From ceaef19fb70523852441c8dd3ba647fa6ad217b9 Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Mon, 30 Nov 2015 17:20:12 -0800 Subject: Fix for GitHub issue #260 -- fix for (non-exploitable) crash in network preferred relay code --- node/Peer.hpp | 1 - node/Switch.cpp | 10 ++++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/node/Peer.hpp b/node/Peer.hpp index 7b8d18ea..5816db69 100644 --- a/node/Peer.hpp +++ b/node/Peer.hpp @@ -263,7 +263,6 @@ public: return (l * (((unsigned int)tsr / (ZT_PEER_DIRECT_PING_DELAY + 1000)) + 1)); } - /** * Update latency with a new direct measurment * diff --git a/node/Switch.cpp b/node/Switch.cpp index 74e2f4c6..bf0d1aff 100644 --- a/node/Switch.cpp +++ b/node/Switch.cpp @@ -820,10 +820,12 @@ bool Switch::_trySend(const Packet &packet,bool encrypt,uint64_t nwid) for(std::vector< std::pair >::const_iterator r(nconf->relays().begin());r!=nconf->relays().end();++r) { if (r->first != peer->address()) { SharedPtr rp(RR->topology->getPeer(r->first)); - const unsigned int q = rp->relayQuality(now); - if ((rp)&&(q < bestq)) { // SUBTILE: < == don't use these if they are nil quality (unsigned int max), instead use a root - bestq = q; - rp.swap(relay); + if (rp) { + const unsigned int q = rp->relayQuality(now); + if (q < bestq) { // SUBTILE: < == don't use these if they are nil quality (unsigned int max), instead use a root + bestq = q; + rp.swap(relay); + } } } } -- cgit v1.2.3 From a4cfe4cd1650ea7e9aada0b004fd7aade2e43ced Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Tue, 1 Dec 2015 10:19:10 -0800 Subject: Fix Linux init script to properly specify runlevels. --- ext/installfiles/linux/init.d/zerotier-one | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/ext/installfiles/linux/init.d/zerotier-one b/ext/installfiles/linux/init.d/zerotier-one index c8e7615e..b0a8aa41 100755 --- a/ext/installfiles/linux/init.d/zerotier-one +++ b/ext/installfiles/linux/init.d/zerotier-one @@ -7,21 +7,20 @@ # networks. See https://www.zerotier.com/ for more information. ### BEGIN INIT INFO -# Provides: zerotier-one -# Required-Start: $local_fs $network -# Required-Stop: $local_fs -# Default-Start: 2345 -# Default-Stop: 90 -# Short-Description: start ZeroTier One -# Description: ZeroTier One provides public and private distributed ethernet \ -# networks. See https://www.zerotier.com/ for more information. +# Provides: zerotier-one +# Required-Start: $local_fs $network +# Required-Stop: $local_fs +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: Start ZeroTier One +# Description: ZeroTier One provides public and private distributed ethernet \ +# networks. See https://www.zerotier.com/ for more information. ### END INIT INFO # # This script is written to avoid distro-specific dependencies, so it does not # use the rc bash script libraries found on some systems. It should work on -# just about anything, even systems using Upstart. Upstart native support may -# come in the future. +# just about anything. # zthome=/var/lib/zerotier-one -- cgit v1.2.3