From nobody Mon Aug 15 06:48:58 2022 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 4M5lHZ6lD9z4YVK0; Mon, 15 Aug 2022 06:48:58 +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 4M5lHZ6JZYz3gGG; Mon, 15 Aug 2022 06:48:58 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1660546138; 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=Yq8ZSslWLAMz+OEfFcYO90fP5I2tkVGOvvYlZYp/jcU=; b=LSITrldHXtK6JIv5iq5VilY4yN6BSd8ZwVfPksLrfkwiVfUNaMJHhlGQfnHIlRJ5B8Kv0X 9vz/LGkBcv1fqRnaasM47OrptSH7bbL1qwy/5DkDFE7pYdC3SPhQAOoXjQAozzYCo7WFQo n+948430NSDl3+WC+abRkvmvDgp01E/YtSb/m/tgzfjbXnPSvceCpmJsS4Hgi1BTrX5S/C TD4TlyBMxzsJzoiBBgV89dVOfniKYg+A0k6ehpQYLe9zIXlhXbp1NA0C1+LoqKpZqQlW+m oc+TLJFEVk+RAGpgQstX/sDKQiJ3NlqPF+FEpM5ht0v9XDbQIoQUSvQynh7f8A== 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 4M5lHZ5MVzzLMV; Mon, 15 Aug 2022 06:48:58 +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 27F6mwlM000354; Mon, 15 Aug 2022 06:48:58 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 27F6mw82000353; Mon, 15 Aug 2022 06:48:58 GMT (envelope-from git) Date: Mon, 15 Aug 2022 06:48:58 GMT Message-Id: <202208150648.27F6mw82000353@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: 036f1bc6139e - main - routing: retire rib_lookup_info() 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: 036f1bc6139e8fc6d3aca61a5ab93ffc5715cf74 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1660546138; 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=Yq8ZSslWLAMz+OEfFcYO90fP5I2tkVGOvvYlZYp/jcU=; b=MbUPw36ev5RdCl5OYiLk8KESdE8k83L2ShFnrP6BFoka6d4dsEgPH72HCCJab2qCgGRB/j V1pb19jTAH0bldUAuoNRWep0mmnuNvF5f6KPLgVi6nCxeOhFrXuNEIb6ScveN4TcYZJEUZ NoBUR5X5dUSAOOxlNfckmLonrXGONTJkF1EagBUO/IAZO5t9ItQNy9TCzU7th6a9teLgg9 YBbF2aOtbNTtgbdr1NnJOvjV1Em1L1VEWBwjqusDc5GzkwVUZkTtCu8JyhaK3jtD9feqTS 5CKXuLEU1o8b+liTsY6g9BC9maL6ND/AwoghT4ubk9eXJETFmA0TTLlt5sqndQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1660546138; a=rsa-sha256; cv=none; b=G7E+EZ8kyEnFpoh1jh3WpU64XY0jJfBGmW3Nsb/nH5I1qY+evRxWDb7JIu0uFQIxmsEItv WDPF+AWjhpQxTvwLG++Hh3BMAv+3DhHMbkH7Ny93c77emEjHNFegs6Qx+bBjcpV1NPdBcM TdSf5aty9jvCln18oQNj5Pi+07w+04qmgUULw2bC8S2ofzoqSCh6oAwLgiOCeYosgo1Pfd vjG45vZLj1gj3W7IYnE6zeKqr3+HvqKmNLNHO3s0DWT9zXqEnk5wkqmR9yrTaVOBWN1x5F RpItQ3vrjZcYT5OR+kWfLV8muSuq7+WCNY76OKqZpz8hlXKzZlUDivfSEYKPAw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by melifaro: URL: https://cgit.FreeBSD.org/src/commit/?id=036f1bc6139e8fc6d3aca61a5ab93ffc5715cf74 commit 036f1bc6139e8fc6d3aca61a5ab93ffc5715cf74 Author: Alexander V. Chernikov AuthorDate: 2022-08-14 10:39:06 +0000 Commit: Alexander V. Chernikov CommitDate: 2022-08-15 06:46:30 +0000 routing: retire rib_lookup_info() This function was added in pre-epoch era ( 9a1b64d5a0224 ) to provide public rtentry access interface & hide rtentry internals. The implementation is based on the large on-stack copying and refcounting of the referenced objects (ifa/ifp). It has become obsolete after epoch & nexthop introduction. Convert the last remaining user and remove the function itself. Differential Revision: https://reviews.freebsd.org/D36197 --- sys/net/route.c | 145 ------------------------------------------------------- sys/net/route.h | 3 -- sys/net/rtsock.c | 19 ++------ 3 files changed, 4 insertions(+), 163 deletions(-) diff --git a/sys/net/route.c b/sys/net/route.c index 8198bc0883be..e4b404390ea4 100644 --- a/sys/net/route.c +++ b/sys/net/route.c @@ -317,151 +317,6 @@ ifa_ifwithroute(int flags, const struct sockaddr *dst, return (ifa); } -/* - * Copy most of @rt data into @info. - * - * If @flags contains NHR_COPY, copies dst,netmask and gw to the - * pointers specified by @info structure. Assume such pointers - * are zeroed sockaddr-like structures with sa_len field initialized - * to reflect size of the provided buffer. if no NHR_COPY is specified, - * point dst,netmask and gw @info fields to appropriate @rt values. - * - * if @flags contains NHR_REF, do refcouting on rt_ifp and rt_ifa. - * - * Returns 0 on success. - */ -static int -rt_exportinfo(struct rtentry *rt, struct nhop_object *nh, - struct rt_addrinfo *info, int flags) -{ - struct rt_metrics *rmx; - struct sockaddr *src, *dst; - int sa_len; - - if (flags & NHR_COPY) { - /* Copy destination if dst is non-zero */ - src = rt_key(rt); - dst = info->rti_info[RTAX_DST]; - sa_len = src->sa_len; - if (dst != NULL) { - if (src->sa_len > dst->sa_len) - return (ENOMEM); - memcpy(dst, src, src->sa_len); - info->rti_addrs |= RTA_DST; - } - - /* Copy mask if set && dst is non-zero */ - src = rt_mask(rt); - dst = info->rti_info[RTAX_NETMASK]; - if (src != NULL && dst != NULL) { - /* - * Radix stores different value in sa_len, - * assume rt_mask() to have the same length - * as rt_key() - */ - if (sa_len > dst->sa_len) - return (ENOMEM); - memcpy(dst, src, src->sa_len); - info->rti_addrs |= RTA_NETMASK; - } - - /* Copy gateway is set && dst is non-zero */ - src = &nh->gw_sa; - dst = info->rti_info[RTAX_GATEWAY]; - if ((nhop_get_rtflags(nh) & RTF_GATEWAY) && - src != NULL && dst != NULL) { - if (src->sa_len > dst->sa_len) - return (ENOMEM); - memcpy(dst, src, src->sa_len); - info->rti_addrs |= RTA_GATEWAY; - } - } else { - info->rti_info[RTAX_DST] = rt_key(rt); - info->rti_addrs |= RTA_DST; - if (rt_mask(rt) != NULL) { - info->rti_info[RTAX_NETMASK] = rt_mask(rt); - info->rti_addrs |= RTA_NETMASK; - } - if (nhop_get_rtflags(nh) & RTF_GATEWAY) { - info->rti_info[RTAX_GATEWAY] = &nh->gw_sa; - info->rti_addrs |= RTA_GATEWAY; - } - } - - rmx = info->rti_rmx; - if (rmx != NULL) { - info->rti_mflags |= RTV_MTU; - rmx->rmx_mtu = nh->nh_mtu; - } - - info->rti_flags = rt->rte_flags | nhop_get_rtflags(nh); - info->rti_ifp = nh->nh_ifp; - info->rti_ifa = nh->nh_ifa; - if (flags & NHR_REF) { - if_ref(info->rti_ifp); - ifa_ref(info->rti_ifa); - } - - return (0); -} - -/* - * Lookups up route entry for @dst in RIB database for fib @fibnum. - * Exports entry data to @info using rt_exportinfo(). - * - * If @flags contains NHR_REF, refcouting is performed on rt_ifp and rt_ifa. - * All references can be released later by calling rib_free_info(). - * - * Returns 0 on success. - * Returns ENOENT for lookup failure, ENOMEM for export failure. - */ -int -rib_lookup_info(uint32_t fibnum, const struct sockaddr *dst, uint32_t flags, - uint32_t flowid, struct rt_addrinfo *info) -{ - RIB_RLOCK_TRACKER; - struct rib_head *rh; - struct radix_node *rn; - struct rtentry *rt; - struct nhop_object *nh; - int error; - - KASSERT((fibnum < rt_numfibs), ("rib_lookup_rte: bad fibnum")); - rh = rt_tables_get_rnh(fibnum, dst->sa_family); - if (rh == NULL) - return (ENOENT); - - RIB_RLOCK(rh); - rn = rh->rnh_matchaddr(__DECONST(void *, dst), &rh->head); - if (rn != NULL && ((rn->rn_flags & RNF_ROOT) == 0)) { - rt = RNTORT(rn); - nh = nhop_select(rt->rt_nhop, flowid); - /* Ensure route & ifp is UP */ - if (RT_LINK_IS_UP(nh->nh_ifp)) { - flags = (flags & NHR_REF) | NHR_COPY; - error = rt_exportinfo(rt, nh, info, flags); - RIB_RUNLOCK(rh); - - return (error); - } - } - RIB_RUNLOCK(rh); - - return (ENOENT); -} - -/* - * Releases all references acquired by rib_lookup_info() when - * called with NHR_REF flags. - */ -void -rib_free_info(struct rt_addrinfo *info) -{ - - ifa_free(info->rti_ifa); - if_rele(info->rti_ifp); -} - /* * Delete Routes for a Network Interface * diff --git a/sys/net/route.h b/sys/net/route.h index 47e4773b4700..348ba16d6e88 100644 --- a/sys/net/route.h +++ b/sys/net/route.h @@ -440,9 +440,6 @@ void rt_flushifroutes(struct ifnet *ifp); * but this will change.. */ int rtioctl_fib(u_long, caddr_t, u_int); -int rib_lookup_info(uint32_t, const struct sockaddr *, uint32_t, uint32_t, - struct rt_addrinfo *); -void rib_free_info(struct rt_addrinfo *info); /* New API */ void rib_flush_routes_family(int family); diff --git a/sys/net/rtsock.c b/sys/net/rtsock.c index 38f7870dc6dd..f0fcc7ab9004 100644 --- a/sys/net/rtsock.c +++ b/sys/net/rtsock.c @@ -630,16 +630,7 @@ fill_addrinfo(struct rt_msghdr *rtm, int len, struct linear_buffer *lb, u_int fi */ if (info->rti_info[RTAX_GATEWAY] != NULL && info->rti_info[RTAX_GATEWAY]->sa_family != AF_LINK) { - struct rt_addrinfo ginfo; - struct sockaddr *gdst; - struct sockaddr_storage ss; - - bzero(&ginfo, sizeof(ginfo)); - bzero(&ss, sizeof(ss)); - ss.ss_len = sizeof(ss); - - ginfo.rti_info[RTAX_GATEWAY] = (struct sockaddr *)&ss; - gdst = info->rti_info[RTAX_GATEWAY]; + struct nhop_object *nh; /* * A host route through the loopback interface is @@ -651,13 +642,11 @@ fill_addrinfo(struct rt_msghdr *rtm, int len, struct linear_buffer *lb, u_int fi * AF_LINK sa_family type of the gateway, and the * rt_ifp has the IFF_LOOPBACK flag set. */ - if (rib_lookup_info(fibnum, gdst, NHR_REF, 0, &ginfo) == 0) { - if (ss.ss_family == AF_LINK && - ginfo.rti_ifp->if_flags & IFF_LOOPBACK) { + nh = rib_lookup(fibnum, info->rti_info[RTAX_GATEWAY], NHR_NONE, 0); + if (nh != NULL && nh->gw_sa.sa_family == AF_LINK && + nh->nh_ifp->if_flags & IFF_LOOPBACK) { info->rti_flags &= ~RTF_GATEWAY; info->rti_flags |= RTF_GWFLAG_COMPAT; - } - rib_free_info(&ginfo); } }