From nobody Mon Dec 05 10:29:50 2022 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4NQftl0NhMz4jKL5; Mon, 5 Dec 2022 10:29:51 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4NQftk70Rkz4YLs; Mon, 5 Dec 2022 10:29:50 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1670236191; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Y0rgo2Sd126/nAxxy3rRwtiIncnAvaHmdiiqXFX/uhk=; b=MGwEANP+yA21FBenQhMjfxbzgPXDN+XbpoiIn+zKBfSW9mzCf5enoAPZF0Wftr87un+uQN 3/1Hs/s0gHBkMRqSnV1pFT1AwNbhJKhsZNSMLDQ581qorIIxzFK7iRR8LLC5zT0nusjEfX +dQEnQ9vzSEl44HRWdrda3GJ7R4+EtkvBi8HU07P56PaxSEImjI+9h/N4mdLR3Mc1wpTBy dwwGB1LRnQDLNM1zeB0S1Z1GraA/ukWGk8i4dZKT5hd6SrR8trtX045K5DK26EpilqIf6f 0wlG9umTZja9ES+0NaqnU+ALqrHv2/vHRguhv4cXrSqBpD7fELfF9OfmYsYU3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1670236191; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Y0rgo2Sd126/nAxxy3rRwtiIncnAvaHmdiiqXFX/uhk=; b=lIRna3lkcGo9agTZc+BAV05otcL7YHheRDF+ckI8QpPyNDe2BIc1wxxCGP4qo1rL920OU7 pRNov9UKU8xDm66gIgWJdHXQzMQO1OXzB881/cHhhtFlC5nOh6MDAzRtLQHnCJheya8Gji r2EZWot35SDX9iueYXErnrvO/LPNNerkg8z1MhUIQfb+WnXCthrYqNjR0kyB9jXoX1pvcI ZZrrXzoGklbp6QhMpCY+hKJoeoy4C2eo7JOEBcP9G8WzCebCq6GGzcBN86Ad+OcUYHSmCl dOg8tHu+IZQFUGxM6HcGUpc/U+3RI0fDy89jjjVJ3GYBcUwxjs/KGoTdXjBCxw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1670236191; a=rsa-sha256; cv=none; b=nZ+os388NzBL4b7WoywqIYZWtYXl0IrFb7O+wnY/hzlScoqZFUPkVbNvydtiDhuQn1n9Qr DIn449AzxYi+8NaSG+jE3qDFrqZpHrEpJ2yMhizHa4XhrQQqB6xQnzCudpB2ArZF+nj55J KqOrRmjwF2JQ+F1sJOlh2udKCQZrcOVLCqzNvqCMol7870FCK3utyHrO/B7gQf+r8jYSID JJ9MOVpMU1kNODpndlMDCz3OxpVVPzqAegg8wSH+avUC/k71YCi0VNEuckH/wkF4KkGgIz nq2GM5GzHX4sS7sT+CLgrrTLkexgiullIWqywFccVlV4E30g7Vlv7Bl4b22i1A== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4NQftk639kzttL; Mon, 5 Dec 2022 10:29:50 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 2B5AToAE013122; Mon, 5 Dec 2022 10:29:50 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 2B5AToul013120; Mon, 5 Dec 2022 10:29:50 GMT (envelope-from git) Date: Mon, 5 Dec 2022 10:29:50 GMT Message-Id: <202212051029.2B5AToul013120@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kristof Provost Subject: git: da69782bf066 - main - if_ovpn: extend notifications with a reason List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: da69782bf06645f38852a8b23afc965fc30d0e08 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=da69782bf06645f38852a8b23afc965fc30d0e08 commit da69782bf06645f38852a8b23afc965fc30d0e08 Author: Kristof Provost AuthorDate: 2022-12-01 15:20:24 +0000 Commit: Kristof Provost CommitDate: 2022-12-05 10:09:34 +0000 if_ovpn: extend notifications with a reason Extend peer deleted notifications (which are the only type right now) to include the reason the peer was deleted. This can be either because userspace requested it, or because the peer timed out. Reviewed by: zlei Sponsored by: Rubicon Communications, LLC ("Netgate") Differential Revision: https://reviews.freebsd.org/D37583 --- sys/net/if_ovpn.c | 35 ++++++++++++++++++++++++----------- sys/net/if_ovpn.h | 5 +++++ 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/sys/net/if_ovpn.c b/sys/net/if_ovpn.c index b8322558e0f1..0f326512b236 100644 --- a/sys/net/if_ovpn.c +++ b/sys/net/if_ovpn.c @@ -116,6 +116,7 @@ struct ovpn_wire_header { struct ovpn_notification { enum ovpn_notif_type type; + enum ovpn_del_reason del_reason; uint32_t peerid; }; @@ -136,6 +137,7 @@ struct ovpn_kpeer { struct ovpn_kkey keys[2]; uint32_t tx_seq; + enum ovpn_del_reason del_reason; struct ovpn_keepalive keepalive; uint32_t *last_active; struct callout ping_send; @@ -388,6 +390,7 @@ ovpn_notify_del_peer(struct ovpn_softc *sc, struct ovpn_kpeer *peer) n->peerid = peer->peerid; n->type = OVPN_NOTIF_DEL_PEER; + n->del_reason = peer->del_reason; if (buf_ring_enqueue(sc->notifring, n) != 0) { free(n, M_OVPN); } else if (sc->so != NULL) { @@ -613,18 +616,17 @@ done: } static int -_ovpn_del_peer(struct ovpn_softc *sc, uint32_t peerid) +_ovpn_del_peer(struct ovpn_softc *sc, struct ovpn_kpeer *peer) { - struct ovpn_kpeer *peer; + struct ovpn_kpeer *tmp __diagused; OVPN_WASSERT(sc); CURVNET_ASSERT_SET(); - peer = ovpn_find_peer(sc, peerid); - if (peer == NULL) - return (ENOENT); - peer = RB_REMOVE(ovpn_kpeers, &sc->peers, peer); - MPASS(peer != NULL); + MPASS(RB_FIND(ovpn_kpeers, &sc->peers, peer) == peer); + + tmp = RB_REMOVE(ovpn_kpeers, &sc->peers, peer); + MPASS(tmp != NULL); sc->peercount--; @@ -637,6 +639,7 @@ static int ovpn_del_peer(struct ifnet *ifp, nvlist_t *nvl) { struct ovpn_softc *sc = ifp->if_softc; + struct ovpn_kpeer *peer; uint32_t peerid; int ret; @@ -650,7 +653,12 @@ ovpn_del_peer(struct ifnet *ifp, nvlist_t *nvl) peerid = nvlist_get_number(nvl, "peerid"); - ret = _ovpn_del_peer(sc, peerid); + peer = ovpn_find_peer(sc, peerid); + if (peer == NULL) + return (ENOENT); + + peer->del_reason = OVPN_DEL_REASON_REQUESTED; + ret = _ovpn_del_peer(sc, peer); return (ret); } @@ -1032,7 +1040,8 @@ ovpn_timeout(void *arg) } CURVNET_SET(sc->ifp->if_vnet); - ret = _ovpn_del_peer(sc, peer->peerid); + peer->del_reason = OVPN_DEL_REASON_TIMEOUT; + ret = _ovpn_del_peer(sc, peer); MPASS(ret == 0); CURVNET_RESTORE(); } @@ -1274,6 +1283,8 @@ opvn_get_pkt(struct ovpn_softc *sc, nvlist_t **onvl) } nvlist_add_number(nvl, "peerid", n->peerid); nvlist_add_number(nvl, "notification", n->type); + if (n->type == OVPN_NOTIF_DEL_PEER) + nvlist_add_number(nvl, "del_reason", n->del_reason); free(n, M_OVPN); *onvl = nvl; @@ -2259,7 +2270,8 @@ ovpn_reassign(struct ifnet *ifp, struct vnet *new_vnet __unused, /* Flush keys & configuration. */ RB_FOREACH_SAFE(peer, ovpn_kpeers, &sc->peers, tmppeer) { - ret = _ovpn_del_peer(sc, peer->peerid); + peer->del_reason = OVPN_DEL_REASON_REQUESTED; + ret = _ovpn_del_peer(sc, peer); MPASS(ret == 0); } @@ -2386,7 +2398,8 @@ ovpn_clone_destroy(struct if_clone *ifc, struct ifnet *ifp, uint32_t flags) } RB_FOREACH_SAFE(peer, ovpn_kpeers, &sc->peers, tmppeer) { - ret = _ovpn_del_peer(sc, peer->peerid); + peer->del_reason = OVPN_DEL_REASON_REQUESTED; + ret = _ovpn_del_peer(sc, peer); MPASS(ret == 0); } diff --git a/sys/net/if_ovpn.h b/sys/net/if_ovpn.h index fd1c21e70435..3db36f5b0539 100644 --- a/sys/net/if_ovpn.h +++ b/sys/net/if_ovpn.h @@ -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