netwerk/sctp/src/user_route.h

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rwxr-xr-x

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

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

mercurial