From 1a02bcc9f5fb079e20e646a1b8b44df122643d32 Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Fri, 19 Dec 2014 13:34:06 -0800 Subject: Fork OSXEthernetTapFactory -> BSDEthernetTapFactory --- attic/make-freebsd.mk | 88 ---------------------------------------- make-freebsd.mk | 89 +++++++++++++++++++++++++++++++++++++++++ osnet/BSDEthernetTapFactory.cpp | 88 ++++++++++++++++++++++++++++++++++++++++ osnet/BSDEthernetTapFactory.hpp | 64 +++++++++++++++++++++++++++++ osnet/OSXEthernetTapFactory.hpp | 4 +- 5 files changed, 243 insertions(+), 90 deletions(-) delete mode 100644 attic/make-freebsd.mk create mode 100644 make-freebsd.mk create mode 100644 osnet/BSDEthernetTapFactory.cpp create mode 100644 osnet/BSDEthernetTapFactory.hpp diff --git a/attic/make-freebsd.mk b/attic/make-freebsd.mk deleted file mode 100644 index 74499972..00000000 --- a/attic/make-freebsd.mk +++ /dev/null @@ -1,88 +0,0 @@ -CC=cc -CXX=c++ - -INCLUDES= -DEFS= -LIBS= - -include objects.mk -OBJS+= -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 -MACHINE=$(shell uname -m) -ifeq ($(MACHINE),x86_64) - DEFS+=-DZT_SALSA20_SSE -endif -ifeq ($(MACHINE),amd64) - DEFS+=-DZT_SALSA20_SSE -endif -ifeq ($(MACHINE),i686) - DEFS+=-DZT_SALSA20_SSE -endif -ifeq ($(MACHINE),i586) - DEFS+=-DZT_SALSA20_SSE -endif -ifeq ($(MACHINE),i386) - DEFS+=-DZT_SALSA20_SSE -endif -ifeq ($(MACHINE),x86) - DEFS+=-DZT_SALSA20_SSE -endif - -# "make official" is a shortcut for this -ifeq ($(ZT_OFFICIAL_RELEASE),1) - ZT_AUTO_UPDATE=1 - DEFS+=-DZT_OFFICIAL_RELEASE -endif -ifeq ($(ZT_AUTO_UPDATE),1) - DEFS+=-DZT_AUTO_UPDATE -endif - -# "make debug" is a shortcut for this -ifeq ($(ZT_DEBUG),1) -# DEFS+=-DZT_TRACE -DZT_LOG_STDOUT - CFLAGS=-Wall -g -pthread $(INCLUDES) $(DEFS) - LDFLAGS= - STRIP=echo - # The following line enables optimization for the crypto code, since - # C25519 in particular is almost UNUSABLE in heavy testing without it. -ext/lz4/lz4.o node/Salsa20.o node/SHA512.o node/C25519.o node/Poly1305.o: CFLAGS = -Wall -O2 -g -pthread $(INCLUDES) $(DEFS) -else - CFLAGS=-Wall -O3 -fPIE -fvisibility=hidden -fstack-protector -pthread $(INCLUDES) -DNDEBUG $(DEFS) - LDFLAGS=-pie -Wl,-z,relro,-z,now - STRIP=strip --strip-all -endif - -CXXFLAGS=$(CFLAGS) -fno-rtti - -all: one - -one: $(OBJS) main.o - $(CXX) $(CXXFLAGS) $(LDFLAGS) -o zerotier-one main.o $(OBJS) $(LIBS) - $(STRIP) zerotier-one - ln -sf zerotier-one zerotier-cli - ln -sf zerotier-one zerotier-idtool - -selftest: $(OBJS) selftest.o - $(CXX) $(CXXFLAGS) $(LDFLAGS) -o zerotier-selftest selftest.o $(OBJS) $(LIBS) - $(STRIP) zerotier-selftest - -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 - -clean: - rm -rf $(OBJS) $(TESTNET_OBJS) node/*.o osnet/*.o control/*.o testnet/*.o *.o zerotier-* build-* ZeroTierOneInstaller-* - -debug: FORCE - make -j 4 ZT_DEBUG=1 - -official: FORCE - make -j 4 ZT_OFFICIAL_RELEASE=1 - ./buildinstaller.sh - -FORCE: diff --git a/make-freebsd.mk b/make-freebsd.mk new file mode 100644 index 00000000..69f094ab --- /dev/null +++ b/make-freebsd.mk @@ -0,0 +1,89 @@ +CC=cc +CXX=c++ + +INCLUDES= +DEFS= +LIBS= + +include objects.mk +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 +MACHINE=$(shell uname -m) +ifeq ($(MACHINE),x86_64) + DEFS+=-DZT_SALSA20_SSE +endif +ifeq ($(MACHINE),amd64) + DEFS+=-DZT_SALSA20_SSE +endif +ifeq ($(MACHINE),i686) + DEFS+=-DZT_SALSA20_SSE +endif +ifeq ($(MACHINE),i586) + DEFS+=-DZT_SALSA20_SSE +endif +ifeq ($(MACHINE),i386) + DEFS+=-DZT_SALSA20_SSE +endif +ifeq ($(MACHINE),x86) + DEFS+=-DZT_SALSA20_SSE +endif + +# "make official" is a shortcut for this +ifeq ($(ZT_OFFICIAL_RELEASE),1) + ZT_AUTO_UPDATE=1 + DEFS+=-DZT_OFFICIAL_RELEASE +endif +ifeq ($(ZT_AUTO_UPDATE),1) + DEFS+=-DZT_AUTO_UPDATE +endif + +# "make debug" is a shortcut for this +ifeq ($(ZT_DEBUG),1) +# DEFS+=-DZT_TRACE -DZT_LOG_STDOUT + CFLAGS=-Wall -g -pthread $(INCLUDES) $(DEFS) + LDFLAGS= + STRIP=echo + # The following line enables optimization for the crypto code, since + # C25519 in particular is almost UNUSABLE in heavy testing without it. +ext/lz4/lz4.o node/Salsa20.o node/SHA512.o node/C25519.o node/Poly1305.o: CFLAGS = -Wall -O2 -g -pthread $(INCLUDES) $(DEFS) +else + CFLAGS=-Wall -O3 -fPIE -fvisibility=hidden -fstack-protector -pthread $(INCLUDES) -DNDEBUG $(DEFS) + LDFLAGS=-pie -Wl,-z,relro,-z,now + STRIP=strip --strip-all +endif + +CXXFLAGS=$(CFLAGS) -fno-rtti + +all: one + +one: $(OBJS) main.o + $(CXX) $(CXXFLAGS) $(LDFLAGS) -o zerotier-one main.o $(OBJS) $(LIBS) + $(STRIP) zerotier-one + ln -sf zerotier-one zerotier-cli + ln -sf zerotier-one zerotier-idtool + +selftest: $(OBJS) selftest.o + $(CXX) $(CXXFLAGS) $(LDFLAGS) -o zerotier-selftest selftest.o $(OBJS) $(LIBS) + $(STRIP) zerotier-selftest + +testnet: $(TESTNET_OBJS) $(OBJS) testnet.o + $(CXX) $(CXXFLAGS) -o zerotier-testnet testnet.o $(OBJS) $(TESTNET_OBJS) $(LIBS) + $(STRIP) zerotier-testnet + +# 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-* + +debug: FORCE + make -j 4 ZT_DEBUG=1 + +#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 -- cgit v1.2.3