xref: /xnu-11215.41.3/bsd/netinet6/mld6_var.h (revision 33de042d024d46de5ff4e89f2471de6608e37fa4)
1 /*
2  * Copyright (c) 2000-2020 Apple Inc. All rights reserved.
3  *
4  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5  *
6  * This file contains Original Code and/or Modifications of Original Code
7  * as defined in and that are subject to the Apple Public Source License
8  * Version 2.0 (the 'License'). You may not use this file except in
9  * compliance with the License. The rights granted to you under the License
10  * may not be used to create, or enable the creation or redistribution of,
11  * unlawful or unlicensed copies of an Apple operating system, or to
12  * circumvent, violate, or enable the circumvention or violation of, any
13  * terms of an Apple operating system software license agreement.
14  *
15  * Please obtain a copy of the License at
16  * http://www.opensource.apple.com/apsl/ and read it before using this file.
17  *
18  * The Original Code and all software distributed under the License are
19  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23  * Please see the License for the specific language governing rights and
24  * limitations under the License.
25  *
26  * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27  */
28 
29 /*	$FreeBSD: src/sys/netinet6/mld6_var.h,v 1.1.2.1 2000/07/15 07:14:36 kris Exp $	*/
30 /*	$KAME: mld6_var.h,v 1.4 2000/03/25 07:23:54 sumikawa Exp $	*/
31 
32 /*
33  * Copyright (C) 1998 WIDE Project.
34  * All rights reserved.
35  *
36  * Redistribution and use in source and binary forms, with or without
37  * modification, are permitted provided that the following conditions
38  * are met:
39  * 1. Redistributions of source code must retain the above copyright
40  *    notice, this list of conditions and the following disclaimer.
41  * 2. Redistributions in binary form must reproduce the above copyright
42  *    notice, this list of conditions and the following disclaimer in the
43  *    documentation and/or other materials provided with the distribution.
44  * 3. Neither the name of the project nor the names of its contributors
45  *    may be used to endorse or promote products derived from this software
46  *    without specific prior written permission.
47  *
48  * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
49  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
50  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
51  * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
52  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
53  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
54  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
55  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
56  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
57  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
58  * SUCH DAMAGE.
59  */
60 
61 #ifndef _NETINET6_MLD6_VAR_H_
62 #define _NETINET6_MLD6_VAR_H_
63 #include <sys/appleapiopts.h>
64 
65 /*
66  * Multicast Listener Discovery (MLD)
67  * implementation-specific definitions.
68  */
69 
70 #ifdef PRIVATE
71 /*
72  * Per-link MLD state.
73  */
74 #ifndef XNU_KERNEL_PRIVATE
75 struct mld_ifinfo {
76 #else
77 struct mld_ifinfo_u {
78 #endif /* XNU_KERNEL_PRIVATE */
79 	uint32_t mli_ifindex;   /* interface this instance belongs to */
80 	uint32_t mli_version;   /* MLDv1 Host Compatibility Mode */
81 	uint32_t mli_v1_timer;  /* MLDv1 Querier Present timer (s) */
82 	uint32_t mli_v2_timer;  /* MLDv2 General Query (interface) timer (s)*/
83 	uint32_t mli_flags;     /* MLD per-interface flags */
84 	uint32_t mli_rv;        /* MLDv2 Robustness Variable */
85 	uint32_t mli_qi;        /* MLDv2 Query Interval (s) */
86 	uint32_t mli_qri;       /* MLDv2 Query Response Interval (s) */
87 	uint32_t mli_uri;       /* MLDv2 Unsolicited Report Interval (s) */
88 	uint32_t _pad;
89 };
90 
91 #define MLIF_SILENT     0x00000001      /* Do not use MLD on this ifp */
92 #define MLIF_USEALLOW   0x00000002      /* Use ALLOW/BLOCK for joins/leaves */
93 #define MLIF_PROCESSED  0x00000004      /* Entry has been processed and can be skipped */
94 
95 /*
96  * MLD version tag.
97  */
98 #define MLD_VERSION_NONE                0 /* Invalid */
99 #define MLD_VERSION_1                   1
100 #define MLD_VERSION_2                   2 /* Default */
101 #endif /* PRIVATE */
102 
103 #ifdef BSD_KERNEL_PRIVATE
104 #include <sys/syslog.h>
105 
106 #define MLD_DEBUG 1
107 #ifdef MLD_DEBUG
108 extern int mld_debug;
109 #define MLD_PRINTF(x)   do { if (mld_debug) printf x; } while (0)
110 #else
111 #define MLD_PRINTF(x)
112 #endif
113 
114 #define MLD_RANDOM_DELAY(X)             (RandomULong() % (X) + 1)
115 #define MLD_MAX_STATE_CHANGES           24 /* Max pending changes per group */
116 
117 /*
118  * MLD per-group states.
119  */
120 #define MLD_NOT_MEMBER                  0 /* Can garbage collect group */
121 #define MLD_SILENT_MEMBER               1 /* Do not perform MLD for group */
122 #define MLD_REPORTING_MEMBER            2 /* MLDv1 we are reporter */
123 #define MLD_IDLE_MEMBER                 3 /* MLDv1 we reported last */
124 #define MLD_LAZY_MEMBER                 4 /* MLDv1 other member reporting */
125 #define MLD_SLEEPING_MEMBER             5 /* MLDv1 start query response */
126 #define MLD_AWAKENING_MEMBER            6 /* MLDv1 group timer will start */
127 #define MLD_G_QUERY_PENDING_MEMBER      7 /* MLDv2 group query pending */
128 #define MLD_SG_QUERY_PENDING_MEMBER     8 /* MLDv2 source query pending */
129 #define MLD_LEAVING_MEMBER              9 /* MLDv2 dying gasp (pending last */
130                                           /* retransmission of INCLUDE {}) */
131 /*
132  * MLDv2 protocol control variables.
133  */
134 #define MLD_RV_INIT             2       /* Robustness Variable */
135 #define MLD_RV_MIN              1
136 #define MLD_RV_MAX              7
137 
138 #define MLD_QI_INIT             125     /* Query Interval (s) */
139 #define MLD_QI_MIN              1
140 #define MLD_QI_MAX              255
141 
142 #define MLD_QRI_INIT            10      /* Query Response Interval (s) */
143 #define MLD_QRI_MIN             1
144 #define MLD_QRI_MAX             255
145 
146 #define MLD_URI_INIT            3       /* Unsolicited Report Interval (s) */
147 #define MLD_URI_MIN             0
148 #define MLD_URI_MAX             10
149 
150 #define MLD_MAX_GS_SOURCES              256 /* # of sources in rx GS query */
151 #define MLD_MAX_G_GS_PACKETS            8 /* # of packets to answer G/GS */
152 #define MLD_MAX_STATE_CHANGE_PACKETS    8 /* # of packets per state change */
153 #define MLD_MAX_RESPONSE_PACKETS        16 /* # of packets for general query */
154 #define MLD_MAX_RESPONSE_BURST          4 /* # of responses to send at once */
155 #define MLD_RESPONSE_BURST_INTERVAL     1 /* 1 second */
156 
157 /*
158  * MLD-specific mbuf flags.
159  */
160 #define M_MLDV1         M_PROTO1        /* Packet is MLDv1 */
161 #define M_GROUPREC      M_PROTO3        /* mbuf chain is a group record */
162 
163 /*
164  * Leading space for MLDv2 reports inside MTU.
165  *
166  * NOTE: This differs from IGMPv3 significantly. KAME IPv6 requires
167  * that a fully formed mbuf chain *without* the Router Alert option
168  * is passed to ip6_output(), however we must account for it in the
169  * MTU if we need to split an MLDv2 report into several packets.
170  *
171  * We now put the MLDv2 report header in the initial mbuf containing
172  * the IPv6 header.
173  */
174 #define MLD_MTUSPACE    (sizeof(struct ip6_hdr) + sizeof(struct mld_raopt) + \
175 	                 sizeof(struct icmp6_hdr))
176 
177 struct mld_ifinfo {
178 	decl_lck_mtx_data(, mli_lock);
179 	uint32_t mli_refcnt;    /* reference count */
180 	uint32_t mli_debug;     /* see ifa_debug flags */
181 	LIST_ENTRY(mld_ifinfo) mli_link;
182 	struct ifnet *mli_ifp;  /* interface this instance belongs to */
183 	uint32_t mli_version;   /* MLDv1 Host Compatibility Mode */
184 	uint32_t mli_v1_timer;  /* MLDv1 Querier Present timer (s) */
185 	uint32_t mli_v2_timer;  /* MLDv2 General Query (interface) timer (s)*/
186 	uint32_t mli_flags;     /* MLD per-interface flags */
187 	uint32_t mli_rv;        /* MLDv2 Robustness Variable */
188 	uint32_t mli_qi;        /* MLDv2 Query Interval (s) */
189 	uint32_t mli_qri;       /* MLDv2 Query Response Interval (s) */
190 	uint32_t mli_uri;       /* MLDv2 Unsolicited Report Interval (s) */
191 	SLIST_HEAD(, in6_multi)  mli_relinmhead; /* released groups */
192 	struct ifqueue   mli_gq;        /* queue of general query responses */
193 	struct ifqueue   mli_v1q; /* MLDv1 message queue */
194 };
195 
196 #define MLI_LOCK_ASSERT_HELD(_mli)                                      \
197 	LCK_MTX_ASSERT(&(_mli)->mli_lock, LCK_MTX_ASSERT_OWNED)
198 
199 #define MLI_LOCK_ASSERT_NOTHELD(_mli)                                   \
200 	LCK_MTX_ASSERT(&(_mli)->mli_lock, LCK_MTX_ASSERT_NOTOWNED)
201 
202 #define MLI_LOCK(_mli)                                                  \
203 	lck_mtx_lock(&(_mli)->mli_lock)
204 
205 #define MLI_LOCK_SPIN(_mli)                                             \
206 	lck_mtx_lock_spin(&(_mli)->mli_lock)
207 
208 #define MLI_CONVERT_LOCK(_mli) do {                                     \
209 	MLI_LOCK_ASSERT_HELD(_mli);                                     \
210 	lck_mtx_convert_spin(&(_mli)->mli_lock);                        \
211 } while (0)
212 
213 #define MLI_UNLOCK(_mli)                                                \
214 	lck_mtx_unlock(&(_mli)->mli_lock)
215 
216 #define MLI_ADDREF(_mli)                                                \
217 	mli_addref(_mli, 0)
218 
219 #define MLI_ADDREF_LOCKED(_mli)                                         \
220 	mli_addref(_mli, 1)
221 
222 #define MLI_REMREF(_mli)                                                \
223 	mli_remref(_mli)
224 
225 /*
226  * Per-link MLD context.
227  */
228 #define MLD_IFINFO(ifp) ((ifp)->if_mli)
229 
230 /*
231  * MLD timer schedule parameters
232  */
233 struct mld_tparams {
234 	int     qpt;    /* querier_present_timers_running6 */
235 	int     it;     /* interface_timers_running6 */
236 	int     cst;    /* current_state_timers_running6 */
237 	int     sct;    /* state_change_timers_running6 */
238 	bool    fast;   /* fast timer */
239 };
240 
241 extern int mld_change_state(struct in6_multi *, struct mld_tparams *,
242     const int);
243 extern struct mld_ifinfo *mld_domifattach(struct ifnet *, zalloc_flags_t);
244 extern void mld_domifreattach(struct mld_ifinfo *);
245 extern void mld_domifdetach(struct ifnet *);
246 extern void mld_fasttimo(void);
247 extern void mld_ifdetach(struct ifnet *);
248 extern int mld_input(struct mbuf *, int, int);
249 extern void mld_init(void);
250 extern void mld_set_timeout(struct mld_tparams *);
251 extern void mld_set_fast_timeout(struct mld_tparams *);
252 extern void mli_addref(struct mld_ifinfo *, int);
253 extern void mli_remref(struct mld_ifinfo *);
254 __private_extern__ void mld6_initsilent(struct ifnet *, struct mld_ifinfo *);
255 
256 #ifdef SYSCTL_DECL
257 SYSCTL_DECL(_net_inet6_mld);
258 #endif
259 
260 #endif /* BSD_KERNEL_PRIVATE */
261 #endif /* _NETINET6_MLD6_VAR_H_ */
262