From nobody Wed Dec 14 05:49:42 2022 X-Original-To: dev-commits-src-all@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 4NX4FM25gdz4kvfg; Wed, 14 Dec 2022 05:49:43 +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 4NX4FM1Kh7z3PHK; Wed, 14 Dec 2022 05:49:43 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1670996983; 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=X+QJJiHN38r1g8FTk44eq2y2cBpQjT1Pxv+tn2dmBkQ=; b=nbKLbCvDMhuIDGQuCIM7C0IAYv3r782t3/VRHDIis7SJcanAopFfmgncwaVempD2LcNG7h lIYMh6d4/EwpIOS9WZort9bfZtMq4gebYO+nokNsve/Y+2D1pKCzjJQ+qRD8N6QbV0JFwh eDfSOyF5zLGSh7b4B2aK1NiY3LQeIyyEun+kOhYDrUvrjHT2s2rQ9z/rJ3dD17D7GzEXE6 ocxapUcwfiiOhthty+UIV8lBPiS6/fr8IoAS4ipQdDsLD86kccaqTec5YkE9Nb6DAct4Mi F+hMJ0Dm515YAxfkmdVf0Swg9vFRZ3b/sg30sbDcGCtrNCkA/8VGcz+Rk6FHzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1670996983; 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=X+QJJiHN38r1g8FTk44eq2y2cBpQjT1Pxv+tn2dmBkQ=; b=tXeFymNh9cvNGXwRAvdZqgHJ11WZNOGhPOwRWVQhhP0QgEux7s8E0vmJ/usaR4AquaLDd3 4+kKP6EmmyAFHEDYlHe+JMNx5GYrJ58rPjUVX+xBF9mv6q2xtt/vbzPulNa/6SAMsiBqzb CofDVitcPFDZHREtvLjdvvzL/qY5Sh6UlMyxQiZ5JpK/Ct6SEQsVn48ggcBqmS+2ThF0eQ otvO+d0wEx3DVEXtdYnhFNYh4UB9xjEV75r/E6cy0upn1NsOz1Prh+MF6/8q8H2ZJJ9eTW Q51A5lXFzAxt3gt1IW8NCCwAWtzOtHxs1uSz4g8uqXulKlyhITDc/BPpMceAnA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1670996983; a=rsa-sha256; cv=none; b=WmhMt5WuPCMCtNtgWmPuahwsrQoiJiQOcqcz5tFs0imMFQukBifW7Cp3WJNqkATS3MMZAE fPCbivbvvPWMEf9n3n9IT6kMJAlOrgbnVjOljPnwn8wYsWT/fuBWMO+KseHjsc/DssFoxa cABsQBXVZTd3MIX5ZiNuxRshVGOjCg7uLOGJ1Rc2jEksJdlnfbLHqUs7buk1WzdSaG2KDm XZIP+hJwfCiie5MH0Lva3eScyN8RQ1FdPP/jQcpHvQNIZ+oR7ebLAV/M25hwTmSKUkx9Ez SIqvqA4UTvzF9bipXEGXJQ67vBB6n1ReXlLFgdIgIkBTQI/vQKMtYjKVMWJsVQ== 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 4NX4FM04Bczjd3; Wed, 14 Dec 2022 05:49:43 +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 2BE5ngHj034608; Wed, 14 Dec 2022 05:49:42 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 2BE5ngXD034607; Wed, 14 Dec 2022 05:49:42 GMT (envelope-from git) Date: Wed, 14 Dec 2022 05:49:42 GMT Message-Id: <202212140549.2BE5ngXD034607@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: 18a30fd39be7 - main - if_ovpn: start tracking per-peer packets/bytes in/out List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@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: 18a30fd39be77de7e56e30ceacc90f4c8833cfc9 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=18a30fd39be77de7e56e30ceacc90f4c8833cfc9 commit 18a30fd39be77de7e56e30ceacc90f4c8833cfc9 Author: Kristof Provost AuthorDate: 2022-11-26 13:22:23 +0000 Commit: Kristof Provost CommitDate: 2022-12-14 05:48:58 +0000 if_ovpn: start tracking per-peer packets/bytes in/out OpenVPN will introduce a mechanism to retrieve per-peer statistics. Start tracking those so we can return them to userspace when queried. Sponsored by: Rubicon Communications, LLC ("Netgate") Differential Revision: https://reviews.freebsd.org/D37603 --- sys/net/if_ovpn.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/sys/net/if_ovpn.c b/sys/net/if_ovpn.c index 256d7d56bada..6686315fbf01 100644 --- a/sys/net/if_ovpn.c +++ b/sys/net/if_ovpn.c @@ -122,6 +122,14 @@ struct ovpn_notification { struct ovpn_softc; +struct ovpn_peer_counters { + uint64_t pkt_in; + uint64_t pkt_out; + uint64_t bytes_in; + uint64_t bytes_out; +}; +#define OVPN_PEER_COUNTER_SIZE (sizeof(struct ovpn_peer_counters)/sizeof(uint64_t)) + struct ovpn_kpeer { RB_ENTRY(ovpn_kpeer) tree; int refcount; @@ -142,6 +150,8 @@ struct ovpn_kpeer { uint32_t *last_active; struct callout ping_send; struct callout ping_rcv; + + counter_u64_t counters[OVPN_PEER_COUNTER_SIZE]; }; struct ovpn_counters { @@ -219,6 +229,9 @@ VNET_DEFINE_STATIC(struct if_clone *, ovpn_cloner); #define OVPN_COUNTER_ADD(sc, name, val) \ counter_u64_add(sc->counters[offsetof(struct ovpn_counters, name) / \ sizeof(uint64_t)], val) +#define OVPN_PEER_COUNTER_ADD(p, name, val) \ + counter_u64_add(p->counters[offsetof(struct ovpn_peer_counters, name) / \ + sizeof(uint64_t)], val) #define TO_IN(x) ((struct sockaddr_in *)(x)) #define TO_IN6(x) ((struct sockaddr_in6 *)(x)) @@ -499,6 +512,7 @@ ovpn_new_peer(struct ifnet *ifp, const nvlist_t *nvl) peer->tx_seq = 1; peer->refcount = 1; peer->last_active = uma_zalloc_pcpu(pcpu_zone_4, M_WAITOK | M_ZERO); + COUNTER_ARRAY_ALLOC(peer->counters, OVPN_PEER_COUNTER_SIZE, M_WAITOK); if (nvlist_exists_binary(nvl, "vpn_ipv4")) { size_t len; @@ -606,6 +620,7 @@ error_locked: OVPN_WUNLOCK(sc); error: free(name, M_SONAME); + COUNTER_ARRAY_FREE(peer->counters, OVPN_PEER_COUNTER_SIZE); uma_zfree_pcpu(pcpu_zone_4, peer->last_active); free(peer, M_OVPN); done: @@ -1404,6 +1419,8 @@ ovpn_finish_rx(struct ovpn_softc *sc, struct mbuf *m, OVPN_COUNTER_ADD(sc, received_data_pkts, 1); OVPN_COUNTER_ADD(sc, tunnel_bytes_received, m->m_pkthdr.len); + OVPN_PEER_COUNTER_ADD(peer, pkt_in, 1); + OVPN_PEER_COUNTER_ADD(peer, bytes_in, m->m_pkthdr.len); /* Receive the packet on our interface. */ m->m_pkthdr.rcvif = sc->ifp; @@ -1740,6 +1757,9 @@ ovpn_transmit_to_peer(struct ifnet *ifp, struct mbuf *m, seq = htonl(seq); ohdr->seq = seq; + OVPN_PEER_COUNTER_ADD(peer, pkt_out, 1); + OVPN_PEER_COUNTER_ADD(peer, bytes_out, len); + if (key->encrypt->cipher == OVPN_CIPHER_ALG_NONE) { ret = ovpn_encap(sc, peer->peerid, m); if (_ovpn_lock_trackerp != NULL)