Skip to content

Commit

Permalink
Read the peer deletion reason from the kernel
Browse files Browse the repository at this point in the history
Recent FreeBSD kernels supply a reason for the OVPN_NOTIF_DEL_PEER
notification. Parse this from the nvlist so we can distinguish
user-requested removals from timeouts.

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]/msg25617.html
Signed-off-by: Gert Doering <[email protected]>
  • Loading branch information
kprovost authored and cron2 committed Dec 14, 2022
1 parent 6674963 commit 10ea190
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/openvpn/dco_freebsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,19 @@ dco_do_read(dco_context_t *dco)
{
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)
{
dco->dco_del_peer_reason = OVPN_DEL_PEER_REASON_EXPIRED;
}
else
{
dco->dco_del_peer_reason = OVPN_DEL_PEER_REASON_USERSPACE;
}
}

if (nvlist_exists_nvlist(nvl, "bytes"))
{
const nvlist_t *bytes = nvlist_get_nvlist(nvl, "bytes");
Expand Down
5 changes: 5 additions & 0 deletions src/openvpn/ovpn_dco_freebsd.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ enum ovpn_notif_type {
OVPN_NOTIF_DEL_PEER,
};

enum ovpn_del_reason {
OVPN_DEL_REASON_REQUESTED = 0,
OVPN_DEL_REASON_TIMEOUT = 1
};

enum ovpn_key_slot {
OVPN_KEY_SLOT_PRIMARY = 0,
OVPN_KEY_SLOT_SECONDARY = 1
Expand Down

0 comments on commit 10ea190

Please sign in to comment.