Browse code

Read the peer deletion reason from the kernel

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 <kprovost@netgate.com>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20221205164103.9190-4-kprovost@netgate.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25617.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit 10ea19092ded38ff25a445f987ad948aa9eac49f)

Kristof Provost authored on 2022/12/06 01:41:02
Showing 2 changed files
... ...
@@ -529,6 +529,19 @@ dco_do_read(dco_context_t *dco)
529 529
     {
530 530
         dco->dco_del_peer_reason = OVPN_DEL_PEER_REASON_EXPIRED;
531 531
 
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)
536
+            {
537
+                dco->dco_del_peer_reason = OVPN_DEL_PEER_REASON_EXPIRED;
538
+            }
539
+            else
540
+            {
541
+                dco->dco_del_peer_reason = OVPN_DEL_PEER_REASON_USERSPACE;
542
+            }
543
+        }
544
+
532 545
         if (nvlist_exists_nvlist(nvl, "bytes"))
533 546
         {
534 547
             const nvlist_t *bytes = nvlist_get_nvlist(nvl, "bytes");
... ...
@@ -38,6 +38,11 @@ enum ovpn_notif_type {
38 38
     OVPN_NOTIF_DEL_PEER,
39 39
 };
40 40
 
41
+enum ovpn_del_reason {
42
+    OVPN_DEL_REASON_REQUESTED       = 0,
43
+    OVPN_DEL_REASON_TIMEOUT         = 1
44
+};
45
+
41 46
 enum ovpn_key_slot {
42 47
     OVPN_KEY_SLOT_PRIMARY   = 0,
43 48
     OVPN_KEY_SLOT_SECONDARY = 1