Changeset View
Changeset View
Standalone View
Standalone View
head/sys/net/route/route_ctl.c
Show First 20 Lines • Show All 245 Lines • ▼ Show 20 Lines | add_route(struct rib_head *rnh, struct rt_addrinfo *info, | ||||
rt = uma_zalloc(V_rtzone, M_NOWAIT | M_ZERO); | rt = uma_zalloc(V_rtzone, M_NOWAIT | M_ZERO); | ||||
if (rt == NULL) { | if (rt == NULL) { | ||||
ifa_free(info->rti_ifa); | ifa_free(info->rti_ifa); | ||||
nhop_free(nh); | nhop_free(nh); | ||||
return (ENOBUFS); | return (ENOBUFS); | ||||
} | } | ||||
RT_LOCK_INIT(rt); | RT_LOCK_INIT(rt); | ||||
rt->rt_flags = RTF_UP | flags; | rt->rte_flags = RTF_UP | flags; | ||||
rt->rt_nhop = nh; | rt->rt_nhop = nh; | ||||
/* Fill in dst */ | /* Fill in dst */ | ||||
memcpy(&rt->rt_dst, dst, dst->sa_len); | memcpy(&rt->rt_dst, dst, dst->sa_len); | ||||
rt_key(rt) = &rt->rt_dst; | rt_key(rt) = &rt->rt_dst; | ||||
/* | /* | ||||
* point to the (possibly newly malloc'd) dest address. | * point to the (possibly newly malloc'd) dest address. | ||||
▲ Show 20 Lines • Show All 138 Lines • ▼ Show 20 Lines | |||||
* EADDRINUSE - if trying to delete PINNED route without appropriate flag. | * EADDRINUSE - if trying to delete PINNED route without appropriate flag. | ||||
* ENOENT - if supplied filter function returned 0 (not matched). | * ENOENT - if supplied filter function returned 0 (not matched). | ||||
*/ | */ | ||||
struct rtentry * | struct rtentry * | ||||
rt_unlinkrte(struct rib_head *rnh, struct rt_addrinfo *info, int *perror) | rt_unlinkrte(struct rib_head *rnh, struct rt_addrinfo *info, int *perror) | ||||
{ | { | ||||
struct sockaddr *dst, *netmask; | struct sockaddr *dst, *netmask; | ||||
struct rtentry *rt; | struct rtentry *rt; | ||||
struct nhop_object *nh; | |||||
struct radix_node *rn; | struct radix_node *rn; | ||||
dst = info->rti_info[RTAX_DST]; | dst = info->rti_info[RTAX_DST]; | ||||
netmask = info->rti_info[RTAX_NETMASK]; | netmask = info->rti_info[RTAX_NETMASK]; | ||||
rt = (struct rtentry *)rnh->rnh_lookup(dst, netmask, &rnh->head); | rt = (struct rtentry *)rnh->rnh_lookup(dst, netmask, &rnh->head); | ||||
if (rt == NULL) { | if (rt == NULL) { | ||||
*perror = ESRCH; | *perror = ESRCH; | ||||
return (NULL); | return (NULL); | ||||
} | } | ||||
nh = rt->rt_nhop; | |||||
if ((info->rti_flags & RTF_PINNED) == 0) { | if ((info->rti_flags & RTF_PINNED) == 0) { | ||||
/* Check if target route can be deleted */ | /* Check if target route can be deleted */ | ||||
if (rt->rt_flags & RTF_PINNED) { | if (NH_IS_PINNED(nh)) { | ||||
*perror = EADDRINUSE; | *perror = EADDRINUSE; | ||||
return (NULL); | return (NULL); | ||||
} | } | ||||
} | } | ||||
if (info->rti_filter != NULL) { | if (info->rti_filter != NULL) { | ||||
if (info->rti_filter(rt, rt->rt_nhop, info->rti_filterdata)==0){ | if (info->rti_filter(rt, nh, info->rti_filterdata)==0){ | ||||
/* Not matched */ | /* Not matched */ | ||||
*perror = ENOENT; | *perror = ENOENT; | ||||
return (NULL); | return (NULL); | ||||
} | } | ||||
/* | /* | ||||
* Filter function requested rte deletion. | * Filter function requested rte deletion. | ||||
* Ease the caller work by filling in remaining info | * Ease the caller work by filling in remaining info | ||||
* from that particular entry. | * from that particular entry. | ||||
*/ | */ | ||||
info->rti_info[RTAX_GATEWAY] = &rt->rt_nhop->gw_sa; | info->rti_info[RTAX_GATEWAY] = &nh->gw_sa; | ||||
} | } | ||||
/* | /* | ||||
* Remove the item from the tree and return it. | * Remove the item from the tree and return it. | ||||
* Complain if it is not there and do no more processing. | * Complain if it is not there and do no more processing. | ||||
*/ | */ | ||||
*perror = ESRCH; | *perror = ESRCH; | ||||
#ifdef RADIX_MPATH | #ifdef RADIX_MPATH | ||||
if (rt_mpath_capable(rnh)) | if (rt_mpath_capable(rnh)) | ||||
rn = rt_mpath_unlink(rnh, info, rt, perror); | rn = rt_mpath_unlink(rnh, info, rt, perror); | ||||
else | else | ||||
#endif | #endif | ||||
rn = rnh->rnh_deladdr(dst, netmask, &rnh->head); | rn = rnh->rnh_deladdr(dst, netmask, &rnh->head); | ||||
if (rn == NULL) | if (rn == NULL) | ||||
return (NULL); | return (NULL); | ||||
if (rn->rn_flags & (RNF_ACTIVE | RNF_ROOT)) | if (rn->rn_flags & (RNF_ACTIVE | RNF_ROOT)) | ||||
panic ("rtrequest delete"); | panic ("rtrequest delete"); | ||||
rt = RNTORT(rn); | rt = RNTORT(rn); | ||||
RT_LOCK(rt); | RT_LOCK(rt); | ||||
rt->rt_flags &= ~RTF_UP; | rt->rte_flags &= ~RTF_UP; | ||||
*perror = 0; | *perror = 0; | ||||
return (rt); | return (rt); | ||||
} | } | ||||
static int | static int | ||||
del_route(struct rib_head *rnh, struct rt_addrinfo *info, | del_route(struct rib_head *rnh, struct rt_addrinfo *info, | ||||
▲ Show 20 Lines • Show All 482 Lines • Show Last 20 Lines |