1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/netwerk/sctp/src/user_route.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,130 @@ 1.4 +/*- 1.5 + * Copyright (c) 1980, 1986, 1993 1.6 + * The Regents of the University of California. All rights reserved. 1.7 + * 1.8 + * Redistribution and use in source and binary forms, with or without 1.9 + * modification, are permitted provided that the following conditions 1.10 + * are met: 1.11 + * 1. Redistributions of source code must retain the above copyright 1.12 + * notice, this list of conditions and the following disclaimer. 1.13 + * 2. Redistributions in binary form must reproduce the above copyright 1.14 + * notice, this list of conditions and the following disclaimer in the 1.15 + * documentation and/or other materials provided with the distribution. 1.16 + * 4. Neither the name of the University nor the names of its contributors 1.17 + * may be used to endorse or promote products derived from this software 1.18 + * without specific prior written permission. 1.19 + * 1.20 + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 1.21 + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1.22 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1.23 + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 1.24 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1.25 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 1.26 + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 1.27 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 1.28 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 1.29 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 1.30 + * SUCH DAMAGE. 1.31 + * 1.32 + */ 1.33 + 1.34 +#ifndef _USER_ROUTE_H_ 1.35 +#define _USER_ROUTE_H_ 1.36 + 1.37 +/* 1.38 + * Kernel resident routing tables. 1.39 + * 1.40 + * The routing tables are initialized when interface addresses 1.41 + * are set by making entries for all directly connected interfaces. 1.42 + */ 1.43 + 1.44 +/* 1.45 + * A route consists of a destination address and a reference 1.46 + * to a routing entry. These are often held by protocols 1.47 + * in their control blocks, e.g. inpcb. 1.48 + */ 1.49 + 1.50 +struct sctp_route { 1.51 + struct sctp_rtentry *ro_rt; 1.52 + struct sockaddr ro_dst; 1.53 +}; 1.54 + 1.55 +/* 1.56 + * These numbers are used by reliable protocols for determining 1.57 + * retransmission behavior and are included in the routing structure. 1.58 + */ 1.59 +struct sctp_rt_metrics_lite { 1.60 + u_long rmx_mtu; /* MTU for this path */ 1.61 +#if 0 1.62 + u_long rmx_expire; /* lifetime for route, e.g. redirect */ 1.63 + u_long rmx_pksent; /* packets sent using this route */ 1.64 +#endif 1.65 +}; 1.66 + 1.67 +/* 1.68 + * We distinguish between routes to hosts and routes to networks, 1.69 + * preferring the former if available. For each route we infer 1.70 + * the interface to use from the gateway address supplied when 1.71 + * the route was entered. Routes that forward packets through 1.72 + * gateways are marked so that the output routines know to address the 1.73 + * gateway rather than the ultimate destination. 1.74 + */ 1.75 +struct sctp_rtentry { 1.76 +#if 0 1.77 + struct radix_node rt_nodes[2]; /* tree glue, and other values */ 1.78 + /* 1.79 + * XXX struct rtentry must begin with a struct radix_node (or two!) 1.80 + * because the code does some casts of a 'struct radix_node *' 1.81 + * to a 'struct rtentry *' 1.82 + */ 1.83 +#define rt_key(r) (*((struct sockaddr **)(&(r)->rt_nodes->rn_key))) 1.84 +#define rt_mask(r) (*((struct sockaddr **)(&(r)->rt_nodes->rn_mask))) 1.85 + struct sockaddr *rt_gateway; /* value */ 1.86 + u_long rt_flags; /* up/down?, host/net */ 1.87 +#endif 1.88 + struct ifnet *rt_ifp; /* the answer: interface to use */ 1.89 + struct ifaddr *rt_ifa; /* the answer: interface address to use */ 1.90 + struct sctp_rt_metrics_lite rt_rmx; /* metrics used by rx'ing protocols */ 1.91 + long rt_refcnt; /* # held references */ 1.92 +#if 0 1.93 + struct sockaddr *rt_genmask; /* for generation of cloned routes */ 1.94 + caddr_t rt_llinfo; /* pointer to link level info cache */ 1.95 + struct rtentry *rt_gwroute; /* implied entry for gatewayed routes */ 1.96 + struct rtentry *rt_parent; /* cloning parent of this route */ 1.97 +#endif 1.98 + struct mtx rt_mtx; /* mutex for routing entry */ 1.99 +}; 1.100 + 1.101 +#define RT_LOCK_INIT(_rt) mtx_init(&(_rt)->rt_mtx, "rtentry", NULL, MTX_DEF | MTX_DUPOK) 1.102 +#define RT_LOCK(_rt) mtx_lock(&(_rt)->rt_mtx) 1.103 +#define RT_UNLOCK(_rt) mtx_unlock(&(_rt)->rt_mtx) 1.104 +#define RT_LOCK_DESTROY(_rt) mtx_destroy(&(_rt)->rt_mtx) 1.105 +#define RT_LOCK_ASSERT(_rt) mtx_assert(&(_rt)->rt_mtx, MA_OWNED) 1.106 + 1.107 +#define RT_ADDREF(_rt) do { \ 1.108 + RT_LOCK_ASSERT(_rt); \ 1.109 + KASSERT((_rt)->rt_refcnt >= 0, \ 1.110 + ("negative refcnt %ld", (_rt)->rt_refcnt)); \ 1.111 + (_rt)->rt_refcnt++; \ 1.112 +} while (0) 1.113 +#define RT_REMREF(_rt) do { \ 1.114 + RT_LOCK_ASSERT(_rt); \ 1.115 + KASSERT((_rt)->rt_refcnt > 0, \ 1.116 + ("bogus refcnt %ld", (_rt)->rt_refcnt)); \ 1.117 + (_rt)->rt_refcnt--; \ 1.118 +} while (0) 1.119 +#define RTFREE_LOCKED(_rt) do { \ 1.120 + if ((_rt)->rt_refcnt <= 1) { \ 1.121 + rtfree(_rt); \ 1.122 + } else { \ 1.123 + RT_REMREF(_rt); \ 1.124 + RT_UNLOCK(_rt); \ 1.125 + } \ 1.126 + /* guard against invalid refs */ \ 1.127 + _rt = NULL; \ 1.128 + } while (0) 1.129 +#define RTFREE(_rt) do { \ 1.130 + RT_LOCK(_rt); \ 1.131 + RTFREE_LOCKED(_rt); \ 1.132 +} while (0) 1.133 +#endif