user_route.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. * 3. 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. #ifndef _USER_ROUTE_H_
  31. #define _USER_ROUTE_H_
  32. /*
  33. * Kernel resident routing tables.
  34. *
  35. * The routing tables are initialized when interface addresses
  36. * are set by making entries for all directly connected interfaces.
  37. */
  38. /*
  39. * A route consists of a destination address and a reference
  40. * to a routing entry. These are often held by protocols
  41. * in their control blocks, e.g. inpcb.
  42. */
  43. struct sctp_route {
  44. struct sctp_rtentry *ro_rt;
  45. struct sockaddr ro_dst;
  46. };
  47. /*
  48. * These numbers are used by reliable protocols for determining
  49. * retransmission behavior and are included in the routing structure.
  50. */
  51. struct sctp_rt_metrics_lite {
  52. uint32_t rmx_mtu; /* MTU for this path */
  53. #if 0
  54. u_long rmx_expire; /* lifetime for route, e.g. redirect */
  55. u_long rmx_pksent; /* packets sent using this route */
  56. #endif
  57. };
  58. /*
  59. * We distinguish between routes to hosts and routes to networks,
  60. * preferring the former if available. For each route we infer
  61. * the interface to use from the gateway address supplied when
  62. * the route was entered. Routes that forward packets through
  63. * gateways are marked so that the output routines know to address the
  64. * gateway rather than the ultimate destination.
  65. */
  66. struct sctp_rtentry {
  67. #if 0
  68. struct radix_node rt_nodes[2]; /* tree glue, and other values */
  69. /*
  70. * XXX struct rtentry must begin with a struct radix_node (or two!)
  71. * because the code does some casts of a 'struct radix_node *'
  72. * to a 'struct rtentry *'
  73. */
  74. #define rt_key(r) (*((struct sockaddr **)(&(r)->rt_nodes->rn_key)))
  75. #define rt_mask(r) (*((struct sockaddr **)(&(r)->rt_nodes->rn_mask)))
  76. struct sockaddr *rt_gateway; /* value */
  77. u_long rt_flags; /* up/down?, host/net */
  78. #endif
  79. struct ifnet *rt_ifp; /* the answer: interface to use */
  80. struct ifaddr *rt_ifa; /* the answer: interface address to use */
  81. struct sctp_rt_metrics_lite rt_rmx; /* metrics used by rx'ing protocols */
  82. long rt_refcnt; /* # held references */
  83. #if 0
  84. struct sockaddr *rt_genmask; /* for generation of cloned routes */
  85. caddr_t rt_llinfo; /* pointer to link level info cache */
  86. struct rtentry *rt_gwroute; /* implied entry for gatewayed routes */
  87. struct rtentry *rt_parent; /* cloning parent of this route */
  88. #endif
  89. struct mtx rt_mtx; /* mutex for routing entry */
  90. };
  91. #define RT_LOCK_INIT(_rt) mtx_init(&(_rt)->rt_mtx, "rtentry", NULL, MTX_DEF | MTX_DUPOK)
  92. #define RT_LOCK(_rt) mtx_lock(&(_rt)->rt_mtx)
  93. #define RT_UNLOCK(_rt) mtx_unlock(&(_rt)->rt_mtx)
  94. #define RT_LOCK_DESTROY(_rt) mtx_destroy(&(_rt)->rt_mtx)
  95. #define RT_LOCK_ASSERT(_rt) mtx_assert(&(_rt)->rt_mtx, MA_OWNED)
  96. #define RT_ADDREF(_rt) do { \
  97. RT_LOCK_ASSERT(_rt); \
  98. KASSERT((_rt)->rt_refcnt >= 0, \
  99. ("negative refcnt %ld", (_rt)->rt_refcnt)); \
  100. (_rt)->rt_refcnt++; \
  101. } while (0)
  102. #define RT_REMREF(_rt) do { \
  103. RT_LOCK_ASSERT(_rt); \
  104. KASSERT((_rt)->rt_refcnt > 0, \
  105. ("bogus refcnt %ld", (_rt)->rt_refcnt)); \
  106. (_rt)->rt_refcnt--; \
  107. } while (0)
  108. #define RTFREE_LOCKED(_rt) do { \
  109. if ((_rt)->rt_refcnt <= 1) { \
  110. rtfree(_rt); \
  111. } else { \
  112. RT_REMREF(_rt); \
  113. RT_UNLOCK(_rt); \
  114. } \
  115. /* guard against invalid refs */ \
  116. _rt = NULL; \
  117. } while (0)
  118. #define RTFREE(_rt) do { \
  119. RT_LOCK(_rt); \
  120. RTFREE_LOCKED(_rt); \
  121. } while (0)
  122. #endif