From nobody Wed Dec 14 05:49:44 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 4NX4FN6GSrz4kvRj; Wed, 14 Dec 2022 05:49:44 +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 4NX4FN1xkKz3PTv; Wed, 14 Dec 2022 05:49:44 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1670996984; 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=rxte89bxops5C6Q2kHN2ZFCC3D6u/RWg7LYkKQf1c20=; b=kf+sReu2Suz1xr5Zx6p47cSjLG4ecRpWjNJWUAoQs4fQNOFpuw5QOnSjNjvIyT7qVhqCy+ BXo+2UqWdVeQCs4xcVz2x/mLDmnLlQQe4ravvXVX0wFwAeceyDir23GX0mpaDErFqe0cnR LoUUQxDDcarZB6udTMB1ppkL3uSTwDD2LAX80XLfhFuvQh4C0NBrGJdlVafI9qDGt05MDf 9JjLC8HwoX1isGUjuVP1dc41msbNKZ66YxQOLDkrDBGFPQkWSFLYYRIoWlX7lftzAojZOP HBq1FX7M8VLwWA+so5NKK87rKGfwkGrzFwoJJryosogT7FjvVmcqX/8aFeEAMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1670996984; 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=rxte89bxops5C6Q2kHN2ZFCC3D6u/RWg7LYkKQf1c20=; b=v3abnQHfkKGdt5Ncfa1gWQeGdWrH8+APGlfhR6iJBypdj7yW73ycFJ2mDSZEFucql/zO2o jsufDKrirQ1N6C1gM8XHPEbfUj7HCGZgc2rynAwztE75R/MNh8p/Nx2ej1axp9LmnnPuVX Kl1eJlMNkcmXL3YocCvAZ6tpj9+PsdLWgcbaOGQPenDfRYqgb0S92h+8hhEPkgHCkrTmA+ tgJAooC8jHCkVb9mvbetCRGPr2MJKplhEIhqXi0TPDXZg9gkmTOLZ9smFaVHQrhaIqHqLV Lolq6IBmnGF1NlNbIDmoUacsIl0g/dsXPdWTKZM9AU3HHm+sj8c1eFU7MejRwg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1670996984; a=rsa-sha256; cv=none; b=GqAMWB5yTlJOjrFelTChrfcmzZEcrkXiZ9UQnmTeYpQSXByPtadpc0lue6hfHfIhGwUf3i GlBPuvMr8jei4Ey6iWv7FwYbgxjqKikDLMl5J+y3LatQGetRb42nGQZcgS5xkSfqbY4/Z5 h2N8UGMbXd8RoDtkCZj0F/lppPaY6ZlhBNcevxo5W6v6QO2p1L0z3abjMjANm5+632DNea KhTzQzLo/29q2k8xPPp2Whbnq715XLPEvpXZrrKB7vYRpdGc7RkMMAhPE6gucDPJEt0nMc TgGN14pQDw2EFdqbrDCCVtxybjVIUQb3rugqxwYtZtZi6r3/jabXo+FNZyd0dQ== 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 4NX4FN0nDSzjgX; Wed, 14 Dec 2022 05:49:44 +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 2BE5niG1034632; Wed, 14 Dec 2022 05:49:44 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 2BE5niK0034631; Wed, 14 Dec 2022 05:49:44 GMT (envelope-from git) Date: Wed, 14 Dec 2022 05:49:44 GMT Message-Id: <202212140549.2BE5niK0034631@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: 8b630fa9ef6e - main - if_ovpn: implement OVPN_GET_PEER_STATS 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: 8b630fa9ef6e2eecc8425e62ea31194c4d0e410e Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=8b630fa9ef6e2eecc8425e62ea31194c4d0e410e commit 8b630fa9ef6e2eecc8425e62ea31194c4d0e410e Author: Kristof Provost AuthorDate: 2022-11-27 11:58:40 +0000 Commit: Kristof Provost CommitDate: 2022-12-14 05:48:58 +0000 if_ovpn: implement OVPN_GET_PEER_STATS Allow userspace to retrieve per-peer traffic stats. Sponsored by: Rubicon Communications, LLC ("Netgate") Differential Revision: https://reviews.freebsd.org/D37604 --- sys/net/if_ovpn.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ sys/net/if_ovpn.h | 1 + 2 files changed, 58 insertions(+) diff --git a/sys/net/if_ovpn.c b/sys/net/if_ovpn.c index 6686315fbf01..2cfe55568348 100644 --- a/sys/net/if_ovpn.c +++ b/sys/net/if_ovpn.c @@ -1212,6 +1212,60 @@ error: return (ret); } +static int +ovpn_get_peer_stats(struct ovpn_softc *sc, nvlist_t **nvl) +{ + struct ovpn_kpeer *peer; + nvlist_t *nvpeer = NULL; + int ret; + + OVPN_RLOCK_TRACKER; + + *nvl = nvlist_create(0); + if (*nvl == NULL) + return (ENOMEM); + +#define OVPN_PEER_COUNTER_OUT(name, in, out) \ + do { \ + ret = ovpn_add_counters(nvpeer, name, \ + peer->counters[offsetof(struct ovpn_peer_counters, in) / \ + sizeof(uint64_t)], \ + peer->counters[offsetof(struct ovpn_peer_counters, out) / \ + sizeof(uint64_t)]); \ + if (ret != 0) \ + goto error; \ + } while(0) + + OVPN_RLOCK(sc); + RB_FOREACH(peer, ovpn_kpeers, &sc->peers) { + nvpeer = nvlist_create(0); + if (nvpeer == NULL) { + OVPN_RUNLOCK(sc); + nvlist_destroy(*nvl); + *nvl = NULL; + return (ENOMEM); + } + + nvlist_add_number(nvpeer, "peerid", peer->peerid); + + OVPN_PEER_COUNTER_OUT("packets", pkt_in, pkt_out); + OVPN_PEER_COUNTER_OUT("bytes", bytes_in, bytes_out); + + nvlist_append_nvlist_array(*nvl, "peers", nvpeer); + nvlist_destroy(nvpeer); + } +#undef OVPN_PEER_COUNTER_OUT + OVPN_RUNLOCK(sc); + + return (0); + +error: + nvlist_destroy(nvpeer); + nvlist_destroy(*nvl); + *nvl = NULL; + return (ret); +} + static int ovpn_poll_pkt(struct ovpn_softc *sc, nvlist_t **onvl) { @@ -1266,6 +1320,9 @@ ovpn_ioctl_get(struct ifnet *ifp, struct ifdrv *ifd) case OVPN_GET_STATS: error = ovpn_get_stats(sc, &nvl); break; + case OVPN_GET_PEER_STATS: + error = ovpn_get_peer_stats(sc, &nvl); + break; case OVPN_POLL_PKT: error = ovpn_poll_pkt(sc, &nvl); break; diff --git a/sys/net/if_ovpn.h b/sys/net/if_ovpn.h index 5ea2ae6dd2ec..1c0299940c3e 100644 --- a/sys/net/if_ovpn.h +++ b/sys/net/if_ovpn.h @@ -66,5 +66,6 @@ enum ovpn_key_cipher { #define OVPN_POLL_PKT _IO ('D', 10) #define OVPN_GET_PKT _IO ('D', 11) #define OVPN_SET_IFMODE _IO ('D', 12) +#define OVPN_GET_PEER_STATS _IO ('D', 13) #endif