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