webkit  2cdf99a9e3038c7e01b3c37e8ad903ecbe5eecf1
https://github.com/WebKit/webkit
user_route.h
Go to the documentation of this file.
1 /*-
2  * Copyright (c) 1980, 1986, 1993
3  * The Regents of the University of California. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * 4. Neither the name of the University nor the names of its contributors
14  * may be used to endorse or promote products derived from this software
15  * without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  */
30 
31 #ifndef _USER_ROUTE_H_
32 #define _USER_ROUTE_H_
33 
34 /*
35  * Kernel resident routing tables.
36  *
37  * The routing tables are initialized when interface addresses
38  * are set by making entries for all directly connected interfaces.
39  */
40 
41 /*
42  * A route consists of a destination address and a reference
43  * to a routing entry. These are often held by protocols
44  * in their control blocks, e.g. inpcb.
45  */
46 
47 struct sctp_route {
49  struct sockaddr ro_dst;
50 };
51 
52 /*
53  * These numbers are used by reliable protocols for determining
54  * retransmission behavior and are included in the routing structure.
55  */
57  uint32_t rmx_mtu; /* MTU for this path */
58 #if 0
59  u_long rmx_expire; /* lifetime for route, e.g. redirect */
60  u_long rmx_pksent; /* packets sent using this route */
61 #endif
62 };
63 
64 /*
65  * We distinguish between routes to hosts and routes to networks,
66  * preferring the former if available. For each route we infer
67  * the interface to use from the gateway address supplied when
68  * the route was entered. Routes that forward packets through
69  * gateways are marked so that the output routines know to address the
70  * gateway rather than the ultimate destination.
71  */
72 struct sctp_rtentry {
73 #if 0
74  struct radix_node rt_nodes[2]; /* tree glue, and other values */
75  /*
76  * XXX struct rtentry must begin with a struct radix_node (or two!)
77  * because the code does some casts of a 'struct radix_node *'
78  * to a 'struct rtentry *'
79  */
80 #define rt_key(r) (*((struct sockaddr **)(&(r)->rt_nodes->rn_key)))
81 #define rt_mask(r) (*((struct sockaddr **)(&(r)->rt_nodes->rn_mask)))
82  struct sockaddr *rt_gateway; /* value */
83  u_long rt_flags; /* up/down?, host/net */
84 #endif
85  struct ifnet *rt_ifp; /* the answer: interface to use */
86  struct ifaddr *rt_ifa; /* the answer: interface address to use */
87  struct sctp_rt_metrics_lite rt_rmx; /* metrics used by rx'ing protocols */
88  long rt_refcnt; /* # held references */
89 #if 0
90  struct sockaddr *rt_genmask; /* for generation of cloned routes */
91  caddr_t rt_llinfo; /* pointer to link level info cache */
92  struct rtentry *rt_gwroute; /* implied entry for gatewayed routes */
93  struct rtentry *rt_parent; /* cloning parent of this route */
94 #endif
95  struct mtx rt_mtx; /* mutex for routing entry */
96 };
97 
98 #define RT_LOCK_INIT(_rt) mtx_init(&(_rt)->rt_mtx, "rtentry", NULL, MTX_DEF | MTX_DUPOK)
99 #define RT_LOCK(_rt) mtx_lock(&(_rt)->rt_mtx)
100 #define RT_UNLOCK(_rt) mtx_unlock(&(_rt)->rt_mtx)
101 #define RT_LOCK_DESTROY(_rt) mtx_destroy(&(_rt)->rt_mtx)
102 #define RT_LOCK_ASSERT(_rt) mtx_assert(&(_rt)->rt_mtx, MA_OWNED)
103 
104 #define RT_ADDREF(_rt) do { \
105  RT_LOCK_ASSERT(_rt); \
106  KASSERT((_rt)->rt_refcnt >= 0, \
107  ("negative refcnt %ld", (_rt)->rt_refcnt)); \
108  (_rt)->rt_refcnt++; \
109 } while (0)
110 #define RT_REMREF(_rt) do { \
111  RT_LOCK_ASSERT(_rt); \
112  KASSERT((_rt)->rt_refcnt > 0, \
113  ("bogus refcnt %ld", (_rt)->rt_refcnt)); \
114  (_rt)->rt_refcnt--; \
115 } while (0)
116 #define RTFREE_LOCKED(_rt) do { \
117  if ((_rt)->rt_refcnt <= 1) { \
118  rtfree(_rt); \
119  } else { \
120  RT_REMREF(_rt); \
121  RT_UNLOCK(_rt); \
122  } \
123  /* guard against invalid refs */ \
124  _rt = NULL; \
125  } while (0)
126 #define RTFREE(_rt) do { \
127  RT_LOCK(_rt); \
128  RTFREE_LOCKED(_rt); \
129 } while (0)
130 #endif
struct sctp_rtentry * ro_rt
Definition: user_route.h:48
struct ifaddr * rt_ifa
Definition: user_route.h:86
unsigned int uint32_t
Definition: ptypes.h:105
Definition: user_route.h:47
Definition: user_route.h:72
Definition: user_route.h:56
uint32_t rmx_mtu
Definition: user_route.h:57
long rt_refcnt
Definition: user_route.h:88
struct sockaddr ro_dst
Definition: user_route.h:49
struct ifnet * rt_ifp
Definition: user_route.h:85
Definition: sctp_os_userspace.h:427