From: "ralf_lici (Code Review)" Date: Thu, 15 May 2025 08:27:43 +0000 In-Reply-To: References: Reply-To: ralf@...2726..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641..., antonio@...2726..., gert@...1296... Message-ID: <3ecb112a4bf0633380b747804572d647c87f8de1-EmailReplacePatchSet-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="TEb7lr8uGXc="; charset=UTF-8 Subject: [Openvpn-devel] [M] Change in openvpn[master]: Implement ovpn version detection List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos , flichtenheld Cc: openvpn-devel --TEb7lr8uGXc= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: cron2, flichtenheld, ordex, plaisthos= , ralf_lici. Hello cron2, flichtenheld, ordex, plaisthos, I'd like you to reexamine a change. Please visit http://gerrit.openvpn.net/c/openvpn/+/1022?usp=3Demail to look at the new patch set (#2). The following approvals got outdated and were removed: Code-Review+1 by ordex, Code-Review-1 by cron2 Change subject: Implement ovpn version detection ...................................................................... Implement ovpn version detection Add detection of the ovpn kernel module type: if a backported (out-of-tree) version is loaded, the MODULE_VERSION string is read from sysfs; otherwise, for the in-tree module, the function reports the kernel release and version. Change-Id: I7fc033a7ffee73045316763356a95d75ef23f5ad Signed-off-by: Ralf Lici --- M src/openvpn/dco_linux.c 1 file changed, 68 insertions(+), 1 deletion(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/22/1022/2 diff --git a/src/openvpn/dco_linux.c b/src/openvpn/dco_linux.c index c950e3d..a5f9e06 100644 --- a/src/openvpn/dco_linux.c +++ b/src/openvpn/dco_linux.c @@ -1117,10 +1117,77 @@ return true; } +/** + * There's no version indicator in the ovpn in-tree module, so we return a + * string containing info about the kernel version and release. + */ +static const char * +dco_version_string_in_tree(struct gc_arena *gc) +{ + struct buffer buf =3D alloc_buf_gc(256, gc); + struct utsname system; + + if (uname(&system)) + { + return "ERR"; + } + + buf_puts(&buf, system.release); + buf_puts(&buf, " "); + buf_puts(&buf, system.version); + return BSTR(&buf); +} + +/** + * When the module is loaded, the backports version of ovpn has a version = file + * in sysfs. Read it and return the string. + * + * The caller is responsible for closing the file pointer. + */ +static const char * +dco_version_string_backports(FILE *fp, struct gc_arena *gc) +{ + char *str =3D gc_malloc(PATH_MAX, false, gc); + + if (!fgets(str, PATH_MAX, fp)) + { + return "ERR"; + } + + /* remove potential newline at the end of the string */ + char *nl =3D strchr(str, '\n'); + if (nl) + { + *nl =3D '\0'; + } + + return str; +} + const char * dco_version_string(struct gc_arena *gc) { - return "Unknown"; + const char *version; + struct stat sb; + FILE *fp; + + if (stat("/sys/module/ovpn", &sb) !=3D 0 || !S_ISDIR(sb.st_mode)) + { + return "N/A"; + } + + /* now that we know for sure that the module is loaded, if there's no + * version file it means we're dealing with the in-tree version, other= wise + * it's backports */ + fp =3D fopen("/sys/module/ovpn/version", "r"); + if (!fp) + { + return dco_version_string_in_tree(gc); + } + version =3D dco_version_string_backports(fp, gc); + + fclose(fp); + return version; } void -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/1022?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: I7fc033a7ffee73045316763356a95d75ef23f5ad Gerrit-Change-Number: 1022 Gerrit-PatchSet: 2 Gerrit-Owner: ralf_lici Gerrit-Reviewer: cron2 Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: ordex Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos Gerrit-Attention: cron2 Gerrit-Attention: flichtenheld Gerrit-Attention: ordex Gerrit-Attention: ralf_lici Gerrit-MessageType: newpatchset --TEb7lr8uGXc= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is currently required from: cron2, flichtenheld, ordex, plais= thos, ralf_lici.

ralf_lici uploaded patch set #2 to this change.

<= a href=3D"http://gerrit.openvpn.net/c/openvpn/+/1022?usp=3Demail">View Chan= ge

The following approvals got outdated and were removed: Code-Review+1 by ordex, Code-Review-1 by cron2

Implement ovpn version detec=
tion

Add detection of the ovpn kernel module type: if a backported(out-of-tree) version is loaded, the MODULE_VERSION string is read fromsysfs; otherwise, for the in-tree module, the function reports the
ker= nel release and version.

Change-Id: I7fc033a7ffee73045316763356a95d7= 5ef23f5ad
Signed-off-by: Ralf Lici <ralf@...2726...>
---
M s= rc/openvpn/dco_linux.c
1 file changed, 68 insertions(+), 1 deletion(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/22/10=
22/2
diff --git a/src/openvpn/dco_linux.c b/src/openvpn/dco_linux.c=

index c950e3d..a5f9e06 100644
--- a/src/op= envpn/dco_linux.c
+++ b/src/openvpn/dco_linux.c
<= span>@@ -1117,10 +1117,77 @@
return true;
}

+/**
+ * There= 9;s no version indicator in the ovpn in-tree module, so we return a<= br>+ * string containing info a= bout the kernel version and release.
+ */
= +static const char *
= +dco_version_string_in_tree(struct gc_arena *gc)
+{
+ struct buffer buf =3D alloc_buf_gc(256, gc);
+ struct utsname system;+
+ if (uname(&system))
+ {
+ return "ERR";
+ }
+
= + buf_puts(&buf, system.release);
+ buf_puts(&buf, " ");
+ buf_puts(&buf, system.versi= on);
+ return BSTR= (&buf);
+}=
+
+/**
+ * When the module is loaded, the backports version of ovpn h= as a version file
+ *= in sysfs. Read it and return the string.
+ *
+ * The caller is responsible for closing the file pointer.
<= span style=3D"color: hsl(120, 100%, 40%);">+ */
+static const char *
+dco_version_string_backports(FILE *fp, struct g= c_arena *gc)
+{

+ char *str =3D gc_mall= oc(PATH_MAX, false, gc);
+
+ if (!fgets= (str, PATH_MAX, fp))
= + {
+ retur= n "ERR";
+ = }
+
+ /* remove potential newline at= the end of the string */
+ char *nl =3D strchr(str, '\n');
+ if (nl)
+ {
+ *nl =3D '\0';
+ }
+
+ return str;=
+}
+
const char *=
dco_version_string(struct gc_arena *gc)
{

- return "Unknown&qu= ot;;
+ const char = *version;
+ struct= stat sb;
+ FILE *= fp;
+
+ if (stat("/sys/module/ovpn= ", &sb) !=3D 0 || !S_ISDIR(sb.st_mode))
+ {
+ return "N/A";
+ }
+
+ /*= now that we know for sure that the module is loaded, if there's no
+ * version file it = means we're dealing with the in-tree version, otherwise
+ * it's backports */
=
+ fp =3D fopen("/sy= s/module/ovpn/version", "r");
+ if (!fp)
+ {
+ return dco_version_string_in_tree(gc);
+ }
+ version =3D dco_version_string_backports(fp, gc);
+
+ fclose(fp);
+ return version;
}=

void

To vi= ew, visit change 1022. To unsubscribe, or for help writing mail filters, visit = settings.

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I7fc033a7ffee73045316763356a= 95d75ef23f5ad
Gerrit-Change-Number: 1022
Gerrit-PatchSet: 2
Gerrit-Owner: ralf_lici <ralf@...2726...>= ;
Gerrit-Reviewer: cron2 <gert@...1296...>=
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-Reviewer: ordex <antonio@...2726...&= gt;
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: ordex <antonio@...2726...= >
Gerrit-Attention: ralf_lici <ralf@...2804...= .>
Gerrit-MessageType: newpatchset
--TEb7lr8uGXc=--