From nobody Sat May 27 11:14:15 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 4QSzh73BXMz4WtWb; Sat, 27 May 2023 11:14:15 +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 4QSzh72X3pz3vS2; Sat, 27 May 2023 11:14:15 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1685186055; 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=RjVZ6uJhqDPvh0Itjckv+d9YHJ9ZzY/T5R21wTl89Nw=; b=GOS6+5WpAP/vlFf6MFN2FXkWbisG34IbVmD9+vELuVf/vdRwgeS1ALXQjOrwgwtf/+/CJY BxRINyPcuLkFD1ahg1LGzRC4+oyQHDDlllQu6LuvjdE3/1P4t8t8u48Odabx/rARmRZugW 2fy+iVsn9t1S9eX7znrkwTFFS+/K6Wzb5LdzuvStZub1KS+iW+TEZKsMbIeBJY9+V8qC7x 4crzTeSE4ngHJoe05ZZHzclbFuVFWWrqGZg9b4n52srQe999BXISGdDp0eYQ8UtHUXAJet 2GZ+4TZOPMRJrYConUDt5rgX3z/k+bOwBzMYLB0TcWXJNFaIXfTuKTtzu+uPfA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1685186055; 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=RjVZ6uJhqDPvh0Itjckv+d9YHJ9ZzY/T5R21wTl89Nw=; b=vsZ/o6fiJyspT+hTaaSadCMQjgL0cjwLNWujF08rSXxNC5FcZbIp356cjEPew4mBEp5w7y OmOlHqPkl9QWjUNl1OVD4ngatz24lqeVoGKzUmTD7VRP5rXqzY3tC1aJbILYZMRAD8X/OX bDwOgzil8HOvRHgImNeEong/6GpwKecgaSTVt5OvWJIN3eZJJVYnuA/nepaQ5oul3LUVcF q2mDnzjYWaLN3Y9QzuE4ZsQrj7MiPoLO6nYNgepY4tkS/loLeTWwzbzAoaHqadyTYfxufm 36gs52t4NiTTwLpvHICnyx84bGxy10fPrd4HJD3aZnHLxm91HDWsmIeF8h8IfQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1685186055; a=rsa-sha256; cv=none; b=mdQjOUC+D3ktNgwAP/S3RHLFP0ZKGHk1+VPVdPEoY7h/0RkkTkRlYfqhg9aewANIYgjdTY 75Hj0d9KSaTKulhxI+UUxmYsZ3iGoy6C/fLaVuPjTr2AyQOaaxf6ejyCutqejHmpgrS3+t /he4IB2HCeIbG18doHEroPVmp314gqtUjsM+fAhddr+o1ATniXRf/A/2OfEy5IimCicVTO +TJSO7IvaqdCVAm9hwDx+wQ8rrXk6tMykcOdD3GyOmDsviYXhv5Vp9OtX/ddmyNBGRKnkG fGSDYc5m7pp4W9k8RX9flUVBRvEE2CAwvPnuK1RGUc0JG2gA50j2I2MO6wbrhA== 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 4QSzh71YbBzmQ6; Sat, 27 May 2023 11:14:15 +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 34RBEFHX007237; Sat, 27 May 2023 11:14:15 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 34RBEF4Z007236; Sat, 27 May 2023 11:14:15 GMT (envelope-from git) Date: Sat, 27 May 2023 11:14:15 GMT Message-Id: <202305271114.34RBEF4Z007236@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: 656a39c1a062 - main - netlink: use newly-added snl(3) array parsing for handling multipath 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: 656a39c1a062411dca09d1566a7a0709c30f3bc7 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by melifaro: URL: https://cgit.FreeBSD.org/src/commit/?id=656a39c1a062411dca09d1566a7a0709c30f3bc7 commit 656a39c1a062411dca09d1566a7a0709c30f3bc7 Author: Alexander V. Chernikov AuthorDate: 2023-05-27 11:11:04 +0000 Commit: Alexander V. Chernikov CommitDate: 2023-05-27 11:13:14 +0000 netlink: use newly-added snl(3) array parsing for handling multipath routes. MFC after: 2 weeks --- sbin/route/route_netlink.c | 12 +++++------ sys/netlink/netlink_snl_route_parsers.h | 37 +++++++-------------------------- usr.bin/netstat/route_netlink.c | 6 +++--- 3 files changed, 17 insertions(+), 38 deletions(-) diff --git a/sbin/route/route_netlink.c b/sbin/route/route_netlink.c index 01494fbefd51..0dbd90151e10 100644 --- a/sbin/route/route_netlink.c +++ b/sbin/route/route_netlink.c @@ -533,14 +533,14 @@ print_nlmsg_route(struct nl_helper *h, struct nlmsghdr *hdr, return; } - if (r.rta_multipath != NULL) { + if (r.rta_multipath.num_nhops != 0) { bool first = true; memset(buf, ' ', sizeof(buf)); buf[len] = '\0'; - for (int i = 0; i < r.rta_multipath->num_nhops; i++) { - struct rta_mpath_nh *nh = &r.rta_multipath->nhops[i]; + for (uint32_t i = 0; i < r.rta_multipath.num_nhops; i++) { + struct rta_mpath_nh *nh = r.rta_multipath.nhops[i]; if (!first) printf("%s", buf); @@ -834,9 +834,9 @@ flushroute_one(struct nl_helper *h, struct snl_parsed_route *r) print_nlmsg(h, hdr, &attrs); } else { - if (r->rta_multipath != NULL) { - for (int i = 0; i < r->rta_multipath->num_nhops; i++) { - struct rta_mpath_nh *nh = &r->rta_multipath->nhops[i]; + if (r->rta_multipath.num_nhops != 0) { + for (uint32_t i = 0; i < r->rta_multipath.num_nhops; i++) { + struct rta_mpath_nh *nh = r->rta_multipath.nhops[i]; print_flushed_route(r, nh->gw); } diff --git a/sys/netlink/netlink_snl_route_parsers.h b/sys/netlink/netlink_snl_route_parsers.h index 0ab338cbe6e8..a89462210133 100644 --- a/sys/netlink/netlink_snl_route_parsers.h +++ b/sys/netlink/netlink_snl_route_parsers.h @@ -90,48 +90,27 @@ SNL_DECLARE_PARSER_EXT(_mpath_nh_parser, sizeof(struct rtnexthop), _cb_p_mp_nh); struct rta_mpath { - int num_nhops; - struct rta_mpath_nh nhops[0]; + uint32_t num_nhops; + struct rta_mpath_nh **nhops; }; static bool -nlattr_get_multipath(struct snl_state *ss, struct nlattr *nla, const void *arg __unused, +nlattr_get_multipath(struct snl_state *ss, struct nlattr *nla, const void *arg, void *target) { - int data_len = nla->nla_len - sizeof(struct nlattr); - struct rtnexthop *rtnh; + uint32_t start_size = 4; - int max_nhops = data_len / sizeof(struct rtnexthop); - size_t sz = (max_nhops + 2) * sizeof(struct rta_mpath_nh); + while (start_size < NLA_DATA_LEN(nla) / sizeof(struct rtnexthop)) + start_size *= 2; - struct rta_mpath *mp = snl_allocz(ss, sz); - if (mp == NULL) - return (false); - mp->num_nhops = 0; - - for (rtnh = (struct rtnexthop *)(void *)(nla + 1); data_len > 0; ) { - struct rta_mpath_nh *mpnh = &mp->nhops[mp->num_nhops++]; - - if (!snl_parse_header(ss, rtnh, rtnh->rtnh_len, &_mpath_nh_parser, mpnh)) - return (false); - - int len = NL_ITEM_ALIGN(rtnh->rtnh_len); - data_len -= len; - rtnh = (struct rtnexthop *)(void *)((char *)rtnh + len); - } - if (data_len != 0 || mp->num_nhops == 0) { - return (false); - } - - *((struct rta_mpath **)target) = mp; - return (true); + return (snl_attr_get_parray_sz(ss, nla, start_size, &_mpath_nh_parser, target)); } struct snl_parsed_route { struct sockaddr *rta_dst; struct sockaddr *rta_gw; struct nlattr *rta_metrics; - struct rta_mpath *rta_multipath; + struct rta_mpath rta_multipath; uint32_t rta_expires; uint32_t rta_oif; uint32_t rta_expire; diff --git a/usr.bin/netstat/route_netlink.c b/usr.bin/netstat/route_netlink.c index 6e7e505c9619..3b1880fb9d90 100644 --- a/usr.bin/netstat/route_netlink.c +++ b/usr.bin/netstat/route_netlink.c @@ -237,11 +237,11 @@ p_rtentry_netlink(struct snl_state *ss, const char *name, struct nlmsghdr *hdr) if (rt.rtax_weight == 0) rt.rtax_weight = rt_default_weight; - if (rt.rta_multipath != NULL) { + if (rt.rta_multipath.num_nhops != 0) { uint32_t orig_rtflags = rt.rta_rtflags; uint32_t orig_mtu = rt.rtax_mtu; - for (int i = 0; i < rt.rta_multipath->num_nhops; i++) { - struct rta_mpath_nh *nhop = &rt.rta_multipath->nhops[i]; + for (uint32_t i = 0; i < rt.rta_multipath.num_nhops; i++) { + struct rta_mpath_nh *nhop = rt.rta_multipath.nhops[i]; rt.rta_gw = nhop->gw; rt.rta_oif = nhop->ifindex;