ip6_mroute.c revision 1.83 1 /* $NetBSD: ip6_mroute.c,v 1.83 2007/07/09 21:11:12 ad Exp $ */
2 /* $KAME: ip6_mroute.c,v 1.49 2001/07/25 09:21:18 jinmei Exp $ */
3
4 /*
5 * Copyright (C) 1998 WIDE Project.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of the project nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 */
32
33 /* BSDI ip_mroute.c,v 2.10 1996/11/14 00:29:52 jch Exp */
34
35 /*
36 * Copyright (c) 1992, 1993
37 * The Regents of the University of California. All rights reserved.
38 *
39 * This code is derived from software contributed to Berkeley by
40 * Stephen Deering of Stanford University.
41 *
42 * Redistribution and use in source and binary forms, with or without
43 * modification, are permitted provided that the following conditions
44 * are met:
45 * 1. Redistributions of source code must retain the above copyright
46 * notice, this list of conditions and the following disclaimer.
47 * 2. Redistributions in binary form must reproduce the above copyright
48 * notice, this list of conditions and the following disclaimer in the
49 * documentation and/or other materials provided with the distribution.
50 * 3. Neither the name of the University nor the names of its contributors
51 * may be used to endorse or promote products derived from this software
52 * without specific prior written permission.
53 *
54 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
55 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
56 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
57 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
58 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
59 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
60 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
61 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
62 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
63 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
64 * SUCH DAMAGE.
65 *
66 * @(#)ip_mroute.c 8.2 (Berkeley) 11/15/93
67 */
68
69 /*
70 * Copyright (c) 1989 Stephen Deering
71 *
72 * This code is derived from software contributed to Berkeley by
73 * Stephen Deering of Stanford University.
74 *
75 * Redistribution and use in source and binary forms, with or without
76 * modification, are permitted provided that the following conditions
77 * are met:
78 * 1. Redistributions of source code must retain the above copyright
79 * notice, this list of conditions and the following disclaimer.
80 * 2. Redistributions in binary form must reproduce the above copyright
81 * notice, this list of conditions and the following disclaimer in the
82 * documentation and/or other materials provided with the distribution.
83 * 3. All advertising materials mentioning features or use of this software
84 * must display the following acknowledgement:
85 * This product includes software developed by the University of
86 * California, Berkeley and its contributors.
87 * 4. Neither the name of the University nor the names of its contributors
88 * may be used to endorse or promote products derived from this software
89 * without specific prior written permission.
90 *
91 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
92 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
93 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
94 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
95 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
96 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
97 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
98 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
99 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
100 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
101 * SUCH DAMAGE.
102 *
103 * @(#)ip_mroute.c 8.2 (Berkeley) 11/15/93
104 */
105
106 /*
107 * IP multicast forwarding procedures
108 *
109 * Written by David Waitzman, BBN Labs, August 1988.
110 * Modified by Steve Deering, Stanford, February 1989.
111 * Modified by Mark J. Steiglitz, Stanford, May, 1991
112 * Modified by Van Jacobson, LBL, January 1993
113 * Modified by Ajit Thyagarajan, PARC, August 1993
114 * Modified by Bill Fenner, PARC, April 1994
115 *
116 * MROUTING Revision: 3.5.1.2 + PIM-SMv2 (pimd) Support
117 */
118
119 #include <sys/cdefs.h>
120 __KERNEL_RCSID(0, "$NetBSD: ip6_mroute.c,v 1.83 2007/07/09 21:11:12 ad Exp $");
121
122 #include "opt_inet.h"
123 #include "opt_mrouting.h"
124
125 #include <sys/param.h>
126 #include <sys/systm.h>
127 #include <sys/callout.h>
128 #include <sys/mbuf.h>
129 #include <sys/socket.h>
130 #include <sys/socketvar.h>
131 #include <sys/sockio.h>
132 #include <sys/protosw.h>
133 #include <sys/errno.h>
134 #include <sys/time.h>
135 #include <sys/kernel.h>
136 #include <sys/ioctl.h>
137 #include <sys/sysctl.h>
138 #include <sys/syslog.h>
139
140 #include <net/if.h>
141 #include <net/route.h>
142 #include <net/raw_cb.h>
143
144 #include <netinet/in.h>
145 #include <netinet/in_var.h>
146 #include <netinet/icmp6.h>
147
148 #include <netinet/ip6.h>
149 #include <netinet6/ip6_var.h>
150 #include <netinet6/ip6_mroute.h>
151 #include <netinet6/scope6_var.h>
152 #include <netinet6/pim6.h>
153 #include <netinet6/pim6_var.h>
154 #include <netinet6/nd6.h>
155
156 #include <net/net_osdep.h>
157
158 static int ip6_mdq __P((struct mbuf *, struct ifnet *, struct mf6c *));
159 static void phyint_send __P((struct ip6_hdr *, struct mif6 *, struct mbuf *));
160
161 static int set_pim6 __P((int *));
162 static int get_pim6 __P((struct mbuf *));
163 static int socket_send __P((struct socket *, struct mbuf *,
164 struct sockaddr_in6 *));
165 static int register_send __P((struct ip6_hdr *, struct mif6 *, struct mbuf *));
166
167 /*
168 * Globals. All but ip6_mrouter, ip6_mrtproto and mrt6stat could be static,
169 * except for netstat or debugging purposes.
170 */
171 struct socket *ip6_mrouter = NULL;
172 int ip6_mrouter_ver = 0;
173 int ip6_mrtproto = IPPROTO_PIM; /* for netstat only */
174 struct mrt6stat mrt6stat;
175
176 #define NO_RTE_FOUND 0x1
177 #define RTE_FOUND 0x2
178
179 struct mf6c *mf6ctable[MF6CTBLSIZ];
180 u_char n6expire[MF6CTBLSIZ];
181 struct mif6 mif6table[MAXMIFS];
182 #ifdef MRT6DEBUG
183 u_int mrt6debug = 0; /* debug level */
184 #define DEBUG_MFC 0x02
185 #define DEBUG_FORWARD 0x04
186 #define DEBUG_EXPIRE 0x08
187 #define DEBUG_XMIT 0x10
188 #define DEBUG_REG 0x20
189 #define DEBUG_PIM 0x40
190 #endif
191
192 static void expire_upcalls __P((void *));
193 #define EXPIRE_TIMEOUT (hz / 4) /* 4x / second */
194 #define UPCALL_EXPIRE 6 /* number of timeouts */
195
196 #ifdef INET
197 #ifdef MROUTING
198 extern struct socket *ip_mrouter;
199 #endif
200 #endif
201
202 /*
203 * 'Interfaces' associated with decapsulator (so we can tell
204 * packets that went through it from ones that get reflected
205 * by a broken gateway). These interfaces are never linked into
206 * the system ifnet list & no routes point to them. I.e., packets
207 * can't be sent this way. They only exist as a placeholder for
208 * multicast source verification.
209 */
210 struct ifnet multicast_register_if6;
211
212 #define ENCAP_HOPS 64
213
214 /*
215 * Private variables.
216 */
217 static mifi_t nummifs = 0;
218 static mifi_t reg_mif_num = (mifi_t)-1;
219
220 struct pim6stat pim6stat;
221 static int pim6;
222
223 /*
224 * Hash function for a source, group entry
225 */
226 #define MF6CHASH(a, g) MF6CHASHMOD((a).s6_addr32[0] ^ (a).s6_addr32[1] ^ \
227 (a).s6_addr32[2] ^ (a).s6_addr32[3] ^ \
228 (g).s6_addr32[0] ^ (g).s6_addr32[1] ^ \
229 (g).s6_addr32[2] ^ (g).s6_addr32[3])
230
231 /*
232 * Find a route for a given origin IPv6 address and Multicast group address.
233 * Quality of service parameter to be added in the future!!!
234 */
235
236 #define MF6CFIND(o, g, rt) do { \
237 struct mf6c *_rt = mf6ctable[MF6CHASH(o,g)]; \
238 rt = NULL; \
239 mrt6stat.mrt6s_mfc_lookups++; \
240 while (_rt) { \
241 if (IN6_ARE_ADDR_EQUAL(&_rt->mf6c_origin.sin6_addr, &(o)) && \
242 IN6_ARE_ADDR_EQUAL(&_rt->mf6c_mcastgrp.sin6_addr, &(g)) && \
243 (_rt->mf6c_stall == NULL)) { \
244 rt = _rt; \
245 break; \
246 } \
247 _rt = _rt->mf6c_next; \
248 } \
249 if (rt == NULL) { \
250 mrt6stat.mrt6s_mfc_misses++; \
251 } \
252 } while (/*CONSTCOND*/ 0)
253
254 /*
255 * Macros to compute elapsed time efficiently
256 * Borrowed from Van Jacobson's scheduling code
257 */
258 #define TV_DELTA(a, b, delta) do { \
259 int xxs; \
260 \
261 delta = (a).tv_usec - (b).tv_usec; \
262 if ((xxs = (a).tv_sec - (b).tv_sec)) { \
263 switch (xxs) { \
264 case 2: \
265 delta += 1000000; \
266 /* FALLTHROUGH */ \
267 case 1: \
268 delta += 1000000; \
269 break; \
270 default: \
271 delta += (1000000 * xxs); \
272 } \
273 } \
274 } while (/*CONSTCOND*/ 0)
275
276 #define TV_LT(a, b) (((a).tv_usec < (b).tv_usec && \
277 (a).tv_sec <= (b).tv_sec) || (a).tv_sec < (b).tv_sec)
278
279 #ifdef UPCALL_TIMING
280 #define UPCALL_MAX 50
281 u_long upcall_data[UPCALL_MAX + 1];
282 static void collate();
283 #endif /* UPCALL_TIMING */
284
285 static int get_sg_cnt __P((struct sioc_sg_req6 *));
286 static int get_mif6_cnt __P((struct sioc_mif_req6 *));
287 static int ip6_mrouter_init __P((struct socket *, int, int));
288 static int add_m6if __P((struct mif6ctl *));
289 static int del_m6if __P((mifi_t *));
290 static int add_m6fc __P((struct mf6cctl *));
291 static int del_m6fc __P((struct mf6cctl *));
292
293 static callout_t expire_upcalls_ch;
294
295 /*
296 * Handle MRT setsockopt commands to modify the multicast routing tables.
297 */
298 int
299 ip6_mrouter_set(int cmd, struct socket *so, struct mbuf *m)
300 {
301 if (cmd != MRT6_INIT && so != ip6_mrouter)
302 return (EACCES);
303
304 switch (cmd) {
305 #ifdef MRT6_OINIT
306 case MRT6_OINIT:
307 #endif
308 case MRT6_INIT:
309 if (m == NULL || m->m_len < sizeof(int))
310 return (EINVAL);
311 return (ip6_mrouter_init(so, *mtod(m, int *), cmd));
312 case MRT6_DONE:
313 return (ip6_mrouter_done());
314 case MRT6_ADD_MIF:
315 if (m == NULL || m->m_len < sizeof(struct mif6ctl))
316 return (EINVAL);
317 return (add_m6if(mtod(m, struct mif6ctl *)));
318 case MRT6_DEL_MIF:
319 if (m == NULL || m->m_len < sizeof(mifi_t))
320 return (EINVAL);
321 return (del_m6if(mtod(m, mifi_t *)));
322 case MRT6_ADD_MFC:
323 if (m == NULL || m->m_len < sizeof(struct mf6cctl))
324 return (EINVAL);
325 return (add_m6fc(mtod(m, struct mf6cctl *)));
326 case MRT6_DEL_MFC:
327 if (m == NULL || m->m_len < sizeof(struct mf6cctl))
328 return (EINVAL);
329 return (del_m6fc(mtod(m, struct mf6cctl *)));
330 case MRT6_PIM:
331 if (m == NULL || m->m_len < sizeof(int))
332 return (EINVAL);
333 return (set_pim6(mtod(m, int *)));
334 default:
335 return (EOPNOTSUPP);
336 }
337 }
338
339 /*
340 * Handle MRT getsockopt commands
341 */
342 int
343 ip6_mrouter_get(int cmd, struct socket *so, struct mbuf **m)
344 {
345 struct mbuf *mb;
346
347 if (so != ip6_mrouter) return EACCES;
348
349 *m = mb = m_get(M_WAIT, MT_SOOPTS);
350
351 switch (cmd) {
352 case MRT6_PIM:
353 return get_pim6(mb);
354 default:
355 m_free(mb);
356 return EOPNOTSUPP;
357 }
358 }
359
360 /*
361 * Handle ioctl commands to obtain information from the cache
362 */
363 int
364 mrt6_ioctl(int cmd, void *data)
365 {
366
367 switch (cmd) {
368 case SIOCGETSGCNT_IN6:
369 return (get_sg_cnt((struct sioc_sg_req6 *)data));
370 case SIOCGETMIFCNT_IN6:
371 return (get_mif6_cnt((struct sioc_mif_req6 *)data));
372 default:
373 return (EINVAL);
374 }
375 }
376
377 /*
378 * returns the packet, byte, rpf-failure count for the source group provided
379 */
380 static int
381 get_sg_cnt(struct sioc_sg_req6 *req)
382 {
383 struct mf6c *rt;
384 int s;
385
386 s = splsoftnet();
387 MF6CFIND(req->src.sin6_addr, req->grp.sin6_addr, rt);
388 splx(s);
389 if (rt != NULL) {
390 req->pktcnt = rt->mf6c_pkt_cnt;
391 req->bytecnt = rt->mf6c_byte_cnt;
392 req->wrong_if = rt->mf6c_wrong_if;
393 } else
394 return (ESRCH);
395 #if 0
396 req->pktcnt = req->bytecnt = req->wrong_if = 0xffffffff;
397 #endif
398
399 return 0;
400 }
401
402 /*
403 * returns the input and output packet and byte counts on the mif provided
404 */
405 static int
406 get_mif6_cnt(struct sioc_mif_req6 *req)
407 {
408 mifi_t mifi = req->mifi;
409
410 if (mifi >= nummifs)
411 return EINVAL;
412
413 req->icount = mif6table[mifi].m6_pkt_in;
414 req->ocount = mif6table[mifi].m6_pkt_out;
415 req->ibytes = mif6table[mifi].m6_bytes_in;
416 req->obytes = mif6table[mifi].m6_bytes_out;
417
418 return 0;
419 }
420
421 /*
422 * Get PIM processiong global
423 */
424 static int
425 get_pim6(struct mbuf *m)
426 {
427 int *i;
428
429 i = mtod(m, int *);
430
431 *i = pim6;
432
433 return 0;
434 }
435
436 static int
437 set_pim6(int *i)
438 {
439 if ((*i != 1) && (*i != 0))
440 return EINVAL;
441
442 pim6 = *i;
443
444 return 0;
445 }
446
447 /*
448 * Enable multicast routing
449 */
450 static int
451 ip6_mrouter_init(struct socket *so, int v, int cmd)
452 {
453 #ifdef MRT6DEBUG
454 if (mrt6debug)
455 log(LOG_DEBUG,
456 "ip6_mrouter_init: so_type = %d, pr_protocol = %d\n",
457 so->so_type, so->so_proto->pr_protocol);
458 #endif
459
460 if (so->so_type != SOCK_RAW ||
461 so->so_proto->pr_protocol != IPPROTO_ICMPV6)
462 return (EOPNOTSUPP);
463
464 if (v != 1)
465 return (ENOPROTOOPT);
466
467 if (ip6_mrouter != NULL)
468 return (EADDRINUSE);
469
470 ip6_mrouter = so;
471 ip6_mrouter_ver = cmd;
472
473 bzero((void *)mf6ctable, sizeof(mf6ctable));
474 bzero((void *)n6expire, sizeof(n6expire));
475
476 pim6 = 0;/* used for stubbing out/in pim stuff */
477
478 callout_init(&expire_upcalls_ch, 0);
479 callout_reset(&expire_upcalls_ch, EXPIRE_TIMEOUT,
480 expire_upcalls, NULL);
481
482 #ifdef MRT6DEBUG
483 if (mrt6debug)
484 log(LOG_DEBUG, "ip6_mrouter_init\n");
485 #endif
486
487 return 0;
488 }
489
490 /*
491 * Disable multicast routing
492 */
493 int
494 ip6_mrouter_done()
495 {
496 mifi_t mifi;
497 int i;
498 struct ifnet *ifp;
499 struct in6_ifreq ifr;
500 struct mf6c *rt;
501 struct rtdetq *rte;
502 int s;
503
504 s = splsoftnet();
505
506 /*
507 * For each phyint in use, disable promiscuous reception of all IPv6
508 * multicasts.
509 */
510 #ifdef INET
511 #ifdef MROUTING
512 /*
513 * If there is still IPv4 multicast routing daemon,
514 * we remain interfaces to receive all muliticasted packets.
515 * XXX: there may be an interface in which the IPv4 multicast
516 * daemon is not interested...
517 */
518 if (!ip_mrouter)
519 #endif
520 #endif
521 {
522 for (mifi = 0; mifi < nummifs; mifi++) {
523 if (mif6table[mifi].m6_ifp &&
524 !(mif6table[mifi].m6_flags & MIFF_REGISTER)) {
525 ifr.ifr_addr.sin6_family = AF_INET6;
526 ifr.ifr_addr.sin6_addr= in6addr_any;
527 ifp = mif6table[mifi].m6_ifp;
528 (*ifp->if_ioctl)(ifp, SIOCDELMULTI,
529 (void *)&ifr);
530 }
531 }
532 }
533 #ifdef notyet
534 bzero((void *)qtable, sizeof(qtable));
535 bzero((void *)tbftable, sizeof(tbftable));
536 #endif
537 bzero((void *)mif6table, sizeof(mif6table));
538 nummifs = 0;
539
540 pim6 = 0; /* used to stub out/in pim specific code */
541
542 callout_stop(&expire_upcalls_ch);
543
544 /*
545 * Free all multicast forwarding cache entries.
546 */
547 for (i = 0; i < MF6CTBLSIZ; i++) {
548 rt = mf6ctable[i];
549 while (rt) {
550 struct mf6c *frt;
551
552 for (rte = rt->mf6c_stall; rte != NULL; ) {
553 struct rtdetq *n = rte->next;
554
555 m_free(rte->m);
556 free(rte, M_MRTABLE);
557 rte = n;
558 }
559 frt = rt;
560 rt = rt->mf6c_next;
561 free(frt, M_MRTABLE);
562 }
563 }
564
565 bzero((void *)mf6ctable, sizeof(mf6ctable));
566
567 /*
568 * Reset register interface
569 */
570 if (reg_mif_num != (mifi_t)-1) {
571 if_detach(&multicast_register_if6);
572 reg_mif_num = (mifi_t)-1;
573 }
574
575 ip6_mrouter = NULL;
576 ip6_mrouter_ver = 0;
577
578 splx(s);
579
580 #ifdef MRT6DEBUG
581 if (mrt6debug)
582 log(LOG_DEBUG, "ip6_mrouter_done\n");
583 #endif
584
585 return 0;
586 }
587
588 void
589 ip6_mrouter_detach(struct ifnet *ifp)
590 {
591 struct rtdetq *rte;
592 struct mf6c *mfc;
593 mifi_t mifi;
594 int i;
595
596 if (ip6_mrouter == NULL)
597 return;
598
599 /*
600 * Delete a mif which points to ifp.
601 */
602 for (mifi = 0; mifi < nummifs; mifi++)
603 if (mif6table[mifi].m6_ifp == ifp)
604 del_m6if(&mifi);
605
606 /*
607 * Clear rte->ifp of cache entries received on ifp.
608 */
609 for (i = 0; i < MF6CTBLSIZ; i++) {
610 if (n6expire[i] == 0)
611 continue;
612
613 for (mfc = mf6ctable[i]; mfc != NULL; mfc = mfc->mf6c_next) {
614 for (rte = mfc->mf6c_stall; rte != NULL; rte = rte->next) {
615 if (rte->ifp == ifp)
616 rte->ifp = NULL;
617 }
618 }
619 }
620 }
621
622
623 /*
624 * Add a mif to the mif table
625 */
626 static int
627 add_m6if(struct mif6ctl *mifcp)
628 {
629 struct mif6 *mifp;
630 struct ifnet *ifp;
631 struct in6_ifreq ifr;
632 int error, s;
633 #ifdef notyet
634 struct tbf *m_tbf = tbftable + mifcp->mif6c_mifi;
635 #endif
636
637 if (mifcp->mif6c_mifi >= MAXMIFS)
638 return EINVAL;
639 mifp = mif6table + mifcp->mif6c_mifi;
640 if (mifp->m6_ifp)
641 return EADDRINUSE; /* XXX: is it appropriate? */
642 if (mifcp->mif6c_pifi == 0 || mifcp->mif6c_pifi >= if_indexlim)
643 return ENXIO;
644 /*
645 * XXX: some OSes can remove ifp and clear ifindex2ifnet[id]
646 * even for id between 0 and if_index.
647 */
648 if ((ifp = ifindex2ifnet[mifcp->mif6c_pifi]) == NULL)
649 return ENXIO;
650
651 if (mifcp->mif6c_flags & MIFF_REGISTER) {
652 ifp = &multicast_register_if6;
653
654 if (reg_mif_num == (mifi_t)-1) {
655 strlcpy(ifp->if_xname, "register_mif",
656 sizeof(ifp->if_xname));
657 ifp->if_flags |= IFF_LOOPBACK;
658 ifp->if_index = mifcp->mif6c_mifi;
659 reg_mif_num = mifcp->mif6c_mifi;
660 if_attach(ifp);
661 }
662
663 } /* if REGISTER */
664 else {
665 /* Make sure the interface supports multicast */
666 if ((ifp->if_flags & IFF_MULTICAST) == 0)
667 return EOPNOTSUPP;
668
669 s = splsoftnet();
670 /*
671 * Enable promiscuous reception of all IPv6 multicasts
672 * from the interface.
673 */
674 ifr.ifr_addr.sin6_family = AF_INET6;
675 ifr.ifr_addr.sin6_addr = in6addr_any;
676 error = (*ifp->if_ioctl)(ifp, SIOCADDMULTI, (void *)&ifr);
677 splx(s);
678 if (error)
679 return error;
680 }
681
682 s = splsoftnet();
683 mifp->m6_flags = mifcp->mif6c_flags;
684 mifp->m6_ifp = ifp;
685 #ifdef notyet
686 /* scaling up here allows division by 1024 in critical code */
687 mifp->m6_rate_limit = mifcp->mif6c_rate_limit * 1024 / 1000;
688 #endif
689 /* initialize per mif pkt counters */
690 mifp->m6_pkt_in = 0;
691 mifp->m6_pkt_out = 0;
692 mifp->m6_bytes_in = 0;
693 mifp->m6_bytes_out = 0;
694 splx(s);
695
696 /* Adjust nummifs up if the mifi is higher than nummifs */
697 if (nummifs <= mifcp->mif6c_mifi)
698 nummifs = mifcp->mif6c_mifi + 1;
699
700 #ifdef MRT6DEBUG
701 if (mrt6debug)
702 log(LOG_DEBUG,
703 "add_mif #%d, phyint %s\n",
704 mifcp->mif6c_mifi, ifp->if_xname);
705 #endif
706
707 return 0;
708 }
709
710 /*
711 * Delete a mif from the mif table
712 */
713 static int
714 del_m6if(mifi_t *mifip)
715 {
716 struct mif6 *mifp = mif6table + *mifip;
717 mifi_t mifi;
718 struct ifnet *ifp;
719 struct in6_ifreq ifr;
720 int s;
721
722 if (*mifip >= nummifs)
723 return EINVAL;
724 if (mifp->m6_ifp == NULL)
725 return EINVAL;
726
727 s = splsoftnet();
728
729 if (!(mifp->m6_flags & MIFF_REGISTER)) {
730 /*
731 * XXX: what if there is yet IPv4 multicast daemon
732 * using the interface?
733 */
734 ifp = mifp->m6_ifp;
735
736 ifr.ifr_addr.sin6_family = AF_INET6;
737 ifr.ifr_addr.sin6_addr = in6addr_any;
738 (*ifp->if_ioctl)(ifp, SIOCDELMULTI, (void *)&ifr);
739 } else {
740 if (reg_mif_num != (mifi_t)-1) {
741 if_detach(&multicast_register_if6);
742 reg_mif_num = (mifi_t)-1;
743 }
744 }
745
746 #ifdef notyet
747 bzero((void *)qtable[*mifip], sizeof(qtable[*mifip]));
748 bzero((void *)mifp->m6_tbf, sizeof(*(mifp->m6_tbf)));
749 #endif
750 bzero((void *)mifp, sizeof (*mifp));
751
752 /* Adjust nummifs down */
753 for (mifi = nummifs; mifi > 0; mifi--)
754 if (mif6table[mifi - 1].m6_ifp)
755 break;
756 nummifs = mifi;
757
758 splx(s);
759
760 #ifdef MRT6DEBUG
761 if (mrt6debug)
762 log(LOG_DEBUG, "del_m6if %d, nummifs %d\n", *mifip, nummifs);
763 #endif
764
765 return 0;
766 }
767
768 /*
769 * Add an mfc entry
770 */
771 static int
772 add_m6fc(struct mf6cctl *mfccp)
773 {
774 struct mf6c *rt;
775 u_long hash;
776 struct rtdetq *rte;
777 u_short nstl;
778 int s;
779
780 MF6CFIND(mfccp->mf6cc_origin.sin6_addr,
781 mfccp->mf6cc_mcastgrp.sin6_addr, rt);
782
783 /* If an entry already exists, just update the fields */
784 if (rt) {
785 #ifdef MRT6DEBUG
786 if (mrt6debug & DEBUG_MFC)
787 log(LOG_DEBUG,"add_m6fc update o %s g %s p %x\n",
788 ip6_sprintf(&mfccp->mf6cc_origin.sin6_addr),
789 ip6_sprintf(&mfccp->mf6cc_mcastgrp.sin6_addr),
790 mfccp->mf6cc_parent);
791 #endif
792
793 s = splsoftnet();
794 rt->mf6c_parent = mfccp->mf6cc_parent;
795 rt->mf6c_ifset = mfccp->mf6cc_ifset;
796 splx(s);
797 return 0;
798 }
799
800 /*
801 * Find the entry for which the upcall was made and update
802 */
803 s = splsoftnet();
804 hash = MF6CHASH(mfccp->mf6cc_origin.sin6_addr,
805 mfccp->mf6cc_mcastgrp.sin6_addr);
806 for (rt = mf6ctable[hash], nstl = 0; rt; rt = rt->mf6c_next) {
807 if (IN6_ARE_ADDR_EQUAL(&rt->mf6c_origin.sin6_addr,
808 &mfccp->mf6cc_origin.sin6_addr) &&
809 IN6_ARE_ADDR_EQUAL(&rt->mf6c_mcastgrp.sin6_addr,
810 &mfccp->mf6cc_mcastgrp.sin6_addr) &&
811 (rt->mf6c_stall != NULL)) {
812
813 if (nstl++)
814 log(LOG_ERR,
815 "add_m6fc: %s o %s g %s p %x dbx %p\n",
816 "multiple kernel entries",
817 ip6_sprintf(&mfccp->mf6cc_origin.sin6_addr),
818 ip6_sprintf(&mfccp->mf6cc_mcastgrp.sin6_addr),
819 mfccp->mf6cc_parent, rt->mf6c_stall);
820
821 #ifdef MRT6DEBUG
822 if (mrt6debug & DEBUG_MFC)
823 log(LOG_DEBUG,
824 "add_m6fc o %s g %s p %x dbg %p\n",
825 ip6_sprintf(&mfccp->mf6cc_origin.sin6_addr),
826 ip6_sprintf(&mfccp->mf6cc_mcastgrp.sin6_addr),
827 mfccp->mf6cc_parent, rt->mf6c_stall);
828 #endif
829
830 rt->mf6c_origin = mfccp->mf6cc_origin;
831 rt->mf6c_mcastgrp = mfccp->mf6cc_mcastgrp;
832 rt->mf6c_parent = mfccp->mf6cc_parent;
833 rt->mf6c_ifset = mfccp->mf6cc_ifset;
834 /* initialize pkt counters per src-grp */
835 rt->mf6c_pkt_cnt = 0;
836 rt->mf6c_byte_cnt = 0;
837 rt->mf6c_wrong_if = 0;
838
839 rt->mf6c_expire = 0; /* Don't clean this guy up */
840 n6expire[hash]--;
841
842 /* free packets Qed at the end of this entry */
843 for (rte = rt->mf6c_stall; rte != NULL; ) {
844 struct rtdetq *n = rte->next;
845 if (rte->ifp) {
846 ip6_mdq(rte->m, rte->ifp, rt);
847 }
848 m_freem(rte->m);
849 #ifdef UPCALL_TIMING
850 collate(&(rte->t));
851 #endif /* UPCALL_TIMING */
852 free(rte, M_MRTABLE);
853 rte = n;
854 }
855 rt->mf6c_stall = NULL;
856 }
857 }
858
859 /*
860 * It is possible that an entry is being inserted without an upcall
861 */
862 if (nstl == 0) {
863 #ifdef MRT6DEBUG
864 if (mrt6debug & DEBUG_MFC)
865 log(LOG_DEBUG,
866 "add_mfc no upcall h %ld o %s g %s p %x\n",
867 hash,
868 ip6_sprintf(&mfccp->mf6cc_origin.sin6_addr),
869 ip6_sprintf(&mfccp->mf6cc_mcastgrp.sin6_addr),
870 mfccp->mf6cc_parent);
871 #endif
872
873 for (rt = mf6ctable[hash]; rt; rt = rt->mf6c_next) {
874
875 if (IN6_ARE_ADDR_EQUAL(&rt->mf6c_origin.sin6_addr,
876 &mfccp->mf6cc_origin.sin6_addr)&&
877 IN6_ARE_ADDR_EQUAL(&rt->mf6c_mcastgrp.sin6_addr,
878 &mfccp->mf6cc_mcastgrp.sin6_addr)) {
879
880 rt->mf6c_origin = mfccp->mf6cc_origin;
881 rt->mf6c_mcastgrp = mfccp->mf6cc_mcastgrp;
882 rt->mf6c_parent = mfccp->mf6cc_parent;
883 rt->mf6c_ifset = mfccp->mf6cc_ifset;
884 /* initialize pkt counters per src-grp */
885 rt->mf6c_pkt_cnt = 0;
886 rt->mf6c_byte_cnt = 0;
887 rt->mf6c_wrong_if = 0;
888
889 if (rt->mf6c_expire)
890 n6expire[hash]--;
891 rt->mf6c_expire = 0;
892 }
893 }
894 if (rt == NULL) {
895 /* no upcall, so make a new entry */
896 rt = (struct mf6c *)malloc(sizeof(*rt), M_MRTABLE,
897 M_NOWAIT);
898 if (rt == NULL) {
899 splx(s);
900 return ENOBUFS;
901 }
902
903 /* insert new entry at head of hash chain */
904 rt->mf6c_origin = mfccp->mf6cc_origin;
905 rt->mf6c_mcastgrp = mfccp->mf6cc_mcastgrp;
906 rt->mf6c_parent = mfccp->mf6cc_parent;
907 rt->mf6c_ifset = mfccp->mf6cc_ifset;
908 /* initialize pkt counters per src-grp */
909 rt->mf6c_pkt_cnt = 0;
910 rt->mf6c_byte_cnt = 0;
911 rt->mf6c_wrong_if = 0;
912 rt->mf6c_expire = 0;
913 rt->mf6c_stall = NULL;
914
915 /* link into table */
916 rt->mf6c_next = mf6ctable[hash];
917 mf6ctable[hash] = rt;
918 }
919 }
920 splx(s);
921 return 0;
922 }
923
924 #ifdef UPCALL_TIMING
925 /*
926 * collect delay statistics on the upcalls
927 */
928 static void
929 collate(struct timeval *t)
930 {
931 u_long d;
932 struct timeval tp;
933 u_long delta;
934
935 GET_TIME(tp);
936
937 if (TV_LT(*t, tp))
938 {
939 TV_DELTA(tp, *t, delta);
940
941 d = delta >> 10;
942 if (d > UPCALL_MAX)
943 d = UPCALL_MAX;
944
945 ++upcall_data[d];
946 }
947 }
948 #endif /* UPCALL_TIMING */
949
950 /*
951 * Delete an mfc entry
952 */
953 static int
954 del_m6fc(struct mf6cctl *mfccp)
955 {
956 struct sockaddr_in6 origin;
957 struct sockaddr_in6 mcastgrp;
958 struct mf6c *rt;
959 struct mf6c **nptr;
960 u_long hash;
961 int s;
962
963 origin = mfccp->mf6cc_origin;
964 mcastgrp = mfccp->mf6cc_mcastgrp;
965 hash = MF6CHASH(origin.sin6_addr, mcastgrp.sin6_addr);
966
967 #ifdef MRT6DEBUG
968 if (mrt6debug & DEBUG_MFC)
969 log(LOG_DEBUG,"del_m6fc orig %s mcastgrp %s\n",
970 ip6_sprintf(&origin.sin6_addr),
971 ip6_sprintf(&mcastgrp.sin6_addr));
972 #endif
973
974 s = splsoftnet();
975
976 nptr = &mf6ctable[hash];
977 while ((rt = *nptr) != NULL) {
978 if (IN6_ARE_ADDR_EQUAL(&origin.sin6_addr,
979 &rt->mf6c_origin.sin6_addr) &&
980 IN6_ARE_ADDR_EQUAL(&mcastgrp.sin6_addr,
981 &rt->mf6c_mcastgrp.sin6_addr) &&
982 rt->mf6c_stall == NULL)
983 break;
984
985 nptr = &rt->mf6c_next;
986 }
987 if (rt == NULL) {
988 splx(s);
989 return EADDRNOTAVAIL;
990 }
991
992 *nptr = rt->mf6c_next;
993 free(rt, M_MRTABLE);
994
995 splx(s);
996
997 return 0;
998 }
999
1000 static int
1001 socket_send(struct socket *s, struct mbuf *mm, struct sockaddr_in6 *src)
1002 {
1003 if (s) {
1004 if (sbappendaddr(&s->so_rcv,
1005 (struct sockaddr *)src,
1006 mm, (struct mbuf *)0) != 0) {
1007 sorwakeup(s);
1008 return 0;
1009 }
1010 }
1011 m_freem(mm);
1012 return -1;
1013 }
1014
1015 /*
1016 * IPv6 multicast forwarding function. This function assumes that the packet
1017 * pointed to by "ip6" has arrived on (or is about to be sent to) the interface
1018 * pointed to by "ifp", and the packet is to be relayed to other networks
1019 * that have members of the packet's destination IPv6 multicast group.
1020 *
1021 * The packet is returned unscathed to the caller, unless it is
1022 * erroneous, in which case a non-zero return value tells the caller to
1023 * discard it.
1024 */
1025
1026 int
1027 ip6_mforward(struct ip6_hdr *ip6, struct ifnet *ifp, struct mbuf *m)
1028 {
1029 struct mf6c *rt;
1030 struct mif6 *mifp;
1031 struct mbuf *mm;
1032 int s;
1033 mifi_t mifi;
1034 struct sockaddr_in6 sin6;
1035
1036 #ifdef MRT6DEBUG
1037 if (mrt6debug & DEBUG_FORWARD)
1038 log(LOG_DEBUG, "ip6_mforward: src %s, dst %s, ifindex %d\n",
1039 ip6_sprintf(&ip6->ip6_src), ip6_sprintf(&ip6->ip6_dst),
1040 ifp->if_index);
1041 #endif
1042
1043 /*
1044 * Don't forward a packet with Hop limit of zero or one,
1045 * or a packet destined to a local-only group.
1046 */
1047 if (ip6->ip6_hlim <= 1 || IN6_IS_ADDR_MC_NODELOCAL(&ip6->ip6_dst) ||
1048 IN6_IS_ADDR_MC_LINKLOCAL(&ip6->ip6_dst))
1049 return 0;
1050 ip6->ip6_hlim--;
1051
1052 /*
1053 * Source address check: do not forward packets with unspecified
1054 * source. It was discussed in July 2000, on ipngwg mailing list.
1055 * This is rather more serious than unicast cases, because some
1056 * MLD packets can be sent with the unspecified source address
1057 * (although such packets must normally set the hop limit field to 1).
1058 */
1059 if (IN6_IS_ADDR_UNSPECIFIED(&ip6->ip6_src)) {
1060 ip6stat.ip6s_cantforward++;
1061 if (ip6_log_time + ip6_log_interval < time_second) {
1062 ip6_log_time = time_second;
1063 log(LOG_DEBUG,
1064 "cannot forward "
1065 "from %s to %s nxt %d received on %s\n",
1066 ip6_sprintf(&ip6->ip6_src),
1067 ip6_sprintf(&ip6->ip6_dst),
1068 ip6->ip6_nxt,
1069 m->m_pkthdr.rcvif ?
1070 if_name(m->m_pkthdr.rcvif) : "?");
1071 }
1072 return 0;
1073 }
1074
1075 /*
1076 * Determine forwarding mifs from the forwarding cache table
1077 */
1078 s = splsoftnet();
1079 MF6CFIND(ip6->ip6_src, ip6->ip6_dst, rt);
1080
1081 /* Entry exists, so forward if necessary */
1082 if (rt) {
1083 splx(s);
1084 return (ip6_mdq(m, ifp, rt));
1085 } else {
1086 /*
1087 * If we don't have a route for packet's origin,
1088 * Make a copy of the packet &
1089 * send message to routing daemon
1090 */
1091
1092 struct mbuf *mb0;
1093 struct rtdetq *rte;
1094 u_long hash;
1095 /* int i, npkts;*/
1096 #ifdef UPCALL_TIMING
1097 struct timeval tp;
1098
1099 GET_TIME(tp);
1100 #endif /* UPCALL_TIMING */
1101
1102 mrt6stat.mrt6s_no_route++;
1103 #ifdef MRT6DEBUG
1104 if (mrt6debug & (DEBUG_FORWARD | DEBUG_MFC))
1105 log(LOG_DEBUG, "ip6_mforward: no rte s %s g %s\n",
1106 ip6_sprintf(&ip6->ip6_src),
1107 ip6_sprintf(&ip6->ip6_dst));
1108 #endif
1109
1110 /*
1111 * Allocate mbufs early so that we don't do extra work if we
1112 * are just going to fail anyway.
1113 */
1114 rte = (struct rtdetq *)malloc(sizeof(*rte), M_MRTABLE,
1115 M_NOWAIT);
1116 if (rte == NULL) {
1117 splx(s);
1118 return ENOBUFS;
1119 }
1120 mb0 = m_copy(m, 0, M_COPYALL);
1121 /*
1122 * Pullup packet header if needed before storing it,
1123 * as other references may modify it in the meantime.
1124 */
1125 if (mb0 &&
1126 (M_READONLY(mb0) || mb0->m_len < sizeof(struct ip6_hdr)))
1127 mb0 = m_pullup(mb0, sizeof(struct ip6_hdr));
1128 if (mb0 == NULL) {
1129 free(rte, M_MRTABLE);
1130 splx(s);
1131 return ENOBUFS;
1132 }
1133
1134 /* is there an upcall waiting for this packet? */
1135 hash = MF6CHASH(ip6->ip6_src, ip6->ip6_dst);
1136 for (rt = mf6ctable[hash]; rt; rt = rt->mf6c_next) {
1137 if (IN6_ARE_ADDR_EQUAL(&ip6->ip6_src,
1138 &rt->mf6c_origin.sin6_addr) &&
1139 IN6_ARE_ADDR_EQUAL(&ip6->ip6_dst,
1140 &rt->mf6c_mcastgrp.sin6_addr) &&
1141 (rt->mf6c_stall != NULL))
1142 break;
1143 }
1144
1145 if (rt == NULL) {
1146 struct mrt6msg *im;
1147 struct omrt6msg *oim;
1148
1149 /* no upcall, so make a new entry */
1150 rt = (struct mf6c *)malloc(sizeof(*rt), M_MRTABLE,
1151 M_NOWAIT);
1152 if (rt == NULL) {
1153 free(rte, M_MRTABLE);
1154 m_freem(mb0);
1155 splx(s);
1156 return ENOBUFS;
1157 }
1158 /*
1159 * Make a copy of the header to send to the user
1160 * level process
1161 */
1162 mm = m_copy(mb0, 0, sizeof(struct ip6_hdr));
1163
1164 if (mm == NULL) {
1165 free(rte, M_MRTABLE);
1166 m_freem(mb0);
1167 free(rt, M_MRTABLE);
1168 splx(s);
1169 return ENOBUFS;
1170 }
1171
1172 /*
1173 * Send message to routing daemon
1174 */
1175 (void)memset(&sin6, 0, sizeof(sin6));
1176 sin6.sin6_len = sizeof(sin6);
1177 sin6.sin6_family = AF_INET6;
1178 sin6.sin6_addr = ip6->ip6_src;
1179
1180 im = NULL;
1181 oim = NULL;
1182 switch (ip6_mrouter_ver) {
1183 case MRT6_OINIT:
1184 oim = mtod(mm, struct omrt6msg *);
1185 oim->im6_msgtype = MRT6MSG_NOCACHE;
1186 oim->im6_mbz = 0;
1187 break;
1188 case MRT6_INIT:
1189 im = mtod(mm, struct mrt6msg *);
1190 im->im6_msgtype = MRT6MSG_NOCACHE;
1191 im->im6_mbz = 0;
1192 break;
1193 default:
1194 free(rte, M_MRTABLE);
1195 m_freem(mb0);
1196 free(rt, M_MRTABLE);
1197 splx(s);
1198 return EINVAL;
1199 }
1200
1201 #ifdef MRT6DEBUG
1202 if (mrt6debug & DEBUG_FORWARD)
1203 log(LOG_DEBUG,
1204 "getting the iif info in the kernel\n");
1205 #endif
1206
1207 for (mifp = mif6table, mifi = 0;
1208 mifi < nummifs && mifp->m6_ifp != ifp;
1209 mifp++, mifi++)
1210 ;
1211
1212 switch (ip6_mrouter_ver) {
1213 case MRT6_OINIT:
1214 oim->im6_mif = mifi;
1215 break;
1216 case MRT6_INIT:
1217 im->im6_mif = mifi;
1218 break;
1219 }
1220
1221 if (socket_send(ip6_mrouter, mm, &sin6) < 0) {
1222 log(LOG_WARNING, "ip6_mforward: ip6_mrouter "
1223 "socket queue full\n");
1224 mrt6stat.mrt6s_upq_sockfull++;
1225 free(rte, M_MRTABLE);
1226 m_freem(mb0);
1227 free(rt, M_MRTABLE);
1228 splx(s);
1229 return ENOBUFS;
1230 }
1231
1232 mrt6stat.mrt6s_upcalls++;
1233
1234 /* insert new entry at head of hash chain */
1235 bzero(rt, sizeof(*rt));
1236 rt->mf6c_origin.sin6_family = AF_INET6;
1237 rt->mf6c_origin.sin6_len = sizeof(struct sockaddr_in6);
1238 rt->mf6c_origin.sin6_addr = ip6->ip6_src;
1239 rt->mf6c_mcastgrp.sin6_family = AF_INET6;
1240 rt->mf6c_mcastgrp.sin6_len = sizeof(struct sockaddr_in6);
1241 rt->mf6c_mcastgrp.sin6_addr = ip6->ip6_dst;
1242 rt->mf6c_expire = UPCALL_EXPIRE;
1243 n6expire[hash]++;
1244 rt->mf6c_parent = MF6C_INCOMPLETE_PARENT;
1245
1246 /* link into table */
1247 rt->mf6c_next = mf6ctable[hash];
1248 mf6ctable[hash] = rt;
1249 /* Add this entry to the end of the queue */
1250 rt->mf6c_stall = rte;
1251 } else {
1252 /* determine if q has overflowed */
1253 struct rtdetq **p;
1254 int npkts = 0;
1255
1256 for (p = &rt->mf6c_stall; *p != NULL; p = &(*p)->next)
1257 if (++npkts > MAX_UPQ6) {
1258 mrt6stat.mrt6s_upq_ovflw++;
1259 free(rte, M_MRTABLE);
1260 m_freem(mb0);
1261 splx(s);
1262 return 0;
1263 }
1264
1265 /* Add this entry to the end of the queue */
1266 *p = rte;
1267 }
1268
1269 rte->next = NULL;
1270 rte->m = mb0;
1271 rte->ifp = ifp;
1272 #ifdef UPCALL_TIMING
1273 rte->t = tp;
1274 #endif /* UPCALL_TIMING */
1275
1276 splx(s);
1277
1278 return 0;
1279 }
1280 }
1281
1282 /*
1283 * Clean up cache entries if upcalls are not serviced
1284 * Call from the Slow Timeout mechanism, every 0.25 seconds.
1285 */
1286 static void
1287 expire_upcalls(void *unused)
1288 {
1289 struct rtdetq *rte;
1290 struct mf6c *mfc, **nptr;
1291 int i;
1292 int s;
1293
1294 s = splsoftnet();
1295 for (i = 0; i < MF6CTBLSIZ; i++) {
1296 if (n6expire[i] == 0)
1297 continue;
1298 nptr = &mf6ctable[i];
1299 while ((mfc = *nptr) != NULL) {
1300 rte = mfc->mf6c_stall;
1301 /*
1302 * Skip real cache entries
1303 * Make sure it wasn't marked to not expire (shouldn't happen)
1304 * If it expires now
1305 */
1306 if (rte != NULL &&
1307 mfc->mf6c_expire != 0 &&
1308 --mfc->mf6c_expire == 0) {
1309 #ifdef MRT6DEBUG
1310 if (mrt6debug & DEBUG_EXPIRE)
1311 log(LOG_DEBUG, "expire_upcalls: expiring (%s %s)\n",
1312 ip6_sprintf(&mfc->mf6c_origin.sin6_addr),
1313 ip6_sprintf(&mfc->mf6c_mcastgrp.sin6_addr));
1314 #endif
1315 /*
1316 * drop all the packets
1317 * free the mbuf with the pkt, if, timing info
1318 */
1319 do {
1320 struct rtdetq *n = rte->next;
1321 m_freem(rte->m);
1322 free(rte, M_MRTABLE);
1323 rte = n;
1324 } while (rte != NULL);
1325 mrt6stat.mrt6s_cache_cleanups++;
1326 n6expire[i]--;
1327
1328 *nptr = mfc->mf6c_next;
1329 free(mfc, M_MRTABLE);
1330 } else {
1331 nptr = &mfc->mf6c_next;
1332 }
1333 }
1334 }
1335 splx(s);
1336 callout_reset(&expire_upcalls_ch, EXPIRE_TIMEOUT,
1337 expire_upcalls, NULL);
1338 }
1339
1340 /*
1341 * Packet forwarding routine once entry in the cache is made
1342 */
1343 static int
1344 ip6_mdq(struct mbuf *m, struct ifnet *ifp, struct mf6c *rt)
1345 {
1346 struct ip6_hdr *ip6 = mtod(m, struct ip6_hdr *);
1347 mifi_t mifi, iif;
1348 struct mif6 *mifp;
1349 int plen = m->m_pkthdr.len;
1350 struct in6_addr src0, dst0; /* copies for local work */
1351 u_int32_t iszone, idzone, oszone, odzone;
1352 int error = 0;
1353
1354 /*
1355 * Macro to send packet on mif. Since RSVP packets don't get counted on
1356 * input, they shouldn't get counted on output, so statistics keeping is
1357 * separate.
1358 */
1359
1360 #define MC6_SEND(ip6, mifp, m) do { \
1361 if ((mifp)->m6_flags & MIFF_REGISTER) \
1362 register_send((ip6), (mifp), (m)); \
1363 else \
1364 phyint_send((ip6), (mifp), (m)); \
1365 } while (/*CONSTCOND*/ 0)
1366
1367 /*
1368 * Don't forward if it didn't arrive from the parent mif
1369 * for its origin.
1370 */
1371 mifi = rt->mf6c_parent;
1372 if ((mifi >= nummifs) || (mif6table[mifi].m6_ifp != ifp)) {
1373 /* came in the wrong interface */
1374 #ifdef MRT6DEBUG
1375 if (mrt6debug & DEBUG_FORWARD)
1376 log(LOG_DEBUG,
1377 "wrong if: ifid %d mifi %d mififid %x\n",
1378 ifp->if_index, mifi,
1379 mif6table[mifi].m6_ifp ?
1380 mif6table[mifi].m6_ifp->if_index : -1);
1381 #endif
1382 mrt6stat.mrt6s_wrong_if++;
1383 rt->mf6c_wrong_if++;
1384 /*
1385 * If we are doing PIM processing, and we are forwarding
1386 * packets on this interface, send a message to the
1387 * routing daemon.
1388 */
1389 /* have to make sure this is a valid mif */
1390 if (mifi < nummifs && mif6table[mifi].m6_ifp)
1391 if (pim6 && (m->m_flags & M_LOOP) == 0) {
1392 /*
1393 * Check the M_LOOP flag to avoid an
1394 * unnecessary PIM assert.
1395 * XXX: M_LOOP is an ad-hoc hack...
1396 */
1397 struct sockaddr_in6 sin6;
1398
1399 struct mbuf *mm;
1400 struct mrt6msg *im;
1401 struct omrt6msg *oim;
1402
1403 mm = m_copy(m, 0, sizeof(struct ip6_hdr));
1404 if (mm &&
1405 (M_READONLY(mm) ||
1406 mm->m_len < sizeof(struct ip6_hdr)))
1407 mm = m_pullup(mm, sizeof(struct ip6_hdr));
1408 if (mm == NULL)
1409 return ENOBUFS;
1410
1411 oim = NULL;
1412 im = NULL;
1413 switch (ip6_mrouter_ver) {
1414 case MRT6_OINIT:
1415 oim = mtod(mm, struct omrt6msg *);
1416 oim->im6_msgtype = MRT6MSG_WRONGMIF;
1417 oim->im6_mbz = 0;
1418 break;
1419 case MRT6_INIT:
1420 im = mtod(mm, struct mrt6msg *);
1421 im->im6_msgtype = MRT6MSG_WRONGMIF;
1422 im->im6_mbz = 0;
1423 break;
1424 default:
1425 m_freem(mm);
1426 return EINVAL;
1427 }
1428
1429 for (mifp = mif6table, iif = 0;
1430 iif < nummifs && mifp &&
1431 mifp->m6_ifp != ifp;
1432 mifp++, iif++)
1433 ;
1434
1435 bzero(&sin6, sizeof(sin6));
1436 sin6.sin6_len = sizeof(sin6);
1437 sin6.sin6_family = AF_INET6;
1438 switch (ip6_mrouter_ver) {
1439 case MRT6_OINIT:
1440 oim->im6_mif = iif;
1441 sin6.sin6_addr = oim->im6_src;
1442 break;
1443 case MRT6_INIT:
1444 im->im6_mif = iif;
1445 sin6.sin6_addr = im->im6_src;
1446 break;
1447 }
1448
1449 mrt6stat.mrt6s_upcalls++;
1450
1451 if (socket_send(ip6_mrouter, mm, &sin6) < 0) {
1452 #ifdef MRT6DEBUG
1453 if (mrt6debug)
1454 log(LOG_WARNING, "mdq, ip6_mrouter socket queue full\n");
1455 #endif
1456 ++mrt6stat.mrt6s_upq_sockfull;
1457 return ENOBUFS;
1458 } /* if socket Q full */
1459 } /* if PIM */
1460 return 0;
1461 } /* if wrong iif */
1462
1463 /* If I sourced this packet, it counts as output, else it was input. */
1464 if (m->m_pkthdr.rcvif == NULL) {
1465 /* XXX: is rcvif really NULL when output?? */
1466 mif6table[mifi].m6_pkt_out++;
1467 mif6table[mifi].m6_bytes_out += plen;
1468 } else {
1469 mif6table[mifi].m6_pkt_in++;
1470 mif6table[mifi].m6_bytes_in += plen;
1471 }
1472 rt->mf6c_pkt_cnt++;
1473 rt->mf6c_byte_cnt += plen;
1474
1475 /*
1476 * For each mif, forward a copy of the packet if there are group
1477 * members downstream on the interface.
1478 */
1479 src0 = ip6->ip6_src;
1480 dst0 = ip6->ip6_dst;
1481 if ((error = in6_setscope(&src0, ifp, &iszone)) != 0 ||
1482 (error = in6_setscope(&dst0, ifp, &idzone)) != 0) {
1483 ip6stat.ip6s_badscope++;
1484 return (error);
1485 }
1486 for (mifp = mif6table, mifi = 0; mifi < nummifs; mifp++, mifi++)
1487 if (IF_ISSET(mifi, &rt->mf6c_ifset)) {
1488 if (mif6table[mifi].m6_ifp == NULL)
1489 continue;
1490 /*
1491 * check if the outgoing packet is going to break
1492 * a scope boundary.
1493 * XXX: For packets through PIM register tunnel
1494 * interface, we believe the routing daemon.
1495 */
1496 if ((mif6table[rt->mf6c_parent].m6_flags &
1497 MIFF_REGISTER) == 0 &&
1498 (mif6table[mifi].m6_flags & MIFF_REGISTER) == 0) {
1499 if (in6_setscope(&src0, mif6table[mifi].m6_ifp,
1500 &oszone) ||
1501 in6_setscope(&dst0, mif6table[mifi].m6_ifp,
1502 &odzone) ||
1503 iszone != oszone || idzone != odzone) {
1504 ip6stat.ip6s_badscope++;
1505 continue;
1506 }
1507 }
1508
1509 mifp->m6_pkt_out++;
1510 mifp->m6_bytes_out += plen;
1511 MC6_SEND(ip6, mifp, m);
1512 }
1513 return 0;
1514 }
1515
1516 static void
1517 phyint_send(struct ip6_hdr *ip6, struct mif6 *mifp, struct mbuf *m)
1518 {
1519 struct mbuf *mb_copy;
1520 struct ifnet *ifp = mifp->m6_ifp;
1521 int error = 0;
1522 int s;
1523 static struct route ro;
1524 struct in6_multi *in6m;
1525 struct sockaddr_in6 dst6;
1526 u_long linkmtu;
1527
1528 s = splsoftnet();
1529 /*
1530 * Make a new reference to the packet; make sure that
1531 * the IPv6 header is actually copied, not just referenced,
1532 * so that ip6_output() only scribbles on the copy.
1533 */
1534 mb_copy = m_copy(m, 0, M_COPYALL);
1535 if (mb_copy &&
1536 (M_READONLY(mb_copy) || mb_copy->m_len < sizeof(struct ip6_hdr)))
1537 mb_copy = m_pullup(mb_copy, sizeof(struct ip6_hdr));
1538 if (mb_copy == NULL) {
1539 splx(s);
1540 return;
1541 }
1542 /* set MCAST flag to the outgoing packet */
1543 mb_copy->m_flags |= M_MCAST;
1544
1545 /*
1546 * If we sourced the packet, call ip6_output since we may divide
1547 * the packet into fragments when the packet is too big for the
1548 * outgoing interface.
1549 * Otherwise, we can simply send the packet to the interface
1550 * sending queue.
1551 */
1552 if (m->m_pkthdr.rcvif == NULL) {
1553 struct ip6_moptions im6o;
1554
1555 im6o.im6o_multicast_ifp = ifp;
1556 /* XXX: ip6_output will override ip6->ip6_hlim */
1557 im6o.im6o_multicast_hlim = ip6->ip6_hlim;
1558 im6o.im6o_multicast_loop = 1;
1559 error = ip6_output(mb_copy, NULL, &ro, IPV6_FORWARDING,
1560 &im6o, NULL, NULL);
1561
1562 #ifdef MRT6DEBUG
1563 if (mrt6debug & DEBUG_XMIT)
1564 log(LOG_DEBUG, "phyint_send on mif %d err %d\n",
1565 mifp - mif6table, error);
1566 #endif
1567 splx(s);
1568 return;
1569 }
1570
1571 /*
1572 * If we belong to the destination multicast group
1573 * on the outgoing interface, loop back a copy.
1574 */
1575 /*
1576 * Does not have to check source info, as it's alreay covered by
1577 * ip6_input
1578 */
1579 memset(&dst6, 0, sizeof(dst6));
1580 dst6.sin6_family = AF_INET6;
1581 dst6.sin6_len = sizeof(struct sockaddr_in6);
1582 dst6.sin6_addr = ip6->ip6_dst;
1583
1584 IN6_LOOKUP_MULTI(ip6->ip6_dst, ifp, in6m);
1585 if (in6m != NULL) {
1586 ip6_mloopback(ifp, m,
1587 satocsin6(rtcache_getdst(&ro)));
1588 }
1589
1590 /*
1591 * Put the packet into the sending queue of the outgoing interface
1592 * if it would fit in the MTU of the interface.
1593 */
1594 linkmtu = IN6_LINKMTU(ifp);
1595 if (mb_copy->m_pkthdr.len <= linkmtu || linkmtu < IPV6_MMTU) {
1596 /*
1597 * We could call if_output directly here, but we use
1598 * nd6_output on purpose to see if IPv6 operation is allowed
1599 * on the interface.
1600 */
1601 error = nd6_output(ifp, ifp, mb_copy, &dst6, NULL);
1602 #ifdef MRT6DEBUG
1603 if (mrt6debug & DEBUG_XMIT)
1604 log(LOG_DEBUG, "phyint_send on mif %d err %d\n",
1605 mifp - mif6table, error);
1606 #endif
1607 } else {
1608 /*
1609 * pMTU discovery is intentionally disabled by default, since
1610 * various router may notify pMTU in multicast, which can be
1611 * a DDoS to a router
1612 */
1613 if (ip6_mcast_pmtu)
1614 icmp6_error(mb_copy, ICMP6_PACKET_TOO_BIG, 0, linkmtu);
1615 else {
1616 #ifdef MRT6DEBUG
1617 if (mrt6debug & DEBUG_XMIT)
1618 log(LOG_DEBUG,
1619 "phyint_send: packet too big on %s o %s g %s"
1620 " size %d(discarded)\n",
1621 if_name(ifp),
1622 ip6_sprintf(&ip6->ip6_src),
1623 ip6_sprintf(&ip6->ip6_dst),
1624 mb_copy->m_pkthdr.len);
1625 #endif /* MRT6DEBUG */
1626 m_freem(mb_copy); /* simply discard the packet */
1627 }
1628 }
1629
1630 splx(s);
1631 }
1632
1633 static int
1634 register_send(struct ip6_hdr *ip6, struct mif6 *mif, struct mbuf *m)
1635 {
1636 struct mbuf *mm;
1637 int i, len = m->m_pkthdr.len;
1638 struct sockaddr_in6 sin6;
1639 struct mrt6msg *im6;
1640
1641 #ifdef MRT6DEBUG
1642 if (mrt6debug)
1643 log(LOG_DEBUG, "** IPv6 register_send **\n src %s dst %s\n",
1644 ip6_sprintf(&ip6->ip6_src), ip6_sprintf(&ip6->ip6_dst));
1645 #endif
1646 ++pim6stat.pim6s_snd_registers;
1647
1648 /* Make a copy of the packet to send to the user level process */
1649 MGETHDR(mm, M_DONTWAIT, MT_HEADER);
1650 if (mm == NULL)
1651 return ENOBUFS;
1652 mm->m_data += max_linkhdr;
1653 mm->m_len = sizeof(struct ip6_hdr);
1654
1655 if ((mm->m_next = m_copy(m, 0, M_COPYALL)) == NULL) {
1656 m_freem(mm);
1657 return ENOBUFS;
1658 }
1659 i = MHLEN - M_LEADINGSPACE(mm);
1660 if (i > len)
1661 i = len;
1662 mm = m_pullup(mm, i);
1663 if (mm == NULL)
1664 return ENOBUFS;
1665 /* TODO: check it! */
1666 mm->m_pkthdr.len = len + sizeof(struct ip6_hdr);
1667
1668 /*
1669 * Send message to routing daemon
1670 */
1671 (void)memset(&sin6, 0, sizeof(sin6));
1672 sin6.sin6_len = sizeof(sin6);
1673 sin6.sin6_family = AF_INET6;
1674 sin6.sin6_addr = ip6->ip6_src;
1675
1676 im6 = mtod(mm, struct mrt6msg *);
1677 im6->im6_msgtype = MRT6MSG_WHOLEPKT;
1678 im6->im6_mbz = 0;
1679
1680 im6->im6_mif = mif - mif6table;
1681
1682 /* iif info is not given for reg. encap.n */
1683 mrt6stat.mrt6s_upcalls++;
1684
1685 if (socket_send(ip6_mrouter, mm, &sin6) < 0) {
1686 #ifdef MRT6DEBUG
1687 if (mrt6debug)
1688 log(LOG_WARNING,
1689 "register_send: ip6_mrouter socket queue full\n");
1690 #endif
1691 ++mrt6stat.mrt6s_upq_sockfull;
1692 return ENOBUFS;
1693 }
1694 return 0;
1695 }
1696
1697 /*
1698 * PIM sparse mode hook
1699 * Receives the pim control messages, and passes them up to the listening
1700 * socket, using rip6_input.
1701 * The only message processed is the REGISTER pim message; the pim header
1702 * is stripped off, and the inner packet is passed to register_mforward.
1703 */
1704 int
1705 pim6_input(struct mbuf **mp, int *offp, int proto)
1706 {
1707 struct pim *pim; /* pointer to a pim struct */
1708 struct ip6_hdr *ip6;
1709 int pimlen;
1710 struct mbuf *m = *mp;
1711 int minlen;
1712 int off = *offp;
1713
1714 ++pim6stat.pim6s_rcv_total;
1715
1716 ip6 = mtod(m, struct ip6_hdr *);
1717 pimlen = m->m_pkthdr.len - *offp;
1718
1719 /*
1720 * Validate lengths
1721 */
1722 if (pimlen < PIM_MINLEN) {
1723 ++pim6stat.pim6s_rcv_tooshort;
1724 #ifdef MRT6DEBUG
1725 if (mrt6debug & DEBUG_PIM)
1726 log(LOG_DEBUG,"pim6_input: PIM packet too short\n");
1727 #endif
1728 m_freem(m);
1729 return (IPPROTO_DONE);
1730 }
1731
1732 /*
1733 * if the packet is at least as big as a REGISTER, go ahead
1734 * and grab the PIM REGISTER header size, to avoid another
1735 * possible m_pullup() later.
1736 *
1737 * PIM_MINLEN == pimhdr + u_int32 == 8
1738 * PIM6_REG_MINLEN == pimhdr + reghdr + eip6hdr == 4 + 4 + 40
1739 */
1740 minlen = (pimlen >= PIM6_REG_MINLEN) ? PIM6_REG_MINLEN : PIM_MINLEN;
1741
1742 /*
1743 * Make sure that the IP6 and PIM headers in contiguous memory, and
1744 * possibly the PIM REGISTER header
1745 */
1746 IP6_EXTHDR_GET(pim, struct pim *, m, off, minlen);
1747 if (pim == NULL) {
1748 pim6stat.pim6s_rcv_tooshort++;
1749 return IPPROTO_DONE;
1750 }
1751
1752 /* PIM version check */
1753 if (pim->pim_ver != PIM_VERSION) {
1754 ++pim6stat.pim6s_rcv_badversion;
1755 #ifdef MRT6DEBUG
1756 log(LOG_ERR,
1757 "pim6_input: incorrect version %d, expecting %d\n",
1758 pim->pim_ver, PIM_VERSION);
1759 #endif
1760 m_freem(m);
1761 return (IPPROTO_DONE);
1762 }
1763
1764 #define PIM6_CHECKSUM
1765 #ifdef PIM6_CHECKSUM
1766 {
1767 int cksumlen;
1768
1769 /*
1770 * Validate checksum.
1771 * If PIM REGISTER, exclude the data packet
1772 */
1773 if (pim->pim_type == PIM_REGISTER)
1774 cksumlen = PIM_MINLEN;
1775 else
1776 cksumlen = pimlen;
1777
1778 if (in6_cksum(m, IPPROTO_PIM, off, cksumlen)) {
1779 ++pim6stat.pim6s_rcv_badsum;
1780 #ifdef MRT6DEBUG
1781 if (mrt6debug & DEBUG_PIM)
1782 log(LOG_DEBUG,
1783 "pim6_input: invalid checksum\n");
1784 #endif
1785 m_freem(m);
1786 return (IPPROTO_DONE);
1787 }
1788 }
1789 #endif /* PIM_CHECKSUM */
1790
1791 if (pim->pim_type == PIM_REGISTER) {
1792 /*
1793 * since this is a REGISTER, we'll make a copy of the register
1794 * headers ip6+pim+u_int32_t+encap_ip6, to be passed up to the
1795 * routing daemon.
1796 */
1797 static const struct sockaddr_in6 dst = {
1798 .sin6_len = sizeof(dst),
1799 .sin6_family = AF_INET6,
1800 };
1801
1802 struct mbuf *mcp;
1803 struct ip6_hdr *eip6;
1804 u_int32_t *reghdr;
1805
1806 ++pim6stat.pim6s_rcv_registers;
1807
1808 if ((reg_mif_num >= nummifs) || (reg_mif_num == (mifi_t) -1)) {
1809 #ifdef MRT6DEBUG
1810 if (mrt6debug & DEBUG_PIM)
1811 log(LOG_DEBUG,
1812 "pim6_input: register mif not set: %d\n",
1813 reg_mif_num);
1814 #endif
1815 m_freem(m);
1816 return (IPPROTO_DONE);
1817 }
1818
1819 reghdr = (u_int32_t *)(pim + 1);
1820
1821 if ((ntohl(*reghdr) & PIM_NULL_REGISTER))
1822 goto pim6_input_to_daemon;
1823
1824 /*
1825 * Validate length
1826 */
1827 if (pimlen < PIM6_REG_MINLEN) {
1828 ++pim6stat.pim6s_rcv_tooshort;
1829 ++pim6stat.pim6s_rcv_badregisters;
1830 #ifdef MRT6DEBUG
1831 log(LOG_ERR,
1832 "pim6_input: register packet size too "
1833 "small %d from %s\n",
1834 pimlen, ip6_sprintf(&ip6->ip6_src));
1835 #endif
1836 m_freem(m);
1837 return (IPPROTO_DONE);
1838 }
1839
1840 eip6 = (struct ip6_hdr *) (reghdr + 1);
1841 #ifdef MRT6DEBUG
1842 if (mrt6debug & DEBUG_PIM)
1843 log(LOG_DEBUG,
1844 "pim6_input[register], eip6: %s -> %s, "
1845 "eip6 plen %d\n",
1846 ip6_sprintf(&eip6->ip6_src),
1847 ip6_sprintf(&eip6->ip6_dst),
1848 ntohs(eip6->ip6_plen));
1849 #endif
1850
1851 /* verify the version number of the inner packet */
1852 if ((eip6->ip6_vfc & IPV6_VERSION_MASK) != IPV6_VERSION) {
1853 ++pim6stat.pim6s_rcv_badregisters;
1854 #ifdef MRT6DEBUG
1855 log(LOG_DEBUG, "pim6_input: invalid IP version (%d) "
1856 "of the inner packet\n",
1857 (eip6->ip6_vfc & IPV6_VERSION));
1858 #endif
1859 m_freem(m);
1860 return (IPPROTO_NONE);
1861 }
1862
1863 /* verify the inner packet is destined to a mcast group */
1864 if (!IN6_IS_ADDR_MULTICAST(&eip6->ip6_dst)) {
1865 ++pim6stat.pim6s_rcv_badregisters;
1866 #ifdef MRT6DEBUG
1867 if (mrt6debug & DEBUG_PIM)
1868 log(LOG_DEBUG,
1869 "pim6_input: inner packet of register "
1870 "is not multicast %s\n",
1871 ip6_sprintf(&eip6->ip6_dst));
1872 #endif
1873 m_freem(m);
1874 return (IPPROTO_DONE);
1875 }
1876
1877 /*
1878 * make a copy of the whole header to pass to the daemon later.
1879 */
1880 mcp = m_copy(m, 0, off + PIM6_REG_MINLEN);
1881 if (mcp == NULL) {
1882 #ifdef MRT6DEBUG
1883 log(LOG_ERR,
1884 "pim6_input: pim register: "
1885 "could not copy register head\n");
1886 #endif
1887 m_freem(m);
1888 return (IPPROTO_DONE);
1889 }
1890
1891 /*
1892 * forward the inner ip6 packet; point m_data at the inner ip6.
1893 */
1894 m_adj(m, off + PIM_MINLEN);
1895 #ifdef MRT6DEBUG
1896 if (mrt6debug & DEBUG_PIM) {
1897 log(LOG_DEBUG,
1898 "pim6_input: forwarding decapsulated register: "
1899 "src %s, dst %s, mif %d\n",
1900 ip6_sprintf(&eip6->ip6_src),
1901 ip6_sprintf(&eip6->ip6_dst),
1902 reg_mif_num);
1903 }
1904 #endif
1905
1906 looutput(mif6table[reg_mif_num].m6_ifp, m,
1907 (struct sockaddr *)__UNCONST(&dst),
1908 (struct rtentry *) NULL);
1909
1910 /* prepare the register head to send to the mrouting daemon */
1911 m = mcp;
1912 }
1913
1914 /*
1915 * Pass the PIM message up to the daemon; if it is a register message
1916 * pass the 'head' only up to the daemon. This includes the
1917 * encapsulator ip6 header, pim header, register header and the
1918 * encapsulated ip6 header.
1919 */
1920 pim6_input_to_daemon:
1921 rip6_input(&m, offp, proto);
1922 return (IPPROTO_DONE);
1923 }
1924
1925 SYSCTL_SETUP(sysctl_net_inet6_pim6_setup, "sysctl net.inet6.pim6 subtree setup")
1926 {
1927 sysctl_createv(clog, 0, NULL, NULL,
1928 CTLFLAG_PERMANENT,
1929 CTLTYPE_NODE, "net", NULL,
1930 NULL, 0, NULL, 0,
1931 CTL_NET, CTL_EOL);
1932 sysctl_createv(clog, 0, NULL, NULL,
1933 CTLFLAG_PERMANENT,
1934 CTLTYPE_NODE, "inet6", NULL,
1935 NULL, 0, NULL, 0,
1936 CTL_NET, PF_INET6, CTL_EOL);
1937 sysctl_createv(clog, 0, NULL, NULL,
1938 CTLFLAG_PERMANENT,
1939 CTLTYPE_NODE, "pim6",
1940 SYSCTL_DESCR("PIMv6 settings"),
1941 NULL, 0, NULL, 0,
1942 CTL_NET, PF_INET6, IPPROTO_PIM, CTL_EOL);
1943
1944 sysctl_createv(clog, 0, NULL, NULL,
1945 CTLFLAG_PERMANENT,
1946 CTLTYPE_STRUCT, "stats",
1947 SYSCTL_DESCR("PIMv6 statistics"),
1948 NULL, 0, &pim6stat, sizeof(pim6stat),
1949 CTL_NET, PF_INET6, IPPROTO_PIM, PIM6CTL_STATS,
1950 CTL_EOL);
1951 }
1952