From 5b567d4a37084065174316671fc33241b67f40bc Mon Sep 17 00:00:00 2001 From: Patrick Mackinlay Date: Tue, 25 Apr 2023 14:45:43 +0700 Subject: [PATCH] taptun: fix adapter detection on windows for newer versions of taptun driver --- 3rdparty/tap-windows6/tap-windows.h | 7 +++++++ src/osd/modules/netdev/taptun.cpp | 21 +++++++++++++-------- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/3rdparty/tap-windows6/tap-windows.h b/3rdparty/tap-windows6/tap-windows.h index 99715343df7..42231533741 100644 --- a/3rdparty/tap-windows6/tap-windows.h +++ b/3rdparty/tap-windows6/tap-windows.h @@ -51,6 +51,13 @@ /* obsoletes TAP_WIN_IOCTL_CONFIG_POINT_TO_POINT */ #define TAP_WIN_IOCTL_CONFIG_TUN TAP_WIN_CONTROL_CODE (10, METHOD_BUFFERED) +/* Control whether 802.1Q headers are added for priority */ +#define TAP_WIN_IOCTL_PRIORITY_BEHAVIOR TAP_WIN_CONTROL_CODE (11, METHOD_BUFFERED) +#define TAP_PRIORITY_BEHAVIOR_NOPRIORITY 0 +#define TAP_PRIORITY_BEHAVIOR_ENABLED 1 +#define TAP_PRIORITY_BEHAVIOR_ADDALWAYS 2 +#define TAP_PRIORITY_BEHAVIOR_MAX 2 + /* * ================= * Registry keys diff --git a/src/osd/modules/netdev/taptun.cpp b/src/osd/modules/netdev/taptun.cpp index a1b8d4d84ce..5196b6e7d2f 100644 --- a/src/osd/modules/netdev/taptun.cpp +++ b/src/osd/modules/netdev/taptun.cpp @@ -293,16 +293,21 @@ static std::vector get_tap_adapters() // check if the ComponentId value indicates a TAP-Windows adapter if (RegQueryValueExW(unit_key, L"ComponentId", NULL, &data_type, LPBYTE(component_id), &component_id_len) == ERROR_SUCCESS - && data_type == REG_SZ - && safe_string(component_id, component_id_len) == L"" PRODUCT_TAP_WIN_COMPONENT_ID) + && data_type == REG_SZ) { - WCHAR net_cfg_instance_id[MAX_PATH]; - DWORD net_cfg_instance_id_len = sizeof(net_cfg_instance_id); + std::wstring const value(safe_string(component_id, component_id_len)); - // add the adapter to the result - if (RegQueryValueExW(unit_key, L"NetCfgInstanceId", NULL, &data_type, LPBYTE(net_cfg_instance_id), &net_cfg_instance_id_len) == ERROR_SUCCESS - && data_type == REG_SZ) - result.push_back(safe_string(net_cfg_instance_id, net_cfg_instance_id_len)); + // some older versions may not set the "root\" prefix + if (value == L"root\\" PRODUCT_TAP_WIN_COMPONENT_ID || value == L"" PRODUCT_TAP_WIN_COMPONENT_ID) + { + WCHAR net_cfg_instance_id[MAX_PATH]; + DWORD net_cfg_instance_id_len = sizeof(net_cfg_instance_id); + + // add the adapter to the result + if (RegQueryValueExW(unit_key, L"NetCfgInstanceId", NULL, &data_type, LPBYTE(net_cfg_instance_id), &net_cfg_instance_id_len) == ERROR_SUCCESS + && data_type == REG_SZ) + result.push_back(safe_string(net_cfg_instance_id, net_cfg_instance_id_len)); + } } RegCloseKey(unit_key);