Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F165286077
D58538.id.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D58538.id.diff
View Options
diff --git a/usr.bin/netstat/main.c b/usr.bin/netstat/main.c
--- a/usr.bin/netstat/main.c
+++ b/usr.bin/netstat/main.c
@@ -531,7 +531,10 @@
if (oflag) {
xo_open_container("statistics");
xo_set_version(NETSTAT_XO_VERSION);
- nhops_print(fib, af);
+ if (sflag)
+ nhops_stats();
+ else
+ nhops_print(fib, af);
xo_close_container("statistics");
if (xo_finish() < 0)
xo_err(EX_IOERR, "stdout");
diff --git a/usr.bin/netstat/netstat.h b/usr.bin/netstat/netstat.h
--- a/usr.bin/netstat/netstat.h
+++ b/usr.bin/netstat/netstat.h
@@ -165,4 +165,5 @@
void mrt_stats(void);
void bpf_stats(char *);
void nhops_print(int fibnum, int af);
+void nhops_stats(void);
void nhgrp_print(int fibnum, int af);
diff --git a/usr.bin/netstat/netstat.1 b/usr.bin/netstat/netstat.1
--- a/usr.bin/netstat/netstat.1
+++ b/usr.bin/netstat/netstat.1
@@ -25,7 +25,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd May 18, 2026
+.Dd July 29, 2026
.Dt NETSTAT 1
.Os
.Sh NAME
@@ -108,8 +108,12 @@
.Op Fl -libxo
.It Nm Fl o
.Fl 4 | Fl 6
+.It Nm Fl os
+.Op Fl -libxo
+.Op Fl s
.It Nm Fl O
.Fl 4 | Fl 6
+.Op Fl s
.El
.Ek
.Sh DESCRIPTION
@@ -413,6 +417,20 @@
used in routing decisions.
.It Xo
.Bk -words
+.Nm
+.Fl os
+.Op Fl s
+.Ek
+.Xc
+Display nexthop statistics.
+.Bl -tag -width indent
+.It Fl s
+If
+.Fl s
+is repeated, counters with a value of zero are suppressed.
+.El
+.It Xo
+.Bk -words
.Nm netstat
.Fl O
.Fl 4 | Fl 6
diff --git a/usr.bin/netstat/nhops.c b/usr.bin/netstat/nhops.c
--- a/usr.bin/netstat/nhops.c
+++ b/usr.bin/netstat/nhops.c
@@ -61,6 +61,7 @@
#include <libxo/xo.h>
#include "netstat.h"
#include "common.h"
+#include "nl_defs.h"
/* column widths; each followed by one space */
#define WID_IF_DEFAULT (Wflag ? IFNAMSIZ : 12) /* width of netif column */
@@ -476,3 +477,26 @@
xo_close_container("route-nhop-information");
}
+/*
+ * Print nexthop statistics
+ */
+void
+nhops_stats(void)
+{
+ struct rtstat rtstat;
+
+ if (fetch_stats("net.route.stats", nl[N_RTSTAT].n_value, &rtstat,
+ sizeof(rtstat), kread_counters) != 0)
+ return;
+
+ xo_emit("{T:nexthop}:\n");
+
+#define p(f, m) if (rtstat.f || sflag <= 1) \
+ xo_emit(m, rtstat.f, plural(rtstat.f))
+
+ p(rts_nh_idx_alloc_failure, "\t{:nh-idx-alloc-failure/%ju} "
+ "{N:/index allocation failure%s}\n");
+ p(rts_nh_alloc_failure, "\t{:nh-alloc-failure/%ju} "
+ "{N:/nexthop allocation failure%s}\n");
+#undef p
+}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Aug 8, 10:24 AM (22 h, 38 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
36147680
Default Alt Text
D58538.id.diff (2 KB)
Attached To
Mode
D58538: netstat(1): Add nexthop statistics support with -os flag
Attached
Detach File
Event Timeline
Log In to Comment