1/* 2 * Copyright (c) 2000-2010 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 75struct mld_ifinfo { 76#else 77struct 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 94/* 95 * MLD version tag. 96 */ 97#define MLD_VERSION_NONE 0 /* Invalid */ 98#define MLD_VERSION_1 1 99#define MLD_VERSION_2 2 /* Default */ 100#endif /* PRIVATE */ 101 102#ifdef XNU_KERNEL_PRIVATE 103#include <sys/syslog.h> 104 105#define MLD_DEBUG 1 106#ifdef MLD_DEBUG 107extern int mld_debug; 108#define MLD_PRINTF(x) do { if (mld_debug) printf x; } while (0) 109#else 110#define MLD_PRINTF(x) 111#endif 112 113#define MLD_RANDOM_DELAY(X) (random() % (X) + 1) 114#define MLD_MAX_STATE_CHANGES 24 /* Max pending changes per group */ 115 116/* 117 * MLD per-group states. 118 */ 119#define MLD_NOT_MEMBER 0 /* Can garbage collect group */ 120#define MLD_SILENT_MEMBER 1 /* Do not perform MLD for group */ 121#define MLD_REPORTING_MEMBER 2 /* MLDv1 we are reporter */ 122#define MLD_IDLE_MEMBER 3 /* MLDv1 we reported last */ 123#define MLD_LAZY_MEMBER 4 /* MLDv1 other member reporting */ 124#define MLD_SLEEPING_MEMBER 5 /* MLDv1 start query response */ 125#define MLD_AWAKENING_MEMBER 6 /* MLDv1 group timer will start */ 126#define MLD_G_QUERY_PENDING_MEMBER 7 /* MLDv2 group query pending */ 127#define MLD_SG_QUERY_PENDING_MEMBER 8 /* MLDv2 source query pending */ 128#define MLD_LEAVING_MEMBER 9 /* MLDv2 dying gasp (pending last */ 129 /* retransmission of INCLUDE {}) */ 130/* 131 * MLDv2 protocol control variables. 132 */ 133#define MLD_RV_INIT 2 /* Robustness Variable */ 134#define MLD_RV_MIN 1 135#define MLD_RV_MAX 7 136 137#define MLD_QI_INIT 125 /* Query Interval (s) */ 138#define MLD_QI_MIN 1 139#define MLD_QI_MAX 255 140 141#define MLD_QRI_INIT 10 /* Query Response Interval (s) */ 142#define MLD_QRI_MIN 1 143#define MLD_QRI_MAX 255 144 145#define MLD_URI_INIT 3 /* Unsolicited Report Interval (s) */ 146#define MLD_URI_MIN 0 147#define MLD_URI_MAX 10 148 149#define MLD_MAX_GS_SOURCES 256 /* # of sources in rx GS query */ 150#define MLD_MAX_G_GS_PACKETS 8 /* # of packets to answer G/GS */ 151#define MLD_MAX_STATE_CHANGE_PACKETS 8 /* # of packets per state change */ 152#define MLD_MAX_RESPONSE_PACKETS 16 /* # of packets for general query */ 153#define MLD_MAX_RESPONSE_BURST 4 /* # of responses to send at once */ 154#define MLD_RESPONSE_BURST_INTERVAL (PR_SLOWHZ) /* 500ms */ 155 156/* 157 * MLD-specific mbuf flags. 158 */ 159#define M_MLDV1 M_PROTO1 /* Packet is MLDv1 */ 160#define M_GROUPREC M_PROTO3 /* mbuf chain is a group record */ 161 162/* 163 * Leading space for MLDv2 reports inside MTU. 164 * 165 * NOTE: This differs from IGMPv3 significantly. KAME IPv6 requires 166 * that a fully formed mbuf chain *without* the Router Alert option 167 * is passed to ip6_output(), however we must account for it in the 168 * MTU if we need to split an MLDv2 report into several packets. 169 * 170 * We now put the MLDv2 report header in the initial mbuf containing 171 * the IPv6 header. 172 */ 173#define MLD_MTUSPACE (sizeof(struct ip6_hdr) + sizeof(struct mld_raopt) + \ 174 sizeof(struct icmp6_hdr)) 175 176struct mld_ifinfo { 177 decl_lck_mtx_data(, mli_lock); 178 uint32_t mli_refcnt; /* reference count */ 179 uint32_t mli_debug; /* see ifa_debug flags */ 180 LIST_ENTRY(mld_ifinfo) mli_link; 181 struct ifnet *mli_ifp; /* interface this instance belongs to */ 182 uint32_t mli_version; /* MLDv1 Host Compatibility Mode */ 183 uint32_t mli_v1_timer; /* MLDv1 Querier Present timer (s) */ 184 uint32_t mli_v2_timer; /* MLDv2 General Query (interface) timer (s)*/ 185 uint32_t mli_flags; /* MLD per-interface flags */ 186 uint32_t mli_rv; /* MLDv2 Robustness Variable */ 187 uint32_t mli_qi; /* MLDv2 Query Interval (s) */ 188 uint32_t mli_qri; /* MLDv2 Query Response Interval (s) */ 189 uint32_t mli_uri; /* MLDv2 Unsolicited Report Interval (s) */ 190 SLIST_HEAD(,in6_multi) mli_relinmhead; /* released groups */ 191 struct ifqueue mli_gq; /* queue of general query responses */ 192 struct ifqueue mli_v1q; /* MLDv1 message queue */ 193}; 194 195#define MLI_LOCK_ASSERT_HELD(_mli) \ 196 lck_mtx_assert(&(_mli)->mli_lock, LCK_MTX_ASSERT_OWNED) 197 198#define MLI_LOCK_ASSERT_NOTHELD(_mli) \ 199 lck_mtx_assert(&(_mli)->mli_lock, LCK_MTX_ASSERT_NOTOWNED) 200 201#define MLI_LOCK(_mli) \ 202 lck_mtx_lock(&(_mli)->mli_lock) 203 204#define MLI_LOCK_SPIN(_mli) \ 205 lck_mtx_lock_spin(&(_mli)->mli_lock) 206 207#define MLI_CONVERT_LOCK(_mli) do { \ 208 MLI_LOCK_ASSERT_HELD(_mli); \ 209 lck_mtx_convert_spin(&(_mli)->mli_lock); \ 210} while (0) 211 212#define MLI_UNLOCK(_mli) \ 213 lck_mtx_unlock(&(_mli)->mli_lock) 214 215#define MLI_ADDREF(_mli) \ 216 mli_addref(_mli, 0) 217 218#define MLI_ADDREF_LOCKED(_mli) \ 219 mli_addref(_mli, 1) 220 221#define MLI_REMREF(_mli) \ 222 mli_remref(_mli) 223 224/* 225 * Per-link MLD context. 226 */ 227#define MLD_IFINFO(ifp) ((ifp)->if_mli) 228 229extern int mld_change_state(struct in6_multi *, const int); 230extern struct mld_ifinfo *mld_domifattach(struct ifnet *, int); 231extern void mld_domifreattach(struct mld_ifinfo *); 232extern void mld_domifdetach(struct ifnet *); 233extern void mld_fasttimo(void); 234extern void mld_ifdetach(struct ifnet *); 235extern int mld_input(struct mbuf *, int, int); 236extern void mld_slowtimo(void); 237extern void mld_init(void); 238extern void mli_addref(struct mld_ifinfo *, int); 239extern void mli_remref(struct mld_ifinfo *); 240__private_extern__ void mld6_initsilent(struct ifnet *, struct mld_ifinfo *); 241 242#ifdef SYSCTL_DECL 243SYSCTL_DECL(_net_inet6_mld); 244#endif 245 246#endif /* XNU_KERNEL_PRIVATE */ 247 248#endif /* _NETINET6_MLD6_VAR_H_ */ 249