From f60dfe496325bfe5d58b3db75e86387799b72c25 Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Fri, 19 Dec 2014 15:18:20 -0800 Subject: FreeBSD works, and some documentation fixes. --- BUILDING.md | 39 ++++++++++++++++++++++ BUILDING.txt | 37 --------------------- RUNNING.md | 84 ++++++++++++++++++++++++++++++++++++++++++++++++ RUNNING.txt | 74 ------------------------------------------ node/Defaults.cpp | 10 ++++++ osnet/BSDEthernetTap.cpp | 16 +++++++-- 6 files changed, 147 insertions(+), 113 deletions(-) create mode 100644 BUILDING.md delete mode 100644 BUILDING.txt create mode 100644 RUNNING.md delete mode 100644 RUNNING.txt diff --git a/BUILDING.md b/BUILDING.md new file mode 100644 index 00000000..7378eb75 --- /dev/null +++ b/BUILDING.md @@ -0,0 +1,39 @@ +Building ZeroTier One From Source +====== + +(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 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 + +make + +If you are building ext/tap-mac you will need a different version of the +OSX gcc compiler chain than what currently ships (clang). We've got a copy +available here: + +http://download.zerotier.com/dev/llvm-g++-Xcode4.6.2.tar.bz2 + +Un-tar this into ext/ (it's excluded in .gitignore) and then 'make' in +ext/tap-mac/tuntap/src/tap. + +Most users should not need to build tap-mac, since a binary is included +in ext/bin. + +To build the UI you will need Qt version 5.0 or later. The Qt home must +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 + +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/BUILDING.txt b/BUILDING.txt deleted file mode 100644 index 9ec53010..00000000 --- a/BUILDING.txt +++ /dev/null @@ -1,37 +0,0 @@ -Building ZeroTier One on different platforms: - -(See RUNNING.txt 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 - -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 - -make - -If you are building ext/tap-mac you will need a different version of the -OSX gcc compiler chain than what currently ships (clang). We've got a copy -available here: - -http://download.zerotier.com/dev/llvm-g++-Xcode4.6.2.tar.bz2 - -Un-tar this into ext/ (it's excluded in .gitignore) and then 'make' in -ext/tap-mac/tuntap/src/tap. - -Most users should not need to build tap-mac, since a binary is included -in ext/bin. - -To build the UI you will need Qt version 5.0 or later. The Qt home must -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 - -Here be dragons. diff --git a/RUNNING.md b/RUNNING.md new file mode 100644 index 00000000..45807144 --- /dev/null +++ b/RUNNING.md @@ -0,0 +1,84 @@ +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 + +On Mac, the default ZeroTier home is: + +/Library/Application Support/ZeroTier/One + +ZeroTier ships with a kernel extension for its own tap device, which it +stores in the above directory. To install this, type: + +sudo make install-mac-tap + +This will create the ZeroTier One home above if it does not exist and install +the kext there. Note that the kext must be owned by root:wheel. The make +rule for install-mac-tap takes care of that. + +Next, simply run the binary. It must be run as root to open the tap device. +If run with no options, it will use the default home directory above. + +sudo ./zerotier-one & + +### LINUX + +On Linux, the default ZeroTier home is: + +/var/lib/zerotier-one + +Just type: + +sudo mkdir /var/lib/zerotier-one +sudo ./zerotier-one & + +Your system must have the Linux tun/tap driver available (tun). All tested +distributions so far ship with this driver as a module that will load +automatically. + +UDP port 9993 must be open in your local firewall for this to work properly. +How to do this varies by Linux distribution. + + - Opening port 9993 on Ubuntu + +Follow the Ubuntu documentation about UFW https://help.ubuntu.com/community/UFW + +Check if your UFW is active. + +sudo ufw status verbose + +If it is active, open UDP port 9993 + +sudo ufw allow 9993/udp + +You should now be able to ping and browse earth.zerotier.net + +### FreeBSD + +FreeBSD is identical to Linux except that the default home is +/var/db/zerotier-one instead of /var/lib. + +### 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 + +If you want to test by joining the Earth network, try: + sudo ./zerotier-cli join 8056c2e21c000001 + +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/RUNNING.txt b/RUNNING.txt deleted file mode 100644 index b7ef8966..00000000 --- a/RUNNING.txt +++ /dev/null @@ -1,74 +0,0 @@ -This guide is for those building and running from source. See BUILDING.txt -first. - -The wiki at GitHub contains several pages that are probably also of interest: - https://github.com/zerotier/ZeroTierOne/wiki - ---- MacOS - -On Mac, the default ZeroTier home is: - -/Library/Application Support/ZeroTier/One - -ZeroTier ships with a kernel extension for its own tap device, which it -stores in the above directory. To install this, type: - -sudo make install-mac-tap - -This will create the ZeroTier One home above if it does not exist and install -the kext there. Note that the kext must be owned by root:wheel. The make -rule for install-mac-tap takes care of that. - -Next, simply run the binary. It must be run as root to open the tap device. -If run with no options, it will use the default home directory above. - -sudo ./zerotier-one & - ---- LINUX - -On Linux, the default ZeroTier home is: - -/var/lib/zerotier-one - -Just type: - -sudo mkdir /var/lib/zerotier-one -sudo ./zerotier-one & - -Your system must have the Linux tun/tap driver available (tun). All tested -distributions so far ship with this driver as a module that will load -automatically. - -UDP port 9993 must be open in your local firewall for this to work properly. -How to do this varies by Linux distribution. - - - Opening port 9993 on Ubuntu - -Follow the Ubuntu documentation about UFW https://help.ubuntu.com/community/UFW - -Check if your UFW is active. - -sudo ufw status verbose - -If it is active, open UDP port 9993 - -sudo ufw allow 9993/udp - -You should now be able to ping and browse earth.zerotier.net - ---- WINDOWS - -A windows port is in progress. - ---- ONCE IT'S RUNNING: - -To use the command line interface, see this guide: - https://github.com/zerotier/ZeroTierOne/wiki/Command-Line-Interface - -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 -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 177be52b..adcb9963 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 8b28510d..100fb171 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) -- cgit v1.2.3