diff options
| author | Odd Stranne <odd@mullvad.net> | 2018-10-05 11:41:31 +0200 |
|---|---|---|
| committer | Odd Stranne <odd@mullvad.net> | 2018-10-06 23:12:19 +0200 |
| commit | 4a6bb4210b5e0e96f076358a87c8cf64feb1934c (patch) | |
| tree | b09c432cc9c05d99c677d28d77fd2b8f33f1892d | |
| parent | f18fefd5e5fc3ac2fa66b5fa667be42e518d9013 (diff) | |
| download | mullvadvpn-4a6bb4210b5e0e96f076358a87c8cf64feb1934c.tar.xz mullvadvpn-4a6bb4210b5e0e96f076358a87c8cf64feb1934c.zip | |
Ignore floating interfaces
| -rw-r--r-- | windows/windns/src/windns/dnsagent.cpp | 20 | ||||
| -rw-r--r-- | windows/windns/src/windns/recoverylogic.cpp | 46 |
2 files changed, 58 insertions, 8 deletions
diff --git a/windows/windns/src/windns/dnsagent.cpp b/windows/windns/src/windns/dnsagent.cpp index 6ff8ee9b39..13fca9613a 100644 --- a/windows/windns/src/windns/dnsagent.cpp +++ b/windows/windns/src/windns/dnsagent.cpp @@ -363,13 +363,29 @@ void DnsAgent::setNameServers(const std::wstring &interfaceGuid, const std::vect { XTRACE(L"Overriding name servers for interface ", interfaceGuid); + uint32_t interfaceIndex = 0; + + try + { + interfaceIndex = NetSh::ConvertInterfaceGuidToIndex(interfaceGuid); + } + catch (...) + { + // + // The interface cannot be linked to a virtual or physical adapter. + // + + XTRACE(L"Ignoring floating interface ", interfaceGuid); + return; + } + if (Protocol::IPv4 == m_protocol) { - NetSh::Instance().SetIpv4StaticDns(NetSh::ConvertInterfaceGuidToIndex(interfaceGuid), enforcedServers); + NetSh::Instance().SetIpv4StaticDns(interfaceIndex, enforcedServers); } else { - NetSh::Instance().SetIpv6StaticDns(NetSh::ConvertInterfaceGuidToIndex(interfaceGuid), enforcedServers); + NetSh::Instance().SetIpv6StaticDns(interfaceIndex, enforcedServers); } } diff --git a/windows/windns/src/windns/recoverylogic.cpp b/windows/windns/src/windns/recoverylogic.cpp index 0c630a89b2..6221c3c2b0 100644 --- a/windows/windns/src/windns/recoverylogic.cpp +++ b/windows/windns/src/windns/recoverylogic.cpp @@ -34,15 +34,32 @@ void RecoveryLogic::RestoreInterfaces(const RecoveryFormatter::Unpacked &data, return; } - XTRACE("Resetting name server configuration for interface ", snap.interfaceGuid()); + XTRACE(L"Resetting name server configuration for interface ", snap.interfaceGuid()); + + uint32_t interfaceIndex = 0; + + try + { + interfaceIndex = NetSh::ConvertInterfaceGuidToIndex(snap.interfaceGuid()); + } + catch (...) + { + // + // The interface cannot be linked to a virtual or physical adapter. + // It's either floating or has been removed. + // + + XTRACE(L"Ignoring floating/invalid interface ", snap.interfaceGuid()); + return; + } if (snap.nameServers().empty()) { - NetSh::Instance().SetIpv4DhcpDns(NetSh::ConvertInterfaceGuidToIndex(snap.interfaceGuid()), timeout); + NetSh::Instance().SetIpv4DhcpDns(interfaceIndex, timeout); } else { - NetSh::Instance().SetIpv4StaticDns(NetSh::ConvertInterfaceGuidToIndex(snap.interfaceGuid()), snap.nameServers(), timeout); + NetSh::Instance().SetIpv4StaticDns(interfaceIndex, snap.nameServers(), timeout); } }); @@ -65,15 +82,32 @@ void RecoveryLogic::RestoreInterfaces(const RecoveryFormatter::Unpacked &data, return; } - XTRACE("Resetting name server configuration for interface ", snap.interfaceGuid()); + XTRACE(L"Resetting name server configuration for interface ", snap.interfaceGuid()); + + uint32_t interfaceIndex = 0; + + try + { + interfaceIndex = NetSh::ConvertInterfaceGuidToIndex(snap.interfaceGuid()); + } + catch (...) + { + // + // The interface cannot be linked to a virtual or physical adapter. + // It's either floating or has been removed. + // + + XTRACE(L"Ignoring floating/invalid interface ", snap.interfaceGuid()); + return; + } if (snap.nameServers().empty()) { - NetSh::Instance().SetIpv6DhcpDns(NetSh::ConvertInterfaceGuidToIndex(snap.interfaceGuid()), timeout); + NetSh::Instance().SetIpv6DhcpDns(interfaceIndex, timeout); } else { - NetSh::Instance().SetIpv6StaticDns(NetSh::ConvertInterfaceGuidToIndex(snap.interfaceGuid()), snap.nameServers(), timeout); + NetSh::Instance().SetIpv6StaticDns(interfaceIndex, snap.nameServers(), timeout); } }); |
