]> git.saurik.com Git - apple/xnu.git/blob - bsd/netinet/igmp_var.h
xnu-4903.270.47.tar.gz
[apple/xnu.git] / bsd / netinet / igmp_var.h
1 /*
2 * Copyright (c) 2000-2013 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 * Copyright (c) 1988 Stephen Deering.
30 * Copyright (c) 1992, 1993
31 * The Regents of the University of California. All rights reserved.
32 *
33 * This code is derived from software contributed to Berkeley by
34 * Stephen Deering of Stanford University.
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. All advertising materials mentioning features or use of this software
45 * must display the following acknowledgement:
46 * This product includes software developed by the University of
47 * California, Berkeley and its contributors.
48 * 4. Neither the name of the University nor the names of its contributors
49 * may be used to endorse or promote products derived from this software
50 * without specific prior written permission.
51 *
52 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
53 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
54 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
55 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
56 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
57 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
58 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
59 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
60 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
61 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
62 * SUCH DAMAGE.
63 *
64 * from: @(#)igmp_var.h 8.1 (Berkeley) 7/19/93
65 */
66
67 #ifndef _NETINET_IGMP_VAR_H_
68 #define _NETINET_IGMP_VAR_H_
69 #include <sys/appleapiopts.h>
70
71 /*
72 * Internet Group Management Protocol (IGMP),
73 * implementation-specific definitions.
74 *
75 * Written by Steve Deering, Stanford, May 1988.
76 *
77 * MULTICAST Revision: 3.5.1.3
78 */
79
80 struct igmpstat_v3 {
81 /*
82 * Structure header (to insulate ABI changes).
83 */
84 uint32_t igps_version; /* version of this structure */
85 uint32_t igps_len; /* length of this structure */
86 /*
87 * Message statistics.
88 */
89 uint64_t igps_rcv_total; /* total IGMP messages received */
90 uint64_t igps_rcv_tooshort; /* received with too few bytes */
91 uint64_t igps_rcv_badttl; /* received with ttl other than 1 */
92 uint64_t igps_rcv_badsum; /* received with bad checksum */
93 /*
94 * Query statistics.
95 */
96 uint64_t igps_rcv_v1v2_queries; /* received IGMPv1/IGMPv2 queries */
97 uint64_t igps_rcv_v3_queries; /* received IGMPv3 queries */
98 uint64_t igps_rcv_badqueries; /* received invalid queries */
99 uint64_t igps_rcv_gen_queries; /* received general queries */
100 uint64_t igps_rcv_group_queries;/* received group queries */
101 uint64_t igps_rcv_gsr_queries; /* received group-source queries */
102 uint64_t igps_drop_gsr_queries; /* dropped group-source queries */
103 /*
104 * Report statistics.
105 */
106 uint64_t igps_rcv_reports; /* received membership reports */
107 uint64_t igps_rcv_badreports; /* received invalid reports */
108 uint64_t igps_rcv_ourreports; /* received reports for our groups */
109 uint64_t igps_rcv_nora; /* received w/o Router Alert option */
110 uint64_t igps_snd_reports; /* sent membership reports */
111 /*
112 * Padding for future additions.
113 */
114 uint64_t __igps_pad[4];
115 } __attribute__((aligned(8)));
116
117 /*
118 * Old IGMPv2 stat structure for backward compatibility
119 *
120 */
121
122 struct igmpstat {
123 u_int igps_rcv_total; /* total IGMP messages received */
124 u_int igps_rcv_tooshort; /* received with too few bytes */
125 u_int igps_rcv_badsum; /* received with bad checksum */
126 u_int igps_rcv_queries; /* received membership queries */
127 u_int igps_rcv_badqueries; /* received invalid queries */
128 u_int igps_rcv_reports; /* received membership reports */
129 u_int igps_rcv_badreports; /* received invalid reports */
130 u_int igps_rcv_ourreports; /* received reports for our groups */
131 u_int igps_snd_reports; /* sent membership reports */
132 };
133
134 #define IGPS_VERSION_3 3
135 #define IGPS_VERSION3_LEN 168
136
137 #ifdef PRIVATE
138 /*
139 * Per-interface IGMP router version information.
140 */
141 #ifndef XNU_KERNEL_PRIVATE
142 struct igmp_ifinfo {
143 #else
144 struct igmp_ifinfo_u {
145 #endif /* XNU_KERNEL_PRIVATE */
146 uint32_t igi_ifindex; /* interface this instance belongs to */
147 uint32_t igi_version; /* IGMPv3 Host Compatibility Mode */
148 uint32_t igi_v1_timer; /* IGMPv1 Querier Present timer (s) */
149 uint32_t igi_v2_timer; /* IGMPv2 Querier Present timer (s) */
150 uint32_t igi_v3_timer; /* IGMPv3 General Query (interface) timer (s)*/
151 uint32_t igi_flags; /* IGMP per-interface flags */
152 uint32_t igi_rv; /* IGMPv3 Robustness Variable */
153 uint32_t igi_qi; /* IGMPv3 Query Interval (s) */
154 uint32_t igi_qri; /* IGMPv3 Query Response Interval (s) */
155 uint32_t igi_uri; /* IGMPv3 Unsolicited Report Interval (s) */
156 };
157
158 #define IGIF_SILENT 0x00000001 /* Do not use IGMP on this ifp */
159 #define IGIF_LOOPBACK 0x00000002 /* Send IGMP reports to loopback */
160
161 /*
162 * IGMP version tag.
163 */
164 #define IGMP_VERSION_NONE 0 /* Invalid */
165 #define IGMP_VERSION_1 1
166 #define IGMP_VERSION_2 2
167 #define IGMP_VERSION_3 3 /* Default */
168 #endif /* PRIVATE */
169
170 #ifdef BSD_KERNEL_PRIVATE
171 #include <libkern/libkern.h>
172 #define IGMP_DEBUG 1
173 #ifdef IGMP_DEBUG
174 extern int igmp_debug;
175
176 #define IGMP_PRINTF(x) do { if (igmp_debug) printf x; } while (0)
177 #define IGMP_INET_PRINTF(addr, x) do { \
178 if (igmp_debug) { \
179 char _igmp_inet_buf[MAX_IPv4_STR_LEN]; \
180 inet_ntop(AF_INET, &(addr), _igmp_inet_buf, \
181 sizeof(_igmp_inet_buf)); \
182 printf x; \
183 } \
184 } while (0)
185 #else
186 #define IGMP_PRINTF(x)
187 #endif
188
189 #define OIGMPSTAT_ADD(name, val) atomic_add_32(&igmpstat.name , (val))
190 #define OIGMPSTAT_INC(name) OIGMPSTAT_ADD(name, 1)
191
192 #define IGMPSTAT_ADD(name, val) atomic_add_64(&igmpstat_v3.name , (val))
193 #define IGMPSTAT_INC(name) IGMPSTAT_ADD(name, 1)
194
195 #define IGMP_RANDOM_DELAY(X) (random() % (X) + 1)
196
197 #define IGMP_MAX_STATE_CHANGES 24 /* Max pending changes per group */
198
199 /*
200 * IGMP per-group states.
201 */
202 #define IGMP_NOT_MEMBER 0 /* Can garbage collect in_multi */
203 #define IGMP_SILENT_MEMBER 1 /* Do not perform IGMP for group */
204 #define IGMP_REPORTING_MEMBER 2 /* IGMPv1/2/3 we are reporter */
205 #define IGMP_IDLE_MEMBER 3 /* IGMPv1/2 we reported last */
206 #define IGMP_LAZY_MEMBER 4 /* IGMPv1/2 other member reporting */
207 #define IGMP_SLEEPING_MEMBER 5 /* IGMPv1/2 start query response */
208 #define IGMP_AWAKENING_MEMBER 6 /* IGMPv1/2 group timer will start */
209 #define IGMP_G_QUERY_PENDING_MEMBER 7 /* IGMPv3 group query pending */
210 #define IGMP_SG_QUERY_PENDING_MEMBER 8 /* IGMPv3 source query pending */
211 #define IGMP_LEAVING_MEMBER 9 /* IGMPv3 dying gasp (pending last */
212 /* retransmission of INCLUDE {}) */
213 /*
214 * IGMPv3 protocol control variables.
215 */
216 #define IGMP_RV_INIT 2 /* Robustness Variable */
217 #define IGMP_RV_MIN 1
218 #define IGMP_RV_MAX 7
219
220 #define IGMP_QI_INIT 125 /* Query Interval (s) */
221 #define IGMP_QI_MIN 1
222 #define IGMP_QI_MAX 255
223
224 #define IGMP_QRI_INIT 10 /* Query Response Interval (s) */
225 #define IGMP_QRI_MIN 1
226 #define IGMP_QRI_MAX 255
227
228 #define IGMP_URI_INIT 3 /* Unsolicited Report Interval (s) */
229 #define IGMP_URI_MIN 0
230 #define IGMP_URI_MAX 10
231
232 #define IGMP_MAX_G_GS_PACKETS 8 /* # of packets to answer G/GS */
233 #define IGMP_MAX_STATE_CHANGE_PACKETS 8 /* # of packets per state change */
234 #define IGMP_MAX_RESPONSE_PACKETS 16 /* # of packets for general query */
235 #define IGMP_MAX_RESPONSE_BURST 4 /* # of responses to send at once */
236 #define IGMP_RESPONSE_BURST_INTERVAL 1 /* 1 second */
237
238 /*
239 * IGMP-specific mbuf flags.
240 */
241 #define M_IGMPV2 M_PROTO1 /* Packet is IGMPv2 */
242 #define M_IGMPV3_HDR M_PROTO2 /* Packet has IGMPv3 headers */
243 #define M_GROUPREC M_PROTO3 /* mbuf chain is a group record */
244 #define M_IGMP_LOOP M_LOOP /* transmit on loif, not real ifp */
245
246 /*
247 * Default amount of leading space for IGMPv3 to allocate at the
248 * beginning of its mbuf packet chains, to avoid fragmentation and
249 * unnecessary allocation of leading mbufs.
250 */
251 #define RAOPT_LEN 4 /* Length of IP Router Alert option */
252 #define IGMP_LEADINGSPACE \
253 (sizeof(struct ip) + RAOPT_LEN + sizeof(struct igmp_report))
254
255 struct igmp_ifinfo {
256 decl_lck_mtx_data(, igi_lock);
257 uint32_t igi_refcnt; /* reference count */
258 uint32_t igi_debug; /* see ifa_debug flags */
259 LIST_ENTRY(igmp_ifinfo) igi_link;
260 struct ifnet *igi_ifp; /* interface this instance belongs to */
261 uint32_t igi_version; /* IGMPv3 Host Compatibility Mode */
262 uint32_t igi_v1_timer; /* IGMPv1 Querier Present timer (s) */
263 uint32_t igi_v2_timer; /* IGMPv2 Querier Present timer (s) */
264 uint32_t igi_v3_timer; /* IGMPv3 General Query (interface) timer (s)*/
265 uint32_t igi_flags; /* IGMP per-interface flags */
266 uint32_t igi_rv; /* IGMPv3 Robustness Variable */
267 uint32_t igi_qi; /* IGMPv3 Query Interval (s) */
268 uint32_t igi_qri; /* IGMPv3 Query Response Interval (s) */
269 uint32_t igi_uri; /* IGMPv3 Unsolicited Report Interval (s) */
270 SLIST_HEAD(, in_multi) igi_relinmhead; /* released groups */
271 struct ifqueue igi_gq; /* queue of general query responses */
272 struct ifqueue igi_v2q; /* queue of v1/v2 packets */
273 };
274
275 #define IGI_LOCK_ASSERT_HELD(_igi) \
276 LCK_MTX_ASSERT(&(_igi)->igi_lock, LCK_MTX_ASSERT_OWNED)
277
278 #define IGI_LOCK_ASSERT_NOTHELD(_igi) \
279 LCK_MTX_ASSERT(&(_igi)->igi_lock, LCK_MTX_ASSERT_NOTOWNED)
280
281 #define IGI_LOCK(_igi) \
282 lck_mtx_lock(&(_igi)->igi_lock)
283
284 #define IGI_LOCK_SPIN(_igi) \
285 lck_mtx_lock_spin(&(_igi)->igi_lock)
286
287 #define IGI_CONVERT_LOCK(_igi) do { \
288 IGI_LOCK_ASSERT_HELD(_igi); \
289 lck_mtx_convert_spin(&(_igi)->igi_lock); \
290 } while (0)
291
292 #define IGI_UNLOCK(_igi) \
293 lck_mtx_unlock(&(_igi)->igi_lock)
294
295 #define IGI_ADDREF(_igi) \
296 igi_addref(_igi, 0)
297
298 #define IGI_ADDREF_LOCKED(_igi) \
299 igi_addref(_igi, 1)
300
301 #define IGI_REMREF(_igi) \
302 igi_remref(_igi)
303
304 /*
305 * Per-link IGMP context.
306 */
307 #define IGMP_IFINFO(ifp) ((ifp)->if_igi)
308
309 /*
310 * IGMP timer schedule parameters
311 */
312 struct igmp_tparams {
313 int qpt; /* querier_present_timers_running */
314 int it; /* interface_timers_running */
315 int cst; /* current_state_timers_running */
316 int sct; /* state_change_timers_running */
317 };
318
319 extern void igmp_init(struct protosw *, struct domain *);
320 extern int igmp_change_state(struct in_multi *, struct igmp_tparams *);
321 extern struct igmp_ifinfo *igmp_domifattach(struct ifnet *, int);
322 extern void igmp_domifreattach(struct igmp_ifinfo *);
323 extern void igmp_domifdetach(struct ifnet *);
324 extern void igmp_input(struct mbuf *, int);
325 extern int igmp_joingroup(struct in_multi *);
326 extern void igmp_leavegroup(struct in_multi *);
327 extern void igmp_set_timeout(struct igmp_tparams *);
328 extern void igi_addref(struct igmp_ifinfo *, int);
329 extern void igi_remref(struct igmp_ifinfo *);
330 __private_extern__ void igmp_initsilent(struct ifnet *, struct igmp_ifinfo *);
331
332 SYSCTL_DECL(_net_inet_igmp);
333
334 #endif /* BSD_KERNEL_PRIVATE */
335
336 /*
337 * Names for IGMP sysctl objects
338 */
339 #define IGMPCTL_STATS 1 /* statistics (read-only) */
340 #define IGMPCTL_MAXID 2
341
342 #ifdef BSD_KERNEL_PRIVATE
343 #define IGMPCTL_NAMES { \
344 { 0, 0 }, \
345 { "stats", CTLTYPE_STRUCT }, \
346 }
347
348 #endif /* BSD_KERNEL_PRIVATE */
349 #endif