From nobody Wed Dec 14 05:49:46 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 4NX4FQ4dpNz4kvfy; Wed, 14 Dec 2022 05:49:46 +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 4NX4FQ3mLTz3PYk; Wed, 14 Dec 2022 05:49:46 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1670996986; 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=0gVUlnVZSKi25uq/05vH0+qzPdj1HRQ2huhufytdZvk=; b=hxo3LlCV1rFUztj27wkJ7UBRHdKNtxOvpB4gneNyMIE3jl+sW1Pf7Sst1XYnG+UwiUbQew 03tJ2SQ65fJ28WM8/u8/izsSDop2flRrD2Nl+tDSSyS2oPgOgG38QiBgmZ4fF+jlBOQ4eX EdLQ8rgDJ0wrHTn05qeiLQIol14YLNyEoT6CGzO/UX57ahwROFusN6kuUHi/3rKUHL8dcQ mzdH4g/ZMSYS87O4FwY5PBhib77tI4pwB0S5NUGxGoxoWVYXiqefktnrLEnNoPLGRE4Yas Ay/k14JUociqgXDIKF4/Vc4JDpD8tmH6VhblmApJFiurxU0csRkT4DzCYV9m0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1670996986; 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=0gVUlnVZSKi25uq/05vH0+qzPdj1HRQ2huhufytdZvk=; b=Ge6TpCyDOxgCpxlnHF/Ls29w2nKcH3dlmSotfMGxacgIe+IIUGCyr1m5SYX9AaQs6TgVyF gI17zgm0GG8pTEBXif7vzXv3hi7To6Lo+0V9uW3WBdJC4tzvbKWA4K4arAkGQKEIQ8+DOM rNBrBNqFbOxwiL++2lT5J5m6IsxT3bpPZ2mmvhCpUR23WShoEnxtPvMDvr245q++oZxP/w dHBa+H3S3UK+SQeWHulRJmetU+MZyxD5/BI8b3yxCSO8Bt594v/XoJIM3ZCQplH00HMdH7 fdlats1jymSlpVCERR/SOBYLn0aDYMVc1vcaljwF0X/54hqMZLcuxIluFJ5wNQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1670996986; a=rsa-sha256; cv=none; b=UhXciaLrdHMpXAbLHyOZ2Df+xg0VODSwd43/pejFUnhwr3hkgG5pa1M5ibqZhRBf2GOPZU paKakssWR1phM5RIWGY3d18OcAjkWb8Cbv/V+dJQZnqD66/iB7Scx6LjDQ/PgxSBB2JM+H dY1FE5Ng1ZCc9oU2/bY5W9nxl+KwxVPk6k9gKzn9JhykGq5L9uoaoD/WGA3WpN/GEjolMY yx/9uioGicyr/9c/8hwF/rcbCiARlZWZoCGkVKT5VrKggChMI5EbaU/A8WbN1vPm0n30hA uY7Ba4ItxsTwFBz/I31QKTXJMNF5YDWzkycKNpVbNY6oUDeHzRCDlQNcByDNpQ== 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 4NX4FQ2t5dzjY1; Wed, 14 Dec 2022 05:49:46 +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 2BE5nk6D034688; Wed, 14 Dec 2022 05:49:46 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 2BE5nkk6034687; Wed, 14 Dec 2022 05:49:46 GMT (envelope-from git) Date: Wed, 14 Dec 2022 05:49:46 GMT Message-Id: <202212140549.2BE5nkk6034687@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: c357bf397f2e - main - if_ovpn: include peer counters in a OVPN_NOTIF_DEL_PEER message 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: c357bf397f2eff67a70d4e4f6c472381eb10416c Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=c357bf397f2eff67a70d4e4f6c472381eb10416c commit c357bf397f2eff67a70d4e4f6c472381eb10416c Author: Kristof Provost AuthorDate: 2022-12-02 15:59:38 +0000 Commit: Kristof Provost CommitDate: 2022-12-14 05:48:59 +0000 if_ovpn: include peer counters in a OVPN_NOTIF_DEL_PEER message When we remove a peer userspace can no longer retrieve its counters. To ensure that userspace can get a full count of the entire session we now include the counters in the deletion message. Sponsored by: Rubicon Communications, LLC ("Netgate") Differential Revision: https://reviews.freebsd.org/D37606 --- sys/net/if_ovpn.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 53 insertions(+), 9 deletions(-) diff --git a/sys/net/if_ovpn.c b/sys/net/if_ovpn.c index cf5f2cc6fcf6..a11dd0b4a6cb 100644 --- a/sys/net/if_ovpn.c +++ b/sys/net/if_ovpn.c @@ -114,14 +114,6 @@ struct ovpn_wire_header { uint8_t auth_tag[16]; }; -struct ovpn_notification { - enum ovpn_notif_type type; - enum ovpn_del_reason del_reason; - uint32_t peerid; -}; - -struct ovpn_softc; - struct ovpn_peer_counters { uint64_t pkt_in; uint64_t pkt_out; @@ -130,6 +122,17 @@ struct ovpn_peer_counters { }; #define OVPN_PEER_COUNTER_SIZE (sizeof(struct ovpn_peer_counters)/sizeof(uint64_t)) +struct ovpn_notification { + enum ovpn_notif_type type; + uint32_t peerid; + + /* Delete notification */ + enum ovpn_del_reason del_reason; + struct ovpn_peer_counters counters; +}; + +struct ovpn_softc; + struct ovpn_kpeer { RB_ENTRY(ovpn_kpeer) tree; int refcount; @@ -438,6 +441,16 @@ 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; + + n->counters.pkt_in = counter_u64_fetch(peer->counters[offsetof( + struct ovpn_peer_counters, pkt_in)/sizeof(uint64_t)]); + n->counters.pkt_out = counter_u64_fetch(peer->counters[offsetof( + struct ovpn_peer_counters, pkt_out)/sizeof(uint64_t)]); + n->counters.bytes_in = counter_u64_fetch(peer->counters[offsetof( + struct ovpn_peer_counters, bytes_in)/sizeof(uint64_t)]); + n->counters.bytes_out = counter_u64_fetch(peer->counters[offsetof( + struct ovpn_peer_counters, bytes_out)/sizeof(uint64_t)]); + if (buf_ring_enqueue(sc->notifring, n) != 0) { free(n, M_OVPN); } else if (sc->so != NULL) { @@ -1335,6 +1348,32 @@ ovpn_poll_pkt(struct ovpn_softc *sc, nvlist_t **onvl) return (0); } +static void +ovpn_notif_add_counters(nvlist_t *parent, struct ovpn_notification *n) +{ + nvlist_t *nvl; + + nvl = nvlist_create(0); + if (nvl == NULL) + return; + + nvlist_add_number(nvl, "in", n->counters.pkt_in); + nvlist_add_number(nvl, "out", n->counters.pkt_out); + + nvlist_add_nvlist(parent, "packets", nvl); + nvlist_destroy(nvl); + + nvl = nvlist_create(0); + if (nvl == NULL) + return; + + nvlist_add_number(nvl, "in", n->counters.bytes_in); + nvlist_add_number(nvl, "out", n->counters.bytes_out); + + nvlist_add_nvlist(parent, "bytes", nvl); + nvlist_destroy(nvl); +} + static int opvn_get_pkt(struct ovpn_softc *sc, nvlist_t **onvl) { @@ -1353,8 +1392,13 @@ 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) + if (n->type == OVPN_NOTIF_DEL_PEER) { nvlist_add_number(nvl, "del_reason", n->del_reason); + + /* No error handling, because we want to send the notification + * even if we can't attach the counters. */ + ovpn_notif_add_counters(nvl, n); + } free(n, M_OVPN); *onvl = nvl;