From nobody Fri Jan 13 21:24:54 2023 X-Original-To: dev-commits-src-branches@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 4NtvZZ4zksz2qkw3; Fri, 13 Jan 2023 21:24:54 +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 4NtvZZ4GQ8z40yb; Fri, 13 Jan 2023 21:24:54 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1673645094; 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=UfG07VskTCZVOvlAREuel9/5sZGOfj8Y43eN9wDLVKg=; b=OfKCz3VTqaeIVSgn7VfRuxpsCu6+TTijDNRSVL2p/FS07pDfm5An5wUUmvGQ5izcJOq+9Y 0BO4qJuCUaeoMaF/TYqznHJySxXGBb6GzZOdGUX6XjAURhCKOadGaDHkFhaAQV6YrusOGb s6mkpfC0KSxMT6t00sKmiafv5tjpvwY67f57fSGe9EMyy6VNcA/JSoWTzhku2osD9Ayy1c jmcxTNud07vdsHYYrg7nMke1VMv2Sa/tRoDUjj8tvpoi+Es2Y7ZFh1Je4aaA6P1MTQ4UQE PApyewQ3ZvCy0x0CmKvoGXrgq2GLzGf4QJySVTMuiwudmx/CwhhnMUlOA+ZEEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1673645094; 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=UfG07VskTCZVOvlAREuel9/5sZGOfj8Y43eN9wDLVKg=; b=BianhkCLY3Ko4jlnqPwdqzMF8XmIg3GsgFYB3/sRF8hNtGOHGreNNMINuWIOHMsql5yRLk vm0PTfmq0Ehaz2Y1d+CZUbWsYp/jMgP+Zjqlfg6vYnMHd7A49mAyJpnkJv39OThavRpCo6 oyv5r81GYuVMrLorRPuG0uZsNv5qfnLF7e2fXzUVD4zSbyTiM6GzgynTfmjSPhBZtz2vO2 eeqJpSZEt9bq/SzghBixJqFefYQ9OeZY2NIoTIdTxGE4RMyXmNeTsj8JNHenzB6y4t+zW9 Zk6Qbado27vLCeDhUsbxWU+O6OyXr0MbTbQsHqRU9V1f0oxjjSZQKkDAv/bNwg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1673645094; a=rsa-sha256; cv=none; b=Rlr8XKqMa5FE+mXOLIAFQrO9K5d1k6V9thE57rD/4LfwTKdMGbDebdfrDJMVk9I1AyaQNK y1O49G4PRlo8TkZSwcCPJ9L4aD1XzSihqKkAiTeYmngtwmuRNdpbkQnaD8davqP+VC3KV4 L7sb8KiiIlCBJcTU/V/Fqm07HUG6JVyh1e5BVybfZi6avPMKxTndaz/djpmiLKR+3mQSdG KY810noSOxMDhjeduQba9naUTysEIU3fJV8o6WVxqYQHPxhIid67XicRuaJS4Cib82Sjpi LtrlGimH3VLFRtdxLn5+OdagTLHPcSmecw0c+BWbv9OIpNFDROeNqUE6VF8VTA== 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 4NtvZZ2zL5zMv8; Fri, 13 Jan 2023 21:24:54 +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 30DLOsvr041003; Fri, 13 Jan 2023 21:24:54 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 30DLOsOv041002; Fri, 13 Jan 2023 21:24:54 GMT (envelope-from git) Date: Fri, 13 Jan 2023 21:24:54 GMT Message-Id: <202301132124.30DLOsOv041002@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: "Alexander V. Chernikov" Subject: git: e6466ec48d29 - stable/13 - routing: remove info argument from add/change_route_nhop(). List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@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/stable/13 X-Git-Reftype: branch X-Git-Commit: e6466ec48d295b7937222b0b75b703c08e59604e Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by melifaro: URL: https://cgit.FreeBSD.org/src/commit/?id=e6466ec48d295b7937222b0b75b703c08e59604e commit e6466ec48d295b7937222b0b75b703c08e59604e Author: Alexander V. Chernikov AuthorDate: 2022-07-28 13:41:11 +0000 Commit: Alexander V. Chernikov CommitDate: 2023-01-13 21:18:26 +0000 routing: remove info argument from add/change_route_nhop(). Currently, rt_addrinfo(info) serves as a main "transport" moving state between various functions inside the routing subsystem. As all of the fields are filled in directly by the customers, it is problematic to maintain consistency, resulting in repeated checks inside many functions. Additionally, there are multiple ways of specifying the same value (RTAX_IFP vs rti_ifp / rti_ifa) and so on. With the upcoming nhop(9) kpi it is possible to store all of the required state in the nexthops in the consistent fashion, reducing the need to use "info" in the KPI calls. Finally, rt_addrinfo structure format was derived from the rtsock wire format, which is different from other kernel routing users or netlink. This cleanup simplifies upcoming nhop(9) kpi and netlink introduction. Reviewed by: zlei.huang@gmail.com Differential Revision: https://reviews.freebsd.org/D35972 MFC after: 2 weeks (cherry picked from commit 29029b06a6f7fd51c34c9db88cc98a6653ee5046) --- sys/net/route/mpath_ctl.c | 2 +- sys/net/route/route_ctl.c | 35 ++++++++++++++--------------------- sys/net/route/route_var.h | 3 +-- 3 files changed, 16 insertions(+), 24 deletions(-) diff --git a/sys/net/route/mpath_ctl.c b/sys/net/route/mpath_ctl.c index 8351437e34c6..db3c757e818d 100644 --- a/sys/net/route/mpath_ctl.c +++ b/sys/net/route/mpath_ctl.c @@ -188,7 +188,7 @@ del_route_mpath(struct rib_head *rh, struct rt_addrinfo *info, nhop_free_any(rnd.rnd_nhop); return (ESRCH); } - error = change_route_nhop(rh, rt, info, &rnd, rc); + error = change_route_nhop(rh, rt, &rnd, rc); } return (error); } diff --git a/sys/net/route/route_ctl.c b/sys/net/route/route_ctl.c index 1127c504400e..80682b7f3b87 100644 --- a/sys/net/route/route_ctl.c +++ b/sys/net/route/route_ctl.c @@ -80,8 +80,7 @@ struct rib_subscription { static int add_route(struct rib_head *rnh, struct rt_addrinfo *info, struct rib_cmd_info *rc); static int add_route_nhop(struct rib_head *rnh, struct rtentry *rt, - struct rt_addrinfo *info, struct route_nhop_data *rnd, - struct rib_cmd_info *rc); + struct route_nhop_data *rnd, struct rib_cmd_info *rc); static int del_route(struct rib_head *rnh, struct rt_addrinfo *info, struct rib_cmd_info *rc); static int change_route(struct rib_head *rnh, struct rt_addrinfo *info, @@ -618,6 +617,8 @@ check_gateway(struct rib_head *rnh, struct sockaddr *dst, /* * Creates rtentry and nexthop based on @info data. * Return 0 and fills in rtentry into @prt on success, + * Note: rtentry mask will be set to RTAX_NETMASK, thus its pointer is required + * to be stable till the end of the operation (radix rt insertion/change/removal). * return errno otherwise. */ static int @@ -685,6 +686,8 @@ create_rtentry(struct rib_head *rnh, struct rt_addrinfo *info, rt_maskedcopy(dst, ndst, netmask); } else bcopy(dst, ndst, dst->sa_len); + /* Set netmask to the storage from info. It will be updated upon insertion */ + rt_mask(rt) = netmask; /* * We use the ifa reference returned by rt_getifa_fib(). @@ -716,7 +719,7 @@ add_route(struct rib_head *rnh, struct rt_addrinfo *info, nh = rt->rt_nhop; RIB_WLOCK(rnh); - error = add_route_nhop(rnh, rt, info, &rnd_add, rc); + error = add_route_nhop(rnh, rt, &rnd_add, rc); if (error == 0) { RIB_WUNLOCK(rnh); return (0); @@ -737,7 +740,7 @@ add_route(struct rib_head *rnh, struct rt_addrinfo *info, /* Check if new route has higher preference */ if (can_override_nhop(info, nh_orig) > 0) { /* Update nexthop to the new route */ - change_route_nhop(rnh, rt_orig, info, &rnd_add, rc); + change_route_nhop(rnh, rt_orig, &rnd_add, rc); RIB_WUNLOCK(rnh); uma_zfree(V_rtzone, rt); nhop_free(nh_orig); @@ -851,8 +854,7 @@ rt_unlinkrte(struct rib_head *rnh, struct rt_addrinfo *info, struct rib_cmd_info * Remove the item from the tree and return it. * Complain if it is not there and do no more processing. */ - rn = rnh->rnh_deladdr(info->rti_info[RTAX_DST], - info->rti_info[RTAX_NETMASK], &rnh->head); + rn = rnh->rnh_deladdr(rt_key_const(rt), rt_mask_const(rt), &rnh->head); if (rn == NULL) return (ESRCH); @@ -1084,21 +1086,16 @@ change_route(struct rib_head *rnh, struct rt_addrinfo *info, */ static int add_route_nhop(struct rib_head *rnh, struct rtentry *rt, - struct rt_addrinfo *info, struct route_nhop_data *rnd, - struct rib_cmd_info *rc) + struct route_nhop_data *rnd, struct rib_cmd_info *rc) { - struct sockaddr *ndst, *netmask; struct radix_node *rn; int error = 0; RIB_WLOCK_ASSERT(rnh); - ndst = (struct sockaddr *)rt_key(rt); - netmask = info->rti_info[RTAX_NETMASK]; - rt->rt_nhop = rnd->rnd_nhop; rt->rt_weight = rnd->rnd_weight; - rn = rnh->rnh_addaddr(ndst, netmask, &rnh->head, rt->rt_nodes); + rn = rnh->rnh_addaddr(rt_key(rt), rt_mask_const(rt), &rnh->head, rt->rt_nodes); if (rn != NULL) { if (!NH_IS_NHGRP(rnd->rnd_nhop) && nhop_get_expire(rnd->rnd_nhop)) @@ -1129,8 +1126,7 @@ add_route_nhop(struct rib_head *rnh, struct rtentry *rt, */ int change_route_nhop(struct rib_head *rnh, struct rtentry *rt, - struct rt_addrinfo *info, struct route_nhop_data *rnd, - struct rib_cmd_info *rc) + struct route_nhop_data *rnd, struct rib_cmd_info *rc) { struct nhop_object *nh_orig; @@ -1146,12 +1142,9 @@ change_route_nhop(struct rib_head *rnh, struct rtentry *rt, tmproutes_update(rnh, rt, rnd->rnd_nhop); } else { /* Route deletion requested. */ - struct sockaddr *ndst, *netmask; struct radix_node *rn; - ndst = (struct sockaddr *)rt_key(rt); - netmask = info->rti_info[RTAX_NETMASK]; - rn = rnh->rnh_deladdr(ndst, netmask, &rnh->head); + rn = rnh->rnh_deladdr(rt_key_const(rt), rt_mask_const(rt), &rnh->head); if (rn == NULL) return (ESRCH); rt = RNTORT(rn); @@ -1203,7 +1196,7 @@ change_route_conditional(struct rib_head *rnh, struct rtentry *rt, if (rt_new == NULL) { if (rnd_orig->rnd_nhop == NULL) - error = add_route_nhop(rnh, rt, info, rnd_new, rc); + error = add_route_nhop(rnh, rt, rnd_new, rc); else { /* * Prefix does not exist, which was not our assumption. @@ -1220,7 +1213,7 @@ change_route_conditional(struct rib_head *rnh, struct rtentry *rt, * Nhop/mpath group hasn't changed. Flip * to the new precalculated one and return */ - error = change_route_nhop(rnh, rt_new, info, rnd_new, rc); + error = change_route_nhop(rnh, rt_new, rnd_new, rc); } else { /* Update and retry */ rnd_orig->rnd_nhop = rt_new->rt_nhop; diff --git a/sys/net/route/route_var.h b/sys/net/route/route_var.h index 60891026c00a..2998c51b608d 100644 --- a/sys/net/route/route_var.h +++ b/sys/net/route/route_var.h @@ -220,8 +220,7 @@ void tmproutes_destroy(struct rib_head *rh); /* route_ctl.c */ struct route_nhop_data; int change_route_nhop(struct rib_head *rnh, struct rtentry *rt, - struct rt_addrinfo *info, struct route_nhop_data *rnd, - struct rib_cmd_info *rc); + struct route_nhop_data *rnd, struct rib_cmd_info *rc); int change_route_conditional(struct rib_head *rnh, struct rtentry *rt, struct rt_addrinfo *info, struct route_nhop_data *nhd_orig, struct route_nhop_data *nhd_new, struct rib_cmd_info *rc);