mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2024-12-22 14:22:23 +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
|
||||
*
|
||||
* 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;
|
||||
|
||||
|
@ -263,6 +263,7 @@ static inline void _intl_freeifmaddrs(struct _intl_ifmaddrs *ifmp)
|
||||
#include "../node/Constants.hpp"
|
||||
#include "../node/Utils.hpp"
|
||||
#include "../node/Mutex.hpp"
|
||||
#include "../node/Dictionary.hpp"
|
||||
#include "OSUtils.hpp"
|
||||
#include "OSXEthernetTap.hpp"
|
||||
|
||||
@ -333,14 +334,16 @@ OSXEthernetTap::OSXEthernetTap(
|
||||
_fd(0),
|
||||
_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;
|
||||
|
||||
Mutex::Lock _gl(globalTapCreateLock);
|
||||
Utils::snprintf(nwids,sizeof(nwids),"%.16llx",nwid);
|
||||
|
||||
if (mtu > 2800)
|
||||
throw std::runtime_error("max tap MTU is 2800");
|
||||
|
||||
Mutex::Lock _gl(globalTapCreateLock);
|
||||
|
||||
if (stat("/dev/zt0",&stattmp)) {
|
||||
if (homePath) {
|
||||
long kextpid = (long)vfork();
|
||||
@ -362,11 +365,13 @@ OSXEthernetTap::OSXEthernetTap(
|
||||
|
||||
// Try to reopen the last device we had, if we had one and it's still unused.
|
||||
bool recalledDevice = false;
|
||||
/*
|
||||
if ((desiredDevice)&&(desiredDevice[0] == 'z')&&(desiredDevice[1] == 't')) {
|
||||
if ((strchr(desiredDevice,'/'))||(strchr(desiredDevice,'.'))) // security sanity check
|
||||
throw std::runtime_error("invalid desiredDevice parameter");
|
||||
Utils::snprintf(devpath,sizeof(devpath),"/dev/%s",desiredDevice);
|
||||
std::string devmapbuf;
|
||||
Dictionary devmap;
|
||||
if (OSUtils::readFile((_homePath + ZT_PATH_SEPARATOR_S + "devicemap").c_str(),devmapbuf)) {
|
||||
devmap.fromString(devmapbuf);
|
||||
std::string desiredDevice(devmap.get(nwids,""));
|
||||
if (desiredDevice.length() > 2) {
|
||||
Utils::snprintf(devpath,sizeof(devpath),"/dev/%s",desiredDevice.c_str());
|
||||
if (stat(devpath,&stattmp) == 0) {
|
||||
_fd = ::open(devpath,O_RDWR);
|
||||
if (_fd > 0) {
|
||||
@ -375,7 +380,7 @@ OSXEthernetTap::OSXEthernetTap(
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
// Open the first unused tap device if we didn't recall a previous one.
|
||||
if (!recalledDevice) {
|
||||
@ -425,9 +430,12 @@ OSXEthernetTap::OSXEthernetTap(
|
||||
|
||||
::pipe(_shutdownSignalPipe);
|
||||
|
||||
_thread = Thread::start(this);
|
||||
|
||||
++globalTapsRunning;
|
||||
|
||||
devmap[nwids] = _dev;
|
||||
OSUtils::writeFile((_homePath + ZT_PATH_SEPARATOR_S + "devicemap").c_str(),devmap.toString());
|
||||
|
||||
_thread = Thread::start(this);
|
||||
}
|
||||
|
||||
OSXEthernetTap::~OSXEthernetTap()
|
||||
|
@ -409,7 +409,7 @@ public:
|
||||
StapFrameHandler,
|
||||
(void *)this))).first;
|
||||
} catch ( ... ) {
|
||||
return -2;
|
||||
return -999;
|
||||
}
|
||||
}
|
||||
// fall through...
|
||||
|
Loading…
Reference in New Issue
Block a user