|
@@ -80,7 +80,7 @@ static inline std::pair<NET_LUID,NET_IFINDEX> _findAdapterByGuid(const GUID &gui
|
|
throw std::runtime_error("interface not found");
|
|
throw std::runtime_error("interface not found");
|
|
}
|
|
}
|
|
|
|
|
|
-// Only create or manipulate devices one at a time to avoid weird driver layer demons
|
|
|
|
|
|
+// Only create or delete devices one at a time
|
|
static Mutex _systemTapInitLock;
|
|
static Mutex _systemTapInitLock;
|
|
|
|
|
|
// Compute some basic environment stuff on startup
|
|
// Compute some basic environment stuff on startup
|
|
@@ -217,7 +217,7 @@ WindowsEthernetTap::WindowsEthernetTap(
|
|
if (mtu > ZT_IF_MTU)
|
|
if (mtu > ZT_IF_MTU)
|
|
throw std::runtime_error("MTU too large for Windows tap");
|
|
throw std::runtime_error("MTU too large for Windows tap");
|
|
|
|
|
|
- Mutex::Lock _l(_systemTapInitLock); // only one thread may mess with taps at a time, process-wide
|
|
|
|
|
|
+ Mutex::Lock _l(_systemTapInitLock);
|
|
|
|
|
|
HKEY nwAdapters;
|
|
HKEY nwAdapters;
|
|
if (RegOpenKeyExA(HKEY_LOCAL_MACHINE,"SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002BE10318}",0,KEY_READ|KEY_WRITE,&nwAdapters) != ERROR_SUCCESS)
|
|
if (RegOpenKeyExA(HKEY_LOCAL_MACHINE,"SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002BE10318}",0,KEY_READ|KEY_WRITE,&nwAdapters) != ERROR_SUCCESS)
|
|
@@ -358,13 +358,12 @@ WindowsEthernetTap::WindowsEthernetTap(
|
|
RegSetKeyValueA(nwAdapters,mySubkeyName.c_str(),"MTU",REG_DWORD,(LPCVOID)&tmp,sizeof(tmp));
|
|
RegSetKeyValueA(nwAdapters,mySubkeyName.c_str(),"MTU",REG_DWORD,(LPCVOID)&tmp,sizeof(tmp));
|
|
tmp = 0;
|
|
tmp = 0;
|
|
RegSetKeyValueA(nwAdapters,mySubkeyName.c_str(),"EnableDHCP",REG_DWORD,(LPCVOID)&tmp,sizeof(tmp));
|
|
RegSetKeyValueA(nwAdapters,mySubkeyName.c_str(),"EnableDHCP",REG_DWORD,(LPCVOID)&tmp,sizeof(tmp));
|
|
|
|
+ RegCloseKey(nwAdapters);
|
|
} else {
|
|
} else {
|
|
RegCloseKey(nwAdapters);
|
|
RegCloseKey(nwAdapters);
|
|
throw std::runtime_error("unable to find or create tap adapter");
|
|
throw std::runtime_error("unable to find or create tap adapter");
|
|
}
|
|
}
|
|
|
|
|
|
- RegCloseKey(nwAdapters);
|
|
|
|
-
|
|
|
|
// Convert device GUID junk... blech... is there an easier way to do this?
|
|
// Convert device GUID junk... blech... is there an easier way to do this?
|
|
{
|
|
{
|
|
char nobraces[128];
|
|
char nobraces[128];
|
|
@@ -438,10 +437,14 @@ bool WindowsEthernetTap::addIP(const InetAddress &ip)
|
|
ipr.Address.Ipv4.sin_family = AF_INET;
|
|
ipr.Address.Ipv4.sin_family = AF_INET;
|
|
ipr.Address.Ipv4.sin_addr.S_un.S_addr = *((const uint32_t *)ip.rawIpData());
|
|
ipr.Address.Ipv4.sin_addr.S_un.S_addr = *((const uint32_t *)ip.rawIpData());
|
|
ipr.OnLinkPrefixLength = ip.port();
|
|
ipr.OnLinkPrefixLength = ip.port();
|
|
|
|
+ if (ipr.OnLinkPrefixLength >= 32)
|
|
|
|
+ return false;
|
|
} else if (ip.isV6()) {
|
|
} else if (ip.isV6()) {
|
|
ipr.Address.Ipv6.sin6_family = AF_INET6;
|
|
ipr.Address.Ipv6.sin6_family = AF_INET6;
|
|
memcpy(ipr.Address.Ipv6.sin6_addr.u.Byte,ip.rawIpData(),16);
|
|
memcpy(ipr.Address.Ipv6.sin6_addr.u.Byte,ip.rawIpData(),16);
|
|
ipr.OnLinkPrefixLength = ip.port();
|
|
ipr.OnLinkPrefixLength = ip.port();
|
|
|
|
+ if (ipr.OnLinkPrefixLength >= 128)
|
|
|
|
+ return false;
|
|
} else return false;
|
|
} else return false;
|
|
|
|
|
|
ipr.PrefixOrigin = IpPrefixOriginManual;
|
|
ipr.PrefixOrigin = IpPrefixOriginManual;
|
|
@@ -463,10 +466,12 @@ bool WindowsEthernetTap::addIP(const InetAddress &ip)
|
|
_syncIpsWithRegistry(haveIps,_netCfgInstanceId);
|
|
_syncIpsWithRegistry(haveIps,_netCfgInstanceId);
|
|
} catch (std::exception &exc) {
|
|
} catch (std::exception &exc) {
|
|
LOG("unexpected exception adding IP address %s to %s: %s",ip.toString().c_str(),deviceName().c_str(),exc.what());
|
|
LOG("unexpected exception adding IP address %s to %s: %s",ip.toString().c_str(),deviceName().c_str(),exc.what());
|
|
|
|
+ return false;
|
|
} catch ( ... ) {
|
|
} catch ( ... ) {
|
|
LOG("unexpected exception adding IP address %s to %s: unknown exception",ip.toString().c_str(),deviceName().c_str());
|
|
LOG("unexpected exception adding IP address %s to %s: unknown exception",ip.toString().c_str(),deviceName().c_str());
|
|
|
|
+ return false;
|
|
}
|
|
}
|
|
- return false;
|
|
|
|
|
|
+ return true;
|
|
}
|
|
}
|
|
|
|
|
|
bool WindowsEthernetTap::removeIP(const InetAddress &ip)
|
|
bool WindowsEthernetTap::removeIP(const InetAddress &ip)
|
|
@@ -546,11 +551,8 @@ std::set<InetAddress> WindowsEthernetTap::ips() const
|
|
|
|
|
|
void WindowsEthernetTap::put(const MAC &from,const MAC &to,unsigned int etherType,const void *data,unsigned int len)
|
|
void WindowsEthernetTap::put(const MAC &from,const MAC &to,unsigned int etherType,const void *data,unsigned int len)
|
|
{
|
|
{
|
|
- if ((!_initialized)||(!_enabled))
|
|
|
|
|
|
+ if ((!_initialized)||(!_enabled)||(_tap == INVALID_HANDLE_VALUE)||(len > (ZT_IF_MTU)))
|
|
return;
|
|
return;
|
|
- if (len > (ZT_IF_MTU))
|
|
|
|
- return; // sanity check
|
|
|
|
-
|
|
|
|
{
|
|
{
|
|
Mutex::Lock _l(_injectPending_m);
|
|
Mutex::Lock _l(_injectPending_m);
|
|
_injectPending.push( std::pair<Array<char,ZT_IF_MTU + 32>,unsigned int>(Array<char,ZT_IF_MTU + 32>(),len + 14) );
|
|
_injectPending.push( std::pair<Array<char,ZT_IF_MTU + 32>,unsigned int>(Array<char,ZT_IF_MTU + 32>(),len + 14) );
|
|
@@ -561,7 +563,6 @@ void WindowsEthernetTap::put(const MAC &from,const MAC &to,unsigned int etherTyp
|
|
d[13] = (char)(etherType & 0xff);
|
|
d[13] = (char)(etherType & 0xff);
|
|
memcpy(d + 14,data,len);
|
|
memcpy(d + 14,data,len);
|
|
}
|
|
}
|
|
-
|
|
|
|
ReleaseSemaphore(_injectSemaphore,1,NULL);
|
|
ReleaseSemaphore(_injectSemaphore,1,NULL);
|
|
}
|
|
}
|
|
|
|
|