Changeset View
Changeset View
Standalone View
Standalone View
head/sys/net/route/route_ctl.c
Show First 20 Lines • Show All 169 Lines • ▼ Show 20 Lines | get_rnh(uint32_t fibnum, const struct rt_addrinfo *info) | ||||
KASSERT((fibnum < rt_numfibs), ("rib_add_route: bad fibnum")); | KASSERT((fibnum < rt_numfibs), ("rib_add_route: bad fibnum")); | ||||
dst = info->rti_info[RTAX_DST]; | dst = info->rti_info[RTAX_DST]; | ||||
rnh = rt_tables_get_rnh(fibnum, dst->sa_family); | rnh = rt_tables_get_rnh(fibnum, dst->sa_family); | ||||
return (rnh); | return (rnh); | ||||
} | } | ||||
static int | |||||
get_info_weight(const struct rt_addrinfo *info, uint32_t default_weight) | |||||
{ | |||||
uint32_t weight; | |||||
if (info->rti_mflags & RTV_WEIGHT) | |||||
weight = info->rti_rmx->rmx_weight; | |||||
else | |||||
weight = default_weight; | |||||
/* Keep upper 1 byte for adm distance purposes */ | |||||
if (weight > RT_MAX_WEIGHT) | |||||
weight = RT_MAX_WEIGHT; | |||||
return (weight); | |||||
} | |||||
static void | |||||
rt_set_expire_info(struct rtentry *rt, const struct rt_addrinfo *info) | |||||
{ | |||||
/* Kernel -> userland timebase conversion. */ | |||||
if (info->rti_mflags & RTV_EXPIRE) | |||||
rt->rt_expire = info->rti_rmx->rmx_expire ? | |||||
info->rti_rmx->rmx_expire - time_second + time_uptime : 0; | |||||
} | |||||
/* | /* | ||||
* Check if specified @gw matches gw data in the nexthop @nh. | * Check if specified @gw matches gw data in the nexthop @nh. | ||||
* | * | ||||
* Returns true if matches, false otherwise. | * Returns true if matches, false otherwise. | ||||
*/ | */ | ||||
static bool | static bool | ||||
match_nhop_gw(const struct nhop_object *nh, const struct sockaddr *gw) | match_nhop_gw(const struct nhop_object *nh, const struct sockaddr *gw) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 232 Lines • ▼ Show 20 Lines | if (netmask) { | ||||
bcopy(dst, ndst, dst->sa_len); | bcopy(dst, ndst, dst->sa_len); | ||||
/* | /* | ||||
* We use the ifa reference returned by rt_getifa_fib(). | * We use the ifa reference returned by rt_getifa_fib(). | ||||
* This moved from below so that rnh->rnh_addaddr() can | * This moved from below so that rnh->rnh_addaddr() can | ||||
* examine the ifa and ifa->ifa_ifp if it so desires. | * examine the ifa and ifa->ifa_ifp if it so desires. | ||||
*/ | */ | ||||
ifa = info->rti_ifa; | ifa = info->rti_ifa; | ||||
rt->rt_weight = 1; | rt->rt_weight = get_info_weight(info, RT_DEFAULT_WEIGHT); | ||||
rt_set_expire_info(rt, info); | |||||
rt_setmetrics(info, rt); | |||||
*prt = rt; | *prt = rt; | ||||
return (0); | return (0); | ||||
} | } | ||||
static int | static int | ||||
add_route(struct rib_head *rnh, struct rt_addrinfo *info, | add_route(struct rib_head *rnh, struct rt_addrinfo *info, | ||||
struct rib_cmd_info *rc) | struct rib_cmd_info *rc) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 372 Lines • ▼ Show 20 Lines | change_route_nhop(struct rib_head *rnh, struct rtentry *rt, | ||||
struct nhop_object *nh_orig; | struct nhop_object *nh_orig; | ||||
RIB_WLOCK_ASSERT(rnh); | RIB_WLOCK_ASSERT(rnh); | ||||
nh_orig = rt->rt_nhop; | nh_orig = rt->rt_nhop; | ||||
if (rnd->rnd_nhop != NULL) { | if (rnd->rnd_nhop != NULL) { | ||||
/* Changing expiration & nexthop & weight to a new one */ | /* Changing expiration & nexthop & weight to a new one */ | ||||
rt_setmetrics(info, rt); | rt_set_expire_info(rt, info); | ||||
rt->rt_nhop = rnd->rnd_nhop; | rt->rt_nhop = rnd->rnd_nhop; | ||||
rt->rt_weight = rnd->rnd_weight; | rt->rt_weight = rnd->rnd_weight; | ||||
if (rt->rt_expire > 0) | if (rt->rt_expire > 0) | ||||
tmproutes_update(rnh, rt); | tmproutes_update(rnh, rt); | ||||
} else { | } else { | ||||
/* Route deletion requested. */ | /* Route deletion requested. */ | ||||
struct sockaddr *ndst, *netmask; | struct sockaddr *ndst, *netmask; | ||||
struct radix_node *rn; | struct radix_node *rn; | ||||
▲ Show 20 Lines • Show All 361 Lines • Show Last 20 Lines |