diff options
author | Adam Ierymenko <adam.ierymenko@gmail.com> | 2017-01-19 10:39:42 -0800 |
---|---|---|
committer | Adam Ierymenko <adam.ierymenko@gmail.com> | 2017-01-19 10:39:42 -0800 |
commit | 7b231b38b02d74afff7ea9cde6ea5c4a8cee5103 (patch) | |
tree | 24c09d169836497c2ca8cb62106837d1e13ebbd0 | |
parent | 13263b8401555ea788097e1aceb24a7a75bb84f4 (diff) | |
download | infinitytier-7b231b38b02d74afff7ea9cde6ea5c4a8cee5103.tar.gz infinitytier-7b231b38b02d74afff7ea9cde6ea5c4a8cee5103.zip |
Now builds on OpenBSD, but segfaults. So not yet but close. GitHub issue #439
-rw-r--r-- | Makefile | 4 | ||||
-rw-r--r-- | make-freebsd.mk | 2 | ||||
-rw-r--r-- | osdep/BSDEthernetTap.cpp | 32 | ||||
-rw-r--r-- | service/OneService.cpp | 4 |
4 files changed, 31 insertions, 11 deletions
@@ -11,8 +11,12 @@ ifeq ($(OSTYPE),Linux) endif ifeq ($(OSTYPE),FreeBSD) + CC=gcc + CXX=g++ include make-freebsd.mk endif ifeq ($(OSTYPE),OpenBSD) + CC=egcc + CXX=eg++ include make-freebsd.mk endif diff --git a/make-freebsd.mk b/make-freebsd.mk index 23ad278b..a90dfc77 100644 --- a/make-freebsd.mk +++ b/make-freebsd.mk @@ -1,5 +1,3 @@ -CC=cc -CXX=c++ INCLUDES= DEFS= LIBS= diff --git a/osdep/BSDEthernetTap.cpp b/osdep/BSDEthernetTap.cpp index e8d36c9c..463206f6 100644 --- a/osdep/BSDEthernetTap.cpp +++ b/osdep/BSDEthernetTap.cpp @@ -85,8 +85,14 @@ BSDEthernetTap::BSDEthernetTap( char devpath[64],ethaddr[64],mtustr[32],metstr[32],tmpdevname[32]; struct stat stattmp; - // On FreeBSD at least we can rename, so use nwid to generate a deterministic unique zt#### name using base32 - // As a result we don't use desiredDevice + Mutex::Lock _gl(globalTapCreateLock); + + if (mtu > 2800) + throw std::runtime_error("max tap MTU is 2800"); + +#ifdef __FreeBSD__ + /* FreeBSD allows long interface names and interface renaming */ + _dev = "zt"; _dev.push_back(ZT_BASE32_CHARS[(unsigned long)((nwid >> 60) & 0x1f)]); _dev.push_back(ZT_BASE32_CHARS[(unsigned long)((nwid >> 55) & 0x1f)]); @@ -102,13 +108,6 @@ BSDEthernetTap::BSDEthernetTap( _dev.push_back(ZT_BASE32_CHARS[(unsigned long)((nwid >> 5) & 0x1f)]); _dev.push_back(ZT_BASE32_CHARS[(unsigned long)(nwid & 0x1f)]); - Mutex::Lock _gl(globalTapCreateLock); - - if (mtu > 2800) - throw std::runtime_error("max tap MTU is 2800"); - - // On BSD we create taps and they can have high numbers, so use ones starting - // at 9993 to not conflict with other stuff. Then we rename it to zt<base32 of nwid> std::vector<std::string> devFiles(OSUtils::listDirectory("/dev")); for(int i=9993;i<(9993+128);++i) { Utils::snprintf(tmpdevname,sizeof(tmpdevname),"tap%d",i); @@ -144,6 +143,19 @@ BSDEthernetTap::BSDEthernetTap( } } } +#else + /* Other BSDs like OpenBSD only have a limited number of tap devices that cannot be renamed */ + + for(int i=0;i<64;++i) { + Utils::snprintf(tmpdevname,sizeof(tmpdevname),"tap%d",i); + Utils::snprintf(devpath,sizeof(devpath),"/dev/%s",tmpdevname); + _fd = ::open(devpath,O_RDWR); + if (_fd > 0) { + _dev = tmpdevname; + break; + } + } +#endif if (_fd <= 0) throw std::runtime_error("unable to open TAP device or no more devices available"); @@ -325,6 +337,7 @@ void BSDEthernetTap::scanMulticastGroups(std::vector<MulticastGroup> &added,std: { std::vector<MulticastGroup> newGroups; +#ifndef __OpenBSD__ struct ifmaddrs *ifmap = (struct ifmaddrs *)0; if (!getifmaddrs(&ifmap)) { struct ifmaddrs *p = ifmap; @@ -339,6 +352,7 @@ void BSDEthernetTap::scanMulticastGroups(std::vector<MulticastGroup> &added,std: } freeifmaddrs(ifmap); } +#endif // __OpenBSD__ std::vector<InetAddress> allIps(ips()); for(std::vector<InetAddress>::iterator ip(allIps.begin());ip!=allIps.end();++ip) diff --git a/service/OneService.cpp b/service/OneService.cpp index d9134a34..93f5b5f0 100644 --- a/service/OneService.cpp +++ b/service/OneService.cpp @@ -115,6 +115,10 @@ namespace ZeroTier { typedef WindowsEthernetTap EthernetTap; } #include "../osdep/BSDEthernetTap.hpp" namespace ZeroTier { typedef BSDEthernetTap EthernetTap; } #endif // __FreeBSD__ +#ifdef __OpenBSD__ +#include "../osdep/BSDEthernetTap.hpp" +namespace ZeroTier { typedef BSDEthernetTap EthernetTap; } +#endif // __OpenBSD__ #endif // ZT_SERVICE_NETCON |