Fork OSXEthernetTapFactory -> BSDEthernetTapFactory

This commit is contained in:
Adam Ierymenko 2014-12-19 13:34:06 -08:00
parent ff539c22f9
commit 1a02bcc9f5
4 changed files with 161 additions and 8 deletions

View File

@ -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:

View File

@ -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 <http://www.gnu.org/licenses/>.
*
* --
*
* 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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/stat.h>
#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<EthernetTap *>::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<EthernetTap *>::iterator d(_devices.begin());d!=_devices.end();++d) {
if (*d == tap) {
_devices.erase(d);
break;
}
}
}
delete tap;
}
} // namespace ZeroTier

View File

@ -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 <http://www.gnu.org/licenses/>.
*
* --
*
* 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 <vector>
#include <string>
#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<EthernetTap *> _devices;
Mutex _devices_m;
const char *_pathToIfconfig;
};
} // namespace ZeroTier
#endif

View File

@ -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 <vector>
#include <string>