2011-07-18 00:54:30 +04:00
|
|
|
/* $NetBSD: igmp.c,v 1.52 2011/07/17 20:54:53 joerg Exp $ */
|
1999-07-01 12:12:45 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
|
|
|
|
* All rights reserved.
|
2002-06-09 20:33:36 +04:00
|
|
|
*
|
1999-07-01 12:12:45 +04:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. Neither the name of the project nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
2002-06-09 20:33:36 +04:00
|
|
|
*
|
1999-07-01 12:12:45 +04:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
1994-06-29 10:29:24 +04:00
|
|
|
|
1993-12-06 07:50:19 +03:00
|
|
|
/*
|
1995-05-31 10:08:17 +04:00
|
|
|
* Internet Group Management Protocol (IGMP) routines.
|
1993-12-06 07:50:19 +03:00
|
|
|
*
|
1995-05-31 10:08:17 +04:00
|
|
|
* Written by Steve Deering, Stanford, May 1988.
|
|
|
|
* Modified by Rosen Sharma, Stanford, Aug 1994.
|
|
|
|
* Modified by Bill Fenner, Xerox PARC, Feb 1995.
|
1993-12-06 07:50:19 +03:00
|
|
|
*
|
1995-05-31 10:08:17 +04:00
|
|
|
* MULTICAST Revision: 1.3
|
1993-12-06 07:50:19 +03:00
|
|
|
*/
|
|
|
|
|
2001-11-13 03:32:34 +03:00
|
|
|
#include <sys/cdefs.h>
|
2011-07-18 00:54:30 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: igmp.c,v 1.52 2011/07/17 20:54:53 joerg Exp $");
|
2001-11-13 03:32:34 +03:00
|
|
|
|
1998-01-12 06:02:48 +03:00
|
|
|
#include "opt_mrouting.h"
|
|
|
|
|
1993-12-06 07:50:19 +03:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/socket.h>
|
2008-04-24 15:38:36 +04:00
|
|
|
#include <sys/socketvar.h>
|
1993-12-06 07:50:19 +03:00
|
|
|
#include <sys/protosw.h>
|
1996-02-14 02:40:59 +03:00
|
|
|
#include <sys/systm.h>
|
2008-04-15 20:02:03 +04:00
|
|
|
#include <sys/sysctl.h>
|
1993-12-06 07:50:19 +03:00
|
|
|
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/route.h>
|
2008-04-23 09:26:50 +04:00
|
|
|
#include <net/net_stats.h>
|
1993-12-06 07:50:19 +03:00
|
|
|
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/in_var.h>
|
|
|
|
#include <netinet/in_systm.h>
|
|
|
|
#include <netinet/ip.h>
|
|
|
|
#include <netinet/ip_var.h>
|
|
|
|
#include <netinet/igmp.h>
|
|
|
|
#include <netinet/igmp_var.h>
|
|
|
|
|
1995-05-31 10:08:17 +04:00
|
|
|
#define IP_MULTICASTOPTS 0
|
1993-12-06 07:50:19 +03:00
|
|
|
|
2009-09-13 22:45:10 +04:00
|
|
|
static struct pool igmp_rti_pool;
|
2008-04-15 20:02:03 +04:00
|
|
|
|
|
|
|
static percpu_t *igmpstat_percpu;
|
|
|
|
|
2008-04-23 09:26:50 +04:00
|
|
|
#define IGMP_STATINC(x) _NET_STATINC(igmpstat_percpu, x)
|
2008-04-15 20:02:03 +04:00
|
|
|
|
2000-06-17 00:21:26 +04:00
|
|
|
int igmp_timers_are_running;
|
2003-06-15 06:49:32 +04:00
|
|
|
static LIST_HEAD(, router_info) rti_head = LIST_HEAD_INITIALIZER(rti_head);
|
1995-05-31 10:08:17 +04:00
|
|
|
|
2005-02-03 00:41:55 +03:00
|
|
|
void igmp_sendpkt(struct in_multi *, int);
|
|
|
|
static int rti_fill(struct in_multi *);
|
|
|
|
static struct router_info *rti_find(struct ifnet *);
|
2003-06-26 07:11:08 +04:00
|
|
|
static void rti_delete(struct ifnet *);
|
1993-12-06 07:50:19 +03:00
|
|
|
|
2009-09-16 19:23:04 +04:00
|
|
|
static void sysctl_net_inet_igmp_setup(struct sysctllog **);
|
|
|
|
|
1995-05-31 10:08:17 +04:00
|
|
|
static int
|
2005-02-03 06:49:01 +03:00
|
|
|
rti_fill(struct in_multi *inm)
|
1995-05-31 10:08:17 +04:00
|
|
|
{
|
2000-03-30 16:51:13 +04:00
|
|
|
struct router_info *rti;
|
1995-05-31 10:08:17 +04:00
|
|
|
|
2006-10-05 21:35:19 +04:00
|
|
|
/* this function is called at splsoftnet() */
|
2003-06-15 06:49:32 +04:00
|
|
|
LIST_FOREACH(rti, &rti_head, rti_link) {
|
1995-05-31 10:08:17 +04:00
|
|
|
if (rti->rti_ifp == inm->inm_ifp) {
|
|
|
|
inm->inm_rti = rti;
|
|
|
|
if (rti->rti_type == IGMP_v1_ROUTER)
|
|
|
|
return (IGMP_v1_HOST_MEMBERSHIP_REPORT);
|
|
|
|
else
|
|
|
|
return (IGMP_v2_HOST_MEMBERSHIP_REPORT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-06-15 06:49:32 +04:00
|
|
|
rti = pool_get(&igmp_rti_pool, PR_NOWAIT);
|
|
|
|
if (rti == NULL)
|
|
|
|
return 0;
|
1995-05-31 10:08:17 +04:00
|
|
|
rti->rti_ifp = inm->inm_ifp;
|
|
|
|
rti->rti_type = IGMP_v2_ROUTER;
|
2003-06-15 06:49:32 +04:00
|
|
|
LIST_INSERT_HEAD(&rti_head, rti, rti_link);
|
1995-05-31 10:08:17 +04:00
|
|
|
inm->inm_rti = rti;
|
|
|
|
return (IGMP_v2_HOST_MEMBERSHIP_REPORT);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct router_info *
|
2005-02-03 06:49:01 +03:00
|
|
|
rti_find(struct ifnet *ifp)
|
1995-05-31 10:08:17 +04:00
|
|
|
{
|
2000-03-30 16:51:13 +04:00
|
|
|
struct router_info *rti;
|
2006-10-05 21:35:19 +04:00
|
|
|
int s = splsoftnet();
|
1995-05-31 10:08:17 +04:00
|
|
|
|
2003-06-15 06:49:32 +04:00
|
|
|
LIST_FOREACH(rti, &rti_head, rti_link) {
|
1995-05-31 10:08:17 +04:00
|
|
|
if (rti->rti_ifp == ifp)
|
|
|
|
return (rti);
|
|
|
|
}
|
|
|
|
|
2003-06-15 06:49:32 +04:00
|
|
|
rti = pool_get(&igmp_rti_pool, PR_NOWAIT);
|
2006-10-05 21:35:19 +04:00
|
|
|
if (rti == NULL) {
|
|
|
|
splx(s);
|
2003-06-15 06:49:32 +04:00
|
|
|
return NULL;
|
2006-10-05 21:35:19 +04:00
|
|
|
}
|
1995-05-31 10:08:17 +04:00
|
|
|
rti->rti_ifp = ifp;
|
|
|
|
rti->rti_type = IGMP_v2_ROUTER;
|
2003-06-15 06:49:32 +04:00
|
|
|
LIST_INSERT_HEAD(&rti_head, rti, rti_link);
|
2006-10-05 21:35:19 +04:00
|
|
|
splx(s);
|
1995-05-31 10:08:17 +04:00
|
|
|
return (rti);
|
1993-12-06 07:50:19 +03:00
|
|
|
}
|
|
|
|
|
2003-06-26 07:11:08 +04:00
|
|
|
static void
|
2006-10-05 21:35:19 +04:00
|
|
|
rti_delete(struct ifnet *ifp) /* MUST be called at splsoftnet */
|
2003-06-26 07:11:08 +04:00
|
|
|
{
|
|
|
|
struct router_info *rti;
|
|
|
|
|
|
|
|
LIST_FOREACH(rti, &rti_head, rti_link) {
|
|
|
|
if (rti->rti_ifp == ifp) {
|
|
|
|
LIST_REMOVE(rti, rti_link);
|
|
|
|
pool_put(&igmp_rti_pool, rti);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-15 20:02:03 +04:00
|
|
|
void
|
|
|
|
igmp_init(void)
|
|
|
|
{
|
|
|
|
|
2009-09-16 19:23:04 +04:00
|
|
|
sysctl_net_inet_igmp_setup(NULL);
|
2009-09-13 22:45:10 +04:00
|
|
|
pool_init(&igmp_rti_pool, sizeof(struct router_info), 0, 0, 0,
|
|
|
|
"igmppl", NULL, IPL_SOFTNET);
|
2008-04-15 20:02:03 +04:00
|
|
|
igmpstat_percpu = percpu_alloc(sizeof(uint64_t) * IGMP_NSTATS);
|
|
|
|
}
|
|
|
|
|
1993-12-06 07:50:19 +03:00
|
|
|
void
|
1996-02-14 02:40:59 +03:00
|
|
|
igmp_input(struct mbuf *m, ...)
|
1993-12-06 07:50:19 +03:00
|
|
|
{
|
1999-07-01 12:12:45 +04:00
|
|
|
int proto;
|
2000-03-30 16:51:13 +04:00
|
|
|
int iphlen;
|
|
|
|
struct ifnet *ifp = m->m_pkthdr.rcvif;
|
|
|
|
struct ip *ip = mtod(m, struct ip *);
|
|
|
|
struct igmp *igmp;
|
2002-11-07 10:15:19 +03:00
|
|
|
u_int minlen;
|
1995-05-31 10:08:17 +04:00
|
|
|
struct in_multi *inm;
|
1993-12-06 07:50:19 +03:00
|
|
|
struct in_multistep step;
|
1995-05-31 10:08:17 +04:00
|
|
|
struct router_info *rti;
|
2000-03-30 16:51:13 +04:00
|
|
|
struct in_ifaddr *ia;
|
2002-11-07 10:15:19 +03:00
|
|
|
u_int timer;
|
1996-02-14 02:40:59 +03:00
|
|
|
va_list ap;
|
2002-08-14 04:23:27 +04:00
|
|
|
u_int16_t ip_len;
|
1996-02-14 02:40:59 +03:00
|
|
|
|
|
|
|
va_start(ap, m);
|
|
|
|
iphlen = va_arg(ap, int);
|
1999-07-01 12:12:45 +04:00
|
|
|
proto = va_arg(ap, int);
|
1996-02-14 02:40:59 +03:00
|
|
|
va_end(ap);
|
1993-12-06 07:50:19 +03:00
|
|
|
|
2008-04-15 20:02:03 +04:00
|
|
|
IGMP_STATINC(IGMP_STAT_RCV_TOTAL);
|
1993-12-06 07:50:19 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Validate lengths
|
|
|
|
*/
|
1999-01-20 02:03:20 +03:00
|
|
|
minlen = iphlen + IGMP_MINLEN;
|
2002-08-14 04:23:27 +04:00
|
|
|
ip_len = ntohs(ip->ip_len);
|
|
|
|
if (ip_len < minlen) {
|
2008-04-15 20:02:03 +04:00
|
|
|
IGMP_STATINC(IGMP_STAT_RCV_TOOSHORT);
|
1993-12-06 07:50:19 +03:00
|
|
|
m_freem(m);
|
|
|
|
return;
|
|
|
|
}
|
2000-06-17 00:21:26 +04:00
|
|
|
if (((m->m_flags & M_EXT) && (ip->ip_src.s_addr & IN_CLASSA_NET) == 0)
|
|
|
|
|| m->m_len < minlen) {
|
|
|
|
if ((m = m_pullup(m, minlen)) == 0) {
|
2008-04-15 20:02:03 +04:00
|
|
|
IGMP_STATINC(IGMP_STAT_RCV_TOOSHORT);
|
2000-06-17 00:21:26 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
ip = mtod(m, struct ip *);
|
1993-12-06 07:50:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Validate checksum
|
|
|
|
*/
|
|
|
|
m->m_data += iphlen;
|
|
|
|
m->m_len -= iphlen;
|
|
|
|
igmp = mtod(m, struct igmp *);
|
Changes to allow the IPv4 and IPv6 layers to align headers themseves,
as necessary:
* Implement a new mbuf utility routine, m_copyup(), is is like
m_pullup(), except that it always prepends and copies, rather
than only doing so if the desired length is larger than m->m_len.
m_copyup() also allows an offset into the destination mbuf, which
allows space for packet headers, in the forwarding case.
* Add *_HDR_ALIGNED_P() macros for IP, IPv6, ICMP, and IGMP. These
macros expand to 1 if __NO_STRICT_ALIGNMENT is defined, so that
architectures which do not have strict alignment constraints don't
pay for the test or visit the new align-if-needed path.
* Use the new macros to check if a header needs to be aligned, or to
assert that it already is, as appropriate.
Note: This code is still somewhat experimental. However, the new
code path won't be visited if individual device drivers continue
to guarantee that packets are delivered to layer 3 already properly
aligned (which are rules that are already in use).
2002-07-01 02:40:32 +04:00
|
|
|
/* No need to assert alignment here. */
|
2002-08-14 04:23:27 +04:00
|
|
|
if (in_cksum(m, ip_len - iphlen)) {
|
2008-04-15 20:02:03 +04:00
|
|
|
IGMP_STATINC(IGMP_STAT_RCV_BADSUM);
|
1993-12-06 07:50:19 +03:00
|
|
|
m_freem(m);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m->m_data -= iphlen;
|
|
|
|
m->m_len += iphlen;
|
|
|
|
|
|
|
|
switch (igmp->igmp_type) {
|
|
|
|
|
|
|
|
case IGMP_HOST_MEMBERSHIP_QUERY:
|
2008-04-15 20:02:03 +04:00
|
|
|
IGMP_STATINC(IGMP_STAT_RCV_QUERIES);
|
1993-12-06 07:50:19 +03:00
|
|
|
|
1994-06-04 12:13:23 +04:00
|
|
|
if (ifp->if_flags & IFF_LOOPBACK)
|
1993-12-06 07:50:19 +03:00
|
|
|
break;
|
|
|
|
|
1995-05-31 10:08:17 +04:00
|
|
|
if (igmp->igmp_code == 0) {
|
|
|
|
rti = rti_find(ifp);
|
2003-06-15 06:49:32 +04:00
|
|
|
if (rti == NULL)
|
|
|
|
break;
|
1995-05-31 10:08:17 +04:00
|
|
|
rti->rti_type = IGMP_v1_ROUTER;
|
|
|
|
rti->rti_age = 0;
|
|
|
|
|
1995-06-02 01:35:34 +04:00
|
|
|
if (ip->ip_dst.s_addr != INADDR_ALLHOSTS_GROUP) {
|
2008-04-15 20:02:03 +04:00
|
|
|
IGMP_STATINC(IGMP_STAT_RCV_BADQUERIES);
|
1995-05-31 10:08:17 +04:00
|
|
|
m_freem(m);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Start the timers in all of our membership records
|
|
|
|
* for the interface on which the query arrived,
|
|
|
|
* except those that are already running and those
|
|
|
|
* that belong to a "local" group (224.0.0.X).
|
|
|
|
*/
|
|
|
|
IN_FIRST_MULTI(step, inm);
|
|
|
|
while (inm != NULL) {
|
|
|
|
if (inm->inm_ifp == ifp &&
|
|
|
|
inm->inm_timer == 0 &&
|
|
|
|
!IN_LOCAL_GROUP(inm->inm_addr.s_addr)) {
|
|
|
|
inm->inm_state = IGMP_DELAYING_MEMBER;
|
|
|
|
inm->inm_timer = IGMP_RANDOM_DELAY(
|
|
|
|
IGMP_MAX_HOST_REPORT_DELAY * PR_FASTHZ);
|
|
|
|
igmp_timers_are_running = 1;
|
|
|
|
}
|
|
|
|
IN_NEXT_MULTI(step, inm);
|
|
|
|
}
|
|
|
|
} else {
|
1995-06-02 01:35:34 +04:00
|
|
|
if (!IN_MULTICAST(ip->ip_dst.s_addr)) {
|
2008-04-15 20:02:03 +04:00
|
|
|
IGMP_STATINC(IGMP_STAT_RCV_BADQUERIES);
|
1995-05-31 10:08:17 +04:00
|
|
|
m_freem(m);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
timer = igmp->igmp_code * PR_FASTHZ / IGMP_TIMER_SCALE;
|
1999-04-25 14:26:29 +04:00
|
|
|
if (timer == 0)
|
|
|
|
timer =1;
|
1995-05-31 10:08:17 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Start the timers in all of our membership records
|
|
|
|
* for the interface on which the query arrived,
|
|
|
|
* except those that are already running and those
|
|
|
|
* that belong to a "local" group (224.0.0.X). For
|
|
|
|
* timers already running, check if they need to be
|
|
|
|
* reset.
|
|
|
|
*/
|
|
|
|
IN_FIRST_MULTI(step, inm);
|
|
|
|
while (inm != NULL) {
|
|
|
|
if (inm->inm_ifp == ifp &&
|
|
|
|
!IN_LOCAL_GROUP(inm->inm_addr.s_addr) &&
|
1995-06-02 01:35:34 +04:00
|
|
|
(ip->ip_dst.s_addr == INADDR_ALLHOSTS_GROUP ||
|
1996-09-09 18:51:07 +04:00
|
|
|
in_hosteq(ip->ip_dst, inm->inm_addr))) {
|
1995-05-31 10:08:17 +04:00
|
|
|
switch (inm->inm_state) {
|
|
|
|
case IGMP_DELAYING_MEMBER:
|
|
|
|
if (inm->inm_timer <= timer)
|
|
|
|
break;
|
|
|
|
/* FALLTHROUGH */
|
|
|
|
case IGMP_IDLE_MEMBER:
|
|
|
|
case IGMP_LAZY_MEMBER:
|
|
|
|
case IGMP_AWAKENING_MEMBER:
|
|
|
|
inm->inm_state =
|
|
|
|
IGMP_DELAYING_MEMBER;
|
|
|
|
inm->inm_timer =
|
|
|
|
IGMP_RANDOM_DELAY(timer);
|
|
|
|
igmp_timers_are_running = 1;
|
|
|
|
break;
|
|
|
|
case IGMP_SLEEPING_MEMBER:
|
|
|
|
inm->inm_state =
|
|
|
|
IGMP_AWAKENING_MEMBER;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
IN_NEXT_MULTI(step, inm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IGMP_v1_HOST_MEMBERSHIP_REPORT:
|
2008-04-15 20:02:03 +04:00
|
|
|
IGMP_STATINC(IGMP_STAT_RCV_REPORTS);
|
1995-05-31 10:08:17 +04:00
|
|
|
|
|
|
|
if (ifp->if_flags & IFF_LOOPBACK)
|
|
|
|
break;
|
|
|
|
|
1995-06-02 01:35:34 +04:00
|
|
|
if (!IN_MULTICAST(igmp->igmp_group.s_addr) ||
|
1996-09-09 18:51:07 +04:00
|
|
|
!in_hosteq(igmp->igmp_group, ip->ip_dst)) {
|
2008-04-15 20:02:03 +04:00
|
|
|
IGMP_STATINC(IGMP_STAT_RCV_BADREPORTS);
|
1993-12-06 07:50:19 +03:00
|
|
|
m_freem(m);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1995-05-31 10:08:17 +04:00
|
|
|
* KLUDGE: if the IP source address of the report has an
|
|
|
|
* unspecified (i.e., zero) subnet number, as is allowed for
|
|
|
|
* a booting host, replace it with the correct subnet number
|
|
|
|
* so that a process-level multicast routing daemon can
|
|
|
|
* determine which subnet it arrived from. This is necessary
|
|
|
|
* to compensate for the lack of any way for a process to
|
|
|
|
* determine the arrival interface of an incoming packet.
|
1993-12-06 07:50:19 +03:00
|
|
|
*/
|
1995-06-02 01:35:34 +04:00
|
|
|
if ((ip->ip_src.s_addr & IN_CLASSA_NET) == 0) {
|
1998-02-13 21:21:38 +03:00
|
|
|
IFP_TO_IA(ifp, ia); /* XXX */
|
1995-05-31 10:08:17 +04:00
|
|
|
if (ia)
|
1995-06-02 01:35:34 +04:00
|
|
|
ip->ip_src.s_addr = ia->ia_subnet;
|
1995-05-31 10:08:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we belong to the group being reported, stop
|
|
|
|
* our timer for that group.
|
|
|
|
*/
|
|
|
|
IN_LOOKUP_MULTI(igmp->igmp_group, ifp, inm);
|
|
|
|
if (inm != NULL) {
|
|
|
|
inm->inm_timer = 0;
|
2008-04-15 20:02:03 +04:00
|
|
|
IGMP_STATINC(IGMP_STAT_RCV_OURREPORTS);
|
1995-05-31 10:08:17 +04:00
|
|
|
|
|
|
|
switch (inm->inm_state) {
|
|
|
|
case IGMP_IDLE_MEMBER:
|
|
|
|
case IGMP_LAZY_MEMBER:
|
|
|
|
case IGMP_AWAKENING_MEMBER:
|
|
|
|
case IGMP_SLEEPING_MEMBER:
|
|
|
|
inm->inm_state = IGMP_SLEEPING_MEMBER;
|
|
|
|
break;
|
|
|
|
case IGMP_DELAYING_MEMBER:
|
|
|
|
if (inm->inm_rti->rti_type == IGMP_v1_ROUTER)
|
|
|
|
inm->inm_state = IGMP_LAZY_MEMBER;
|
|
|
|
else
|
|
|
|
inm->inm_state = IGMP_SLEEPING_MEMBER;
|
|
|
|
break;
|
1993-12-06 07:50:19 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
1995-05-31 10:08:17 +04:00
|
|
|
case IGMP_v2_HOST_MEMBERSHIP_REPORT:
|
|
|
|
#ifdef MROUTING
|
|
|
|
/*
|
|
|
|
* Make sure we don't hear our own membership report. Fast
|
|
|
|
* leave requires knowing that we are the only member of a
|
|
|
|
* group.
|
|
|
|
*/
|
1998-02-13 21:21:38 +03:00
|
|
|
IFP_TO_IA(ifp, ia); /* XXX */
|
1996-09-09 18:51:07 +04:00
|
|
|
if (ia && in_hosteq(ip->ip_src, ia->ia_addr.sin_addr))
|
1995-05-31 10:08:17 +04:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
2008-04-15 20:02:03 +04:00
|
|
|
IGMP_STATINC(IGMP_STAT_RCV_REPORTS);
|
1993-12-06 07:50:19 +03:00
|
|
|
|
1994-06-04 12:13:23 +04:00
|
|
|
if (ifp->if_flags & IFF_LOOPBACK)
|
1993-12-06 07:50:19 +03:00
|
|
|
break;
|
|
|
|
|
1995-06-02 01:35:34 +04:00
|
|
|
if (!IN_MULTICAST(igmp->igmp_group.s_addr) ||
|
1996-09-09 18:51:07 +04:00
|
|
|
!in_hosteq(igmp->igmp_group, ip->ip_dst)) {
|
2008-04-15 20:02:03 +04:00
|
|
|
IGMP_STATINC(IGMP_STAT_RCV_BADREPORTS);
|
1993-12-06 07:50:19 +03:00
|
|
|
m_freem(m);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* KLUDGE: if the IP source address of the report has an
|
|
|
|
* unspecified (i.e., zero) subnet number, as is allowed for
|
|
|
|
* a booting host, replace it with the correct subnet number
|
1995-05-31 10:08:17 +04:00
|
|
|
* so that a process-level multicast routing daemon can
|
1993-12-06 07:50:19 +03:00
|
|
|
* determine which subnet it arrived from. This is necessary
|
|
|
|
* to compensate for the lack of any way for a process to
|
|
|
|
* determine the arrival interface of an incoming packet.
|
|
|
|
*/
|
1995-06-02 01:35:34 +04:00
|
|
|
if ((ip->ip_src.s_addr & IN_CLASSA_NET) == 0) {
|
1995-05-31 10:08:17 +04:00
|
|
|
#ifndef MROUTING
|
1998-02-13 21:21:38 +03:00
|
|
|
IFP_TO_IA(ifp, ia); /* XXX */
|
1995-05-31 10:08:17 +04:00
|
|
|
#endif
|
|
|
|
if (ia)
|
1995-06-02 01:35:34 +04:00
|
|
|
ip->ip_src.s_addr = ia->ia_subnet;
|
1993-12-06 07:50:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we belong to the group being reported, stop
|
|
|
|
* our timer for that group.
|
|
|
|
*/
|
|
|
|
IN_LOOKUP_MULTI(igmp->igmp_group, ifp, inm);
|
|
|
|
if (inm != NULL) {
|
|
|
|
inm->inm_timer = 0;
|
2008-04-15 20:02:03 +04:00
|
|
|
IGMP_STATINC(IGMP_STAT_RCV_OURREPORTS);
|
1995-05-31 10:08:17 +04:00
|
|
|
|
|
|
|
switch (inm->inm_state) {
|
|
|
|
case IGMP_DELAYING_MEMBER:
|
|
|
|
case IGMP_IDLE_MEMBER:
|
|
|
|
case IGMP_AWAKENING_MEMBER:
|
|
|
|
inm->inm_state = IGMP_LAZY_MEMBER;
|
|
|
|
break;
|
|
|
|
case IGMP_LAZY_MEMBER:
|
|
|
|
case IGMP_SLEEPING_MEMBER:
|
|
|
|
break;
|
|
|
|
}
|
1993-12-06 07:50:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
1995-05-31 10:08:17 +04:00
|
|
|
|
1993-12-06 07:50:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Pass all valid IGMP packets up to any process(es) listening
|
|
|
|
* on a raw IGMP socket.
|
|
|
|
*/
|
1999-07-01 12:12:45 +04:00
|
|
|
rip_input(m, iphlen, proto);
|
|
|
|
return;
|
1993-12-06 07:50:19 +03:00
|
|
|
}
|
|
|
|
|
2003-06-15 06:49:32 +04:00
|
|
|
int
|
2005-02-03 06:49:01 +03:00
|
|
|
igmp_joingroup(struct in_multi *inm)
|
1993-12-06 07:50:19 +03:00
|
|
|
{
|
2003-06-15 06:49:32 +04:00
|
|
|
int report_type;
|
1995-08-13 03:59:09 +04:00
|
|
|
int s = splsoftnet();
|
1993-12-06 07:50:19 +03:00
|
|
|
|
1995-05-31 10:08:17 +04:00
|
|
|
inm->inm_state = IGMP_IDLE_MEMBER;
|
|
|
|
|
|
|
|
if (!IN_LOCAL_GROUP(inm->inm_addr.s_addr) &&
|
|
|
|
(inm->inm_ifp->if_flags & IFF_LOOPBACK) == 0) {
|
2003-06-15 06:49:32 +04:00
|
|
|
report_type = rti_fill(inm);
|
2004-11-13 22:17:50 +03:00
|
|
|
if (report_type == 0) {
|
|
|
|
splx(s);
|
2003-06-15 06:49:32 +04:00
|
|
|
return ENOMEM;
|
2004-11-13 22:17:50 +03:00
|
|
|
}
|
2003-06-15 06:49:32 +04:00
|
|
|
igmp_sendpkt(inm, report_type);
|
1995-05-31 10:08:17 +04:00
|
|
|
inm->inm_state = IGMP_DELAYING_MEMBER;
|
|
|
|
inm->inm_timer = IGMP_RANDOM_DELAY(
|
|
|
|
IGMP_MAX_HOST_REPORT_DELAY * PR_FASTHZ);
|
1993-12-06 07:50:19 +03:00
|
|
|
igmp_timers_are_running = 1;
|
1995-05-31 10:08:17 +04:00
|
|
|
} else
|
|
|
|
inm->inm_timer = 0;
|
1993-12-06 07:50:19 +03:00
|
|
|
splx(s);
|
2003-06-15 06:49:32 +04:00
|
|
|
return 0;
|
1993-12-06 07:50:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2005-02-03 06:49:01 +03:00
|
|
|
igmp_leavegroup(struct in_multi *inm)
|
1993-12-06 07:50:19 +03:00
|
|
|
{
|
1995-05-31 10:08:17 +04:00
|
|
|
|
|
|
|
switch (inm->inm_state) {
|
|
|
|
case IGMP_DELAYING_MEMBER:
|
|
|
|
case IGMP_IDLE_MEMBER:
|
|
|
|
if (!IN_LOCAL_GROUP(inm->inm_addr.s_addr) &&
|
|
|
|
(inm->inm_ifp->if_flags & IFF_LOOPBACK) == 0)
|
|
|
|
if (inm->inm_rti->rti_type != IGMP_v1_ROUTER)
|
|
|
|
igmp_sendpkt(inm, IGMP_HOST_LEAVE_MESSAGE);
|
|
|
|
break;
|
|
|
|
case IGMP_LAZY_MEMBER:
|
|
|
|
case IGMP_AWAKENING_MEMBER:
|
|
|
|
case IGMP_SLEEPING_MEMBER:
|
|
|
|
break;
|
|
|
|
}
|
1993-12-06 07:50:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2005-02-03 06:49:01 +03:00
|
|
|
igmp_fasttimo(void)
|
1993-12-06 07:50:19 +03:00
|
|
|
{
|
2000-03-30 16:51:13 +04:00
|
|
|
struct in_multi *inm;
|
1993-12-06 07:50:19 +03:00
|
|
|
struct in_multistep step;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Quick check to see if any work needs to be done, in order
|
|
|
|
* to minimize the overhead of fasttimo processing.
|
|
|
|
*/
|
|
|
|
if (!igmp_timers_are_running)
|
|
|
|
return;
|
|
|
|
|
2008-04-24 15:38:36 +04:00
|
|
|
mutex_enter(softnet_lock);
|
|
|
|
KERNEL_LOCK(1, NULL);
|
|
|
|
|
1993-12-06 07:50:19 +03:00
|
|
|
igmp_timers_are_running = 0;
|
|
|
|
IN_FIRST_MULTI(step, inm);
|
|
|
|
while (inm != NULL) {
|
|
|
|
if (inm->inm_timer == 0) {
|
|
|
|
/* do nothing */
|
|
|
|
} else if (--inm->inm_timer == 0) {
|
1995-05-31 10:08:17 +04:00
|
|
|
if (inm->inm_state == IGMP_DELAYING_MEMBER) {
|
|
|
|
if (inm->inm_rti->rti_type == IGMP_v1_ROUTER)
|
|
|
|
igmp_sendpkt(inm,
|
|
|
|
IGMP_v1_HOST_MEMBERSHIP_REPORT);
|
|
|
|
else
|
|
|
|
igmp_sendpkt(inm,
|
|
|
|
IGMP_v2_HOST_MEMBERSHIP_REPORT);
|
|
|
|
inm->inm_state = IGMP_IDLE_MEMBER;
|
|
|
|
}
|
1993-12-06 07:50:19 +03:00
|
|
|
} else {
|
|
|
|
igmp_timers_are_running = 1;
|
|
|
|
}
|
|
|
|
IN_NEXT_MULTI(step, inm);
|
|
|
|
}
|
2008-04-24 15:38:36 +04:00
|
|
|
|
|
|
|
KERNEL_UNLOCK_ONE(NULL);
|
|
|
|
mutex_exit(softnet_lock);
|
1993-12-06 07:50:19 +03:00
|
|
|
}
|
|
|
|
|
1995-05-31 10:08:17 +04:00
|
|
|
void
|
2005-02-03 06:49:01 +03:00
|
|
|
igmp_slowtimo(void)
|
1993-12-06 07:50:19 +03:00
|
|
|
{
|
2000-03-30 16:51:13 +04:00
|
|
|
struct router_info *rti;
|
1995-05-31 10:08:17 +04:00
|
|
|
|
2008-04-24 15:38:36 +04:00
|
|
|
mutex_enter(softnet_lock);
|
|
|
|
KERNEL_LOCK(1, NULL);
|
2003-06-15 06:49:32 +04:00
|
|
|
LIST_FOREACH(rti, &rti_head, rti_link) {
|
1995-05-31 10:08:17 +04:00
|
|
|
if (rti->rti_type == IGMP_v1_ROUTER &&
|
|
|
|
++rti->rti_age >= IGMP_AGE_THRESHOLD) {
|
|
|
|
rti->rti_type = IGMP_v2_ROUTER;
|
|
|
|
}
|
|
|
|
}
|
2008-04-24 15:38:36 +04:00
|
|
|
KERNEL_UNLOCK_ONE(NULL);
|
|
|
|
mutex_exit(softnet_lock);
|
1995-05-31 10:08:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2005-02-03 06:49:01 +03:00
|
|
|
igmp_sendpkt(struct in_multi *inm, int type)
|
1995-05-31 10:08:17 +04:00
|
|
|
{
|
|
|
|
struct mbuf *m;
|
|
|
|
struct igmp *igmp;
|
|
|
|
struct ip *ip;
|
|
|
|
struct ip_moptions imo;
|
|
|
|
#ifdef MROUTING
|
|
|
|
extern struct socket *ip_mrouter;
|
|
|
|
#endif /* MROUTING */
|
1993-12-06 07:50:19 +03:00
|
|
|
|
|
|
|
MGETHDR(m, M_DONTWAIT, MT_HEADER);
|
|
|
|
if (m == NULL)
|
|
|
|
return;
|
|
|
|
/*
|
|
|
|
* Assume max_linkhdr + sizeof(struct ip) + IGMP_MINLEN
|
|
|
|
* is smaller than mbuf size returned by MGETHDR.
|
|
|
|
*/
|
|
|
|
m->m_data += max_linkhdr;
|
|
|
|
m->m_len = sizeof(struct ip) + IGMP_MINLEN;
|
|
|
|
m->m_pkthdr.len = sizeof(struct ip) + IGMP_MINLEN;
|
|
|
|
|
|
|
|
ip = mtod(m, struct ip *);
|
|
|
|
ip->ip_tos = 0;
|
2002-08-14 04:23:27 +04:00
|
|
|
ip->ip_len = htons(sizeof(struct ip) + IGMP_MINLEN);
|
|
|
|
ip->ip_off = htons(0);
|
1993-12-06 07:50:19 +03:00
|
|
|
ip->ip_p = IPPROTO_IGMP;
|
1996-09-09 18:51:07 +04:00
|
|
|
ip->ip_src = zeroin_addr;
|
1993-12-06 07:50:19 +03:00
|
|
|
ip->ip_dst = inm->inm_addr;
|
|
|
|
|
1994-06-09 19:59:47 +04:00
|
|
|
m->m_data += sizeof(struct ip);
|
|
|
|
m->m_len -= sizeof(struct ip);
|
|
|
|
igmp = mtod(m, struct igmp *);
|
1995-05-31 10:08:17 +04:00
|
|
|
igmp->igmp_type = type;
|
1993-12-06 07:50:19 +03:00
|
|
|
igmp->igmp_code = 0;
|
|
|
|
igmp->igmp_group = inm->inm_addr;
|
|
|
|
igmp->igmp_cksum = 0;
|
|
|
|
igmp->igmp_cksum = in_cksum(m, IGMP_MINLEN);
|
1994-06-09 19:59:47 +04:00
|
|
|
m->m_data -= sizeof(struct ip);
|
|
|
|
m->m_len += sizeof(struct ip);
|
1993-12-06 07:50:19 +03:00
|
|
|
|
1995-05-31 10:08:17 +04:00
|
|
|
imo.imo_multicast_ifp = inm->inm_ifp;
|
|
|
|
imo.imo_multicast_ttl = 1;
|
|
|
|
#ifdef RSVP_ISI
|
|
|
|
imo.imo_multicast_vif = -1;
|
|
|
|
#endif
|
1993-12-06 07:50:19 +03:00
|
|
|
/*
|
|
|
|
* Request loopback of the report if we are acting as a multicast
|
|
|
|
* router, so that the process-level routing demon can hear it.
|
|
|
|
*/
|
|
|
|
#ifdef MROUTING
|
1995-05-31 10:08:17 +04:00
|
|
|
imo.imo_multicast_loop = (ip_mrouter != NULL);
|
|
|
|
#else
|
|
|
|
imo.imo_multicast_loop = 0;
|
|
|
|
#endif /* MROUTING */
|
|
|
|
|
2007-04-25 04:11:18 +04:00
|
|
|
ip_output(m, NULL, NULL, IP_MULTICASTOPTS, &imo, NULL);
|
1993-12-06 07:50:19 +03:00
|
|
|
|
2008-04-15 20:02:03 +04:00
|
|
|
IGMP_STATINC(IGMP_STAT_SND_REPORTS);
|
1993-12-06 07:50:19 +03:00
|
|
|
}
|
2003-06-26 07:11:08 +04:00
|
|
|
|
|
|
|
void
|
2006-10-05 21:35:19 +04:00
|
|
|
igmp_purgeif(struct ifnet *ifp) /* MUST be called at splsoftnet() */
|
2003-06-26 07:11:08 +04:00
|
|
|
{
|
2006-10-05 21:35:19 +04:00
|
|
|
rti_delete(ifp); /* manipulates pools */
|
2003-06-26 07:11:08 +04:00
|
|
|
}
|
2008-04-15 20:02:03 +04:00
|
|
|
|
|
|
|
static int
|
|
|
|
sysctl_net_inet_igmp_stats(SYSCTLFN_ARGS)
|
|
|
|
{
|
|
|
|
|
2008-05-04 11:22:14 +04:00
|
|
|
return (NETSTAT_SYSCTL(igmpstat_percpu, IGMP_NSTATS));
|
2008-04-15 20:02:03 +04:00
|
|
|
}
|
|
|
|
|
2009-09-16 19:23:04 +04:00
|
|
|
static void
|
|
|
|
sysctl_net_inet_igmp_setup(struct sysctllog **clog)
|
2008-04-15 20:02:03 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
sysctl_createv(clog, 0, NULL, NULL,
|
|
|
|
CTLFLAG_PERMANENT,
|
|
|
|
CTLTYPE_NODE, "net", NULL,
|
|
|
|
NULL, 0, NULL, 0,
|
|
|
|
CTL_NET, CTL_EOL);
|
|
|
|
sysctl_createv(clog, 0, NULL, NULL,
|
|
|
|
CTLFLAG_PERMANENT,
|
|
|
|
CTLTYPE_NODE, "inet", NULL,
|
|
|
|
NULL, 0, NULL, 0,
|
|
|
|
CTL_NET, PF_INET, CTL_EOL);
|
|
|
|
sysctl_createv(clog, 0, NULL, NULL,
|
|
|
|
CTLFLAG_PERMANENT,
|
|
|
|
CTLTYPE_NODE, "igmp",
|
|
|
|
SYSCTL_DESCR("Internet Group Management Protocol"),
|
|
|
|
NULL, 0, NULL, 0,
|
|
|
|
CTL_NET, PF_INET, IPPROTO_IGMP, CTL_EOL);
|
|
|
|
|
|
|
|
sysctl_createv(clog, 0, NULL, NULL,
|
|
|
|
CTLFLAG_PERMANENT,
|
|
|
|
CTLTYPE_STRUCT, "stats",
|
|
|
|
SYSCTL_DESCR("IGMP statistics"),
|
|
|
|
sysctl_net_inet_igmp_stats, 0, NULL, 0,
|
|
|
|
CTL_NET, PF_INET, IPPROTO_IGMP, CTL_CREATE, CTL_EOL);
|
|
|
|
}
|