diff options
| author | David Lönnhager <david.l@mullvad.net> | 2021-02-18 18:35:46 +0100 |
|---|---|---|
| committer | David Lönnhager <david.l@mullvad.net> | 2021-02-22 11:55:09 +0100 |
| commit | 88071bce90222fc9fd71ab54fc5fa63f558062e4 (patch) | |
| tree | c6aa9eb8c7d42a7a0e47bc3d37c2567e130634e9 /windows | |
| parent | 6f1e7ca077e27861f72770f34b45bd97c4b21031 (diff) | |
| download | mullvadvpn-88071bce90222fc9fd71ab54fc5fa63f558062e4.tar.xz mullvadvpn-88071bce90222fc9fd71ab54fc5fa63f558062e4.zip | |
Remove unused WinNet_EnableIpv6ForAdapter function
Diffstat (limited to 'windows')
| -rw-r--r-- | windows/winnet/src/winnet/netconfig.cpp | 269 | ||||
| -rw-r--r-- | windows/winnet/src/winnet/netconfig.h | 5 | ||||
| -rw-r--r-- | windows/winnet/src/winnet/winnet.cpp | 29 | ||||
| -rw-r--r-- | windows/winnet/src/winnet/winnet.def | 1 | ||||
| -rw-r--r-- | windows/winnet/src/winnet/winnet.h | 10 | ||||
| -rw-r--r-- | windows/winnet/src/winnet/winnet.vcxproj | 2 | ||||
| -rw-r--r-- | windows/winnet/src/winnet/winnet.vcxproj.filters | 2 |
7 files changed, 0 insertions, 318 deletions
diff --git a/windows/winnet/src/winnet/netconfig.cpp b/windows/winnet/src/winnet/netconfig.cpp deleted file mode 100644 index 7fd7b38869..0000000000 --- a/windows/winnet/src/winnet/netconfig.cpp +++ /dev/null @@ -1,269 +0,0 @@ -#include "stdafx.h" -#include "netconfig.h" -#include <stdexcept> -#include <sstream> -#include <windows.h> -#include <netcfgx.h> -#include <devguid.h> -#include <libcommon/registry/registry.h> -#include <libcommon/error.h> -#include <libcommon/string.h> -#include <libcommon/memory.h> -#include <libshared/network/interfaceutils.h> - - -namespace -{ - -const wchar_t NETCFG_LOCK_CLIENT_NAME[] = L"MULLVAD"; -constexpr uint16_t NETCFG_LOCK_TIMEOUT = 5000; // milliseconds -const wchar_t NETCFG_IPV6_COMPONENT_NAME[] = L"MS_TCPIP6"; - -void SetIpv6BindingForBindName(INetCfg *netCfg, const std::wstring &bindName, bool enable) -{ - INetCfgComponent *transactionComponent = nullptr; - HRESULT result = netCfg->FindComponent(NETCFG_IPV6_COMPONENT_NAME, &transactionComponent); - - if (S_OK != result) - { - THROW_ERROR("Failed to obtain transaction component"); - } - - INetCfgComponentBindings *bindings = nullptr; - result = transactionComponent->QueryInterface( - IID_INetCfgComponentBindings, - reinterpret_cast<void**>(&bindings) - ); - - transactionComponent->Release(); - transactionComponent = nullptr; - - if (S_OK != result) - { - std::wstringstream ss; - ss << L"Failed to obtain component bindings for "; - ss << NETCFG_IPV6_COMPONENT_NAME; - THROW_ERROR(common::string::ToAnsi(ss.str()).c_str()); - } - - IEnumNetCfgBindingPath *pathsEnum = NULL; - result = bindings->EnumBindingPaths(EBP_BELOW, &pathsEnum); - - bindings->Release(); - bindings = nullptr; - - if (S_OK != result) - { - THROW_ERROR("Failed to acquire binding path enumerator"); - } - - common::memory::ScopeDestructor pathsEnumDestructor; - pathsEnumDestructor += [&pathsEnum]() { - pathsEnum->Release(); - pathsEnum = nullptr; - }; - - INetCfgBindingPath *bindingPath = NULL; - - result = pathsEnum->Next(1, &bindingPath, nullptr); - - for (; S_OK == result; result = pathsEnum->Next(1, &bindingPath, nullptr)) - { - common::memory::ScopeDestructor bindingPathDestructor; - bindingPathDestructor += [&bindingPath]() { - bindingPath->Release(); - bindingPath = nullptr; - }; - - IEnumNetCfgBindingInterface *enumInterface = nullptr; - HRESULT enumResult = bindingPath->EnumBindingInterfaces(&enumInterface); - - if (S_OK != enumResult) - { - THROW_ERROR("Failed to acquire binding path interfaces"); - } - - common::memory::ScopeDestructor interfaceEnumDestructor; - interfaceEnumDestructor += [&enumInterface]() { - enumInterface->Release(); - enumInterface = nullptr; - }; - - INetCfgBindingInterface *iface = nullptr; - - while (S_OK == enumInterface->Next(1, &iface, nullptr)) - { - INetCfgComponent *cfgComponent = nullptr; - - auto status = iface->GetLowerComponent(&cfgComponent); - - iface->Release(); - iface = nullptr; - - if (S_OK != status) - { - THROW_ERROR("Failed to acquire binding interface component"); - } - - wchar_t *componentBindName = 0; - - status = cfgComponent->GetBindName(&componentBindName); - - cfgComponent->Release(); - cfgComponent = nullptr; - - if (S_OK != status) - { - THROW_ERROR("Failed to acquire bind name"); - } - - bool matchesBindName = (0 == _wcsicmp(bindName.c_str(), componentBindName)); - CoTaskMemFree(componentBindName); - - if (matchesBindName) - { - // - // Apply the changes and exit the function - // - - result = bindingPath->Enable(enable); - if (S_OK != result) - { - THROW_ERROR("Failed to set IPv6 status"); - } - netCfg->Apply(); - - return; - } - } - } -} - -} // anonymous namespace - - -void EnableIpv6ForAdapter(const std::wstring &adapterGuid) -{ - try - { - // - // Avoid using the COM objects unless necessary - // due to slow performance. - // - - const auto key = common::registry::Registry::OpenKey( - HKEY_LOCAL_MACHINE, - L"SYSTEM\\CurrentControlSet\\Services\\Tcpip6\\Linkage" - ); - const auto bindings = key->readStringArray(L"Bind"); - - std::wstring matchString = std::wstring(L"\\Device\\").append(adapterGuid); - - for (auto it = bindings.begin(); it != bindings.end(); ++it) - { - if (0 == _wcsicmp(it->c_str(), matchString.c_str())) - { - // return from function - return; - } - } - } - catch (...) - { - } - - // - // Initialize COM - // - - HRESULT result = CoInitialize(nullptr); - - if (S_OK != result) - { - std::stringstream ss; - ss << "Failed to initialize COM: " << result; - THROW_ERROR(ss.str().c_str()); - } - - common::memory::ScopeDestructor scopeDest; - scopeDest += []() { - CoUninitialize(); - }; - - // - // Initialize INetCfg - // - - INetCfg *netCfg = nullptr; - result = CoCreateInstance( - CLSID_CNetCfg, - nullptr, - CLSCTX_INPROC_SERVER, - IID_INetCfg, - reinterpret_cast<void **>(&netCfg) - ); - - if (S_OK != result) - { - std::stringstream ss; - ss << "Failed to create INetCfg instance: " << result; - THROW_ERROR(ss.str().c_str()); - - } - - scopeDest += [&netCfg]() { netCfg->Release(); }; - - INetCfgLock *netCfgLock = nullptr; - result = netCfg->QueryInterface(IID_INetCfgLock, reinterpret_cast<void **>(&netCfgLock)); - - if (S_OK != result) - { - std::stringstream ss; - ss << "Failed to obtain INetCfg lock interface: " << result; - THROW_ERROR(ss.str().c_str()); - } - - scopeDest += [&netCfgLock]() { - netCfgLock->Release(); - }; - - wchar_t *blockingApplication = nullptr; - - // NOTE: This should be done before initializing INetCfg - result = netCfgLock->AcquireWriteLock( - NETCFG_LOCK_TIMEOUT, - NETCFG_LOCK_CLIENT_NAME, - &blockingApplication - ); - - if (S_OK != result) - { - std::wstringstream ss; - ss << L"Failed to acquire write lock"; - if (nullptr != blockingApplication) - { - ss << L" due to application: " << blockingApplication; - } - ss << ". (" << result << ")"; - - THROW_ERROR(common::string::ToAnsi(ss.str()).c_str()); - } - - scopeDest += [&]() { - CoTaskMemFree(blockingApplication); - netCfgLock->ReleaseWriteLock(); - }; - - result = netCfg->Initialize(nullptr); - - if (S_OK != result) - { - std::stringstream ss; - ss << "Failed to initialize INetCfg: " << result; - THROW_ERROR(ss.str().c_str()); - } - - scopeDest += [&netCfg]() { netCfg->Uninitialize(); }; - - SetIpv6BindingForBindName(netCfg, adapterGuid, true); -} diff --git a/windows/winnet/src/winnet/netconfig.h b/windows/winnet/src/winnet/netconfig.h deleted file mode 100644 index b2849857a2..0000000000 --- a/windows/winnet/src/winnet/netconfig.h +++ /dev/null @@ -1,5 +0,0 @@ -#pragma once - -#include <string> - -void EnableIpv6ForAdapter(const std::wstring &guid); diff --git a/windows/winnet/src/winnet/winnet.cpp b/windows/winnet/src/winnet/winnet.cpp index e52662c7a2..9ed2ec103e 100644 --- a/windows/winnet/src/winnet/winnet.cpp +++ b/windows/winnet/src/winnet/winnet.cpp @@ -4,7 +4,6 @@ #include "offlinemonitor.h"
#include "routing/routemanager.h"
#include "converters.h"
-#include "netconfig.h"
#include <libshared/logging/logsinkadapter.h>
#include <libshared/logging/unwind.h>
#include <libshared/network/interfaceutils.h>
@@ -67,34 +66,6 @@ WinNet_EnsureBestMetric( extern "C"
WINNET_LINKAGE
-bool
-WINNET_API
-WinNet_EnableIpv6ForAdapter(
- const wchar_t *deviceGuid,
- MullvadLogSink logSink,
- void *logSinkContext
-)
-{
- try
- {
- if (nullptr == deviceGuid)
- {
- THROW_ERROR("Invalid argument: deviceGuid");
- }
-
- EnableIpv6ForAdapter(deviceGuid);
- return true;
- }
- catch (const std::exception & err)
- {
- shared::logging::UnwindAndLog(logSink, logSinkContext, err);
- return false;
- }
- return false;
-}
-
-extern "C"
-WINNET_LINKAGE
WINNET_STATUS
WINNET_API
WinNet_GetBestDefaultRoute(
diff --git a/windows/winnet/src/winnet/winnet.def b/windows/winnet/src/winnet/winnet.def index 82cb952790..4b840ee818 100644 --- a/windows/winnet/src/winnet/winnet.def +++ b/windows/winnet/src/winnet/winnet.def @@ -1,7 +1,6 @@ LIBRARY winnet EXPORTS WinNet_EnsureBestMetric - WinNet_EnableIpv6ForAdapter WinNet_ActivateConnectivityMonitor WinNet_DeactivateConnectivityMonitor WinNet_ActivateRouteManager diff --git a/windows/winnet/src/winnet/winnet.h b/windows/winnet/src/winnet/winnet.h index 2d3c579e60..32d377e73f 100644 --- a/windows/winnet/src/winnet/winnet.h +++ b/windows/winnet/src/winnet/winnet.h @@ -33,16 +33,6 @@ WinNet_EnsureBestMetric( void *logSinkContext ); -extern "C" -WINNET_LINKAGE -bool -WINNET_API -WinNet_EnableIpv6ForAdapter( - const wchar_t *deviceGuid, - MullvadLogSink logSink, - void *logSinkContext -); - typedef void (WINNET_API *WinNetConnectivityMonitorCallback)(bool connected, void *context); extern "C" diff --git a/windows/winnet/src/winnet/winnet.vcxproj b/windows/winnet/src/winnet/winnet.vcxproj index 6876035160..7b4578d4b1 100644 --- a/windows/winnet/src/winnet/winnet.vcxproj +++ b/windows/winnet/src/winnet/winnet.vcxproj @@ -28,7 +28,6 @@ </ItemGroup> <ItemGroup> <ClCompile Include="converters.cpp" /> - <ClCompile Include="netconfig.cpp" /> <ClCompile Include="networkadaptermonitor.cpp" /> <ClCompile Include="dllmain.cpp" /> <ClCompile Include="InterfacePair.cpp" /> @@ -43,7 +42,6 @@ </ItemGroup> <ItemGroup> <ClInclude Include="converters.h" /> - <ClInclude Include="netconfig.h" /> <ClInclude Include="networkadaptermonitor.h" /> <ClInclude Include="InterfacePair.h" /> <ClInclude Include="offlinemonitor.h" /> diff --git a/windows/winnet/src/winnet/winnet.vcxproj.filters b/windows/winnet/src/winnet/winnet.vcxproj.filters index 27f0051bc6..2d5a039c6b 100644 --- a/windows/winnet/src/winnet/winnet.vcxproj.filters +++ b/windows/winnet/src/winnet/winnet.vcxproj.filters @@ -21,7 +21,6 @@ <Filter>routing</Filter> </ClCompile> <ClCompile Include="converters.cpp" /> - <ClCompile Include="netconfig.cpp" /> </ItemGroup> <ItemGroup> <ClInclude Include="stdafx.h" /> @@ -44,7 +43,6 @@ <Filter>routing</Filter> </ClInclude> <ClInclude Include="converters.h" /> - <ClInclude Include="netconfig.h" /> </ItemGroup> <ItemGroup> <None Include="winnet.def" /> |
