]> git.ipfire.org Git - thirdparty/openvpn.git/commitdiff
dco: print version to log if available
authorAntonio Quartulli <a@unstable.cc>
Thu, 9 Mar 2023 13:14:19 +0000 (14:14 +0100)
committerGert Doering <gert@greenie.muc.de>
Mon, 13 Mar 2023 14:20:29 +0000 (15:20 +0100)
In order to provide better support in case of troubleshooting issues,
it's important to know what exact DCO version is loaded on the user
system.

Therefore print the DCO version during bootup.

For Windows and FreeBSD we currently implement a placeholder printing 'v0'.
This should be improved with a follow-up patch.

For Linux we directly fetch the module version from /sys and print
something like:

DCO version: 0.1.20230206-15-g580608ec7c59

Change-Id: Ie1f6fa5d12a473d353d84fd119c2430b638e8bcd
Signed-off-by: Antonio Quartulli <a@unstable.cc>
Acked-by: Arne Schwabe <arne@rfc2549.org>
Message-Id: <20230309131419.29157-1-a@unstable.cc>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg26370.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
src/openvpn/dco.h
src/openvpn/dco_freebsd.c
src/openvpn/dco_linux.c
src/openvpn/dco_win.c
src/openvpn/openvpn.c
src/openvpn/options.c
src/openvpn/options.h

index 2fe671bf6fcdeea8ecec8fb03831d6fbb6c6e811..96d95c21f644725dc6a388dffaba0a9caeee3bb5 100644 (file)
@@ -58,6 +58,15 @@ struct tuntap;
  */
 bool dco_available(int msglevel);
 
+
+/**
+ * Return a human readable string representing the DCO version
+ *
+ * @param gc    the garbage collector to use for any dynamic allocation
+ * @return      a pointer to the string (allocated via gc) containing the string
+ */
+const char *dco_version_string(struct gc_arena *gc);
+
 /**
  * Check whether the options struct has any option that is not supported by
  * our current dco implementation. If so print a warning at warning level
@@ -250,6 +259,12 @@ dco_available(int msglevel)
     return false;
 }
 
+static inline const char *
+dco_version_string(struct gc_arena *gc)
+{
+    return "not-compiled";
+}
+
 static inline bool
 dco_check_option(int msglevel, const struct options *o)
 {
index 92de5f04b1d412c0ee4f7f6957558511e18671d7..cbd2ce205805a88c683b10d3deb33caa1f3b1cfd 100644 (file)
@@ -614,6 +614,12 @@ out:
     return available;
 }
 
+const char *
+dco_version_string(struct gc_arena *gc)
+{
+    return "v0";
+}
+
 void
 dco_event_set(dco_context_t *dco, struct event_set *es, void *arg)
 {
index 2b349529fff2c37ac5577038650fc45667f8c0ca..b2fdbf53f1d3123eb4f52c39c4996fb8a049ab60 100644 (file)
@@ -843,9 +843,36 @@ dco_available(int msglevel)
             "Note: Kernel support for ovpn-dco missing, disabling data channel offload.");
         return false;
     }
+
     return true;
 }
 
+const char *
+dco_version_string(struct gc_arena *gc)
+{
+    struct buffer out = alloc_buf_gc(256, gc);
+    FILE *fp = fopen("/sys/module/ovpn_dco_v2/version", "r");
+    if (!fp)
+    {
+        return "N/A";
+    }
+
+    if (!fgets(BSTR(&out), BCAP(&out), fp))
+    {
+        return "ERR";
+    }
+
+    /* remove potential newline at the end of the string */
+    char *str = BSTR(&out);
+    char *nl = strchr(str, '\n');
+    if (nl)
+    {
+        *nl = '\0';
+    }
+
+    return BSTR(&out);
+}
+
 void
 dco_event_set(dco_context_t *dco, struct event_set *es, void *arg)
 {
index a805c2a03809c011f7bcc7c4f9b17ace3f8f2f0e..26463b387dea6ee38c6e417dd84a2e3b32b22b1e 100644 (file)
@@ -385,6 +385,12 @@ dco_available(int msglevel)
     return false;
 }
 
+const char *
+dco_version_string(struct gc_arena *gc)
+{
+    return "v0";
+}
+
 int
 dco_do_read(dco_context_t *dco)
 {
index cba582769e8387cd9dceb253cd681b08568d7936..1aaddcdfc94c7f0233e2e8c1a6f16ba4322ed490 100644 (file)
@@ -262,6 +262,8 @@ openvpn_main(int argc, char *argv[])
 #endif
             show_library_versions(M_INFO);
 
+            show_dco_version(M_INFO);
+
             /* misc stuff */
             pre_setup(&c.options);
 
index ce7bd0a79708fb49057a720cc08b9c12466b38bb..8f0e21940dea2534a6d07b646ffc1ac28817bba4 100644 (file)
@@ -4816,6 +4816,16 @@ show_windows_version(const unsigned int flags)
 }
 #endif
 
+void
+show_dco_version(const unsigned int flags)
+{
+#ifdef ENABLE_DCO
+    struct gc_arena gc = gc_new();
+    msg(flags, "DCO version: %s", dco_version_string(&gc));
+    gc_free(&gc);
+#endif
+}
+
 void
 show_library_versions(const unsigned int flags)
 {
@@ -4839,6 +4849,7 @@ usage_version(void)
 #ifdef _WIN32
     show_windows_version( M_INFO|M_NOPREFIX );
 #endif
+    show_dco_version(M_INFO | M_NOPREFIX);
     msg(M_INFO|M_NOPREFIX, "Originally developed by James Yonan");
     msg(M_INFO|M_NOPREFIX, "Copyright (C) 2002-2023 OpenVPN Inc <sales@openvpn.net>");
 #ifndef ENABLE_SMALL
index 7df717f73f6ec6319f6ed8039885495a8bb17ee7..2f25f5d0771bbcdc00f364ec7ea59153810e2183 100644 (file)
@@ -796,6 +796,8 @@ void show_windows_version(const unsigned int flags);
 
 #endif
 
+void show_dco_version(const unsigned int flags);
+
 void init_options(struct options *o, const bool init_gc);
 
 void uninit_options(struct options *o);