forked from OpenVPN/ovpn-dco-win
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
More robust way to get a version info
The current way to get a version information is to open DCO device and make IOCTL call. This has a few issues: - If DCO device is already in use, an another app won't be to get the version, since the device is exclusive - With the multiple DCO devices there is a high chance that \\.\ovpn-dco device, which we use to get version information, is already in use. To open another device, we use via device interface enumeration, which requires a lot of boilerplate code to work. To make it easier for userspace to get the device version, create a non-exclusive control device \\.\ovpn-dco-ver which supports single IOCTL to get the version number. This device is created when the first network device is created and removed with the last network device. Bump version to 1.3.0. OpenVPN#75 Signed-off-by: Lev Stipakov <[email protected]>
- Loading branch information
Showing
7 changed files
with
224 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
/* | ||
* ovpn-dco-win OpenVPN protocol accelerator for Windows | ||
* | ||
* Copyright (C) 2024- OpenVPN Inc <[email protected]> | ||
* | ||
* Author: Lev Stipakov <[email protected]> | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License version 2 | ||
* as published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along | ||
* with this program; if not, write to the Free Software Foundation, Inc., | ||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
*/ | ||
|
||
#include "control.h" | ||
#include "Driver.h" | ||
#include "uapi\ovpn-dco.h" | ||
#include "trace.h" | ||
|
||
_Use_decl_annotations_ | ||
NTSTATUS | ||
OvpnGetVersion(WDFREQUEST request, ULONG_PTR* bytesReturned) | ||
{ | ||
LOG_ENTER(); | ||
|
||
*bytesReturned = 0; | ||
|
||
NTSTATUS status; | ||
POVPN_VERSION version = NULL; | ||
GOTO_IF_NOT_NT_SUCCESS(done, status, WdfRequestRetrieveOutputBuffer(request, sizeof(OVPN_VERSION), (PVOID*)&version, NULL)); | ||
|
||
version->Major = OVPN_DCO_VERSION_MAJOR; | ||
version->Minor = OVPN_DCO_VERSION_MINOR; | ||
version->Patch = OVPN_DCO_VERSION_PATCH; | ||
|
||
LOG_INFO("Version", TraceLoggingValue(version->Major, "Major"), TraceLoggingValue(version->Minor, "Minor"), TraceLoggingValue(version->Patch, "Patch")); | ||
|
||
*bytesReturned = sizeof(OVPN_VERSION); | ||
|
||
done: | ||
LOG_EXIT(); | ||
|
||
return status; | ||
} | ||
|
||
EVT_WDF_IO_QUEUE_IO_DEVICE_CONTROL OvpnEvtControlDeviceIOControl; | ||
|
||
VOID | ||
OvpnEvtControlDeviceIOControl(WDFQUEUE queue, WDFREQUEST request, size_t outputBufferLength, size_t inputBufferLength, ULONG ioControlCode) | ||
{ | ||
UNREFERENCED_PARAMETER(queue); | ||
UNREFERENCED_PARAMETER(inputBufferLength); | ||
UNREFERENCED_PARAMETER(outputBufferLength); | ||
|
||
NTSTATUS status = STATUS_SUCCESS; | ||
ULONG_PTR bytesReturned = 0; | ||
|
||
switch (ioControlCode) | ||
{ | ||
case OVPN_IOCTL_GET_VERSION: | ||
status = OvpnGetVersion(request, &bytesReturned); | ||
break; | ||
|
||
default: | ||
status = STATUS_INVALID_DEVICE_REQUEST; | ||
break; | ||
} | ||
|
||
WdfRequestCompleteWithInformation(request, status, bytesReturned); | ||
} | ||
|
||
NTSTATUS | ||
OvpnCreateControlDevice(WDFDRIVER wdfDriver) | ||
{ | ||
LOG_ENTER(); | ||
|
||
DECLARE_CONST_UNICODE_STRING(symLink, L"\\DosDevices\\ovpn-dco-ver"); // this will be used by CreateFile | ||
DECLARE_CONST_UNICODE_STRING(deviceName, L"\\Device\\ovpn-dco-ver"); // this is required tp create symlink | ||
|
||
// allocate control device initialization structure | ||
PWDFDEVICE_INIT deviceInit = WdfControlDeviceInitAllocate(wdfDriver, &SDDL_DEVOBJ_SYS_ALL_ADM_RWX_WORLD_R_RES_R); | ||
if (deviceInit == NULL) | ||
{ | ||
return STATUS_INSUFFICIENT_RESOURCES; | ||
} | ||
|
||
// create the control device | ||
WDF_OBJECT_ATTRIBUTES deviceAttributes; | ||
WDF_OBJECT_ATTRIBUTES_INIT(&deviceAttributes); | ||
WDFDEVICE controlDevice; | ||
NTSTATUS status; | ||
|
||
GOTO_IF_NOT_NT_SUCCESS(done, status, WdfDeviceInitAssignName(deviceInit, &deviceName)); | ||
GOTO_IF_NOT_NT_SUCCESS(done, status, WdfDeviceCreate(&deviceInit, &deviceAttributes, &controlDevice)); | ||
|
||
POVPN_DRIVER driverCtx = OvpnGetDriverContext(WdfGetDriver()); | ||
driverCtx->ControlDevice = controlDevice; | ||
|
||
// symlink for control device | ||
GOTO_IF_NOT_NT_SUCCESS(done, status, WdfDeviceCreateSymbolicLink(controlDevice, &symLink)); | ||
|
||
// queue to handle IO | ||
WDF_IO_QUEUE_CONFIG queueConfig; | ||
WDF_IO_QUEUE_CONFIG_INIT_DEFAULT_QUEUE(&queueConfig, WdfIoQueueDispatchParallel); | ||
queueConfig.EvtIoDeviceControl = OvpnEvtControlDeviceIOControl; | ||
WDFQUEUE queue; | ||
GOTO_IF_NOT_NT_SUCCESS(done, status, WdfIoQueueCreate(controlDevice, &queueConfig, WDF_NO_OBJECT_ATTRIBUTES, &queue)); | ||
|
||
// Complete the control device initialization | ||
WdfControlFinishInitializing(controlDevice); | ||
|
||
done: | ||
if (deviceInit) | ||
{ | ||
WdfDeviceInitFree(deviceInit); | ||
} | ||
|
||
LOG_EXIT(); | ||
|
||
return status; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* ovpn-dco-win OpenVPN protocol accelerator for Windows | ||
* | ||
* Copyright (C) 2024- OpenVPN Inc <[email protected]> | ||
* | ||
* Author: Lev Stipakov <[email protected]> | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License version 2 | ||
* as published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along | ||
* with this program; if not, write to the Free Software Foundation, Inc., | ||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <ntddk.h> | ||
#include <wdf.h> | ||
|
||
NTSTATUS | ||
OvpnGetVersion(WDFREQUEST request, _Out_ ULONG_PTR* bytesReturned); | ||
|
||
NTSTATUS | ||
OvpnCreateControlDevice(WDFDRIVER wdfDriver); |
Oops, something went wrong.