diff --git a/usr.bin/netstat/common.h b/usr.bin/netstat/common.h --- a/usr.bin/netstat/common.h +++ b/usr.bin/netstat/common.h @@ -52,6 +52,7 @@ int pksent; int mtu; int iface; + int metric; int expire; }; void set_wid(int fam); 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 April 7, 2026 +.Dd May 18, 2026 .Dt NETSTAT 1 .Os .Sh NAME @@ -678,7 +678,7 @@ See .Sx GENERAL OPTIONS . .It Fl W -Show the path MTU for each route, and print interface names with a +Show the metric and path MTU for each route, and print interface names with a wider field size. .It Fl F Display the routing table with the number diff --git a/usr.bin/netstat/route.c b/usr.bin/netstat/route.c --- a/usr.bin/netstat/route.c +++ b/usr.bin/netstat/route.c @@ -205,13 +205,14 @@ if (Wflag) { xo_emit("{T:/%-*.*s} {T:/%-*.*s} {T:/%-*.*s} {T:/%*.*s} " - "{T:/%*.*s} {T:/%*.*s} {T:/%*s}\n", + "{T:/%*.*s} {T:/%*.*s} {T:/%*.*s} {T:/%*s}\n", wid.dst, wid.dst, "Destination", wid.gw, wid.gw, "Gateway", wid.flags, wid.flags, "Flags", wid.mtu, wid.mtu, "Nhop#", wid.mtu, wid.mtu, "Mtu", wid.iface, wid.iface, "Netif", + wid.metric, wid.metric, "Metric", wid.expire, "Expire"); } else { xo_emit("{T:/%-*.*s} {T:/%-*.*s} {T:/%-*.*s} {T:/%*.*s} " @@ -233,6 +234,7 @@ wid.pksent = 8; wid.mtu = 6; wid.iface = WID_IF_DEFAULT; + wid.metric = 8; wid.expire = 6; } @@ -326,8 +328,9 @@ snprintf(buffer, sizeof(buffer), "{[:-%d}{:flags/%%s}{]:} ", wid.flags - protrusion); p_flags(rtm->rtm_flags, buffer); - /* Output path weight as non-visual property */ + /* Output path weight and metric as non-visual property */ xo_emit("{e:weight/%u}", rtm->rtm_rmx.rmx_weight); + xo_emit("{e:metric/%lu}", rtm->rtm_rmx.rmx_metric); if (Wflag) { /* XXX: use=0? */ xo_emit("{t:nhop/%*lu} ", wid.mtu, rtm->rtm_rmx.rmx_nhidx); @@ -346,9 +349,10 @@ strlcpy(prettyname, "---", sizeof(prettyname)); } - if (Wflag) + if (Wflag) { xo_emit("{t:interface-name/%*s}", wid.iface, prettyname); - else + xo_emit("{t:metric/%*lu} ", wid.metric, rtm->rtm_rmx.rmx_metric); + } else xo_emit("{t:interface-name/%*.*s}", wid.iface, wid.iface, prettyname); if (rtm->rtm_rmx.rmx_expire) { diff --git a/usr.bin/netstat/route_netlink.c b/usr.bin/netstat/route_netlink.c --- a/usr.bin/netstat/route_netlink.c +++ b/usr.bin/netstat/route_netlink.c @@ -177,8 +177,9 @@ snprintf(buffer, sizeof(buffer), "{[:-%d}{:flags/%%s}{]:} ", wid.flags - protrusion); p_flags(rt->rta_rtflags | RTF_UP, buffer); - /* Output path weight as non-visual property */ + /* Output path weight and metric as non-visual property */ xo_emit("{e:weight/%u}", rt->rtax_weight); + xo_emit("{e:metric/%lu}", rt->rta_metric); if (is_mpath) xo_emit("{e:nhg-kidx/%u}", rt->rta_knh_id); else @@ -213,9 +214,10 @@ } - if (Wflag) + if (Wflag) { xo_emit("{t:interface-name/%*s}", wid.iface, prettyname); - else + xo_emit("{t:metric/%*lu} ", wid.metric, rt->rta_metric); + } else xo_emit("{t:interface-name/%*.*s}", wid.iface, wid.iface, prettyname); if (rt->rta_expire > 0) { @@ -242,6 +244,7 @@ rt.rta_gw = nhop->gw; rt.rta_oif = nhop->ifindex; rt.rtax_weight = nhop->rtnh_weight; + rt.rta_metric = nhop->rta_metric; rt.rta_rtflags = nhop->rta_rtflags ? nhop->rta_rtflags : orig_rtflags; rt.rtax_mtu = nhop->rtax_mtu ? nhop->rtax_mtu : orig_mtu; rt.rta_expire = nhop->rta_expire;