summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDavid Lönnhager <david.l@mullvad.net>2020-01-21 15:24:07 +0100
committerDavid Lönnhager <david.l@mullvad.net>2020-01-31 16:24:48 +0100
commit60d01c3525f4d3c133d517702997d83c463df3ba (patch)
tree56fb5ec432fdca3ffc9194dfe9b6e6020760576c
parentddf28d3a7599ebeed20a4b425630aa4a8bf7e9b4 (diff)
downloadmullvadvpn-60d01c3525f4d3c133d517702997d83c463df3ba.tar.xz
mullvadvpn-60d01c3525f4d3c133d517702997d83c463df3ba.zip
Refactor driverlogic
-rw-r--r--dist-assets/windows/installer.nsh68
-rw-r--r--windows/nsis-plugins/src/driverlogic/context.h71
-rw-r--r--windows/nsis-plugins/src/driverlogic/driverlogic.cpp257
-rw-r--r--windows/nsis-plugins/src/driverlogic/driverlogic.def6
-rw-r--r--windows/nsis-plugins/src/driverlogic/driverlogic.vcxproj4
-rw-r--r--windows/nsis-plugins/src/driverlogic/driverlogic.vcxproj.filters4
-rw-r--r--windows/nsis-plugins/src/driverlogic/driverlogicops.cpp (renamed from windows/nsis-plugins/src/driverlogic/context.cpp)91
-rw-r--r--windows/nsis-plugins/src/driverlogic/driverlogicops.h46
8 files changed, 117 insertions, 430 deletions
diff --git a/dist-assets/windows/installer.nsh b/dist-assets/windows/installer.nsh
index 4c04ebb74e..41962c2048 100644
--- a/dist-assets/windows/installer.nsh
+++ b/dist-assets/windows/installer.nsh
@@ -161,11 +161,11 @@
!define ForceRenameAdapter '!insertmacro "ForceRenameAdapter"'
#
-# RemoveTap
+# RemoveBrandedTap
#
# Try to remove the Mullvad TAP adapter driver
#
-!macro RemoveTap
+!macro RemoveBrandedTap
Push $0
Push $1
@@ -178,43 +178,62 @@
!macroend
-!define RemoveTap '!insertmacro "RemoveTap"'
+!define RemoveBrandedTap '!insertmacro "RemoveBrandedTap"'
#
-# RemoveOldIdTap
+# RemoveVanillaTap
#
# Try to remove the old Mullvad TAP adapter (with a non-unique hardware ID),
# and uninstall the driver if it's not in use.
#
-!macro RemoveOldIdTap
+!macro RemoveVanillaTap
Push $0
Push $1
- driverlogic::RemoveOldMullvadTap
+ log::Log "RemoveVanillaTap()"
+
+ driverlogic::RemoveVanillaMullvadTap
Pop $0
Pop $1
${If} $0 == ${RMT_GENERAL_ERROR}
- Goto RemoveOldIdTap_return
+ StrCpy $R0 "Failed to remove vanilla TAP adapter: $1"
+ log::Log $R0
+
+ Goto RemoveVanillaTap_return
${EndIf}
${If} $0 == ${RMT_NO_REMAINING_ADAPTERS}
- # Remove the driver altogether
+ log::Log "Removing vanilla TAP adapter driver since it is no longer in use"
+
nsExec::ExecToStack '"$TEMP\driver\tapinstall.exe" remove ${DEPRECATED_TAP_HARDWARE_ID}'
Pop $0
Pop $1
+
+ ${If} $0 != ${DEVCON_EXIT_OK}
+ ${AndIf} $0 != ${DEVCON_EXIT_REBOOT}
+ StrCpy $R0 "Failed to remove driver: $1"
+ log::Log $R0
+
+ Goto RemoveVanillaTap_return
+ ${EndIf}
${EndIf}
-
- RemoveOldIdTap_return:
+
+ log::Log "RemoveVanillaTap() completed successfully"
+
+ RemoveVanillaTap_return:
+
+ Push 0
+ Pop $R0
Pop $1
Pop $0
!macroend
-!define RemoveOldIdTap '!insertmacro "RemoveOldIdTap"'
+!define RemoveVanillaTap '!insertmacro "RemoveVanillaTap"'
#
# InstallDriver
@@ -232,21 +251,10 @@
Push $0
Push $1
- driverlogic::Initialize
-
- Pop $0
- Pop $1
-
- ${If} $0 != ${MULLVAD_SUCCESS}
- StrCpy $R0 "Failed to initialize plugin 'driverlogic': $1"
- log::Log $R0
- Goto InstallDriver_return_only
- ${EndIf}
-
#
# Remove the old-ID Mullvad TAP, if it exists
#
- ${RemoveOldIdTap}
+ ${RemoveVanillaTap}
#
# Silently approve the certificate before installing the driver
@@ -317,18 +325,6 @@
InstallDriver_return:
- driverlogic::Deinitialize
-
- Pop $0
- Pop $1
-
- ${If} $0 != ${MULLVAD_SUCCESS}
- # Do not update $R0
- log::Log "Failed to deinitialize plugin 'driverlogic': $1"
- ${EndIf}
-
- InstallDriver_return_only:
-
Pop $1
Pop $0
@@ -849,7 +845,7 @@
# Remove the TAP adapter
${ExtractDriver}
- ${RemoveTap}
+ ${RemoveBrandedTap}
# If not ran silently
${If} $FullUninstall == 1
diff --git a/windows/nsis-plugins/src/driverlogic/context.h b/windows/nsis-plugins/src/driverlogic/context.h
deleted file mode 100644
index d3b57d4f44..0000000000
--- a/windows/nsis-plugins/src/driverlogic/context.h
+++ /dev/null
@@ -1,71 +0,0 @@
-#pragma once
-
-#include <set>
-#include <string>
-#include <optional>
-
-class Context
-{
-public:
-
- Context()
- {
- }
-
- struct NetworkAdapter
- {
- std::wstring guid;
- std::wstring name;
- std::wstring alias;
- std::wstring deviceInstanceId;
-
- NetworkAdapter(std::wstring guid, std::wstring name, std::wstring alias, std::wstring deviceInstanceId)
- : guid(guid)
- , name(name)
- , alias(alias)
- , deviceInstanceId(deviceInstanceId)
- {
- }
-
- bool operator<(const NetworkAdapter &rhs) const
- {
- return _wcsicmp(deviceInstanceId.c_str(), rhs.deviceInstanceId.c_str()) < 0;
- }
- };
-
- enum class BaselineStatus
- {
- NO_TAP_ADAPTERS_PRESENT,
- SOME_TAP_ADAPTERS_PRESENT,
- MULLVAD_ADAPTER_PRESENT
- };
-
- BaselineStatus establishBaseline();
-
- void recordCurrentState();
-
- //
- // Restore TAP aliases to baseline state
- //
- void rollbackTapAliases();
-
- //
- // Identify a single new TAP adapter
- //
- NetworkAdapter getNewAdapter();
-
- enum class DeletionResult
- {
- NO_REMAINING_TAP_ADAPTERS,
- SOME_REMAINING_TAP_ADAPTERS
- };
-
- static DeletionResult DeleteOldMullvadAdapter();
-
-private:
-
- static std::optional<NetworkAdapter> FindMullvadAdapter(const std::set<NetworkAdapter> &tapAdapters);
-
- std::set<NetworkAdapter> m_baseline;
- std::set<NetworkAdapter> m_currentState;
-};
diff --git a/windows/nsis-plugins/src/driverlogic/driverlogic.cpp b/windows/nsis-plugins/src/driverlogic/driverlogic.cpp
index 8f00dbcecf..6861bbd623 100644
--- a/windows/nsis-plugins/src/driverlogic/driverlogic.cpp
+++ b/windows/nsis-plugins/src/driverlogic/driverlogic.cpp
@@ -1,6 +1,6 @@
-#include <stdafx.h>
+#include "stdafx.h"
#include "../error.h"
-#include "context.h"
+#include "driverlogicops.h"
#include <libcommon/string.h>
#include <libcommon/error.h>
#include <libcommon/valuemapper.h>
@@ -12,157 +12,20 @@
#include <nsis/pluginapi.h>
#pragma warning (pop)
-Context *g_context = nullptr;
-
-namespace
-{
-
-EXTERN_C IMAGE_DOS_HEADER __ImageBase;
-
-void PinDll()
-{
- //
- // Apparently NSIS loads and unloads the plugin module for EVERY call it makes to the plugin.
- // This makes it kind of difficult to maintain state.
- //
- // We can work around this by incrementing the module reference count.
- // When NSIS calls FreeLibrary() the reference count decrements and becomes one.
- //
-
- wchar_t self[MAX_PATH];
-
- if (0 == GetModuleFileNameW((HINSTANCE)&__ImageBase, self, _countof(self)))
- {
- THROW_ERROR("Failed to pin plugin module");
- }
-
- //
- // NSIS sometimes frees a plugin module more times than it loads it.
- // This hasn't been observed for this particular plugin but let's up the
- // reference count a bit extra anyway.
- //
- for (int i = 0; i < 100; ++i)
- {
- LoadLibraryW(self);
- }
-}
-
-} // anonymous namespace
-
-//
-// Initialize
//
-// Call this function once during startup.
-//
-
-void __declspec(dllexport) NSISCALL Initialize
-(
- HWND hwndParent,
- int string_size,
- LPTSTR variables,
- stack_t **stacktop,
- extra_parameters *extra,
- ...
-)
-{
- EXDLL_INIT();
-
- try
- {
- if (nullptr == g_context)
- {
- g_context = new Context;
-
- PinDll();
- }
-
- pushstring(L"");
- pushint(NsisStatus::SUCCESS);
- }
- catch (std::exception &err)
- {
- pushstring(common::string::ToWide(err.what()).c_str());
- pushint(NsisStatus::GENERAL_ERROR);
- }
- catch (...)
- {
- pushstring(L"Unspecified error");
- pushint(NsisStatus::GENERAL_ERROR);
- }
-}
-
-//
-// EstablishBaseline
-//
-// Call this function to establish a baseline W.R.T network adapters
-// present in the system.
-//
-// The return value reflects the status of TAP presence in the system.
-//
-enum class EstablishBaselineStatus
-{
- GENERAL_ERROR = 0,
- NO_TAP_ADAPTERS_PRESENT,
- SOME_TAP_ADAPTERS_PRESENT,
- MULLVAD_ADAPTER_PRESENT
-};
-
-void __declspec(dllexport) NSISCALL EstablishBaseline
-(
- HWND hwndParent,
- int string_size,
- LPTSTR variables,
- stack_t **stacktop,
- extra_parameters *extra,
- ...
-)
-{
- EXDLL_INIT();
-
- if (nullptr == g_context)
- {
- pushstring(L"Initialize() function was not called or was not successful");
- pushint(EstablishBaselineStatus::GENERAL_ERROR);
- return;
- }
-
- try
- {
- const auto status = common::ValueMapper::Map(g_context->establishBaseline(), {
- std::make_pair(Context::BaselineStatus::NO_TAP_ADAPTERS_PRESENT, EstablishBaselineStatus::NO_TAP_ADAPTERS_PRESENT),
- std::make_pair(Context::BaselineStatus::SOME_TAP_ADAPTERS_PRESENT, EstablishBaselineStatus::SOME_TAP_ADAPTERS_PRESENT),
- std::make_pair(Context::BaselineStatus::MULLVAD_ADAPTER_PRESENT, EstablishBaselineStatus::MULLVAD_ADAPTER_PRESENT)
- });
-
- pushstring(L"");
- pushint(status);
- }
- catch (std::exception &err)
- {
- pushstring(common::string::ToWide(err.what()).c_str());
- pushint(EstablishBaselineStatus::GENERAL_ERROR);
- }
- catch (...)
- {
- pushstring(L"Unspecified error");
- pushint(EstablishBaselineStatus::GENERAL_ERROR);
- }
-}
-
-//
-// RemoveOldMullvadTap
+// RemoveVanillaMullvadTap
//
// Deletes the old Mullvad TAP adapter with ID tap0901.
//
//
-enum class RemoveOldMullvadTapStatus
+enum class RemoveVanillaMullvadTapStatus
{
GENERAL_ERROR = 0,
SUCCESS_NO_REMAINING_TAP_ADAPTERS,
SUCCESS_SOME_REMAINING_TAP_ADAPTERS
};
-void __declspec(dllexport) NSISCALL RemoveOldMullvadTap
+void __declspec(dllexport) NSISCALL RemoveVanillaMullvadTap
(
HWND hwndParent,
int string_size,
@@ -178,17 +41,17 @@ void __declspec(dllexport) NSISCALL RemoveOldMullvadTap
{
pushstring(L"");
- switch (Context::DeleteOldMullvadAdapter())
+ switch (driverlogic::DeleteOldMullvadAdapter())
{
- case Context::DeletionResult::NO_REMAINING_TAP_ADAPTERS:
+ case driverlogic::DeletionResult::NO_REMAINING_TAP_ADAPTERS:
{
- pushint(RemoveOldMullvadTapStatus::SUCCESS_NO_REMAINING_TAP_ADAPTERS);
+ pushint(RemoveVanillaMullvadTapStatus::SUCCESS_NO_REMAINING_TAP_ADAPTERS);
break;
}
- case Context::DeletionResult::SOME_REMAINING_TAP_ADAPTERS:
+ case driverlogic::DeletionResult::SOME_REMAINING_TAP_ADAPTERS:
{
- pushint(RemoveOldMullvadTapStatus::SUCCESS_SOME_REMAINING_TAP_ADAPTERS);
+ pushint(RemoveVanillaMullvadTapStatus::SUCCESS_SOME_REMAINING_TAP_ADAPTERS);
break;
}
@@ -201,12 +64,12 @@ void __declspec(dllexport) NSISCALL RemoveOldMullvadTap
catch (std::exception &err)
{
pushstring(common::string::ToWide(err.what()).c_str());
- pushint(RemoveOldMullvadTapStatus::GENERAL_ERROR);
+ pushint(RemoveVanillaMullvadTapStatus::GENERAL_ERROR);
}
catch (...)
{
pushstring(L"Unspecified error");
- pushint(RemoveOldMullvadTapStatus::GENERAL_ERROR);
+ pushint(RemoveVanillaMullvadTapStatus::GENERAL_ERROR);
}
}
@@ -232,18 +95,9 @@ void __declspec(dllexport) NSISCALL IdentifyNewAdapter
{
EXDLL_INIT();
- if (nullptr == g_context)
- {
- pushstring(L"Initialize() function was not called or was not successful");
- pushint(NsisStatus::GENERAL_ERROR);
- return;
- }
-
try
{
- g_context->recordCurrentState();
-
- auto adapter = g_context->getNewAdapter();
+ auto adapter = driverlogic::GetAdapter();
pushstring(adapter.alias.c_str());
pushint(NsisStatus::SUCCESS);
@@ -259,88 +113,3 @@ void __declspec(dllexport) NSISCALL IdentifyNewAdapter
pushint(NsisStatus::GENERAL_ERROR);
}
}
-
-//
-// RollbackTapAliases
-//
-// Updating the TAP driver may replace GUIDs and aliases.
-// Use this to restore the aliases to their baseline state.
-//
-
-void __declspec(dllexport) NSISCALL RollbackTapAliases
-(
- HWND hwndParent,
- int string_size,
- LPTSTR variables,
- stack_t** stacktop,
- extra_parameters* extra,
- ...
-)
-{
- EXDLL_INIT();
-
- if (nullptr == g_context)
- {
- pushstring(L"Initialize() function was not called or was not successful");
- pushint(NsisStatus::GENERAL_ERROR);
- return;
- }
-
- try
- {
- g_context->recordCurrentState();
- g_context->rollbackTapAliases();
-
- pushstring(L"");
- pushint(NsisStatus::SUCCESS);
- }
- catch (std::exception & err)
- {
- pushstring(common::string::ToWide(err.what()).c_str());
- pushint(NsisStatus::GENERAL_ERROR);
- }
- catch (...)
- {
- pushstring(L"Unspecified error");
- pushint(NsisStatus::GENERAL_ERROR);
- }
-}
-
-//
-// Deinitialize
-//
-// Call this function once during shutdown.
-//
-
-void __declspec(dllexport) NSISCALL Deinitialize
-(
- HWND hwndParent,
- int string_size,
- LPTSTR variables,
- stack_t **stacktop,
- extra_parameters *extra,
- ...
-)
-{
- EXDLL_INIT();
-
- try
- {
- delete g_context;
-
- pushstring(L"");
- pushint(NsisStatus::SUCCESS);
- }
- catch (std::exception &err)
- {
- pushstring(common::string::ToWide(err.what()).c_str());
- pushint(NsisStatus::GENERAL_ERROR);
- }
- catch (...)
- {
- pushstring(L"Unspecified error");
- pushint(NsisStatus::GENERAL_ERROR);
- }
-
- g_context = nullptr;
-}
diff --git a/windows/nsis-plugins/src/driverlogic/driverlogic.def b/windows/nsis-plugins/src/driverlogic/driverlogic.def
index 2367487538..78730b5f9b 100644
--- a/windows/nsis-plugins/src/driverlogic/driverlogic.def
+++ b/windows/nsis-plugins/src/driverlogic/driverlogic.def
@@ -2,9 +2,5 @@ LIBRARY driverlogic
EXPORTS
-Initialize
-EstablishBaseline
IdentifyNewAdapter
-RemoveOldMullvadTap
-RollbackTapAliases
-Deinitialize
+RemoveVanillaMullvadTap
diff --git a/windows/nsis-plugins/src/driverlogic/driverlogic.vcxproj b/windows/nsis-plugins/src/driverlogic/driverlogic.vcxproj
index 5a4e4b18c4..40e9bac4e2 100644
--- a/windows/nsis-plugins/src/driverlogic/driverlogic.vcxproj
+++ b/windows/nsis-plugins/src/driverlogic/driverlogic.vcxproj
@@ -102,14 +102,14 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
- <ClInclude Include="context.h" />
+ <ClInclude Include="driverlogicops.h" />
<ClInclude Include="stdafx.h" />
<ClInclude Include="targetver.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="dllmain.cpp" />
<ClCompile Include="driverlogic.cpp" />
- <ClCompile Include="context.cpp" />
+ <ClCompile Include="driverlogicops.cpp" />
<ClCompile Include="stdafx.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
diff --git a/windows/nsis-plugins/src/driverlogic/driverlogic.vcxproj.filters b/windows/nsis-plugins/src/driverlogic/driverlogic.vcxproj.filters
index 2c25d275f1..2c390fd544 100644
--- a/windows/nsis-plugins/src/driverlogic/driverlogic.vcxproj.filters
+++ b/windows/nsis-plugins/src/driverlogic/driverlogic.vcxproj.filters
@@ -3,13 +3,13 @@
<ItemGroup>
<ClInclude Include="stdafx.h" />
<ClInclude Include="targetver.h" />
- <ClInclude Include="context.h" />
+ <ClInclude Include="driverlogicops.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="dllmain.cpp" />
<ClCompile Include="driverlogic.cpp" />
<ClCompile Include="stdafx.cpp" />
- <ClCompile Include="context.cpp" />
+ <ClCompile Include="driverlogicops.cpp" />
</ItemGroup>
<ItemGroup>
<None Include="driverlogic.def" />
diff --git a/windows/nsis-plugins/src/driverlogic/context.cpp b/windows/nsis-plugins/src/driverlogic/driverlogicops.cpp
index 1718182768..66fa2d9f24 100644
--- a/windows/nsis-plugins/src/driverlogic/context.cpp
+++ b/windows/nsis-plugins/src/driverlogic/driverlogicops.cpp
@@ -1,5 +1,5 @@
#include "stdafx.h"
-#include "context.h"
+#include "driverlogicops.h"
#include <libcommon/guid.h>
#include <libcommon/string.h>
@@ -8,9 +8,6 @@
#include <libcommon/network/nci.h>
#include <log/log.h>
-#include <winsock2.h>
-#include <ws2ipdef.h>
-#include <iphlpapi.h>
#include <windows.h>
#include <vector>
@@ -51,6 +48,11 @@ void LogAdapters(const std::wstring &description, const T &adapters)
PluginLogWithDetails(description, details);
}
+} // anonymous namespace
+
+namespace driverlogic
+{
+
std::wstring GetNetCfgInstanceId(HDEVINFO devInfo, const SP_DEVINFO_DATA &devInfoData)
{
HKEY hNet = SetupDiOpenDevRegKey(
@@ -246,9 +248,9 @@ std::optional<std::wstring> GetDeviceRegistryStringProperty(
return { buffer.data() };
}
-std::set<Context::NetworkAdapter> GetTapAdapters(const std::wstring &tapHardwareId)
+std::set<NetworkAdapter> GetTapAdapters(const std::wstring &tapHardwareId)
{
- std::set<Context::NetworkAdapter> adapters;
+ std::set<NetworkAdapter> adapters;
HDEVINFO devInfo = SetupDiGetClassDevs(
&GUID_DEVCLASS_NET,
@@ -308,7 +310,7 @@ std::set<Context::NetworkAdapter> GetTapAdapters(const std::wstring &tapHardware
const std::wstring guid = GetNetCfgInstanceId(devInfo, devInfoData);
GUID guidObj = common::Guid::FromString(guid);
- adapters.emplace(Context::NetworkAdapter(
+ adapters.emplace(NetworkAdapter(
guid,
GetDeviceStringProperty(devInfo, &devInfoData, &DEVPKEY_Device_DriverDesc),
nci.getConnectionName(guidObj),
@@ -321,19 +323,16 @@ std::set<Context::NetworkAdapter> GetTapAdapters(const std::wstring &tapHardware
// Log exception and skip this adapter
//
- std::string msg = "Skipping TAP adapter due to exception caught while iterating: ";
- msg.append(e.what());
- PluginLog(std::wstring(msg.begin(), msg.end()));
+ const auto msg =
+ std::string("Skipping TAP adapter due to exception caught while iterating: ").append(e.what());
+ PluginLog(common::string::ToWide(msg));
}
}
return adapters;
}
-} // anonymous namespace
-
-//static
-std::optional<Context::NetworkAdapter> Context::FindMullvadAdapter(const std::set<Context::NetworkAdapter> &tapAdapters)
+std::optional<NetworkAdapter> FindMullvadAdapter(const std::set<NetworkAdapter> &tapAdapters)
{
if (tapAdapters.empty())
{
@@ -386,66 +385,17 @@ std::optional<Context::NetworkAdapter> Context::FindMullvadAdapter(const std::se
return std::nullopt;
}
-Context::BaselineStatus Context::establishBaseline()
+NetworkAdapter GetAdapter()
{
- m_baseline = GetTapAdapters(TAP_HARDWARE_ID);
+ std::set<NetworkAdapter> added = GetTapAdapters(TAP_HARDWARE_ID);
- if (m_baseline.empty())
+ if (added.empty())
{
- return BaselineStatus::NO_TAP_ADAPTERS_PRESENT;
- }
-
- if (FindMullvadAdapter(m_baseline).has_value())
- {
- return BaselineStatus::MULLVAD_ADAPTER_PRESENT;
- }
-
- return BaselineStatus::SOME_TAP_ADAPTERS_PRESENT;
-}
-
-void Context::recordCurrentState()
-{
- m_currentState = GetTapAdapters(TAP_HARDWARE_ID);
-}
-
-void Context::rollbackTapAliases()
-{
- common::network::Nci nci;
-
- for (const auto &adapter : m_currentState)
- {
- const auto oldInfo = m_baseline.find(adapter);
- if (m_baseline.end() != oldInfo)
- {
- GUID guidObj = common::Guid::FromString(&adapter.guid[0]);
-
- nci.setConnectionName(guidObj, oldInfo->alias.c_str());
- }
- }
-}
-
-Context::NetworkAdapter Context::getNewAdapter()
-{
- std::list<NetworkAdapter> added;
-
- for (const auto &adapter : m_currentState)
- {
- if (m_baseline.end() == m_baseline.find(adapter))
- {
- added.push_back(adapter);
- }
- }
-
- if (added.size() == 0)
- {
- LogAdapters(L"Enumerable network TAP adapters", m_currentState);
-
- THROW_ERROR("Unable to identify recently added TAP adapter");
+ THROW_ERROR("Could not identify TAP");
}
else if (added.size() > 1)
{
- LogAdapters(L"Enumerable network TAP adapters", m_currentState);
- LogAdapters(L"New TAP adapters:", added);
+ LogAdapters(L"Enumerable network TAP adapters", added);
THROW_ERROR("Identified more TAP adapters than expected");
}
@@ -453,8 +403,7 @@ Context::NetworkAdapter Context::getNewAdapter()
return *added.begin();
}
-//static
-Context::DeletionResult Context::DeleteOldMullvadAdapter()
+DeletionResult DeleteOldMullvadAdapter()
{
auto tapAdapters = GetTapAdapters(DEPRECATED_TAP_HARDWARE_ID);
std::optional<NetworkAdapter> mullvadAdapter = FindMullvadAdapter(tapAdapters);
@@ -528,3 +477,5 @@ Context::DeletionResult Context::DeleteOldMullvadAdapter()
? DeletionResult::SOME_REMAINING_TAP_ADAPTERS
: DeletionResult::NO_REMAINING_TAP_ADAPTERS;
}
+
+}
diff --git a/windows/nsis-plugins/src/driverlogic/driverlogicops.h b/windows/nsis-plugins/src/driverlogic/driverlogicops.h
new file mode 100644
index 0000000000..c56ff60472
--- /dev/null
+++ b/windows/nsis-plugins/src/driverlogic/driverlogicops.h
@@ -0,0 +1,46 @@
+#pragma once
+
+#include <set>
+#include <string>
+#include <optional>
+
+namespace driverlogic
+{
+
+struct NetworkAdapter
+{
+ std::wstring guid;
+ std::wstring name;
+ std::wstring alias;
+ std::wstring deviceInstanceId;
+
+ NetworkAdapter(std::wstring guid, std::wstring name, std::wstring alias, std::wstring deviceInstanceId)
+ : guid(guid)
+ , name(name)
+ , alias(alias)
+ , deviceInstanceId(deviceInstanceId)
+ {
+ }
+
+ bool operator<(const NetworkAdapter &rhs) const
+ {
+ return _wcsicmp(deviceInstanceId.c_str(), rhs.deviceInstanceId.c_str()) < 0;
+ }
+};
+
+//
+// Identify the Mullvad TAP adapter
+//
+NetworkAdapter GetAdapter();
+
+enum class DeletionResult
+{
+ NO_REMAINING_TAP_ADAPTERS,
+ SOME_REMAINING_TAP_ADAPTERS
+};
+
+DeletionResult DeleteOldMullvadAdapter();
+
+std::optional<NetworkAdapter> FindMullvadAdapter(const std::set<NetworkAdapter> &tapAdapters);
+
+}