]> git.ipfire.org Git - thirdparty/openvpn.git/commitdiff
dco: cleanup FreeBSD dco_do_read()
authorKristof Provost <kp@FreeBSD.org>
Mon, 5 Dec 2022 16:41:03 +0000 (17:41 +0100)
committerGert Doering <gert@greenie.muc.de>
Wed, 14 Dec 2022 22:02:45 +0000 (23:02 +0100)
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>
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>
(cherry picked from commit 235161cd2bcd5403c807e66432c421114c896b74)

src/openvpn/dco_freebsd.c

index d7e373d7650373789ba3ee896e53b2f8ea00e2ca..550a13a8bdb0d6fe9c266ce22bfe48156ce1a396 100644 (file)
@@ -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,39 +517,39 @@ dco_do_read(dco_context_t *dco)
 
     dco->dco_message_peer_id = nvlist_get_number(nvl, "peerid");
 
-    if (nvlist_exists_binary(nvl, "packet"))
+    type = nvlist_get_number(nvl, "notification");
+    switch (type)
     {
-        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
-    {
-        dco->dco_del_peer_reason = OVPN_DEL_PEER_REASON_EXPIRED;
+        case OVPN_NOTIF_DEL_PEER:
+            dco->dco_del_peer_reason = OVPN_DEL_PEER_REASON_EXPIRED;
 
-        if (nvlist_exists_number(nvl, "del_reason"))
-        {
-            uint32_t reason = nvlist_get_number(nvl, "del_reason");
-            if (reason == OVPN_DEL_REASON_TIMEOUT)
+            if (nvlist_exists_number(nvl, "del_reason"))
             {
-                dco->dco_del_peer_reason = OVPN_DEL_PEER_REASON_EXPIRED;
+                uint32_t reason = nvlist_get_number(nvl, "del_reason");
+                if (reason == OVPN_DEL_REASON_TIMEOUT)
+                {
+                    dco->dco_del_peer_reason = OVPN_DEL_PEER_REASON_EXPIRED;
+                }
+                else
+                {
+                    dco->dco_del_peer_reason = OVPN_DEL_PEER_REASON_USERSPACE;
+                }
             }
-            else
+
+            if (nvlist_exists_nvlist(nvl, "bytes"))
             {
-                dco->dco_del_peer_reason = OVPN_DEL_PEER_REASON_USERSPACE;
-            }
-        }
+                const nvlist_t *bytes = nvlist_get_nvlist(nvl, "bytes");
 
-        if (nvlist_exists_nvlist(nvl, "bytes"))
-        {
-            const nvlist_t *bytes = nvlist_get_nvlist(nvl, "bytes");
+                dco->dco_read_bytes = nvlist_get_number(bytes, "in");
+                dco->dco_write_bytes = nvlist_get_number(bytes, "out");
+            }
 
-            dco->dco_read_bytes = nvlist_get_number(bytes, "in");
-            dco->dco_write_bytes = nvlist_get_number(bytes, "out");
-        }
+            dco->dco_message_type = OVPN_CMD_DEL_PEER;
+            break;
 
-        dco->dco_message_type = OVPN_CMD_DEL_PEER;
+        default:
+            msg(M_WARN, "Unknown kernel notification %d", type);
+            break;
     }
 
     nvlist_destroy(nvl);