Page MenuHomeFreeBSD

netstat(1): Show metric value for routes
AcceptedPublic

Authored by pouria on Fri, May 15, 10:11 AM.
Tags
None
Referenced Files
F157253969: D57011.diff
Tue, May 19, 6:11 PM
F157253967: D57011.diff
Tue, May 19, 6:11 PM
F157253965: D57011.diff
Tue, May 19, 6:11 PM
F157253964: D57011.diff
Tue, May 19, 6:10 PM
F157253963: D57011.diff
Tue, May 19, 6:10 PM
F157253954: D57011.diff
Tue, May 19, 6:10 PM
F157253947: D57011.diff
Tue, May 19, 6:10 PM
F157253935: D57011.diff
Tue, May 19, 6:10 PM
Subscribers

Details

Reviewers
melifaro
markj
glebius
Group Reviewers
network
Summary

Add metric support and show its value in wide flag and
libxo output.

Depends on D56323

Test Plan

Run netstat -rW or
netstat -r --libxo json | jq ' .statistics."route-information"."route-table"."rt-family".[]."rt-entry".[].metric'

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 73196
Build 70079: arc lint + arc unit

Event Timeline

usr.bin/netstat/route.c
213

Won't this break simple scripts that parse netstat -r output by printing a particular column? That is, shouldn't we add metric as the final column?

Also the description of -W in the man page should be updated.

usr.bin/netstat/route.c
213

Won't this break simple scripts that parse netstat -r output by printing a particular column? That is, shouldn't we add metric as the final column?

wide columns (-W) are adjusted dynamically, users should not write scripts on -W.
That's why I didn't add metric column into -r without the wide flag.

Also the description of -W in the man page should be updated.

I will, Thank you!

usr.bin/netstat/route.c
213

Well, "should" and "does" are sadly not the same. We have some code in the base system which does exactly that:

usr.sbin/bsdinstall/scripts/netconfig_ipv6:ROUTER6=`netstat -Wrn -f inet6 | awk '/default/ {printf("%s\n", $2);}'`

IMO it's important to avoid reordering columns.

usr.bin/netstat/route.c
213

Oops, you're right.
IMHO, due to the nature of metric and the fact we didn't support it until now, it should not be the last column.
But I'm fine with not reordering it. so I will do as you suggested.
I really want to add metric to without w flag too. but expire column could be hidden if route don't have one.
That's why I didn't do it. But we really should do. :D

Address @markj comment.
Place metric column before expire column because expire column can be hidden.

usr.bin/netstat/route.c
213

Sorry, I don't really understand why it is okay to reorder "expire"?

usr.bin/netstat/route_netlink.c
182

It's a uint32_t.

220

fix format specifier to 32 bit.
@markj: Done.
Thank you

pouria added inline comments.
usr.bin/netstat/route.c
358

@markj: Here
It can be zero, therefore it will not get printed.
For this reason, expire should be the last column.

Also, it was broken until last month, when I fixed it.
So I'm almost sure nobody wrote an script for that. :D

This revision is now accepted and ready to land.Tue, May 19, 6:03 PM