From: "stipa (Code Review)" Date: Tue, 10 Sep 2024 09:13:15 +0000 In-Reply-To: References: Reply-To: lstipakov@...277..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641..., gert@...1296... Message-ID: <7cbe32e0f28858100e35c9e922644616d44f1d9b-EmailReplacePatchSet-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="VovPhZv1Y00="; charset=UTF-8 Subject: [Openvpn-devel] [M] Change in openvpn[master]: dco-win: factor out getting dco version info own function List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos , flichtenheld Cc: cron2 , openvpn-devel --VovPhZv1Y00= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: flichtenheld, plaisthos, stipa. Hello 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 (#2). Change subject: dco-win: factor out getting dco version info own function ...................................................................... dco-win: factor out getting dco version info own function Instead of having duplicated code to get dco version for data_v3 checks and for version info, have it in one place and store the version in dco context - the latter is a preparation for dco v2 support (multi-peer). Change-Id: I8e8ddd35bd3cc3334faf7f57118d1892512ae9f7 Signed-off-by: Lev Stipakov --- M src/openvpn/dco_win.c M src/openvpn/dco_win.h 2 files changed, 71 insertions(+), 58 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/33/733/2 diff --git a/src/openvpn/dco_win.c b/src/openvpn/dco_win.c index 189864b..349b45a 100644 --- a/src/openvpn/dco_win.c +++ b/src/openvpn/dco_win.c @@ -52,10 +52,70 @@ return tt; } +/** + * Gets version of dco-win driver + * + * Fills Major/Minor/Patch fields in a passes 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; +} + +static inline +bool +dco_version_supports_data_v3(OVPN_VERSION *version) +{ + return (version->Major > 1) || (version->Minor >=3D 4); +} + bool ovpn_dco_init(int mode, dco_context_t *dco) { - dco->supports_data_v3 =3D dco_supports_data_v3(NULL); + (void)dco_get_version(&dco->version); + dco->supports_data_v3 =3D dco_version_supports_data_v3(&dco->version); + msg(D_DCO_DEBUG, "dco supports data_v3: %d", dco->supports_data_v3); return true; @@ -427,39 +487,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); } =20 int @@ -538,36 +576,10 @@ bool dco_supports_data_v3(struct context *c) { - bool res =3D false; + OVPN_VERSION version =3D {0}; + (void)dco_get_version(&version); - HANDLE h =3D CreateFile("\\\\.\\ovpn-dco-ver", GENERIC_READ, - 0, NULL, OPEN_EXISTING, 0, NULL); - - if (h =3D=3D INVALID_HANDLE_VALUE) - { - goto done; - } - - OVPN_VERSION version; - ZeroMemory(&version, sizeof(OVPN_VERSION)); - - DWORD bytes_returned =3D 0; - if (!DeviceIoControl(h, OVPN_IOCTL_GET_VERSION, NULL, 0, - &version, sizeof(version), &bytes_returned, NULL)) - { - goto done; - } - - /* data_v3 is supported starting from 1.4 */ - res =3D (version.Major > 1) || (version.Minor >=3D 4); - -done: - if (h !=3D INVALID_HANDLE_VALUE) - { - CloseHandle(h); - } - - return res; + return dco_version_supports_data_v3(&version); } #endif /* defined(_WIN32) */ diff --git a/src/openvpn/dco_win.h b/src/openvpn/dco_win.h index f58488f..ce57817 100644 --- a/src/openvpn/dco_win.h +++ b/src/openvpn/dco_win.h @@ -34,6 +34,7 @@ struct dco_context { struct tuntap *tt; bool supports_data_v3; + OVPN_VERSION version; }; typedef struct dco_context dco_context_t; -- 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: 2 Gerrit-Owner: stipa Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: cron2 Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos Gerrit-Attention: flichtenheld Gerrit-Attention: stipa Gerrit-MessageType: newpatchset --VovPhZv1Y00= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is currently required from: flichtenheld, plaisthos, stipa. <= /p>

stipa uploaded patch set #2 to this change.

View Change

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/33/733/2
diff --git a/src/openvpn/dco_win.c b/src/openvpn/dco_win.cindex 189864b..349b45a 100644
--- a/src/openvpn/dco_= win.c
+++ b/src/openvpn/dco_win.c
@@ -52,10= +52,70 @@
return tt;
}

+/**
<= span style=3D"color: hsl(120, 100%, 40%);">+ * Gets version of dco-win driv= er
+ *
+ * Fills Major/Minor/Patch fields = in a passes OVPN_VERSION
+ * struct. If version cannot be obtained, fields are set to 0.<= br>+ *
+ * @param version pointer to OVPN_VERSION st= ruct
+ * @returns tru= e 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);
+<= br>+ if (h =3D=3D INVALID_HA= NDLE_VALUE)
+ {
+ /* fallback to= a "normal" device, this will fail if device is already in use */=
+ h =3D Creat= eFile("\\\\.\\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;
+ }
+
+ r= es =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;
+}
++static inline
+bool
+dco_version_supports_data_v3(OVPN_VERSION *version= )
+{
+ return (version->Major > 1= ) || (version->Minor >=3D 4);
+}
+
bool
ovpn_dco_init(int mode, dco_context_t= *dco)
{
- dco->supports_data_v3 =3D dco_supports_data_v3(NULL);
= + (void)dco_get_version(&= ;dco->version);
+ = dco->supports_data_v3 =3D dco_version_supports_data_v3(&dco->v= ersion);
+
= msg(D_DCO_DEBUG, "dco supports data_v3: %d", dco->s= upports_data_v3);

return true;

@@ -427,39 +487,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>
@@ -538,36 +576,10 @@
bool
dco_supports_data_v3(struct context *c)

{
- bool res =3D false;

+ OVPN_VERSION version =3D {0}= ;

+ (void)dco_get_= version(&version);

- HANDLE h =3D CreateFile("\\\\.\\ovpn-dco-ver&qu= ot;, GENERIC_READ,
- = 0, NULL, OPEN_EXISTING, 0, NULL);
-
- if (h =3D=3D INVALID_HANDLE_VALUE)
- {
- goto done;
- }
-

- OVPN_VERSION version= ;
- ZeroMemory(&= version, sizeof(OVPN_VERSION));
-
- DWORD b= ytes_returned =3D 0;
- = if (!DeviceIoControl(h, OVPN_IOCTL_GET_VERSION, NULL, 0,
- &version= , sizeof(version), &bytes_returned, NULL))
- {
- goto done;
- }
-- /* data_v3 is supported sta= rting from 1.4 */
- = res =3D (version.Major > 1) || (version.Minor >=3D 4);
-
-done:
- if (h !=3D INVALID_HANDLE_VALUE)
- {
= - CloseHandle(h);
-
- return res;
+ return dco_version_supports_data_v= 3(&version);
}

#end= if /* defined(_WIN32) */
diff --git a/src/openvpn/dco_win.h= b/src/openvpn/dco_win.h
index f58488f..ce57817 100644

--- a/src/openvpn/dco_win.h
+++ b/src/openvpn/d= co_win.h
@@ -34,6 +34,7 @@
struct dco_cont= ext {
struct tuntap *tt;
bool sup= ports_data_v3;
+ O= VPN_VERSION version;
};

= typedef struct dco_context dco_context_t;

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

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