Changeset View
Changeset View
Standalone View
Standalone View
head/sys/net/route.c
Show First 20 Lines • Show All 208 Lines • ▼ Show 20 Lines | rib_add_redirect(u_int fibnum, struct sockaddr *dst, struct sockaddr *gateway, | ||||
NET_EPOCH_ASSERT(); | NET_EPOCH_ASSERT(); | ||||
if (rt_tables_get_rnh(fibnum, dst->sa_family) == NULL) | if (rt_tables_get_rnh(fibnum, dst->sa_family) == NULL) | ||||
return (EAFNOSUPPORT); | return (EAFNOSUPPORT); | ||||
/* Verify the allowed flag mask. */ | /* Verify the allowed flag mask. */ | ||||
KASSERT(((flags & ~(RTF_GATEWAY)) == 0), | KASSERT(((flags & ~(RTF_GATEWAY)) == 0), | ||||
("invalid redirect flags: %x", flags)); | ("invalid redirect flags: %x", flags)); | ||||
flags |= RTF_HOST | RTF_DYNAMIC; | |||||
/* Get the best ifa for the given interface and gateway. */ | /* Get the best ifa for the given interface and gateway. */ | ||||
if ((ifa = ifaof_ifpforaddr(gateway, ifp)) == NULL) | if ((ifa = ifaof_ifpforaddr(gateway, ifp)) == NULL) | ||||
return (ENETUNREACH); | return (ENETUNREACH); | ||||
ifa_ref(ifa); | ifa_ref(ifa); | ||||
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; | ||||
info.rti_ifa = ifa; | info.rti_ifa = ifa; | ||||
info.rti_ifp = ifp; | info.rti_ifp = ifp; | ||||
info.rti_flags = flags | RTF_HOST | RTF_DYNAMIC; | info.rti_flags = flags; | ||||
/* Setup route metrics to define expire time. */ | /* Setup route metrics to define expire time. */ | ||||
bzero(&rti_rmx, sizeof(rti_rmx)); | bzero(&rti_rmx, sizeof(rti_rmx)); | ||||
/* Set expire time as absolute. */ | /* Set expire time as absolute. */ | ||||
rti_rmx.rmx_expire = lifetime_sec + time_second; | rti_rmx.rmx_expire = lifetime_sec + time_second; | ||||
info.rti_mflags |= RTV_EXPIRE; | info.rti_mflags |= RTV_EXPIRE; | ||||
info.rti_rmx = &rti_rmx; | info.rti_rmx = &rti_rmx; | ||||
error = rib_action(fibnum, RTM_ADD, &info, &rc); | error = rib_action(fibnum, RTM_ADD, &info, &rc); | ||||
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); | |||||
flags = rc.rc_rt->rte_flags; | |||||
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; | ||||
info.rti_info[RTAX_AUTHOR] = author; | info.rti_info[RTAX_AUTHOR] = author; | ||||
rt_missmsg_fib(RTM_REDIRECT, &info, flags, error, fibnum); | rt_missmsg_fib(RTM_REDIRECT, &info, flags | RTF_UP, error, fibnum); | ||||
return (0); | return (0); | ||||
} | } | ||||
/* | /* | ||||
* Routing table ioctl interface. | * Routing table ioctl interface. | ||||
*/ | */ | ||||
int | int | ||||
▲ Show 20 Lines • Show All 541 Lines • ▼ Show 20 Lines | rt_mpath_unlink(struct rib_head *rnh, struct rt_addrinfo *info, | ||||
*/ | */ | ||||
if (rto == rt) { | if (rto == rt) { | ||||
rn = rn_mpath_next((struct radix_node *)rt); | rn = rn_mpath_next((struct radix_node *)rt); | ||||
/* | /* | ||||
* there is another entry, now it's active | * there is another entry, now it's active | ||||
*/ | */ | ||||
if (rn) { | if (rn) { | ||||
rto = RNTORT(rn); | rto = RNTORT(rn); | ||||
RT_LOCK(rto); | |||||
rto->rte_flags |= RTF_UP; | rto->rte_flags |= RTF_UP; | ||||
RT_UNLOCK(rto); | |||||
} else if (rt->rte_flags & RTF_GATEWAY) { | } else if (rt->rte_flags & RTF_GATEWAY) { | ||||
/* | /* | ||||
* For gateway routes, we need to | * For gateway routes, we need to | ||||
* make sure that we we are deleting | * make sure that we we are deleting | ||||
* the correct gateway. | * the correct gateway. | ||||
* rt_mpath_matchgate() does not | * rt_mpath_matchgate() does not | ||||
* check the case when there is only | * check the case when there is only | ||||
* one route in the chain. | * one route in the chain. | ||||
▲ Show 20 Lines • Show All 356 Lines • Show Last 20 Lines |