From nobody Tue Jan 16 08:51:53 2024 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 4TDjRt2m6Mz57B1t; Tue, 16 Jan 2024 08:51:54 +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 4TDjRs6jpvz4Ptp; Tue, 16 Jan 2024 08:51:53 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1705395113; 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=aDSWBjFdAjVJvtrlXy+wim8xLNUzrXvCAPVkE5Je57Y=; b=rFZDr5zt9t8r4laYBFvRWP3yQNoaYowPLjAF6ZlzG75Dl8V+P7njNyXDvi+HG4pzDsFbZp IxsyYxrwxXnCv73VhnpEyKzzTr1mAjccoEuOCUbAZe5IH4goAfARPW5RDeuKhyUJHLvmwA JSNj9n+0iC3/ds8FrTMWp/B1BRMQYQ+TY1+sMCO7ZCC4/+bBZTob4zccU8so6XyBFsZdvf RsaJ8SE8Y9zJwJ3kZhp35kVj52SCFuXTh/nk9H7iJ2Ikm06QbQO26F2VYbWcsgZLcf96EI CZuVMbaL52H2KV7HFis7t9mxHPFmH07VkSkAFPE8840ndwXwQH73QXHX3bcU3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1705395113; 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=aDSWBjFdAjVJvtrlXy+wim8xLNUzrXvCAPVkE5Je57Y=; b=QuwXaJn5MKS0aryno32H3/thJuwjplfKN499QE/G9d3wiH7yVpTiERL9QDhWWqLyCYmVyP j83gddvbMuji3xQxzY+HajmbMOBNgifkBNnwUm2LeKJRKOHaeT84AfOItQK+sSYicMXVG1 7YIS3PlXStVoQAh2KTbqJyx1ywxqT2rAwJ732RxdF5HC1XrdVVBNK3mR43ikOciXqf6c7g H/DdT4ltT3lwfmZM3cNQjrrMC6iG6vRZcdISa+AolEj+FQPH1usUhC+4TQ/NxL8+d3p2Yf aACvi3Y83om9rxH3V2xEo+0O7R9PXrTXY3nwSZRWuW8bUqU1TL2Gpt7BDyU8Ig== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1705395113; a=rsa-sha256; cv=none; b=kMX2iOUqiU5olQKdrrxdbHkha71w6jSqAPCz58ZDkEi8IQRM7J0mXFoml/6gSIkQZctwLt EyxXl0fEbFPmgJYexC7HilWqpGH+I7CQT9YCJ3u3YgPO0l77DaJTaJHEaPy/lrbV4dDE9t TSq8PZXWWX6Gud/Cs0BgJTK8l5W5ekdTVjViZGeBmXBMFACHYyhZ3aOgJ4JpxRKebPIAlK e44Rr6FlaqXbn4vC3bI1YUIkNWmXMe24cYal+gMJFVSTYie6bxzeQeT+9s7TxLxdXE4WaY VUWRGCHs0i1V3VBmhNQBQm7EcjsTnpz4A62fJjVFBYJiDCM654CEiHO3HIpUVw== 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 4TDjRs5qJhzZ9Q; Tue, 16 Jan 2024 08:51:53 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 40G8prv8075717; Tue, 16 Jan 2024 08:51:53 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 40G8prB7075714; Tue, 16 Jan 2024 08:51:53 GMT (envelope-from git) Date: Tue, 16 Jan 2024 08:51:53 GMT Message-Id: <202401160851.40G8prB7075714@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: 5dea523bd241 - main - pflow: netstat statistics 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: 5dea523bd241fea07dc28c067b124d607dc96948 Auto-Submitted: auto-generated The branch main has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=5dea523bd241fea07dc28c067b124d607dc96948 commit 5dea523bd241fea07dc28c067b124d607dc96948 Author: Kristof Provost AuthorDate: 2023-12-06 13:55:33 +0000 Commit: Kristof Provost CommitDate: 2024-01-16 08:45:53 +0000 pflow: netstat statistics Expose pflow counters via netstat. Sponsored by: Rubicon Communications, LLC ("Netgate") Differential Revision: https://reviews.freebsd.org/D43107 --- sys/netpfil/pf/pflow.c | 10 ++++++++-- usr.bin/netstat/if.c | 26 ++++++++++++++++++++++++++ usr.bin/netstat/main.c | 2 ++ usr.bin/netstat/netstat.h | 1 + usr.bin/netstat/nlist_symbols | 1 + 5 files changed, 38 insertions(+), 2 deletions(-) diff --git a/sys/netpfil/pf/pflow.c b/sys/netpfil/pf/pflow.c index 855ebe5ca98c..2dc612bd9e07 100644 --- a/sys/netpfil/pf/pflow.c +++ b/sys/netpfil/pf/pflow.c @@ -128,13 +128,19 @@ VNET_DEFINE(CK_LIST_HEAD(, pflow_softc), pflowif_list); #define V_pflowif_list VNET(pflowif_list) VNET_DEFINE(struct mtx, pflowif_list_mtx); #define V_pflowif_list_mtx VNET(pflowif_list_mtx) -VNET_DEFINE(struct pflowstats, pflowstats); -#define V_pflowstats VNET(pflowstats) +VNET_DEFINE(struct pflowstats, pflowstat); +#define V_pflowstats VNET(pflowstat) #define PFLOW_LOCK(_sc) mtx_lock(&(_sc)->sc_lock) #define PFLOW_UNLOCK(_sc) mtx_unlock(&(_sc)->sc_lock) #define PFLOW_ASSERT(_sc) mtx_assert(&(_sc)->sc_lock, MA_OWNED) +SYSCTL_NODE(_net, OID_AUTO, pflow, CTLFLAG_RW | CTLFLAG_MPSAFE, 0, + "PFLOW"); +SYSCTL_STRUCT(_net_pflow, OID_AUTO, stats, CTLFLAG_VNET | CTLFLAG_RW, + &VNET_NAME(pflowstat), pflowstats, + "PFLOW statistics (struct pflowstats, net/if_pflow.h)"); + static void vnet_pflowattach(void) { diff --git a/usr.bin/netstat/if.c b/usr.bin/netstat/if.c index 7aafdf78b296..172ea5324ccb 100644 --- a/usr.bin/netstat/if.c +++ b/usr.bin/netstat/if.c @@ -45,6 +45,7 @@ #include #ifdef PF #include +#include #include #endif @@ -181,6 +182,31 @@ pfsync_stats(u_long off, const char *name, int af1 __unused, int proto __unused) #undef p xo_close_container(name); } + +void +pflow_stats(u_long off, const char *name, int af1 __unused, int proto __unused) +{ + struct pflowstats pflowstat; + + if (fetch_stats("net.pflow.stats", off, &pflowstat, + sizeof(pflowstat), kread) != 0) + return; + + xo_emit("{T:/%s}:\n", name); + xo_open_container(name); + +#define p(f, m) if (pflowstat.f || sflag <= 1) \ + xo_emit(m, (uintmax_t)pflowstat.f, plural(pflowstat.f)) + + p(pflow_flows, "\t{:flows/%ju} {N:/flow%s sent}\n"); + p(pflow_packets, "\t{:packets/%ju} {N:/packet%s sent}\n"); + p(pflow_onomem, "\t{:nomem/%ju} " + "{N:/send failed due to mbuf memory error}\n"); + p(pflow_oerrors, "\t{:send-error/%ju} {N:/send error}\n"); +#undef p + + xo_close_container(name); +} #endif /* PF */ /* diff --git a/usr.bin/netstat/main.c b/usr.bin/netstat/main.c index b5d8754777cb..2ed6eca4626e 100644 --- a/usr.bin/netstat/main.c +++ b/usr.bin/netstat/main.c @@ -116,6 +116,8 @@ static struct protox { #ifdef PF { -1, N_PFSYNCSTATS, 1, NULL, pfsync_stats, NULL, "pfsync", 1, 0 }, + { -1, N_PFLOWSTATS, 1, NULL, + pflow_stats, NULL, "pflow", 1, 0 }, #endif { -1, N_ARPSTAT, 1, NULL, arp_stats, NULL, "arp", 1, 0 }, diff --git a/usr.bin/netstat/netstat.h b/usr.bin/netstat/netstat.h index fd8171734c97..c41862d9fbdd 100644 --- a/usr.bin/netstat/netstat.h +++ b/usr.bin/netstat/netstat.h @@ -96,6 +96,7 @@ void igmp_stats(u_long, const char *, int, int); void pim_stats(u_long, const char *, int, int); void carp_stats(u_long, const char *, int, int); void pfsync_stats(u_long, const char *, int, int); +void pflow_stats(u_long, const char *, int, int); #ifdef IPSEC void ipsec_stats(u_long, const char *, int, int); void esp_stats(u_long, const char *, int, int); diff --git a/usr.bin/netstat/nlist_symbols b/usr.bin/netstat/nlist_symbols index 7d7fcdc4c249..30cdd69bc54b 100644 --- a/usr.bin/netstat/nlist_symbols +++ b/usr.bin/netstat/nlist_symbols @@ -31,6 +31,7 @@ all _nws_array all _nws_count all _pfkeystat all _pfsyncstats +all _pflowstats all _pim6stat all _pimstat all _rip6stat