Changeset View
Changeset View
Standalone View
Standalone View
head/sys/net/route_var.h
Show All 26 Lines | |||||
* SUCH DAMAGE. | * SUCH DAMAGE. | ||||
* | * | ||||
* $FreeBSD$ | * $FreeBSD$ | ||||
*/ | */ | ||||
#ifndef _NET_ROUTE_VAR_H_ | #ifndef _NET_ROUTE_VAR_H_ | ||||
#define _NET_ROUTE_VAR_H_ | #define _NET_ROUTE_VAR_H_ | ||||
#ifndef RNF_NORMAL | |||||
#include <net/radix.h> | |||||
#endif | |||||
#include <sys/counter.h> | |||||
struct nh_control; | struct nh_control; | ||||
typedef int rnh_preadd_entry_f_t(u_int fibnum, const struct sockaddr *addr, | typedef int rnh_preadd_entry_f_t(u_int fibnum, const struct sockaddr *addr, | ||||
const struct sockaddr *mask, struct nhop_object *nh); | const struct sockaddr *mask, struct nhop_object *nh); | ||||
struct rib_head { | struct rib_head { | ||||
struct radix_head head; | struct radix_head head; | ||||
rn_matchaddr_f_t *rnh_matchaddr; /* longest match for sockaddr */ | rn_matchaddr_f_t *rnh_matchaddr; /* longest match for sockaddr */ | ||||
rn_addaddr_f_t *rnh_addaddr; /* add based on sockaddr*/ | rn_addaddr_f_t *rnh_addaddr; /* add based on sockaddr*/ | ||||
▲ Show 20 Lines • Show All 52 Lines • ▼ Show 20 Lines | |||||
struct rib_head *rt_tables_get_rnh(int fib, int family); | struct rib_head *rt_tables_get_rnh(int fib, int family); | ||||
void rt_mpath_init_rnh(struct rib_head *rnh); | void rt_mpath_init_rnh(struct rib_head *rnh); | ||||
VNET_PCPUSTAT_DECLARE(struct rtstat, rtstat); | VNET_PCPUSTAT_DECLARE(struct rtstat, rtstat); | ||||
#define RTSTAT_ADD(name, val) \ | #define RTSTAT_ADD(name, val) \ | ||||
VNET_PCPUSTAT_ADD(struct rtstat, rtstat, name, (val)) | VNET_PCPUSTAT_ADD(struct rtstat, rtstat, name, (val)) | ||||
#define RTSTAT_INC(name) RTSTAT_ADD(name, 1) | #define RTSTAT_INC(name) RTSTAT_ADD(name, 1) | ||||
struct rtentry { | |||||
struct radix_node rt_nodes[2]; /* tree glue, and other values */ | |||||
/* | |||||
* XXX struct rtentry must begin with a struct radix_node (or two!) | |||||
* because the code does some casts of a 'struct radix_node *' | |||||
* to a 'struct rtentry *' | |||||
*/ | |||||
#define rt_key(r) (*((struct sockaddr **)(&(r)->rt_nodes->rn_key))) | |||||
#define rt_mask(r) (*((struct sockaddr **)(&(r)->rt_nodes->rn_mask))) | |||||
#define rt_key_const(r) (*((const struct sockaddr * const *)(&(r)->rt_nodes->rn_key))) | |||||
#define rt_mask_const(r) (*((const struct sockaddr * const *)(&(r)->rt_nodes->rn_mask))) | |||||
struct sockaddr *rt_gateway; /* value */ | |||||
struct ifnet *rt_ifp; /* the answer: interface to use */ | |||||
struct ifaddr *rt_ifa; /* the answer: interface address to use */ | |||||
struct nhop_object *rt_nhop; /* nexthop data */ | |||||
int rt_flags; /* up/down?, host/net */ | |||||
int rt_refcnt; /* # held references */ | |||||
u_int rt_fibnum; /* which FIB */ | |||||
u_long rt_mtu; /* MTU for this path */ | |||||
u_long rt_weight; /* absolute weight */ | |||||
u_long rt_expire; /* lifetime for route, e.g. redirect */ | |||||
#define rt_endzero rt_pksent | |||||
counter_u64_t rt_pksent; /* packets sent using this route */ | |||||
struct mtx rt_mtx; /* mutex for routing entry */ | |||||
struct rtentry *rt_chain; /* pointer to next rtentry to delete */ | |||||
}; | |||||
#define RT_LOCK_INIT(_rt) \ | |||||
mtx_init(&(_rt)->rt_mtx, "rtentry", NULL, MTX_DEF | MTX_DUPOK | MTX_NEW) | |||||
#define RT_LOCK(_rt) mtx_lock(&(_rt)->rt_mtx) | |||||
#define RT_UNLOCK(_rt) mtx_unlock(&(_rt)->rt_mtx) | |||||
#define RT_LOCK_DESTROY(_rt) mtx_destroy(&(_rt)->rt_mtx) | |||||
#define RT_LOCK_ASSERT(_rt) mtx_assert(&(_rt)->rt_mtx, MA_OWNED) | |||||
#define RT_UNLOCK_COND(_rt) do { \ | |||||
if (mtx_owned(&(_rt)->rt_mtx)) \ | |||||
mtx_unlock(&(_rt)->rt_mtx); \ | |||||
} while (0) | |||||
#define RT_ADDREF(_rt) do { \ | |||||
RT_LOCK_ASSERT(_rt); \ | |||||
KASSERT((_rt)->rt_refcnt >= 0, \ | |||||
("negative refcnt %d", (_rt)->rt_refcnt)); \ | |||||
(_rt)->rt_refcnt++; \ | |||||
} while (0) | |||||
#define RT_REMREF(_rt) do { \ | |||||
RT_LOCK_ASSERT(_rt); \ | |||||
KASSERT((_rt)->rt_refcnt > 0, \ | |||||
("bogus refcnt %d", (_rt)->rt_refcnt)); \ | |||||
(_rt)->rt_refcnt--; \ | |||||
} while (0) | |||||
#define RTFREE_LOCKED(_rt) do { \ | |||||
if ((_rt)->rt_refcnt <= 1) \ | |||||
rtfree(_rt); \ | |||||
else { \ | |||||
RT_REMREF(_rt); \ | |||||
RT_UNLOCK(_rt); \ | |||||
} \ | |||||
/* guard against invalid refs */ \ | |||||
_rt = 0; \ | |||||
} while (0) | |||||
#define RTFREE(_rt) do { \ | |||||
RT_LOCK(_rt); \ | |||||
RTFREE_LOCKED(_rt); \ | |||||
} while (0) | |||||
/* | /* | ||||
* With the split between the routing entry and the nexthop, | * With the split between the routing entry and the nexthop, | ||||
* rt_flags has to be split between these 2 entries. As rtentry | * rt_flags has to be split between these 2 entries. As rtentry | ||||
* mostly contains prefix data and is thought to be generic enough | * mostly contains prefix data and is thought to be generic enough | ||||
* so one can transparently change the nexthop pointer w/o requiring | * so one can transparently change the nexthop pointer w/o requiring | ||||
* any other rtentry changes, most of rt_flags shifts to the particular nexthop. | * any other rtentry changes, most of rt_flags shifts to the particular nexthop. | ||||
* / | * / | ||||
▲ Show 20 Lines • Show All 47 Lines • Show Last 20 Lines |