Separate radix and routing: use different structures for route and
for other customers. Introduce new 'struct rib_head' for routing purposes and make all routing api use it.
This commit is contained in:
parent
a9413f6ca0
commit
55e5eda676
@ -199,7 +199,7 @@ vfs_hang_addrlist(struct mount *mp, struct netexport *nep,
|
||||
goto out;
|
||||
}
|
||||
RADIX_NODE_HEAD_LOCK(rnh);
|
||||
rn = (*rnh->rnh_addaddr)(saddr, smask, rnh, np->netc_rnodes);
|
||||
rn = (*rnh->rnh_addaddr)(saddr, smask, &rnh->rh, np->netc_rnodes);
|
||||
RADIX_NODE_HEAD_UNLOCK(rnh);
|
||||
if (rn == NULL || np != (struct netcred *)rn) { /* already exists */
|
||||
error = EPERM;
|
||||
@ -231,7 +231,7 @@ vfs_free_netcred(struct radix_node *rn, void *w)
|
||||
struct radix_node_head *rnh = (struct radix_node_head *) w;
|
||||
struct ucred *cred;
|
||||
|
||||
(*rnh->rnh_deladdr) (rn->rn_key, rn->rn_mask, rnh);
|
||||
(*rnh->rnh_deladdr) (rn->rn_key, rn->rn_mask, &rnh->rh);
|
||||
cred = ((struct netcred *)rn)->netc_anon;
|
||||
if (cred != NULL)
|
||||
crfree(cred);
|
||||
@ -256,7 +256,7 @@ vfs_free_addrlist_af(struct radix_node_head **prnh)
|
||||
|
||||
rnh = *prnh;
|
||||
RADIX_NODE_HEAD_LOCK(rnh);
|
||||
(*rnh->rnh_walktree) (rnh, vfs_free_netcred, rnh);
|
||||
(*rnh->rnh_walktree)(&rnh->rh, vfs_free_netcred, &rnh->rh);
|
||||
RADIX_NODE_HEAD_UNLOCK(rnh);
|
||||
RADIX_NODE_HEAD_DESTROY(rnh);
|
||||
free(rnh, M_RTABLE);
|
||||
@ -470,7 +470,7 @@ vfs_export_lookup(struct mount *mp, struct sockaddr *nam)
|
||||
if (rnh != NULL) {
|
||||
RADIX_NODE_HEAD_RLOCK(rnh);
|
||||
np = (struct netcred *)
|
||||
(*rnh->rnh_matchaddr)(saddr, rnh);
|
||||
(*rnh->rnh_matchaddr)(saddr, &rnh->rh);
|
||||
RADIX_NODE_HEAD_RUNLOCK(rnh);
|
||||
if (np && np->netc_rnodes->rn_flags & RNF_ROOT)
|
||||
np = NULL;
|
||||
|
@ -56,9 +56,6 @@
|
||||
#include <net/radix.h>
|
||||
#endif /* !_KERNEL */
|
||||
|
||||
static int rn_walktree_from(struct radix_head *h, void *a, void *m,
|
||||
walktree_f_t *f, void *w);
|
||||
static int rn_walktree(struct radix_head *, walktree_f_t *, void *);
|
||||
static struct radix_node
|
||||
*rn_insert(void *, struct radix_head *, int *,
|
||||
struct radix_node [2]),
|
||||
@ -68,7 +65,6 @@ static struct radix_node
|
||||
static struct radix_node *rn_addmask(void *, struct radix_head *, int, int);
|
||||
|
||||
static void rn_detachhead_internal(void **head);
|
||||
static int rn_inithead_internal(void **head, int off);
|
||||
|
||||
#define RADIX_MAX_KEY_LEN 32
|
||||
|
||||
@ -225,7 +221,7 @@ rn_lookup(void *v_arg, void *m_arg, struct radix_head *head)
|
||||
/*
|
||||
* Most common case: search exact prefix/mask
|
||||
*/
|
||||
x = rn_addmask(m_arg, head->rnh_masks, 1,
|
||||
x = rn_addmask(m_arg, head->s.rnh_masks, 1,
|
||||
head->rnh_treetop->rn_offset);
|
||||
if (x == NULL)
|
||||
return (NULL);
|
||||
@ -507,7 +503,7 @@ rn_addmask(void *n_arg, struct radix_head *maskhead, int search, int skip)
|
||||
if (skip == 0)
|
||||
skip = 1;
|
||||
if (mlen <= skip)
|
||||
return (((struct radix_node_head *)maskhead)->rnh_nodes);
|
||||
return (maskhead->s.mask_nodes);
|
||||
|
||||
bzero(addmask_key, RADIX_MAX_KEY_LEN);
|
||||
if (skip > 1)
|
||||
@ -520,7 +516,7 @@ rn_addmask(void *n_arg, struct radix_head *maskhead, int search, int skip)
|
||||
cp--;
|
||||
mlen = cp - addmask_key;
|
||||
if (mlen <= skip)
|
||||
return (((struct radix_node_head *)maskhead)->rnh_nodes);
|
||||
return (maskhead->s.mask_nodes);
|
||||
*addmask_key = mlen;
|
||||
x = rn_search(addmask_key, maskhead->rnh_treetop);
|
||||
if (bcmp(addmask_key, x->rn_key, mlen) != 0)
|
||||
@ -619,7 +615,7 @@ rn_addroute(void *v_arg, void *n_arg, struct radix_head *head,
|
||||
* nodes and possibly save time in calculating indices.
|
||||
*/
|
||||
if (netmask) {
|
||||
x = rn_addmask(netmask, head->rnh_masks, 0, top->rn_offset);
|
||||
x = rn_addmask(netmask, head->s.rnh_masks, 0, top->rn_offset);
|
||||
if (x == NULL)
|
||||
return (0);
|
||||
b_leaf = x->rn_bit;
|
||||
@ -797,7 +793,7 @@ rn_delete(void *v_arg, void *netmask_arg, struct radix_head *head)
|
||||
* Delete our route from mask lists.
|
||||
*/
|
||||
if (netmask) {
|
||||
x = rn_addmask(netmask, head->rnh_masks, 1, head_off);
|
||||
x = rn_addmask(netmask, head->s.rnh_masks, 1, head_off);
|
||||
if (x == NULL)
|
||||
return (0);
|
||||
netmask = x->rn_key;
|
||||
@ -961,7 +957,7 @@ out:
|
||||
* This is the same as rn_walktree() except for the parameters and the
|
||||
* exit.
|
||||
*/
|
||||
static int
|
||||
int
|
||||
rn_walktree_from(struct radix_head *h, void *a, void *m,
|
||||
walktree_f_t *f, void *w)
|
||||
{
|
||||
@ -1067,7 +1063,7 @@ rn_walktree_from(struct radix_head *h, void *a, void *m,
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
int
|
||||
rn_walktree(struct radix_head *h, walktree_f_t *f, void *w)
|
||||
{
|
||||
int error;
|
||||
@ -1107,76 +1103,75 @@ rn_walktree(struct radix_head *h, walktree_f_t *f, void *w)
|
||||
}
|
||||
|
||||
/*
|
||||
* Allocate and initialize an empty tree. This has 3 nodes, which are
|
||||
* part of the radix_node_head (in the order <left,root,right>) and are
|
||||
* Initialize an empty tree. This has 3 nodes, which are passed
|
||||
* via base_nodes (in the order <left,root,right>) and are
|
||||
* marked RNF_ROOT so they cannot be freed.
|
||||
* The leaves have all-zero and all-one keys, with significant
|
||||
* bits starting at 'off'.
|
||||
* Return 1 on success, 0 on error.
|
||||
*/
|
||||
static int
|
||||
rn_inithead_internal(void **head, int off)
|
||||
void
|
||||
rn_inithead_internal(struct radix_head *rh, struct radix_node *base_nodes, int off)
|
||||
{
|
||||
struct radix_node_head *rnh;
|
||||
struct radix_node *t, *tt, *ttt;
|
||||
if (*head)
|
||||
return (1);
|
||||
R_Zalloc(rnh, struct radix_node_head *, sizeof (*rnh));
|
||||
if (rnh == 0)
|
||||
return (0);
|
||||
*head = rnh;
|
||||
t = rn_newpair(rn_zeros, off, rnh->rnh_nodes);
|
||||
ttt = rnh->rnh_nodes + 2;
|
||||
|
||||
t = rn_newpair(rn_zeros, off, base_nodes);
|
||||
ttt = base_nodes + 2;
|
||||
t->rn_right = ttt;
|
||||
t->rn_parent = t;
|
||||
tt = t->rn_left; /* ... which in turn is rnh->rnh_nodes */
|
||||
tt = t->rn_left; /* ... which in turn is base_nodes */
|
||||
tt->rn_flags = t->rn_flags = RNF_ROOT | RNF_ACTIVE;
|
||||
tt->rn_bit = -1 - off;
|
||||
*ttt = *tt;
|
||||
ttt->rn_key = rn_ones;
|
||||
rnh->rnh_addaddr = (rn_addaddr_f_t *)rn_addroute;
|
||||
rnh->rnh_deladdr = (rn_deladdr_f_t *)rn_delete;
|
||||
rnh->rnh_matchaddr = (rn_matchaddr_f_t *)rn_match;
|
||||
rnh->rnh_lookup = (rn_lookup_f_t *)rn_lookup;
|
||||
rnh->rnh_walktree = (rn_walktree_t *)rn_walktree;
|
||||
rnh->rnh_walktree_from = (rn_walktree_from_t *)rn_walktree_from;
|
||||
rnh->rh.rnh_treetop = t;
|
||||
return (1);
|
||||
|
||||
rh->rnh_treetop = t;
|
||||
}
|
||||
|
||||
static void
|
||||
rn_detachhead_internal(void **head)
|
||||
{
|
||||
struct radix_node_head *rnh;
|
||||
|
||||
KASSERT((head != NULL && *head != NULL),
|
||||
("%s: head already freed", __func__));
|
||||
rnh = *head;
|
||||
|
||||
/* Free <left,root,right> nodes. */
|
||||
Free(rnh);
|
||||
Free(*head);
|
||||
|
||||
*head = NULL;
|
||||
}
|
||||
|
||||
/* BELOW ARE FUNCTIONS TO SUPPORT struct radix_node_head USERS */
|
||||
int
|
||||
rn_inithead(void **head, int off)
|
||||
{
|
||||
struct radix_node_head *rnh;
|
||||
struct radix_mask_head *rmh;
|
||||
|
||||
if (*head != NULL)
|
||||
return (1);
|
||||
|
||||
if (rn_inithead_internal(head, off) == 0)
|
||||
return (0);
|
||||
|
||||
rnh = (struct radix_node_head *)(*head);
|
||||
|
||||
if (rn_inithead_internal((void **)&rnh->rh.rnh_masks, 0) == 0) {
|
||||
rn_detachhead_internal(head);
|
||||
return (0);
|
||||
R_Zalloc(rnh, struct radix_node_head *, sizeof (*rnh));
|
||||
R_Zalloc(rmh, struct radix_mask_head *, sizeof (*rmh));
|
||||
if (rnh == NULL || rmh == NULL) {
|
||||
if (rnh != NULL)
|
||||
Free(rnh);
|
||||
return (1);
|
||||
}
|
||||
|
||||
/* Init trees */
|
||||
rn_inithead_internal(&rnh->rh, rnh->rnh_nodes, off);
|
||||
rn_inithead_internal(&rmh->head, rmh->mask_nodes, 0);
|
||||
rnh->rh.s.rnh_masks = &rmh->head;
|
||||
rmh->head.s.mask_nodes = rmh->mask_nodes;
|
||||
|
||||
/* Finally, set base callbacks */
|
||||
rnh->rnh_addaddr = rn_addroute;
|
||||
rnh->rnh_deladdr = rn_delete;
|
||||
rnh->rnh_matchaddr = rn_match;
|
||||
rnh->rnh_lookup = rn_lookup;
|
||||
rnh->rnh_walktree = rn_walktree;
|
||||
rnh->rnh_walktree_from = rn_walktree_from;
|
||||
|
||||
return (1);
|
||||
}
|
||||
|
||||
@ -1202,8 +1197,8 @@ rn_detachhead(void **head)
|
||||
|
||||
rnh = *head;
|
||||
|
||||
rn_walktree(rnh->rh.rnh_masks, rn_freeentry, rnh->rh.rnh_masks);
|
||||
rn_detachhead_internal((void **)&rnh->rh.rnh_masks);
|
||||
rn_walktree(rnh->rh.s.rnh_masks, rn_freeentry, rnh->rh.s.rnh_masks);
|
||||
rn_detachhead_internal((void **)&rnh->rh.s.rnh_masks);
|
||||
rn_detachhead_internal(head);
|
||||
return (1);
|
||||
}
|
||||
|
@ -101,26 +101,29 @@ struct radix_mask {
|
||||
#define rm_mask rm_rmu.rmu_mask
|
||||
#define rm_leaf rm_rmu.rmu_leaf /* extra field would make 32 bytes */
|
||||
|
||||
struct radix_node_head;
|
||||
struct radix_head;
|
||||
|
||||
typedef int walktree_f_t(struct radix_node *, void *);
|
||||
typedef struct radix_node *rn_matchaddr_f_t(void *v,
|
||||
struct radix_node_head *head);
|
||||
struct radix_head *head);
|
||||
typedef struct radix_node *rn_addaddr_f_t(void *v, void *mask,
|
||||
struct radix_node_head *head, struct radix_node nodes[]);
|
||||
struct radix_head *head, struct radix_node nodes[]);
|
||||
typedef struct radix_node *rn_deladdr_f_t(void *v, void *mask,
|
||||
struct radix_node_head *head);
|
||||
struct radix_head *head);
|
||||
typedef struct radix_node *rn_lookup_f_t(void *v, void *mask,
|
||||
struct radix_node_head *head);
|
||||
typedef int rn_walktree_t(struct radix_node_head *head, walktree_f_t *f,
|
||||
struct radix_head *head);
|
||||
typedef int rn_walktree_t(struct radix_head *head, walktree_f_t *f,
|
||||
void *w);
|
||||
typedef int rn_walktree_from_t(struct radix_node_head *head,
|
||||
typedef int rn_walktree_from_t(struct radix_head *head,
|
||||
void *a, void *m, walktree_f_t *f, void *w);
|
||||
typedef void rn_close_t(struct radix_node *rn, struct radix_node_head *head);
|
||||
typedef void rn_close_t(struct radix_node *rn, struct radix_head *head);
|
||||
|
||||
struct radix_head {
|
||||
struct radix_node *rnh_treetop;
|
||||
struct radix_head *rnh_masks; /* Storage for our masks */
|
||||
union {
|
||||
struct radix_head *rnh_masks; /* Storage for our masks */
|
||||
struct radix_node *mask_nodes;
|
||||
} s;
|
||||
};
|
||||
|
||||
struct radix_node_head {
|
||||
@ -140,6 +143,14 @@ struct radix_node_head {
|
||||
#endif
|
||||
};
|
||||
|
||||
/* XXX: Temporarily xported to support external radix users */
|
||||
struct radix_mask_head {
|
||||
struct radix_head head;
|
||||
struct radix_node mask_nodes[3];
|
||||
};
|
||||
void rn_inithead_internal(struct radix_head *rh, struct radix_node *base_nodes,
|
||||
int off);
|
||||
|
||||
#ifndef _KERNEL
|
||||
#define R_Malloc(p, t, n) (p = (t) malloc((unsigned int)(n)))
|
||||
#define R_Zalloc(p, t, n) (p = (t) calloc(1,(unsigned int)(n)))
|
||||
@ -172,5 +183,8 @@ struct radix_node *rn_delete(void *, void *, struct radix_head *);
|
||||
struct radix_node *rn_lookup (void *v_arg, void *m_arg,
|
||||
struct radix_head *head);
|
||||
struct radix_node *rn_match(void *, struct radix_head *);
|
||||
int rn_walktree_from(struct radix_head *h, void *a, void *m,
|
||||
walktree_f_t *f, void *w);
|
||||
int rn_walktree(struct radix_head *, walktree_f_t *, void *);
|
||||
|
||||
#endif /* _RADIX_H_ */
|
||||
|
@ -167,7 +167,7 @@ rt_mpath_conflict(struct radix_node_head *rnh, struct rtentry *rt,
|
||||
struct rtentry *rt1;
|
||||
|
||||
rn = (struct radix_node *)rt;
|
||||
rn1 = rnh->rnh_lookup(rt_key(rt), netmask, rnh);
|
||||
rn1 = rnh->rnh_lookup(rt_key(rt), netmask, &rnh->rh);
|
||||
if (!rn1 || rn1->rn_flags & RNF_ROOT)
|
||||
return (0);
|
||||
|
||||
|
226
sys/net/route.c
226
sys/net/route.c
@ -116,7 +116,7 @@ SYSCTL_UINT(_net, OID_AUTO, add_addr_allfibs, CTLFLAG_RWTUN | CTLFLAG_VNET,
|
||||
VNET_DEFINE(struct rtstat, rtstat);
|
||||
#define V_rtstat VNET(rtstat)
|
||||
|
||||
VNET_DEFINE(struct radix_node_head *, rt_tables);
|
||||
VNET_DEFINE(struct rib_head *, rt_tables);
|
||||
#define V_rt_tables VNET(rt_tables)
|
||||
|
||||
VNET_DEFINE(int, rttrash); /* routes not in table but not freed */
|
||||
@ -138,7 +138,7 @@ VNET_DEFINE(int, rttrash); /* routes not in table but not freed */
|
||||
static VNET_DEFINE(uma_zone_t, rtzone); /* Routing table UMA zone. */
|
||||
#define V_rtzone VNET(rtzone)
|
||||
|
||||
static int rtrequest1_fib_change(struct radix_node_head *, struct rt_addrinfo *,
|
||||
static int rtrequest1_fib_change(struct rib_head *, struct rt_addrinfo *,
|
||||
struct rtentry **, u_int);
|
||||
static void rt_setmetrics(const struct rt_addrinfo *, struct rtentry *);
|
||||
static int rt_ifdelroute(struct rtentry *rt, void *arg);
|
||||
@ -160,25 +160,25 @@ sysctl_my_fibnum(SYSCTL_HANDLER_ARGS)
|
||||
SYSCTL_PROC(_net, OID_AUTO, my_fibnum, CTLTYPE_INT|CTLFLAG_RD,
|
||||
NULL, 0, &sysctl_my_fibnum, "I", "default FIB of caller");
|
||||
|
||||
static __inline struct radix_node_head **
|
||||
static __inline struct rib_head **
|
||||
rt_tables_get_rnh_ptr(int table, int fam)
|
||||
{
|
||||
struct radix_node_head **rnh;
|
||||
struct rib_head **rh;
|
||||
|
||||
KASSERT(table >= 0 && table < rt_numfibs, ("%s: table out of bounds.",
|
||||
__func__));
|
||||
KASSERT(fam >= 0 && fam < (AF_MAX+1), ("%s: fam out of bounds.",
|
||||
__func__));
|
||||
|
||||
/* rnh is [fib=0][af=0]. */
|
||||
rnh = (struct radix_node_head **)V_rt_tables;
|
||||
/* rh is [fib=0][af=0]. */
|
||||
rh = (struct rib_head **)V_rt_tables;
|
||||
/* Get the offset to the requested table and fam. */
|
||||
rnh += table * (AF_MAX+1) + fam;
|
||||
rh += table * (AF_MAX+1) + fam;
|
||||
|
||||
return (rnh);
|
||||
return (rh);
|
||||
}
|
||||
|
||||
struct radix_node_head *
|
||||
struct rib_head *
|
||||
rt_tables_get_rnh(int table, int fam)
|
||||
{
|
||||
|
||||
@ -247,12 +247,12 @@ static void
|
||||
vnet_route_init(const void *unused __unused)
|
||||
{
|
||||
struct domain *dom;
|
||||
struct radix_node_head **rnh;
|
||||
struct rib_head **rh;
|
||||
int table;
|
||||
int fam;
|
||||
|
||||
V_rt_tables = malloc(rt_numfibs * (AF_MAX+1) *
|
||||
sizeof(struct radix_node_head *), M_RTABLE, M_WAITOK|M_ZERO);
|
||||
sizeof(struct rib_head *), M_RTABLE, M_WAITOK|M_ZERO);
|
||||
|
||||
V_rtzone = uma_zcreate("rtentry", sizeof(struct rtentry),
|
||||
rtentry_ctor, rtentry_dtor,
|
||||
@ -266,10 +266,10 @@ vnet_route_init(const void *unused __unused)
|
||||
if (table != 0 && fam != AF_INET6 && fam != AF_INET)
|
||||
break;
|
||||
|
||||
rnh = rt_tables_get_rnh_ptr(table, fam);
|
||||
if (rnh == NULL)
|
||||
panic("%s: rnh NULL", __func__);
|
||||
dom->dom_rtattach((void **)rnh, 0);
|
||||
rh = rt_tables_get_rnh_ptr(table, fam);
|
||||
if (rh == NULL)
|
||||
panic("%s: rh NULL", __func__);
|
||||
dom->dom_rtattach((void **)rh, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -283,7 +283,7 @@ vnet_route_uninit(const void *unused __unused)
|
||||
int table;
|
||||
int fam;
|
||||
struct domain *dom;
|
||||
struct radix_node_head **rnh;
|
||||
struct rib_head **rh;
|
||||
|
||||
for (dom = domains; dom; dom = dom->dom_next) {
|
||||
if (dom->dom_rtdetach == NULL)
|
||||
@ -295,10 +295,10 @@ vnet_route_uninit(const void *unused __unused)
|
||||
if (table != 0 && fam != AF_INET6 && fam != AF_INET)
|
||||
break;
|
||||
|
||||
rnh = rt_tables_get_rnh_ptr(table, fam);
|
||||
if (rnh == NULL)
|
||||
panic("%s: rnh NULL", __func__);
|
||||
dom->dom_rtdetach((void **)rnh, 0);
|
||||
rh = rt_tables_get_rnh_ptr(table, fam);
|
||||
if (rh == NULL)
|
||||
panic("%s: rh NULL", __func__);
|
||||
dom->dom_rtdetach((void **)rh, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@ -309,6 +309,44 @@ VNET_SYSUNINIT(vnet_route_uninit, SI_SUB_PROTO_DOMAIN, SI_ORDER_THIRD,
|
||||
vnet_route_uninit, 0);
|
||||
#endif
|
||||
|
||||
struct rib_head *
|
||||
rt_table_init(int offset)
|
||||
{
|
||||
struct rib_head *rh;
|
||||
|
||||
rh = malloc(sizeof(struct rib_head), M_RTABLE, M_WAITOK | M_ZERO);
|
||||
|
||||
/* XXX: These details should be hidded inside radix.c */
|
||||
/* Init masks tree */
|
||||
rn_inithead_internal(&rh->head, rh->rnh_nodes, offset);
|
||||
rn_inithead_internal(&rh->rmhead.head, rh->rmhead.mask_nodes, 0);
|
||||
rh->head.s.rnh_masks = &rh->rmhead.head;
|
||||
rh->rmhead.head.s.mask_nodes = rh->rmhead.mask_nodes;
|
||||
|
||||
/* Init locks */
|
||||
rw_init(&rh->rib_lock, "rib head");
|
||||
|
||||
/* Finally, set base callbacks */
|
||||
rh->rnh_addaddr = rn_addroute;
|
||||
rh->rnh_deladdr = rn_delete;
|
||||
rh->rnh_matchaddr = rn_match;
|
||||
rh->rnh_lookup = rn_lookup;
|
||||
rh->rnh_walktree = rn_walktree;
|
||||
rh->rnh_walktree_from = rn_walktree_from;
|
||||
|
||||
return (rh);
|
||||
}
|
||||
|
||||
void
|
||||
rt_table_destroy(struct rib_head *rh)
|
||||
{
|
||||
|
||||
/* Assume table is already empty */
|
||||
rw_destroy(&rh->rib_lock);
|
||||
free(rh, M_RTABLE);
|
||||
}
|
||||
|
||||
|
||||
#ifndef _SYS_SYSPROTO_H_
|
||||
struct setfib_args {
|
||||
int fibnum;
|
||||
@ -388,7 +426,7 @@ struct rtentry *
|
||||
rtalloc1_fib(struct sockaddr *dst, int report, u_long ignflags,
|
||||
u_int fibnum)
|
||||
{
|
||||
struct radix_node_head *rnh;
|
||||
struct rib_head *rh;
|
||||
struct radix_node *rn;
|
||||
struct rtentry *newrt;
|
||||
struct rt_addrinfo info;
|
||||
@ -396,9 +434,9 @@ rtalloc1_fib(struct sockaddr *dst, int report, u_long ignflags,
|
||||
int needlock;
|
||||
|
||||
KASSERT((fibnum < rt_numfibs), ("rtalloc1_fib: bad fibnum"));
|
||||
rnh = rt_tables_get_rnh(fibnum, dst->sa_family);
|
||||
rh = rt_tables_get_rnh(fibnum, dst->sa_family);
|
||||
newrt = NULL;
|
||||
if (rnh == NULL)
|
||||
if (rh == NULL)
|
||||
goto miss;
|
||||
|
||||
/*
|
||||
@ -406,22 +444,22 @@ rtalloc1_fib(struct sockaddr *dst, int report, u_long ignflags,
|
||||
*/
|
||||
needlock = !(ignflags & RTF_RNH_LOCKED);
|
||||
if (needlock)
|
||||
RADIX_NODE_HEAD_RLOCK(rnh);
|
||||
RIB_RLOCK(rh);
|
||||
#ifdef INVARIANTS
|
||||
else
|
||||
RADIX_NODE_HEAD_LOCK_ASSERT(rnh);
|
||||
RIB_LOCK_ASSERT(rh);
|
||||
#endif
|
||||
rn = rnh->rnh_matchaddr(dst, rnh);
|
||||
rn = rh->rnh_matchaddr(dst, &rh->head);
|
||||
if (rn && ((rn->rn_flags & RNF_ROOT) == 0)) {
|
||||
newrt = RNTORT(rn);
|
||||
RT_LOCK(newrt);
|
||||
RT_ADDREF(newrt);
|
||||
if (needlock)
|
||||
RADIX_NODE_HEAD_RUNLOCK(rnh);
|
||||
RIB_RUNLOCK(rh);
|
||||
goto done;
|
||||
|
||||
} else if (needlock)
|
||||
RADIX_NODE_HEAD_RUNLOCK(rnh);
|
||||
RIB_RUNLOCK(rh);
|
||||
|
||||
/*
|
||||
* Either we hit the root or couldn't find any match,
|
||||
@ -454,11 +492,11 @@ done:
|
||||
void
|
||||
rtfree(struct rtentry *rt)
|
||||
{
|
||||
struct radix_node_head *rnh;
|
||||
struct rib_head *rh;
|
||||
|
||||
KASSERT(rt != NULL,("%s: NULL rt", __func__));
|
||||
rnh = rt_tables_get_rnh(rt->rt_fibnum, rt_key(rt)->sa_family);
|
||||
KASSERT(rnh != NULL,("%s: NULL rnh", __func__));
|
||||
rh = rt_tables_get_rnh(rt->rt_fibnum, rt_key(rt)->sa_family);
|
||||
KASSERT(rh != NULL,("%s: NULL rh", __func__));
|
||||
|
||||
RT_LOCK_ASSERT(rt);
|
||||
|
||||
@ -481,8 +519,8 @@ rtfree(struct rtentry *rt)
|
||||
* typically calls rtexpunge which clears the RTF_UP flag
|
||||
* on the entry so that the code below reclaims the storage.
|
||||
*/
|
||||
if (rt->rt_refcnt == 0 && rnh->rnh_close)
|
||||
rnh->rnh_close((struct radix_node *)rt, rnh);
|
||||
if (rt->rt_refcnt == 0 && rh->rnh_close)
|
||||
rh->rnh_close((struct radix_node *)rt, &rh->head);
|
||||
|
||||
/*
|
||||
* If we are no longer "up" (and ref == 0)
|
||||
@ -557,11 +595,11 @@ rtredirect_fib(struct sockaddr *dst,
|
||||
short *stat = NULL;
|
||||
struct rt_addrinfo info;
|
||||
struct ifaddr *ifa;
|
||||
struct radix_node_head *rnh;
|
||||
struct rib_head *rh;
|
||||
|
||||
ifa = NULL;
|
||||
rnh = rt_tables_get_rnh(fibnum, dst->sa_family);
|
||||
if (rnh == NULL) {
|
||||
rh = rt_tables_get_rnh(fibnum, dst->sa_family);
|
||||
if (rh == NULL) {
|
||||
error = EAFNOSUPPORT;
|
||||
goto out;
|
||||
}
|
||||
@ -615,7 +653,7 @@ rtredirect_fib(struct sockaddr *dst,
|
||||
info.rti_ifa = ifa;
|
||||
info.rti_flags = flags;
|
||||
if (rt0 != NULL)
|
||||
RT_UNLOCK(rt0); /* drop lock to avoid LOR with RNH */
|
||||
RT_UNLOCK(rt0); /* drop lock to avoid LOR with rh */
|
||||
error = rtrequest1_fib(RTM_ADD, &info, &rt, fibnum);
|
||||
if (rt != NULL) {
|
||||
RT_LOCK(rt);
|
||||
@ -641,11 +679,11 @@ rtredirect_fib(struct sockaddr *dst,
|
||||
* add the key and gateway (in one malloc'd chunk).
|
||||
*/
|
||||
RT_UNLOCK(rt);
|
||||
RADIX_NODE_HEAD_LOCK(rnh);
|
||||
RIB_WLOCK(rh);
|
||||
RT_LOCK(rt);
|
||||
rt_setgate(rt, rt_key(rt), gateway);
|
||||
gwrt = rtalloc1(gateway, 1, RTF_RNH_LOCKED);
|
||||
RADIX_NODE_HEAD_UNLOCK(rnh);
|
||||
RIB_WUNLOCK(rh);
|
||||
EVENTHANDLER_INVOKE(route_redirect_event, rt, gwrt, dst);
|
||||
RTFREE_LOCKED(gwrt);
|
||||
}
|
||||
@ -810,35 +848,35 @@ rtrequest_fib(int req,
|
||||
void
|
||||
rt_foreach_fib(int af, rt_setwarg_t *setwa_f, rt_walktree_f_t *wa_f, void *arg)
|
||||
{
|
||||
struct radix_node_head *rnh;
|
||||
struct rib_head *rh;
|
||||
uint32_t fibnum;
|
||||
int i;
|
||||
|
||||
for (fibnum = 0; fibnum < rt_numfibs; fibnum++) {
|
||||
/* Do we want some specific family? */
|
||||
if (af != AF_UNSPEC) {
|
||||
rnh = rt_tables_get_rnh(fibnum, af);
|
||||
if (rnh == NULL)
|
||||
rh = rt_tables_get_rnh(fibnum, af);
|
||||
if (rh == NULL)
|
||||
continue;
|
||||
if (setwa_f != NULL)
|
||||
setwa_f(rnh, fibnum, i, arg);
|
||||
setwa_f(rh, fibnum, i, arg);
|
||||
|
||||
RADIX_NODE_HEAD_LOCK(rnh);
|
||||
rnh->rnh_walktree(rnh, (walktree_f_t *)wa_f, arg);
|
||||
RADIX_NODE_HEAD_UNLOCK(rnh);
|
||||
RIB_WLOCK(rh);
|
||||
rh->rnh_walktree(&rh->head, (walktree_f_t *)wa_f, arg);
|
||||
RIB_WUNLOCK(rh);
|
||||
continue;
|
||||
}
|
||||
|
||||
for (i = 1; i <= AF_MAX; i++) {
|
||||
rnh = rt_tables_get_rnh(fibnum, i);
|
||||
if (rnh == NULL)
|
||||
rh = rt_tables_get_rnh(fibnum, i);
|
||||
if (rh == NULL)
|
||||
continue;
|
||||
if (setwa_f != NULL)
|
||||
setwa_f(rnh, fibnum, i, arg);
|
||||
setwa_f(rh, fibnum, i, arg);
|
||||
|
||||
RADIX_NODE_HEAD_LOCK(rnh);
|
||||
rnh->rnh_walktree(rnh, (walktree_f_t *)wa_f, arg);
|
||||
RADIX_NODE_HEAD_UNLOCK(rnh);
|
||||
RIB_WLOCK(rh);
|
||||
rh->rnh_walktree(&rh->head, (walktree_f_t *)wa_f, arg);
|
||||
RIB_WUNLOCK(rh);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -846,12 +884,12 @@ rt_foreach_fib(int af, rt_setwarg_t *setwa_f, rt_walktree_f_t *wa_f, void *arg)
|
||||
/*
|
||||
* Delete Routes for a Network Interface
|
||||
*
|
||||
* Called for each routing entry via the rnh->rnh_walktree() call above
|
||||
* Called for each routing entry via the rh->rnh_walktree() call above
|
||||
* to delete all route entries referencing a detaching network interface.
|
||||
*
|
||||
* Arguments:
|
||||
* rt pointer to rtentry
|
||||
* arg argument passed to rnh->rnh_walktree() - detaching interface
|
||||
* arg argument passed to rh->rnh_walktree() - detaching interface
|
||||
*
|
||||
* Returns:
|
||||
* 0 successful
|
||||
@ -963,7 +1001,7 @@ rt_getifa_fib(struct rt_addrinfo *info, u_int fibnum)
|
||||
* The route must be locked.
|
||||
*/
|
||||
int
|
||||
rt_expunge(struct radix_node_head *rnh, struct rtentry *rt)
|
||||
rt_expunge(struct rib_head *rh, struct rtentry *rt)
|
||||
{
|
||||
#if !defined(RADIX_MPATH)
|
||||
struct radix_node *rn;
|
||||
@ -976,7 +1014,7 @@ rt_expunge(struct radix_node_head *rnh, struct rtentry *rt)
|
||||
int error = 0;
|
||||
|
||||
RT_LOCK_ASSERT(rt);
|
||||
RADIX_NODE_HEAD_LOCK_ASSERT(rnh);
|
||||
RIB_LOCK_ASSERT(rh);
|
||||
|
||||
#ifdef RADIX_MPATH
|
||||
fib = rt->rt_fibnum;
|
||||
@ -1001,7 +1039,7 @@ rt_expunge(struct radix_node_head *rnh, struct rtentry *rt)
|
||||
* Remove the item from the tree; it should be there,
|
||||
* but when callers invoke us blindly it may not (sigh).
|
||||
*/
|
||||
rn = rnh->rnh_deladdr(rt_key(rt), rt_mask(rt), rnh);
|
||||
rn = rh->rnh_deladdr(rt_key(rt), rt_mask(rt), &rh->head);
|
||||
if (rn == NULL) {
|
||||
error = ESRCH;
|
||||
goto bad;
|
||||
@ -1093,7 +1131,7 @@ rt_print(char *buf, int buflen, struct rtentry *rt)
|
||||
#ifdef RADIX_MPATH
|
||||
static int
|
||||
rn_mpath_update(int req, struct rt_addrinfo *info,
|
||||
struct radix_node_head *rnh, struct rtentry **ret_nrt)
|
||||
struct rib_head *rh, struct rtentry **ret_nrt)
|
||||
{
|
||||
/*
|
||||
* if we got multipath routes, we require users to specify
|
||||
@ -1103,7 +1141,7 @@ rn_mpath_update(int req, struct rt_addrinfo *info,
|
||||
struct radix_node *rn;
|
||||
int error = 0;
|
||||
|
||||
rn = rnh->rnh_lookup(dst, netmask, rnh);
|
||||
rn = rh->rnh_lookup(dst, netmask, rh);
|
||||
if (rn == NULL)
|
||||
return (ESRCH);
|
||||
rto = rt = RNTORT(rn);
|
||||
@ -1142,7 +1180,7 @@ rn_mpath_update(int req, struct rt_addrinfo *info,
|
||||
* remove from tree before returning it
|
||||
* to the caller
|
||||
*/
|
||||
rn = rnh->rnh_deladdr(dst, netmask, rnh);
|
||||
rn = rh->rnh_deladdr(dst, netmask, rh);
|
||||
KASSERT(rt == RNTORT(rn), ("radix node disappeared"));
|
||||
goto gwdelete;
|
||||
}
|
||||
@ -1207,7 +1245,7 @@ rtrequest1_fib(int req, struct rt_addrinfo *info, struct rtentry **ret_nrt,
|
||||
struct rtentry *rt0;
|
||||
#endif
|
||||
struct radix_node *rn;
|
||||
struct radix_node_head *rnh;
|
||||
struct rib_head *rh;
|
||||
struct ifaddr *ifa;
|
||||
struct sockaddr *ndst;
|
||||
struct sockaddr_storage mdst;
|
||||
@ -1227,15 +1265,15 @@ rtrequest1_fib(int req, struct rt_addrinfo *info, struct rtentry **ret_nrt,
|
||||
/*
|
||||
* Find the correct routing tree to use for this Address Family
|
||||
*/
|
||||
rnh = rt_tables_get_rnh(fibnum, dst->sa_family);
|
||||
if (rnh == NULL)
|
||||
rh = rt_tables_get_rnh(fibnum, dst->sa_family);
|
||||
if (rh == NULL)
|
||||
return (EAFNOSUPPORT);
|
||||
needlock = ((flags & RTF_RNH_LOCKED) == 0);
|
||||
flags &= ~RTF_RNH_LOCKED;
|
||||
if (needlock)
|
||||
RADIX_NODE_HEAD_LOCK(rnh);
|
||||
RIB_WLOCK(rh);
|
||||
else
|
||||
RADIX_NODE_HEAD_LOCK_ASSERT(rnh);
|
||||
RIB_LOCK_ASSERT(rh);
|
||||
/*
|
||||
* If we are adding a host route then we don't want to put
|
||||
* a netmask in the tree, nor do we want to clone it.
|
||||
@ -1250,8 +1288,8 @@ rtrequest1_fib(int req, struct rt_addrinfo *info, struct rtentry **ret_nrt,
|
||||
dst = (struct sockaddr *)&mdst;
|
||||
}
|
||||
#ifdef RADIX_MPATH
|
||||
if (rn_mpath_capable(rnh)) {
|
||||
error = rn_mpath_update(req, info, rnh, ret_nrt);
|
||||
if (rn_mpath_capable(rh)) {
|
||||
error = rn_mpath_update(req, info, rh, ret_nrt);
|
||||
/*
|
||||
* "bad" holds true for the success case
|
||||
* as well
|
||||
@ -1263,8 +1301,8 @@ rtrequest1_fib(int req, struct rt_addrinfo *info, struct rtentry **ret_nrt,
|
||||
#endif
|
||||
if ((flags & RTF_PINNED) == 0) {
|
||||
/* Check if target route can be deleted */
|
||||
rt = (struct rtentry *)rnh->rnh_lookup(dst,
|
||||
netmask, rnh);
|
||||
rt = (struct rtentry *)rh->rnh_lookup(dst,
|
||||
netmask, &rh->head);
|
||||
if ((rt != NULL) && (rt->rt_flags & RTF_PINNED))
|
||||
senderr(EADDRINUSE);
|
||||
}
|
||||
@ -1273,7 +1311,7 @@ rtrequest1_fib(int req, struct rt_addrinfo *info, struct rtentry **ret_nrt,
|
||||
* Remove the item from the tree and return it.
|
||||
* Complain if it is not there and do no more processing.
|
||||
*/
|
||||
rn = rnh->rnh_deladdr(dst, netmask, rnh);
|
||||
rn = rh->rnh_deladdr(dst, netmask, &rh->head);
|
||||
if (rn == NULL)
|
||||
senderr(ESRCH);
|
||||
if (rn->rn_flags & (RNF_ACTIVE | RNF_ROOT))
|
||||
@ -1359,7 +1397,7 @@ rtrequest1_fib(int req, struct rt_addrinfo *info, struct rtentry **ret_nrt,
|
||||
|
||||
/*
|
||||
* 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 rh->rnh_addaddr() can
|
||||
* examine the ifa and ifa->ifa_ifp if it so desires.
|
||||
*/
|
||||
rt->rt_ifa = ifa;
|
||||
@ -1370,8 +1408,8 @@ rtrequest1_fib(int req, struct rt_addrinfo *info, struct rtentry **ret_nrt,
|
||||
|
||||
#ifdef RADIX_MPATH
|
||||
/* do not permit exactly the same dst/mask/gw pair */
|
||||
if (rn_mpath_capable(rnh) &&
|
||||
rt_mpath_conflict(rnh, rt, netmask)) {
|
||||
if (rn_mpath_capable(rh) &&
|
||||
rt_mpath_conflict(rh, rt, netmask)) {
|
||||
ifa_free(rt->rt_ifa);
|
||||
Free(rt_key(rt));
|
||||
uma_zfree(V_rtzone, rt);
|
||||
@ -1390,7 +1428,7 @@ rtrequest1_fib(int req, struct rt_addrinfo *info, struct rtentry **ret_nrt,
|
||||
case AF_INET:
|
||||
#endif
|
||||
#if defined(INET6) || defined(INET)
|
||||
rn = rnh->rnh_matchaddr(dst, rnh);
|
||||
rn = rh->rnh_matchaddr(dst, rh);
|
||||
if (rn && ((rn->rn_flags & RNF_ROOT) == 0)) {
|
||||
struct sockaddr *mask;
|
||||
u_char *m, *n;
|
||||
@ -1433,7 +1471,7 @@ rtrequest1_fib(int req, struct rt_addrinfo *info, struct rtentry **ret_nrt,
|
||||
#endif /* FLOWTABLE */
|
||||
|
||||
/* XXX mtu manipulation will be done in rnh_addaddr -- itojun */
|
||||
rn = rnh->rnh_addaddr(ndst, netmask, rnh, rt->rt_nodes);
|
||||
rn = rh->rnh_addaddr(ndst, netmask, &rh->head, rt->rt_nodes);
|
||||
/*
|
||||
* If it still failed to go into the tree,
|
||||
* then un-make it (this should be a function)
|
||||
@ -1473,14 +1511,14 @@ rtrequest1_fib(int req, struct rt_addrinfo *info, struct rtentry **ret_nrt,
|
||||
RT_UNLOCK(rt);
|
||||
break;
|
||||
case RTM_CHANGE:
|
||||
error = rtrequest1_fib_change(rnh, info, ret_nrt, fibnum);
|
||||
error = rtrequest1_fib_change(rh, info, ret_nrt, fibnum);
|
||||
break;
|
||||
default:
|
||||
error = EOPNOTSUPP;
|
||||
}
|
||||
bad:
|
||||
if (needlock)
|
||||
RADIX_NODE_HEAD_UNLOCK(rnh);
|
||||
RIB_WUNLOCK(rh);
|
||||
return (error);
|
||||
#undef senderr
|
||||
}
|
||||
@ -1493,7 +1531,7 @@ bad:
|
||||
#undef flags
|
||||
|
||||
static int
|
||||
rtrequest1_fib_change(struct radix_node_head *rnh, struct rt_addrinfo *info,
|
||||
rtrequest1_fib_change(struct rib_head *rh, struct rt_addrinfo *info,
|
||||
struct rtentry **ret_nrt, u_int fibnum)
|
||||
{
|
||||
struct rtentry *rt = NULL;
|
||||
@ -1501,8 +1539,8 @@ rtrequest1_fib_change(struct radix_node_head *rnh, struct rt_addrinfo *info,
|
||||
int free_ifa = 0;
|
||||
int family, mtu;
|
||||
|
||||
rt = (struct rtentry *)rnh->rnh_lookup(info->rti_info[RTAX_DST],
|
||||
info->rti_info[RTAX_NETMASK], rnh);
|
||||
rt = (struct rtentry *)rh->rnh_lookup(info->rti_info[RTAX_DST],
|
||||
info->rti_info[RTAX_NETMASK], &rh->head);
|
||||
|
||||
if (rt == NULL)
|
||||
return (ESRCH);
|
||||
@ -1512,7 +1550,7 @@ rtrequest1_fib_change(struct radix_node_head *rnh, struct rt_addrinfo *info,
|
||||
* If we got multipath routes,
|
||||
* we require users to specify a matching RTAX_GATEWAY.
|
||||
*/
|
||||
if (rn_mpath_capable(rnh)) {
|
||||
if (rn_mpath_capable(rh)) {
|
||||
rt = rt_mpath_matchgate(rt, info->rti_info[RTAX_GATEWAY]);
|
||||
if (rt == NULL)
|
||||
return (ESRCH);
|
||||
@ -1609,13 +1647,13 @@ rt_setgate(struct rtentry *rt, struct sockaddr *dst, struct sockaddr *gate)
|
||||
/* XXX dst may be overwritten, can we move this to below */
|
||||
int dlen = SA_SIZE(dst), glen = SA_SIZE(gate);
|
||||
#ifdef INVARIANTS
|
||||
struct radix_node_head *rnh;
|
||||
struct rib_head *rh;
|
||||
|
||||
rnh = rt_tables_get_rnh(rt->rt_fibnum, dst->sa_family);
|
||||
rh = rt_tables_get_rnh(rt->rt_fibnum, dst->sa_family);
|
||||
#endif
|
||||
|
||||
RT_LOCK_ASSERT(rt);
|
||||
RADIX_NODE_HEAD_LOCK_ASSERT(rnh);
|
||||
RIB_LOCK_ASSERT(rh);
|
||||
|
||||
/*
|
||||
* Prepare to store the gateway in rt->rt_gateway.
|
||||
@ -1688,7 +1726,7 @@ rtinit1(struct ifaddr *ifa, int cmd, int flags, int fibnum)
|
||||
int didwork = 0;
|
||||
int a_failure = 0;
|
||||
static struct sockaddr_dl null_sdl = {sizeof(null_sdl), AF_LINK};
|
||||
struct radix_node_head *rnh;
|
||||
struct rib_head *rh;
|
||||
|
||||
if (flags & RTF_HOST) {
|
||||
dst = ifa->ifa_dstaddr;
|
||||
@ -1752,14 +1790,14 @@ rtinit1(struct ifaddr *ifa, int cmd, int flags, int fibnum)
|
||||
* Look up an rtentry that is in the routing tree and
|
||||
* contains the correct info.
|
||||
*/
|
||||
rnh = rt_tables_get_rnh(fibnum, dst->sa_family);
|
||||
if (rnh == NULL)
|
||||
rh = rt_tables_get_rnh(fibnum, dst->sa_family);
|
||||
if (rh == NULL)
|
||||
/* this table doesn't exist but others might */
|
||||
continue;
|
||||
RADIX_NODE_HEAD_RLOCK(rnh);
|
||||
rn = rnh->rnh_lookup(dst, netmask, rnh);
|
||||
RIB_RLOCK(rh);
|
||||
rn = rh->rnh_lookup(dst, netmask, &rh->head);
|
||||
#ifdef RADIX_MPATH
|
||||
if (rn_mpath_capable(rnh)) {
|
||||
if (rn_mpath_capable(rh)) {
|
||||
|
||||
if (rn == NULL)
|
||||
error = ESRCH;
|
||||
@ -1782,7 +1820,7 @@ rtinit1(struct ifaddr *ifa, int cmd, int flags, int fibnum)
|
||||
error = (rn == NULL ||
|
||||
(rn->rn_flags & RNF_ROOT) ||
|
||||
RNTORT(rn)->rt_ifa != ifa);
|
||||
RADIX_NODE_HEAD_RUNLOCK(rnh);
|
||||
RIB_RUNLOCK(rh);
|
||||
if (error) {
|
||||
/* this is only an error if bad on ALL tables */
|
||||
continue;
|
||||
@ -1814,8 +1852,8 @@ rtinit1(struct ifaddr *ifa, int cmd, int flags, int fibnum)
|
||||
* RTM_DELETE message, and retry adding
|
||||
* interface prefix.
|
||||
*/
|
||||
rnh = rt_tables_get_rnh(fibnum, dst->sa_family);
|
||||
RADIX_NODE_HEAD_LOCK(rnh);
|
||||
rh = rt_tables_get_rnh(fibnum, dst->sa_family);
|
||||
RIB_WLOCK(rh);
|
||||
|
||||
/* Delete old prefix */
|
||||
info.rti_ifa = NULL;
|
||||
@ -1829,7 +1867,7 @@ rtinit1(struct ifaddr *ifa, int cmd, int flags, int fibnum)
|
||||
error = rtrequest1_fib(cmd, &info, &rt, fibnum);
|
||||
}
|
||||
|
||||
RADIX_NODE_HEAD_UNLOCK(rnh);
|
||||
RIB_WUNLOCK(rh);
|
||||
}
|
||||
|
||||
|
||||
|
@ -107,6 +107,7 @@ VNET_DECLARE(u_int, rt_add_addr_allfibs); /* Announce interfaces to all fibs */
|
||||
#endif
|
||||
#endif
|
||||
|
||||
struct rib_head;
|
||||
struct rtentry;
|
||||
#if !defined(_KERNEL) || defined(_WANT_RTENTRY)
|
||||
/* This structure is kept for compatibility reasons only */
|
||||
@ -292,7 +293,7 @@ struct rt_addrinfo {
|
||||
#define RT_LINK_IS_UP(ifp) (!((ifp)->if_capabilities & IFCAP_LINKSTATE) \
|
||||
|| (ifp)->if_link_state == LINK_STATE_UP)
|
||||
|
||||
struct radix_node_head *rt_tables_get_rnh(int, int);
|
||||
struct rib_head *rt_tables_get_rnh(int, int);
|
||||
|
||||
struct ifmultiaddr;
|
||||
|
||||
@ -324,12 +325,12 @@ int rtsock_routemsg(int, struct ifnet *ifp, int, struct rtentry *, int);
|
||||
* RTFREE() uses an unlocked entry.
|
||||
*/
|
||||
|
||||
int rt_expunge(struct radix_node_head *, struct rtentry *);
|
||||
int rt_expunge(struct rib_head *, struct rtentry *);
|
||||
void rtfree(struct rtentry *);
|
||||
int rt_check(struct rtentry **, struct rtentry **, struct sockaddr *);
|
||||
|
||||
typedef int rt_walktree_f_t(struct rtentry *, void *);
|
||||
typedef void rt_setwarg_t(struct radix_node_head *, uint32_t, int, void *);
|
||||
typedef void rt_setwarg_t(struct rib_head *, uint32_t, int, void *);
|
||||
void rt_foreach_fib(int af, rt_setwarg_t *, rt_walktree_f_t *, void *);
|
||||
void rt_flushifroutes(struct ifnet *ifp);
|
||||
|
||||
|
@ -30,6 +30,31 @@
|
||||
#ifndef _NET_ROUTE_INTERNAL_H_
|
||||
#define _NET_ROUTE_INTERNAL_H_
|
||||
|
||||
struct rib_head {
|
||||
struct radix_head head;
|
||||
rn_matchaddr_f_t *rnh_matchaddr; /* longest match for sockaddr */
|
||||
rn_addaddr_f_t *rnh_addaddr; /* add based on sockaddr*/
|
||||
rn_deladdr_f_t *rnh_deladdr; /* remove based on sockaddr */
|
||||
rn_lookup_f_t *rnh_lookup; /* exact match for sockaddr */
|
||||
rn_walktree_t *rnh_walktree; /* traverse tree */
|
||||
rn_walktree_from_t *rnh_walktree_from; /* traverse tree below a */
|
||||
rn_close_t *rnh_close; /*do something when the last ref drops*/
|
||||
struct radix_node rnh_nodes[3]; /* empty tree for common case */
|
||||
struct rwlock rib_lock; /* locks entire radix tree */
|
||||
struct radix_mask_head rmhead; /* masks radix head */
|
||||
};
|
||||
|
||||
#define RIB_RLOCK(rh) rw_rlock(&(rh)->rib_lock)
|
||||
#define RIB_RUNLOCK(rh) rw_runlock(&(rh)->rib_lock)
|
||||
#define RIB_WLOCK(rh) rw_wlock(&(rh)->rib_lock)
|
||||
#define RIB_WUNLOCK(rh) rw_wunlock(&(rh)->rib_lock)
|
||||
#define RIB_LOCK_ASSERT(rh) rw_assert(&(rh)->rib_lock, RA_LOCKED)
|
||||
#define RIB_WLOCK_ASSERT(rh) rw_assert(&(rh)->rib_lock, RA_WLOCKED)
|
||||
|
||||
struct rib_head *rt_table_init(int offset);
|
||||
void rt_table_destroy(struct rib_head *rh);
|
||||
|
||||
|
||||
struct rtentry {
|
||||
struct radix_node rt_nodes[2]; /* tree glue, and other values */
|
||||
/*
|
||||
|
@ -194,8 +194,8 @@ fib_choose_prepend(uint32_t fibnum, struct nhop_prepend *nh_src,
|
||||
idx = nh_multi->nh_nhops[flowid % nh_multi->nh_count];
|
||||
#if 0
|
||||
KASSERT((fibnum < rt_numfibs), ("fib4_lookup_prepend§: bad fibnum"));
|
||||
rnh = rt_tables_get_rnh(fibnum, AF_INET);
|
||||
//nh_src = &rnh->nhops[i];
|
||||
rh = rt_tables_get_rnh(fibnum, AF_INET);
|
||||
//nh_src = &rh->nhops[i];
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -255,7 +255,7 @@ int
|
||||
fib4_lookup_prepend(uint32_t fibnum, struct in_addr dst, struct mbuf *m,
|
||||
struct nhop_prepend *nh, struct nhop4_extended *nh_ext)
|
||||
{
|
||||
struct radix_node_head *rnh;
|
||||
struct rib_head *rh;
|
||||
struct radix_node *rn;
|
||||
struct sockaddr_in *gw_sa, sin;
|
||||
struct ifnet *lifp;
|
||||
@ -266,8 +266,8 @@ fib4_lookup_prepend(uint32_t fibnum, struct in_addr dst, struct mbuf *m,
|
||||
struct rtentry *rte;
|
||||
|
||||
KASSERT((fibnum < rt_numfibs), ("fib4_lookup_prepend: bad fibnum"));
|
||||
rnh = rt_tables_get_rnh(fibnum, AF_INET);
|
||||
if (rnh == NULL)
|
||||
rh = rt_tables_get_rnh(fibnum, AF_INET);
|
||||
if (rh == NULL)
|
||||
return (EHOSTUNREACH);
|
||||
|
||||
/* Prepare lookup key */
|
||||
@ -275,12 +275,12 @@ fib4_lookup_prepend(uint32_t fibnum, struct in_addr dst, struct mbuf *m,
|
||||
sin.sin_len = sizeof(struct sockaddr_in);
|
||||
sin.sin_addr = dst;
|
||||
|
||||
RADIX_NODE_HEAD_RLOCK(rnh);
|
||||
rn = rnh->rnh_matchaddr((void *)&sin, rnh);
|
||||
RIB_RLOCK(rh);
|
||||
rn = rh->rnh_matchaddr((void *)&sin, &rh->head);
|
||||
rte = RNTORT(rn);
|
||||
if (rn == NULL || ((rn->rn_flags & RNF_ROOT) != 0) ||
|
||||
RT_LINK_IS_UP(rte->rt_ifp) == 0) {
|
||||
RADIX_NODE_HEAD_RUNLOCK(rnh);
|
||||
RIB_RUNLOCK(rh);
|
||||
return (EHOSTUNREACH);
|
||||
}
|
||||
|
||||
@ -321,7 +321,7 @@ fib4_lookup_prepend(uint32_t fibnum, struct in_addr dst, struct mbuf *m,
|
||||
fib4_rte_to_nh_extended(rte, dst, nh_ext);
|
||||
}
|
||||
|
||||
RADIX_NODE_HEAD_RUNLOCK(rnh);
|
||||
RIB_RUNLOCK(rh);
|
||||
|
||||
nh->nh_flags = flags;
|
||||
/*
|
||||
@ -501,14 +501,14 @@ int
|
||||
fib4_lookup_nh_basic(uint32_t fibnum, struct in_addr dst, uint32_t flowid,
|
||||
struct nhop4_basic *pnh4)
|
||||
{
|
||||
struct radix_node_head *rnh;
|
||||
struct rib_head *rh;
|
||||
struct radix_node *rn;
|
||||
struct sockaddr_in sin;
|
||||
struct rtentry *rte;
|
||||
|
||||
KASSERT((fibnum < rt_numfibs), ("fib4_lookup_nh_basic: bad fibnum"));
|
||||
rnh = rt_tables_get_rnh(fibnum, AF_INET);
|
||||
if (rnh == NULL)
|
||||
rh = rt_tables_get_rnh(fibnum, AF_INET);
|
||||
if (rh == NULL)
|
||||
return (ENOENT);
|
||||
|
||||
/* Prepare lookup key */
|
||||
@ -516,19 +516,19 @@ fib4_lookup_nh_basic(uint32_t fibnum, struct in_addr dst, uint32_t flowid,
|
||||
sin.sin_len = sizeof(struct sockaddr_in);
|
||||
sin.sin_addr = dst;
|
||||
|
||||
RADIX_NODE_HEAD_RLOCK(rnh);
|
||||
rn = rnh->rnh_matchaddr((void *)&sin, rnh);
|
||||
RIB_RLOCK(rh);
|
||||
rn = rh->rnh_matchaddr((void *)&sin, &rh->head);
|
||||
if (rn != NULL && ((rn->rn_flags & RNF_ROOT) == 0)) {
|
||||
rte = RNTORT(rn);
|
||||
/* Ensure route & ifp is UP */
|
||||
if (RT_LINK_IS_UP(rte->rt_ifp)) {
|
||||
fib4_rte_to_nh_basic(rte, dst, pnh4);
|
||||
RADIX_NODE_HEAD_RUNLOCK(rnh);
|
||||
RIB_RUNLOCK(rh);
|
||||
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
RADIX_NODE_HEAD_RUNLOCK(rnh);
|
||||
RIB_RUNLOCK(rh);
|
||||
|
||||
return (ENOENT);
|
||||
}
|
||||
@ -537,14 +537,14 @@ int
|
||||
fib4_lookup_nh_ifp(uint32_t fibnum, struct in_addr dst, uint32_t flowid,
|
||||
struct nhop4_basic *pnh4)
|
||||
{
|
||||
struct radix_node_head *rnh;
|
||||
struct rib_head *rh;
|
||||
struct radix_node *rn;
|
||||
struct sockaddr_in sin;
|
||||
struct rtentry *rte;
|
||||
|
||||
KASSERT((fibnum < rt_numfibs), ("fib4_lookup_nh_ifp: bad fibnum"));
|
||||
rnh = rt_tables_get_rnh(fibnum, AF_INET);
|
||||
if (rnh == NULL)
|
||||
rh = rt_tables_get_rnh(fibnum, AF_INET);
|
||||
if (rh == NULL)
|
||||
return (ENOENT);
|
||||
|
||||
/* Prepare lookup key */
|
||||
@ -552,19 +552,19 @@ fib4_lookup_nh_ifp(uint32_t fibnum, struct in_addr dst, uint32_t flowid,
|
||||
sin.sin_len = sizeof(struct sockaddr_in);
|
||||
sin.sin_addr = dst;
|
||||
|
||||
RADIX_NODE_HEAD_RLOCK(rnh);
|
||||
rn = rnh->rnh_matchaddr((void *)&sin, rnh);
|
||||
RIB_RLOCK(rh);
|
||||
rn = rh->rnh_matchaddr((void *)&sin, &rh->head);
|
||||
if (rn != NULL && ((rn->rn_flags & RNF_ROOT) == 0)) {
|
||||
rte = RNTORT(rn);
|
||||
/* Ensure route & ifp is UP */
|
||||
if (RT_LINK_IS_UP(rte->rt_ifp)) {
|
||||
fib4_rte_to_nh_basic(rte, dst, pnh4);
|
||||
RADIX_NODE_HEAD_RUNLOCK(rnh);
|
||||
RIB_RUNLOCK(rh);
|
||||
pnh4->nh_ifp = rte->rt_ifp;
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
RADIX_NODE_HEAD_RUNLOCK(rnh);
|
||||
RIB_RUNLOCK(rh);
|
||||
|
||||
return (ENOENT);
|
||||
}
|
||||
@ -582,14 +582,14 @@ int
|
||||
fib4_lookup_nh_ext(uint32_t fibnum, struct in_addr dst, uint32_t flowid,
|
||||
uint32_t flags, struct nhop4_extended *pnh4)
|
||||
{
|
||||
struct radix_node_head *rnh;
|
||||
struct rib_head *rh;
|
||||
struct radix_node *rn;
|
||||
struct sockaddr_in sin;
|
||||
struct rtentry *rte;
|
||||
|
||||
KASSERT((fibnum < rt_numfibs), ("fib4_lookup_nh_ext: bad fibnum"));
|
||||
rnh = rt_tables_get_rnh(fibnum, AF_INET);
|
||||
if (rnh == NULL)
|
||||
rh = rt_tables_get_rnh(fibnum, AF_INET);
|
||||
if (rh == NULL)
|
||||
return (ENOENT);
|
||||
|
||||
/* Prepare lookup key */
|
||||
@ -597,8 +597,8 @@ fib4_lookup_nh_ext(uint32_t fibnum, struct in_addr dst, uint32_t flowid,
|
||||
sin.sin_len = sizeof(struct sockaddr_in);
|
||||
sin.sin_addr = dst;
|
||||
|
||||
RADIX_NODE_HEAD_RLOCK(rnh);
|
||||
rn = rnh->rnh_matchaddr((void *)&sin, rnh);
|
||||
RIB_RLOCK(rh);
|
||||
rn = rh->rnh_matchaddr((void *)&sin, &rh->head);
|
||||
if (rn != NULL && ((rn->rn_flags & RNF_ROOT) == 0)) {
|
||||
rte = RNTORT(rn);
|
||||
/* Ensure route & ifp is UP */
|
||||
@ -607,12 +607,12 @@ fib4_lookup_nh_ext(uint32_t fibnum, struct in_addr dst, uint32_t flowid,
|
||||
if ((flags & NHOP_LOOKUP_REF) != 0) {
|
||||
/* TODO: Do lwref on egress ifp's */
|
||||
}
|
||||
RADIX_NODE_HEAD_RUNLOCK(rnh);
|
||||
RIB_RUNLOCK(rh);
|
||||
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
RADIX_NODE_HEAD_RUNLOCK(rnh);
|
||||
RIB_RUNLOCK(rh);
|
||||
|
||||
return (ENOENT);
|
||||
}
|
||||
@ -627,14 +627,14 @@ int
|
||||
rib4_lookup_nh_ext(uint32_t fibnum, struct in_addr dst, uint32_t flowid,
|
||||
uint32_t flags, struct rt4_extended *prt4)
|
||||
{
|
||||
struct radix_node_head *rnh;
|
||||
struct rib_head *rh;
|
||||
struct radix_node *rn;
|
||||
struct sockaddr_in sin;
|
||||
struct rtentry *rte;
|
||||
|
||||
KASSERT((fibnum < rt_numfibs), ("rib4_lookup_nh_ext: bad fibnum"));
|
||||
rnh = rt_tables_get_rnh(fibnum, AF_INET);
|
||||
if (rnh == NULL)
|
||||
rh = rt_tables_get_rnh(fibnum, AF_INET);
|
||||
if (rh == NULL)
|
||||
return (ENOENT);
|
||||
|
||||
/* Prepare lookup key */
|
||||
@ -642,8 +642,8 @@ rib4_lookup_nh_ext(uint32_t fibnum, struct in_addr dst, uint32_t flowid,
|
||||
sin.sin_len = sizeof(struct sockaddr_in);
|
||||
sin.sin_addr = dst;
|
||||
|
||||
RADIX_NODE_HEAD_RLOCK(rnh);
|
||||
rn = rnh->rnh_matchaddr((void *)&sin, rnh);
|
||||
RIB_RLOCK(rh);
|
||||
rn = rh->rnh_matchaddr((void *)&sin, &rh->head);
|
||||
if (rn != NULL && ((rn->rn_flags & RNF_ROOT) == 0)) {
|
||||
rte = RNTORT(rn);
|
||||
/* Ensure route & ifp is UP */
|
||||
@ -652,11 +652,11 @@ rib4_lookup_nh_ext(uint32_t fibnum, struct in_addr dst, uint32_t flowid,
|
||||
if ((flags & NHOP_LOOKUP_REF) != 0) {
|
||||
/* TODO: Do lwref on egress ifp's */
|
||||
}
|
||||
RADIX_NODE_HEAD_RUNLOCK(rnh);
|
||||
RIB_RUNLOCK(rh);
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
RADIX_NODE_HEAD_RUNLOCK(rnh);
|
||||
RIB_RUNLOCK(rh);
|
||||
|
||||
return (ENOENT);
|
||||
}
|
||||
@ -749,7 +749,7 @@ int
|
||||
fib6_lookup_prepend(uint32_t fibnum, struct in6_addr *dst, uint32_t scopeid,
|
||||
struct mbuf *m, struct nhop_prepend *nh, struct nhop6_extended *nh_ext)
|
||||
{
|
||||
struct radix_node_head *rnh;
|
||||
struct rib_head *rh;
|
||||
struct radix_node *rn;
|
||||
struct sockaddr_in6 sin6, *gw_sa;
|
||||
struct in6_addr gw6;
|
||||
@ -771,8 +771,8 @@ fib6_lookup_prepend(uint32_t fibnum, struct in6_addr *dst, uint32_t scopeid,
|
||||
|
||||
|
||||
KASSERT((fibnum < rt_numfibs), ("fib6_lookup_prepend: bad fibnum"));
|
||||
rnh = rt_tables_get_rnh(fibnum, AF_INET6);
|
||||
if (rnh == NULL)
|
||||
rh = rt_tables_get_rnh(fibnum, AF_INET6);
|
||||
if (rh == NULL)
|
||||
return (ENOENT);
|
||||
|
||||
/* Prepare lookup key */
|
||||
@ -783,12 +783,12 @@ fib6_lookup_prepend(uint32_t fibnum, struct in6_addr *dst, uint32_t scopeid,
|
||||
sa6_embedscope(&sin6, 0);
|
||||
|
||||
|
||||
RADIX_NODE_HEAD_RLOCK(rnh);
|
||||
rn = rnh->rnh_matchaddr((void *)&sin6, rnh);
|
||||
RIB_RLOCK(rh);
|
||||
rn = rh->rnh_matchaddr((void *)&sin6, &rh->head);
|
||||
rte = RNTORT(rn);
|
||||
if (rn == NULL || ((rn->rn_flags & RNF_ROOT) != 0) ||
|
||||
RT_LINK_IS_UP(rte->rt_ifp) == 0) {
|
||||
RADIX_NODE_HEAD_RUNLOCK(rnh);
|
||||
RIB_RUNLOCK(rh);
|
||||
return (EHOSTUNREACH);
|
||||
}
|
||||
|
||||
@ -820,7 +820,7 @@ fib6_lookup_prepend(uint32_t fibnum, struct in6_addr *dst, uint32_t scopeid,
|
||||
nh->lifp_idx = lifp->if_index;
|
||||
nh->i.ifp_idx = nh->lifp_idx;
|
||||
|
||||
RADIX_NODE_HEAD_RUNLOCK(rnh);
|
||||
RIB_RUNLOCK(rh);
|
||||
|
||||
nh->nh_flags = flags;
|
||||
do_l2:
|
||||
@ -1123,7 +1123,7 @@ int
|
||||
fib6_lookup_nh_ifp(uint32_t fibnum, struct in6_addr *dst, uint32_t scopeid,
|
||||
uint32_t flowid, struct nhop6_basic *pnh6)
|
||||
{
|
||||
struct radix_node_head *rnh;
|
||||
struct rib_head *rh;
|
||||
struct radix_node *rn;
|
||||
struct sockaddr_in6 sin6;
|
||||
struct rtentry *rte;
|
||||
@ -1135,8 +1135,8 @@ fib6_lookup_nh_ifp(uint32_t fibnum, struct in6_addr *dst, uint32_t scopeid,
|
||||
}
|
||||
|
||||
KASSERT((fibnum < rt_numfibs), ("fib6_lookup_nh_basic: bad fibnum"));
|
||||
rnh = rt_tables_get_rnh(fibnum, AF_INET6);
|
||||
if (rnh == NULL)
|
||||
rh = rt_tables_get_rnh(fibnum, AF_INET6);
|
||||
if (rh == NULL)
|
||||
return (ENOENT);
|
||||
|
||||
/* Prepare lookup key */
|
||||
@ -1145,19 +1145,19 @@ fib6_lookup_nh_ifp(uint32_t fibnum, struct in6_addr *dst, uint32_t scopeid,
|
||||
sin6.sin6_scope_id = scopeid;
|
||||
sa6_embedscope(&sin6, 0);
|
||||
|
||||
RADIX_NODE_HEAD_RLOCK(rnh);
|
||||
rn = rnh->rnh_matchaddr((void *)&sin6, rnh);
|
||||
RIB_RLOCK(rh);
|
||||
rn = rh->rnh_matchaddr((void *)&sin6, &rh->head);
|
||||
if (rn != NULL && ((rn->rn_flags & RNF_ROOT) == 0)) {
|
||||
rte = RNTORT(rn);
|
||||
/* Ensure route & ifp is UP */
|
||||
if (RT_LINK_IS_UP(rte->rt_ifp)) {
|
||||
fib6_rte_to_nh_basic(rte, dst, pnh6);
|
||||
pnh6->nh_ifp = rte->rt_ifp;
|
||||
RADIX_NODE_HEAD_RUNLOCK(rnh);
|
||||
RIB_RUNLOCK(rh);
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
RADIX_NODE_HEAD_RUNLOCK(rnh);
|
||||
RIB_RUNLOCK(rh);
|
||||
|
||||
return (ENOENT);
|
||||
}
|
||||
@ -1166,7 +1166,7 @@ int
|
||||
fib6_lookup_nh_basic(uint32_t fibnum, struct in6_addr *dst, uint32_t scopeid,
|
||||
uint32_t flowid, struct nhop6_basic *pnh6)
|
||||
{
|
||||
struct radix_node_head *rnh;
|
||||
struct rib_head *rh;
|
||||
struct radix_node *rn;
|
||||
struct sockaddr_in6 sin6;
|
||||
struct rtentry *rte;
|
||||
@ -1177,8 +1177,8 @@ fib6_lookup_nh_basic(uint32_t fibnum, struct in6_addr *dst, uint32_t scopeid,
|
||||
}
|
||||
|
||||
KASSERT((fibnum < rt_numfibs), ("fib6_lookup_nh_basic: bad fibnum"));
|
||||
rnh = rt_tables_get_rnh(fibnum, AF_INET6);
|
||||
if (rnh == NULL)
|
||||
rh = rt_tables_get_rnh(fibnum, AF_INET6);
|
||||
if (rh == NULL)
|
||||
return (ENOENT);
|
||||
|
||||
/* Prepare lookup key */
|
||||
@ -1187,18 +1187,18 @@ fib6_lookup_nh_basic(uint32_t fibnum, struct in6_addr *dst, uint32_t scopeid,
|
||||
sin6.sin6_scope_id = scopeid;
|
||||
sa6_embedscope(&sin6, 0);
|
||||
|
||||
RADIX_NODE_HEAD_RLOCK(rnh);
|
||||
rn = rnh->rnh_matchaddr((void *)&sin6, rnh);
|
||||
RIB_RLOCK(rh);
|
||||
rn = rh->rnh_matchaddr((void *)&sin6, &rh->head);
|
||||
if (rn != NULL && ((rn->rn_flags & RNF_ROOT) == 0)) {
|
||||
rte = RNTORT(rn);
|
||||
/* Ensure route & ifp is UP */
|
||||
if (RT_LINK_IS_UP(rte->rt_ifp)) {
|
||||
fib6_rte_to_nh_basic(rte, dst, pnh6);
|
||||
RADIX_NODE_HEAD_RUNLOCK(rnh);
|
||||
RIB_RUNLOCK(rh);
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
RADIX_NODE_HEAD_RUNLOCK(rnh);
|
||||
RIB_RUNLOCK(rh);
|
||||
|
||||
return (ENOENT);
|
||||
}
|
||||
@ -1216,7 +1216,7 @@ int
|
||||
fib6_lookup_nh_ext(uint32_t fibnum, struct in6_addr *dst, uint32_t scopeid,
|
||||
uint32_t flowid, uint32_t flags, struct nhop6_extended *pnh6)
|
||||
{
|
||||
struct radix_node_head *rnh;
|
||||
struct rib_head *rh;
|
||||
struct radix_node *rn;
|
||||
struct sockaddr_in6 sin6;
|
||||
struct rtentry *rte;
|
||||
@ -1228,8 +1228,8 @@ fib6_lookup_nh_ext(uint32_t fibnum, struct in6_addr *dst, uint32_t scopeid,
|
||||
}
|
||||
|
||||
KASSERT((fibnum < rt_numfibs), ("fib4_lookup_nh_ext: bad fibnum"));
|
||||
rnh = rt_tables_get_rnh(fibnum, AF_INET6);
|
||||
if (rnh == NULL)
|
||||
rh = rt_tables_get_rnh(fibnum, AF_INET6);
|
||||
if (rh == NULL)
|
||||
return (ENOENT);
|
||||
|
||||
/* Prepare lookup key */
|
||||
@ -1239,8 +1239,8 @@ fib6_lookup_nh_ext(uint32_t fibnum, struct in6_addr *dst, uint32_t scopeid,
|
||||
sin6.sin6_scope_id = scopeid;
|
||||
sa6_embedscope(&sin6, 0);
|
||||
|
||||
RADIX_NODE_HEAD_RLOCK(rnh);
|
||||
rn = rnh->rnh_matchaddr((void *)&sin6, rnh);
|
||||
RIB_RLOCK(rh);
|
||||
rn = rh->rnh_matchaddr((void *)&sin6, &rh->head);
|
||||
if (rn != NULL && ((rn->rn_flags & RNF_ROOT) == 0)) {
|
||||
rte = RNTORT(rn);
|
||||
/* Ensure route & ifp is UP */
|
||||
@ -1249,12 +1249,12 @@ fib6_lookup_nh_ext(uint32_t fibnum, struct in6_addr *dst, uint32_t scopeid,
|
||||
if ((flags & NHOP_LOOKUP_REF) != 0) {
|
||||
/* TODO: Do lwref on egress ifp's */
|
||||
}
|
||||
RADIX_NODE_HEAD_RUNLOCK(rnh);
|
||||
RIB_RUNLOCK(rh);
|
||||
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
RADIX_NODE_HEAD_RUNLOCK(rnh);
|
||||
RIB_RUNLOCK(rh);
|
||||
|
||||
return (ENOENT);
|
||||
}
|
||||
@ -1269,7 +1269,7 @@ int
|
||||
rib6_lookup_nh_ext(uint32_t fibnum, struct in6_addr *dst, uint32_t scopeid,
|
||||
uint32_t flowid, uint32_t flags, struct rt6_extended *prt6)
|
||||
{
|
||||
struct radix_node_head *rnh;
|
||||
struct rib_head *rh;
|
||||
struct radix_node *rn;
|
||||
struct sockaddr_in6 sin6;
|
||||
struct rtentry *rte;
|
||||
@ -1281,8 +1281,8 @@ rib6_lookup_nh_ext(uint32_t fibnum, struct in6_addr *dst, uint32_t scopeid,
|
||||
}
|
||||
|
||||
KASSERT((fibnum < rt_numfibs), ("rib6_lookup_nh_ext: bad fibnum"));
|
||||
rnh = rt_tables_get_rnh(fibnum, AF_INET6);
|
||||
if (rnh == NULL)
|
||||
rh = rt_tables_get_rnh(fibnum, AF_INET6);
|
||||
if (rh == NULL)
|
||||
return (ENOENT);
|
||||
|
||||
/* Prepare lookup key */
|
||||
@ -1292,8 +1292,8 @@ rib6_lookup_nh_ext(uint32_t fibnum, struct in6_addr *dst, uint32_t scopeid,
|
||||
sin6.sin6_scope_id = scopeid;
|
||||
sa6_embedscope(&sin6, 0);
|
||||
|
||||
RADIX_NODE_HEAD_RLOCK(rnh);
|
||||
rn = rnh->rnh_matchaddr((void *)&sin6, rnh);
|
||||
RIB_RLOCK(rh);
|
||||
rn = rh->rnh_matchaddr((void *)&sin6, &rh->head);
|
||||
if (rn != NULL && ((rn->rn_flags & RNF_ROOT) == 0)) {
|
||||
rte = RNTORT(rn);
|
||||
/* Ensure route & ifp is UP */
|
||||
@ -1302,12 +1302,12 @@ rib6_lookup_nh_ext(uint32_t fibnum, struct in6_addr *dst, uint32_t scopeid,
|
||||
if ((flags & NHOP_LOOKUP_REF) != 0) {
|
||||
/* TODO: Do lwref on egress ifp's */
|
||||
}
|
||||
RADIX_NODE_HEAD_RUNLOCK(rnh);
|
||||
RIB_RUNLOCK(rh);
|
||||
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
RADIX_NODE_HEAD_RUNLOCK(rnh);
|
||||
RIB_RUNLOCK(rh);
|
||||
|
||||
return (ENOENT);
|
||||
}
|
||||
|
@ -287,7 +287,7 @@ int fib6_sendmbuf(struct ifnet *ifp, struct ifnet *origifp, struct mbuf *m,
|
||||
|
||||
typedef void *fib_init_t(u_int fibnum);
|
||||
typedef void fib_destroy_t(void *state);
|
||||
typedef int fib_dump_t(void *state, struct radix_node_head *rnh);
|
||||
typedef int fib_dump_t(void *state, struct rib_head *rh);
|
||||
typedef int fib_change_t(void *state, int req, struct rtentry *rte,
|
||||
struct rt_addrinfo *info);
|
||||
typedef int fib_lookup_t(void *state, void *key, uint64_t *attr, u_int flowid,
|
||||
@ -320,7 +320,7 @@ struct fwd_module {
|
||||
|
||||
int fwd_attach_module(struct fwd_module_info *m, void **);
|
||||
int fwd_destroy_module(void *state);
|
||||
int fwd_change_fib(struct radix_node_head *rnh, int req, struct rtentry *rte,
|
||||
int fwd_change_fib(struct rib_head *rh, int req, struct rtentry *rte,
|
||||
struct rt_addrinfo *info);
|
||||
|
||||
#endif
|
||||
|
@ -521,7 +521,7 @@ route_output(struct mbuf *m, struct socket *so, ...)
|
||||
{
|
||||
struct rt_msghdr *rtm = NULL;
|
||||
struct rtentry *rt = NULL;
|
||||
struct radix_node_head *rnh;
|
||||
struct rib_head *rh;
|
||||
struct rt_addrinfo info;
|
||||
struct sockaddr_storage ss;
|
||||
#ifdef INET6
|
||||
@ -698,11 +698,11 @@ route_output(struct mbuf *m, struct socket *so, ...)
|
||||
break;
|
||||
|
||||
case RTM_GET:
|
||||
rnh = rt_tables_get_rnh(fibnum, saf);
|
||||
if (rnh == NULL)
|
||||
rh = rt_tables_get_rnh(fibnum, saf);
|
||||
if (rh == NULL)
|
||||
senderr(EAFNOSUPPORT);
|
||||
|
||||
RADIX_NODE_HEAD_RLOCK(rnh);
|
||||
RIB_RLOCK(rh);
|
||||
|
||||
if (info.rti_info[RTAX_NETMASK] == NULL &&
|
||||
rtm->rtm_type == RTM_GET) {
|
||||
@ -711,15 +711,15 @@ route_output(struct mbuf *m, struct socket *so, ...)
|
||||
* address lookup (no mask).
|
||||
* 'route -n get addr'
|
||||
*/
|
||||
rt = (struct rtentry *) rnh->rnh_matchaddr(
|
||||
info.rti_info[RTAX_DST], rnh);
|
||||
rt = (struct rtentry *) rh->rnh_matchaddr(
|
||||
info.rti_info[RTAX_DST], &rh->head);
|
||||
} else
|
||||
rt = (struct rtentry *) rnh->rnh_lookup(
|
||||
rt = (struct rtentry *) rh->rnh_lookup(
|
||||
info.rti_info[RTAX_DST],
|
||||
info.rti_info[RTAX_NETMASK], rnh);
|
||||
info.rti_info[RTAX_NETMASK], &rh->head);
|
||||
|
||||
if (rt == NULL) {
|
||||
RADIX_NODE_HEAD_RUNLOCK(rnh);
|
||||
RIB_RUNLOCK(rh);
|
||||
senderr(ESRCH);
|
||||
}
|
||||
#ifdef RADIX_MPATH
|
||||
@ -731,11 +731,11 @@ route_output(struct mbuf *m, struct socket *so, ...)
|
||||
* if gate == NULL the first match is returned.
|
||||
* (no need to call rt_mpath_matchgate if gate == NULL)
|
||||
*/
|
||||
if (rn_mpath_capable(rnh) &&
|
||||
if (rn_mpath_capable(rh) &&
|
||||
(rtm->rtm_type != RTM_GET || info.rti_info[RTAX_GATEWAY])) {
|
||||
rt = rt_mpath_matchgate(rt, info.rti_info[RTAX_GATEWAY]);
|
||||
if (!rt) {
|
||||
RADIX_NODE_HEAD_RUNLOCK(rnh);
|
||||
RIB_RUNLOCK(rh);
|
||||
senderr(ESRCH);
|
||||
}
|
||||
}
|
||||
@ -766,15 +766,15 @@ route_output(struct mbuf *m, struct socket *so, ...)
|
||||
/*
|
||||
* refactor rt and no lock operation necessary
|
||||
*/
|
||||
rt = (struct rtentry *)rnh->rnh_matchaddr(&laddr, rnh);
|
||||
rt = (struct rtentry *)rh->rnh_matchaddr(&laddr, &rh->head);
|
||||
if (rt == NULL) {
|
||||
RADIX_NODE_HEAD_RUNLOCK(rnh);
|
||||
RIB_RUNLOCK(rh);
|
||||
senderr(ESRCH);
|
||||
}
|
||||
}
|
||||
RT_LOCK(rt);
|
||||
RT_ADDREF(rt);
|
||||
RADIX_NODE_HEAD_RUNLOCK(rnh);
|
||||
RIB_RUNLOCK(rh);
|
||||
|
||||
report:
|
||||
RT_LOCK_ASSERT(rt);
|
||||
@ -1799,7 +1799,7 @@ sysctl_rtsock(SYSCTL_HANDLER_ARGS)
|
||||
{
|
||||
int *name = (int *)arg1;
|
||||
u_int namelen = arg2;
|
||||
struct radix_node_head *rnh = NULL; /* silence compiler. */
|
||||
struct rib_head *rh = NULL; /* silence compiler. */
|
||||
int i, lim, error = EINVAL;
|
||||
int fib = 0;
|
||||
u_char af;
|
||||
@ -1866,12 +1866,12 @@ sysctl_rtsock(SYSCTL_HANDLER_ARGS)
|
||||
* take care of routing entries
|
||||
*/
|
||||
for (error = 0; error == 0 && i <= lim; i++) {
|
||||
rnh = rt_tables_get_rnh(fib, i);
|
||||
if (rnh != NULL) {
|
||||
RADIX_NODE_HEAD_RLOCK(rnh);
|
||||
error = rnh->rnh_walktree(rnh,
|
||||
rh = rt_tables_get_rnh(fib, i);
|
||||
if (rh != NULL) {
|
||||
RIB_RLOCK(rh);
|
||||
error = rh->rnh_walktree(&rh->head,
|
||||
sysctl_dumpentry, &w);
|
||||
RADIX_NODE_HEAD_RUNLOCK(rnh);
|
||||
RIB_RUNLOCK(rh);
|
||||
} else if (af != 0)
|
||||
error = EAFNOSUPPORT;
|
||||
}
|
||||
|
@ -56,9 +56,9 @@ extern int in_inithead(void **head, int off);
|
||||
extern int in_detachhead(void **head, int off);
|
||||
#endif
|
||||
|
||||
static void in_setifarnh(struct radix_node_head *rnh, uint32_t fibnum,
|
||||
static void in_setifarnh(struct rib_head *rh, uint32_t fibnum,
|
||||
int af, void *_arg);
|
||||
static void in_rtqtimo_setrnh(struct radix_node_head *rnh, uint32_t fibnum,
|
||||
static void in_rtqtimo_setrnh(struct rib_head *rh, uint32_t fibnum,
|
||||
int af, void *_arg);
|
||||
|
||||
#define RTPRF_OURS RTF_PROTO3 /* set on routes we manage */
|
||||
@ -67,13 +67,12 @@ static void in_rtqtimo_setrnh(struct radix_node_head *rnh, uint32_t fibnum,
|
||||
* Do what we need to do when inserting a route.
|
||||
*/
|
||||
static struct radix_node *
|
||||
in_addroute(void *v_arg, void *n_arg, struct radix_node_head *head,
|
||||
in_addroute(void *v_arg, void *n_arg, struct radix_head *head,
|
||||
struct radix_node *treenodes)
|
||||
{
|
||||
struct rtentry *rt = (struct rtentry *)treenodes;
|
||||
struct sockaddr_in *sin = (struct sockaddr_in *)rt_key(rt);
|
||||
|
||||
RADIX_NODE_HEAD_WLOCK_ASSERT(head);
|
||||
/*
|
||||
* A little bit of help for both IP output and input:
|
||||
* For host routes, we make sure that RTF_BROADCAST
|
||||
@ -113,7 +112,7 @@ in_addroute(void *v_arg, void *n_arg, struct radix_node_head *head,
|
||||
rt->rt_mtu = rt->rt_ifp->if_mtu;
|
||||
}
|
||||
|
||||
return (rn_addroute(v_arg, n_arg, &head->rh, treenodes));
|
||||
return (rn_addroute(v_arg, n_arg, head, treenodes));
|
||||
}
|
||||
|
||||
/*
|
||||
@ -122,9 +121,9 @@ in_addroute(void *v_arg, void *n_arg, struct radix_node_head *head,
|
||||
* back off again.
|
||||
*/
|
||||
static struct radix_node *
|
||||
in_matroute(void *v_arg, struct radix_node_head *head)
|
||||
in_matroute(void *v_arg, struct radix_head *head)
|
||||
{
|
||||
struct radix_node *rn = rn_match(v_arg, &head->rh);
|
||||
struct radix_node *rn = rn_match(v_arg, head);
|
||||
struct rtentry *rt = (struct rtentry *)rn;
|
||||
|
||||
if (rt) {
|
||||
@ -149,9 +148,10 @@ SYSCTL_INT(_net_inet_ip, IPCTL_RTEXPIRE, rtexpire, CTLFLAG_VNET | CTLFLAG_RW,
|
||||
* timed out.
|
||||
*/
|
||||
static void
|
||||
in_clsroute(struct radix_node *rn, struct radix_node_head *head)
|
||||
in_clsroute(struct radix_node *rn, struct radix_head *head)
|
||||
{
|
||||
struct rtentry *rt = (struct rtentry *)rn;
|
||||
struct rib_head *rh = (struct rib_head *)head;
|
||||
|
||||
RT_LOCK_ASSERT(rt);
|
||||
|
||||
@ -172,11 +172,11 @@ in_clsroute(struct radix_node *rn, struct radix_node_head *head)
|
||||
rt->rt_flags |= RTPRF_OURS;
|
||||
rt->rt_expire = time_uptime + V_rtq_reallyold;
|
||||
} else
|
||||
rt_expunge(head, rt);
|
||||
rt_expunge(rh, rt);
|
||||
}
|
||||
|
||||
struct rtqk_arg {
|
||||
struct radix_node_head *rnh;
|
||||
struct rib_head *rh;
|
||||
int draining;
|
||||
int killed;
|
||||
int found;
|
||||
@ -192,7 +192,7 @@ in_rtqkill(struct rtentry *rt, void *rock)
|
||||
struct rtqk_arg *ap = rock;
|
||||
int err;
|
||||
|
||||
RADIX_NODE_HEAD_WLOCK_ASSERT(ap->rnh);
|
||||
RIB_WLOCK_ASSERT(ap->rh);
|
||||
|
||||
if (rt->rt_flags & RTPRF_OURS) {
|
||||
ap->found++;
|
||||
@ -224,7 +224,7 @@ static VNET_DEFINE(struct callout, rtq_timer);
|
||||
#define V_rtq_timer VNET(rtq_timer)
|
||||
|
||||
static void
|
||||
in_rtqtimo_setrnh(struct radix_node_head *rnh, uint32_t fibnum, int af,
|
||||
in_rtqtimo_setrnh(struct rib_head *rh, uint32_t fibnum, int af,
|
||||
void *_arg)
|
||||
{
|
||||
struct rtqk_arg *arg;
|
||||
@ -234,7 +234,7 @@ in_rtqtimo_setrnh(struct radix_node_head *rnh, uint32_t fibnum, int af,
|
||||
|
||||
draining = arg->draining;
|
||||
memset(arg, 0, sizeof(*arg));
|
||||
arg->rnh = rnh;
|
||||
arg->rh = rh;
|
||||
arg->draining = arg->draining;
|
||||
}
|
||||
|
||||
@ -275,11 +275,12 @@ in_rtqdrain(void)
|
||||
}
|
||||
|
||||
void
|
||||
in_setmatchfunc(struct radix_node_head *rnh, int val)
|
||||
in_setmatchfunc(struct rib_head *rh, int val)
|
||||
{
|
||||
|
||||
rnh->rnh_matchaddr = (val != 0) ?
|
||||
(rn_matchaddr_f_t *)rn_match : in_matroute;
|
||||
RIB_WLOCK(rh);
|
||||
rh->rnh_matchaddr = (val != 0) ? rn_match : in_matroute;
|
||||
RIB_WUNLOCK(rh);
|
||||
}
|
||||
|
||||
static int _in_rt_was_here;
|
||||
@ -289,17 +290,17 @@ static int _in_rt_was_here;
|
||||
int
|
||||
in_inithead(void **head, int off)
|
||||
{
|
||||
struct radix_node_head *rnh;
|
||||
struct rib_head *rh;
|
||||
|
||||
if (!rn_inithead(head, 32))
|
||||
return 0;
|
||||
rh = rt_table_init(32);
|
||||
if (rh == NULL)
|
||||
return (0);
|
||||
|
||||
rnh = *head;
|
||||
RADIX_NODE_HEAD_LOCK_INIT(rnh);
|
||||
rh->rnh_addaddr = in_addroute;
|
||||
in_setmatchfunc(rh, V_drop_redirect);
|
||||
rh->rnh_close = in_clsroute;
|
||||
*head = (void *)rh;
|
||||
|
||||
rnh->rnh_addaddr = in_addroute;
|
||||
in_setmatchfunc(rnh, V_drop_redirect);
|
||||
rnh->rnh_close = in_clsroute;
|
||||
if (_in_rt_was_here == 0 ) {
|
||||
callout_init(&V_rtq_timer, CALLOUT_MPSAFE);
|
||||
callout_reset(&V_rtq_timer, 1, in_rtqtimo, curvnet);
|
||||
@ -328,7 +329,7 @@ in_detachhead(void **head, int off)
|
||||
* plug back in.
|
||||
*/
|
||||
struct in_ifadown_arg {
|
||||
struct radix_node_head *rnh;
|
||||
struct rib_head *rh;
|
||||
struct ifaddr *ifa;
|
||||
int del;
|
||||
};
|
||||
@ -351,7 +352,7 @@ in_ifadownkill(struct rtentry *rt, void *xap)
|
||||
* Disconnect it from the tree and permit protocols
|
||||
* to cleanup.
|
||||
*/
|
||||
rt_expunge(ap->rnh, rt);
|
||||
rt_expunge(ap->rh, rt);
|
||||
/*
|
||||
* At this point it is an rttrash node, and in case
|
||||
* the above is the only reference we must free it.
|
||||
@ -370,14 +371,14 @@ in_ifadownkill(struct rtentry *rt, void *xap)
|
||||
}
|
||||
|
||||
static void
|
||||
in_setifarnh(struct radix_node_head *rnh, uint32_t fibnum, int af,
|
||||
in_setifarnh(struct rib_head *rh, uint32_t fibnum, int af,
|
||||
void *_arg)
|
||||
{
|
||||
struct in_ifadown_arg *arg;
|
||||
|
||||
arg = (struct in_ifadown_arg *)_arg;
|
||||
|
||||
arg->rnh = rnh;
|
||||
arg->rh = rh;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -382,7 +382,7 @@ inm_acquire_locked(struct in_multi *inm)
|
||||
|
||||
struct rtentry;
|
||||
struct ip_moptions;
|
||||
struct radix_node_head;
|
||||
struct rib_head;
|
||||
|
||||
struct in_multi *inm_lookup_locked(struct ifnet *, const struct in_addr);
|
||||
struct in_multi *inm_lookup(struct ifnet *, const struct in_addr);
|
||||
@ -422,7 +422,7 @@ void in_rtredirect(struct sockaddr *, struct sockaddr *,
|
||||
struct sockaddr *, int, struct sockaddr *, u_int);
|
||||
int in_rtrequest(int, struct sockaddr *,
|
||||
struct sockaddr *, struct sockaddr *, int, struct rtentry **, u_int);
|
||||
void in_setmatchfunc(struct radix_node_head *, int);
|
||||
void in_setmatchfunc(struct rib_head *, int);
|
||||
|
||||
#if 0
|
||||
int in_rt_getifa(struct rt_addrinfo *, u_int fibnum);
|
||||
|
@ -170,7 +170,7 @@ sysctl_net_icmp_drop_redir(SYSCTL_HANDLER_ARGS)
|
||||
{
|
||||
int error, new;
|
||||
int i;
|
||||
struct radix_node_head *rnh;
|
||||
struct rib_head *rh;
|
||||
|
||||
new = V_drop_redirect;
|
||||
error = sysctl_handle_int(oidp, &new, 0, req);
|
||||
@ -181,11 +181,9 @@ sysctl_net_icmp_drop_redir(SYSCTL_HANDLER_ARGS)
|
||||
return (0);
|
||||
|
||||
for (i = 0; i < rt_numfibs; i++) {
|
||||
if ((rnh = rt_tables_get_rnh(i, AF_INET)) == NULL)
|
||||
if ((rh = rt_tables_get_rnh(i, AF_INET)) == NULL)
|
||||
continue;
|
||||
RADIX_NODE_HEAD_LOCK(rnh);
|
||||
in_setmatchfunc(rnh, new);
|
||||
RADIX_NODE_HEAD_UNLOCK(rnh);
|
||||
in_setmatchfunc(rh, new);
|
||||
}
|
||||
|
||||
V_drop_redirect = new;
|
||||
|
@ -104,14 +104,13 @@ extern int in6_detachhead(void **head, int off);
|
||||
* Do what we need to do when inserting a route.
|
||||
*/
|
||||
static struct radix_node *
|
||||
in6_addroute(void *v_arg, void *n_arg, struct radix_node_head *head,
|
||||
in6_addroute(void *v_arg, void *n_arg, struct radix_head *head,
|
||||
struct radix_node *treenodes)
|
||||
{
|
||||
struct rtentry *rt = (struct rtentry *)treenodes;
|
||||
struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)rt_key(rt);
|
||||
struct radix_node *ret;
|
||||
|
||||
RADIX_NODE_HEAD_WLOCK_ASSERT(head);
|
||||
if (IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr))
|
||||
rt->rt_flags |= RTF_MULTICAST;
|
||||
|
||||
@ -150,7 +149,7 @@ in6_addroute(void *v_arg, void *n_arg, struct radix_node_head *head,
|
||||
rt->rt_mtu = IN6_LINKMTU(rt->rt_ifp);
|
||||
}
|
||||
|
||||
ret = rn_addroute(v_arg, n_arg, &head->rh, treenodes);
|
||||
ret = rn_addroute(v_arg, n_arg, head, treenodes);
|
||||
if (ret == NULL) {
|
||||
struct rtentry *rt2;
|
||||
/*
|
||||
@ -181,7 +180,7 @@ in6_addroute(void *v_arg, void *n_arg, struct radix_node_head *head,
|
||||
}
|
||||
|
||||
struct rtqk_arg {
|
||||
struct radix_node_head *rnh;
|
||||
struct rib_head *rh;
|
||||
int mode;
|
||||
int draining;
|
||||
int killed;
|
||||
@ -192,7 +191,7 @@ struct rtqk_arg {
|
||||
* Age old PMTUs.
|
||||
*/
|
||||
struct mtuex_arg {
|
||||
struct radix_node_head *rnh;
|
||||
struct rib_head *rh;
|
||||
};
|
||||
static VNET_DEFINE(struct callout, rtq_mtutimer);
|
||||
#define V_rtq_mtutimer VNET(rtq_mtutimer)
|
||||
@ -213,13 +212,13 @@ in6_mtuexpire(struct rtentry *rt, void *rock)
|
||||
#define MTUTIMO_DEFAULT (60*1)
|
||||
|
||||
static void
|
||||
in6_mtutimo_setwa(struct radix_node_head *rnh, uint32_t fibum, int af, void *_arg)
|
||||
in6_mtutimo_setwa(struct rib_head *rh, uint32_t fibum, int af, void *_arg)
|
||||
{
|
||||
struct mtuex_arg *arg;
|
||||
|
||||
arg = (struct mtuex_arg *)_arg;
|
||||
|
||||
arg->rnh = rnh;
|
||||
arg->rh = rh;
|
||||
}
|
||||
|
||||
static void
|
||||
@ -246,15 +245,14 @@ static VNET_DEFINE(int, _in6_rt_was_here);
|
||||
int
|
||||
in6_inithead(void **head, int off)
|
||||
{
|
||||
struct radix_node_head *rnh;
|
||||
struct rib_head *rh;
|
||||
|
||||
if (!rn_inithead(head, offsetof(struct sockaddr_in6, sin6_addr) << 3))
|
||||
rh = rt_table_init(offsetof(struct sockaddr_in6, sin6_addr) << 3);
|
||||
if (rh == NULL)
|
||||
return (0);
|
||||
|
||||
rnh = *head;
|
||||
RADIX_NODE_HEAD_LOCK_INIT(rnh);
|
||||
|
||||
rnh->rnh_addaddr = in6_addroute;
|
||||
rh->rnh_addaddr = in6_addroute;
|
||||
*head = (void *)rh;
|
||||
|
||||
if (V__in6_rt_was_here == 0) {
|
||||
callout_init(&V_rtq_mtutimer, CALLOUT_MPSAFE);
|
||||
|
@ -1518,7 +1518,7 @@ static int
|
||||
nd6_prefix_onlink_rtrequest(struct nd_prefix *pr, struct ifaddr *ifa)
|
||||
{
|
||||
static struct sockaddr_dl null_sdl = {sizeof(null_sdl), AF_LINK};
|
||||
struct radix_node_head *rnh;
|
||||
struct rib_head *rh;
|
||||
struct rtentry *rt;
|
||||
struct sockaddr_in6 mask6;
|
||||
u_long rtflags;
|
||||
@ -1545,9 +1545,9 @@ nd6_prefix_onlink_rtrequest(struct nd_prefix *pr, struct ifaddr *ifa)
|
||||
"error(%d) but rt is NULL, pr=%p, ifa=%p", __func__,
|
||||
error, pr, ifa));
|
||||
|
||||
rnh = rt_tables_get_rnh(rt->rt_fibnum, AF_INET6);
|
||||
rh = rt_tables_get_rnh(rt->rt_fibnum, AF_INET6);
|
||||
/* XXX what if rhn == NULL? */
|
||||
RADIX_NODE_HEAD_LOCK(rnh);
|
||||
RIB_WLOCK(rh);
|
||||
RT_LOCK(rt);
|
||||
if (rt_setgate(rt, rt_key(rt),
|
||||
(struct sockaddr *)&null_sdl) == 0) {
|
||||
@ -1557,7 +1557,7 @@ nd6_prefix_onlink_rtrequest(struct nd_prefix *pr, struct ifaddr *ifa)
|
||||
dl->sdl_type = rt->rt_ifp->if_type;
|
||||
dl->sdl_index = rt->rt_ifp->if_index;
|
||||
}
|
||||
RADIX_NODE_HEAD_UNLOCK(rnh);
|
||||
RIB_WUNLOCK(rh);
|
||||
nd6_rtmsg(RTM_ADD, rt);
|
||||
RT_UNLOCK(rt);
|
||||
pr->ndpr_stateflags |= NDPRF_ONLINK;
|
||||
|
@ -408,7 +408,7 @@ ta_lookup_radix(struct table_info *ti, void *key, uint32_t keylen,
|
||||
KEY_LEN(sa) = KEY_LEN_INET;
|
||||
sa.sin_addr.s_addr = *((in_addr_t *)key);
|
||||
rnh = (struct radix_node_head *)ti->state;
|
||||
ent = (struct radix_addr_entry *)(rnh->rnh_matchaddr(&sa, rnh));
|
||||
ent = (struct radix_addr_entry *)(rnh->rnh_matchaddr(&sa, &rnh->rh));
|
||||
if (ent != NULL) {
|
||||
*val = ent->value;
|
||||
return (1);
|
||||
@ -419,7 +419,7 @@ ta_lookup_radix(struct table_info *ti, void *key, uint32_t keylen,
|
||||
KEY_LEN(sa6) = KEY_LEN_INET6;
|
||||
memcpy(&sa6.sin6_addr, key, sizeof(struct in6_addr));
|
||||
rnh = (struct radix_node_head *)ti->xstate;
|
||||
xent = (struct radix_addr_xentry *)(rnh->rnh_matchaddr(&sa6, rnh));
|
||||
xent = (struct radix_addr_xentry *)(rnh->rnh_matchaddr(&sa6, &rnh->rh));
|
||||
if (xent != NULL) {
|
||||
*val = xent->value;
|
||||
return (1);
|
||||
@ -460,7 +460,7 @@ flush_radix_entry(struct radix_node *rn, void *arg)
|
||||
struct radix_addr_entry *ent;
|
||||
|
||||
ent = (struct radix_addr_entry *)
|
||||
rnh->rnh_deladdr(rn->rn_key, rn->rn_mask, rnh);
|
||||
rnh->rnh_deladdr(rn->rn_key, rn->rn_mask, &rnh->rh);
|
||||
if (ent != NULL)
|
||||
free(ent, M_IPFW_TBL);
|
||||
return (0);
|
||||
@ -475,11 +475,11 @@ ta_destroy_radix(void *ta_state, struct table_info *ti)
|
||||
cfg = (struct radix_cfg *)ta_state;
|
||||
|
||||
rnh = (struct radix_node_head *)(ti->state);
|
||||
rnh->rnh_walktree(rnh, flush_radix_entry, rnh);
|
||||
rnh->rnh_walktree(&rnh->rh, flush_radix_entry, rnh);
|
||||
rn_detachhead(&ti->state);
|
||||
|
||||
rnh = (struct radix_node_head *)(ti->xstate);
|
||||
rnh->rnh_walktree(rnh, flush_radix_entry, rnh);
|
||||
rnh->rnh_walktree(&rnh->rh, flush_radix_entry, rnh);
|
||||
rn_detachhead(&ti->xstate);
|
||||
|
||||
free(cfg, M_IPFW);
|
||||
@ -547,13 +547,13 @@ ta_find_radix_tentry(void *ta_state, struct table_info *ti,
|
||||
KEY_LEN(sa) = KEY_LEN_INET;
|
||||
sa.sin_addr.s_addr = tent->k.addr.s_addr;
|
||||
rnh = (struct radix_node_head *)ti->state;
|
||||
e = rnh->rnh_matchaddr(&sa, rnh);
|
||||
e = rnh->rnh_matchaddr(&sa, &rnh->rh);
|
||||
} else {
|
||||
struct sa_in6 sa6;
|
||||
KEY_LEN(sa6) = KEY_LEN_INET6;
|
||||
memcpy(&sa6.sin6_addr, &tent->k.addr6, sizeof(struct in6_addr));
|
||||
rnh = (struct radix_node_head *)ti->xstate;
|
||||
e = rnh->rnh_matchaddr(&sa6, rnh);
|
||||
e = rnh->rnh_matchaddr(&sa6, &rnh->rh);
|
||||
}
|
||||
|
||||
if (e != NULL) {
|
||||
@ -571,10 +571,10 @@ ta_foreach_radix(void *ta_state, struct table_info *ti, ta_foreach_f *f,
|
||||
struct radix_node_head *rnh;
|
||||
|
||||
rnh = (struct radix_node_head *)(ti->state);
|
||||
rnh->rnh_walktree(rnh, (walktree_f_t *)f, arg);
|
||||
rnh->rnh_walktree(&rnh->rh, (walktree_f_t *)f, arg);
|
||||
|
||||
rnh = (struct radix_node_head *)(ti->xstate);
|
||||
rnh->rnh_walktree(rnh, (walktree_f_t *)f, arg);
|
||||
rnh->rnh_walktree(&rnh->rh, (walktree_f_t *)f, arg);
|
||||
}
|
||||
|
||||
|
||||
@ -721,7 +721,7 @@ ta_add_radix(void *ta_state, struct table_info *ti, struct tentry_info *tei,
|
||||
}
|
||||
|
||||
/* Search for an entry first */
|
||||
rn = rnh->rnh_lookup(tb->addr_ptr, tb->mask_ptr, rnh);
|
||||
rn = rnh->rnh_lookup(tb->addr_ptr, tb->mask_ptr, &rnh->rh);
|
||||
if (rn != NULL) {
|
||||
if ((tei->flags & TEI_FLAGS_UPDATE) == 0)
|
||||
return (EEXIST);
|
||||
@ -745,7 +745,7 @@ ta_add_radix(void *ta_state, struct table_info *ti, struct tentry_info *tei,
|
||||
if ((tei->flags & TEI_FLAGS_DONTADD) != 0)
|
||||
return (EFBIG);
|
||||
|
||||
rn = rnh->rnh_addaddr(tb->addr_ptr, tb->mask_ptr, rnh, tb->ent_ptr);
|
||||
rn = rnh->rnh_addaddr(tb->addr_ptr, tb->mask_ptr, &rnh->rh, tb->ent_ptr);
|
||||
if (rn == NULL) {
|
||||
/* Unknown error */
|
||||
return (EINVAL);
|
||||
@ -816,7 +816,7 @@ ta_del_radix(void *ta_state, struct table_info *ti, struct tentry_info *tei,
|
||||
else
|
||||
rnh = ti->xstate;
|
||||
|
||||
rn = rnh->rnh_deladdr(tb->addr_ptr, tb->mask_ptr, rnh);
|
||||
rn = rnh->rnh_deladdr(tb->addr_ptr, tb->mask_ptr, &rnh->rh);
|
||||
|
||||
if (rn == NULL)
|
||||
return (ENOENT);
|
||||
@ -4018,21 +4018,21 @@ static void
|
||||
ta_foreach_kfib(void *ta_state, struct table_info *ti, ta_foreach_f *f,
|
||||
void *arg)
|
||||
{
|
||||
struct radix_node_head *rnh;
|
||||
struct rib_head *rh;
|
||||
int error;
|
||||
|
||||
rnh = rt_tables_get_rnh(ti->data, AF_INET);
|
||||
if (rnh != NULL) {
|
||||
RADIX_NODE_HEAD_RLOCK(rnh);
|
||||
error = rnh->rnh_walktree(rnh, (walktree_f_t *)f, arg);
|
||||
RADIX_NODE_HEAD_RUNLOCK(rnh);
|
||||
rh = rt_tables_get_rnh(ti->data, AF_INET);
|
||||
if (rh != NULL) {
|
||||
RIB_RLOCK(rh);
|
||||
error = rh->rnh_walktree(&rh->head, (walktree_f_t *)f, arg);
|
||||
RIB_RUNLOCK(rh);
|
||||
}
|
||||
|
||||
rnh = rt_tables_get_rnh(ti->data, AF_INET6);
|
||||
if (rnh != NULL) {
|
||||
RADIX_NODE_HEAD_RLOCK(rnh);
|
||||
error = rnh->rnh_walktree(rnh, (walktree_f_t *)f, arg);
|
||||
RADIX_NODE_HEAD_RUNLOCK(rnh);
|
||||
rh = rt_tables_get_rnh(ti->data, AF_INET6);
|
||||
if (rh != NULL) {
|
||||
RIB_RLOCK(rh);
|
||||
error = rh->rnh_walktree(&rh->head, (walktree_f_t *)f, arg);
|
||||
RIB_RUNLOCK(rh);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -559,10 +559,10 @@ pfr_get_addrs(struct pfr_table *tbl, struct pfr_addr *addr, int *size,
|
||||
w.pfrw_op = PFRW_GET_ADDRS;
|
||||
w.pfrw_addr = addr;
|
||||
w.pfrw_free = kt->pfrkt_cnt;
|
||||
rv = kt->pfrkt_ip4->rnh_walktree(kt->pfrkt_ip4, pfr_walktree, &w);
|
||||
rv = kt->pfrkt_ip4->rnh_walktree(&kt->pfrkt_ip4->rh, pfr_walktree, &w);
|
||||
if (!rv)
|
||||
rv = kt->pfrkt_ip6->rnh_walktree(kt->pfrkt_ip6, pfr_walktree,
|
||||
&w);
|
||||
rv = kt->pfrkt_ip6->rnh_walktree(&kt->pfrkt_ip6->rh,
|
||||
pfr_walktree, &w);
|
||||
if (rv)
|
||||
return (rv);
|
||||
|
||||
@ -601,10 +601,10 @@ pfr_get_astats(struct pfr_table *tbl, struct pfr_astats *addr, int *size,
|
||||
w.pfrw_op = PFRW_GET_ASTATS;
|
||||
w.pfrw_astats = addr;
|
||||
w.pfrw_free = kt->pfrkt_cnt;
|
||||
rv = kt->pfrkt_ip4->rnh_walktree(kt->pfrkt_ip4, pfr_walktree, &w);
|
||||
rv = kt->pfrkt_ip4->rnh_walktree(&kt->pfrkt_ip4->rh, pfr_walktree, &w);
|
||||
if (!rv)
|
||||
rv = kt->pfrkt_ip6->rnh_walktree(kt->pfrkt_ip6, pfr_walktree,
|
||||
&w);
|
||||
rv = kt->pfrkt_ip6->rnh_walktree(&kt->pfrkt_ip6->rh,
|
||||
pfr_walktree, &w);
|
||||
if (!rv && (flags & PFR_FLAG_CLSTATS)) {
|
||||
pfr_enqueue_addrs(kt, &workq, NULL, 0);
|
||||
pfr_clstats_kentries(&workq, tzero, 0);
|
||||
@ -710,12 +710,12 @@ pfr_enqueue_addrs(struct pfr_ktable *kt, struct pfr_kentryworkq *workq,
|
||||
w.pfrw_op = sweep ? PFRW_SWEEP : PFRW_ENQUEUE;
|
||||
w.pfrw_workq = workq;
|
||||
if (kt->pfrkt_ip4 != NULL)
|
||||
if (kt->pfrkt_ip4->rnh_walktree(kt->pfrkt_ip4, pfr_walktree,
|
||||
&w))
|
||||
if (kt->pfrkt_ip4->rnh_walktree(&kt->pfrkt_ip4->rh,
|
||||
pfr_walktree, &w))
|
||||
printf("pfr_enqueue_addrs: IPv4 walktree failed.\n");
|
||||
if (kt->pfrkt_ip6 != NULL)
|
||||
if (kt->pfrkt_ip6->rnh_walktree(kt->pfrkt_ip6, pfr_walktree,
|
||||
&w))
|
||||
if (kt->pfrkt_ip6->rnh_walktree(&kt->pfrkt_ip6->rh,
|
||||
pfr_walktree, &w))
|
||||
printf("pfr_enqueue_addrs: IPv6 walktree failed.\n");
|
||||
if (naddr != NULL)
|
||||
*naddr = w.pfrw_cnt;
|
||||
@ -728,9 +728,9 @@ pfr_mark_addrs(struct pfr_ktable *kt)
|
||||
|
||||
bzero(&w, sizeof(w));
|
||||
w.pfrw_op = PFRW_MARK;
|
||||
if (kt->pfrkt_ip4->rnh_walktree(kt->pfrkt_ip4, pfr_walktree, &w))
|
||||
if (kt->pfrkt_ip4->rnh_walktree(&kt->pfrkt_ip4->rh, pfr_walktree, &w))
|
||||
printf("pfr_mark_addrs: IPv4 walktree failed.\n");
|
||||
if (kt->pfrkt_ip6->rnh_walktree(kt->pfrkt_ip6, pfr_walktree, &w))
|
||||
if (kt->pfrkt_ip6->rnh_walktree(&kt->pfrkt_ip6->rh, pfr_walktree, &w))
|
||||
printf("pfr_mark_addrs: IPv6 walktree failed.\n");
|
||||
}
|
||||
|
||||
@ -2162,12 +2162,12 @@ pfr_kentry_byidx(struct pfr_ktable *kt, int idx, int af)
|
||||
switch (af) {
|
||||
#ifdef INET
|
||||
case AF_INET:
|
||||
kt->pfrkt_ip4->rnh_walktree(kt->pfrkt_ip4, pfr_walktree, &w);
|
||||
kt->pfrkt_ip4->rnh_walktree(&kt->pfrkt_ip4->rh, pfr_walktree, &w);
|
||||
return (w.pfrw_kentry);
|
||||
#endif /* INET */
|
||||
#ifdef INET6
|
||||
case AF_INET6:
|
||||
kt->pfrkt_ip6->rnh_walktree(kt->pfrkt_ip6, pfr_walktree, &w);
|
||||
kt->pfrkt_ip6->rnh_walktree(&kt->pfrkt_ip6->rh, pfr_walktree, &w);
|
||||
return (w.pfrw_kentry);
|
||||
#endif /* INET6 */
|
||||
default:
|
||||
@ -2187,7 +2187,7 @@ pfr_dynaddr_update(struct pfr_ktable *kt, struct pfi_dynaddr *dyn)
|
||||
dyn->pfid_acnt4 = 0;
|
||||
dyn->pfid_acnt6 = 0;
|
||||
if (!dyn->pfid_af || dyn->pfid_af == AF_INET)
|
||||
kt->pfrkt_ip4->rnh_walktree(kt->pfrkt_ip4, pfr_walktree, &w);
|
||||
kt->pfrkt_ip4->rnh_walktree(&kt->pfrkt_ip4->rh, pfr_walktree, &w);
|
||||
if (!dyn->pfid_af || dyn->pfid_af == AF_INET6)
|
||||
kt->pfrkt_ip6->rnh_walktree(kt->pfrkt_ip6, pfr_walktree, &w);
|
||||
kt->pfrkt_ip6->rnh_walktree(&kt->pfrkt_ip6->rh, pfr_walktree, &w);
|
||||
}
|
||||
|
@ -369,15 +369,15 @@ bootpboot_p_tree(struct radix_node *rn)
|
||||
void
|
||||
bootpboot_p_rtlist(void)
|
||||
{
|
||||
struct radix_node_head *rnh;
|
||||
struct rib_head *rh;
|
||||
|
||||
printf("Routing table:\n");
|
||||
rnh = rt_tables_get_rnh(0, AF_INET);
|
||||
if (rnh == NULL)
|
||||
return;
|
||||
RADIX_NODE_HEAD_RLOCK(rnh); /* could sleep XXX */
|
||||
bootpboot_p_tree(rnh->rnh_treetop);
|
||||
RADIX_NODE_HEAD_RUNLOCK(rnh);
|
||||
RIB_RLOCK(rnh); /* could sleep XXX */
|
||||
bootpboot_p_tree(rh->rnh_treetop);
|
||||
RIB_RUNLOCK(rnh);
|
||||
}
|
||||
|
||||
void
|
||||
|
Loading…
x
Reference in New Issue
Block a user