diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2021-01-30 16:39:33 +0100 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2021-01-30 16:41:16 +0100 |
commit | 49b7692d5becd86d4ff4854ed089ddd4c3d93b15 (patch) | |
tree | 23fd1e5afdc724b188f7719ca4df995800698e8b | |
parent | api: close private namespace when unloading DLL (diff) | |
download | wintun-49b7692d5becd86d4ff4854ed089ddd4c3d93b15.tar.xz wintun-49b7692d5becd86d4ff4854ed089ddd4c3d93b15.zip |
api: use custom devpkey for pool
It seems like the friendly name is still getting reset sometimes. Rather
than swimming upstream, it turns out we can just use a custom devpkey
that, according to msdn, is respected.
https://docs.microsoft.com/en-us/windows-hardware/drivers/install/creating-custom-device-properties
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
-rw-r--r-- | api/adapter.c | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/api/adapter.c b/api/adapter.c index a5fce7e..9373c42 100644 --- a/api/adapter.c +++ b/api/adapter.c @@ -44,6 +44,11 @@ # error Unsupported architecture #endif +static const DEVPROPKEY DEVPKEY_Wintun_Pool = { + { 0xaba51201, 0xdf7a, 0x3a38, { 0x0a, 0xd9, 0x90, 0x64, 0x42, 0xd2, 0x71, 0xae } }, + DEVPROPID_FIRST_USABLE + 0 +}; + typedef struct _SP_DEVINFO_DATA_LIST { SP_DEVINFO_DATA Data; @@ -470,10 +475,18 @@ static _Return_type_success_(return != FALSE) BOOL static BOOL IsPoolMember(_In_z_ const WCHAR *Pool, _In_ HDEVINFO DevInfo, _In_ SP_DEVINFO_DATA *DevInfoData) { - WCHAR *DeviceDesc = GetDeviceRegistryString(DevInfo, DevInfoData, SPDRP_DEVICEDESC); - WCHAR *FriendlyName = GetDeviceRegistryString(DevInfo, DevInfoData, SPDRP_FRIENDLYNAME); + WCHAR PoolProp[MAX_POOL_DEVICE_TYPE]; + DEVPROPTYPE PropType; + if (SetupDiGetDevicePropertyW( + DevInfo, DevInfoData, &DEVPKEY_Wintun_Pool, &PropType, (PBYTE)PoolProp, sizeof(PoolProp), NULL, 0) && + PropType == DEVPROP_TYPE_STRING) + return !_wcsicmp(PoolProp, Pool); + + LOG_LAST_ERROR(L"Reading pool devpkey failed, falling back"); DWORD LastError = ERROR_SUCCESS; BOOL Ret = FALSE; + WCHAR *DeviceDesc = GetDeviceRegistryString(DevInfo, DevInfoData, SPDRP_DEVICEDESC); + WCHAR *FriendlyName = GetDeviceRegistryString(DevInfo, DevInfoData, SPDRP_FRIENDLYNAME); WCHAR PoolDeviceTypeName[MAX_POOL_DEVICE_TYPE]; if (!GetPoolDeviceTypeName(Pool, PoolDeviceTypeName)) { @@ -1436,6 +1449,19 @@ static _Return_type_success_(return != NULL) WINTUN_ADAPTER *CreateAdapter( } *RebootRequired = *RebootRequired || CheckReboot(DevInfo, &DevInfoData); + if (!SetupDiSetDevicePropertyW( + DevInfo, + &DevInfoData, + &DEVPKEY_Wintun_Pool, + DEVPROP_TYPE_STRING, +#pragma warning(suppress : 4090) + (const BYTE *)Pool, + (DWORD)((wcslen(Pool) + 1) * sizeof(WCHAR)), + 0)) + { + LastError = LOG_LAST_ERROR(L"Failed to set adapter pool"); + goto cleanupNetDevRegKey; + } if (!SetupDiSetDeviceRegistryPropertyW( DevInfo, &DevInfoData, |