MFP r287070,r287073: split radix implementation and route table structure.

There are number of radix consumers in kernel land (pf,ipfw,nfs,route)
  with different requirements. In fact, first 3 don't have _any_ requirements
  and first 2 does not use radix locking. On the other hand, routing
  structure do have these requirements (rnh_gen, multipath, custom
  to-be-added control plane functions, different locking).
Additionally, radix should not known anything about its consumers internals.

So, radix code now uses tiny 'struct radix_head' structure along with
  internal 'struct radix_mask_head' instead of 'struct radix_node_head'.
  Existing consumers still uses the same 'struct radix_node_head' with
  slight modifications: they need to pass pointer to (embedded)
  'struct radix_head' to all radix callbacks.

Routing code now uses new 'struct rib_head' with different locking macro:
  RADIX_NODE_HEAD prefix was renamed to RIB_ (which stands for routing
  information base).

New net/route_var.h header was added to hold routing subsystem internal
  data. 'struct rib_head' was placed there. 'struct rtentry' will also
  be moved there soon.
This commit is contained in:
Alexander V. Chernikov 2016-01-25 06:33:15 +00:00
parent 51f6f18c88
commit 61eee0e202
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=294706
18 changed files with 457 additions and 320 deletions

View File

@ -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;

View File

@ -56,18 +56,15 @@
#include <net/radix.h>
#endif /* !_KERNEL */
static int rn_walktree_from(struct radix_node_head *h, void *a, void *m,
walktree_f_t *f, void *w);
static int rn_walktree(struct radix_node_head *, walktree_f_t *, void *);
static struct radix_node
*rn_insert(void *, struct radix_node_head *, int *,
*rn_insert(void *, struct radix_head *, int *,
struct radix_node [2]),
*rn_newpair(void *, int, struct radix_node[2]),
*rn_search(void *, struct radix_node *),
*rn_search_m(void *, struct radix_node *, void *);
static struct radix_node *rn_addmask(void *, struct radix_mask_head *, int,int);
static void rn_detachhead_internal(void **head);
static int rn_inithead_internal(void **head, int off);
static void rn_detachhead_internal(struct radix_head *);
#define RADIX_MAX_KEY_LEN 32
@ -215,7 +212,7 @@ rn_refines(void *m_arg, void *n_arg)
* from host routes.
*/
struct radix_node *
rn_lookup(void *v_arg, void *m_arg, struct radix_node_head *head)
rn_lookup(void *v_arg, void *m_arg, struct radix_head *head)
{
struct radix_node *x;
caddr_t netmask;
@ -277,7 +274,7 @@ rn_satisfies_leaf(char *trial, struct radix_node *leaf, int skip)
* Search for longest-prefix match in given @head
*/
struct radix_node *
rn_match(void *v_arg, struct radix_node_head *head)
rn_match(void *v_arg, struct radix_head *head)
{
caddr_t v = v_arg;
struct radix_node *t = head->rnh_treetop, *x;
@ -426,7 +423,7 @@ rn_newpair(void *v, int b, struct radix_node nodes[2])
}
static struct radix_node *
rn_insert(void *v_arg, struct radix_node_head *head, int *dupentry,
rn_insert(void *v_arg, struct radix_head *head, int *dupentry,
struct radix_node nodes[2])
{
caddr_t v = v_arg;
@ -490,7 +487,7 @@ rn_insert(void *v_arg, struct radix_node_head *head, int *dupentry,
}
struct radix_node *
rn_addmask(void *n_arg, struct radix_node_head *maskhead, int search, int skip)
rn_addmask(void *n_arg, struct radix_mask_head *maskhead, int search, int skip)
{
unsigned char *netmask = n_arg;
unsigned char *cp, *cplim;
@ -505,7 +502,7 @@ rn_addmask(void *n_arg, struct radix_node_head *maskhead, int search, int skip)
if (skip == 0)
skip = 1;
if (mlen <= skip)
return (maskhead->rnh_nodes);
return (maskhead->mask_nodes);
bzero(addmask_key, RADIX_MAX_KEY_LEN);
if (skip > 1)
@ -518,9 +515,9 @@ rn_addmask(void *n_arg, struct radix_node_head *maskhead, int search, int skip)
cp--;
mlen = cp - addmask_key;
if (mlen <= skip)
return (maskhead->rnh_nodes);
return (maskhead->mask_nodes);
*addmask_key = mlen;
x = rn_search(addmask_key, maskhead->rnh_treetop);
x = rn_search(addmask_key, maskhead->head.rnh_treetop);
if (bcmp(addmask_key, x->rn_key, mlen) != 0)
x = 0;
if (x || search)
@ -530,7 +527,7 @@ rn_addmask(void *n_arg, struct radix_node_head *maskhead, int search, int skip)
return (0);
netmask = cp = (unsigned char *)(x + 2);
bcopy(addmask_key, cp, mlen);
x = rn_insert(cp, maskhead, &maskduplicated, x);
x = rn_insert(cp, &maskhead->head, &maskduplicated, x);
if (maskduplicated) {
log(LOG_ERR, "rn_addmask: mask impossibly already in tree");
R_Free(saved_x);
@ -598,7 +595,7 @@ rn_new_radix_mask(struct radix_node *tt, struct radix_mask *next)
}
struct radix_node *
rn_addroute(void *v_arg, void *n_arg, struct radix_node_head *head,
rn_addroute(void *v_arg, void *n_arg, struct radix_head *head,
struct radix_node treenodes[2])
{
caddr_t v = (caddr_t)v_arg, netmask = (caddr_t)n_arg;
@ -772,7 +769,7 @@ rn_addroute(void *v_arg, void *n_arg, struct radix_node_head *head,
}
struct radix_node *
rn_delete(void *v_arg, void *netmask_arg, struct radix_node_head *head)
rn_delete(void *v_arg, void *netmask_arg, struct radix_head *head)
{
struct radix_node *t, *p, *x, *tt;
struct radix_mask *m, *saved_m, **mp;
@ -959,8 +956,8 @@ rn_delete(void *v_arg, void *netmask_arg, struct radix_node_head *head)
* This is the same as rn_walktree() except for the parameters and the
* exit.
*/
static int
rn_walktree_from(struct radix_node_head *h, void *a, void *m,
int
rn_walktree_from(struct radix_head *h, void *a, void *m,
walktree_f_t *f, void *w)
{
int error;
@ -1065,8 +1062,8 @@ rn_walktree_from(struct radix_node_head *h, void *a, void *m,
return (0);
}
static int
rn_walktree(struct radix_node_head *h, walktree_f_t *f, void *w)
int
rn_walktree(struct radix_head *h, walktree_f_t *f, void *w)
{
int error;
struct radix_node *base, *next;
@ -1105,75 +1102,76 @@ rn_walktree(struct radix_node_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;
rh->rnh_treetop = t;
}
static void
rn_detachhead_internal(struct radix_head *head)
{
KASSERT((head != NULL),
("%s: head already freed", __func__));
/* Free <left,root,right> nodes. */
R_Free(head);
}
/* Functions used by 'struct radix_node_head' users */
int
rn_inithead(void **head, int off)
{
struct radix_node_head *rnh;
struct radix_mask_head *rmh;
rnh = *head;
rmh = NULL;
if (*head != NULL)
return (1);
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)
R_Free(rnh);
return (0);
}
/* Init trees */
rn_inithead_internal(&rnh->rh, rnh->rnh_nodes, off);
rn_inithead_internal(&rmh->head, rmh->mask_nodes, 0);
*head = rnh;
rnh->rh.rnh_masks = rmh;
/* 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;
rnh->rnh_treetop = t;
return (1);
}
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. */
R_Free(rnh);
*head = NULL;
}
int
rn_inithead(void **head, int off)
{
struct radix_node_head *rnh;
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->rnh_masks, 0) == 0) {
rn_detachhead_internal(head);
return (0);
}
return (1);
}
@ -1181,7 +1179,7 @@ rn_inithead(void **head, int off)
static int
rn_freeentry(struct radix_node *rn, void *arg)
{
struct radix_node_head * const rnh = arg;
struct radix_head * const rnh = arg;
struct radix_node *x;
x = (struct radix_node *)rn_delete(rn + 2, NULL, rnh);
@ -1198,11 +1196,14 @@ rn_detachhead(void **head)
KASSERT((head != NULL && *head != NULL),
("%s: head already freed", __func__));
rnh = *head;
rnh = (struct radix_node_head *)(*head);
rn_walktree(&rnh->rh.rnh_masks->head, rn_freeentry, rnh->rh.rnh_masks);
rn_detachhead_internal(&rnh->rh.rnh_masks->head);
rn_detachhead_internal(&rnh->rh);
*head = NULL;
rn_walktree(rnh->rnh_masks, rn_freeentry, rnh->rnh_masks);
rn_detachhead_internal((void **)&rnh->rnh_masks);
rn_detachhead_internal(head);
return (1);
}

View File

@ -101,35 +101,53 @@ 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_head;
typedef int walktree_f_t(struct radix_node *, void *);
typedef struct radix_node *rn_matchaddr_f_t(void *v,
struct radix_head *head);
typedef struct radix_node *rn_addaddr_f_t(void *v, void *mask,
struct radix_head *head, struct radix_node nodes[]);
typedef struct radix_node *rn_deladdr_f_t(void *v, void *mask,
struct radix_head *head);
typedef struct radix_node *rn_lookup_f_t(void *v, void *mask,
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_head *head,
void *a, void *m, walktree_f_t *f, void *w);
typedef void rn_close_t(struct radix_node *rn, struct radix_head *head);
struct radix_mask_head;
struct radix_head {
struct radix_node *rnh_treetop;
struct radix_mask_head *rnh_masks; /* Storage for our masks */
};
struct radix_node_head {
struct radix_node *rnh_treetop;
u_int rnh_gen; /* generation counter */
int rnh_multipath; /* multipath capable ? */
struct radix_node *(*rnh_addaddr) /* add based on sockaddr */
(void *v, void *mask,
struct radix_node_head *head, struct radix_node nodes[]);
struct radix_node *(*rnh_deladdr) /* remove based on sockaddr */
(void *v, void *mask, struct radix_node_head *head);
struct radix_node *(*rnh_matchaddr) /* longest match for sockaddr */
(void *v, struct radix_node_head *head);
struct radix_node *(*rnh_lookup) /*exact match for sockaddr*/
(void *v, void *mask, struct radix_node_head *head);
int (*rnh_walktree) /* traverse tree */
(struct radix_node_head *head, walktree_f_t *f, void *w);
int (*rnh_walktree_from) /* traverse tree below a */
(struct radix_node_head *head, void *a, void *m,
walktree_f_t *f, void *w);
void (*rnh_close) /* do something when the last ref drops */
(struct radix_node *rn, struct radix_node_head *head);
struct radix_head rh;
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 radix_node_head *rnh_masks; /* Storage for our masks */
#ifdef _KERNEL
struct rwlock rnh_lock; /* locks entire radix tree */
#endif
};
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)))
@ -156,13 +174,14 @@ struct radix_node_head {
int rn_inithead(void **, int);
int rn_detachhead(void **);
int rn_refines(void *, void *);
struct radix_node
*rn_addmask(void *, struct radix_node_head *, int, int),
*rn_addroute (void *, void *, struct radix_node_head *,
struct radix_node [2]),
*rn_delete(void *, void *, struct radix_node_head *),
*rn_lookup (void *v_arg, void *m_arg,
struct radix_node_head *head),
*rn_match(void *, struct radix_node_head *);
struct radix_node *rn_addroute(void *, void *, struct radix_head *,
struct radix_node[2]);
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_ */

View File

@ -48,6 +48,7 @@ __FBSDID("$FreeBSD$");
#include <net/radix.h>
#include <net/radix_mpath.h>
#include <net/route.h>
#include <net/route_var.h>
#include <net/if.h>
#include <net/if_var.h>
@ -57,12 +58,19 @@ __FBSDID("$FreeBSD$");
static uint32_t hashjitter;
int
rn_mpath_capable(struct radix_node_head *rnh)
rt_mpath_capable(struct rib_head *rnh)
{
return rnh->rnh_multipath;
}
int
rn_mpath_capable(struct radix_head *rh)
{
return (rt_mpath_capable((struct rib_head *)rh));
}
struct radix_node *
rn_mpath_next(struct radix_node *rn)
{
@ -159,14 +167,14 @@ rt_mpath_deldup(struct rtentry *headrt, struct rtentry *rt)
* Assume @rt rt_key host bits are cleared according to @netmask
*/
int
rt_mpath_conflict(struct radix_node_head *rnh, struct rtentry *rt,
rt_mpath_conflict(struct rib_head *rnh, struct rtentry *rt,
struct sockaddr *netmask)
{
struct radix_node *rn, *rn1;
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->head);
if (!rn1 || rn1->rn_flags & RNF_ROOT)
return (0);
@ -284,11 +292,11 @@ extern int in_inithead(void **head, int off);
int
rn4_mpath_inithead(void **head, int off)
{
struct radix_node_head *rnh;
struct rib_head *rnh;
hashjitter = arc4random();
if (in_inithead(head, off) == 1) {
rnh = (struct radix_node_head *)*head;
rnh = (struct rib_head *)*head;
rnh->rnh_multipath = 1;
return 1;
} else
@ -300,11 +308,11 @@ rn4_mpath_inithead(void **head, int off)
int
rn6_mpath_inithead(void **head, int off)
{
struct radix_node_head *rnh;
struct rib_head *rnh;
hashjitter = arc4random();
if (in6_inithead(head, off) == 1) {
rnh = (struct radix_node_head *)*head;
rnh = (struct rib_head *)*head;
rnh->rnh_multipath = 1;
return 1;
} else

View File

@ -44,11 +44,13 @@
struct route;
struct rtentry;
struct sockaddr;
int rn_mpath_capable(struct radix_node_head *);
struct rib_head;
int rt_mpath_capable(struct rib_head *);
int rn_mpath_capable(struct radix_head *);
struct radix_node *rn_mpath_next(struct radix_node *);
u_int32_t rn_mpath_count(struct radix_node *);
struct rtentry *rt_mpath_matchgate(struct rtentry *, struct sockaddr *);
int rt_mpath_conflict(struct radix_node_head *, struct rtentry *,
int rt_mpath_conflict(struct rib_head *, struct rtentry *,
struct sockaddr *);
void rtalloc_mpath_fib(struct route *, u_int32_t, u_int);
struct rtentry *rt_mpath_select(struct rtentry *, uint32_t);

View File

@ -57,6 +57,7 @@
#include <net/if_var.h>
#include <net/if_dl.h>
#include <net/route.h>
#include <net/route_var.h>
#include <net/vnet.h>
#include <net/flowtable.h>
@ -114,7 +115,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 */
@ -136,15 +137,15 @@ 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(const struct rtentry *rt, void *arg);
static struct rtentry *rt_unlinkrte(struct radix_node_head *rnh,
static struct rtentry *rt_unlinkrte(struct rib_head *rnh,
struct rt_addrinfo *info, int *perror);
static void rt_notifydelete(struct rtentry *rt, struct rt_addrinfo *info);
#ifdef RADIX_MPATH
static struct radix_node *rt_mpath_unlink(struct radix_node_head *rnh,
static struct radix_node *rt_mpath_unlink(struct rib_head *rnh,
struct rt_addrinfo *info, struct rtentry *rto, int *perror);
#endif
static int rt_exportinfo(struct rtentry *rt, struct rt_addrinfo *info,
@ -175,10 +176,10 @@ 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 **rnh;
KASSERT(table >= 0 && table < rt_numfibs, ("%s: table out of bounds.",
__func__));
@ -186,14 +187,14 @@ rt_tables_get_rnh_ptr(int table, int fam)
__func__));
/* rnh is [fib=0][af=0]. */
rnh = (struct radix_node_head **)V_rt_tables;
rnh = (struct rib_head **)V_rt_tables;
/* Get the offset to the requested table and fam. */
rnh += table * (AF_MAX+1) + fam;
return (rnh);
}
struct radix_node_head *
struct rib_head *
rt_tables_get_rnh(int table, int fam)
{
@ -263,12 +264,12 @@ static void
vnet_route_init(const void *unused __unused)
{
struct domain *dom;
struct radix_node_head **rnh;
struct rib_head **rnh;
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,
@ -299,7 +300,7 @@ vnet_route_uninit(const void *unused __unused)
int table;
int fam;
struct domain *dom;
struct radix_node_head **rnh;
struct rib_head **rnh;
for (dom = domains; dom; dom = dom->dom_next) {
if (dom->dom_rtdetach == NULL)
@ -325,6 +326,43 @@ 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);
/* TODO: 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.rnh_masks = &rh->rmhead;
/* Init locks */
rw_init(&rh->rib_lock, "rib head lock");
/* 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;
@ -375,32 +413,32 @@ 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;
int err = 0, msgtype = RTM_MISS;
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;
/*
* Look up the address in the table for that Address Family
*/
RADIX_NODE_HEAD_RLOCK(rnh);
rn = rnh->rnh_matchaddr(dst, rnh);
RIB_RLOCK(rh);
rn = rh->rnh_matchaddr(dst, &rh->head);
if (rn && ((rn->rn_flags & RNF_ROOT) == 0)) {
newrt = RNTORT(rn);
RT_LOCK(newrt);
RT_ADDREF(newrt);
RADIX_NODE_HEAD_RUNLOCK(rnh);
RIB_RUNLOCK(rh);
return (newrt);
} else
RADIX_NODE_HEAD_RUNLOCK(rnh);
RIB_RUNLOCK(rh);
/*
* Either we hit the root or couldn't find any match,
@ -430,7 +468,7 @@ rtalloc1_fib(struct sockaddr *dst, int report, u_long ignflags,
void
rtfree(struct rtentry *rt)
{
struct radix_node_head *rnh;
struct rib_head *rnh;
KASSERT(rt != NULL,("%s: NULL rt", __func__));
rnh = rt_tables_get_rnh(rt->rt_fibnum, rt_key(rt)->sa_family);
@ -458,7 +496,7 @@ rtfree(struct rtentry *rt)
* 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);
rnh->rnh_close((struct radix_node *)rt, &rnh->head);
/*
* If we are no longer "up" (and ref == 0)
@ -522,7 +560,7 @@ rtredirect_fib(struct sockaddr *dst,
short *stat = NULL;
struct rt_addrinfo info;
struct ifaddr *ifa;
struct radix_node_head *rnh;
struct rib_head *rnh;
ifa = NULL;
rnh = rt_tables_get_rnh(fibnum, dst->sa_family);
@ -608,10 +646,10 @@ 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(rnh);
RT_LOCK(rt);
rt_setgate(rt, rt_key(rt), gateway);
RADIX_NODE_HEAD_UNLOCK(rnh);
RIB_WUNLOCK(rnh);
}
} else
error = EHOSTUNREACH;
@ -853,7 +891,7 @@ int
rib_lookup_info(uint32_t fibnum, const struct sockaddr *dst, uint32_t flags,
uint32_t flowid, struct rt_addrinfo *info)
{
struct radix_node_head *rh;
struct rib_head *rh;
struct radix_node *rn;
struct rtentry *rt;
int error;
@ -863,20 +901,20 @@ rib_lookup_info(uint32_t fibnum, const struct sockaddr *dst, uint32_t flags,
if (rh == NULL)
return (ENOENT);
RADIX_NODE_HEAD_RLOCK(rh);
rn = rh->rnh_matchaddr(__DECONST(void *, dst), rh);
RIB_RLOCK(rh);
rn = rh->rnh_matchaddr(__DECONST(void *, dst), &rh->head);
if (rn != NULL && ((rn->rn_flags & RNF_ROOT) == 0)) {
rt = RNTORT(rn);
/* Ensure route & ifp is UP */
if (RT_LINK_IS_UP(rt->rt_ifp)) {
flags = (flags & NHR_REF) | NHR_COPY;
error = rt_exportinfo(rt, info, flags);
RADIX_NODE_HEAD_RUNLOCK(rh);
RIB_RUNLOCK(rh);
return (error);
}
}
RADIX_NODE_HEAD_RUNLOCK(rh);
RIB_RUNLOCK(rh);
return (ENOENT);
}
@ -903,7 +941,7 @@ void
rt_foreach_fib_walk(int af, rt_setwarg_t *setwa_f, rt_walktree_f_t *wa_f,
void *arg)
{
struct radix_node_head *rnh;
struct rib_head *rnh;
uint32_t fibnum;
int i;
@ -916,9 +954,9 @@ rt_foreach_fib_walk(int af, rt_setwarg_t *setwa_f, rt_walktree_f_t *wa_f,
if (setwa_f != NULL)
setwa_f(rnh, fibnum, af, arg);
RADIX_NODE_HEAD_LOCK(rnh);
rnh->rnh_walktree(rnh, (walktree_f_t *)wa_f, arg);
RADIX_NODE_HEAD_UNLOCK(rnh);
RIB_WLOCK(rnh);
rnh->rnh_walktree(&rnh->head, (walktree_f_t *)wa_f,arg);
RIB_WUNLOCK(rnh);
continue;
}
@ -929,9 +967,9 @@ rt_foreach_fib_walk(int af, rt_setwarg_t *setwa_f, rt_walktree_f_t *wa_f,
if (setwa_f != NULL)
setwa_f(rnh, 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(rnh);
rnh->rnh_walktree(&rnh->head, (walktree_f_t *)wa_f,arg);
RIB_WUNLOCK(rnh);
}
}
}
@ -939,7 +977,7 @@ rt_foreach_fib_walk(int af, rt_setwarg_t *setwa_f, rt_walktree_f_t *wa_f,
struct rt_delinfo
{
struct rt_addrinfo info;
struct radix_node_head *rnh;
struct rib_head *rnh;
struct rtentry *head;
};
@ -987,7 +1025,7 @@ rt_checkdelroute(struct radix_node *rn, void *arg)
void
rt_foreach_fib_walk_del(int af, rt_filter_f_t *filter_f, void *arg)
{
struct radix_node_head *rnh;
struct rib_head *rnh;
struct rt_delinfo di;
struct rtentry *rt;
uint32_t fibnum;
@ -1013,9 +1051,9 @@ rt_foreach_fib_walk_del(int af, rt_filter_f_t *filter_f, void *arg)
continue;
di.rnh = rnh;
RADIX_NODE_HEAD_LOCK(rnh);
rnh->rnh_walktree(rnh, rt_checkdelroute, &di);
RADIX_NODE_HEAD_UNLOCK(rnh);
RIB_WLOCK(rnh);
rnh->rnh_walktree(&rnh->head, rt_checkdelroute, &di);
RIB_WUNLOCK(rnh);
if (di.head == NULL)
continue;
@ -1092,7 +1130,7 @@ rt_flushifroutes(struct ifnet *ifp)
* ENOENT - if supplied filter function returned 0 (not matched).
*/
static struct rtentry *
rt_unlinkrte(struct radix_node_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 rtentry *rt;
@ -1101,7 +1139,7 @@ rt_unlinkrte(struct radix_node_head *rnh, struct rt_addrinfo *info, int *perror)
dst = info->rti_info[RTAX_DST];
netmask = info->rti_info[RTAX_NETMASK];
rt = (struct rtentry *)rnh->rnh_lookup(dst, netmask, rnh);
rt = (struct rtentry *)rnh->rnh_lookup(dst, netmask, &rnh->head);
if (rt == NULL) {
*perror = ESRCH;
return (NULL);
@ -1136,11 +1174,11 @@ rt_unlinkrte(struct radix_node_head *rnh, struct rt_addrinfo *info, int *perror)
*/
*perror = ESRCH;
#ifdef RADIX_MPATH
if (rn_mpath_capable(rnh))
if (rt_mpath_capable(rnh))
rn = rt_mpath_unlink(rnh, info, rt, perror);
else
#endif
rn = rnh->rnh_deladdr(dst, netmask, rnh);
rn = rnh->rnh_deladdr(dst, netmask, &rnh->head);
if (rn == NULL)
return (NULL);
@ -1273,7 +1311,7 @@ void
rt_updatemtu(struct ifnet *ifp)
{
struct if_mtuinfo ifmtu;
struct radix_node_head *rnh;
struct rib_head *rnh;
int i, j;
ifmtu.ifp = ifp;
@ -1289,9 +1327,9 @@ rt_updatemtu(struct ifnet *ifp)
rnh = rt_tables_get_rnh(j, i);
if (rnh == NULL)
continue;
RADIX_NODE_HEAD_LOCK(rnh);
rnh->rnh_walktree(rnh, if_updatemtu_cb, &ifmtu);
RADIX_NODE_HEAD_UNLOCK(rnh);
RIB_WLOCK(rnh);
rnh->rnh_walktree(&rnh->head, if_updatemtu_cb, &ifmtu);
RIB_WUNLOCK(rnh);
}
}
}
@ -1357,7 +1395,7 @@ rt_print(char *buf, int buflen, struct rtentry *rt)
* and sets @perror to ESRCH.
*/
static struct radix_node *
rt_mpath_unlink(struct radix_node_head *rnh, struct rt_addrinfo *info,
rt_mpath_unlink(struct rib_head *rnh, struct rt_addrinfo *info,
struct rtentry *rto, int *perror)
{
/*
@ -1409,7 +1447,7 @@ rt_mpath_unlink(struct radix_node_head *rnh, struct rt_addrinfo *info,
* use the normal delete code to remove
* the first entry
*/
rn = rnh->rnh_deladdr(dst, netmask, rnh);
rn = rnh->rnh_deladdr(dst, netmask, &rnh->head);
*perror = 0;
return (rn);
}
@ -1427,7 +1465,7 @@ rt_mpath_unlink(struct radix_node_head *rnh, struct rt_addrinfo *info,
#ifdef FLOWTABLE
static struct rtentry *
rt_flowtable_check_route(struct radix_node_head *rnh, struct rt_addrinfo *info)
rt_flowtable_check_route(struct rib_head *rnh, struct rt_addrinfo *info)
{
#if defined(INET6) || defined(INET)
struct radix_node *rn;
@ -1499,7 +1537,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 *rnh;
struct ifaddr *ifa;
struct sockaddr *ndst;
struct sockaddr_storage mdst;
@ -1537,9 +1575,9 @@ rtrequest1_fib(int req, struct rt_addrinfo *info, struct rtentry **ret_nrt,
dst = (struct sockaddr *)&mdst;
}
RADIX_NODE_HEAD_LOCK(rnh);
RIB_WLOCK(rnh);
rt = rt_unlinkrte(rnh, info, &error);
RADIX_NODE_HEAD_UNLOCK(rnh);
RIB_WUNLOCK(rnh);
if (error != 0)
return (error);
@ -1616,13 +1654,13 @@ rtrequest1_fib(int req, struct rt_addrinfo *info, struct rtentry **ret_nrt,
rt_setmetrics(info, rt);
RADIX_NODE_HEAD_LOCK(rnh);
RIB_WLOCK(rnh);
RT_LOCK(rt);
#ifdef RADIX_MPATH
/* do not permit exactly the same dst/mask/gw pair */
if (rn_mpath_capable(rnh) &&
if (rt_mpath_capable(rnh) &&
rt_mpath_conflict(rnh, rt, netmask)) {
RADIX_NODE_HEAD_UNLOCK(rnh);
RIB_WUNLOCK(rnh);
ifa_free(rt->rt_ifa);
R_Free(rt_key(rt));
@ -1636,7 +1674,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 = rnh->rnh_addaddr(ndst, netmask, &rnh->head, rt->rt_nodes);
rt_old = NULL;
if (rn == NULL && (info->rti_flags & RTF_PINNED) != 0) {
@ -1653,10 +1691,10 @@ rtrequest1_fib(int req, struct rt_addrinfo *info, struct rtentry **ret_nrt,
info->rti_flags |= RTF_PINNED;
info->rti_info[RTAX_DST] = info_dst;
if (rt_old != NULL)
rn = rnh->rnh_addaddr(ndst, netmask, rnh,
rn = rnh->rnh_addaddr(ndst, netmask, &rnh->head,
rt->rt_nodes);
}
RADIX_NODE_HEAD_UNLOCK(rnh);
RIB_WUNLOCK(rnh);
if (rt_old != NULL)
RT_UNLOCK(rt_old);
@ -1705,9 +1743,9 @@ rtrequest1_fib(int req, struct rt_addrinfo *info, struct rtentry **ret_nrt,
RT_UNLOCK(rt);
break;
case RTM_CHANGE:
RADIX_NODE_HEAD_LOCK(rnh);
RIB_WLOCK(rnh);
error = rtrequest1_fib_change(rnh, info, ret_nrt, fibnum);
RADIX_NODE_HEAD_UNLOCK(rnh);
RIB_WUNLOCK(rnh);
break;
default:
error = EOPNOTSUPP;
@ -1724,7 +1762,7 @@ rtrequest1_fib(int req, struct rt_addrinfo *info, struct rtentry **ret_nrt,
#undef flags
static int
rtrequest1_fib_change(struct radix_node_head *rnh, struct rt_addrinfo *info,
rtrequest1_fib_change(struct rib_head *rnh, struct rt_addrinfo *info,
struct rtentry **ret_nrt, u_int fibnum)
{
struct rtentry *rt = NULL;
@ -1734,7 +1772,7 @@ rtrequest1_fib_change(struct radix_node_head *rnh, struct rt_addrinfo *info,
struct if_mtuinfo ifmtu;
rt = (struct rtentry *)rnh->rnh_lookup(info->rti_info[RTAX_DST],
info->rti_info[RTAX_NETMASK], rnh);
info->rti_info[RTAX_NETMASK], &rnh->head);
if (rt == NULL)
return (ESRCH);
@ -1744,7 +1782,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 (rt_mpath_capable(rnh)) {
rt = rt_mpath_matchgate(rt, info->rti_info[RTAX_GATEWAY]);
if (rt == NULL)
return (ESRCH);
@ -1935,7 +1973,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 *rnh;
if (flags & RTF_HOST) {
dst = ifa->ifa_dstaddr;
@ -2003,10 +2041,10 @@ rtinit1(struct ifaddr *ifa, int cmd, int flags, int fibnum)
if (rnh == NULL)
/* this table doesn't exist but others might */
continue;
RADIX_NODE_HEAD_RLOCK(rnh);
rn = rnh->rnh_lookup(dst, netmask, rnh);
RIB_RLOCK(rnh);
rn = rnh->rnh_lookup(dst, netmask, &rnh->head);
#ifdef RADIX_MPATH
if (rn_mpath_capable(rnh)) {
if (rt_mpath_capable(rnh)) {
if (rn == NULL)
error = ESRCH;
@ -2029,7 +2067,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(rnh);
if (error) {
/* this is only an error if bad on ALL tables */
continue;

View File

@ -204,21 +204,6 @@ struct rtentry {
/* Control plane route request flags */
#define NHR_COPY 0x100 /* Copy rte data */
/* rte<>nhop translation */
static inline uint16_t
fib_rte_to_nh_flags(int rt_flags)
{
uint16_t res;
res = (rt_flags & RTF_REJECT) ? NHF_REJECT : 0;
res |= (rt_flags & RTF_BLACKHOLE) ? NHF_BLACKHOLE : 0;
res |= (rt_flags & (RTF_DYNAMIC|RTF_MODIFIED)) ? NHF_REDIRECT : 0;
res |= (rt_flags & RTF_BROADCAST) ? NHF_BROADCAST : 0;
res |= (rt_flags & RTF_GATEWAY) ? NHF_GATEWAY : 0;
return (res);
}
#ifdef _KERNEL
/* rte<>ro_flags translation */
static inline void
@ -413,9 +398,8 @@ struct rt_addrinfo {
} \
} while (0)
struct radix_node_head *rt_tables_get_rnh(int, int);
struct ifmultiaddr;
struct rib_head;
void rt_ieee80211msg(struct ifnet *, int, void *, size_t);
void rt_ifannouncemsg(struct ifnet *, int);
@ -429,6 +413,8 @@ int rt_routemsg(int, struct ifnet *ifp, int, struct rtentry *, int);
void rt_newmaddrmsg(int, struct ifmultiaddr *);
int rt_setgate(struct rtentry *, struct sockaddr *, struct sockaddr *);
void rt_maskedcopy(struct sockaddr *, struct sockaddr *, struct sockaddr *);
struct rib_head *rt_table_init(int);
void rt_table_destroy(struct rib_head *);
int rtsock_addrmsg(int, struct ifaddr *, int);
int rtsock_routemsg(int, struct ifnet *ifp, int, struct rtentry *, int);
@ -447,7 +433,7 @@ void rtfree(struct rtentry *);
void rt_updatemtu(struct ifnet *);
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_walk(int af, rt_setwarg_t *, rt_walktree_f_t *, void *);
void rt_foreach_fib_walk_del(int af, rt_filter_f_t *filter_f, void *arg);
void rt_flushifroutes(struct ifnet *ifp);

76
sys/net/route_var.h Normal file
View File

@ -0,0 +1,76 @@
/*-
* Copyright (c) 2015-2016
* Alexander V. Chernikov <melifaro@FreeBSD.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#ifndef _NET_ROUTE_VAR_H_
#define _NET_ROUTE_VAR_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*/
u_int rnh_gen; /* generation counter */
int rnh_multipath; /* multipath capable ? */
struct radix_node rnh_nodes[3]; /* empty tree for common case */
struct rwlock rib_lock; /* config/data path lock */
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_tables_get_rnh(int fib, int family);
/* rte<>nhop translation */
static inline uint16_t
fib_rte_to_nh_flags(int rt_flags)
{
uint16_t res;
res = (rt_flags & RTF_REJECT) ? NHF_REJECT : 0;
res |= (rt_flags & RTF_BLACKHOLE) ? NHF_BLACKHOLE : 0;
res |= (rt_flags & (RTF_DYNAMIC|RTF_MODIFIED)) ? NHF_REDIRECT : 0;
res |= (rt_flags & RTF_BROADCAST) ? NHF_BROADCAST : 0;
res |= (rt_flags & RTF_GATEWAY) ? NHF_GATEWAY : 0;
return (res);
}
#endif

View File

@ -59,6 +59,7 @@
#include <net/netisr.h>
#include <net/raw_cb.h>
#include <net/route.h>
#include <net/route_var.h>
#include <net/vnet.h>
#include <netinet/in.h>
@ -520,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 *rnh;
struct rt_addrinfo info;
struct sockaddr_storage ss;
#ifdef INET6
@ -706,7 +707,7 @@ route_output(struct mbuf *m, struct socket *so, ...)
if (rnh == NULL)
senderr(EAFNOSUPPORT);
RADIX_NODE_HEAD_RLOCK(rnh);
RIB_RLOCK(rnh);
if (info.rti_info[RTAX_NETMASK] == NULL &&
rtm->rtm_type == RTM_GET) {
@ -716,14 +717,14 @@ route_output(struct mbuf *m, struct socket *so, ...)
* 'route -n get addr'
*/
rt = (struct rtentry *) rnh->rnh_matchaddr(
info.rti_info[RTAX_DST], rnh);
info.rti_info[RTAX_DST], &rnh->head);
} else
rt = (struct rtentry *) rnh->rnh_lookup(
info.rti_info[RTAX_DST],
info.rti_info[RTAX_NETMASK], rnh);
info.rti_info[RTAX_NETMASK], &rnh->head);
if (rt == NULL) {
RADIX_NODE_HEAD_RUNLOCK(rnh);
RIB_RUNLOCK(rnh);
senderr(ESRCH);
}
#ifdef RADIX_MPATH
@ -735,11 +736,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 (rt_mpath_capable(rnh) &&
(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(rnh);
senderr(ESRCH);
}
}
@ -770,15 +771,16 @@ 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 *)rnh->rnh_matchaddr(&laddr,
&rnh->head);
if (rt == NULL) {
RADIX_NODE_HEAD_RUNLOCK(rnh);
RIB_RUNLOCK(rnh);
senderr(ESRCH);
}
}
RT_LOCK(rt);
RT_ADDREF(rt);
RADIX_NODE_HEAD_RUNLOCK(rnh);
RIB_RUNLOCK(rnh);
report:
RT_LOCK_ASSERT(rt);
@ -1803,7 +1805,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 *rnh = NULL; /* silence compiler. */
int i, lim, error = EINVAL;
int fib = 0;
u_char af;
@ -1872,10 +1874,10 @@ sysctl_rtsock(SYSCTL_HANDLER_ARGS)
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,
RIB_RLOCK(rnh);
error = rnh->rnh_walktree(&rnh->head,
sysctl_dumpentry, &w);
RADIX_NODE_HEAD_RUNLOCK(rnh);
RIB_RUNLOCK(rnh);
} else if (af != 0)
error = EAFNOSUPPORT;
}

View File

@ -48,6 +48,7 @@ __FBSDID("$FreeBSD$");
#include <net/if_var.h>
#include <net/if_dl.h>
#include <net/route.h>
#include <net/route_var.h>
#include <net/vnet.h>
#ifdef RADIX_MPATH
@ -133,7 +134,7 @@ int
fib4_lookup_nh_basic(uint32_t fibnum, struct in_addr dst, uint32_t flags,
uint32_t flowid, struct nhop4_basic *pnh4)
{
struct radix_node_head *rh;
struct rib_head *rh;
struct radix_node *rn;
struct sockaddr_in sin;
struct rtentry *rte;
@ -148,19 +149,19 @@ fib4_lookup_nh_basic(uint32_t fibnum, struct in_addr dst, uint32_t flags,
sin.sin_len = sizeof(struct sockaddr_in);
sin.sin_addr = dst;
RADIX_NODE_HEAD_RLOCK(rh);
rn = rh->rnh_matchaddr((void *)&sin, rh);
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, flags, pnh4);
RADIX_NODE_HEAD_RUNLOCK(rh);
RIB_RUNLOCK(rh);
return (0);
}
}
RADIX_NODE_HEAD_RUNLOCK(rh);
RIB_RUNLOCK(rh);
return (ENOENT);
}
@ -181,7 +182,7 @@ int
fib4_lookup_nh_ext(uint32_t fibnum, struct in_addr dst, uint32_t flags,
uint32_t flowid, struct nhop4_extended *pnh4)
{
struct radix_node_head *rh;
struct rib_head *rh;
struct radix_node *rn;
struct sockaddr_in sin;
struct rtentry *rte;
@ -196,14 +197,14 @@ fib4_lookup_nh_ext(uint32_t fibnum, struct in_addr dst, uint32_t flags,
sin.sin_len = sizeof(struct sockaddr_in);
sin.sin_addr = dst;
RADIX_NODE_HEAD_RLOCK(rh);
rn = rh->rnh_matchaddr((void *)&sin, rh);
RIB_RLOCK(rh);
rn = rh->rnh_matchaddr((void *)&sin, &rh->head);
if (rn != NULL && ((rn->rn_flags & RNF_ROOT) == 0)) {
rte = RNTORT(rn);
#ifdef RADIX_MPATH
rte = rt_mpath_select(rte, flowid);
if (rte == NULL) {
RADIX_NODE_HEAD_RUNLOCK(rh);
RIB_RUNLOCK(rh);
return (ENOENT);
}
#endif
@ -213,12 +214,12 @@ fib4_lookup_nh_ext(uint32_t fibnum, struct in_addr dst, uint32_t flags,
if ((flags & NHR_REF) != 0) {
/* TODO: lwref on egress ifp's ? */
}
RADIX_NODE_HEAD_RUNLOCK(rh);
RIB_RUNLOCK(rh);
return (0);
}
}
RADIX_NODE_HEAD_RUNLOCK(rh);
RIB_RUNLOCK(rh);
return (ENOENT);
}

View File

@ -40,6 +40,7 @@ __FBSDID("$FreeBSD$");
#include <net/if.h>
#include <net/if_var.h>
#include <net/route.h>
#include <net/route_var.h>
#include <net/vnet.h>
#include <netinet/in.h>
@ -57,13 +58,12 @@ extern int in_detachhead(void **head, int off);
* 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,15 +113,15 @@ 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;
*head = (void *)rh;
rnh->rnh_addaddr = in_addroute;
if (_in_rt_was_here == 0 ) {
_in_rt_was_here = 1;
}

View File

@ -351,7 +351,6 @@ inm_acquire_locked(struct in_multi *inm)
struct rtentry;
struct route;
struct ip_moptions;
struct radix_node_head;
struct in_multi *inm_lookup_locked(struct ifnet *, const struct in_addr);
struct in_multi *inm_lookup(struct ifnet *, const struct in_addr);

View File

@ -49,6 +49,7 @@ __FBSDID("$FreeBSD$");
#include <net/if_var.h>
#include <net/if_dl.h>
#include <net/route.h>
#include <net/route_var.h>
#include <net/vnet.h>
#ifdef RADIX_MPATH
@ -170,7 +171,7 @@ int
fib6_lookup_nh_basic(uint32_t fibnum, const struct in6_addr *dst, uint32_t scopeid,
uint32_t flags, uint32_t flowid, struct nhop6_basic *pnh6)
{
struct radix_node_head *rh;
struct rib_head *rh;
struct radix_node *rn;
struct sockaddr_in6 sin6;
struct rtentry *rte;
@ -188,18 +189,18 @@ fib6_lookup_nh_basic(uint32_t fibnum, const struct in6_addr *dst, uint32_t scope
if (IN6_IS_SCOPE_LINKLOCAL(dst))
sin6.sin6_addr.s6_addr16[1] = htons(scopeid & 0xffff);
RADIX_NODE_HEAD_RLOCK(rh);
rn = rh->rnh_matchaddr((void *)&sin6, rh);
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, &sin6.sin6_addr, flags, pnh6);
RADIX_NODE_HEAD_RUNLOCK(rh);
RIB_RUNLOCK(rh);
return (0);
}
}
RADIX_NODE_HEAD_RUNLOCK(rh);
RIB_RUNLOCK(rh);
return (ENOENT);
}
@ -219,7 +220,7 @@ int
fib6_lookup_nh_ext(uint32_t fibnum, const struct in6_addr *dst,uint32_t scopeid,
uint32_t flags, uint32_t flowid, struct nhop6_extended *pnh6)
{
struct radix_node_head *rh;
struct rib_head *rh;
struct radix_node *rn;
struct sockaddr_in6 sin6;
struct rtentry *rte;
@ -237,14 +238,14 @@ fib6_lookup_nh_ext(uint32_t fibnum, const struct in6_addr *dst,uint32_t scopeid,
if (IN6_IS_SCOPE_LINKLOCAL(dst))
sin6.sin6_addr.s6_addr16[1] = htons(scopeid & 0xffff);
RADIX_NODE_HEAD_RLOCK(rh);
rn = rh->rnh_matchaddr((void *)&sin6, rh);
RIB_RLOCK(rh);
rn = rh->rnh_matchaddr((void *)&sin6, &rh->head);
if (rn != NULL && ((rn->rn_flags & RNF_ROOT) == 0)) {
rte = RNTORT(rn);
#ifdef RADIX_MPATH
rte = rt_mpath_select(rte, flowid);
if (rte == NULL) {
RADIX_NODE_HEAD_RUNLOCK(rh);
RIB_RUNLOCK(rh);
return (ENOENT);
}
#endif
@ -255,12 +256,12 @@ fib6_lookup_nh_ext(uint32_t fibnum, const struct in6_addr *dst,uint32_t scopeid,
if ((flags & NHR_REF) != 0) {
/* TODO: Do lwref on egress ifp's */
}
RADIX_NODE_HEAD_RUNLOCK(rh);
RIB_RUNLOCK(rh);
return (0);
}
}
RADIX_NODE_HEAD_RUNLOCK(rh);
RIB_RUNLOCK(rh);
return (ENOENT);
}

View File

@ -77,6 +77,7 @@ __FBSDID("$FreeBSD$");
#include <net/if.h>
#include <net/if_var.h>
#include <net/route.h>
#include <net/route_var.h>
#include <netinet/in.h>
#include <netinet/ip_var.h>
@ -102,13 +103,12 @@ 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);
RADIX_NODE_HEAD_WLOCK_ASSERT(head);
if (IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr))
rt->rt_flags |= RTF_MULTICAST;
@ -154,7 +154,7 @@ in6_addroute(void *v_arg, void *n_arg, struct radix_node_head *head,
* Age old PMTUs.
*/
struct mtuex_arg {
struct radix_node_head *rnh;
struct rib_head *rnh;
time_t nextstop;
};
static VNET_DEFINE(struct callout, rtq_mtutimer);
@ -179,7 +179,7 @@ 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,
in6_mtutimo_setwa(struct rib_head *rnh, uint32_t fibum, int af,
void *_arg)
{
struct mtuex_arg *arg;
@ -213,15 +213,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, 1);

View File

@ -54,6 +54,7 @@ __FBSDID("$FreeBSD$");
#include <net/if_types.h>
#include <net/if_dl.h>
#include <net/route.h>
#include <net/route_var.h>
#include <net/radix.h>
#include <net/vnet.h>
@ -1525,7 +1526,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 *rnh;
struct rtentry *rt;
struct sockaddr_in6 mask6;
u_long rtflags;
@ -1554,7 +1555,7 @@ nd6_prefix_onlink_rtrequest(struct nd_prefix *pr, struct ifaddr *ifa)
rnh = rt_tables_get_rnh(rt->rt_fibnum, AF_INET6);
/* XXX what if rhn == NULL? */
RADIX_NODE_HEAD_LOCK(rnh);
RIB_WLOCK(rnh);
RT_LOCK(rt);
if (rt_setgate(rt, rt_key(rt),
(struct sockaddr *)&null_sdl) == 0) {
@ -1564,7 +1565,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(rnh);
nd6_rtmsg(RTM_ADD, rt);
RT_UNLOCK(rt);
pr->ndpr_stateflags |= NDPRF_ONLINK;

View File

@ -51,6 +51,7 @@ __FBSDID("$FreeBSD$");
#include <net/if.h> /* ip_fw.h requires IFNAMSIZ */
#include <net/radix.h>
#include <net/route.h>
#include <net/route_var.h>
#include <netinet/in.h>
#include <netinet/in_fib.h>
@ -409,7 +410,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);
@ -420,7 +421,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);
@ -461,7 +462,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);
@ -476,11 +477,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);
@ -548,13 +549,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) {
@ -572,10 +573,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);
}
@ -722,7 +723,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);
@ -746,7 +747,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);
@ -817,7 +818,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);
@ -4042,21 +4043,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);
}
}

View File

@ -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");
}
@ -739,7 +739,7 @@ static struct pfr_kentry *
pfr_lookup_addr(struct pfr_ktable *kt, struct pfr_addr *ad, int exact)
{
union sockaddr_union sa, mask;
struct radix_node_head *head = NULL;
struct radix_head *head = NULL;
struct pfr_kentry *ke;
PF_RULES_ASSERT();
@ -747,10 +747,10 @@ pfr_lookup_addr(struct pfr_ktable *kt, struct pfr_addr *ad, int exact)
bzero(&sa, sizeof(sa));
if (ad->pfra_af == AF_INET) {
FILLIN_SIN(sa.sin, ad->pfra_ip4addr);
head = kt->pfrkt_ip4;
head = &kt->pfrkt_ip4->rh;
} else if ( ad->pfra_af == AF_INET6 ) {
FILLIN_SIN6(sa.sin6, ad->pfra_ip6addr);
head = kt->pfrkt_ip6;
head = &kt->pfrkt_ip6->rh;
}
if (ADDR_NETWORK(ad)) {
pfr_prepare_network(&mask, ad->pfra_af, ad->pfra_net);
@ -929,15 +929,15 @@ pfr_route_kentry(struct pfr_ktable *kt, struct pfr_kentry *ke)
{
union sockaddr_union mask;
struct radix_node *rn;
struct radix_node_head *head = NULL;
struct radix_head *head = NULL;
PF_RULES_WASSERT();
bzero(ke->pfrke_node, sizeof(ke->pfrke_node));
if (ke->pfrke_af == AF_INET)
head = kt->pfrkt_ip4;
head = &kt->pfrkt_ip4->rh;
else if (ke->pfrke_af == AF_INET6)
head = kt->pfrkt_ip6;
head = &kt->pfrkt_ip6->rh;
if (KENTRY_NETWORK(ke)) {
pfr_prepare_network(&mask, ke->pfrke_af, ke->pfrke_net);
@ -953,12 +953,12 @@ pfr_unroute_kentry(struct pfr_ktable *kt, struct pfr_kentry *ke)
{
union sockaddr_union mask;
struct radix_node *rn;
struct radix_node_head *head = NULL;
struct radix_head *head = NULL;
if (ke->pfrke_af == AF_INET)
head = kt->pfrkt_ip4;
head = &kt->pfrkt_ip4->rh;
else if (ke->pfrke_af == AF_INET6)
head = kt->pfrkt_ip6;
head = &kt->pfrkt_ip6->rh;
if (KENTRY_NETWORK(ke)) {
pfr_prepare_network(&mask, ke->pfrke_af, ke->pfrke_net);
@ -1907,7 +1907,7 @@ pfr_match_addr(struct pfr_ktable *kt, struct pf_addr *a, sa_family_t af)
sin.sin_len = sizeof(sin);
sin.sin_family = AF_INET;
sin.sin_addr.s_addr = a->addr32[0];
ke = (struct pfr_kentry *)rn_match(&sin, kt->pfrkt_ip4);
ke = (struct pfr_kentry *)rn_match(&sin, &kt->pfrkt_ip4->rh);
if (ke && KENTRY_RNF_ROOT(ke))
ke = NULL;
break;
@ -1922,7 +1922,7 @@ pfr_match_addr(struct pfr_ktable *kt, struct pf_addr *a, sa_family_t af)
sin6.sin6_len = sizeof(sin6);
sin6.sin6_family = AF_INET6;
bcopy(a, &sin6.sin6_addr, sizeof(sin6.sin6_addr));
ke = (struct pfr_kentry *)rn_match(&sin6, kt->pfrkt_ip6);
ke = (struct pfr_kentry *)rn_match(&sin6, &kt->pfrkt_ip6->rh);
if (ke && KENTRY_RNF_ROOT(ke))
ke = NULL;
break;
@ -1958,7 +1958,7 @@ pfr_update_stats(struct pfr_ktable *kt, struct pf_addr *a, sa_family_t af,
sin.sin_len = sizeof(sin);
sin.sin_family = AF_INET;
sin.sin_addr.s_addr = a->addr32[0];
ke = (struct pfr_kentry *)rn_match(&sin, kt->pfrkt_ip4);
ke = (struct pfr_kentry *)rn_match(&sin, &kt->pfrkt_ip4->rh);
if (ke && KENTRY_RNF_ROOT(ke))
ke = NULL;
break;
@ -1973,7 +1973,7 @@ pfr_update_stats(struct pfr_ktable *kt, struct pf_addr *a, sa_family_t af,
sin6.sin6_len = sizeof(sin6);
sin6.sin6_family = AF_INET6;
bcopy(a, &sin6.sin6_addr, sizeof(sin6.sin6_addr));
ke = (struct pfr_kentry *)rn_match(&sin6, kt->pfrkt_ip6);
ke = (struct pfr_kentry *)rn_match(&sin6, &kt->pfrkt_ip6->rh);
if (ke && KENTRY_RNF_ROOT(ke))
ke = NULL;
break;
@ -2120,11 +2120,11 @@ pfr_pool_get(struct pfr_ktable *kt, int *pidx, struct pf_addr *counter,
switch (af) {
case AF_INET:
ke2 = (struct pfr_kentry *)rn_match(&uaddr,
kt->pfrkt_ip4);
&kt->pfrkt_ip4->rh);
break;
case AF_INET6:
ke2 = (struct pfr_kentry *)rn_match(&uaddr,
kt->pfrkt_ip6);
&kt->pfrkt_ip6->rh);
break;
}
/* no need to check KENTRY_RNF_ROOT() here */
@ -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);
}

View File

@ -65,6 +65,9 @@ __FBSDID("$FreeBSD$");
#include <net/if.h>
#include <net/if_var.h>
#include <net/route.h>
#ifdef BOOTP_DEBUG
#include <net/route_var.h>
#endif
#include <netinet/in.h>
#include <netinet/in_var.h>
@ -369,15 +372,15 @@ bootpboot_p_tree(struct radix_node *rn)
void
bootpboot_p_rtlist(void)
{
struct radix_node_head *rnh;
struct rib_head *rnh;
printf("Routing table:\n");
rnh = rt_tables_get_rnh(0, AF_INET);
if (rnh == NULL)
return;
RADIX_NODE_HEAD_RLOCK(rnh); /* could sleep XXX */
RIB_RLOCK(rnh); /* could sleep XXX */
bootpboot_p_tree(rnh->rnh_treetop);
RADIX_NODE_HEAD_RUNLOCK(rnh);
RIB_RUNLOCK(rnh);
}
void