summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Ierymenko <adam.ierymenko@zerotier.com>2014-04-08 16:10:48 -0700
committerAdam Ierymenko <adam.ierymenko@zerotier.com>2014-04-08 16:10:48 -0700
commit48a1799f49da8c9f36a41a8a378bdc1c26bf70f8 (patch)
tree89af22c952eb78518687528bd2d8081084bbf09b
parentbf24de43fe4050923e564e1375a1661954bebe8d (diff)
downloadinfinitytier-48a1799f49da8c9f36a41a8a378bdc1c26bf70f8.tar.gz
infinitytier-48a1799f49da8c9f36a41a8a378bdc1c26bf70f8.zip
More Windows tap cleanup... seems solid. We'll see.
-rw-r--r--ext/installfiles/windows/ZeroTier One.aip2
-rw-r--r--node/WindowsEthernetTap.cpp21
2 files changed, 12 insertions, 11 deletions
diff --git a/ext/installfiles/windows/ZeroTier One.aip b/ext/installfiles/windows/ZeroTier One.aip
index 4b65a681..ef2d8530 100644
--- a/ext/installfiles/windows/ZeroTier One.aip
+++ b/ext/installfiles/windows/ZeroTier One.aip
@@ -20,7 +20,7 @@
<ROW Property="CTRLS" Value="2"/>
<ROW Property="MSIFASTINSTALL" MultiBuildValue="DefaultBuild:2"/>
<ROW Property="Manufacturer" Value="ZeroTier Networks LLC"/>
- <ROW Property="ProductCode" Value="1033:{D74139EC-0303-454F-8812-2407A0ED13B3} " Type="16"/>
+ <ROW Property="ProductCode" Value="1033:{8DCAA7E9-E403-417C-AE92-C55DC32CA7B5} " Type="16"/>
<ROW Property="ProductLanguage" Value="1033"/>
<ROW Property="ProductName" Value="ZeroTier One"/>
<ROW Property="ProductVersion" Value="0.8.0" Type="32"/>
diff --git a/node/WindowsEthernetTap.cpp b/node/WindowsEthernetTap.cpp
index 792e960d..ea7f7510 100644
--- a/node/WindowsEthernetTap.cpp
+++ b/node/WindowsEthernetTap.cpp
@@ -80,7 +80,7 @@ static inline std::pair<NET_LUID,NET_IFINDEX> _findAdapterByGuid(const GUID &gui
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;
// Compute some basic environment stuff on startup
@@ -217,7 +217,7 @@ WindowsEthernetTap::WindowsEthernetTap(
if (mtu > ZT_IF_MTU)
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;
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));
tmp = 0;
RegSetKeyValueA(nwAdapters,mySubkeyName.c_str(),"EnableDHCP",REG_DWORD,(LPCVOID)&tmp,sizeof(tmp));
+ RegCloseKey(nwAdapters);
} else {
RegCloseKey(nwAdapters);
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?
{
char nobraces[128];
@@ -438,10 +437,14 @@ bool WindowsEthernetTap::addIP(const InetAddress &ip)
ipr.Address.Ipv4.sin_family = AF_INET;
ipr.Address.Ipv4.sin_addr.S_un.S_addr = *((const uint32_t *)ip.rawIpData());
ipr.OnLinkPrefixLength = ip.port();
+ if (ipr.OnLinkPrefixLength >= 32)
+ return false;
} else if (ip.isV6()) {
ipr.Address.Ipv6.sin6_family = AF_INET6;
memcpy(ipr.Address.Ipv6.sin6_addr.u.Byte,ip.rawIpData(),16);
ipr.OnLinkPrefixLength = ip.port();
+ if (ipr.OnLinkPrefixLength >= 128)
+ return false;
} else return false;
ipr.PrefixOrigin = IpPrefixOriginManual;
@@ -463,10 +466,12 @@ bool WindowsEthernetTap::addIP(const InetAddress &ip)
_syncIpsWithRegistry(haveIps,_netCfgInstanceId);
} catch (std::exception &exc) {
LOG("unexpected exception adding IP address %s to %s: %s",ip.toString().c_str(),deviceName().c_str(),exc.what());
+ return false;
} catch ( ... ) {
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)
@@ -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)
{
- if ((!_initialized)||(!_enabled))
+ if ((!_initialized)||(!_enabled)||(_tap == INVALID_HANDLE_VALUE)||(len > (ZT_IF_MTU)))
return;
- if (len > (ZT_IF_MTU))
- return; // sanity check
-
{
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) );
@@ -561,7 +563,6 @@ void WindowsEthernetTap::put(const MAC &from,const MAC &to,unsigned int etherTyp
d[13] = (char)(etherType & 0xff);
memcpy(d + 14,data,len);
}
-
ReleaseSemaphore(_injectSemaphore,1,NULL);
}