mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-06-05 03:53:44 +02:00
Some Mac feth tap changes to hopefully fix slow-leave problem.
This commit is contained in:
parent
1331739ee4
commit
fe5aad3cef
3 changed files with 52 additions and 11 deletions
|
@ -79,6 +79,7 @@ MacEthernetTap::MacEthernetTap(
|
||||||
_homePath(homePath),
|
_homePath(homePath),
|
||||||
_mtu(mtu),
|
_mtu(mtu),
|
||||||
_metric(metric),
|
_metric(metric),
|
||||||
|
_devNo(0),
|
||||||
_agentStdin(-1),
|
_agentStdin(-1),
|
||||||
_agentStdout(-1),
|
_agentStdout(-1),
|
||||||
_agentStderr(-1),
|
_agentStderr(-1),
|
||||||
|
@ -97,7 +98,7 @@ MacEthernetTap::MacEthernetTap(
|
||||||
agentPath.push_back(ZT_PATH_SEPARATOR);
|
agentPath.push_back(ZT_PATH_SEPARATOR);
|
||||||
agentPath.append("MacEthernetTapAgent");
|
agentPath.append("MacEthernetTapAgent");
|
||||||
if (!OSUtils::fileExists(agentPath.c_str()))
|
if (!OSUtils::fileExists(agentPath.c_str()))
|
||||||
throw std::runtime_error("MacEthernetTapAgent not installed in ZeroTier home");
|
throw std::runtime_error("MacEthernetTapAgent not present in ZeroTier home");
|
||||||
|
|
||||||
Mutex::Lock _gl(globalTapCreateLock); // only make one at a time
|
Mutex::Lock _gl(globalTapCreateLock); // only make one at a time
|
||||||
|
|
||||||
|
@ -112,7 +113,7 @@ MacEthernetTap::MacEthernetTap(
|
||||||
while (p) {
|
while (p) {
|
||||||
int nameLen = (int)strlen(p->ifa_name);
|
int nameLen = (int)strlen(p->ifa_name);
|
||||||
// Delete feth# from feth0 to feth9999, but don't touch >10000.
|
// Delete feth# from feth0 to feth9999, but don't touch >10000.
|
||||||
if ((!strncmp(p->ifa_name,"feth",4))&&(nameLen >= 5)&&(nameLen < 9)&&(deleted.count(std::string(p->ifa_name)) == 0)) {
|
if ((!strncmp(p->ifa_name,"feth",4))&&(nameLen >= 5)&&(nameLen <= 8)&&(deleted.count(std::string(p->ifa_name)) == 0)) {
|
||||||
deleted.insert(std::string(p->ifa_name));
|
deleted.insert(std::string(p->ifa_name));
|
||||||
const char *args[4];
|
const char *args[4];
|
||||||
args[0] = "/sbin/ifconfig";
|
args[0] = "/sbin/ifconfig";
|
||||||
|
@ -156,10 +157,11 @@ MacEthernetTap::MacEthernetTap(
|
||||||
if (devNo < 100)
|
if (devNo < 100)
|
||||||
devNo = 100;
|
devNo = 100;
|
||||||
} else {
|
} else {
|
||||||
|
_dev = devstr;
|
||||||
|
_devNo = devNo;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_dev = devstr;
|
|
||||||
|
|
||||||
if (::pipe(_shutdownSignalPipe))
|
if (::pipe(_shutdownSignalPipe))
|
||||||
throw std::runtime_error("pipe creation failed");
|
throw std::runtime_error("pipe creation failed");
|
||||||
|
@ -204,22 +206,60 @@ MacEthernetTap::MacEthernetTap(
|
||||||
|
|
||||||
MacEthernetTap::~MacEthernetTap()
|
MacEthernetTap::~MacEthernetTap()
|
||||||
{
|
{
|
||||||
|
char tmp[64];
|
||||||
|
const char *args[4];
|
||||||
|
pid_t pid0,pid1;
|
||||||
|
|
||||||
MacDNSHelper::removeDNS(_nwid);
|
MacDNSHelper::removeDNS(_nwid);
|
||||||
|
|
||||||
Mutex::Lock _gl(globalTapCreateLock);
|
Mutex::Lock _gl(globalTapCreateLock);
|
||||||
::write(_shutdownSignalPipe[1],"\0",1); // causes thread to exit
|
::write(_shutdownSignalPipe[1],"\0",1); // causes thread to exit
|
||||||
Thread::join(_thread);
|
|
||||||
::close(_shutdownSignalPipe[0]);
|
::close(_shutdownSignalPipe[0]);
|
||||||
::close(_shutdownSignalPipe[1]);
|
::close(_shutdownSignalPipe[1]);
|
||||||
|
|
||||||
int ec = 0;
|
int ec = 0;
|
||||||
::kill(_agentPid,SIGTERM);
|
::kill(_agentPid,SIGKILL);
|
||||||
::waitpid(_agentPid,&ec,0);
|
|
||||||
::close(_agentStdin);
|
::close(_agentStdin);
|
||||||
::close(_agentStdout);
|
::close(_agentStdout);
|
||||||
::close(_agentStderr);
|
::close(_agentStderr);
|
||||||
::close(_agentStdin2);
|
::close(_agentStdin2);
|
||||||
::close(_agentStdout2);
|
::close(_agentStdout2);
|
||||||
::close(_agentStderr2);
|
::close(_agentStderr2);
|
||||||
|
|
||||||
|
::waitpid(_agentPid,&ec,0);
|
||||||
|
|
||||||
|
args[0] = "/sbin/ifconfig";
|
||||||
|
args[1] = _dev.c_str();
|
||||||
|
args[2] = "destroy";
|
||||||
|
args[3] = (char *)0;
|
||||||
|
pid0 = vfork();
|
||||||
|
if (pid0 == 0) {
|
||||||
|
execv(args[0],const_cast<char **>(args));
|
||||||
|
_exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
snprintf(tmp,sizeof(tmp),"feth%u",_devNo + 5000);
|
||||||
|
//args[0] = "/sbin/ifconfig";
|
||||||
|
args[1] = tmp;
|
||||||
|
//args[2] = "destroy";
|
||||||
|
//args[3] = (char *)0;
|
||||||
|
pid1 = vfork();
|
||||||
|
if (pid1 == 0) {
|
||||||
|
execv(args[0],const_cast<char **>(args));
|
||||||
|
_exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pid0 > 0) {
|
||||||
|
int rv = 0;
|
||||||
|
waitpid(pid0,&rv,0);
|
||||||
|
}
|
||||||
|
if (pid1 > 0) {
|
||||||
|
int rv = 0;
|
||||||
|
waitpid(pid1,&rv,0);
|
||||||
|
}
|
||||||
|
|
||||||
|
Thread::join(_thread);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MacEthernetTap::setEnabled(bool en) { _enabled = en; }
|
void MacEthernetTap::setEnabled(bool en) { _enabled = en; }
|
||||||
|
|
|
@ -72,6 +72,7 @@ private:
|
||||||
Mutex _putLock;
|
Mutex _putLock;
|
||||||
unsigned int _mtu;
|
unsigned int _mtu;
|
||||||
unsigned int _metric;
|
unsigned int _metric;
|
||||||
|
unsigned int _devNo;
|
||||||
int _shutdownSignalPipe[2];
|
int _shutdownSignalPipe[2];
|
||||||
int _agentStdin,_agentStdout,_agentStderr,_agentStdin2,_agentStdout2,_agentStderr2;
|
int _agentStdin,_agentStdout,_agentStderr,_agentStdin2,_agentStdout2,_agentStderr2;
|
||||||
long _agentPid;
|
long _agentPid;
|
||||||
|
|
|
@ -29,13 +29,13 @@
|
||||||
* is limited to 2048. AF_NDRV packet injection is required to inject
|
* is limited to 2048. AF_NDRV packet injection is required to inject
|
||||||
* ZeroTier's large MTU frames.
|
* ZeroTier's large MTU frames.
|
||||||
*
|
*
|
||||||
* Benchmarks show that this performs similarly to the old tap.kext driver,
|
|
||||||
* and a kext is no longer required. Splitting it off into an agent will
|
|
||||||
* also make it easier to have zerotier-one itself drop permissions.
|
|
||||||
*
|
|
||||||
* All this stuff is basically undocumented. A lot of tracing through
|
* All this stuff is basically undocumented. A lot of tracing through
|
||||||
* the Darwin/XNU kernel source was required to figure out how to make
|
* the Darwin/XNU kernel source was required to figure out how to make
|
||||||
* this actually work.
|
* this actually work.
|
||||||
|
*
|
||||||
|
* We hope to develop a DriverKit-based driver in the near-mid future to
|
||||||
|
* replace this weird hack, but it works for now through Big Sur in our
|
||||||
|
* testing.
|
||||||
*
|
*
|
||||||
* See also:
|
* See also:
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Reference in a new issue