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
This commit is contained in:
parent
35b587464a
commit
036f1bc613
145
sys/net/route.c
145
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
|
||||
*
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user