api: split adapter creation/deletion to delegator and worker functions
Suggested-by: Jason A. Donenfeld <Jason@zx2c4.com> Signed-off-by: Simon Rozman <simon@rozman.si>
This commit is contained in:
parent
3dacd1c6ce
commit
5a3a217b0b
@ -1492,20 +1492,15 @@ cleanupMutex:
|
|||||||
return Result;
|
return Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
static WINTUN_STATUS
|
||||||
|
CreateAdapterNatively(
|
||||||
WINTUN_STATUS WINAPI
|
|
||||||
WintunCreateAdapter(
|
|
||||||
_In_z_count_c_(MAX_POOL) const WCHAR *Pool,
|
_In_z_count_c_(MAX_POOL) const WCHAR *Pool,
|
||||||
_In_z_count_c_(MAX_ADAPTER_NAME) const WCHAR *Name,
|
_In_z_count_c_(MAX_ADAPTER_NAME) const WCHAR *Name,
|
||||||
_In_opt_ const GUID *RequestedGUID,
|
_In_opt_ const GUID *RequestedGUID,
|
||||||
_Out_ WINTUN_ADAPTER **Adapter,
|
_Out_ WINTUN_ADAPTER **Adapter,
|
||||||
_Inout_ BOOL *RebootRequired)
|
_Inout_ BOOL *RebootRequired)
|
||||||
{
|
{
|
||||||
#if defined(_M_IX86) || defined(_M_ARM)
|
LOG(WINTUN_LOG_INFO, L"Spawning native process");
|
||||||
if (NativeMachine != IMAGE_FILE_PROCESS)
|
|
||||||
{
|
|
||||||
LOG(WINTUN_LOG_INFO, L"Spawning native process for the job");
|
|
||||||
WCHAR RequestedGUIDStr[MAX_GUID_STRING_LEN];
|
WCHAR RequestedGUIDStr[MAX_GUID_STRING_LEN];
|
||||||
WCHAR Arguments[15 + MAX_POOL + 3 + MAX_ADAPTER_NAME + 2 + MAX_GUID_STRING_LEN + 1];
|
WCHAR Arguments[15 + MAX_POOL + 3 + MAX_ADAPTER_NAME + 2 + MAX_GUID_STRING_LEN + 1];
|
||||||
if (_snwprintf_s(
|
if (_snwprintf_s(
|
||||||
@ -1544,10 +1539,24 @@ WintunCreateAdapter(
|
|||||||
}
|
}
|
||||||
if (wcstoul(Argv[2], NULL, 16))
|
if (wcstoul(Argv[2], NULL, 16))
|
||||||
*RebootRequired = TRUE;
|
*RebootRequired = TRUE;
|
||||||
cleanupArgv:
|
cleanupArgv:
|
||||||
LocalFree(Argv);
|
LocalFree(Argv);
|
||||||
return Result;
|
return Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
WINTUN_STATUS WINAPI
|
||||||
|
WintunCreateAdapter(
|
||||||
|
_In_z_count_c_(MAX_POOL) const WCHAR *Pool,
|
||||||
|
_In_z_count_c_(MAX_ADAPTER_NAME) const WCHAR *Name,
|
||||||
|
_In_opt_ const GUID *RequestedGUID,
|
||||||
|
_Out_ WINTUN_ADAPTER **Adapter,
|
||||||
|
_Inout_ BOOL *RebootRequired)
|
||||||
|
{
|
||||||
|
#if defined(_M_IX86) || defined(_M_ARM)
|
||||||
|
if (NativeMachine != IMAGE_FILE_PROCESS)
|
||||||
|
return CreateAdapterNatively(Pool, Name, RequestedGUID, Adapter, RebootRequired);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(HAVE_EV) || defined(HAVE_WHQL)
|
#if defined(HAVE_EV) || defined(HAVE_WHQL)
|
||||||
@ -1601,13 +1610,12 @@ cleanupDirectory:
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
WINTUN_STATUS WINAPI
|
|
||||||
WintunDeleteAdapter(_In_ const WINTUN_ADAPTER *Adapter, _Inout_ BOOL *RebootRequired)
|
|
||||||
{
|
|
||||||
#if defined(_M_IX86) || defined(_M_ARM)
|
#if defined(_M_IX86) || defined(_M_ARM)
|
||||||
if (NativeMachine != IMAGE_FILE_PROCESS)
|
|
||||||
{
|
static WINTUN_STATUS
|
||||||
LOG(WINTUN_LOG_INFO, L"Spawning native process for the job");
|
DeleteAdapterNatively(_In_ const WINTUN_ADAPTER *Adapter, _Inout_ BOOL *RebootRequired)
|
||||||
|
{
|
||||||
|
LOG(WINTUN_LOG_INFO, L"Spawning native process");
|
||||||
WCHAR GuidStr[MAX_GUID_STRING_LEN];
|
WCHAR GuidStr[MAX_GUID_STRING_LEN];
|
||||||
WCHAR Arguments[14 + MAX_GUID_STRING_LEN + 1];
|
WCHAR Arguments[14 + MAX_GUID_STRING_LEN + 1];
|
||||||
if (_snwprintf_s(
|
if (_snwprintf_s(
|
||||||
@ -1633,10 +1641,19 @@ WintunDeleteAdapter(_In_ const WINTUN_ADAPTER *Adapter, _Inout_ BOOL *RebootRequ
|
|||||||
Result = wcstoul(Argv[0], NULL, 16);
|
Result = wcstoul(Argv[0], NULL, 16);
|
||||||
if (wcstoul(Argv[1], NULL, 16))
|
if (wcstoul(Argv[1], NULL, 16))
|
||||||
*RebootRequired = TRUE;
|
*RebootRequired = TRUE;
|
||||||
cleanupArgv:
|
cleanupArgv:
|
||||||
LocalFree(Argv);
|
LocalFree(Argv);
|
||||||
return Result;
|
return Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
WINTUN_STATUS WINAPI
|
||||||
|
WintunDeleteAdapter(_In_ const WINTUN_ADAPTER *Adapter, _Inout_ BOOL *RebootRequired)
|
||||||
|
{
|
||||||
|
#if defined(_M_IX86) || defined(_M_ARM)
|
||||||
|
if (NativeMachine != IMAGE_FILE_PROCESS)
|
||||||
|
return DeleteAdapterNatively(Adapter, RebootRequired);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
HDEVINFO DevInfo;
|
HDEVINFO DevInfo;
|
||||||
|
Loading…
Reference in New Issue
Block a user