git: 036f1bc6139e - main - routing: retire rib_lookup_info()
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 15 Aug 2022 06:48:58 UTC
The branch main has been updated by melifaro: URL: https://cgit.FreeBSD.org/src/commit/?id=036f1bc6139e8fc6d3aca61a5ab93ffc5715cf74 commit 036f1bc6139e8fc6d3aca61a5ab93ffc5715cf74 Author: Alexander V. Chernikov <melifaro@FreeBSD.org> AuthorDate: 2022-08-14 10:39:06 +0000 Commit: Alexander V. Chernikov <melifaro@FreeBSD.org> 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); } }