FreeBSD works, and some documentation fixes.

This commit is contained in:
Adam Ierymenko 2014-12-19 15:18:20 -08:00
parent 536bcf6505
commit f60dfe4963
4 changed files with 49 additions and 15 deletions

View File

@ -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 Developers note: there is currently no management of dependencies on *nix
platforms, so you should make clean ; make if you change a header. Will platforms, so you should make clean ; make if you change a header. Will
do this eventually. do this eventually.
-- Linux ### Linux and FreeBSD
Just type 'make'. You'll need gcc and g++ installed, but ZeroTier One requires 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. no other third party libraries beyond the standard libc, libstdc++, and libm.
-- MacOS ### MacOS
make 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. 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. 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.

View File

@ -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. first.
The wiki at GitHub contains several pages that are probably also of interest: The wiki at GitHub contains several pages that are probably also of interest:
https://github.com/zerotier/ZeroTierOne/wiki https://github.com/zerotier/ZeroTierOne/wiki
--- MacOS ### MacOS
On Mac, the default ZeroTier home is: 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 & sudo ./zerotier-one &
--- LINUX ### LINUX
On Linux, the default ZeroTier home is: 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 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: To use the command line interface, see this guide:
https://github.com/zerotier/ZeroTierOne/wiki/Command-Line-Interface 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: If you want to test by joining the Earth network, try:
sudo ./zerotier-cli join 8056c2e21c000001 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 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 pinging earth.zerotier.net or navigating to http://earth.zerotier.net/ in
a web browser. a web browser.

View File

@ -51,14 +51,24 @@ static inline std::string _mkDefaultHomePath()
#ifdef __UNIX_LIKE__ #ifdef __UNIX_LIKE__
#ifdef __APPLE__ #ifdef __APPLE__
// /Library/... on Apple
return std::string("/Library/Application Support/ZeroTier/One"); return std::string("/Library/Application Support/ZeroTier/One");
#else #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"); return std::string("/var/lib/zerotier-one");
#endif #endif
#endif
#else // not __UNIX_LIKE__ #else // not __UNIX_LIKE__
#ifdef __WINDOWS__ #ifdef __WINDOWS__
// Look up app data folder on Windows, e.g. C:\ProgramData\...
char buf[16384]; char buf[16384];
if (SUCCEEDED(SHGetFolderPathA(NULL,CSIDL_COMMON_APPDATA,NULL,0,buf))) if (SUCCEEDED(SHGetFolderPathA(NULL,CSIDL_COMMON_APPDATA,NULL,0,buf)))
return (std::string(buf) + "\\ZeroTier\\One"); return (std::string(buf) + "\\ZeroTier\\One");

View File

@ -117,10 +117,11 @@ BSDEthernetTap::BSDEthernetTap(
// On BSD we create taps and they can have high numbers, so use ones starting // 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> // at 9993 to not conflict with other stuff. Then we rename it to zt<base32 of nwid>
for(int i=9993;i<500;++i) { std::map<std::string,bool> devFiles(Utils::listDirectory("/dev"));
for(int i=9993;i<(9993+128);++i) {
Utils::snprintf(tmpdevname,sizeof(tmpdevname),"tap%d",i); Utils::snprintf(tmpdevname,sizeof(tmpdevname),"tap%d",i);
Utils::snprintf(devpath,sizeof(devpath),"/dev/%s",tmpdevname); Utils::snprintf(devpath,sizeof(devpath),"/dev/%s",tmpdevname);
if (stat(devpath,&stattmp)) { if (devFiles.count(std::string(tmpdevname)) == 0) {
long cpid = (long)vfork(); long cpid = (long)vfork();
if (cpid == 0) { if (cpid == 0) {
::execl("/sbin/ifconfig","/sbin/ifconfig",tmpdevname,"create",(const char *)0); ::execl("/sbin/ifconfig","/sbin/ifconfig",tmpdevname,"create",(const char *)0);
@ -146,6 +147,8 @@ BSDEthernetTap::BSDEthernetTap(
if (_fd > 0) if (_fd > 0)
break; break;
else throw std::runtime_error("unable to open created tap device"); 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(_fd);
::close(_shutdownSignalPipe[0]); ::close(_shutdownSignalPipe[0]);
::close(_shutdownSignalPipe[1]); ::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) void BSDEthernetTap::setEnabled(bool en)