From nobody Sun Jan 29 16:37:02 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4P4cR24V0Lz3bD4l; Sun, 29 Jan 2023 16:37:02 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4P4cR240VPz4SF6; Sun, 29 Jan 2023 16:37:02 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1675010222; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=u9sp1r7BUIkzhKck4jSqWJH4dEZwlSneyod44BpZzGw=; b=WH+zWs3Lp5Ct+tf91UXgglkKAHlmefm1xBCPxl+4Et3eO4KaGKRvTRWM2Nre1jF1687wFu flgLNBnnAAoiRqHt/WiwIsoJAgQAux9qARA/7uNQHMO3KMocfSNtmQL3oubUJySRI0w/fu /S61IL5FhYW5zZ9FllkMdCS7EQQDpIPQO4IbfsJjd6Fv3gDnUqLZbfkh1VHLw2tgjneQDY TRzdqhhipT/cQgXXDWecE5sFW6gnd2V8ks4JpdY9Bj2rGaODbA0h9c8ErzsF2F0knN5sE6 CRFBphSL0DOUrEU2sSmlHnCVRzpVMbQwYC18vR08eh+JnS/RqyBWn2i2Wh+xrA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1675010222; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=u9sp1r7BUIkzhKck4jSqWJH4dEZwlSneyod44BpZzGw=; b=ybxxgwMnSUjFChd8vlMiRRC2tK+UjFRr/pQMsFppctiZ9lboTAPjQZBh01A8aNkUv053xb NgbrmfyR4UZ6Biz6plxuZt/Q6bQJzXGzS5vw2y+ze6HDp2h82gEuZxD3bAKxEf2yQh+gS/ D+gKyyhBqXOOXdgo7b6uTCmNVUsfgXjShivBLuVBN4OlgzmHOTl3Kp8HCUM+qvRIwXoQbB tJpau0WHtM/Plzo7OMoLDIVDZ1ig/n431bOJ05xWMG+ejSqvC9DXYmmezxRdchT6d4++EI N2Wt4vox8w+tq6IfQtiK2Hqco4WUF8SWCURNNCfy1Bku1BohHTHc59PYQDwFPw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1675010222; a=rsa-sha256; cv=none; b=nizwLEESIjk4/aPHTwv30ITiYAvCdSrgIwDmQfa85aKpcE0pfyQMYDZOm2cKBoGB9V2RBT xVEDZJn5uK57R2KHOFpgdtctJprraro2Z0+N4SbJhpxWRttae4DGfRojRH/GbGJJNM2Gp9 6JP1d/kDhTjQcLPaYFQKv19lBxBv4+7id7X2RS+xqm9mxgohBoxgdQGXwqLfv4PkILVjn0 hC5ikg0v4L7FbfGqpQ/fzBQSN+jiRtJbuv80RaNdDt8wsOYcED3Pe23it5kHJrZhISdr4Z oqrDlGt0b98yeSI9iHWYfcBky7t6hqX28EO6jsFuUoImTlMuusVQWhc8GJ1vcA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4P4cR233hzzbVL; Sun, 29 Jan 2023 16:37:02 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 30TGb27b092159; Sun, 29 Jan 2023 16:37:02 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 30TGb2Go092158; Sun, 29 Jan 2023 16:37:02 GMT (envelope-from git) Date: Sun, 29 Jan 2023 16:37:02 GMT Message-Id: <202301291637.30TGb2Go092158@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: "Alexander V. Chernikov" Subject: git: 15dbf5a24169 - main - netstat: export weight for single-path routes. List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: melifaro X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 15dbf5a24169d39fe951c3532f9dfbd8b55e8042 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by melifaro: URL: https://cgit.FreeBSD.org/src/commit/?id=15dbf5a24169d39fe951c3532f9dfbd8b55e8042 commit 15dbf5a24169d39fe951c3532f9dfbd8b55e8042 Author: Alexander V. Chernikov AuthorDate: 2023-01-29 16:27:31 +0000 Commit: Alexander V. Chernikov CommitDate: 2023-01-29 16:27:31 +0000 netstat: export weight for single-path routes. * Parse and export newly-added NL_RTA_WEIGHT attribute, providing path weight for a non-multipath route. This fixes a number of tests in sys/net/routing which rely on this data. * Remove handling of NL_RTA_KNH_ID in multipath routes, as it is not provided. * Improve kernel/user nexthop index export. As a result, for multipath routes: * nhg-kidx attribute represents kernel nhg index (always provided) * nhg-uidx attribute represents user-provided nhg index (if set) for non-multipath routes: * nhop-kidx attribute represents kernel nhop index (always provided) * nhop-udx attribute represents user-provided nexthop index (if set) --- usr.bin/netstat/common.h | 1 + usr.bin/netstat/route.c | 1 + usr.bin/netstat/route_netlink.c | 26 +++++++++++++++++++------- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/usr.bin/netstat/common.h b/usr.bin/netstat/common.h index d5aadd50b34e..113180c0a6f4 100644 --- a/usr.bin/netstat/common.h +++ b/usr.bin/netstat/common.h @@ -70,6 +70,7 @@ struct ifmap_entry { }; struct ifmap_entry *prepare_ifmap(size_t *ifmap_size); +extern const uint32_t rt_default_weight; struct rt_msghdr; struct nhops_map { diff --git a/usr.bin/netstat/route.c b/usr.bin/netstat/route.c index 0026ee924854..5de683ebfe7a 100644 --- a/usr.bin/netstat/route.c +++ b/usr.bin/netstat/route.c @@ -108,6 +108,7 @@ static void p_rtable_sysctl(int, int); static void p_rtentry_sysctl(const char *name, struct rt_msghdr *); static void domask(char *, size_t, u_long); +const uint32_t rt_default_weight = RT_DEFAULT_WEIGHT; /* * Print routing tables. diff --git a/usr.bin/netstat/route_netlink.c b/usr.bin/netstat/route_netlink.c index e4a56af4b8a9..17b15579b83b 100644 --- a/usr.bin/netstat/route_netlink.c +++ b/usr.bin/netstat/route_netlink.c @@ -150,7 +150,6 @@ struct rta_mpath_nh { uint8_t rtnh_flags; uint8_t rtnh_weight; uint32_t rtax_mtu; - uint32_t rta_knh_id; uint32_t rta_rtflags; }; @@ -164,7 +163,6 @@ 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_KNH_ID, .off = _OUT(rta_knh_id), .cb = snl_attr_get_uint32 }, { .type = NL_RTA_RTFLAGS, .off = _OUT(gw), .cb = snl_attr_get_uint32 }, { .type = NL_RTA_VIA, .off = _OUT(gw), .cb = snl_attr_get_ipvia }, }; @@ -225,6 +223,7 @@ struct nl_parsed_route { uint32_t rta_expire; uint32_t rta_table; uint32_t rta_knh_id; + uint32_t rta_nh_id; uint32_t rta_rtflags; uint32_t rtax_mtu; uint32_t rtax_weight; @@ -248,10 +247,12 @@ static const struct snl_attr_parser ps[] = { { .type = NL_RTA_METRICS, .arg = &metrics_parser, .cb = snl_attr_get_nested }, { .type = NL_RTA_MULTIPATH, .off = _OUT(rta_multipath), .cb = nlattr_get_multipath }, { .type = NL_RTA_KNH_ID, .off = _OUT(rta_knh_id), .cb = snl_attr_get_uint32 }, + { .type = NL_RTA_WEIGHT, .off = _OUT(rtax_weight), .cb = snl_attr_get_uint32 }, { .type = NL_RTA_RTFLAGS, .off = _OUT(rta_rtflags), .cb = snl_attr_get_uint32 }, { .type = NL_RTA_TABLE, .off = _OUT(rta_table), .cb = snl_attr_get_uint32 }, { .type = NL_RTA_VIA, .off = _OUT(rta_gw), .cb = snl_attr_get_ipvia }, { .type = NL_RTA_EXPIRES, .off = _OUT(rta_expire), .cb = snl_attr_get_uint32 }, + { .type = NL_RTA_NH_ID, .off = _OUT(rta_nh_id), .cb = snl_attr_get_uint32 }, }; static const struct snl_field_parser fprt[] = { @@ -320,7 +321,7 @@ struct sockaddr_dl_short { }; static void -p_path(struct nl_parsed_route *rt) +p_path(struct nl_parsed_route *rt, bool is_mpath) { struct sockaddr_in6 mask6; struct sockaddr *pmask = (struct sockaddr *)&mask6; @@ -337,6 +338,16 @@ p_path(struct nl_parsed_route *rt) p_flags(rt->rta_rtflags | RTF_UP, buffer); /* Output path weight as non-visual property */ xo_emit("{e:weight/%u}", rt->rtax_weight); + if (is_mpath) + xo_emit("{e:nhg-kidx/%u}", rt->rta_knh_id); + else + xo_emit("{e:nhop-kidx/%u}", rt->rta_knh_id); + if (rt->rta_nh_id != 0) { + if (is_mpath) + xo_emit("{e:nhg-uidx/%u}", rt->rta_nh_id); + else + xo_emit("{e:nhop-uidx/%u}", rt->rta_nh_id); + } memset(prettyname, 0, sizeof(prettyname)); if (rt->rta_oif < ifmap_size) { @@ -350,7 +361,7 @@ p_path(struct nl_parsed_route *rt) if (Wflag) { /* XXX: use=0? */ - xo_emit("{t:nhop/%*lu} ", wid.mtu, rt->rta_knh_id); + xo_emit("{t:nhop/%*lu} ", wid.mtu, is_mpath ? 0 : rt->rta_knh_id); if (rt->rtax_mtu != 0) xo_emit("{t:mtu/%*lu} ", wid.mtu, rt->rtax_mtu); @@ -378,6 +389,8 @@ p_rtentry_netlink(struct snl_state *ss, const char *name, struct nlmsghdr *hdr) struct nl_parsed_route rt = {}; if (!snl_parse_nlmsg(ss, hdr, &rtm_parser, &rt)) return; + if (rt.rtax_weight == 0) + rt.rtax_weight = rt_default_weight; if (rt.rta_multipath != NULL) { uint32_t orig_rtflags = rt.rta_rtflags; @@ -389,11 +402,10 @@ p_rtentry_netlink(struct snl_state *ss, const char *name, struct nlmsghdr *hdr) rt.rta_oif = nhop->ifindex; rt.rtax_weight = nhop->rtnh_weight; rt.rta_rtflags = nhop->rta_rtflags ? nhop->rta_rtflags : orig_rtflags; - rt.rta_knh_id = nhop->rta_knh_id; rt.rtax_mtu = nhop->rtax_mtu ? nhop->rtax_mtu : orig_mtu; xo_open_instance(name); - p_path(&rt); + p_path(&rt, true); xo_emit("\n"); xo_close_instance(name); } @@ -409,7 +421,7 @@ p_rtentry_netlink(struct snl_state *ss, const char *name, struct nlmsghdr *hdr) rt.rta_gw = (struct sockaddr *)&sdl_gw; xo_open_instance(name); - p_path(&rt); + p_path(&rt, false); xo_emit("\n"); xo_close_instance(name); }