Skip to contentSkip to conversation

dco: print version to log if available

PATCH Superseded Antonio Quartulli 4 participants 11 messages Mar 9, 2023 – Mar 13, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dco: print version to log if available

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
Cc Lev Stipakov <[email protected]...>
Cc Kristof Provost <[email protected]...>
Change-Id Ie1f6fa5d12a473d353d84fd119c2430b638e8bcd
---
 src/openvpn/dco.h         | 15 +++++++++++++++
 src/openvpn/dco_freebsd.c |  6 ++++++
 src/openvpn/dco_linux.c   | 30 ++++++++++++++++++++++++++++++
 src/openvpn/dco_win.c     |  6 ++++++
 src/openvpn/openvpn.c     |  2 ++
 src/openvpn/options.c     | 11 +++++++++++
 src/openvpn/options.h     |  2 ++
 7 files changed, 72 insertions(+)
src/openvpn/dco.h +15 -0
index 2fe671bf..96d95c21 100644
@@ -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)
 {
src/openvpn/dco_freebsd.c +6 -0
index 92de5f04..cbd2ce20 100644
@@ -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)
 {
src/openvpn/dco_linux.c +30 -0
index 308abfc4..c9cd9df1 100644
@@ -841,9 +841,39 @@ 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)
+    {
+        buf_printf(&out, "N/A");
+        goto out;
+    }
+
+    if (!fgets((char *)buf_bptr(&out), out.capacity - 1, fp))
+    {
+        buf_printf(&out, "ERR");
+        goto out;
+    }
+
+    /* remove potential newline at the end of the string */
+    char *str = (char *)buf_bptr(&out);
+    char *nl = strchr(str, '\n');
+    if (nl)
+    {
+        *nl = '\0';
+    }
+
+out:
+    return (char *)out.data;
+}
+
 void
 dco_event_set(dco_context_t *dco, struct event_set *es, void *arg)
 {
src/openvpn/dco_win.c +6 -0
index a805c2a0..26463b38 100644
@@ -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)
 {
src/openvpn/openvpn.c +2 -0
index cba58276..1aaddcdf 100644
@@ -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);
 
src/openvpn/options.c +11 -0
index ce7bd0a7..8f0e2194 100644
@@ -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 <[email protected]...>");
 #ifndef ENABLE_SMALL
src/openvpn/options.h +2 -0
index 7df717f7..2f25f5d0 100644
@@ -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);
Signature · 1 line
2.39.2
#1 lore raw
Quoted 9 lines · Antonio Quartulli

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.

FreeBSD is a bit special in this regard, because the DCO driver is part of the base operating system and not an add-on as in Linux and Windows.

Arguably the thing to do for FreeBSD is to log the OS version.

Kristof

#2 lore raw

Hi,

Quoted 5 lines · Kristof Provost
Quoted 4 lines · Antonio Quartulli

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.

Quoted 8 lines
Quoted 5 lines

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.

FreeBSD is a bit special in this regard, because the DCO driver is part of the base operating system and not an add-on as in Linux and Windows.

Arguably the thing to do for FreeBSD is to log the OS version.

Isn't it possible to install DCO "out-of-tree" (as we can do on Linux)?

However, what you said will also apply to linux in the future: we will also need to report the kernel version, *if* DCO is compiled in (to be implemented).

This said, reporting the kernel/os version is absolutely appropriate if that's what identifies the DCO version.

Is that something you could implement in dco_freebsd.c?

Cheers,

Quoted 2 lines

Kristof

Signature · 1 line
Antonio Quartulli
#3 lore raw
Quoted 8 lines · Antonio Quartulli
Quoted 7 lines · Kristof Provost
Quoted 6 lines · Antonio Quartulli

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.

Quoted 9 lines
Quoted 6 lines
Quoted 3 lines

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

FreeBSD is a bit special in this regard, because the DCO driver is part of the base operating system and not an add-on as in Linux and Windows.

Arguably the thing to do for FreeBSD is to log the OS version.

Isn't it possible to install DCO "out-of-tree" (as we can do on Linux)?

With some effort it could be done, but any version (in the source tree) before DCO was actually imported isn’t going to work. I made a few (small) tweaks to the network stack to make things work.

Realistically this isn’t something people will do, and if they do decide to the usual warranty applies (i.e. they get to keep all of the pieces it breaks into).

Quoted 4 lines

However, what you said will also apply to linux in the future: we will also need to report the kernel version, *if* DCO is compiled in (to be implemented).

This said, reporting the kernel/os version is absolutely appropriate if that's what identifies the DCO version.

There’s no API in FreeBSD’s DCO to identify its version either, which is another reason to just use the OS version.

Quoted 2 lines

Is that something you could implement in dco_freebsd.c?

Sure. I’ll send a patch later today.

Best regards,
Kristof

#4 lore raw

Hi,

Quoted 14 lines · Kristof Provost
Quoted 13 lines · Antonio Quartulli
Quoted 12 lines · Kristof Provost
Quoted 9 lines · Antonio Quartulli

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.

FreeBSD is a bit special in this regard, because the DCO driver is part of the base operating system and not an add-on as in Linux and Windows.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Arguably the thing to do for FreeBSD is to log the OS version.

Isn't it possible to install DCO "out-of-tree" (as we can do on Linux)?

With some effort it could be done, but any version (in the source tree) before DCO was actually imported isn’t going to work. I made a few (small) tweaks to the network stack to make things work.

Realistically this isn’t something people will do, and if they do decide to the usual warranty applies (i.e. they get to keep all of the pieces it breaks into).

Yeah, same problem on Linux. This is why we have to ship a compatibility layer in order to compile DCO on older kernels.

On Linux, though, compiling a new module on an older kernel is pretty common, this is why we have put some effort there too.

Quoted 6 lines
Quoted 5 lines

However, what you said will also apply to linux in the future: we will also need to report the kernel version, *if* DCO is compiled in (to be implemented).

This said, reporting the kernel/os version is absolutely appropriate if that's what identifies the DCO version.

There’s no API in FreeBSD’s DCO to identify its version either, which is another reason to just use the OS version.

yup, makes sense!

Quoted 4 lines
Quoted 3 lines

Is that something you could implement in dco_freebsd.c?

Sure. I’ll send a patch later today.

Thanks!

Cheers,

Quoted 3 lines

Best regards,
Kristof

Signature · 1 line
Antonio Quartulli
#5 lore raw

PATCH v2 1/1 dco: print version to log if available

In reply to Antonio Quartulli

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

---
Changes from v1:
* beautify usage of buf with some helpers
* don't apply -1 to buffer capacity as fgets will already read one byte less than provided length and will add a null terminator there

---
 src/openvpn/dco.h         | 15 +++++++++++++++
 src/openvpn/dco_freebsd.c |  6 ++++++
 src/openvpn/dco_linux.c   | 27 +++++++++++++++++++++++++++
 src/openvpn/dco_win.c     |  6 ++++++
 src/openvpn/openvpn.c     |  2 ++
 src/openvpn/options.c     | 11 +++++++++++
 src/openvpn/options.h     |  2 ++
 7 files changed, 69 insertions(+)
src/openvpn/dco.h +15 -0
index 2fe671bf..96d95c21 100644
@@ -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)
 {
src/openvpn/dco_freebsd.c +6 -0
index 92de5f04..cbd2ce20 100644
@@ -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)
 {
src/openvpn/dco_linux.c +27 -0
index 308abfc4..00d32d05 100644
@@ -841,9 +841,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)
 {
src/openvpn/dco_win.c +6 -0
index a805c2a0..26463b38 100644
@@ -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)
 {
src/openvpn/openvpn.c +2 -0
index cba58276..1aaddcdf 100644
@@ -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);
 
src/openvpn/options.c +11 -0
index ce7bd0a7..8f0e2194 100644
@@ -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 <[email protected]...>");
 #ifndef ENABLE_SMALL
src/openvpn/options.h +2 -0
index 7df717f7..2f25f5d0 100644
@@ -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);
Signature · 1 line
2.39.2
#6 lore raw

PATCH v3 1/1 dco: print version to log if available

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

---
Changes from v1:
* beautify usage of buf with some helpers
* don't apply -1 to buffer capacity as fgets will already read one byte less than provided length and will add a null terminator there

Changes from v2:
* fix style of type returned by dco_version_string() (uncrustify doesn't work anymore on my box..due to incompatibler config)

---
 src/openvpn/dco.h         | 15 +++++++++++++++
 src/openvpn/dco_freebsd.c |  6 ++++++
 src/openvpn/dco_linux.c   | 27 +++++++++++++++++++++++++++
 src/openvpn/dco_win.c     |  6 ++++++
 src/openvpn/openvpn.c     |  2 ++
 src/openvpn/options.c     | 11 +++++++++++
 src/openvpn/options.h     |  2 ++
 7 files changed, 69 insertions(+)
src/openvpn/dco.h +15 -0
index 2fe671bf..96d95c21 100644
@@ -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)
 {
src/openvpn/dco_freebsd.c +6 -0
index 92de5f04..cbd2ce20 100644
@@ -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)
 {
src/openvpn/dco_linux.c +27 -0
index 308abfc4..9f3531d5 100644
@@ -841,9 +841,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)
 {
src/openvpn/dco_win.c +6 -0
index a805c2a0..26463b38 100644
@@ -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)
 {
src/openvpn/openvpn.c +2 -0
index cba58276..1aaddcdf 100644
@@ -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);
 
src/openvpn/options.c +11 -0
index ce7bd0a7..8f0e2194 100644
@@ -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 <[email protected]...>");
 #ifndef ENABLE_SMALL
src/openvpn/options.h +2 -0
index 7df717f7..2f25f5d0 100644
@@ -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);
Signature · 1 line
2.39.2
#7 lore raw

This is being discussed on Gerrit at:

https://gerrit.openvpn.net/c/openvpn/+/28

Quoted 198 lines · Antonio Quartulli

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

---
Changes from v1:
* beautify usage of buf with some helpers
* don't apply -1 to buffer capacity as fgets will already read one byte less than provided length and will add a null terminator there

Changes from v2:
* fix style of type returned by dco_version_string() (uncrustify doesn't work anymore on my box..due to incompatibler config)

---
  src/openvpn/dco.h         | 15 +++++++++++++++
  src/openvpn/dco_freebsd.c |  6 ++++++
  src/openvpn/dco_linux.c   | 27 +++++++++++++++++++++++++++
  src/openvpn/dco_win.c     |  6 ++++++
  src/openvpn/openvpn.c     |  2 ++
  src/openvpn/options.c     | 11 +++++++++++
  src/openvpn/options.h     |  2 ++
  7 files changed, 69 insertions(+)
src/openvpn/dco.h +15 -0
index 2fe671bf..96d95c21 100644
@@ -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)
  {
src/openvpn/dco_freebsd.c +6 -0
index 92de5f04..cbd2ce20 100644
@@ -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)
  {
src/openvpn/dco_linux.c +27 -0
index 308abfc4..9f3531d5 100644
@@ -841,9 +841,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)
  {
src/openvpn/dco_win.c +6 -0
index a805c2a0..26463b38 100644
@@ -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)
  {
src/openvpn/openvpn.c +2 -0
index cba58276..1aaddcdf 100644
@@ -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);
 
src/openvpn/options.c +11 -0
index ce7bd0a7..8f0e2194 100644
@@ -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 <[email protected]...>");
  #ifndef ENABLE_SMALL
src/openvpn/options.h +2 -0
index 7df717f7..2f25f5d0 100644
@@ -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);
Signature · 1 line
Antonio Quartulli
#8 lore raw

Ignore the last message - it was meant for another patch *shrug*

Quoted 194 lines · Antonio Quartulli

This is being discussed on Gerrit at:

https://gerrit.openvpn.net/c/openvpn/+/28

Quoted 188 lines · Antonio Quartulli

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

---
Changes from v1:
* beautify usage of buf with some helpers
* don't apply -1 to buffer capacity as fgets will already read one byte less than provided length and will add a null terminator there

Changes from v2:
* fix style of type returned by dco_version_string() (uncrustify doesn't work anymore on my box..due to incompatibler config)
---
  src/openvpn/dco.h         | 15 +++++++++++++++ src/openvpn/dco_freebsd.c |  6 ++++++ src/openvpn/dco_linux.c   | 27 +++++++++++++++++++++++++++

  src/openvpn/dco_win.c     |  6 ++++++
  src/openvpn/openvpn.c     |  2 ++
  src/openvpn/options.c     | 11 +++++++++++
  src/openvpn/options.h     |  2 ++
  7 files changed, 69 insertions(+)
src/openvpn/dco.h +6 -0
index 2fe671bf..96d95c21 100644
@@ -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
+ */

src/openvpn/dco.h +2 -0
+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

src/openvpn/dco.h +6 -0
@@ -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) {

src/openvpn/dco_freebsd.c +6 -0
index 92de5f04..cbd2ce20 100644
@@ -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) {

src/openvpn/dco_linux.c +27 -0
index 308abfc4..9f3531d5 100644
@@ -841,9 +841,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) {

src/openvpn/dco_win.c +6 -0
index a805c2a0..26463b38 100644
@@ -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)
  {

src/openvpn/openvpn.c +2 -0
index cba58276..1aaddcdf 100644
@@ -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);
src/openvpn/options.c +10 -0
index ce7bd0a7..8f0e2194 100644
@@ -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)
  {

src/openvpn/options.c +1 -0
@@ -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 <[email protected]...>");
   #ifndef ENABLE_SMALL
src/openvpn/options.h +2 -0
index 7df717f7..2f25f5d0 100644
@@ -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);
Signature · 1 line
Antonio Quartulli
Acked-by on v3 1/1
#9 lore raw
In reply to Antonio Quartulli

Am 09.03.23 um 14:14 schrieb Antonio Quartulli:

Quoted 22 lines

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

---
Changes from v1:
* beautify usage of buf with some helpers
* don't apply -1 to buffer capacity as fgets will already read one byte less than provided length and will add a null terminator there

Quoted 3 lines

Changes from v2:
* fix style of type returned by dco_version_string() (uncrustify doesn't work anymore on my box..due to incompatibler config)

any more, incompatible

src/openvpn/dco_linux.c dco_available(int msglevel) · line 853

Quoted 9 lines
      return true;

}

src/openvpn/dco_linux.c +6 -0
+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)

Note: this patch should only merged after "dco: don't use NetLink to exchange control packets" as it uses the same API version as that patch.

#10 lore raw
In reply to Antonio Quartulli

I briefly tested this on a system with the dco-v2 kernel module (and with the module unloaded). It did what I expected:

DCO version: 0.1.20230206-15-g580608e

or

DCO version: N/A

On FreeBSD 12 (no DCO), it does not print anything, on FreeBSD 14 it prints

DCO version: v0

(which will be addressed in a subsequent patch).

The code itself looks a bit overcomplicated, using a "struct buffer" with all the macros, just to have something for fgets() to fill... (it could use a on-stack char[] + capacity provided by the caller, getting rid of the gc in the process...) but it has an ACK, it works, and I want the FreeBSD version patch done...

Your patch has been applied to the master and release/2.6 branch.

commit 3da238e677b7801607e6777d9d23eb61e38034c2 (master) commit 9bd6fff74cf34892339fcab2fb3fc3cee54a2051 (release/2.6)

Author: Antonio Quartulli
Date:   Thu Mar 9 14:14:19 2023 +0100
     dco: print version to log if available

     Signed-off-by: Antonio Quartulli <[email protected]...>
     Acked-by: Arne Schwabe <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg26370.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering