[Openvpn-devel,4/4] dco: cleanup FreeBSD dco_do_read()

Message ID 20221205164103.9190-5-kprovost@netgate.com
State Accepted
Headers show
Series [Openvpn-devel,1/4] Read DCO traffic stats from the kernel | expand

Commit Message

Kristof Provost Dec. 5, 2022, 4:41 p.m. UTC
From: Kristof Provost <kp@FreeBSD.org>

Remove support for reading packets through the control interface.
FreeBSD no longer does this, so there's no point in keeping the code for
it.

While here also check that we know what type of notification we're
getting. There's currently only one, but we should check anyway.

Signed-off-by: Kristof Provost <kprovost@netgate.com>
---
 src/openvpn/dco_freebsd.c | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)

Comments

Gert Doering Dec. 14, 2022, 10:28 p.m. UTC | #1
Acked-by: Gert Doering <gert@greenie.muc.de>

Tested on FreeBSD with/without DCO, client/server, all works as before.

The formatting of the switch/case bits was not what uncrustify wanted
to see, so I've adjusted this (only indenting).  This makes "git show"
a bit hard to read, but "git show -w" shows that most of the patch
is very straightforward.

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

commit 235161cd2bcd5403c807e66432c421114c896b74 (master)
commit 67e7846134bd8119737c3f80d958f401b5128cef (release/2.6)
Author: Kristof Provost
Date:   Mon Dec 5 17:41:03 2022 +0100

     dco: cleanup FreeBSD dco_do_read()

     Signed-off-by: Kristof Provost <kprovost@netgate.com>
     Acked-by: Gert Doering <gert@greenie.muc.de>
     Message-Id: <20221205164103.9190-5-kprovost@netgate.com>
     URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25616.html
     Signed-off-by: Gert Doering <gert@greenie.muc.de>


--
kind regards,

Gert Doering

Patch

diff --git a/src/openvpn/dco_freebsd.c b/src/openvpn/dco_freebsd.c
index 8d7ceb70..b6d869b0 100644
--- a/src/openvpn/dco_freebsd.c
+++ b/src/openvpn/dco_freebsd.c
@@ -489,8 +489,7 @@  dco_do_read(dco_context_t *dco)
     struct ifdrv drv;
     uint8_t buf[4096];
     nvlist_t *nvl;
-    const uint8_t *pkt;
-    size_t pktlen;
+    enum ovpn_notif_type type;
     int ret;
 
     /* Flush any pending data from the pipe. */
@@ -518,15 +517,9 @@  dco_do_read(dco_context_t *dco)
 
     dco->dco_message_peer_id = nvlist_get_number(nvl, "peerid");
 
-    if (nvlist_exists_binary(nvl, "packet"))
-    {
-        pkt = nvlist_get_binary(nvl, "packet", &pktlen);
-        memcpy(BPTR(&dco->dco_packet_in), pkt, pktlen);
-        dco->dco_packet_in.len = pktlen;
-        dco->dco_message_type = OVPN_CMD_PACKET;
-    }
-    else
-    {
+    type = nvlist_get_number(nvl, "notification");
+    switch (type) {
+    case OVPN_NOTIF_DEL_PEER:
         dco->dco_del_peer_reason = OVPN_DEL_PEER_REASON_EXPIRED;
 
         if (nvlist_exists_number(nvl, "del_reason"))
@@ -551,6 +544,10 @@  dco_do_read(dco_context_t *dco)
         }
 
         dco->dco_message_type = OVPN_CMD_DEL_PEER;
+        break;
+    default:
+        msg(M_WARN, "Unknown kernel notification %d", type);
+        break;
     }
 
     nvlist_destroy(nvl);