Skip to content

Commit

Permalink
Add OVPN_IOCTL_SET_MODE
Browse files Browse the repository at this point in the history
THis is to select between client mode (OVPN_MODE_P2P, default)
and server mode (OVPN_MODE_MP).

At the moment only ioctl is added, no functional changes.

Co-authored-by: Leon Dang <[email protected]>

Signed-off-by: Leon Dang <[email protected]>
Signed-off-by: Lev Stipakov <[email protected]>
  • Loading branch information
lstipakov committed Sep 5, 2024
1 parent f7877d2 commit 4690799
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
38 changes: 38 additions & 0 deletions Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,38 @@ OvpnEvtIoWrite(WDFQUEUE queue, WDFREQUEST request, size_t length)
ExReleaseSpinLockShared(&device->SpinLock, kiqrl);
}

NTSTATUS
OvpnSetMode(POVPN_DEVICE device, WDFREQUEST request)
{
POVPN_SET_MODE mode;
NTSTATUS status = WdfRequestRetrieveInputBuffer(request, sizeof(OVPN_SET_MODE), (PVOID*)&mode, NULL);
if (!NT_SUCCESS(status)) {
return status;
}

if (device->Mode != OVPN_MODE_P2P) {
LOG_ERROR("mode already set");
return STATUS_ALREADY_INITIALIZED;
}

status = STATUS_SUCCESS;

LOG_INFO("Set mode", TraceLoggingValue(static_cast<int>(mode->Mode), "mode"));

switch (mode->Mode) {
case OVPN_MODE_P2P:
case OVPN_MODE_MP:
device->Mode = mode->Mode;
break;

default:
status = STATUS_INVALID_PARAMETER;
break;
}

return status;
}

EVT_WDF_IO_QUEUE_IO_DEVICE_CONTROL OvpnEvtIoDeviceControl;

_Use_decl_annotations_
Expand Down Expand Up @@ -291,6 +323,12 @@ OvpnEvtIoDeviceControl(WDFQUEUE queue, WDFREQUEST request, size_t outputBufferLe
status = OvpnGetVersion(request, &bytesReturned);
break;

case OVPN_IOCTL_SET_MODE:
kirql = ExAcquireSpinLockExclusive(&device->SpinLock);
status = OvpnSetMode(device, request);
ExReleaseSpinLockExclusive(&device->SpinLock, kirql);
break;

default:
LOG_WARN("Unknown <ioControlCode>", TraceLoggingValue(ioControlCode, "ioControlCode"));
status = STATUS_INVALID_DEVICE_REQUEST;
Expand Down
1 change: 1 addition & 0 deletions Driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ struct OVPN_DEVICE {
_Guarded_by_(SpinLock)
RTL_GENERIC_TABLE Peers;

OVPN_MODE Mode;
};

typedef OVPN_DEVICE * POVPN_DEVICE;
Expand Down
10 changes: 10 additions & 0 deletions uapi/ovpn-dco.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,15 @@ typedef struct _OVPN_VERSION {
LONG Patch;
} OVPN_VERSION, * POVPN_VERSION;

typedef enum {
OVPN_MODE_P2P,
OVPN_MODE_MP
} OVPN_MODE;

typedef struct _OVPN_SET_MODE {
OVPN_MODE Mode;
} OVPN_SET_MODE, * POVPN_SET_MODE;

#define OVPN_IOCTL_NEW_PEER CTL_CODE(FILE_DEVICE_UNKNOWN, 1, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define OVPN_IOCTL_GET_STATS CTL_CODE(FILE_DEVICE_UNKNOWN, 2, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define OVPN_IOCTL_NEW_KEY CTL_CODE(FILE_DEVICE_UNKNOWN, 3, METHOD_BUFFERED, FILE_ANY_ACCESS)
Expand All @@ -123,3 +132,4 @@ typedef struct _OVPN_VERSION {
#define OVPN_IOCTL_DEL_PEER CTL_CODE(FILE_DEVICE_UNKNOWN, 7, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define OVPN_IOCTL_GET_VERSION CTL_CODE(FILE_DEVICE_UNKNOWN, 8, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define OVPN_IOCTL_NEW_KEY_V2 CTL_CODE(FILE_DEVICE_UNKNOWN, 9, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define OVPN_IOCTL_SET_MODE CTL_CODE(FILE_DEVICE_UNKNOWN, 10, METHOD_BUFFERED, FILE_ANY_ACCESS)

0 comments on commit 4690799

Please sign in to comment.