mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-06-05 03:53:44 +02:00
Tap now basically sorta works on Windows. Now have to figure out how to control DHCP behavior since we normally don't want that.
This commit is contained in:
parent
335733f110
commit
b4be07149f
2 changed files with 28 additions and 7 deletions
|
@ -714,7 +714,7 @@ static inline std::pair<NET_LUID,NET_IFINDEX> _findAdapterByGuid(const GUID &gui
|
||||||
for(ULONG i=0;i<ift->NumEntries;++i) {
|
for(ULONG i=0;i<ift->NumEntries;++i) {
|
||||||
if (ift->Table[i].InterfaceGuid == guid) {
|
if (ift->Table[i].InterfaceGuid == guid) {
|
||||||
std::pair<NET_LUID,NET_IFINDEX> tmp(ift->Table[i].InterfaceLuid,ift->Table[i].InterfaceIndex);
|
std::pair<NET_LUID,NET_IFINDEX> tmp(ift->Table[i].InterfaceLuid,ift->Table[i].InterfaceIndex);
|
||||||
FreeMibTable(&ift);
|
FreeMibTable(ift);
|
||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -751,10 +751,10 @@ EthernetTap::EthernetTap(
|
||||||
throw std::runtime_error("MTU too large for Windows tap");
|
throw std::runtime_error("MTU too large for Windows tap");
|
||||||
|
|
||||||
#ifdef _WIN64
|
#ifdef _WIN64
|
||||||
const char *devcon = "\\devcon64.exe";
|
const char *devcon = "\\devcon64.exe";
|
||||||
#else
|
#else
|
||||||
BOOL f64 = FALSE;
|
BOOL f64 = FALSE;
|
||||||
const char *devcon = ((IsWow64Process(GetCurrentProcess(),&f64) == TRUE) ? "\\devcon64.exe" : "\\devcon32.exe");
|
const char *devcon = ((IsWow64Process(GetCurrentProcess(),&f64) == TRUE) ? "\\devcon64.exe" : "\\devcon32.exe");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Mutex::Lock _l(_systemTapInitLock); // only init one tap at a time, process-wide
|
Mutex::Lock _l(_systemTapInitLock); // only init one tap at a time, process-wide
|
||||||
|
@ -961,6 +961,26 @@ EthernetTap::~EthernetTap()
|
||||||
CloseHandle(_tapOvlRead.hEvent);
|
CloseHandle(_tapOvlRead.hEvent);
|
||||||
CloseHandle(_tapOvlWrite.hEvent);
|
CloseHandle(_tapOvlWrite.hEvent);
|
||||||
CloseHandle(_injectSemaphore);
|
CloseHandle(_injectSemaphore);
|
||||||
|
|
||||||
|
// Disable network device on shutdown
|
||||||
|
#ifdef _WIN64
|
||||||
|
const char *devcon = "\\devcon64.exe";
|
||||||
|
#else
|
||||||
|
BOOL f64 = FALSE;
|
||||||
|
const char *devcon = ((IsWow64Process(GetCurrentProcess(),&f64) == TRUE) ? "\\devcon64.exe" : "\\devcon32.exe");
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
STARTUPINFOA startupInfo;
|
||||||
|
startupInfo.cb = sizeof(startupInfo);
|
||||||
|
PROCESS_INFORMATION processInfo;
|
||||||
|
memset(&startupInfo,0,sizeof(STARTUPINFOA));
|
||||||
|
memset(&processInfo,0,sizeof(PROCESS_INFORMATION));
|
||||||
|
if (CreateProcessA(NULL,(LPSTR)(std::string("\"") + _r->homePath + devcon + "\" disable @" + _myDeviceInstanceIdPath).c_str(),NULL,NULL,FALSE,0,NULL,NULL,&startupInfo,&processInfo)) {
|
||||||
|
WaitForSingleObject(processInfo.hProcess,INFINITE);
|
||||||
|
CloseHandle(processInfo.hProcess);
|
||||||
|
CloseHandle(processInfo.hThread);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void EthernetTap::whack()
|
void EthernetTap::whack()
|
||||||
|
@ -1026,7 +1046,7 @@ bool EthernetTap::removeIP(const InetAddress &ip)
|
||||||
}
|
}
|
||||||
if (addr == ip) {
|
if (addr == ip) {
|
||||||
DeleteUnicastIpAddressEntry(&(ipt->Table[i]));
|
DeleteUnicastIpAddressEntry(&(ipt->Table[i]));
|
||||||
FreeMibTable(&ipt);
|
FreeMibTable(ipt);
|
||||||
Mutex::Lock _l(_ips_m);
|
Mutex::Lock _l(_ips_m);
|
||||||
_ips.erase(ip);
|
_ips.erase(ip);
|
||||||
return true;
|
return true;
|
||||||
|
@ -1060,7 +1080,7 @@ std::set<InetAddress> EthernetTap::allIps() const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
FreeMibTable(&ipt);
|
FreeMibTable(ipt);
|
||||||
}
|
}
|
||||||
} catch ( ... ) {}
|
} catch ( ... ) {}
|
||||||
|
|
||||||
|
|
|
@ -167,14 +167,15 @@ UdpSocket::UdpSocket(
|
||||||
|
|
||||||
UdpSocket::~UdpSocket()
|
UdpSocket::~UdpSocket()
|
||||||
{
|
{
|
||||||
int s = _sock;
|
|
||||||
#ifdef __WINDOWS__
|
#ifdef __WINDOWS__
|
||||||
|
SOCKET s = _sock;
|
||||||
_sock = INVALID_SOCKET;
|
_sock = INVALID_SOCKET;
|
||||||
if (s != INVALID_SOCKET) {
|
if (s != INVALID_SOCKET) {
|
||||||
::shutdown(s,SD_BOTH);
|
::shutdown(s,SD_BOTH);
|
||||||
::closesocket(s);
|
::closesocket(s);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
int s = _sock;
|
||||||
_sock = 0;
|
_sock = 0;
|
||||||
if (s > 0) {
|
if (s > 0) {
|
||||||
::shutdown(s,SHUT_RDWR);
|
::shutdown(s,SHUT_RDWR);
|
||||||
|
|
Loading…
Add table
Reference in a new issue