aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2021-05-11 19:43:34 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2021-05-11 19:43:34 +0200
commit479bbdc50a45ca9ae62ac15a1ee7445a6cbbe42a (patch)
tree008f6cf1b24248fd182276638098f4b70299eef7
parentversion: bump (diff)
downloadwintun-479bbdc50a45ca9ae62ac15a1ee7445a6cbbe42a.tar.xz
wintun-479bbdc50a45ca9ae62ac15a1ee7445a6cbbe42a.zip
api: only mark GUID as in-use if Status != NotPresent
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
-rw-r--r--api/adapter.c29
1 files changed, 16 insertions, 13 deletions
diff --git a/api/adapter.c b/api/adapter.c
index 5cc0dad..c15a420 100644
--- a/api/adapter.c
+++ b/api/adapter.c
@@ -3,22 +3,13 @@
* Copyright (C) 2018-2021 WireGuard LLC. All Rights Reserved.
*/
-#include "adapter.h"
-#include "elevate.h"
-#include "entry.h"
-#include "logger.h"
-#include "namespace.h"
-#include "nci.h"
-#include "ntdll.h"
-#include "registry.h"
-#include "resource.h"
-#include "wintun-inf.h"
-
+#include <WinSock2.h>
#include <Windows.h>
#include <winternl.h>
#define _NTDEF_ /* TODO: figure out how to include ntsecapi and winternal together without requiring this */
#include <cfgmgr32.h>
#include <devguid.h>
+#include <ws2tcpip.h>
#include <iphlpapi.h>
#include <ndisguid.h>
#include <NTSecAPI.h>
@@ -28,6 +19,17 @@
#include <initguid.h> /* Keep these two at bottom in this order, so that we only generate extra GUIDs for devpkey. The other keys we'll get from uuid.lib like usual. */
#include <devpkey.h>
+#include "adapter.h"
+#include "elevate.h"
+#include "entry.h"
+#include "logger.h"
+#include "namespace.h"
+#include "nci.h"
+#include "ntdll.h"
+#include "registry.h"
+#include "resource.h"
+#include "wintun-inf.h"
+
#pragma warning(disable : 4221) /* nonstandard: address of automatic in initializer */
#define WAIT_FOR_REGISTRY_TIMEOUT 10000 /* ms */
@@ -1452,8 +1454,9 @@ static _Return_type_success_(return != NULL) WINTUN_ADAPTER *CreateAdapter(
if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, RegPath, 0, KEY_QUERY_VALUE, &Key) == ERROR_SUCCESS)
{
RegCloseKey(Key);
- NET_LUID Luid;
- if (ConvertInterfaceGuidToLuid(RequestedGUID, &Luid) == NO_ERROR)
+ MIB_IF_ROW2 IfRow = { 0 };
+ if (ConvertInterfaceGuidToLuid(RequestedGUID, &IfRow.InterfaceLuid) == NO_ERROR &&
+ GetIfEntry2(&IfRow) == NO_ERROR && IfRow.OperStatus != IfOperStatusNotPresent)
{
SetLastError(
LOG_ERROR(ERROR_ALREADY_EXISTS, L"Requested GUID is already in use: %s", RequestedGUIDStr));