git: 6a6f2b0ce9e6 - main - netstat: fix IPv6 link-locals & custom multipath printing.
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 06 Mar 2023 15:08:33 UTC
The branch main has been updated by melifaro: URL: https://cgit.FreeBSD.org/src/commit/?id=6a6f2b0ce9e6f4be276405118e296f2d42eedba7 commit 6a6f2b0ce9e6f4be276405118e296f2d42eedba7 Author: Alexander V. Chernikov <melifaro@FreeBSD.org> AuthorDate: 2023-03-06 15:06:04 +0000 Commit: Alexander V. Chernikov <melifaro@FreeBSD.org> CommitDate: 2023-03-06 15:08:09 +0000 netstat: fix IPv6 link-locals & custom multipath printing. --- usr.bin/netstat/route_netlink.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/usr.bin/netstat/route_netlink.c b/usr.bin/netstat/route_netlink.c index 17b15579b83b..ea50d8076182 100644 --- a/usr.bin/netstat/route_netlink.c +++ b/usr.bin/netstat/route_netlink.c @@ -163,7 +163,7 @@ SNL_DECLARE_ATTR_PARSER(metrics_mp_parser, nla_p_mp_rtmetrics); static const struct snl_attr_parser psnh[] = { { .type = NL_RTA_GATEWAY, .off = _OUT(gw), .cb = snl_attr_get_ip }, { .type = NL_RTA_METRICS, .arg = &metrics_mp_parser, .cb = snl_attr_get_nested }, - { .type = NL_RTA_RTFLAGS, .off = _OUT(gw), .cb = snl_attr_get_uint32 }, + { .type = NL_RTA_RTFLAGS, .off = _OUT(rta_rtflags), .cb = snl_attr_get_uint32 }, { .type = NL_RTA_VIA, .off = _OUT(gw), .cb = snl_attr_get_ipvia }, }; @@ -320,6 +320,16 @@ struct sockaddr_dl_short { char sdl_data[8]; /* unused */ }; +static void +add_scopeid(struct sockaddr *sa, int ifindex) +{ + if (sa->sa_family == AF_INET6) { + struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sa; + if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) + sin6->sin6_scope_id = ifindex; + } +} + static void p_path(struct nl_parsed_route *rt, bool is_mpath) { @@ -330,6 +340,8 @@ p_path(struct nl_parsed_route *rt, bool is_mpath) int protrusion; gen_mask(rt->rtm_family, rt->rtm_dst_len, pmask); + add_scopeid(rt->rta_dst, rt->rta_oif); + add_scopeid(rt->rta_gw, rt->rta_oif); protrusion = p_sockaddr("destination", rt->rta_dst, pmask, rt->rta_rtflags, wid.dst); protrusion = p_sockaddr("gateway", rt->rta_gw, NULL, RTF_HOST, wid.gw - protrusion);