igmp.c revision 152592
1139823Simp/*-
21541Srgrimes * Copyright (c) 1988 Stephen Deering.
31541Srgrimes * Copyright (c) 1992, 1993
41541Srgrimes *	The Regents of the University of California.  All rights reserved.
51541Srgrimes *
61541Srgrimes * This code is derived from software contributed to Berkeley by
71541Srgrimes * Stephen Deering of Stanford University.
81541Srgrimes *
91541Srgrimes * Redistribution and use in source and binary forms, with or without
101541Srgrimes * modification, are permitted provided that the following conditions
111541Srgrimes * are met:
121541Srgrimes * 1. Redistributions of source code must retain the above copyright
131541Srgrimes *    notice, this list of conditions and the following disclaimer.
141541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
151541Srgrimes *    notice, this list of conditions and the following disclaimer in the
161541Srgrimes *    documentation and/or other materials provided with the distribution.
171541Srgrimes * 4. Neither the name of the University nor the names of its contributors
181541Srgrimes *    may be used to endorse or promote products derived from this software
191541Srgrimes *    without specific prior written permission.
201541Srgrimes *
211541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
221541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
231541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
241541Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
251541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
261541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
271541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
281541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
291541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
301541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
311541Srgrimes * SUCH DAMAGE.
321541Srgrimes *
331541Srgrimes *	@(#)igmp.c	8.1 (Berkeley) 7/19/93
3450477Speter * $FreeBSD: head/sys/netinet/igmp.c 152592 2005-11-18 20:12:40Z andre $
351541Srgrimes */
361541Srgrimes
372531Swollman/*
382531Swollman * Internet Group Management Protocol (IGMP) routines.
392531Swollman *
402531Swollman * Written by Steve Deering, Stanford, May 1988.
412531Swollman * Modified by Rosen Sharma, Stanford, Aug 1994.
429209Swollman * Modified by Bill Fenner, Xerox PARC, Feb 1995.
4314622Sfenner * Modified to fully comply to IGMPv2 by Bill Fenner, Oct 1995.
442531Swollman *
4514622Sfenner * MULTICAST Revision: 3.5.1.4
462531Swollman */
471541Srgrimes
48101091Srwatson#include "opt_mac.h"
49101091Srwatson
501541Srgrimes#include <sys/param.h>
511549Srgrimes#include <sys/systm.h>
52101091Srwatson#include <sys/mac.h>
5329024Sbde#include <sys/malloc.h>
541541Srgrimes#include <sys/mbuf.h>
551541Srgrimes#include <sys/socket.h>
561541Srgrimes#include <sys/protosw.h>
5712296Sphk#include <sys/kernel.h>
586472Swollman#include <sys/sysctl.h>
591541Srgrimes
601541Srgrimes#include <net/if.h>
611541Srgrimes#include <net/route.h>
621541Srgrimes
631541Srgrimes#include <netinet/in.h>
641541Srgrimes#include <netinet/in_var.h>
651541Srgrimes#include <netinet/in_systm.h>
661541Srgrimes#include <netinet/ip.h>
671541Srgrimes#include <netinet/ip_var.h>
68152592Sandre#include <netinet/ip_options.h>
691541Srgrimes#include <netinet/igmp.h>
701541Srgrimes#include <netinet/igmp_var.h>
711541Srgrimes
7260105Sjlemon#include <machine/in_cksum.h>
7360105Sjlemon
7442776Sfennerstatic MALLOC_DEFINE(M_IGMP, "igmp", "igmp state");
7530309Sphk
76119181Srwatsonstatic struct router_info	*find_rti(struct ifnet *ifp);
77119181Srwatsonstatic void	igmp_sendpkt(struct in_multi *, int, unsigned long);
7812579Sbde
7912704Sphkstatic struct igmpstat igmpstat;
802531Swollman
81119181SrwatsonSYSCTL_STRUCT(_net_inet_igmp, IGMPCTL_STATS, stats, CTLFLAG_RW, &igmpstat,
82119181Srwatson    igmpstat, "");
8312296Sphk
84130333Srwatson/*
85130333Srwatson * igmp_mtx protects all mutable global variables in igmp.c, as well as
86130333Srwatson * the data fields in struct router_info.  In general, a router_info
87130333Srwatson * structure will be valid as long as the referencing struct in_multi is
88130333Srwatson * valid, so no reference counting is used.  We allow unlocked reads of
89130333Srwatson * router_info data when accessed via an in_multi read-only.
90130333Srwatson */
91130333Srwatsonstatic struct mtx igmp_mtx;
92119181Srwatsonstatic SLIST_HEAD(, router_info) router_info_head;
939209Swollmanstatic int igmp_timers_are_running;
94130333Srwatson
95130333Srwatson/*
96130333Srwatson * XXXRW: can we define these such that these can be made const?  In any
97130333Srwatson * case, these shouldn't be changed after igmp_init() and therefore don't
98130333Srwatson * need locking.
99130333Srwatson */
1001541Srgrimesstatic u_long igmp_all_hosts_group;
10114622Sfennerstatic u_long igmp_all_rtrs_group;
102130333Srwatson
10314622Sfennerstatic struct mbuf *router_alert;
104119181Srwatsonstatic struct route igmprt;
1051541Srgrimes
106119180Srwatson#ifdef IGMP_DEBUG
107119180Srwatson#define	IGMP_PRINTF(x)	printf(x)
108119180Srwatson#else
109119180Srwatson#define	IGMP_PRINTF(x)
110119180Srwatson#endif
111119180Srwatson
1121541Srgrimesvoid
113119181Srwatsonigmp_init(void)
1141541Srgrimes{
11514622Sfenner	struct ipoption *ra;
11614622Sfenner
1171541Srgrimes	/*
1181541Srgrimes	 * To avoid byte-swapping the same value over and over again.
1191541Srgrimes	 */
1201541Srgrimes	igmp_all_hosts_group = htonl(INADDR_ALLHOSTS_GROUP);
12114622Sfenner	igmp_all_rtrs_group = htonl(INADDR_ALLRTRS_GROUP);
1229209Swollman
1239209Swollman	igmp_timers_are_running = 0;
1249209Swollman
12514622Sfenner	/*
12614622Sfenner	 * Construct a Router Alert option to use in outgoing packets
12714622Sfenner	 */
128111119Simp	MGET(router_alert, M_DONTWAIT, MT_DATA);
12914622Sfenner	ra = mtod(router_alert, struct ipoption *);
13014622Sfenner	ra->ipopt_dst.s_addr = 0;
13114622Sfenner	ra->ipopt_list[0] = IPOPT_RA;	/* Router Alert Option */
13214622Sfenner	ra->ipopt_list[1] = 0x04;	/* 4 bytes long */
13314622Sfenner	ra->ipopt_list[2] = 0x00;
13414622Sfenner	ra->ipopt_list[3] = 0x00;
13514622Sfenner	router_alert->m_len = sizeof(ra->ipopt_dst) + ra->ipopt_list[1];
13614622Sfenner
137130333Srwatson	mtx_init(&igmp_mtx, "igmp_mtx", NULL, MTX_DEF);
138119180Srwatson	SLIST_INIT(&router_info_head);
1391541Srgrimes}
1401541Srgrimes
14112704Sphkstatic struct router_info *
142119181Srwatsonfind_rti(struct ifnet *ifp)
1432531Swollman{
144119180Srwatson	struct router_info *rti;
1452531Swollman
146130333Srwatson	mtx_assert(&igmp_mtx, MA_OWNED);
147119180Srwatson	IGMP_PRINTF("[igmp.c, _find_rti] --> entering \n");
148119180Srwatson	SLIST_FOREACH(rti, &router_info_head, rti_list) {
149119180Srwatson		if (rti->rti_ifp == ifp) {
150119180Srwatson			IGMP_PRINTF(
151119180Srwatson			    "[igmp.c, _find_rti] --> found old entry \n");
152119181Srwatson			return rti;
153119181Srwatson		}
154119181Srwatson	}
15542776Sfenner	MALLOC(rti, struct router_info *, sizeof *rti, M_IGMP, M_NOWAIT);
156144163Ssam	if (rti == NULL) {
157144163Ssam		IGMP_PRINTF( "[igmp.c, _find_rti] --> no memory for entry\n");
158144163Ssam		return NULL;
159144163Ssam	}
160119181Srwatson	rti->rti_ifp = ifp;
161119181Srwatson	rti->rti_type = IGMP_V2_ROUTER;
162119181Srwatson	rti->rti_time = 0;
163119180Srwatson	SLIST_INSERT_HEAD(&router_info_head, rti, rti_list);
164119180Srwatson
165119180Srwatson	IGMP_PRINTF("[igmp.c, _find_rti] --> created an entry \n");
166119181Srwatson	return rti;
1672531Swollman}
1682531Swollman
1691541Srgrimesvoid
170119181Srwatsonigmp_input(register struct mbuf *m, int off)
1711541Srgrimes{
172107113Sluigi	register int iphlen = off;
173107113Sluigi	register struct igmp *igmp;
174107113Sluigi	register struct ip *ip;
175107113Sluigi	register int igmplen;
176107113Sluigi	register struct ifnet *ifp = m->m_pkthdr.rcvif;
177107113Sluigi	register int minlen;
178107113Sluigi	register struct in_multi *inm;
179107113Sluigi	register struct in_ifaddr *ia;
1801541Srgrimes	struct in_multistep step;
1812531Swollman	struct router_info *rti;
1828546Sdg	int timer; /** timer value in the igmp query header **/
1831541Srgrimes
1841541Srgrimes	++igmpstat.igps_rcv_total;
1851541Srgrimes
1861541Srgrimes	ip = mtod(m, struct ip *);
1871541Srgrimes	igmplen = ip->ip_len;
1881541Srgrimes
1891541Srgrimes	/*
1901541Srgrimes	 * Validate lengths
1911541Srgrimes	 */
1921541Srgrimes	if (igmplen < IGMP_MINLEN) {
1931541Srgrimes		++igmpstat.igps_rcv_tooshort;
1941541Srgrimes		m_freem(m);
1951541Srgrimes		return;
1961541Srgrimes	}
1971541Srgrimes	minlen = iphlen + IGMP_MINLEN;
1981541Srgrimes	if ((m->m_flags & M_EXT || m->m_len < minlen) &&
1991541Srgrimes	    (m = m_pullup(m, minlen)) == 0) {
2001541Srgrimes		++igmpstat.igps_rcv_tooshort;
2011541Srgrimes		return;
2021541Srgrimes	}
2031541Srgrimes
2041541Srgrimes	/*
2051541Srgrimes	 * Validate checksum
2061541Srgrimes	 */
2071541Srgrimes	m->m_data += iphlen;
2081541Srgrimes	m->m_len -= iphlen;
2091541Srgrimes	igmp = mtod(m, struct igmp *);
2101541Srgrimes	if (in_cksum(m, igmplen)) {
2111541Srgrimes		++igmpstat.igps_rcv_badsum;
2121541Srgrimes		m_freem(m);
2131541Srgrimes		return;
2141541Srgrimes	}
2151541Srgrimes	m->m_data -= iphlen;
2161541Srgrimes	m->m_len += iphlen;
2172531Swollman
2181541Srgrimes	ip = mtod(m, struct ip *);
2198546Sdg	timer = igmp->igmp_code * PR_FASTHZ / IGMP_TIMER_SCALE;
22041702Sdillon	if (timer == 0)
22141702Sdillon		timer = 1;
2221541Srgrimes
22314622Sfenner	/*
22414622Sfenner	 * In the IGMPv2 specification, there are 3 states and a flag.
22514622Sfenner	 *
22614622Sfenner	 * In Non-Member state, we simply don't have a membership record.
22714622Sfenner	 * In Delaying Member state, our timer is running (inm->inm_timer)
22814622Sfenner	 * In Idle Member state, our timer is not running (inm->inm_timer==0)
22914622Sfenner	 *
23014622Sfenner	 * The flag is inm->inm_state, it is set to IGMP_OTHERMEMBER if
23114622Sfenner	 * we have heard a report from another member, or IGMP_IREPORTEDLAST
23214622Sfenner	 * if I sent the last report.
23314622Sfenner	 */
2341541Srgrimes	switch (igmp->igmp_type) {
23514622Sfenner	case IGMP_MEMBERSHIP_QUERY:
2361541Srgrimes		++igmpstat.igps_rcv_queries;
2371541Srgrimes
2388090Spst		if (ifp->if_flags & IFF_LOOPBACK)
2391541Srgrimes			break;
2401541Srgrimes
2412531Swollman		if (igmp->igmp_code == 0) {
24214622Sfenner			/*
24314622Sfenner			 * Old router.  Remember that the querier on this
24414622Sfenner			 * interface is old, and set the timer to the
24514622Sfenner			 * value in RFC 1112.
24614622Sfenner			 */
2474028Spst
248130333Srwatson			mtx_lock(&igmp_mtx);
249130333Srwatson			rti = find_rti(ifp);
250144163Ssam			if (rti == NULL) {
251144163Ssam				mtx_unlock(&igmp_mtx);
252144163Ssam				m_freem(m);
253144163Ssam				return;
254144163Ssam			}
25514622Sfenner			rti->rti_type = IGMP_V1_ROUTER;
25614622Sfenner			rti->rti_time = 0;
257130333Srwatson			mtx_unlock(&igmp_mtx);
2584028Spst
25914622Sfenner			timer = IGMP_MAX_HOST_REPORT_DELAY * PR_FASTHZ;
2604028Spst
26114622Sfenner			if (ip->ip_dst.s_addr != igmp_all_hosts_group ||
26214622Sfenner			    igmp->igmp_group.s_addr != 0) {
2632531Swollman				++igmpstat.igps_rcv_badqueries;
2642531Swollman				m_freem(m);
2652531Swollman				return;
2662531Swollman			}
26714622Sfenner		} else {
2682531Swollman			/*
26914622Sfenner			 * New router.  Simply do the new validity check.
2702531Swollman			 */
27114622Sfenner
27214622Sfenner			if (igmp->igmp_group.s_addr != 0 &&
27314622Sfenner			    !IN_MULTICAST(ntohl(igmp->igmp_group.s_addr))) {
27414622Sfenner				++igmpstat.igps_rcv_badqueries;
27514622Sfenner				m_freem(m);
27614622Sfenner				return;
27714622Sfenner			}
27814622Sfenner		}
2792531Swollman
28014622Sfenner		/*
28114622Sfenner		 * - Start the timers in all of our membership records
28214622Sfenner		 *   that the query applies to for the interface on
28314622Sfenner		 *   which the query arrived excl. those that belong
28414622Sfenner		 *   to the "all-hosts" group (224.0.0.1).
28514622Sfenner		 * - Restart any timer that is already running but has
28614622Sfenner		 *   a value longer than the requested timeout.
28714622Sfenner		 * - Use the value specified in the query message as
28814622Sfenner		 *   the maximum timeout.
28914622Sfenner		 */
290148682Srwatson		IN_MULTI_LOCK();
29114622Sfenner		IN_FIRST_MULTI(step, inm);
29214622Sfenner		while (inm != NULL) {
29314622Sfenner			if (inm->inm_ifp == ifp &&
29414622Sfenner			    inm->inm_addr.s_addr != igmp_all_hosts_group &&
29514622Sfenner			    (igmp->igmp_group.s_addr == 0 ||
29614622Sfenner			     igmp->igmp_group.s_addr == inm->inm_addr.s_addr)) {
29714622Sfenner				if (inm->inm_timer == 0 ||
29814622Sfenner				    inm->inm_timer > timer) {
29914622Sfenner					inm->inm_timer =
30014622Sfenner						IGMP_RANDOM_DELAY(timer);
3012531Swollman					igmp_timers_are_running = 1;
3022531Swollman				}
3031541Srgrimes			}
3041541Srgrimes			IN_NEXT_MULTI(step, inm);
3051541Srgrimes		}
306148682Srwatson		IN_MULTI_UNLOCK();
3079209Swollman
3081541Srgrimes		break;
3091541Srgrimes
31014622Sfenner	case IGMP_V1_MEMBERSHIP_REPORT:
31114622Sfenner	case IGMP_V2_MEMBERSHIP_REPORT:
3129209Swollman		/*
31314622Sfenner		 * For fast leave to work, we have to know that we are the
31414622Sfenner		 * last person to send a report for this group.  Reports
31514622Sfenner		 * can potentially get looped back if we are a multicast
31614622Sfenner		 * router, so discard reports sourced by me.
3179209Swollman		 */
31814622Sfenner		IFP_TO_IA(ifp, ia);
31914622Sfenner		if (ia && ip->ip_src.s_addr == IA_SIN(ia)->sin_addr.s_addr)
32014622Sfenner			break;
32114622Sfenner
3221541Srgrimes		++igmpstat.igps_rcv_reports;
3231541Srgrimes
3248090Spst		if (ifp->if_flags & IFF_LOOPBACK)
3251541Srgrimes			break;
3261541Srgrimes
32714622Sfenner		if (!IN_MULTICAST(ntohl(igmp->igmp_group.s_addr))) {
3281541Srgrimes			++igmpstat.igps_rcv_badreports;
3291541Srgrimes			m_freem(m);
3301541Srgrimes			return;
3311541Srgrimes		}
3321541Srgrimes
3331541Srgrimes		/*
3341541Srgrimes		 * KLUDGE: if the IP source address of the report has an
3351541Srgrimes		 * unspecified (i.e., zero) subnet number, as is allowed for
3361541Srgrimes		 * a booting host, replace it with the correct subnet number
33796432Sdd		 * so that a process-level multicast routing daemon can
3381541Srgrimes		 * determine which subnet it arrived from.  This is necessary
3391541Srgrimes		 * to compensate for the lack of any way for a process to
3401541Srgrimes		 * determine the arrival interface of an incoming packet.
3411541Srgrimes		 */
34214622Sfenner		if ((ntohl(ip->ip_src.s_addr) & IN_CLASSA_NET) == 0)
3431541Srgrimes			if (ia) ip->ip_src.s_addr = htonl(ia->ia_subnet);
3441541Srgrimes
3451541Srgrimes		/*
3461541Srgrimes		 * If we belong to the group being reported, stop
3471541Srgrimes		 * our timer for that group.
3481541Srgrimes		 */
349148682Srwatson		IN_MULTI_LOCK();
3501541Srgrimes		IN_LOOKUP_MULTI(igmp->igmp_group, ifp, inm);
3512531Swollman		if (inm != NULL) {
35214622Sfenner			inm->inm_timer = 0;
35314622Sfenner			++igmpstat.igps_rcv_ourreports;
35414622Sfenner
35514622Sfenner			inm->inm_state = IGMP_OTHERMEMBER;
3562531Swollman		}
357148682Srwatson		IN_MULTI_UNLOCK();
35814622Sfenner
3591541Srgrimes		break;
3601541Srgrimes	}
3611541Srgrimes
3621541Srgrimes	/*
3631541Srgrimes	 * Pass all valid IGMP packets up to any process(es) listening
3641541Srgrimes	 * on a raw IGMP socket.
3651541Srgrimes	 */
36682890Sjulian	rip_input(m, off);
3671541Srgrimes}
3681541Srgrimes
3691541Srgrimesvoid
370119181Srwatsonigmp_joingroup(struct in_multi *inm)
3711541Srgrimes{
3721541Srgrimes
373148682Srwatson	IN_MULTI_LOCK_ASSERT();
374148682Srwatson
37514622Sfenner	if (inm->inm_addr.s_addr == igmp_all_hosts_group
37614622Sfenner	    || inm->inm_ifp->if_flags & IFF_LOOPBACK) {
3771541Srgrimes		inm->inm_timer = 0;
37814622Sfenner		inm->inm_state = IGMP_OTHERMEMBER;
37914622Sfenner	} else {
380130333Srwatson		mtx_lock(&igmp_mtx);
38114622Sfenner		inm->inm_rti = find_rti(inm->inm_ifp);
382130333Srwatson		mtx_unlock(&igmp_mtx);
383144163Ssam		if (inm->inm_rti != NULL) {
384144163Ssam			igmp_sendpkt(inm, inm->inm_rti->rti_type, 0);
385144163Ssam			inm->inm_timer = IGMP_RANDOM_DELAY(
3862531Swollman					IGMP_MAX_HOST_REPORT_DELAY*PR_FASTHZ);
387144163Ssam			inm->inm_state = IGMP_IREPORTEDLAST;
388144163Ssam			igmp_timers_are_running = 1;
389144163Ssam		}
390144163Ssam		/* XXX handling of failure case? */
3911541Srgrimes	}
3921541Srgrimes}
3931541Srgrimes
3941541Srgrimesvoid
395119181Srwatsonigmp_leavegroup(struct in_multi *inm)
3961541Srgrimes{
397119181Srwatson
398148682Srwatson	IN_MULTI_LOCK_ASSERT();
399148682Srwatson
40014622Sfenner	if (inm->inm_state == IGMP_IREPORTEDLAST &&
40114622Sfenner	    inm->inm_addr.s_addr != igmp_all_hosts_group &&
40214622Sfenner	    !(inm->inm_ifp->if_flags & IFF_LOOPBACK) &&
40314622Sfenner	    inm->inm_rti->rti_type != IGMP_V1_ROUTER)
40414622Sfenner		igmp_sendpkt(inm, IGMP_V2_LEAVE_GROUP, igmp_all_rtrs_group);
4051541Srgrimes}
4061541Srgrimes
4071541Srgrimesvoid
408119181Srwatsonigmp_fasttimo(void)
4091541Srgrimes{
410107113Sluigi	register struct in_multi *inm;
4111541Srgrimes	struct in_multistep step;
4121541Srgrimes
4131541Srgrimes	/*
4141541Srgrimes	 * Quick check to see if any work needs to be done, in order
4151541Srgrimes	 * to minimize the overhead of fasttimo processing.
4161541Srgrimes	 */
4179209Swollman
4181541Srgrimes	if (!igmp_timers_are_running)
4191541Srgrimes		return;
4201541Srgrimes
421148682Srwatson	IN_MULTI_LOCK();
4221541Srgrimes	igmp_timers_are_running = 0;
4231541Srgrimes	IN_FIRST_MULTI(step, inm);
4241541Srgrimes	while (inm != NULL) {
4251541Srgrimes		if (inm->inm_timer == 0) {
4261541Srgrimes			/* do nothing */
4271541Srgrimes		} else if (--inm->inm_timer == 0) {
42814622Sfenner			igmp_sendpkt(inm, inm->inm_rti->rti_type, 0);
42914622Sfenner			inm->inm_state = IGMP_IREPORTEDLAST;
4301541Srgrimes		} else {
4311541Srgrimes			igmp_timers_are_running = 1;
4321541Srgrimes		}
4331541Srgrimes		IN_NEXT_MULTI(step, inm);
4341541Srgrimes	}
435148682Srwatson	IN_MULTI_UNLOCK();
4361541Srgrimes}
4371541Srgrimes
4382531Swollmanvoid
439119181Srwatsonigmp_slowtimo(void)
4402531Swollman{
441119180Srwatson	struct router_info *rti;
4422531Swollman
443119180Srwatson	IGMP_PRINTF("[igmp.c,_slowtimo] -- > entering \n");
444130333Srwatson	mtx_lock(&igmp_mtx);
445119180Srwatson	SLIST_FOREACH(rti, &router_info_head, rti_list) {
446119181Srwatson		if (rti->rti_type == IGMP_V1_ROUTER) {
447119181Srwatson			rti->rti_time++;
448119181Srwatson			if (rti->rti_time >= IGMP_AGE_THRESHOLD)
449119181Srwatson				rti->rti_type = IGMP_V2_ROUTER;
4502531Swollman		}
4512531Swollman	}
452130333Srwatson	mtx_unlock(&igmp_mtx);
453119180Srwatson	IGMP_PRINTF("[igmp.c,_slowtimo] -- > exiting \n");
4542531Swollman}
4552531Swollman
4561541Srgrimesstatic void
457119181Srwatsonigmp_sendpkt(struct in_multi *inm, int type, unsigned long addr)
4581541Srgrimes{
459119181Srwatson	struct mbuf *m;
460119181Srwatson	struct igmp *igmp;
461119181Srwatson	struct ip *ip;
462119181Srwatson	struct ip_moptions imo;
4631541Srgrimes
464148682Srwatson	IN_MULTI_LOCK_ASSERT();
465148682Srwatson
466151967Sandre	MGETHDR(m, M_DONTWAIT, MT_DATA);
467119181Srwatson	if (m == NULL)
468119181Srwatson		return;
4692531Swollman
4708090Spst	m->m_pkthdr.rcvif = loif;
471101091Srwatson#ifdef MAC
472101091Srwatson	mac_create_mbuf_linklayer(inm->inm_ifp, m);
473101091Srwatson#endif
4741541Srgrimes	m->m_pkthdr.len = sizeof(struct ip) + IGMP_MINLEN;
4752531Swollman	MH_ALIGN(m, IGMP_MINLEN + sizeof(struct ip));
4762531Swollman	m->m_data += sizeof(struct ip);
477119181Srwatson	m->m_len = IGMP_MINLEN;
478119181Srwatson	igmp = mtod(m, struct igmp *);
479119181Srwatson	igmp->igmp_type = type;
480119181Srwatson	igmp->igmp_code = 0;
481119181Srwatson	igmp->igmp_group = inm->inm_addr;
482119181Srwatson	igmp->igmp_cksum = 0;
483119181Srwatson	igmp->igmp_cksum = in_cksum(m, IGMP_MINLEN);
4841541Srgrimes
485119181Srwatson	m->m_data -= sizeof(struct ip);
486119181Srwatson	m->m_len += sizeof(struct ip);
487119181Srwatson	ip = mtod(m, struct ip *);
488119181Srwatson	ip->ip_tos = 0;
489119181Srwatson	ip->ip_len = sizeof(struct ip) + IGMP_MINLEN;
490119181Srwatson	ip->ip_off = 0;
491119181Srwatson	ip->ip_p = IPPROTO_IGMP;
492119181Srwatson	ip->ip_src.s_addr = INADDR_ANY;
493119181Srwatson	ip->ip_dst.s_addr = addr ? addr : igmp->igmp_group.s_addr;
4941541Srgrimes
495119181Srwatson	imo.imo_multicast_ifp  = inm->inm_ifp;
496119181Srwatson	imo.imo_multicast_ttl  = 1;
49715292Swollman	imo.imo_multicast_vif  = -1;
498119181Srwatson	/*
499119181Srwatson	 * Request loopback of the report if we are acting as a multicast
500119181Srwatson	 * router, so that the process-level routing daemon can hear it.
501119181Srwatson	 */
502119181Srwatson	imo.imo_multicast_loop = (ip_mrouter != NULL);
5031541Srgrimes
50415292Swollman	/*
50515292Swollman	 * XXX
50615292Swollman	 * Do we have to worry about reentrancy here?  Don't think so.
50715292Swollman	 */
508119181Srwatson	ip_output(m, router_alert, &igmprt, 0, &imo, NULL);
5092531Swollman
510119181Srwatson	++igmpstat.igps_snd_reports;
5111541Srgrimes}
512