Changeset View
Standalone View
usr.bin/netstat/route.c
| Show First 20 Lines • Show All 199 Lines • ▼ Show 20 Lines | |||||
| * Print header for routing table columns. | * Print header for routing table columns. | ||||
| */ | */ | ||||
| void | void | ||||
| pr_rthdr(int af1 __unused) | pr_rthdr(int af1 __unused) | ||||
| { | { | ||||
| if (Wflag) { | if (Wflag) { | ||||
| xo_emit("{T:/%-*.*s} {T:/%-*.*s} {T:/%-*.*s} {T:/%*.*s} " | 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.dst, wid.dst, "Destination", | ||||
| wid.gw, wid.gw, "Gateway", | wid.gw, wid.gw, "Gateway", | ||||
| wid.flags, wid.flags, "Flags", | wid.flags, wid.flags, "Flags", | ||||
| wid.mtu, wid.mtu, "Nhop#", | wid.mtu, wid.mtu, "Nhop#", | ||||
| wid.mtu, wid.mtu, "Mtu", | wid.mtu, wid.mtu, "Mtu", | ||||
markj: Won't this break simple scripts that parse `netstat -r` output by printing a particular column? | |||||
Done Inline Actions
wide columns (-W) are adjusted dynamically, users should not write scripts on -W.
I will, Thank you! pouria: > Won't this break simple scripts that parse `netstat -r` output by printing a particular… | |||||
Not Done Inline ActionsWell, "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. markj: Well, "should" and "does" are sadly not the same. We have some code in the base system which… | |||||
Done Inline ActionsOops, you're right. pouria: Oops, you're right.
IMHO, due to the nature of metric and the fact we didn't support it until… | |||||
Not Done Inline ActionsSorry, I don't really understand why it is okay to reorder "expire"? markj: Sorry, I don't really understand why it is okay to reorder "expire"? | |||||
| wid.iface, wid.iface, "Netif", | wid.iface, wid.iface, "Netif", | ||||
| wid.metric, wid.metric, "Metric", | |||||
| wid.expire, "Expire"); | wid.expire, "Expire"); | ||||
| } else { | } else { | ||||
| xo_emit("{T:/%-*.*s} {T:/%-*.*s} {T:/%-*.*s} {T:/%*.*s} " | xo_emit("{T:/%-*.*s} {T:/%-*.*s} {T:/%-*.*s} {T:/%*.*s} " | ||||
| "{T:/%*s}\n", | "{T:/%*s}\n", | ||||
| wid.dst, wid.dst, "Destination", | wid.dst, wid.dst, "Destination", | ||||
| wid.gw, wid.gw, "Gateway", | wid.gw, wid.gw, "Gateway", | ||||
| wid.flags, wid.flags, "Flags", | wid.flags, wid.flags, "Flags", | ||||
| wid.iface, wid.iface, "Netif", | wid.iface, wid.iface, "Netif", | ||||
| wid.expire, "Expire"); | wid.expire, "Expire"); | ||||
| } | } | ||||
| } | } | ||||
| void | void | ||||
| set_wid(int fam) | set_wid(int fam) | ||||
| { | { | ||||
| wid.dst = WID_DST_DEFAULT(fam); | wid.dst = WID_DST_DEFAULT(fam); | ||||
| wid.gw = WID_GW_DEFAULT(fam); | wid.gw = WID_GW_DEFAULT(fam); | ||||
| wid.flags = 6; | wid.flags = 6; | ||||
| wid.pksent = 8; | wid.pksent = 8; | ||||
| wid.mtu = 6; | wid.mtu = 6; | ||||
| wid.iface = WID_IF_DEFAULT; | wid.iface = WID_IF_DEFAULT; | ||||
| wid.metric = 8; | |||||
| wid.expire = 6; | wid.expire = 6; | ||||
| } | } | ||||
| #ifdef WITHOUT_NETLINK | #ifdef WITHOUT_NETLINK | ||||
| static void | static void | ||||
| p_rtable_sysctl(int fibnum, int af) | p_rtable_sysctl(int fibnum, int af) | ||||
| { | { | ||||
| size_t needed; | size_t needed; | ||||
| ▲ Show 20 Lines • Show All 77 Lines • ▼ Show 20 Lines | p_rtentry_sysctl(const char *name, struct rt_msghdr *rtm) | ||||
| protrusion = p_sockaddr("destination", addr[RTAX_DST], | protrusion = p_sockaddr("destination", addr[RTAX_DST], | ||||
| addr[RTAX_NETMASK], | addr[RTAX_NETMASK], | ||||
| rtm->rtm_flags, wid.dst); | rtm->rtm_flags, wid.dst); | ||||
| protrusion = p_sockaddr("gateway", addr[RTAX_GATEWAY], NULL, RTF_HOST, | protrusion = p_sockaddr("gateway", addr[RTAX_GATEWAY], NULL, RTF_HOST, | ||||
| wid.gw - protrusion); | wid.gw - protrusion); | ||||
| snprintf(buffer, sizeof(buffer), "{[:-%d}{:flags/%%s}{]:} ", | snprintf(buffer, sizeof(buffer), "{[:-%d}{:flags/%%s}{]:} ", | ||||
| wid.flags - protrusion); | wid.flags - protrusion); | ||||
| p_flags(rtm->rtm_flags, buffer); | 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:weight/%u}", rtm->rtm_rmx.rmx_weight); | ||||
| xo_emit("{e:metric/%lu}", rtm->rtm_rmx.rmx_metric); | |||||
| if (Wflag) { | if (Wflag) { | ||||
| /* XXX: use=0? */ | /* XXX: use=0? */ | ||||
| xo_emit("{t:nhop/%*lu} ", wid.mtu, rtm->rtm_rmx.rmx_nhidx); | xo_emit("{t:nhop/%*lu} ", wid.mtu, rtm->rtm_rmx.rmx_nhidx); | ||||
| if (rtm->rtm_rmx.rmx_mtu != 0) | if (rtm->rtm_rmx.rmx_mtu != 0) | ||||
| xo_emit("{t:mtu/%*lu} ", wid.mtu, rtm->rtm_rmx.rmx_mtu); | xo_emit("{t:mtu/%*lu} ", wid.mtu, rtm->rtm_rmx.rmx_mtu); | ||||
| else | else | ||||
| xo_emit("{P:/%*s} ", wid.mtu, ""); | xo_emit("{P:/%*s} ", wid.mtu, ""); | ||||
| } | } | ||||
| memset(prettyname, 0, sizeof(prettyname)); | memset(prettyname, 0, sizeof(prettyname)); | ||||
| if (rtm->rtm_index < ifmap_size) { | if (rtm->rtm_index < ifmap_size) { | ||||
| strlcpy(prettyname, ifmap[rtm->rtm_index].ifname, | strlcpy(prettyname, ifmap[rtm->rtm_index].ifname, | ||||
| sizeof(prettyname)); | sizeof(prettyname)); | ||||
| if (*prettyname == '\0') | if (*prettyname == '\0') | ||||
| strlcpy(prettyname, "---", sizeof(prettyname)); | strlcpy(prettyname, "---", sizeof(prettyname)); | ||||
| } | } | ||||
| if (Wflag) | if (Wflag) { | ||||
| xo_emit("{t:interface-name/%*s}", wid.iface, prettyname); | 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, | xo_emit("{t:interface-name/%*.*s}", wid.iface, wid.iface, | ||||
| prettyname); | prettyname); | ||||
| if (rtm->rtm_rmx.rmx_expire) { | if (rtm->rtm_rmx.rmx_expire) { | ||||
Done Inline Actions@markj: Here Also, it was broken until last month, when I fixed it. pouria: @markj: Here
It can be zero, therefore it will not get printed.
For this reason, expire should… | |||||
| time_t expire_time; | time_t expire_time; | ||||
| if ((expire_time = rtm->rtm_rmx.rmx_expire - uptime.tv_sec) > 0) | if ((expire_time = rtm->rtm_rmx.rmx_expire - uptime.tv_sec) > 0) | ||||
| xo_emit(" {:expire-time/%*d}", wid.expire, | xo_emit(" {:expire-time/%*d}", wid.expire, | ||||
| (int)expire_time); | (int)expire_time); | ||||
| } | } | ||||
| xo_emit("\n"); | xo_emit("\n"); | ||||
| ▲ Show 20 Lines • Show All 362 Lines • Show Last 20 Lines | |||||
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.