Browse code

dco: cleanup FreeBSD dco_do_read()

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)

Kristof Provost authored on 2022/12/06 01:41:03
Showing 1 changed files
... ...
@@ -489,8 +489,7 @@ dco_do_read(dco_context_t *dco)
489 489
     struct ifdrv drv;
490 490
     uint8_t buf[4096];
491 491
     nvlist_t *nvl;
492
-    const uint8_t *pkt;
493
-    size_t pktlen;
492
+    enum ovpn_notif_type type;
494 493
     int ret;
495 494
 
496 495
     /* Flush any pending data from the pipe. */
... ...
@@ -518,39 +517,39 @@ dco_do_read(dco_context_t *dco)
518 518
 
519 519
     dco->dco_message_peer_id = nvlist_get_number(nvl, "peerid");
520 520
 
521
-    if (nvlist_exists_binary(nvl, "packet"))
521
+    type = nvlist_get_number(nvl, "notification");
522
+    switch (type)
522 523
     {
523
-        pkt = nvlist_get_binary(nvl, "packet", &pktlen);
524
-        memcpy(BPTR(&dco->dco_packet_in), pkt, pktlen);
525
-        dco->dco_packet_in.len = pktlen;
526
-        dco->dco_message_type = OVPN_CMD_PACKET;
527
-    }
528
-    else
529
-    {
530
-        dco->dco_del_peer_reason = OVPN_DEL_PEER_REASON_EXPIRED;
524
+        case OVPN_NOTIF_DEL_PEER:
525
+            dco->dco_del_peer_reason = OVPN_DEL_PEER_REASON_EXPIRED;
531 526
 
532
-        if (nvlist_exists_number(nvl, "del_reason"))
533
-        {
534
-            uint32_t reason = nvlist_get_number(nvl, "del_reason");
535
-            if (reason == OVPN_DEL_REASON_TIMEOUT)
527
+            if (nvlist_exists_number(nvl, "del_reason"))
536 528
             {
537
-                dco->dco_del_peer_reason = OVPN_DEL_PEER_REASON_EXPIRED;
529
+                uint32_t reason = nvlist_get_number(nvl, "del_reason");
530
+                if (reason == OVPN_DEL_REASON_TIMEOUT)
531
+                {
532
+                    dco->dco_del_peer_reason = OVPN_DEL_PEER_REASON_EXPIRED;
533
+                }
534
+                else
535
+                {
536
+                    dco->dco_del_peer_reason = OVPN_DEL_PEER_REASON_USERSPACE;
537
+                }
538 538
             }
539
-            else
539
+
540
+            if (nvlist_exists_nvlist(nvl, "bytes"))
540 541
             {
541
-                dco->dco_del_peer_reason = OVPN_DEL_PEER_REASON_USERSPACE;
542
-            }
543
-        }
542
+                const nvlist_t *bytes = nvlist_get_nvlist(nvl, "bytes");
544 543
 
545
-        if (nvlist_exists_nvlist(nvl, "bytes"))
546
-        {
547
-            const nvlist_t *bytes = nvlist_get_nvlist(nvl, "bytes");
544
+                dco->dco_read_bytes = nvlist_get_number(bytes, "in");
545
+                dco->dco_write_bytes = nvlist_get_number(bytes, "out");
546
+            }
548 547
 
549
-            dco->dco_read_bytes = nvlist_get_number(bytes, "in");
550
-            dco->dco_write_bytes = nvlist_get_number(bytes, "out");
551
-        }
548
+            dco->dco_message_type = OVPN_CMD_DEL_PEER;
549
+            break;
552 550
 
553
-        dco->dco_message_type = OVPN_CMD_DEL_PEER;
551
+        default:
552
+            msg(M_WARN, "Unknown kernel notification %d", type);
553
+            break;
554 554
     }
555 555
 
556 556
     nvlist_destroy(nvl);