igmp.c revision 1.18 1 1.18 tls /* $NetBSD: igmp.c,v 1.18 1998/02/13 18:21:40 tls 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.2 mycroft register int igmplen;
114 1.1 hpeyerl register int minlen;
115 1.10 mycroft struct in_multi *inm;
116 1.10 mycroft struct in_multistep step;
117 1.10 mycroft struct router_info *rti;
118 1.1 hpeyerl register struct in_ifaddr *ia;
119 1.10 mycroft int timer;
120 1.15 christos va_list ap;
121 1.15 christos
122 1.15 christos va_start(ap, m);
123 1.15 christos iphlen = va_arg(ap, int);
124 1.15 christos va_end(ap);
125 1.1 hpeyerl
126 1.1 hpeyerl ++igmpstat.igps_rcv_total;
127 1.1 hpeyerl
128 1.1 hpeyerl igmplen = ip->ip_len;
129 1.1 hpeyerl
130 1.1 hpeyerl /*
131 1.1 hpeyerl * Validate lengths
132 1.1 hpeyerl */
133 1.1 hpeyerl if (igmplen < IGMP_MINLEN) {
134 1.1 hpeyerl ++igmpstat.igps_rcv_tooshort;
135 1.1 hpeyerl m_freem(m);
136 1.1 hpeyerl return;
137 1.1 hpeyerl }
138 1.1 hpeyerl minlen = iphlen + IGMP_MINLEN;
139 1.1 hpeyerl if ((m->m_flags & M_EXT || m->m_len < minlen) &&
140 1.1 hpeyerl (m = m_pullup(m, minlen)) == 0) {
141 1.1 hpeyerl ++igmpstat.igps_rcv_tooshort;
142 1.1 hpeyerl return;
143 1.1 hpeyerl }
144 1.1 hpeyerl
145 1.1 hpeyerl /*
146 1.1 hpeyerl * Validate checksum
147 1.1 hpeyerl */
148 1.1 hpeyerl m->m_data += iphlen;
149 1.1 hpeyerl m->m_len -= iphlen;
150 1.1 hpeyerl igmp = mtod(m, struct igmp *);
151 1.1 hpeyerl if (in_cksum(m, igmplen)) {
152 1.1 hpeyerl ++igmpstat.igps_rcv_badsum;
153 1.1 hpeyerl m_freem(m);
154 1.1 hpeyerl return;
155 1.1 hpeyerl }
156 1.1 hpeyerl m->m_data -= iphlen;
157 1.1 hpeyerl m->m_len += iphlen;
158 1.1 hpeyerl ip = mtod(m, struct ip *);
159 1.1 hpeyerl
160 1.1 hpeyerl switch (igmp->igmp_type) {
161 1.1 hpeyerl
162 1.1 hpeyerl case IGMP_HOST_MEMBERSHIP_QUERY:
163 1.1 hpeyerl ++igmpstat.igps_rcv_queries;
164 1.1 hpeyerl
165 1.6 mycroft if (ifp->if_flags & IFF_LOOPBACK)
166 1.1 hpeyerl break;
167 1.1 hpeyerl
168 1.10 mycroft if (igmp->igmp_code == 0) {
169 1.10 mycroft rti = rti_find(ifp);
170 1.10 mycroft rti->rti_type = IGMP_v1_ROUTER;
171 1.10 mycroft rti->rti_age = 0;
172 1.10 mycroft
173 1.12 mycroft if (ip->ip_dst.s_addr != INADDR_ALLHOSTS_GROUP) {
174 1.10 mycroft ++igmpstat.igps_rcv_badqueries;
175 1.10 mycroft m_freem(m);
176 1.10 mycroft return;
177 1.10 mycroft }
178 1.10 mycroft
179 1.10 mycroft /*
180 1.10 mycroft * Start the timers in all of our membership records
181 1.10 mycroft * for the interface on which the query arrived,
182 1.10 mycroft * except those that are already running and those
183 1.10 mycroft * that belong to a "local" group (224.0.0.X).
184 1.10 mycroft */
185 1.10 mycroft IN_FIRST_MULTI(step, inm);
186 1.10 mycroft while (inm != NULL) {
187 1.10 mycroft if (inm->inm_ifp == ifp &&
188 1.10 mycroft inm->inm_timer == 0 &&
189 1.10 mycroft !IN_LOCAL_GROUP(inm->inm_addr.s_addr)) {
190 1.10 mycroft inm->inm_state = IGMP_DELAYING_MEMBER;
191 1.10 mycroft inm->inm_timer = IGMP_RANDOM_DELAY(
192 1.10 mycroft IGMP_MAX_HOST_REPORT_DELAY * PR_FASTHZ);
193 1.10 mycroft igmp_timers_are_running = 1;
194 1.10 mycroft }
195 1.10 mycroft IN_NEXT_MULTI(step, inm);
196 1.10 mycroft }
197 1.10 mycroft } else {
198 1.12 mycroft if (!IN_MULTICAST(ip->ip_dst.s_addr)) {
199 1.10 mycroft ++igmpstat.igps_rcv_badqueries;
200 1.10 mycroft m_freem(m);
201 1.10 mycroft return;
202 1.10 mycroft }
203 1.10 mycroft
204 1.10 mycroft timer = igmp->igmp_code * PR_FASTHZ / IGMP_TIMER_SCALE;
205 1.10 mycroft
206 1.10 mycroft /*
207 1.10 mycroft * Start the timers in all of our membership records
208 1.10 mycroft * for the interface on which the query arrived,
209 1.10 mycroft * except those that are already running and those
210 1.10 mycroft * that belong to a "local" group (224.0.0.X). For
211 1.10 mycroft * timers already running, check if they need to be
212 1.10 mycroft * reset.
213 1.10 mycroft */
214 1.10 mycroft IN_FIRST_MULTI(step, inm);
215 1.10 mycroft while (inm != NULL) {
216 1.10 mycroft if (inm->inm_ifp == ifp &&
217 1.10 mycroft !IN_LOCAL_GROUP(inm->inm_addr.s_addr) &&
218 1.12 mycroft (ip->ip_dst.s_addr == INADDR_ALLHOSTS_GROUP ||
219 1.16 mycroft in_hosteq(ip->ip_dst, inm->inm_addr))) {
220 1.10 mycroft switch (inm->inm_state) {
221 1.10 mycroft case IGMP_DELAYING_MEMBER:
222 1.10 mycroft if (inm->inm_timer <= timer)
223 1.10 mycroft break;
224 1.10 mycroft /* FALLTHROUGH */
225 1.10 mycroft case IGMP_IDLE_MEMBER:
226 1.10 mycroft case IGMP_LAZY_MEMBER:
227 1.10 mycroft case IGMP_AWAKENING_MEMBER:
228 1.10 mycroft inm->inm_state =
229 1.10 mycroft IGMP_DELAYING_MEMBER;
230 1.10 mycroft inm->inm_timer =
231 1.10 mycroft IGMP_RANDOM_DELAY(timer);
232 1.10 mycroft igmp_timers_are_running = 1;
233 1.10 mycroft break;
234 1.10 mycroft case IGMP_SLEEPING_MEMBER:
235 1.10 mycroft inm->inm_state =
236 1.10 mycroft IGMP_AWAKENING_MEMBER;
237 1.10 mycroft break;
238 1.10 mycroft }
239 1.10 mycroft }
240 1.10 mycroft IN_NEXT_MULTI(step, inm);
241 1.10 mycroft }
242 1.10 mycroft }
243 1.10 mycroft
244 1.10 mycroft break;
245 1.10 mycroft
246 1.10 mycroft case IGMP_v1_HOST_MEMBERSHIP_REPORT:
247 1.10 mycroft ++igmpstat.igps_rcv_reports;
248 1.10 mycroft
249 1.10 mycroft if (ifp->if_flags & IFF_LOOPBACK)
250 1.10 mycroft break;
251 1.10 mycroft
252 1.12 mycroft if (!IN_MULTICAST(igmp->igmp_group.s_addr) ||
253 1.16 mycroft !in_hosteq(igmp->igmp_group, ip->ip_dst)) {
254 1.10 mycroft ++igmpstat.igps_rcv_badreports;
255 1.1 hpeyerl m_freem(m);
256 1.1 hpeyerl return;
257 1.1 hpeyerl }
258 1.1 hpeyerl
259 1.1 hpeyerl /*
260 1.10 mycroft * KLUDGE: if the IP source address of the report has an
261 1.10 mycroft * unspecified (i.e., zero) subnet number, as is allowed for
262 1.10 mycroft * a booting host, replace it with the correct subnet number
263 1.10 mycroft * so that a process-level multicast routing daemon can
264 1.10 mycroft * determine which subnet it arrived from. This is necessary
265 1.10 mycroft * to compensate for the lack of any way for a process to
266 1.10 mycroft * determine the arrival interface of an incoming packet.
267 1.1 hpeyerl */
268 1.12 mycroft if ((ip->ip_src.s_addr & IN_CLASSA_NET) == 0) {
269 1.18 tls IFP_TO_IA(ifp, ia); /* XXX */
270 1.10 mycroft if (ia)
271 1.12 mycroft ip->ip_src.s_addr = ia->ia_subnet;
272 1.10 mycroft }
273 1.10 mycroft
274 1.10 mycroft /*
275 1.10 mycroft * If we belong to the group being reported, stop
276 1.10 mycroft * our timer for that group.
277 1.10 mycroft */
278 1.10 mycroft IN_LOOKUP_MULTI(igmp->igmp_group, ifp, inm);
279 1.10 mycroft if (inm != NULL) {
280 1.10 mycroft inm->inm_timer = 0;
281 1.10 mycroft ++igmpstat.igps_rcv_ourreports;
282 1.10 mycroft
283 1.10 mycroft switch (inm->inm_state) {
284 1.10 mycroft case IGMP_IDLE_MEMBER:
285 1.10 mycroft case IGMP_LAZY_MEMBER:
286 1.10 mycroft case IGMP_AWAKENING_MEMBER:
287 1.10 mycroft case IGMP_SLEEPING_MEMBER:
288 1.10 mycroft inm->inm_state = IGMP_SLEEPING_MEMBER;
289 1.10 mycroft break;
290 1.10 mycroft case IGMP_DELAYING_MEMBER:
291 1.10 mycroft if (inm->inm_rti->rti_type == IGMP_v1_ROUTER)
292 1.10 mycroft inm->inm_state = IGMP_LAZY_MEMBER;
293 1.10 mycroft else
294 1.10 mycroft inm->inm_state = IGMP_SLEEPING_MEMBER;
295 1.10 mycroft break;
296 1.1 hpeyerl }
297 1.1 hpeyerl }
298 1.1 hpeyerl
299 1.1 hpeyerl break;
300 1.1 hpeyerl
301 1.10 mycroft case IGMP_v2_HOST_MEMBERSHIP_REPORT:
302 1.10 mycroft #ifdef MROUTING
303 1.10 mycroft /*
304 1.10 mycroft * Make sure we don't hear our own membership report. Fast
305 1.10 mycroft * leave requires knowing that we are the only member of a
306 1.10 mycroft * group.
307 1.10 mycroft */
308 1.18 tls IFP_TO_IA(ifp, ia); /* XXX */
309 1.16 mycroft if (ia && in_hosteq(ip->ip_src, ia->ia_addr.sin_addr))
310 1.10 mycroft break;
311 1.10 mycroft #endif
312 1.10 mycroft
313 1.1 hpeyerl ++igmpstat.igps_rcv_reports;
314 1.1 hpeyerl
315 1.6 mycroft if (ifp->if_flags & IFF_LOOPBACK)
316 1.1 hpeyerl break;
317 1.1 hpeyerl
318 1.12 mycroft if (!IN_MULTICAST(igmp->igmp_group.s_addr) ||
319 1.16 mycroft !in_hosteq(igmp->igmp_group, ip->ip_dst)) {
320 1.1 hpeyerl ++igmpstat.igps_rcv_badreports;
321 1.1 hpeyerl m_freem(m);
322 1.1 hpeyerl return;
323 1.1 hpeyerl }
324 1.1 hpeyerl
325 1.1 hpeyerl /*
326 1.1 hpeyerl * KLUDGE: if the IP source address of the report has an
327 1.1 hpeyerl * unspecified (i.e., zero) subnet number, as is allowed for
328 1.1 hpeyerl * a booting host, replace it with the correct subnet number
329 1.10 mycroft * so that a process-level multicast routing daemon can
330 1.1 hpeyerl * determine which subnet it arrived from. This is necessary
331 1.1 hpeyerl * to compensate for the lack of any way for a process to
332 1.1 hpeyerl * determine the arrival interface of an incoming packet.
333 1.1 hpeyerl */
334 1.12 mycroft if ((ip->ip_src.s_addr & IN_CLASSA_NET) == 0) {
335 1.10 mycroft #ifndef MROUTING
336 1.18 tls IFP_TO_IA(ifp, ia); /* XXX */
337 1.10 mycroft #endif
338 1.10 mycroft if (ia)
339 1.12 mycroft ip->ip_src.s_addr = ia->ia_subnet;
340 1.1 hpeyerl }
341 1.1 hpeyerl
342 1.1 hpeyerl /*
343 1.1 hpeyerl * If we belong to the group being reported, stop
344 1.1 hpeyerl * our timer for that group.
345 1.1 hpeyerl */
346 1.1 hpeyerl IN_LOOKUP_MULTI(igmp->igmp_group, ifp, inm);
347 1.1 hpeyerl if (inm != NULL) {
348 1.1 hpeyerl inm->inm_timer = 0;
349 1.1 hpeyerl ++igmpstat.igps_rcv_ourreports;
350 1.10 mycroft
351 1.10 mycroft switch (inm->inm_state) {
352 1.10 mycroft case IGMP_DELAYING_MEMBER:
353 1.10 mycroft case IGMP_IDLE_MEMBER:
354 1.10 mycroft case IGMP_AWAKENING_MEMBER:
355 1.10 mycroft inm->inm_state = IGMP_LAZY_MEMBER;
356 1.10 mycroft break;
357 1.10 mycroft case IGMP_LAZY_MEMBER:
358 1.10 mycroft case IGMP_SLEEPING_MEMBER:
359 1.10 mycroft break;
360 1.10 mycroft }
361 1.1 hpeyerl }
362 1.1 hpeyerl
363 1.1 hpeyerl break;
364 1.10 mycroft
365 1.1 hpeyerl }
366 1.1 hpeyerl
367 1.1 hpeyerl /*
368 1.1 hpeyerl * Pass all valid IGMP packets up to any process(es) listening
369 1.1 hpeyerl * on a raw IGMP socket.
370 1.1 hpeyerl */
371 1.1 hpeyerl rip_input(m);
372 1.1 hpeyerl }
373 1.1 hpeyerl
374 1.1 hpeyerl void
375 1.1 hpeyerl igmp_joingroup(inm)
376 1.1 hpeyerl struct in_multi *inm;
377 1.1 hpeyerl {
378 1.14 mycroft int s = splsoftnet();
379 1.10 mycroft
380 1.10 mycroft inm->inm_state = IGMP_IDLE_MEMBER;
381 1.1 hpeyerl
382 1.10 mycroft if (!IN_LOCAL_GROUP(inm->inm_addr.s_addr) &&
383 1.10 mycroft (inm->inm_ifp->if_flags & IFF_LOOPBACK) == 0) {
384 1.10 mycroft igmp_sendpkt(inm, rti_fill(inm));
385 1.10 mycroft inm->inm_state = IGMP_DELAYING_MEMBER;
386 1.10 mycroft inm->inm_timer = IGMP_RANDOM_DELAY(
387 1.10 mycroft IGMP_MAX_HOST_REPORT_DELAY * PR_FASTHZ);
388 1.10 mycroft igmp_timers_are_running = 1;
389 1.10 mycroft } else
390 1.1 hpeyerl inm->inm_timer = 0;
391 1.1 hpeyerl splx(s);
392 1.1 hpeyerl }
393 1.1 hpeyerl
394 1.1 hpeyerl void
395 1.1 hpeyerl igmp_leavegroup(inm)
396 1.1 hpeyerl struct in_multi *inm;
397 1.1 hpeyerl {
398 1.10 mycroft
399 1.10 mycroft switch (inm->inm_state) {
400 1.10 mycroft case IGMP_DELAYING_MEMBER:
401 1.10 mycroft case IGMP_IDLE_MEMBER:
402 1.10 mycroft if (!IN_LOCAL_GROUP(inm->inm_addr.s_addr) &&
403 1.10 mycroft (inm->inm_ifp->if_flags & IFF_LOOPBACK) == 0)
404 1.10 mycroft if (inm->inm_rti->rti_type != IGMP_v1_ROUTER)
405 1.10 mycroft igmp_sendpkt(inm, IGMP_HOST_LEAVE_MESSAGE);
406 1.10 mycroft break;
407 1.10 mycroft case IGMP_LAZY_MEMBER:
408 1.10 mycroft case IGMP_AWAKENING_MEMBER:
409 1.10 mycroft case IGMP_SLEEPING_MEMBER:
410 1.10 mycroft break;
411 1.10 mycroft }
412 1.1 hpeyerl }
413 1.1 hpeyerl
414 1.1 hpeyerl void
415 1.1 hpeyerl igmp_fasttimo()
416 1.1 hpeyerl {
417 1.1 hpeyerl register struct in_multi *inm;
418 1.1 hpeyerl struct in_multistep step;
419 1.10 mycroft int s;
420 1.1 hpeyerl
421 1.1 hpeyerl /*
422 1.1 hpeyerl * Quick check to see if any work needs to be done, in order
423 1.1 hpeyerl * to minimize the overhead of fasttimo processing.
424 1.1 hpeyerl */
425 1.1 hpeyerl if (!igmp_timers_are_running)
426 1.1 hpeyerl return;
427 1.1 hpeyerl
428 1.14 mycroft s = splsoftnet();
429 1.1 hpeyerl igmp_timers_are_running = 0;
430 1.1 hpeyerl IN_FIRST_MULTI(step, inm);
431 1.1 hpeyerl while (inm != NULL) {
432 1.1 hpeyerl if (inm->inm_timer == 0) {
433 1.1 hpeyerl /* do nothing */
434 1.1 hpeyerl } else if (--inm->inm_timer == 0) {
435 1.10 mycroft if (inm->inm_state == IGMP_DELAYING_MEMBER) {
436 1.10 mycroft if (inm->inm_rti->rti_type == IGMP_v1_ROUTER)
437 1.10 mycroft igmp_sendpkt(inm,
438 1.10 mycroft IGMP_v1_HOST_MEMBERSHIP_REPORT);
439 1.10 mycroft else
440 1.10 mycroft igmp_sendpkt(inm,
441 1.10 mycroft IGMP_v2_HOST_MEMBERSHIP_REPORT);
442 1.10 mycroft inm->inm_state = IGMP_IDLE_MEMBER;
443 1.10 mycroft }
444 1.1 hpeyerl } else {
445 1.1 hpeyerl igmp_timers_are_running = 1;
446 1.1 hpeyerl }
447 1.1 hpeyerl IN_NEXT_MULTI(step, inm);
448 1.1 hpeyerl }
449 1.1 hpeyerl splx(s);
450 1.1 hpeyerl }
451 1.1 hpeyerl
452 1.10 mycroft void
453 1.10 mycroft igmp_slowtimo()
454 1.10 mycroft {
455 1.10 mycroft register struct router_info *rti;
456 1.10 mycroft int s;
457 1.10 mycroft
458 1.14 mycroft s = splsoftnet();
459 1.10 mycroft for (rti = rti_head; rti != 0; rti = rti->rti_next) {
460 1.10 mycroft if (rti->rti_type == IGMP_v1_ROUTER &&
461 1.10 mycroft ++rti->rti_age >= IGMP_AGE_THRESHOLD) {
462 1.10 mycroft rti->rti_type = IGMP_v2_ROUTER;
463 1.10 mycroft }
464 1.10 mycroft }
465 1.10 mycroft splx(s);
466 1.10 mycroft }
467 1.10 mycroft
468 1.10 mycroft void
469 1.10 mycroft igmp_sendpkt(inm, type)
470 1.10 mycroft struct in_multi *inm;
471 1.10 mycroft int type;
472 1.1 hpeyerl {
473 1.10 mycroft struct mbuf *m;
474 1.10 mycroft struct igmp *igmp;
475 1.10 mycroft struct ip *ip;
476 1.10 mycroft struct ip_moptions imo;
477 1.10 mycroft #ifdef MROUTING
478 1.10 mycroft extern struct socket *ip_mrouter;
479 1.10 mycroft #endif /* MROUTING */
480 1.1 hpeyerl
481 1.1 hpeyerl MGETHDR(m, M_DONTWAIT, MT_HEADER);
482 1.1 hpeyerl if (m == NULL)
483 1.1 hpeyerl return;
484 1.1 hpeyerl /*
485 1.1 hpeyerl * Assume max_linkhdr + sizeof(struct ip) + IGMP_MINLEN
486 1.1 hpeyerl * is smaller than mbuf size returned by MGETHDR.
487 1.1 hpeyerl */
488 1.1 hpeyerl m->m_data += max_linkhdr;
489 1.1 hpeyerl m->m_len = sizeof(struct ip) + IGMP_MINLEN;
490 1.1 hpeyerl m->m_pkthdr.len = sizeof(struct ip) + IGMP_MINLEN;
491 1.1 hpeyerl
492 1.1 hpeyerl ip = mtod(m, struct ip *);
493 1.1 hpeyerl ip->ip_tos = 0;
494 1.1 hpeyerl ip->ip_len = sizeof(struct ip) + IGMP_MINLEN;
495 1.1 hpeyerl ip->ip_off = 0;
496 1.1 hpeyerl ip->ip_p = IPPROTO_IGMP;
497 1.16 mycroft ip->ip_src = zeroin_addr;
498 1.1 hpeyerl ip->ip_dst = inm->inm_addr;
499 1.1 hpeyerl
500 1.7 brezak m->m_data += sizeof(struct ip);
501 1.7 brezak m->m_len -= sizeof(struct ip);
502 1.7 brezak igmp = mtod(m, struct igmp *);
503 1.10 mycroft igmp->igmp_type = type;
504 1.1 hpeyerl igmp->igmp_code = 0;
505 1.1 hpeyerl igmp->igmp_group = inm->inm_addr;
506 1.1 hpeyerl igmp->igmp_cksum = 0;
507 1.1 hpeyerl igmp->igmp_cksum = in_cksum(m, IGMP_MINLEN);
508 1.7 brezak m->m_data -= sizeof(struct ip);
509 1.7 brezak m->m_len += sizeof(struct ip);
510 1.1 hpeyerl
511 1.10 mycroft imo.imo_multicast_ifp = inm->inm_ifp;
512 1.10 mycroft imo.imo_multicast_ttl = 1;
513 1.10 mycroft #ifdef RSVP_ISI
514 1.10 mycroft imo.imo_multicast_vif = -1;
515 1.10 mycroft #endif
516 1.1 hpeyerl /*
517 1.1 hpeyerl * Request loopback of the report if we are acting as a multicast
518 1.1 hpeyerl * router, so that the process-level routing demon can hear it.
519 1.1 hpeyerl */
520 1.1 hpeyerl #ifdef MROUTING
521 1.10 mycroft imo.imo_multicast_loop = (ip_mrouter != NULL);
522 1.10 mycroft #else
523 1.10 mycroft imo.imo_multicast_loop = 0;
524 1.10 mycroft #endif /* MROUTING */
525 1.10 mycroft
526 1.10 mycroft ip_output(m, (struct mbuf *)0, (struct route *)0, IP_MULTICASTOPTS,
527 1.10 mycroft &imo);
528 1.1 hpeyerl
529 1.1 hpeyerl ++igmpstat.igps_snd_reports;
530 1.1 hpeyerl }
531