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