From: "cron2 (Code Review)" Date: Thu, 15 May 2025 15:12:59 +0000 In-Reply-To: References: Reply-To: gert@...1296..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, ralf@...2726..., frank@...2641..., antonio@...2726... Message-ID: <11c566eb24cccf96de2c59621400928193826ee5-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="gM6GASsYY/c="; 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: ralf_lici Cc: plaisthos , flichtenheld , openvpn-devel --gM6GASsYY/c= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/10= 22?usp=3Demail ) 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 Acked-by: Gert Doering Message-Id: <20250515150038.30097-1-gert@...1296...> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg31= 652.html Signed-off-by: Gert Doering --- M src/openvpn/dco_linux.c 1 file changed, 68 insertions(+), 1 deletion(-) 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: 3 Gerrit-Owner: ralf_lici Gerrit-Reviewer: cron2 Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: ordex Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-MessageType: merged --gM6GASsYY/c= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

cron2 submitted this change.

View Change

Implement ovpn version detection

Add d= etection of the ovpn kernel module type: if a backported
(out-of-tree) v= ersion is loaded, the MODULE_VERSION string is read from
sysfs; otherwis= e, for the in-tree module, the function reports the
kernel release and v= ersion.

Change-Id: I7fc033a7ffee73045316763356a95d75ef23f5ad
Sign= ed-off-by: Ralf Lici <ralf@...2726...>
Acked-by: Gert Doering <= gert@...1296...>
Message-Id: <20250515150038.30097-1-gert@...1725...= ..>
URL: https://www.mail-archive.com/openvpn-devel@...282...= .net/msg31652.html
Signed-off-by: Gert Doering <gert@...1296...>---
M src/openvpn/dco_linux.c
1 file changed, 68 insertions(+), 1 d= eletion(-)

diff --git a/src/openvpn/dco_linux.c b/src/openvpn/dco_linux.cindex c950e3d..a5f9e06 100644
--- a/src/openvpn/dco_= linux.c
+++ b/src/openvpn/dco_linux.c
@@ -1= 117,10 +1117,77 @@
return true;
}


+/**
+ * There's no ver= sion indicator in the ovpn in-tree module, so we return a
+ * string containing info about the k= ernel version and release.
+ */
+static co= nst char *
+dco_versi= on_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_p= uts(&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 versi= on file
+ * in sysfs.= Read it and return the string.
+ *
+ * Th= e caller is responsible for closing the file pointer.
+ */
+static const char *
+dco_version_string_backports(FILE *fp, struct gc_arena *g= c)
+{
+ char *str =3D gc_malloc(PATH_MA= X, false, gc);

+
+ if (!fgets(str, PATH= _MAX, fp))
+ {
+ return "ER= R";
+ }
+
+ /* remove potential newline at the end o= f 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;<= /span>
+ struct stat sb;<= /span>
+ FILE *fp;=
+
+ if (stat("/sys/module/ovpn", &a= mp;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&#= 39;re dealing with the in-tree version, otherwise

+ * it's backports */
+ fp =3D fopen("/sys/module/o= vpn/version", "r");
+ if (!fp)
+ {
+ = return dco_version_string_in_tree(gc);
+ }
+ version =3D dco_version_string_backports(fp, gc);
+

+ fclose(fp);
+ return version;
}
<= /span>
void

To view, visit change 102= 2. 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: 3
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-MessageType: merged
--gM6GASsYY/c=--