ip6_mroute.h 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. /* $OpenBSD: ip6_mroute.h,v 1.16 2015/06/08 22:19:28 krw Exp $ */
  2. /* $KAME: ip6_mroute.h,v 1.17 2001/02/10 02:05:52 itojun Exp $ */
  3. /*
  4. * Copyright (C) 1998 WIDE Project.
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. * 3. Neither the name of the project nor the names of its contributors
  16. * may be used to endorse or promote products derived from this software
  17. * without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
  20. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  21. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  22. * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
  23. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  24. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  25. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  26. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  27. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  28. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  29. * SUCH DAMAGE.
  30. */
  31. /*
  32. * Definitions for IP multicast forwarding.
  33. *
  34. * Written by David Waitzman, BBN Labs, August 1988.
  35. * Modified by Steve Deering, Stanford, February 1989.
  36. * Modified by Ajit Thyagarajan, PARC, August 1993.
  37. * Modified by Ajit Thyagarajan, PARC, August 1994.
  38. * Modified by Ahmed Helmy, USC, September 1996.
  39. *
  40. * MROUTING Revision: 1.2
  41. */
  42. #ifndef _NETINET6_IP6_MROUTE_H_
  43. #define _NETINET6_IP6_MROUTE_H_
  44. /*
  45. * Multicast Routing set/getsockopt commands.
  46. */
  47. #define MRT6_DONE 101 /* shut down forwarder */
  48. #define MRT6_ADD_MIF 102 /* add multicast interface */
  49. #define MRT6_DEL_MIF 103 /* delete multicast interface */
  50. #define MRT6_ADD_MFC 104 /* insert forwarding cache entry */
  51. #define MRT6_DEL_MFC 105 /* delete forwarding cache entry */
  52. #define MRT6_PIM 107 /* enable pim code */
  53. #define MRT6_INIT 108 /* initialize forwarder (mrt6msg) */
  54. /*
  55. * Types and macros for handling bitmaps with one bit per multicast interface.
  56. */
  57. typedef u_short mifi_t; /* type of a mif index */
  58. #define MAXMIFS 64
  59. /*
  60. * Assume inclusion of sys/param.h or sys/select.h for howmany()
  61. */
  62. #define __NIFBITS (sizeof(uint32_t) * 8) /* bits per mask */
  63. typedef struct if_set {
  64. uint32_t ifs_bits[howmany(256, __NIFBITS)];
  65. } if_set;
  66. #define IF_SET(n, p) \
  67. ((p)->ifs_bits[(n)/__NIFBITS] |= (1U << ((n) % __NIFBITS)))
  68. #define IF_CLR(n, p) \
  69. ((p)->ifs_bits[(n)/__NIFBITS] &= ~(1U << ((n) % __NIFBITS)))
  70. #define IF_ISSET(n, p) \
  71. ((p)->ifs_bits[(n)/__NIFBITS] & (1U << ((n) % __NIFBITS)))
  72. #define IF_COPY(f, t) memcpy(t, f, sizeof(*(f)))
  73. #define IF_ZERO(p) memset(p, 0, sizeof(*(p)))
  74. /*
  75. * Argument structure for MRT6_ADD_IF.
  76. */
  77. struct mif6ctl {
  78. mifi_t mif6c_mifi; /* the index of the mif to be added */
  79. u_char mif6c_flags; /* MIFF_ flags defined below */
  80. u_short mif6c_pifi; /* the index of the physical IF */
  81. #ifdef notyet
  82. u_int mif6c_rate_limit; /* max rate */
  83. #endif
  84. };
  85. #define MIFF_REGISTER 0x1 /* mif represents a register end-point */
  86. #define MF6C_INCOMPLETE_PARENT ((mifi_t)-1)
  87. /*
  88. * Argument structure for MRT6_ADD_MFC and MRT6_DEL_MFC
  89. */
  90. struct mf6cctl {
  91. struct sockaddr_in6 mf6cc_origin; /* IPv6 origin of mcasts */
  92. struct sockaddr_in6 mf6cc_mcastgrp; /* multicast group associated */
  93. mifi_t mf6cc_parent; /* incoming ifindex */
  94. struct if_set mf6cc_ifset; /* set of forwarding ifs */
  95. };
  96. /* structure used to get all the mif entries via sysctl */
  97. struct mif6info {
  98. struct in6_addr m6_lcl_addr; /* local interface address */
  99. u_int16_t m6_ifindex; /* interface index */
  100. u_int64_t m6_pkt_in; /* # pkts in on interface */
  101. u_int64_t m6_pkt_out; /* # pkts out on interface */
  102. u_int64_t m6_bytes_in; /* # bytes in on interface */
  103. u_int64_t m6_bytes_out; /* # bytes out on interface */
  104. u_int m6_rate_limit; /* max rate */
  105. mifi_t m6_mifi;
  106. u_char m6_flags; /* MIFF_ flags defined above */
  107. };
  108. /* structure used to get all the mf6c entries via sysctl */
  109. struct mf6cinfo {
  110. struct sockaddr_in6 mf6c_origin; /* IPv6 origin of mcasts */
  111. struct sockaddr_in6 mf6c_mcastgrp; /* multicast group associated*/
  112. mifi_t mf6c_parent; /* incoming IF */
  113. struct if_set mf6c_ifset; /* set of outgoing IFs */
  114. u_int64_t mf6c_pkt_cnt; /* pkt count for src-grp */
  115. u_int64_t mf6c_byte_cnt; /* byte count for src-grp */
  116. u_int64_t mf6c_stall_cnt; /* pkt-cnt waiting for route */
  117. };
  118. /*
  119. * The kernel's multicast routing statistics.
  120. */
  121. struct mrt6stat {
  122. u_int64_t mrt6s_mfc_lookups; /* # forw. cache hash table hits */
  123. u_int64_t mrt6s_mfc_misses; /* # forw. cache hash table misses */
  124. u_int64_t mrt6s_upcalls; /* # calls to mrouted */
  125. u_int64_t mrt6s_no_route; /* no route for packet's origin */
  126. u_int64_t mrt6s_bad_tunnel; /* malformed tunnel options */
  127. u_int64_t mrt6s_cant_tunnel; /* no room for tunnel options */
  128. u_int64_t mrt6s_wrong_if; /* arrived on wrong interface */
  129. u_int64_t mrt6s_upq_ovflw; /* upcall Q overflow */
  130. u_int64_t mrt6s_cache_cleanups; /* # entries with no upcalls */
  131. u_int64_t mrt6s_drop_sel; /* pkts dropped selectively */
  132. u_int64_t mrt6s_q_overflow; /* pkts dropped - Q overflow */
  133. u_int64_t mrt6s_pkt2large; /* pkts dropped - size > BKT SIZE */
  134. u_int64_t mrt6s_upq_sockfull; /* upcalls dropped - socket full */
  135. };
  136. /*
  137. * Structure used to communicate from kernel to multicast router.
  138. * We'll overlay the structure onto an MLD header (not an IPv6 header
  139. * like igmpmsg{} used for IPv4 implementation). This is because this
  140. * structure will be passed via an IPv6 raw socket, on which an application
  141. * will only receive the payload i.e. the data after the IPv6 header and all
  142. * the extension headers. (see Section 3 of draft-ietf-ipngwg-2292bis-01)
  143. */
  144. struct mrt6msg {
  145. #define MRT6MSG_NOCACHE 1
  146. #define MRT6MSG_WRONGMIF 2
  147. #define MRT6MSG_WHOLEPKT 3 /* used for user level encap*/
  148. u_char im6_mbz; /* must be zero */
  149. u_char im6_msgtype; /* what type of message */
  150. u_int16_t im6_mif; /* mif rec'd on */
  151. u_int32_t im6_pad; /* padding for 64bit arch */
  152. struct in6_addr im6_src, im6_dst;
  153. };
  154. /*
  155. * Argument structure used by multicast routing daemon to get src-grp
  156. * packet counts
  157. */
  158. struct sioc_sg_req6 {
  159. struct sockaddr_in6 src;
  160. struct sockaddr_in6 grp;
  161. u_int64_t pktcnt;
  162. u_int64_t bytecnt;
  163. u_int64_t wrong_if;
  164. };
  165. /*
  166. * Argument structure used by mrouted to get mif pkt counts
  167. */
  168. struct sioc_mif_req6 {
  169. mifi_t mifi; /* mif number */
  170. u_int64_t icount; /* Input packet count on mif */
  171. u_int64_t ocount; /* Output packet count on mif */
  172. u_int64_t ibytes; /* Input byte count on mif */
  173. u_int64_t obytes; /* Output byte count on mif */
  174. };
  175. #if defined(_KERNEL)
  176. /*
  177. * The kernel's multicast-interface structure.
  178. */
  179. struct mif6 {
  180. u_char m6_flags; /* MIFF_ flags defined above */
  181. u_int m6_rate_limit; /* max rate */
  182. #ifdef notyet
  183. struct tbf *m6_tbf; /* token bucket structure at intf. */
  184. #endif
  185. struct in6_addr m6_lcl_addr; /* local interface address */
  186. struct ifnet *m6_ifp; /* pointer to interface */
  187. u_int64_t m6_pkt_in; /* # pkts in on interface */
  188. u_int64_t m6_pkt_out; /* # pkts out on interface */
  189. u_int64_t m6_bytes_in; /* # bytes in on interface */
  190. u_int64_t m6_bytes_out; /* # bytes out on interface */
  191. };
  192. /*
  193. * The kernel's multicast forwarding cache entry structure
  194. */
  195. struct mf6c {
  196. struct sockaddr_in6 mf6c_origin; /* IPv6 origin of mcasts */
  197. struct sockaddr_in6 mf6c_mcastgrp; /* multicast group associated*/
  198. mifi_t mf6c_parent; /* incoming IF */
  199. struct if_set mf6c_ifset; /* set of outgoing IFs */
  200. u_int64_t mf6c_pkt_cnt; /* pkt count for src-grp */
  201. u_int64_t mf6c_byte_cnt; /* byte count for src-grp */
  202. u_int64_t mf6c_wrong_if; /* wrong if for src-grp */
  203. int mf6c_expire; /* time to clean entry up */
  204. struct timeval mf6c_last_assert; /* last time I sent an assert*/
  205. struct rtdetq *mf6c_stall; /* pkts waiting for route */
  206. struct mf6c *mf6c_next; /* hash table linkage */
  207. };
  208. /*
  209. * Argument structure used for pkt info. while upcall is made
  210. */
  211. #ifndef _NETINET_IP_MROUTE_H_
  212. struct rtdetq { /* XXX: rtdetq is also defined in ip_mroute.h */
  213. struct mbuf *m; /* A copy of the packet */
  214. struct ifnet *ifp; /* Interface pkt came in on */
  215. struct rtdetq *next;
  216. };
  217. #endif /* _NETINET_IP_MROUTE_H_ */
  218. #define MF6CTBLSIZ 256
  219. #if (MF6CTBLSIZ & (MF6CTBLSIZ - 1)) == 0 /* from sys:route.h */
  220. #define MF6CHASHMOD(h) ((h) & (MF6CTBLSIZ - 1))
  221. #else
  222. #define MF6CHASHMOD(h) ((h) % MF6CTBLSIZ)
  223. #endif
  224. #define MAX_UPQ6 4 /* max. no of pkts in upcall Q */
  225. int ip6_mrouter_set(int, struct socket *, struct mbuf *);
  226. int ip6_mrouter_get(int, struct socket *, struct mbuf **);
  227. int ip6_mrouter_done(void);
  228. void ip6_mrouter_detach(struct ifnet *);
  229. int mrt6_ioctl(u_long, caddr_t);
  230. int mrt6_sysctl_mif(void *, size_t *);
  231. int mrt6_sysctl_mfc(void *, size_t *);
  232. #endif /* _KERNEL */
  233. #endif /* !_NETINET6_IP6_MROUTE_H_ */