mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-01-31 16:35:26 +00:00
Destroy tap devices on Windows 'leave'.
This commit is contained in:
parent
e2c65bf16a
commit
ce09e363dc
@ -789,7 +789,29 @@ void WindowsEthernetTap::destroyAllPersistentTapDevices(const char *pathToHelper
|
||||
}
|
||||
|
||||
for(std::set<std::string>::iterator iidp(instanceIdPathsToRemove.begin());iidp!=instanceIdPathsToRemove.end();++iidp)
|
||||
_deletePersistentTapDevice(pathToHelpers,iidp->c_str());
|
||||
deletePersistentTapDevice(pathToHelpers,iidp->c_str());
|
||||
}
|
||||
|
||||
void WindowsEthernetTap::deletePersistentTapDevice(const char *pathToHelpers,const char *instanceId)
|
||||
{
|
||||
HANDLE devconLog = CreateFileA((std::string(pathToHelpers) + "\\devcon.log").c_str(),GENERIC_WRITE,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
|
||||
STARTUPINFOA startupInfo;
|
||||
startupInfo.cb = sizeof(startupInfo);
|
||||
if (devconLog != INVALID_HANDLE_VALUE) {
|
||||
SetFilePointer(devconLog,0,0,FILE_END);
|
||||
startupInfo.hStdOutput = devconLog;
|
||||
startupInfo.hStdError = devconLog;
|
||||
}
|
||||
PROCESS_INFORMATION processInfo;
|
||||
memset(&startupInfo,0,sizeof(STARTUPINFOA));
|
||||
memset(&processInfo,0,sizeof(PROCESS_INFORMATION));
|
||||
if (CreateProcessA(NULL,(LPSTR)(std::string("\"") + pathToHelpers + WINENV.devcon + "\" remove @" + instanceId).c_str(),NULL,NULL,FALSE,0,NULL,NULL,&startupInfo,&processInfo)) {
|
||||
WaitForSingleObject(processInfo.hProcess,INFINITE);
|
||||
CloseHandle(processInfo.hProcess);
|
||||
CloseHandle(processInfo.hThread);
|
||||
}
|
||||
if (devconLog != INVALID_HANDLE_VALUE)
|
||||
CloseHandle(devconLog);
|
||||
}
|
||||
|
||||
bool WindowsEthernetTap::_disableTapDevice()
|
||||
@ -922,26 +944,4 @@ void WindowsEthernetTap::_setRegistryIPv4Value(const char *regKey,const std::vec
|
||||
}
|
||||
}
|
||||
|
||||
void WindowsEthernetTap::_deletePersistentTapDevice(const char *pathToHelpers,const char *instanceId)
|
||||
{
|
||||
HANDLE devconLog = CreateFileA((std::string(pathToHelpers) + "\\devcon.log").c_str(),GENERIC_WRITE,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
|
||||
STARTUPINFOA startupInfo;
|
||||
startupInfo.cb = sizeof(startupInfo);
|
||||
if (devconLog != INVALID_HANDLE_VALUE) {
|
||||
SetFilePointer(devconLog,0,0,FILE_END);
|
||||
startupInfo.hStdOutput = devconLog;
|
||||
startupInfo.hStdError = devconLog;
|
||||
}
|
||||
PROCESS_INFORMATION processInfo;
|
||||
memset(&startupInfo,0,sizeof(STARTUPINFOA));
|
||||
memset(&processInfo,0,sizeof(PROCESS_INFORMATION));
|
||||
if (CreateProcessA(NULL,(LPSTR)(std::string("\"") + pathToHelpers + WINENV.devcon + "\" remove @" + instanceId).c_str(),NULL,NULL,FALSE,0,NULL,NULL,&startupInfo,&processInfo)) {
|
||||
WaitForSingleObject(processInfo.hProcess,INFINITE);
|
||||
CloseHandle(processInfo.hProcess);
|
||||
CloseHandle(processInfo.hThread);
|
||||
}
|
||||
if (devconLog != INVALID_HANDLE_VALUE)
|
||||
CloseHandle(devconLog);
|
||||
}
|
||||
|
||||
} // namespace ZeroTier
|
||||
|
@ -78,6 +78,7 @@ public:
|
||||
throw();
|
||||
|
||||
static void destroyAllPersistentTapDevices(const char *pathToHelpers);
|
||||
static void deletePersistentTapDevice(const char *pathToHelpers,const char *instanceId);
|
||||
|
||||
private:
|
||||
bool _disableTapDevice();
|
||||
@ -85,7 +86,6 @@ private:
|
||||
NET_IFINDEX _getDeviceIndex(); // throws on failure
|
||||
std::vector<std::string> _getRegistryIPv4Value(const char *regKey);
|
||||
void _setRegistryIPv4Value(const char *regKey,const std::vector<std::string> &value);
|
||||
static void _deletePersistentTapDevice(const char *pathToHelpers,const char *instanceId);
|
||||
|
||||
void (*_handler)(void *,uint64_t,const MAC &,const MAC &,unsigned int,unsigned int,const void *,unsigned int);
|
||||
void *_arg;
|
||||
|
@ -461,9 +461,16 @@ public:
|
||||
case ZT1_VIRTUAL_NETWORK_CONFIG_OPERATION_DOWN:
|
||||
case ZT1_VIRTUAL_NETWORK_CONFIG_OPERATION_DESTROY:
|
||||
if (t != _taps.end()) {
|
||||
#ifdef __WINDOWS__
|
||||
std::string winInstanceId(t->second->instanceId());
|
||||
#endif
|
||||
delete t->second;
|
||||
_taps.erase(t);
|
||||
_tapAssignedIps.erase(nwid);
|
||||
#ifdef __WINDOWS__
|
||||
if ((op == ZT1_VIRTUAL_NETWORK_CONFIG_OPERATION_DESTROY)&&(winInstanceId.length() > 0))
|
||||
WindowsEthernetTap::deletePersistentTapDevice(_homePath.c_str(),winInstanceId.c_str());
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user