Skip to contentSkip to conversation

dco: print FreeBSD version

PATCH In review Kristof Provost 3 participants 4 messages Mar 9, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dco: print FreeBSD version

From: Kristof Provost <[email protected]...>

Implement dco_version_string() for FreeBSD.
Unlike Linux and Windows the DCO driver is built into the operating system itself, so we log the OS version as a proxy for the DCO version.

---
 src/openvpn/dco_freebsd.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
src/openvpn/dco_freebsd.c +13 -1
index 2b94b2a2..a5e96bb2 100644
@@ -31,6 +31,8 @@
 #include <sys/param.h>
 #include <sys/linker.h>
 #include <sys/nv.h>
+#include <sys/utsname.h>
+
 #include <netinet/in.h>
 
 #include "dco_freebsd.h"
@@ -627,7 +629,17 @@ out:
 const char *
 dco_version_string(struct gc_arena *gc)
 {
-    return "v0";
+    struct utsname name;
+    struct buffer out = alloc_buf_gc(256, gc);
+    int ret;
+
+    ret = uname(&name);
+    if (ret != 0)
+        return "N/A";
+
+    buf_printf(&out, "%s", name.version);
+
+    return (char *)out.data;
 }
 
 void
Signature · 1 line
2.39.2
#1 lore raw

Am 09.03.23 um 10:26 schrieb Kristof Provost via Openvpn-devel:

Quoted 24 lines

From: Kristof Provost <[email protected]...>

Implement dco_version_string() for FreeBSD.
Unlike Linux and Windows the DCO driver is built into the operating system itself, so we log the OS version as a proxy for the DCO version.

---
  src/openvpn/dco_freebsd.c | 14 +++++++++++++-
  1 file changed, 13 insertions(+), 1 deletion(-)
src/openvpn/dco_freebsd.c +2 -0
index 2b94b2a2..a5e96bb2 100644
@@ -31,6 +31,8 @@
  #include <sys/param.h>
  #include <sys/linker.h>
  #include <sys/nv.h>
+#include <sys/utsname.h>
+
  #include <netinet/in.h>
 
  #include "dco_freebsd.h"
@@ -627,7 +629,17 @@ out:
  const char *

src/openvpn/dco_freebsd.c out: · line 638

Quoted 10 lines
src/openvpn/dco_freebsd.c +7 -1
  dco_version_string(struct gc_arena *gc)
  {
-    return "v0";
+    struct utsname name;
+    struct buffer out = alloc_buf_gc(256, gc);
+    int ret;
+
+    ret = uname(&name);
+    if (ret != 0)
+        return "N/A";

There should be { around the return

src/openvpn/dco_freebsd.c out: · line 642

Quoted 4 lines
src/openvpn/dco_freebsd.c +4 -0
+
+    buf_printf(&out, "%s", name.version);
+
+    return (char *)out.data;

This should use BSTR(data) instead. Instead of copying/printf, you could also just do:

    struct utsname* uts;
    ALLOC_OBJ_GC(uts, struct utsname, gc);


    if (uname(&name) != 0)
    {
        return "N/A";
    }

    return uts->name;

Arne

#2 lore raw
Quoted 28 lines · Arne Schwabe

Am 09.03.23 um 10:26 schrieb Kristof Provost via Openvpn-devel:

Quoted 27 lines

From: Kristof Provost <[email protected]...>

Implement dco_version_string() for FreeBSD.
Unlike Linux and Windows the DCO driver is built into the operating system itself, so we log the OS version as a proxy for the DCO version.

---
  src/openvpn/dco_freebsd.c | 14 +++++++++++++-
  1 file changed, 13 insertions(+), 1 deletion(-)
src/openvpn/dco_freebsd.c +3 -1
index 2b94b2a2..a5e96bb2 100644
@@ -31,6 +31,8 @@
  #include <sys/param.h>
  #include <sys/linker.h>
  #include <sys/nv.h>
+#include <sys/utsname.h>
+
  #include <netinet/in.h>
   #include "dco_freebsd.h"
@@ -627,7 +629,17 @@ out:
  const char *
  dco_version_string(struct gc_arena *gc)
  {
-    return "v0";
+    struct utsname name;
Quoted 8 lines

src/openvpn/dco_freebsd.c out: · line 638

Quoted 6 lines
src/openvpn/dco_freebsd.c +6 -0
+    struct buffer out = alloc_buf_gc(256, gc);
+    int ret;
+
+    ret = uname(&name);
+    if (ret != 0)
+        return "N/A";

There should be { around the return

I’ll fix that.

Quoted 7 lines

src/openvpn/dco_freebsd.c out: · line 642

Quoted 4 lines
src/openvpn/dco_freebsd.c +4 -0
+
+    buf_printf(&out, "%s", name.version);
+
+    return (char *)out.data;

This should use BSTR(data) instead.

I copied Antonio’s code here, but that is better, so I’ll fix that too.

Quoted 13 lines

Instead of copying/printf, you could also just do:

    struct utsname* uts;
    ALLOC_OBJ_GC(uts, struct utsname, gc);


    if (uname(&name) != 0)
    {
        return "N/A";
    }

    return uts->name;

I was going to object that we can’t return stack variables, but that’s an allocation of utsname, and it removes an intermediate step, so yeah, that’s better too (and means I can just copy your code, call it my own and pretend I did work ;))

Thanks.
Kristof

#3 lore raw

Hi,

Quoted 4 lines · Kristof Provost via Openvpn-devel
Quoted 2 lines

This should use BSTR(data) instead.

I copied Antonio’s code here, but that is better, so I’ll fix that too.

dang! with one email Arne spoiled two patches!

Cheers,

Signature · 1 line
Antonio Quartulli