2000-07-04 16:35:15 +00:00
|
|
|
/* $FreeBSD$ */
|
2001-06-11 12:39:29 +00:00
|
|
|
/* $KAME: mld6.c,v 1.27 2001/04/04 05:17:30 itojun Exp $ */
|
2000-07-04 16:35:15 +00:00
|
|
|
|
1999-11-22 02:45:11 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 1998 WIDE Project.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1988 Stephen Deering.
|
|
|
|
* Copyright (c) 1992, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to Berkeley by
|
|
|
|
* Stephen Deering of Stanford University.
|
|
|
|
*
|
|
|
|
* 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. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
|
|
|
|
*
|
|
|
|
* @(#)igmp.c 8.1 (Berkeley) 7/19/93
|
|
|
|
*/
|
|
|
|
|
2000-07-04 16:35:15 +00:00
|
|
|
#include "opt_inet.h"
|
|
|
|
#include "opt_inet6.h"
|
1999-12-22 19:13:38 +00:00
|
|
|
|
1999-11-22 02:45:11 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/protosw.h>
|
|
|
|
#include <sys/syslog.h>
|
|
|
|
|
|
|
|
#include <net/if.h>
|
|
|
|
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/in_var.h>
|
2000-07-04 16:35:15 +00:00
|
|
|
#include <netinet/ip6.h>
|
1999-11-22 02:45:11 +00:00
|
|
|
#include <netinet6/ip6_var.h>
|
2000-07-04 16:35:15 +00:00
|
|
|
#include <netinet/icmp6.h>
|
1999-11-22 02:45:11 +00:00
|
|
|
#include <netinet6/mld6_var.h>
|
|
|
|
|
|
|
|
#include <net/net_osdep.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Protocol constants
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* denotes that the MLD max response delay field specifies time in milliseconds */
|
2000-07-04 16:35:15 +00:00
|
|
|
#define MLD6_TIMER_SCALE 1000
|
1999-11-22 02:45:11 +00:00
|
|
|
/*
|
|
|
|
* time between repetitions of a node's initial report of interest in a
|
|
|
|
* multicast address(in seconds)
|
|
|
|
*/
|
2000-07-04 16:35:15 +00:00
|
|
|
#define MLD6_UNSOLICITED_REPORT_INTERVAL 10
|
1999-11-22 02:45:11 +00:00
|
|
|
|
2000-07-04 16:35:15 +00:00
|
|
|
static struct ip6_pktopts ip6_opts;
|
|
|
|
static int mld6_timers_are_running;
|
1999-11-22 02:45:11 +00:00
|
|
|
/* XXX: These are necessary for KAME's link-local hack */
|
2000-07-04 16:35:15 +00:00
|
|
|
static struct in6_addr mld6_all_nodes_linklocal = IN6ADDR_LINKLOCAL_ALLNODES_INIT;
|
|
|
|
static struct in6_addr mld6_all_routers_linklocal = IN6ADDR_LINKLOCAL_ALLROUTERS_INIT;
|
1999-11-22 02:45:11 +00:00
|
|
|
|
2003-10-09 16:13:47 +00:00
|
|
|
static void mld6_sendpkt(struct in6_multi *, int, const struct in6_addr *);
|
1999-11-22 02:45:11 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
mld6_init()
|
|
|
|
{
|
|
|
|
static u_int8_t hbh_buf[8];
|
|
|
|
struct ip6_hbh *hbh = (struct ip6_hbh *)hbh_buf;
|
|
|
|
u_int16_t rtalert_code = htons((u_int16_t)IP6OPT_RTALERT_MLD);
|
|
|
|
|
|
|
|
mld6_timers_are_running = 0;
|
|
|
|
|
|
|
|
/* ip6h_nxt will be fill in later */
|
2000-07-04 16:35:15 +00:00
|
|
|
hbh->ip6h_len = 0; /* (8 >> 3) - 1 */
|
1999-11-22 02:45:11 +00:00
|
|
|
|
|
|
|
/* XXX: grotty hard coding... */
|
|
|
|
hbh_buf[2] = IP6OPT_PADN; /* 2 byte padding */
|
|
|
|
hbh_buf[3] = 0;
|
2003-10-24 18:26:30 +00:00
|
|
|
hbh_buf[4] = IP6OPT_ROUTER_ALERT;
|
1999-11-22 02:45:11 +00:00
|
|
|
hbh_buf[5] = IP6OPT_RTALERT_LEN - 2;
|
|
|
|
bcopy((caddr_t)&rtalert_code, &hbh_buf[6], sizeof(u_int16_t));
|
|
|
|
|
2001-06-11 12:39:29 +00:00
|
|
|
init_ip6pktopts(&ip6_opts);
|
1999-11-22 02:45:11 +00:00
|
|
|
ip6_opts.ip6po_hbh = hbh;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
mld6_start_listening(in6m)
|
|
|
|
struct in6_multi *in6m;
|
|
|
|
{
|
|
|
|
int s = splnet();
|
|
|
|
|
|
|
|
/*
|
2000-07-04 16:35:15 +00:00
|
|
|
* RFC2710 page 10:
|
1999-11-22 02:45:11 +00:00
|
|
|
* The node never sends a Report or Done for the link-scope all-nodes
|
|
|
|
* address.
|
|
|
|
* MLD messages are never sent for multicast addresses whose scope is 0
|
|
|
|
* (reserved) or 1 (node-local).
|
|
|
|
*/
|
|
|
|
mld6_all_nodes_linklocal.s6_addr16[1] =
|
|
|
|
htons(in6m->in6m_ifp->if_index); /* XXX */
|
|
|
|
if (IN6_ARE_ADDR_EQUAL(&in6m->in6m_addr, &mld6_all_nodes_linklocal) ||
|
|
|
|
IPV6_ADDR_MC_SCOPE(&in6m->in6m_addr) < IPV6_ADDR_SCOPE_LINKLOCAL) {
|
|
|
|
in6m->in6m_timer = 0;
|
|
|
|
in6m->in6m_state = MLD6_OTHERLISTENER;
|
|
|
|
} else {
|
2002-05-06 16:28:25 +00:00
|
|
|
mld6_sendpkt(in6m, MLD_LISTENER_REPORT, NULL);
|
1999-11-22 02:45:11 +00:00
|
|
|
in6m->in6m_timer = MLD6_RANDOM_DELAY(
|
|
|
|
MLD6_UNSOLICITED_REPORT_INTERVAL * PR_FASTHZ);
|
|
|
|
in6m->in6m_state = MLD6_IREPORTEDLAST;
|
|
|
|
mld6_timers_are_running = 1;
|
|
|
|
}
|
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
mld6_stop_listening(in6m)
|
|
|
|
struct in6_multi *in6m;
|
|
|
|
{
|
|
|
|
mld6_all_nodes_linklocal.s6_addr16[1] =
|
|
|
|
htons(in6m->in6m_ifp->if_index); /* XXX */
|
|
|
|
mld6_all_routers_linklocal.s6_addr16[1] =
|
|
|
|
htons(in6m->in6m_ifp->if_index); /* XXX: necessary when mrouting */
|
|
|
|
|
|
|
|
if (in6m->in6m_state == MLD6_IREPORTEDLAST &&
|
|
|
|
(!IN6_ARE_ADDR_EQUAL(&in6m->in6m_addr, &mld6_all_nodes_linklocal)) &&
|
2003-10-21 20:05:32 +00:00
|
|
|
IPV6_ADDR_MC_SCOPE(&in6m->in6m_addr) > IPV6_ADDR_SCOPE_INTFACELOCAL)
|
2002-05-06 16:28:25 +00:00
|
|
|
mld6_sendpkt(in6m, MLD_LISTENER_DONE,
|
1999-11-22 02:45:11 +00:00
|
|
|
&mld6_all_routers_linklocal);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
mld6_input(m, off)
|
|
|
|
struct mbuf *m;
|
|
|
|
int off;
|
|
|
|
{
|
|
|
|
struct ip6_hdr *ip6 = mtod(m, struct ip6_hdr *);
|
2002-05-06 16:28:25 +00:00
|
|
|
struct mld_hdr *mldh;
|
1999-11-22 02:45:11 +00:00
|
|
|
struct ifnet *ifp = m->m_pkthdr.rcvif;
|
|
|
|
struct in6_multi *in6m;
|
|
|
|
struct in6_ifaddr *ia;
|
|
|
|
struct ifmultiaddr *ifma;
|
|
|
|
int timer; /* timer value in the MLD query header */
|
|
|
|
|
2001-06-11 12:39:29 +00:00
|
|
|
#ifndef PULLDOWN_TEST
|
|
|
|
IP6_EXTHDR_CHECK(m, off, sizeof(*mldh),);
|
2002-05-06 16:28:25 +00:00
|
|
|
mldh = (struct mld_hdr *)(mtod(m, caddr_t) + off);
|
2001-06-11 12:39:29 +00:00
|
|
|
#else
|
2002-05-06 16:28:25 +00:00
|
|
|
IP6_EXTHDR_GET(mldh, struct mld_hdr *, m, off, sizeof(*mldh));
|
2001-06-11 12:39:29 +00:00
|
|
|
if (mldh == NULL) {
|
|
|
|
icmp6stat.icp6s_tooshort++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1999-11-22 02:45:11 +00:00
|
|
|
/* source address validation */
|
2003-10-09 16:13:47 +00:00
|
|
|
ip6 = mtod(m, struct ip6_hdr *); /* in case mpullup */
|
1999-11-22 02:45:11 +00:00
|
|
|
if (!IN6_IS_ADDR_LINKLOCAL(&ip6->ip6_src)) {
|
|
|
|
log(LOG_ERR,
|
2001-06-11 12:39:29 +00:00
|
|
|
"mld6_input: src %s is not link-local (grp=%s)\n",
|
|
|
|
ip6_sprintf(&ip6->ip6_src),
|
2002-05-06 16:28:25 +00:00
|
|
|
ip6_sprintf(&mldh->mld_addr));
|
1999-11-22 02:45:11 +00:00
|
|
|
/*
|
2000-07-04 16:35:15 +00:00
|
|
|
* spec (RFC2710) does not explicitly
|
1999-11-22 02:45:11 +00:00
|
|
|
* specify to discard the packet from a non link-local
|
|
|
|
* source address. But we believe it's expected to do so.
|
2001-06-11 12:39:29 +00:00
|
|
|
* XXX: do we have to allow :: as source?
|
1999-11-22 02:45:11 +00:00
|
|
|
*/
|
2000-07-04 16:35:15 +00:00
|
|
|
m_freem(m);
|
1999-11-22 02:45:11 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* In the MLD6 specification, there are 3 states and a flag.
|
|
|
|
*
|
|
|
|
* In Non-Listener state, we simply don't have a membership record.
|
|
|
|
* In Delaying Listener state, our timer is running (in6m->in6m_timer)
|
|
|
|
* In Idle Listener state, our timer is not running (in6m->in6m_timer==0)
|
|
|
|
*
|
|
|
|
* The flag is in6m->in6m_state, it is set to MLD6_OTHERLISTENER if
|
|
|
|
* we have heard a report from another member, or MLD6_IREPORTEDLAST
|
|
|
|
* if we sent the last report.
|
|
|
|
*/
|
2002-05-06 16:28:25 +00:00
|
|
|
switch(mldh->mld_type) {
|
|
|
|
case MLD_LISTENER_QUERY:
|
1999-11-22 02:45:11 +00:00
|
|
|
if (ifp->if_flags & IFF_LOOPBACK)
|
|
|
|
break;
|
|
|
|
|
2002-05-06 16:28:25 +00:00
|
|
|
if (!IN6_IS_ADDR_UNSPECIFIED(&mldh->mld_addr) &&
|
|
|
|
!IN6_IS_ADDR_MULTICAST(&mldh->mld_addr))
|
1999-11-22 02:45:11 +00:00
|
|
|
break; /* print error or log stat? */
|
2002-05-06 16:28:25 +00:00
|
|
|
if (IN6_IS_ADDR_MC_LINKLOCAL(&mldh->mld_addr))
|
|
|
|
mldh->mld_addr.s6_addr16[1] =
|
1999-11-22 02:45:11 +00:00
|
|
|
htons(ifp->if_index); /* XXX */
|
|
|
|
|
|
|
|
/*
|
2000-07-04 16:35:15 +00:00
|
|
|
* - Start the timers in all of our membership records
|
|
|
|
* that the query applies to for the interface on
|
|
|
|
* which the query arrived excl. those that belong
|
|
|
|
* to the "all-nodes" group (ff02::1).
|
|
|
|
* - Restart any timer that is already running but has
|
|
|
|
* A value longer than the requested timeout.
|
|
|
|
* - Use the value specified in the query message as
|
|
|
|
* the maximum timeout.
|
|
|
|
*/
|
1999-11-22 02:45:11 +00:00
|
|
|
IFP_TO_IA6(ifp, ia);
|
|
|
|
if (ia == NULL)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/*
|
2000-07-04 16:35:15 +00:00
|
|
|
* XXX: System timer resolution is too low to handle Max
|
|
|
|
* Response Delay, so set 1 to the internal timer even if
|
|
|
|
* the calculated value equals to zero when Max Response
|
|
|
|
* Delay is positive.
|
|
|
|
*/
|
2003-10-09 16:13:47 +00:00
|
|
|
timer = ntohs(mldh->mld_maxdelay) * PR_FASTHZ / MLD6_TIMER_SCALE;
|
2002-05-06 16:28:25 +00:00
|
|
|
if (timer == 0 && mldh->mld_maxdelay)
|
1999-11-22 02:45:11 +00:00
|
|
|
timer = 1;
|
|
|
|
mld6_all_nodes_linklocal.s6_addr16[1] =
|
|
|
|
htons(ifp->if_index); /* XXX */
|
2003-10-09 16:13:47 +00:00
|
|
|
|
|
|
|
TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
|
1999-11-22 02:45:11 +00:00
|
|
|
if (ifma->ifma_addr->sa_family != AF_INET6)
|
|
|
|
continue;
|
|
|
|
in6m = (struct in6_multi *)ifma->ifma_protospec;
|
2003-10-09 16:13:47 +00:00
|
|
|
|
1999-11-22 02:45:11 +00:00
|
|
|
if (IN6_ARE_ADDR_EQUAL(&in6m->in6m_addr,
|
|
|
|
&mld6_all_nodes_linklocal) ||
|
|
|
|
IPV6_ADDR_MC_SCOPE(&in6m->in6m_addr) <
|
|
|
|
IPV6_ADDR_SCOPE_LINKLOCAL)
|
|
|
|
continue;
|
|
|
|
|
2002-05-06 16:28:25 +00:00
|
|
|
if (IN6_IS_ADDR_UNSPECIFIED(&mldh->mld_addr) ||
|
|
|
|
IN6_ARE_ADDR_EQUAL(&mldh->mld_addr,
|
1999-11-22 02:45:11 +00:00
|
|
|
&in6m->in6m_addr))
|
|
|
|
{
|
|
|
|
if (timer == 0) {
|
|
|
|
/* send a report immediately */
|
2002-05-06 16:28:25 +00:00
|
|
|
mld6_sendpkt(in6m, MLD_LISTENER_REPORT,
|
1999-11-22 02:45:11 +00:00
|
|
|
NULL);
|
|
|
|
in6m->in6m_timer = 0; /* reset timer */
|
|
|
|
in6m->in6m_state = MLD6_IREPORTEDLAST;
|
2000-07-04 16:35:15 +00:00
|
|
|
}
|
|
|
|
else if (in6m->in6m_timer == 0 || /*idle state*/
|
1999-11-22 02:45:11 +00:00
|
|
|
in6m->in6m_timer > timer) {
|
|
|
|
in6m->in6m_timer =
|
|
|
|
MLD6_RANDOM_DELAY(timer);
|
|
|
|
mld6_timers_are_running = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-05-06 16:28:25 +00:00
|
|
|
if (IN6_IS_ADDR_MC_LINKLOCAL(&mldh->mld_addr))
|
|
|
|
mldh->mld_addr.s6_addr16[1] = 0; /* XXX */
|
1999-11-22 02:45:11 +00:00
|
|
|
break;
|
2003-10-09 16:13:47 +00:00
|
|
|
|
2002-05-06 16:28:25 +00:00
|
|
|
case MLD_LISTENER_REPORT:
|
1999-11-22 02:45:11 +00:00
|
|
|
/*
|
2000-07-04 16:35:15 +00:00
|
|
|
* For fast leave to work, we have to know that we are the
|
|
|
|
* last person to send a report for this group. Reports
|
|
|
|
* can potentially get looped back if we are a multicast
|
|
|
|
* router, so discard reports sourced by me.
|
|
|
|
* Note that it is impossible to check IFF_LOOPBACK flag of
|
|
|
|
* ifp for this purpose, since ip6_mloopback pass the physical
|
|
|
|
* interface to looutput.
|
|
|
|
*/
|
1999-11-22 02:45:11 +00:00
|
|
|
if (m->m_flags & M_LOOP) /* XXX: grotty flag, but efficient */
|
|
|
|
break;
|
|
|
|
|
2002-05-06 16:28:25 +00:00
|
|
|
if (!IN6_IS_ADDR_MULTICAST(&mldh->mld_addr))
|
1999-11-22 02:45:11 +00:00
|
|
|
break;
|
|
|
|
|
2002-05-06 16:28:25 +00:00
|
|
|
if (IN6_IS_ADDR_MC_LINKLOCAL(&mldh->mld_addr))
|
|
|
|
mldh->mld_addr.s6_addr16[1] =
|
1999-11-22 02:45:11 +00:00
|
|
|
htons(ifp->if_index); /* XXX */
|
|
|
|
/*
|
2000-07-04 16:35:15 +00:00
|
|
|
* If we belong to the group being reported, stop
|
|
|
|
* our timer for that group.
|
|
|
|
*/
|
2002-05-06 16:28:25 +00:00
|
|
|
IN6_LOOKUP_MULTI(mldh->mld_addr, ifp, in6m);
|
1999-11-22 02:45:11 +00:00
|
|
|
if (in6m) {
|
|
|
|
in6m->in6m_timer = 0; /* transit to idle state */
|
|
|
|
in6m->in6m_state = MLD6_OTHERLISTENER; /* clear flag */
|
|
|
|
}
|
|
|
|
|
2002-05-06 16:28:25 +00:00
|
|
|
if (IN6_IS_ADDR_MC_LINKLOCAL(&mldh->mld_addr))
|
|
|
|
mldh->mld_addr.s6_addr16[1] = 0; /* XXX */
|
1999-11-22 02:45:11 +00:00
|
|
|
break;
|
|
|
|
default: /* this is impossible */
|
2002-05-06 16:28:25 +00:00
|
|
|
log(LOG_ERR, "mld6_input: illegal type(%d)", mldh->mld_type);
|
1999-11-22 02:45:11 +00:00
|
|
|
break;
|
|
|
|
}
|
2000-07-04 16:35:15 +00:00
|
|
|
|
|
|
|
m_freem(m);
|
1999-11-22 02:45:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
mld6_fasttimeo()
|
|
|
|
{
|
2001-06-11 12:39:29 +00:00
|
|
|
struct in6_multi *in6m;
|
1999-11-22 02:45:11 +00:00
|
|
|
struct in6_multistep step;
|
|
|
|
int s;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Quick check to see if any work needs to be done, in order
|
|
|
|
* to minimize the overhead of fasttimo processing.
|
|
|
|
*/
|
|
|
|
if (!mld6_timers_are_running)
|
|
|
|
return;
|
|
|
|
|
|
|
|
s = splnet();
|
2003-10-09 16:13:47 +00:00
|
|
|
|
1999-11-22 02:45:11 +00:00
|
|
|
mld6_timers_are_running = 0;
|
|
|
|
IN6_FIRST_MULTI(step, in6m);
|
|
|
|
while (in6m != NULL) {
|
|
|
|
if (in6m->in6m_timer == 0) {
|
|
|
|
/* do nothing */
|
|
|
|
} else if (--in6m->in6m_timer == 0) {
|
2002-05-06 16:28:25 +00:00
|
|
|
mld6_sendpkt(in6m, MLD_LISTENER_REPORT, NULL);
|
1999-11-22 02:45:11 +00:00
|
|
|
in6m->in6m_state = MLD6_IREPORTEDLAST;
|
|
|
|
} else {
|
|
|
|
mld6_timers_are_running = 1;
|
|
|
|
}
|
|
|
|
IN6_NEXT_MULTI(step, in6m);
|
|
|
|
}
|
2003-10-09 16:13:47 +00:00
|
|
|
|
1999-11-22 02:45:11 +00:00
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
mld6_sendpkt(in6m, type, dst)
|
|
|
|
struct in6_multi *in6m;
|
|
|
|
int type;
|
|
|
|
const struct in6_addr *dst;
|
|
|
|
{
|
|
|
|
struct mbuf *mh, *md;
|
2002-05-06 16:28:25 +00:00
|
|
|
struct mld_hdr *mldh;
|
1999-11-22 02:45:11 +00:00
|
|
|
struct ip6_hdr *ip6;
|
|
|
|
struct ip6_moptions im6o;
|
|
|
|
struct in6_ifaddr *ia;
|
|
|
|
struct ifnet *ifp = in6m->in6m_ifp;
|
|
|
|
struct ifnet *outif = NULL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* At first, find a link local address on the outgoing interface
|
|
|
|
* to use as the source address of the MLD packet.
|
|
|
|
*/
|
2000-07-04 16:35:15 +00:00
|
|
|
if ((ia = in6ifa_ifpforlinklocal(ifp, IN6_IFF_NOTREADY|IN6_IFF_ANYCAST))
|
|
|
|
== NULL)
|
1999-11-22 02:45:11 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate mbufs to store ip6 header and MLD header.
|
|
|
|
* We allocate 2 mbufs and make chain in advance because
|
|
|
|
* it is more convenient when inserting the hop-by-hop option later.
|
|
|
|
*/
|
2003-02-19 05:47:46 +00:00
|
|
|
MGETHDR(mh, M_DONTWAIT, MT_HEADER);
|
1999-11-22 02:45:11 +00:00
|
|
|
if (mh == NULL)
|
|
|
|
return;
|
2003-02-19 05:47:46 +00:00
|
|
|
MGET(md, M_DONTWAIT, MT_DATA);
|
1999-11-22 02:45:11 +00:00
|
|
|
if (md == NULL) {
|
|
|
|
m_free(mh);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mh->m_next = md;
|
2000-07-04 16:35:15 +00:00
|
|
|
|
2001-06-11 12:39:29 +00:00
|
|
|
mh->m_pkthdr.rcvif = NULL;
|
2002-05-06 16:28:25 +00:00
|
|
|
mh->m_pkthdr.len = sizeof(struct ip6_hdr) + sizeof(struct mld_hdr);
|
1999-11-22 02:45:11 +00:00
|
|
|
mh->m_len = sizeof(struct ip6_hdr);
|
|
|
|
MH_ALIGN(mh, sizeof(struct ip6_hdr));
|
|
|
|
|
|
|
|
/* fill in the ip6 header */
|
|
|
|
ip6 = mtod(mh, struct ip6_hdr *);
|
|
|
|
ip6->ip6_flow = 0;
|
2000-07-04 16:35:15 +00:00
|
|
|
ip6->ip6_vfc &= ~IPV6_VERSION_MASK;
|
|
|
|
ip6->ip6_vfc |= IPV6_VERSION;
|
1999-11-22 02:45:11 +00:00
|
|
|
/* ip6_plen will be set later */
|
|
|
|
ip6->ip6_nxt = IPPROTO_ICMPV6;
|
|
|
|
/* ip6_hlim will be set by im6o.im6o_multicast_hlim */
|
|
|
|
ip6->ip6_src = ia->ia_addr.sin6_addr;
|
|
|
|
ip6->ip6_dst = dst ? *dst : in6m->in6m_addr;
|
|
|
|
|
|
|
|
/* fill in the MLD header */
|
2002-05-06 16:28:25 +00:00
|
|
|
md->m_len = sizeof(struct mld_hdr);
|
|
|
|
mldh = mtod(md, struct mld_hdr *);
|
|
|
|
mldh->mld_type = type;
|
|
|
|
mldh->mld_code = 0;
|
|
|
|
mldh->mld_cksum = 0;
|
1999-11-22 02:45:11 +00:00
|
|
|
/* XXX: we assume the function will not be called for query messages */
|
2002-05-06 16:28:25 +00:00
|
|
|
mldh->mld_maxdelay = 0;
|
|
|
|
mldh->mld_reserved = 0;
|
|
|
|
mldh->mld_addr = in6m->in6m_addr;
|
|
|
|
if (IN6_IS_ADDR_MC_LINKLOCAL(&mldh->mld_addr))
|
|
|
|
mldh->mld_addr.s6_addr16[1] = 0; /* XXX */
|
2003-10-09 16:13:47 +00:00
|
|
|
mldh->mld_cksum = in6_cksum(mh, IPPROTO_ICMPV6, sizeof(struct ip6_hdr),
|
|
|
|
sizeof(struct mld_hdr));
|
1999-11-22 02:45:11 +00:00
|
|
|
|
|
|
|
/* construct multicast option */
|
|
|
|
bzero(&im6o, sizeof(im6o));
|
|
|
|
im6o.im6o_multicast_ifp = ifp;
|
|
|
|
im6o.im6o_multicast_hlim = 1;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Request loopback of the report if we are acting as a multicast
|
|
|
|
* router, so that the process-level routing daemon can hear it.
|
|
|
|
*/
|
2000-07-04 16:35:15 +00:00
|
|
|
im6o.im6o_multicast_loop = (ip6_mrouter != NULL);
|
1999-11-22 02:45:11 +00:00
|
|
|
|
|
|
|
/* increment output statictics */
|
|
|
|
icmp6stat.icp6s_outhist[type]++;
|
|
|
|
|
2002-10-16 01:54:46 +00:00
|
|
|
ip6_output(mh, &ip6_opts, NULL, 0, &im6o, &outif, NULL);
|
1999-11-22 02:45:11 +00:00
|
|
|
if (outif) {
|
|
|
|
icmp6_ifstat_inc(outif, ifs6_out_msg);
|
2001-06-11 12:39:29 +00:00
|
|
|
switch (type) {
|
2002-05-06 16:28:25 +00:00
|
|
|
case MLD_LISTENER_QUERY:
|
2001-06-11 12:39:29 +00:00
|
|
|
icmp6_ifstat_inc(outif, ifs6_out_mldquery);
|
|
|
|
break;
|
2002-05-06 16:28:25 +00:00
|
|
|
case MLD_LISTENER_REPORT:
|
2001-06-11 12:39:29 +00:00
|
|
|
icmp6_ifstat_inc(outif, ifs6_out_mldreport);
|
|
|
|
break;
|
2002-05-06 16:28:25 +00:00
|
|
|
case MLD_LISTENER_DONE:
|
2001-06-11 12:39:29 +00:00
|
|
|
icmp6_ifstat_inc(outif, ifs6_out_mlddone);
|
|
|
|
break;
|
1999-11-22 02:45:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|