From: "stipa (Code Review)" Date: Fri, 22 Nov 2024 15:44:25 +0000 In-Reply-To: References: Reply-To: lstipakov@...277..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641..., gert@...1296... Message-ID: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="6/mcjBAug38="; charset=UTF-8 Subject: [Openvpn-devel] [M] Change in openvpn[master]: dco-win: factor out getting dco version List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos , cron2 , flichtenheld Cc: openvpn-devel --6/mcjBAug38= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: cron2, flichtenheld, plaisthos, stipa. Hello cron2, flichtenheld, plaisthos, I'd like you to reexamine a change. Please visit http://gerrit.openvpn.net/c/openvpn/+/733?usp=3Demail to look at the new patch set (#4). The following approvals got outdated and were removed: Code-Review+2 by flichtenheld The change is no longer submittable: Code-Review and checks~ChecksSubmitRul= e are unsatisfied now. Change subject: dco-win: factor out getting dco version ...................................................................... dco-win: factor out getting dco version As a preparation for multipeer and data_v3, add function which returns dco version in machine-readable format. Change-Id: I8e8ddd35bd3cc3334faf7f57118d1892512ae9f7 Signed-off-by: Lev Stipakov --- M src/openvpn/dco_win.c 1 file changed, 57 insertions(+), 28 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/33/733/4 diff --git a/src/openvpn/dco_win.c b/src/openvpn/dco_win.c index 9224bca..f59bf8c 100644 --- a/src/openvpn/dco_win.c +++ b/src/openvpn/dco_win.c @@ -52,6 +52,57 @@ return tt; } +/** + * Gets version of dco-win driver + * + * Fills Major/Minor/Patch fields in a passed OVPN_VERSION + * struct. If version cannot be obtained, fields are set to 0. + * + * @param version pointer to OVPN_VERSION struct + * @returns true if version has been obtained, false otherwise + */ +static bool +dco_get_version(OVPN_VERSION *version) +{ + CLEAR(*version); + + bool res =3D false; + + HANDLE h =3D CreateFile("\\\\.\\ovpn-dco-ver", GENERIC_READ, + 0, NULL, OPEN_EXISTING, 0, NULL); + + if (h =3D=3D INVALID_HANDLE_VALUE) + { + /* fallback to a "normal" device, this will fail if device is alre= ady in use */ + h =3D CreateFile("\\\\.\\ovpn-dco", GENERIC_READ, + 0, NULL, OPEN_EXISTING, 0, NULL); + } + + if (h =3D=3D INVALID_HANDLE_VALUE) + { + goto done; + } + + DWORD bytes_returned =3D 0; + if (!DeviceIoControl(h, OVPN_IOCTL_GET_VERSION, NULL, 0, + version, sizeof(*version), &bytes_returned, NULL)) + { + goto done; + } + + res =3D true; + +done: + if (h !=3D INVALID_HANDLE_VALUE) + { + CloseHandle(h); + } + + msg(D_DCO_DEBUG, "dco version: %ld.%ld.%ld", version->Major, version->= Minor, version->Patch); + + return res; +} + bool ovpn_dco_init(int mode, dco_context_t *dco) { @@ -386,39 +437,17 @@ const char * dco_version_string(struct gc_arena *gc) { - OVPN_VERSION version; - ZeroMemory(&version, sizeof(OVPN_VERSION)); - - /* first, try a non-exclusive control device, available from 1.3.0 */ - HANDLE h =3D CreateFile("\\\\.\\ovpn-dco-ver", GENERIC_READ, - 0, NULL, OPEN_EXISTING, 0, NULL); - - if (h =3D=3D INVALID_HANDLE_VALUE) + OVPN_VERSION version =3D {0}; + if (dco_get_version(&version)) { - /* fallback to a "normal" device, this will fail if device is alre= ady in use */ - h =3D CreateFile("\\\\.\\ovpn-dco", GENERIC_READ, - 0, NULL, OPEN_EXISTING, 0, NULL); + struct buffer out =3D alloc_buf_gc(256, gc); + buf_printf(&out, "%ld.%ld.%ld", version.Major, version.Minor, vers= ion.Patch); + return BSTR(&out); } - - if (h =3D=3D INVALID_HANDLE_VALUE) + else { return "N/A"; } - - DWORD bytes_returned =3D 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 =3D alloc_buf_gc(256, gc); - buf_printf(&out, "%ld.%ld.%ld", version.Major, version.Minor, version.= Patch); - - return BSTR(&out); } int -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/733?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: I8e8ddd35bd3cc3334faf7f57118d1892512ae9f7 Gerrit-Change-Number: 733 Gerrit-PatchSet: 4 Gerrit-Owner: stipa Gerrit-Reviewer: cron2 Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos Gerrit-Attention: cron2 Gerrit-Attention: flichtenheld Gerrit-Attention: stipa Gerrit-MessageType: newpatchset --6/mcjBAug38= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is currently required from: cron2, flichtenheld, plaisthos, s= tipa.

stipa uploaded patch set #4 to this change.

View Change

The following approvals got outdated and were removed: Code-Review+2 by flichtenheld

The change is no longer submittable: Co= de-Review and checks~ChecksSubmitRule are unsatisfied now.

dco-win: factor =
out getting dco version

As a preparation for multipeer and data_v3,<= br>add function which returns dco version in
machine-readable format.
Change-Id: I8e8ddd35bd3cc3334faf7f57118d1892512ae9f7
Signed-off-by:= Lev Stipakov <lev@...515...>
---
M src/openvpn/dco_win.c
1 = file changed, 57 insertions(+), 28 deletions(-)

git pull ssh://ge=
rrit.openvpn.net:29418/openvpn refs/changes/33/733/4
diff --git a/s=
rc/openvpn/dco_win.c b/src/openvpn/dco_win.c
index 9224bca.= .f59bf8c 100644
--- a/src/openvpn/dco_win.c
+++ b/src/openvpn/dco_win.c
@@ -52,6 +52,57 @@
<= span> return tt;
}

+/**
+ * Gets version of dco-win driver
+ *
+ * Fills Major/Minor/Patch fields in a passed OVPN_VERSI= ON
+ * struct. If ver= sion cannot be obtained, fields are set to 0.
+ *
+ * @param version pointer to OVPN_VERSION struct
+ * @returns true if version has been = obtained, false otherwise
+ */
+static boo= l
+dco_get_version(OV= PN_VERSION *version)
= +{
+ CLEAR(*versio= n);
+
+ bool res =3D false;
<= span style=3D"color: hsl(120, 100%, 40%);">+
+ HANDLE h =3D CreateFile("\\\\.\\ovpn-dco-= ver", GENERIC_READ,
+ 0, NULL, OPEN_EXISTING, 0, NULL);
= +
+ if (h =3D=3D INVALID_HANDLE_VALUE)
= + {
+ /* fallback to a "normal" = device, this will fail if device is already in use */
+ h =3D CreateFile("\\\\.\\ovp= n-dco", GENERIC_READ,
+ 0, NULL, OPEN_EXISTING, 0, NULL);
<= span style=3D"color: hsl(120, 100%, 40%);">+ }
+
+ if (h =3D=3D INVALID_HANDLE_VALUE)
+ {
+ goto done;
+ }
= +
+ DWORD bytes_re= turned =3D 0;
+ if= (!DeviceIoControl(h, OVPN_IOCTL_GET_VERSION, NULL, 0,
+ version, sizeof= (*version), &bytes_returned, NULL))
+ {
+ goto done;
+ }
++ res =3D true;
= +
+done:
+ if (h !=3D INVALID_HANDLE_VALUE)
+ {
+ CloseHandle(h);
+ }
+
+ msg(D_DCO_= DEBUG, "dco version: %ld.%ld.%ld", version->Major, version->= ;Minor, version->Patch);
+
+ return = res;
+}
+
bool
= ovpn_dco_init(int mode, dco_context_t *dco)
{

@@ -386,39 +437,17 @@
const char *
dco_version_string(struct gc_arena *gc)
{
<= span style=3D"color: hsl(0, 100%, 40%);">- OVPN_VERSION version;<= br>- ZeroMemory(&version, = sizeof(OVPN_VERSION));
= -
- /* first, try a = non-exclusive control device, available from 1.3.0 */
- HANDLE h =3D CreateFile("\\\\.\\ov= pn-dco-ver", GENERIC_READ,
- 0, NULL, OPEN_EXISTING, 0, NULL);

-
- if (h =3D=3D INVALID_HANDLE_VALUE)+ OVPN_VERSION version =3D = {0};
+ if (dco_get= _version(&version))
{
- /* fallback to a "normal" device= , this will fail if device is already in use */
- h =3D CreateFile("\\\\.\\ovpn-dco&qu= ot;, GENERIC_READ,
- = 0, NULL, OPEN_EXISTING, 0, NULL);
+ struct buffer out =3D alloc_buf_g= c(256, gc);
+ = buf_printf(&out, "%ld.%ld.%ld", version.Major, version.Minor,= version.Patch);
+ = return BSTR(&out);
}
-
- if (h =3D=3D INVALID_HANDLE_VALUE)
+ else
{
= return "N/A";
}
-
- DWORD bytes_returned =3D 0;
- if (!DeviceIoControl(h, OVPN_IOCTL_GET_VERSION, = NULL, 0,
- = &version, sizeof(version), &bytes_returned, NULL))
- {
- CloseHandle(h);
- return "N/A";- }
-
- CloseHandle(h);
-
- struct buff= er out =3D alloc_buf_gc(256, gc);
- buf_printf(&out, "%ld.%ld.%ld", version.Major= , version.Minor, version.Patch);
-
- return= BSTR(&out);
}

int<= /span>

To view, visit change 733. To unsubscribe, o= r for help writing mail filters, visit settings.

=
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I8e8ddd35bd3cc3334faf7f57118= d1892512ae9f7
Gerrit-Change-Number: 733
Gerrit-PatchSet: 4
Gerrit-Owner: stipa <lstipakov@...277...>= ;
Gerrit-Reviewer: cron2 <gert@...1296...>=
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-Attention: plaisthos <arne-openvpn@...220...= ..1227...>
Gerrit-Attention: cron2 <gert@...1296...>= ;
Gerrit-Attention: flichtenheld <frank@...2375...= 41...>
Gerrit-Attention: stipa <lstipakov@...1663...= .>
Gerrit-MessageType: newpatchset
--6/mcjBAug38=--