Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F177564545
D58538.1794744813.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
4 KB
Referenced Files
None
Subscribers
None
D58538.1794744813.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");
@@ -916,7 +919,7 @@
static void
usage(void)
{
- xo_error("%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n",
+ xo_error("%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n",
"usage: netstat [-j jail] [-46AaCcLnRSTWx] [-f protocol_family | -p protocol]\n"
" [-M core] [-N system]",
" netstat [-j jail] -i | -I interface [-46abdhnW] [-f address_family]\n"
@@ -934,6 +937,9 @@
" netstat [-j jail] -rs [-s] [-M core] [-N system]",
" netstat [-j jail] -g [-46W] [-f address_family] [-M core] [-N system]",
" netstat [-j jail] -gs [-46s] [-f address_family] [-M core] [-N system]",
-" netstat [-j jail] -Q");
+" netstat [-j jail] -Q",
+" netstat [-j jail] -o -4 | -6",
+" netstat [-j jail] -os [-s] [-M core] [-N system]",
+" netstat [-j jail] -O -4 | -6");
exit(EX_USAGE);
}
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 August 20, 2026
.Dt NETSTAT 1
.Os
.Sh NAME
@@ -108,8 +108,18 @@
.Op Fl -libxo
.It Nm Fl o
.Fl 4 | Fl 6
+.Op Fl j Ar jail
+.Op Fl -libxo
+.It Nm Fl os
+.Op Fl j Ar jail
+.Op Fl -libxo
+.Op Fl s
+.Op Fl M Ar core
+.Op Fl N Ar system
.It Nm Fl O
.Fl 4 | Fl 6
+.Op Fl j Ar jail
+.Op Fl -libxo
.El
.Ek
.Sh DESCRIPTION
@@ -401,6 +411,7 @@
.Nm netstat
.Fl o
.Fl 4 | Fl 6
+.Op Fl j Ar jail
.Ek
.Xc
Print nexthop (nhops) information associated with routing entries.
@@ -411,11 +422,47 @@
limit the output to IPv4 or IPv6 routes respectively.
This option provides details about individual nexthop addresses
used in routing decisions.
+.Bl -tag -width indent
+.It Fl j Ar jail
+Run inside a jail.
+See
+.Sx GENERAL OPTIONS .
+.El
+.It Xo
+.Bk -words
+.Nm
+.Fl os
+.Op Fl s
+.Op Fl M Ar core
+.Op Fl N Ar system
+.Op Fl j Ar jail
+.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.
+.It Fl M
+Use an alternative core
+See
+.Sx GENERAL OPTIONS .
+.It Fl N
+Use an alternative kernel image
+See
+.Sx GENERAL OPTIONS .
+.It Fl j Ar jail
+Run inside a jail.
+See
+.Sx GENERAL OPTIONS .
+.El
.It Xo
.Bk -words
.Nm netstat
.Fl O
.Fl 4 | Fl 6
+.Op Fl j Ar jail
.Ek
.Xc
Print nexthop groups (nhgrp) information associated with routing entries.
@@ -426,6 +473,12 @@
restrict the output to IPv4 or IPv6 nexthop groups respectively.
This option shows grouped nexthop entries for multipath or
load-balanced routing setups.
+.Bl -tag -width indent
+.It Fl j Ar jail
+Run inside a jail.
+See
+.Sx GENERAL OPTIONS .
+.El
.It Xo
.Bk -words
.Nm
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
Sun, Nov 15, 12:13 PM (9 h, 34 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
41742600
Default Alt Text
D58538.1794744813.diff (4 KB)
Attached To
Mode
D58538: netstat(1): Add nexthop statistics support with -os flag
Attached
Detach File
Event Timeline