mld6_var.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /*-
  2. * SPDX-License-Identifier: BSD-3-Clause
  3. *
  4. * Copyright (c) 2009 Bruce Simpson.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. * 3. The name of the author may not be used to endorse or promote
  15. * products derived from this software without specific prior written
  16. * permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  19. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  20. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  21. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  22. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  23. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  24. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  25. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  26. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  27. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  28. * SUCH DAMAGE.
  29. *
  30. * $FreeBSD$
  31. */
  32. #ifndef _NETINET6_MLD6_VAR_H_
  33. #define _NETINET6_MLD6_VAR_H_
  34. /*
  35. * Multicast Listener Discovery (MLD)
  36. * implementation-specific definitions.
  37. */
  38. /*
  39. * MLD per-group states.
  40. */
  41. #define MLD_NOT_MEMBER 0 /* Can garbage collect group */
  42. #define MLD_SILENT_MEMBER 1 /* Do not perform MLD for group */
  43. #define MLD_REPORTING_MEMBER 2 /* MLDv1 we are reporter */
  44. #define MLD_IDLE_MEMBER 3 /* MLDv1 we reported last */
  45. #define MLD_LAZY_MEMBER 4 /* MLDv1 other member reporting */
  46. #define MLD_SLEEPING_MEMBER 5 /* MLDv1 start query response */
  47. #define MLD_AWAKENING_MEMBER 6 /* MLDv1 group timer will start */
  48. #define MLD_G_QUERY_PENDING_MEMBER 7 /* MLDv2 group query pending */
  49. #define MLD_SG_QUERY_PENDING_MEMBER 8 /* MLDv2 source query pending */
  50. #define MLD_LEAVING_MEMBER 9 /* MLDv2 dying gasp (pending last */
  51. /* retransmission of INCLUDE {}) */
  52. /*
  53. * MLD version tag.
  54. */
  55. #define MLD_VERSION_NONE 0 /* Invalid */
  56. #define MLD_VERSION_1 1
  57. #define MLD_VERSION_2 2 /* Default */
  58. /*
  59. * MLDv2 protocol control variables.
  60. */
  61. #define MLD_RV_INIT 2 /* Robustness Variable */
  62. #define MLD_RV_MIN 1
  63. #define MLD_RV_MAX 7
  64. #define MLD_QI_INIT 125 /* Query Interval (s) */
  65. #define MLD_QI_MIN 1
  66. #define MLD_QI_MAX 255
  67. #define MLD_QRI_INIT 10 /* Query Response Interval (s) */
  68. #define MLD_QRI_MIN 1
  69. #define MLD_QRI_MAX 255
  70. #define MLD_URI_INIT 3 /* Unsolicited Report Interval (s) */
  71. #define MLD_URI_MIN 0
  72. #define MLD_URI_MAX 10
  73. #define MLD_MAX_GS_SOURCES 256 /* # of sources in rx GS query */
  74. #define MLD_MAX_G_GS_PACKETS 8 /* # of packets to answer G/GS */
  75. #define MLD_MAX_STATE_CHANGE_PACKETS 8 /* # of packets per state change */
  76. #define MLD_MAX_RESPONSE_PACKETS 16 /* # of packets for general query */
  77. #define MLD_MAX_RESPONSE_BURST 4 /* # of responses to send at once */
  78. #define MLD_RESPONSE_BURST_INTERVAL (PR_FASTHZ / 2) /* 500ms */
  79. /*
  80. * MLD-specific mbuf flags.
  81. */
  82. #define M_MLDV1 M_PROTO1 /* Packet is MLDv1 */
  83. #define M_GROUPREC M_PROTO3 /* mbuf chain is a group record */
  84. /*
  85. * Leading space for MLDv2 reports inside MTU.
  86. *
  87. * NOTE: This differs from IGMPv3 significantly. KAME IPv6 requires
  88. * that a fully formed mbuf chain *without* the Router Alert option
  89. * is passed to ip6_output(), however we must account for it in the
  90. * MTU if we need to split an MLDv2 report into several packets.
  91. *
  92. * We now put the MLDv2 report header in the initial mbuf containing
  93. * the IPv6 header.
  94. */
  95. #define MLD_MTUSPACE (sizeof(struct ip6_hdr) + sizeof(struct mld_raopt) + \
  96. sizeof(struct icmp6_hdr))
  97. /*
  98. * Structure returned by net.inet6.mld.ifinfo.
  99. */
  100. struct mld_ifinfo {
  101. uint32_t mli_version; /* MLDv1 Host Compatibility Mode */
  102. uint32_t mli_v1_timer; /* MLDv1 Querier Present timer (s) */
  103. uint32_t mli_v2_timer; /* MLDv2 General Query (interface) timer (s)*/
  104. uint32_t mli_flags; /* MLD per-interface flags */
  105. #define MLIF_SILENT 0x00000001 /* Do not use MLD on this ifp */
  106. #define MLIF_USEALLOW 0x00000002 /* Use ALLOW/BLOCK for joins/leaves */
  107. uint32_t mli_rv; /* MLDv2 Robustness Variable */
  108. uint32_t mli_qi; /* MLDv2 Query Interval (s) */
  109. uint32_t mli_qri; /* MLDv2 Query Response Interval (s) */
  110. uint32_t mli_uri; /* MLDv2 Unsolicited Report Interval (s) */
  111. };
  112. #ifdef _KERNEL
  113. /*
  114. * Per-link MLD state.
  115. */
  116. struct mld_ifsoftc {
  117. LIST_ENTRY(mld_ifsoftc) mli_link;
  118. struct ifnet *mli_ifp; /* interface this instance belongs to */
  119. uint32_t mli_version; /* MLDv1 Host Compatibility Mode */
  120. uint32_t mli_v1_timer; /* MLDv1 Querier Present timer (s) */
  121. uint32_t mli_v2_timer; /* MLDv2 General Query (interface) timer (s)*/
  122. uint32_t mli_flags; /* MLD per-interface flags */
  123. uint32_t mli_rv; /* MLDv2 Robustness Variable */
  124. uint32_t mli_qi; /* MLDv2 Query Interval (s) */
  125. uint32_t mli_qri; /* MLDv2 Query Response Interval (s) */
  126. uint32_t mli_uri; /* MLDv2 Unsolicited Report Interval (s) */
  127. struct mbufq mli_gq; /* queue of general query responses */
  128. };
  129. #define MLD_RANDOM_DELAY(X) (arc4random() % (X) + 1)
  130. #define MLD_MAX_STATE_CHANGES 24 /* Max pending changes per group */
  131. /*
  132. * Subsystem lock macros.
  133. * The MLD lock is only taken with MLD. Currently it is system-wide.
  134. * VIMAGE: The lock could be pushed to per-VIMAGE granularity in future.
  135. */
  136. #define MLD_LOCK_INIT() mtx_init(&mld_mtx, "mld_mtx", NULL, MTX_DEF)
  137. #define MLD_LOCK_DESTROY() mtx_destroy(&mld_mtx)
  138. #define MLD_LOCK() mtx_lock(&mld_mtx)
  139. #define MLD_LOCK_ASSERT() mtx_assert(&mld_mtx, MA_OWNED)
  140. #define MLD_UNLOCK() mtx_unlock(&mld_mtx)
  141. #define MLD_UNLOCK_ASSERT() mtx_assert(&mld_mtx, MA_NOTOWNED)
  142. /*
  143. * Per-link MLD context.
  144. */
  145. #define MLD_IFINFO(ifp) \
  146. (((struct in6_ifextra *)(ifp)->if_afdata[AF_INET6])->mld_ifinfo)
  147. struct in6_multi_head;
  148. int mld_change_state(struct in6_multi *, const int);
  149. struct mld_ifsoftc *
  150. mld_domifattach(struct ifnet *);
  151. void mld_domifdetach(struct ifnet *);
  152. void mld_fasttimo(void);
  153. void mld_ifdetach(struct ifnet *, struct in6_multi_head *);
  154. int mld_input(struct mbuf **, int, int);
  155. void mld_slowtimo(void);
  156. #ifdef SYSCTL_DECL
  157. SYSCTL_DECL(_net_inet6_mld);
  158. #endif
  159. #endif /* _KERNEL */
  160. #endif /* _NETINET6_MLD6_VAR_H_ */