Changeset View
Changeset View
Standalone View
Standalone View
sys/net/route/rtentry_var.h
- This file was added.
Property | Old Value | New Value |
---|---|---|
svn:eol-style | null | native \ No newline at end of property |
svn:keywords | null | FreeBSD=%H \ No newline at end of property |
svn:mime-type | null | text/plain \ No newline at end of property |
/*- | |||||
* SPDX-License-Identifier: BSD-3-Clause | |||||
* | |||||
* Copyright (c) 1980, 1986, 1993 | |||||
* The Regents of the University of California. All rights reserved. | |||||
* | |||||
* 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. | |||||
* 3. 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. | |||||
* | |||||
* @(#)route.h 8.4 (Berkeley) 1/9/95 | |||||
* $FreeBSD$ | |||||
*/ | |||||
/* | |||||
* This header contains struct rtentry definition and supporting macro. | |||||
* | |||||
* Header is not intended to be included by the code external to the | |||||
* routing subsystem. | |||||
*/ | |||||
#ifndef _NET_RTENTRY_VAR_H_ | |||||
#define _NET_RTENTRY_VAR_H_ | |||||
#if defined(_KERNEL) | |||||
#include <sys/counter.h> | |||||
#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 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))) | |||||
/* | |||||
* 2 structures above consists of 2x6 pointers, leaving | |||||
* 4 pointers / 32 bytes in the cacheline on amd64 | |||||
*/ | |||||
struct nhop_object *rt_nhop; /* nexthop data */ | |||||
union { | |||||
struct sockaddr_in rt_dst4; | |||||
struct sockaddr_in6 rt_dst6; | |||||
struct sockaddr rt_dst; | |||||
}; | |||||
/* | |||||
* sizeof(struct sockaddr_in6) == 28 on amd64, | |||||
* however, the dataplane-relevant part (e.g. address) | |||||
* lies at offset 8..24, making it into the end of the cache line. | |||||
*/ | |||||
int rte_flags; /* up/down?, host/net */ | |||||
int rt_refcnt; /* # held references */ | |||||
u_int rt_fibnum; /* which FIB */ | |||||
u_long rt_weight; /* absolute weight */ | |||||
u_long rt_expire; /* lifetime for route, e.g. redirect */ | |||||
#define rt_endzero rt_mtx | |||||
struct mtx rt_mtx; /* mutex for routing entry */ | |||||
struct rtentry *rt_chain; /* pointer to next rtentry to delete */ | |||||
struct epoch_context rt_epoch_ctx; /* net epoch tracker */ | |||||
}; | |||||
#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) | |||||
#define RT_IS_UP(_rt) ((_rt)->rte_flags & RTF_UP) | |||||
#define RT_IS_HOST_ROUTE(_rt) ((_rt)->rte_flags & RTF_HOST) | |||||
/* | |||||
* Convert a 'struct radix_node *' to a 'struct rtentry *'. | |||||
* The operation can be done safely (in this code) because a | |||||
* 'struct rtentry' starts with two 'struct radix_node''s, the first | |||||
* one representing leaf nodes in the routing tree, which is | |||||
* what the code in radix.c passes us as a 'struct radix_node'. | |||||
* | |||||
* But because there are a lot of assumptions in this conversion, | |||||
* do not cast explicitly, but always use the macro below. | |||||
*/ | |||||
#define RNTORT(p) ((struct rtentry *)(p)) | |||||
#endif /* _KERNEL */ | |||||
#endif |