aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyle Evans <kevans@FreeBSD.org>2024-10-24 16:53:59 +0000
committerKyle Evans <kevans@FreeBSD.org>2024-10-24 16:54:21 +0000
commitf3a097d0312cbadefa9bbb00cf3c6af784f9fbb9 (patch)
tree693f0da3c95f1f7eaab0df320986755cbb01f43c
parent2f395cfda8b5c1dc267e9cd4d99d7d0862fb4fca (diff)
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
-rw-r--r--usr.bin/netstat/main.c7
-rw-r--r--usr.bin/netstat/route.c8
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) \