Changeset View
Changeset View
Standalone View
Standalone View
head/sys/net/route.c
Show First 20 Lines • Show All 237 Lines • ▼ Show 20 Lines | rib_add_redirect(u_int fibnum, struct sockaddr *dst, struct sockaddr *gateway, | ||||
ifa_free(ifa); | ifa_free(ifa); | ||||
if (error != 0) { | if (error != 0) { | ||||
/* TODO: add per-fib redirect stats. */ | /* TODO: add per-fib redirect stats. */ | ||||
return (error); | return (error); | ||||
} | } | ||||
RT_LOCK(rc.rc_rt); | RT_LOCK(rc.rc_rt); | ||||
flags = rc.rc_rt->rt_flags; | flags = rc.rc_rt->rte_flags; | ||||
RT_UNLOCK(rc.rc_rt); | RT_UNLOCK(rc.rc_rt); | ||||
RTSTAT_INC(rts_dynamic); | RTSTAT_INC(rts_dynamic); | ||||
/* Send notification of a route addition to userland. */ | /* Send notification of a route addition to userland. */ | ||||
bzero(&info, sizeof(info)); | bzero(&info, sizeof(info)); | ||||
info.rti_info[RTAX_DST] = dst; | info.rti_info[RTAX_DST] = dst; | ||||
info.rti_info[RTAX_GATEWAY] = gateway; | info.rti_info[RTAX_GATEWAY] = gateway; | ||||
▲ Show 20 Lines • Show All 94 Lines • ▼ Show 20 Lines | |||||
int | int | ||||
rt_exportinfo(struct rtentry *rt, struct rt_addrinfo *info, int flags) | rt_exportinfo(struct rtentry *rt, struct rt_addrinfo *info, int flags) | ||||
{ | { | ||||
struct rt_metrics *rmx; | struct rt_metrics *rmx; | ||||
struct sockaddr *src, *dst; | struct sockaddr *src, *dst; | ||||
struct nhop_object *nh; | struct nhop_object *nh; | ||||
int sa_len; | int sa_len; | ||||
nh = rt->rt_nhop; | |||||
if (flags & NHR_COPY) { | if (flags & NHR_COPY) { | ||||
/* Copy destination if dst is non-zero */ | /* Copy destination if dst is non-zero */ | ||||
src = rt_key(rt); | src = rt_key(rt); | ||||
dst = info->rti_info[RTAX_DST]; | dst = info->rti_info[RTAX_DST]; | ||||
sa_len = src->sa_len; | sa_len = src->sa_len; | ||||
if (dst != NULL) { | if (dst != NULL) { | ||||
if (src->sa_len > dst->sa_len) | if (src->sa_len > dst->sa_len) | ||||
return (ENOMEM); | return (ENOMEM); | ||||
Show All 13 Lines | if (src != NULL && dst != NULL) { | ||||
*/ | */ | ||||
if (sa_len > dst->sa_len) | if (sa_len > dst->sa_len) | ||||
return (ENOMEM); | return (ENOMEM); | ||||
memcpy(dst, src, src->sa_len); | memcpy(dst, src, src->sa_len); | ||||
info->rti_addrs |= RTA_NETMASK; | info->rti_addrs |= RTA_NETMASK; | ||||
} | } | ||||
/* Copy gateway is set && dst is non-zero */ | /* Copy gateway is set && dst is non-zero */ | ||||
src = &rt->rt_nhop->gw_sa; | src = &nh->gw_sa; | ||||
dst = info->rti_info[RTAX_GATEWAY]; | dst = info->rti_info[RTAX_GATEWAY]; | ||||
if ((rt->rt_flags & RTF_GATEWAY) && src != NULL && dst != NULL){ | if ((nhop_get_rtflags(nh) & RTF_GATEWAY) && | ||||
src != NULL && dst != NULL) { | |||||
if (src->sa_len > dst->sa_len) | if (src->sa_len > dst->sa_len) | ||||
return (ENOMEM); | return (ENOMEM); | ||||
memcpy(dst, src, src->sa_len); | memcpy(dst, src, src->sa_len); | ||||
info->rti_addrs |= RTA_GATEWAY; | info->rti_addrs |= RTA_GATEWAY; | ||||
} | } | ||||
} else { | } else { | ||||
info->rti_info[RTAX_DST] = rt_key(rt); | info->rti_info[RTAX_DST] = rt_key(rt); | ||||
info->rti_addrs |= RTA_DST; | info->rti_addrs |= RTA_DST; | ||||
if (rt_mask(rt) != NULL) { | if (rt_mask(rt) != NULL) { | ||||
info->rti_info[RTAX_NETMASK] = rt_mask(rt); | info->rti_info[RTAX_NETMASK] = rt_mask(rt); | ||||
info->rti_addrs |= RTA_NETMASK; | info->rti_addrs |= RTA_NETMASK; | ||||
} | } | ||||
if (rt->rt_flags & RTF_GATEWAY) { | if (nhop_get_rtflags(nh) & RTF_GATEWAY) { | ||||
info->rti_info[RTAX_GATEWAY] = &rt->rt_nhop->gw_sa; | info->rti_info[RTAX_GATEWAY] = &nh->gw_sa; | ||||
info->rti_addrs |= RTA_GATEWAY; | info->rti_addrs |= RTA_GATEWAY; | ||||
} | } | ||||
} | } | ||||
nh = rt->rt_nhop; | |||||
rmx = info->rti_rmx; | rmx = info->rti_rmx; | ||||
if (rmx != NULL) { | if (rmx != NULL) { | ||||
info->rti_mflags |= RTV_MTU; | info->rti_mflags |= RTV_MTU; | ||||
rmx->rmx_mtu = nh->nh_mtu; | rmx->rmx_mtu = nh->nh_mtu; | ||||
} | } | ||||
info->rti_flags = rt->rt_flags | nhop_get_rtflags(nh); | info->rti_flags = rt->rte_flags | nhop_get_rtflags(nh); | ||||
info->rti_ifp = nh->nh_ifp; | info->rti_ifp = nh->nh_ifp; | ||||
info->rti_ifa = nh->nh_ifa; | info->rti_ifa = nh->nh_ifa; | ||||
if (flags & NHR_REF) { | if (flags & NHR_REF) { | ||||
if_ref(info->rti_ifp); | if_ref(info->rti_ifp); | ||||
ifa_ref(info->rti_ifa); | ifa_ref(info->rti_ifa); | ||||
} | } | ||||
return (0); | return (0); | ||||
▲ Show 20 Lines • Show All 151 Lines • ▼ Show 20 Lines | rt_ifdelroute(const struct rtentry *rt, const struct nhop_object *nh, void *arg) | ||||
if (nh->nh_ifp != ifp) | if (nh->nh_ifp != ifp) | ||||
return (0); | return (0); | ||||
/* | /* | ||||
* Protect (sorta) against walktree recursion problems | * Protect (sorta) against walktree recursion problems | ||||
* with cloned routes | * with cloned routes | ||||
*/ | */ | ||||
if ((rt->rt_flags & RTF_UP) == 0) | if ((rt->rte_flags & RTF_UP) == 0) | ||||
return (0); | return (0); | ||||
return (1); | return (1); | ||||
} | } | ||||
/* | /* | ||||
* Delete all remaining routes using this interface | * Delete all remaining routes using this interface | ||||
* Unfortuneatly the only way to do this is to slog through | * Unfortuneatly the only way to do this is to slog through | ||||
▲ Show 20 Lines • Show All 589 Lines • Show Last 20 Lines |