diff --git a/sys/fs/nfs/nfsport.h b/sys/fs/nfs/nfsport.h index 88c7a34ae3ff..a392cecdefb1 100644 --- a/sys/fs/nfs/nfsport.h +++ b/sys/fs/nfs/nfsport.h @@ -82,6 +82,7 @@ #include #include #include +#include #include #include #include diff --git a/sys/net/if.c b/sys/net/if.c index a7fb2a95feec..d603bc5d8f25 100644 --- a/sys/net/if.c +++ b/sys/net/if.c @@ -75,6 +75,7 @@ #include #include #include +#include #include #if defined(INET) || defined(INET6) diff --git a/sys/net/if_disc.c b/sys/net/if_disc.c index de36886fcae4..cfd284d9445e 100644 --- a/sys/net/if_disc.c +++ b/sys/net/if_disc.c @@ -49,6 +49,7 @@ #include #include #include +#include #include #include diff --git a/sys/net/if_faith.c b/sys/net/if_faith.c index 2aeb14adfdbb..37d19274eb7c 100644 --- a/sys/net/if_faith.c +++ b/sys/net/if_faith.c @@ -61,6 +61,7 @@ #include #include #include +#include #include #include diff --git a/sys/net/if_gre.c b/sys/net/if_gre.c index 9de63ccc1c03..e84b256c9a2a 100644 --- a/sys/net/if_gre.c +++ b/sys/net/if_gre.c @@ -65,6 +65,7 @@ #include #include #include +#include #include #ifdef INET diff --git a/sys/net/if_loop.c b/sys/net/if_loop.c index 6d2b9143dfb1..3ddbba695e17 100644 --- a/sys/net/if_loop.c +++ b/sys/net/if_loop.c @@ -54,6 +54,7 @@ #include #include #include +#include #include #include diff --git a/sys/net/if_stf.c b/sys/net/if_stf.c index 64812bfe0a3c..38da515d6382 100644 --- a/sys/net/if_stf.c +++ b/sys/net/if_stf.c @@ -97,6 +97,7 @@ #include #include #include +#include #include #include #include diff --git a/sys/net/radix_mpath.c b/sys/net/radix_mpath.c index 82c0adda0d76..12481c88b116 100644 --- a/sys/net/radix_mpath.c +++ b/sys/net/radix_mpath.c @@ -48,6 +48,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include diff --git a/sys/net/route.c b/sys/net/route.c index 38e610a841a3..7dc558a6a509 100644 --- a/sys/net/route.c +++ b/sys/net/route.c @@ -58,6 +58,7 @@ #include #include #include +#include #include #include diff --git a/sys/net/route.h b/sys/net/route.h index b9672b8cc42f..e427017d2e9a 100644 --- a/sys/net/route.h +++ b/sys/net/route.h @@ -107,7 +107,9 @@ VNET_DECLARE(u_int, rt_add_addr_allfibs); /* Announce interfaces to all fibs */ #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 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_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 */ +#define rt_endzero rt_mtx struct mtx rt_mtx; /* mutex for routing entry */ }; -#endif /* _KERNEL || _WANT_RTENTRY */ +#endif /* !_KERNEL || _WANT_RTENTRY */ #define RTF_UP 0x1 /* route usable */ #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) \ || (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 ifmultiaddr; diff --git a/sys/net/route_internal.h b/sys/net/route_internal.h new file mode 100644 index 000000000000..cd207fb48658 --- /dev/null +++ b/sys/net/route_internal.h @@ -0,0 +1,113 @@ +/*- + * Copyright (c) 2014 + * Alexander V. Chernikov + * + * 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 + + diff --git a/sys/net/rt_nhops.c b/sys/net/rt_nhops.c index a7998078ef39..10ce89c62789 100644 --- a/sys/net/rt_nhops.c +++ b/sys/net/rt_nhops.c @@ -55,6 +55,7 @@ #include #include #include +#include #include #ifdef RADIX_MPATH diff --git a/sys/net/rtsock.c b/sys/net/rtsock.c index 6fcbbc6ec431..9c2e96fa34f6 100644 --- a/sys/net/rtsock.c +++ b/sys/net/rtsock.c @@ -59,6 +59,7 @@ #include #include #include +#include #include #include diff --git a/sys/netgraph/netflow/netflow.c b/sys/netgraph/netflow/netflow.c index 7422fbd7745d..bcc16979bf88 100644 --- a/sys/netgraph/netflow/netflow.c +++ b/sys/netgraph/netflow/netflow.c @@ -45,6 +45,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include diff --git a/sys/netinet/if_ether.c b/sys/netinet/if_ether.c index e7b82db61575..23e756bfa306 100644 --- a/sys/netinet/if_ether.c +++ b/sys/netinet/if_ether.c @@ -59,6 +59,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include diff --git a/sys/netinet/in.c b/sys/netinet/in.c index 0a2b130d752d..f64b66273148 100644 --- a/sys/netinet/in.c +++ b/sys/netinet/in.c @@ -56,6 +56,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include diff --git a/sys/netinet/in_gif.c b/sys/netinet/in_gif.c index f039a97e012a..dab59a8948b5 100644 --- a/sys/netinet/in_gif.c +++ b/sys/netinet/in_gif.c @@ -50,6 +50,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include diff --git a/sys/netinet/in_rmx.c b/sys/netinet/in_rmx.c index 09669e67cfc3..8cbecd307a9c 100644 --- a/sys/netinet/in_rmx.c +++ b/sys/netinet/in_rmx.c @@ -42,6 +42,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include diff --git a/sys/netinet/sctp_os_bsd.h b/sys/netinet/sctp_os_bsd.h index 860de2879498..71f4b1ca34e3 100644 --- a/sys/netinet/sctp_os_bsd.h +++ b/sys/netinet/sctp_os_bsd.h @@ -71,6 +71,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include diff --git a/sys/netinet6/icmp6.c b/sys/netinet6/icmp6.c index ff23257558cd..9817f6adf355 100644 --- a/sys/netinet6/icmp6.c +++ b/sys/netinet6/icmp6.c @@ -90,6 +90,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include diff --git a/sys/netinet6/in6.c b/sys/netinet6/in6.c index c816e44abfa2..3cdc76f9367b 100644 --- a/sys/netinet6/in6.c +++ b/sys/netinet6/in6.c @@ -86,6 +86,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include diff --git a/sys/netinet6/in6_gif.c b/sys/netinet6/in6_gif.c index 6dcc08129c91..43671b793916 100644 --- a/sys/netinet6/in6_gif.c +++ b/sys/netinet6/in6_gif.c @@ -51,6 +51,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include diff --git a/sys/netinet6/in6_ifattach.c b/sys/netinet6/in6_ifattach.c index 6eb737e813a1..495d8179023f 100644 --- a/sys/netinet6/in6_ifattach.c +++ b/sys/netinet6/in6_ifattach.c @@ -48,6 +48,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include diff --git a/sys/netinet6/in6_rmx.c b/sys/netinet6/in6_rmx.c index c1caf2c721d6..efe3b552019c 100644 --- a/sys/netinet6/in6_rmx.c +++ b/sys/netinet6/in6_rmx.c @@ -78,6 +78,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include diff --git a/sys/netinet6/ip6_forward.c b/sys/netinet6/ip6_forward.c index 1b1b9d058b3a..d462c3403ead 100644 --- a/sys/netinet6/ip6_forward.c +++ b/sys/netinet6/ip6_forward.c @@ -54,6 +54,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include diff --git a/sys/netinet6/ip6_input.c b/sys/netinet6/ip6_input.c index 1f89bd05ffa2..f985108f2112 100644 --- a/sys/netinet6/ip6_input.c +++ b/sys/netinet6/ip6_input.c @@ -89,6 +89,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include diff --git a/sys/netinet6/nd6.c b/sys/netinet6/nd6.c index e48cb8a7e5f5..5e7ceca1929e 100644 --- a/sys/netinet6/nd6.c +++ b/sys/netinet6/nd6.c @@ -61,6 +61,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include diff --git a/sys/netinet6/nd6_nbr.c b/sys/netinet6/nd6_nbr.c index 7c5018e3d538..5b8ec334f0bc 100644 --- a/sys/netinet6/nd6_nbr.c +++ b/sys/netinet6/nd6_nbr.c @@ -57,6 +57,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #ifdef RADIX_MPATH #include #endif diff --git a/sys/netinet6/nd6_rtr.c b/sys/netinet6/nd6_rtr.c index 19c5f8d53474..b82faf55bce1 100644 --- a/sys/netinet6/nd6_rtr.c +++ b/sys/netinet6/nd6_rtr.c @@ -54,6 +54,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include diff --git a/sys/netpfil/ipfw/ip_fw_table_algo.c b/sys/netpfil/ipfw/ip_fw_table_algo.c index ec2d472fea69..2387537d1f35 100644 --- a/sys/netpfil/ipfw/ip_fw_table_algo.c +++ b/sys/netpfil/ipfw/ip_fw_table_algo.c @@ -51,6 +51,7 @@ __FBSDID("$FreeBSD$"); #include /* ip_fw.h requires IFNAMSIZ */ #include #include +#include #include #include /* struct ipfw_rule_ref */