Dont write IPv6 addresses to IPv4 sections of registry TCPIP settings.

Also, dont add the prefix length to the IP addresses in there.

Appears to fix Github Issue #357.  Still waiting on some info from Microsoft for confirmation of a few things.
This commit is contained in:
Grant Limberg 2016-12-09 11:36:01 -08:00
parent 244f37179c
commit 697520f1f5

View file

@ -672,6 +672,7 @@ bool WindowsEthernetTap::addIp(const InetAddress &ip)
{ {
if (!ip.netmaskBits()) // sanity check... netmask of 0.0.0.0 is WUT? if (!ip.netmaskBits()) // sanity check... netmask of 0.0.0.0 is WUT?
return false; return false;
Mutex::Lock _l(_assignedIps_m); Mutex::Lock _l(_assignedIps_m);
if (std::find(_assignedIps.begin(),_assignedIps.end(),ip) != _assignedIps.end()) if (std::find(_assignedIps.begin(),_assignedIps.end(),ip) != _assignedIps.end())
return true; return true;
@ -682,6 +683,9 @@ bool WindowsEthernetTap::addIp(const InetAddress &ip)
bool WindowsEthernetTap::removeIp(const InetAddress &ip) bool WindowsEthernetTap::removeIp(const InetAddress &ip)
{ {
if (ip.isV6())
return true;
{ {
Mutex::Lock _l(_assignedIps_m); Mutex::Lock _l(_assignedIps_m);
std::vector<InetAddress>::iterator aip(std::find(_assignedIps.begin(),_assignedIps.end(),ip)); std::vector<InetAddress>::iterator aip(std::find(_assignedIps.begin(),_assignedIps.end(),ip));
@ -713,17 +717,19 @@ bool WindowsEthernetTap::removeIp(const InetAddress &ip)
DeleteUnicastIpAddressEntry(&(ipt->Table[i])); DeleteUnicastIpAddressEntry(&(ipt->Table[i]));
FreeMibTable(ipt); FreeMibTable(ipt);
if (ip.isV4()) {
std::vector<std::string> regIps(_getRegistryIPv4Value("IPAddress")); std::vector<std::string> regIps(_getRegistryIPv4Value("IPAddress"));
std::vector<std::string> regSubnetMasks(_getRegistryIPv4Value("SubnetMask")); std::vector<std::string> regSubnetMasks(_getRegistryIPv4Value("SubnetMask"));
std::string ipstr(ip.toIpString()); std::string ipstr(ip.toIpString());
for(std::vector<std::string>::iterator rip(regIps.begin()),rm(regSubnetMasks.begin());((rip!=regIps.end())&&(rm!=regSubnetMasks.end()));++rip,++rm) { for (std::vector<std::string>::iterator rip(regIps.begin()), rm(regSubnetMasks.begin()); ((rip != regIps.end()) && (rm != regSubnetMasks.end())); ++rip, ++rm) {
if (*rip == ipstr) { if (*rip == ipstr) {
regIps.erase(rip); regIps.erase(rip);
regSubnetMasks.erase(rm); regSubnetMasks.erase(rm);
_setRegistryIPv4Value("IPAddress",regIps); _setRegistryIPv4Value("IPAddress", regIps);
_setRegistryIPv4Value("SubnetMask",regSubnetMasks); _setRegistryIPv4Value("SubnetMask", regSubnetMasks);
break; break;
} }
}
} }
return true; return true;
@ -1195,14 +1201,17 @@ void WindowsEthernetTap::_syncIps()
CreateUnicastIpAddressEntry(&ipr); CreateUnicastIpAddressEntry(&ipr);
} }
std::string ipStr(aip->toString()); if (aip->isV4())
{
std::string ipStr(aip->toIpString());
std::vector<std::string> regIps(_getRegistryIPv4Value("IPAddress")); std::vector<std::string> regIps(_getRegistryIPv4Value("IPAddress"));
if (std::find(regIps.begin(),regIps.end(),ipStr) == regIps.end()) { if (std::find(regIps.begin(), regIps.end(), ipStr) == regIps.end()) {
std::vector<std::string> regSubnetMasks(_getRegistryIPv4Value("SubnetMask")); std::vector<std::string> regSubnetMasks(_getRegistryIPv4Value("SubnetMask"));
regIps.push_back(ipStr); regIps.push_back(ipStr);
regSubnetMasks.push_back(aip->netmask().toIpString()); regSubnetMasks.push_back(aip->netmask().toIpString());
_setRegistryIPv4Value("IPAddress",regIps); _setRegistryIPv4Value("IPAddress", regIps);
_setRegistryIPv4Value("SubnetMask",regSubnetMasks); _setRegistryIPv4Value("SubnetMask", regSubnetMasks);
}
} }
} }
} }