From f60dfe496325bfe5d58b3db75e86387799b72c25 Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Fri, 19 Dec 2014 15:18:20 -0800 Subject: [PATCH] FreeBSD works, and some documentation fixes. --- BUILDING.txt => BUILDING.md | 14 ++++++++------ RUNNING.txt => RUNNING.md | 24 +++++++++++++++++------- node/Defaults.cpp | 10 ++++++++++ osnet/BSDEthernetTap.cpp | 16 ++++++++++++++-- 4 files changed, 49 insertions(+), 15 deletions(-) rename BUILDING.txt => BUILDING.md (79%) rename RUNNING.txt => RUNNING.md (80%) diff --git a/BUILDING.txt b/BUILDING.md similarity index 79% rename from BUILDING.txt rename to BUILDING.md index 9ec53010e..7378eb755 100644 --- a/BUILDING.txt +++ b/BUILDING.md @@ -1,17 +1,18 @@ -Building ZeroTier One on different platforms: +Building ZeroTier One From Source +====== -(See RUNNING.txt for what to do next.) +(See RUNNING.md for what to do next.) Developers note: there is currently no management of dependencies on *nix platforms, so you should make clean ; make if you change a header. Will do this eventually. --- Linux +### Linux and FreeBSD Just type 'make'. You'll need gcc and g++ installed, but ZeroTier One requires no other third party libraries beyond the standard libc, libstdc++, and libm. --- MacOS +### MacOS make @@ -32,6 +33,7 @@ be symbolically linked into "Qt" in the parent directory of the ZeroTier One source tree. Then you can type "make mac-ui" and the UI should build. You can also load the UI in Qt Creator and build/test it that way. --- Windows +### Windows -Here be dragons. +There's a Visual Studio 2012 solution file in windows/ that can be used. +I've never tried it with MinGW, but theoretically this should be possible. diff --git a/RUNNING.txt b/RUNNING.md similarity index 80% rename from RUNNING.txt rename to RUNNING.md index b7ef89669..45807144f 100644 --- a/RUNNING.txt +++ b/RUNNING.md @@ -1,10 +1,13 @@ -This guide is for those building and running from source. See BUILDING.txt +Running ZeroTier One +====== + +This guide is for those building and running from source. See BUILDING.md first. The wiki at GitHub contains several pages that are probably also of interest: https://github.com/zerotier/ZeroTierOne/wiki ---- MacOS +### MacOS On Mac, the default ZeroTier home is: @@ -24,7 +27,7 @@ If run with no options, it will use the default home directory above. sudo ./zerotier-one & ---- LINUX +### LINUX On Linux, the default ZeroTier home is: @@ -56,11 +59,18 @@ sudo ufw allow 9993/udp You should now be able to ping and browse earth.zerotier.net ---- WINDOWS +### FreeBSD -A windows port is in progress. +FreeBSD is identical to Linux except that the default home is +/var/db/zerotier-one instead of /var/lib. ---- ONCE IT'S RUNNING: +### WINDOWS + +Run zerotier-one.exe -h for help. There's a command to install the current +binary as a service to run it that way, and another option to run it from +the Windows console. + +### Once you're up and running... To use the command line interface, see this guide: https://github.com/zerotier/ZeroTierOne/wiki/Command-Line-Interface @@ -68,7 +78,7 @@ To use the command line interface, see this guide: If you want to test by joining the Earth network, try: sudo ./zerotier-cli join 8056c2e21c000001 -An interface called 'zt0' should appear and should get an IP address in +An interface called 'zt####' should appear and should get an IP address in the 28.0.0.0/7 range (28.* or 29.*) within a few seconds or so. Then try pinging earth.zerotier.net or navigating to http://earth.zerotier.net/ in a web browser. diff --git a/node/Defaults.cpp b/node/Defaults.cpp index 177be52b6..adcb9963a 100644 --- a/node/Defaults.cpp +++ b/node/Defaults.cpp @@ -51,14 +51,24 @@ static inline std::string _mkDefaultHomePath() #ifdef __UNIX_LIKE__ #ifdef __APPLE__ + // /Library/... on Apple return std::string("/Library/Application Support/ZeroTier/One"); #else + +#ifdef __FreeBSD__ + // FreeBSD likes /var/db instead of /var/lib + return std::string("/var/db/zerotier-one"); +#else + // Use /var/lib for Linux and other *nix return std::string("/var/lib/zerotier-one"); #endif +#endif + #else // not __UNIX_LIKE__ #ifdef __WINDOWS__ + // Look up app data folder on Windows, e.g. C:\ProgramData\... char buf[16384]; if (SUCCEEDED(SHGetFolderPathA(NULL,CSIDL_COMMON_APPDATA,NULL,0,buf))) return (std::string(buf) + "\\ZeroTier\\One"); diff --git a/osnet/BSDEthernetTap.cpp b/osnet/BSDEthernetTap.cpp index 8b28510de..100fb171d 100644 --- a/osnet/BSDEthernetTap.cpp +++ b/osnet/BSDEthernetTap.cpp @@ -117,10 +117,11 @@ BSDEthernetTap::BSDEthernetTap( // 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 - for(int i=9993;i<500;++i) { + std::map devFiles(Utils::listDirectory("/dev")); + for(int i=9993;i<(9993+128);++i) { Utils::snprintf(tmpdevname,sizeof(tmpdevname),"tap%d",i); Utils::snprintf(devpath,sizeof(devpath),"/dev/%s",tmpdevname); - if (stat(devpath,&stattmp)) { + if (devFiles.count(std::string(tmpdevname)) == 0) { long cpid = (long)vfork(); if (cpid == 0) { ::execl("/sbin/ifconfig","/sbin/ifconfig",tmpdevname,"create",(const char *)0); @@ -146,6 +147,8 @@ BSDEthernetTap::BSDEthernetTap( if (_fd > 0) break; else throw std::runtime_error("unable to open created tap device"); + } else { + throw std::runtime_error("cannot find /dev node for newly created tap device"); } } } @@ -190,6 +193,15 @@ BSDEthernetTap::~BSDEthernetTap() ::close(_fd); ::close(_shutdownSignalPipe[0]); ::close(_shutdownSignalPipe[1]); + + long cpid = (long)vfork(); + if (cpid == 0) { + ::execl("/sbin/ifconfig","/sbin/ifconfig",_dev.c_str(),"destroy",(const char *)0); + ::_exit(-1); + } else if (cpid > 0) { + int exitcode = -1; + ::waitpid(cpid,&exitcode,0); + } } void BSDEthernetTap::setEnabled(bool en)