mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-06-01 23:10:52 +00:00
Make tap itself handle remembering sticky device to nwid mappings.
This commit is contained in:
parent
67f1f1892f
commit
aeb4b42ab3
@ -448,6 +448,9 @@ typedef struct
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* If nonzero, this network supports and allows broadcast (ff:ff:ff:ff:ff:ff) traffic
|
* If nonzero, this network supports and allows broadcast (ff:ff:ff:ff:ff:ff) traffic
|
||||||
|
*
|
||||||
|
* This is really just a hint to user code. If this is true, the user can
|
||||||
|
* subscribe to the broadcast group. If not, then the user shouldn't.
|
||||||
*/
|
*/
|
||||||
int broadcastEnabled;
|
int broadcastEnabled;
|
||||||
|
|
||||||
|
@ -263,6 +263,7 @@ static inline void _intl_freeifmaddrs(struct _intl_ifmaddrs *ifmp)
|
|||||||
#include "../node/Constants.hpp"
|
#include "../node/Constants.hpp"
|
||||||
#include "../node/Utils.hpp"
|
#include "../node/Utils.hpp"
|
||||||
#include "../node/Mutex.hpp"
|
#include "../node/Mutex.hpp"
|
||||||
|
#include "../node/Dictionary.hpp"
|
||||||
#include "OSUtils.hpp"
|
#include "OSUtils.hpp"
|
||||||
#include "OSXEthernetTap.hpp"
|
#include "OSXEthernetTap.hpp"
|
||||||
|
|
||||||
@ -333,14 +334,16 @@ OSXEthernetTap::OSXEthernetTap(
|
|||||||
_fd(0),
|
_fd(0),
|
||||||
_enabled(true)
|
_enabled(true)
|
||||||
{
|
{
|
||||||
char devpath[64],ethaddr[64],mtustr[32],metstr[32];
|
char devpath[64],ethaddr[64],mtustr[32],metstr[32],nwids[32];
|
||||||
struct stat stattmp;
|
struct stat stattmp;
|
||||||
|
|
||||||
Mutex::Lock _gl(globalTapCreateLock);
|
Utils::snprintf(nwids,sizeof(nwids),"%.16llx",nwid);
|
||||||
|
|
||||||
if (mtu > 2800)
|
if (mtu > 2800)
|
||||||
throw std::runtime_error("max tap MTU is 2800");
|
throw std::runtime_error("max tap MTU is 2800");
|
||||||
|
|
||||||
|
Mutex::Lock _gl(globalTapCreateLock);
|
||||||
|
|
||||||
if (stat("/dev/zt0",&stattmp)) {
|
if (stat("/dev/zt0",&stattmp)) {
|
||||||
if (homePath) {
|
if (homePath) {
|
||||||
long kextpid = (long)vfork();
|
long kextpid = (long)vfork();
|
||||||
@ -362,20 +365,22 @@ OSXEthernetTap::OSXEthernetTap(
|
|||||||
|
|
||||||
// Try to reopen the last device we had, if we had one and it's still unused.
|
// Try to reopen the last device we had, if we had one and it's still unused.
|
||||||
bool recalledDevice = false;
|
bool recalledDevice = false;
|
||||||
/*
|
std::string devmapbuf;
|
||||||
if ((desiredDevice)&&(desiredDevice[0] == 'z')&&(desiredDevice[1] == 't')) {
|
Dictionary devmap;
|
||||||
if ((strchr(desiredDevice,'/'))||(strchr(desiredDevice,'.'))) // security sanity check
|
if (OSUtils::readFile((_homePath + ZT_PATH_SEPARATOR_S + "devicemap").c_str(),devmapbuf)) {
|
||||||
throw std::runtime_error("invalid desiredDevice parameter");
|
devmap.fromString(devmapbuf);
|
||||||
Utils::snprintf(devpath,sizeof(devpath),"/dev/%s",desiredDevice);
|
std::string desiredDevice(devmap.get(nwids,""));
|
||||||
if (stat(devpath,&stattmp) == 0) {
|
if (desiredDevice.length() > 2) {
|
||||||
_fd = ::open(devpath,O_RDWR);
|
Utils::snprintf(devpath,sizeof(devpath),"/dev/%s",desiredDevice.c_str());
|
||||||
if (_fd > 0) {
|
if (stat(devpath,&stattmp) == 0) {
|
||||||
_dev = desiredDevice;
|
_fd = ::open(devpath,O_RDWR);
|
||||||
recalledDevice = true;
|
if (_fd > 0) {
|
||||||
|
_dev = desiredDevice;
|
||||||
|
recalledDevice = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
// Open the first unused tap device if we didn't recall a previous one.
|
// Open the first unused tap device if we didn't recall a previous one.
|
||||||
if (!recalledDevice) {
|
if (!recalledDevice) {
|
||||||
@ -425,9 +430,12 @@ OSXEthernetTap::OSXEthernetTap(
|
|||||||
|
|
||||||
::pipe(_shutdownSignalPipe);
|
::pipe(_shutdownSignalPipe);
|
||||||
|
|
||||||
_thread = Thread::start(this);
|
|
||||||
|
|
||||||
++globalTapsRunning;
|
++globalTapsRunning;
|
||||||
|
|
||||||
|
devmap[nwids] = _dev;
|
||||||
|
OSUtils::writeFile((_homePath + ZT_PATH_SEPARATOR_S + "devicemap").c_str(),devmap.toString());
|
||||||
|
|
||||||
|
_thread = Thread::start(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
OSXEthernetTap::~OSXEthernetTap()
|
OSXEthernetTap::~OSXEthernetTap()
|
||||||
|
@ -409,7 +409,7 @@ public:
|
|||||||
StapFrameHandler,
|
StapFrameHandler,
|
||||||
(void *)this))).first;
|
(void *)this))).first;
|
||||||
} catch ( ... ) {
|
} catch ( ... ) {
|
||||||
return -2;
|
return -999;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// fall through...
|
// fall through...
|
||||||
|
Loading…
x
Reference in New Issue
Block a user