Hide 'struct rtentry' and all its macro inside new header:

net/route_internal.h
The goal is to make its opaque for all code except route/rtsock and
proto domain _rmx.
This commit is contained in:
Alexander V. Chernikov 2014-11-04 17:28:13 +00:00
parent a9ac00b76b
commit 8c3cfe0be0
30 changed files with 146 additions and 57 deletions

View File

@ -82,6 +82,7 @@
#include <net/if_var.h> #include <net/if_var.h>
#include <net/radix.h> #include <net/radix.h>
#include <net/route.h> #include <net/route.h>
#include <net/route_internal.h>
#include <net/if_dl.h> #include <net/if_dl.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <netinet/in_pcb.h> #include <netinet/in_pcb.h>

View File

@ -75,6 +75,7 @@
#include <net/if_vlan_var.h> #include <net/if_vlan_var.h>
#include <net/radix.h> #include <net/radix.h>
#include <net/route.h> #include <net/route.h>
#include <net/route_internal.h>
#include <net/vnet.h> #include <net/vnet.h>
#if defined(INET) || defined(INET6) #if defined(INET) || defined(INET6)

View File

@ -49,6 +49,7 @@
#include <net/if_clone.h> #include <net/if_clone.h>
#include <net/if_types.h> #include <net/if_types.h>
#include <net/route.h> #include <net/route.h>
#include <net/route_internal.h>
#include <net/bpf.h> #include <net/bpf.h>
#include <net/vnet.h> #include <net/vnet.h>

View File

@ -61,6 +61,7 @@
#include <net/if_types.h> #include <net/if_types.h>
#include <net/netisr.h> #include <net/netisr.h>
#include <net/route.h> #include <net/route.h>
#include <net/route_internal.h>
#include <net/bpf.h> #include <net/bpf.h>
#include <net/vnet.h> #include <net/vnet.h>

View File

@ -65,6 +65,7 @@
#include <net/if_clone.h> #include <net/if_clone.h>
#include <net/if_types.h> #include <net/if_types.h>
#include <net/route.h> #include <net/route.h>
#include <net/route_internal.h>
#include <net/vnet.h> #include <net/vnet.h>
#ifdef INET #ifdef INET

View File

@ -54,6 +54,7 @@
#include <net/if_types.h> #include <net/if_types.h>
#include <net/netisr.h> #include <net/netisr.h>
#include <net/route.h> #include <net/route.h>
#include <net/route_internal.h>
#include <net/bpf.h> #include <net/bpf.h>
#include <net/vnet.h> #include <net/vnet.h>

View File

@ -97,6 +97,7 @@
#include <net/if_var.h> #include <net/if_var.h>
#include <net/if_clone.h> #include <net/if_clone.h>
#include <net/route.h> #include <net/route.h>
#include <net/route_internal.h>
#include <net/netisr.h> #include <net/netisr.h>
#include <net/if_types.h> #include <net/if_types.h>
#include <net/if_stf.h> #include <net/if_stf.h>

View File

@ -48,6 +48,7 @@ __FBSDID("$FreeBSD$");
#include <net/radix.h> #include <net/radix.h>
#include <net/radix_mpath.h> #include <net/radix_mpath.h>
#include <net/route.h> #include <net/route.h>
#include <net/route_internal.h>
#include <net/if.h> #include <net/if.h>
#include <net/if_var.h> #include <net/if_var.h>

View File

@ -58,6 +58,7 @@
#include <net/if_var.h> #include <net/if_var.h>
#include <net/if_dl.h> #include <net/if_dl.h>
#include <net/route.h> #include <net/route.h>
#include <net/route_internal.h>
#include <net/vnet.h> #include <net/vnet.h>
#include <net/flowtable.h> #include <net/flowtable.h>

View File

@ -107,7 +107,9 @@ VNET_DECLARE(u_int, rt_add_addr_allfibs); /* Announce interfaces to all fibs */
#endif #endif
#endif #endif
#if defined(_KERNEL) || defined(_WANT_RTENTRY) struct rtentry;
#if !defined(_KERNEL) || defined(_WANT_RTENTRY)
/* This structure is kept for compatibility reasons only */
struct rtentry { struct rtentry {
struct radix_node rt_nodes[2]; /* tree glue, and other values */ struct radix_node rt_nodes[2]; /* tree glue, and other values */
/* /*
@ -126,11 +128,10 @@ struct rtentry {
u_long rt_mtu; /* MTU for this path */ u_long rt_mtu; /* MTU for this path */
u_long rt_weight; /* absolute weight */ u_long rt_weight; /* absolute weight */
u_long rt_expire; /* lifetime for route, e.g. redirect */ u_long rt_expire; /* lifetime for route, e.g. redirect */
#define rt_endzero rt_pksent #define rt_endzero rt_mtx
counter_u64_t rt_pksent; /* packets sent using this route */
struct mtx rt_mtx; /* mutex for routing entry */ struct mtx rt_mtx; /* mutex for routing entry */
}; };
#endif /* _KERNEL || _WANT_RTENTRY */ #endif /* !_KERNEL || _WANT_RTENTRY */
#define RTF_UP 0x1 /* route usable */ #define RTF_UP 0x1 /* route usable */
#define RTF_GATEWAY 0x2 /* destination is a gateway */ #define RTF_GATEWAY 0x2 /* destination is a gateway */
@ -291,59 +292,6 @@ struct rt_addrinfo {
#define RT_LINK_IS_UP(ifp) (!((ifp)->if_capabilities & IFCAP_LINKSTATE) \ #define RT_LINK_IS_UP(ifp) (!((ifp)->if_capabilities & IFCAP_LINKSTATE) \
|| (ifp)->if_link_state == LINK_STATE_UP) || (ifp)->if_link_state == LINK_STATE_UP)
#define RT_LOCK_INIT(_rt) \
mtx_init(&(_rt)->rt_mtx, "rtentry", NULL, MTX_DEF | MTX_DUPOK)
#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 RO_RTFREE(_ro) do { \
if ((_ro)->ro_rt) { \
if ((_ro)->ro_flags & RT_NORTREF) { \
(_ro)->ro_flags &= ~RT_NORTREF; \
(_ro)->ro_rt = NULL; \
} else { \
RT_LOCK((_ro)->ro_rt); \
RTFREE_LOCKED((_ro)->ro_rt); \
} \
} \
} while (0)
struct radix_node_head *rt_tables_get_rnh(int, int); struct radix_node_head *rt_tables_get_rnh(int, int);
struct ifmultiaddr; struct ifmultiaddr;

113
sys/net/route_internal.h Normal file
View File

@ -0,0 +1,113 @@
/*-
* Copyright (c) 2014
* 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.
*/
#ifndef _NET_ROUTE_INTERNAL_H_
#define _NET_ROUTE_INTERNAL_H_
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)))
struct sockaddr *rt_gateway; /* value */
struct ifnet *rt_ifp; /* the answer: interface to use */
struct ifaddr *rt_ifa; /* the answer: interface address to use */
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 */
};
#define RT_LOCK_INIT(_rt) \
mtx_init(&(_rt)->rt_mtx, "rtentry", NULL, MTX_DEF | MTX_DUPOK)
#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 RO_RTFREE(_ro) do { \
if ((_ro)->ro_rt) { \
if ((_ro)->ro_flags & RT_NORTREF) { \
(_ro)->ro_flags &= ~RT_NORTREF; \
(_ro)->ro_rt = NULL; \
} else { \
RT_LOCK((_ro)->ro_rt); \
RTFREE_LOCKED((_ro)->ro_rt); \
} \
} \
} while (0)
#endif

View File

@ -55,6 +55,7 @@
#include <net/if_var.h> #include <net/if_var.h>
#include <net/if_dl.h> #include <net/if_dl.h>
#include <net/route.h> #include <net/route.h>
#include <net/route_internal.h>
#include <net/vnet.h> #include <net/vnet.h>
#ifdef RADIX_MPATH #ifdef RADIX_MPATH

View File

@ -59,6 +59,7 @@
#include <net/netisr.h> #include <net/netisr.h>
#include <net/raw_cb.h> #include <net/raw_cb.h>
#include <net/route.h> #include <net/route.h>
#include <net/route_internal.h>
#include <net/vnet.h> #include <net/vnet.h>
#include <netinet/in.h> #include <netinet/in.h>

View File

@ -45,6 +45,7 @@ __FBSDID("$FreeBSD$");
#include <net/if.h> #include <net/if.h>
#include <net/if_var.h> #include <net/if_var.h>
#include <net/route.h> #include <net/route.h>
#include <net/route_internal.h>
#include <net/ethernet.h> #include <net/ethernet.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <netinet/in_systm.h> #include <netinet/in_systm.h>

View File

@ -59,6 +59,7 @@ __FBSDID("$FreeBSD$");
#include <net/if_llc.h> #include <net/if_llc.h>
#include <net/ethernet.h> #include <net/ethernet.h>
#include <net/route.h> #include <net/route.h>
#include <net/route_internal.h>
#include <net/vnet.h> #include <net/vnet.h>
#include <netinet/in.h> #include <netinet/in.h>

View File

@ -56,6 +56,7 @@ __FBSDID("$FreeBSD$");
#include <net/if_llatbl.h> #include <net/if_llatbl.h>
#include <net/if_types.h> #include <net/if_types.h>
#include <net/route.h> #include <net/route.h>
#include <net/route_internal.h>
#include <net/vnet.h> #include <net/vnet.h>
#include <netinet/if_ether.h> #include <netinet/if_ether.h>

View File

@ -50,6 +50,7 @@ __FBSDID("$FreeBSD$");
#include <net/if.h> #include <net/if.h>
#include <net/if_var.h> #include <net/if_var.h>
#include <net/route.h> #include <net/route.h>
#include <net/route_internal.h>
#include <net/vnet.h> #include <net/vnet.h>
#include <netinet/in.h> #include <netinet/in.h>

View File

@ -42,6 +42,7 @@ __FBSDID("$FreeBSD$");
#include <net/if.h> #include <net/if.h>
#include <net/if_var.h> #include <net/if_var.h>
#include <net/route.h> #include <net/route.h>
#include <net/route_internal.h>
#include <net/vnet.h> #include <net/vnet.h>
#include <netinet/in.h> #include <netinet/in.h>

View File

@ -71,6 +71,7 @@ __FBSDID("$FreeBSD$");
#include <net/if_types.h> #include <net/if_types.h>
#include <net/if_var.h> #include <net/if_var.h>
#include <net/route.h> #include <net/route.h>
#include <net/route_internal.h>
#include <net/vnet.h> #include <net/vnet.h>
#include <netinet/in.h> #include <netinet/in.h>

View File

@ -90,6 +90,7 @@ __FBSDID("$FreeBSD$");
#include <net/if_llatbl.h> #include <net/if_llatbl.h>
#include <net/if_types.h> #include <net/if_types.h>
#include <net/route.h> #include <net/route.h>
#include <net/route_internal.h>
#include <net/vnet.h> #include <net/vnet.h>
#include <netinet/in.h> #include <netinet/in.h>

View File

@ -86,6 +86,7 @@ __FBSDID("$FreeBSD$");
#include <net/if_var.h> #include <net/if_var.h>
#include <net/if_types.h> #include <net/if_types.h>
#include <net/route.h> #include <net/route.h>
#include <net/route_internal.h>
#include <net/if_dl.h> #include <net/if_dl.h>
#include <net/vnet.h> #include <net/vnet.h>

View File

@ -51,6 +51,7 @@ __FBSDID("$FreeBSD$");
#include <net/if.h> #include <net/if.h>
#include <net/if_var.h> #include <net/if_var.h>
#include <net/route.h> #include <net/route.h>
#include <net/route_internal.h>
#include <net/vnet.h> #include <net/vnet.h>
#include <netinet/in.h> #include <netinet/in.h>

View File

@ -48,6 +48,7 @@ __FBSDID("$FreeBSD$");
#include <net/if_dl.h> #include <net/if_dl.h>
#include <net/if_types.h> #include <net/if_types.h>
#include <net/route.h> #include <net/route.h>
#include <net/route_internal.h>
#include <net/vnet.h> #include <net/vnet.h>
#include <netinet/in.h> #include <netinet/in.h>

View File

@ -78,6 +78,7 @@ __FBSDID("$FreeBSD$");
#include <net/if.h> #include <net/if.h>
#include <net/if_var.h> #include <net/if_var.h>
#include <net/route.h> #include <net/route.h>
#include <net/route_internal.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <netinet/ip_var.h> #include <netinet/ip_var.h>

View File

@ -54,6 +54,7 @@ __FBSDID("$FreeBSD$");
#include <net/if_var.h> #include <net/if_var.h>
#include <net/netisr.h> #include <net/netisr.h>
#include <net/route.h> #include <net/route.h>
#include <net/route_internal.h>
#include <net/pfil.h> #include <net/pfil.h>
#include <netinet/in.h> #include <netinet/in.h>

View File

@ -89,6 +89,7 @@ __FBSDID("$FreeBSD$");
#include <net/if_types.h> #include <net/if_types.h>
#include <net/if_dl.h> #include <net/if_dl.h>
#include <net/route.h> #include <net/route.h>
#include <net/route_internal.h>
#include <net/netisr.h> #include <net/netisr.h>
#include <net/pfil.h> #include <net/pfil.h>
#include <net/vnet.h> #include <net/vnet.h>

View File

@ -61,6 +61,7 @@ __FBSDID("$FreeBSD$");
#include <net/iso88025.h> #include <net/iso88025.h>
#include <net/fddi.h> #include <net/fddi.h>
#include <net/route.h> #include <net/route.h>
#include <net/route_internal.h>
#include <net/vnet.h> #include <net/vnet.h>
#include <netinet/in.h> #include <netinet/in.h>

View File

@ -57,6 +57,7 @@ __FBSDID("$FreeBSD$");
#include <net/if_dl.h> #include <net/if_dl.h>
#include <net/if_var.h> #include <net/if_var.h>
#include <net/route.h> #include <net/route.h>
#include <net/route_internal.h>
#ifdef RADIX_MPATH #ifdef RADIX_MPATH
#include <net/radix_mpath.h> #include <net/radix_mpath.h>
#endif #endif

View File

@ -54,6 +54,7 @@ __FBSDID("$FreeBSD$");
#include <net/if_types.h> #include <net/if_types.h>
#include <net/if_dl.h> #include <net/if_dl.h>
#include <net/route.h> #include <net/route.h>
#include <net/route_internal.h>
#include <net/radix.h> #include <net/radix.h>
#include <net/vnet.h> #include <net/vnet.h>

View File

@ -51,6 +51,7 @@ __FBSDID("$FreeBSD$");
#include <net/if.h> /* ip_fw.h requires IFNAMSIZ */ #include <net/if.h> /* ip_fw.h requires IFNAMSIZ */
#include <net/radix.h> #include <net/radix.h>
#include <net/route.h> #include <net/route.h>
#include <net/route_internal.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <netinet/ip_var.h> /* struct ipfw_rule_ref */ #include <netinet/ip_var.h> /* struct ipfw_rule_ref */