From 1a02bcc9f5fb079e20e646a1b8b44df122643d32 Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Fri, 19 Dec 2014 13:34:06 -0800 Subject: [PATCH] Fork OSXEthernetTapFactory -> BSDEthernetTapFactory --- attic/make-freebsd.mk => make-freebsd.mk | 13 ++-- osnet/BSDEthernetTapFactory.cpp | 88 ++++++++++++++++++++++++ osnet/BSDEthernetTapFactory.hpp | 64 +++++++++++++++++ osnet/OSXEthernetTapFactory.hpp | 4 +- 4 files changed, 161 insertions(+), 8 deletions(-) rename attic/make-freebsd.mk => make-freebsd.mk (90%) create mode 100644 osnet/BSDEthernetTapFactory.cpp create mode 100644 osnet/BSDEthernetTapFactory.hpp diff --git a/attic/make-freebsd.mk b/make-freebsd.mk similarity index 90% rename from attic/make-freebsd.mk rename to make-freebsd.mk index 74499972..69f094ab 100644 --- a/attic/make-freebsd.mk +++ b/make-freebsd.mk @@ -6,7 +6,7 @@ DEFS= LIBS= include objects.mk -OBJS+= +OBJS+=osnet/BSDEthernetTapFactory.o osnet/BSDEthernetTap.o osnet/BSDRoutingTable.o TESTNET_OBJS=testnet/SimNet.o testnet/SimNetSocketManager.o testnet/TestEthernetTap.o testnet/TestEthernetTapFactory.o testnet/TestRoutingTable.o # Enable SSE-optimized Salsa20 on x86 and x86_64 machines @@ -72,8 +72,9 @@ testnet: $(TESTNET_OBJS) $(OBJS) testnet.o $(CXX) $(CXXFLAGS) -o zerotier-testnet testnet.o $(OBJS) $(TESTNET_OBJS) $(LIBS) $(STRIP) zerotier-testnet -installer: one FORCE - ./buildinstaller.sh +# No installer on FreeBSD yet +#installer: one FORCE +# ./buildinstaller.sh clean: rm -rf $(OBJS) $(TESTNET_OBJS) node/*.o osnet/*.o control/*.o testnet/*.o *.o zerotier-* build-* ZeroTierOneInstaller-* @@ -81,8 +82,8 @@ clean: debug: FORCE make -j 4 ZT_DEBUG=1 -official: FORCE - make -j 4 ZT_OFFICIAL_RELEASE=1 - ./buildinstaller.sh +#official: FORCE +# make -j 4 ZT_OFFICIAL_RELEASE=1 +# ./buildinstaller.sh FORCE: diff --git a/osnet/BSDEthernetTapFactory.cpp b/osnet/BSDEthernetTapFactory.cpp new file mode 100644 index 00000000..202b1de4 --- /dev/null +++ b/osnet/BSDEthernetTapFactory.cpp @@ -0,0 +1,88 @@ +/* + * ZeroTier One - Global Peer to Peer Ethernet + * Copyright (C) 2011-2014 ZeroTier Networks LLC + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * -- + * + * ZeroTier may be used and distributed under the terms of the GPLv3, which + * are available at: http://www.gnu.org/licenses/gpl-3.0.html + * + * If you would like to embed ZeroTier into a commercial application or + * redistribute it in a modified binary form, please contact ZeroTier Networks + * LLC. Start here: http://www.zerotier.com/ + */ + +#include +#include +#include +#include +#include + +#include "BSDEthernetTapFactory.hpp" +#include "BSDEthernetTap.hpp" + +#include "../node/Utils.hpp" + +namespace ZeroTier { + +BSDEthernetTapFactory::BSDEthernetTapFactory() +{ + struct stat stattmp; + if (!stat("/sbin/ifconfig",&stattmp)) + _pathToIfconfig = "/sbin/ifconfig"; + else if (!stat("/usr/sbin/ifconfig",&stattmp)) + _pathToIfconfig = "/usr/sbin/ifconfig"; + else throw std::runtime_error("can't find ifconfig"); +} + +BSDEthernetTapFactory::~BSDEthernetTapFactory() +{ + Mutex::Lock _l(_devices_m); + for(std::vector::iterator d(_devices.begin());d!=_devices.end();++d) + delete *d; +} + +EthernetTap *BSDEthernetTapFactory::open( + const MAC &mac, + unsigned int mtu, + unsigned int metric, + uint64_t nwid, + const char *desiredDevice, + const char *friendlyName, + void (*handler)(void *,const MAC &,const MAC &,unsigned int,const Buffer<4096> &), + void *arg) +{ + Mutex::Lock _l(_devices_m); + EthernetTap *t = new BSDEthernetTap(mac,mtu,metric,nwid,desiredDevice,friendlyName,handler,arg); + _devices.push_back(t); + return t; +} + +void BSDEthernetTapFactory::close(EthernetTap *tap,bool destroyPersistentDevices) +{ + { + Mutex::Lock _l(_devices_m); + for(std::vector::iterator d(_devices.begin());d!=_devices.end();++d) { + if (*d == tap) { + _devices.erase(d); + break; + } + } + } + delete tap; +} + +} // namespace ZeroTier diff --git a/osnet/BSDEthernetTapFactory.hpp b/osnet/BSDEthernetTapFactory.hpp new file mode 100644 index 00000000..b5988625 --- /dev/null +++ b/osnet/BSDEthernetTapFactory.hpp @@ -0,0 +1,64 @@ +/* + * ZeroTier One - Global Peer to Peer Ethernet + * Copyright (C) 2011-2014 ZeroTier Networks LLC + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * -- + * + * ZeroTier may be used and distributed under the terms of the GPLv3, which + * are available at: http://www.gnu.org/licenses/gpl-3.0.html + * + * If you would like to embed ZeroTier into a commercial application or + * redistribute it in a modified binary form, please contact ZeroTier Networks + * LLC. Start here: http://www.zerotier.com/ + */ + +#ifndef ZT_BSDETHERNETTAPFACTORY_HPP +#define ZT_BSDETHERNETTAPFACTORY_HPP + +#include +#include + +#include "../node/EthernetTapFactory.hpp" +#include "../node/Mutex.hpp" + +namespace ZeroTier { + +class BSDEthernetTapFactory : public EthernetTapFactory +{ +public: + BSDEthernetTapFactory(); + virtual ~BSDEthernetTapFactory(); + + virtual EthernetTap *open( + const MAC &mac, + unsigned int mtu, + unsigned int metric, + uint64_t nwid, + const char *desiredDevice, + const char *friendlyName, + void (*handler)(void *,const MAC &,const MAC &,unsigned int,const Buffer<4096> &), + void *arg); + virtual void close(EthernetTap *tap,bool destroyPersistentDevices); + +private: + std::vector _devices; + Mutex _devices_m; + const char *_pathToIfconfig; +}; + +} // namespace ZeroTier + +#endif diff --git a/osnet/OSXEthernetTapFactory.hpp b/osnet/OSXEthernetTapFactory.hpp index 45d6eab5..ee1d5989 100644 --- a/osnet/OSXEthernetTapFactory.hpp +++ b/osnet/OSXEthernetTapFactory.hpp @@ -25,8 +25,8 @@ * LLC. Start here: http://www.zerotier.com/ */ -#ifndef ZT_LINUXETHERNETTAPFACTORY_HPP -#define ZT_LINUXETHERNETTAPFACTORY_HPP +#ifndef ZT_OSXETHERNETTAPFACTORY_HPP +#define ZT_OSXETHERNETTAPFACTORY_HPP #include #include