]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
6d2010ae | 2 | * Copyright (c) 2000-2010 Apple Computer, Inc. All rights reserved. |
5d5c5d0d | 3 | * |
2d21ac55 | 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
1c79356b | 5 | * |
2d21ac55 A |
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. | |
8f6c56a5 | 14 | * |
2d21ac55 A |
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 | |
8f6c56a5 A |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
2d21ac55 A |
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. | |
8f6c56a5 | 25 | * |
2d21ac55 | 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
1c79356b A |
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_ | |
9bccf70c A |
69 | #include <sys/appleapiopts.h> |
70 | ||
1c79356b A |
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 | ||
6d2010ae A |
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 | ||
1c79356b A |
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 | ||
6d2010ae A |
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 XNU_KERNEL_PRIVATE | |
171 | #include <libkern/libkern.h> | |
172 | #define IGMP_DEBUG 1 | |
173 | #ifdef IGMP_DEBUG | |
174 | extern char * inet_ntoa(struct in_addr); | |
175 | extern int igmp_debug; | |
176 | ||
177 | #define IGMP_PRINTF(x) do { if (igmp_debug) printf x; } while (0) | |
178 | #else | |
179 | #define IGMP_PRINTF(x) | |
180 | #endif | |
181 | ||
182 | #define OIGMPSTAT_ADD(name, val) atomic_add_32(&igmpstat.name , (val)) | |
183 | #define OIGMPSTAT_INC(name) OIGMPSTAT_ADD(name, 1) | |
184 | ||
185 | #define IGMPSTAT_ADD(name, val) atomic_add_64(&igmpstat_v3.name , (val)) | |
186 | #define IGMPSTAT_INC(name) IGMPSTAT_ADD(name, 1) | |
187 | ||
1c79356b A |
188 | #define IGMP_RANDOM_DELAY(X) (random() % (X) + 1) |
189 | ||
6d2010ae A |
190 | #define IGMP_MAX_STATE_CHANGES 24 /* Max pending changes per group */ |
191 | ||
1c79356b | 192 | /* |
6d2010ae | 193 | * IGMP per-group states. |
1c79356b | 194 | */ |
6d2010ae A |
195 | #define IGMP_NOT_MEMBER 0 /* Can garbage collect in_multi */ |
196 | #define IGMP_SILENT_MEMBER 1 /* Do not perform IGMP for group */ | |
197 | #define IGMP_REPORTING_MEMBER 2 /* IGMPv1/2/3 we are reporter */ | |
198 | #define IGMP_IDLE_MEMBER 3 /* IGMPv1/2 we reported last */ | |
199 | #define IGMP_LAZY_MEMBER 4 /* IGMPv1/2 other member reporting */ | |
200 | #define IGMP_SLEEPING_MEMBER 5 /* IGMPv1/2 start query response */ | |
201 | #define IGMP_AWAKENING_MEMBER 6 /* IGMPv1/2 group timer will start */ | |
202 | #define IGMP_G_QUERY_PENDING_MEMBER 7 /* IGMPv3 group query pending */ | |
203 | #define IGMP_SG_QUERY_PENDING_MEMBER 8 /* IGMPv3 source query pending */ | |
204 | #define IGMP_LEAVING_MEMBER 9 /* IGMPv3 dying gasp (pending last */ | |
205 | /* retransmission of INCLUDE {}) */ | |
206 | /* | |
207 | * IGMPv3 protocol control variables. | |
208 | */ | |
209 | #define IGMP_RV_INIT 2 /* Robustness Variable */ | |
210 | #define IGMP_RV_MIN 1 | |
211 | #define IGMP_RV_MAX 7 | |
212 | ||
213 | #define IGMP_QI_INIT 125 /* Query Interval (s) */ | |
214 | #define IGMP_QI_MIN 1 | |
215 | #define IGMP_QI_MAX 255 | |
216 | ||
217 | #define IGMP_QRI_INIT 10 /* Query Response Interval (s) */ | |
218 | #define IGMP_QRI_MIN 1 | |
219 | #define IGMP_QRI_MAX 255 | |
220 | ||
221 | #define IGMP_URI_INIT 3 /* Unsolicited Report Interval (s) */ | |
222 | #define IGMP_URI_MIN 0 | |
223 | #define IGMP_URI_MAX 10 | |
224 | ||
225 | #define IGMP_MAX_G_GS_PACKETS 8 /* # of packets to answer G/GS */ | |
226 | #define IGMP_MAX_STATE_CHANGE_PACKETS 8 /* # of packets per state change */ | |
227 | #define IGMP_MAX_RESPONSE_PACKETS 16 /* # of packets for general query */ | |
228 | #define IGMP_MAX_RESPONSE_BURST 4 /* # of responses to send at once */ | |
229 | #define IGMP_RESPONSE_BURST_INTERVAL (PR_SLOWHZ) /* 500ms */ | |
1c79356b A |
230 | |
231 | /* | |
6d2010ae | 232 | * IGMP-specific mbuf flags. |
1c79356b | 233 | */ |
6d2010ae A |
234 | #define M_IGMPV2 M_PROTO1 /* Packet is IGMPv2 */ |
235 | #define M_IGMPV3_HDR M_PROTO2 /* Packet has IGMPv3 headers */ | |
236 | #define M_GROUPREC M_PROTO3 /* mbuf chain is a group record */ | |
237 | #define M_IGMP_LOOP M_LOOP /* transmit on loif, not real ifp */ | |
238 | ||
239 | /* | |
240 | * Default amount of leading space for IGMPv3 to allocate at the | |
241 | * beginning of its mbuf packet chains, to avoid fragmentation and | |
242 | * unnecessary allocation of leading mbufs. | |
243 | */ | |
244 | #define RAOPT_LEN 4 /* Length of IP Router Alert option */ | |
245 | #define IGMP_LEADINGSPACE \ | |
246 | (sizeof(struct ip) + RAOPT_LEN + sizeof(struct igmp_report)) | |
247 | ||
248 | struct igmp_ifinfo { | |
249 | decl_lck_mtx_data(, igi_lock); | |
250 | uint32_t igi_refcnt; /* reference count */ | |
251 | uint32_t igi_debug; /* see ifa_debug flags */ | |
252 | LIST_ENTRY(igmp_ifinfo) igi_link; | |
253 | struct ifnet *igi_ifp; /* interface this instance belongs to */ | |
254 | uint32_t igi_version; /* IGMPv3 Host Compatibility Mode */ | |
255 | uint32_t igi_v1_timer; /* IGMPv1 Querier Present timer (s) */ | |
256 | uint32_t igi_v2_timer; /* IGMPv2 Querier Present timer (s) */ | |
257 | uint32_t igi_v3_timer; /* IGMPv3 General Query (interface) timer (s)*/ | |
258 | uint32_t igi_flags; /* IGMP per-interface flags */ | |
259 | uint32_t igi_rv; /* IGMPv3 Robustness Variable */ | |
260 | uint32_t igi_qi; /* IGMPv3 Query Interval (s) */ | |
261 | uint32_t igi_qri; /* IGMPv3 Query Response Interval (s) */ | |
262 | uint32_t igi_uri; /* IGMPv3 Unsolicited Report Interval (s) */ | |
263 | SLIST_HEAD(,in_multi) igi_relinmhead; /* released groups */ | |
264 | struct ifqueue igi_gq; /* queue of general query responses */ | |
265 | struct ifqueue igi_v2q; /* queue of v1/v2 packets */ | |
266 | }; | |
267 | ||
268 | #define IGI_LOCK_ASSERT_HELD(_igi) \ | |
269 | lck_mtx_assert(&(_igi)->igi_lock, LCK_MTX_ASSERT_OWNED) | |
270 | ||
271 | #define IGI_LOCK_ASSERT_NOTHELD(_igi) \ | |
272 | lck_mtx_assert(&(_igi)->igi_lock, LCK_MTX_ASSERT_NOTOWNED) | |
273 | ||
274 | #define IGI_LOCK(_igi) \ | |
275 | lck_mtx_lock(&(_igi)->igi_lock) | |
276 | ||
277 | #define IGI_LOCK_SPIN(_igi) \ | |
278 | lck_mtx_lock_spin(&(_igi)->igi_lock) | |
279 | ||
280 | #define IGI_CONVERT_LOCK(_igi) do { \ | |
281 | IGI_LOCK_ASSERT_HELD(_igi); \ | |
282 | lck_mtx_convert_spin(&(_igi)->igi_lock); \ | |
283 | } while (0) | |
284 | ||
285 | #define IGI_UNLOCK(_igi) \ | |
286 | lck_mtx_unlock(&(_igi)->igi_lock) | |
287 | ||
288 | #define IGI_ADDREF(_igi) \ | |
289 | igi_addref(_igi, 0) | |
290 | ||
291 | #define IGI_ADDREF_LOCKED(_igi) \ | |
292 | igi_addref(_igi, 1) | |
293 | ||
294 | #define IGI_REMREF(_igi) \ | |
295 | igi_remref(_igi) | |
1c79356b A |
296 | |
297 | /* | |
6d2010ae | 298 | * Per-link IGMP context. |
1c79356b | 299 | */ |
6d2010ae | 300 | #define IGMP_IFINFO(ifp) ((ifp)->if_igi) |
1c79356b | 301 | |
6d2010ae A |
302 | extern void igmp_init(void) __attribute__((section("__TEXT, initcode"))); |
303 | extern int igmp_change_state(struct in_multi *); | |
304 | extern struct igmp_ifinfo *igmp_domifattach(struct ifnet *, int); | |
305 | extern void igmp_domifreattach(struct igmp_ifinfo *); | |
306 | extern void igmp_domifdetach(struct ifnet *); | |
307 | extern void igmp_input(struct mbuf *, int); | |
308 | extern int igmp_joingroup(struct in_multi *); | |
309 | extern void igmp_leavegroup(struct in_multi *); | |
310 | extern void igmp_slowtimo(void); | |
311 | extern void igi_addref(struct igmp_ifinfo *, int); | |
312 | extern void igi_remref(struct igmp_ifinfo *); | |
1c79356b A |
313 | |
314 | SYSCTL_DECL(_net_inet_igmp); | |
315 | ||
6d2010ae | 316 | #endif /* XNU_KERNEL_PRIVATE */ |
1c79356b A |
317 | |
318 | /* | |
319 | * Names for IGMP sysctl objects | |
320 | */ | |
321 | #define IGMPCTL_STATS 1 /* statistics (read-only) */ | |
322 | #define IGMPCTL_MAXID 2 | |
323 | ||
6d2010ae | 324 | #ifdef XNU_KERNEL_PRIVATE |
1c79356b A |
325 | #define IGMPCTL_NAMES { \ |
326 | { 0, 0 }, \ | |
327 | { "stats", CTLTYPE_STRUCT }, \ | |
328 | } | |
329 | ||
6d2010ae | 330 | #endif /* XNU_KERNEL_PRIVATE */ |
1c79356b | 331 | #endif |