Skip to content

Commit

Permalink
dco-win: get driver version
Browse files Browse the repository at this point in the history
Print dco-win driver version using the new ioctl.
Requires dco-win driver 1.0.0 or newer to work.

Change-Id: I1d0d909e7fca3f51b5c848f1a771a989ab040f17
Signed-off-by: Lev Stipakov <[email protected]>
Acked-by: Arne Schwabe <[email protected]>
Message-Id: <[email protected]>
URL: https://www.mail-archive.com/[email protected]/msg27174.html
Signed-off-by: Gert Doering <[email protected]>
(cherry picked from commit e8e5f8a)
  • Loading branch information
lstipakov authored and cron2 committed Oct 15, 2023
1 parent 1240d97 commit c54e1b2
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/openvpn/dco_win.c
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,32 @@ dco_available(int msglevel)
const char *
dco_version_string(struct gc_arena *gc)
{
return "v0";
OVPN_VERSION version;
ZeroMemory(&version, sizeof(OVPN_VERSION));

/* try to open device by symbolic name */
HANDLE h = CreateFile("\\\\.\\ovpn-dco", GENERIC_READ | GENERIC_WRITE,
0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_SYSTEM | FILE_FLAG_OVERLAPPED, NULL);

if (h == INVALID_HANDLE_VALUE)
{
return "N/A";
}

DWORD bytes_returned = 0;
if (!DeviceIoControl(h, OVPN_IOCTL_GET_VERSION, NULL, 0,
&version, sizeof(version), &bytes_returned, NULL))
{
CloseHandle(h);
return "N/A";
}

CloseHandle(h);

struct buffer out = alloc_buf_gc(256, gc);
buf_printf(&out, "%ld.%ld.%ld", version.Major, version.Minor, version.Patch);

return BSTR(&out);
}

int
Expand Down
7 changes: 7 additions & 0 deletions src/openvpn/ovpn_dco_win.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,17 @@ typedef struct _OVPN_SET_PEER {
LONG MSS;
} OVPN_SET_PEER, * POVPN_SET_PEER;

typedef struct _OVPN_VERSION {
LONG Major;
LONG Minor;
LONG Patch;
} OVPN_VERSION, * POVPN_VERSION;

#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)
#define OVPN_IOCTL_SWAP_KEYS CTL_CODE(FILE_DEVICE_UNKNOWN, 4, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define OVPN_IOCTL_SET_PEER CTL_CODE(FILE_DEVICE_UNKNOWN, 5, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define OVPN_IOCTL_START_VPN CTL_CODE(FILE_DEVICE_UNKNOWN, 6, METHOD_BUFFERED, FILE_ANY_ACCESS)
#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)

0 comments on commit c54e1b2

Please sign in to comment.