1caf43b02SWarner Losh /*- 2fe267a55SPedro F. Giffuni * SPDX-License-Identifier: BSD-3-Clause 3fe267a55SPedro F. Giffuni * 433cde130SBruce M Simpson * Copyright (c) 2009 Bruce Simpson. 582cd038dSYoshinobu Inoue * 682cd038dSYoshinobu Inoue * Redistribution and use in source and binary forms, with or without 782cd038dSYoshinobu Inoue * modification, are permitted provided that the following conditions 882cd038dSYoshinobu Inoue * are met: 982cd038dSYoshinobu Inoue * 1. Redistributions of source code must retain the above copyright 1082cd038dSYoshinobu Inoue * notice, this list of conditions and the following disclaimer. 1182cd038dSYoshinobu Inoue * 2. Redistributions in binary form must reproduce the above copyright 1282cd038dSYoshinobu Inoue * notice, this list of conditions and the following disclaimer in the 1382cd038dSYoshinobu Inoue * documentation and/or other materials provided with the distribution. 1433cde130SBruce M Simpson * 3. The name of the author may not be used to endorse or promote 1533cde130SBruce M Simpson * products derived from this software without specific prior written 1633cde130SBruce M Simpson * permission. 1782cd038dSYoshinobu Inoue * 1833cde130SBruce M Simpson * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1982cd038dSYoshinobu Inoue * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2082cd038dSYoshinobu Inoue * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2133cde130SBruce M Simpson * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 2282cd038dSYoshinobu Inoue * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2382cd038dSYoshinobu Inoue * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2482cd038dSYoshinobu Inoue * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2582cd038dSYoshinobu Inoue * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2682cd038dSYoshinobu Inoue * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2782cd038dSYoshinobu Inoue * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2882cd038dSYoshinobu Inoue * SUCH DAMAGE. 2982cd038dSYoshinobu Inoue */ 3082cd038dSYoshinobu Inoue #ifndef _NETINET6_MLD6_VAR_H_ 3182cd038dSYoshinobu Inoue #define _NETINET6_MLD6_VAR_H_ 3282cd038dSYoshinobu Inoue 3333cde130SBruce M Simpson /* 3433cde130SBruce M Simpson * Multicast Listener Discovery (MLD) 3533cde130SBruce M Simpson * implementation-specific definitions. 3633cde130SBruce M Simpson */ 3733cde130SBruce M Simpson 3882cd038dSYoshinobu Inoue /* 3933cde130SBruce M Simpson * MLD per-group states. 4082cd038dSYoshinobu Inoue */ 4133cde130SBruce M Simpson #define MLD_NOT_MEMBER 0 /* Can garbage collect group */ 4233cde130SBruce M Simpson #define MLD_SILENT_MEMBER 1 /* Do not perform MLD for group */ 4333cde130SBruce M Simpson #define MLD_REPORTING_MEMBER 2 /* MLDv1 we are reporter */ 4433cde130SBruce M Simpson #define MLD_IDLE_MEMBER 3 /* MLDv1 we reported last */ 4533cde130SBruce M Simpson #define MLD_LAZY_MEMBER 4 /* MLDv1 other member reporting */ 4633cde130SBruce M Simpson #define MLD_SLEEPING_MEMBER 5 /* MLDv1 start query response */ 4733cde130SBruce M Simpson #define MLD_AWAKENING_MEMBER 6 /* MLDv1 group timer will start */ 4833cde130SBruce M Simpson #define MLD_G_QUERY_PENDING_MEMBER 7 /* MLDv2 group query pending */ 4933cde130SBruce M Simpson #define MLD_SG_QUERY_PENDING_MEMBER 8 /* MLDv2 source query pending */ 5033cde130SBruce M Simpson #define MLD_LEAVING_MEMBER 9 /* MLDv2 dying gasp (pending last */ 5133cde130SBruce M Simpson /* retransmission of INCLUDE {}) */ 5282cd038dSYoshinobu Inoue 5333cde130SBruce M Simpson /* 5433cde130SBruce M Simpson * MLD version tag. 5533cde130SBruce M Simpson */ 5633cde130SBruce M Simpson #define MLD_VERSION_NONE 0 /* Invalid */ 5733cde130SBruce M Simpson #define MLD_VERSION_1 1 5833cde130SBruce M Simpson #define MLD_VERSION_2 2 /* Default */ 5933cde130SBruce M Simpson 6033cde130SBruce M Simpson /* 6133cde130SBruce M Simpson * MLDv2 protocol control variables. 6233cde130SBruce M Simpson */ 6333cde130SBruce M Simpson #define MLD_RV_INIT 2 /* Robustness Variable */ 6433cde130SBruce M Simpson #define MLD_RV_MIN 1 6533cde130SBruce M Simpson #define MLD_RV_MAX 7 6633cde130SBruce M Simpson 6733cde130SBruce M Simpson #define MLD_QI_INIT 125 /* Query Interval (s) */ 6833cde130SBruce M Simpson #define MLD_QI_MIN 1 6933cde130SBruce M Simpson #define MLD_QI_MAX 255 7033cde130SBruce M Simpson 7133cde130SBruce M Simpson #define MLD_QRI_INIT 10 /* Query Response Interval (s) */ 7233cde130SBruce M Simpson #define MLD_QRI_MIN 1 7333cde130SBruce M Simpson #define MLD_QRI_MAX 255 7433cde130SBruce M Simpson 7533cde130SBruce M Simpson #define MLD_URI_INIT 3 /* Unsolicited Report Interval (s) */ 7633cde130SBruce M Simpson #define MLD_URI_MIN 0 7733cde130SBruce M Simpson #define MLD_URI_MAX 10 7833cde130SBruce M Simpson 7933cde130SBruce M Simpson #define MLD_MAX_GS_SOURCES 256 /* # of sources in rx GS query */ 8033cde130SBruce M Simpson #define MLD_MAX_G_GS_PACKETS 8 /* # of packets to answer G/GS */ 8133cde130SBruce M Simpson #define MLD_MAX_STATE_CHANGE_PACKETS 8 /* # of packets per state change */ 8233cde130SBruce M Simpson #define MLD_MAX_RESPONSE_PACKETS 16 /* # of packets for general query */ 8333cde130SBruce M Simpson #define MLD_MAX_RESPONSE_BURST 4 /* # of responses to send at once */ 84*b730de8bSGleb Smirnoff #define MLD_RESPONSE_BURST_INTERVAL (MLD_FASTHZ / 2) /* 500ms */ 8533cde130SBruce M Simpson 8633cde130SBruce M Simpson /* 8733cde130SBruce M Simpson * MLD-specific mbuf flags. 8833cde130SBruce M Simpson */ 8933cde130SBruce M Simpson #define M_MLDV1 M_PROTO1 /* Packet is MLDv1 */ 9033cde130SBruce M Simpson #define M_GROUPREC M_PROTO3 /* mbuf chain is a group record */ 9133cde130SBruce M Simpson 9233cde130SBruce M Simpson /* 9333cde130SBruce M Simpson * Leading space for MLDv2 reports inside MTU. 9433cde130SBruce M Simpson * 9533cde130SBruce M Simpson * NOTE: This differs from IGMPv3 significantly. KAME IPv6 requires 9633cde130SBruce M Simpson * that a fully formed mbuf chain *without* the Router Alert option 9733cde130SBruce M Simpson * is passed to ip6_output(), however we must account for it in the 9833cde130SBruce M Simpson * MTU if we need to split an MLDv2 report into several packets. 9933cde130SBruce M Simpson * 10033cde130SBruce M Simpson * We now put the MLDv2 report header in the initial mbuf containing 10133cde130SBruce M Simpson * the IPv6 header. 10233cde130SBruce M Simpson */ 10333cde130SBruce M Simpson #define MLD_MTUSPACE (sizeof(struct ip6_hdr) + sizeof(struct mld_raopt) + \ 10433cde130SBruce M Simpson sizeof(struct icmp6_hdr)) 10533cde130SBruce M Simpson 10633cde130SBruce M Simpson /* 1079e62a5a3SGleb Smirnoff * Structure returned by net.inet6.mld.ifinfo. 1089e62a5a3SGleb Smirnoff */ 1099e62a5a3SGleb Smirnoff struct mld_ifinfo { 1109e62a5a3SGleb Smirnoff uint32_t mli_version; /* MLDv1 Host Compatibility Mode */ 1119e62a5a3SGleb Smirnoff uint32_t mli_v1_timer; /* MLDv1 Querier Present timer (s) */ 1129e62a5a3SGleb Smirnoff uint32_t mli_v2_timer; /* MLDv2 General Query (interface) timer (s)*/ 1139e62a5a3SGleb Smirnoff uint32_t mli_flags; /* MLD per-interface flags */ 1149e62a5a3SGleb Smirnoff #define MLIF_SILENT 0x00000001 /* Do not use MLD on this ifp */ 1159e62a5a3SGleb Smirnoff #define MLIF_USEALLOW 0x00000002 /* Use ALLOW/BLOCK for joins/leaves */ 1169e62a5a3SGleb Smirnoff uint32_t mli_rv; /* MLDv2 Robustness Variable */ 1179e62a5a3SGleb Smirnoff uint32_t mli_qi; /* MLDv2 Query Interval (s) */ 1189e62a5a3SGleb Smirnoff uint32_t mli_qri; /* MLDv2 Query Response Interval (s) */ 1199e62a5a3SGleb Smirnoff uint32_t mli_uri; /* MLDv2 Unsolicited Report Interval (s) */ 1209e62a5a3SGleb Smirnoff }; 1219e62a5a3SGleb Smirnoff 1229e62a5a3SGleb Smirnoff #ifdef _KERNEL 1239e62a5a3SGleb Smirnoff /* 1249e62a5a3SGleb Smirnoff * Per-link MLD state. 1259e62a5a3SGleb Smirnoff */ 1269e62a5a3SGleb Smirnoff struct mld_ifsoftc { 1279e62a5a3SGleb Smirnoff LIST_ENTRY(mld_ifsoftc) mli_link; 1289e62a5a3SGleb Smirnoff struct ifnet *mli_ifp; /* interface this instance belongs to */ 1299e62a5a3SGleb Smirnoff uint32_t mli_version; /* MLDv1 Host Compatibility Mode */ 1309e62a5a3SGleb Smirnoff uint32_t mli_v1_timer; /* MLDv1 Querier Present timer (s) */ 1319e62a5a3SGleb Smirnoff uint32_t mli_v2_timer; /* MLDv2 General Query (interface) timer (s)*/ 1329e62a5a3SGleb Smirnoff uint32_t mli_flags; /* MLD per-interface flags */ 1339e62a5a3SGleb Smirnoff uint32_t mli_rv; /* MLDv2 Robustness Variable */ 1349e62a5a3SGleb Smirnoff uint32_t mli_qi; /* MLDv2 Query Interval (s) */ 1359e62a5a3SGleb Smirnoff uint32_t mli_qri; /* MLDv2 Query Response Interval (s) */ 1369e62a5a3SGleb Smirnoff uint32_t mli_uri; /* MLDv2 Unsolicited Report Interval (s) */ 1379e62a5a3SGleb Smirnoff struct mbufq mli_gq; /* queue of general query responses */ 1389e62a5a3SGleb Smirnoff }; 1399e62a5a3SGleb Smirnoff 1409e62a5a3SGleb Smirnoff #define MLD_RANDOM_DELAY(X) (arc4random() % (X) + 1) 1419e62a5a3SGleb Smirnoff #define MLD_MAX_STATE_CHANGES 24 /* Max pending changes per group */ 1429e62a5a3SGleb Smirnoff 1439e62a5a3SGleb Smirnoff /* 14433cde130SBruce M Simpson * Subsystem lock macros. 14533cde130SBruce M Simpson * The MLD lock is only taken with MLD. Currently it is system-wide. 14633cde130SBruce M Simpson * VIMAGE: The lock could be pushed to per-VIMAGE granularity in future. 14733cde130SBruce M Simpson */ 14833cde130SBruce M Simpson #define MLD_LOCK_INIT() mtx_init(&mld_mtx, "mld_mtx", NULL, MTX_DEF) 14933cde130SBruce M Simpson #define MLD_LOCK_DESTROY() mtx_destroy(&mld_mtx) 15033cde130SBruce M Simpson #define MLD_LOCK() mtx_lock(&mld_mtx) 15133cde130SBruce M Simpson #define MLD_LOCK_ASSERT() mtx_assert(&mld_mtx, MA_OWNED) 15233cde130SBruce M Simpson #define MLD_UNLOCK() mtx_unlock(&mld_mtx) 15333cde130SBruce M Simpson #define MLD_UNLOCK_ASSERT() mtx_assert(&mld_mtx, MA_NOTOWNED) 15433cde130SBruce M Simpson 15533cde130SBruce M Simpson /* 15633cde130SBruce M Simpson * Per-link MLD context. 15733cde130SBruce M Simpson */ 15833cde130SBruce M Simpson #define MLD_IFINFO(ifp) \ 15933cde130SBruce M Simpson (((struct in6_ifextra *)(ifp)->if_afdata[AF_INET6])->mld_ifinfo) 16033cde130SBruce M Simpson 1612cd6ad76SHans Petter Selasky struct in6_multi_head; 16233cde130SBruce M Simpson int mld_change_state(struct in6_multi *, const int); 1639e62a5a3SGleb Smirnoff struct mld_ifsoftc * 16433cde130SBruce M Simpson mld_domifattach(struct ifnet *); 16533cde130SBruce M Simpson void mld_domifdetach(struct ifnet *); 1662cd6ad76SHans Petter Selasky void mld_ifdetach(struct ifnet *, struct in6_multi_head *); 16732af08ecSBjoern A. Zeeb int mld_input(struct mbuf **, int, int); 168*b730de8bSGleb Smirnoff 169*b730de8bSGleb Smirnoff #define MLD_SLOWHZ 2 /* 2 slow timeouts per second */ 170*b730de8bSGleb Smirnoff #define MLD_FASTHZ 5 /* 5 fast timeouts per second */ 17133cde130SBruce M Simpson 17233cde130SBruce M Simpson #ifdef SYSCTL_DECL 17333cde130SBruce M Simpson SYSCTL_DECL(_net_inet6_mld); 17433cde130SBruce M Simpson #endif 17533cde130SBruce M Simpson 17682cd038dSYoshinobu Inoue #endif /* _KERNEL */ 17782cd038dSYoshinobu Inoue 17882cd038dSYoshinobu Inoue #endif /* _NETINET6_MLD6_VAR_H_ */ 179