1 |
27 |
unneback |
//==========================================================================
|
2 |
|
|
//
|
3 |
|
|
// src/sys/netinet6/mld6.c
|
4 |
|
|
//
|
5 |
|
|
//==========================================================================
|
6 |
|
|
//####BSDCOPYRIGHTBEGIN####
|
7 |
|
|
//
|
8 |
|
|
// -------------------------------------------
|
9 |
|
|
//
|
10 |
|
|
// Portions of this software may have been derived from OpenBSD,
|
11 |
|
|
// FreeBSD or other sources, and are covered by the appropriate
|
12 |
|
|
// copyright disclaimers included herein.
|
13 |
|
|
//
|
14 |
|
|
// Portions created by Red Hat are
|
15 |
|
|
// Copyright (C) 2002 Red Hat, Inc. All Rights Reserved.
|
16 |
|
|
//
|
17 |
|
|
// -------------------------------------------
|
18 |
|
|
//
|
19 |
|
|
//####BSDCOPYRIGHTEND####
|
20 |
|
|
//==========================================================================
|
21 |
|
|
|
22 |
|
|
/* $KAME: mld6.c,v 1.35 2001/12/18 02:23:44 itojun Exp $ */
|
23 |
|
|
|
24 |
|
|
/*
|
25 |
|
|
* Copyright (C) 1998 WIDE Project.
|
26 |
|
|
* All rights reserved.
|
27 |
|
|
*
|
28 |
|
|
* Redistribution and use in source and binary forms, with or without
|
29 |
|
|
* modification, are permitted provided that the following conditions
|
30 |
|
|
* are met:
|
31 |
|
|
* 1. Redistributions of source code must retain the above copyright
|
32 |
|
|
* notice, this list of conditions and the following disclaimer.
|
33 |
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
34 |
|
|
* notice, this list of conditions and the following disclaimer in the
|
35 |
|
|
* documentation and/or other materials provided with the distribution.
|
36 |
|
|
* 3. Neither the name of the project nor the names of its contributors
|
37 |
|
|
* may be used to endorse or promote products derived from this software
|
38 |
|
|
* without specific prior written permission.
|
39 |
|
|
*
|
40 |
|
|
* THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
|
41 |
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
42 |
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
43 |
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
|
44 |
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
45 |
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
46 |
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
47 |
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
48 |
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
49 |
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
50 |
|
|
* SUCH DAMAGE.
|
51 |
|
|
*/
|
52 |
|
|
|
53 |
|
|
/*
|
54 |
|
|
* Copyright (c) 1988 Stephen Deering.
|
55 |
|
|
* Copyright (c) 1992, 1993
|
56 |
|
|
* The Regents of the University of California. All rights reserved.
|
57 |
|
|
*
|
58 |
|
|
* This code is derived from software contributed to Berkeley by
|
59 |
|
|
* Stephen Deering of Stanford University.
|
60 |
|
|
*
|
61 |
|
|
* Redistribution and use in source and binary forms, with or without
|
62 |
|
|
* modification, are permitted provided that the following conditions
|
63 |
|
|
* are met:
|
64 |
|
|
* 1. Redistributions of source code must retain the above copyright
|
65 |
|
|
* notice, this list of conditions and the following disclaimer.
|
66 |
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
67 |
|
|
* notice, this list of conditions and the following disclaimer in the
|
68 |
|
|
* documentation and/or other materials provided with the distribution.
|
69 |
|
|
* 3. All advertising materials mentioning features or use of this software
|
70 |
|
|
* must display the following acknowledgement:
|
71 |
|
|
* This product includes software developed by the University of
|
72 |
|
|
* California, Berkeley and its contributors.
|
73 |
|
|
* 4. Neither the name of the University nor the names of its contributors
|
74 |
|
|
* may be used to endorse or promote products derived from this software
|
75 |
|
|
* without specific prior written permission.
|
76 |
|
|
*
|
77 |
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
78 |
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
79 |
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
80 |
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
81 |
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
82 |
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
83 |
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
84 |
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
85 |
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
86 |
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
87 |
|
|
* SUCH DAMAGE.
|
88 |
|
|
*
|
89 |
|
|
* @(#)igmp.c 8.1 (Berkeley) 7/19/93
|
90 |
|
|
*/
|
91 |
|
|
|
92 |
|
|
#include <sys/param.h>
|
93 |
|
|
#include <sys/mbuf.h>
|
94 |
|
|
#include <sys/socket.h>
|
95 |
|
|
#include <sys/protosw.h>
|
96 |
|
|
#ifdef __OpenBSD__
|
97 |
|
|
#include <dev/rndvar.h>
|
98 |
|
|
#endif
|
99 |
|
|
|
100 |
|
|
#include <net/if.h>
|
101 |
|
|
#ifdef NEW_STRUCT_ROUTE
|
102 |
|
|
#include <net/route.h>
|
103 |
|
|
#endif
|
104 |
|
|
|
105 |
|
|
#include <netinet/in.h>
|
106 |
|
|
#include <netinet/in_var.h>
|
107 |
|
|
#include <netinet/ip6.h>
|
108 |
|
|
#include <netinet6/ip6_var.h>
|
109 |
|
|
#include <netinet/icmp6.h>
|
110 |
|
|
#include <netinet6/mld6_var.h>
|
111 |
|
|
|
112 |
|
|
/*
|
113 |
|
|
* Protocol constants
|
114 |
|
|
*/
|
115 |
|
|
|
116 |
|
|
/* denotes that the MLD max response delay field specifies time in milliseconds */
|
117 |
|
|
#define MLD6_TIMER_SCALE 1000
|
118 |
|
|
/*
|
119 |
|
|
* time between repetitions of a node's initial report of interest in a
|
120 |
|
|
* multicast address(in seconds)
|
121 |
|
|
*/
|
122 |
|
|
#define MLD6_UNSOLICITED_REPORT_INTERVAL 10
|
123 |
|
|
|
124 |
|
|
static struct ip6_pktopts ip6_opts;
|
125 |
|
|
static int mld6_timers_are_running;
|
126 |
|
|
/* XXX: These are necessary for KAME's link-local hack */
|
127 |
|
|
static struct in6_addr mld6_all_nodes_linklocal = IN6ADDR_LINKLOCAL_ALLNODES_INIT;
|
128 |
|
|
static struct in6_addr mld6_all_routers_linklocal = IN6ADDR_LINKLOCAL_ALLROUTERS_INIT;
|
129 |
|
|
|
130 |
|
|
static void mld6_sendpkt __P((struct in6_multi *, int, const struct in6_addr *));
|
131 |
|
|
|
132 |
|
|
void
|
133 |
|
|
mld6_init()
|
134 |
|
|
{
|
135 |
|
|
static u_int8_t hbh_buf[8];
|
136 |
|
|
struct ip6_hbh *hbh = (struct ip6_hbh *)hbh_buf;
|
137 |
|
|
u_int16_t rtalert_code = htons((u_int16_t)IP6OPT_RTALERT_MLD);
|
138 |
|
|
|
139 |
|
|
mld6_timers_are_running = 0;
|
140 |
|
|
|
141 |
|
|
/* ip6h_nxt will be fill in later */
|
142 |
|
|
hbh->ip6h_len = 0; /* (8 >> 3) - 1 */
|
143 |
|
|
|
144 |
|
|
/* XXX: grotty hard coding... */
|
145 |
|
|
hbh_buf[2] = IP6OPT_PADN; /* 2 byte padding */
|
146 |
|
|
hbh_buf[3] = 0;
|
147 |
|
|
hbh_buf[4] = IP6OPT_RTALERT;
|
148 |
|
|
hbh_buf[5] = IP6OPT_RTALERT_LEN - 2;
|
149 |
|
|
bcopy((caddr_t)&rtalert_code, &hbh_buf[6], sizeof(u_int16_t));
|
150 |
|
|
|
151 |
|
|
init_ip6pktopts(&ip6_opts);
|
152 |
|
|
ip6_opts.ip6po_hbh = hbh;
|
153 |
|
|
}
|
154 |
|
|
|
155 |
|
|
void
|
156 |
|
|
mld6_start_listening(in6m)
|
157 |
|
|
struct in6_multi *in6m;
|
158 |
|
|
{
|
159 |
|
|
#ifdef __NetBSD__
|
160 |
|
|
int s = splsoftnet();
|
161 |
|
|
#else
|
162 |
|
|
int s = splnet();
|
163 |
|
|
#endif
|
164 |
|
|
|
165 |
|
|
/*
|
166 |
|
|
* RFC2710 page 10:
|
167 |
|
|
* The node never sends a Report or Done for the link-scope all-nodes
|
168 |
|
|
* address.
|
169 |
|
|
* MLD messages are never sent for multicast addresses whose scope is 0
|
170 |
|
|
* (reserved) or 1 (node-local).
|
171 |
|
|
*/
|
172 |
|
|
mld6_all_nodes_linklocal.s6_addr16[1] =
|
173 |
|
|
htons(in6m->in6m_ifp->if_index); /* XXX */
|
174 |
|
|
if (IN6_ARE_ADDR_EQUAL(&in6m->in6m_addr, &mld6_all_nodes_linklocal) ||
|
175 |
|
|
IPV6_ADDR_MC_SCOPE(&in6m->in6m_addr) < IPV6_ADDR_SCOPE_LINKLOCAL) {
|
176 |
|
|
in6m->in6m_timer = 0;
|
177 |
|
|
in6m->in6m_state = MLD6_OTHERLISTENER;
|
178 |
|
|
} else {
|
179 |
|
|
mld6_sendpkt(in6m, MLD_LISTENER_REPORT, NULL);
|
180 |
|
|
in6m->in6m_timer = MLD6_RANDOM_DELAY(
|
181 |
|
|
MLD6_UNSOLICITED_REPORT_INTERVAL * PR_FASTHZ);
|
182 |
|
|
in6m->in6m_state = MLD6_IREPORTEDLAST;
|
183 |
|
|
mld6_timers_are_running = 1;
|
184 |
|
|
}
|
185 |
|
|
splx(s);
|
186 |
|
|
}
|
187 |
|
|
|
188 |
|
|
void
|
189 |
|
|
mld6_stop_listening(in6m)
|
190 |
|
|
struct in6_multi *in6m;
|
191 |
|
|
{
|
192 |
|
|
mld6_all_nodes_linklocal.s6_addr16[1] =
|
193 |
|
|
htons(in6m->in6m_ifp->if_index); /* XXX */
|
194 |
|
|
mld6_all_routers_linklocal.s6_addr16[1] =
|
195 |
|
|
htons(in6m->in6m_ifp->if_index); /* XXX: necessary when mrouting */
|
196 |
|
|
|
197 |
|
|
if (in6m->in6m_state == MLD6_IREPORTEDLAST &&
|
198 |
|
|
(!IN6_ARE_ADDR_EQUAL(&in6m->in6m_addr, &mld6_all_nodes_linklocal)) &&
|
199 |
|
|
IPV6_ADDR_MC_SCOPE(&in6m->in6m_addr) > IPV6_ADDR_SCOPE_INTFACELOCAL)
|
200 |
|
|
mld6_sendpkt(in6m, MLD_LISTENER_DONE,
|
201 |
|
|
&mld6_all_routers_linklocal);
|
202 |
|
|
}
|
203 |
|
|
|
204 |
|
|
void
|
205 |
|
|
mld6_input(m, off)
|
206 |
|
|
struct mbuf *m;
|
207 |
|
|
int off;
|
208 |
|
|
{
|
209 |
|
|
struct ip6_hdr *ip6 = mtod(m, struct ip6_hdr *);
|
210 |
|
|
struct mld_hdr *mldh;
|
211 |
|
|
struct ifnet *ifp = m->m_pkthdr.rcvif;
|
212 |
|
|
struct in6_multi *in6m;
|
213 |
|
|
struct in6_ifaddr *ia;
|
214 |
|
|
#if defined(__FreeBSD__) && __FreeBSD__ >= 3
|
215 |
|
|
struct ifmultiaddr *ifma;
|
216 |
|
|
#endif
|
217 |
|
|
int timer; /* timer value in the MLD query header */
|
218 |
|
|
|
219 |
|
|
#ifndef PULLDOWN_TEST
|
220 |
|
|
IP6_EXTHDR_CHECK(m, off, sizeof(*mldh),);
|
221 |
|
|
mldh = (struct mld_hdr *)(mtod(m, caddr_t) + off);
|
222 |
|
|
#else
|
223 |
|
|
IP6_EXTHDR_GET(mldh, struct mld_hdr *, m, off, sizeof(*mldh));
|
224 |
|
|
if (mldh == NULL) {
|
225 |
|
|
icmp6stat.icp6s_tooshort++;
|
226 |
|
|
return;
|
227 |
|
|
}
|
228 |
|
|
#endif
|
229 |
|
|
|
230 |
|
|
/* source address validation */
|
231 |
|
|
ip6 = mtod(m, struct ip6_hdr *); /* in case mpullup */
|
232 |
|
|
if (!(IN6_IS_ADDR_LINKLOCAL(&ip6->ip6_src) ||
|
233 |
|
|
IN6_IS_ADDR_UNSPECIFIED(&ip6->ip6_src))) {
|
234 |
|
|
#if 0 /* do not log in an input path */
|
235 |
|
|
log(LOG_INFO,
|
236 |
|
|
"mld6_input: src %s is not link-local (grp=%s)\n",
|
237 |
|
|
ip6_sprintf(&ip6->ip6_src),
|
238 |
|
|
ip6_sprintf(&mldh->mld_addr));
|
239 |
|
|
#endif
|
240 |
|
|
/*
|
241 |
|
|
* spec (RFC2710) does not explicitly
|
242 |
|
|
* specify to discard the packet from a non link-local
|
243 |
|
|
* source address. But we believe it's expected to do so.
|
244 |
|
|
*/
|
245 |
|
|
m_freem(m);
|
246 |
|
|
return;
|
247 |
|
|
}
|
248 |
|
|
|
249 |
|
|
/*
|
250 |
|
|
* In the MLD6 specification, there are 3 states and a flag.
|
251 |
|
|
*
|
252 |
|
|
* In Non-Listener state, we simply don't have a membership record.
|
253 |
|
|
* In Delaying Listener state, our timer is running (in6m->in6m_timer)
|
254 |
|
|
* In Idle Listener state, our timer is not running (in6m->in6m_timer==0)
|
255 |
|
|
*
|
256 |
|
|
* The flag is in6m->in6m_state, it is set to MLD6_OTHERLISTENER if
|
257 |
|
|
* we have heard a report from another member, or MLD6_IREPORTEDLAST
|
258 |
|
|
* if we sent the last report.
|
259 |
|
|
*/
|
260 |
|
|
switch (mldh->mld_type) {
|
261 |
|
|
case MLD_LISTENER_QUERY:
|
262 |
|
|
if (ifp->if_flags & IFF_LOOPBACK)
|
263 |
|
|
break;
|
264 |
|
|
|
265 |
|
|
if (!IN6_IS_ADDR_UNSPECIFIED(&mldh->mld_addr) &&
|
266 |
|
|
!IN6_IS_ADDR_MULTICAST(&mldh->mld_addr))
|
267 |
|
|
break; /* print error or log stat? */
|
268 |
|
|
if (IN6_IS_ADDR_MC_LINKLOCAL(&mldh->mld_addr))
|
269 |
|
|
mldh->mld_addr.s6_addr16[1] =
|
270 |
|
|
htons(ifp->if_index); /* XXX */
|
271 |
|
|
|
272 |
|
|
/*
|
273 |
|
|
* - Start the timers in all of our membership records
|
274 |
|
|
* that the query applies to for the interface on
|
275 |
|
|
* which the query arrived excl. those that belong
|
276 |
|
|
* to the "all-nodes" group (ff02::1).
|
277 |
|
|
* - Restart any timer that is already running but has
|
278 |
|
|
* A value longer than the requested timeout.
|
279 |
|
|
* - Use the value specified in the query message as
|
280 |
|
|
* the maximum timeout.
|
281 |
|
|
*/
|
282 |
|
|
IFP_TO_IA6(ifp, ia);
|
283 |
|
|
if (ia == NULL)
|
284 |
|
|
break;
|
285 |
|
|
|
286 |
|
|
/*
|
287 |
|
|
* XXX: System timer resolution is too low to handle Max
|
288 |
|
|
* Response Delay, so set 1 to the internal timer even if
|
289 |
|
|
* the calculated value equals to zero when Max Response
|
290 |
|
|
* Delay is positive.
|
291 |
|
|
*/
|
292 |
|
|
timer = ntohs(mldh->mld_maxdelay)*PR_FASTHZ/MLD6_TIMER_SCALE;
|
293 |
|
|
if (timer == 0 && mldh->mld_maxdelay)
|
294 |
|
|
timer = 1;
|
295 |
|
|
mld6_all_nodes_linklocal.s6_addr16[1] =
|
296 |
|
|
htons(ifp->if_index); /* XXX */
|
297 |
|
|
|
298 |
|
|
#if defined(__FreeBSD__) && __FreeBSD__ >= 3
|
299 |
|
|
LIST_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link)
|
300 |
|
|
#else
|
301 |
|
|
for (in6m = ia->ia6_multiaddrs.lh_first;
|
302 |
|
|
in6m;
|
303 |
|
|
in6m = in6m->in6m_entry.le_next)
|
304 |
|
|
#endif
|
305 |
|
|
{
|
306 |
|
|
#if defined(__FreeBSD__) && __FreeBSD__ >= 3
|
307 |
|
|
if (ifma->ifma_addr->sa_family != AF_INET6)
|
308 |
|
|
continue;
|
309 |
|
|
in6m = (struct in6_multi *)ifma->ifma_protospec;
|
310 |
|
|
if (IN6_ARE_ADDR_EQUAL(&in6m->in6m_addr,
|
311 |
|
|
&mld6_all_nodes_linklocal) ||
|
312 |
|
|
IPV6_ADDR_MC_SCOPE(&in6m->in6m_addr) <
|
313 |
|
|
IPV6_ADDR_SCOPE_LINKLOCAL)
|
314 |
|
|
continue;
|
315 |
|
|
#else
|
316 |
|
|
if (IN6_ARE_ADDR_EQUAL(&in6m->in6m_addr,
|
317 |
|
|
&mld6_all_nodes_linklocal) ||
|
318 |
|
|
IPV6_ADDR_MC_SCOPE(&in6m->in6m_addr) <
|
319 |
|
|
IPV6_ADDR_SCOPE_LINKLOCAL)
|
320 |
|
|
continue;
|
321 |
|
|
#endif
|
322 |
|
|
|
323 |
|
|
if (IN6_IS_ADDR_UNSPECIFIED(&mldh->mld_addr) ||
|
324 |
|
|
IN6_ARE_ADDR_EQUAL(&mldh->mld_addr,
|
325 |
|
|
&in6m->in6m_addr))
|
326 |
|
|
{
|
327 |
|
|
if (timer == 0) {
|
328 |
|
|
/* send a report immediately */
|
329 |
|
|
mld6_sendpkt(in6m, MLD_LISTENER_REPORT,
|
330 |
|
|
NULL);
|
331 |
|
|
in6m->in6m_timer = 0; /* reset timer */
|
332 |
|
|
in6m->in6m_state = MLD6_IREPORTEDLAST;
|
333 |
|
|
}
|
334 |
|
|
else if (in6m->in6m_timer == 0 || /* idle */
|
335 |
|
|
in6m->in6m_timer > timer) {
|
336 |
|
|
in6m->in6m_timer =
|
337 |
|
|
MLD6_RANDOM_DELAY(timer);
|
338 |
|
|
mld6_timers_are_running = 1;
|
339 |
|
|
}
|
340 |
|
|
}
|
341 |
|
|
}
|
342 |
|
|
|
343 |
|
|
if (IN6_IS_ADDR_MC_LINKLOCAL(&mldh->mld_addr))
|
344 |
|
|
mldh->mld_addr.s6_addr16[1] = 0; /* XXX */
|
345 |
|
|
break;
|
346 |
|
|
case MLD_LISTENER_REPORT:
|
347 |
|
|
/*
|
348 |
|
|
* For fast leave to work, we have to know that we are the
|
349 |
|
|
* last person to send a report for this group. Reports
|
350 |
|
|
* can potentially get looped back if we are a multicast
|
351 |
|
|
* router, so discard reports sourced by me.
|
352 |
|
|
* Note that it is impossible to check IFF_LOOPBACK flag of
|
353 |
|
|
* ifp for this purpose, since ip6_mloopback pass the physical
|
354 |
|
|
* interface to looutput.
|
355 |
|
|
*/
|
356 |
|
|
if (m->m_flags & M_LOOP) /* XXX: grotty flag, but efficient */
|
357 |
|
|
break;
|
358 |
|
|
|
359 |
|
|
if (!IN6_IS_ADDR_MULTICAST(&mldh->mld_addr))
|
360 |
|
|
break;
|
361 |
|
|
|
362 |
|
|
if (IN6_IS_ADDR_MC_LINKLOCAL(&mldh->mld_addr))
|
363 |
|
|
mldh->mld_addr.s6_addr16[1] =
|
364 |
|
|
htons(ifp->if_index); /* XXX */
|
365 |
|
|
/*
|
366 |
|
|
* If we belong to the group being reported, stop
|
367 |
|
|
* our timer for that group.
|
368 |
|
|
*/
|
369 |
|
|
IN6_LOOKUP_MULTI(mldh->mld_addr, ifp, in6m);
|
370 |
|
|
if (in6m) {
|
371 |
|
|
in6m->in6m_timer = 0; /* transit to idle state */
|
372 |
|
|
in6m->in6m_state = MLD6_OTHERLISTENER; /* clear flag */
|
373 |
|
|
}
|
374 |
|
|
|
375 |
|
|
if (IN6_IS_ADDR_MC_LINKLOCAL(&mldh->mld_addr))
|
376 |
|
|
mldh->mld_addr.s6_addr16[1] = 0; /* XXX */
|
377 |
|
|
break;
|
378 |
|
|
default: /* this is impossible */
|
379 |
|
|
log(LOG_ERR, "mld6_input: illegal type(%d)", mldh->mld_type);
|
380 |
|
|
break;
|
381 |
|
|
}
|
382 |
|
|
|
383 |
|
|
m_freem(m);
|
384 |
|
|
}
|
385 |
|
|
|
386 |
|
|
void
|
387 |
|
|
mld6_fasttimeo()
|
388 |
|
|
{
|
389 |
|
|
struct in6_multi *in6m;
|
390 |
|
|
struct in6_multistep step;
|
391 |
|
|
int s;
|
392 |
|
|
|
393 |
|
|
/*
|
394 |
|
|
* Quick check to see if any work needs to be done, in order
|
395 |
|
|
* to minimize the overhead of fasttimo processing.
|
396 |
|
|
*/
|
397 |
|
|
if (!mld6_timers_are_running)
|
398 |
|
|
return;
|
399 |
|
|
|
400 |
|
|
#ifdef __NetBSD__
|
401 |
|
|
s = splsoftnet();
|
402 |
|
|
#else
|
403 |
|
|
s = splnet();
|
404 |
|
|
#endif
|
405 |
|
|
mld6_timers_are_running = 0;
|
406 |
|
|
IN6_FIRST_MULTI(step, in6m);
|
407 |
|
|
while (in6m != NULL) {
|
408 |
|
|
if (in6m->in6m_timer == 0) {
|
409 |
|
|
/* do nothing */
|
410 |
|
|
} else if (--in6m->in6m_timer == 0) {
|
411 |
|
|
mld6_sendpkt(in6m, MLD_LISTENER_REPORT, NULL);
|
412 |
|
|
in6m->in6m_state = MLD6_IREPORTEDLAST;
|
413 |
|
|
} else {
|
414 |
|
|
mld6_timers_are_running = 1;
|
415 |
|
|
}
|
416 |
|
|
IN6_NEXT_MULTI(step, in6m);
|
417 |
|
|
}
|
418 |
|
|
splx(s);
|
419 |
|
|
}
|
420 |
|
|
|
421 |
|
|
static void
|
422 |
|
|
mld6_sendpkt(in6m, type, dst)
|
423 |
|
|
struct in6_multi *in6m;
|
424 |
|
|
int type;
|
425 |
|
|
const struct in6_addr *dst;
|
426 |
|
|
{
|
427 |
|
|
struct mbuf *mh, *md;
|
428 |
|
|
struct mld_hdr *mldh;
|
429 |
|
|
struct ip6_hdr *ip6;
|
430 |
|
|
struct ip6_moptions im6o;
|
431 |
|
|
struct in6_ifaddr *ia;
|
432 |
|
|
struct ifnet *ifp = in6m->in6m_ifp;
|
433 |
|
|
int ignflags;
|
434 |
|
|
|
435 |
|
|
/*
|
436 |
|
|
* At first, find a link local address on the outgoing interface
|
437 |
|
|
* to use as the source address of the MLD packet.
|
438 |
|
|
* We do not reject tentative addresses for MLD report to deal with
|
439 |
|
|
* the case where we first join a link-local address.
|
440 |
|
|
*/
|
441 |
|
|
ignflags = (IN6_IFF_NOTREADY|IN6_IFF_ANYCAST) & ~IN6_IFF_TENTATIVE;
|
442 |
|
|
if ((ia = in6ifa_ifpforlinklocal(ifp, ignflags)) == NULL)
|
443 |
|
|
return;
|
444 |
|
|
if ((ia->ia6_flags & IN6_IFF_TENTATIVE))
|
445 |
|
|
ia = NULL;
|
446 |
|
|
|
447 |
|
|
/*
|
448 |
|
|
* Allocate mbufs to store ip6 header and MLD header.
|
449 |
|
|
* We allocate 2 mbufs and make chain in advance because
|
450 |
|
|
* it is more convenient when inserting the hop-by-hop option later.
|
451 |
|
|
*/
|
452 |
|
|
MGETHDR(mh, M_DONTWAIT, MT_HEADER);
|
453 |
|
|
if (mh == NULL)
|
454 |
|
|
return;
|
455 |
|
|
MGET(md, M_DONTWAIT, MT_DATA);
|
456 |
|
|
if (md == NULL) {
|
457 |
|
|
m_free(mh);
|
458 |
|
|
return;
|
459 |
|
|
}
|
460 |
|
|
mh->m_next = md;
|
461 |
|
|
|
462 |
|
|
mh->m_pkthdr.rcvif = NULL;
|
463 |
|
|
mh->m_pkthdr.len = sizeof(struct ip6_hdr) + sizeof(struct mld_hdr);
|
464 |
|
|
mh->m_len = sizeof(struct ip6_hdr);
|
465 |
|
|
MH_ALIGN(mh, sizeof(struct ip6_hdr));
|
466 |
|
|
|
467 |
|
|
/* fill in the ip6 header */
|
468 |
|
|
ip6 = mtod(mh, struct ip6_hdr *);
|
469 |
|
|
ip6->ip6_flow = 0;
|
470 |
|
|
ip6->ip6_vfc &= ~IPV6_VERSION_MASK;
|
471 |
|
|
ip6->ip6_vfc |= IPV6_VERSION;
|
472 |
|
|
/* ip6_plen will be set later */
|
473 |
|
|
ip6->ip6_nxt = IPPROTO_ICMPV6;
|
474 |
|
|
/* ip6_hlim will be set by im6o.im6o_multicast_hlim */
|
475 |
|
|
ip6->ip6_src = ia ? ia->ia_addr.sin6_addr : in6addr_any;
|
476 |
|
|
ip6->ip6_dst = dst ? *dst : in6m->in6m_addr;
|
477 |
|
|
|
478 |
|
|
/* fill in the MLD header */
|
479 |
|
|
md->m_len = sizeof(struct mld_hdr);
|
480 |
|
|
mldh = mtod(md, struct mld_hdr *);
|
481 |
|
|
mldh->mld_type = type;
|
482 |
|
|
mldh->mld_code = 0;
|
483 |
|
|
mldh->mld_cksum = 0;
|
484 |
|
|
/* XXX: we assume the function will not be called for query messages */
|
485 |
|
|
mldh->mld_maxdelay = 0;
|
486 |
|
|
mldh->mld_reserved = 0;
|
487 |
|
|
mldh->mld_addr = in6m->in6m_addr;
|
488 |
|
|
if (IN6_IS_ADDR_MC_LINKLOCAL(&mldh->mld_addr))
|
489 |
|
|
mldh->mld_addr.s6_addr16[1] = 0; /* XXX */
|
490 |
|
|
mldh->mld_cksum = in6_cksum(mh, IPPROTO_ICMPV6,
|
491 |
|
|
sizeof(struct ip6_hdr),
|
492 |
|
|
sizeof(struct mld_hdr));
|
493 |
|
|
|
494 |
|
|
/* construct multicast option */
|
495 |
|
|
bzero(&im6o, sizeof(im6o));
|
496 |
|
|
im6o.im6o_multicast_ifp = ifp;
|
497 |
|
|
im6o.im6o_multicast_hlim = 1;
|
498 |
|
|
|
499 |
|
|
/*
|
500 |
|
|
* Request loopback of the report if we are acting as a multicast
|
501 |
|
|
* router, so that the process-level routing daemon can hear it.
|
502 |
|
|
*/
|
503 |
|
|
im6o.im6o_multicast_loop = (ip6_mrouter != NULL);
|
504 |
|
|
|
505 |
|
|
/* increment output statictics */
|
506 |
|
|
icmp6stat.icp6s_outhist[type]++;
|
507 |
|
|
icmp6_ifstat_inc(ifp, ifs6_out_msg);
|
508 |
|
|
switch (type) {
|
509 |
|
|
case MLD_LISTENER_QUERY:
|
510 |
|
|
icmp6_ifstat_inc(ifp, ifs6_out_mldquery);
|
511 |
|
|
break;
|
512 |
|
|
case MLD_LISTENER_REPORT:
|
513 |
|
|
icmp6_ifstat_inc(ifp, ifs6_out_mldreport);
|
514 |
|
|
break;
|
515 |
|
|
case MLD_LISTENER_DONE:
|
516 |
|
|
icmp6_ifstat_inc(ifp, ifs6_out_mlddone);
|
517 |
|
|
break;
|
518 |
|
|
}
|
519 |
|
|
|
520 |
|
|
ip6_output(mh, &ip6_opts, NULL, ia ? 0 : IPV6_UNSPECSRC, &im6o, NULL);
|
521 |
|
|
}
|