git: f3a097d0312c - main - netstat: switch to using the sysctl-exported stats for live stats
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Thu, 24 Oct 2024 16:54:53 UTC
The branch main has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=f3a097d0312cbadefa9bbb00cf3c6af784f9fbb9 commit f3a097d0312cbadefa9bbb00cf3c6af784f9fbb9 Author: Kyle Evans <kevans@FreeBSD.org> AuthorDate: 2024-10-24 16:53:59 +0000 Commit: Kyle Evans <kevans@FreeBSD.org> CommitDate: 2024-10-24 16:54:21 +0000 netstat: switch to using the sysctl-exported stats for live stats Now that we export the relevant stats via the net.route.stats sysctl, switch to using that to avoid having to dig around in mem(4) for live kernel statistics. Based on callers of kresolve_list(), this is the last live path using mem(4) that could be functional today. Tested both with `netstat -rs` and `netstat -rs -M`. Note that this will not be able to extract stats from a running kernel that predates 3360a15898 / 1500026, but this can be worked around by specifying `-M /dev/mem` explicitly in the interim to fallback to libkvm against /dev/mem. Reviewed by: glebius, markj, zlei Differential Revision: https://reviews.freebsd.org/D47231 --- usr.bin/netstat/main.c | 7 ++----- usr.bin/netstat/route.c | 8 +++----- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/usr.bin/netstat/main.c b/usr.bin/netstat/main.c index eaca38365ed8..97509ea6798b 100644 --- a/usr.bin/netstat/main.c +++ b/usr.bin/netstat/main.c @@ -523,12 +523,9 @@ main(int argc, char *argv[]) if (rflag) { xo_open_container("statistics"); xo_set_version(NETSTAT_XO_VERSION); - if (sflag) { - if (live) { - kresolve_list(nl); - } + if (sflag) rt_stats(); - } else + else routepr(fib, af); xo_close_container("statistics"); if (xo_finish() < 0) diff --git a/usr.bin/netstat/route.c b/usr.bin/netstat/route.c index f32ddee8403f..74797e2addb8 100644 --- a/usr.bin/netstat/route.c +++ b/usr.bin/netstat/route.c @@ -699,13 +699,11 @@ void rt_stats(void) { struct rtstat rtstat; - u_long rtsaddr; - if ((rtsaddr = nl[N_RTSTAT].n_value) == 0) { - xo_emit("{W:rtstat: symbol not in namelist}\n"); + if (fetch_stats("net.route.stats", nl[N_RTSTAT].n_value, &rtstat, + sizeof(rtstat), kread_counters) != 0) return; - } - kread_counters(rtsaddr, (char *)&rtstat, sizeof (rtstat)); + xo_emit("{T:routing}:\n"); #define p(f, m) if (rtstat.f || sflag <= 1) \