igmp.c revision 1.20 1 1.20 hwr /* $NetBSD: igmp.c,v 1.20 1999/04/25 10:26:29 hwr Exp $ */
2 1.8 cgd
3 1.1 hpeyerl /*
4 1.10 mycroft * Internet Group Management Protocol (IGMP) routines.
5 1.1 hpeyerl *
6 1.10 mycroft * Written by Steve Deering, Stanford, May 1988.
7 1.10 mycroft * Modified by Rosen Sharma, Stanford, Aug 1994.
8 1.10 mycroft * Modified by Bill Fenner, Xerox PARC, Feb 1995.
9 1.1 hpeyerl *
10 1.10 mycroft * MULTICAST Revision: 1.3
11 1.1 hpeyerl */
12 1.17 scottr
13 1.17 scottr #include "opt_mrouting.h"
14 1.1 hpeyerl
15 1.1 hpeyerl #include <sys/param.h>
16 1.1 hpeyerl #include <sys/mbuf.h>
17 1.1 hpeyerl #include <sys/socket.h>
18 1.1 hpeyerl #include <sys/protosw.h>
19 1.15 christos #include <sys/systm.h>
20 1.1 hpeyerl
21 1.1 hpeyerl #include <net/if.h>
22 1.1 hpeyerl #include <net/route.h>
23 1.1 hpeyerl
24 1.1 hpeyerl #include <netinet/in.h>
25 1.1 hpeyerl #include <netinet/in_var.h>
26 1.1 hpeyerl #include <netinet/in_systm.h>
27 1.1 hpeyerl #include <netinet/ip.h>
28 1.1 hpeyerl #include <netinet/ip_var.h>
29 1.1 hpeyerl #include <netinet/igmp.h>
30 1.1 hpeyerl #include <netinet/igmp_var.h>
31 1.1 hpeyerl
32 1.15 christos #include <machine/stdarg.h>
33 1.15 christos
34 1.10 mycroft #define IP_MULTICASTOPTS 0
35 1.10 mycroft
36 1.10 mycroft int igmp_timers_are_running;
37 1.10 mycroft static struct router_info *rti_head;
38 1.1 hpeyerl
39 1.10 mycroft void igmp_sendpkt __P((struct in_multi *, int));
40 1.15 christos static int rti_fill __P((struct in_multi *));
41 1.15 christos static struct router_info * rti_find __P((struct ifnet *));
42 1.1 hpeyerl
43 1.1 hpeyerl void
44 1.1 hpeyerl igmp_init()
45 1.1 hpeyerl {
46 1.10 mycroft
47 1.1 hpeyerl /*
48 1.1 hpeyerl * To avoid byte-swapping the same value over and over again.
49 1.1 hpeyerl */
50 1.10 mycroft igmp_timers_are_running = 0;
51 1.10 mycroft rti_head = 0;
52 1.10 mycroft }
53 1.10 mycroft
54 1.10 mycroft static int
55 1.10 mycroft rti_fill(inm)
56 1.10 mycroft struct in_multi *inm;
57 1.10 mycroft {
58 1.10 mycroft register struct router_info *rti;
59 1.10 mycroft
60 1.10 mycroft for (rti = rti_head; rti != 0; rti = rti->rti_next) {
61 1.10 mycroft if (rti->rti_ifp == inm->inm_ifp) {
62 1.10 mycroft inm->inm_rti = rti;
63 1.10 mycroft if (rti->rti_type == IGMP_v1_ROUTER)
64 1.10 mycroft return (IGMP_v1_HOST_MEMBERSHIP_REPORT);
65 1.10 mycroft else
66 1.10 mycroft return (IGMP_v2_HOST_MEMBERSHIP_REPORT);
67 1.10 mycroft }
68 1.10 mycroft }
69 1.10 mycroft
70 1.10 mycroft rti = (struct router_info *)malloc(sizeof(struct router_info),
71 1.10 mycroft M_MRTABLE, M_NOWAIT);
72 1.10 mycroft rti->rti_ifp = inm->inm_ifp;
73 1.10 mycroft rti->rti_type = IGMP_v2_ROUTER;
74 1.10 mycroft rti->rti_next = rti_head;
75 1.10 mycroft rti_head = rti;
76 1.10 mycroft inm->inm_rti = rti;
77 1.10 mycroft return (IGMP_v2_HOST_MEMBERSHIP_REPORT);
78 1.10 mycroft }
79 1.10 mycroft
80 1.10 mycroft static struct router_info *
81 1.10 mycroft rti_find(ifp)
82 1.10 mycroft struct ifnet *ifp;
83 1.10 mycroft {
84 1.10 mycroft register struct router_info *rti;
85 1.10 mycroft
86 1.10 mycroft for (rti = rti_head; rti != 0; rti = rti->rti_next) {
87 1.10 mycroft if (rti->rti_ifp == ifp)
88 1.10 mycroft return (rti);
89 1.10 mycroft }
90 1.10 mycroft
91 1.10 mycroft rti = (struct router_info *)malloc(sizeof(struct router_info),
92 1.10 mycroft M_MRTABLE, M_NOWAIT);
93 1.10 mycroft rti->rti_ifp = ifp;
94 1.10 mycroft rti->rti_type = IGMP_v2_ROUTER;
95 1.10 mycroft rti->rti_next = rti_head;
96 1.10 mycroft rti_head = rti;
97 1.10 mycroft return (rti);
98 1.1 hpeyerl }
99 1.1 hpeyerl
100 1.1 hpeyerl void
101 1.15 christos #if __STDC__
102 1.15 christos igmp_input(struct mbuf *m, ...)
103 1.15 christos #else
104 1.15 christos igmp_input(m, va_alist)
105 1.15 christos struct mbuf *m;
106 1.15 christos va_dcl
107 1.15 christos #endif
108 1.15 christos {
109 1.1 hpeyerl register int iphlen;
110 1.10 mycroft register struct ifnet *ifp = m->m_pkthdr.rcvif;
111 1.10 mycroft register struct ip *ip = mtod(m, struct ip *);
112 1.1 hpeyerl register struct igmp *igmp;
113 1.1 hpeyerl register int minlen;
114 1.10 mycroft struct in_multi *inm;
115 1.10 mycroft struct in_multistep step;
116 1.10 mycroft struct router_info *rti;
117 1.1 hpeyerl register struct in_ifaddr *ia;
118 1.10 mycroft int timer;
119 1.15 christos va_list ap;
120 1.15 christos
121 1.15 christos va_start(ap, m);
122 1.15 christos iphlen = va_arg(ap, int);
123 1.15 christos va_end(ap);
124 1.1 hpeyerl
125 1.1 hpeyerl ++igmpstat.igps_rcv_total;
126 1.1 hpeyerl
127 1.1 hpeyerl /*
128 1.1 hpeyerl * Validate lengths
129 1.1 hpeyerl */
130 1.19 mycroft minlen = iphlen + IGMP_MINLEN;
131 1.19 mycroft if (ip->ip_len < minlen) {
132 1.1 hpeyerl ++igmpstat.igps_rcv_tooshort;
133 1.1 hpeyerl m_freem(m);
134 1.1 hpeyerl return;
135 1.1 hpeyerl }
136 1.1 hpeyerl if ((m->m_flags & M_EXT || m->m_len < minlen) &&
137 1.1 hpeyerl (m = m_pullup(m, minlen)) == 0) {
138 1.1 hpeyerl ++igmpstat.igps_rcv_tooshort;
139 1.1 hpeyerl return;
140 1.1 hpeyerl }
141 1.1 hpeyerl
142 1.1 hpeyerl /*
143 1.1 hpeyerl * Validate checksum
144 1.1 hpeyerl */
145 1.1 hpeyerl m->m_data += iphlen;
146 1.1 hpeyerl m->m_len -= iphlen;
147 1.1 hpeyerl igmp = mtod(m, struct igmp *);
148 1.19 mycroft if (in_cksum(m, ip->ip_len - iphlen)) {
149 1.1 hpeyerl ++igmpstat.igps_rcv_badsum;
150 1.1 hpeyerl m_freem(m);
151 1.1 hpeyerl return;
152 1.1 hpeyerl }
153 1.1 hpeyerl m->m_data -= iphlen;
154 1.1 hpeyerl m->m_len += iphlen;
155 1.1 hpeyerl ip = mtod(m, struct ip *);
156 1.1 hpeyerl
157 1.1 hpeyerl switch (igmp->igmp_type) {
158 1.1 hpeyerl
159 1.1 hpeyerl case IGMP_HOST_MEMBERSHIP_QUERY:
160 1.1 hpeyerl ++igmpstat.igps_rcv_queries;
161 1.1 hpeyerl
162 1.6 mycroft if (ifp->if_flags & IFF_LOOPBACK)
163 1.1 hpeyerl break;
164 1.1 hpeyerl
165 1.10 mycroft if (igmp->igmp_code == 0) {
166 1.10 mycroft rti = rti_find(ifp);
167 1.10 mycroft rti->rti_type = IGMP_v1_ROUTER;
168 1.10 mycroft rti->rti_age = 0;
169 1.10 mycroft
170 1.12 mycroft if (ip->ip_dst.s_addr != INADDR_ALLHOSTS_GROUP) {
171 1.10 mycroft ++igmpstat.igps_rcv_badqueries;
172 1.10 mycroft m_freem(m);
173 1.10 mycroft return;
174 1.10 mycroft }
175 1.10 mycroft
176 1.10 mycroft /*
177 1.10 mycroft * Start the timers in all of our membership records
178 1.10 mycroft * for the interface on which the query arrived,
179 1.10 mycroft * except those that are already running and those
180 1.10 mycroft * that belong to a "local" group (224.0.0.X).
181 1.10 mycroft */
182 1.10 mycroft IN_FIRST_MULTI(step, inm);
183 1.10 mycroft while (inm != NULL) {
184 1.10 mycroft if (inm->inm_ifp == ifp &&
185 1.10 mycroft inm->inm_timer == 0 &&
186 1.10 mycroft !IN_LOCAL_GROUP(inm->inm_addr.s_addr)) {
187 1.10 mycroft inm->inm_state = IGMP_DELAYING_MEMBER;
188 1.10 mycroft inm->inm_timer = IGMP_RANDOM_DELAY(
189 1.10 mycroft IGMP_MAX_HOST_REPORT_DELAY * PR_FASTHZ);
190 1.10 mycroft igmp_timers_are_running = 1;
191 1.10 mycroft }
192 1.10 mycroft IN_NEXT_MULTI(step, inm);
193 1.10 mycroft }
194 1.10 mycroft } else {
195 1.12 mycroft if (!IN_MULTICAST(ip->ip_dst.s_addr)) {
196 1.10 mycroft ++igmpstat.igps_rcv_badqueries;
197 1.10 mycroft m_freem(m);
198 1.10 mycroft return;
199 1.10 mycroft }
200 1.10 mycroft
201 1.10 mycroft timer = igmp->igmp_code * PR_FASTHZ / IGMP_TIMER_SCALE;
202 1.20 hwr if (timer == 0)
203 1.20 hwr timer =1;
204 1.10 mycroft
205 1.10 mycroft /*
206 1.10 mycroft * Start the timers in all of our membership records
207 1.10 mycroft * for the interface on which the query arrived,
208 1.10 mycroft * except those that are already running and those
209 1.10 mycroft * that belong to a "local" group (224.0.0.X). For
210 1.10 mycroft * timers already running, check if they need to be
211 1.10 mycroft * reset.
212 1.10 mycroft */
213 1.10 mycroft IN_FIRST_MULTI(step, inm);
214 1.10 mycroft while (inm != NULL) {
215 1.10 mycroft if (inm->inm_ifp == ifp &&
216 1.10 mycroft !IN_LOCAL_GROUP(inm->inm_addr.s_addr) &&
217 1.12 mycroft (ip->ip_dst.s_addr == INADDR_ALLHOSTS_GROUP ||
218 1.16 mycroft in_hosteq(ip->ip_dst, inm->inm_addr))) {
219 1.10 mycroft switch (inm->inm_state) {
220 1.10 mycroft case IGMP_DELAYING_MEMBER:
221 1.10 mycroft if (inm->inm_timer <= timer)
222 1.10 mycroft break;
223 1.10 mycroft /* FALLTHROUGH */
224 1.10 mycroft case IGMP_IDLE_MEMBER:
225 1.10 mycroft case IGMP_LAZY_MEMBER:
226 1.10 mycroft case IGMP_AWAKENING_MEMBER:
227 1.10 mycroft inm->inm_state =
228 1.10 mycroft IGMP_DELAYING_MEMBER;
229 1.10 mycroft inm->inm_timer =
230 1.10 mycroft IGMP_RANDOM_DELAY(timer);
231 1.10 mycroft igmp_timers_are_running = 1;
232 1.10 mycroft break;
233 1.10 mycroft case IGMP_SLEEPING_MEMBER:
234 1.10 mycroft inm->inm_state =
235 1.10 mycroft IGMP_AWAKENING_MEMBER;
236 1.10 mycroft break;
237 1.10 mycroft }
238 1.10 mycroft }
239 1.10 mycroft IN_NEXT_MULTI(step, inm);
240 1.10 mycroft }
241 1.10 mycroft }
242 1.10 mycroft
243 1.10 mycroft break;
244 1.10 mycroft
245 1.10 mycroft case IGMP_v1_HOST_MEMBERSHIP_REPORT:
246 1.10 mycroft ++igmpstat.igps_rcv_reports;
247 1.10 mycroft
248 1.10 mycroft if (ifp->if_flags & IFF_LOOPBACK)
249 1.10 mycroft break;
250 1.10 mycroft
251 1.12 mycroft if (!IN_MULTICAST(igmp->igmp_group.s_addr) ||
252 1.16 mycroft !in_hosteq(igmp->igmp_group, ip->ip_dst)) {
253 1.10 mycroft ++igmpstat.igps_rcv_badreports;
254 1.1 hpeyerl m_freem(m);
255 1.1 hpeyerl return;
256 1.1 hpeyerl }
257 1.1 hpeyerl
258 1.1 hpeyerl /*
259 1.10 mycroft * KLUDGE: if the IP source address of the report has an
260 1.10 mycroft * unspecified (i.e., zero) subnet number, as is allowed for
261 1.10 mycroft * a booting host, replace it with the correct subnet number
262 1.10 mycroft * so that a process-level multicast routing daemon can
263 1.10 mycroft * determine which subnet it arrived from. This is necessary
264 1.10 mycroft * to compensate for the lack of any way for a process to
265 1.10 mycroft * determine the arrival interface of an incoming packet.
266 1.1 hpeyerl */
267 1.12 mycroft if ((ip->ip_src.s_addr & IN_CLASSA_NET) == 0) {
268 1.18 tls IFP_TO_IA(ifp, ia); /* XXX */
269 1.10 mycroft if (ia)
270 1.12 mycroft ip->ip_src.s_addr = ia->ia_subnet;
271 1.10 mycroft }
272 1.10 mycroft
273 1.10 mycroft /*
274 1.10 mycroft * If we belong to the group being reported, stop
275 1.10 mycroft * our timer for that group.
276 1.10 mycroft */
277 1.10 mycroft IN_LOOKUP_MULTI(igmp->igmp_group, ifp, inm);
278 1.10 mycroft if (inm != NULL) {
279 1.10 mycroft inm->inm_timer = 0;
280 1.10 mycroft ++igmpstat.igps_rcv_ourreports;
281 1.10 mycroft
282 1.10 mycroft switch (inm->inm_state) {
283 1.10 mycroft case IGMP_IDLE_MEMBER:
284 1.10 mycroft case IGMP_LAZY_MEMBER:
285 1.10 mycroft case IGMP_AWAKENING_MEMBER:
286 1.10 mycroft case IGMP_SLEEPING_MEMBER:
287 1.10 mycroft inm->inm_state = IGMP_SLEEPING_MEMBER;
288 1.10 mycroft break;
289 1.10 mycroft case IGMP_DELAYING_MEMBER:
290 1.10 mycroft if (inm->inm_rti->rti_type == IGMP_v1_ROUTER)
291 1.10 mycroft inm->inm_state = IGMP_LAZY_MEMBER;
292 1.10 mycroft else
293 1.10 mycroft inm->inm_state = IGMP_SLEEPING_MEMBER;
294 1.10 mycroft break;
295 1.1 hpeyerl }
296 1.1 hpeyerl }
297 1.1 hpeyerl
298 1.1 hpeyerl break;
299 1.1 hpeyerl
300 1.10 mycroft case IGMP_v2_HOST_MEMBERSHIP_REPORT:
301 1.10 mycroft #ifdef MROUTING
302 1.10 mycroft /*
303 1.10 mycroft * Make sure we don't hear our own membership report. Fast
304 1.10 mycroft * leave requires knowing that we are the only member of a
305 1.10 mycroft * group.
306 1.10 mycroft */
307 1.18 tls IFP_TO_IA(ifp, ia); /* XXX */
308 1.16 mycroft if (ia && in_hosteq(ip->ip_src, ia->ia_addr.sin_addr))
309 1.10 mycroft break;
310 1.10 mycroft #endif
311 1.10 mycroft
312 1.1 hpeyerl ++igmpstat.igps_rcv_reports;
313 1.1 hpeyerl
314 1.6 mycroft if (ifp->if_flags & IFF_LOOPBACK)
315 1.1 hpeyerl break;
316 1.1 hpeyerl
317 1.12 mycroft if (!IN_MULTICAST(igmp->igmp_group.s_addr) ||
318 1.16 mycroft !in_hosteq(igmp->igmp_group, ip->ip_dst)) {
319 1.1 hpeyerl ++igmpstat.igps_rcv_badreports;
320 1.1 hpeyerl m_freem(m);
321 1.1 hpeyerl return;
322 1.1 hpeyerl }
323 1.1 hpeyerl
324 1.1 hpeyerl /*
325 1.1 hpeyerl * KLUDGE: if the IP source address of the report has an
326 1.1 hpeyerl * unspecified (i.e., zero) subnet number, as is allowed for
327 1.1 hpeyerl * a booting host, replace it with the correct subnet number
328 1.10 mycroft * so that a process-level multicast routing daemon can
329 1.1 hpeyerl * determine which subnet it arrived from. This is necessary
330 1.1 hpeyerl * to compensate for the lack of any way for a process to
331 1.1 hpeyerl * determine the arrival interface of an incoming packet.
332 1.1 hpeyerl */
333 1.12 mycroft if ((ip->ip_src.s_addr & IN_CLASSA_NET) == 0) {
334 1.10 mycroft #ifndef MROUTING
335 1.18 tls IFP_TO_IA(ifp, ia); /* XXX */
336 1.10 mycroft #endif
337 1.10 mycroft if (ia)
338 1.12 mycroft ip->ip_src.s_addr = ia->ia_subnet;
339 1.1 hpeyerl }
340 1.1 hpeyerl
341 1.1 hpeyerl /*
342 1.1 hpeyerl * If we belong to the group being reported, stop
343 1.1 hpeyerl * our timer for that group.
344 1.1 hpeyerl */
345 1.1 hpeyerl IN_LOOKUP_MULTI(igmp->igmp_group, ifp, inm);
346 1.1 hpeyerl if (inm != NULL) {
347 1.1 hpeyerl inm->inm_timer = 0;
348 1.1 hpeyerl ++igmpstat.igps_rcv_ourreports;
349 1.10 mycroft
350 1.10 mycroft switch (inm->inm_state) {
351 1.10 mycroft case IGMP_DELAYING_MEMBER:
352 1.10 mycroft case IGMP_IDLE_MEMBER:
353 1.10 mycroft case IGMP_AWAKENING_MEMBER:
354 1.10 mycroft inm->inm_state = IGMP_LAZY_MEMBER;
355 1.10 mycroft break;
356 1.10 mycroft case IGMP_LAZY_MEMBER:
357 1.10 mycroft case IGMP_SLEEPING_MEMBER:
358 1.10 mycroft break;
359 1.10 mycroft }
360 1.1 hpeyerl }
361 1.1 hpeyerl
362 1.1 hpeyerl break;
363 1.10 mycroft
364 1.1 hpeyerl }
365 1.1 hpeyerl
366 1.1 hpeyerl /*
367 1.1 hpeyerl * Pass all valid IGMP packets up to any process(es) listening
368 1.1 hpeyerl * on a raw IGMP socket.
369 1.1 hpeyerl */
370 1.1 hpeyerl rip_input(m);
371 1.1 hpeyerl }
372 1.1 hpeyerl
373 1.1 hpeyerl void
374 1.1 hpeyerl igmp_joingroup(inm)
375 1.1 hpeyerl struct in_multi *inm;
376 1.1 hpeyerl {
377 1.14 mycroft int s = splsoftnet();
378 1.10 mycroft
379 1.10 mycroft inm->inm_state = IGMP_IDLE_MEMBER;
380 1.1 hpeyerl
381 1.10 mycroft if (!IN_LOCAL_GROUP(inm->inm_addr.s_addr) &&
382 1.10 mycroft (inm->inm_ifp->if_flags & IFF_LOOPBACK) == 0) {
383 1.10 mycroft igmp_sendpkt(inm, rti_fill(inm));
384 1.10 mycroft inm->inm_state = IGMP_DELAYING_MEMBER;
385 1.10 mycroft inm->inm_timer = IGMP_RANDOM_DELAY(
386 1.10 mycroft IGMP_MAX_HOST_REPORT_DELAY * PR_FASTHZ);
387 1.10 mycroft igmp_timers_are_running = 1;
388 1.10 mycroft } else
389 1.1 hpeyerl inm->inm_timer = 0;
390 1.1 hpeyerl splx(s);
391 1.1 hpeyerl }
392 1.1 hpeyerl
393 1.1 hpeyerl void
394 1.1 hpeyerl igmp_leavegroup(inm)
395 1.1 hpeyerl struct in_multi *inm;
396 1.1 hpeyerl {
397 1.10 mycroft
398 1.10 mycroft switch (inm->inm_state) {
399 1.10 mycroft case IGMP_DELAYING_MEMBER:
400 1.10 mycroft case IGMP_IDLE_MEMBER:
401 1.10 mycroft if (!IN_LOCAL_GROUP(inm->inm_addr.s_addr) &&
402 1.10 mycroft (inm->inm_ifp->if_flags & IFF_LOOPBACK) == 0)
403 1.10 mycroft if (inm->inm_rti->rti_type != IGMP_v1_ROUTER)
404 1.10 mycroft igmp_sendpkt(inm, IGMP_HOST_LEAVE_MESSAGE);
405 1.10 mycroft break;
406 1.10 mycroft case IGMP_LAZY_MEMBER:
407 1.10 mycroft case IGMP_AWAKENING_MEMBER:
408 1.10 mycroft case IGMP_SLEEPING_MEMBER:
409 1.10 mycroft break;
410 1.10 mycroft }
411 1.1 hpeyerl }
412 1.1 hpeyerl
413 1.1 hpeyerl void
414 1.1 hpeyerl igmp_fasttimo()
415 1.1 hpeyerl {
416 1.1 hpeyerl register struct in_multi *inm;
417 1.1 hpeyerl struct in_multistep step;
418 1.10 mycroft int s;
419 1.1 hpeyerl
420 1.1 hpeyerl /*
421 1.1 hpeyerl * Quick check to see if any work needs to be done, in order
422 1.1 hpeyerl * to minimize the overhead of fasttimo processing.
423 1.1 hpeyerl */
424 1.1 hpeyerl if (!igmp_timers_are_running)
425 1.1 hpeyerl return;
426 1.1 hpeyerl
427 1.14 mycroft s = splsoftnet();
428 1.1 hpeyerl igmp_timers_are_running = 0;
429 1.1 hpeyerl IN_FIRST_MULTI(step, inm);
430 1.1 hpeyerl while (inm != NULL) {
431 1.1 hpeyerl if (inm->inm_timer == 0) {
432 1.1 hpeyerl /* do nothing */
433 1.1 hpeyerl } else if (--inm->inm_timer == 0) {
434 1.10 mycroft if (inm->inm_state == IGMP_DELAYING_MEMBER) {
435 1.10 mycroft if (inm->inm_rti->rti_type == IGMP_v1_ROUTER)
436 1.10 mycroft igmp_sendpkt(inm,
437 1.10 mycroft IGMP_v1_HOST_MEMBERSHIP_REPORT);
438 1.10 mycroft else
439 1.10 mycroft igmp_sendpkt(inm,
440 1.10 mycroft IGMP_v2_HOST_MEMBERSHIP_REPORT);
441 1.10 mycroft inm->inm_state = IGMP_IDLE_MEMBER;
442 1.10 mycroft }
443 1.1 hpeyerl } else {
444 1.1 hpeyerl igmp_timers_are_running = 1;
445 1.1 hpeyerl }
446 1.1 hpeyerl IN_NEXT_MULTI(step, inm);
447 1.1 hpeyerl }
448 1.1 hpeyerl splx(s);
449 1.1 hpeyerl }
450 1.1 hpeyerl
451 1.10 mycroft void
452 1.10 mycroft igmp_slowtimo()
453 1.10 mycroft {
454 1.10 mycroft register struct router_info *rti;
455 1.10 mycroft int s;
456 1.10 mycroft
457 1.14 mycroft s = splsoftnet();
458 1.10 mycroft for (rti = rti_head; rti != 0; rti = rti->rti_next) {
459 1.10 mycroft if (rti->rti_type == IGMP_v1_ROUTER &&
460 1.10 mycroft ++rti->rti_age >= IGMP_AGE_THRESHOLD) {
461 1.10 mycroft rti->rti_type = IGMP_v2_ROUTER;
462 1.10 mycroft }
463 1.10 mycroft }
464 1.10 mycroft splx(s);
465 1.10 mycroft }
466 1.10 mycroft
467 1.10 mycroft void
468 1.10 mycroft igmp_sendpkt(inm, type)
469 1.10 mycroft struct in_multi *inm;
470 1.10 mycroft int type;
471 1.1 hpeyerl {
472 1.10 mycroft struct mbuf *m;
473 1.10 mycroft struct igmp *igmp;
474 1.10 mycroft struct ip *ip;
475 1.10 mycroft struct ip_moptions imo;
476 1.10 mycroft #ifdef MROUTING
477 1.10 mycroft extern struct socket *ip_mrouter;
478 1.10 mycroft #endif /* MROUTING */
479 1.1 hpeyerl
480 1.1 hpeyerl MGETHDR(m, M_DONTWAIT, MT_HEADER);
481 1.1 hpeyerl if (m == NULL)
482 1.1 hpeyerl return;
483 1.1 hpeyerl /*
484 1.1 hpeyerl * Assume max_linkhdr + sizeof(struct ip) + IGMP_MINLEN
485 1.1 hpeyerl * is smaller than mbuf size returned by MGETHDR.
486 1.1 hpeyerl */
487 1.1 hpeyerl m->m_data += max_linkhdr;
488 1.1 hpeyerl m->m_len = sizeof(struct ip) + IGMP_MINLEN;
489 1.1 hpeyerl m->m_pkthdr.len = sizeof(struct ip) + IGMP_MINLEN;
490 1.1 hpeyerl
491 1.1 hpeyerl ip = mtod(m, struct ip *);
492 1.1 hpeyerl ip->ip_tos = 0;
493 1.1 hpeyerl ip->ip_len = sizeof(struct ip) + IGMP_MINLEN;
494 1.1 hpeyerl ip->ip_off = 0;
495 1.1 hpeyerl ip->ip_p = IPPROTO_IGMP;
496 1.16 mycroft ip->ip_src = zeroin_addr;
497 1.1 hpeyerl ip->ip_dst = inm->inm_addr;
498 1.1 hpeyerl
499 1.7 brezak m->m_data += sizeof(struct ip);
500 1.7 brezak m->m_len -= sizeof(struct ip);
501 1.7 brezak igmp = mtod(m, struct igmp *);
502 1.10 mycroft igmp->igmp_type = type;
503 1.1 hpeyerl igmp->igmp_code = 0;
504 1.1 hpeyerl igmp->igmp_group = inm->inm_addr;
505 1.1 hpeyerl igmp->igmp_cksum = 0;
506 1.1 hpeyerl igmp->igmp_cksum = in_cksum(m, IGMP_MINLEN);
507 1.7 brezak m->m_data -= sizeof(struct ip);
508 1.7 brezak m->m_len += sizeof(struct ip);
509 1.1 hpeyerl
510 1.10 mycroft imo.imo_multicast_ifp = inm->inm_ifp;
511 1.10 mycroft imo.imo_multicast_ttl = 1;
512 1.10 mycroft #ifdef RSVP_ISI
513 1.10 mycroft imo.imo_multicast_vif = -1;
514 1.10 mycroft #endif
515 1.1 hpeyerl /*
516 1.1 hpeyerl * Request loopback of the report if we are acting as a multicast
517 1.1 hpeyerl * router, so that the process-level routing demon can hear it.
518 1.1 hpeyerl */
519 1.1 hpeyerl #ifdef MROUTING
520 1.10 mycroft imo.imo_multicast_loop = (ip_mrouter != NULL);
521 1.10 mycroft #else
522 1.10 mycroft imo.imo_multicast_loop = 0;
523 1.10 mycroft #endif /* MROUTING */
524 1.10 mycroft
525 1.10 mycroft ip_output(m, (struct mbuf *)0, (struct route *)0, IP_MULTICASTOPTS,
526 1.10 mycroft &imo);
527 1.1 hpeyerl
528 1.1 hpeyerl ++igmpstat.igps_snd_reports;
529 1.1 hpeyerl }
530