Skip to content

Commit

Permalink
dco: cleanup FreeBSD dco_do_read()
Browse files Browse the repository at this point in the history
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 <[email protected]>
Acked-by: Gert Doering <[email protected]>
Message-Id: <[email protected]>
URL: https://www.mail-archive.com/[email protected]/msg25616.html
Signed-off-by: Gert Doering <[email protected]>
  • Loading branch information
kprovost authored and cron2 committed Dec 14, 2022
1 parent 6dbf835 commit 235161c
Showing 1 changed file with 26 additions and 27 deletions.
53 changes: 26 additions & 27 deletions src/openvpn/dco_freebsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 235161c

Please sign in to comment.