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/raw_cb.h>
105 #include <net/route.h>
107 #include <netinet/in.h>
108 #include <netinet/in_var.h>
109 #include <netinet/icmp6.h>
111 #include <netinet/ip6.h>
112 #include <netinet6/ip6_var.h>
113 #include <netinet6/scope6_var.h>
114 #include <netinet6/nd6.h>
115 #include <netinet6/ip6_mroute.h>
116 #include <netinet6/pim6.h>
117 #include <netinet6/pim6_var.h>
119 #include <net/net_osdep.h>
121 static MALLOC_DEFINE(M_MRTABLE6, "mf6c", "multicast forwarding cache entry");
123 #define M_HASCL(m) ((m)->m_flags & M_EXT)
125 static int ip6_mdq __P((struct mbuf *, struct ifnet *, struct mf6c *));
126 static void phyint_send __P((struct ip6_hdr *, struct mif6 *, struct mbuf *));
128 static int set_pim6 __P((int *));
129 static int socket_send __P((struct socket *, struct mbuf *,
130 struct sockaddr_in6 *));
131 static int register_send __P((struct ip6_hdr *, struct mif6 *,
135 * Globals. All but ip6_mrouter, ip6_mrtproto and mrt6stat could be static,
136 * except for netstat or debugging purposes.
138 struct socket *ip6_mrouter = NULL;
139 int ip6_mrouter_ver = 0;
140 int ip6_mrtproto = IPPROTO_PIM; /* for netstat only */
141 struct mrt6stat mrt6stat;
143 #define NO_RTE_FOUND 0x1
144 #define RTE_FOUND 0x2
146 struct mf6c *mf6ctable[MF6CTBLSIZ];
147 u_char n6expire[MF6CTBLSIZ];
148 static struct mif6 mif6table[MAXMIFS];
150 u_int mrt6debug = 0; /* debug level */
151 #define DEBUG_MFC 0x02
152 #define DEBUG_FORWARD 0x04
153 #define DEBUG_EXPIRE 0x08
154 #define DEBUG_XMIT 0x10
155 #define DEBUG_REG 0x20
156 #define DEBUG_PIM 0x40
159 static void expire_upcalls __P((void *));
160 #define EXPIRE_TIMEOUT (hz / 4) /* 4x / second */
161 #define UPCALL_EXPIRE 6 /* number of timeouts */
165 extern struct socket *ip_mrouter;
170 * 'Interfaces' associated with decapsulator (so we can tell
171 * packets that went through it from ones that get reflected
172 * by a broken gateway). These interfaces are never linked into
173 * the system ifnet list & no routes point to them. I.e., packets
174 * can't be sent this way. They only exist as a placeholder for
175 * multicast source verification.
177 struct ifnet multicast_register_if;
179 #define ENCAP_HOPS 64
184 static mifi_t nummifs = 0;
185 static mifi_t reg_mif_num = (mifi_t)-1;
187 static struct pim6stat pim6stat;
191 * Hash function for a source, group entry
193 #define MF6CHASH(a, g) MF6CHASHMOD((a).s6_addr32[0] ^ (a).s6_addr32[1] ^ \
194 (a).s6_addr32[2] ^ (a).s6_addr32[3] ^ \
195 (g).s6_addr32[0] ^ (g).s6_addr32[1] ^ \
196 (g).s6_addr32[2] ^ (g).s6_addr32[3])
199 * Find a route for a given origin IPv6 address and Multicast group address.
200 * Quality of service parameter to be added in the future!!!
203 #define MF6CFIND(o, g, rt) do { \
204 struct mf6c *_rt = mf6ctable[MF6CHASH(o,g)]; \
206 mrt6stat.mrt6s_mfc_lookups++; \
208 if (IN6_ARE_ADDR_EQUAL(&_rt->mf6c_origin.sin6_addr, &(o)) && \
209 IN6_ARE_ADDR_EQUAL(&_rt->mf6c_mcastgrp.sin6_addr, &(g)) && \
210 (_rt->mf6c_stall == NULL)) { \
214 _rt = _rt->mf6c_next; \
217 mrt6stat.mrt6s_mfc_misses++; \
219 } while (/*CONSTCOND*/ 0)
222 * Macros to compute elapsed time efficiently
223 * Borrowed from Van Jacobson's scheduling code
225 #define TV_DELTA(a, b, delta) do { \
228 delta = (a).tv_usec - (b).tv_usec; \
229 if ((xxs = (a).tv_sec - (b).tv_sec)) { \
238 delta += (1000000 * xxs); \
241 } while (/*CONSTCOND*/ 0)
243 #define TV_LT(a, b) (((a).tv_usec < (b).tv_usec && \
244 (a).tv_sec <= (b).tv_sec) || (a).tv_sec < (b).tv_sec)
247 #define UPCALL_MAX 50
248 u_long upcall_data[UPCALL_MAX + 1];
249 static void collate();
250 #endif /* UPCALL_TIMING */
252 static int get_sg_cnt __P((struct sioc_sg_req6 *));
253 static int get_mif6_cnt __P((struct sioc_mif_req6 *));
254 static int ip6_mrouter_init __P((struct socket *, int, int));
255 static int add_m6if __P((struct mif6ctl *));
256 static int del_m6if __P((mifi_t *));
257 static int add_m6fc __P((struct mf6cctl *));
258 static int del_m6fc __P((struct mf6cctl *));
260 static struct callout expire_upcalls_ch;
263 * Handle MRT setsockopt commands to modify the multicast routing tables.
266 ip6_mrouter_set(so, sopt)
268 struct sockopt *sopt;
276 if (so != ip6_mrouter && sopt->sopt_name != MRT6_INIT)
279 switch (sopt->sopt_name) {
284 error = sooptcopyin(sopt, &optval, sizeof(optval),
288 error = ip6_mrouter_init(so, optval, sopt->sopt_name);
291 error = ip6_mrouter_done();
294 error = sooptcopyin(sopt, &mifc, sizeof(mifc), sizeof(mifc));
297 error = add_m6if(&mifc);
300 error = sooptcopyin(sopt, &mfcc, sizeof(mfcc), sizeof(mfcc));
303 error = add_m6fc(&mfcc);
306 error = sooptcopyin(sopt, &mfcc, sizeof(mfcc), sizeof(mfcc));
309 error = del_m6fc(&mfcc);
312 error = sooptcopyin(sopt, &mifi, sizeof(mifi), sizeof(mifi));
315 error = del_m6if(&mifi);
318 error = sooptcopyin(sopt, &optval, sizeof(optval),
322 error = set_pim6(&optval);
333 * Handle MRT getsockopt commands
336 ip6_mrouter_get(so, sopt)
338 struct sockopt *sopt;
342 if (so != ip6_mrouter)
345 switch (sopt->sopt_name) {
347 error = sooptcopyout(sopt, &pim6, sizeof(pim6));
354 * Handle ioctl commands to obtain information from the cache
357 mrt6_ioctl(cmd, data)
362 case SIOCGETSGCNT_IN6:
363 return (get_sg_cnt((struct sioc_sg_req6 *)data));
364 case SIOCGETMIFCNT_IN6:
365 return (get_mif6_cnt((struct sioc_mif_req6 *)data));
372 * returns the packet, byte, rpf-failure count for the source group provided
376 struct sioc_sg_req6 *req;
382 MF6CFIND(req->src.sin6_addr, req->grp.sin6_addr, rt);
385 req->pktcnt = rt->mf6c_pkt_cnt;
386 req->bytecnt = rt->mf6c_byte_cnt;
387 req->wrong_if = rt->mf6c_wrong_if;
391 req->pktcnt = req->bytecnt = req->wrong_if = 0xffffffff;
398 * returns the input and output packet and byte counts on the mif provided
402 struct sioc_mif_req6 *req;
404 mifi_t mifi = req->mifi;
409 req->icount = mif6table[mifi].m6_pkt_in;
410 req->ocount = mif6table[mifi].m6_pkt_out;
411 req->ibytes = mif6table[mifi].m6_bytes_in;
412 req->obytes = mif6table[mifi].m6_bytes_out;
421 if ((*i != 1) && (*i != 0))
430 * Enable multicast routing
433 ip6_mrouter_init(so, v, cmd)
441 "ip6_mrouter_init: so_type = %d, pr_protocol = %d\n",
442 so->so_type, so->so_proto->pr_protocol);
445 if (so->so_type != SOCK_RAW ||
446 so->so_proto->pr_protocol != IPPROTO_ICMPV6)
450 return (ENOPROTOOPT);
452 if (ip6_mrouter != NULL)
456 ip6_mrouter_ver = cmd;
458 bzero((caddr_t)mf6ctable, sizeof(mf6ctable));
459 bzero((caddr_t)n6expire, sizeof(n6expire));
461 pim6 = 0;/* used for stubbing out/in pim stuff */
463 callout_init(&expire_upcalls_ch, 0);
464 callout_reset(&expire_upcalls_ch, EXPIRE_TIMEOUT,
465 expire_upcalls, NULL);
469 log(LOG_DEBUG, "ip6_mrouter_init\n");
476 * Disable multicast routing
484 struct in6_ifreq ifr;
492 * For each phyint in use, disable promiscuous reception of all IPv6
498 * If there is still IPv4 multicast routing daemon,
499 * we remain interfaces to receive all muliticasted packets.
500 * XXX: there may be an interface in which the IPv4 multicast
501 * daemon is not interested...
507 for (mifi = 0; mifi < nummifs; mifi++) {
508 if (mif6table[mifi].m6_ifp &&
509 !(mif6table[mifi].m6_flags & MIFF_REGISTER)) {
510 ifr.ifr_addr.sin6_family = AF_INET6;
511 ifr.ifr_addr.sin6_addr = in6addr_any;
512 ifp = mif6table[mifi].m6_ifp;
513 (*ifp->if_ioctl)(ifp, SIOCDELMULTI,
519 bzero((caddr_t)qtable, sizeof(qtable));
520 bzero((caddr_t)tbftable, sizeof(tbftable));
522 bzero((caddr_t)mif6table, sizeof(mif6table));
525 pim6 = 0; /* used to stub out/in pim specific code */
527 callout_stop(&expire_upcalls_ch);
530 * Free all multicast forwarding cache entries.
532 for (i = 0; i < MF6CTBLSIZ; i++) {
537 for (rte = rt->mf6c_stall; rte != NULL; ) {
538 struct rtdetq *n = rte->next;
541 free(rte, M_MRTABLE6);
546 free(frt, M_MRTABLE6);
550 bzero((caddr_t)mf6ctable, sizeof(mf6ctable));
553 * Reset de-encapsulation cache
564 log(LOG_DEBUG, "ip6_mrouter_done\n");
570 static struct sockaddr_in6 sin6 = { sizeof(sin6), AF_INET6 };
573 * Add a mif to the mif table
577 struct mif6ctl *mifcp;
583 struct tbf *m_tbf = tbftable + mifcp->mif6c_mifi;
586 if (mifcp->mif6c_mifi >= MAXMIFS)
588 mifp = mif6table + mifcp->mif6c_mifi;
590 return (EADDRINUSE); /* XXX: is it appropriate? */
591 if (mifcp->mif6c_pifi == 0 || mifcp->mif6c_pifi > if_index)
593 ifp = ifnet_byindex(mifcp->mif6c_pifi);
595 if (mifcp->mif6c_flags & MIFF_REGISTER) {
596 if (reg_mif_num == (mifi_t)-1) {
597 strlcpy(multicast_register_if.if_xname, "register_mif",
599 multicast_register_if.if_flags |= IFF_LOOPBACK;
600 multicast_register_if.if_index = mifcp->mif6c_mifi;
601 reg_mif_num = mifcp->mif6c_mifi;
604 ifp = &multicast_register_if;
608 /* Make sure the interface supports multicast */
609 if ((ifp->if_flags & IFF_MULTICAST) == 0)
613 error = if_allmulti(ifp, 1);
620 mifp->m6_flags = mifcp->mif6c_flags;
623 /* scaling up here allows division by 1024 in critical code */
624 mifp->m6_rate_limit = mifcp->mif6c_rate_limit * 1024 / 1000;
626 /* initialize per mif pkt counters */
628 mifp->m6_pkt_out = 0;
629 mifp->m6_bytes_in = 0;
630 mifp->m6_bytes_out = 0;
633 /* Adjust nummifs up if the mifi is higher than nummifs */
634 if (nummifs <= mifcp->mif6c_mifi)
635 nummifs = mifcp->mif6c_mifi + 1;
640 "add_mif #%d, phyint %s\n",
649 * Delete a mif from the mif table
655 struct mif6 *mifp = mif6table + *mifip;
660 if (*mifip >= nummifs)
662 if (mifp->m6_ifp == NULL)
667 if (!(mifp->m6_flags & MIFF_REGISTER)) {
669 * XXX: what if there is yet IPv4 multicast daemon
670 * using the interface?
678 bzero((caddr_t)qtable[*mifip], sizeof(qtable[*mifip]));
679 bzero((caddr_t)mifp->m6_tbf, sizeof(*(mifp->m6_tbf)));
681 bzero((caddr_t)mifp, sizeof(*mifp));
683 /* Adjust nummifs down */
684 for (mifi = nummifs; mifi > 0; mifi--)
685 if (mif6table[mifi - 1].m6_ifp)
693 log(LOG_DEBUG, "del_m6if %d, nummifs %d\n", *mifip, nummifs);
704 struct mf6cctl *mfccp;
712 MF6CFIND(mfccp->mf6cc_origin.sin6_addr,
713 mfccp->mf6cc_mcastgrp.sin6_addr, rt);
715 /* If an entry already exists, just update the fields */
718 if (mrt6debug & DEBUG_MFC)
720 "add_m6fc no upcall h %d o %s g %s p %x\n",
721 ip6_sprintf(&mfccp->mf6cc_origin.sin6_addr),
722 ip6_sprintf(&mfccp->mf6cc_mcastgrp.sin6_addr),
723 mfccp->mf6cc_parent);
727 rt->mf6c_parent = mfccp->mf6cc_parent;
728 rt->mf6c_ifset = mfccp->mf6cc_ifset;
734 * Find the entry for which the upcall was made and update
737 hash = MF6CHASH(mfccp->mf6cc_origin.sin6_addr,
738 mfccp->mf6cc_mcastgrp.sin6_addr);
739 for (rt = mf6ctable[hash], nstl = 0; rt; rt = rt->mf6c_next) {
740 if (IN6_ARE_ADDR_EQUAL(&rt->mf6c_origin.sin6_addr,
741 &mfccp->mf6cc_origin.sin6_addr) &&
742 IN6_ARE_ADDR_EQUAL(&rt->mf6c_mcastgrp.sin6_addr,
743 &mfccp->mf6cc_mcastgrp.sin6_addr) &&
744 (rt->mf6c_stall != NULL)) {
748 "add_m6fc: %s o %s g %s p %x dbx %p\n",
749 "multiple kernel entries",
750 ip6_sprintf(&mfccp->mf6cc_origin.sin6_addr),
751 ip6_sprintf(&mfccp->mf6cc_mcastgrp.sin6_addr),
752 mfccp->mf6cc_parent, rt->mf6c_stall);
755 if (mrt6debug & DEBUG_MFC)
757 "add_m6fc o %s g %s p %x dbg %x\n",
758 ip6_sprintf(&mfccp->mf6cc_origin.sin6_addr),
759 ip6_sprintf(&mfccp->mf6cc_mcastgrp.sin6_addr),
760 mfccp->mf6cc_parent, rt->mf6c_stall);
763 rt->mf6c_origin = mfccp->mf6cc_origin;
764 rt->mf6c_mcastgrp = mfccp->mf6cc_mcastgrp;
765 rt->mf6c_parent = mfccp->mf6cc_parent;
766 rt->mf6c_ifset = mfccp->mf6cc_ifset;
767 /* initialize pkt counters per src-grp */
768 rt->mf6c_pkt_cnt = 0;
769 rt->mf6c_byte_cnt = 0;
770 rt->mf6c_wrong_if = 0;
772 rt->mf6c_expire = 0; /* Don't clean this guy up */
775 /* free packets Qed at the end of this entry */
776 for (rte = rt->mf6c_stall; rte != NULL; ) {
777 struct rtdetq *n = rte->next;
778 ip6_mdq(rte->m, rte->ifp, rt);
782 #endif /* UPCALL_TIMING */
783 free(rte, M_MRTABLE6);
786 rt->mf6c_stall = NULL;
791 * It is possible that an entry is being inserted without an upcall
795 if (mrt6debug & DEBUG_MFC)
797 "add_mfc no upcall h %d o %s g %s p %x\n",
799 ip6_sprintf(&mfccp->mf6cc_origin.sin6_addr),
800 ip6_sprintf(&mfccp->mf6cc_mcastgrp.sin6_addr),
801 mfccp->mf6cc_parent);
804 for (rt = mf6ctable[hash]; rt; rt = rt->mf6c_next) {
806 if (IN6_ARE_ADDR_EQUAL(&rt->mf6c_origin.sin6_addr,
807 &mfccp->mf6cc_origin.sin6_addr)&&
808 IN6_ARE_ADDR_EQUAL(&rt->mf6c_mcastgrp.sin6_addr,
809 &mfccp->mf6cc_mcastgrp.sin6_addr)) {
811 rt->mf6c_origin = mfccp->mf6cc_origin;
812 rt->mf6c_mcastgrp = mfccp->mf6cc_mcastgrp;
813 rt->mf6c_parent = mfccp->mf6cc_parent;
814 rt->mf6c_ifset = mfccp->mf6cc_ifset;
815 /* initialize pkt counters per src-grp */
816 rt->mf6c_pkt_cnt = 0;
817 rt->mf6c_byte_cnt = 0;
818 rt->mf6c_wrong_if = 0;
826 /* no upcall, so make a new entry */
827 rt = (struct mf6c *)malloc(sizeof(*rt), M_MRTABLE6,
834 /* insert new entry at head of hash chain */
835 rt->mf6c_origin = mfccp->mf6cc_origin;
836 rt->mf6c_mcastgrp = mfccp->mf6cc_mcastgrp;
837 rt->mf6c_parent = mfccp->mf6cc_parent;
838 rt->mf6c_ifset = mfccp->mf6cc_ifset;
839 /* initialize pkt counters per src-grp */
840 rt->mf6c_pkt_cnt = 0;
841 rt->mf6c_byte_cnt = 0;
842 rt->mf6c_wrong_if = 0;
844 rt->mf6c_stall = NULL;
846 /* link into table */
847 rt->mf6c_next = mf6ctable[hash];
848 mf6ctable[hash] = rt;
857 * collect delay statistics on the upcalls
871 TV_DELTA(tp, *t, delta);
880 #endif /* UPCALL_TIMING */
883 * Delete an mfc entry
887 struct mf6cctl *mfccp;
889 struct sockaddr_in6 origin;
890 struct sockaddr_in6 mcastgrp;
896 origin = mfccp->mf6cc_origin;
897 mcastgrp = mfccp->mf6cc_mcastgrp;
898 hash = MF6CHASH(origin.sin6_addr, mcastgrp.sin6_addr);
901 if (mrt6debug & DEBUG_MFC)
902 log(LOG_DEBUG,"del_m6fc orig %s mcastgrp %s\n",
903 ip6_sprintf(&origin.sin6_addr),
904 ip6_sprintf(&mcastgrp.sin6_addr));
909 nptr = &mf6ctable[hash];
910 while ((rt = *nptr) != NULL) {
911 if (IN6_ARE_ADDR_EQUAL(&origin.sin6_addr,
912 &rt->mf6c_origin.sin6_addr) &&
913 IN6_ARE_ADDR_EQUAL(&mcastgrp.sin6_addr,
914 &rt->mf6c_mcastgrp.sin6_addr) &&
915 rt->mf6c_stall == NULL)
918 nptr = &rt->mf6c_next;
922 return (EADDRNOTAVAIL);
925 *nptr = rt->mf6c_next;
926 free(rt, M_MRTABLE6);
934 socket_send(s, mm, src)
937 struct sockaddr_in6 *src;
940 if (sbappendaddr(&s->so_rcv,
941 (struct sockaddr *)src,
942 mm, (struct mbuf *)0) != 0) {
952 * IPv6 multicast forwarding function. This function assumes that the packet
953 * pointed to by "ip6" has arrived on (or is about to be sent to) the interface
954 * pointed to by "ifp", and the packet is to be relayed to other networks
955 * that have members of the packet's destination IPv6 multicast group.
957 * The packet is returned unscathed to the caller, unless it is
958 * erroneous, in which case a non-zero return value tells the caller to
963 ip6_mforward(ip6, ifp, m)
975 if (mrt6debug & DEBUG_FORWARD)
976 log(LOG_DEBUG, "ip6_mforward: src %s, dst %s, ifindex %d\n",
977 ip6_sprintf(&ip6->ip6_src), ip6_sprintf(&ip6->ip6_dst),
982 * Don't forward a packet with Hop limit of zero or one,
983 * or a packet destined to a local-only group.
985 if (ip6->ip6_hlim <= 1 || IN6_IS_ADDR_MC_INTFACELOCAL(&ip6->ip6_dst) ||
986 IN6_IS_ADDR_MC_LINKLOCAL(&ip6->ip6_dst))
991 * Source address check: do not forward packets with unspecified
992 * source. It was discussed in July 2000, on ipngwg mailing list.
993 * This is rather more serious than unicast cases, because some
994 * MLD packets can be sent with the unspecified source address
995 * (although such packets must normally set 1 to the hop limit field).
997 if (IN6_IS_ADDR_UNSPECIFIED(&ip6->ip6_src)) {
998 ip6stat.ip6s_cantforward++;
999 if (ip6_log_time + ip6_log_interval < time_second) {
1000 ip6_log_time = time_second;
1003 "from %s to %s nxt %d received on %s\n",
1004 ip6_sprintf(&ip6->ip6_src),
1005 ip6_sprintf(&ip6->ip6_dst),
1007 if_name(m->m_pkthdr.rcvif));
1013 * Determine forwarding mifs from the forwarding cache table
1016 MF6CFIND(ip6->ip6_src, ip6->ip6_dst, rt);
1018 /* Entry exists, so forward if necessary */
1021 return (ip6_mdq(m, ifp, rt));
1024 * If we don't have a route for packet's origin,
1025 * Make a copy of the packet &
1026 * send message to routing daemon
1033 #ifdef UPCALL_TIMING
1037 #endif /* UPCALL_TIMING */
1039 mrt6stat.mrt6s_no_route++;
1041 if (mrt6debug & (DEBUG_FORWARD | DEBUG_MFC))
1042 log(LOG_DEBUG, "ip6_mforward: no rte s %s g %s\n",
1043 ip6_sprintf(&ip6->ip6_src),
1044 ip6_sprintf(&ip6->ip6_dst));
1048 * Allocate mbufs early so that we don't do extra work if we
1049 * are just going to fail anyway.
1051 rte = (struct rtdetq *)malloc(sizeof(*rte), M_MRTABLE6,
1057 mb0 = m_copy(m, 0, M_COPYALL);
1059 * Pullup packet header if needed before storing it,
1060 * as other references may modify it in the meantime.
1063 (M_HASCL(mb0) || mb0->m_len < sizeof(struct ip6_hdr)))
1064 mb0 = m_pullup(mb0, sizeof(struct ip6_hdr));
1066 free(rte, M_MRTABLE6);
1071 /* is there an upcall waiting for this packet? */
1072 hash = MF6CHASH(ip6->ip6_src, ip6->ip6_dst);
1073 for (rt = mf6ctable[hash]; rt; rt = rt->mf6c_next) {
1074 if (IN6_ARE_ADDR_EQUAL(&ip6->ip6_src,
1075 &rt->mf6c_origin.sin6_addr) &&
1076 IN6_ARE_ADDR_EQUAL(&ip6->ip6_dst,
1077 &rt->mf6c_mcastgrp.sin6_addr) &&
1078 (rt->mf6c_stall != NULL))
1085 struct omrt6msg *oim;
1088 /* no upcall, so make a new entry */
1089 rt = (struct mf6c *)malloc(sizeof(*rt), M_MRTABLE6,
1092 free(rte, M_MRTABLE6);
1098 * Make a copy of the header to send to the user
1101 mm = m_copy(mb0, 0, sizeof(struct ip6_hdr));
1104 free(rte, M_MRTABLE6);
1106 free(rt, M_MRTABLE6);
1112 * Send message to routing daemon
1114 sin6.sin6_addr = ip6->ip6_src;
1120 switch (ip6_mrouter_ver) {
1123 oim = mtod(mm, struct omrt6msg *);
1124 oim->im6_msgtype = MRT6MSG_NOCACHE;
1129 im = mtod(mm, struct mrt6msg *);
1130 im->im6_msgtype = MRT6MSG_NOCACHE;
1134 free(rte, M_MRTABLE6);
1136 free(rt, M_MRTABLE6);
1142 if (mrt6debug & DEBUG_FORWARD)
1144 "getting the iif info in the kernel\n");
1147 for (mifp = mif6table, mifi = 0;
1148 mifi < nummifs && mifp->m6_ifp != ifp;
1152 switch (ip6_mrouter_ver) {
1155 oim->im6_mif = mifi;
1163 if (socket_send(ip6_mrouter, mm, &sin6) < 0) {
1164 log(LOG_WARNING, "ip6_mforward: ip6_mrouter "
1165 "socket queue full\n");
1166 mrt6stat.mrt6s_upq_sockfull++;
1167 free(rte, M_MRTABLE6);
1169 free(rt, M_MRTABLE6);
1174 mrt6stat.mrt6s_upcalls++;
1176 /* insert new entry at head of hash chain */
1177 bzero(rt, sizeof(*rt));
1178 rt->mf6c_origin.sin6_family = AF_INET6;
1179 rt->mf6c_origin.sin6_len = sizeof(struct sockaddr_in6);
1180 rt->mf6c_origin.sin6_addr = ip6->ip6_src;
1181 rt->mf6c_mcastgrp.sin6_family = AF_INET6;
1182 rt->mf6c_mcastgrp.sin6_len = sizeof(struct sockaddr_in6);
1183 rt->mf6c_mcastgrp.sin6_addr = ip6->ip6_dst;
1184 rt->mf6c_expire = UPCALL_EXPIRE;
1186 rt->mf6c_parent = MF6C_INCOMPLETE_PARENT;
1188 /* link into table */
1189 rt->mf6c_next = mf6ctable[hash];
1190 mf6ctable[hash] = rt;
1191 /* Add this entry to the end of the queue */
1192 rt->mf6c_stall = rte;
1194 /* determine if q has overflowed */
1198 for (p = &rt->mf6c_stall; *p != NULL; p = &(*p)->next)
1199 if (++npkts > MAX_UPQ6) {
1200 mrt6stat.mrt6s_upq_ovflw++;
1201 free(rte, M_MRTABLE6);
1207 /* Add this entry to the end of the queue */
1214 #ifdef UPCALL_TIMING
1216 #endif /* UPCALL_TIMING */
1225 * Clean up cache entries if upcalls are not serviced
1226 * Call from the Slow Timeout mechanism, every half second.
1229 expire_upcalls(unused)
1233 struct mf6c *mfc, **nptr;
1238 for (i = 0; i < MF6CTBLSIZ; i++) {
1239 if (n6expire[i] == 0)
1241 nptr = &mf6ctable[i];
1242 while ((mfc = *nptr) != NULL) {
1243 rte = mfc->mf6c_stall;
1245 * Skip real cache entries
1246 * Make sure it wasn't marked to not expire (shouldn't happen)
1250 mfc->mf6c_expire != 0 &&
1251 --mfc->mf6c_expire == 0) {
1253 if (mrt6debug & DEBUG_EXPIRE)
1254 log(LOG_DEBUG, "expire_upcalls: expiring (%s %s)\n",
1255 ip6_sprintf(&mfc->mf6c_origin.sin6_addr),
1256 ip6_sprintf(&mfc->mf6c_mcastgrp.sin6_addr));
1259 * drop all the packets
1260 * free the mbuf with the pkt, if, timing info
1263 struct rtdetq *n = rte->next;
1265 free(rte, M_MRTABLE6);
1267 } while (rte != NULL);
1268 mrt6stat.mrt6s_cache_cleanups++;
1271 *nptr = mfc->mf6c_next;
1272 free(mfc, M_MRTABLE6);
1274 nptr = &mfc->mf6c_next;
1279 callout_reset(&expire_upcalls_ch, EXPIRE_TIMEOUT,
1280 expire_upcalls, NULL);
1284 * Packet forwarding routine once entry in the cache is made
1292 struct ip6_hdr *ip6 = mtod(m, struct ip6_hdr *);
1295 int plen = m->m_pkthdr.len;
1296 struct in6_addr src0, dst0; /* copies for local work */
1297 u_int32_t iszone, idzone, oszone, odzone;
1301 * Macro to send packet on mif. Since RSVP packets don't get counted on
1302 * input, they shouldn't get counted on output, so statistics keeping is
1306 #define MC6_SEND(ip6, mifp, m) do { \
1307 if ((mifp)->m6_flags & MIFF_REGISTER) \
1308 register_send((ip6), (mifp), (m)); \
1310 phyint_send((ip6), (mifp), (m)); \
1311 } while (/*CONSTCOND*/ 0)
1314 * Don't forward if it didn't arrive from the parent mif
1317 mifi = rt->mf6c_parent;
1318 if ((mifi >= nummifs) || (mif6table[mifi].m6_ifp != ifp)) {
1319 /* came in the wrong interface */
1321 if (mrt6debug & DEBUG_FORWARD)
1323 "wrong if: ifid %d mifi %d mififid %x\n",
1324 ifp->if_index, mifi,
1325 mif6table[mifi].m6_ifp->if_index);
1327 mrt6stat.mrt6s_wrong_if++;
1328 rt->mf6c_wrong_if++;
1330 * If we are doing PIM processing, and we are forwarding
1331 * packets on this interface, send a message to the
1334 /* have to make sure this is a valid mif */
1335 if (mifi < nummifs && mif6table[mifi].m6_ifp)
1336 if (pim6 && (m->m_flags & M_LOOP) == 0) {
1338 * Check the M_LOOP flag to avoid an
1339 * unnecessary PIM assert.
1340 * XXX: M_LOOP is an ad-hoc hack...
1342 static struct sockaddr_in6 sin6 =
1343 { sizeof(sin6), AF_INET6 };
1348 struct omrt6msg *oim;
1351 mm = m_copy(m, 0, sizeof(struct ip6_hdr));
1354 mm->m_len < sizeof(struct ip6_hdr)))
1355 mm = m_pullup(mm, sizeof(struct ip6_hdr));
1363 switch (ip6_mrouter_ver) {
1366 oim = mtod(mm, struct omrt6msg *);
1367 oim->im6_msgtype = MRT6MSG_WRONGMIF;
1372 im = mtod(mm, struct mrt6msg *);
1373 im->im6_msgtype = MRT6MSG_WRONGMIF;
1381 for (mifp = mif6table, iif = 0;
1382 iif < nummifs && mifp &&
1383 mifp->m6_ifp != ifp;
1387 switch (ip6_mrouter_ver) {
1391 sin6.sin6_addr = oim->im6_src;
1396 sin6.sin6_addr = im->im6_src;
1400 mrt6stat.mrt6s_upcalls++;
1402 if (socket_send(ip6_mrouter, mm, &sin6) < 0) {
1405 log(LOG_WARNING, "mdq, ip6_mrouter socket queue full\n");
1407 ++mrt6stat.mrt6s_upq_sockfull;
1409 } /* if socket Q full */
1412 } /* if wrong iif */
1414 /* If I sourced this packet, it counts as output, else it was input. */
1415 if (m->m_pkthdr.rcvif == NULL) {
1416 /* XXX: is rcvif really NULL when output?? */
1417 mif6table[mifi].m6_pkt_out++;
1418 mif6table[mifi].m6_bytes_out += plen;
1420 mif6table[mifi].m6_pkt_in++;
1421 mif6table[mifi].m6_bytes_in += plen;
1424 rt->mf6c_byte_cnt += plen;
1427 * For each mif, forward a copy of the packet if there are group
1428 * members downstream on the interface.
1430 src0 = ip6->ip6_src;
1431 dst0 = ip6->ip6_dst;
1432 if ((error = in6_setscope(&src0, ifp, &iszone)) != 0 ||
1433 (error = in6_setscope(&dst0, ifp, &idzone)) != 0) {
1434 ip6stat.ip6s_badscope++;
1437 for (mifp = mif6table, mifi = 0; mifi < nummifs; mifp++, mifi++) {
1438 if (IF_ISSET(mifi, &rt->mf6c_ifset)) {
1440 * check if the outgoing packet is going to break
1442 * XXX For packets through PIM register tunnel
1443 * interface, we believe a routing daemon.
1445 if (!(mif6table[rt->mf6c_parent].m6_flags &
1447 !(mif6table[mifi].m6_flags & MIFF_REGISTER)) {
1448 if (in6_setscope(&src0, mif6table[mifi].m6_ifp,
1450 in6_setscope(&dst0, mif6table[mifi].m6_ifp,
1454 ip6stat.ip6s_badscope++;
1460 mifp->m6_bytes_out += plen;
1461 MC6_SEND(ip6, mifp, m);
1468 phyint_send(ip6, mifp, m)
1469 struct ip6_hdr *ip6;
1473 struct mbuf *mb_copy;
1474 struct ifnet *ifp = mifp->m6_ifp;
1476 int s = splnet(); /* needs to protect static "ro" below. */
1477 static struct route_in6 ro;
1478 struct in6_multi *in6m;
1479 struct sockaddr_in6 *dst6;
1483 * Make a new reference to the packet; make sure that
1484 * the IPv6 header is actually copied, not just referenced,
1485 * so that ip6_output() only scribbles on the copy.
1487 mb_copy = m_copy(m, 0, M_COPYALL);
1489 (M_HASCL(mb_copy) || mb_copy->m_len < sizeof(struct ip6_hdr)))
1490 mb_copy = m_pullup(mb_copy, sizeof(struct ip6_hdr));
1491 if (mb_copy == NULL) {
1495 /* set MCAST flag to the outgoing packet */
1496 mb_copy->m_flags |= M_MCAST;
1499 * If we sourced the packet, call ip6_output since we may devide
1500 * the packet into fragments when the packet is too big for the
1501 * outgoing interface.
1502 * Otherwise, we can simply send the packet to the interface
1505 if (m->m_pkthdr.rcvif == NULL) {
1506 struct ip6_moptions im6o;
1508 im6o.im6o_multicast_ifp = ifp;
1509 /* XXX: ip6_output will override ip6->ip6_hlim */
1510 im6o.im6o_multicast_hlim = ip6->ip6_hlim;
1511 im6o.im6o_multicast_loop = 1;
1512 error = ip6_output(mb_copy, NULL, &ro,
1513 IPV6_FORWARDING, &im6o, NULL, NULL);
1516 if (mrt6debug & DEBUG_XMIT)
1517 log(LOG_DEBUG, "phyint_send on mif %d err %d\n",
1518 mifp - mif6table, error);
1525 * If we belong to the destination multicast group
1526 * on the outgoing interface, loop back a copy.
1528 dst6 = (struct sockaddr_in6 *)&ro.ro_dst;
1529 IN6_LOOKUP_MULTI(ip6->ip6_dst, ifp, in6m);
1531 dst6->sin6_len = sizeof(struct sockaddr_in6);
1532 dst6->sin6_family = AF_INET6;
1533 dst6->sin6_addr = ip6->ip6_dst;
1534 ip6_mloopback(ifp, m, (struct sockaddr_in6 *)&ro.ro_dst);
1537 * Put the packet into the sending queue of the outgoing interface
1538 * if it would fit in the MTU of the interface.
1540 linkmtu = IN6_LINKMTU(ifp);
1541 if (mb_copy->m_pkthdr.len <= linkmtu || linkmtu < IPV6_MMTU) {
1542 dst6->sin6_len = sizeof(struct sockaddr_in6);
1543 dst6->sin6_family = AF_INET6;
1544 dst6->sin6_addr = ip6->ip6_dst;
1546 * We just call if_output instead of nd6_output here, since
1547 * we need no ND for a multicast forwarded packet...right?
1549 error = (*ifp->if_output)(ifp, mb_copy,
1550 (struct sockaddr *)&ro.ro_dst, NULL);
1552 if (mrt6debug & DEBUG_XMIT)
1553 log(LOG_DEBUG, "phyint_send on mif %d err %d\n",
1554 mifp - mif6table, error);
1558 * pMTU discovery is intentionally disabled by default, since
1559 * various router may notify pMTU in multicast, which can be
1560 * a DDoS to a router
1563 icmp6_error(mb_copy, ICMP6_PACKET_TOO_BIG, 0, linkmtu);
1566 if (mrt6debug & DEBUG_XMIT)
1568 "phyint_send: packet too big on %s o %s "
1569 "g %s size %d(discarded)\n",
1571 ip6_sprintf(&ip6->ip6_src),
1572 ip6_sprintf(&ip6->ip6_dst),
1573 mb_copy->m_pkthdr.len);
1574 #endif /* MRT6DEBUG */
1575 m_freem(mb_copy); /* simply discard the packet */
1583 register_send(ip6, mif, m)
1584 struct ip6_hdr *ip6;
1589 int i, len = m->m_pkthdr.len;
1590 static struct sockaddr_in6 sin6 = { sizeof(sin6), AF_INET6 };
1591 struct mrt6msg *im6;
1595 log(LOG_DEBUG, "** IPv6 register_send **\n src %s dst %s\n",
1596 ip6_sprintf(&ip6->ip6_src), ip6_sprintf(&ip6->ip6_dst));
1598 ++pim6stat.pim6s_snd_registers;
1600 /* Make a copy of the packet to send to the user level process */
1601 MGETHDR(mm, M_DONTWAIT, MT_HEADER);
1604 mm->m_pkthdr.rcvif = NULL;
1605 mm->m_data += max_linkhdr;
1606 mm->m_len = sizeof(struct ip6_hdr);
1608 if ((mm->m_next = m_copy(m, 0, M_COPYALL)) == NULL) {
1612 i = MHLEN - M_LEADINGSPACE(mm);
1615 mm = m_pullup(mm, i);
1618 /* TODO: check it! */
1619 mm->m_pkthdr.len = len + sizeof(struct ip6_hdr);
1622 * Send message to routing daemon
1624 sin6.sin6_addr = ip6->ip6_src;
1626 im6 = mtod(mm, struct mrt6msg *);
1627 im6->im6_msgtype = MRT6MSG_WHOLEPKT;
1630 im6->im6_mif = mif - mif6table;
1632 /* iif info is not given for reg. encap.n */
1633 mrt6stat.mrt6s_upcalls++;
1635 if (socket_send(ip6_mrouter, mm, &sin6) < 0) {
1639 "register_send: ip6_mrouter socket queue full\n");
1641 ++mrt6stat.mrt6s_upq_sockfull;
1648 * PIM sparse mode hook
1649 * Receives the pim control messages, and passes them up to the listening
1650 * socket, using rip6_input.
1651 * The only message processed is the REGISTER pim message; the pim header
1652 * is stripped off, and the inner packet is passed to register_mforward.
1655 pim6_input(mp, offp, proto)
1659 struct pim *pim; /* pointer to a pim struct */
1660 struct ip6_hdr *ip6;
1662 struct mbuf *m = *mp;
1666 ++pim6stat.pim6s_rcv_total;
1668 ip6 = mtod(m, struct ip6_hdr *);
1669 pimlen = m->m_pkthdr.len - *offp;
1674 if (pimlen < PIM_MINLEN) {
1675 ++pim6stat.pim6s_rcv_tooshort;
1677 if (mrt6debug & DEBUG_PIM)
1678 log(LOG_DEBUG,"pim6_input: PIM packet too short\n");
1681 return (IPPROTO_DONE);
1685 * if the packet is at least as big as a REGISTER, go ahead
1686 * and grab the PIM REGISTER header size, to avoid another
1687 * possible m_pullup() later.
1689 * PIM_MINLEN == pimhdr + u_int32 == 8
1690 * PIM6_REG_MINLEN == pimhdr + reghdr + eip6hdr == 4 + 4 + 40
1692 minlen = (pimlen >= PIM6_REG_MINLEN) ? PIM6_REG_MINLEN : PIM_MINLEN;
1695 * Make sure that the IP6 and PIM headers in contiguous memory, and
1696 * possibly the PIM REGISTER header
1698 #ifndef PULLDOWN_TEST
1699 IP6_EXTHDR_CHECK(m, off, minlen, IPPROTO_DONE);
1700 /* adjust pointer */
1701 ip6 = mtod(m, struct ip6_hdr *);
1703 /* adjust mbuf to point to the PIM header */
1704 pim = (struct pim *)((caddr_t)ip6 + off);
1706 IP6_EXTHDR_GET(pim, struct pim *, m, off, minlen);
1708 pim6stat.pim6s_rcv_tooshort++;
1709 return (IPPROTO_DONE);
1713 #define PIM6_CHECKSUM
1714 #ifdef PIM6_CHECKSUM
1719 * Validate checksum.
1720 * If PIM REGISTER, exclude the data packet
1722 if (pim->pim_type == PIM_REGISTER)
1723 cksumlen = PIM_MINLEN;
1727 if (in6_cksum(m, IPPROTO_PIM, off, cksumlen)) {
1728 ++pim6stat.pim6s_rcv_badsum;
1730 if (mrt6debug & DEBUG_PIM)
1732 "pim6_input: invalid checksum\n");
1735 return (IPPROTO_DONE);
1738 #endif /* PIM_CHECKSUM */
1740 /* PIM version check */
1741 if (pim->pim_ver != PIM_VERSION) {
1742 ++pim6stat.pim6s_rcv_badversion;
1745 "pim6_input: incorrect version %d, expecting %d\n",
1746 pim->pim_ver, PIM_VERSION);
1749 return (IPPROTO_DONE);
1752 if (pim->pim_type == PIM_REGISTER) {
1754 * since this is a REGISTER, we'll make a copy of the register
1755 * headers ip6+pim+u_int32_t+encap_ip6, to be passed up to the
1758 static struct sockaddr_in6 dst = { sizeof(dst), AF_INET6 };
1761 struct ip6_hdr *eip6;
1765 ++pim6stat.pim6s_rcv_registers;
1767 if ((reg_mif_num >= nummifs) || (reg_mif_num == (mifi_t) -1)) {
1769 if (mrt6debug & DEBUG_PIM)
1771 "pim6_input: register mif not set: %d\n",
1775 return (IPPROTO_DONE);
1778 reghdr = (u_int32_t *)(pim + 1);
1780 if ((ntohl(*reghdr) & PIM_NULL_REGISTER))
1781 goto pim6_input_to_daemon;
1786 if (pimlen < PIM6_REG_MINLEN) {
1787 ++pim6stat.pim6s_rcv_tooshort;
1788 ++pim6stat.pim6s_rcv_badregisters;
1791 "pim6_input: register packet size too "
1792 "small %d from %s\n",
1793 pimlen, ip6_sprintf(&ip6->ip6_src));
1796 return (IPPROTO_DONE);
1799 eip6 = (struct ip6_hdr *) (reghdr + 1);
1801 if (mrt6debug & DEBUG_PIM)
1803 "pim6_input[register], eip6: %s -> %s, "
1805 ip6_sprintf(&eip6->ip6_src),
1806 ip6_sprintf(&eip6->ip6_dst),
1807 ntohs(eip6->ip6_plen));
1810 /* verify the version number of the inner packet */
1811 if ((eip6->ip6_vfc & IPV6_VERSION_MASK) != IPV6_VERSION) {
1812 ++pim6stat.pim6s_rcv_badregisters;
1814 log(LOG_DEBUG, "pim6_input: invalid IP version (%d) "
1815 "of the inner packet\n",
1816 (eip6->ip6_vfc & IPV6_VERSION));
1819 return (IPPROTO_NONE);
1822 /* verify the inner packet is destined to a mcast group */
1823 if (!IN6_IS_ADDR_MULTICAST(&eip6->ip6_dst)) {
1824 ++pim6stat.pim6s_rcv_badregisters;
1826 if (mrt6debug & DEBUG_PIM)
1828 "pim6_input: inner packet of register "
1829 "is not multicast %s\n",
1830 ip6_sprintf(&eip6->ip6_dst));
1833 return (IPPROTO_DONE);
1837 * make a copy of the whole header to pass to the daemon later.
1839 mcp = m_copy(m, 0, off + PIM6_REG_MINLEN);
1843 "pim6_input: pim register: "
1844 "could not copy register head\n");
1847 return (IPPROTO_DONE);
1851 * forward the inner ip6 packet; point m_data at the inner ip6.
1853 m_adj(m, off + PIM_MINLEN);
1855 if (mrt6debug & DEBUG_PIM) {
1857 "pim6_input: forwarding decapsulated register: "
1858 "src %s, dst %s, mif %d\n",
1859 ip6_sprintf(&eip6->ip6_src),
1860 ip6_sprintf(&eip6->ip6_dst),
1865 rc = if_simloop(mif6table[reg_mif_num].m6_ifp, m,
1866 dst.sin6_family, 0);
1868 /* prepare the register head to send to the mrouting daemon */
1873 * Pass the PIM message up to the daemon; if it is a register message
1874 * pass the 'head' only up to the daemon. This includes the
1875 * encapsulator ip6 header, pim header, register header and the
1876 * encapsulated ip6 header.
1878 pim6_input_to_daemon:
1879 rip6_input(&m, offp, proto);
1880 return (IPPROTO_DONE);