Date: Tue, 16 Jan 2024 08:51:53 GMT From: Kristof Provost <kp@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Subject: git: 5dea523bd241 - main - pflow: netstat statistics Message-ID: <202401160851.40G8prB7075714@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch main has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=5dea523bd241fea07dc28c067b124d607dc96948 commit 5dea523bd241fea07dc28c067b124d607dc96948 Author: Kristof Provost <kp@FreeBSD.org> AuthorDate: 2023-12-06 13:55:33 +0000 Commit: Kristof Provost <kp@FreeBSD.org> 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 <arpa/inet.h> #ifdef PF #include <net/pfvar.h> +#include <net/pflow.h> #include <net/if_pfsync.h> #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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202401160851.40G8prB7075714>