From: "ralf_lici (Code Review)" Date: Wed, 14 May 2025 21:02:52 +0000 References: Reply-To: ralf@...2726..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="NzEwmM4jaxc="; 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 --NzEwmM4jaxc= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: flichtenheld, plaisthos. Hello plaisthos, flichtenheld, I'd like you to do a code review. Please visit http://gerrit.openvpn.net/c/openvpn/+/1022?usp=3Demail to review the following change. 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, 69 insertions(+), 1 deletion(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/22/1022/1 diff --git a/src/openvpn/dco_linux.c b/src/openvpn/dco_linux.c index c950e3d..7ee0613 100644 --- a/src/openvpn/dco_linux.c +++ b/src/openvpn/dco_linux.c @@ -1117,10 +1117,78 @@ 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) +{ + struct buffer buf =3D alloc_buf_gc(256, gc); + char *str =3D BSTR(&buf); + + if (!fgets(str, BCAP(&buf), fp)) + { + return "ERR"; + } + + /* remove potential newline at the end of the string */ + char *nl =3D strchr(str, '\n'); + if (nl) + { + *nl =3D '\0'; + } + + return BSTR(&buf); +} + 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: 1 Gerrit-Owner: ralf_lici Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos Gerrit-Attention: flichtenheld Gerrit-MessageType: newchange --NzEwmM4jaxc= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is currently required from: flichtenheld, plaisthos.

ralf_lici would like plaisthos and flichtenheld to review this change.

V= iew Change

Implement ovpn version detection

Add detection of the= ovpn kernel module type: if a backported
(out-of-tree) version is loade= d, the MODULE_VERSION string is read from
sysfs; otherwise, for the in-t= ree module, the function reports the
kernel release and version.

= Change-Id: I7fc033a7ffee73045316763356a95d75ef23f5ad
Signed-off-by: Ralf= Lici <ralf@...2726...>
---
M src/openvpn/dco_linux.c
1 file= changed, 69 insertions(+), 1 deletion(-)

git pull ssh://gerrit.o=
penvpn.net:29418/openvpn refs/changes/22/1022/1
diff --git a/src/op=
envpn/dco_linux.c b/src/openvpn/dco_linux.c
index c950e3d..= 7ee0613 100644
--- a/src/openvpn/dco_linux.c
+++ b/src/openvpn/dco_linux.c
@@ -1117,10 +1117,78 @@
return true;
}
<= br>+/**
+ * There's no version indicator in th= e ovpn in-tree module, so we return a
+ * string containing info about the kernel version and re= lease.
+ */+static const char *+dco_version_string_in_tree(st= ruct gc_arena *gc)
+{=
+ struct buffer b= uf =3D alloc_buf_gc(256, gc);
+ struct utsname system;
+
+ = if (uname(&system))
+ {
+ = return "ERR";
+ }
++ buf_puts(&buf, system= .release);
+ buf_p= uts(&buf, " ");
+ buf_puts(&buf, system.version);
+ return BSTR(&buf);
+}
+
+= /**
+ * When the modu= le is loaded, the backports version of ovpn has a version file
+ * in sysfs. Read it and return = the string.

+ *
+ * The caller is responsi= ble for closing the file pointer.
+ */
+st= atic const char *
+dc= o_version_string_backports(FILE *fp, struct gc_arena *gc)
+{
+ struct buffer buf =3D alloc_buf_gc(256, gc);=
+ char *str =3D BSTR(&am= p;buf);
+
<= span style=3D"color: hsl(120, 100%, 40%);">+ if (!fgets(str, BCAP(&b= uf), fp))

+ {

+ return "ERR= ";
+ }=
+
+ /* remove potential newline at the end of= the string */
+ c= har *nl =3D strchr(str, '\n');
+ if (nl)
+ {
+ = *nl =3D '\0';
+ }
+=
+ return BSTR(&buf);=
+}
+
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: 1
Gerrit-Owner: ralf_lici <ralf@...2726...>= ;
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: flichtenheld <frank@...2375...= 41...>
Gerrit-MessageType: newchange
--NzEwmM4jaxc=--