2 /* $KAME: ip6_mroute.c,v 1.58 2001/12/18 02:36:31 itojun Exp $ */
5 * Copyright (C) 1998 WIDE Project.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
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.
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
33 /* BSDI ip_mroute.c,v 2.10 1996/11/14 00:29:52 jch Exp */
36 * Copyright (c) 1989 Stephen Deering
37 * Copyright (c) 1992, 1993
38 * The Regents of the University of California. All rights reserved.
40 * This code is derived from software contributed to Berkeley by
41 * Stephen Deering of Stanford University.
43 * Redistribution and use in source and binary forms, with or without
44 * modification, are permitted provided that the following conditions
46 * 1. Redistributions of source code must retain the above copyright
47 * notice, this list of conditions and the following disclaimer.
48 * 2. Redistributions in binary form must reproduce the above copyright
49 * notice, this list of conditions and the following disclaimer in the
50 * documentation and/or other materials provided with the distribution.
51 * 4. Neither the name of the University nor the names of its contributors
52 * may be used to endorse or promote products derived from this software
53 * without specific prior written permission.
55 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
56 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
57 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
58 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
59 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
60 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
61 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
62 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
63 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
64 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
67 * @(#)ip_mroute.c 8.2 (Berkeley) 11/15/93
71 * IP multicast forwarding procedures
73 * Written by David Waitzman, BBN Labs, August 1988.
74 * Modified by Steve Deering, Stanford, February 1989.
75 * Modified by Mark J. Steiglitz, Stanford, May, 1991
76 * Modified by Van Jacobson, LBL, January 1993
77 * Modified by Ajit Thyagarajan, PARC, August 1993
78 * Modified by Bill Fenner, PARC, April 1994
80 * MROUTING Revision: 3.5.1.2 + PIM-SMv2 (pimd) Support
84 #include "opt_inet6.h"
86 #include <sys/param.h>
87 #include <sys/callout.h>
88 #include <sys/errno.h>
89 #include <sys/kernel.h>
91 #include <sys/malloc.h>
93 #include <sys/protosw.h>
94 #include <sys/signalvar.h>
95 #include <sys/socket.h>
96 #include <sys/socketvar.h>
97 #include <sys/sockio.h>
99 #include <sys/syslog.h>
100 #include <sys/systm.h>
101 #include <sys/time.h>
104 #include <net/if_types.h>
105 #include <net/raw_cb.h>
106 #include <net/route.h>
108 #include <netinet/in.h>
109 #include <netinet/in_var.h>
110 #include <netinet/icmp6.h>
112 #include <netinet/ip6.h>
113 #include <netinet6/ip6_var.h>
114 #include <netinet6/scope6_var.h>
115 #include <netinet6/nd6.h>
116 #include <netinet6/ip6_mroute.h>
117 #include <netinet6/pim6.h>
118 #include <netinet6/pim6_var.h>
120 #include <net/net_osdep.h>
122 static MALLOC_DEFINE(M_MRTABLE6, "mf6c", "multicast forwarding cache entry");
124 #define M_HASCL(m) ((m)->m_flags & M_EXT)
126 static int ip6_mdq __P((struct mbuf *, struct ifnet *, struct mf6c *));
127 static void phyint_send __P((struct ip6_hdr *, struct mif6 *, struct mbuf *));
129 static int set_pim6 __P((int *));
130 static int socket_send __P((struct socket *, struct mbuf *,
131 struct sockaddr_in6 *));
132 static int register_send __P((struct ip6_hdr *, struct mif6 *,
136 * Globals. All but ip6_mrouter, ip6_mrtproto and mrt6stat could be static,
137 * except for netstat or debugging purposes.
139 struct socket *ip6_mrouter = NULL;
140 int ip6_mrouter_ver = 0;
141 int ip6_mrtproto = IPPROTO_PIM; /* for netstat only */
142 struct mrt6stat mrt6stat;
144 #define NO_RTE_FOUND 0x1
145 #define RTE_FOUND 0x2
147 struct mf6c *mf6ctable[MF6CTBLSIZ];
148 u_char n6expire[MF6CTBLSIZ];
149 static struct mif6 mif6table[MAXMIFS];
151 u_int mrt6debug = 0; /* debug level */
152 #define DEBUG_MFC 0x02
153 #define DEBUG_FORWARD 0x04
154 #define DEBUG_EXPIRE 0x08
155 #define DEBUG_XMIT 0x10
156 #define DEBUG_REG 0x20
157 #define DEBUG_PIM 0x40
160 static void expire_upcalls __P((void *));
161 #define EXPIRE_TIMEOUT (hz / 4) /* 4x / second */
162 #define UPCALL_EXPIRE 6 /* number of timeouts */
166 extern struct socket *ip_mrouter;
171 * 'Interfaces' associated with decapsulator (so we can tell
172 * packets that went through it from ones that get reflected
173 * by a broken gateway). Different from IPv4 register_if,
174 * these interfaces are linked into the system ifnet list,
175 * because per-interface IPv6 statistics are maintained in
176 * ifp->if_afdata. But it does not have any routes point
177 * to them. I.e., packets can't be sent this way. They
178 * only exist as a placeholder for multicast source
181 static struct ifnet *multicast_register_if6;
183 #define ENCAP_HOPS 64
188 static mifi_t nummifs = 0;
189 static mifi_t reg_mif_num = (mifi_t)-1;
191 static struct pim6stat pim6stat;
195 * Hash function for a source, group entry
197 #define MF6CHASH(a, g) MF6CHASHMOD((a).s6_addr32[0] ^ (a).s6_addr32[1] ^ \
198 (a).s6_addr32[2] ^ (a).s6_addr32[3] ^ \
199 (g).s6_addr32[0] ^ (g).s6_addr32[1] ^ \
200 (g).s6_addr32[2] ^ (g).s6_addr32[3])
203 * Find a route for a given origin IPv6 address and Multicast group address.
204 * Quality of service parameter to be added in the future!!!
207 #define MF6CFIND(o, g, rt) do { \
208 struct mf6c *_rt = mf6ctable[MF6CHASH(o,g)]; \
210 mrt6stat.mrt6s_mfc_lookups++; \
212 if (IN6_ARE_ADDR_EQUAL(&_rt->mf6c_origin.sin6_addr, &(o)) && \
213 IN6_ARE_ADDR_EQUAL(&_rt->mf6c_mcastgrp.sin6_addr, &(g)) && \
214 (_rt->mf6c_stall == NULL)) { \
218 _rt = _rt->mf6c_next; \
221 mrt6stat.mrt6s_mfc_misses++; \
223 } while (/*CONSTCOND*/ 0)
226 * Macros to compute elapsed time efficiently
227 * Borrowed from Van Jacobson's scheduling code
229 #define TV_DELTA(a, b, delta) do { \
232 delta = (a).tv_usec - (b).tv_usec; \
233 if ((xxs = (a).tv_sec - (b).tv_sec)) { \
242 delta += (1000000 * xxs); \
245 } while (/*CONSTCOND*/ 0)
247 #define TV_LT(a, b) (((a).tv_usec < (b).tv_usec && \
248 (a).tv_sec <= (b).tv_sec) || (a).tv_sec < (b).tv_sec)
251 #define UPCALL_MAX 50
252 u_long upcall_data[UPCALL_MAX + 1];
253 static void collate();
254 #endif /* UPCALL_TIMING */
256 static int get_sg_cnt __P((struct sioc_sg_req6 *));
257 static int get_mif6_cnt __P((struct sioc_mif_req6 *));
258 static int ip6_mrouter_init __P((struct socket *, int, int));
259 static int add_m6if __P((struct mif6ctl *));
260 static int del_m6if __P((mifi_t *));
261 static int add_m6fc __P((struct mf6cctl *));
262 static int del_m6fc __P((struct mf6cctl *));
264 static struct callout expire_upcalls_ch;
267 * Handle MRT setsockopt commands to modify the multicast routing tables.
270 ip6_mrouter_set(so, sopt)
272 struct sockopt *sopt;
280 if (so != ip6_mrouter && sopt->sopt_name != MRT6_INIT)
283 switch (sopt->sopt_name) {
288 error = sooptcopyin(sopt, &optval, sizeof(optval),
292 error = ip6_mrouter_init(so, optval, sopt->sopt_name);
295 error = ip6_mrouter_done();
298 error = sooptcopyin(sopt, &mifc, sizeof(mifc), sizeof(mifc));
301 error = add_m6if(&mifc);
304 error = sooptcopyin(sopt, &mfcc, sizeof(mfcc), sizeof(mfcc));
307 error = add_m6fc(&mfcc);
310 error = sooptcopyin(sopt, &mfcc, sizeof(mfcc), sizeof(mfcc));
313 error = del_m6fc(&mfcc);
316 error = sooptcopyin(sopt, &mifi, sizeof(mifi), sizeof(mifi));
319 error = del_m6if(&mifi);
322 error = sooptcopyin(sopt, &optval, sizeof(optval),
326 error = set_pim6(&optval);
337 * Handle MRT getsockopt commands
340 ip6_mrouter_get(so, sopt)
342 struct sockopt *sopt;
346 if (so != ip6_mrouter)
349 switch (sopt->sopt_name) {
351 error = sooptcopyout(sopt, &pim6, sizeof(pim6));
358 * Handle ioctl commands to obtain information from the cache
361 mrt6_ioctl(cmd, data)
366 case SIOCGETSGCNT_IN6:
367 return (get_sg_cnt((struct sioc_sg_req6 *)data));
368 case SIOCGETMIFCNT_IN6:
369 return (get_mif6_cnt((struct sioc_mif_req6 *)data));
376 * returns the packet, byte, rpf-failure count for the source group provided
380 struct sioc_sg_req6 *req;
386 MF6CFIND(req->src.sin6_addr, req->grp.sin6_addr, rt);
389 req->pktcnt = rt->mf6c_pkt_cnt;
390 req->bytecnt = rt->mf6c_byte_cnt;
391 req->wrong_if = rt->mf6c_wrong_if;
395 req->pktcnt = req->bytecnt = req->wrong_if = 0xffffffff;
402 * returns the input and output packet and byte counts on the mif provided
406 struct sioc_mif_req6 *req;
408 mifi_t mifi = req->mifi;
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;
425 if ((*i != 1) && (*i != 0))
434 * Enable multicast routing
437 ip6_mrouter_init(so, v, cmd)
445 "ip6_mrouter_init: so_type = %d, pr_protocol = %d\n",
446 so->so_type, so->so_proto->pr_protocol);
449 if (so->so_type != SOCK_RAW ||
450 so->so_proto->pr_protocol != IPPROTO_ICMPV6)
454 return (ENOPROTOOPT);
456 if (ip6_mrouter != NULL)
460 ip6_mrouter_ver = cmd;
462 bzero((caddr_t)mf6ctable, sizeof(mf6ctable));
463 bzero((caddr_t)n6expire, sizeof(n6expire));
465 pim6 = 0;/* used for stubbing out/in pim stuff */
467 callout_init(&expire_upcalls_ch, 0);
468 callout_reset(&expire_upcalls_ch, EXPIRE_TIMEOUT,
469 expire_upcalls, NULL);
473 log(LOG_DEBUG, "ip6_mrouter_init\n");
480 * Disable multicast routing
488 struct in6_ifreq ifr;
496 * For each phyint in use, disable promiscuous reception of all IPv6
502 * If there is still IPv4 multicast routing daemon,
503 * we remain interfaces to receive all muliticasted packets.
504 * XXX: there may be an interface in which the IPv4 multicast
505 * daemon is not interested...
511 for (mifi = 0; mifi < nummifs; mifi++) {
512 if (mif6table[mifi].m6_ifp &&
513 !(mif6table[mifi].m6_flags & MIFF_REGISTER)) {
514 ifr.ifr_addr.sin6_family = AF_INET6;
515 ifr.ifr_addr.sin6_addr = in6addr_any;
516 ifp = mif6table[mifi].m6_ifp;
517 (*ifp->if_ioctl)(ifp, SIOCDELMULTI,
523 bzero((caddr_t)qtable, sizeof(qtable));
524 bzero((caddr_t)tbftable, sizeof(tbftable));
526 bzero((caddr_t)mif6table, sizeof(mif6table));
529 pim6 = 0; /* used to stub out/in pim specific code */
531 callout_stop(&expire_upcalls_ch);
534 * Free all multicast forwarding cache entries.
536 for (i = 0; i < MF6CTBLSIZ; i++) {
541 for (rte = rt->mf6c_stall; rte != NULL; ) {
542 struct rtdetq *n = rte->next;
545 free(rte, M_MRTABLE6);
550 free(frt, M_MRTABLE6);
554 bzero((caddr_t)mf6ctable, sizeof(mf6ctable));
557 * Reset register interface
559 if (reg_mif_num != (mifi_t)-1 && multicast_register_if6 != NULL) {
560 if_detach(multicast_register_if6);
561 if_free(multicast_register_if6);
562 reg_mif_num = (mifi_t)-1;
563 multicast_register_if6 = NULL;
573 log(LOG_DEBUG, "ip6_mrouter_done\n");
579 static struct sockaddr_in6 sin6 = { sizeof(sin6), AF_INET6 };
582 * Add a mif to the mif table
586 struct mif6ctl *mifcp;
592 struct tbf *m_tbf = tbftable + mifcp->mif6c_mifi;
595 if (mifcp->mif6c_mifi >= MAXMIFS)
597 mifp = mif6table + mifcp->mif6c_mifi;
599 return (EADDRINUSE); /* XXX: is it appropriate? */
600 if (mifcp->mif6c_pifi == 0 || mifcp->mif6c_pifi > if_index)
602 ifp = ifnet_byindex(mifcp->mif6c_pifi);
604 if (mifcp->mif6c_flags & MIFF_REGISTER) {
605 if (reg_mif_num == (mifi_t)-1) {
606 ifp = if_alloc(IFT_OTHER);
608 if_initname(ifp, "register_mif", 0);
609 ifp->if_flags |= IFF_LOOPBACK;
611 multicast_register_if6 = ifp;
612 reg_mif_num = mifcp->mif6c_mifi;
614 * it is impossible to guess the ifindex of the
615 * register interface. So mif6c_pifi is automatically
618 mifcp->mif6c_pifi = ifp->if_index;
620 ifp = multicast_register_if6;
625 /* Make sure the interface supports multicast */
626 if ((ifp->if_flags & IFF_MULTICAST) == 0)
630 error = if_allmulti(ifp, 1);
637 mifp->m6_flags = mifcp->mif6c_flags;
640 /* scaling up here allows division by 1024 in critical code */
641 mifp->m6_rate_limit = mifcp->mif6c_rate_limit * 1024 / 1000;
643 /* initialize per mif pkt counters */
645 mifp->m6_pkt_out = 0;
646 mifp->m6_bytes_in = 0;
647 mifp->m6_bytes_out = 0;
650 /* Adjust nummifs up if the mifi is higher than nummifs */
651 if (nummifs <= mifcp->mif6c_mifi)
652 nummifs = mifcp->mif6c_mifi + 1;
657 "add_mif #%d, phyint %s\n",
666 * Delete a mif from the mif table
672 struct mif6 *mifp = mif6table + *mifip;
677 if (*mifip >= nummifs)
679 if (mifp->m6_ifp == NULL)
684 if (!(mifp->m6_flags & MIFF_REGISTER)) {
686 * XXX: what if there is yet IPv4 multicast daemon
687 * using the interface?
693 if (reg_mif_num != (mifi_t)-1 &&
694 multicast_register_if6 != NULL) {
695 if_detach(multicast_register_if6);
696 if_free(multicast_register_if6);
697 reg_mif_num = (mifi_t)-1;
698 multicast_register_if6 = NULL;
703 bzero((caddr_t)qtable[*mifip], sizeof(qtable[*mifip]));
704 bzero((caddr_t)mifp->m6_tbf, sizeof(*(mifp->m6_tbf)));
706 bzero((caddr_t)mifp, sizeof(*mifp));
708 /* Adjust nummifs down */
709 for (mifi = nummifs; mifi > 0; mifi--)
710 if (mif6table[mifi - 1].m6_ifp)
718 log(LOG_DEBUG, "del_m6if %d, nummifs %d\n", *mifip, nummifs);
729 struct mf6cctl *mfccp;
737 MF6CFIND(mfccp->mf6cc_origin.sin6_addr,
738 mfccp->mf6cc_mcastgrp.sin6_addr, rt);
740 /* If an entry already exists, just update the fields */
743 if (mrt6debug & DEBUG_MFC)
745 "add_m6fc no upcall h %d o %s g %s p %x\n",
746 ip6_sprintf(&mfccp->mf6cc_origin.sin6_addr),
747 ip6_sprintf(&mfccp->mf6cc_mcastgrp.sin6_addr),
748 mfccp->mf6cc_parent);
752 rt->mf6c_parent = mfccp->mf6cc_parent;
753 rt->mf6c_ifset = mfccp->mf6cc_ifset;
759 * Find the entry for which the upcall was made and update
762 hash = MF6CHASH(mfccp->mf6cc_origin.sin6_addr,
763 mfccp->mf6cc_mcastgrp.sin6_addr);
764 for (rt = mf6ctable[hash], nstl = 0; rt; rt = rt->mf6c_next) {
765 if (IN6_ARE_ADDR_EQUAL(&rt->mf6c_origin.sin6_addr,
766 &mfccp->mf6cc_origin.sin6_addr) &&
767 IN6_ARE_ADDR_EQUAL(&rt->mf6c_mcastgrp.sin6_addr,
768 &mfccp->mf6cc_mcastgrp.sin6_addr) &&
769 (rt->mf6c_stall != NULL)) {
773 "add_m6fc: %s o %s g %s p %x dbx %p\n",
774 "multiple kernel entries",
775 ip6_sprintf(&mfccp->mf6cc_origin.sin6_addr),
776 ip6_sprintf(&mfccp->mf6cc_mcastgrp.sin6_addr),
777 mfccp->mf6cc_parent, rt->mf6c_stall);
780 if (mrt6debug & DEBUG_MFC)
782 "add_m6fc o %s g %s p %x dbg %x\n",
783 ip6_sprintf(&mfccp->mf6cc_origin.sin6_addr),
784 ip6_sprintf(&mfccp->mf6cc_mcastgrp.sin6_addr),
785 mfccp->mf6cc_parent, rt->mf6c_stall);
788 rt->mf6c_origin = mfccp->mf6cc_origin;
789 rt->mf6c_mcastgrp = mfccp->mf6cc_mcastgrp;
790 rt->mf6c_parent = mfccp->mf6cc_parent;
791 rt->mf6c_ifset = mfccp->mf6cc_ifset;
792 /* initialize pkt counters per src-grp */
793 rt->mf6c_pkt_cnt = 0;
794 rt->mf6c_byte_cnt = 0;
795 rt->mf6c_wrong_if = 0;
797 rt->mf6c_expire = 0; /* Don't clean this guy up */
800 /* free packets Qed at the end of this entry */
801 for (rte = rt->mf6c_stall; rte != NULL; ) {
802 struct rtdetq *n = rte->next;
803 ip6_mdq(rte->m, rte->ifp, rt);
807 #endif /* UPCALL_TIMING */
808 free(rte, M_MRTABLE6);
811 rt->mf6c_stall = NULL;
816 * It is possible that an entry is being inserted without an upcall
820 if (mrt6debug & DEBUG_MFC)
822 "add_mfc no upcall h %d o %s g %s p %x\n",
824 ip6_sprintf(&mfccp->mf6cc_origin.sin6_addr),
825 ip6_sprintf(&mfccp->mf6cc_mcastgrp.sin6_addr),
826 mfccp->mf6cc_parent);
829 for (rt = mf6ctable[hash]; rt; rt = rt->mf6c_next) {
831 if (IN6_ARE_ADDR_EQUAL(&rt->mf6c_origin.sin6_addr,
832 &mfccp->mf6cc_origin.sin6_addr)&&
833 IN6_ARE_ADDR_EQUAL(&rt->mf6c_mcastgrp.sin6_addr,
834 &mfccp->mf6cc_mcastgrp.sin6_addr)) {
836 rt->mf6c_origin = mfccp->mf6cc_origin;
837 rt->mf6c_mcastgrp = mfccp->mf6cc_mcastgrp;
838 rt->mf6c_parent = mfccp->mf6cc_parent;
839 rt->mf6c_ifset = mfccp->mf6cc_ifset;
840 /* initialize pkt counters per src-grp */
841 rt->mf6c_pkt_cnt = 0;
842 rt->mf6c_byte_cnt = 0;
843 rt->mf6c_wrong_if = 0;
851 /* no upcall, so make a new entry */
852 rt = (struct mf6c *)malloc(sizeof(*rt), M_MRTABLE6,
859 /* insert new entry at head of hash chain */
860 rt->mf6c_origin = mfccp->mf6cc_origin;
861 rt->mf6c_mcastgrp = mfccp->mf6cc_mcastgrp;
862 rt->mf6c_parent = mfccp->mf6cc_parent;
863 rt->mf6c_ifset = mfccp->mf6cc_ifset;
864 /* initialize pkt counters per src-grp */
865 rt->mf6c_pkt_cnt = 0;
866 rt->mf6c_byte_cnt = 0;
867 rt->mf6c_wrong_if = 0;
869 rt->mf6c_stall = NULL;
871 /* link into table */
872 rt->mf6c_next = mf6ctable[hash];
873 mf6ctable[hash] = rt;
882 * collect delay statistics on the upcalls
896 TV_DELTA(tp, *t, delta);
905 #endif /* UPCALL_TIMING */
908 * Delete an mfc entry
912 struct mf6cctl *mfccp;
914 struct sockaddr_in6 origin;
915 struct sockaddr_in6 mcastgrp;
921 origin = mfccp->mf6cc_origin;
922 mcastgrp = mfccp->mf6cc_mcastgrp;
923 hash = MF6CHASH(origin.sin6_addr, mcastgrp.sin6_addr);
926 if (mrt6debug & DEBUG_MFC)
927 log(LOG_DEBUG,"del_m6fc orig %s mcastgrp %s\n",
928 ip6_sprintf(&origin.sin6_addr),
929 ip6_sprintf(&mcastgrp.sin6_addr));
934 nptr = &mf6ctable[hash];
935 while ((rt = *nptr) != NULL) {
936 if (IN6_ARE_ADDR_EQUAL(&origin.sin6_addr,
937 &rt->mf6c_origin.sin6_addr) &&
938 IN6_ARE_ADDR_EQUAL(&mcastgrp.sin6_addr,
939 &rt->mf6c_mcastgrp.sin6_addr) &&
940 rt->mf6c_stall == NULL)
943 nptr = &rt->mf6c_next;
947 return (EADDRNOTAVAIL);
950 *nptr = rt->mf6c_next;
951 free(rt, M_MRTABLE6);
959 socket_send(s, mm, src)
962 struct sockaddr_in6 *src;
965 if (sbappendaddr(&s->so_rcv,
966 (struct sockaddr *)src,
967 mm, (struct mbuf *)0) != 0) {
977 * IPv6 multicast forwarding function. This function assumes that the packet
978 * pointed to by "ip6" has arrived on (or is about to be sent to) the interface
979 * pointed to by "ifp", and the packet is to be relayed to other networks
980 * that have members of the packet's destination IPv6 multicast group.
982 * The packet is returned unscathed to the caller, unless it is
983 * erroneous, in which case a non-zero return value tells the caller to
988 ip6_mforward(ip6, ifp, m)
1000 if (mrt6debug & DEBUG_FORWARD)
1001 log(LOG_DEBUG, "ip6_mforward: src %s, dst %s, ifindex %d\n",
1002 ip6_sprintf(&ip6->ip6_src), ip6_sprintf(&ip6->ip6_dst),
1007 * Don't forward a packet with Hop limit of zero or one,
1008 * or a packet destined to a local-only group.
1010 if (ip6->ip6_hlim <= 1 || IN6_IS_ADDR_MC_INTFACELOCAL(&ip6->ip6_dst) ||
1011 IN6_IS_ADDR_MC_LINKLOCAL(&ip6->ip6_dst))
1016 * Source address check: do not forward packets with unspecified
1017 * source. It was discussed in July 2000, on ipngwg mailing list.
1018 * This is rather more serious than unicast cases, because some
1019 * MLD packets can be sent with the unspecified source address
1020 * (although such packets must normally set 1 to the hop limit field).
1022 if (IN6_IS_ADDR_UNSPECIFIED(&ip6->ip6_src)) {
1023 ip6stat.ip6s_cantforward++;
1024 if (ip6_log_time + ip6_log_interval < time_second) {
1025 ip6_log_time = time_second;
1028 "from %s to %s nxt %d received on %s\n",
1029 ip6_sprintf(&ip6->ip6_src),
1030 ip6_sprintf(&ip6->ip6_dst),
1032 if_name(m->m_pkthdr.rcvif));
1038 * Determine forwarding mifs from the forwarding cache table
1041 MF6CFIND(ip6->ip6_src, ip6->ip6_dst, rt);
1043 /* Entry exists, so forward if necessary */
1046 return (ip6_mdq(m, ifp, rt));
1049 * If we don't have a route for packet's origin,
1050 * Make a copy of the packet &
1051 * send message to routing daemon
1058 #ifdef UPCALL_TIMING
1062 #endif /* UPCALL_TIMING */
1064 mrt6stat.mrt6s_no_route++;
1066 if (mrt6debug & (DEBUG_FORWARD | DEBUG_MFC))
1067 log(LOG_DEBUG, "ip6_mforward: no rte s %s g %s\n",
1068 ip6_sprintf(&ip6->ip6_src),
1069 ip6_sprintf(&ip6->ip6_dst));
1073 * Allocate mbufs early so that we don't do extra work if we
1074 * are just going to fail anyway.
1076 rte = (struct rtdetq *)malloc(sizeof(*rte), M_MRTABLE6,
1082 mb0 = m_copy(m, 0, M_COPYALL);
1084 * Pullup packet header if needed before storing it,
1085 * as other references may modify it in the meantime.
1088 (M_HASCL(mb0) || mb0->m_len < sizeof(struct ip6_hdr)))
1089 mb0 = m_pullup(mb0, sizeof(struct ip6_hdr));
1091 free(rte, M_MRTABLE6);
1096 /* is there an upcall waiting for this packet? */
1097 hash = MF6CHASH(ip6->ip6_src, ip6->ip6_dst);
1098 for (rt = mf6ctable[hash]; rt; rt = rt->mf6c_next) {
1099 if (IN6_ARE_ADDR_EQUAL(&ip6->ip6_src,
1100 &rt->mf6c_origin.sin6_addr) &&
1101 IN6_ARE_ADDR_EQUAL(&ip6->ip6_dst,
1102 &rt->mf6c_mcastgrp.sin6_addr) &&
1103 (rt->mf6c_stall != NULL))
1110 struct omrt6msg *oim;
1113 /* no upcall, so make a new entry */
1114 rt = (struct mf6c *)malloc(sizeof(*rt), M_MRTABLE6,
1117 free(rte, M_MRTABLE6);
1123 * Make a copy of the header to send to the user
1126 mm = m_copy(mb0, 0, sizeof(struct ip6_hdr));
1129 free(rte, M_MRTABLE6);
1131 free(rt, M_MRTABLE6);
1137 * Send message to routing daemon
1139 sin6.sin6_addr = ip6->ip6_src;
1145 switch (ip6_mrouter_ver) {
1148 oim = mtod(mm, struct omrt6msg *);
1149 oim->im6_msgtype = MRT6MSG_NOCACHE;
1154 im = mtod(mm, struct mrt6msg *);
1155 im->im6_msgtype = MRT6MSG_NOCACHE;
1159 free(rte, M_MRTABLE6);
1161 free(rt, M_MRTABLE6);
1167 if (mrt6debug & DEBUG_FORWARD)
1169 "getting the iif info in the kernel\n");
1172 for (mifp = mif6table, mifi = 0;
1173 mifi < nummifs && mifp->m6_ifp != ifp;
1177 switch (ip6_mrouter_ver) {
1180 oim->im6_mif = mifi;
1188 if (socket_send(ip6_mrouter, mm, &sin6) < 0) {
1189 log(LOG_WARNING, "ip6_mforward: ip6_mrouter "
1190 "socket queue full\n");
1191 mrt6stat.mrt6s_upq_sockfull++;
1192 free(rte, M_MRTABLE6);
1194 free(rt, M_MRTABLE6);
1199 mrt6stat.mrt6s_upcalls++;
1201 /* insert new entry at head of hash chain */
1202 bzero(rt, sizeof(*rt));
1203 rt->mf6c_origin.sin6_family = AF_INET6;
1204 rt->mf6c_origin.sin6_len = sizeof(struct sockaddr_in6);
1205 rt->mf6c_origin.sin6_addr = ip6->ip6_src;
1206 rt->mf6c_mcastgrp.sin6_family = AF_INET6;
1207 rt->mf6c_mcastgrp.sin6_len = sizeof(struct sockaddr_in6);
1208 rt->mf6c_mcastgrp.sin6_addr = ip6->ip6_dst;
1209 rt->mf6c_expire = UPCALL_EXPIRE;
1211 rt->mf6c_parent = MF6C_INCOMPLETE_PARENT;
1213 /* link into table */
1214 rt->mf6c_next = mf6ctable[hash];
1215 mf6ctable[hash] = rt;
1216 /* Add this entry to the end of the queue */
1217 rt->mf6c_stall = rte;
1219 /* determine if q has overflowed */
1223 for (p = &rt->mf6c_stall; *p != NULL; p = &(*p)->next)
1224 if (++npkts > MAX_UPQ6) {
1225 mrt6stat.mrt6s_upq_ovflw++;
1226 free(rte, M_MRTABLE6);
1232 /* Add this entry to the end of the queue */
1239 #ifdef UPCALL_TIMING
1241 #endif /* UPCALL_TIMING */
1250 * Clean up cache entries if upcalls are not serviced
1251 * Call from the Slow Timeout mechanism, every half second.
1254 expire_upcalls(unused)
1258 struct mf6c *mfc, **nptr;
1263 for (i = 0; i < MF6CTBLSIZ; i++) {
1264 if (n6expire[i] == 0)
1266 nptr = &mf6ctable[i];
1267 while ((mfc = *nptr) != NULL) {
1268 rte = mfc->mf6c_stall;
1270 * Skip real cache entries
1271 * Make sure it wasn't marked to not expire (shouldn't happen)
1275 mfc->mf6c_expire != 0 &&
1276 --mfc->mf6c_expire == 0) {
1278 if (mrt6debug & DEBUG_EXPIRE)
1279 log(LOG_DEBUG, "expire_upcalls: expiring (%s %s)\n",
1280 ip6_sprintf(&mfc->mf6c_origin.sin6_addr),
1281 ip6_sprintf(&mfc->mf6c_mcastgrp.sin6_addr));
1284 * drop all the packets
1285 * free the mbuf with the pkt, if, timing info
1288 struct rtdetq *n = rte->next;
1290 free(rte, M_MRTABLE6);
1292 } while (rte != NULL);
1293 mrt6stat.mrt6s_cache_cleanups++;
1296 *nptr = mfc->mf6c_next;
1297 free(mfc, M_MRTABLE6);
1299 nptr = &mfc->mf6c_next;
1304 callout_reset(&expire_upcalls_ch, EXPIRE_TIMEOUT,
1305 expire_upcalls, NULL);
1309 * Packet forwarding routine once entry in the cache is made
1317 struct ip6_hdr *ip6 = mtod(m, struct ip6_hdr *);
1320 int plen = m->m_pkthdr.len;
1321 struct in6_addr src0, dst0; /* copies for local work */
1322 u_int32_t iszone, idzone, oszone, odzone;
1326 * Macro to send packet on mif. Since RSVP packets don't get counted on
1327 * input, they shouldn't get counted on output, so statistics keeping is
1331 #define MC6_SEND(ip6, mifp, m) do { \
1332 if ((mifp)->m6_flags & MIFF_REGISTER) \
1333 register_send((ip6), (mifp), (m)); \
1335 phyint_send((ip6), (mifp), (m)); \
1336 } while (/*CONSTCOND*/ 0)
1339 * Don't forward if it didn't arrive from the parent mif
1342 mifi = rt->mf6c_parent;
1343 if ((mifi >= nummifs) || (mif6table[mifi].m6_ifp != ifp)) {
1344 /* came in the wrong interface */
1346 if (mrt6debug & DEBUG_FORWARD)
1348 "wrong if: ifid %d mifi %d mififid %x\n",
1349 ifp->if_index, mifi,
1350 mif6table[mifi].m6_ifp->if_index);
1352 mrt6stat.mrt6s_wrong_if++;
1353 rt->mf6c_wrong_if++;
1355 * If we are doing PIM processing, and we are forwarding
1356 * packets on this interface, send a message to the
1359 /* have to make sure this is a valid mif */
1360 if (mifi < nummifs && mif6table[mifi].m6_ifp)
1361 if (pim6 && (m->m_flags & M_LOOP) == 0) {
1363 * Check the M_LOOP flag to avoid an
1364 * unnecessary PIM assert.
1365 * XXX: M_LOOP is an ad-hoc hack...
1367 static struct sockaddr_in6 sin6 =
1368 { sizeof(sin6), AF_INET6 };
1373 struct omrt6msg *oim;
1376 mm = m_copy(m, 0, sizeof(struct ip6_hdr));
1379 mm->m_len < sizeof(struct ip6_hdr)))
1380 mm = m_pullup(mm, sizeof(struct ip6_hdr));
1388 switch (ip6_mrouter_ver) {
1391 oim = mtod(mm, struct omrt6msg *);
1392 oim->im6_msgtype = MRT6MSG_WRONGMIF;
1397 im = mtod(mm, struct mrt6msg *);
1398 im->im6_msgtype = MRT6MSG_WRONGMIF;
1406 for (mifp = mif6table, iif = 0;
1407 iif < nummifs && mifp &&
1408 mifp->m6_ifp != ifp;
1412 switch (ip6_mrouter_ver) {
1416 sin6.sin6_addr = oim->im6_src;
1421 sin6.sin6_addr = im->im6_src;
1425 mrt6stat.mrt6s_upcalls++;
1427 if (socket_send(ip6_mrouter, mm, &sin6) < 0) {
1430 log(LOG_WARNING, "mdq, ip6_mrouter socket queue full\n");
1432 ++mrt6stat.mrt6s_upq_sockfull;
1434 } /* if socket Q full */
1437 } /* if wrong iif */
1439 /* If I sourced this packet, it counts as output, else it was input. */
1440 if (m->m_pkthdr.rcvif == NULL) {
1441 /* XXX: is rcvif really NULL when output?? */
1442 mif6table[mifi].m6_pkt_out++;
1443 mif6table[mifi].m6_bytes_out += plen;
1445 mif6table[mifi].m6_pkt_in++;
1446 mif6table[mifi].m6_bytes_in += plen;
1449 rt->mf6c_byte_cnt += plen;
1452 * For each mif, forward a copy of the packet if there are group
1453 * members downstream on the interface.
1455 src0 = ip6->ip6_src;
1456 dst0 = ip6->ip6_dst;
1457 if ((error = in6_setscope(&src0, ifp, &iszone)) != 0 ||
1458 (error = in6_setscope(&dst0, ifp, &idzone)) != 0) {
1459 ip6stat.ip6s_badscope++;
1462 for (mifp = mif6table, mifi = 0; mifi < nummifs; mifp++, mifi++) {
1463 if (IF_ISSET(mifi, &rt->mf6c_ifset)) {
1465 * check if the outgoing packet is going to break
1467 * XXX For packets through PIM register tunnel
1468 * interface, we believe a routing daemon.
1470 if (!(mif6table[rt->mf6c_parent].m6_flags &
1472 !(mif6table[mifi].m6_flags & MIFF_REGISTER)) {
1473 if (in6_setscope(&src0, mif6table[mifi].m6_ifp,
1475 in6_setscope(&dst0, mif6table[mifi].m6_ifp,
1479 ip6stat.ip6s_badscope++;
1485 mifp->m6_bytes_out += plen;
1486 MC6_SEND(ip6, mifp, m);
1493 phyint_send(ip6, mifp, m)
1494 struct ip6_hdr *ip6;
1498 struct mbuf *mb_copy;
1499 struct ifnet *ifp = mifp->m6_ifp;
1501 int s = splnet(); /* needs to protect static "ro" below. */
1502 static struct route_in6 ro;
1503 struct in6_multi *in6m;
1504 struct sockaddr_in6 *dst6;
1508 * Make a new reference to the packet; make sure that
1509 * the IPv6 header is actually copied, not just referenced,
1510 * so that ip6_output() only scribbles on the copy.
1512 mb_copy = m_copy(m, 0, M_COPYALL);
1514 (M_HASCL(mb_copy) || mb_copy->m_len < sizeof(struct ip6_hdr)))
1515 mb_copy = m_pullup(mb_copy, sizeof(struct ip6_hdr));
1516 if (mb_copy == NULL) {
1520 /* set MCAST flag to the outgoing packet */
1521 mb_copy->m_flags |= M_MCAST;
1524 * If we sourced the packet, call ip6_output since we may devide
1525 * the packet into fragments when the packet is too big for the
1526 * outgoing interface.
1527 * Otherwise, we can simply send the packet to the interface
1530 if (m->m_pkthdr.rcvif == NULL) {
1531 struct ip6_moptions im6o;
1533 im6o.im6o_multicast_ifp = ifp;
1534 /* XXX: ip6_output will override ip6->ip6_hlim */
1535 im6o.im6o_multicast_hlim = ip6->ip6_hlim;
1536 im6o.im6o_multicast_loop = 1;
1537 error = ip6_output(mb_copy, NULL, &ro,
1538 IPV6_FORWARDING, &im6o, NULL, NULL);
1541 if (mrt6debug & DEBUG_XMIT)
1542 log(LOG_DEBUG, "phyint_send on mif %d err %d\n",
1543 mifp - mif6table, error);
1550 * If we belong to the destination multicast group
1551 * on the outgoing interface, loop back a copy.
1553 dst6 = (struct sockaddr_in6 *)&ro.ro_dst;
1554 IN6_LOOKUP_MULTI(ip6->ip6_dst, ifp, in6m);
1556 dst6->sin6_len = sizeof(struct sockaddr_in6);
1557 dst6->sin6_family = AF_INET6;
1558 dst6->sin6_addr = ip6->ip6_dst;
1559 ip6_mloopback(ifp, m, (struct sockaddr_in6 *)&ro.ro_dst);
1562 * Put the packet into the sending queue of the outgoing interface
1563 * if it would fit in the MTU of the interface.
1565 linkmtu = IN6_LINKMTU(ifp);
1566 if (mb_copy->m_pkthdr.len <= linkmtu || linkmtu < IPV6_MMTU) {
1567 dst6->sin6_len = sizeof(struct sockaddr_in6);
1568 dst6->sin6_family = AF_INET6;
1569 dst6->sin6_addr = ip6->ip6_dst;
1571 * We just call if_output instead of nd6_output here, since
1572 * we need no ND for a multicast forwarded packet...right?
1574 error = (*ifp->if_output)(ifp, mb_copy,
1575 (struct sockaddr *)&ro.ro_dst, NULL);
1577 if (mrt6debug & DEBUG_XMIT)
1578 log(LOG_DEBUG, "phyint_send on mif %d err %d\n",
1579 mifp - mif6table, error);
1583 * pMTU discovery is intentionally disabled by default, since
1584 * various router may notify pMTU in multicast, which can be
1585 * a DDoS to a router
1588 icmp6_error(mb_copy, ICMP6_PACKET_TOO_BIG, 0, linkmtu);
1591 if (mrt6debug & DEBUG_XMIT)
1593 "phyint_send: packet too big on %s o %s "
1594 "g %s size %d(discarded)\n",
1596 ip6_sprintf(&ip6->ip6_src),
1597 ip6_sprintf(&ip6->ip6_dst),
1598 mb_copy->m_pkthdr.len);
1599 #endif /* MRT6DEBUG */
1600 m_freem(mb_copy); /* simply discard the packet */
1608 register_send(ip6, mif, m)
1609 struct ip6_hdr *ip6;
1614 int i, len = m->m_pkthdr.len;
1615 static struct sockaddr_in6 sin6 = { sizeof(sin6), AF_INET6 };
1616 struct mrt6msg *im6;
1620 log(LOG_DEBUG, "** IPv6 register_send **\n src %s dst %s\n",
1621 ip6_sprintf(&ip6->ip6_src), ip6_sprintf(&ip6->ip6_dst));
1623 ++pim6stat.pim6s_snd_registers;
1625 /* Make a copy of the packet to send to the user level process */
1626 MGETHDR(mm, M_DONTWAIT, MT_HEADER);
1629 mm->m_pkthdr.rcvif = NULL;
1630 mm->m_data += max_linkhdr;
1631 mm->m_len = sizeof(struct ip6_hdr);
1633 if ((mm->m_next = m_copy(m, 0, M_COPYALL)) == NULL) {
1637 i = MHLEN - M_LEADINGSPACE(mm);
1640 mm = m_pullup(mm, i);
1643 /* TODO: check it! */
1644 mm->m_pkthdr.len = len + sizeof(struct ip6_hdr);
1647 * Send message to routing daemon
1649 sin6.sin6_addr = ip6->ip6_src;
1651 im6 = mtod(mm, struct mrt6msg *);
1652 im6->im6_msgtype = MRT6MSG_WHOLEPKT;
1655 im6->im6_mif = mif - mif6table;
1657 /* iif info is not given for reg. encap.n */
1658 mrt6stat.mrt6s_upcalls++;
1660 if (socket_send(ip6_mrouter, mm, &sin6) < 0) {
1664 "register_send: ip6_mrouter socket queue full\n");
1666 ++mrt6stat.mrt6s_upq_sockfull;
1673 * PIM sparse mode hook
1674 * Receives the pim control messages, and passes them up to the listening
1675 * socket, using rip6_input.
1676 * The only message processed is the REGISTER pim message; the pim header
1677 * is stripped off, and the inner packet is passed to register_mforward.
1680 pim6_input(mp, offp, proto)
1684 struct pim *pim; /* pointer to a pim struct */
1685 struct ip6_hdr *ip6;
1687 struct mbuf *m = *mp;
1691 ++pim6stat.pim6s_rcv_total;
1693 ip6 = mtod(m, struct ip6_hdr *);
1694 pimlen = m->m_pkthdr.len - *offp;
1699 if (pimlen < PIM_MINLEN) {
1700 ++pim6stat.pim6s_rcv_tooshort;
1702 if (mrt6debug & DEBUG_PIM)
1703 log(LOG_DEBUG,"pim6_input: PIM packet too short\n");
1706 return (IPPROTO_DONE);
1710 * if the packet is at least as big as a REGISTER, go ahead
1711 * and grab the PIM REGISTER header size, to avoid another
1712 * possible m_pullup() later.
1714 * PIM_MINLEN == pimhdr + u_int32 == 8
1715 * PIM6_REG_MINLEN == pimhdr + reghdr + eip6hdr == 4 + 4 + 40
1717 minlen = (pimlen >= PIM6_REG_MINLEN) ? PIM6_REG_MINLEN : PIM_MINLEN;
1720 * Make sure that the IP6 and PIM headers in contiguous memory, and
1721 * possibly the PIM REGISTER header
1723 #ifndef PULLDOWN_TEST
1724 IP6_EXTHDR_CHECK(m, off, minlen, IPPROTO_DONE);
1725 /* adjust pointer */
1726 ip6 = mtod(m, struct ip6_hdr *);
1728 /* adjust mbuf to point to the PIM header */
1729 pim = (struct pim *)((caddr_t)ip6 + off);
1731 IP6_EXTHDR_GET(pim, struct pim *, m, off, minlen);
1733 pim6stat.pim6s_rcv_tooshort++;
1734 return (IPPROTO_DONE);
1738 #define PIM6_CHECKSUM
1739 #ifdef PIM6_CHECKSUM
1744 * Validate checksum.
1745 * If PIM REGISTER, exclude the data packet
1747 if (pim->pim_type == PIM_REGISTER)
1748 cksumlen = PIM_MINLEN;
1752 if (in6_cksum(m, IPPROTO_PIM, off, cksumlen)) {
1753 ++pim6stat.pim6s_rcv_badsum;
1755 if (mrt6debug & DEBUG_PIM)
1757 "pim6_input: invalid checksum\n");
1760 return (IPPROTO_DONE);
1763 #endif /* PIM_CHECKSUM */
1765 /* PIM version check */
1766 if (pim->pim_ver != PIM_VERSION) {
1767 ++pim6stat.pim6s_rcv_badversion;
1770 "pim6_input: incorrect version %d, expecting %d\n",
1771 pim->pim_ver, PIM_VERSION);
1774 return (IPPROTO_DONE);
1777 if (pim->pim_type == PIM_REGISTER) {
1779 * since this is a REGISTER, we'll make a copy of the register
1780 * headers ip6+pim+u_int32_t+encap_ip6, to be passed up to the
1783 static struct sockaddr_in6 dst = { sizeof(dst), AF_INET6 };
1786 struct ip6_hdr *eip6;
1790 ++pim6stat.pim6s_rcv_registers;
1792 if ((reg_mif_num >= nummifs) || (reg_mif_num == (mifi_t) -1)) {
1794 if (mrt6debug & DEBUG_PIM)
1796 "pim6_input: register mif not set: %d\n",
1800 return (IPPROTO_DONE);
1803 reghdr = (u_int32_t *)(pim + 1);
1805 if ((ntohl(*reghdr) & PIM_NULL_REGISTER))
1806 goto pim6_input_to_daemon;
1811 if (pimlen < PIM6_REG_MINLEN) {
1812 ++pim6stat.pim6s_rcv_tooshort;
1813 ++pim6stat.pim6s_rcv_badregisters;
1816 "pim6_input: register packet size too "
1817 "small %d from %s\n",
1818 pimlen, ip6_sprintf(&ip6->ip6_src));
1821 return (IPPROTO_DONE);
1824 eip6 = (struct ip6_hdr *) (reghdr + 1);
1826 if (mrt6debug & DEBUG_PIM)
1828 "pim6_input[register], eip6: %s -> %s, "
1830 ip6_sprintf(&eip6->ip6_src),
1831 ip6_sprintf(&eip6->ip6_dst),
1832 ntohs(eip6->ip6_plen));
1835 /* verify the version number of the inner packet */
1836 if ((eip6->ip6_vfc & IPV6_VERSION_MASK) != IPV6_VERSION) {
1837 ++pim6stat.pim6s_rcv_badregisters;
1839 log(LOG_DEBUG, "pim6_input: invalid IP version (%d) "
1840 "of the inner packet\n",
1841 (eip6->ip6_vfc & IPV6_VERSION));
1844 return (IPPROTO_NONE);
1847 /* verify the inner packet is destined to a mcast group */
1848 if (!IN6_IS_ADDR_MULTICAST(&eip6->ip6_dst)) {
1849 ++pim6stat.pim6s_rcv_badregisters;
1851 if (mrt6debug & DEBUG_PIM)
1853 "pim6_input: inner packet of register "
1854 "is not multicast %s\n",
1855 ip6_sprintf(&eip6->ip6_dst));
1858 return (IPPROTO_DONE);
1862 * make a copy of the whole header to pass to the daemon later.
1864 mcp = m_copy(m, 0, off + PIM6_REG_MINLEN);
1868 "pim6_input: pim register: "
1869 "could not copy register head\n");
1872 return (IPPROTO_DONE);
1876 * forward the inner ip6 packet; point m_data at the inner ip6.
1878 m_adj(m, off + PIM_MINLEN);
1880 if (mrt6debug & DEBUG_PIM) {
1882 "pim6_input: forwarding decapsulated register: "
1883 "src %s, dst %s, mif %d\n",
1884 ip6_sprintf(&eip6->ip6_src),
1885 ip6_sprintf(&eip6->ip6_dst),
1890 rc = if_simloop(mif6table[reg_mif_num].m6_ifp, m,
1891 dst.sin6_family, 0);
1893 /* prepare the register head to send to the mrouting daemon */
1898 * Pass the PIM message up to the daemon; if it is a register message
1899 * pass the 'head' only up to the daemon. This includes the
1900 * encapsulator ip6 header, pim header, register header and the
1901 * encapsulated ip6 header.
1903 pim6_input_to_daemon:
1904 rip6_input(&m, offp, proto);
1905 return (IPPROTO_DONE);