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