From c54e1b226e9d6709cdc2b243e6a961a6cd47c7c6 Mon Sep 17 00:00:00 2001 From: Lev Stipakov Date: Sun, 8 Oct 2023 13:27:55 +0200 Subject: [PATCH] dco-win: get driver version 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 Acked-by: Arne Schwabe Message-Id: <20231008112755.23568-1-frank@lichtenheld.com> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg27174.html Signed-off-by: Gert Doering (cherry picked from commit e8e5f8a4c4f8e01dc7317ac87a85d3204882d6bf) --- src/openvpn/dco_win.c | 27 ++++++++++++++++++++++++++- src/openvpn/ovpn_dco_win.h | 7 +++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/openvpn/dco_win.c b/src/openvpn/dco_win.c index 53f1523d9ef..a775c829f96 100644 --- a/src/openvpn/dco_win.c +++ b/src/openvpn/dco_win.c @@ -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 diff --git a/src/openvpn/ovpn_dco_win.h b/src/openvpn/ovpn_dco_win.h index cbbdf92e5b2..ea2a733776c 100644 --- a/src/openvpn/ovpn_dco_win.h +++ b/src/openvpn/ovpn_dco_win.h @@ -100,6 +100,12 @@ 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) @@ -107,3 +113,4 @@ typedef struct _OVPN_SET_PEER { #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)