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
This commit is contained in:
Kyle Evans 2024-10-24 11:53:59 -05:00
parent 2f395cfda8
commit f3a097d031
2 changed files with 5 additions and 10 deletions

View File

@ -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)

View File

@ -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) \