mld6.c revision 194760
1139826Simp/*- 2191672Sbms * Copyright (c) 2009 Bruce Simpson. 353541Sshin * 453541Sshin * Redistribution and use in source and binary forms, with or without 553541Sshin * modification, are permitted provided that the following conditions 653541Sshin * are met: 753541Sshin * 1. Redistributions of source code must retain the above copyright 853541Sshin * notice, this list of conditions and the following disclaimer. 953541Sshin * 2. Redistributions in binary form must reproduce the above copyright 1053541Sshin * notice, this list of conditions and the following disclaimer in the 1153541Sshin * documentation and/or other materials provided with the distribution. 12191672Sbms * 3. The name of the author may not be used to endorse or promote 13191672Sbms * products derived from this software without specific prior written 14191672Sbms * permission. 1553541Sshin * 16191672Sbms * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1753541Sshin * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1853541Sshin * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19191672Sbms * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 2053541Sshin * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2153541Sshin * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2253541Sshin * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2353541Sshin * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2453541Sshin * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2553541Sshin * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2653541Sshin * SUCH DAMAGE. 27174510Sobrien * 28174510Sobrien * $KAME: mld6.c,v 1.27 2001/04/04 05:17:30 itojun Exp $ 2953541Sshin */ 3053541Sshin 31139826Simp/*- 3253541Sshin * Copyright (c) 1988 Stephen Deering. 3353541Sshin * Copyright (c) 1992, 1993 3453541Sshin * The Regents of the University of California. All rights reserved. 3553541Sshin * 3653541Sshin * This code is derived from software contributed to Berkeley by 3753541Sshin * Stephen Deering of Stanford University. 3853541Sshin * 3953541Sshin * Redistribution and use in source and binary forms, with or without 4053541Sshin * modification, are permitted provided that the following conditions 4153541Sshin * are met: 4253541Sshin * 1. Redistributions of source code must retain the above copyright 4353541Sshin * notice, this list of conditions and the following disclaimer. 4453541Sshin * 2. Redistributions in binary form must reproduce the above copyright 4553541Sshin * notice, this list of conditions and the following disclaimer in the 4653541Sshin * documentation and/or other materials provided with the distribution. 4753541Sshin * 4. Neither the name of the University nor the names of its contributors 4853541Sshin * may be used to endorse or promote products derived from this software 4953541Sshin * without specific prior written permission. 5053541Sshin * 5153541Sshin * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 5253541Sshin * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 5353541Sshin * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 5453541Sshin * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 5553541Sshin * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 5653541Sshin * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 5753541Sshin * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 5853541Sshin * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 5953541Sshin * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 6053541Sshin * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 6153541Sshin * SUCH DAMAGE. 6253541Sshin * 6353541Sshin * @(#)igmp.c 8.1 (Berkeley) 7/19/93 6453541Sshin */ 6553541Sshin 66174510Sobrien#include <sys/cdefs.h> 67174510Sobrien__FBSDID("$FreeBSD: head/sys/netinet6/mld6.c 194760 2009-06-23 20:19:09Z rwatson $"); 68174510Sobrien 6962587Sitojun#include "opt_inet.h" 7062587Sitojun#include "opt_inet6.h" 7155009Sshin 7253541Sshin#include <sys/param.h> 7353541Sshin#include <sys/systm.h> 7453541Sshin#include <sys/mbuf.h> 7553541Sshin#include <sys/socket.h> 7653541Sshin#include <sys/protosw.h> 77191672Sbms#include <sys/sysctl.h> 78151539Ssuz#include <sys/kernel.h> 79151539Ssuz#include <sys/callout.h> 80126603Sume#include <sys/malloc.h> 81191672Sbms#include <sys/module.h> 82181803Sbz#include <sys/vimage.h> 8353541Sshin 8453541Sshin#include <net/if.h> 85191672Sbms#include <net/route.h> 86191672Sbms#include <net/vnet.h> 8753541Sshin 8853541Sshin#include <netinet/in.h> 8953541Sshin#include <netinet/in_var.h> 90151539Ssuz#include <netinet6/in6_var.h> 9162587Sitojun#include <netinet/ip6.h> 9253541Sshin#include <netinet6/ip6_var.h> 93148385Sume#include <netinet6/scope6_var.h> 9462587Sitojun#include <netinet/icmp6.h> 95191672Sbms#include <netinet6/mld6.h> 9653541Sshin#include <netinet6/mld6_var.h> 97191672Sbms#include <netinet/vinet.h> 98185571Sbz#include <netinet6/vinet6.h> 9953541Sshin 100191672Sbms#include <security/mac/mac_framework.h> 101191672Sbms 102191672Sbms#ifndef KTR_MLD 103191672Sbms#define KTR_MLD KTR_INET6 104191672Sbms#endif 105191672Sbms 106191672Sbmsstatic struct mld_ifinfo * 107191672Sbms mli_alloc_locked(struct ifnet *); 108191672Sbmsstatic void mli_delete_locked(const struct ifnet *); 109191672Sbmsstatic void mld_dispatch_packet(struct mbuf *); 110191672Sbmsstatic void mld_dispatch_queue(struct ifqueue *, int); 111191672Sbmsstatic void mld_final_leave(struct in6_multi *, struct mld_ifinfo *); 112191672Sbmsstatic void mld_fasttimo_vnet(void); 113191672Sbmsstatic int mld_handle_state_change(struct in6_multi *, 114191672Sbms struct mld_ifinfo *); 115191672Sbmsstatic int mld_initial_join(struct in6_multi *, struct mld_ifinfo *, 116191672Sbms const int); 117191672Sbms#ifdef KTR 118191672Sbmsstatic char * mld_rec_type_to_str(const int); 119191672Sbms#endif 120191672Sbmsstatic void mld_set_version(struct mld_ifinfo *, const int); 121191672Sbmsstatic void mld_slowtimo_vnet(void); 122191672Sbmsstatic void mld_sysinit(void); 123191672Sbmsstatic void mld_sysuninit(void); 124191672Sbmsstatic int mld_v1_input_query(struct ifnet *, const struct ip6_hdr *, 125192923Sbms /*const*/ struct mld_hdr *); 126191672Sbmsstatic int mld_v1_input_report(struct ifnet *, const struct ip6_hdr *, 127192923Sbms /*const*/ struct mld_hdr *); 128191672Sbmsstatic void mld_v1_process_group_timer(struct in6_multi *, const int); 129191672Sbmsstatic void mld_v1_process_querier_timers(struct mld_ifinfo *); 130191672Sbmsstatic int mld_v1_transmit_report(struct in6_multi *, const int); 131191672Sbmsstatic void mld_v1_update_group(struct in6_multi *, const int); 132191672Sbmsstatic void mld_v2_cancel_link_timers(struct mld_ifinfo *); 133191672Sbmsstatic void mld_v2_dispatch_general_query(struct mld_ifinfo *); 134191672Sbmsstatic struct mbuf * 135191672Sbms mld_v2_encap_report(struct ifnet *, struct mbuf *); 136191672Sbmsstatic int mld_v2_enqueue_filter_change(struct ifqueue *, 137191672Sbms struct in6_multi *); 138191672Sbmsstatic int mld_v2_enqueue_group_record(struct ifqueue *, 139191672Sbms struct in6_multi *, const int, const int, const int); 140191672Sbmsstatic int mld_v2_input_query(struct ifnet *, const struct ip6_hdr *, 141191672Sbms struct mbuf *, const int, const int); 142191672Sbmsstatic int mld_v2_merge_state_changes(struct in6_multi *, 143191672Sbms struct ifqueue *); 144191672Sbmsstatic void mld_v2_process_group_timers(struct mld_ifinfo *, 145191672Sbms struct ifqueue *, struct ifqueue *, 146191672Sbms struct in6_multi *, const int); 147191672Sbmsstatic int mld_v2_process_group_query(struct in6_multi *, 148191672Sbms struct mld_ifinfo *mli, int, struct mbuf *, const int); 149191672Sbmsstatic int sysctl_mld_gsr(SYSCTL_HANDLER_ARGS); 150191672Sbmsstatic int sysctl_mld_ifinfo(SYSCTL_HANDLER_ARGS); 151191672Sbms 152191672Sbmsstatic vnet_attach_fn vnet_mld_iattach; 153191672Sbmsstatic vnet_detach_fn vnet_mld_idetach; 154191672Sbms 15553541Sshin/* 156191672Sbms * Normative references: RFC 2710, RFC 3590, RFC 3810. 157191672Sbms * 158191672Sbms * Locking: 159191672Sbms * * The MLD subsystem lock ends up being system-wide for the moment, 160191672Sbms * but could be per-VIMAGE later on. 161191672Sbms * * The permitted lock order is: IN6_MULTI_LOCK, MLD_LOCK, IF_ADDR_LOCK. 162191672Sbms * Any may be taken independently; if any are held at the same 163191672Sbms * time, the above lock order must be followed. 164191672Sbms * * IN6_MULTI_LOCK covers in_multi. 165191672Sbms * * MLD_LOCK covers per-link state and any global variables in this file. 166191672Sbms * * IF_ADDR_LOCK covers if_multiaddrs, which is used for a variety of 167191672Sbms * per-link state iterators. 168191672Sbms * 169191672Sbms * XXX LOR PREVENTION 170191672Sbms * A special case for IPv6 is the in6_setscope() routine. ip6_output() 171191672Sbms * will not accept an ifp; it wants an embedded scope ID, unlike 172191672Sbms * ip_output(), which happily takes the ifp given to it. The embedded 173191672Sbms * scope ID is only used by MLD to select the outgoing interface. 174191672Sbms * 175191672Sbms * During interface attach and detach, MLD will take MLD_LOCK *after* 176191672Sbms * the IF_AFDATA_LOCK. 177191672Sbms * As in6_setscope() takes IF_AFDATA_LOCK then SCOPE_LOCK, we can't call 178191672Sbms * it with MLD_LOCK held without triggering an LOR. A netisr with indirect 179191672Sbms * dispatch could work around this, but we'd rather not do that, as it 180191672Sbms * can introduce other races. 181191672Sbms * 182191672Sbms * As such, we exploit the fact that the scope ID is just the interface 183191672Sbms * index, and embed it in the IPv6 destination address accordingly. 184191672Sbms * This is potentially NOT VALID for MLDv1 reports, as they 185191672Sbms * are always sent to the multicast group itself; as MLDv2 186191672Sbms * reports are always sent to ff02::16, this is not an issue 187191672Sbms * when MLDv2 is in use. 188191672Sbms * 189191672Sbms * This does not however eliminate the LOR when ip6_output() itself 190191672Sbms * calls in6_setscope() internally whilst MLD_LOCK is held. This will 191191672Sbms * trigger a LOR warning in WITNESS when the ifnet is detached. 192191672Sbms * 193191672Sbms * The right answer is probably to make IF_AFDATA_LOCK an rwlock, given 194191672Sbms * how it's used across the network stack. Here we're simply exploiting 195191672Sbms * the fact that MLD runs at a similar layer in the stack to scope6.c. 196191672Sbms * 197191672Sbms * VIMAGE: 198191672Sbms * * Each in6_multi corresponds to an ifp, and each ifp corresponds 199191672Sbms * to a vnet in ifp->if_vnet. 20053541Sshin */ 201191672Sbmsstatic struct mtx mld_mtx; 202191672SbmsMALLOC_DEFINE(M_MLD, "mld", "mld state"); 20353541Sshin 204191672Sbms#define MLD_EMBEDSCOPE(pin6, zoneid) \ 205191672Sbms (pin6)->s6_addr16[1] = htons((zoneid) & 0xFFFF) 206191672Sbms 20753541Sshin/* 208191672Sbms * VIMAGE-wide globals. 20953541Sshin */ 210185088Szec#ifdef VIMAGE_GLOBALS 211191672Sbmsstruct timeval mld_gsrdelay; 212191672SbmsLIST_HEAD(, mld_ifinfo) mli_head; 213191672Sbmsint interface_timers_running6; 214191672Sbmsint state_change_timers_running6; 215191672Sbmsint current_state_timers_running6; 216191672Sbms#endif /* VIMAGE_GLOBALS */ 21753541Sshin 218191672SbmsSYSCTL_DECL(_net_inet6); /* Note: Not in any common header. */ 21953541Sshin 220191672SbmsSYSCTL_NODE(_net_inet6, OID_AUTO, mld, CTLFLAG_RW, 0, 221191672Sbms "IPv6 Multicast Listener Discovery"); 222191672Sbms 223191672Sbms/* 224191672Sbms * Virtualized sysctls. 225191672Sbms */ 226191672SbmsSYSCTL_V_PROC(V_NET, vnet_inet6, _net_inet6_mld, OID_AUTO, gsrdelay, 227191672Sbms CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE, mld_gsrdelay.tv_sec, 0, 228191672Sbms sysctl_mld_gsr, "I", 229191672Sbms "Rate limit for MLDv2 Group-and-Source queries in seconds"); 230191672Sbms 231191672Sbms/* 232191672Sbms * Non-virtualized sysctls. 233191672Sbms */ 234191672SbmsSYSCTL_NODE(_net_inet6_mld, OID_AUTO, ifinfo, CTLFLAG_RD | CTLFLAG_MPSAFE, 235191672Sbms sysctl_mld_ifinfo, "Per-interface MLDv2 state"); 236191672Sbms 237192923Sbmsstatic int mld_v1enable = 1; 238192923SbmsSYSCTL_INT(_net_inet6_mld, OID_AUTO, v1enable, CTLFLAG_RW, 239192923Sbms &mld_v1enable, 0, "Enable fallback to MLDv1"); 240192923SbmsTUNABLE_INT("net.inet6.mld.v1enable", &mld_v1enable); 241192923Sbms 242191672Sbms/* 243191672Sbms * Packed Router Alert option structure declaration. 244191672Sbms */ 245191672Sbmsstruct mld_raopt { 246191672Sbms struct ip6_hbh hbh; 247191672Sbms struct ip6_opt pad; 248191672Sbms struct ip6_opt_router ra; 249191672Sbms} __packed; 250191672Sbms 251191672Sbms/* 252191672Sbms * Router Alert hop-by-hop option header. 253191672Sbms */ 254191672Sbmsstatic struct mld_raopt mld_ra = { 255191672Sbms .hbh = { 0, 0 }, 256191672Sbms .pad = { .ip6o_type = IP6OPT_PADN, 0 }, 257191672Sbms .ra = { 258191672Sbms .ip6or_type = IP6OPT_ROUTER_ALERT, 259191672Sbms .ip6or_len = IP6OPT_RTALERT_LEN - 2, 260191672Sbms .ip6or_value[0] = ((IP6OPT_RTALERT_MLD >> 8) & 0xFF), 261191672Sbms .ip6or_value[1] = (IP6OPT_RTALERT_MLD & 0xFF) 262191672Sbms } 263191672Sbms}; 264191672Sbmsstatic struct ip6_pktopts mld_po; 265191672Sbms 266191672Sbmsstatic __inline void 267191672Sbmsmld_save_context(struct mbuf *m, struct ifnet *ifp) 26853541Sshin{ 269191672Sbms 270191672Sbms#ifdef VIMAGE 271191672Sbms m->m_pkthdr.header = ifp->if_vnet; 272191672Sbms#endif /* VIMAGE */ 273191672Sbms m->m_pkthdr.flowid = ifp->if_index; 274191672Sbms} 275191672Sbms 276191672Sbmsstatic __inline void 277191672Sbmsmld_scrub_context(struct mbuf *m) 278191672Sbms{ 279191672Sbms 280191672Sbms m->m_pkthdr.header = NULL; 281191672Sbms m->m_pkthdr.flowid = 0; 282191672Sbms} 283191672Sbms 284191672Sbms/* 285191672Sbms * Restore context from a queued output chain. 286191672Sbms * Return saved ifindex. 287191672Sbms * 288191672Sbms * VIMAGE: The assertion is there to make sure that we 289191672Sbms * actually called CURVNET_SET() with what's in the mbuf chain. 290191672Sbms */ 291191672Sbmsstatic __inline uint32_t 292191672Sbmsmld_restore_context(struct mbuf *m) 293191672Sbms{ 294191672Sbms 295191672Sbms#if defined(VIMAGE) && defined(INVARIANTS) 296191846Szec KASSERT(curvnet == m->m_pkthdr.header, 297191672Sbms ("%s: called when curvnet was not restored", __func__)); 298191672Sbms#endif 299191672Sbms return (m->m_pkthdr.flowid); 300191672Sbms} 301191672Sbms 302191672Sbms/* 303191672Sbms * Retrieve or set threshold between group-source queries in seconds. 304191672Sbms * 305191672Sbms * VIMAGE: Assume curvnet set by caller. 306191672Sbms * SMPng: NOTE: Serialized by MLD lock. 307191672Sbms */ 308191672Sbmsstatic int 309191672Sbmssysctl_mld_gsr(SYSCTL_HANDLER_ARGS) 310191672Sbms{ 311183550Szec INIT_VNET_INET6(curvnet); 312191672Sbms int error; 313191672Sbms int i; 31453541Sshin 315191672Sbms error = sysctl_wire_old_buffer(req, sizeof(int)); 316191672Sbms if (error) 317191672Sbms return (error); 31853541Sshin 319191672Sbms MLD_LOCK(); 32053541Sshin 321191672Sbms i = V_mld_gsrdelay.tv_sec; 322191672Sbms 323191672Sbms error = sysctl_handle_int(oidp, &i, 0, req); 324191672Sbms if (error || !req->newptr) 325191672Sbms goto out_locked; 326191672Sbms 327191672Sbms if (i < -1 || i >= 60) { 328191672Sbms error = EINVAL; 329191672Sbms goto out_locked; 330191672Sbms } 331191672Sbms 332191672Sbms CTR2(KTR_MLD, "change mld_gsrdelay from %d to %d", 333191672Sbms V_mld_gsrdelay.tv_sec, i); 334191672Sbms V_mld_gsrdelay.tv_sec = i; 335191672Sbms 336191672Sbmsout_locked: 337191672Sbms MLD_UNLOCK(); 338191672Sbms return (error); 33953541Sshin} 34053541Sshin 341191672Sbms/* 342191672Sbms * Expose struct mld_ifinfo to userland, keyed by ifindex. 343191672Sbms * For use by ifmcstat(8). 344191672Sbms * 345191672Sbms * SMPng: NOTE: Does an unlocked ifindex space read. 346191672Sbms * VIMAGE: Assume curvnet set by caller. The node handler itself 347191672Sbms * is not directly virtualized. 348191672Sbms */ 349191672Sbmsstatic int 350191672Sbmssysctl_mld_ifinfo(SYSCTL_HANDLER_ARGS) 351151539Ssuz{ 352191672Sbms INIT_VNET_NET(curvnet); 353191672Sbms INIT_VNET_INET6(curvnet); 354191672Sbms int *name; 355191672Sbms int error; 356191672Sbms u_int namelen; 357191672Sbms struct ifnet *ifp; 358191672Sbms struct mld_ifinfo *mli; 359151539Ssuz 360191672Sbms name = (int *)arg1; 361191672Sbms namelen = arg2; 362191672Sbms 363191672Sbms if (req->newptr != NULL) 364191672Sbms return (EPERM); 365191672Sbms 366191672Sbms if (namelen != 1) 367191672Sbms return (EINVAL); 368191672Sbms 369191672Sbms error = sysctl_wire_old_buffer(req, sizeof(struct mld_ifinfo)); 370191672Sbms if (error) 371191672Sbms return (error); 372191672Sbms 373191672Sbms IN6_MULTI_LOCK(); 374191672Sbms MLD_LOCK(); 375191672Sbms 376191672Sbms if (name[0] <= 0 || name[0] > V_if_index) { 377191672Sbms error = ENOENT; 378191672Sbms goto out_locked; 379151539Ssuz } 380151539Ssuz 381191672Sbms error = ENOENT; 382191672Sbms 383191672Sbms ifp = ifnet_byindex(name[0]); 384191672Sbms if (ifp == NULL) 385191672Sbms goto out_locked; 386191672Sbms 387191672Sbms LIST_FOREACH(mli, &V_mli_head, mli_link) { 388191672Sbms if (ifp == mli->mli_ifp) { 389191672Sbms error = SYSCTL_OUT(req, mli, 390191672Sbms sizeof(struct mld_ifinfo)); 391191672Sbms break; 392191672Sbms } 393191672Sbms } 394191672Sbms 395191672Sbmsout_locked: 396191672Sbms MLD_UNLOCK(); 397191672Sbms IN6_MULTI_UNLOCK(); 398191672Sbms return (error); 399151539Ssuz} 400151539Ssuz 401191672Sbms/* 402191672Sbms * Dispatch an entire queue of pending packet chains. 403191672Sbms * VIMAGE: Assumes the vnet pointer has been set. 404191672Sbms */ 405151539Ssuzstatic void 406191672Sbmsmld_dispatch_queue(struct ifqueue *ifq, int limit) 407151539Ssuz{ 408191672Sbms struct mbuf *m; 409151539Ssuz 410191672Sbms for (;;) { 411191672Sbms _IF_DEQUEUE(ifq, m); 412191672Sbms if (m == NULL) 413191672Sbms break; 414191672Sbms CTR3(KTR_MLD, "%s: dispatch %p from %p", __func__, ifq, m); 415191672Sbms mld_dispatch_packet(m); 416191672Sbms if (--limit == 0) 417191672Sbms break; 418191672Sbms } 419151539Ssuz} 420151539Ssuz 421191672Sbms/* 422191672Sbms * Filter outgoing MLD report state by group. 423191672Sbms * 424191672Sbms * Reports are ALWAYS suppressed for ALL-HOSTS (ff02::1) 425191672Sbms * and node-local addresses. However, kernel and socket consumers 426191672Sbms * always embed the KAME scope ID in the address provided, so strip it 427191672Sbms * when performing comparison. 428191672Sbms * Note: This is not the same as the *multicast* scope. 429191672Sbms * 430191672Sbms * Return zero if the given group is one for which MLD reports 431191672Sbms * should be suppressed, or non-zero if reports should be issued. 432191672Sbms */ 433191672Sbmsstatic __inline int 434191672Sbmsmld_is_addr_reported(const struct in6_addr *addr) 435151539Ssuz{ 436151539Ssuz 437191672Sbms KASSERT(IN6_IS_ADDR_MULTICAST(addr), ("%s: not multicast", __func__)); 438151539Ssuz 439191672Sbms if (IPV6_ADDR_MC_SCOPE(addr) == IPV6_ADDR_SCOPE_NODELOCAL) 440191672Sbms return (0); 441151539Ssuz 442191672Sbms if (IPV6_ADDR_MC_SCOPE(addr) == IPV6_ADDR_SCOPE_LINKLOCAL) { 443191672Sbms struct in6_addr tmp = *addr; 444191672Sbms in6_clearscope(&tmp); 445191672Sbms if (IN6_ARE_ADDR_EQUAL(&tmp, &in6addr_linklocal_allnodes)) 446191672Sbms return (0); 447151539Ssuz } 448151539Ssuz 449191672Sbms return (1); 450151539Ssuz} 451151539Ssuz 452191672Sbms/* 453191672Sbms * Attach MLD when PF_INET6 is attached to an interface. 454191672Sbms * 455191672Sbms * SMPng: Normally called with IF_AFDATA_LOCK held. 456191672Sbms */ 457191672Sbmsstruct mld_ifinfo * 458191672Sbmsmld_domifattach(struct ifnet *ifp) 459151539Ssuz{ 460191672Sbms struct mld_ifinfo *mli; 461151539Ssuz 462191672Sbms CTR3(KTR_MLD, "%s: called for ifp %p(%s)", 463191672Sbms __func__, ifp, ifp->if_xname); 464151539Ssuz 465191672Sbms MLD_LOCK(); 466191672Sbms 467191672Sbms mli = mli_alloc_locked(ifp); 468191672Sbms if (!(ifp->if_flags & IFF_MULTICAST)) 469191672Sbms mli->mli_flags |= MLIF_SILENT; 470191672Sbms 471191672Sbms MLD_UNLOCK(); 472191672Sbms 473191672Sbms return (mli); 474191672Sbms} 475191672Sbms 476191672Sbms/* 477191672Sbms * VIMAGE: assume curvnet set by caller. 478191672Sbms */ 479191672Sbmsstatic struct mld_ifinfo * 480191672Sbmsmli_alloc_locked(/*const*/ struct ifnet *ifp) 481191672Sbms{ 482191672Sbms INIT_VNET_INET6(ifp->if_vnet); 483191672Sbms struct mld_ifinfo *mli; 484191672Sbms 485191672Sbms MLD_LOCK_ASSERT(); 486191672Sbms 487191672Sbms mli = malloc(sizeof(struct mld_ifinfo), M_MLD, M_NOWAIT|M_ZERO); 488191672Sbms if (mli == NULL) 489191672Sbms goto out; 490191672Sbms 491191672Sbms mli->mli_ifp = ifp; 492191672Sbms mli->mli_version = MLD_VERSION_2; 493191672Sbms mli->mli_flags = 0; 494191672Sbms mli->mli_rv = MLD_RV_INIT; 495191672Sbms mli->mli_qi = MLD_QI_INIT; 496191672Sbms mli->mli_qri = MLD_QRI_INIT; 497191672Sbms mli->mli_uri = MLD_URI_INIT; 498191672Sbms 499191672Sbms SLIST_INIT(&mli->mli_relinmhead); 500191672Sbms 501191672Sbms /* 502191672Sbms * Responses to general queries are subject to bounds. 503191672Sbms */ 504191672Sbms IFQ_SET_MAXLEN(&mli->mli_gq, MLD_MAX_RESPONSE_PACKETS); 505191672Sbms 506191672Sbms LIST_INSERT_HEAD(&V_mli_head, mli, mli_link); 507191672Sbms 508191672Sbms CTR2(KTR_MLD, "allocate mld_ifinfo for ifp %p(%s)", 509191672Sbms ifp, ifp->if_xname); 510191672Sbms 511191672Sbmsout: 512191672Sbms return (mli); 513191672Sbms} 514191672Sbms 515191672Sbms/* 516191672Sbms * Hook for ifdetach. 517191672Sbms * 518191672Sbms * NOTE: Some finalization tasks need to run before the protocol domain 519191672Sbms * is detached, but also before the link layer does its cleanup. 520191672Sbms * Run before link-layer cleanup; cleanup groups, but do not free MLD state. 521191672Sbms * 522191672Sbms * SMPng: Caller must hold IN6_MULTI_LOCK(). 523191672Sbms * Must take IF_ADDR_LOCK() to cover if_multiaddrs iterator. 524191672Sbms * XXX This routine is also bitten by unlocked ifma_protospec access. 525191672Sbms */ 526191672Sbmsvoid 527191672Sbmsmld_ifdetach(struct ifnet *ifp) 528191672Sbms{ 529191672Sbms struct mld_ifinfo *mli; 530191672Sbms struct ifmultiaddr *ifma; 531191672Sbms struct in6_multi *inm, *tinm; 532191672Sbms 533191672Sbms CTR3(KTR_MLD, "%s: called for ifp %p(%s)", __func__, ifp, 534191672Sbms ifp->if_xname); 535191672Sbms 536191672Sbms IN6_MULTI_LOCK_ASSERT(); 537191672Sbms MLD_LOCK(); 538191672Sbms 539191672Sbms mli = MLD_IFINFO(ifp); 540191672Sbms if (mli->mli_version == MLD_VERSION_2) { 541191672Sbms IF_ADDR_LOCK(ifp); 542191672Sbms TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) { 543191672Sbms if (ifma->ifma_addr->sa_family != AF_INET6 || 544191672Sbms ifma->ifma_protospec == NULL) 545191672Sbms continue; 546191672Sbms inm = (struct in6_multi *)ifma->ifma_protospec; 547191672Sbms if (inm->in6m_state == MLD_LEAVING_MEMBER) { 548191672Sbms SLIST_INSERT_HEAD(&mli->mli_relinmhead, 549191672Sbms inm, in6m_nrele); 550191672Sbms } 551191672Sbms in6m_clear_recorded(inm); 552191672Sbms } 553191672Sbms IF_ADDR_UNLOCK(ifp); 554191672Sbms SLIST_FOREACH_SAFE(inm, &mli->mli_relinmhead, in6m_nrele, 555191672Sbms tinm) { 556191672Sbms SLIST_REMOVE_HEAD(&mli->mli_relinmhead, in6m_nrele); 557191672Sbms in6m_release_locked(inm); 558191672Sbms } 559151539Ssuz } 560151539Ssuz 561191672Sbms MLD_UNLOCK(); 562151539Ssuz} 563151539Ssuz 564191672Sbms/* 565191672Sbms * Hook for domifdetach. 566191672Sbms * Runs after link-layer cleanup; free MLD state. 567191672Sbms * 568191672Sbms * SMPng: Normally called with IF_AFDATA_LOCK held. 569191672Sbms */ 57053541Sshinvoid 571191672Sbmsmld_domifdetach(struct ifnet *ifp) 57253541Sshin{ 57353541Sshin 574191672Sbms CTR3(KTR_MLD, "%s: called for ifp %p(%s)", 575191672Sbms __func__, ifp, ifp->if_xname); 576191672Sbms 577191672Sbms MLD_LOCK(); 578191672Sbms mli_delete_locked(ifp); 579191672Sbms MLD_UNLOCK(); 580191672Sbms} 581191672Sbms 582191672Sbmsstatic void 583191672Sbmsmli_delete_locked(const struct ifnet *ifp) 584191672Sbms{ 585191672Sbms INIT_VNET_INET6(ifp->if_vnet); 586191672Sbms struct mld_ifinfo *mli, *tmli; 587191672Sbms 588191672Sbms CTR3(KTR_MLD, "%s: freeing mld_ifinfo for ifp %p(%s)", 589191672Sbms __func__, ifp, ifp->if_xname); 590191672Sbms 591191672Sbms MLD_LOCK_ASSERT(); 592191672Sbms 593191672Sbms LIST_FOREACH_SAFE(mli, &V_mli_head, mli_link, tmli) { 594191672Sbms if (mli->mli_ifp == ifp) { 595191672Sbms /* 596191672Sbms * Free deferred General Query responses. 597191672Sbms */ 598191672Sbms _IF_DRAIN(&mli->mli_gq); 599191672Sbms 600191672Sbms LIST_REMOVE(mli, mli_link); 601191672Sbms 602191672Sbms KASSERT(SLIST_EMPTY(&mli->mli_relinmhead), 603191672Sbms ("%s: there are dangling in_multi references", 604191672Sbms __func__)); 605191672Sbms 606191672Sbms free(mli, M_MLD); 607191672Sbms return; 608191672Sbms } 609191672Sbms } 610191672Sbms#ifdef INVARIANTS 611191672Sbms panic("%s: mld_ifinfo not found for ifp %p\n", __func__, ifp); 612191672Sbms#endif 613191672Sbms} 614191672Sbms 615191672Sbms/* 616191672Sbms * Process a received MLDv1 general or address-specific query. 617191672Sbms * Assumes that the query header has been pulled up to sizeof(mld_hdr). 618192923Sbms * 619192923Sbms * NOTE: Can't be fully const correct as we temporarily embed scope ID in 620192923Sbms * mld_addr. This is OK as we own the mbuf chain. 621191672Sbms */ 622191672Sbmsstatic int 623191672Sbmsmld_v1_input_query(struct ifnet *ifp, const struct ip6_hdr *ip6, 624192923Sbms /*const*/ struct mld_hdr *mld) 625191672Sbms{ 626191672Sbms struct ifmultiaddr *ifma; 627191672Sbms struct mld_ifinfo *mli; 628191672Sbms struct in6_multi *inm; 629192923Sbms int is_general_query; 630191672Sbms uint16_t timer; 631191672Sbms#ifdef KTR 632191672Sbms char ip6tbuf[INET6_ADDRSTRLEN]; 633191672Sbms#endif 634191672Sbms 635192923Sbms is_general_query = 0; 636192923Sbms 637192923Sbms if (!mld_v1enable) { 638192923Sbms CTR3(KTR_MLD, "ignore v1 query %s on ifp %p(%s)", 639192923Sbms ip6_sprintf(ip6tbuf, &mld->mld_addr), 640192923Sbms ifp, ifp->if_xname); 641192923Sbms return (0); 642192923Sbms } 643192923Sbms 644192923Sbms /* 645192923Sbms * RFC3810 Section 6.2: MLD queries must originate from 646192923Sbms * a router's link-local address. 647192923Sbms */ 648192923Sbms if (!IN6_IS_SCOPE_LINKLOCAL(&ip6->ip6_src)) { 649192923Sbms CTR3(KTR_MLD, "ignore v1 query src %s on ifp %p(%s)", 650192923Sbms ip6_sprintf(ip6tbuf, &ip6->ip6_src), 651192923Sbms ifp, ifp->if_xname); 652192923Sbms return (0); 653192923Sbms } 654192923Sbms 655192923Sbms /* 656192923Sbms * Do address field validation upfront before we accept 657192923Sbms * the query. 658192923Sbms */ 659192923Sbms if (IN6_IS_ADDR_UNSPECIFIED(&mld->mld_addr)) { 660192923Sbms /* 661192923Sbms * MLDv1 General Query. 662192923Sbms * If this was not sent to the all-nodes group, ignore it. 663192923Sbms */ 664192923Sbms struct in6_addr dst; 665192923Sbms 666192923Sbms dst = ip6->ip6_dst; 667192923Sbms in6_clearscope(&dst); 668192923Sbms if (!IN6_ARE_ADDR_EQUAL(&dst, &in6addr_linklocal_allnodes)) 669192923Sbms return (EINVAL); 670192923Sbms is_general_query = 1; 671192923Sbms } else { 672192923Sbms /* 673192923Sbms * Embed scope ID of receiving interface in MLD query for 674192923Sbms * lookup whilst we don't hold other locks. 675192923Sbms */ 676192923Sbms in6_setscope(&mld->mld_addr, ifp, NULL); 677192923Sbms } 678192923Sbms 679191672Sbms IN6_MULTI_LOCK(); 680192547Sbms MLD_LOCK(); 681191672Sbms IF_ADDR_LOCK(ifp); 682191672Sbms 68353541Sshin /* 684191672Sbms * Switch to MLDv1 host compatibility mode. 68553541Sshin */ 686192923Sbms mli = MLD_IFINFO(ifp); 687192923Sbms KASSERT(mli != NULL, ("%s: no mld_ifinfo for ifp %p", __func__, ifp)); 688191672Sbms mld_set_version(mli, MLD_VERSION_1); 689191672Sbms 690192923Sbms timer = (ntohs(mld->mld_maxdelay) * PR_FASTHZ) / MLD_TIMER_SCALE; 691191672Sbms if (timer == 0) 692191672Sbms timer = 1; 693191672Sbms 694192923Sbms if (is_general_query) { 695191672Sbms /* 696192923Sbms * For each reporting group joined on this 697192923Sbms * interface, kick the report timer. 698192923Sbms */ 699192923Sbms CTR2(KTR_MLD, "process v1 general query on ifp %p(%s)", 700192923Sbms ifp, ifp->if_xname); 701192923Sbms TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) { 702192923Sbms if (ifma->ifma_addr->sa_family != AF_INET6 || 703192923Sbms ifma->ifma_protospec == NULL) 704192923Sbms continue; 705192923Sbms inm = (struct in6_multi *)ifma->ifma_protospec; 706192923Sbms mld_v1_update_group(inm, timer); 707192923Sbms } 708192923Sbms } else { 709192923Sbms /* 710191672Sbms * MLDv1 Group-Specific Query. 711191672Sbms * If this is a group-specific MLDv1 query, we need only 712191672Sbms * look up the single group to process it. 713191672Sbms */ 714191672Sbms inm = in6m_lookup_locked(ifp, &mld->mld_addr); 715191672Sbms if (inm != NULL) { 716191672Sbms CTR3(KTR_MLD, "process v1 query %s on ifp %p(%s)", 717191672Sbms ip6_sprintf(ip6tbuf, &mld->mld_addr), 718191672Sbms ifp, ifp->if_xname); 719191672Sbms mld_v1_update_group(inm, timer); 720191672Sbms } 721192923Sbms /* XXX Clear embedded scope ID as userland won't expect it. */ 722192923Sbms in6_clearscope(&mld->mld_addr); 72353541Sshin } 724191672Sbms 725192547Sbms IF_ADDR_UNLOCK(ifp); 726191672Sbms MLD_UNLOCK(); 727191672Sbms IN6_MULTI_UNLOCK(); 728191672Sbms 729191672Sbms return (0); 73053541Sshin} 73153541Sshin 732191672Sbms/* 733191672Sbms * Update the report timer on a group in response to an MLDv1 query. 734191672Sbms * 735191672Sbms * If we are becoming the reporting member for this group, start the timer. 736191672Sbms * If we already are the reporting member for this group, and timer is 737191672Sbms * below the threshold, reset it. 738191672Sbms * 739191672Sbms * We may be updating the group for the first time since we switched 740191672Sbms * to MLDv2. If we are, then we must clear any recorded source lists, 741191672Sbms * and transition to REPORTING state; the group timer is overloaded 742191672Sbms * for group and group-source query responses. 743191672Sbms * 744191672Sbms * Unlike MLDv2, the delay per group should be jittered 745191672Sbms * to avoid bursts of MLDv1 reports. 746191672Sbms */ 747191672Sbmsstatic void 748191672Sbmsmld_v1_update_group(struct in6_multi *inm, const int timer) 74953541Sshin{ 750191672Sbms INIT_VNET_INET6(curvnet); 751191672Sbms#ifdef KTR 752191672Sbms char ip6tbuf[INET6_ADDRSTRLEN]; 753191672Sbms#endif 75453541Sshin 755191672Sbms CTR4(KTR_MLD, "%s: %s/%s timer=%d", __func__, 756191672Sbms ip6_sprintf(ip6tbuf, &inm->in6m_addr), 757191672Sbms inm->in6m_ifp->if_xname, timer); 758191672Sbms 759191672Sbms IN6_MULTI_LOCK_ASSERT(); 760191672Sbms 761191672Sbms switch (inm->in6m_state) { 762191672Sbms case MLD_NOT_MEMBER: 763191672Sbms case MLD_SILENT_MEMBER: 764191672Sbms break; 765191672Sbms case MLD_REPORTING_MEMBER: 766191672Sbms if (inm->in6m_timer != 0 && 767191672Sbms inm->in6m_timer <= timer) { 768191672Sbms CTR1(KTR_MLD, "%s: REPORTING and timer running, " 769191672Sbms "skipping.", __func__); 770191672Sbms break; 771191672Sbms } 772191672Sbms /* FALLTHROUGH */ 773191672Sbms case MLD_SG_QUERY_PENDING_MEMBER: 774191672Sbms case MLD_G_QUERY_PENDING_MEMBER: 775191672Sbms case MLD_IDLE_MEMBER: 776191672Sbms case MLD_LAZY_MEMBER: 777191672Sbms case MLD_AWAKENING_MEMBER: 778191672Sbms CTR1(KTR_MLD, "%s: ->REPORTING", __func__); 779191672Sbms inm->in6m_state = MLD_REPORTING_MEMBER; 780191672Sbms inm->in6m_timer = MLD_RANDOM_DELAY(timer); 781191672Sbms V_current_state_timers_running6 = 1; 782191672Sbms break; 783191672Sbms case MLD_SLEEPING_MEMBER: 784191672Sbms CTR1(KTR_MLD, "%s: ->AWAKENING", __func__); 785191672Sbms inm->in6m_state = MLD_AWAKENING_MEMBER; 786191672Sbms break; 787191672Sbms case MLD_LEAVING_MEMBER: 788191672Sbms break; 789148385Sume } 79053541Sshin} 79153541Sshin 792191672Sbms/* 793191672Sbms * Process a received MLDv2 general, group-specific or 794191672Sbms * group-and-source-specific query. 795191672Sbms * 796191672Sbms * Assumes that the query header has been pulled up to sizeof(mldv2_query). 797191672Sbms * 798191672Sbms * Return 0 if successful, otherwise an appropriate error code is returned. 799191672Sbms */ 800191672Sbmsstatic int 801191672Sbmsmld_v2_input_query(struct ifnet *ifp, const struct ip6_hdr *ip6, 802191672Sbms struct mbuf *m, const int off, const int icmp6len) 80353541Sshin{ 804183550Szec INIT_VNET_INET6(curvnet); 805191672Sbms struct mld_ifinfo *mli; 806191672Sbms struct mldv2_query *mld; 807191672Sbms struct in6_multi *inm; 808191672Sbms uint32_t maxdelay, nsrc, qqi; 809192923Sbms int is_general_query; 810191672Sbms uint16_t timer; 811191672Sbms uint8_t qrv; 812192923Sbms#ifdef KTR 813192923Sbms char ip6tbuf[INET6_ADDRSTRLEN]; 814192923Sbms#endif 81553541Sshin 816192923Sbms is_general_query = 0; 817191672Sbms 818192923Sbms /* 819192923Sbms * RFC3810 Section 6.2: MLD queries must originate from 820192923Sbms * a router's link-local address. 821192923Sbms */ 822192923Sbms if (!IN6_IS_SCOPE_LINKLOCAL(&ip6->ip6_src)) { 823192923Sbms CTR3(KTR_MLD, "ignore v1 query src %s on ifp %p(%s)", 824192923Sbms ip6_sprintf(ip6tbuf, &ip6->ip6_src), 825192923Sbms ifp, ifp->if_xname); 826192923Sbms return (0); 827192923Sbms } 828192923Sbms 829192923Sbms CTR2(KTR_MLD, "input v2 query on ifp %p(%s)", ifp, ifp->if_xname); 830192923Sbms 831191672Sbms mld = (struct mldv2_query *)(mtod(m, uint8_t *) + off); 832191672Sbms 833191672Sbms maxdelay = ntohs(mld->mld_maxdelay); /* in 1/10ths of a second */ 834191672Sbms if (maxdelay >= 32678) { 835192923Sbms maxdelay = (MLD_MRC_MANT(maxdelay) | 0x1000) << 836192923Sbms (MLD_MRC_EXP(maxdelay) + 3); 83778064Sume } 838192923Sbms timer = (maxdelay * PR_FASTHZ) / MLD_TIMER_SCALE; 839192923Sbms if (timer == 0) 840192923Sbms timer = 1; 84178064Sume 842191672Sbms qrv = MLD_QRV(mld->mld_misc); 843191672Sbms if (qrv < 2) { 844191672Sbms CTR3(KTR_MLD, "%s: clamping qrv %d to %d", __func__, 845191672Sbms qrv, MLD_RV_INIT); 846191672Sbms qrv = MLD_RV_INIT; 847191672Sbms } 848191672Sbms 849191672Sbms qqi = mld->mld_qqi; 850191672Sbms if (qqi >= 128) { 851191672Sbms qqi = MLD_QQIC_MANT(mld->mld_qqi) << 852191672Sbms (MLD_QQIC_EXP(mld->mld_qqi) + 3); 853191672Sbms } 854191672Sbms 855191672Sbms nsrc = ntohs(mld->mld_numsrc); 856191672Sbms if (nsrc > MLD_MAX_GS_SOURCES) 857191672Sbms return (EMSGSIZE); 858191672Sbms if (icmp6len < sizeof(struct mldv2_query) + 859191672Sbms (nsrc * sizeof(struct in6_addr))) 860191672Sbms return (EMSGSIZE); 861191672Sbms 862192923Sbms /* 863192923Sbms * Do further input validation upfront to avoid resetting timers 864192923Sbms * should we need to discard this query. 865192923Sbms */ 866192923Sbms if (IN6_IS_ADDR_UNSPECIFIED(&mld->mld_addr)) { 867192923Sbms /* 868192923Sbms * General Queries SHOULD be directed to ff02::1. 869192923Sbms * A general query with a source list has undefined 870192923Sbms * behaviour; discard it. 871192923Sbms */ 872192923Sbms struct in6_addr dst; 873192923Sbms 874192923Sbms dst = ip6->ip6_dst; 875192923Sbms in6_clearscope(&dst); 876192923Sbms if (!IN6_ARE_ADDR_EQUAL(&dst, &in6addr_linklocal_allnodes) || 877192923Sbms nsrc > 0) 878192923Sbms return (EINVAL); 879192923Sbms is_general_query = 1; 880192923Sbms } else { 881192923Sbms /* 882192923Sbms * Embed scope ID of receiving interface in MLD query for 883192923Sbms * lookup whilst we don't hold other locks (due to KAME 884192923Sbms * locking lameness). We own this mbuf chain just now. 885192923Sbms */ 886192923Sbms in6_setscope(&mld->mld_addr, ifp, NULL); 887192923Sbms } 888192923Sbms 889191672Sbms IN6_MULTI_LOCK(); 890192547Sbms MLD_LOCK(); 891191672Sbms IF_ADDR_LOCK(ifp); 892191672Sbms 893191672Sbms mli = MLD_IFINFO(ifp); 894191672Sbms KASSERT(mli != NULL, ("%s: no mld_ifinfo for ifp %p", __func__, ifp)); 895191672Sbms 896192923Sbms /* 897192923Sbms * Discard the v2 query if we're in Compatibility Mode. 898192923Sbms * The RFC is pretty clear that hosts need to stay in MLDv1 mode 899192923Sbms * until the Old Version Querier Present timer expires. 900192923Sbms */ 901192923Sbms if (mli->mli_version != MLD_VERSION_2) 902192923Sbms goto out_locked; 903192923Sbms 904191672Sbms mld_set_version(mli, MLD_VERSION_2); 905191672Sbms mli->mli_rv = qrv; 906191672Sbms mli->mli_qi = qqi; 907191672Sbms mli->mli_qri = maxdelay; 908191672Sbms 909192547Sbms CTR4(KTR_MLD, "%s: qrv %d qi %d maxdelay %d", __func__, qrv, qqi, 910191672Sbms maxdelay); 911191672Sbms 912192923Sbms if (is_general_query) { 91353541Sshin /* 914191672Sbms * MLDv2 General Query. 915192547Sbms * 916191672Sbms * Schedule a current-state report on this ifp for 917191672Sbms * all groups, possibly containing source lists. 918192547Sbms * 919191672Sbms * If there is a pending General Query response 920191672Sbms * scheduled earlier than the selected delay, do 921191672Sbms * not schedule any other reports. 922191672Sbms * Otherwise, reset the interface timer. 923191672Sbms */ 924192923Sbms CTR2(KTR_MLD, "process v2 general query on ifp %p(%s)", 925192923Sbms ifp, ifp->if_xname); 926192562Sbms if (mli->mli_v2_timer == 0 || mli->mli_v2_timer >= timer) { 927192562Sbms mli->mli_v2_timer = MLD_RANDOM_DELAY(timer); 928191672Sbms V_interface_timers_running6 = 1; 929191672Sbms } 930191672Sbms } else { 931191672Sbms /* 932191672Sbms * MLDv2 Group-specific or Group-and-source-specific Query. 933191672Sbms * 934191672Sbms * Group-source-specific queries are throttled on 935191672Sbms * a per-group basis to defeat denial-of-service attempts. 936191672Sbms * Queries for groups we are not a member of on this 937191672Sbms * link are simply ignored. 938191672Sbms */ 939191672Sbms inm = in6m_lookup_locked(ifp, &mld->mld_addr); 940191672Sbms if (inm == NULL) 941191672Sbms goto out_locked; 942191672Sbms if (nsrc > 0) { 943191672Sbms if (!ratecheck(&inm->in6m_lastgsrtv, 944191672Sbms &V_mld_gsrdelay)) { 945191672Sbms CTR1(KTR_MLD, "%s: GS query throttled.", 946191672Sbms __func__); 947191672Sbms goto out_locked; 948191672Sbms } 949191672Sbms } 950191672Sbms CTR2(KTR_MLD, "process v2 group query on ifp %p(%s)", 951191672Sbms ifp, ifp->if_xname); 952191672Sbms /* 953191672Sbms * If there is a pending General Query response 954191672Sbms * scheduled sooner than the selected delay, no 955191672Sbms * further report need be scheduled. 956191672Sbms * Otherwise, prepare to respond to the 957191672Sbms * group-specific or group-and-source query. 958191672Sbms */ 959192562Sbms if (mli->mli_v2_timer == 0 || mli->mli_v2_timer >= timer) 960191672Sbms mld_v2_process_group_query(inm, mli, timer, m, off); 961192923Sbms 962192923Sbms /* XXX Clear embedded scope ID as userland won't expect it. */ 963192923Sbms in6_clearscope(&mld->mld_addr); 96453541Sshin } 96553541Sshin 966191672Sbmsout_locked: 967192547Sbms IF_ADDR_UNLOCK(ifp); 968191672Sbms MLD_UNLOCK(); 969191672Sbms IN6_MULTI_UNLOCK(); 970191672Sbms 971191672Sbms return (0); 972191672Sbms} 973191672Sbms 974191672Sbms/* 975191672Sbms * Process a recieved MLDv2 group-specific or group-and-source-specific 976191672Sbms * query. 977191672Sbms * Return <0 if any error occured. Currently this is ignored. 978191672Sbms */ 979191672Sbmsstatic int 980191672Sbmsmld_v2_process_group_query(struct in6_multi *inm, struct mld_ifinfo *mli, 981191672Sbms int timer, struct mbuf *m0, const int off) 982191672Sbms{ 983191672Sbms INIT_VNET_INET6(curvnet); 984191672Sbms struct mldv2_query *mld; 985191672Sbms int retval; 986191672Sbms uint16_t nsrc; 987191672Sbms 988191672Sbms IN6_MULTI_LOCK_ASSERT(); 989191672Sbms MLD_LOCK_ASSERT(); 990191672Sbms 991191672Sbms retval = 0; 992191672Sbms mld = (struct mldv2_query *)(mtod(m0, uint8_t *) + off); 993191672Sbms 994191672Sbms switch (inm->in6m_state) { 995191672Sbms case MLD_NOT_MEMBER: 996191672Sbms case MLD_SILENT_MEMBER: 997191672Sbms case MLD_SLEEPING_MEMBER: 998191672Sbms case MLD_LAZY_MEMBER: 999191672Sbms case MLD_AWAKENING_MEMBER: 1000191672Sbms case MLD_IDLE_MEMBER: 1001191672Sbms case MLD_LEAVING_MEMBER: 1002191672Sbms return (retval); 1003191672Sbms break; 1004191672Sbms case MLD_REPORTING_MEMBER: 1005191672Sbms case MLD_G_QUERY_PENDING_MEMBER: 1006191672Sbms case MLD_SG_QUERY_PENDING_MEMBER: 1007191672Sbms break; 1008191672Sbms } 1009191672Sbms 1010191672Sbms nsrc = ntohs(mld->mld_numsrc); 1011191672Sbms 101253541Sshin /* 1013191672Sbms * Deal with group-specific queries upfront. 1014191672Sbms * If any group query is already pending, purge any recorded 1015191672Sbms * source-list state if it exists, and schedule a query response 1016191672Sbms * for this group-specific query. 1017148385Sume */ 1018191672Sbms if (nsrc == 0) { 1019191672Sbms if (inm->in6m_state == MLD_G_QUERY_PENDING_MEMBER || 1020191672Sbms inm->in6m_state == MLD_SG_QUERY_PENDING_MEMBER) { 1021191672Sbms in6m_clear_recorded(inm); 1022191672Sbms timer = min(inm->in6m_timer, timer); 1023191672Sbms } 1024191672Sbms inm->in6m_state = MLD_G_QUERY_PENDING_MEMBER; 1025191672Sbms inm->in6m_timer = MLD_RANDOM_DELAY(timer); 1026191672Sbms V_current_state_timers_running6 = 1; 1027191672Sbms return (retval); 1028148385Sume } 1029148385Sume 1030148385Sume /* 1031191672Sbms * Deal with the case where a group-and-source-specific query has 1032191672Sbms * been received but a group-specific query is already pending. 103353541Sshin */ 1034191672Sbms if (inm->in6m_state == MLD_G_QUERY_PENDING_MEMBER) { 1035191672Sbms timer = min(inm->in6m_timer, timer); 1036191672Sbms inm->in6m_timer = MLD_RANDOM_DELAY(timer); 1037191672Sbms V_current_state_timers_running6 = 1; 1038191672Sbms return (retval); 1039191672Sbms } 104053541Sshin 1041191672Sbms /* 1042191672Sbms * Finally, deal with the case where a group-and-source-specific 1043191672Sbms * query has been received, where a response to a previous g-s-r 1044191672Sbms * query exists, or none exists. 1045191672Sbms * In this case, we need to parse the source-list which the Querier 1046191672Sbms * has provided us with and check if we have any source list filter 1047191672Sbms * entries at T1 for these sources. If we do not, there is no need 1048191672Sbms * schedule a report and the query may be dropped. 1049191672Sbms * If we do, we must record them and schedule a current-state 1050191672Sbms * report for those sources. 1051191672Sbms */ 1052191672Sbms if (inm->in6m_nsrc > 0) { 1053191672Sbms struct mbuf *m; 1054191672Sbms uint8_t *sp; 1055191672Sbms int i, nrecorded; 1056191672Sbms int soff; 105753541Sshin 1058191672Sbms m = m0; 1059191672Sbms soff = off + sizeof(struct mldv2_query); 1060191672Sbms nrecorded = 0; 1061191672Sbms for (i = 0; i < nsrc; i++) { 1062191672Sbms sp = mtod(m, uint8_t *) + soff; 1063191672Sbms retval = in6m_record_source(inm, 1064191672Sbms (const struct in6_addr *)sp); 1065191672Sbms if (retval < 0) 1066191672Sbms break; 1067191672Sbms nrecorded += retval; 1068191672Sbms soff += sizeof(struct in6_addr); 1069191672Sbms if (soff >= m->m_len) { 1070191672Sbms soff = soff - m->m_len; 1071191672Sbms m = m->m_next; 1072191672Sbms if (m == NULL) 1073191672Sbms break; 1074191672Sbms } 1075148385Sume } 1076191672Sbms if (nrecorded > 0) { 1077191672Sbms CTR1(KTR_MLD, 1078191672Sbms "%s: schedule response to SG query", __func__); 1079191672Sbms inm->in6m_state = MLD_SG_QUERY_PENDING_MEMBER; 1080191672Sbms inm->in6m_timer = MLD_RANDOM_DELAY(timer); 1081191672Sbms V_current_state_timers_running6 = 1; 1082191672Sbms } 1083191672Sbms } 1084148385Sume 1085191672Sbms return (retval); 1086191672Sbms} 1087191672Sbms 1088191672Sbms/* 1089191672Sbms * Process a received MLDv1 host membership report. 1090191672Sbms * Assumes mld points to mld_hdr in pulled up mbuf chain. 1091192923Sbms * 1092192923Sbms * NOTE: Can't be fully const correct as we temporarily embed scope ID in 1093192923Sbms * mld_addr. This is OK as we own the mbuf chain. 1094191672Sbms */ 1095191672Sbmsstatic int 1096191672Sbmsmld_v1_input_report(struct ifnet *ifp, const struct ip6_hdr *ip6, 1097192923Sbms /*const*/ struct mld_hdr *mld) 1098191672Sbms{ 1099192923Sbms struct in6_addr src, dst; 1100191672Sbms struct in6_ifaddr *ia; 1101191672Sbms struct in6_multi *inm; 1102191672Sbms#ifdef KTR 1103191672Sbms char ip6tbuf[INET6_ADDRSTRLEN]; 1104191672Sbms#endif 1105191672Sbms 1106192923Sbms if (!mld_v1enable) { 1107192923Sbms CTR3(KTR_MLD, "ignore v1 report %s on ifp %p(%s)", 1108192923Sbms ip6_sprintf(ip6tbuf, &mld->mld_addr), 1109192923Sbms ifp, ifp->if_xname); 1110192923Sbms return (0); 1111192923Sbms } 1112192923Sbms 1113191672Sbms if (ifp->if_flags & IFF_LOOPBACK) 1114191672Sbms return (0); 1115192923Sbms 1116192923Sbms /* 1117192923Sbms * MLDv1 reports must originate from a host's link-local address, 1118192923Sbms * or the unspecified address (when booting). 1119192923Sbms */ 1120192923Sbms src = ip6->ip6_src; 1121192923Sbms in6_clearscope(&src); 1122192923Sbms if (!IN6_IS_SCOPE_LINKLOCAL(&src) && !IN6_IS_ADDR_UNSPECIFIED(&src)) { 1123192923Sbms CTR3(KTR_MLD, "ignore v1 query src %s on ifp %p(%s)", 1124192923Sbms ip6_sprintf(ip6tbuf, &ip6->ip6_src), 1125192923Sbms ifp, ifp->if_xname); 1126192547Sbms return (EINVAL); 1127192923Sbms } 1128191672Sbms 1129192923Sbms /* 1130192923Sbms * RFC2710 Section 4: MLDv1 reports must pertain to a multicast 1131192923Sbms * group, and must be directed to the group itself. 1132192923Sbms */ 1133192547Sbms dst = ip6->ip6_dst; 1134192547Sbms in6_clearscope(&dst); 1135192923Sbms if (!IN6_IS_ADDR_MULTICAST(&mld->mld_addr) || 1136192923Sbms !IN6_ARE_ADDR_EQUAL(&mld->mld_addr, &dst)) { 1137192923Sbms CTR3(KTR_MLD, "ignore v1 query dst %s on ifp %p(%s)", 1138192923Sbms ip6_sprintf(ip6tbuf, &ip6->ip6_dst), 1139192923Sbms ifp, ifp->if_xname); 1140191672Sbms return (EINVAL); 1141192923Sbms } 1142191672Sbms 1143191672Sbms /* 1144191672Sbms * Make sure we don't hear our own membership report, as fast 1145191672Sbms * leave requires knowing that we are the only member of a 1146191672Sbms * group. Assume we used the link-local address if available, 1147191672Sbms * otherwise look for ::. 1148192547Sbms * 1149192547Sbms * XXX Note that scope ID comparison is needed for the address 1150192547Sbms * returned by in6ifa_ifpforlinklocal(), but SHOULD NOT be 1151192547Sbms * performed for the on-wire address. 1152191672Sbms */ 1153191672Sbms ia = in6ifa_ifpforlinklocal(ifp, IN6_IFF_NOTREADY|IN6_IFF_ANYCAST); 1154191672Sbms if ((ia && IN6_ARE_ADDR_EQUAL(&ip6->ip6_src, IA6_IN6(ia))) || 1155194760Srwatson (ia == NULL && IN6_IS_ADDR_UNSPECIFIED(&src))) { 1156194760Srwatson if (ia != NULL) 1157194760Srwatson ifa_free(&ia->ia_ifa); 1158191672Sbms return (0); 1159194760Srwatson } 1160194760Srwatson if (ia != NULL) 1161194760Srwatson ifa_free(&ia->ia_ifa); 1162191672Sbms 1163191672Sbms CTR3(KTR_MLD, "process v1 report %s on ifp %p(%s)", 1164191672Sbms ip6_sprintf(ip6tbuf, &mld->mld_addr), ifp, ifp->if_xname); 1165191672Sbms 1166192923Sbms /* 1167192923Sbms * Embed scope ID of receiving interface in MLD query for lookup 1168192923Sbms * whilst we don't hold other locks (due to KAME locking lameness). 1169192923Sbms */ 1170192923Sbms if (!IN6_IS_ADDR_UNSPECIFIED(&mld->mld_addr)) 1171192923Sbms in6_setscope(&mld->mld_addr, ifp, NULL); 1172192923Sbms 1173191672Sbms IN6_MULTI_LOCK(); 1174192547Sbms MLD_LOCK(); 1175191672Sbms IF_ADDR_LOCK(ifp); 1176191672Sbms 1177191672Sbms /* 1178191672Sbms * MLDv1 report suppression. 1179191672Sbms * If we are a member of this group, and our membership should be 1180191672Sbms * reported, and our group timer is pending or about to be reset, 1181191672Sbms * stop our group timer by transitioning to the 'lazy' state. 1182191672Sbms */ 1183191672Sbms inm = in6m_lookup_locked(ifp, &mld->mld_addr); 1184191672Sbms if (inm != NULL) { 1185191672Sbms struct mld_ifinfo *mli; 1186191672Sbms 1187191672Sbms mli = inm->in6m_mli; 1188191672Sbms KASSERT(mli != NULL, 1189191672Sbms ("%s: no mli for ifp %p", __func__, ifp)); 1190191672Sbms 119153541Sshin /* 1192191672Sbms * If we are in MLDv2 host mode, do not allow the 1193191672Sbms * other host's MLDv1 report to suppress our reports. 119462587Sitojun */ 1195191672Sbms if (mli->mli_version == MLD_VERSION_2) 1196191672Sbms goto out_locked; 1197151539Ssuz 1198191672Sbms inm->in6m_timer = 0; 1199191672Sbms 1200191672Sbms switch (inm->in6m_state) { 1201191672Sbms case MLD_NOT_MEMBER: 1202191672Sbms case MLD_SILENT_MEMBER: 1203191672Sbms case MLD_SLEEPING_MEMBER: 120453541Sshin break; 1205191672Sbms case MLD_REPORTING_MEMBER: 1206191672Sbms case MLD_IDLE_MEMBER: 1207191672Sbms case MLD_AWAKENING_MEMBER: 1208191672Sbms CTR3(KTR_MLD, 1209191672Sbms "report suppressed for %s on ifp %p(%s)", 1210191672Sbms ip6_sprintf(ip6tbuf, &mld->mld_addr), 1211191672Sbms ifp, ifp->if_xname); 1212191672Sbms case MLD_LAZY_MEMBER: 1213191672Sbms inm->in6m_state = MLD_LAZY_MEMBER; 1214191672Sbms break; 1215191672Sbms case MLD_G_QUERY_PENDING_MEMBER: 1216191672Sbms case MLD_SG_QUERY_PENDING_MEMBER: 1217191672Sbms case MLD_LEAVING_MEMBER: 1218191672Sbms break; 1219191341Srwatson } 1220191672Sbms } 122153541Sshin 1222191672Sbmsout_locked: 1223192547Sbms MLD_UNLOCK(); 1224191672Sbms IF_ADDR_UNLOCK(ifp); 1225191672Sbms IN6_MULTI_UNLOCK(); 1226120941Sume 1227192923Sbms /* XXX Clear embedded scope ID as userland won't expect it. */ 1228192923Sbms in6_clearscope(&mld->mld_addr); 1229192923Sbms 1230191672Sbms return (0); 1231191672Sbms} 1232120941Sume 1233191672Sbms/* 1234191672Sbms * MLD input path. 1235191672Sbms * 1236191672Sbms * Assume query messages which fit in a single ICMPv6 message header 1237191672Sbms * have been pulled up. 1238191672Sbms * Assume that userland will want to see the message, even if it 1239191672Sbms * otherwise fails kernel input validation; do not free it. 1240191672Sbms * Pullup may however free the mbuf chain m if it fails. 1241191672Sbms * 1242191672Sbms * Return IPPROTO_DONE if we freed m. Otherwise, return 0. 1243191672Sbms */ 1244191672Sbmsint 1245191672Sbmsmld_input(struct mbuf *m, int off, int icmp6len) 1246191672Sbms{ 1247191672Sbms struct ifnet *ifp; 1248191672Sbms struct ip6_hdr *ip6; 1249191672Sbms struct mld_hdr *mld; 1250191672Sbms int mldlen; 1251191672Sbms 1252191672Sbms CTR3(KTR_MLD, "%s: called w/mbuf (%p,%d)", __func__, m, off); 1253191672Sbms 1254191672Sbms ifp = m->m_pkthdr.rcvif; 1255191672Sbms INIT_VNET_INET6(ifp->if_vnet); 1256191672Sbms 1257191672Sbms ip6 = mtod(m, struct ip6_hdr *); 1258191672Sbms 1259191672Sbms /* Pullup to appropriate size. */ 1260191672Sbms mld = (struct mld_hdr *)(mtod(m, uint8_t *) + off); 1261191672Sbms if (mld->mld_type == MLD_LISTENER_QUERY && 1262191672Sbms icmp6len >= sizeof(struct mldv2_query)) { 1263191672Sbms mldlen = sizeof(struct mldv2_query); 1264191672Sbms } else { 1265191672Sbms mldlen = sizeof(struct mld_hdr); 1266191672Sbms } 1267191672Sbms IP6_EXTHDR_GET(mld, struct mld_hdr *, m, off, mldlen); 1268191672Sbms if (mld == NULL) { 1269191672Sbms ICMP6STAT_INC(icp6s_badlen); 1270191672Sbms return (IPPROTO_DONE); 1271191672Sbms } 1272191672Sbms 1273192923Sbms /* 1274192923Sbms * Userland needs to see all of this traffic for implementing 1275192923Sbms * the endpoint discovery portion of multicast routing. 1276192923Sbms */ 1277191672Sbms switch (mld->mld_type) { 1278191672Sbms case MLD_LISTENER_QUERY: 1279191672Sbms icmp6_ifstat_inc(ifp, ifs6_in_mldquery); 1280191672Sbms if (icmp6len == sizeof(struct mld_hdr)) { 1281191672Sbms if (mld_v1_input_query(ifp, ip6, mld) != 0) 1282191672Sbms return (0); 1283191672Sbms } else if (icmp6len >= sizeof(struct mldv2_query)) { 1284191672Sbms if (mld_v2_input_query(ifp, ip6, m, off, 1285191672Sbms icmp6len) != 0) 1286191672Sbms return (0); 1287191672Sbms } 1288191672Sbms break; 1289191672Sbms case MLD_LISTENER_REPORT: 1290191672Sbms icmp6_ifstat_inc(ifp, ifs6_in_mldreport); 1291191672Sbms if (mld_v1_input_report(ifp, ip6, mld) != 0) 1292192923Sbms return (0); 1293191672Sbms break; 1294191672Sbms case MLDV2_LISTENER_REPORT: 1295191672Sbms icmp6_ifstat_inc(ifp, ifs6_in_mldreport); 1296191672Sbms break; 1297191672Sbms case MLD_LISTENER_DONE: 1298191672Sbms icmp6_ifstat_inc(ifp, ifs6_in_mlddone); 1299191672Sbms break; 1300191672Sbms default: 1301191672Sbms break; 1302191672Sbms } 1303191672Sbms 1304191672Sbms return (0); 1305191672Sbms} 1306191672Sbms 1307191672Sbms/* 1308191672Sbms * Fast timeout handler (global). 1309191672Sbms * VIMAGE: Timeout handlers are expected to service all vimages. 1310191672Sbms */ 1311191672Sbmsvoid 1312191672Sbmsmld_fasttimo(void) 1313191672Sbms{ 1314191672Sbms VNET_ITERATOR_DECL(vnet_iter); 1315191672Sbms 1316191672Sbms VNET_LIST_RLOCK(); 1317191672Sbms VNET_FOREACH(vnet_iter) { 1318191672Sbms CURVNET_SET(vnet_iter); 1319191672Sbms mld_fasttimo_vnet(); 1320191672Sbms CURVNET_RESTORE(); 1321191672Sbms } 1322191672Sbms VNET_LIST_RUNLOCK(); 1323191672Sbms} 1324191672Sbms 1325191672Sbms/* 1326191672Sbms * Fast timeout handler (per-vnet). 1327191672Sbms * 1328191672Sbms * VIMAGE: Assume caller has set up our curvnet. 1329191672Sbms */ 1330191672Sbmsstatic void 1331191672Sbmsmld_fasttimo_vnet(void) 1332191672Sbms{ 1333191672Sbms INIT_VNET_INET6(curvnet); 1334191672Sbms struct ifqueue scq; /* State-change packets */ 1335191672Sbms struct ifqueue qrq; /* Query response packets */ 1336191672Sbms struct ifnet *ifp; 1337191672Sbms struct mld_ifinfo *mli; 1338191672Sbms struct ifmultiaddr *ifma, *tifma; 1339191672Sbms struct in6_multi *inm; 1340191672Sbms int uri_fasthz; 1341191672Sbms 1342191672Sbms uri_fasthz = 0; 1343191672Sbms 1344191672Sbms /* 1345191672Sbms * Quick check to see if any work needs to be done, in order to 1346191672Sbms * minimize the overhead of fasttimo processing. 1347191672Sbms * SMPng: XXX Unlocked reads. 1348191672Sbms */ 1349191672Sbms if (!V_current_state_timers_running6 && 1350191672Sbms !V_interface_timers_running6 && 1351191672Sbms !V_state_change_timers_running6) 1352191672Sbms return; 1353191672Sbms 1354191672Sbms IN6_MULTI_LOCK(); 1355191672Sbms MLD_LOCK(); 1356191672Sbms 1357191672Sbms /* 1358191672Sbms * MLDv2 General Query response timer processing. 1359191672Sbms */ 1360191672Sbms if (V_interface_timers_running6) { 1361191672Sbms CTR1(KTR_MLD, "%s: interface timers running", __func__); 1362191672Sbms 1363191672Sbms V_interface_timers_running6 = 0; 1364191672Sbms LIST_FOREACH(mli, &V_mli_head, mli_link) { 1365191672Sbms if (mli->mli_v2_timer == 0) { 1366191672Sbms /* Do nothing. */ 1367191672Sbms } else if (--mli->mli_v2_timer == 0) { 1368191672Sbms mld_v2_dispatch_general_query(mli); 1369191672Sbms } else { 1370191672Sbms V_interface_timers_running6 = 1; 1371191672Sbms } 1372191672Sbms } 1373191672Sbms } 1374191672Sbms 1375191672Sbms if (!V_current_state_timers_running6 && 1376191672Sbms !V_state_change_timers_running6) 1377191672Sbms goto out_locked; 1378191672Sbms 1379191672Sbms V_current_state_timers_running6 = 0; 1380191672Sbms V_state_change_timers_running6 = 0; 1381191672Sbms 1382191672Sbms CTR1(KTR_MLD, "%s: state change timers running", __func__); 1383191672Sbms 1384191672Sbms /* 1385191672Sbms * MLD host report and state-change timer processing. 1386191672Sbms * Note: Processing a v2 group timer may remove a node. 1387191672Sbms */ 1388191672Sbms LIST_FOREACH(mli, &V_mli_head, mli_link) { 1389191672Sbms ifp = mli->mli_ifp; 1390191672Sbms 1391191672Sbms if (mli->mli_version == MLD_VERSION_2) { 1392191672Sbms uri_fasthz = MLD_RANDOM_DELAY(mli->mli_uri * 1393191672Sbms PR_FASTHZ); 1394191672Sbms 1395191672Sbms memset(&qrq, 0, sizeof(struct ifqueue)); 1396191672Sbms IFQ_SET_MAXLEN(&qrq, MLD_MAX_G_GS_PACKETS); 1397191672Sbms 1398191672Sbms memset(&scq, 0, sizeof(struct ifqueue)); 1399191672Sbms IFQ_SET_MAXLEN(&scq, MLD_MAX_STATE_CHANGE_PACKETS); 1400191672Sbms } 1401191672Sbms 1402191672Sbms IF_ADDR_LOCK(ifp); 1403191672Sbms TAILQ_FOREACH_SAFE(ifma, &ifp->if_multiaddrs, ifma_link, 1404191672Sbms tifma) { 1405191672Sbms if (ifma->ifma_addr->sa_family != AF_INET6 || 1406191672Sbms ifma->ifma_protospec == NULL) 140753541Sshin continue; 1408191672Sbms inm = (struct in6_multi *)ifma->ifma_protospec; 1409191672Sbms switch (mli->mli_version) { 1410191672Sbms case MLD_VERSION_1: 1411192923Sbms /* 1412192923Sbms * XXX Drop IF_ADDR lock temporarily to 1413192923Sbms * avoid recursion caused by a potential 1414192923Sbms * call by in6ifa_ifpforlinklocal(). 1415192923Sbms * rwlock candidate? 1416192923Sbms */ 1417192923Sbms IF_ADDR_UNLOCK(ifp); 1418191672Sbms mld_v1_process_group_timer(inm, 1419191672Sbms mli->mli_version); 1420192923Sbms IF_ADDR_LOCK(ifp); 1421191672Sbms break; 1422191672Sbms case MLD_VERSION_2: 1423191672Sbms mld_v2_process_group_timers(mli, &qrq, 1424191672Sbms &scq, inm, uri_fasthz); 1425191672Sbms break; 1426191672Sbms } 1427191672Sbms } 1428191672Sbms IF_ADDR_UNLOCK(ifp); 142953541Sshin 1430191672Sbms if (mli->mli_version == MLD_VERSION_2) { 1431191672Sbms struct in6_multi *tinm; 1432191672Sbms 1433191672Sbms mld_dispatch_queue(&qrq, 0); 1434191672Sbms mld_dispatch_queue(&scq, 0); 1435191672Sbms 1436191672Sbms /* 1437191672Sbms * Free the in_multi reference(s) for 1438191672Sbms * this lifecycle. 1439191672Sbms */ 1440191672Sbms SLIST_FOREACH_SAFE(inm, &mli->mli_relinmhead, 1441191672Sbms in6m_nrele, tinm) { 1442191672Sbms SLIST_REMOVE_HEAD(&mli->mli_relinmhead, 1443191672Sbms in6m_nrele); 1444191672Sbms in6m_release_locked(inm); 144553541Sshin } 144653541Sshin } 1447191672Sbms } 1448191672Sbms 1449191672Sbmsout_locked: 1450191672Sbms MLD_UNLOCK(); 1451191672Sbms IN6_MULTI_UNLOCK(); 1452191672Sbms} 1453191672Sbms 1454191672Sbms/* 1455191672Sbms * Update host report group timer. 1456191672Sbms * Will update the global pending timer flags. 1457191672Sbms */ 1458191672Sbmsstatic void 1459191672Sbmsmld_v1_process_group_timer(struct in6_multi *inm, const int version) 1460191672Sbms{ 1461191672Sbms INIT_VNET_INET6(curvnet); 1462191672Sbms int report_timer_expired; 1463191672Sbms 1464191672Sbms IN6_MULTI_LOCK_ASSERT(); 1465191672Sbms MLD_LOCK_ASSERT(); 1466191672Sbms 1467191672Sbms if (inm->in6m_timer == 0) { 1468191672Sbms report_timer_expired = 0; 1469191672Sbms } else if (--inm->in6m_timer == 0) { 1470191672Sbms report_timer_expired = 1; 1471191672Sbms } else { 1472191672Sbms V_current_state_timers_running6 = 1; 1473191672Sbms return; 1474191672Sbms } 1475191672Sbms 1476191672Sbms switch (inm->in6m_state) { 1477191672Sbms case MLD_NOT_MEMBER: 1478191672Sbms case MLD_SILENT_MEMBER: 1479191672Sbms case MLD_IDLE_MEMBER: 1480191672Sbms case MLD_LAZY_MEMBER: 1481191672Sbms case MLD_SLEEPING_MEMBER: 1482191672Sbms case MLD_AWAKENING_MEMBER: 148353541Sshin break; 1484191672Sbms case MLD_REPORTING_MEMBER: 1485191672Sbms if (report_timer_expired) { 1486191672Sbms inm->in6m_state = MLD_IDLE_MEMBER; 1487191672Sbms (void)mld_v1_transmit_report(inm, 1488191672Sbms MLD_LISTENER_REPORT); 1489191672Sbms } 1490191672Sbms break; 1491191672Sbms case MLD_G_QUERY_PENDING_MEMBER: 1492191672Sbms case MLD_SG_QUERY_PENDING_MEMBER: 1493191672Sbms case MLD_LEAVING_MEMBER: 1494191672Sbms break; 1495191672Sbms } 1496191672Sbms} 1497120941Sume 1498191672Sbms/* 1499191672Sbms * Update a group's timers for MLDv2. 1500191672Sbms * Will update the global pending timer flags. 1501191672Sbms * Note: Unlocked read from mli. 1502191672Sbms */ 1503191672Sbmsstatic void 1504191672Sbmsmld_v2_process_group_timers(struct mld_ifinfo *mli, 1505191672Sbms struct ifqueue *qrq, struct ifqueue *scq, 1506191672Sbms struct in6_multi *inm, const int uri_fasthz) 1507191672Sbms{ 1508191672Sbms INIT_VNET_INET6(curvnet); 1509191672Sbms int query_response_timer_expired; 1510191672Sbms int state_change_retransmit_timer_expired; 1511191672Sbms#ifdef KTR 1512191672Sbms char ip6tbuf[INET6_ADDRSTRLEN]; 1513191672Sbms#endif 1514191672Sbms 1515191672Sbms IN6_MULTI_LOCK_ASSERT(); 1516191672Sbms MLD_LOCK_ASSERT(); 1517191672Sbms 1518191672Sbms query_response_timer_expired = 0; 1519191672Sbms state_change_retransmit_timer_expired = 0; 1520191672Sbms 1521191672Sbms /* 1522191672Sbms * During a transition from compatibility mode back to MLDv2, 1523191672Sbms * a group record in REPORTING state may still have its group 1524191672Sbms * timer active. This is a no-op in this function; it is easier 1525191672Sbms * to deal with it here than to complicate the slow-timeout path. 1526191672Sbms */ 1527191672Sbms if (inm->in6m_timer == 0) { 1528191672Sbms query_response_timer_expired = 0; 1529191672Sbms } else if (--inm->in6m_timer == 0) { 1530191672Sbms query_response_timer_expired = 1; 1531191672Sbms } else { 1532191672Sbms V_current_state_timers_running6 = 1; 1533191672Sbms } 1534191672Sbms 1535191672Sbms if (inm->in6m_sctimer == 0) { 1536191672Sbms state_change_retransmit_timer_expired = 0; 1537191672Sbms } else if (--inm->in6m_sctimer == 0) { 1538191672Sbms state_change_retransmit_timer_expired = 1; 1539191672Sbms } else { 1540191672Sbms V_state_change_timers_running6 = 1; 1541191672Sbms } 1542191672Sbms 1543191672Sbms /* We are in fasttimo, so be quick about it. */ 1544191672Sbms if (!state_change_retransmit_timer_expired && 1545191672Sbms !query_response_timer_expired) 1546191672Sbms return; 1547191672Sbms 1548191672Sbms switch (inm->in6m_state) { 1549191672Sbms case MLD_NOT_MEMBER: 1550191672Sbms case MLD_SILENT_MEMBER: 1551191672Sbms case MLD_SLEEPING_MEMBER: 1552191672Sbms case MLD_LAZY_MEMBER: 1553191672Sbms case MLD_AWAKENING_MEMBER: 1554191672Sbms case MLD_IDLE_MEMBER: 1555191672Sbms break; 1556191672Sbms case MLD_G_QUERY_PENDING_MEMBER: 1557191672Sbms case MLD_SG_QUERY_PENDING_MEMBER: 155853541Sshin /* 1559191672Sbms * Respond to a previously pending Group-Specific 1560191672Sbms * or Group-and-Source-Specific query by enqueueing 1561191672Sbms * the appropriate Current-State report for 1562191672Sbms * immediate transmission. 156362587Sitojun */ 1564191672Sbms if (query_response_timer_expired) { 1565191672Sbms int retval; 156653541Sshin 1567191672Sbms retval = mld_v2_enqueue_group_record(qrq, inm, 0, 1, 1568191672Sbms (inm->in6m_state == MLD_SG_QUERY_PENDING_MEMBER)); 1569191672Sbms CTR2(KTR_MLD, "%s: enqueue record = %d", 1570191672Sbms __func__, retval); 1571191672Sbms inm->in6m_state = MLD_REPORTING_MEMBER; 1572191672Sbms in6m_clear_recorded(inm); 1573191672Sbms } 1574191672Sbms /* FALLTHROUGH */ 1575191672Sbms case MLD_REPORTING_MEMBER: 1576191672Sbms case MLD_LEAVING_MEMBER: 1577191672Sbms if (state_change_retransmit_timer_expired) { 1578191672Sbms /* 1579191672Sbms * State-change retransmission timer fired. 1580191672Sbms * If there are any further pending retransmissions, 1581191672Sbms * set the global pending state-change flag, and 1582191672Sbms * reset the timer. 1583191672Sbms */ 1584191672Sbms if (--inm->in6m_scrv > 0) { 1585191672Sbms inm->in6m_sctimer = uri_fasthz; 1586191672Sbms V_state_change_timers_running6 = 1; 1587191672Sbms } 1588191672Sbms /* 1589191672Sbms * Retransmit the previously computed state-change 1590191672Sbms * report. If there are no further pending 1591191672Sbms * retransmissions, the mbuf queue will be consumed. 1592191672Sbms * Update T0 state to T1 as we have now sent 1593191672Sbms * a state-change. 1594191672Sbms */ 1595191672Sbms (void)mld_v2_merge_state_changes(inm, scq); 159653541Sshin 1597191672Sbms in6m_commit(inm); 1598191672Sbms CTR3(KTR_MLD, "%s: T1 -> T0 for %s/%s", __func__, 1599191672Sbms ip6_sprintf(ip6tbuf, &inm->in6m_addr), 1600191672Sbms inm->in6m_ifp->if_xname); 1601191672Sbms 1602191672Sbms /* 1603191672Sbms * If we are leaving the group for good, make sure 1604191672Sbms * we release MLD's reference to it. 1605191672Sbms * This release must be deferred using a SLIST, 1606191672Sbms * as we are called from a loop which traverses 1607191672Sbms * the in_ifmultiaddr TAILQ. 1608191672Sbms */ 1609191672Sbms if (inm->in6m_state == MLD_LEAVING_MEMBER && 1610191672Sbms inm->in6m_scrv == 0) { 1611191672Sbms inm->in6m_state = MLD_NOT_MEMBER; 1612191672Sbms SLIST_INSERT_HEAD(&mli->mli_relinmhead, 1613191672Sbms inm, in6m_nrele); 1614191672Sbms } 1615191672Sbms } 1616191672Sbms break; 1617191672Sbms } 1618191672Sbms} 1619191672Sbms 1620191672Sbms/* 1621191672Sbms * Switch to a different version on the given interface, 1622191672Sbms * as per Section 9.12. 1623191672Sbms */ 1624191672Sbmsstatic void 1625191672Sbmsmld_set_version(struct mld_ifinfo *mli, const int version) 1626191672Sbms{ 1627192562Sbms int old_version_timer; 1628191672Sbms 1629191672Sbms MLD_LOCK_ASSERT(); 1630191672Sbms 1631191672Sbms CTR4(KTR_MLD, "%s: switching to v%d on ifp %p(%s)", __func__, 1632191672Sbms version, mli->mli_ifp, mli->mli_ifp->if_xname); 1633191672Sbms 1634191672Sbms if (version == MLD_VERSION_1) { 163553541Sshin /* 1636191672Sbms * Compute the "Older Version Querier Present" timer as per 1637191672Sbms * Section 9.12. 163862587Sitojun */ 1639192923Sbms old_version_timer = (mli->mli_rv * mli->mli_qi) + mli->mli_qri; 1640191672Sbms old_version_timer *= PR_SLOWHZ; 1641192562Sbms mli->mli_v1_timer = old_version_timer; 164253541Sshin } 164362587Sitojun 1644192562Sbms if (mli->mli_v1_timer > 0 && mli->mli_version != MLD_VERSION_1) { 1645192562Sbms mli->mli_version = MLD_VERSION_1; 1646192562Sbms mld_v2_cancel_link_timers(mli); 1647191672Sbms } 164853541Sshin} 164953541Sshin 1650191672Sbms/* 1651191672Sbms * Cancel pending MLDv2 timers for the given link and all groups 1652191672Sbms * joined on it; state-change, general-query, and group-query timers. 1653191672Sbms */ 165453541Sshinstatic void 1655191672Sbmsmld_v2_cancel_link_timers(struct mld_ifinfo *mli) 165653541Sshin{ 1657183550Szec INIT_VNET_INET6(curvnet); 1658191672Sbms struct ifmultiaddr *ifma; 1659191672Sbms struct ifnet *ifp; 1660191672Sbms struct in6_multi *inm; 166153541Sshin 1662191672Sbms CTR3(KTR_MLD, "%s: cancel v2 timers on ifp %p(%s)", __func__, 1663191672Sbms mli->mli_ifp, mli->mli_ifp->if_xname); 1664191672Sbms 1665191672Sbms IN6_MULTI_LOCK_ASSERT(); 1666191672Sbms MLD_LOCK_ASSERT(); 1667191672Sbms 166853541Sshin /* 1669191672Sbms * Fast-track this potentially expensive operation 1670191672Sbms * by checking all the global 'timer pending' flags. 167153541Sshin */ 1672191672Sbms if (!V_interface_timers_running6 && 1673191672Sbms !V_state_change_timers_running6 && 1674191672Sbms !V_current_state_timers_running6) 167553541Sshin return; 167653541Sshin 1677191672Sbms mli->mli_v2_timer = 0; 1678191672Sbms 1679191672Sbms ifp = mli->mli_ifp; 1680191672Sbms 1681191672Sbms IF_ADDR_LOCK(ifp); 1682191672Sbms TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) { 1683191672Sbms if (ifma->ifma_addr->sa_family != AF_INET6) 1684191672Sbms continue; 1685191672Sbms inm = (struct in6_multi *)ifma->ifma_protospec; 1686191672Sbms switch (inm->in6m_state) { 1687191672Sbms case MLD_NOT_MEMBER: 1688191672Sbms case MLD_SILENT_MEMBER: 1689191672Sbms case MLD_IDLE_MEMBER: 1690191672Sbms case MLD_LAZY_MEMBER: 1691191672Sbms case MLD_SLEEPING_MEMBER: 1692191672Sbms case MLD_AWAKENING_MEMBER: 1693191672Sbms break; 1694191672Sbms case MLD_LEAVING_MEMBER: 1695191672Sbms /* 1696191672Sbms * If we are leaving the group and switching 1697191672Sbms * version, we need to release the final 1698191672Sbms * reference held for issuing the INCLUDE {}. 1699191672Sbms * 1700191672Sbms * SMPNG: Must drop and re-acquire IF_ADDR_LOCK 1701191672Sbms * around in6m_release_locked(), as it is not 1702191672Sbms * a recursive mutex. 1703191672Sbms */ 1704191672Sbms IF_ADDR_UNLOCK(ifp); 1705191672Sbms in6m_release_locked(inm); 1706191672Sbms IF_ADDR_LOCK(ifp); 1707191672Sbms /* FALLTHROUGH */ 1708191672Sbms case MLD_G_QUERY_PENDING_MEMBER: 1709191672Sbms case MLD_SG_QUERY_PENDING_MEMBER: 1710191672Sbms in6m_clear_recorded(inm); 1711191672Sbms /* FALLTHROUGH */ 1712191672Sbms case MLD_REPORTING_MEMBER: 1713191672Sbms inm->in6m_sctimer = 0; 1714191672Sbms inm->in6m_timer = 0; 1715191672Sbms inm->in6m_state = MLD_REPORTING_MEMBER; 1716191672Sbms /* 1717191672Sbms * Free any pending MLDv2 state-change records. 1718191672Sbms */ 1719191672Sbms _IF_DRAIN(&inm->in6m_scq); 1720191672Sbms break; 1721191672Sbms } 1722191672Sbms } 1723191672Sbms IF_ADDR_UNLOCK(ifp); 1724191672Sbms} 1725191672Sbms 1726191672Sbms/* 1727191672Sbms * Global slowtimo handler. 1728191672Sbms * VIMAGE: Timeout handlers are expected to service all vimages. 1729191672Sbms */ 1730191672Sbmsvoid 1731191672Sbmsmld_slowtimo(void) 1732191672Sbms{ 1733191672Sbms VNET_ITERATOR_DECL(vnet_iter); 1734191672Sbms 1735191672Sbms VNET_LIST_RLOCK(); 1736191672Sbms VNET_FOREACH(vnet_iter) { 1737191672Sbms CURVNET_SET(vnet_iter); 1738191672Sbms mld_slowtimo_vnet(); 1739191672Sbms CURVNET_RESTORE(); 1740191672Sbms } 1741191672Sbms VNET_LIST_RUNLOCK(); 1742191672Sbms} 1743191672Sbms 1744191672Sbms/* 1745191672Sbms * Per-vnet slowtimo handler. 1746191672Sbms */ 1747191672Sbmsstatic void 1748191672Sbmsmld_slowtimo_vnet(void) 1749191672Sbms{ 1750191672Sbms INIT_VNET_INET6(curvnet); 1751191672Sbms struct mld_ifinfo *mli; 1752191672Sbms 1753191672Sbms MLD_LOCK(); 1754191672Sbms 1755191672Sbms LIST_FOREACH(mli, &V_mli_head, mli_link) { 1756191672Sbms mld_v1_process_querier_timers(mli); 1757191672Sbms } 1758191672Sbms 1759191672Sbms MLD_UNLOCK(); 1760191672Sbms} 1761191672Sbms 1762191672Sbms/* 1763191672Sbms * Update the Older Version Querier Present timers for a link. 1764191672Sbms * See Section 9.12 of RFC 3810. 1765191672Sbms */ 1766191672Sbmsstatic void 1767191672Sbmsmld_v1_process_querier_timers(struct mld_ifinfo *mli) 1768191672Sbms{ 1769191672Sbms 1770191672Sbms MLD_LOCK_ASSERT(); 1771191672Sbms 1772192923Sbms if (mli->mli_version != MLD_VERSION_2 && --mli->mli_v1_timer == 0) { 1773191672Sbms /* 1774192562Sbms * MLDv1 Querier Present timer expired; revert to MLDv2. 1775191672Sbms */ 1776192562Sbms CTR5(KTR_MLD, 1777192562Sbms "%s: transition from v%d -> v%d on %p(%s)", 1778192562Sbms __func__, mli->mli_version, MLD_VERSION_2, 1779192562Sbms mli->mli_ifp, mli->mli_ifp->if_xname); 1780192562Sbms mli->mli_version = MLD_VERSION_2; 1781191672Sbms } 1782191672Sbms} 1783191672Sbms 1784191672Sbms/* 1785191672Sbms * Transmit an MLDv1 report immediately. 1786191672Sbms */ 1787191672Sbmsstatic int 1788191672Sbmsmld_v1_transmit_report(struct in6_multi *in6m, const int type) 1789191672Sbms{ 1790191672Sbms struct ifnet *ifp; 1791191672Sbms struct in6_ifaddr *ia; 1792191672Sbms struct ip6_hdr *ip6; 1793191672Sbms struct mbuf *mh, *md; 1794191672Sbms struct mld_hdr *mld; 1795191672Sbms 1796191672Sbms IN6_MULTI_LOCK_ASSERT(); 1797191672Sbms MLD_LOCK_ASSERT(); 1798191672Sbms 1799191672Sbms ifp = in6m->in6m_ifp; 1800191672Sbms ia = in6ifa_ifpforlinklocal(ifp, IN6_IFF_NOTREADY|IN6_IFF_ANYCAST); 1801191672Sbms /* ia may be NULL if link-local address is tentative. */ 1802191672Sbms 1803111119Simp MGETHDR(mh, M_DONTWAIT, MT_HEADER); 1804194760Srwatson if (mh == NULL) { 1805194760Srwatson if (ia != NULL) 1806194760Srwatson ifa_free(&ia->ia_ifa); 1807191672Sbms return (ENOMEM); 1808194760Srwatson } 1809111119Simp MGET(md, M_DONTWAIT, MT_DATA); 181053541Sshin if (md == NULL) { 181153541Sshin m_free(mh); 1812194760Srwatson if (ia != NULL) 1813194760Srwatson ifa_free(&ia->ia_ifa); 1814191672Sbms return (ENOMEM); 181553541Sshin } 181653541Sshin mh->m_next = md; 181762587Sitojun 1818191672Sbms /* 1819191672Sbms * FUTURE: Consider increasing alignment by ETHER_HDR_LEN, so 1820191672Sbms * that ether_output() does not need to allocate another mbuf 1821191672Sbms * for the header in the most common case. 1822191672Sbms */ 1823191672Sbms MH_ALIGN(mh, sizeof(struct ip6_hdr)); 182496116Sume mh->m_pkthdr.len = sizeof(struct ip6_hdr) + sizeof(struct mld_hdr); 182553541Sshin mh->m_len = sizeof(struct ip6_hdr); 182653541Sshin 182753541Sshin ip6 = mtod(mh, struct ip6_hdr *); 182853541Sshin ip6->ip6_flow = 0; 182962587Sitojun ip6->ip6_vfc &= ~IPV6_VERSION_MASK; 183062587Sitojun ip6->ip6_vfc |= IPV6_VERSION; 183153541Sshin ip6->ip6_nxt = IPPROTO_ICMPV6; 1832191672Sbms ip6->ip6_src = ia ? ia->ia_addr.sin6_addr : in6addr_any; 1833191672Sbms ip6->ip6_dst = in6m->in6m_addr; 183453541Sshin 183596116Sume md->m_len = sizeof(struct mld_hdr); 1836191672Sbms mld = mtod(md, struct mld_hdr *); 1837191672Sbms mld->mld_type = type; 1838191672Sbms mld->mld_code = 0; 1839191672Sbms mld->mld_cksum = 0; 1840191672Sbms mld->mld_maxdelay = 0; 1841191672Sbms mld->mld_reserved = 0; 1842191672Sbms mld->mld_addr = in6m->in6m_addr; 1843191672Sbms in6_clearscope(&mld->mld_addr); 1844191672Sbms mld->mld_cksum = in6_cksum(mh, IPPROTO_ICMPV6, 1845191672Sbms sizeof(struct ip6_hdr), sizeof(struct mld_hdr)); 184653541Sshin 1847191672Sbms mld_save_context(mh, ifp); 1848191672Sbms mh->m_flags |= M_MLDV1; 184953541Sshin 1850191672Sbms mld_dispatch_packet(mh); 1851191672Sbms 1852194760Srwatson if (ia != NULL) 1853194760Srwatson ifa_free(&ia->ia_ifa); 1854191672Sbms return (0); 1855191672Sbms} 1856191672Sbms 1857191672Sbms/* 1858191672Sbms * Process a state change from the upper layer for the given IPv6 group. 1859191672Sbms * 1860191672Sbms * Each socket holds a reference on the in_multi in its own ip_moptions. 1861191672Sbms * The socket layer will have made the necessary updates to.the group 1862191672Sbms * state, it is now up to MLD to issue a state change report if there 1863191672Sbms * has been any change between T0 (when the last state-change was issued) 1864191672Sbms * and T1 (now). 1865191672Sbms * 1866191672Sbms * We use the MLDv2 state machine at group level. The MLd module 1867191672Sbms * however makes the decision as to which MLD protocol version to speak. 1868191672Sbms * A state change *from* INCLUDE {} always means an initial join. 1869191672Sbms * A state change *to* INCLUDE {} always means a final leave. 1870191672Sbms * 1871191672Sbms * If delay is non-zero, and the state change is an initial multicast 1872191672Sbms * join, the state change report will be delayed by 'delay' ticks 1873191672Sbms * in units of PR_FASTHZ if MLDv1 is active on the link; otherwise 1874191672Sbms * the initial MLDv2 state change report will be delayed by whichever 1875191672Sbms * is sooner, a pending state-change timer or delay itself. 1876191672Sbms * 1877191672Sbms * VIMAGE: curvnet should have been set by caller, as this routine 1878191672Sbms * is called from the socket option handlers. 1879191672Sbms */ 1880191672Sbmsint 1881191672Sbmsmld_change_state(struct in6_multi *inm, const int delay) 1882191672Sbms{ 1883191672Sbms struct mld_ifinfo *mli; 1884191672Sbms struct ifnet *ifp; 1885191672Sbms int error; 1886191672Sbms 1887191672Sbms IN6_MULTI_LOCK_ASSERT(); 1888191672Sbms 1889191672Sbms error = 0; 1890191672Sbms 189153541Sshin /* 1892191672Sbms * Try to detect if the upper layer just asked us to change state 1893191672Sbms * for an interface which has now gone away. 189453541Sshin */ 1895191672Sbms KASSERT(inm->in6m_ifma != NULL, ("%s: no ifma", __func__)); 1896191672Sbms ifp = inm->in6m_ifma->ifma_ifp; 1897191672Sbms if (ifp != NULL) { 1898191672Sbms /* 1899191672Sbms * Sanity check that netinet6's notion of ifp is the 1900191672Sbms * same as net's. 1901191672Sbms */ 1902191672Sbms KASSERT(inm->in6m_ifp == ifp, ("%s: bad ifp", __func__)); 1903191672Sbms } 190453541Sshin 1905191672Sbms MLD_LOCK(); 190653541Sshin 1907191672Sbms mli = MLD_IFINFO(ifp); 1908191672Sbms KASSERT(mli != NULL, ("%s: no mld_ifinfo for ifp %p", __func__, ifp)); 1909191672Sbms 1910191672Sbms /* 1911191672Sbms * If we detect a state transition to or from MCAST_UNDEFINED 1912191672Sbms * for this group, then we are starting or finishing an MLD 1913191672Sbms * life cycle for this group. 1914191672Sbms */ 1915191672Sbms if (inm->in6m_st[1].iss_fmode != inm->in6m_st[0].iss_fmode) { 1916191672Sbms CTR3(KTR_MLD, "%s: inm transition %d -> %d", __func__, 1917191672Sbms inm->in6m_st[0].iss_fmode, inm->in6m_st[1].iss_fmode); 1918191672Sbms if (inm->in6m_st[0].iss_fmode == MCAST_UNDEFINED) { 1919191672Sbms CTR1(KTR_MLD, "%s: initial join", __func__); 1920191672Sbms error = mld_initial_join(inm, mli, delay); 1921191672Sbms goto out_locked; 1922191672Sbms } else if (inm->in6m_st[1].iss_fmode == MCAST_UNDEFINED) { 1923191672Sbms CTR1(KTR_MLD, "%s: final leave", __func__); 1924191672Sbms mld_final_leave(inm, mli); 1925191672Sbms goto out_locked; 1926191672Sbms } 1927191672Sbms } else { 1928191672Sbms CTR1(KTR_MLD, "%s: filter set change", __func__); 1929191672Sbms } 1930191672Sbms 1931191672Sbms error = mld_handle_state_change(inm, mli); 1932191672Sbms 1933191672Sbmsout_locked: 1934191672Sbms MLD_UNLOCK(); 1935191672Sbms return (error); 1936191672Sbms} 1937191672Sbms 1938191672Sbms/* 1939191672Sbms * Perform the initial join for an MLD group. 1940191672Sbms * 1941191672Sbms * When joining a group: 1942191672Sbms * If the group should have its MLD traffic suppressed, do nothing. 1943191672Sbms * MLDv1 starts sending MLDv1 host membership reports. 1944191672Sbms * MLDv2 will schedule an MLDv2 state-change report containing the 1945191672Sbms * initial state of the membership. 1946191672Sbms * 1947191672Sbms * If the delay argument is non-zero, then we must delay sending the 1948191672Sbms * initial state change for delay ticks (in units of PR_FASTHZ). 1949191672Sbms */ 1950191672Sbmsstatic int 1951191672Sbmsmld_initial_join(struct in6_multi *inm, struct mld_ifinfo *mli, 1952191672Sbms const int delay) 1953191672Sbms{ 1954191672Sbms INIT_VNET_INET6(curvnet); 1955191672Sbms struct ifnet *ifp; 1956191672Sbms struct ifqueue *ifq; 1957191672Sbms int error, retval, syncstates; 1958191672Sbms int odelay; 1959191672Sbms#ifdef KTR 1960191672Sbms char ip6tbuf[INET6_ADDRSTRLEN]; 1961191672Sbms#endif 1962191672Sbms 1963191672Sbms CTR4(KTR_MLD, "%s: initial join %s on ifp %p(%s)", 1964191672Sbms __func__, ip6_sprintf(ip6tbuf, &inm->in6m_addr), 1965191672Sbms inm->in6m_ifp, inm->in6m_ifp->if_xname); 1966191672Sbms 1967191672Sbms error = 0; 1968191672Sbms syncstates = 1; 1969191672Sbms 1970191672Sbms ifp = inm->in6m_ifp; 1971191672Sbms 1972191672Sbms IN6_MULTI_LOCK_ASSERT(); 1973191672Sbms MLD_LOCK_ASSERT(); 1974191672Sbms 1975191672Sbms KASSERT(mli && mli->mli_ifp == ifp, ("%s: inconsistent ifp", __func__)); 1976191672Sbms 1977191672Sbms /* 1978191672Sbms * Groups joined on loopback or marked as 'not reported', 1979191672Sbms * enter the MLD_SILENT_MEMBER state and 1980191672Sbms * are never reported in any protocol exchanges. 1981191672Sbms * All other groups enter the appropriate state machine 1982191672Sbms * for the version in use on this link. 1983191672Sbms * A link marked as MLIF_SILENT causes MLD to be completely 1984191672Sbms * disabled for the link. 1985191672Sbms */ 1986191672Sbms if ((ifp->if_flags & IFF_LOOPBACK) || 1987191672Sbms (mli->mli_flags & MLIF_SILENT) || 1988191672Sbms !mld_is_addr_reported(&inm->in6m_addr)) { 1989191672Sbms CTR1(KTR_MLD, 1990191672Sbms"%s: not kicking state machine for silent group", __func__); 1991191672Sbms inm->in6m_state = MLD_SILENT_MEMBER; 1992191672Sbms inm->in6m_timer = 0; 1993191672Sbms } else { 1994191672Sbms /* 1995191672Sbms * Deal with overlapping in_multi lifecycle. 1996191672Sbms * If this group was LEAVING, then make sure 1997191672Sbms * we drop the reference we picked up to keep the 1998191672Sbms * group around for the final INCLUDE {} enqueue. 1999191672Sbms */ 2000191672Sbms if (mli->mli_version == MLD_VERSION_2 && 2001191672Sbms inm->in6m_state == MLD_LEAVING_MEMBER) 2002191672Sbms in6m_release_locked(inm); 2003191672Sbms 2004191672Sbms inm->in6m_state = MLD_REPORTING_MEMBER; 2005191672Sbms 2006191672Sbms switch (mli->mli_version) { 2007191672Sbms case MLD_VERSION_1: 2008191672Sbms /* 2009191672Sbms * If a delay was provided, only use it if 2010191672Sbms * it is greater than the delay normally 2011191672Sbms * used for an MLDv1 state change report, 2012191672Sbms * and delay sending the initial MLDv1 report 2013191672Sbms * by not transitioning to the IDLE state. 2014191672Sbms */ 2015191672Sbms odelay = MLD_RANDOM_DELAY(MLD_V1_MAX_RI * PR_FASTHZ); 2016191672Sbms if (delay) { 2017191672Sbms inm->in6m_timer = max(delay, odelay); 2018191672Sbms V_current_state_timers_running6 = 1; 2019191672Sbms } else { 2020191672Sbms inm->in6m_state = MLD_IDLE_MEMBER; 2021191672Sbms error = mld_v1_transmit_report(inm, 2022191672Sbms MLD_LISTENER_REPORT); 2023191672Sbms if (error == 0) { 2024191672Sbms inm->in6m_timer = odelay; 2025191672Sbms V_current_state_timers_running6 = 1; 2026191672Sbms } 2027191672Sbms } 202878064Sume break; 2029191672Sbms 2030191672Sbms case MLD_VERSION_2: 2031191672Sbms /* 2032191672Sbms * Defer update of T0 to T1, until the first copy 2033191672Sbms * of the state change has been transmitted. 2034191672Sbms */ 2035191672Sbms syncstates = 0; 2036191672Sbms 2037191672Sbms /* 2038191672Sbms * Immediately enqueue a State-Change Report for 2039191672Sbms * this interface, freeing any previous reports. 2040191672Sbms * Don't kick the timers if there is nothing to do, 2041191672Sbms * or if an error occurred. 2042191672Sbms */ 2043191672Sbms ifq = &inm->in6m_scq; 2044191672Sbms _IF_DRAIN(ifq); 2045191672Sbms retval = mld_v2_enqueue_group_record(ifq, inm, 1, 2046191672Sbms 0, 0); 2047191672Sbms CTR2(KTR_MLD, "%s: enqueue record = %d", 2048191672Sbms __func__, retval); 2049191672Sbms if (retval <= 0) { 2050191672Sbms error = retval * -1; 2051191672Sbms break; 2052191672Sbms } 2053191672Sbms 2054191672Sbms /* 2055191672Sbms * Schedule transmission of pending state-change 2056191672Sbms * report up to RV times for this link. The timer 2057191672Sbms * will fire at the next mld_fasttimo (~200ms), 2058191672Sbms * giving us an opportunity to merge the reports. 2059191672Sbms * 2060191672Sbms * If a delay was provided to this function, only 2061191672Sbms * use this delay if sooner than the existing one. 2062191672Sbms */ 2063191672Sbms KASSERT(mli->mli_rv > 1, 2064191672Sbms ("%s: invalid robustness %d", __func__, 2065191672Sbms mli->mli_rv)); 2066191672Sbms inm->in6m_scrv = mli->mli_rv; 2067191672Sbms if (delay) { 2068191672Sbms if (inm->in6m_sctimer > 1) { 2069191672Sbms inm->in6m_sctimer = 2070191672Sbms min(inm->in6m_sctimer, delay); 2071191672Sbms } else 2072191672Sbms inm->in6m_sctimer = delay; 2073191672Sbms } else 2074191672Sbms inm->in6m_sctimer = 1; 2075191672Sbms V_state_change_timers_running6 = 1; 2076191672Sbms 2077191672Sbms error = 0; 207878064Sume break; 2079191672Sbms } 2080191672Sbms } 2081191672Sbms 2082191672Sbms /* 2083191672Sbms * Only update the T0 state if state change is atomic, 2084191672Sbms * i.e. we don't need to wait for a timer to fire before we 2085191672Sbms * can consider the state change to have been communicated. 2086191672Sbms */ 2087191672Sbms if (syncstates) { 2088191672Sbms in6m_commit(inm); 2089191672Sbms CTR3(KTR_MLD, "%s: T1 -> T0 for %s/%s", __func__, 2090191672Sbms ip6_sprintf(ip6tbuf, &inm->in6m_addr), 2091191672Sbms inm->in6m_ifp->if_xname); 2092191672Sbms } 2093191672Sbms 2094191672Sbms return (error); 2095191672Sbms} 2096191672Sbms 2097191672Sbms/* 2098191672Sbms * Issue an intermediate state change during the life-cycle. 2099191672Sbms */ 2100191672Sbmsstatic int 2101191672Sbmsmld_handle_state_change(struct in6_multi *inm, struct mld_ifinfo *mli) 2102191672Sbms{ 2103191672Sbms INIT_VNET_INET6(curvnet); 2104191672Sbms struct ifnet *ifp; 2105191672Sbms int retval; 2106191672Sbms#ifdef KTR 2107191672Sbms char ip6tbuf[INET6_ADDRSTRLEN]; 2108191672Sbms#endif 2109191672Sbms 2110191672Sbms CTR4(KTR_MLD, "%s: state change for %s on ifp %p(%s)", 2111191672Sbms __func__, ip6_sprintf(ip6tbuf, &inm->in6m_addr), 2112191672Sbms inm->in6m_ifp, inm->in6m_ifp->if_xname); 2113191672Sbms 2114191672Sbms ifp = inm->in6m_ifp; 2115191672Sbms 2116191672Sbms IN6_MULTI_LOCK_ASSERT(); 2117191672Sbms MLD_LOCK_ASSERT(); 2118191672Sbms 2119191672Sbms KASSERT(mli && mli->mli_ifp == ifp, 2120191672Sbms ("%s: inconsistent ifp", __func__)); 2121191672Sbms 2122191672Sbms if ((ifp->if_flags & IFF_LOOPBACK) || 2123191672Sbms (mli->mli_flags & MLIF_SILENT) || 2124191672Sbms !mld_is_addr_reported(&inm->in6m_addr) || 2125191672Sbms (mli->mli_version != MLD_VERSION_2)) { 2126191672Sbms if (!mld_is_addr_reported(&inm->in6m_addr)) { 2127191672Sbms CTR1(KTR_MLD, 2128191672Sbms"%s: not kicking state machine for silent group", __func__); 2129191672Sbms } 2130191672Sbms CTR1(KTR_MLD, "%s: nothing to do", __func__); 2131191672Sbms in6m_commit(inm); 2132191672Sbms CTR3(KTR_MLD, "%s: T1 -> T0 for %s/%s", __func__, 2133191672Sbms ip6_sprintf(ip6tbuf, &inm->in6m_addr), 2134191672Sbms inm->in6m_ifp->if_xname); 2135191672Sbms return (0); 2136191672Sbms } 2137191672Sbms 2138191672Sbms _IF_DRAIN(&inm->in6m_scq); 2139191672Sbms 2140191672Sbms retval = mld_v2_enqueue_group_record(&inm->in6m_scq, inm, 1, 0, 0); 2141191672Sbms CTR2(KTR_MLD, "%s: enqueue record = %d", __func__, retval); 2142191672Sbms if (retval <= 0) 2143191672Sbms return (-retval); 2144191672Sbms 2145191672Sbms /* 2146191672Sbms * If record(s) were enqueued, start the state-change 2147191672Sbms * report timer for this group. 2148191672Sbms */ 2149191672Sbms inm->in6m_scrv = mli->mli_rv; 2150191672Sbms inm->in6m_sctimer = 1; 2151191672Sbms V_state_change_timers_running6 = 1; 2152191672Sbms 2153191672Sbms return (0); 2154191672Sbms} 2155191672Sbms 2156191672Sbms/* 2157191672Sbms * Perform the final leave for a multicast address. 2158191672Sbms * 2159191672Sbms * When leaving a group: 2160191672Sbms * MLDv1 sends a DONE message, if and only if we are the reporter. 2161191672Sbms * MLDv2 enqueues a state-change report containing a transition 2162191672Sbms * to INCLUDE {} for immediate transmission. 2163191672Sbms */ 2164191672Sbmsstatic void 2165191672Sbmsmld_final_leave(struct in6_multi *inm, struct mld_ifinfo *mli) 2166191672Sbms{ 2167191672Sbms INIT_VNET_INET6(curvnet); 2168191672Sbms int syncstates; 2169191672Sbms#ifdef KTR 2170191672Sbms char ip6tbuf[INET6_ADDRSTRLEN]; 2171191672Sbms#endif 2172191672Sbms 2173191672Sbms syncstates = 1; 2174191672Sbms 2175191672Sbms CTR4(KTR_MLD, "%s: final leave %s on ifp %p(%s)", 2176191672Sbms __func__, ip6_sprintf(ip6tbuf, &inm->in6m_addr), 2177191672Sbms inm->in6m_ifp, inm->in6m_ifp->if_xname); 2178191672Sbms 2179191672Sbms IN6_MULTI_LOCK_ASSERT(); 2180191672Sbms MLD_LOCK_ASSERT(); 2181191672Sbms 2182191672Sbms switch (inm->in6m_state) { 2183191672Sbms case MLD_NOT_MEMBER: 2184191672Sbms case MLD_SILENT_MEMBER: 2185191672Sbms case MLD_LEAVING_MEMBER: 2186191672Sbms /* Already leaving or left; do nothing. */ 2187191672Sbms CTR1(KTR_MLD, 2188191672Sbms"%s: not kicking state machine for silent group", __func__); 2189191672Sbms break; 2190191672Sbms case MLD_REPORTING_MEMBER: 2191191672Sbms case MLD_IDLE_MEMBER: 2192191672Sbms case MLD_G_QUERY_PENDING_MEMBER: 2193191672Sbms case MLD_SG_QUERY_PENDING_MEMBER: 2194191672Sbms if (mli->mli_version == MLD_VERSION_1) { 2195191672Sbms#ifdef INVARIANTS 2196191672Sbms if (inm->in6m_state == MLD_G_QUERY_PENDING_MEMBER || 2197191672Sbms inm->in6m_state == MLD_SG_QUERY_PENDING_MEMBER) 2198191672Sbms panic("%s: MLDv2 state reached, not MLDv2 mode", 2199191672Sbms __func__); 2200191672Sbms#endif 2201191672Sbms mld_v1_transmit_report(inm, MLD_LISTENER_DONE); 2202191672Sbms inm->in6m_state = MLD_NOT_MEMBER; 2203191672Sbms } else if (mli->mli_version == MLD_VERSION_2) { 2204191672Sbms /* 2205191672Sbms * Stop group timer and all pending reports. 2206191672Sbms * Immediately enqueue a state-change report 2207191672Sbms * TO_IN {} to be sent on the next fast timeout, 2208191672Sbms * giving us an opportunity to merge reports. 2209191672Sbms */ 2210191672Sbms _IF_DRAIN(&inm->in6m_scq); 2211191672Sbms inm->in6m_timer = 0; 2212191672Sbms inm->in6m_scrv = mli->mli_rv; 2213191672Sbms CTR4(KTR_MLD, "%s: Leaving %s/%s with %d " 2214191672Sbms "pending retransmissions.", __func__, 2215191672Sbms ip6_sprintf(ip6tbuf, &inm->in6m_addr), 2216191672Sbms inm->in6m_ifp->if_xname, inm->in6m_scrv); 2217191672Sbms if (inm->in6m_scrv == 0) { 2218191672Sbms inm->in6m_state = MLD_NOT_MEMBER; 2219191672Sbms inm->in6m_sctimer = 0; 2220191672Sbms } else { 2221191672Sbms int retval; 2222191672Sbms 2223191672Sbms in6m_acquire_locked(inm); 2224191672Sbms 2225191672Sbms retval = mld_v2_enqueue_group_record( 2226191672Sbms &inm->in6m_scq, inm, 1, 0, 0); 2227191672Sbms KASSERT(retval != 0, 2228191672Sbms ("%s: enqueue record = %d", __func__, 2229191672Sbms retval)); 2230191672Sbms 2231191672Sbms inm->in6m_state = MLD_LEAVING_MEMBER; 2232191672Sbms inm->in6m_sctimer = 1; 2233191672Sbms V_state_change_timers_running6 = 1; 2234191672Sbms syncstates = 0; 2235191672Sbms } 223678064Sume break; 223753541Sshin } 2238191672Sbms break; 2239191672Sbms case MLD_LAZY_MEMBER: 2240191672Sbms case MLD_SLEEPING_MEMBER: 2241191672Sbms case MLD_AWAKENING_MEMBER: 2242191672Sbms /* Our reports are suppressed; do nothing. */ 2243191672Sbms break; 224453541Sshin } 2245191672Sbms 2246191672Sbms if (syncstates) { 2247191672Sbms in6m_commit(inm); 2248191672Sbms CTR3(KTR_MLD, "%s: T1 -> T0 for %s/%s", __func__, 2249191672Sbms ip6_sprintf(ip6tbuf, &inm->in6m_addr), 2250191672Sbms inm->in6m_ifp->if_xname); 2251191672Sbms inm->in6m_st[1].iss_fmode = MCAST_UNDEFINED; 2252191672Sbms CTR3(KTR_MLD, "%s: T1 now MCAST_UNDEFINED for %p/%s", 2253191672Sbms __func__, &inm->in6m_addr, inm->in6m_ifp->if_xname); 2254191672Sbms } 225553541Sshin} 2256126603Sume 2257126603Sume/* 2258191672Sbms * Enqueue an MLDv2 group record to the given output queue. 2259191672Sbms * 2260191672Sbms * If is_state_change is zero, a current-state record is appended. 2261191672Sbms * If is_state_change is non-zero, a state-change report is appended. 2262191672Sbms * 2263191672Sbms * If is_group_query is non-zero, an mbuf packet chain is allocated. 2264191672Sbms * If is_group_query is zero, and if there is a packet with free space 2265191672Sbms * at the tail of the queue, it will be appended to providing there 2266191672Sbms * is enough free space. 2267191672Sbms * Otherwise a new mbuf packet chain is allocated. 2268191672Sbms * 2269191672Sbms * If is_source_query is non-zero, each source is checked to see if 2270191672Sbms * it was recorded for a Group-Source query, and will be omitted if 2271191672Sbms * it is not both in-mode and recorded. 2272191672Sbms * 2273191672Sbms * The function will attempt to allocate leading space in the packet 2274191672Sbms * for the IPv6+ICMP headers to be prepended without fragmenting the chain. 2275191672Sbms * 2276191672Sbms * If successful the size of all data appended to the queue is returned, 2277191672Sbms * otherwise an error code less than zero is returned, or zero if 2278191672Sbms * no record(s) were appended. 2279126603Sume */ 2280191672Sbmsstatic int 2281191672Sbmsmld_v2_enqueue_group_record(struct ifqueue *ifq, struct in6_multi *inm, 2282191672Sbms const int is_state_change, const int is_group_query, 2283191672Sbms const int is_source_query) 2284126603Sume{ 2285191672Sbms struct mldv2_record mr; 2286191672Sbms struct mldv2_record *pmr; 2287191672Sbms struct ifnet *ifp; 2288191672Sbms struct ip6_msource *ims, *nims; 2289191672Sbms struct mbuf *m0, *m, *md; 2290191672Sbms int error, is_filter_list_change; 2291191672Sbms int minrec0len, m0srcs, msrcs, nbytes, off; 2292191672Sbms int record_has_sources; 2293191672Sbms int now; 2294191672Sbms int type; 2295191672Sbms uint8_t mode; 2296191672Sbms#ifdef KTR 2297191672Sbms char ip6tbuf[INET6_ADDRSTRLEN]; 2298191672Sbms#endif 2299126603Sume 2300191672Sbms IN6_MULTI_LOCK_ASSERT(); 2301126603Sume 2302191672Sbms error = 0; 2303191672Sbms ifp = inm->in6m_ifp; 2304191672Sbms is_filter_list_change = 0; 2305191672Sbms m = NULL; 2306191672Sbms m0 = NULL; 2307191672Sbms m0srcs = 0; 2308191672Sbms msrcs = 0; 2309191672Sbms nbytes = 0; 2310191672Sbms nims = NULL; 2311191672Sbms record_has_sources = 1; 2312191672Sbms pmr = NULL; 2313191672Sbms type = MLD_DO_NOTHING; 2314191672Sbms mode = inm->in6m_st[1].iss_fmode; 2315126603Sume 2316191672Sbms /* 2317191672Sbms * If we did not transition out of ASM mode during t0->t1, 2318191672Sbms * and there are no source nodes to process, we can skip 2319191672Sbms * the generation of source records. 2320191672Sbms */ 2321191672Sbms if (inm->in6m_st[0].iss_asm > 0 && inm->in6m_st[1].iss_asm > 0 && 2322191672Sbms inm->in6m_nsrc == 0) 2323191672Sbms record_has_sources = 0; 2324191672Sbms 2325191672Sbms if (is_state_change) { 2326167729Sbms /* 2327191672Sbms * Queue a state change record. 2328191672Sbms * If the mode did not change, and there are non-ASM 2329191672Sbms * listeners or source filters present, 2330191672Sbms * we potentially need to issue two records for the group. 2331191672Sbms * If we are transitioning to MCAST_UNDEFINED, we need 2332191672Sbms * not send any sources. 2333191672Sbms * If there are ASM listeners, and there was no filter 2334191672Sbms * mode transition of any kind, do nothing. 2335167729Sbms */ 2336191672Sbms if (mode != inm->in6m_st[0].iss_fmode) { 2337191672Sbms if (mode == MCAST_EXCLUDE) { 2338191672Sbms CTR1(KTR_MLD, "%s: change to EXCLUDE", 2339191672Sbms __func__); 2340191672Sbms type = MLD_CHANGE_TO_EXCLUDE_MODE; 2341191672Sbms } else { 2342191672Sbms CTR1(KTR_MLD, "%s: change to INCLUDE", 2343191672Sbms __func__); 2344191672Sbms type = MLD_CHANGE_TO_INCLUDE_MODE; 2345191672Sbms if (mode == MCAST_UNDEFINED) 2346191672Sbms record_has_sources = 0; 2347191672Sbms } 2348191672Sbms } else { 2349191672Sbms if (record_has_sources) { 2350191672Sbms is_filter_list_change = 1; 2351191672Sbms } else { 2352191672Sbms type = MLD_DO_NOTHING; 2353191672Sbms } 2354191672Sbms } 2355191672Sbms } else { 2356191672Sbms /* 2357191672Sbms * Queue a current state record. 2358191672Sbms */ 2359191672Sbms if (mode == MCAST_EXCLUDE) { 2360191672Sbms type = MLD_MODE_IS_EXCLUDE; 2361191672Sbms } else if (mode == MCAST_INCLUDE) { 2362191672Sbms type = MLD_MODE_IS_INCLUDE; 2363191672Sbms KASSERT(inm->in6m_st[1].iss_asm == 0, 2364191672Sbms ("%s: inm %p is INCLUDE but ASM count is %d", 2365191672Sbms __func__, inm, inm->in6m_st[1].iss_asm)); 2366191672Sbms } 2367191672Sbms } 2368126603Sume 2369191672Sbms /* 2370191672Sbms * Generate the filter list changes using a separate function. 2371191672Sbms */ 2372191672Sbms if (is_filter_list_change) 2373191672Sbms return (mld_v2_enqueue_filter_change(ifq, inm)); 2374126603Sume 2375191672Sbms if (type == MLD_DO_NOTHING) { 2376191672Sbms CTR3(KTR_MLD, "%s: nothing to do for %s/%s", 2377191672Sbms __func__, ip6_sprintf(ip6tbuf, &inm->in6m_addr), 2378191672Sbms inm->in6m_ifp->if_xname); 2379191672Sbms return (0); 2380191672Sbms } 2381126603Sume 2382191672Sbms /* 2383191672Sbms * If any sources are present, we must be able to fit at least 2384191672Sbms * one in the trailing space of the tail packet's mbuf, 2385191672Sbms * ideally more. 2386191672Sbms */ 2387191672Sbms minrec0len = sizeof(struct mldv2_record); 2388191672Sbms if (record_has_sources) 2389191672Sbms minrec0len += sizeof(struct in6_addr); 2390191672Sbms 2391191672Sbms CTR4(KTR_MLD, "%s: queueing %s for %s/%s", __func__, 2392191672Sbms mld_rec_type_to_str(type), 2393191672Sbms ip6_sprintf(ip6tbuf, &inm->in6m_addr), 2394191672Sbms inm->in6m_ifp->if_xname); 2395191672Sbms 2396191672Sbms /* 2397191672Sbms * Check if we have a packet in the tail of the queue for this 2398191672Sbms * group into which the first group record for this group will fit. 2399191672Sbms * Otherwise allocate a new packet. 2400191672Sbms * Always allocate leading space for IP6+RA+ICMPV6+REPORT. 2401191672Sbms * Note: Group records for G/GSR query responses MUST be sent 2402191672Sbms * in their own packet. 2403191672Sbms */ 2404191672Sbms m0 = ifq->ifq_tail; 2405191672Sbms if (!is_group_query && 2406191672Sbms m0 != NULL && 2407191672Sbms (m0->m_pkthdr.PH_vt.vt_nrecs + 1 <= MLD_V2_REPORT_MAXRECS) && 2408191672Sbms (m0->m_pkthdr.len + minrec0len) < 2409191672Sbms (ifp->if_mtu - MLD_MTUSPACE)) { 2410191672Sbms m0srcs = (ifp->if_mtu - m0->m_pkthdr.len - 2411191672Sbms sizeof(struct mldv2_record)) / 2412191672Sbms sizeof(struct in6_addr); 2413191672Sbms m = m0; 2414191672Sbms CTR1(KTR_MLD, "%s: use existing packet", __func__); 2415191672Sbms } else { 2416191672Sbms if (_IF_QFULL(ifq)) { 2417191672Sbms CTR1(KTR_MLD, "%s: outbound queue full", __func__); 2418191672Sbms return (-ENOMEM); 2419191672Sbms } 2420191672Sbms m = NULL; 2421191672Sbms m0srcs = (ifp->if_mtu - MLD_MTUSPACE - 2422191672Sbms sizeof(struct mldv2_record)) / sizeof(struct in6_addr); 2423191672Sbms if (!is_state_change && !is_group_query) 2424191672Sbms m = m_getcl(M_DONTWAIT, MT_DATA, M_PKTHDR); 2425191672Sbms if (m == NULL) 2426191672Sbms m = m_gethdr(M_DONTWAIT, MT_DATA); 2427191672Sbms if (m == NULL) 2428191672Sbms return (-ENOMEM); 2429191672Sbms 2430191672Sbms mld_save_context(m, ifp); 2431191672Sbms 2432191672Sbms CTR1(KTR_MLD, "%s: allocated first packet", __func__); 2433191672Sbms } 2434191672Sbms 2435191672Sbms /* 2436191672Sbms * Append group record. 2437191672Sbms * If we have sources, we don't know how many yet. 2438191672Sbms */ 2439191672Sbms mr.mr_type = type; 2440191672Sbms mr.mr_datalen = 0; 2441191672Sbms mr.mr_numsrc = 0; 2442191672Sbms mr.mr_addr = inm->in6m_addr; 2443191672Sbms in6_clearscope(&mr.mr_addr); 2444191672Sbms if (!m_append(m, sizeof(struct mldv2_record), (void *)&mr)) { 2445191672Sbms if (m != m0) 2446191672Sbms m_freem(m); 2447191672Sbms CTR1(KTR_MLD, "%s: m_append() failed.", __func__); 2448191672Sbms return (-ENOMEM); 2449191672Sbms } 2450191672Sbms nbytes += sizeof(struct mldv2_record); 2451191672Sbms 2452191672Sbms /* 2453191672Sbms * Append as many sources as will fit in the first packet. 2454191672Sbms * If we are appending to a new packet, the chain allocation 2455191672Sbms * may potentially use clusters; use m_getptr() in this case. 2456191672Sbms * If we are appending to an existing packet, we need to obtain 2457191672Sbms * a pointer to the group record after m_append(), in case a new 2458191672Sbms * mbuf was allocated. 2459191672Sbms * Only append sources which are in-mode at t1. If we are 2460191672Sbms * transitioning to MCAST_UNDEFINED state on the group, do not 2461191672Sbms * include source entries. 2462191672Sbms * Only report recorded sources in our filter set when responding 2463191672Sbms * to a group-source query. 2464191672Sbms */ 2465191672Sbms if (record_has_sources) { 2466191672Sbms if (m == m0) { 2467191672Sbms md = m_last(m); 2468191672Sbms pmr = (struct mldv2_record *)(mtod(md, uint8_t *) + 2469191672Sbms md->m_len - nbytes); 2470191672Sbms } else { 2471191672Sbms md = m_getptr(m, 0, &off); 2472191672Sbms pmr = (struct mldv2_record *)(mtod(md, uint8_t *) + 2473191672Sbms off); 2474191672Sbms } 2475191672Sbms msrcs = 0; 2476191672Sbms RB_FOREACH_SAFE(ims, ip6_msource_tree, &inm->in6m_srcs, 2477191672Sbms nims) { 2478191672Sbms CTR2(KTR_MLD, "%s: visit node %s", __func__, 2479191672Sbms ip6_sprintf(ip6tbuf, &ims->im6s_addr)); 2480191672Sbms now = im6s_get_mode(inm, ims, 1); 2481191672Sbms CTR2(KTR_MLD, "%s: node is %d", __func__, now); 2482191672Sbms if ((now != mode) || 2483191672Sbms (now == mode && mode == MCAST_UNDEFINED)) { 2484191672Sbms CTR1(KTR_MLD, "%s: skip node", __func__); 2485191672Sbms continue; 2486191672Sbms } 2487191672Sbms if (is_source_query && ims->im6s_stp == 0) { 2488191672Sbms CTR1(KTR_MLD, "%s: skip unrecorded node", 2489191672Sbms __func__); 2490191672Sbms continue; 2491191672Sbms } 2492191672Sbms CTR1(KTR_MLD, "%s: append node", __func__); 2493191672Sbms if (!m_append(m, sizeof(struct in6_addr), 2494191672Sbms (void *)&ims->im6s_addr)) { 2495191672Sbms if (m != m0) 2496191672Sbms m_freem(m); 2497191672Sbms CTR1(KTR_MLD, "%s: m_append() failed.", 2498191672Sbms __func__); 2499191672Sbms return (-ENOMEM); 2500191672Sbms } 2501191672Sbms nbytes += sizeof(struct in6_addr); 2502191672Sbms ++msrcs; 2503191672Sbms if (msrcs == m0srcs) 2504191672Sbms break; 2505191672Sbms } 2506191672Sbms CTR2(KTR_MLD, "%s: msrcs is %d this packet", __func__, 2507191672Sbms msrcs); 2508191672Sbms pmr->mr_numsrc = htons(msrcs); 2509191672Sbms nbytes += (msrcs * sizeof(struct in6_addr)); 2510191672Sbms } 2511191672Sbms 2512191672Sbms if (is_source_query && msrcs == 0) { 2513191672Sbms CTR1(KTR_MLD, "%s: no recorded sources to report", __func__); 2514191672Sbms if (m != m0) 2515191672Sbms m_freem(m); 2516191672Sbms return (0); 2517191672Sbms } 2518191672Sbms 2519191672Sbms /* 2520191672Sbms * We are good to go with first packet. 2521191672Sbms */ 2522191672Sbms if (m != m0) { 2523191672Sbms CTR1(KTR_MLD, "%s: enqueueing first packet", __func__); 2524191672Sbms m->m_pkthdr.PH_vt.vt_nrecs = 1; 2525191672Sbms _IF_ENQUEUE(ifq, m); 2526191672Sbms } else 2527191672Sbms m->m_pkthdr.PH_vt.vt_nrecs++; 2528191672Sbms 2529191672Sbms /* 2530191672Sbms * No further work needed if no source list in packet(s). 2531191672Sbms */ 2532191672Sbms if (!record_has_sources) 2533191672Sbms return (nbytes); 2534191672Sbms 2535191672Sbms /* 2536191672Sbms * Whilst sources remain to be announced, we need to allocate 2537191672Sbms * a new packet and fill out as many sources as will fit. 2538191672Sbms * Always try for a cluster first. 2539191672Sbms */ 2540191672Sbms while (nims != NULL) { 2541191672Sbms if (_IF_QFULL(ifq)) { 2542191672Sbms CTR1(KTR_MLD, "%s: outbound queue full", __func__); 2543191672Sbms return (-ENOMEM); 2544191672Sbms } 2545191672Sbms m = m_getcl(M_DONTWAIT, MT_DATA, M_PKTHDR); 2546191672Sbms if (m == NULL) 2547191672Sbms m = m_gethdr(M_DONTWAIT, MT_DATA); 2548191672Sbms if (m == NULL) 2549191672Sbms return (-ENOMEM); 2550191672Sbms mld_save_context(m, ifp); 2551191672Sbms md = m_getptr(m, 0, &off); 2552191672Sbms pmr = (struct mldv2_record *)(mtod(md, uint8_t *) + off); 2553191672Sbms CTR1(KTR_MLD, "%s: allocated next packet", __func__); 2554191672Sbms 2555191672Sbms if (!m_append(m, sizeof(struct mldv2_record), (void *)&mr)) { 2556191672Sbms if (m != m0) 2557191672Sbms m_freem(m); 2558191672Sbms CTR1(KTR_MLD, "%s: m_append() failed.", __func__); 2559191672Sbms return (-ENOMEM); 2560191672Sbms } 2561191672Sbms m->m_pkthdr.PH_vt.vt_nrecs = 1; 2562191672Sbms nbytes += sizeof(struct mldv2_record); 2563191672Sbms 2564191672Sbms m0srcs = (ifp->if_mtu - MLD_MTUSPACE - 2565191672Sbms sizeof(struct mldv2_record)) / sizeof(struct in6_addr); 2566191672Sbms 2567191672Sbms msrcs = 0; 2568191672Sbms RB_FOREACH_FROM(ims, ip6_msource_tree, nims) { 2569191672Sbms CTR2(KTR_MLD, "%s: visit node %s", 2570191672Sbms __func__, ip6_sprintf(ip6tbuf, &ims->im6s_addr)); 2571191672Sbms now = im6s_get_mode(inm, ims, 1); 2572191672Sbms if ((now != mode) || 2573191672Sbms (now == mode && mode == MCAST_UNDEFINED)) { 2574191672Sbms CTR1(KTR_MLD, "%s: skip node", __func__); 2575191672Sbms continue; 2576191672Sbms } 2577191672Sbms if (is_source_query && ims->im6s_stp == 0) { 2578191672Sbms CTR1(KTR_MLD, "%s: skip unrecorded node", 2579191672Sbms __func__); 2580191672Sbms continue; 2581191672Sbms } 2582191672Sbms CTR1(KTR_MLD, "%s: append node", __func__); 2583191672Sbms if (!m_append(m, sizeof(struct in6_addr), 2584191672Sbms (void *)&ims->im6s_addr)) { 2585191672Sbms if (m != m0) 2586191672Sbms m_freem(m); 2587191672Sbms CTR1(KTR_MLD, "%s: m_append() failed.", 2588191672Sbms __func__); 2589191672Sbms return (-ENOMEM); 2590191672Sbms } 2591191672Sbms ++msrcs; 2592191672Sbms if (msrcs == m0srcs) 2593191672Sbms break; 2594191672Sbms } 2595191672Sbms pmr->mr_numsrc = htons(msrcs); 2596191672Sbms nbytes += (msrcs * sizeof(struct in6_addr)); 2597191672Sbms 2598191672Sbms CTR1(KTR_MLD, "%s: enqueueing next packet", __func__); 2599191672Sbms _IF_ENQUEUE(ifq, m); 2600191672Sbms } 2601191672Sbms 2602191672Sbms return (nbytes); 2603191672Sbms} 2604191672Sbms 2605191672Sbms/* 2606191672Sbms * Type used to mark record pass completion. 2607191672Sbms * We exploit the fact we can cast to this easily from the 2608191672Sbms * current filter modes on each ip_msource node. 2609191672Sbms */ 2610191672Sbmstypedef enum { 2611191672Sbms REC_NONE = 0x00, /* MCAST_UNDEFINED */ 2612191672Sbms REC_ALLOW = 0x01, /* MCAST_INCLUDE */ 2613191672Sbms REC_BLOCK = 0x02, /* MCAST_EXCLUDE */ 2614191672Sbms REC_FULL = REC_ALLOW | REC_BLOCK 2615191672Sbms} rectype_t; 2616191672Sbms 2617191672Sbms/* 2618191672Sbms * Enqueue an MLDv2 filter list change to the given output queue. 2619191672Sbms * 2620191672Sbms * Source list filter state is held in an RB-tree. When the filter list 2621191672Sbms * for a group is changed without changing its mode, we need to compute 2622191672Sbms * the deltas between T0 and T1 for each source in the filter set, 2623191672Sbms * and enqueue the appropriate ALLOW_NEW/BLOCK_OLD records. 2624191672Sbms * 2625191672Sbms * As we may potentially queue two record types, and the entire R-B tree 2626191672Sbms * needs to be walked at once, we break this out into its own function 2627191672Sbms * so we can generate a tightly packed queue of packets. 2628191672Sbms * 2629191672Sbms * XXX This could be written to only use one tree walk, although that makes 2630191672Sbms * serializing into the mbuf chains a bit harder. For now we do two walks 2631191672Sbms * which makes things easier on us, and it may or may not be harder on 2632191672Sbms * the L2 cache. 2633191672Sbms * 2634191672Sbms * If successful the size of all data appended to the queue is returned, 2635191672Sbms * otherwise an error code less than zero is returned, or zero if 2636191672Sbms * no record(s) were appended. 2637191672Sbms */ 2638191672Sbmsstatic int 2639191672Sbmsmld_v2_enqueue_filter_change(struct ifqueue *ifq, struct in6_multi *inm) 2640191672Sbms{ 2641191672Sbms static const int MINRECLEN = 2642191672Sbms sizeof(struct mldv2_record) + sizeof(struct in6_addr); 2643191672Sbms struct ifnet *ifp; 2644191672Sbms struct mldv2_record mr; 2645191672Sbms struct mldv2_record *pmr; 2646191672Sbms struct ip6_msource *ims, *nims; 2647191672Sbms struct mbuf *m, *m0, *md; 2648191672Sbms int m0srcs, nbytes, npbytes, off, rsrcs, schanged; 2649191672Sbms int nallow, nblock; 2650191672Sbms uint8_t mode, now, then; 2651191672Sbms rectype_t crt, drt, nrt; 2652191672Sbms#ifdef KTR 2653191672Sbms char ip6tbuf[INET6_ADDRSTRLEN]; 2654191672Sbms#endif 2655191672Sbms 2656191672Sbms IN6_MULTI_LOCK_ASSERT(); 2657191672Sbms 2658191672Sbms if (inm->in6m_nsrc == 0 || 2659191672Sbms (inm->in6m_st[0].iss_asm > 0 && inm->in6m_st[1].iss_asm > 0)) 2660191672Sbms return (0); 2661191672Sbms 2662191672Sbms ifp = inm->in6m_ifp; /* interface */ 2663191672Sbms mode = inm->in6m_st[1].iss_fmode; /* filter mode at t1 */ 2664191672Sbms crt = REC_NONE; /* current group record type */ 2665191672Sbms drt = REC_NONE; /* mask of completed group record types */ 2666191672Sbms nrt = REC_NONE; /* record type for current node */ 2667191672Sbms m0srcs = 0; /* # source which will fit in current mbuf chain */ 2668191672Sbms npbytes = 0; /* # of bytes appended this packet */ 2669191672Sbms nbytes = 0; /* # of bytes appended to group's state-change queue */ 2670191672Sbms rsrcs = 0; /* # sources encoded in current record */ 2671191672Sbms schanged = 0; /* # nodes encoded in overall filter change */ 2672191672Sbms nallow = 0; /* # of source entries in ALLOW_NEW */ 2673191672Sbms nblock = 0; /* # of source entries in BLOCK_OLD */ 2674191672Sbms nims = NULL; /* next tree node pointer */ 2675191672Sbms 2676191672Sbms /* 2677191672Sbms * For each possible filter record mode. 2678191672Sbms * The first kind of source we encounter tells us which 2679191672Sbms * is the first kind of record we start appending. 2680191672Sbms * If a node transitioned to UNDEFINED at t1, its mode is treated 2681191672Sbms * as the inverse of the group's filter mode. 2682191672Sbms */ 2683191672Sbms while (drt != REC_FULL) { 2684191672Sbms do { 2685191672Sbms m0 = ifq->ifq_tail; 2686191672Sbms if (m0 != NULL && 2687191672Sbms (m0->m_pkthdr.PH_vt.vt_nrecs + 1 <= 2688191672Sbms MLD_V2_REPORT_MAXRECS) && 2689191672Sbms (m0->m_pkthdr.len + MINRECLEN) < 2690191672Sbms (ifp->if_mtu - MLD_MTUSPACE)) { 2691191672Sbms m = m0; 2692191672Sbms m0srcs = (ifp->if_mtu - m0->m_pkthdr.len - 2693191672Sbms sizeof(struct mldv2_record)) / 2694191672Sbms sizeof(struct in6_addr); 2695191672Sbms CTR1(KTR_MLD, 2696191672Sbms "%s: use previous packet", __func__); 2697191672Sbms } else { 2698191672Sbms m = m_getcl(M_DONTWAIT, MT_DATA, M_PKTHDR); 2699191672Sbms if (m == NULL) 2700191672Sbms m = m_gethdr(M_DONTWAIT, MT_DATA); 2701191672Sbms if (m == NULL) { 2702191672Sbms CTR1(KTR_MLD, 2703191672Sbms "%s: m_get*() failed", __func__); 2704191672Sbms return (-ENOMEM); 2705191672Sbms } 2706191672Sbms m->m_pkthdr.PH_vt.vt_nrecs = 0; 2707191672Sbms mld_save_context(m, ifp); 2708191672Sbms m0srcs = (ifp->if_mtu - MLD_MTUSPACE - 2709191672Sbms sizeof(struct mldv2_record)) / 2710191672Sbms sizeof(struct in6_addr); 2711191672Sbms npbytes = 0; 2712191672Sbms CTR1(KTR_MLD, 2713191672Sbms "%s: allocated new packet", __func__); 2714191672Sbms } 2715191672Sbms /* 2716191672Sbms * Append the MLD group record header to the 2717191672Sbms * current packet's data area. 2718191672Sbms * Recalculate pointer to free space for next 2719191672Sbms * group record, in case m_append() allocated 2720191672Sbms * a new mbuf or cluster. 2721191672Sbms */ 2722191672Sbms memset(&mr, 0, sizeof(mr)); 2723191672Sbms mr.mr_addr = inm->in6m_addr; 2724191672Sbms in6_clearscope(&mr.mr_addr); 2725191672Sbms if (!m_append(m, sizeof(mr), (void *)&mr)) { 2726191672Sbms if (m != m0) 2727191672Sbms m_freem(m); 2728191672Sbms CTR1(KTR_MLD, 2729191672Sbms "%s: m_append() failed", __func__); 2730191672Sbms return (-ENOMEM); 2731191672Sbms } 2732191672Sbms npbytes += sizeof(struct mldv2_record); 2733191672Sbms if (m != m0) { 2734191672Sbms /* new packet; offset in chain */ 2735191672Sbms md = m_getptr(m, npbytes - 2736191672Sbms sizeof(struct mldv2_record), &off); 2737191672Sbms pmr = (struct mldv2_record *)(mtod(md, 2738191672Sbms uint8_t *) + off); 2739191672Sbms } else { 2740191672Sbms /* current packet; offset from last append */ 2741191672Sbms md = m_last(m); 2742191672Sbms pmr = (struct mldv2_record *)(mtod(md, 2743191672Sbms uint8_t *) + md->m_len - 2744191672Sbms sizeof(struct mldv2_record)); 2745191672Sbms } 2746191672Sbms /* 2747191672Sbms * Begin walking the tree for this record type 2748191672Sbms * pass, or continue from where we left off 2749191672Sbms * previously if we had to allocate a new packet. 2750191672Sbms * Only report deltas in-mode at t1. 2751191672Sbms * We need not report included sources as allowed 2752191672Sbms * if we are in inclusive mode on the group, 2753191672Sbms * however the converse is not true. 2754191672Sbms */ 2755191672Sbms rsrcs = 0; 2756191672Sbms if (nims == NULL) { 2757191672Sbms nims = RB_MIN(ip6_msource_tree, 2758191672Sbms &inm->in6m_srcs); 2759191672Sbms } 2760191672Sbms RB_FOREACH_FROM(ims, ip6_msource_tree, nims) { 2761191672Sbms CTR2(KTR_MLD, "%s: visit node %s", __func__, 2762191672Sbms ip6_sprintf(ip6tbuf, &ims->im6s_addr)); 2763191672Sbms now = im6s_get_mode(inm, ims, 1); 2764191672Sbms then = im6s_get_mode(inm, ims, 0); 2765191672Sbms CTR3(KTR_MLD, "%s: mode: t0 %d, t1 %d", 2766191672Sbms __func__, then, now); 2767191672Sbms if (now == then) { 2768191672Sbms CTR1(KTR_MLD, 2769191672Sbms "%s: skip unchanged", __func__); 2770191672Sbms continue; 2771191672Sbms } 2772191672Sbms if (mode == MCAST_EXCLUDE && 2773191672Sbms now == MCAST_INCLUDE) { 2774191672Sbms CTR1(KTR_MLD, 2775191672Sbms "%s: skip IN src on EX group", 2776191672Sbms __func__); 2777191672Sbms continue; 2778191672Sbms } 2779191672Sbms nrt = (rectype_t)now; 2780191672Sbms if (nrt == REC_NONE) 2781191672Sbms nrt = (rectype_t)(~mode & REC_FULL); 2782191672Sbms if (schanged++ == 0) { 2783191672Sbms crt = nrt; 2784191672Sbms } else if (crt != nrt) 2785191672Sbms continue; 2786191672Sbms if (!m_append(m, sizeof(struct in6_addr), 2787191672Sbms (void *)&ims->im6s_addr)) { 2788191672Sbms if (m != m0) 2789191672Sbms m_freem(m); 2790191672Sbms CTR1(KTR_MLD, 2791191672Sbms "%s: m_append() failed", __func__); 2792191672Sbms return (-ENOMEM); 2793191672Sbms } 2794191672Sbms nallow += !!(crt == REC_ALLOW); 2795191672Sbms nblock += !!(crt == REC_BLOCK); 2796191672Sbms if (++rsrcs == m0srcs) 2797191672Sbms break; 2798191672Sbms } 2799191672Sbms /* 2800191672Sbms * If we did not append any tree nodes on this 2801191672Sbms * pass, back out of allocations. 2802191672Sbms */ 2803191672Sbms if (rsrcs == 0) { 2804191672Sbms npbytes -= sizeof(struct mldv2_record); 2805191672Sbms if (m != m0) { 2806191672Sbms CTR1(KTR_MLD, 2807191672Sbms "%s: m_free(m)", __func__); 2808191672Sbms m_freem(m); 2809191672Sbms } else { 2810191672Sbms CTR1(KTR_MLD, 2811191672Sbms "%s: m_adj(m, -mr)", __func__); 2812191672Sbms m_adj(m, -((int)sizeof( 2813191672Sbms struct mldv2_record))); 2814191672Sbms } 2815191672Sbms continue; 2816191672Sbms } 2817191672Sbms npbytes += (rsrcs * sizeof(struct in6_addr)); 2818191672Sbms if (crt == REC_ALLOW) 2819191672Sbms pmr->mr_type = MLD_ALLOW_NEW_SOURCES; 2820191672Sbms else if (crt == REC_BLOCK) 2821191672Sbms pmr->mr_type = MLD_BLOCK_OLD_SOURCES; 2822191672Sbms pmr->mr_numsrc = htons(rsrcs); 2823191672Sbms /* 2824191672Sbms * Count the new group record, and enqueue this 2825191672Sbms * packet if it wasn't already queued. 2826191672Sbms */ 2827191672Sbms m->m_pkthdr.PH_vt.vt_nrecs++; 2828191672Sbms if (m != m0) 2829191672Sbms _IF_ENQUEUE(ifq, m); 2830191672Sbms nbytes += npbytes; 2831191672Sbms } while (nims != NULL); 2832191672Sbms drt |= crt; 2833191672Sbms crt = (~crt & REC_FULL); 2834191672Sbms } 2835191672Sbms 2836191672Sbms CTR3(KTR_MLD, "%s: queued %d ALLOW_NEW, %d BLOCK_OLD", __func__, 2837191672Sbms nallow, nblock); 2838191672Sbms 2839191672Sbms return (nbytes); 2840191672Sbms} 2841191672Sbms 2842191672Sbmsstatic int 2843191672Sbmsmld_v2_merge_state_changes(struct in6_multi *inm, struct ifqueue *ifscq) 2844191672Sbms{ 2845191672Sbms struct ifqueue *gq; 2846191672Sbms struct mbuf *m; /* pending state-change */ 2847191672Sbms struct mbuf *m0; /* copy of pending state-change */ 2848191672Sbms struct mbuf *mt; /* last state-change in packet */ 2849191672Sbms int docopy, domerge; 2850191672Sbms u_int recslen; 2851191672Sbms 2852191672Sbms docopy = 0; 2853191672Sbms domerge = 0; 2854191672Sbms recslen = 0; 2855191672Sbms 2856191672Sbms IN6_MULTI_LOCK_ASSERT(); 2857191672Sbms MLD_LOCK_ASSERT(); 2858191672Sbms 2859191672Sbms /* 2860191672Sbms * If there are further pending retransmissions, make a writable 2861191672Sbms * copy of each queued state-change message before merging. 2862191672Sbms */ 2863191672Sbms if (inm->in6m_scrv > 0) 2864191672Sbms docopy = 1; 2865191672Sbms 2866191672Sbms gq = &inm->in6m_scq; 2867191672Sbms#ifdef KTR 2868191672Sbms if (gq->ifq_head == NULL) { 2869191672Sbms CTR2(KTR_MLD, "%s: WARNING: queue for inm %p is empty", 2870191672Sbms __func__, inm); 2871191672Sbms } 2872191672Sbms#endif 2873191672Sbms 2874191672Sbms m = gq->ifq_head; 2875191672Sbms while (m != NULL) { 2876167729Sbms /* 2877191672Sbms * Only merge the report into the current packet if 2878191672Sbms * there is sufficient space to do so; an MLDv2 report 2879191672Sbms * packet may only contain 65,535 group records. 2880191672Sbms * Always use a simple mbuf chain concatentation to do this, 2881191672Sbms * as large state changes for single groups may have 2882191672Sbms * allocated clusters. 2883167729Sbms */ 2884191672Sbms domerge = 0; 2885191672Sbms mt = ifscq->ifq_tail; 2886191672Sbms if (mt != NULL) { 2887191672Sbms recslen = m_length(m, NULL); 2888191672Sbms 2889191672Sbms if ((mt->m_pkthdr.PH_vt.vt_nrecs + 2890191672Sbms m->m_pkthdr.PH_vt.vt_nrecs <= 2891191672Sbms MLD_V2_REPORT_MAXRECS) && 2892191672Sbms (mt->m_pkthdr.len + recslen <= 2893191672Sbms (inm->in6m_ifp->if_mtu - MLD_MTUSPACE))) 2894191672Sbms domerge = 1; 2895167729Sbms } 2896151539Ssuz 2897191672Sbms if (!domerge && _IF_QFULL(gq)) { 2898191672Sbms CTR2(KTR_MLD, 2899191672Sbms "%s: outbound queue full, skipping whole packet %p", 2900191672Sbms __func__, m); 2901191672Sbms mt = m->m_nextpkt; 2902191672Sbms if (!docopy) 2903191672Sbms m_freem(m); 2904191672Sbms m = mt; 2905191672Sbms continue; 2906167729Sbms } 2907151539Ssuz 2908191672Sbms if (!docopy) { 2909191672Sbms CTR2(KTR_MLD, "%s: dequeueing %p", __func__, m); 2910191672Sbms _IF_DEQUEUE(gq, m0); 2911191672Sbms m = m0->m_nextpkt; 2912191672Sbms } else { 2913191672Sbms CTR2(KTR_MLD, "%s: copying %p", __func__, m); 2914191672Sbms m0 = m_dup(m, M_NOWAIT); 2915191672Sbms if (m0 == NULL) 2916191672Sbms return (ENOMEM); 2917191672Sbms m0->m_nextpkt = NULL; 2918191672Sbms m = m->m_nextpkt; 2919191672Sbms } 2920167729Sbms 2921191672Sbms if (!domerge) { 2922191672Sbms CTR3(KTR_MLD, "%s: queueing %p to ifscq %p)", 2923191672Sbms __func__, m0, ifscq); 2924191672Sbms _IF_ENQUEUE(ifscq, m0); 2925191672Sbms } else { 2926191672Sbms struct mbuf *mtl; /* last mbuf of packet mt */ 2927191672Sbms 2928191672Sbms CTR3(KTR_MLD, "%s: merging %p with ifscq tail %p)", 2929191672Sbms __func__, m0, mt); 2930191672Sbms 2931191672Sbms mtl = m_last(mt); 2932191672Sbms m0->m_flags &= ~M_PKTHDR; 2933191672Sbms mt->m_pkthdr.len += recslen; 2934191672Sbms mt->m_pkthdr.PH_vt.vt_nrecs += 2935191672Sbms m0->m_pkthdr.PH_vt.vt_nrecs; 2936191672Sbms 2937191672Sbms mtl->m_next = m0; 2938191672Sbms } 2939191672Sbms } 2940191672Sbms 2941191672Sbms return (0); 2942191672Sbms} 2943191672Sbms 2944191672Sbms/* 2945191672Sbms * Respond to a pending MLDv2 General Query. 2946191672Sbms */ 2947191672Sbmsstatic void 2948191672Sbmsmld_v2_dispatch_general_query(struct mld_ifinfo *mli) 2949191672Sbms{ 2950191672Sbms INIT_VNET_INET6(curvnet); 2951191672Sbms struct ifmultiaddr *ifma, *tifma; 2952191672Sbms struct ifnet *ifp; 2953191672Sbms struct in6_multi *inm; 2954191672Sbms int retval; 2955191672Sbms 2956191672Sbms IN6_MULTI_LOCK_ASSERT(); 2957191672Sbms MLD_LOCK_ASSERT(); 2958191672Sbms 2959191672Sbms KASSERT(mli->mli_version == MLD_VERSION_2, 2960191672Sbms ("%s: called when version %d", __func__, mli->mli_version)); 2961191672Sbms 2962191672Sbms ifp = mli->mli_ifp; 2963191672Sbms 2964191672Sbms IF_ADDR_LOCK(ifp); 2965191672Sbms TAILQ_FOREACH_SAFE(ifma, &ifp->if_multiaddrs, ifma_link, tifma) { 2966191672Sbms if (ifma->ifma_addr->sa_family != AF_INET6 || 2967191672Sbms ifma->ifma_protospec == NULL) 2968191672Sbms continue; 2969191672Sbms 2970191672Sbms inm = (struct in6_multi *)ifma->ifma_protospec; 2971191672Sbms KASSERT(ifp == inm->in6m_ifp, 2972191672Sbms ("%s: inconsistent ifp", __func__)); 2973191672Sbms 2974191672Sbms switch (inm->in6m_state) { 2975191672Sbms case MLD_NOT_MEMBER: 2976191672Sbms case MLD_SILENT_MEMBER: 2977167729Sbms break; 2978191672Sbms case MLD_REPORTING_MEMBER: 2979191672Sbms case MLD_IDLE_MEMBER: 2980191672Sbms case MLD_LAZY_MEMBER: 2981191672Sbms case MLD_SLEEPING_MEMBER: 2982191672Sbms case MLD_AWAKENING_MEMBER: 2983191672Sbms inm->in6m_state = MLD_REPORTING_MEMBER; 2984191672Sbms retval = mld_v2_enqueue_group_record(&mli->mli_gq, 2985191672Sbms inm, 0, 0, 0); 2986191672Sbms CTR2(KTR_MLD, "%s: enqueue record = %d", 2987191672Sbms __func__, retval); 2988191672Sbms break; 2989191672Sbms case MLD_G_QUERY_PENDING_MEMBER: 2990191672Sbms case MLD_SG_QUERY_PENDING_MEMBER: 2991191672Sbms case MLD_LEAVING_MEMBER: 2992191672Sbms break; 2993167729Sbms } 2994191672Sbms } 2995191672Sbms IF_ADDR_UNLOCK(ifp); 2996167729Sbms 2997191672Sbms mld_dispatch_queue(&mli->mli_gq, MLD_MAX_RESPONSE_BURST); 2998167729Sbms 2999191672Sbms /* 3000191672Sbms * Slew transmission of bursts over 500ms intervals. 3001191672Sbms */ 3002191672Sbms if (mli->mli_gq.ifq_head != NULL) { 3003191672Sbms mli->mli_v2_timer = 1 + MLD_RANDOM_DELAY( 3004191672Sbms MLD_RESPONSE_BURST_INTERVAL); 3005191672Sbms V_interface_timers_running6 = 1; 3006191672Sbms } 3007191672Sbms} 3008191672Sbms 3009191672Sbms/* 3010191672Sbms * Transmit the next pending message in the output queue. 3011191672Sbms * 3012191672Sbms * VIMAGE: Needs to store/restore vnet pointer on a per-mbuf-chain basis. 3013191672Sbms * MRT: Nothing needs to be done, as MLD traffic is always local to 3014191672Sbms * a link and uses a link-scope multicast address. 3015191672Sbms */ 3016191672Sbmsstatic void 3017191672Sbmsmld_dispatch_packet(struct mbuf *m) 3018191672Sbms{ 3019191672Sbms struct ip6_moptions im6o; 3020191672Sbms struct ifnet *ifp; 3021191672Sbms struct ifnet *oifp; 3022191672Sbms struct mbuf *m0; 3023191672Sbms struct mbuf *md; 3024191672Sbms struct ip6_hdr *ip6; 3025191672Sbms struct mld_hdr *mld; 3026191672Sbms int error; 3027191672Sbms int off; 3028191672Sbms int type; 3029191672Sbms uint32_t ifindex; 3030191672Sbms 3031191672Sbms CTR2(KTR_MLD, "%s: transmit %p", __func__, m); 3032191672Sbms 3033191672Sbms /* 3034191672Sbms * Set VNET image pointer from enqueued mbuf chain 3035191672Sbms * before doing anything else. Whilst we use interface 3036191672Sbms * indexes to guard against interface detach, they are 3037191672Sbms * unique to each VIMAGE and must be retrieved. 3038191672Sbms */ 3039191672Sbms INIT_VNET_NET(curvnet); 3040191672Sbms INIT_VNET_INET6(curvnet); 3041191672Sbms ifindex = mld_restore_context(m); 3042191672Sbms 3043191672Sbms /* 3044191672Sbms * Check if the ifnet still exists. This limits the scope of 3045191672Sbms * any race in the absence of a global ifp lock for low cost 3046191672Sbms * (an array lookup). 3047191672Sbms */ 3048191672Sbms ifp = ifnet_byindex(ifindex); 3049191672Sbms if (ifp == NULL) { 3050191672Sbms CTR3(KTR_MLD, "%s: dropped %p as ifindex %u went away.", 3051191672Sbms __func__, m, ifindex); 3052191672Sbms m_freem(m); 3053191672Sbms IP6STAT_INC(ip6s_noroute); 3054191672Sbms goto out; 3055191672Sbms } 3056191672Sbms 3057191672Sbms im6o.im6o_multicast_hlim = 1; 3058191672Sbms im6o.im6o_multicast_loop = (V_ip6_mrouter != NULL); 3059191672Sbms im6o.im6o_multicast_ifp = ifp; 3060191672Sbms 3061191672Sbms if (m->m_flags & M_MLDV1) { 3062191672Sbms m0 = m; 3063191672Sbms } else { 3064191672Sbms m0 = mld_v2_encap_report(ifp, m); 3065191672Sbms if (m0 == NULL) { 3066191672Sbms CTR2(KTR_MLD, "%s: dropped %p", __func__, m); 3067191672Sbms m_freem(m); 3068191672Sbms IP6STAT_INC(ip6s_odropped); 3069191672Sbms goto out; 3070167729Sbms } 3071191672Sbms } 3072167729Sbms 3073191672Sbms mld_scrub_context(m0); 3074191672Sbms m->m_flags &= ~(M_PROTOFLAGS); 3075191672Sbms m0->m_pkthdr.rcvif = V_loif; 3076167729Sbms 3077191672Sbms ip6 = mtod(m0, struct ip6_hdr *); 3078191672Sbms#if 0 3079191672Sbms (void)in6_setscope(&ip6->ip6_dst, ifp, NULL); /* XXX LOR */ 3080191672Sbms#else 3081191672Sbms /* 3082191672Sbms * XXX XXX Break some KPI rules to prevent an LOR which would 3083191672Sbms * occur if we called in6_setscope() at transmission. 3084191672Sbms * See comments at top of file. 3085191672Sbms */ 3086191672Sbms MLD_EMBEDSCOPE(&ip6->ip6_dst, ifp->if_index); 3087191672Sbms#endif 3088167729Sbms 3089191672Sbms /* 3090191672Sbms * Retrieve the ICMPv6 type before handoff to ip6_output(), 3091191672Sbms * so we can bump the stats. 3092191672Sbms */ 3093191672Sbms md = m_getptr(m0, sizeof(struct ip6_hdr), &off); 3094191672Sbms mld = (struct mld_hdr *)(mtod(md, uint8_t *) + off); 3095191672Sbms type = mld->mld_type; 3096167729Sbms 3097191672Sbms error = ip6_output(m0, &mld_po, NULL, IPV6_UNSPECSRC, &im6o, 3098191672Sbms &oifp, NULL); 3099191672Sbms if (error) { 3100191672Sbms CTR3(KTR_MLD, "%s: ip6_output(%p) = %d", __func__, m0, error); 3101191672Sbms goto out; 3102191672Sbms } 3103191672Sbms ICMP6STAT_INC(icp6s_outhist[type]); 3104191672Sbms if (oifp != NULL) { 3105191672Sbms icmp6_ifstat_inc(oifp, ifs6_out_msg); 3106191672Sbms switch (type) { 3107191672Sbms case MLD_LISTENER_REPORT: 3108191672Sbms case MLDV2_LISTENER_REPORT: 3109191672Sbms icmp6_ifstat_inc(oifp, ifs6_out_mldreport); 3110191672Sbms break; 3111191672Sbms case MLD_LISTENER_DONE: 3112191672Sbms icmp6_ifstat_inc(oifp, ifs6_out_mlddone); 3113191672Sbms break; 3114191672Sbms } 3115191672Sbms } 3116191672Sbmsout: 3117191816Szec return; 3118126603Sume} 3119126603Sume 3120126603Sume/* 3121191672Sbms * Encapsulate an MLDv2 report. 3122167729Sbms * 3123191672Sbms * KAME IPv6 requires that hop-by-hop options be passed separately, 3124191672Sbms * and that the IPv6 header be prepended in a separate mbuf. 3125191672Sbms * 3126191672Sbms * Returns a pointer to the new mbuf chain head, or NULL if the 3127191672Sbms * allocation failed. 3128126603Sume */ 3129191672Sbmsstatic struct mbuf * 3130191672Sbmsmld_v2_encap_report(struct ifnet *ifp, struct mbuf *m) 3131126603Sume{ 3132191672Sbms struct mbuf *mh; 3133191672Sbms struct mldv2_report *mld; 3134191672Sbms struct ip6_hdr *ip6; 3135191672Sbms struct in6_ifaddr *ia; 3136191672Sbms int mldreclen; 3137126603Sume 3138191672Sbms KASSERT(ifp != NULL, ("%s: null ifp", __func__)); 3139191672Sbms KASSERT((m->m_flags & M_PKTHDR), 3140191672Sbms ("%s: mbuf chain %p is !M_PKTHDR", __func__, m)); 3141167729Sbms 3142191672Sbms /* 3143191672Sbms * RFC3590: OK to send as :: or tentative during DAD. 3144191672Sbms */ 3145191672Sbms ia = in6ifa_ifpforlinklocal(ifp, IN6_IFF_NOTREADY|IN6_IFF_ANYCAST); 3146191672Sbms if (ia == NULL) 3147191672Sbms CTR1(KTR_MLD, "%s: warning: ia is NULL", __func__); 3148167729Sbms 3149191672Sbms MGETHDR(mh, M_DONTWAIT, MT_HEADER); 3150191672Sbms if (mh == NULL) { 3151194760Srwatson if (ia != NULL) 3152194760Srwatson ifa_free(&ia->ia_ifa); 3153191672Sbms m_freem(m); 3154191672Sbms return (NULL); 3155191672Sbms } 3156191672Sbms MH_ALIGN(mh, sizeof(struct ip6_hdr) + sizeof(struct mldv2_report)); 3157167729Sbms 3158191672Sbms mldreclen = m_length(m, NULL); 3159191672Sbms CTR2(KTR_MLD, "%s: mldreclen is %d", __func__, mldreclen); 3160167729Sbms 3161191672Sbms mh->m_len = sizeof(struct ip6_hdr) + sizeof(struct mldv2_report); 3162191672Sbms mh->m_pkthdr.len = sizeof(struct ip6_hdr) + 3163191672Sbms sizeof(struct mldv2_report) + mldreclen; 3164191672Sbms 3165191672Sbms ip6 = mtod(mh, struct ip6_hdr *); 3166191672Sbms ip6->ip6_flow = 0; 3167191672Sbms ip6->ip6_vfc &= ~IPV6_VERSION_MASK; 3168191672Sbms ip6->ip6_vfc |= IPV6_VERSION; 3169191672Sbms ip6->ip6_nxt = IPPROTO_ICMPV6; 3170191672Sbms ip6->ip6_src = ia ? ia->ia_addr.sin6_addr : in6addr_any; 3171194760Srwatson if (ia != NULL) 3172194760Srwatson ifa_free(&ia->ia_ifa); 3173191672Sbms ip6->ip6_dst = in6addr_linklocal_allv2routers; 3174191672Sbms /* scope ID will be set in netisr */ 3175191672Sbms 3176191672Sbms mld = (struct mldv2_report *)(ip6 + 1); 3177191672Sbms mld->mld_type = MLDV2_LISTENER_REPORT; 3178191672Sbms mld->mld_code = 0; 3179191672Sbms mld->mld_cksum = 0; 3180191672Sbms mld->mld_v2_reserved = 0; 3181191672Sbms mld->mld_v2_numrecs = htons(m->m_pkthdr.PH_vt.vt_nrecs); 3182191672Sbms m->m_pkthdr.PH_vt.vt_nrecs = 0; 3183191672Sbms 3184191672Sbms mh->m_next = m; 3185191672Sbms mld->mld_cksum = in6_cksum(mh, IPPROTO_ICMPV6, 3186191672Sbms sizeof(struct ip6_hdr), sizeof(struct mldv2_report) + mldreclen); 3187191672Sbms return (mh); 3188191672Sbms} 3189191672Sbms 3190191672Sbms#ifdef KTR 3191191672Sbmsstatic char * 3192191672Sbmsmld_rec_type_to_str(const int type) 3193191672Sbms{ 3194191672Sbms 3195191672Sbms switch (type) { 3196191672Sbms case MLD_CHANGE_TO_EXCLUDE_MODE: 3197191672Sbms return "TO_EX"; 3198191672Sbms break; 3199191672Sbms case MLD_CHANGE_TO_INCLUDE_MODE: 3200191672Sbms return "TO_IN"; 3201191672Sbms break; 3202191672Sbms case MLD_MODE_IS_EXCLUDE: 3203191672Sbms return "MODE_EX"; 3204191672Sbms break; 3205191672Sbms case MLD_MODE_IS_INCLUDE: 3206191672Sbms return "MODE_IN"; 3207191672Sbms break; 3208191672Sbms case MLD_ALLOW_NEW_SOURCES: 3209191672Sbms return "ALLOW_NEW"; 3210191672Sbms break; 3211191672Sbms case MLD_BLOCK_OLD_SOURCES: 3212191672Sbms return "BLOCK_OLD"; 3213191672Sbms break; 3214191672Sbms default: 3215191672Sbms break; 3216126603Sume } 3217191672Sbms return "unknown"; 3218126603Sume} 3219191672Sbms#endif 3220191672Sbms 3221191672Sbmsstatic void 3222191672Sbmsmld_sysinit(void) 3223191672Sbms{ 3224191672Sbms 3225191672Sbms CTR1(KTR_MLD, "%s: initializing", __func__); 3226191672Sbms MLD_LOCK_INIT(); 3227191672Sbms 3228191672Sbms ip6_initpktopts(&mld_po); 3229191672Sbms mld_po.ip6po_hlim = 1; 3230191672Sbms mld_po.ip6po_hbh = &mld_ra.hbh; 3231191672Sbms mld_po.ip6po_prefer_tempaddr = IP6PO_TEMPADDR_NOTPREFER; 3232191672Sbms mld_po.ip6po_flags = IP6PO_DONTFRAG; 3233191672Sbms} 3234191672Sbms 3235191672Sbmsstatic void 3236191672Sbmsmld_sysuninit(void) 3237191672Sbms{ 3238191672Sbms 3239191672Sbms CTR1(KTR_MLD, "%s: tearing down", __func__); 3240191672Sbms MLD_LOCK_DESTROY(); 3241191672Sbms} 3242191672Sbms 3243191672Sbms/* 3244191672Sbms * Initialize an MLDv2 instance. 3245191672Sbms * VIMAGE: Assumes curvnet set by caller and called per vimage. 3246191672Sbms */ 3247191672Sbmsstatic int 3248191672Sbmsvnet_mld_iattach(const void *unused __unused) 3249191672Sbms{ 3250191672Sbms INIT_VNET_INET6(curvnet); 3251191672Sbms 3252191672Sbms CTR1(KTR_MLD, "%s: initializing", __func__); 3253191672Sbms 3254191672Sbms LIST_INIT(&V_mli_head); 3255191672Sbms 3256191672Sbms V_current_state_timers_running6 = 0; 3257191672Sbms V_interface_timers_running6 = 0; 3258191672Sbms V_state_change_timers_running6 = 0; 3259191672Sbms 3260191672Sbms /* 3261191672Sbms * Initialize sysctls to default values. 3262191672Sbms */ 3263191672Sbms V_mld_gsrdelay.tv_sec = 10; 3264191672Sbms V_mld_gsrdelay.tv_usec = 0; 3265191672Sbms 3266191672Sbms return (0); 3267191672Sbms} 3268191672Sbms 3269191672Sbmsstatic int 3270191672Sbmsvnet_mld_idetach(const void *unused __unused) 3271191672Sbms{ 3272191816Szec#ifdef INVARIANTS 3273191672Sbms INIT_VNET_INET6(curvnet); 3274191816Szec#endif 3275191672Sbms 3276191672Sbms CTR1(KTR_MLD, "%s: tearing down", __func__); 3277191672Sbms 3278191672Sbms KASSERT(LIST_EMPTY(&V_mli_head), 3279191672Sbms ("%s: mli list not empty; ifnets not detached?", __func__)); 3280191672Sbms 3281191672Sbms return (0); 3282191672Sbms} 3283191672Sbms 3284191672Sbms#ifndef VIMAGE_GLOBALS 3285191672Sbmsstatic vnet_modinfo_t vnet_mld_modinfo = { 3286191672Sbms .vmi_id = VNET_MOD_MLD, 3287191672Sbms .vmi_name = "mld", 3288191672Sbms .vmi_dependson = VNET_MOD_INET6, 3289191672Sbms .vmi_iattach = vnet_mld_iattach, 3290191672Sbms .vmi_idetach = vnet_mld_idetach 3291191672Sbms}; 3292191672Sbms#endif 3293191672Sbms 3294191672Sbmsstatic int 3295191672Sbmsmld_modevent(module_t mod, int type, void *unused __unused) 3296191672Sbms{ 3297191672Sbms 3298191672Sbms switch (type) { 3299191672Sbms case MOD_LOAD: 3300191672Sbms mld_sysinit(); 3301191672Sbms#ifndef VIMAGE_GLOBALS 3302191672Sbms vnet_mod_register(&vnet_mld_modinfo); 3303191672Sbms#else 3304191672Sbms vnet_mld_iattach(NULL); 3305191672Sbms#endif 3306191672Sbms break; 3307191672Sbms case MOD_UNLOAD: 3308191672Sbms#ifndef VIMAGE_GLOBALS 3309191672Sbms vnet_mod_deregister(&vnet_mld_modinfo); 3310191672Sbms#else 3311191672Sbms vnet_mld_idetach(NULL); 3312191672Sbms#endif 3313191672Sbms mld_sysuninit(); 3314191672Sbms break; 3315191672Sbms default: 3316191672Sbms return (EOPNOTSUPP); 3317191672Sbms } 3318191672Sbms return (0); 3319191672Sbms} 3320191672Sbms 3321191672Sbmsstatic moduledata_t mld_mod = { 3322191672Sbms "mld", 3323191672Sbms mld_modevent, 3324191672Sbms 0 3325191672Sbms}; 3326191672SbmsDECLARE_MODULE(mld, mld_mod, SI_SUB_PSEUDO, SI_ORDER_ANY); 3327