From 235161cd2bcd5403c807e66432c421114c896b74 Mon Sep 17 00:00:00 2001 From: Kristof Provost Date: Mon, 5 Dec 2022 17:41:03 +0100 Subject: [PATCH] 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 Acked-by: Gert Doering 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 --- src/openvpn/dco_freebsd.c | 53 +++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 27 deletions(-) diff --git a/src/openvpn/dco_freebsd.c b/src/openvpn/dco_freebsd.c index d7e373d7650..550a13a8bdb 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,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);