17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*45916cd2Sjpk * Common Development and Distribution License (the "License"). 6*45916cd2Sjpk * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 2267b33d89Srk * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate /* Copyright (c) 1990 Mentat Inc. */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate /* 307c478bd9Sstevel@tonic-gate * Internet Group Management Protocol (IGMP) routines. 317c478bd9Sstevel@tonic-gate * Multicast Listener Discovery Protocol (MLD) routines. 327c478bd9Sstevel@tonic-gate * 337c478bd9Sstevel@tonic-gate * Written by Steve Deering, Stanford, May 1988. 347c478bd9Sstevel@tonic-gate * Modified by Rosen Sharma, Stanford, Aug 1994. 357c478bd9Sstevel@tonic-gate * Modified by Bill Fenner, Xerox PARC, Feb. 1995. 367c478bd9Sstevel@tonic-gate * 377c478bd9Sstevel@tonic-gate * MULTICAST 3.5.1.1 387c478bd9Sstevel@tonic-gate */ 397c478bd9Sstevel@tonic-gate 407c478bd9Sstevel@tonic-gate #include <sys/types.h> 417c478bd9Sstevel@tonic-gate #include <sys/stream.h> 427c478bd9Sstevel@tonic-gate #include <sys/stropts.h> 437c478bd9Sstevel@tonic-gate #include <sys/strlog.h> 447c478bd9Sstevel@tonic-gate #include <sys/strsun.h> 457c478bd9Sstevel@tonic-gate #include <sys/systm.h> 467c478bd9Sstevel@tonic-gate #include <sys/ddi.h> 477c478bd9Sstevel@tonic-gate #include <sys/sunddi.h> 487c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h> 497c478bd9Sstevel@tonic-gate #include <sys/atomic.h> 507c478bd9Sstevel@tonic-gate #include <sys/zone.h> 517c478bd9Sstevel@tonic-gate 527c478bd9Sstevel@tonic-gate #include <sys/param.h> 537c478bd9Sstevel@tonic-gate #include <sys/socket.h> 547c478bd9Sstevel@tonic-gate #include <inet/ipclassifier.h> 557c478bd9Sstevel@tonic-gate #include <net/if.h> 567c478bd9Sstevel@tonic-gate #include <net/route.h> 577c478bd9Sstevel@tonic-gate #include <netinet/in.h> 587c478bd9Sstevel@tonic-gate #include <netinet/igmp_var.h> 597c478bd9Sstevel@tonic-gate #include <netinet/ip6.h> 607c478bd9Sstevel@tonic-gate #include <netinet/icmp6.h> 617c478bd9Sstevel@tonic-gate 627c478bd9Sstevel@tonic-gate #include <inet/common.h> 637c478bd9Sstevel@tonic-gate #include <inet/mi.h> 647c478bd9Sstevel@tonic-gate #include <inet/nd.h> 657c478bd9Sstevel@tonic-gate #include <inet/ip.h> 667c478bd9Sstevel@tonic-gate #include <inet/ip6.h> 677c478bd9Sstevel@tonic-gate #include <inet/ip_multi.h> 687c478bd9Sstevel@tonic-gate #include <inet/ip_listutils.h> 697c478bd9Sstevel@tonic-gate 707c478bd9Sstevel@tonic-gate #include <netinet/igmp.h> 717c478bd9Sstevel@tonic-gate #include <inet/ip_if.h> 727c478bd9Sstevel@tonic-gate #include <net/pfkeyv2.h> 737c478bd9Sstevel@tonic-gate #include <inet/ipsec_info.h> 747c478bd9Sstevel@tonic-gate 757c478bd9Sstevel@tonic-gate static uint_t igmp_query_in(ipha_t *ipha, igmpa_t *igmpa, ill_t *ill); 767c478bd9Sstevel@tonic-gate static uint_t igmpv3_query_in(igmp3qa_t *igmp3qa, ill_t *ill, int igmplen); 777c478bd9Sstevel@tonic-gate static uint_t mld_query_in(mld_hdr_t *mldh, ill_t *ill); 787c478bd9Sstevel@tonic-gate static uint_t mldv2_query_in(mld2q_t *mld2q, ill_t *ill, int mldlen); 797c478bd9Sstevel@tonic-gate static void igmp_sendpkt(ilm_t *ilm, uchar_t type, ipaddr_t addr); 807c478bd9Sstevel@tonic-gate static void mld_sendpkt(ilm_t *ilm, uchar_t type, const in6_addr_t *v6addr); 817c478bd9Sstevel@tonic-gate static void igmpv3_sendrpt(ipif_t *ipif, mrec_t *reclist); 827c478bd9Sstevel@tonic-gate static void mldv2_sendrpt(ill_t *ill, mrec_t *reclist); 837c478bd9Sstevel@tonic-gate static mrec_t *mcast_bldmrec(mcast_record_t type, in6_addr_t *grp, 847c478bd9Sstevel@tonic-gate slist_t *srclist, mrec_t *next); 857c478bd9Sstevel@tonic-gate static void mcast_init_rtx(ill_t *ill, rtx_state_t *rtxp, 867c478bd9Sstevel@tonic-gate mcast_record_t rtype, slist_t *flist); 877c478bd9Sstevel@tonic-gate static mrec_t *mcast_merge_rtx(ilm_t *ilm, mrec_t *rp, slist_t *flist); 887c478bd9Sstevel@tonic-gate 897c478bd9Sstevel@tonic-gate /* Following protected by igmp_timer_lock */ 907c478bd9Sstevel@tonic-gate static int igmp_time_to_next; /* Time since last timeout */ 917c478bd9Sstevel@tonic-gate static int igmp_timer_fired_last; 927c478bd9Sstevel@tonic-gate uint_t igmp_deferred_next = INFINITY; 937c478bd9Sstevel@tonic-gate timeout_id_t igmp_timeout_id = 0; 947c478bd9Sstevel@tonic-gate kmutex_t igmp_timer_lock; 957c478bd9Sstevel@tonic-gate 967c478bd9Sstevel@tonic-gate /* Protected by igmp_slowtimeout_lock */ 977c478bd9Sstevel@tonic-gate timeout_id_t igmp_slowtimeout_id = 0; 987c478bd9Sstevel@tonic-gate kmutex_t igmp_slowtimeout_lock; 997c478bd9Sstevel@tonic-gate 1007c478bd9Sstevel@tonic-gate /* Following protected by mld_timer_lock */ 1017c478bd9Sstevel@tonic-gate static int mld_time_to_next; /* Time since last timeout */ 1027c478bd9Sstevel@tonic-gate static int mld_timer_fired_last; 1037c478bd9Sstevel@tonic-gate uint_t mld_deferred_next = INFINITY; 1047c478bd9Sstevel@tonic-gate timeout_id_t mld_timeout_id = 0; 1057c478bd9Sstevel@tonic-gate kmutex_t mld_timer_lock; 1067c478bd9Sstevel@tonic-gate 1077c478bd9Sstevel@tonic-gate /* Protected by mld_slowtimeout_lock */ 1087c478bd9Sstevel@tonic-gate timeout_id_t mld_slowtimeout_id = 0; 1097c478bd9Sstevel@tonic-gate kmutex_t mld_slowtimeout_lock; 1107c478bd9Sstevel@tonic-gate 1117c478bd9Sstevel@tonic-gate /* 1127c478bd9Sstevel@tonic-gate * Macros used to do timer len conversions. Timer values are always 1137c478bd9Sstevel@tonic-gate * stored and passed to the timer functions as milliseconds; but the 1147c478bd9Sstevel@tonic-gate * default values and values from the wire may not be. 1157c478bd9Sstevel@tonic-gate * 1167c478bd9Sstevel@tonic-gate * And yes, it's obscure, but decisecond is easier to abbreviate than 1177c478bd9Sstevel@tonic-gate * "tenths of a second". 1187c478bd9Sstevel@tonic-gate */ 1197c478bd9Sstevel@tonic-gate #define DSEC_TO_MSEC(dsec) ((dsec) * 100) 1207c478bd9Sstevel@tonic-gate #define SEC_TO_MSEC(sec) ((sec) * 1000) 1217c478bd9Sstevel@tonic-gate 1227c478bd9Sstevel@tonic-gate /* 1237c478bd9Sstevel@tonic-gate * The first multicast join will trigger the igmp timers / mld timers 1247c478bd9Sstevel@tonic-gate * The unit for next is milliseconds. 1257c478bd9Sstevel@tonic-gate */ 1267c478bd9Sstevel@tonic-gate void 1277c478bd9Sstevel@tonic-gate igmp_start_timers(unsigned next) 1287c478bd9Sstevel@tonic-gate { 1297c478bd9Sstevel@tonic-gate int time_left; 1307c478bd9Sstevel@tonic-gate /* Protected by igmp_timer_lock */ 1317c478bd9Sstevel@tonic-gate static boolean_t igmp_timer_setter_active; 1327c478bd9Sstevel@tonic-gate int ret; 1337c478bd9Sstevel@tonic-gate 1347c478bd9Sstevel@tonic-gate ASSERT(next != 0 && next != INFINITY); 1357c478bd9Sstevel@tonic-gate 1367c478bd9Sstevel@tonic-gate mutex_enter(&igmp_timer_lock); 1377c478bd9Sstevel@tonic-gate 1387c478bd9Sstevel@tonic-gate if (igmp_timer_setter_active) { 1397c478bd9Sstevel@tonic-gate /* 1407c478bd9Sstevel@tonic-gate * Serialize timer setters, one at a time. If the 1417c478bd9Sstevel@tonic-gate * timer is currently being set by someone, 1427c478bd9Sstevel@tonic-gate * just record the next time when it has to be 1437c478bd9Sstevel@tonic-gate * invoked and return. The current setter will 1447c478bd9Sstevel@tonic-gate * take care. 1457c478bd9Sstevel@tonic-gate */ 1467c478bd9Sstevel@tonic-gate igmp_time_to_next = MIN(igmp_time_to_next, next); 1477c478bd9Sstevel@tonic-gate mutex_exit(&igmp_timer_lock); 1487c478bd9Sstevel@tonic-gate return; 1497c478bd9Sstevel@tonic-gate } else { 1507c478bd9Sstevel@tonic-gate igmp_timer_setter_active = B_TRUE; 1517c478bd9Sstevel@tonic-gate } 1527c478bd9Sstevel@tonic-gate if (igmp_timeout_id == 0) { 1537c478bd9Sstevel@tonic-gate /* 1547c478bd9Sstevel@tonic-gate * The timer is inactive. We need to start a timer 1557c478bd9Sstevel@tonic-gate */ 1567c478bd9Sstevel@tonic-gate igmp_time_to_next = next; 1577c478bd9Sstevel@tonic-gate igmp_timeout_id = timeout(igmp_timeout_handler, NULL, 1587c478bd9Sstevel@tonic-gate MSEC_TO_TICK(igmp_time_to_next)); 1597c478bd9Sstevel@tonic-gate igmp_timer_setter_active = B_FALSE; 1607c478bd9Sstevel@tonic-gate mutex_exit(&igmp_timer_lock); 1617c478bd9Sstevel@tonic-gate return; 1627c478bd9Sstevel@tonic-gate } 1637c478bd9Sstevel@tonic-gate 1647c478bd9Sstevel@tonic-gate /* 1657c478bd9Sstevel@tonic-gate * The timer was scheduled sometime back for firing in 1667c478bd9Sstevel@tonic-gate * 'igmp_time_to_next' ms and is active. We need to 1677c478bd9Sstevel@tonic-gate * reschedule the timeout if the new 'next' will happen 1687c478bd9Sstevel@tonic-gate * earlier than the currently scheduled timeout 1697c478bd9Sstevel@tonic-gate */ 1707c478bd9Sstevel@tonic-gate time_left = igmp_timer_fired_last + 1717c478bd9Sstevel@tonic-gate MSEC_TO_TICK(igmp_time_to_next) - ddi_get_lbolt(); 1727c478bd9Sstevel@tonic-gate if (time_left < MSEC_TO_TICK(next)) { 1737c478bd9Sstevel@tonic-gate igmp_timer_setter_active = B_FALSE; 1747c478bd9Sstevel@tonic-gate mutex_exit(&igmp_timer_lock); 1757c478bd9Sstevel@tonic-gate return; 1767c478bd9Sstevel@tonic-gate } 1777c478bd9Sstevel@tonic-gate 1787c478bd9Sstevel@tonic-gate mutex_exit(&igmp_timer_lock); 1797c478bd9Sstevel@tonic-gate ret = untimeout(igmp_timeout_id); 1807c478bd9Sstevel@tonic-gate mutex_enter(&igmp_timer_lock); 1817c478bd9Sstevel@tonic-gate /* 1827c478bd9Sstevel@tonic-gate * The timeout was cancelled, or the timeout handler 1837c478bd9Sstevel@tonic-gate * completed, while we were blocked in the untimeout. 1847c478bd9Sstevel@tonic-gate * No other thread could have set the timer meanwhile 1857c478bd9Sstevel@tonic-gate * since we serialized all the timer setters. Thus 1867c478bd9Sstevel@tonic-gate * no timer is currently active nor executing nor will 1877c478bd9Sstevel@tonic-gate * any timer fire in the future. We start the timer now 1887c478bd9Sstevel@tonic-gate * if needed. 1897c478bd9Sstevel@tonic-gate */ 1907c478bd9Sstevel@tonic-gate if (ret == -1) { 1917c478bd9Sstevel@tonic-gate ASSERT(igmp_timeout_id == 0); 1927c478bd9Sstevel@tonic-gate } else { 1937c478bd9Sstevel@tonic-gate ASSERT(igmp_timeout_id != 0); 1947c478bd9Sstevel@tonic-gate igmp_timeout_id = 0; 1957c478bd9Sstevel@tonic-gate } 1967c478bd9Sstevel@tonic-gate if (igmp_time_to_next != 0) { 1977c478bd9Sstevel@tonic-gate igmp_time_to_next = MIN(igmp_time_to_next, next); 1987c478bd9Sstevel@tonic-gate igmp_timeout_id = timeout(igmp_timeout_handler, NULL, 1997c478bd9Sstevel@tonic-gate MSEC_TO_TICK(igmp_time_to_next)); 2007c478bd9Sstevel@tonic-gate } 20167b33d89Srk igmp_timer_setter_active = B_FALSE; 2027c478bd9Sstevel@tonic-gate mutex_exit(&igmp_timer_lock); 2037c478bd9Sstevel@tonic-gate } 2047c478bd9Sstevel@tonic-gate 2057c478bd9Sstevel@tonic-gate /* 2067c478bd9Sstevel@tonic-gate * mld_start_timers: 2077c478bd9Sstevel@tonic-gate * The unit for next is milliseconds. 2087c478bd9Sstevel@tonic-gate */ 2097c478bd9Sstevel@tonic-gate void 2107c478bd9Sstevel@tonic-gate mld_start_timers(unsigned next) 2117c478bd9Sstevel@tonic-gate { 2127c478bd9Sstevel@tonic-gate int time_left; 2137c478bd9Sstevel@tonic-gate /* Protedted by mld_timer_lock */ 2147c478bd9Sstevel@tonic-gate static boolean_t mld_timer_setter_active; 2157c478bd9Sstevel@tonic-gate int ret; 2167c478bd9Sstevel@tonic-gate 2177c478bd9Sstevel@tonic-gate ASSERT(next != 0 && next != INFINITY); 2187c478bd9Sstevel@tonic-gate 2197c478bd9Sstevel@tonic-gate mutex_enter(&mld_timer_lock); 2207c478bd9Sstevel@tonic-gate if (mld_timer_setter_active) { 2217c478bd9Sstevel@tonic-gate /* 2227c478bd9Sstevel@tonic-gate * Serialize timer setters, one at a time. If the 2237c478bd9Sstevel@tonic-gate * timer is currently being set by someone, 2247c478bd9Sstevel@tonic-gate * just record the next time when it has to be 2257c478bd9Sstevel@tonic-gate * invoked and return. The current setter will 2267c478bd9Sstevel@tonic-gate * take care. 2277c478bd9Sstevel@tonic-gate */ 2287c478bd9Sstevel@tonic-gate mld_time_to_next = MIN(mld_time_to_next, next); 2297c478bd9Sstevel@tonic-gate mutex_exit(&mld_timer_lock); 2307c478bd9Sstevel@tonic-gate return; 2317c478bd9Sstevel@tonic-gate } else { 2327c478bd9Sstevel@tonic-gate mld_timer_setter_active = B_TRUE; 2337c478bd9Sstevel@tonic-gate } 2347c478bd9Sstevel@tonic-gate if (mld_timeout_id == 0) { 2357c478bd9Sstevel@tonic-gate /* 2367c478bd9Sstevel@tonic-gate * The timer is inactive. We need to start a timer 2377c478bd9Sstevel@tonic-gate */ 2387c478bd9Sstevel@tonic-gate mld_time_to_next = next; 2397c478bd9Sstevel@tonic-gate mld_timeout_id = timeout(mld_timeout_handler, NULL, 2407c478bd9Sstevel@tonic-gate MSEC_TO_TICK(mld_time_to_next)); 2417c478bd9Sstevel@tonic-gate mld_timer_setter_active = B_FALSE; 2427c478bd9Sstevel@tonic-gate mutex_exit(&mld_timer_lock); 2437c478bd9Sstevel@tonic-gate return; 2447c478bd9Sstevel@tonic-gate } 2457c478bd9Sstevel@tonic-gate 2467c478bd9Sstevel@tonic-gate /* 2477c478bd9Sstevel@tonic-gate * The timer was scheduled sometime back for firing in 2487c478bd9Sstevel@tonic-gate * 'igmp_time_to_next' ms and is active. We need to 2497c478bd9Sstevel@tonic-gate * reschedule the timeout if the new 'next' will happen 2507c478bd9Sstevel@tonic-gate * earlier than the currently scheduled timeout 2517c478bd9Sstevel@tonic-gate */ 2527c478bd9Sstevel@tonic-gate time_left = mld_timer_fired_last + 2537c478bd9Sstevel@tonic-gate MSEC_TO_TICK(mld_time_to_next) - ddi_get_lbolt(); 2547c478bd9Sstevel@tonic-gate if (time_left < MSEC_TO_TICK(next)) { 2557c478bd9Sstevel@tonic-gate mld_timer_setter_active = B_FALSE; 2567c478bd9Sstevel@tonic-gate mutex_exit(&mld_timer_lock); 2577c478bd9Sstevel@tonic-gate return; 2587c478bd9Sstevel@tonic-gate } 2597c478bd9Sstevel@tonic-gate 2607c478bd9Sstevel@tonic-gate mutex_exit(&mld_timer_lock); 2617c478bd9Sstevel@tonic-gate ret = untimeout(mld_timeout_id); 2627c478bd9Sstevel@tonic-gate mutex_enter(&mld_timer_lock); 2637c478bd9Sstevel@tonic-gate /* 2647c478bd9Sstevel@tonic-gate * The timeout was cancelled, or the timeout handler 2657c478bd9Sstevel@tonic-gate * completed, while we were blocked in the untimeout. 2667c478bd9Sstevel@tonic-gate * No other thread could have set the timer meanwhile 2677c478bd9Sstevel@tonic-gate * since we serialized all the timer setters. Thus 2687c478bd9Sstevel@tonic-gate * no timer is currently active nor executing nor will 2697c478bd9Sstevel@tonic-gate * any timer fire in the future. We start the timer now 2707c478bd9Sstevel@tonic-gate * if needed. 2717c478bd9Sstevel@tonic-gate */ 2727c478bd9Sstevel@tonic-gate if (ret == -1) { 2737c478bd9Sstevel@tonic-gate ASSERT(mld_timeout_id == 0); 2747c478bd9Sstevel@tonic-gate } else { 2757c478bd9Sstevel@tonic-gate ASSERT(mld_timeout_id != 0); 2767c478bd9Sstevel@tonic-gate mld_timeout_id = 0; 2777c478bd9Sstevel@tonic-gate } 2787c478bd9Sstevel@tonic-gate if (mld_time_to_next != 0) { 2797c478bd9Sstevel@tonic-gate mld_time_to_next = MIN(mld_time_to_next, next); 2807c478bd9Sstevel@tonic-gate mld_timeout_id = timeout(mld_timeout_handler, NULL, 2817c478bd9Sstevel@tonic-gate MSEC_TO_TICK(mld_time_to_next)); 2827c478bd9Sstevel@tonic-gate } 28367b33d89Srk mld_timer_setter_active = B_FALSE; 2847c478bd9Sstevel@tonic-gate mutex_exit(&mld_timer_lock); 2857c478bd9Sstevel@tonic-gate } 2867c478bd9Sstevel@tonic-gate 2877c478bd9Sstevel@tonic-gate /* 2887c478bd9Sstevel@tonic-gate * igmp_input: 2897c478bd9Sstevel@tonic-gate * Return 0 if the message is OK and should be handed to "raw" receivers. 2907c478bd9Sstevel@tonic-gate * Callers of igmp_input() may need to reinitialize variables that were copied 2917c478bd9Sstevel@tonic-gate * from the mblk as this calls pullupmsg(). 2927c478bd9Sstevel@tonic-gate */ 2937c478bd9Sstevel@tonic-gate /* ARGSUSED */ 2947c478bd9Sstevel@tonic-gate int 2957c478bd9Sstevel@tonic-gate igmp_input(queue_t *q, mblk_t *mp, ill_t *ill) 2967c478bd9Sstevel@tonic-gate { 2977c478bd9Sstevel@tonic-gate igmpa_t *igmpa; 2987c478bd9Sstevel@tonic-gate ipha_t *ipha = (ipha_t *)(mp->b_rptr); 2997c478bd9Sstevel@tonic-gate int iphlen, igmplen, mblklen; 3007c478bd9Sstevel@tonic-gate ilm_t *ilm; 3017c478bd9Sstevel@tonic-gate uint32_t src, dst; 3027c478bd9Sstevel@tonic-gate uint32_t group; 3037c478bd9Sstevel@tonic-gate uint_t next; 3047c478bd9Sstevel@tonic-gate ipif_t *ipif; 3057c478bd9Sstevel@tonic-gate 3067c478bd9Sstevel@tonic-gate ASSERT(ill != NULL); 3077c478bd9Sstevel@tonic-gate ASSERT(!ill->ill_isv6); 3087c478bd9Sstevel@tonic-gate ++igmpstat.igps_rcv_total; 3097c478bd9Sstevel@tonic-gate 3107c478bd9Sstevel@tonic-gate mblklen = MBLKL(mp); 3117c478bd9Sstevel@tonic-gate if (mblklen < 1 || mblklen < (iphlen = IPH_HDR_LENGTH(ipha))) { 3127c478bd9Sstevel@tonic-gate ++igmpstat.igps_rcv_tooshort; 3137c478bd9Sstevel@tonic-gate freemsg(mp); 3147c478bd9Sstevel@tonic-gate return (-1); 3157c478bd9Sstevel@tonic-gate } 3167c478bd9Sstevel@tonic-gate igmplen = ntohs(ipha->ipha_length) - iphlen; 3177c478bd9Sstevel@tonic-gate /* 3187c478bd9Sstevel@tonic-gate * Since msg sizes are more variable with v3, just pullup the 3197c478bd9Sstevel@tonic-gate * whole thing now. 3207c478bd9Sstevel@tonic-gate */ 3217c478bd9Sstevel@tonic-gate if (MBLKL(mp) < (igmplen + iphlen)) { 3227c478bd9Sstevel@tonic-gate mblk_t *mp1; 3237c478bd9Sstevel@tonic-gate if ((mp1 = msgpullup(mp, -1)) == NULL) { 3247c478bd9Sstevel@tonic-gate ++igmpstat.igps_rcv_tooshort; 3257c478bd9Sstevel@tonic-gate freemsg(mp); 3267c478bd9Sstevel@tonic-gate return (-1); 3277c478bd9Sstevel@tonic-gate } 3287c478bd9Sstevel@tonic-gate freemsg(mp); 3297c478bd9Sstevel@tonic-gate mp = mp1; 3307c478bd9Sstevel@tonic-gate ipha = (ipha_t *)(mp->b_rptr); 3317c478bd9Sstevel@tonic-gate } 3327c478bd9Sstevel@tonic-gate 3337c478bd9Sstevel@tonic-gate /* 3347c478bd9Sstevel@tonic-gate * Validate lengths 3357c478bd9Sstevel@tonic-gate */ 3367c478bd9Sstevel@tonic-gate if (igmplen < IGMP_MINLEN) { 3377c478bd9Sstevel@tonic-gate ++igmpstat.igps_rcv_tooshort; 3387c478bd9Sstevel@tonic-gate freemsg(mp); 3397c478bd9Sstevel@tonic-gate return (-1); 3407c478bd9Sstevel@tonic-gate } 3417c478bd9Sstevel@tonic-gate /* 3427c478bd9Sstevel@tonic-gate * Validate checksum 3437c478bd9Sstevel@tonic-gate */ 3447c478bd9Sstevel@tonic-gate if (IP_CSUM(mp, iphlen, 0)) { 3457c478bd9Sstevel@tonic-gate ++igmpstat.igps_rcv_badsum; 3467c478bd9Sstevel@tonic-gate freemsg(mp); 3477c478bd9Sstevel@tonic-gate return (-1); 3487c478bd9Sstevel@tonic-gate } 3497c478bd9Sstevel@tonic-gate 3507c478bd9Sstevel@tonic-gate igmpa = (igmpa_t *)(&mp->b_rptr[iphlen]); 3517c478bd9Sstevel@tonic-gate src = ipha->ipha_src; 3527c478bd9Sstevel@tonic-gate dst = ipha->ipha_dst; 3537c478bd9Sstevel@tonic-gate if (ip_debug > 1) 3547c478bd9Sstevel@tonic-gate (void) mi_strlog(ill->ill_rq, 1, SL_TRACE, 3557c478bd9Sstevel@tonic-gate "igmp_input: src 0x%x, dst 0x%x on %s\n", 3567c478bd9Sstevel@tonic-gate (int)ntohl(src), (int)ntohl(dst), 3577c478bd9Sstevel@tonic-gate ill->ill_name); 3587c478bd9Sstevel@tonic-gate 3597c478bd9Sstevel@tonic-gate switch (igmpa->igmpa_type) { 3607c478bd9Sstevel@tonic-gate case IGMP_MEMBERSHIP_QUERY: 3617c478bd9Sstevel@tonic-gate /* 3627c478bd9Sstevel@tonic-gate * packet length differentiates between v1/v2 and v3 3637c478bd9Sstevel@tonic-gate * v1/v2 should be exactly 8 octets long; v3 is >= 12 3647c478bd9Sstevel@tonic-gate */ 3657c478bd9Sstevel@tonic-gate if (igmplen == IGMP_MINLEN) { 3667c478bd9Sstevel@tonic-gate next = igmp_query_in(ipha, igmpa, ill); 3677c478bd9Sstevel@tonic-gate } else if (igmplen >= IGMP_V3_QUERY_MINLEN) { 3687c478bd9Sstevel@tonic-gate next = igmpv3_query_in((igmp3qa_t *)igmpa, ill, 3697c478bd9Sstevel@tonic-gate igmplen); 3707c478bd9Sstevel@tonic-gate } else { 3717c478bd9Sstevel@tonic-gate ++igmpstat.igps_rcv_tooshort; 3727c478bd9Sstevel@tonic-gate freemsg(mp); 3737c478bd9Sstevel@tonic-gate return (-1); 3747c478bd9Sstevel@tonic-gate } 3757c478bd9Sstevel@tonic-gate if (next == 0) { 3767c478bd9Sstevel@tonic-gate freemsg(mp); 3777c478bd9Sstevel@tonic-gate return (-1); 3787c478bd9Sstevel@tonic-gate } 3797c478bd9Sstevel@tonic-gate 3807c478bd9Sstevel@tonic-gate if (next != INFINITY) 3817c478bd9Sstevel@tonic-gate igmp_start_timers(next); 3827c478bd9Sstevel@tonic-gate 3837c478bd9Sstevel@tonic-gate break; 3847c478bd9Sstevel@tonic-gate 3857c478bd9Sstevel@tonic-gate case IGMP_V1_MEMBERSHIP_REPORT: 3867c478bd9Sstevel@tonic-gate case IGMP_V2_MEMBERSHIP_REPORT: 3877c478bd9Sstevel@tonic-gate /* 3887c478bd9Sstevel@tonic-gate * For fast leave to work, we have to know that we are the 3897c478bd9Sstevel@tonic-gate * last person to send a report for this group. Reports 3907c478bd9Sstevel@tonic-gate * generated by us are looped back since we could potentially 3917c478bd9Sstevel@tonic-gate * be a multicast router, so discard reports sourced by me. 3927c478bd9Sstevel@tonic-gate */ 3937c478bd9Sstevel@tonic-gate mutex_enter(&ill->ill_lock); 3947c478bd9Sstevel@tonic-gate for (ipif = ill->ill_ipif; ipif != NULL; 3957c478bd9Sstevel@tonic-gate ipif = ipif->ipif_next) { 3967c478bd9Sstevel@tonic-gate if (ipif->ipif_lcl_addr == src) { 3977c478bd9Sstevel@tonic-gate if (ip_debug > 1) { 3987c478bd9Sstevel@tonic-gate (void) mi_strlog(ill->ill_rq, 3997c478bd9Sstevel@tonic-gate 1, 4007c478bd9Sstevel@tonic-gate SL_TRACE, 4017c478bd9Sstevel@tonic-gate "igmp_input: we are only " 4027c478bd9Sstevel@tonic-gate "member src 0x%x ipif_local 0x%x", 4037c478bd9Sstevel@tonic-gate (int)ntohl(src), 4047c478bd9Sstevel@tonic-gate (int) 4057c478bd9Sstevel@tonic-gate ntohl(ipif->ipif_lcl_addr)); 4067c478bd9Sstevel@tonic-gate } 4077c478bd9Sstevel@tonic-gate mutex_exit(&ill->ill_lock); 4087c478bd9Sstevel@tonic-gate return (0); 4097c478bd9Sstevel@tonic-gate } 4107c478bd9Sstevel@tonic-gate } 4117c478bd9Sstevel@tonic-gate mutex_exit(&ill->ill_lock); 4127c478bd9Sstevel@tonic-gate 4137c478bd9Sstevel@tonic-gate ++igmpstat.igps_rcv_reports; 4147c478bd9Sstevel@tonic-gate group = igmpa->igmpa_group; 4157c478bd9Sstevel@tonic-gate if (!CLASSD(group)) { 4167c478bd9Sstevel@tonic-gate ++igmpstat.igps_rcv_badreports; 4177c478bd9Sstevel@tonic-gate freemsg(mp); 4187c478bd9Sstevel@tonic-gate return (-1); 4197c478bd9Sstevel@tonic-gate } 4207c478bd9Sstevel@tonic-gate 4217c478bd9Sstevel@tonic-gate /* 4227c478bd9Sstevel@tonic-gate * KLUDGE: if the IP source address of the report has an 4237c478bd9Sstevel@tonic-gate * unspecified (i.e., zero) subnet number, as is allowed for 4247c478bd9Sstevel@tonic-gate * a booting host, replace it with the correct subnet number 4257c478bd9Sstevel@tonic-gate * so that a process-level multicast routing demon can 4267c478bd9Sstevel@tonic-gate * determine which subnet it arrived from. This is necessary 4277c478bd9Sstevel@tonic-gate * to compensate for the lack of any way for a process to 4287c478bd9Sstevel@tonic-gate * determine the arrival interface of an incoming packet. 4297c478bd9Sstevel@tonic-gate * 4307c478bd9Sstevel@tonic-gate * Requires that a copy of *this* message it passed up 4317c478bd9Sstevel@tonic-gate * to the raw interface which is done by our caller. 4327c478bd9Sstevel@tonic-gate */ 4337c478bd9Sstevel@tonic-gate if ((src & htonl(0xFF000000U)) == 0) { /* Minimum net mask */ 4347c478bd9Sstevel@tonic-gate /* Pick the first ipif on this ill */ 4357c478bd9Sstevel@tonic-gate mutex_enter(&ill->ill_lock); 4367c478bd9Sstevel@tonic-gate src = ill->ill_ipif->ipif_subnet; 4377c478bd9Sstevel@tonic-gate mutex_exit(&ill->ill_lock); 4387c478bd9Sstevel@tonic-gate ip1dbg(("igmp_input: changed src to 0x%x\n", 4397c478bd9Sstevel@tonic-gate (int)ntohl(src))); 4407c478bd9Sstevel@tonic-gate ipha->ipha_src = src; 4417c478bd9Sstevel@tonic-gate } 4427c478bd9Sstevel@tonic-gate 4437c478bd9Sstevel@tonic-gate /* 4447c478bd9Sstevel@tonic-gate * If we belong to the group being reported, and 4457c478bd9Sstevel@tonic-gate * we are a 'Delaying member' in the RFC terminology, 4467c478bd9Sstevel@tonic-gate * stop our timer for that group and 'clear flag' i.e. 4477c478bd9Sstevel@tonic-gate * mark as IGMP_OTHERMEMBER. Do this for all logical 4487c478bd9Sstevel@tonic-gate * interfaces on the given physical interface. 4497c478bd9Sstevel@tonic-gate */ 4507c478bd9Sstevel@tonic-gate mutex_enter(&ill->ill_lock); 4517c478bd9Sstevel@tonic-gate for (ipif = ill->ill_ipif; ipif != NULL; 4527c478bd9Sstevel@tonic-gate ipif = ipif->ipif_next) { 4537c478bd9Sstevel@tonic-gate ilm = ilm_lookup_ipif(ipif, group); 4547c478bd9Sstevel@tonic-gate if (ilm != NULL) { 4557c478bd9Sstevel@tonic-gate ++igmpstat.igps_rcv_ourreports; 4567c478bd9Sstevel@tonic-gate ilm->ilm_timer = INFINITY; 4577c478bd9Sstevel@tonic-gate ilm->ilm_state = IGMP_OTHERMEMBER; 4587c478bd9Sstevel@tonic-gate } 4597c478bd9Sstevel@tonic-gate } /* for */ 4607c478bd9Sstevel@tonic-gate mutex_exit(&ill->ill_lock); 4617c478bd9Sstevel@tonic-gate break; 4627c478bd9Sstevel@tonic-gate 4637c478bd9Sstevel@tonic-gate case IGMP_V3_MEMBERSHIP_REPORT: 4647c478bd9Sstevel@tonic-gate /* 4657c478bd9Sstevel@tonic-gate * Currently nothing to do here; IGMP router is not 4667c478bd9Sstevel@tonic-gate * implemented in ip, and v3 hosts don't pay attention 4677c478bd9Sstevel@tonic-gate * to membership reports. 4687c478bd9Sstevel@tonic-gate */ 4697c478bd9Sstevel@tonic-gate break; 4707c478bd9Sstevel@tonic-gate } 4717c478bd9Sstevel@tonic-gate /* 4727c478bd9Sstevel@tonic-gate * Pass all valid IGMP packets up to any process(es) listening 4737c478bd9Sstevel@tonic-gate * on a raw IGMP socket. Do not free the packet. 4747c478bd9Sstevel@tonic-gate */ 4757c478bd9Sstevel@tonic-gate return (0); 4767c478bd9Sstevel@tonic-gate } 4777c478bd9Sstevel@tonic-gate 4787c478bd9Sstevel@tonic-gate static uint_t 4797c478bd9Sstevel@tonic-gate igmp_query_in(ipha_t *ipha, igmpa_t *igmpa, ill_t *ill) 4807c478bd9Sstevel@tonic-gate { 4817c478bd9Sstevel@tonic-gate ilm_t *ilm; 4827c478bd9Sstevel@tonic-gate int timer; 4837c478bd9Sstevel@tonic-gate uint_t next; 4847c478bd9Sstevel@tonic-gate 4857c478bd9Sstevel@tonic-gate ++igmpstat.igps_rcv_queries; 4867c478bd9Sstevel@tonic-gate 4877c478bd9Sstevel@tonic-gate /* 4887c478bd9Sstevel@tonic-gate * In the IGMPv2 specification, there are 3 states and a flag. 4897c478bd9Sstevel@tonic-gate * 4907c478bd9Sstevel@tonic-gate * In Non-Member state, we simply don't have a membership record. 4917c478bd9Sstevel@tonic-gate * In Delaying Member state, our timer is running (ilm->ilm_timer 4927c478bd9Sstevel@tonic-gate * < INFINITY). In Idle Member state, our timer is not running 4937c478bd9Sstevel@tonic-gate * (ilm->ilm_timer == INFINITY). 4947c478bd9Sstevel@tonic-gate * 4957c478bd9Sstevel@tonic-gate * The flag is ilm->ilm_state, it is set to IGMP_OTHERMEMBER if 4967c478bd9Sstevel@tonic-gate * we have heard a report from another member, or IGMP_IREPORTEDLAST 4977c478bd9Sstevel@tonic-gate * if I sent the last report. 4987c478bd9Sstevel@tonic-gate */ 4997c478bd9Sstevel@tonic-gate if (igmpa->igmpa_code == 0) { 5007c478bd9Sstevel@tonic-gate /* 5017c478bd9Sstevel@tonic-gate * Query from an old router. 5027c478bd9Sstevel@tonic-gate * Remember that the querier on this interface is old, 5037c478bd9Sstevel@tonic-gate * and set the timer to the value in RFC 1112. 5047c478bd9Sstevel@tonic-gate */ 5057c478bd9Sstevel@tonic-gate 5067c478bd9Sstevel@tonic-gate 5077c478bd9Sstevel@tonic-gate mutex_enter(&ill->ill_lock); 5087c478bd9Sstevel@tonic-gate ill->ill_mcast_v1_time = 0; 5097c478bd9Sstevel@tonic-gate ill->ill_mcast_v1_tset = 1; 5107c478bd9Sstevel@tonic-gate if (ill->ill_mcast_type != IGMP_V1_ROUTER) { 5117c478bd9Sstevel@tonic-gate ip1dbg(("Received IGMPv1 Query on %s, switching mode " 5127c478bd9Sstevel@tonic-gate "to IGMP_V1_ROUTER\n", ill->ill_name)); 5137c478bd9Sstevel@tonic-gate atomic_add_16(&ill->ill_ifptr->illif_mcast_v1, 1); 5147c478bd9Sstevel@tonic-gate ill->ill_mcast_type = IGMP_V1_ROUTER; 5157c478bd9Sstevel@tonic-gate } 5167c478bd9Sstevel@tonic-gate mutex_exit(&ill->ill_lock); 5177c478bd9Sstevel@tonic-gate 5187c478bd9Sstevel@tonic-gate timer = SEC_TO_MSEC(IGMP_MAX_HOST_REPORT_DELAY); 5197c478bd9Sstevel@tonic-gate 5207c478bd9Sstevel@tonic-gate if (ipha->ipha_dst != htonl(INADDR_ALLHOSTS_GROUP) || 5217c478bd9Sstevel@tonic-gate igmpa->igmpa_group != 0) { 5227c478bd9Sstevel@tonic-gate ++igmpstat.igps_rcv_badqueries; 5237c478bd9Sstevel@tonic-gate return (0); 5247c478bd9Sstevel@tonic-gate } 5257c478bd9Sstevel@tonic-gate 5267c478bd9Sstevel@tonic-gate } else { 5277c478bd9Sstevel@tonic-gate in_addr_t group; 5287c478bd9Sstevel@tonic-gate 5297c478bd9Sstevel@tonic-gate /* 5307c478bd9Sstevel@tonic-gate * Query from a new router 5317c478bd9Sstevel@tonic-gate * Simply do a validity check 5327c478bd9Sstevel@tonic-gate */ 5337c478bd9Sstevel@tonic-gate group = igmpa->igmpa_group; 5347c478bd9Sstevel@tonic-gate if (group != 0 && (!CLASSD(group))) { 5357c478bd9Sstevel@tonic-gate ++igmpstat.igps_rcv_badqueries; 5367c478bd9Sstevel@tonic-gate return (0); 5377c478bd9Sstevel@tonic-gate } 5387c478bd9Sstevel@tonic-gate 5397c478bd9Sstevel@tonic-gate /* 5407c478bd9Sstevel@tonic-gate * Switch interface state to v2 on receipt of a v2 query 5417c478bd9Sstevel@tonic-gate * ONLY IF current state is v3. Let things be if current 5427c478bd9Sstevel@tonic-gate * state if v1 but do reset the v2-querier-present timer. 5437c478bd9Sstevel@tonic-gate */ 5447c478bd9Sstevel@tonic-gate mutex_enter(&ill->ill_lock); 5457c478bd9Sstevel@tonic-gate if (ill->ill_mcast_type == IGMP_V3_ROUTER) { 5467c478bd9Sstevel@tonic-gate ip1dbg(("Received IGMPv2 Query on %s, switching mode " 5477c478bd9Sstevel@tonic-gate "to IGMP_V2_ROUTER", ill->ill_name)); 5487c478bd9Sstevel@tonic-gate atomic_add_16(&ill->ill_ifptr->illif_mcast_v2, 1); 5497c478bd9Sstevel@tonic-gate ill->ill_mcast_type = IGMP_V2_ROUTER; 5507c478bd9Sstevel@tonic-gate } 5517c478bd9Sstevel@tonic-gate ill->ill_mcast_v2_time = 0; 5527c478bd9Sstevel@tonic-gate ill->ill_mcast_v2_tset = 1; 5537c478bd9Sstevel@tonic-gate mutex_exit(&ill->ill_lock); 5547c478bd9Sstevel@tonic-gate 5557c478bd9Sstevel@tonic-gate timer = DSEC_TO_MSEC((int)igmpa->igmpa_code); 5567c478bd9Sstevel@tonic-gate } 5577c478bd9Sstevel@tonic-gate 5587c478bd9Sstevel@tonic-gate if (ip_debug > 1) { 5597c478bd9Sstevel@tonic-gate mutex_enter(&ill->ill_lock); 5607c478bd9Sstevel@tonic-gate (void) mi_strlog(ill->ill_rq, 1, SL_TRACE, 5617c478bd9Sstevel@tonic-gate "igmp_input: TIMER = igmp_code %d igmp_type 0x%x", 5627c478bd9Sstevel@tonic-gate (int)ntohs(igmpa->igmpa_code), 5637c478bd9Sstevel@tonic-gate (int)ntohs(igmpa->igmpa_type)); 5647c478bd9Sstevel@tonic-gate mutex_exit(&ill->ill_lock); 5657c478bd9Sstevel@tonic-gate } 5667c478bd9Sstevel@tonic-gate 5677c478bd9Sstevel@tonic-gate /* 5687c478bd9Sstevel@tonic-gate * -Start the timers in all of our membership records 5697c478bd9Sstevel@tonic-gate * for the physical interface on which the query 5707c478bd9Sstevel@tonic-gate * arrived, excluding those that belong to the "all 5717c478bd9Sstevel@tonic-gate * hosts" group (224.0.0.1). 5727c478bd9Sstevel@tonic-gate * 5737c478bd9Sstevel@tonic-gate * -Restart any timer that is already running but has 5747c478bd9Sstevel@tonic-gate * a value longer than the requested timeout. 5757c478bd9Sstevel@tonic-gate * 5767c478bd9Sstevel@tonic-gate * -Use the value specified in the query message as 5777c478bd9Sstevel@tonic-gate * the maximum timeout. 5787c478bd9Sstevel@tonic-gate */ 5797c478bd9Sstevel@tonic-gate next = (unsigned)INFINITY; 5807c478bd9Sstevel@tonic-gate mutex_enter(&ill->ill_lock); 5817c478bd9Sstevel@tonic-gate for (ilm = ill->ill_ilm; ilm; ilm = ilm->ilm_next) { 5827c478bd9Sstevel@tonic-gate 5837c478bd9Sstevel@tonic-gate /* 5847c478bd9Sstevel@tonic-gate * A multicast router joins INADDR_ANY address 5857c478bd9Sstevel@tonic-gate * to enable promiscuous reception of all 5867c478bd9Sstevel@tonic-gate * mcasts from the interface. This INADDR_ANY 5877c478bd9Sstevel@tonic-gate * is stored in the ilm_v6addr as V6 unspec addr 5887c478bd9Sstevel@tonic-gate */ 5897c478bd9Sstevel@tonic-gate if (!IN6_IS_ADDR_V4MAPPED(&ilm->ilm_v6addr)) 5907c478bd9Sstevel@tonic-gate continue; 5917c478bd9Sstevel@tonic-gate if (ilm->ilm_addr == htonl(INADDR_ANY)) 5927c478bd9Sstevel@tonic-gate continue; 5937c478bd9Sstevel@tonic-gate if (ilm->ilm_addr != htonl(INADDR_ALLHOSTS_GROUP) && 5947c478bd9Sstevel@tonic-gate (igmpa->igmpa_group == 0) || 5957c478bd9Sstevel@tonic-gate (igmpa->igmpa_group == ilm->ilm_addr)) { 5967c478bd9Sstevel@tonic-gate if (ilm->ilm_timer > timer) { 5977c478bd9Sstevel@tonic-gate MCAST_RANDOM_DELAY(ilm->ilm_timer, timer); 5987c478bd9Sstevel@tonic-gate if (ilm->ilm_timer < next) 5997c478bd9Sstevel@tonic-gate next = ilm->ilm_timer; 6007c478bd9Sstevel@tonic-gate } 6017c478bd9Sstevel@tonic-gate } 6027c478bd9Sstevel@tonic-gate } 6037c478bd9Sstevel@tonic-gate mutex_exit(&ill->ill_lock); 6047c478bd9Sstevel@tonic-gate 6057c478bd9Sstevel@tonic-gate return (next); 6067c478bd9Sstevel@tonic-gate } 6077c478bd9Sstevel@tonic-gate 6087c478bd9Sstevel@tonic-gate static uint_t 6097c478bd9Sstevel@tonic-gate igmpv3_query_in(igmp3qa_t *igmp3qa, ill_t *ill, int igmplen) 6107c478bd9Sstevel@tonic-gate { 6117c478bd9Sstevel@tonic-gate uint_t i, next, mrd, qqi, timer, delay, numsrc; 6127c478bd9Sstevel@tonic-gate ilm_t *ilm; 6137c478bd9Sstevel@tonic-gate ipaddr_t *src_array; 6147c478bd9Sstevel@tonic-gate uint8_t qrv; 6157c478bd9Sstevel@tonic-gate 6167c478bd9Sstevel@tonic-gate /* make sure numsrc matches packet size */ 6177c478bd9Sstevel@tonic-gate numsrc = ntohs(igmp3qa->igmp3qa_numsrc); 6187c478bd9Sstevel@tonic-gate if (igmplen < IGMP_V3_QUERY_MINLEN + (numsrc * sizeof (ipaddr_t))) { 6197c478bd9Sstevel@tonic-gate ++igmpstat.igps_rcv_tooshort; 6207c478bd9Sstevel@tonic-gate return (0); 6217c478bd9Sstevel@tonic-gate } 6227c478bd9Sstevel@tonic-gate src_array = (ipaddr_t *)&igmp3qa[1]; 6237c478bd9Sstevel@tonic-gate 6247c478bd9Sstevel@tonic-gate ++igmpstat.igps_rcv_queries; 6257c478bd9Sstevel@tonic-gate 6267c478bd9Sstevel@tonic-gate if ((mrd = (uint_t)igmp3qa->igmp3qa_mxrc) >= IGMP_V3_MAXRT_FPMIN) { 6277c478bd9Sstevel@tonic-gate uint_t hdrval, mant, exp; 6287c478bd9Sstevel@tonic-gate hdrval = (uint_t)igmp3qa->igmp3qa_mxrc; 6297c478bd9Sstevel@tonic-gate mant = hdrval & IGMP_V3_MAXRT_MANT_MASK; 6307c478bd9Sstevel@tonic-gate exp = (hdrval & IGMP_V3_MAXRT_EXP_MASK) >> 4; 6317c478bd9Sstevel@tonic-gate mrd = (mant | 0x10) << (exp + 3); 6327c478bd9Sstevel@tonic-gate } 6337c478bd9Sstevel@tonic-gate if (mrd == 0) 6347c478bd9Sstevel@tonic-gate mrd = MCAST_DEF_QUERY_RESP_INTERVAL; 6357c478bd9Sstevel@tonic-gate timer = DSEC_TO_MSEC(mrd); 6367c478bd9Sstevel@tonic-gate MCAST_RANDOM_DELAY(delay, timer); 6377c478bd9Sstevel@tonic-gate next = (unsigned)INFINITY; 6387c478bd9Sstevel@tonic-gate 6397c478bd9Sstevel@tonic-gate if ((qrv = igmp3qa->igmp3qa_sqrv & IGMP_V3_RV_MASK) == 0) 6407c478bd9Sstevel@tonic-gate ill->ill_mcast_rv = MCAST_DEF_ROBUSTNESS; 6417c478bd9Sstevel@tonic-gate else 6427c478bd9Sstevel@tonic-gate ill->ill_mcast_rv = qrv; 6437c478bd9Sstevel@tonic-gate 6447c478bd9Sstevel@tonic-gate if ((qqi = (uint_t)igmp3qa->igmp3qa_qqic) >= IGMP_V3_QQI_FPMIN) { 6457c478bd9Sstevel@tonic-gate uint_t hdrval, mant, exp; 6467c478bd9Sstevel@tonic-gate hdrval = (uint_t)igmp3qa->igmp3qa_qqic; 6477c478bd9Sstevel@tonic-gate mant = hdrval & IGMP_V3_QQI_MANT_MASK; 6487c478bd9Sstevel@tonic-gate exp = (hdrval & IGMP_V3_QQI_EXP_MASK) >> 4; 6497c478bd9Sstevel@tonic-gate qqi = (mant | 0x10) << (exp + 3); 6507c478bd9Sstevel@tonic-gate } 6517c478bd9Sstevel@tonic-gate ill->ill_mcast_qi = (qqi == 0) ? MCAST_DEF_QUERY_INTERVAL : qqi; 6527c478bd9Sstevel@tonic-gate 6537c478bd9Sstevel@tonic-gate /* 6547c478bd9Sstevel@tonic-gate * If we have a pending general query response that's scheduled 6557c478bd9Sstevel@tonic-gate * sooner than the delay we calculated for this response, then 6567c478bd9Sstevel@tonic-gate * no action is required (RFC3376 section 5.2 rule 1) 6577c478bd9Sstevel@tonic-gate */ 6587c478bd9Sstevel@tonic-gate mutex_enter(&ill->ill_lock); 6597c478bd9Sstevel@tonic-gate if (ill->ill_global_timer < delay) { 6607c478bd9Sstevel@tonic-gate mutex_exit(&ill->ill_lock); 6617c478bd9Sstevel@tonic-gate return (next); 6627c478bd9Sstevel@tonic-gate } 6637c478bd9Sstevel@tonic-gate mutex_exit(&ill->ill_lock); 6647c478bd9Sstevel@tonic-gate 6657c478bd9Sstevel@tonic-gate /* 6667c478bd9Sstevel@tonic-gate * Now take action depending upon query type: 6677c478bd9Sstevel@tonic-gate * general, group specific, or group/source specific. 6687c478bd9Sstevel@tonic-gate */ 6697c478bd9Sstevel@tonic-gate if ((numsrc == 0) && (igmp3qa->igmp3qa_group == INADDR_ANY)) { 6707c478bd9Sstevel@tonic-gate /* 6717c478bd9Sstevel@tonic-gate * general query 6727c478bd9Sstevel@tonic-gate * We know global timer is either not running or is 6737c478bd9Sstevel@tonic-gate * greater than our calculated delay, so reset it to 6747c478bd9Sstevel@tonic-gate * our delay (random value in range [0, response time]). 6757c478bd9Sstevel@tonic-gate */ 6767c478bd9Sstevel@tonic-gate mutex_enter(&ill->ill_lock); 6777c478bd9Sstevel@tonic-gate ill->ill_global_timer = delay; 6787c478bd9Sstevel@tonic-gate next = ill->ill_global_timer; 6797c478bd9Sstevel@tonic-gate mutex_exit(&ill->ill_lock); 6807c478bd9Sstevel@tonic-gate 6817c478bd9Sstevel@tonic-gate } else { 6827c478bd9Sstevel@tonic-gate /* group or group/source specific query */ 6837c478bd9Sstevel@tonic-gate mutex_enter(&ill->ill_lock); 6847c478bd9Sstevel@tonic-gate for (ilm = ill->ill_ilm; ilm; ilm = ilm->ilm_next) { 6857c478bd9Sstevel@tonic-gate if (!IN6_IS_ADDR_V4MAPPED(&ilm->ilm_v6addr) || 6867c478bd9Sstevel@tonic-gate (ilm->ilm_addr == htonl(INADDR_ANY)) || 6877c478bd9Sstevel@tonic-gate (ilm->ilm_addr == htonl(INADDR_ALLHOSTS_GROUP)) || 6887c478bd9Sstevel@tonic-gate (igmp3qa->igmp3qa_group != ilm->ilm_addr)) 6897c478bd9Sstevel@tonic-gate continue; 6907c478bd9Sstevel@tonic-gate /* 6917c478bd9Sstevel@tonic-gate * If the query is group specific or we have a 6927c478bd9Sstevel@tonic-gate * pending group specific query, the response is 6937c478bd9Sstevel@tonic-gate * group specific (pending sources list should be 6947c478bd9Sstevel@tonic-gate * empty). Otherwise, need to update the pending 6957c478bd9Sstevel@tonic-gate * sources list for the group and source specific 6967c478bd9Sstevel@tonic-gate * response. 6977c478bd9Sstevel@tonic-gate */ 6987c478bd9Sstevel@tonic-gate if (numsrc == 0 || (ilm->ilm_timer < INFINITY && 6997c478bd9Sstevel@tonic-gate SLIST_IS_EMPTY(ilm->ilm_pendsrcs))) { 7007c478bd9Sstevel@tonic-gate group_query: 7017c478bd9Sstevel@tonic-gate FREE_SLIST(ilm->ilm_pendsrcs); 7027c478bd9Sstevel@tonic-gate ilm->ilm_pendsrcs = NULL; 7037c478bd9Sstevel@tonic-gate } else { 7047c478bd9Sstevel@tonic-gate boolean_t overflow; 7057c478bd9Sstevel@tonic-gate slist_t *pktl; 7067c478bd9Sstevel@tonic-gate if (numsrc > MAX_FILTER_SIZE || 7077c478bd9Sstevel@tonic-gate (ilm->ilm_pendsrcs == NULL && 7087c478bd9Sstevel@tonic-gate (ilm->ilm_pendsrcs = l_alloc()) == NULL)) { 7097c478bd9Sstevel@tonic-gate /* 7107c478bd9Sstevel@tonic-gate * We've been sent more sources than 7117c478bd9Sstevel@tonic-gate * we can deal with; or we can't deal 7127c478bd9Sstevel@tonic-gate * with a source list at all. Revert 7137c478bd9Sstevel@tonic-gate * to a group specific query. 7147c478bd9Sstevel@tonic-gate */ 7157c478bd9Sstevel@tonic-gate goto group_query; 7167c478bd9Sstevel@tonic-gate } 7177c478bd9Sstevel@tonic-gate if ((pktl = l_alloc()) == NULL) 7187c478bd9Sstevel@tonic-gate goto group_query; 7197c478bd9Sstevel@tonic-gate pktl->sl_numsrc = numsrc; 7207c478bd9Sstevel@tonic-gate for (i = 0; i < numsrc; i++) 7217c478bd9Sstevel@tonic-gate IN6_IPADDR_TO_V4MAPPED(src_array[i], 7227c478bd9Sstevel@tonic-gate &(pktl->sl_addr[i])); 7237c478bd9Sstevel@tonic-gate l_union_in_a(ilm->ilm_pendsrcs, pktl, 7247c478bd9Sstevel@tonic-gate &overflow); 7257c478bd9Sstevel@tonic-gate l_free(pktl); 7267c478bd9Sstevel@tonic-gate if (overflow) 7277c478bd9Sstevel@tonic-gate goto group_query; 7287c478bd9Sstevel@tonic-gate } 7297c478bd9Sstevel@tonic-gate /* choose soonest timer */ 7307c478bd9Sstevel@tonic-gate ilm->ilm_timer = MIN(ilm->ilm_timer, delay); 7317c478bd9Sstevel@tonic-gate if (ilm->ilm_timer < next) 7327c478bd9Sstevel@tonic-gate next = ilm->ilm_timer; 7337c478bd9Sstevel@tonic-gate } 7347c478bd9Sstevel@tonic-gate mutex_exit(&ill->ill_lock); 7357c478bd9Sstevel@tonic-gate } 7367c478bd9Sstevel@tonic-gate 7377c478bd9Sstevel@tonic-gate return (next); 7387c478bd9Sstevel@tonic-gate } 7397c478bd9Sstevel@tonic-gate 7407c478bd9Sstevel@tonic-gate void 7417c478bd9Sstevel@tonic-gate igmp_joingroup(ilm_t *ilm) 7427c478bd9Sstevel@tonic-gate { 7437c478bd9Sstevel@tonic-gate ill_t *ill; 7447c478bd9Sstevel@tonic-gate 7457c478bd9Sstevel@tonic-gate ill = ilm->ilm_ipif->ipif_ill; 7467c478bd9Sstevel@tonic-gate 7477c478bd9Sstevel@tonic-gate ASSERT(IAM_WRITER_ILL(ill)); 7487c478bd9Sstevel@tonic-gate ASSERT(ilm->ilm_ill == NULL && !ilm->ilm_ipif->ipif_isv6); 7497c478bd9Sstevel@tonic-gate 7507c478bd9Sstevel@tonic-gate mutex_enter(&ill->ill_lock); 7517c478bd9Sstevel@tonic-gate if (ilm->ilm_addr == htonl(INADDR_ALLHOSTS_GROUP)) { 7527c478bd9Sstevel@tonic-gate ilm->ilm_rtx.rtx_timer = INFINITY; 7537c478bd9Sstevel@tonic-gate ilm->ilm_state = IGMP_OTHERMEMBER; 7547c478bd9Sstevel@tonic-gate mutex_exit(&ill->ill_lock); 7557c478bd9Sstevel@tonic-gate } else { 7567c478bd9Sstevel@tonic-gate ip1dbg(("Querier mode %d, sending report, group %x\n", 7577c478bd9Sstevel@tonic-gate ill->ill_mcast_type, htonl(ilm->ilm_addr))); 7587c478bd9Sstevel@tonic-gate if (ill->ill_mcast_type == IGMP_V1_ROUTER) { 7597c478bd9Sstevel@tonic-gate mutex_exit(&ill->ill_lock); 7607c478bd9Sstevel@tonic-gate igmp_sendpkt(ilm, IGMP_V1_MEMBERSHIP_REPORT, 0); 7617c478bd9Sstevel@tonic-gate mutex_enter(&ill->ill_lock); 7627c478bd9Sstevel@tonic-gate } else if (ill->ill_mcast_type == IGMP_V2_ROUTER) { 7637c478bd9Sstevel@tonic-gate mutex_exit(&ill->ill_lock); 7647c478bd9Sstevel@tonic-gate igmp_sendpkt(ilm, IGMP_V2_MEMBERSHIP_REPORT, 0); 7657c478bd9Sstevel@tonic-gate mutex_enter(&ill->ill_lock); 7667c478bd9Sstevel@tonic-gate } else if (ill->ill_mcast_type == IGMP_V3_ROUTER) { 7677c478bd9Sstevel@tonic-gate mrec_t *rp; 7687c478bd9Sstevel@tonic-gate mcast_record_t rtype; 7697c478bd9Sstevel@tonic-gate /* 7707c478bd9Sstevel@tonic-gate * The possible state changes we need to handle here: 7717c478bd9Sstevel@tonic-gate * Old State New State Report 7727c478bd9Sstevel@tonic-gate * 7737c478bd9Sstevel@tonic-gate * INCLUDE(0) INCLUDE(X) ALLOW(X),BLOCK(0) 7747c478bd9Sstevel@tonic-gate * INCLUDE(0) EXCLUDE(X) TO_EX(X) 7757c478bd9Sstevel@tonic-gate * 7767c478bd9Sstevel@tonic-gate * No need to send the BLOCK(0) report; ALLOW(X) 7777c478bd9Sstevel@tonic-gate * is enough. 7787c478bd9Sstevel@tonic-gate */ 7797c478bd9Sstevel@tonic-gate rtype = (ilm->ilm_fmode == MODE_IS_INCLUDE) ? 7807c478bd9Sstevel@tonic-gate ALLOW_NEW_SOURCES : CHANGE_TO_EXCLUDE; 7817c478bd9Sstevel@tonic-gate rp = mcast_bldmrec(rtype, &ilm->ilm_v6addr, 7827c478bd9Sstevel@tonic-gate ilm->ilm_filter, NULL); 7837c478bd9Sstevel@tonic-gate mutex_exit(&ill->ill_lock); 7847c478bd9Sstevel@tonic-gate igmpv3_sendrpt(ilm->ilm_ipif, rp); 7857c478bd9Sstevel@tonic-gate mutex_enter(&ill->ill_lock); 7867c478bd9Sstevel@tonic-gate /* 7877c478bd9Sstevel@tonic-gate * Set up retransmission state. Timer is set below, 7887c478bd9Sstevel@tonic-gate * for both v3 and older versions. 7897c478bd9Sstevel@tonic-gate */ 7907c478bd9Sstevel@tonic-gate mcast_init_rtx(ill, &ilm->ilm_rtx, rtype, 7917c478bd9Sstevel@tonic-gate ilm->ilm_filter); 7927c478bd9Sstevel@tonic-gate } 7937c478bd9Sstevel@tonic-gate 7947c478bd9Sstevel@tonic-gate /* Set the ilm timer value */ 7957c478bd9Sstevel@tonic-gate MCAST_RANDOM_DELAY(ilm->ilm_rtx.rtx_timer, 7967c478bd9Sstevel@tonic-gate SEC_TO_MSEC(IGMP_MAX_HOST_REPORT_DELAY)); 7977c478bd9Sstevel@tonic-gate ilm->ilm_state = IGMP_IREPORTEDLAST; 7987c478bd9Sstevel@tonic-gate mutex_exit(&ill->ill_lock); 7997c478bd9Sstevel@tonic-gate 8007c478bd9Sstevel@tonic-gate /* 8017c478bd9Sstevel@tonic-gate * To avoid deadlock, we don't call igmp_start_timers from 8027c478bd9Sstevel@tonic-gate * here. igmp_start_timers needs to call untimeout, and we 8037c478bd9Sstevel@tonic-gate * can't hold the ipsq across untimeout since 8047c478bd9Sstevel@tonic-gate * igmp_timeout_handler could be blocking trying to 8057c478bd9Sstevel@tonic-gate * acquire the ipsq. Instead we start the timer after we get 8067c478bd9Sstevel@tonic-gate * out of the ipsq in ipsq_exit. 8077c478bd9Sstevel@tonic-gate */ 8087c478bd9Sstevel@tonic-gate mutex_enter(&igmp_timer_lock); 8097c478bd9Sstevel@tonic-gate igmp_deferred_next = MIN(ilm->ilm_rtx.rtx_timer, 8107c478bd9Sstevel@tonic-gate igmp_deferred_next); 8117c478bd9Sstevel@tonic-gate mutex_exit(&igmp_timer_lock); 8127c478bd9Sstevel@tonic-gate } 8137c478bd9Sstevel@tonic-gate 8147c478bd9Sstevel@tonic-gate if (ip_debug > 1) { 8157c478bd9Sstevel@tonic-gate (void) mi_strlog(ilm->ilm_ipif->ipif_ill->ill_rq, 1, SL_TRACE, 8167c478bd9Sstevel@tonic-gate "igmp_joingroup: multicast_type %d timer %d", 8177c478bd9Sstevel@tonic-gate (ilm->ilm_ipif->ipif_ill->ill_mcast_type), 8187c478bd9Sstevel@tonic-gate (int)ntohl(ilm->ilm_rtx.rtx_timer)); 8197c478bd9Sstevel@tonic-gate } 8207c478bd9Sstevel@tonic-gate } 8217c478bd9Sstevel@tonic-gate 8227c478bd9Sstevel@tonic-gate void 8237c478bd9Sstevel@tonic-gate mld_joingroup(ilm_t *ilm) 8247c478bd9Sstevel@tonic-gate { 8257c478bd9Sstevel@tonic-gate ill_t *ill; 8267c478bd9Sstevel@tonic-gate 8277c478bd9Sstevel@tonic-gate ill = ilm->ilm_ill; 8287c478bd9Sstevel@tonic-gate 8297c478bd9Sstevel@tonic-gate ASSERT(IAM_WRITER_ILL(ill)); 8307c478bd9Sstevel@tonic-gate ASSERT(ilm->ilm_ipif == NULL && ill->ill_isv6); 8317c478bd9Sstevel@tonic-gate 8327c478bd9Sstevel@tonic-gate mutex_enter(&ill->ill_lock); 8337c478bd9Sstevel@tonic-gate if (IN6_ARE_ADDR_EQUAL(&ipv6_all_hosts_mcast, &ilm->ilm_v6addr)) { 8347c478bd9Sstevel@tonic-gate ilm->ilm_rtx.rtx_timer = INFINITY; 8357c478bd9Sstevel@tonic-gate ilm->ilm_state = IGMP_OTHERMEMBER; 8367c478bd9Sstevel@tonic-gate mutex_exit(&ill->ill_lock); 8377c478bd9Sstevel@tonic-gate } else { 8387c478bd9Sstevel@tonic-gate if (ill->ill_mcast_type == MLD_V1_ROUTER) { 8397c478bd9Sstevel@tonic-gate mutex_exit(&ill->ill_lock); 8407c478bd9Sstevel@tonic-gate mld_sendpkt(ilm, MLD_LISTENER_REPORT, NULL); 8417c478bd9Sstevel@tonic-gate mutex_enter(&ill->ill_lock); 8427c478bd9Sstevel@tonic-gate } else { 8437c478bd9Sstevel@tonic-gate mrec_t *rp; 8447c478bd9Sstevel@tonic-gate mcast_record_t rtype; 8457c478bd9Sstevel@tonic-gate /* 8467c478bd9Sstevel@tonic-gate * The possible state changes we need to handle here: 8477c478bd9Sstevel@tonic-gate * Old State New State Report 8487c478bd9Sstevel@tonic-gate * 8497c478bd9Sstevel@tonic-gate * INCLUDE(0) INCLUDE(X) ALLOW(X),BLOCK(0) 8507c478bd9Sstevel@tonic-gate * INCLUDE(0) EXCLUDE(X) TO_EX(X) 8517c478bd9Sstevel@tonic-gate * 8527c478bd9Sstevel@tonic-gate * No need to send the BLOCK(0) report; ALLOW(X) 8537c478bd9Sstevel@tonic-gate * is enough 8547c478bd9Sstevel@tonic-gate */ 8557c478bd9Sstevel@tonic-gate rtype = (ilm->ilm_fmode == MODE_IS_INCLUDE) ? 8567c478bd9Sstevel@tonic-gate ALLOW_NEW_SOURCES : CHANGE_TO_EXCLUDE; 8577c478bd9Sstevel@tonic-gate rp = mcast_bldmrec(rtype, &ilm->ilm_v6addr, 8587c478bd9Sstevel@tonic-gate ilm->ilm_filter, NULL); 8597c478bd9Sstevel@tonic-gate mutex_exit(&ill->ill_lock); 8607c478bd9Sstevel@tonic-gate mldv2_sendrpt(ill, rp); 8617c478bd9Sstevel@tonic-gate mutex_enter(&ill->ill_lock); 8627c478bd9Sstevel@tonic-gate /* 8637c478bd9Sstevel@tonic-gate * Set up retransmission state. Timer is set below, 8647c478bd9Sstevel@tonic-gate * for both v2 and v1. 8657c478bd9Sstevel@tonic-gate */ 8667c478bd9Sstevel@tonic-gate mcast_init_rtx(ill, &ilm->ilm_rtx, rtype, 8677c478bd9Sstevel@tonic-gate ilm->ilm_filter); 8687c478bd9Sstevel@tonic-gate } 8697c478bd9Sstevel@tonic-gate 8707c478bd9Sstevel@tonic-gate /* Set the ilm timer value */ 8717c478bd9Sstevel@tonic-gate ASSERT(ill->ill_mcast_type != MLD_V2_ROUTER || 8727c478bd9Sstevel@tonic-gate ilm->ilm_rtx.rtx_cnt > 0); 8737c478bd9Sstevel@tonic-gate MCAST_RANDOM_DELAY(ilm->ilm_rtx.rtx_timer, 8747c478bd9Sstevel@tonic-gate SEC_TO_MSEC(ICMP6_MAX_HOST_REPORT_DELAY)); 8757c478bd9Sstevel@tonic-gate ilm->ilm_state = IGMP_IREPORTEDLAST; 8767c478bd9Sstevel@tonic-gate mutex_exit(&ill->ill_lock); 8777c478bd9Sstevel@tonic-gate 8787c478bd9Sstevel@tonic-gate /* 8797c478bd9Sstevel@tonic-gate * To avoid deadlock, we don't call mld_start_timers from 8807c478bd9Sstevel@tonic-gate * here. mld_start_timers needs to call untimeout, and we 8817c478bd9Sstevel@tonic-gate * can't hold the ipsq (i.e. the lock) across untimeout 8827c478bd9Sstevel@tonic-gate * since mld_timeout_handler could be blocking trying to 8837c478bd9Sstevel@tonic-gate * acquire the ipsq. Instead we start the timer after we get 8847c478bd9Sstevel@tonic-gate * out of the ipsq in ipsq_exit 8857c478bd9Sstevel@tonic-gate */ 8867c478bd9Sstevel@tonic-gate mutex_enter(&mld_timer_lock); 8877c478bd9Sstevel@tonic-gate mld_deferred_next = MIN(ilm->ilm_rtx.rtx_timer, 8887c478bd9Sstevel@tonic-gate mld_deferred_next); 8897c478bd9Sstevel@tonic-gate mutex_exit(&mld_timer_lock); 8907c478bd9Sstevel@tonic-gate } 8917c478bd9Sstevel@tonic-gate 8927c478bd9Sstevel@tonic-gate if (ip_debug > 1) { 8937c478bd9Sstevel@tonic-gate (void) mi_strlog(ilm->ilm_ill->ill_rq, 1, SL_TRACE, 8947c478bd9Sstevel@tonic-gate "mld_joingroup: multicast_type %d timer %d", 8957c478bd9Sstevel@tonic-gate (ilm->ilm_ill->ill_mcast_type), 8967c478bd9Sstevel@tonic-gate (int)ntohl(ilm->ilm_rtx.rtx_timer)); 8977c478bd9Sstevel@tonic-gate } 8987c478bd9Sstevel@tonic-gate } 8997c478bd9Sstevel@tonic-gate 9007c478bd9Sstevel@tonic-gate void 9017c478bd9Sstevel@tonic-gate igmp_leavegroup(ilm_t *ilm) 9027c478bd9Sstevel@tonic-gate { 9037c478bd9Sstevel@tonic-gate ill_t *ill = ilm->ilm_ipif->ipif_ill; 9047c478bd9Sstevel@tonic-gate 9057c478bd9Sstevel@tonic-gate ASSERT(ilm->ilm_ill == NULL); 9067c478bd9Sstevel@tonic-gate ASSERT(!ill->ill_isv6); 9077c478bd9Sstevel@tonic-gate 9087c478bd9Sstevel@tonic-gate mutex_enter(&ill->ill_lock); 9097c478bd9Sstevel@tonic-gate if (ilm->ilm_state == IGMP_IREPORTEDLAST && 9107c478bd9Sstevel@tonic-gate ill->ill_mcast_type == IGMP_V2_ROUTER && 9117c478bd9Sstevel@tonic-gate (ilm->ilm_addr != htonl(INADDR_ALLHOSTS_GROUP))) { 9127c478bd9Sstevel@tonic-gate mutex_exit(&ill->ill_lock); 9137c478bd9Sstevel@tonic-gate igmp_sendpkt(ilm, IGMP_V2_LEAVE_GROUP, 9147c478bd9Sstevel@tonic-gate (htonl(INADDR_ALLRTRS_GROUP))); 9157c478bd9Sstevel@tonic-gate return; 9167c478bd9Sstevel@tonic-gate } else if ((ill->ill_mcast_type == IGMP_V3_ROUTER) && 9177c478bd9Sstevel@tonic-gate (ilm->ilm_addr != htonl(INADDR_ALLHOSTS_GROUP))) { 9187c478bd9Sstevel@tonic-gate mrec_t *rp; 9197c478bd9Sstevel@tonic-gate /* 9207c478bd9Sstevel@tonic-gate * The possible state changes we need to handle here: 9217c478bd9Sstevel@tonic-gate * Old State New State Report 9227c478bd9Sstevel@tonic-gate * 9237c478bd9Sstevel@tonic-gate * INCLUDE(X) INCLUDE(0) ALLOW(0),BLOCK(X) 9247c478bd9Sstevel@tonic-gate * EXCLUDE(X) INCLUDE(0) TO_IN(0) 9257c478bd9Sstevel@tonic-gate * 9267c478bd9Sstevel@tonic-gate * No need to send the ALLOW(0) report; BLOCK(X) is enough 9277c478bd9Sstevel@tonic-gate */ 9287c478bd9Sstevel@tonic-gate if (ilm->ilm_fmode == MODE_IS_INCLUDE) { 9297c478bd9Sstevel@tonic-gate rp = mcast_bldmrec(BLOCK_OLD_SOURCES, &ilm->ilm_v6addr, 9307c478bd9Sstevel@tonic-gate ilm->ilm_filter, NULL); 9317c478bd9Sstevel@tonic-gate } else { 9327c478bd9Sstevel@tonic-gate rp = mcast_bldmrec(CHANGE_TO_INCLUDE, &ilm->ilm_v6addr, 9337c478bd9Sstevel@tonic-gate NULL, NULL); 9347c478bd9Sstevel@tonic-gate } 9357c478bd9Sstevel@tonic-gate mutex_exit(&ill->ill_lock); 9367c478bd9Sstevel@tonic-gate igmpv3_sendrpt(ilm->ilm_ipif, rp); 9377c478bd9Sstevel@tonic-gate return; 9387c478bd9Sstevel@tonic-gate } 9397c478bd9Sstevel@tonic-gate mutex_exit(&ill->ill_lock); 9407c478bd9Sstevel@tonic-gate } 9417c478bd9Sstevel@tonic-gate 9427c478bd9Sstevel@tonic-gate void 9437c478bd9Sstevel@tonic-gate mld_leavegroup(ilm_t *ilm) 9447c478bd9Sstevel@tonic-gate { 9457c478bd9Sstevel@tonic-gate ill_t *ill = ilm->ilm_ill; 9467c478bd9Sstevel@tonic-gate 9477c478bd9Sstevel@tonic-gate ASSERT(ilm->ilm_ipif == NULL); 9487c478bd9Sstevel@tonic-gate ASSERT(ill->ill_isv6); 9497c478bd9Sstevel@tonic-gate 9507c478bd9Sstevel@tonic-gate mutex_enter(&ill->ill_lock); 9517c478bd9Sstevel@tonic-gate if (ilm->ilm_state == IGMP_IREPORTEDLAST && 9527c478bd9Sstevel@tonic-gate ill->ill_mcast_type == MLD_V1_ROUTER && 9537c478bd9Sstevel@tonic-gate (!IN6_ARE_ADDR_EQUAL(&ipv6_all_hosts_mcast, &ilm->ilm_v6addr))) { 9547c478bd9Sstevel@tonic-gate mutex_exit(&ill->ill_lock); 9557c478bd9Sstevel@tonic-gate mld_sendpkt(ilm, MLD_LISTENER_REDUCTION, &ipv6_all_rtrs_mcast); 9567c478bd9Sstevel@tonic-gate return; 9577c478bd9Sstevel@tonic-gate } else if ((ill->ill_mcast_type == MLD_V2_ROUTER) && 9587c478bd9Sstevel@tonic-gate (!IN6_ARE_ADDR_EQUAL(&ipv6_all_hosts_mcast, &ilm->ilm_v6addr))) { 9597c478bd9Sstevel@tonic-gate mrec_t *rp; 9607c478bd9Sstevel@tonic-gate /* 9617c478bd9Sstevel@tonic-gate * The possible state changes we need to handle here: 9627c478bd9Sstevel@tonic-gate * Old State New State Report 9637c478bd9Sstevel@tonic-gate * 9647c478bd9Sstevel@tonic-gate * INCLUDE(X) INCLUDE(0) ALLOW(0),BLOCK(X) 9657c478bd9Sstevel@tonic-gate * EXCLUDE(X) INCLUDE(0) TO_IN(0) 9667c478bd9Sstevel@tonic-gate * 9677c478bd9Sstevel@tonic-gate * No need to send the ALLOW(0) report; BLOCK(X) is enough 9687c478bd9Sstevel@tonic-gate */ 9697c478bd9Sstevel@tonic-gate if (ilm->ilm_fmode == MODE_IS_INCLUDE) { 9707c478bd9Sstevel@tonic-gate rp = mcast_bldmrec(BLOCK_OLD_SOURCES, &ilm->ilm_v6addr, 9717c478bd9Sstevel@tonic-gate ilm->ilm_filter, NULL); 9727c478bd9Sstevel@tonic-gate } else { 9737c478bd9Sstevel@tonic-gate rp = mcast_bldmrec(CHANGE_TO_INCLUDE, &ilm->ilm_v6addr, 9747c478bd9Sstevel@tonic-gate NULL, NULL); 9757c478bd9Sstevel@tonic-gate } 9767c478bd9Sstevel@tonic-gate mutex_exit(&ill->ill_lock); 9777c478bd9Sstevel@tonic-gate mldv2_sendrpt(ill, rp); 9787c478bd9Sstevel@tonic-gate return; 9797c478bd9Sstevel@tonic-gate } 9807c478bd9Sstevel@tonic-gate mutex_exit(&ill->ill_lock); 9817c478bd9Sstevel@tonic-gate } 9827c478bd9Sstevel@tonic-gate 9837c478bd9Sstevel@tonic-gate void 9847c478bd9Sstevel@tonic-gate igmp_statechange(ilm_t *ilm, mcast_record_t fmode, slist_t *flist) 9857c478bd9Sstevel@tonic-gate { 9867c478bd9Sstevel@tonic-gate ill_t *ill; 9877c478bd9Sstevel@tonic-gate mrec_t *rp; 9887c478bd9Sstevel@tonic-gate 9897c478bd9Sstevel@tonic-gate ASSERT(ilm != NULL); 9907c478bd9Sstevel@tonic-gate 9917c478bd9Sstevel@tonic-gate /* state change reports should only be sent if the router is v3 */ 9927c478bd9Sstevel@tonic-gate if (ilm->ilm_ipif->ipif_ill->ill_mcast_type != IGMP_V3_ROUTER) 9937c478bd9Sstevel@tonic-gate return; 9947c478bd9Sstevel@tonic-gate 9957c478bd9Sstevel@tonic-gate if (ilm->ilm_ill == NULL) { 9967c478bd9Sstevel@tonic-gate ASSERT(ilm->ilm_ipif != NULL); 9977c478bd9Sstevel@tonic-gate ill = ilm->ilm_ipif->ipif_ill; 9987c478bd9Sstevel@tonic-gate } else { 9997c478bd9Sstevel@tonic-gate ill = ilm->ilm_ill; 10007c478bd9Sstevel@tonic-gate } 10017c478bd9Sstevel@tonic-gate 10027c478bd9Sstevel@tonic-gate mutex_enter(&ill->ill_lock); 10037c478bd9Sstevel@tonic-gate 10047c478bd9Sstevel@tonic-gate /* 10057c478bd9Sstevel@tonic-gate * Compare existing(old) state with the new state and prepare 10067c478bd9Sstevel@tonic-gate * State Change Report, according to the rules in RFC 3376: 10077c478bd9Sstevel@tonic-gate * 10087c478bd9Sstevel@tonic-gate * Old State New State State Change Report 10097c478bd9Sstevel@tonic-gate * 10107c478bd9Sstevel@tonic-gate * INCLUDE(A) INCLUDE(B) ALLOW(B-A),BLOCK(A-B) 10117c478bd9Sstevel@tonic-gate * EXCLUDE(A) EXCLUDE(B) ALLOW(A-B),BLOCK(B-A) 10127c478bd9Sstevel@tonic-gate * INCLUDE(A) EXCLUDE(B) TO_EX(B) 10137c478bd9Sstevel@tonic-gate * EXCLUDE(A) INCLUDE(B) TO_IN(B) 10147c478bd9Sstevel@tonic-gate */ 10157c478bd9Sstevel@tonic-gate 10167c478bd9Sstevel@tonic-gate if (ilm->ilm_fmode == fmode) { 10177c478bd9Sstevel@tonic-gate slist_t *a_minus_b = NULL, *b_minus_a = NULL; 10187c478bd9Sstevel@tonic-gate slist_t *allow, *block; 10197c478bd9Sstevel@tonic-gate if (((a_minus_b = l_alloc()) == NULL) || 10207c478bd9Sstevel@tonic-gate ((b_minus_a = l_alloc()) == NULL)) { 10217c478bd9Sstevel@tonic-gate l_free(a_minus_b); 10227c478bd9Sstevel@tonic-gate if (ilm->ilm_fmode == MODE_IS_INCLUDE) 10237c478bd9Sstevel@tonic-gate goto send_to_ex; 10247c478bd9Sstevel@tonic-gate else 10257c478bd9Sstevel@tonic-gate goto send_to_in; 10267c478bd9Sstevel@tonic-gate } 10277c478bd9Sstevel@tonic-gate l_difference(ilm->ilm_filter, flist, a_minus_b); 10287c478bd9Sstevel@tonic-gate l_difference(flist, ilm->ilm_filter, b_minus_a); 10297c478bd9Sstevel@tonic-gate if (ilm->ilm_fmode == MODE_IS_INCLUDE) { 10307c478bd9Sstevel@tonic-gate allow = b_minus_a; 10317c478bd9Sstevel@tonic-gate block = a_minus_b; 10327c478bd9Sstevel@tonic-gate } else { 10337c478bd9Sstevel@tonic-gate allow = a_minus_b; 10347c478bd9Sstevel@tonic-gate block = b_minus_a; 10357c478bd9Sstevel@tonic-gate } 10367c478bd9Sstevel@tonic-gate rp = NULL; 10377c478bd9Sstevel@tonic-gate if (!SLIST_IS_EMPTY(allow)) 10387c478bd9Sstevel@tonic-gate rp = mcast_bldmrec(ALLOW_NEW_SOURCES, &ilm->ilm_v6addr, 10397c478bd9Sstevel@tonic-gate allow, rp); 10407c478bd9Sstevel@tonic-gate if (!SLIST_IS_EMPTY(block)) 10417c478bd9Sstevel@tonic-gate rp = mcast_bldmrec(BLOCK_OLD_SOURCES, &ilm->ilm_v6addr, 10427c478bd9Sstevel@tonic-gate block, rp); 10437c478bd9Sstevel@tonic-gate l_free(a_minus_b); 10447c478bd9Sstevel@tonic-gate l_free(b_minus_a); 10457c478bd9Sstevel@tonic-gate } else if (ilm->ilm_fmode == MODE_IS_INCLUDE) { 10467c478bd9Sstevel@tonic-gate send_to_ex: 10477c478bd9Sstevel@tonic-gate rp = mcast_bldmrec(CHANGE_TO_EXCLUDE, &ilm->ilm_v6addr, flist, 10487c478bd9Sstevel@tonic-gate NULL); 10497c478bd9Sstevel@tonic-gate } else { 10507c478bd9Sstevel@tonic-gate send_to_in: 10517c478bd9Sstevel@tonic-gate rp = mcast_bldmrec(CHANGE_TO_INCLUDE, &ilm->ilm_v6addr, flist, 10527c478bd9Sstevel@tonic-gate NULL); 10537c478bd9Sstevel@tonic-gate } 10547c478bd9Sstevel@tonic-gate 10557c478bd9Sstevel@tonic-gate /* 10567c478bd9Sstevel@tonic-gate * Need to set up retransmission state; merge the new info with the 10577c478bd9Sstevel@tonic-gate * current state (which may be null). If the timer is not currently 10587c478bd9Sstevel@tonic-gate * running, start it (need to do a delayed start of the timer as 10597c478bd9Sstevel@tonic-gate * we're currently in the sq). 10607c478bd9Sstevel@tonic-gate */ 10617c478bd9Sstevel@tonic-gate rp = mcast_merge_rtx(ilm, rp, flist); 10627c478bd9Sstevel@tonic-gate if (ilm->ilm_rtx.rtx_timer == INFINITY) { 10637c478bd9Sstevel@tonic-gate MCAST_RANDOM_DELAY(ilm->ilm_rtx.rtx_timer, 10647c478bd9Sstevel@tonic-gate SEC_TO_MSEC(IGMP_MAX_HOST_REPORT_DELAY)); 10657c478bd9Sstevel@tonic-gate mutex_enter(&igmp_timer_lock); 10667c478bd9Sstevel@tonic-gate igmp_deferred_next = MIN(igmp_deferred_next, 10677c478bd9Sstevel@tonic-gate ilm->ilm_rtx.rtx_timer); 10687c478bd9Sstevel@tonic-gate mutex_exit(&igmp_timer_lock); 10697c478bd9Sstevel@tonic-gate } 10707c478bd9Sstevel@tonic-gate 10717c478bd9Sstevel@tonic-gate mutex_exit(&ill->ill_lock); 10727c478bd9Sstevel@tonic-gate igmpv3_sendrpt(ilm->ilm_ipif, rp); 10737c478bd9Sstevel@tonic-gate } 10747c478bd9Sstevel@tonic-gate 10757c478bd9Sstevel@tonic-gate void 10767c478bd9Sstevel@tonic-gate mld_statechange(ilm_t *ilm, mcast_record_t fmode, slist_t *flist) 10777c478bd9Sstevel@tonic-gate { 10787c478bd9Sstevel@tonic-gate ill_t *ill; 10797c478bd9Sstevel@tonic-gate mrec_t *rp = NULL; 10807c478bd9Sstevel@tonic-gate 10817c478bd9Sstevel@tonic-gate ASSERT(ilm != NULL); 10827c478bd9Sstevel@tonic-gate 10837c478bd9Sstevel@tonic-gate ill = ilm->ilm_ill; 10847c478bd9Sstevel@tonic-gate 10857c478bd9Sstevel@tonic-gate /* only need to send if we have an mldv2-capable router */ 10867c478bd9Sstevel@tonic-gate mutex_enter(&ill->ill_lock); 10877c478bd9Sstevel@tonic-gate if (ill->ill_mcast_type != MLD_V2_ROUTER) { 10887c478bd9Sstevel@tonic-gate mutex_exit(&ill->ill_lock); 10897c478bd9Sstevel@tonic-gate return; 10907c478bd9Sstevel@tonic-gate } 10917c478bd9Sstevel@tonic-gate 10927c478bd9Sstevel@tonic-gate /* 10937c478bd9Sstevel@tonic-gate * Compare existing (old) state with the new state passed in 10947c478bd9Sstevel@tonic-gate * and send appropriate MLDv2 State Change Report. 10957c478bd9Sstevel@tonic-gate * 10967c478bd9Sstevel@tonic-gate * Old State New State State Change Report 10977c478bd9Sstevel@tonic-gate * 10987c478bd9Sstevel@tonic-gate * INCLUDE(A) INCLUDE(B) ALLOW(B-A),BLOCK(A-B) 10997c478bd9Sstevel@tonic-gate * EXCLUDE(A) EXCLUDE(B) ALLOW(A-B),BLOCK(B-A) 11007c478bd9Sstevel@tonic-gate * INCLUDE(A) EXCLUDE(B) TO_EX(B) 11017c478bd9Sstevel@tonic-gate * EXCLUDE(A) INCLUDE(B) TO_IN(B) 11027c478bd9Sstevel@tonic-gate */ 11037c478bd9Sstevel@tonic-gate if (ilm->ilm_fmode == fmode) { 11047c478bd9Sstevel@tonic-gate slist_t *a_minus_b = NULL, *b_minus_a = NULL; 11057c478bd9Sstevel@tonic-gate slist_t *allow, *block; 11067c478bd9Sstevel@tonic-gate if (((a_minus_b = l_alloc()) == NULL) || 11077c478bd9Sstevel@tonic-gate ((b_minus_a = l_alloc()) == NULL)) { 11087c478bd9Sstevel@tonic-gate l_free(a_minus_b); 11097c478bd9Sstevel@tonic-gate if (ilm->ilm_fmode == MODE_IS_INCLUDE) 11107c478bd9Sstevel@tonic-gate goto send_to_ex; 11117c478bd9Sstevel@tonic-gate else 11127c478bd9Sstevel@tonic-gate goto send_to_in; 11137c478bd9Sstevel@tonic-gate } 11147c478bd9Sstevel@tonic-gate l_difference(ilm->ilm_filter, flist, a_minus_b); 11157c478bd9Sstevel@tonic-gate l_difference(flist, ilm->ilm_filter, b_minus_a); 11167c478bd9Sstevel@tonic-gate if (ilm->ilm_fmode == MODE_IS_INCLUDE) { 11177c478bd9Sstevel@tonic-gate allow = b_minus_a; 11187c478bd9Sstevel@tonic-gate block = a_minus_b; 11197c478bd9Sstevel@tonic-gate } else { 11207c478bd9Sstevel@tonic-gate allow = a_minus_b; 11217c478bd9Sstevel@tonic-gate block = b_minus_a; 11227c478bd9Sstevel@tonic-gate } 11237c478bd9Sstevel@tonic-gate if (!SLIST_IS_EMPTY(allow)) 11247c478bd9Sstevel@tonic-gate rp = mcast_bldmrec(ALLOW_NEW_SOURCES, &ilm->ilm_v6addr, 11257c478bd9Sstevel@tonic-gate allow, rp); 11267c478bd9Sstevel@tonic-gate if (!SLIST_IS_EMPTY(block)) 11277c478bd9Sstevel@tonic-gate rp = mcast_bldmrec(BLOCK_OLD_SOURCES, &ilm->ilm_v6addr, 11287c478bd9Sstevel@tonic-gate block, rp); 11297c478bd9Sstevel@tonic-gate l_free(a_minus_b); 11307c478bd9Sstevel@tonic-gate l_free(b_minus_a); 11317c478bd9Sstevel@tonic-gate } else if (ilm->ilm_fmode == MODE_IS_INCLUDE) { 11327c478bd9Sstevel@tonic-gate send_to_ex: 11337c478bd9Sstevel@tonic-gate rp = mcast_bldmrec(CHANGE_TO_EXCLUDE, &ilm->ilm_v6addr, flist, 11347c478bd9Sstevel@tonic-gate NULL); 11357c478bd9Sstevel@tonic-gate } else { 11367c478bd9Sstevel@tonic-gate send_to_in: 11377c478bd9Sstevel@tonic-gate rp = mcast_bldmrec(CHANGE_TO_INCLUDE, &ilm->ilm_v6addr, flist, 11387c478bd9Sstevel@tonic-gate NULL); 11397c478bd9Sstevel@tonic-gate } 11407c478bd9Sstevel@tonic-gate 11417c478bd9Sstevel@tonic-gate /* 11427c478bd9Sstevel@tonic-gate * Need to set up retransmission state; merge the new info with the 11437c478bd9Sstevel@tonic-gate * current state (which may be null). If the timer is not currently 11447c478bd9Sstevel@tonic-gate * running, start it (need to do a deferred start of the timer as 11457c478bd9Sstevel@tonic-gate * we're currently in the sq). 11467c478bd9Sstevel@tonic-gate */ 11477c478bd9Sstevel@tonic-gate rp = mcast_merge_rtx(ilm, rp, flist); 11487c478bd9Sstevel@tonic-gate ASSERT(ilm->ilm_rtx.rtx_cnt > 0); 11497c478bd9Sstevel@tonic-gate if (ilm->ilm_rtx.rtx_timer == INFINITY) { 11507c478bd9Sstevel@tonic-gate MCAST_RANDOM_DELAY(ilm->ilm_rtx.rtx_timer, 11517c478bd9Sstevel@tonic-gate SEC_TO_MSEC(ICMP6_MAX_HOST_REPORT_DELAY)); 11527c478bd9Sstevel@tonic-gate mutex_enter(&mld_timer_lock); 11537c478bd9Sstevel@tonic-gate mld_deferred_next = 11547c478bd9Sstevel@tonic-gate MIN(mld_deferred_next, ilm->ilm_rtx.rtx_timer); 11557c478bd9Sstevel@tonic-gate mutex_exit(&mld_timer_lock); 11567c478bd9Sstevel@tonic-gate } 11577c478bd9Sstevel@tonic-gate 11587c478bd9Sstevel@tonic-gate mutex_exit(&ill->ill_lock); 11597c478bd9Sstevel@tonic-gate mldv2_sendrpt(ill, rp); 11607c478bd9Sstevel@tonic-gate } 11617c478bd9Sstevel@tonic-gate 11627c478bd9Sstevel@tonic-gate uint_t 11637c478bd9Sstevel@tonic-gate igmp_timeout_handler_per_ill(ill_t *ill, int elapsed) 11647c478bd9Sstevel@tonic-gate { 11657c478bd9Sstevel@tonic-gate uint_t next = INFINITY; 11667c478bd9Sstevel@tonic-gate ilm_t *ilm; 11677c478bd9Sstevel@tonic-gate ipif_t *ipif; 11687c478bd9Sstevel@tonic-gate mrec_t *rp = NULL; 11697c478bd9Sstevel@tonic-gate mrec_t *rtxrp = NULL; 11707c478bd9Sstevel@tonic-gate rtx_state_t *rtxp; 11717c478bd9Sstevel@tonic-gate mcast_record_t rtype; 11727c478bd9Sstevel@tonic-gate 11737c478bd9Sstevel@tonic-gate ASSERT(IAM_WRITER_ILL(ill)); 11747c478bd9Sstevel@tonic-gate 11757c478bd9Sstevel@tonic-gate mutex_enter(&ill->ill_lock); 11767c478bd9Sstevel@tonic-gate 11777c478bd9Sstevel@tonic-gate /* First check the global timer on this interface */ 11787c478bd9Sstevel@tonic-gate if (ill->ill_global_timer == INFINITY) 11797c478bd9Sstevel@tonic-gate goto per_ilm_timer; 11807c478bd9Sstevel@tonic-gate if (ill->ill_global_timer <= elapsed) { 11817c478bd9Sstevel@tonic-gate ill->ill_global_timer = INFINITY; 11827c478bd9Sstevel@tonic-gate /* 11837c478bd9Sstevel@tonic-gate * Send report for each group on this interface. 11847c478bd9Sstevel@tonic-gate * Since we just set the global timer (received a v3 general 11857c478bd9Sstevel@tonic-gate * query), need to skip the all hosts addr (224.0.0.1), per 11867c478bd9Sstevel@tonic-gate * RFC 3376 section 5. 11877c478bd9Sstevel@tonic-gate */ 11887c478bd9Sstevel@tonic-gate for (ilm = ill->ill_ilm; ilm != NULL; ilm = ilm->ilm_next) { 11897c478bd9Sstevel@tonic-gate if (ilm->ilm_addr == htonl(INADDR_ALLHOSTS_GROUP)) 11907c478bd9Sstevel@tonic-gate continue; 11917c478bd9Sstevel@tonic-gate ASSERT(ilm->ilm_ipif != NULL); 11927c478bd9Sstevel@tonic-gate ilm->ilm_ipif->ipif_igmp_rpt = 11937c478bd9Sstevel@tonic-gate mcast_bldmrec(ilm->ilm_fmode, &ilm->ilm_v6addr, 11947c478bd9Sstevel@tonic-gate ilm->ilm_filter, ilm->ilm_ipif->ipif_igmp_rpt); 11957c478bd9Sstevel@tonic-gate /* 11967c478bd9Sstevel@tonic-gate * Since we're sending a report on this group, okay 11977c478bd9Sstevel@tonic-gate * to delete pending group-specific timers. Note 11987c478bd9Sstevel@tonic-gate * that group-specific retransmit timers still need 11997c478bd9Sstevel@tonic-gate * to be checked in the per_ilm_timer for-loop. 12007c478bd9Sstevel@tonic-gate */ 12017c478bd9Sstevel@tonic-gate ilm->ilm_timer = INFINITY; 12027c478bd9Sstevel@tonic-gate ilm->ilm_state = IGMP_IREPORTEDLAST; 12037c478bd9Sstevel@tonic-gate FREE_SLIST(ilm->ilm_pendsrcs); 12047c478bd9Sstevel@tonic-gate ilm->ilm_pendsrcs = NULL; 12057c478bd9Sstevel@tonic-gate } 12067c478bd9Sstevel@tonic-gate /* 12077c478bd9Sstevel@tonic-gate * We've built per-ipif mrec lists; walk the ill's ipif list 12087c478bd9Sstevel@tonic-gate * and send a report for each ipif that has an mrec list. 12097c478bd9Sstevel@tonic-gate */ 12107c478bd9Sstevel@tonic-gate for (ipif = ill->ill_ipif; ipif != NULL; 12117c478bd9Sstevel@tonic-gate ipif = ipif->ipif_next) { 12127c478bd9Sstevel@tonic-gate if (ipif->ipif_igmp_rpt == NULL) 12137c478bd9Sstevel@tonic-gate continue; 12147c478bd9Sstevel@tonic-gate mutex_exit(&ill->ill_lock); 12157c478bd9Sstevel@tonic-gate igmpv3_sendrpt(ipif, ipif->ipif_igmp_rpt); 12167c478bd9Sstevel@tonic-gate mutex_enter(&ill->ill_lock); 12177c478bd9Sstevel@tonic-gate /* mrec list was freed by igmpv3_sendrpt() */ 12187c478bd9Sstevel@tonic-gate ipif->ipif_igmp_rpt = NULL; 12197c478bd9Sstevel@tonic-gate } 12207c478bd9Sstevel@tonic-gate } else { 12217c478bd9Sstevel@tonic-gate ill->ill_global_timer -= elapsed; 12227c478bd9Sstevel@tonic-gate if (ill->ill_global_timer < next) 12237c478bd9Sstevel@tonic-gate next = ill->ill_global_timer; 12247c478bd9Sstevel@tonic-gate } 12257c478bd9Sstevel@tonic-gate 12267c478bd9Sstevel@tonic-gate per_ilm_timer: 12277c478bd9Sstevel@tonic-gate for (ilm = ill->ill_ilm; ilm != NULL; ilm = ilm->ilm_next) { 12287c478bd9Sstevel@tonic-gate if (ilm->ilm_timer == INFINITY) 12297c478bd9Sstevel@tonic-gate goto per_ilm_rtxtimer; 12307c478bd9Sstevel@tonic-gate 12317c478bd9Sstevel@tonic-gate if (ilm->ilm_timer > elapsed) { 12327c478bd9Sstevel@tonic-gate ilm->ilm_timer -= elapsed; 12337c478bd9Sstevel@tonic-gate if (ilm->ilm_timer < next) 12347c478bd9Sstevel@tonic-gate next = ilm->ilm_timer; 12357c478bd9Sstevel@tonic-gate 12367c478bd9Sstevel@tonic-gate if (ip_debug > 1) { 12377c478bd9Sstevel@tonic-gate (void) mi_strlog(ill->ill_rq, 1, SL_TRACE, 12387c478bd9Sstevel@tonic-gate "igmp_timo_hlr 2: ilm_timr %d elap %d " 12397c478bd9Sstevel@tonic-gate "typ %d nxt %d", 12407c478bd9Sstevel@tonic-gate (int)ntohl(ilm->ilm_timer), elapsed, 12417c478bd9Sstevel@tonic-gate (ill->ill_mcast_type), next); 12427c478bd9Sstevel@tonic-gate } 12437c478bd9Sstevel@tonic-gate 12447c478bd9Sstevel@tonic-gate goto per_ilm_rtxtimer; 12457c478bd9Sstevel@tonic-gate } 12467c478bd9Sstevel@tonic-gate 12477c478bd9Sstevel@tonic-gate /* the timer has expired, need to take action */ 12487c478bd9Sstevel@tonic-gate ilm->ilm_timer = INFINITY; 12497c478bd9Sstevel@tonic-gate ilm->ilm_state = IGMP_IREPORTEDLAST; 12507c478bd9Sstevel@tonic-gate if (ill->ill_mcast_type == IGMP_V1_ROUTER) { 12517c478bd9Sstevel@tonic-gate mutex_exit(&ill->ill_lock); 12527c478bd9Sstevel@tonic-gate igmp_sendpkt(ilm, IGMP_V1_MEMBERSHIP_REPORT, 0); 12537c478bd9Sstevel@tonic-gate mutex_enter(&ill->ill_lock); 12547c478bd9Sstevel@tonic-gate } else if (ill->ill_mcast_type == IGMP_V2_ROUTER) { 12557c478bd9Sstevel@tonic-gate mutex_exit(&ill->ill_lock); 12567c478bd9Sstevel@tonic-gate igmp_sendpkt(ilm, IGMP_V2_MEMBERSHIP_REPORT, 0); 12577c478bd9Sstevel@tonic-gate mutex_enter(&ill->ill_lock); 12587c478bd9Sstevel@tonic-gate } else { 12597c478bd9Sstevel@tonic-gate slist_t *rsp; 12607c478bd9Sstevel@tonic-gate if (!SLIST_IS_EMPTY(ilm->ilm_pendsrcs) && 12617c478bd9Sstevel@tonic-gate (rsp = l_alloc()) != NULL) { 12627c478bd9Sstevel@tonic-gate /* 12637c478bd9Sstevel@tonic-gate * Contents of reply depend on pending 12647c478bd9Sstevel@tonic-gate * requested source list. 12657c478bd9Sstevel@tonic-gate */ 12667c478bd9Sstevel@tonic-gate if (ilm->ilm_fmode == MODE_IS_INCLUDE) { 12677c478bd9Sstevel@tonic-gate l_intersection(ilm->ilm_filter, 12687c478bd9Sstevel@tonic-gate ilm->ilm_pendsrcs, rsp); 12697c478bd9Sstevel@tonic-gate } else { 12707c478bd9Sstevel@tonic-gate l_difference(ilm->ilm_pendsrcs, 12717c478bd9Sstevel@tonic-gate ilm->ilm_filter, rsp); 12727c478bd9Sstevel@tonic-gate } 12737c478bd9Sstevel@tonic-gate FREE_SLIST(ilm->ilm_pendsrcs); 12747c478bd9Sstevel@tonic-gate ilm->ilm_pendsrcs = NULL; 12757c478bd9Sstevel@tonic-gate if (!SLIST_IS_EMPTY(rsp)) 12767c478bd9Sstevel@tonic-gate rp = mcast_bldmrec(MODE_IS_INCLUDE, 12777c478bd9Sstevel@tonic-gate &ilm->ilm_v6addr, rsp, rp); 12787c478bd9Sstevel@tonic-gate FREE_SLIST(rsp); 12797c478bd9Sstevel@tonic-gate } else { 12807c478bd9Sstevel@tonic-gate /* 12817c478bd9Sstevel@tonic-gate * Either the pending request is just group- 12827c478bd9Sstevel@tonic-gate * specific, or we couldn't get the resources 12837c478bd9Sstevel@tonic-gate * (rsp) to build a source-specific reply. 12847c478bd9Sstevel@tonic-gate */ 12857c478bd9Sstevel@tonic-gate rp = mcast_bldmrec(ilm->ilm_fmode, 12867c478bd9Sstevel@tonic-gate &ilm->ilm_v6addr, ilm->ilm_filter, rp); 12877c478bd9Sstevel@tonic-gate } 12887c478bd9Sstevel@tonic-gate mutex_exit(&ill->ill_lock); 12897c478bd9Sstevel@tonic-gate igmpv3_sendrpt(ill->ill_ipif, rp); 12907c478bd9Sstevel@tonic-gate mutex_enter(&ill->ill_lock); 12917c478bd9Sstevel@tonic-gate rp = NULL; 12927c478bd9Sstevel@tonic-gate } 12937c478bd9Sstevel@tonic-gate 12947c478bd9Sstevel@tonic-gate if (ip_debug > 1) { 12957c478bd9Sstevel@tonic-gate (void) mi_strlog(ill->ill_rq, 1, SL_TRACE, 12967c478bd9Sstevel@tonic-gate "igmp_timo_hlr 1: ilm_timr %d elap %d " 12977c478bd9Sstevel@tonic-gate "typ %d nxt %d", 12987c478bd9Sstevel@tonic-gate (int)ntohl(ilm->ilm_timer), elapsed, 12997c478bd9Sstevel@tonic-gate (ill->ill_mcast_type), next); 13007c478bd9Sstevel@tonic-gate } 13017c478bd9Sstevel@tonic-gate 13027c478bd9Sstevel@tonic-gate per_ilm_rtxtimer: 13037c478bd9Sstevel@tonic-gate rtxp = &ilm->ilm_rtx; 13047c478bd9Sstevel@tonic-gate 13057c478bd9Sstevel@tonic-gate if (rtxp->rtx_timer == INFINITY) 13067c478bd9Sstevel@tonic-gate continue; 13077c478bd9Sstevel@tonic-gate if (rtxp->rtx_timer > elapsed) { 13087c478bd9Sstevel@tonic-gate rtxp->rtx_timer -= elapsed; 13097c478bd9Sstevel@tonic-gate if (rtxp->rtx_timer < next) 13107c478bd9Sstevel@tonic-gate next = rtxp->rtx_timer; 13117c478bd9Sstevel@tonic-gate continue; 13127c478bd9Sstevel@tonic-gate } 13137c478bd9Sstevel@tonic-gate 13147c478bd9Sstevel@tonic-gate rtxp->rtx_timer = INFINITY; 13157c478bd9Sstevel@tonic-gate ilm->ilm_state = IGMP_IREPORTEDLAST; 13167c478bd9Sstevel@tonic-gate if (ill->ill_mcast_type == IGMP_V1_ROUTER) { 13177c478bd9Sstevel@tonic-gate mutex_exit(&ill->ill_lock); 13187c478bd9Sstevel@tonic-gate igmp_sendpkt(ilm, IGMP_V1_MEMBERSHIP_REPORT, 0); 13197c478bd9Sstevel@tonic-gate mutex_enter(&ill->ill_lock); 13207c478bd9Sstevel@tonic-gate continue; 13217c478bd9Sstevel@tonic-gate } else if (ill->ill_mcast_type == IGMP_V2_ROUTER) { 13227c478bd9Sstevel@tonic-gate mutex_exit(&ill->ill_lock); 13237c478bd9Sstevel@tonic-gate igmp_sendpkt(ilm, IGMP_V2_MEMBERSHIP_REPORT, 0); 13247c478bd9Sstevel@tonic-gate mutex_enter(&ill->ill_lock); 13257c478bd9Sstevel@tonic-gate continue; 13267c478bd9Sstevel@tonic-gate } 13277c478bd9Sstevel@tonic-gate 13287c478bd9Sstevel@tonic-gate /* 13297c478bd9Sstevel@tonic-gate * The retransmit timer has popped, and our router is 13307c478bd9Sstevel@tonic-gate * IGMPv3. We have to delve into the retransmit state 13317c478bd9Sstevel@tonic-gate * stored in the ilm. 13327c478bd9Sstevel@tonic-gate * 13337c478bd9Sstevel@tonic-gate * Decrement the retransmit count. If the fmode rtx 13347c478bd9Sstevel@tonic-gate * count is active, decrement it, and send a filter 13357c478bd9Sstevel@tonic-gate * mode change report with the ilm's source list. 13367c478bd9Sstevel@tonic-gate * Otherwise, send a source list change report with 13377c478bd9Sstevel@tonic-gate * the current retransmit lists. 13387c478bd9Sstevel@tonic-gate */ 13397c478bd9Sstevel@tonic-gate ASSERT(rtxp->rtx_cnt > 0); 13407c478bd9Sstevel@tonic-gate ASSERT(rtxp->rtx_cnt >= rtxp->rtx_fmode_cnt); 13417c478bd9Sstevel@tonic-gate rtxp->rtx_cnt--; 13427c478bd9Sstevel@tonic-gate if (rtxp->rtx_fmode_cnt > 0) { 13437c478bd9Sstevel@tonic-gate rtxp->rtx_fmode_cnt--; 13447c478bd9Sstevel@tonic-gate rtype = (ilm->ilm_fmode == MODE_IS_INCLUDE) ? 13457c478bd9Sstevel@tonic-gate CHANGE_TO_INCLUDE : CHANGE_TO_EXCLUDE; 13467c478bd9Sstevel@tonic-gate rtxrp = mcast_bldmrec(rtype, &ilm->ilm_v6addr, 13477c478bd9Sstevel@tonic-gate ilm->ilm_filter, rtxrp); 13487c478bd9Sstevel@tonic-gate } else { 13497c478bd9Sstevel@tonic-gate rtxrp = mcast_bldmrec(ALLOW_NEW_SOURCES, 13507c478bd9Sstevel@tonic-gate &ilm->ilm_v6addr, rtxp->rtx_allow, rtxrp); 13517c478bd9Sstevel@tonic-gate rtxrp = mcast_bldmrec(BLOCK_OLD_SOURCES, 13527c478bd9Sstevel@tonic-gate &ilm->ilm_v6addr, rtxp->rtx_block, rtxrp); 13537c478bd9Sstevel@tonic-gate } 13547c478bd9Sstevel@tonic-gate if (rtxp->rtx_cnt > 0) { 13557c478bd9Sstevel@tonic-gate MCAST_RANDOM_DELAY(rtxp->rtx_timer, 13567c478bd9Sstevel@tonic-gate SEC_TO_MSEC(IGMP_MAX_HOST_REPORT_DELAY)); 13577c478bd9Sstevel@tonic-gate if (rtxp->rtx_timer < next) 13587c478bd9Sstevel@tonic-gate next = rtxp->rtx_timer; 13597c478bd9Sstevel@tonic-gate } else { 13607c478bd9Sstevel@tonic-gate CLEAR_SLIST(rtxp->rtx_allow); 13617c478bd9Sstevel@tonic-gate CLEAR_SLIST(rtxp->rtx_block); 13627c478bd9Sstevel@tonic-gate } 13637c478bd9Sstevel@tonic-gate mutex_exit(&ill->ill_lock); 13647c478bd9Sstevel@tonic-gate igmpv3_sendrpt(ilm->ilm_ipif, rtxrp); 13657c478bd9Sstevel@tonic-gate mutex_enter(&ill->ill_lock); 13667c478bd9Sstevel@tonic-gate rtxrp = NULL; 13677c478bd9Sstevel@tonic-gate } 13687c478bd9Sstevel@tonic-gate 13697c478bd9Sstevel@tonic-gate mutex_exit(&ill->ill_lock); 13707c478bd9Sstevel@tonic-gate 13717c478bd9Sstevel@tonic-gate return (next); 13727c478bd9Sstevel@tonic-gate } 13737c478bd9Sstevel@tonic-gate 13747c478bd9Sstevel@tonic-gate /* 13757c478bd9Sstevel@tonic-gate * igmp_timeout_handler: 13767c478bd9Sstevel@tonic-gate * Called when there are timeout events, every next * TMEOUT_INTERVAL (tick). 13777c478bd9Sstevel@tonic-gate * Returns number of ticks to next event (or 0 if none). 13787c478bd9Sstevel@tonic-gate * 13797c478bd9Sstevel@tonic-gate * As part of multicast join and leave igmp we may need to send out an 13807c478bd9Sstevel@tonic-gate * igmp request. The igmp related state variables in the ilm are protected 13817c478bd9Sstevel@tonic-gate * by ill_lock. A single global igmp timer is used to track igmp timeouts. 13827c478bd9Sstevel@tonic-gate * igmp_timer_lock protects the global igmp_timeout_id. igmp_start_timers 13837c478bd9Sstevel@tonic-gate * starts the igmp timer if needed. It serializes multiple threads trying to 13847c478bd9Sstevel@tonic-gate * simultaneously start the timer using the igmp_timer_setter_active flag. 13857c478bd9Sstevel@tonic-gate * 13867c478bd9Sstevel@tonic-gate * igmp_input() receives igmp queries and responds to the queries 13877c478bd9Sstevel@tonic-gate * in a delayed fashion by posting a timer i.e. it calls igmp_start_timers(). 13887c478bd9Sstevel@tonic-gate * Later the igmp_timer fires, the timeout handler igmp_timerout_handler() 13897c478bd9Sstevel@tonic-gate * performs the action exclusively after entering each ill's ipsq as writer. 13907c478bd9Sstevel@tonic-gate * The actual igmp timeout handler needs to run in the ipsq since it has to 13917c478bd9Sstevel@tonic-gate * access the ilm's and we don't want another exclusive operation like 13927c478bd9Sstevel@tonic-gate * say an IPMP failover to be simultaneously moving the ilms from one ill to 13937c478bd9Sstevel@tonic-gate * another. 13947c478bd9Sstevel@tonic-gate * 13957c478bd9Sstevel@tonic-gate * The igmp_slowtimeo() function is called thru another timer. 13967c478bd9Sstevel@tonic-gate * igmp_slowtimeout_lock protects the igmp_slowtimeout_id 13977c478bd9Sstevel@tonic-gate */ 13987c478bd9Sstevel@tonic-gate 13997c478bd9Sstevel@tonic-gate /* ARGSUSED */ 14007c478bd9Sstevel@tonic-gate void 14017c478bd9Sstevel@tonic-gate igmp_timeout_handler(void *arg) 14027c478bd9Sstevel@tonic-gate { 14037c478bd9Sstevel@tonic-gate ill_t *ill; 14047c478bd9Sstevel@tonic-gate int elapsed; /* Since last call */ 14057c478bd9Sstevel@tonic-gate uint_t global_next = INFINITY; 14067c478bd9Sstevel@tonic-gate uint_t next; 14077c478bd9Sstevel@tonic-gate ill_walk_context_t ctx; 14087c478bd9Sstevel@tonic-gate boolean_t success; 14097c478bd9Sstevel@tonic-gate 14107c478bd9Sstevel@tonic-gate mutex_enter(&igmp_timer_lock); 14117c478bd9Sstevel@tonic-gate ASSERT(igmp_timeout_id != 0); 14127c478bd9Sstevel@tonic-gate igmp_timer_fired_last = ddi_get_lbolt(); 14137c478bd9Sstevel@tonic-gate elapsed = igmp_time_to_next; 14147c478bd9Sstevel@tonic-gate igmp_time_to_next = 0; 14157c478bd9Sstevel@tonic-gate mutex_exit(&igmp_timer_lock); 14167c478bd9Sstevel@tonic-gate 14177c478bd9Sstevel@tonic-gate rw_enter(&ill_g_lock, RW_READER); 14187c478bd9Sstevel@tonic-gate ill = ILL_START_WALK_V4(&ctx); 14197c478bd9Sstevel@tonic-gate for (; ill != NULL; ill = ill_next(&ctx, ill)) { 14207c478bd9Sstevel@tonic-gate ASSERT(!ill->ill_isv6); 14217c478bd9Sstevel@tonic-gate /* 14227c478bd9Sstevel@tonic-gate * We may not be able to refhold the ill if the ill/ipif 14237c478bd9Sstevel@tonic-gate * is changing. But we need to make sure that the ill will 14247c478bd9Sstevel@tonic-gate * not vanish. So we just bump up the ill_waiter count. 14257c478bd9Sstevel@tonic-gate */ 14267c478bd9Sstevel@tonic-gate if (!ill_waiter_inc(ill)) 14277c478bd9Sstevel@tonic-gate continue; 14287c478bd9Sstevel@tonic-gate rw_exit(&ill_g_lock); 14297c478bd9Sstevel@tonic-gate success = ipsq_enter(ill, B_TRUE); 14307c478bd9Sstevel@tonic-gate if (success) { 14317c478bd9Sstevel@tonic-gate next = igmp_timeout_handler_per_ill(ill, elapsed); 14327c478bd9Sstevel@tonic-gate if (next < global_next) 14337c478bd9Sstevel@tonic-gate global_next = next; 14347c478bd9Sstevel@tonic-gate ipsq_exit(ill->ill_phyint->phyint_ipsq, B_FALSE, 14357c478bd9Sstevel@tonic-gate B_TRUE); 14367c478bd9Sstevel@tonic-gate } 14377c478bd9Sstevel@tonic-gate rw_enter(&ill_g_lock, RW_READER); 14387c478bd9Sstevel@tonic-gate ill_waiter_dcr(ill); 14397c478bd9Sstevel@tonic-gate } 14407c478bd9Sstevel@tonic-gate rw_exit(&ill_g_lock); 14417c478bd9Sstevel@tonic-gate 14427c478bd9Sstevel@tonic-gate mutex_enter(&igmp_timer_lock); 14437c478bd9Sstevel@tonic-gate ASSERT(igmp_timeout_id != 0); 14447c478bd9Sstevel@tonic-gate igmp_timeout_id = 0; 14457c478bd9Sstevel@tonic-gate mutex_exit(&igmp_timer_lock); 14467c478bd9Sstevel@tonic-gate 14477c478bd9Sstevel@tonic-gate if (global_next != INFINITY) 14487c478bd9Sstevel@tonic-gate igmp_start_timers(global_next); 14497c478bd9Sstevel@tonic-gate } 14507c478bd9Sstevel@tonic-gate 14517c478bd9Sstevel@tonic-gate /* 14527c478bd9Sstevel@tonic-gate * mld_timeout_handler: 14537c478bd9Sstevel@tonic-gate * Called when there are timeout events, every next (tick). 14547c478bd9Sstevel@tonic-gate * Returns number of ticks to next event (or 0 if none). 14557c478bd9Sstevel@tonic-gate */ 14567c478bd9Sstevel@tonic-gate /* ARGSUSED */ 14577c478bd9Sstevel@tonic-gate uint_t 14587c478bd9Sstevel@tonic-gate mld_timeout_handler_per_ill(ill_t *ill, int elapsed) 14597c478bd9Sstevel@tonic-gate { 14607c478bd9Sstevel@tonic-gate ilm_t *ilm; 14617c478bd9Sstevel@tonic-gate uint_t next = INFINITY; 14627c478bd9Sstevel@tonic-gate mrec_t *rp, *rtxrp; 14637c478bd9Sstevel@tonic-gate rtx_state_t *rtxp; 14647c478bd9Sstevel@tonic-gate mcast_record_t rtype; 14657c478bd9Sstevel@tonic-gate 14667c478bd9Sstevel@tonic-gate ASSERT(IAM_WRITER_ILL(ill)); 14677c478bd9Sstevel@tonic-gate 14687c478bd9Sstevel@tonic-gate mutex_enter(&ill->ill_lock); 14697c478bd9Sstevel@tonic-gate 14707c478bd9Sstevel@tonic-gate /* 14717c478bd9Sstevel@tonic-gate * First check the global timer on this interface; the global timer 14727c478bd9Sstevel@tonic-gate * is not used for MLDv1, so if it's set we can assume we're v2. 14737c478bd9Sstevel@tonic-gate */ 14747c478bd9Sstevel@tonic-gate if (ill->ill_global_timer == INFINITY) 14757c478bd9Sstevel@tonic-gate goto per_ilm_timer; 14767c478bd9Sstevel@tonic-gate if (ill->ill_global_timer <= elapsed) { 14777c478bd9Sstevel@tonic-gate ill->ill_global_timer = INFINITY; 14787c478bd9Sstevel@tonic-gate /* 14797c478bd9Sstevel@tonic-gate * Send report for each group on this interface. 14807c478bd9Sstevel@tonic-gate * Since we just set the global timer (received a v2 general 14817c478bd9Sstevel@tonic-gate * query), need to skip the all hosts addr (ff02::1), per 14827c478bd9Sstevel@tonic-gate * RFC 3810 section 6. 14837c478bd9Sstevel@tonic-gate */ 14847c478bd9Sstevel@tonic-gate rp = NULL; 14857c478bd9Sstevel@tonic-gate for (ilm = ill->ill_ilm; ilm != NULL; ilm = ilm->ilm_next) { 14867c478bd9Sstevel@tonic-gate if (IN6_ARE_ADDR_EQUAL(&ilm->ilm_v6addr, 14877c478bd9Sstevel@tonic-gate &ipv6_all_hosts_mcast)) 14887c478bd9Sstevel@tonic-gate continue; 14897c478bd9Sstevel@tonic-gate rp = mcast_bldmrec(ilm->ilm_fmode, &ilm->ilm_v6addr, 14907c478bd9Sstevel@tonic-gate ilm->ilm_filter, rp); 14917c478bd9Sstevel@tonic-gate /* 14927c478bd9Sstevel@tonic-gate * Since we're sending a report on this group, okay 14937c478bd9Sstevel@tonic-gate * to delete pending group-specific timers. Note 14947c478bd9Sstevel@tonic-gate * that group-specific retransmit timers still need 14957c478bd9Sstevel@tonic-gate * to be checked in the per_ilm_timer for-loop. 14967c478bd9Sstevel@tonic-gate */ 14977c478bd9Sstevel@tonic-gate ilm->ilm_timer = INFINITY; 14987c478bd9Sstevel@tonic-gate ilm->ilm_state = IGMP_IREPORTEDLAST; 14997c478bd9Sstevel@tonic-gate FREE_SLIST(ilm->ilm_pendsrcs); 15007c478bd9Sstevel@tonic-gate ilm->ilm_pendsrcs = NULL; 15017c478bd9Sstevel@tonic-gate } 15027c478bd9Sstevel@tonic-gate mutex_exit(&ill->ill_lock); 15037c478bd9Sstevel@tonic-gate mldv2_sendrpt(ill, rp); 15047c478bd9Sstevel@tonic-gate mutex_enter(&ill->ill_lock); 15057c478bd9Sstevel@tonic-gate } else { 15067c478bd9Sstevel@tonic-gate ill->ill_global_timer -= elapsed; 15077c478bd9Sstevel@tonic-gate if (ill->ill_global_timer < next) 15087c478bd9Sstevel@tonic-gate next = ill->ill_global_timer; 15097c478bd9Sstevel@tonic-gate } 15107c478bd9Sstevel@tonic-gate 15117c478bd9Sstevel@tonic-gate per_ilm_timer: 15127c478bd9Sstevel@tonic-gate rp = rtxrp = NULL; 15137c478bd9Sstevel@tonic-gate for (ilm = ill->ill_ilm; ilm != NULL; ilm = ilm->ilm_next) { 15147c478bd9Sstevel@tonic-gate if (ilm->ilm_timer == INFINITY) 15157c478bd9Sstevel@tonic-gate goto per_ilm_rtxtimer; 15167c478bd9Sstevel@tonic-gate 15177c478bd9Sstevel@tonic-gate if (ilm->ilm_timer > elapsed) { 15187c478bd9Sstevel@tonic-gate ilm->ilm_timer -= elapsed; 15197c478bd9Sstevel@tonic-gate if (ilm->ilm_timer < next) 15207c478bd9Sstevel@tonic-gate next = ilm->ilm_timer; 15217c478bd9Sstevel@tonic-gate 15227c478bd9Sstevel@tonic-gate if (ip_debug > 1) { 15237c478bd9Sstevel@tonic-gate (void) mi_strlog(ill->ill_rq, 1, SL_TRACE, 15247c478bd9Sstevel@tonic-gate "igmp_timo_hlr 2: ilm_timr" 15257c478bd9Sstevel@tonic-gate " %d elap %d typ %d nxt %d", 15267c478bd9Sstevel@tonic-gate (int)ntohl(ilm->ilm_timer), elapsed, 15277c478bd9Sstevel@tonic-gate (ill->ill_mcast_type), next); 15287c478bd9Sstevel@tonic-gate } 15297c478bd9Sstevel@tonic-gate 15307c478bd9Sstevel@tonic-gate goto per_ilm_rtxtimer; 15317c478bd9Sstevel@tonic-gate } 15327c478bd9Sstevel@tonic-gate 15337c478bd9Sstevel@tonic-gate /* the timer has expired, need to take action */ 15347c478bd9Sstevel@tonic-gate ilm->ilm_timer = INFINITY; 15357c478bd9Sstevel@tonic-gate ilm->ilm_state = IGMP_IREPORTEDLAST; 15367c478bd9Sstevel@tonic-gate if (ill->ill_mcast_type == MLD_V1_ROUTER) { 15377c478bd9Sstevel@tonic-gate mutex_exit(&ill->ill_lock); 15387c478bd9Sstevel@tonic-gate mld_sendpkt(ilm, MLD_LISTENER_REPORT, NULL); 15397c478bd9Sstevel@tonic-gate mutex_enter(&ill->ill_lock); 15407c478bd9Sstevel@tonic-gate } else { 15417c478bd9Sstevel@tonic-gate slist_t *rsp; 15427c478bd9Sstevel@tonic-gate if (!SLIST_IS_EMPTY(ilm->ilm_pendsrcs) && 15437c478bd9Sstevel@tonic-gate (rsp = l_alloc()) != NULL) { 15447c478bd9Sstevel@tonic-gate /* 15457c478bd9Sstevel@tonic-gate * Contents of reply depend on pending 15467c478bd9Sstevel@tonic-gate * requested source list. 15477c478bd9Sstevel@tonic-gate */ 15487c478bd9Sstevel@tonic-gate if (ilm->ilm_fmode == MODE_IS_INCLUDE) { 15497c478bd9Sstevel@tonic-gate l_intersection(ilm->ilm_filter, 15507c478bd9Sstevel@tonic-gate ilm->ilm_pendsrcs, rsp); 15517c478bd9Sstevel@tonic-gate } else { 15527c478bd9Sstevel@tonic-gate l_difference(ilm->ilm_pendsrcs, 15537c478bd9Sstevel@tonic-gate ilm->ilm_filter, rsp); 15547c478bd9Sstevel@tonic-gate } 15557c478bd9Sstevel@tonic-gate FREE_SLIST(ilm->ilm_pendsrcs); 15567c478bd9Sstevel@tonic-gate ilm->ilm_pendsrcs = NULL; 15577c478bd9Sstevel@tonic-gate if (!SLIST_IS_EMPTY(rsp)) 15587c478bd9Sstevel@tonic-gate rp = mcast_bldmrec(MODE_IS_INCLUDE, 15597c478bd9Sstevel@tonic-gate &ilm->ilm_v6addr, rsp, rp); 15607c478bd9Sstevel@tonic-gate FREE_SLIST(rsp); 15617c478bd9Sstevel@tonic-gate } else { 15627c478bd9Sstevel@tonic-gate rp = mcast_bldmrec(ilm->ilm_fmode, 15637c478bd9Sstevel@tonic-gate &ilm->ilm_v6addr, ilm->ilm_filter, rp); 15647c478bd9Sstevel@tonic-gate } 15657c478bd9Sstevel@tonic-gate } 15667c478bd9Sstevel@tonic-gate 15677c478bd9Sstevel@tonic-gate if (ip_debug > 1) { 15687c478bd9Sstevel@tonic-gate (void) mi_strlog(ill->ill_rq, 1, SL_TRACE, 15697c478bd9Sstevel@tonic-gate "igmp_timo_hlr 1: ilm_timr %d elap %d " 15707c478bd9Sstevel@tonic-gate "typ %d nxt %d", 15717c478bd9Sstevel@tonic-gate (int)ntohl(ilm->ilm_timer), elapsed, 15727c478bd9Sstevel@tonic-gate (ill->ill_mcast_type), next); 15737c478bd9Sstevel@tonic-gate } 15747c478bd9Sstevel@tonic-gate 15757c478bd9Sstevel@tonic-gate per_ilm_rtxtimer: 15767c478bd9Sstevel@tonic-gate rtxp = &ilm->ilm_rtx; 15777c478bd9Sstevel@tonic-gate 15787c478bd9Sstevel@tonic-gate if (rtxp->rtx_timer == INFINITY) 15797c478bd9Sstevel@tonic-gate continue; 15807c478bd9Sstevel@tonic-gate if (rtxp->rtx_timer > elapsed) { 15817c478bd9Sstevel@tonic-gate rtxp->rtx_timer -= elapsed; 15827c478bd9Sstevel@tonic-gate if (rtxp->rtx_timer < next) 15837c478bd9Sstevel@tonic-gate next = rtxp->rtx_timer; 15847c478bd9Sstevel@tonic-gate continue; 15857c478bd9Sstevel@tonic-gate } 15867c478bd9Sstevel@tonic-gate 15877c478bd9Sstevel@tonic-gate rtxp->rtx_timer = INFINITY; 15887c478bd9Sstevel@tonic-gate ilm->ilm_state = IGMP_IREPORTEDLAST; 15897c478bd9Sstevel@tonic-gate if (ill->ill_mcast_type == MLD_V1_ROUTER) { 15907c478bd9Sstevel@tonic-gate mutex_exit(&ill->ill_lock); 15917c478bd9Sstevel@tonic-gate mld_sendpkt(ilm, MLD_LISTENER_REPORT, NULL); 15927c478bd9Sstevel@tonic-gate mutex_enter(&ill->ill_lock); 15937c478bd9Sstevel@tonic-gate continue; 15947c478bd9Sstevel@tonic-gate } 15957c478bd9Sstevel@tonic-gate 15967c478bd9Sstevel@tonic-gate /* 15977c478bd9Sstevel@tonic-gate * The retransmit timer has popped, and our router is 15987c478bd9Sstevel@tonic-gate * MLDv2. We have to delve into the retransmit state 15997c478bd9Sstevel@tonic-gate * stored in the ilm. 16007c478bd9Sstevel@tonic-gate * 16017c478bd9Sstevel@tonic-gate * Decrement the retransmit count. If the fmode rtx 16027c478bd9Sstevel@tonic-gate * count is active, decrement it, and send a filter 16037c478bd9Sstevel@tonic-gate * mode change report with the ilm's source list. 16047c478bd9Sstevel@tonic-gate * Otherwise, send a source list change report with 16057c478bd9Sstevel@tonic-gate * the current retransmit lists. 16067c478bd9Sstevel@tonic-gate */ 16077c478bd9Sstevel@tonic-gate ASSERT(rtxp->rtx_cnt > 0); 16087c478bd9Sstevel@tonic-gate ASSERT(rtxp->rtx_cnt >= rtxp->rtx_fmode_cnt); 16097c478bd9Sstevel@tonic-gate rtxp->rtx_cnt--; 16107c478bd9Sstevel@tonic-gate if (rtxp->rtx_fmode_cnt > 0) { 16117c478bd9Sstevel@tonic-gate rtxp->rtx_fmode_cnt--; 16127c478bd9Sstevel@tonic-gate rtype = (ilm->ilm_fmode == MODE_IS_INCLUDE) ? 16137c478bd9Sstevel@tonic-gate CHANGE_TO_INCLUDE : CHANGE_TO_EXCLUDE; 16147c478bd9Sstevel@tonic-gate rtxrp = mcast_bldmrec(rtype, &ilm->ilm_v6addr, 16157c478bd9Sstevel@tonic-gate ilm->ilm_filter, rtxrp); 16167c478bd9Sstevel@tonic-gate } else { 16177c478bd9Sstevel@tonic-gate rtxrp = mcast_bldmrec(ALLOW_NEW_SOURCES, 16187c478bd9Sstevel@tonic-gate &ilm->ilm_v6addr, rtxp->rtx_allow, rtxrp); 16197c478bd9Sstevel@tonic-gate rtxrp = mcast_bldmrec(BLOCK_OLD_SOURCES, 16207c478bd9Sstevel@tonic-gate &ilm->ilm_v6addr, rtxp->rtx_block, rtxrp); 16217c478bd9Sstevel@tonic-gate } 16227c478bd9Sstevel@tonic-gate if (rtxp->rtx_cnt > 0) { 16237c478bd9Sstevel@tonic-gate MCAST_RANDOM_DELAY(rtxp->rtx_timer, 16247c478bd9Sstevel@tonic-gate SEC_TO_MSEC(ICMP6_MAX_HOST_REPORT_DELAY)); 16257c478bd9Sstevel@tonic-gate if (rtxp->rtx_timer < next) 16267c478bd9Sstevel@tonic-gate next = rtxp->rtx_timer; 16277c478bd9Sstevel@tonic-gate } else { 16287c478bd9Sstevel@tonic-gate CLEAR_SLIST(rtxp->rtx_allow); 16297c478bd9Sstevel@tonic-gate CLEAR_SLIST(rtxp->rtx_block); 16307c478bd9Sstevel@tonic-gate } 16317c478bd9Sstevel@tonic-gate } 16327c478bd9Sstevel@tonic-gate 16337c478bd9Sstevel@tonic-gate if (ill->ill_mcast_type == MLD_V2_ROUTER) { 16347c478bd9Sstevel@tonic-gate mutex_exit(&ill->ill_lock); 16357c478bd9Sstevel@tonic-gate mldv2_sendrpt(ill, rp); 16367c478bd9Sstevel@tonic-gate mldv2_sendrpt(ill, rtxrp); 16377c478bd9Sstevel@tonic-gate return (next); 16387c478bd9Sstevel@tonic-gate } 16397c478bd9Sstevel@tonic-gate 16407c478bd9Sstevel@tonic-gate mutex_exit(&ill->ill_lock); 16417c478bd9Sstevel@tonic-gate 16427c478bd9Sstevel@tonic-gate return (next); 16437c478bd9Sstevel@tonic-gate } 16447c478bd9Sstevel@tonic-gate 16457c478bd9Sstevel@tonic-gate /* 16467c478bd9Sstevel@tonic-gate * mld_timeout_handler: 16477c478bd9Sstevel@tonic-gate * Called when there are timeout events, every next * TMEOUT_INTERVAL (tick). 16487c478bd9Sstevel@tonic-gate * Returns number of ticks to next event (or 0 if none). 16497c478bd9Sstevel@tonic-gate * MT issues are same as igmp_timeout_handler 16507c478bd9Sstevel@tonic-gate */ 16517c478bd9Sstevel@tonic-gate /* ARGSUSED */ 16527c478bd9Sstevel@tonic-gate void 16537c478bd9Sstevel@tonic-gate mld_timeout_handler(void *arg) 16547c478bd9Sstevel@tonic-gate { 16557c478bd9Sstevel@tonic-gate ill_t *ill; 16567c478bd9Sstevel@tonic-gate int elapsed; /* Since last call */ 16577c478bd9Sstevel@tonic-gate uint_t global_next = INFINITY; 16587c478bd9Sstevel@tonic-gate uint_t next; 16597c478bd9Sstevel@tonic-gate ill_walk_context_t ctx; 16607c478bd9Sstevel@tonic-gate boolean_t success; 16617c478bd9Sstevel@tonic-gate 16627c478bd9Sstevel@tonic-gate mutex_enter(&mld_timer_lock); 16637c478bd9Sstevel@tonic-gate ASSERT(mld_timeout_id != 0); 16647c478bd9Sstevel@tonic-gate mld_timer_fired_last = ddi_get_lbolt(); 16657c478bd9Sstevel@tonic-gate elapsed = mld_time_to_next; 16667c478bd9Sstevel@tonic-gate mld_time_to_next = 0; 16677c478bd9Sstevel@tonic-gate mutex_exit(&mld_timer_lock); 16687c478bd9Sstevel@tonic-gate 16697c478bd9Sstevel@tonic-gate rw_enter(&ill_g_lock, RW_READER); 16707c478bd9Sstevel@tonic-gate ill = ILL_START_WALK_V6(&ctx); 16717c478bd9Sstevel@tonic-gate for (; ill != NULL; ill = ill_next(&ctx, ill)) { 16727c478bd9Sstevel@tonic-gate ASSERT(ill->ill_isv6); 16737c478bd9Sstevel@tonic-gate /* 16747c478bd9Sstevel@tonic-gate * We may not be able to refhold the ill if the ill/ipif 16757c478bd9Sstevel@tonic-gate * is changing. But we need to make sure that the ill will 16767c478bd9Sstevel@tonic-gate * not vanish. So we just bump up the ill_waiter count. 16777c478bd9Sstevel@tonic-gate */ 16787c478bd9Sstevel@tonic-gate if (!ill_waiter_inc(ill)) 16797c478bd9Sstevel@tonic-gate continue; 16807c478bd9Sstevel@tonic-gate rw_exit(&ill_g_lock); 16817c478bd9Sstevel@tonic-gate success = ipsq_enter(ill, B_TRUE); 16827c478bd9Sstevel@tonic-gate if (success) { 16837c478bd9Sstevel@tonic-gate next = mld_timeout_handler_per_ill(ill, elapsed); 16847c478bd9Sstevel@tonic-gate if (next < global_next) 16857c478bd9Sstevel@tonic-gate global_next = next; 16867c478bd9Sstevel@tonic-gate ipsq_exit(ill->ill_phyint->phyint_ipsq, B_TRUE, 16877c478bd9Sstevel@tonic-gate B_FALSE); 16887c478bd9Sstevel@tonic-gate } 16897c478bd9Sstevel@tonic-gate rw_enter(&ill_g_lock, RW_READER); 16907c478bd9Sstevel@tonic-gate ill_waiter_dcr(ill); 16917c478bd9Sstevel@tonic-gate } 16927c478bd9Sstevel@tonic-gate rw_exit(&ill_g_lock); 16937c478bd9Sstevel@tonic-gate 16947c478bd9Sstevel@tonic-gate mutex_enter(&mld_timer_lock); 16957c478bd9Sstevel@tonic-gate ASSERT(mld_timeout_id != 0); 16967c478bd9Sstevel@tonic-gate mld_timeout_id = 0; 16977c478bd9Sstevel@tonic-gate mutex_exit(&mld_timer_lock); 16987c478bd9Sstevel@tonic-gate 16997c478bd9Sstevel@tonic-gate if (global_next != INFINITY) 17007c478bd9Sstevel@tonic-gate mld_start_timers(global_next); 17017c478bd9Sstevel@tonic-gate } 17027c478bd9Sstevel@tonic-gate 17037c478bd9Sstevel@tonic-gate /* 17047c478bd9Sstevel@tonic-gate * Calculate the Older Version Querier Present timeout value, in number 17057c478bd9Sstevel@tonic-gate * of slowtimo intervals, for the given ill. 17067c478bd9Sstevel@tonic-gate */ 17077c478bd9Sstevel@tonic-gate #define OVQP(ill) \ 17087c478bd9Sstevel@tonic-gate ((1000 * (((ill)->ill_mcast_rv * (ill)->ill_mcast_qi) \ 17097c478bd9Sstevel@tonic-gate + MCAST_QUERY_RESP_INTERVAL)) / MCAST_SLOWTIMO_INTERVAL) 17107c478bd9Sstevel@tonic-gate 17117c478bd9Sstevel@tonic-gate /* 17127c478bd9Sstevel@tonic-gate * igmp_slowtimo: 17137c478bd9Sstevel@tonic-gate * - Resets to new router if we didnt we hear from the router 17147c478bd9Sstevel@tonic-gate * in IGMP_AGE_THRESHOLD seconds. 17157c478bd9Sstevel@tonic-gate * - Resets slowtimeout. 17167c478bd9Sstevel@tonic-gate */ 17177c478bd9Sstevel@tonic-gate /* ARGSUSED */ 17187c478bd9Sstevel@tonic-gate void 17197c478bd9Sstevel@tonic-gate igmp_slowtimo(void *arg) 17207c478bd9Sstevel@tonic-gate { 17217c478bd9Sstevel@tonic-gate ill_t *ill; 17227c478bd9Sstevel@tonic-gate ill_if_t *ifp; 17237c478bd9Sstevel@tonic-gate avl_tree_t *avl_tree; 17247c478bd9Sstevel@tonic-gate 17257c478bd9Sstevel@tonic-gate /* Hold the ill_g_lock so that we can safely walk the ill list */ 17267c478bd9Sstevel@tonic-gate rw_enter(&ill_g_lock, RW_READER); 17277c478bd9Sstevel@tonic-gate 17287c478bd9Sstevel@tonic-gate /* 17297c478bd9Sstevel@tonic-gate * The ill_if_t list is circular, hence the odd loop parameters. 17307c478bd9Sstevel@tonic-gate * 17317c478bd9Sstevel@tonic-gate * We can't use the ILL_START_WALK and ill_next() wrappers for this 17327c478bd9Sstevel@tonic-gate * walk, as we need to check the illif_mcast_* fields in the ill_if_t 17337c478bd9Sstevel@tonic-gate * structure (allowing us to skip if none of the instances have timers 17347c478bd9Sstevel@tonic-gate * running). 17357c478bd9Sstevel@tonic-gate */ 17367c478bd9Sstevel@tonic-gate for (ifp = IP_V4_ILL_G_LIST; ifp != (ill_if_t *)&IP_V4_ILL_G_LIST; 17377c478bd9Sstevel@tonic-gate ifp = ifp->illif_next) { 17387c478bd9Sstevel@tonic-gate /* 17397c478bd9Sstevel@tonic-gate * illif_mcast_v[12] are set using atomics. If an ill hears 17407c478bd9Sstevel@tonic-gate * a V1 or V2 query now and we miss seeing the count now, 17417c478bd9Sstevel@tonic-gate * we will see it the next time igmp_slowtimo is called. 17427c478bd9Sstevel@tonic-gate */ 17437c478bd9Sstevel@tonic-gate if (ifp->illif_mcast_v1 == 0 && ifp->illif_mcast_v2 == 0) 17447c478bd9Sstevel@tonic-gate continue; 17457c478bd9Sstevel@tonic-gate 17467c478bd9Sstevel@tonic-gate avl_tree = &ifp->illif_avl_by_ppa; 17477c478bd9Sstevel@tonic-gate for (ill = avl_first(avl_tree); ill != NULL; 17487c478bd9Sstevel@tonic-gate ill = avl_walk(avl_tree, ill, AVL_AFTER)) { 17497c478bd9Sstevel@tonic-gate mutex_enter(&ill->ill_lock); 17507c478bd9Sstevel@tonic-gate if (ill->ill_mcast_v1_tset == 1) 17517c478bd9Sstevel@tonic-gate ill->ill_mcast_v1_time++; 17527c478bd9Sstevel@tonic-gate if (ill->ill_mcast_v2_tset == 1) 17537c478bd9Sstevel@tonic-gate ill->ill_mcast_v2_time++; 17547c478bd9Sstevel@tonic-gate if (ill->ill_mcast_type == IGMP_V1_ROUTER) { 17557c478bd9Sstevel@tonic-gate if (ill->ill_mcast_v1_time >= OVQP(ill)) { 17567c478bd9Sstevel@tonic-gate if (ill->ill_mcast_v2_tset > 0) { 17577c478bd9Sstevel@tonic-gate ip1dbg(("V1 query timer " 17587c478bd9Sstevel@tonic-gate "expired on %s; switching " 17597c478bd9Sstevel@tonic-gate "mode to IGMP_V2\n", 17607c478bd9Sstevel@tonic-gate ill->ill_name)); 17617c478bd9Sstevel@tonic-gate ill->ill_mcast_type = 17627c478bd9Sstevel@tonic-gate IGMP_V2_ROUTER; 17637c478bd9Sstevel@tonic-gate } else { 17647c478bd9Sstevel@tonic-gate ip1dbg(("V1 query timer " 17657c478bd9Sstevel@tonic-gate "expired on %s; switching " 17667c478bd9Sstevel@tonic-gate "mode to IGMP_V3\n", 17677c478bd9Sstevel@tonic-gate ill->ill_name)); 17687c478bd9Sstevel@tonic-gate ill->ill_mcast_type = 17697c478bd9Sstevel@tonic-gate IGMP_V3_ROUTER; 17707c478bd9Sstevel@tonic-gate } 17717c478bd9Sstevel@tonic-gate ill->ill_mcast_v1_time = 0; 17727c478bd9Sstevel@tonic-gate ill->ill_mcast_v1_tset = 0; 17737c478bd9Sstevel@tonic-gate atomic_add_16(&ifp->illif_mcast_v1, -1); 17747c478bd9Sstevel@tonic-gate } 17757c478bd9Sstevel@tonic-gate } 17767c478bd9Sstevel@tonic-gate if (ill->ill_mcast_type == IGMP_V2_ROUTER) { 17777c478bd9Sstevel@tonic-gate if (ill->ill_mcast_v2_time >= OVQP(ill)) { 17787c478bd9Sstevel@tonic-gate ip1dbg(("V2 query timer expired on " 17797c478bd9Sstevel@tonic-gate "%s; switching mode to IGMP_V3\n", 17807c478bd9Sstevel@tonic-gate ill->ill_name)); 17817c478bd9Sstevel@tonic-gate ill->ill_mcast_type = IGMP_V3_ROUTER; 17827c478bd9Sstevel@tonic-gate ill->ill_mcast_v2_time = 0; 17837c478bd9Sstevel@tonic-gate ill->ill_mcast_v2_tset = 0; 17847c478bd9Sstevel@tonic-gate atomic_add_16(&ifp->illif_mcast_v2, -1); 17857c478bd9Sstevel@tonic-gate } 17867c478bd9Sstevel@tonic-gate } 17877c478bd9Sstevel@tonic-gate mutex_exit(&ill->ill_lock); 17887c478bd9Sstevel@tonic-gate } 17897c478bd9Sstevel@tonic-gate 17907c478bd9Sstevel@tonic-gate } 17917c478bd9Sstevel@tonic-gate rw_exit(&ill_g_lock); 17927c478bd9Sstevel@tonic-gate mutex_enter(&igmp_slowtimeout_lock); 17937c478bd9Sstevel@tonic-gate igmp_slowtimeout_id = timeout(igmp_slowtimo, NULL, 17947c478bd9Sstevel@tonic-gate MSEC_TO_TICK(MCAST_SLOWTIMO_INTERVAL)); 17957c478bd9Sstevel@tonic-gate mutex_exit(&igmp_slowtimeout_lock); 17967c478bd9Sstevel@tonic-gate } 17977c478bd9Sstevel@tonic-gate 17987c478bd9Sstevel@tonic-gate /* 17997c478bd9Sstevel@tonic-gate * mld_slowtimo: 18007c478bd9Sstevel@tonic-gate * - Resets to newer version if we didn't hear from the older version router 18017c478bd9Sstevel@tonic-gate * in MLD_AGE_THRESHOLD seconds. 18027c478bd9Sstevel@tonic-gate * - Restarts slowtimeout. 18037c478bd9Sstevel@tonic-gate */ 18047c478bd9Sstevel@tonic-gate /* ARGSUSED */ 18057c478bd9Sstevel@tonic-gate void 18067c478bd9Sstevel@tonic-gate mld_slowtimo(void *arg) 18077c478bd9Sstevel@tonic-gate { 18087c478bd9Sstevel@tonic-gate ill_t *ill; 18097c478bd9Sstevel@tonic-gate ill_if_t *ifp; 18107c478bd9Sstevel@tonic-gate avl_tree_t *avl_tree; 18117c478bd9Sstevel@tonic-gate 18127c478bd9Sstevel@tonic-gate /* See comments in igmp_slowtimo() above... */ 18137c478bd9Sstevel@tonic-gate rw_enter(&ill_g_lock, RW_READER); 18147c478bd9Sstevel@tonic-gate for (ifp = IP_V6_ILL_G_LIST; ifp != (ill_if_t *)&IP_V6_ILL_G_LIST; 18157c478bd9Sstevel@tonic-gate ifp = ifp->illif_next) { 18167c478bd9Sstevel@tonic-gate 18177c478bd9Sstevel@tonic-gate if (ifp->illif_mcast_v1 == 0) 18187c478bd9Sstevel@tonic-gate continue; 18197c478bd9Sstevel@tonic-gate 18207c478bd9Sstevel@tonic-gate avl_tree = &ifp->illif_avl_by_ppa; 18217c478bd9Sstevel@tonic-gate for (ill = avl_first(avl_tree); ill != NULL; 18227c478bd9Sstevel@tonic-gate ill = avl_walk(avl_tree, ill, AVL_AFTER)) { 18237c478bd9Sstevel@tonic-gate mutex_enter(&ill->ill_lock); 18247c478bd9Sstevel@tonic-gate if (ill->ill_mcast_v1_tset == 1) 18257c478bd9Sstevel@tonic-gate ill->ill_mcast_v1_time++; 18267c478bd9Sstevel@tonic-gate if (ill->ill_mcast_type == MLD_V1_ROUTER) { 18277c478bd9Sstevel@tonic-gate if (ill->ill_mcast_v1_time >= OVQP(ill)) { 18287c478bd9Sstevel@tonic-gate ip1dbg(("MLD query timer expired on" 18297c478bd9Sstevel@tonic-gate " %s; switching mode to MLD_V2\n", 18307c478bd9Sstevel@tonic-gate ill->ill_name)); 18317c478bd9Sstevel@tonic-gate ill->ill_mcast_type = MLD_V2_ROUTER; 18327c478bd9Sstevel@tonic-gate ill->ill_mcast_v1_time = 0; 18337c478bd9Sstevel@tonic-gate ill->ill_mcast_v1_tset = 0; 18347c478bd9Sstevel@tonic-gate atomic_add_16(&ifp->illif_mcast_v1, -1); 18357c478bd9Sstevel@tonic-gate } 18367c478bd9Sstevel@tonic-gate } 18377c478bd9Sstevel@tonic-gate mutex_exit(&ill->ill_lock); 18387c478bd9Sstevel@tonic-gate } 18397c478bd9Sstevel@tonic-gate } 18407c478bd9Sstevel@tonic-gate rw_exit(&ill_g_lock); 18417c478bd9Sstevel@tonic-gate mutex_enter(&mld_slowtimeout_lock); 18427c478bd9Sstevel@tonic-gate mld_slowtimeout_id = timeout(mld_slowtimo, NULL, 18437c478bd9Sstevel@tonic-gate MSEC_TO_TICK(MCAST_SLOWTIMO_INTERVAL)); 18447c478bd9Sstevel@tonic-gate mutex_exit(&mld_slowtimeout_lock); 18457c478bd9Sstevel@tonic-gate } 18467c478bd9Sstevel@tonic-gate 18477c478bd9Sstevel@tonic-gate /* 18487c478bd9Sstevel@tonic-gate * igmp_sendpkt: 18497c478bd9Sstevel@tonic-gate * This will send to ip_wput like icmp_inbound. 18507c478bd9Sstevel@tonic-gate * Note that the lower ill (on which the membership is kept) is used 18517c478bd9Sstevel@tonic-gate * as an upper ill to pass in the multicast parameters. 18527c478bd9Sstevel@tonic-gate */ 18537c478bd9Sstevel@tonic-gate static void 18547c478bd9Sstevel@tonic-gate igmp_sendpkt(ilm_t *ilm, uchar_t type, ipaddr_t addr) 18557c478bd9Sstevel@tonic-gate { 18567c478bd9Sstevel@tonic-gate mblk_t *mp; 18577c478bd9Sstevel@tonic-gate igmpa_t *igmpa; 18587c478bd9Sstevel@tonic-gate uint8_t *rtralert; 18597c478bd9Sstevel@tonic-gate ipha_t *ipha; 18607c478bd9Sstevel@tonic-gate int hdrlen = sizeof (ipha_t) + RTRALERT_LEN; 18617c478bd9Sstevel@tonic-gate size_t size = hdrlen + sizeof (igmpa_t); 18627c478bd9Sstevel@tonic-gate ipif_t *ipif = ilm->ilm_ipif; 18637c478bd9Sstevel@tonic-gate ill_t *ill = ipif->ipif_ill; /* Will be the "lower" ill */ 18647c478bd9Sstevel@tonic-gate mblk_t *first_mp; 18657c478bd9Sstevel@tonic-gate ipsec_out_t *io; 1866*45916cd2Sjpk zoneid_t zoneid; 18677c478bd9Sstevel@tonic-gate 18687c478bd9Sstevel@tonic-gate /* 18697c478bd9Sstevel@tonic-gate * We need to make sure this packet goes out on an ipif. If 18707c478bd9Sstevel@tonic-gate * there is some global policy match in ip_wput_ire, we need 18717c478bd9Sstevel@tonic-gate * to get to the right interface after IPSEC processing. 18727c478bd9Sstevel@tonic-gate * To make sure this multicast packet goes out on the right 18737c478bd9Sstevel@tonic-gate * interface, we attach an ipsec_out and initialize ill_index 18747c478bd9Sstevel@tonic-gate * like we did in ip_wput. To make sure that this packet does 18757c478bd9Sstevel@tonic-gate * not get forwarded on other interfaces or looped back, we 18767c478bd9Sstevel@tonic-gate * set ipsec_out_dontroute to B_TRUE and ipsec_out_multicast_loop 18777c478bd9Sstevel@tonic-gate * to B_FALSE. 18787c478bd9Sstevel@tonic-gate * 18797c478bd9Sstevel@tonic-gate * We also need to make sure that this does not get load balanced 18807c478bd9Sstevel@tonic-gate * if it hits ip_newroute_ipif. So, we initialize ipsec_out_attach_if 18817c478bd9Sstevel@tonic-gate * here. If it gets load balanced, switches supporting igmp snooping 18827c478bd9Sstevel@tonic-gate * will send the packet that it receives for this multicast group 18837c478bd9Sstevel@tonic-gate * to the interface that we are sending on. As we have joined the 18847c478bd9Sstevel@tonic-gate * multicast group on this ill, by sending the packet out on this 18857c478bd9Sstevel@tonic-gate * ill, we receive all the packets back on this ill. 18867c478bd9Sstevel@tonic-gate */ 18877c478bd9Sstevel@tonic-gate first_mp = allocb(sizeof (ipsec_info_t), BPRI_HI); 18887c478bd9Sstevel@tonic-gate if (first_mp == NULL) 18897c478bd9Sstevel@tonic-gate return; 18907c478bd9Sstevel@tonic-gate 18917c478bd9Sstevel@tonic-gate first_mp->b_datap->db_type = M_CTL; 18927c478bd9Sstevel@tonic-gate first_mp->b_wptr += sizeof (ipsec_info_t); 18937c478bd9Sstevel@tonic-gate bzero(first_mp->b_rptr, sizeof (ipsec_info_t)); 18947c478bd9Sstevel@tonic-gate /* ipsec_out_secure is B_FALSE now */ 18957c478bd9Sstevel@tonic-gate io = (ipsec_out_t *)first_mp->b_rptr; 18967c478bd9Sstevel@tonic-gate io->ipsec_out_type = IPSEC_OUT; 18977c478bd9Sstevel@tonic-gate io->ipsec_out_len = sizeof (ipsec_out_t); 18987c478bd9Sstevel@tonic-gate io->ipsec_out_use_global_policy = B_TRUE; 18997c478bd9Sstevel@tonic-gate io->ipsec_out_ill_index = ill->ill_phyint->phyint_ifindex; 19007c478bd9Sstevel@tonic-gate io->ipsec_out_attach_if = B_TRUE; 19017c478bd9Sstevel@tonic-gate io->ipsec_out_multicast_loop = B_FALSE; 19027c478bd9Sstevel@tonic-gate io->ipsec_out_dontroute = B_TRUE; 1903*45916cd2Sjpk if ((zoneid = ilm->ilm_zoneid) == ALL_ZONES) 1904*45916cd2Sjpk zoneid = GLOBAL_ZONEID; 1905*45916cd2Sjpk io->ipsec_out_zoneid = zoneid; 19067c478bd9Sstevel@tonic-gate 19077c478bd9Sstevel@tonic-gate mp = allocb(size, BPRI_HI); 19087c478bd9Sstevel@tonic-gate if (mp == NULL) { 19097c478bd9Sstevel@tonic-gate freemsg(first_mp); 19107c478bd9Sstevel@tonic-gate return; 19117c478bd9Sstevel@tonic-gate } 19127c478bd9Sstevel@tonic-gate mp->b_wptr = mp->b_rptr + size; 19137c478bd9Sstevel@tonic-gate first_mp->b_cont = mp; 19147c478bd9Sstevel@tonic-gate 19157c478bd9Sstevel@tonic-gate ipha = (ipha_t *)mp->b_rptr; 19167c478bd9Sstevel@tonic-gate rtralert = (uint8_t *)&(ipha[1]); 19177c478bd9Sstevel@tonic-gate igmpa = (igmpa_t *)&(rtralert[RTRALERT_LEN]); 19187c478bd9Sstevel@tonic-gate igmpa->igmpa_type = type; 19197c478bd9Sstevel@tonic-gate igmpa->igmpa_code = 0; 19207c478bd9Sstevel@tonic-gate igmpa->igmpa_group = ilm->ilm_addr; 19217c478bd9Sstevel@tonic-gate igmpa->igmpa_cksum = 0; 19227c478bd9Sstevel@tonic-gate igmpa->igmpa_cksum = IP_CSUM(mp, hdrlen, 0); 1923ff550d0eSmasputra if (igmpa->igmpa_cksum == 0) 1924ff550d0eSmasputra igmpa->igmpa_cksum = 0xffff; 19257c478bd9Sstevel@tonic-gate 19267c478bd9Sstevel@tonic-gate rtralert[0] = IPOPT_COPY & IPOPT_RTRALERT; 19277c478bd9Sstevel@tonic-gate rtralert[1] = RTRALERT_LEN; 19287c478bd9Sstevel@tonic-gate rtralert[2] = 0; 19297c478bd9Sstevel@tonic-gate rtralert[3] = 0; 19307c478bd9Sstevel@tonic-gate 19317c478bd9Sstevel@tonic-gate ipha->ipha_version_and_hdr_length = (IP_VERSION << 4) 19327c478bd9Sstevel@tonic-gate | (IP_SIMPLE_HDR_LENGTH_IN_WORDS + RTRALERT_LEN_IN_WORDS); 19337c478bd9Sstevel@tonic-gate ipha->ipha_type_of_service = 0; 19347c478bd9Sstevel@tonic-gate ipha->ipha_length = htons(size); 19357c478bd9Sstevel@tonic-gate ipha->ipha_ident = 0; 19367c478bd9Sstevel@tonic-gate ipha->ipha_fragment_offset_and_flags = 0; 19377c478bd9Sstevel@tonic-gate ipha->ipha_ttl = IGMP_TTL; 19387c478bd9Sstevel@tonic-gate ipha->ipha_protocol = IPPROTO_IGMP; 19397c478bd9Sstevel@tonic-gate ipha->ipha_hdr_checksum = 0; 19407c478bd9Sstevel@tonic-gate ipha->ipha_dst = addr ? addr : igmpa->igmpa_group; 19417c478bd9Sstevel@tonic-gate ipha->ipha_src = ipif->ipif_src_addr; 19427c478bd9Sstevel@tonic-gate /* 19437c478bd9Sstevel@tonic-gate * Request loopback of the report if we are acting as a multicast 19447c478bd9Sstevel@tonic-gate * router, so that the process-level routing demon can hear it. 19457c478bd9Sstevel@tonic-gate */ 19467c478bd9Sstevel@tonic-gate /* 19477c478bd9Sstevel@tonic-gate * This will run multiple times for the same group if there are members 19487c478bd9Sstevel@tonic-gate * on the same group for multiple ipif's on the same ill. The 19497c478bd9Sstevel@tonic-gate * igmp_input code will suppress this due to the loopback thus we 19507c478bd9Sstevel@tonic-gate * always loopback membership report. 19517c478bd9Sstevel@tonic-gate */ 19527c478bd9Sstevel@tonic-gate ASSERT(ill->ill_rq != NULL); 19537c478bd9Sstevel@tonic-gate ip_multicast_loopback(ill->ill_rq, ill, first_mp, 0, ilm->ilm_zoneid); 19547c478bd9Sstevel@tonic-gate 19557c478bd9Sstevel@tonic-gate ip_wput_multicast(ill->ill_wq, first_mp, ipif); 19567c478bd9Sstevel@tonic-gate 19577c478bd9Sstevel@tonic-gate ++igmpstat.igps_snd_reports; 19587c478bd9Sstevel@tonic-gate } 19597c478bd9Sstevel@tonic-gate 19607c478bd9Sstevel@tonic-gate /* 19617c478bd9Sstevel@tonic-gate * Sends an IGMP_V3_MEMBERSHIP_REPORT message out the ill associated 19627c478bd9Sstevel@tonic-gate * with the passed-in ipif. The report will contain one group record 19637c478bd9Sstevel@tonic-gate * for each element of reclist. If this causes packet length to 19647c478bd9Sstevel@tonic-gate * exceed ipif->ipif_ill->ill_max_frag, multiple reports are sent. 19657c478bd9Sstevel@tonic-gate * reclist is assumed to be made up of buffers allocated by mcast_bldmrec(), 19667c478bd9Sstevel@tonic-gate * and those buffers are freed here. 19677c478bd9Sstevel@tonic-gate */ 19687c478bd9Sstevel@tonic-gate static void 19697c478bd9Sstevel@tonic-gate igmpv3_sendrpt(ipif_t *ipif, mrec_t *reclist) 19707c478bd9Sstevel@tonic-gate { 19717c478bd9Sstevel@tonic-gate ipsec_out_t *io; 19727c478bd9Sstevel@tonic-gate igmp3ra_t *igmp3ra; 19737c478bd9Sstevel@tonic-gate grphdra_t *grphdr; 19747c478bd9Sstevel@tonic-gate mblk_t *first_mp, *mp; 19757c478bd9Sstevel@tonic-gate ipha_t *ipha; 19767c478bd9Sstevel@tonic-gate uint8_t *rtralert; 19777c478bd9Sstevel@tonic-gate ipaddr_t *src_array; 19787c478bd9Sstevel@tonic-gate int i, j, numrec, more_src_cnt; 19797c478bd9Sstevel@tonic-gate size_t hdrsize, size, rsize; 19807c478bd9Sstevel@tonic-gate ill_t *ill = ipif->ipif_ill; 19817c478bd9Sstevel@tonic-gate mrec_t *rp, *cur_reclist; 19827c478bd9Sstevel@tonic-gate mrec_t *next_reclist = reclist; 19837c478bd9Sstevel@tonic-gate boolean_t morepkts; 1984*45916cd2Sjpk zoneid_t zoneid; 19857c478bd9Sstevel@tonic-gate 19867c478bd9Sstevel@tonic-gate /* if there aren't any records, there's nothing to send */ 19877c478bd9Sstevel@tonic-gate if (reclist == NULL) 19887c478bd9Sstevel@tonic-gate return; 19897c478bd9Sstevel@tonic-gate 19907c478bd9Sstevel@tonic-gate hdrsize = sizeof (ipha_t) + RTRALERT_LEN; 19917c478bd9Sstevel@tonic-gate nextpkt: 19927c478bd9Sstevel@tonic-gate size = hdrsize + sizeof (igmp3ra_t); 19937c478bd9Sstevel@tonic-gate morepkts = B_FALSE; 19947c478bd9Sstevel@tonic-gate more_src_cnt = 0; 19957c478bd9Sstevel@tonic-gate cur_reclist = next_reclist; 19967c478bd9Sstevel@tonic-gate numrec = 0; 19977c478bd9Sstevel@tonic-gate for (rp = cur_reclist; rp != NULL; rp = rp->mrec_next) { 19987c478bd9Sstevel@tonic-gate rsize = sizeof (grphdra_t) + 19997c478bd9Sstevel@tonic-gate (rp->mrec_srcs.sl_numsrc * sizeof (ipaddr_t)); 20007c478bd9Sstevel@tonic-gate if (size + rsize > ill->ill_max_frag) { 20017c478bd9Sstevel@tonic-gate if (rp == cur_reclist) { 20027c478bd9Sstevel@tonic-gate /* 20037c478bd9Sstevel@tonic-gate * If the first mrec we looked at is too big 20047c478bd9Sstevel@tonic-gate * to fit in a single packet (i.e the source 20057c478bd9Sstevel@tonic-gate * list is too big), we must either truncate 20067c478bd9Sstevel@tonic-gate * the list (if TO_EX or IS_EX), or send 20077c478bd9Sstevel@tonic-gate * multiple reports for the same group (all 20087c478bd9Sstevel@tonic-gate * other types). 20097c478bd9Sstevel@tonic-gate */ 20107c478bd9Sstevel@tonic-gate int srcspace, srcsperpkt; 20117c478bd9Sstevel@tonic-gate srcspace = ill->ill_max_frag - (size + 20127c478bd9Sstevel@tonic-gate sizeof (grphdra_t)); 20137c478bd9Sstevel@tonic-gate srcsperpkt = srcspace / sizeof (ipaddr_t); 20147c478bd9Sstevel@tonic-gate /* 20157c478bd9Sstevel@tonic-gate * Increment size and numrec, because we will 20167c478bd9Sstevel@tonic-gate * be sending a record for the mrec we're 20177c478bd9Sstevel@tonic-gate * looking at now. 20187c478bd9Sstevel@tonic-gate */ 20197c478bd9Sstevel@tonic-gate size += sizeof (grphdra_t) + 20207c478bd9Sstevel@tonic-gate (srcsperpkt * sizeof (ipaddr_t)); 20217c478bd9Sstevel@tonic-gate numrec++; 20227c478bd9Sstevel@tonic-gate if (rp->mrec_type == MODE_IS_EXCLUDE || 20237c478bd9Sstevel@tonic-gate rp->mrec_type == CHANGE_TO_EXCLUDE) { 20247c478bd9Sstevel@tonic-gate rp->mrec_srcs.sl_numsrc = srcsperpkt; 20257c478bd9Sstevel@tonic-gate if (rp->mrec_next == NULL) { 20267c478bd9Sstevel@tonic-gate /* no more packets to send */ 20277c478bd9Sstevel@tonic-gate break; 20287c478bd9Sstevel@tonic-gate } else { 20297c478bd9Sstevel@tonic-gate /* 20307c478bd9Sstevel@tonic-gate * more packets, but we're 20317c478bd9Sstevel@tonic-gate * done with this mrec. 20327c478bd9Sstevel@tonic-gate */ 20337c478bd9Sstevel@tonic-gate next_reclist = rp->mrec_next; 20347c478bd9Sstevel@tonic-gate } 20357c478bd9Sstevel@tonic-gate } else { 20367c478bd9Sstevel@tonic-gate more_src_cnt = rp->mrec_srcs.sl_numsrc 20377c478bd9Sstevel@tonic-gate - srcsperpkt; 20387c478bd9Sstevel@tonic-gate rp->mrec_srcs.sl_numsrc = srcsperpkt; 20397c478bd9Sstevel@tonic-gate /* 20407c478bd9Sstevel@tonic-gate * We'll fix up this mrec (remove the 20417c478bd9Sstevel@tonic-gate * srcs we've already sent) before 20427c478bd9Sstevel@tonic-gate * returning to nextpkt above. 20437c478bd9Sstevel@tonic-gate */ 20447c478bd9Sstevel@tonic-gate next_reclist = rp; 20457c478bd9Sstevel@tonic-gate } 20467c478bd9Sstevel@tonic-gate } else { 20477c478bd9Sstevel@tonic-gate next_reclist = rp; 20487c478bd9Sstevel@tonic-gate } 20497c478bd9Sstevel@tonic-gate morepkts = B_TRUE; 20507c478bd9Sstevel@tonic-gate break; 20517c478bd9Sstevel@tonic-gate } 20527c478bd9Sstevel@tonic-gate size += rsize; 20537c478bd9Sstevel@tonic-gate numrec++; 20547c478bd9Sstevel@tonic-gate } 20557c478bd9Sstevel@tonic-gate 20567c478bd9Sstevel@tonic-gate /* 20577c478bd9Sstevel@tonic-gate * See comments in igmp_sendpkt() about initializing for ipsec and 20587c478bd9Sstevel@tonic-gate * load balancing requirements. 20597c478bd9Sstevel@tonic-gate */ 20607c478bd9Sstevel@tonic-gate first_mp = allocb(sizeof (ipsec_info_t), BPRI_HI); 20617c478bd9Sstevel@tonic-gate if (first_mp == NULL) 20627c478bd9Sstevel@tonic-gate goto free_reclist; 20637c478bd9Sstevel@tonic-gate 20647c478bd9Sstevel@tonic-gate first_mp->b_datap->db_type = M_CTL; 20657c478bd9Sstevel@tonic-gate first_mp->b_wptr += sizeof (ipsec_info_t); 20667c478bd9Sstevel@tonic-gate bzero(first_mp->b_rptr, sizeof (ipsec_info_t)); 20677c478bd9Sstevel@tonic-gate /* ipsec_out_secure is B_FALSE now */ 20687c478bd9Sstevel@tonic-gate io = (ipsec_out_t *)first_mp->b_rptr; 20697c478bd9Sstevel@tonic-gate io->ipsec_out_type = IPSEC_OUT; 20707c478bd9Sstevel@tonic-gate io->ipsec_out_len = sizeof (ipsec_out_t); 20717c478bd9Sstevel@tonic-gate io->ipsec_out_use_global_policy = B_TRUE; 20727c478bd9Sstevel@tonic-gate io->ipsec_out_ill_index = ill->ill_phyint->phyint_ifindex; 20737c478bd9Sstevel@tonic-gate io->ipsec_out_attach_if = B_TRUE; 20747c478bd9Sstevel@tonic-gate io->ipsec_out_multicast_loop = B_FALSE; 20757c478bd9Sstevel@tonic-gate io->ipsec_out_dontroute = B_TRUE; 2076*45916cd2Sjpk if ((zoneid = ipif->ipif_zoneid) == ALL_ZONES) 2077*45916cd2Sjpk zoneid = GLOBAL_ZONEID; 2078*45916cd2Sjpk io->ipsec_out_zoneid = zoneid; 20797c478bd9Sstevel@tonic-gate 20807c478bd9Sstevel@tonic-gate mp = allocb(size, BPRI_HI); 20817c478bd9Sstevel@tonic-gate if (mp == NULL) { 20827c478bd9Sstevel@tonic-gate freemsg(first_mp); 20837c478bd9Sstevel@tonic-gate goto free_reclist; 20847c478bd9Sstevel@tonic-gate } 20857c478bd9Sstevel@tonic-gate bzero((char *)mp->b_rptr, size); 20867c478bd9Sstevel@tonic-gate mp->b_wptr = (uchar_t *)(mp->b_rptr + size); 20877c478bd9Sstevel@tonic-gate first_mp->b_cont = mp; 20887c478bd9Sstevel@tonic-gate 20897c478bd9Sstevel@tonic-gate ipha = (ipha_t *)mp->b_rptr; 20907c478bd9Sstevel@tonic-gate rtralert = (uint8_t *)&(ipha[1]); 20917c478bd9Sstevel@tonic-gate igmp3ra = (igmp3ra_t *)&(rtralert[RTRALERT_LEN]); 20927c478bd9Sstevel@tonic-gate grphdr = (grphdra_t *)&(igmp3ra[1]); 20937c478bd9Sstevel@tonic-gate 20947c478bd9Sstevel@tonic-gate rp = cur_reclist; 20957c478bd9Sstevel@tonic-gate for (i = 0; i < numrec; i++) { 20967c478bd9Sstevel@tonic-gate grphdr->grphdra_type = rp->mrec_type; 20977c478bd9Sstevel@tonic-gate grphdr->grphdra_numsrc = htons(rp->mrec_srcs.sl_numsrc); 20987c478bd9Sstevel@tonic-gate grphdr->grphdra_group = V4_PART_OF_V6(rp->mrec_group); 20997c478bd9Sstevel@tonic-gate src_array = (ipaddr_t *)&(grphdr[1]); 21007c478bd9Sstevel@tonic-gate 21017c478bd9Sstevel@tonic-gate for (j = 0; j < rp->mrec_srcs.sl_numsrc; j++) 21027c478bd9Sstevel@tonic-gate src_array[j] = V4_PART_OF_V6(rp->mrec_srcs.sl_addr[j]); 21037c478bd9Sstevel@tonic-gate 21047c478bd9Sstevel@tonic-gate grphdr = (grphdra_t *)&(src_array[j]); 21057c478bd9Sstevel@tonic-gate rp = rp->mrec_next; 21067c478bd9Sstevel@tonic-gate } 21077c478bd9Sstevel@tonic-gate 21087c478bd9Sstevel@tonic-gate igmp3ra->igmp3ra_type = IGMP_V3_MEMBERSHIP_REPORT; 21097c478bd9Sstevel@tonic-gate igmp3ra->igmp3ra_numrec = htons(numrec); 21107c478bd9Sstevel@tonic-gate igmp3ra->igmp3ra_cksum = IP_CSUM(mp, hdrsize, 0); 21117c478bd9Sstevel@tonic-gate 21127c478bd9Sstevel@tonic-gate rtralert[0] = IPOPT_COPY & IPOPT_RTRALERT; 21137c478bd9Sstevel@tonic-gate rtralert[1] = RTRALERT_LEN; 21147c478bd9Sstevel@tonic-gate rtralert[2] = 0; 21157c478bd9Sstevel@tonic-gate rtralert[3] = 0; 21167c478bd9Sstevel@tonic-gate 21177c478bd9Sstevel@tonic-gate ipha->ipha_version_and_hdr_length = IP_VERSION << 4 21187c478bd9Sstevel@tonic-gate | (IP_SIMPLE_HDR_LENGTH_IN_WORDS + RTRALERT_LEN_IN_WORDS); 21197c478bd9Sstevel@tonic-gate ipha->ipha_type_of_service = IPTOS_PREC_INTERNETCONTROL; 21207c478bd9Sstevel@tonic-gate ipha->ipha_length = htons(size); 21217c478bd9Sstevel@tonic-gate ipha->ipha_ttl = IGMP_TTL; 21227c478bd9Sstevel@tonic-gate ipha->ipha_protocol = IPPROTO_IGMP; 21237c478bd9Sstevel@tonic-gate ipha->ipha_dst = htonl(INADDR_ALLRPTS_GROUP); 21247c478bd9Sstevel@tonic-gate ipha->ipha_src = ipif->ipif_src_addr; 21257c478bd9Sstevel@tonic-gate 21267c478bd9Sstevel@tonic-gate /* 21277c478bd9Sstevel@tonic-gate * Request loopback of the report if we are acting as a multicast 21287c478bd9Sstevel@tonic-gate * router, so that the process-level routing daemon can hear it. 21297c478bd9Sstevel@tonic-gate * 21307c478bd9Sstevel@tonic-gate * This will run multiple times for the same group if there are 21317c478bd9Sstevel@tonic-gate * members on the same group for multiple ipifs on the same ill. 21327c478bd9Sstevel@tonic-gate * The igmp_input code will suppress this due to the loopback; 21337c478bd9Sstevel@tonic-gate * thus we always loopback membership report. 21347c478bd9Sstevel@tonic-gate */ 21357c478bd9Sstevel@tonic-gate ASSERT(ill->ill_rq != NULL); 21367c478bd9Sstevel@tonic-gate ip_multicast_loopback(ill->ill_rq, ill, mp, 0, ipif->ipif_zoneid); 21377c478bd9Sstevel@tonic-gate 21387c478bd9Sstevel@tonic-gate ip_wput_multicast(ill->ill_wq, first_mp, ipif); 21397c478bd9Sstevel@tonic-gate 21407c478bd9Sstevel@tonic-gate ++igmpstat.igps_snd_reports; 21417c478bd9Sstevel@tonic-gate 21427c478bd9Sstevel@tonic-gate if (morepkts) { 21437c478bd9Sstevel@tonic-gate if (more_src_cnt > 0) { 21447c478bd9Sstevel@tonic-gate int index, mvsize; 21457c478bd9Sstevel@tonic-gate slist_t *sl = &next_reclist->mrec_srcs; 21467c478bd9Sstevel@tonic-gate index = sl->sl_numsrc; 21477c478bd9Sstevel@tonic-gate mvsize = more_src_cnt * sizeof (in6_addr_t); 21487c478bd9Sstevel@tonic-gate (void) memmove(&sl->sl_addr[0], &sl->sl_addr[index], 21497c478bd9Sstevel@tonic-gate mvsize); 21507c478bd9Sstevel@tonic-gate sl->sl_numsrc = more_src_cnt; 21517c478bd9Sstevel@tonic-gate } 21527c478bd9Sstevel@tonic-gate goto nextpkt; 21537c478bd9Sstevel@tonic-gate } 21547c478bd9Sstevel@tonic-gate 21557c478bd9Sstevel@tonic-gate free_reclist: 21567c478bd9Sstevel@tonic-gate while (reclist != NULL) { 21577c478bd9Sstevel@tonic-gate rp = reclist->mrec_next; 21587c478bd9Sstevel@tonic-gate mi_free(reclist); 21597c478bd9Sstevel@tonic-gate reclist = rp; 21607c478bd9Sstevel@tonic-gate } 21617c478bd9Sstevel@tonic-gate } 21627c478bd9Sstevel@tonic-gate 21637c478bd9Sstevel@tonic-gate /* 21647c478bd9Sstevel@tonic-gate * mld_input: 21657c478bd9Sstevel@tonic-gate */ 21667c478bd9Sstevel@tonic-gate /* ARGSUSED */ 21677c478bd9Sstevel@tonic-gate void 21687c478bd9Sstevel@tonic-gate mld_input(queue_t *q, mblk_t *mp, ill_t *ill) 21697c478bd9Sstevel@tonic-gate { 21707c478bd9Sstevel@tonic-gate ip6_t *ip6h = (ip6_t *)(mp->b_rptr); 21717c478bd9Sstevel@tonic-gate mld_hdr_t *mldh; 21727c478bd9Sstevel@tonic-gate ilm_t *ilm; 21737c478bd9Sstevel@tonic-gate ipif_t *ipif; 21747c478bd9Sstevel@tonic-gate uint16_t hdr_length, exthdr_length; 21757c478bd9Sstevel@tonic-gate in6_addr_t *v6group_ptr, *lcladdr_ptr; 21767c478bd9Sstevel@tonic-gate uint_t next; 21777c478bd9Sstevel@tonic-gate int mldlen; 21787c478bd9Sstevel@tonic-gate 21797c478bd9Sstevel@tonic-gate BUMP_MIB(ill->ill_icmp6_mib, ipv6IfIcmpInGroupMembTotal); 21807c478bd9Sstevel@tonic-gate 21817c478bd9Sstevel@tonic-gate /* Make sure the src address of the packet is link-local */ 21827c478bd9Sstevel@tonic-gate if (!(IN6_IS_ADDR_LINKLOCAL(&ip6h->ip6_src))) { 21837c478bd9Sstevel@tonic-gate BUMP_MIB(ill->ill_icmp6_mib, ipv6IfIcmpInErrors); 21847c478bd9Sstevel@tonic-gate freemsg(mp); 21857c478bd9Sstevel@tonic-gate return; 21867c478bd9Sstevel@tonic-gate } 21877c478bd9Sstevel@tonic-gate 21887c478bd9Sstevel@tonic-gate if (ip6h->ip6_hlim != 1) { 21897c478bd9Sstevel@tonic-gate BUMP_MIB(ill->ill_icmp6_mib, ipv6IfIcmpBadHoplimit); 21907c478bd9Sstevel@tonic-gate freemsg(mp); 21917c478bd9Sstevel@tonic-gate return; 21927c478bd9Sstevel@tonic-gate } 21937c478bd9Sstevel@tonic-gate 21947c478bd9Sstevel@tonic-gate /* Get to the icmp header part */ 21957c478bd9Sstevel@tonic-gate if (ip6h->ip6_nxt != IPPROTO_ICMPV6) { 21967c478bd9Sstevel@tonic-gate hdr_length = ip_hdr_length_v6(mp, ip6h); 21977c478bd9Sstevel@tonic-gate exthdr_length = hdr_length - IPV6_HDR_LEN; 21987c478bd9Sstevel@tonic-gate } else { 21997c478bd9Sstevel@tonic-gate hdr_length = IPV6_HDR_LEN; 22007c478bd9Sstevel@tonic-gate exthdr_length = 0; 22017c478bd9Sstevel@tonic-gate } 22027c478bd9Sstevel@tonic-gate mldlen = ntohs(ip6h->ip6_plen) - exthdr_length; 22037c478bd9Sstevel@tonic-gate 22047c478bd9Sstevel@tonic-gate /* An MLD packet must at least be 24 octets to be valid */ 22057c478bd9Sstevel@tonic-gate if (mldlen < MLD_MINLEN) { 22067c478bd9Sstevel@tonic-gate BUMP_MIB(ill->ill_icmp6_mib, ipv6IfIcmpInErrors); 22077c478bd9Sstevel@tonic-gate freemsg(mp); 22087c478bd9Sstevel@tonic-gate return; 22097c478bd9Sstevel@tonic-gate } 22107c478bd9Sstevel@tonic-gate 22117c478bd9Sstevel@tonic-gate mldh = (mld_hdr_t *)(&mp->b_rptr[hdr_length]); 22127c478bd9Sstevel@tonic-gate 22137c478bd9Sstevel@tonic-gate switch (mldh->mld_type) { 22147c478bd9Sstevel@tonic-gate case MLD_LISTENER_QUERY: 22157c478bd9Sstevel@tonic-gate /* 22167c478bd9Sstevel@tonic-gate * packet length differentiates between v1 and v2. v1 22177c478bd9Sstevel@tonic-gate * query should be exactly 24 octets long; v2 is >= 28. 22187c478bd9Sstevel@tonic-gate */ 22197c478bd9Sstevel@tonic-gate if (mldlen == MLD_MINLEN) { 22207c478bd9Sstevel@tonic-gate next = mld_query_in(mldh, ill); 22217c478bd9Sstevel@tonic-gate } else if (mldlen >= MLD_V2_QUERY_MINLEN) { 22227c478bd9Sstevel@tonic-gate next = mldv2_query_in((mld2q_t *)mldh, ill, mldlen); 22237c478bd9Sstevel@tonic-gate } else { 22247c478bd9Sstevel@tonic-gate BUMP_MIB(ill->ill_icmp6_mib, ipv6IfIcmpInErrors); 22257c478bd9Sstevel@tonic-gate freemsg(mp); 22267c478bd9Sstevel@tonic-gate return; 22277c478bd9Sstevel@tonic-gate } 22287c478bd9Sstevel@tonic-gate if (next == 0) { 22297c478bd9Sstevel@tonic-gate freemsg(mp); 22307c478bd9Sstevel@tonic-gate return; 22317c478bd9Sstevel@tonic-gate } 22327c478bd9Sstevel@tonic-gate 22337c478bd9Sstevel@tonic-gate if (next != INFINITY) 22347c478bd9Sstevel@tonic-gate mld_start_timers(next); 22357c478bd9Sstevel@tonic-gate break; 22367c478bd9Sstevel@tonic-gate 22377c478bd9Sstevel@tonic-gate case MLD_LISTENER_REPORT: { 22387c478bd9Sstevel@tonic-gate 22397c478bd9Sstevel@tonic-gate ASSERT(ill->ill_ipif != NULL); 22407c478bd9Sstevel@tonic-gate /* 22417c478bd9Sstevel@tonic-gate * For fast leave to work, we have to know that we are the 22427c478bd9Sstevel@tonic-gate * last person to send a report for this group. Reports 22437c478bd9Sstevel@tonic-gate * generated by us are looped back since we could potentially 22447c478bd9Sstevel@tonic-gate * be a multicast router, so discard reports sourced by me. 22457c478bd9Sstevel@tonic-gate */ 22467c478bd9Sstevel@tonic-gate lcladdr_ptr = &(ill->ill_ipif->ipif_v6subnet); 22477c478bd9Sstevel@tonic-gate mutex_enter(&ill->ill_lock); 22487c478bd9Sstevel@tonic-gate for (ipif = ill->ill_ipif; ipif != NULL; 22497c478bd9Sstevel@tonic-gate ipif = ipif->ipif_next) { 22507c478bd9Sstevel@tonic-gate if (IN6_ARE_ADDR_EQUAL(&ipif->ipif_v6lcl_addr, 22517c478bd9Sstevel@tonic-gate lcladdr_ptr)) { 22527c478bd9Sstevel@tonic-gate if (ip_debug > 1) { 22537c478bd9Sstevel@tonic-gate char buf1[INET6_ADDRSTRLEN]; 22547c478bd9Sstevel@tonic-gate char buf2[INET6_ADDRSTRLEN]; 22557c478bd9Sstevel@tonic-gate 22567c478bd9Sstevel@tonic-gate (void) mi_strlog(ill->ill_rq, 22577c478bd9Sstevel@tonic-gate 1, 22587c478bd9Sstevel@tonic-gate SL_TRACE, 22597c478bd9Sstevel@tonic-gate "mld_input: we are only " 22607c478bd9Sstevel@tonic-gate "member src %s ipif_local %s", 22617c478bd9Sstevel@tonic-gate inet_ntop(AF_INET6, lcladdr_ptr, 22627c478bd9Sstevel@tonic-gate buf1, sizeof (buf1)), 22637c478bd9Sstevel@tonic-gate inet_ntop(AF_INET6, 22647c478bd9Sstevel@tonic-gate &ipif->ipif_v6lcl_addr, 22657c478bd9Sstevel@tonic-gate buf2, sizeof (buf2))); 22667c478bd9Sstevel@tonic-gate } 22677c478bd9Sstevel@tonic-gate mutex_exit(&ill->ill_lock); 22687c478bd9Sstevel@tonic-gate freemsg(mp); 22697c478bd9Sstevel@tonic-gate return; 22707c478bd9Sstevel@tonic-gate } 22717c478bd9Sstevel@tonic-gate } 22727c478bd9Sstevel@tonic-gate mutex_exit(&ill->ill_lock); 22737c478bd9Sstevel@tonic-gate BUMP_MIB(ill->ill_icmp6_mib, ipv6IfIcmpInGroupMembResponses); 22747c478bd9Sstevel@tonic-gate 22757c478bd9Sstevel@tonic-gate v6group_ptr = &mldh->mld_addr; 22767c478bd9Sstevel@tonic-gate if (!IN6_IS_ADDR_MULTICAST(v6group_ptr)) { 22777c478bd9Sstevel@tonic-gate BUMP_MIB(ill->ill_icmp6_mib, 22787c478bd9Sstevel@tonic-gate ipv6IfIcmpInGroupMembBadReports); 22797c478bd9Sstevel@tonic-gate freemsg(mp); 22807c478bd9Sstevel@tonic-gate return; 22817c478bd9Sstevel@tonic-gate } 22827c478bd9Sstevel@tonic-gate 22837c478bd9Sstevel@tonic-gate 22847c478bd9Sstevel@tonic-gate /* 22857c478bd9Sstevel@tonic-gate * If we belong to the group being reported, and we are a 22867c478bd9Sstevel@tonic-gate * 'Delaying member' per the RFC terminology, stop our timer 22877c478bd9Sstevel@tonic-gate * for that group and 'clear flag' i.e. mark ilm_state as 22887c478bd9Sstevel@tonic-gate * IGMP_OTHERMEMBER. With zones, there can be multiple group 22897c478bd9Sstevel@tonic-gate * membership entries for the same group address (one per zone) 22907c478bd9Sstevel@tonic-gate * so we need to walk the ill_ilm list. 22917c478bd9Sstevel@tonic-gate */ 22927c478bd9Sstevel@tonic-gate mutex_enter(&ill->ill_lock); 22937c478bd9Sstevel@tonic-gate for (ilm = ill->ill_ilm; ilm != NULL; ilm = ilm->ilm_next) { 22947c478bd9Sstevel@tonic-gate if (!IN6_ARE_ADDR_EQUAL(&ilm->ilm_v6addr, v6group_ptr)) 22957c478bd9Sstevel@tonic-gate continue; 22967c478bd9Sstevel@tonic-gate BUMP_MIB(ill->ill_icmp6_mib, 22977c478bd9Sstevel@tonic-gate ipv6IfIcmpInGroupMembOurReports); 22987c478bd9Sstevel@tonic-gate 22997c478bd9Sstevel@tonic-gate ilm->ilm_timer = INFINITY; 23007c478bd9Sstevel@tonic-gate ilm->ilm_state = IGMP_OTHERMEMBER; 23017c478bd9Sstevel@tonic-gate } 23027c478bd9Sstevel@tonic-gate mutex_exit(&ill->ill_lock); 23037c478bd9Sstevel@tonic-gate break; 23047c478bd9Sstevel@tonic-gate } 23057c478bd9Sstevel@tonic-gate case MLD_LISTENER_REDUCTION: 23067c478bd9Sstevel@tonic-gate BUMP_MIB(ill->ill_icmp6_mib, ipv6IfIcmpInGroupMembReductions); 23077c478bd9Sstevel@tonic-gate break; 23087c478bd9Sstevel@tonic-gate } 23097c478bd9Sstevel@tonic-gate /* 23107c478bd9Sstevel@tonic-gate * All MLD packets have already been passed up to any 23117c478bd9Sstevel@tonic-gate * process(es) listening on a ICMP6 raw socket. This 23127c478bd9Sstevel@tonic-gate * has been accomplished in ip_deliver_local_v6 prior to 23137c478bd9Sstevel@tonic-gate * this function call. It is assumed that the multicast daemon 23147c478bd9Sstevel@tonic-gate * will have a SOCK_RAW IPPROTO_ICMPV6 (and presumbly use the 23157c478bd9Sstevel@tonic-gate * ICMP6_FILTER socket option to only receive the MLD messages) 23167c478bd9Sstevel@tonic-gate * Thus we can free the MLD message block here 23177c478bd9Sstevel@tonic-gate */ 23187c478bd9Sstevel@tonic-gate freemsg(mp); 23197c478bd9Sstevel@tonic-gate } 23207c478bd9Sstevel@tonic-gate 23217c478bd9Sstevel@tonic-gate /* 23227c478bd9Sstevel@tonic-gate * Handles an MLDv1 Listener Query. Returns 0 on error, or the appropriate 23237c478bd9Sstevel@tonic-gate * (non-zero, unsigned) timer value to be set on success. 23247c478bd9Sstevel@tonic-gate */ 23257c478bd9Sstevel@tonic-gate static uint_t 23267c478bd9Sstevel@tonic-gate mld_query_in(mld_hdr_t *mldh, ill_t *ill) 23277c478bd9Sstevel@tonic-gate { 23287c478bd9Sstevel@tonic-gate ilm_t *ilm; 23297c478bd9Sstevel@tonic-gate int timer; 23307c478bd9Sstevel@tonic-gate uint_t next; 23317c478bd9Sstevel@tonic-gate in6_addr_t *v6group; 23327c478bd9Sstevel@tonic-gate 23337c478bd9Sstevel@tonic-gate BUMP_MIB(ill->ill_icmp6_mib, ipv6IfIcmpInGroupMembQueries); 23347c478bd9Sstevel@tonic-gate 23357c478bd9Sstevel@tonic-gate /* 23367c478bd9Sstevel@tonic-gate * In the MLD specification, there are 3 states and a flag. 23377c478bd9Sstevel@tonic-gate * 23387c478bd9Sstevel@tonic-gate * In Non-Listener state, we simply don't have a membership record. 23397c478bd9Sstevel@tonic-gate * In Delaying state, our timer is running (ilm->ilm_timer < INFINITY) 23407c478bd9Sstevel@tonic-gate * In Idle Member state, our timer is not running (ilm->ilm_timer == 23417c478bd9Sstevel@tonic-gate * INFINITY) 23427c478bd9Sstevel@tonic-gate * 23437c478bd9Sstevel@tonic-gate * The flag is ilm->ilm_state, it is set to IGMP_OTHERMEMBER if 23447c478bd9Sstevel@tonic-gate * we have heard a report from another member, or IGMP_IREPORTEDLAST 23457c478bd9Sstevel@tonic-gate * if I sent the last report. 23467c478bd9Sstevel@tonic-gate */ 23477c478bd9Sstevel@tonic-gate v6group = &mldh->mld_addr; 23487c478bd9Sstevel@tonic-gate if (!(IN6_IS_ADDR_UNSPECIFIED(v6group)) && 23497c478bd9Sstevel@tonic-gate ((!IN6_IS_ADDR_MULTICAST(v6group)))) { 23507c478bd9Sstevel@tonic-gate BUMP_MIB(ill->ill_icmp6_mib, ipv6IfIcmpInGroupMembBadQueries); 23517c478bd9Sstevel@tonic-gate return (0); 23527c478bd9Sstevel@tonic-gate } 23537c478bd9Sstevel@tonic-gate 23547c478bd9Sstevel@tonic-gate /* Need to do compatibility mode checking */ 23557c478bd9Sstevel@tonic-gate mutex_enter(&ill->ill_lock); 23567c478bd9Sstevel@tonic-gate ill->ill_mcast_v1_time = 0; 23577c478bd9Sstevel@tonic-gate ill->ill_mcast_v1_tset = 1; 23587c478bd9Sstevel@tonic-gate if (ill->ill_mcast_type == MLD_V2_ROUTER) { 23597c478bd9Sstevel@tonic-gate ip1dbg(("Received MLDv1 Query on %s, switching mode to " 23607c478bd9Sstevel@tonic-gate "MLD_V1_ROUTER\n", ill->ill_name)); 23617c478bd9Sstevel@tonic-gate atomic_add_16(&ill->ill_ifptr->illif_mcast_v1, 1); 23627c478bd9Sstevel@tonic-gate ill->ill_mcast_type = MLD_V1_ROUTER; 23637c478bd9Sstevel@tonic-gate } 23647c478bd9Sstevel@tonic-gate mutex_exit(&ill->ill_lock); 23657c478bd9Sstevel@tonic-gate 23667c478bd9Sstevel@tonic-gate timer = (int)ntohs(mldh->mld_maxdelay); 23677c478bd9Sstevel@tonic-gate if (ip_debug > 1) { 23687c478bd9Sstevel@tonic-gate (void) mi_strlog(ill->ill_rq, 1, SL_TRACE, 23697c478bd9Sstevel@tonic-gate "mld_input: TIMER = mld_maxdelay %d mld_type 0x%x", 23707c478bd9Sstevel@tonic-gate timer, (int)mldh->mld_type); 23717c478bd9Sstevel@tonic-gate } 23727c478bd9Sstevel@tonic-gate 23737c478bd9Sstevel@tonic-gate /* 23747c478bd9Sstevel@tonic-gate * -Start the timers in all of our membership records for 23757c478bd9Sstevel@tonic-gate * the physical interface on which the query arrived, 23767c478bd9Sstevel@tonic-gate * excl: 23777c478bd9Sstevel@tonic-gate * 1. those that belong to the "all hosts" group, 23787c478bd9Sstevel@tonic-gate * 2. those with 0 scope, or 1 node-local scope. 23797c478bd9Sstevel@tonic-gate * 23807c478bd9Sstevel@tonic-gate * -Restart any timer that is already running but has a value 23817c478bd9Sstevel@tonic-gate * longer that the requested timeout. 23827c478bd9Sstevel@tonic-gate * -Use the value specified in the query message as the 23837c478bd9Sstevel@tonic-gate * maximum timeout. 23847c478bd9Sstevel@tonic-gate */ 23857c478bd9Sstevel@tonic-gate next = INFINITY; 23867c478bd9Sstevel@tonic-gate mutex_enter(&ill->ill_lock); 23877c478bd9Sstevel@tonic-gate for (ilm = ill->ill_ilm; ilm != NULL; ilm = ilm->ilm_next) { 23887c478bd9Sstevel@tonic-gate ASSERT(!IN6_IS_ADDR_V4MAPPED(&ilm->ilm_v6addr)); 23897c478bd9Sstevel@tonic-gate 23907c478bd9Sstevel@tonic-gate if (IN6_IS_ADDR_UNSPECIFIED(&ilm->ilm_v6addr) || 23917c478bd9Sstevel@tonic-gate IN6_IS_ADDR_MC_NODELOCAL(&ilm->ilm_v6addr) || 23927c478bd9Sstevel@tonic-gate IN6_IS_ADDR_MC_RESERVED(&ilm->ilm_v6addr)) 23937c478bd9Sstevel@tonic-gate continue; 23947c478bd9Sstevel@tonic-gate if ((!IN6_ARE_ADDR_EQUAL(&ilm->ilm_v6addr, 23957c478bd9Sstevel@tonic-gate &ipv6_all_hosts_mcast)) && 23967c478bd9Sstevel@tonic-gate (IN6_IS_ADDR_UNSPECIFIED(v6group)) || 23977c478bd9Sstevel@tonic-gate (IN6_ARE_ADDR_EQUAL(v6group, &ilm->ilm_v6addr))) { 23987c478bd9Sstevel@tonic-gate if (timer == 0) { 23997c478bd9Sstevel@tonic-gate /* Respond immediately */ 24007c478bd9Sstevel@tonic-gate ilm->ilm_timer = INFINITY; 24017c478bd9Sstevel@tonic-gate ilm->ilm_state = IGMP_IREPORTEDLAST; 24027c478bd9Sstevel@tonic-gate mutex_exit(&ill->ill_lock); 24037c478bd9Sstevel@tonic-gate mld_sendpkt(ilm, MLD_LISTENER_REPORT, NULL); 24047c478bd9Sstevel@tonic-gate mutex_enter(&ill->ill_lock); 24057c478bd9Sstevel@tonic-gate break; 24067c478bd9Sstevel@tonic-gate } 24077c478bd9Sstevel@tonic-gate if (ilm->ilm_timer > timer) { 24087c478bd9Sstevel@tonic-gate MCAST_RANDOM_DELAY(ilm->ilm_timer, timer); 24097c478bd9Sstevel@tonic-gate if (ilm->ilm_timer < next) 24107c478bd9Sstevel@tonic-gate next = ilm->ilm_timer; 24117c478bd9Sstevel@tonic-gate } 24127c478bd9Sstevel@tonic-gate break; 24137c478bd9Sstevel@tonic-gate } 24147c478bd9Sstevel@tonic-gate } 24157c478bd9Sstevel@tonic-gate mutex_exit(&ill->ill_lock); 24167c478bd9Sstevel@tonic-gate 24177c478bd9Sstevel@tonic-gate return (next); 24187c478bd9Sstevel@tonic-gate } 24197c478bd9Sstevel@tonic-gate 24207c478bd9Sstevel@tonic-gate /* 24217c478bd9Sstevel@tonic-gate * Handles an MLDv2 Listener Query. On error, returns 0; on success, 24227c478bd9Sstevel@tonic-gate * returns the appropriate (non-zero, unsigned) timer value (which may 24237c478bd9Sstevel@tonic-gate * be INFINITY) to be set. 24247c478bd9Sstevel@tonic-gate */ 24257c478bd9Sstevel@tonic-gate static uint_t 24267c478bd9Sstevel@tonic-gate mldv2_query_in(mld2q_t *mld2q, ill_t *ill, int mldlen) 24277c478bd9Sstevel@tonic-gate { 24287c478bd9Sstevel@tonic-gate ilm_t *ilm; 24297c478bd9Sstevel@tonic-gate in6_addr_t *v6group, *src_array; 24307c478bd9Sstevel@tonic-gate uint_t next, numsrc, i, mrd, delay, qqi; 24317c478bd9Sstevel@tonic-gate uint8_t qrv; 24327c478bd9Sstevel@tonic-gate 24337c478bd9Sstevel@tonic-gate v6group = &mld2q->mld2q_addr; 24347c478bd9Sstevel@tonic-gate numsrc = ntohs(mld2q->mld2q_numsrc); 24357c478bd9Sstevel@tonic-gate 24367c478bd9Sstevel@tonic-gate /* make sure numsrc matches packet size */ 24377c478bd9Sstevel@tonic-gate if (mldlen < MLD_V2_QUERY_MINLEN + (numsrc * sizeof (in6_addr_t))) { 24387c478bd9Sstevel@tonic-gate BUMP_MIB(ill->ill_icmp6_mib, ipv6IfIcmpInErrors); 24397c478bd9Sstevel@tonic-gate return (0); 24407c478bd9Sstevel@tonic-gate } 24417c478bd9Sstevel@tonic-gate src_array = (in6_addr_t *)&mld2q[1]; 24427c478bd9Sstevel@tonic-gate 24437c478bd9Sstevel@tonic-gate BUMP_MIB(ill->ill_icmp6_mib, ipv6IfIcmpInGroupMembQueries); 24447c478bd9Sstevel@tonic-gate 24457c478bd9Sstevel@tonic-gate /* extract Maximum Response Delay from code in header */ 24467c478bd9Sstevel@tonic-gate mrd = ntohs(mld2q->mld2q_mxrc); 24477c478bd9Sstevel@tonic-gate if (mrd >= MLD_V2_MAXRT_FPMIN) { 24487c478bd9Sstevel@tonic-gate uint_t hdrval, mant, exp; 24497c478bd9Sstevel@tonic-gate hdrval = mrd; 24507c478bd9Sstevel@tonic-gate mant = hdrval & MLD_V2_MAXRT_MANT_MASK; 24517c478bd9Sstevel@tonic-gate exp = (hdrval & MLD_V2_MAXRT_EXP_MASK) >> 12; 24527c478bd9Sstevel@tonic-gate mrd = (mant | 0x1000) << (exp + 3); 24537c478bd9Sstevel@tonic-gate } 24547c478bd9Sstevel@tonic-gate MCAST_RANDOM_DELAY(delay, mrd); 24557c478bd9Sstevel@tonic-gate next = (unsigned)INFINITY; 24567c478bd9Sstevel@tonic-gate 24577c478bd9Sstevel@tonic-gate if ((qrv = mld2q->mld2q_sqrv & MLD_V2_RV_MASK) == 0) 24587c478bd9Sstevel@tonic-gate ill->ill_mcast_rv = MCAST_DEF_ROBUSTNESS; 24597c478bd9Sstevel@tonic-gate else 24607c478bd9Sstevel@tonic-gate ill->ill_mcast_rv = qrv; 24617c478bd9Sstevel@tonic-gate 24627c478bd9Sstevel@tonic-gate if ((qqi = (uint_t)mld2q->mld2q_qqic) >= MLD_V2_QQI_FPMIN) { 24637c478bd9Sstevel@tonic-gate uint_t mant, exp; 24647c478bd9Sstevel@tonic-gate mant = qqi & MLD_V2_QQI_MANT_MASK; 24657c478bd9Sstevel@tonic-gate exp = (qqi & MLD_V2_QQI_EXP_MASK) >> 12; 24667c478bd9Sstevel@tonic-gate qqi = (mant | 0x10) << (exp + 3); 24677c478bd9Sstevel@tonic-gate } 24687c478bd9Sstevel@tonic-gate ill->ill_mcast_qi = (qqi == 0) ? MCAST_DEF_QUERY_INTERVAL : qqi; 24697c478bd9Sstevel@tonic-gate 24707c478bd9Sstevel@tonic-gate /* 24717c478bd9Sstevel@tonic-gate * If we have a pending general query response that's scheduled 24727c478bd9Sstevel@tonic-gate * sooner than the delay we calculated for this response, then 24737c478bd9Sstevel@tonic-gate * no action is required (MLDv2 draft section 6.2 rule 1) 24747c478bd9Sstevel@tonic-gate */ 24757c478bd9Sstevel@tonic-gate mutex_enter(&ill->ill_lock); 24767c478bd9Sstevel@tonic-gate if (ill->ill_global_timer < delay) { 24777c478bd9Sstevel@tonic-gate mutex_exit(&ill->ill_lock); 24787c478bd9Sstevel@tonic-gate return (next); 24797c478bd9Sstevel@tonic-gate } 24807c478bd9Sstevel@tonic-gate mutex_exit(&ill->ill_lock); 24817c478bd9Sstevel@tonic-gate 24827c478bd9Sstevel@tonic-gate /* 24837c478bd9Sstevel@tonic-gate * Now take action depending on query type: general, 24847c478bd9Sstevel@tonic-gate * group specific, or group/source specific. 24857c478bd9Sstevel@tonic-gate */ 24867c478bd9Sstevel@tonic-gate if ((numsrc == 0) && IN6_IS_ADDR_UNSPECIFIED(v6group)) { 24877c478bd9Sstevel@tonic-gate /* 24887c478bd9Sstevel@tonic-gate * general query 24897c478bd9Sstevel@tonic-gate * We know global timer is either not running or is 24907c478bd9Sstevel@tonic-gate * greater than our calculated delay, so reset it to 24917c478bd9Sstevel@tonic-gate * our delay (random value in range [0, response time]) 24927c478bd9Sstevel@tonic-gate */ 24937c478bd9Sstevel@tonic-gate mutex_enter(&ill->ill_lock); 24947c478bd9Sstevel@tonic-gate ill->ill_global_timer = delay; 24957c478bd9Sstevel@tonic-gate next = ill->ill_global_timer; 24967c478bd9Sstevel@tonic-gate mutex_exit(&ill->ill_lock); 24977c478bd9Sstevel@tonic-gate 24987c478bd9Sstevel@tonic-gate } else { 24997c478bd9Sstevel@tonic-gate /* group or group/source specific query */ 25007c478bd9Sstevel@tonic-gate mutex_enter(&ill->ill_lock); 25017c478bd9Sstevel@tonic-gate for (ilm = ill->ill_ilm; ilm != NULL; ilm = ilm->ilm_next) { 25027c478bd9Sstevel@tonic-gate if (IN6_IS_ADDR_UNSPECIFIED(&ilm->ilm_v6addr) || 25037c478bd9Sstevel@tonic-gate IN6_IS_ADDR_MC_NODELOCAL(&ilm->ilm_v6addr) || 25047c478bd9Sstevel@tonic-gate IN6_IS_ADDR_MC_RESERVED(&ilm->ilm_v6addr) || 25057c478bd9Sstevel@tonic-gate !IN6_ARE_ADDR_EQUAL(v6group, &ilm->ilm_v6addr)) 25067c478bd9Sstevel@tonic-gate continue; 25077c478bd9Sstevel@tonic-gate 25087c478bd9Sstevel@tonic-gate /* 25097c478bd9Sstevel@tonic-gate * If the query is group specific or we have a 25107c478bd9Sstevel@tonic-gate * pending group specific query, the response is 25117c478bd9Sstevel@tonic-gate * group specific (pending sources list should be 25127c478bd9Sstevel@tonic-gate * empty). Otherwise, need to update the pending 25137c478bd9Sstevel@tonic-gate * sources list for the group and source specific 25147c478bd9Sstevel@tonic-gate * response. 25157c478bd9Sstevel@tonic-gate */ 25167c478bd9Sstevel@tonic-gate if (numsrc == 0 || (ilm->ilm_timer < INFINITY && 25177c478bd9Sstevel@tonic-gate SLIST_IS_EMPTY(ilm->ilm_pendsrcs))) { 25187c478bd9Sstevel@tonic-gate group_query: 25197c478bd9Sstevel@tonic-gate FREE_SLIST(ilm->ilm_pendsrcs); 25207c478bd9Sstevel@tonic-gate ilm->ilm_pendsrcs = NULL; 25217c478bd9Sstevel@tonic-gate } else { 25227c478bd9Sstevel@tonic-gate boolean_t overflow; 25237c478bd9Sstevel@tonic-gate slist_t *pktl; 25247c478bd9Sstevel@tonic-gate if (numsrc > MAX_FILTER_SIZE || 25257c478bd9Sstevel@tonic-gate (ilm->ilm_pendsrcs == NULL && 25267c478bd9Sstevel@tonic-gate (ilm->ilm_pendsrcs = l_alloc()) == NULL)) { 25277c478bd9Sstevel@tonic-gate /* 25287c478bd9Sstevel@tonic-gate * We've been sent more sources than 25297c478bd9Sstevel@tonic-gate * we can deal with; or we can't deal 25307c478bd9Sstevel@tonic-gate * with a source list at all. Revert 25317c478bd9Sstevel@tonic-gate * to a group specific query. 25327c478bd9Sstevel@tonic-gate */ 25337c478bd9Sstevel@tonic-gate goto group_query; 25347c478bd9Sstevel@tonic-gate } 25357c478bd9Sstevel@tonic-gate if ((pktl = l_alloc()) == NULL) 25367c478bd9Sstevel@tonic-gate goto group_query; 25377c478bd9Sstevel@tonic-gate pktl->sl_numsrc = numsrc; 25387c478bd9Sstevel@tonic-gate for (i = 0; i < numsrc; i++) 25397c478bd9Sstevel@tonic-gate pktl->sl_addr[i] = src_array[i]; 25407c478bd9Sstevel@tonic-gate l_union_in_a(ilm->ilm_pendsrcs, pktl, 25417c478bd9Sstevel@tonic-gate &overflow); 25427c478bd9Sstevel@tonic-gate l_free(pktl); 25437c478bd9Sstevel@tonic-gate if (overflow) 25447c478bd9Sstevel@tonic-gate goto group_query; 25457c478bd9Sstevel@tonic-gate } 25467c478bd9Sstevel@tonic-gate /* set timer to soonest value */ 25477c478bd9Sstevel@tonic-gate ilm->ilm_timer = MIN(ilm->ilm_timer, delay); 25487c478bd9Sstevel@tonic-gate if (ilm->ilm_timer < next) 25497c478bd9Sstevel@tonic-gate next = ilm->ilm_timer; 25507c478bd9Sstevel@tonic-gate break; 25517c478bd9Sstevel@tonic-gate } 25527c478bd9Sstevel@tonic-gate mutex_exit(&ill->ill_lock); 25537c478bd9Sstevel@tonic-gate } 25547c478bd9Sstevel@tonic-gate 25557c478bd9Sstevel@tonic-gate return (next); 25567c478bd9Sstevel@tonic-gate } 25577c478bd9Sstevel@tonic-gate 25587c478bd9Sstevel@tonic-gate /* 25597c478bd9Sstevel@tonic-gate * Send MLDv1 response packet with hoplimit 1 25607c478bd9Sstevel@tonic-gate */ 25617c478bd9Sstevel@tonic-gate static void 25627c478bd9Sstevel@tonic-gate mld_sendpkt(ilm_t *ilm, uchar_t type, const in6_addr_t *v6addr) 25637c478bd9Sstevel@tonic-gate { 25647c478bd9Sstevel@tonic-gate mblk_t *mp; 25657c478bd9Sstevel@tonic-gate mld_hdr_t *mldh; 25667c478bd9Sstevel@tonic-gate ip6_t *ip6h; 25677c478bd9Sstevel@tonic-gate ip6_hbh_t *ip6hbh; 25687c478bd9Sstevel@tonic-gate struct ip6_opt_router *ip6router; 25697c478bd9Sstevel@tonic-gate size_t size = IPV6_HDR_LEN + sizeof (mld_hdr_t); 25707c478bd9Sstevel@tonic-gate ill_t *ill = ilm->ilm_ill; /* Will be the "lower" ill */ 25717c478bd9Sstevel@tonic-gate ipif_t *ipif; 25727c478bd9Sstevel@tonic-gate ip6i_t *ip6i; 25737c478bd9Sstevel@tonic-gate 25747c478bd9Sstevel@tonic-gate /* 25757c478bd9Sstevel@tonic-gate * We need to place a router alert option in this packet. The length 25767c478bd9Sstevel@tonic-gate * of the options must be a multiple of 8. The hbh option header is 2 25777c478bd9Sstevel@tonic-gate * bytes followed by the 4 byte router alert option. That leaves 25787c478bd9Sstevel@tonic-gate * 2 bytes of pad for a total of 8 bytes. 25797c478bd9Sstevel@tonic-gate */ 25807c478bd9Sstevel@tonic-gate const int router_alert_length = 8; 25817c478bd9Sstevel@tonic-gate 25827c478bd9Sstevel@tonic-gate ASSERT(ill->ill_isv6); 25837c478bd9Sstevel@tonic-gate 25847c478bd9Sstevel@tonic-gate /* 25857c478bd9Sstevel@tonic-gate * We need to make sure that this packet does not get load balanced. 25867c478bd9Sstevel@tonic-gate * So, we allocate an ip6i_t and set ATTACH_IF. ip_wput_v6 and 25877c478bd9Sstevel@tonic-gate * ip_newroute_ipif_v6 knows how to handle such packets. 25887c478bd9Sstevel@tonic-gate * If it gets load balanced, switches supporting MLD snooping 25897c478bd9Sstevel@tonic-gate * (in the future) will send the packet that it receives for this 25907c478bd9Sstevel@tonic-gate * multicast group to the interface that we are sending on. As we have 25917c478bd9Sstevel@tonic-gate * joined the multicast group on this ill, by sending the packet out 25927c478bd9Sstevel@tonic-gate * on this ill, we receive all the packets back on this ill. 25937c478bd9Sstevel@tonic-gate */ 25947c478bd9Sstevel@tonic-gate size += sizeof (ip6i_t) + router_alert_length; 25957c478bd9Sstevel@tonic-gate mp = allocb(size, BPRI_HI); 25967c478bd9Sstevel@tonic-gate if (mp == NULL) 25977c478bd9Sstevel@tonic-gate return; 25987c478bd9Sstevel@tonic-gate bzero(mp->b_rptr, size); 25997c478bd9Sstevel@tonic-gate mp->b_wptr = mp->b_rptr + size; 26007c478bd9Sstevel@tonic-gate 26017c478bd9Sstevel@tonic-gate ip6i = (ip6i_t *)mp->b_rptr; 26027c478bd9Sstevel@tonic-gate ip6i->ip6i_vcf = IPV6_DEFAULT_VERS_AND_FLOW; 26037c478bd9Sstevel@tonic-gate ip6i->ip6i_nxt = IPPROTO_RAW; 26047c478bd9Sstevel@tonic-gate ip6i->ip6i_flags = IP6I_ATTACH_IF | IP6I_HOPLIMIT; 26057c478bd9Sstevel@tonic-gate ip6i->ip6i_ifindex = ill->ill_phyint->phyint_ifindex; 26067c478bd9Sstevel@tonic-gate 26077c478bd9Sstevel@tonic-gate ip6h = (ip6_t *)&ip6i[1]; 26087c478bd9Sstevel@tonic-gate ip6hbh = (struct ip6_hbh *)&ip6h[1]; 26097c478bd9Sstevel@tonic-gate ip6router = (struct ip6_opt_router *)&ip6hbh[1]; 26107c478bd9Sstevel@tonic-gate /* 26117c478bd9Sstevel@tonic-gate * A zero is a pad option of length 1. The bzero of the whole packet 26127c478bd9Sstevel@tonic-gate * above will pad between ip6router and mld. 26137c478bd9Sstevel@tonic-gate */ 26147c478bd9Sstevel@tonic-gate mldh = (mld_hdr_t *)((uint8_t *)ip6hbh + router_alert_length); 26157c478bd9Sstevel@tonic-gate 26167c478bd9Sstevel@tonic-gate mldh->mld_type = type; 26177c478bd9Sstevel@tonic-gate mldh->mld_addr = ilm->ilm_v6addr; 26187c478bd9Sstevel@tonic-gate 26197c478bd9Sstevel@tonic-gate ip6router->ip6or_type = IP6OPT_ROUTER_ALERT; 26207c478bd9Sstevel@tonic-gate ip6router->ip6or_len = 2; 26217c478bd9Sstevel@tonic-gate ip6router->ip6or_value[0] = 0; 26227c478bd9Sstevel@tonic-gate ip6router->ip6or_value[1] = IP6_ALERT_MLD; 26237c478bd9Sstevel@tonic-gate 26247c478bd9Sstevel@tonic-gate ip6hbh->ip6h_nxt = IPPROTO_ICMPV6; 26257c478bd9Sstevel@tonic-gate ip6hbh->ip6h_len = 0; 26267c478bd9Sstevel@tonic-gate 26277c478bd9Sstevel@tonic-gate ip6h->ip6_vcf = IPV6_DEFAULT_VERS_AND_FLOW; 26287c478bd9Sstevel@tonic-gate ip6h->ip6_plen = htons(sizeof (*mldh) + router_alert_length); 26297c478bd9Sstevel@tonic-gate ip6h->ip6_nxt = IPPROTO_HOPOPTS; 26307c478bd9Sstevel@tonic-gate ip6h->ip6_hops = MLD_HOP_LIMIT; 26317c478bd9Sstevel@tonic-gate if (v6addr == NULL) 26327c478bd9Sstevel@tonic-gate ip6h->ip6_dst = ilm->ilm_v6addr; 26337c478bd9Sstevel@tonic-gate else 26347c478bd9Sstevel@tonic-gate ip6h->ip6_dst = *v6addr; 26357c478bd9Sstevel@tonic-gate 26367c478bd9Sstevel@tonic-gate /* ipif returned by ipif_lookup_zoneid is link-local (if present) */ 26377c478bd9Sstevel@tonic-gate if (ipif_lookup_zoneid(ill, ilm->ilm_zoneid, IPIF_UP, &ipif)) { 26387c478bd9Sstevel@tonic-gate ip6h->ip6_src = ipif->ipif_v6src_addr; 26397c478bd9Sstevel@tonic-gate ipif_refrele(ipif); 26407c478bd9Sstevel@tonic-gate } else { 26417c478bd9Sstevel@tonic-gate /* Otherwise, use IPv6 default address selection. */ 26427c478bd9Sstevel@tonic-gate ip6h->ip6_src = ipv6_all_zeros; 26437c478bd9Sstevel@tonic-gate } 26447c478bd9Sstevel@tonic-gate 26457c478bd9Sstevel@tonic-gate /* 26467c478bd9Sstevel@tonic-gate * Prepare for checksum by putting icmp length in the icmp 26477c478bd9Sstevel@tonic-gate * checksum field. The checksum is calculated in ip_wput_v6. 26487c478bd9Sstevel@tonic-gate */ 26497c478bd9Sstevel@tonic-gate mldh->mld_cksum = htons(sizeof (*mldh)); 26507c478bd9Sstevel@tonic-gate 26517c478bd9Sstevel@tonic-gate /* 26527c478bd9Sstevel@tonic-gate * ip_wput will automatically loopback the multicast packet to 26537c478bd9Sstevel@tonic-gate * the conn if multicast loopback is enabled. 26547c478bd9Sstevel@tonic-gate * The MIB stats corresponding to this outgoing MLD packet 26557c478bd9Sstevel@tonic-gate * will be accounted for in ip_wput->ip_wput_v6->ip_wput_ire_v6 26567c478bd9Sstevel@tonic-gate * ->icmp_update_out_mib_v6 function call. 26577c478bd9Sstevel@tonic-gate */ 26587c478bd9Sstevel@tonic-gate (void) ip_output_v6(NULL, mp, ill->ill_wq, IP_WPUT); 26597c478bd9Sstevel@tonic-gate } 26607c478bd9Sstevel@tonic-gate 26617c478bd9Sstevel@tonic-gate /* 26627c478bd9Sstevel@tonic-gate * Sends an MLD_V2_LISTENER_REPORT message out the passed-in ill. The 26637c478bd9Sstevel@tonic-gate * report will contain one multicast address record for each element of 26647c478bd9Sstevel@tonic-gate * reclist. If this causes packet length to exceed ill->ill_max_frag, 26657c478bd9Sstevel@tonic-gate * multiple reports are sent. reclist is assumed to be made up of 26667c478bd9Sstevel@tonic-gate * buffers allocated by mcast_bldmrec(), and those buffers are freed here. 26677c478bd9Sstevel@tonic-gate */ 26687c478bd9Sstevel@tonic-gate static void 26697c478bd9Sstevel@tonic-gate mldv2_sendrpt(ill_t *ill, mrec_t *reclist) 26707c478bd9Sstevel@tonic-gate { 26717c478bd9Sstevel@tonic-gate mblk_t *mp; 26727c478bd9Sstevel@tonic-gate mld2r_t *mld2r; 26737c478bd9Sstevel@tonic-gate mld2mar_t *mld2mar; 26747c478bd9Sstevel@tonic-gate in6_addr_t *srcarray; 26757c478bd9Sstevel@tonic-gate ip6_t *ip6h; 26767c478bd9Sstevel@tonic-gate ip6_hbh_t *ip6hbh; 26777c478bd9Sstevel@tonic-gate ip6i_t *ip6i; 26787c478bd9Sstevel@tonic-gate struct ip6_opt_router *ip6router; 26797c478bd9Sstevel@tonic-gate size_t size, optlen, padlen, icmpsize, rsize; 26807c478bd9Sstevel@tonic-gate ipif_t *ipif; 26817c478bd9Sstevel@tonic-gate int i, numrec, more_src_cnt; 26827c478bd9Sstevel@tonic-gate mrec_t *rp, *cur_reclist; 26837c478bd9Sstevel@tonic-gate mrec_t *next_reclist = reclist; 26847c478bd9Sstevel@tonic-gate boolean_t morepkts; 26857c478bd9Sstevel@tonic-gate 26867c478bd9Sstevel@tonic-gate /* If there aren't any records, there's nothing to send */ 26877c478bd9Sstevel@tonic-gate if (reclist == NULL) 26887c478bd9Sstevel@tonic-gate return; 26897c478bd9Sstevel@tonic-gate 26907c478bd9Sstevel@tonic-gate ASSERT(ill->ill_isv6); 26917c478bd9Sstevel@tonic-gate 26927c478bd9Sstevel@tonic-gate /* 26937c478bd9Sstevel@tonic-gate * Total option length (optlen + padlen) must be a multiple of 26947c478bd9Sstevel@tonic-gate * 8 bytes. We assume here that optlen <= 8, so the total option 26957c478bd9Sstevel@tonic-gate * length will be 8. Assert this in case anything ever changes. 26967c478bd9Sstevel@tonic-gate */ 26977c478bd9Sstevel@tonic-gate optlen = sizeof (ip6_hbh_t) + sizeof (struct ip6_opt_router); 26987c478bd9Sstevel@tonic-gate ASSERT(optlen <= 8); 26997c478bd9Sstevel@tonic-gate padlen = 8 - optlen; 27007c478bd9Sstevel@tonic-gate nextpkt: 27017c478bd9Sstevel@tonic-gate icmpsize = sizeof (mld2r_t); 27027c478bd9Sstevel@tonic-gate size = IPV6_HDR_LEN + optlen + padlen + icmpsize; 27037c478bd9Sstevel@tonic-gate morepkts = B_FALSE; 27047c478bd9Sstevel@tonic-gate more_src_cnt = 0; 27057c478bd9Sstevel@tonic-gate for (rp = cur_reclist = next_reclist, numrec = 0; rp != NULL; 27067c478bd9Sstevel@tonic-gate rp = rp->mrec_next, numrec++) { 27077c478bd9Sstevel@tonic-gate rsize = sizeof (mld2mar_t) + 27087c478bd9Sstevel@tonic-gate (rp->mrec_srcs.sl_numsrc * sizeof (in6_addr_t)); 27097c478bd9Sstevel@tonic-gate if (size + rsize > ill->ill_max_frag) { 27107c478bd9Sstevel@tonic-gate if (rp == cur_reclist) { 27117c478bd9Sstevel@tonic-gate /* 27127c478bd9Sstevel@tonic-gate * If the first mrec we looked at is too big 27137c478bd9Sstevel@tonic-gate * to fit in a single packet (i.e the source 27147c478bd9Sstevel@tonic-gate * list is too big), we must either truncate 27157c478bd9Sstevel@tonic-gate * the list (if TO_EX or IS_EX), or send 27167c478bd9Sstevel@tonic-gate * multiple reports for the same group (all 27177c478bd9Sstevel@tonic-gate * other types). 27187c478bd9Sstevel@tonic-gate */ 27197c478bd9Sstevel@tonic-gate int srcspace, srcsperpkt; 27207c478bd9Sstevel@tonic-gate srcspace = ill->ill_max_frag - 27217c478bd9Sstevel@tonic-gate (size + sizeof (mld2mar_t)); 27227c478bd9Sstevel@tonic-gate srcsperpkt = srcspace / sizeof (in6_addr_t); 27237c478bd9Sstevel@tonic-gate /* 27247c478bd9Sstevel@tonic-gate * Increment icmpsize and size, because we will 27257c478bd9Sstevel@tonic-gate * be sending a record for the mrec we're 27267c478bd9Sstevel@tonic-gate * looking at now. 27277c478bd9Sstevel@tonic-gate */ 27287c478bd9Sstevel@tonic-gate rsize = sizeof (mld2mar_t) + 27297c478bd9Sstevel@tonic-gate (srcsperpkt * sizeof (in6_addr_t)); 27307c478bd9Sstevel@tonic-gate icmpsize += rsize; 27317c478bd9Sstevel@tonic-gate size += rsize; 27327c478bd9Sstevel@tonic-gate if (rp->mrec_type == MODE_IS_EXCLUDE || 27337c478bd9Sstevel@tonic-gate rp->mrec_type == CHANGE_TO_EXCLUDE) { 27347c478bd9Sstevel@tonic-gate rp->mrec_srcs.sl_numsrc = srcsperpkt; 27357c478bd9Sstevel@tonic-gate if (rp->mrec_next == NULL) { 27367c478bd9Sstevel@tonic-gate /* no more packets to send */ 27377c478bd9Sstevel@tonic-gate break; 27387c478bd9Sstevel@tonic-gate } else { 27397c478bd9Sstevel@tonic-gate /* 27407c478bd9Sstevel@tonic-gate * more packets, but we're 27417c478bd9Sstevel@tonic-gate * done with this mrec. 27427c478bd9Sstevel@tonic-gate */ 27437c478bd9Sstevel@tonic-gate next_reclist = rp->mrec_next; 27447c478bd9Sstevel@tonic-gate } 27457c478bd9Sstevel@tonic-gate } else { 27467c478bd9Sstevel@tonic-gate more_src_cnt = rp->mrec_srcs.sl_numsrc 27477c478bd9Sstevel@tonic-gate - srcsperpkt; 27487c478bd9Sstevel@tonic-gate rp->mrec_srcs.sl_numsrc = srcsperpkt; 27497c478bd9Sstevel@tonic-gate /* 27507c478bd9Sstevel@tonic-gate * We'll fix up this mrec (remove the 27517c478bd9Sstevel@tonic-gate * srcs we've already sent) before 27527c478bd9Sstevel@tonic-gate * returning to nextpkt above. 27537c478bd9Sstevel@tonic-gate */ 27547c478bd9Sstevel@tonic-gate next_reclist = rp; 27557c478bd9Sstevel@tonic-gate } 27567c478bd9Sstevel@tonic-gate } else { 27577c478bd9Sstevel@tonic-gate next_reclist = rp; 27587c478bd9Sstevel@tonic-gate } 27597c478bd9Sstevel@tonic-gate morepkts = B_TRUE; 27607c478bd9Sstevel@tonic-gate break; 27617c478bd9Sstevel@tonic-gate } 27627c478bd9Sstevel@tonic-gate icmpsize += rsize; 27637c478bd9Sstevel@tonic-gate size += rsize; 27647c478bd9Sstevel@tonic-gate } 27657c478bd9Sstevel@tonic-gate 27667c478bd9Sstevel@tonic-gate /* 27677c478bd9Sstevel@tonic-gate * We need to make sure that this packet does not get load balanced. 27687c478bd9Sstevel@tonic-gate * So, we allocate an ip6i_t and set ATTACH_IF. ip_wput_v6 and 27697c478bd9Sstevel@tonic-gate * ip_newroute_ipif_v6 know how to handle such packets. 27707c478bd9Sstevel@tonic-gate * If it gets load balanced, switches supporting MLD snooping 27717c478bd9Sstevel@tonic-gate * (in the future) will send the packet that it receives for this 27727c478bd9Sstevel@tonic-gate * multicast group to the interface that we are sending on. As we have 27737c478bd9Sstevel@tonic-gate * joined the multicast group on this ill, by sending the packet out 27747c478bd9Sstevel@tonic-gate * on this ill, we receive all the packets back on this ill. 27757c478bd9Sstevel@tonic-gate */ 27767c478bd9Sstevel@tonic-gate size += sizeof (ip6i_t); 27777c478bd9Sstevel@tonic-gate mp = allocb(size, BPRI_HI); 27787c478bd9Sstevel@tonic-gate if (mp == NULL) 27797c478bd9Sstevel@tonic-gate goto free_reclist; 27807c478bd9Sstevel@tonic-gate bzero(mp->b_rptr, size); 27817c478bd9Sstevel@tonic-gate mp->b_wptr = mp->b_rptr + size; 27827c478bd9Sstevel@tonic-gate 27837c478bd9Sstevel@tonic-gate ip6i = (ip6i_t *)mp->b_rptr; 27847c478bd9Sstevel@tonic-gate ip6i->ip6i_vcf = IPV6_DEFAULT_VERS_AND_FLOW; 27857c478bd9Sstevel@tonic-gate ip6i->ip6i_nxt = IPPROTO_RAW; 27867c478bd9Sstevel@tonic-gate ip6i->ip6i_flags = IP6I_ATTACH_IF; 27877c478bd9Sstevel@tonic-gate ip6i->ip6i_ifindex = ill->ill_phyint->phyint_ifindex; 27887c478bd9Sstevel@tonic-gate 27897c478bd9Sstevel@tonic-gate ip6h = (ip6_t *)&(ip6i[1]); 27907c478bd9Sstevel@tonic-gate ip6hbh = (ip6_hbh_t *)&(ip6h[1]); 27917c478bd9Sstevel@tonic-gate ip6router = (struct ip6_opt_router *)&(ip6hbh[1]); 27927c478bd9Sstevel@tonic-gate mld2r = (mld2r_t *)((uint8_t *)ip6hbh + optlen + padlen); 27937c478bd9Sstevel@tonic-gate mld2mar = (mld2mar_t *)&(mld2r[1]); 27947c478bd9Sstevel@tonic-gate 27957c478bd9Sstevel@tonic-gate ip6h->ip6_vcf = IPV6_DEFAULT_VERS_AND_FLOW; 27967c478bd9Sstevel@tonic-gate ip6h->ip6_plen = htons(optlen + padlen + icmpsize); 27977c478bd9Sstevel@tonic-gate ip6h->ip6_nxt = IPPROTO_HOPOPTS; 27987c478bd9Sstevel@tonic-gate ip6h->ip6_hops = MLD_HOP_LIMIT; 27997c478bd9Sstevel@tonic-gate ip6h->ip6_dst = ipv6_all_v2rtrs_mcast; 28007c478bd9Sstevel@tonic-gate /* ipif returned by ipif_lookup_zoneid is link-local (if present) */ 28017c478bd9Sstevel@tonic-gate if (ipif_lookup_zoneid(ill, ALL_ZONES, IPIF_UP, &ipif)) { 28027c478bd9Sstevel@tonic-gate ip6h->ip6_src = ipif->ipif_v6src_addr; 28037c478bd9Sstevel@tonic-gate ipif_refrele(ipif); 28047c478bd9Sstevel@tonic-gate } else { 28057c478bd9Sstevel@tonic-gate /* otherwise, use IPv6 default address selection. */ 28067c478bd9Sstevel@tonic-gate ip6h->ip6_src = ipv6_all_zeros; 28077c478bd9Sstevel@tonic-gate } 28087c478bd9Sstevel@tonic-gate 28097c478bd9Sstevel@tonic-gate ip6hbh->ip6h_nxt = IPPROTO_ICMPV6; 28107c478bd9Sstevel@tonic-gate /* 28117c478bd9Sstevel@tonic-gate * ip6h_len is the number of 8-byte words, not including the first 28127c478bd9Sstevel@tonic-gate * 8 bytes; we've assumed optlen + padlen == 8 bytes; hence len = 0. 28137c478bd9Sstevel@tonic-gate */ 28147c478bd9Sstevel@tonic-gate ip6hbh->ip6h_len = 0; 28157c478bd9Sstevel@tonic-gate 28167c478bd9Sstevel@tonic-gate ip6router->ip6or_type = IP6OPT_ROUTER_ALERT; 28177c478bd9Sstevel@tonic-gate ip6router->ip6or_len = 2; 28187c478bd9Sstevel@tonic-gate ip6router->ip6or_value[0] = 0; 28197c478bd9Sstevel@tonic-gate ip6router->ip6or_value[1] = IP6_ALERT_MLD; 28207c478bd9Sstevel@tonic-gate 28217c478bd9Sstevel@tonic-gate mld2r->mld2r_type = MLD_V2_LISTENER_REPORT; 28227c478bd9Sstevel@tonic-gate mld2r->mld2r_nummar = htons(numrec); 28237c478bd9Sstevel@tonic-gate /* 28247c478bd9Sstevel@tonic-gate * Prepare for the checksum by putting icmp length in the icmp 28257c478bd9Sstevel@tonic-gate * checksum field. The checksum is calculated in ip_wput_v6. 28267c478bd9Sstevel@tonic-gate */ 28277c478bd9Sstevel@tonic-gate mld2r->mld2r_cksum = htons(icmpsize); 28287c478bd9Sstevel@tonic-gate 28297c478bd9Sstevel@tonic-gate for (rp = cur_reclist; rp != NULL; rp = rp->mrec_next) { 28307c478bd9Sstevel@tonic-gate mld2mar->mld2mar_type = rp->mrec_type; 28317c478bd9Sstevel@tonic-gate mld2mar->mld2mar_auxlen = 0; 28327c478bd9Sstevel@tonic-gate mld2mar->mld2mar_numsrc = htons(rp->mrec_srcs.sl_numsrc); 28337c478bd9Sstevel@tonic-gate mld2mar->mld2mar_group = rp->mrec_group; 28347c478bd9Sstevel@tonic-gate srcarray = (in6_addr_t *)&(mld2mar[1]); 28357c478bd9Sstevel@tonic-gate 28367c478bd9Sstevel@tonic-gate for (i = 0; i < rp->mrec_srcs.sl_numsrc; i++) 28377c478bd9Sstevel@tonic-gate srcarray[i] = rp->mrec_srcs.sl_addr[i]; 28387c478bd9Sstevel@tonic-gate 28397c478bd9Sstevel@tonic-gate mld2mar = (mld2mar_t *)&(srcarray[i]); 28407c478bd9Sstevel@tonic-gate } 28417c478bd9Sstevel@tonic-gate 28427c478bd9Sstevel@tonic-gate /* 28437c478bd9Sstevel@tonic-gate * ip_wput will automatically loopback the multicast packet to 28447c478bd9Sstevel@tonic-gate * the conn if multicast loopback is enabled. 28457c478bd9Sstevel@tonic-gate * The MIB stats corresponding to this outgoing MLD packet 28467c478bd9Sstevel@tonic-gate * will be accounted for in ip_wput->ip_wput_v6->ip_wput_ire_v6 28477c478bd9Sstevel@tonic-gate * ->icmp_update_out_mib_v6 function call. 28487c478bd9Sstevel@tonic-gate */ 28497c478bd9Sstevel@tonic-gate (void) ip_output_v6(NULL, mp, ill->ill_wq, IP_WPUT); 28507c478bd9Sstevel@tonic-gate 28517c478bd9Sstevel@tonic-gate if (morepkts) { 28527c478bd9Sstevel@tonic-gate if (more_src_cnt > 0) { 28537c478bd9Sstevel@tonic-gate int index, mvsize; 28547c478bd9Sstevel@tonic-gate slist_t *sl = &next_reclist->mrec_srcs; 28557c478bd9Sstevel@tonic-gate index = sl->sl_numsrc; 28567c478bd9Sstevel@tonic-gate mvsize = more_src_cnt * sizeof (in6_addr_t); 28577c478bd9Sstevel@tonic-gate (void) memmove(&sl->sl_addr[0], &sl->sl_addr[index], 28587c478bd9Sstevel@tonic-gate mvsize); 28597c478bd9Sstevel@tonic-gate sl->sl_numsrc = more_src_cnt; 28607c478bd9Sstevel@tonic-gate } 28617c478bd9Sstevel@tonic-gate goto nextpkt; 28627c478bd9Sstevel@tonic-gate } 28637c478bd9Sstevel@tonic-gate 28647c478bd9Sstevel@tonic-gate free_reclist: 28657c478bd9Sstevel@tonic-gate while (reclist != NULL) { 28667c478bd9Sstevel@tonic-gate rp = reclist->mrec_next; 28677c478bd9Sstevel@tonic-gate mi_free(reclist); 28687c478bd9Sstevel@tonic-gate reclist = rp; 28697c478bd9Sstevel@tonic-gate } 28707c478bd9Sstevel@tonic-gate } 28717c478bd9Sstevel@tonic-gate 28727c478bd9Sstevel@tonic-gate static mrec_t * 28737c478bd9Sstevel@tonic-gate mcast_bldmrec(mcast_record_t type, in6_addr_t *grp, slist_t *srclist, 28747c478bd9Sstevel@tonic-gate mrec_t *next) 28757c478bd9Sstevel@tonic-gate { 28767c478bd9Sstevel@tonic-gate mrec_t *rp; 28777c478bd9Sstevel@tonic-gate int i; 28787c478bd9Sstevel@tonic-gate 28797c478bd9Sstevel@tonic-gate if ((type == ALLOW_NEW_SOURCES || type == BLOCK_OLD_SOURCES) && 28807c478bd9Sstevel@tonic-gate SLIST_IS_EMPTY(srclist)) 28817c478bd9Sstevel@tonic-gate return (next); 28827c478bd9Sstevel@tonic-gate 28837c478bd9Sstevel@tonic-gate rp = (mrec_t *)mi_alloc(sizeof (mrec_t), BPRI_HI); 28847c478bd9Sstevel@tonic-gate if (rp == NULL) 28857c478bd9Sstevel@tonic-gate return (next); 28867c478bd9Sstevel@tonic-gate 28877c478bd9Sstevel@tonic-gate rp->mrec_next = next; 28887c478bd9Sstevel@tonic-gate rp->mrec_type = type; 28897c478bd9Sstevel@tonic-gate rp->mrec_auxlen = 0; 28907c478bd9Sstevel@tonic-gate rp->mrec_group = *grp; 28917c478bd9Sstevel@tonic-gate if (srclist == NULL) { 28927c478bd9Sstevel@tonic-gate rp->mrec_srcs.sl_numsrc = 0; 28937c478bd9Sstevel@tonic-gate } else { 28947c478bd9Sstevel@tonic-gate rp->mrec_srcs.sl_numsrc = srclist->sl_numsrc; 28957c478bd9Sstevel@tonic-gate for (i = 0; i < srclist->sl_numsrc; i++) 28967c478bd9Sstevel@tonic-gate rp->mrec_srcs.sl_addr[i] = srclist->sl_addr[i]; 28977c478bd9Sstevel@tonic-gate } 28987c478bd9Sstevel@tonic-gate 28997c478bd9Sstevel@tonic-gate return (rp); 29007c478bd9Sstevel@tonic-gate } 29017c478bd9Sstevel@tonic-gate 29027c478bd9Sstevel@tonic-gate /* 29037c478bd9Sstevel@tonic-gate * Set up initial retransmit state. If memory cannot be allocated for 29047c478bd9Sstevel@tonic-gate * the source lists, simply create as much state as is possible; memory 29057c478bd9Sstevel@tonic-gate * allocation failures are considered one type of transient error that 29067c478bd9Sstevel@tonic-gate * the retransmissions are designed to overcome (and if they aren't 29077c478bd9Sstevel@tonic-gate * transient, there are bigger problems than failing to notify the 29087c478bd9Sstevel@tonic-gate * router about multicast group membership state changes). 29097c478bd9Sstevel@tonic-gate */ 29107c478bd9Sstevel@tonic-gate static void 29117c478bd9Sstevel@tonic-gate mcast_init_rtx(ill_t *ill, rtx_state_t *rtxp, mcast_record_t rtype, 29127c478bd9Sstevel@tonic-gate slist_t *flist) 29137c478bd9Sstevel@tonic-gate { 29147c478bd9Sstevel@tonic-gate /* 29157c478bd9Sstevel@tonic-gate * There are only three possibilities for rtype: 29167c478bd9Sstevel@tonic-gate * New join, transition from INCLUDE {} to INCLUDE {flist} 29177c478bd9Sstevel@tonic-gate * => rtype is ALLOW_NEW_SOURCES 29187c478bd9Sstevel@tonic-gate * New join, transition from INCLUDE {} to EXCLUDE {flist} 29197c478bd9Sstevel@tonic-gate * => rtype is CHANGE_TO_EXCLUDE 29207c478bd9Sstevel@tonic-gate * State change that involves a filter mode change 29217c478bd9Sstevel@tonic-gate * => rtype is either CHANGE_TO_INCLUDE or CHANGE_TO_EXCLUDE 29227c478bd9Sstevel@tonic-gate */ 29237c478bd9Sstevel@tonic-gate ASSERT(rtype == CHANGE_TO_EXCLUDE || rtype == CHANGE_TO_INCLUDE || 29247c478bd9Sstevel@tonic-gate rtype == ALLOW_NEW_SOURCES); 29257c478bd9Sstevel@tonic-gate 29267c478bd9Sstevel@tonic-gate rtxp->rtx_cnt = ill->ill_mcast_rv; 29277c478bd9Sstevel@tonic-gate 29287c478bd9Sstevel@tonic-gate switch (rtype) { 29297c478bd9Sstevel@tonic-gate case CHANGE_TO_EXCLUDE: 29307c478bd9Sstevel@tonic-gate rtxp->rtx_fmode_cnt = ill->ill_mcast_rv; 29317c478bd9Sstevel@tonic-gate CLEAR_SLIST(rtxp->rtx_allow); 29327c478bd9Sstevel@tonic-gate COPY_SLIST(flist, rtxp->rtx_block); 29337c478bd9Sstevel@tonic-gate break; 29347c478bd9Sstevel@tonic-gate case ALLOW_NEW_SOURCES: 29357c478bd9Sstevel@tonic-gate case CHANGE_TO_INCLUDE: 29367c478bd9Sstevel@tonic-gate rtxp->rtx_fmode_cnt = 29377c478bd9Sstevel@tonic-gate rtype == ALLOW_NEW_SOURCES ? 0 : ill->ill_mcast_rv; 29387c478bd9Sstevel@tonic-gate CLEAR_SLIST(rtxp->rtx_block); 29397c478bd9Sstevel@tonic-gate COPY_SLIST(flist, rtxp->rtx_allow); 29407c478bd9Sstevel@tonic-gate break; 29417c478bd9Sstevel@tonic-gate } 29427c478bd9Sstevel@tonic-gate } 29437c478bd9Sstevel@tonic-gate 29447c478bd9Sstevel@tonic-gate /* 29457c478bd9Sstevel@tonic-gate * The basic strategy here, as extrapolated from RFC 3810 section 6.1 and 29467c478bd9Sstevel@tonic-gate * RFC 3376 section 5.1, covers three cases: 29477c478bd9Sstevel@tonic-gate * * The current state change is a filter mode change 29487c478bd9Sstevel@tonic-gate * Set filter mode retransmit counter; set retransmit allow or 29497c478bd9Sstevel@tonic-gate * block list to new source list as appropriate, and clear the 29507c478bd9Sstevel@tonic-gate * retransmit list that was not set; send TO_IN or TO_EX with 29517c478bd9Sstevel@tonic-gate * new source list. 29527c478bd9Sstevel@tonic-gate * * The current state change is a source list change, but the filter 29537c478bd9Sstevel@tonic-gate * mode retransmit counter is > 0 29547c478bd9Sstevel@tonic-gate * Decrement filter mode retransmit counter; set retransmit 29557c478bd9Sstevel@tonic-gate * allow or block list to new source list as appropriate, 29567c478bd9Sstevel@tonic-gate * and clear the retransmit list that was not set; send TO_IN 29577c478bd9Sstevel@tonic-gate * or TO_EX with new source list. 29587c478bd9Sstevel@tonic-gate * * The current state change is a source list change, and the filter 29597c478bd9Sstevel@tonic-gate * mode retransmit counter is 0. 29607c478bd9Sstevel@tonic-gate * Merge existing rtx allow and block lists with new state: 29617c478bd9Sstevel@tonic-gate * rtx_allow = (new allow + rtx_allow) - new block 29627c478bd9Sstevel@tonic-gate * rtx_block = (new block + rtx_block) - new allow 29637c478bd9Sstevel@tonic-gate * Send ALLOW and BLOCK records for new retransmit lists; 29647c478bd9Sstevel@tonic-gate * decrement retransmit counter. 29657c478bd9Sstevel@tonic-gate * 29667c478bd9Sstevel@tonic-gate * As is the case for mcast_init_rtx(), memory allocation failures are 29677c478bd9Sstevel@tonic-gate * acceptable; we just create as much state as we can. 29687c478bd9Sstevel@tonic-gate */ 29697c478bd9Sstevel@tonic-gate static mrec_t * 29707c478bd9Sstevel@tonic-gate mcast_merge_rtx(ilm_t *ilm, mrec_t *mreclist, slist_t *flist) 29717c478bd9Sstevel@tonic-gate { 29727c478bd9Sstevel@tonic-gate ill_t *ill; 29737c478bd9Sstevel@tonic-gate rtx_state_t *rtxp = &ilm->ilm_rtx; 29747c478bd9Sstevel@tonic-gate mcast_record_t txtype; 29757c478bd9Sstevel@tonic-gate mrec_t *rp, *rpnext, *rtnmrec; 29767c478bd9Sstevel@tonic-gate boolean_t ovf; 29777c478bd9Sstevel@tonic-gate 29787c478bd9Sstevel@tonic-gate ill = (ilm->ilm_ill == NULL ? ilm->ilm_ipif->ipif_ill : ilm->ilm_ill); 29797c478bd9Sstevel@tonic-gate 29807c478bd9Sstevel@tonic-gate if (mreclist == NULL) 29817c478bd9Sstevel@tonic-gate return (mreclist); 29827c478bd9Sstevel@tonic-gate 29837c478bd9Sstevel@tonic-gate /* 29847c478bd9Sstevel@tonic-gate * A filter mode change is indicated by a single mrec, which is 29857c478bd9Sstevel@tonic-gate * either TO_IN or TO_EX. In this case, we just need to set new 29867c478bd9Sstevel@tonic-gate * retransmit state as if this were an initial join. There is 29877c478bd9Sstevel@tonic-gate * no change to the mrec list. 29887c478bd9Sstevel@tonic-gate */ 29897c478bd9Sstevel@tonic-gate if (mreclist->mrec_type == CHANGE_TO_INCLUDE || 29907c478bd9Sstevel@tonic-gate mreclist->mrec_type == CHANGE_TO_EXCLUDE) { 29917c478bd9Sstevel@tonic-gate mcast_init_rtx(ill, rtxp, mreclist->mrec_type, 29927c478bd9Sstevel@tonic-gate &mreclist->mrec_srcs); 29937c478bd9Sstevel@tonic-gate return (mreclist); 29947c478bd9Sstevel@tonic-gate } 29957c478bd9Sstevel@tonic-gate 29967c478bd9Sstevel@tonic-gate /* 29977c478bd9Sstevel@tonic-gate * Only the source list has changed 29987c478bd9Sstevel@tonic-gate */ 29997c478bd9Sstevel@tonic-gate rtxp->rtx_cnt = ill->ill_mcast_rv; 30007c478bd9Sstevel@tonic-gate if (rtxp->rtx_fmode_cnt > 0) { 30017c478bd9Sstevel@tonic-gate /* but we're still sending filter mode change reports */ 30027c478bd9Sstevel@tonic-gate rtxp->rtx_fmode_cnt--; 30037c478bd9Sstevel@tonic-gate if (ilm->ilm_fmode == MODE_IS_INCLUDE) { 30047c478bd9Sstevel@tonic-gate CLEAR_SLIST(rtxp->rtx_block); 30057c478bd9Sstevel@tonic-gate COPY_SLIST(flist, rtxp->rtx_allow); 30067c478bd9Sstevel@tonic-gate txtype = CHANGE_TO_INCLUDE; 30077c478bd9Sstevel@tonic-gate } else { 30087c478bd9Sstevel@tonic-gate CLEAR_SLIST(rtxp->rtx_allow); 30097c478bd9Sstevel@tonic-gate COPY_SLIST(flist, rtxp->rtx_block); 30107c478bd9Sstevel@tonic-gate txtype = CHANGE_TO_EXCLUDE; 30117c478bd9Sstevel@tonic-gate } 30127c478bd9Sstevel@tonic-gate /* overwrite first mrec with new info */ 30137c478bd9Sstevel@tonic-gate mreclist->mrec_type = txtype; 30147c478bd9Sstevel@tonic-gate l_copy(flist, &mreclist->mrec_srcs); 30157c478bd9Sstevel@tonic-gate /* then free any remaining mrecs */ 30167c478bd9Sstevel@tonic-gate for (rp = mreclist->mrec_next; rp != NULL; rp = rpnext) { 30177c478bd9Sstevel@tonic-gate rpnext = rp->mrec_next; 30187c478bd9Sstevel@tonic-gate mi_free(rp); 30197c478bd9Sstevel@tonic-gate } 30207c478bd9Sstevel@tonic-gate mreclist->mrec_next = NULL; 30217c478bd9Sstevel@tonic-gate rtnmrec = mreclist; 30227c478bd9Sstevel@tonic-gate } else { 30237c478bd9Sstevel@tonic-gate mrec_t *allow_mrec, *block_mrec; 30247c478bd9Sstevel@tonic-gate /* 30257c478bd9Sstevel@tonic-gate * Just send the source change reports; but we need to 30267c478bd9Sstevel@tonic-gate * recalculate the ALLOW and BLOCK lists based on previous 30277c478bd9Sstevel@tonic-gate * state and new changes. 30287c478bd9Sstevel@tonic-gate */ 30297c478bd9Sstevel@tonic-gate rtnmrec = mreclist; 30307c478bd9Sstevel@tonic-gate allow_mrec = block_mrec = NULL; 30317c478bd9Sstevel@tonic-gate for (rp = mreclist; rp != NULL; rp = rp->mrec_next) { 30327c478bd9Sstevel@tonic-gate ASSERT(rp->mrec_type == ALLOW_NEW_SOURCES || 30337c478bd9Sstevel@tonic-gate rp->mrec_type == BLOCK_OLD_SOURCES); 30347c478bd9Sstevel@tonic-gate if (rp->mrec_type == ALLOW_NEW_SOURCES) 30357c478bd9Sstevel@tonic-gate allow_mrec = rp; 30367c478bd9Sstevel@tonic-gate else 30377c478bd9Sstevel@tonic-gate block_mrec = rp; 30387c478bd9Sstevel@tonic-gate } 30397c478bd9Sstevel@tonic-gate /* 30407c478bd9Sstevel@tonic-gate * Perform calculations: 30417c478bd9Sstevel@tonic-gate * new_allow = mrec_allow + (rtx_allow - mrec_block) 30427c478bd9Sstevel@tonic-gate * new_block = mrec_block + (rtx_block - mrec_allow) 30437c478bd9Sstevel@tonic-gate * 30447c478bd9Sstevel@tonic-gate * Each calc requires two steps, for example: 30457c478bd9Sstevel@tonic-gate * rtx_allow = rtx_allow - mrec_block; 30467c478bd9Sstevel@tonic-gate * new_allow = mrec_allow + rtx_allow; 30477c478bd9Sstevel@tonic-gate * 30487c478bd9Sstevel@tonic-gate * Store results in mrec lists, and then copy into rtx lists. 30497c478bd9Sstevel@tonic-gate * We do it in this order in case the rtx list hasn't been 30507c478bd9Sstevel@tonic-gate * alloc'd yet; if it hasn't and our alloc fails, that's okay, 30517c478bd9Sstevel@tonic-gate * Overflows are also okay. 30527c478bd9Sstevel@tonic-gate */ 30537c478bd9Sstevel@tonic-gate if (block_mrec != NULL) { 30547c478bd9Sstevel@tonic-gate l_difference_in_a(rtxp->rtx_allow, 30557c478bd9Sstevel@tonic-gate &block_mrec->mrec_srcs); 30567c478bd9Sstevel@tonic-gate } 30577c478bd9Sstevel@tonic-gate if (allow_mrec != NULL) { 30587c478bd9Sstevel@tonic-gate l_difference_in_a(rtxp->rtx_block, 30597c478bd9Sstevel@tonic-gate &allow_mrec->mrec_srcs); 30607c478bd9Sstevel@tonic-gate l_union_in_a(&allow_mrec->mrec_srcs, rtxp->rtx_allow, 30617c478bd9Sstevel@tonic-gate &ovf); 30627c478bd9Sstevel@tonic-gate } 30637c478bd9Sstevel@tonic-gate if (block_mrec != NULL) { 30647c478bd9Sstevel@tonic-gate l_union_in_a(&block_mrec->mrec_srcs, rtxp->rtx_block, 30657c478bd9Sstevel@tonic-gate &ovf); 30667c478bd9Sstevel@tonic-gate COPY_SLIST(&block_mrec->mrec_srcs, rtxp->rtx_block); 30677c478bd9Sstevel@tonic-gate } else { 30687c478bd9Sstevel@tonic-gate rtnmrec = mcast_bldmrec(BLOCK_OLD_SOURCES, 30697c478bd9Sstevel@tonic-gate &ilm->ilm_v6addr, rtxp->rtx_block, allow_mrec); 30707c478bd9Sstevel@tonic-gate } 30717c478bd9Sstevel@tonic-gate if (allow_mrec != NULL) { 30727c478bd9Sstevel@tonic-gate COPY_SLIST(&allow_mrec->mrec_srcs, rtxp->rtx_allow); 30737c478bd9Sstevel@tonic-gate } else { 30747c478bd9Sstevel@tonic-gate rtnmrec = mcast_bldmrec(ALLOW_NEW_SOURCES, 30757c478bd9Sstevel@tonic-gate &ilm->ilm_v6addr, rtxp->rtx_allow, block_mrec); 30767c478bd9Sstevel@tonic-gate } 30777c478bd9Sstevel@tonic-gate } 30787c478bd9Sstevel@tonic-gate 30797c478bd9Sstevel@tonic-gate return (rtnmrec); 30807c478bd9Sstevel@tonic-gate } 3081