1 /* $FreeBSD: src/sys/netinet6/ip6_mroute.c,v 1.2.2.4 2001/07/03 11:01:53 ume Exp $ */
2 /* $KAME: ip6_mroute.c,v 1.46 2001/04/04 05:17:30 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 * IP multicast forwarding procedures
38 * Written by David Waitzman, BBN Labs, August 1988.
39 * Modified by Steve Deering, Stanford, February 1989.
40 * Modified by Mark J. Steiglitz, Stanford, May, 1991
41 * Modified by Van Jacobson, LBL, January 1993
42 * Modified by Ajit Thyagarajan, PARC, August 1993
43 * Modified by Bill Fenenr, PARC, April 1994
45 * MROUTING Revision: 3.5.1.2 + PIM-SMv2 (pimd) Support
49 #include <sys/param.h>
50 #include <sys/systm.h>
51 #include <sys/malloc.h>
53 #include <sys/socket.h>
54 #include <sys/socketvar.h>
55 #include <sys/sockio.h>
56 #include <sys/protosw.h>
57 #include <sys/errno.h>
59 #include <sys/kernel.h>
60 #include <sys/syslog.h>
63 #include <net/route.h>
64 #include <net/raw_cb.h>
66 #include <netinet/in.h>
67 #include <netinet/in_var.h>
69 #include <netinet/ip6.h>
70 #include <netinet6/ip6_var.h>
71 #include <netinet6/ip6_mroute.h>
72 #include <netinet6/pim6.h>
73 #include <netinet6/pim6_var.h>
76 static MALLOC_DEFINE(M_MRTABLE
, "mf6c", "multicast forwarding cache entry");
79 #define M_HASCL(m) ((m)->m_flags & M_EXT)
81 static int ip6_mdq
__P((struct mbuf
*, struct ifnet
*, struct mf6c
*));
82 static void phyint_send
__P((struct ip6_hdr
*, struct mif6
*, struct mbuf
*));
84 static int set_pim6
__P((int *));
85 static int socket_send
__P((struct socket
*, struct mbuf
*,
86 struct sockaddr_in6
*));
87 static int register_send
__P((struct ip6_hdr
*, struct mif6
*,
91 * Globals. All but ip6_mrouter, ip6_mrtproto and mrt6stat could be static,
92 * except for netstat or debugging purposes.
94 struct socket
*ip6_mrouter
= NULL
;
95 int ip6_mrouter_ver
= 0;
96 int ip6_mrtproto
= IPPROTO_PIM
; /* for netstat only */
97 struct mrt6stat mrt6stat
;
99 #define NO_RTE_FOUND 0x1
100 #define RTE_FOUND 0x2
102 struct mf6c
*mf6ctable
[MF6CTBLSIZ
];
103 u_char nexpire
[MF6CTBLSIZ
];
104 static struct mif6 mif6table
[MAXMIFS
];
106 u_int mrt6debug
= 0; /* debug level */
107 #define DEBUG_MFC 0x02
108 #define DEBUG_FORWARD 0x04
109 #define DEBUG_EXPIRE 0x08
110 #define DEBUG_XMIT 0x10
111 #define DEBUG_REG 0x20
112 #define DEBUG_PIM 0x40
115 static void expire_upcalls
__P((void *));
116 static void expire_upcalls_funneled
__P((void *));
118 #define EXPIRE_TIMEOUT (hz / 4) /* 4x / second */
119 #define UPCALL_EXPIRE 6 /* number of timeouts */
123 extern struct socket
*ip_mrouter
;
127 static u_long lo_dl_tag
= 0;
129 * 'Interfaces' associated with decapsulator (so we can tell
130 * packets that went through it from ones that get reflected
131 * by a broken gateway). These interfaces are never linked into
132 * the system ifnet list & no routes point to them. I.e., packets
133 * can't be sent this way. They only exist as a placeholder for
134 * multicast source verification.
136 struct ifnet multicast_register_if
;
138 #define ENCAP_HOPS 64
143 static mifi_t nummifs
= 0;
144 static mifi_t reg_mif_num
= (mifi_t
)-1;
146 static struct pim6stat pim6stat
;
149 * one-back cache used by ipip_input to locate a tunnel's mif
150 * given a datagram's src ip address.
155 * Hash function for a source, group entry
157 #define MF6CHASH(a, g) MF6CHASHMOD((a).s6_addr32[0] ^ (a).s6_addr32[1] ^ \
158 (a).s6_addr32[2] ^ (a).s6_addr32[3] ^ \
159 (g).s6_addr32[0] ^ (g).s6_addr32[1] ^ \
160 (g).s6_addr32[2] ^ (g).s6_addr32[3])
163 * Find a route for a given origin IPv6 address and Multicast group address.
164 * Quality of service parameter to be added in the future!!!
167 #define MF6CFIND(o, g, rt) do { \
168 struct mf6c *_rt = mf6ctable[MF6CHASH(o,g)]; \
170 mrt6stat.mrt6s_mfc_lookups++; \
172 if (IN6_ARE_ADDR_EQUAL(&_rt->mf6c_origin.sin6_addr, &(o)) && \
173 IN6_ARE_ADDR_EQUAL(&_rt->mf6c_mcastgrp.sin6_addr, &(g)) && \
174 (_rt->mf6c_stall == NULL)) { \
178 _rt = _rt->mf6c_next; \
181 mrt6stat.mrt6s_mfc_misses++; \
186 * Macros to compute elapsed time efficiently
187 * Borrowed from Van Jacobson's scheduling code
189 #define TV_DELTA(a, b, delta) do { \
192 delta = (a).tv_usec - (b).tv_usec; \
193 if ((xxs = (a).tv_sec - (b).tv_sec)) { \
202 delta += (1000000 * xxs); \
207 #define TV_LT(a, b) (((a).tv_usec < (b).tv_usec && \
208 (a).tv_sec <= (b).tv_sec) || (a).tv_sec < (b).tv_sec)
211 #define UPCALL_MAX 50
212 u_long upcall_data
[UPCALL_MAX
+ 1];
213 static void collate();
214 #endif /* UPCALL_TIMING */
216 static int get_sg_cnt
__P((struct sioc_sg_req6
*));
217 static int get_mif6_cnt
__P((struct sioc_mif_req6
*));
218 static int ip6_mrouter_init
__P((struct socket
*, struct mbuf
*, int));
219 static int add_m6if
__P((struct mif6ctl
*));
220 static int del_m6if
__P((mifi_t
*));
221 static int add_m6fc
__P((struct mf6cctl
*));
222 static int del_m6fc
__P((struct mf6cctl
*));
225 static struct callout expire_upcalls_ch
;
228 * Handle MRT setsockopt commands to modify the multicast routing tables.
231 ip6_mrouter_set(so
, sopt
)
233 struct sockopt
*sopt
;
238 if (so
!= ip6_mrouter
&& sopt
->sopt_name
!= MRT6_INIT
)
241 if ((error
= soopt_getm(sopt
, &m
)) != 0) /* XXX */
243 if ((error
= soopt_mcopyin(sopt
, m
)) != 0) /* XXX */
246 switch (sopt
->sopt_name
) {
251 error
= ip6_mrouter_init(so
, m
, sopt
->sopt_name
);
254 error
= ip6_mrouter_done();
257 error
= add_m6if(mtod(m
, struct mif6ctl
*));
260 error
= del_m6if(mtod(m
, mifi_t
*));
263 error
= add_m6fc(mtod(m
, struct mf6cctl
*));
266 error
= del_m6fc(mtod(m
, struct mf6cctl
*));
269 error
= set_pim6(mtod(m
, int *));
281 * Handle MRT getsockopt commands
284 ip6_mrouter_get(so
, sopt
)
286 struct sockopt
*sopt
;
290 if (so
!= ip6_mrouter
) return EACCES
;
292 switch (sopt
->sopt_name
) {
294 error
= sooptcopyout(sopt
, &pim6
, sizeof(pim6
));
301 * Handle ioctl commands to obtain information from the cache
304 mrt6_ioctl(cmd
, data
)
311 case SIOCGETSGCNT_IN6
:
312 return(get_sg_cnt((struct sioc_sg_req6
*)data
));
313 break; /* for safety */
314 case SIOCGETMIFCNT_IN6
:
315 return(get_mif6_cnt((struct sioc_mif_req6
*)data
));
316 break; /* for safety */
325 * returns the packet, byte, rpf-failure count for the source group provided
329 struct sioc_sg_req6
*req
;
335 MF6CFIND(req
->src
.sin6_addr
, req
->grp
.sin6_addr
, rt
);
338 req
->pktcnt
= rt
->mf6c_pkt_cnt
;
339 req
->bytecnt
= rt
->mf6c_byte_cnt
;
340 req
->wrong_if
= rt
->mf6c_wrong_if
;
344 req
->pktcnt
= req
->bytecnt
= req
->wrong_if
= 0xffffffff;
351 * returns the input and output packet and byte counts on the mif provided
355 struct sioc_mif_req6
*req
;
357 mifi_t mifi
= req
->mifi
;
362 req
->icount
= mif6table
[mifi
].m6_pkt_in
;
363 req
->ocount
= mif6table
[mifi
].m6_pkt_out
;
364 req
->ibytes
= mif6table
[mifi
].m6_bytes_in
;
365 req
->obytes
= mif6table
[mifi
].m6_bytes_out
;
374 if ((*i
!= 1) && (*i
!= 0))
383 * Enable multicast routing
386 ip6_mrouter_init(so
, m
, cmd
)
396 "ip6_mrouter_init: so_type = %d, pr_protocol = %d\n",
397 so
->so_type
, so
->so_proto
->pr_protocol
);
400 if (so
->so_type
!= SOCK_RAW
||
401 so
->so_proto
->pr_protocol
!= IPPROTO_ICMPV6
)
404 if (!m
|| (m
->m_len
!= sizeof(int *)))
411 if (ip6_mrouter
!= NULL
) return EADDRINUSE
;
414 ip6_mrouter_ver
= cmd
;
416 bzero((caddr_t
)mf6ctable
, sizeof(mf6ctable
));
417 bzero((caddr_t
)nexpire
, sizeof(nexpire
));
419 pim6
= 0;/* used for stubbing out/in pim stuff */
422 callout_reset(&expire_upcalls_ch
, EXPIRE_TIMEOUT
,
423 expire_upcalls
, NULL
);
425 timeout(expire_upcalls_funneled
, (caddr_t
)NULL
, EXPIRE_TIMEOUT
);
430 log(LOG_DEBUG
, "ip6_mrouter_init\n");
437 * Disable multicast routing
445 struct in6_ifreq ifr
;
453 * For each phyint in use, disable promiscuous reception of all IPv6
459 * If there is still IPv4 multicast routing daemon,
460 * we remain interfaces to receive all muliticasted packets.
461 * XXX: there may be an interface in which the IPv4 multicast
462 * daemon is not interested...
468 for (mifi
= 0; mifi
< nummifs
; mifi
++) {
469 if (mif6table
[mifi
].m6_ifp
&&
470 !(mif6table
[mifi
].m6_flags
& MIFF_REGISTER
)) {
471 ifr
.ifr_addr
.sin6_family
= AF_INET6
;
472 ifr
.ifr_addr
.sin6_addr
= in6addr_any
;
473 ifp
= mif6table
[mifi
].m6_ifp
;
475 dlil_ioctl(0, ifp
, SIOCDELMULTI
,
478 (*ifp
->if_ioctl
)(ifp
, SIOCDELMULTI
,
485 bzero((caddr_t
)qtable
, sizeof(qtable
));
486 bzero((caddr_t
)tbftable
, sizeof(tbftable
));
488 bzero((caddr_t
)mif6table
, sizeof(mif6table
));
491 pim6
= 0; /* used to stub out/in pim specific code */
494 callout_stop(&expire_upcalls_ch
);
496 untimeout(expire_upcalls_funneled
, (caddr_t
)NULL
);
500 * Free all multicast forwarding cache entries.
502 for (i
= 0; i
< MF6CTBLSIZ
; i
++) {
507 for (rte
= rt
->mf6c_stall
; rte
!= NULL
; ) {
508 struct rtdetq
*n
= rte
->next
;
511 FREE(rte
, M_MRTABLE
);
516 FREE(frt
, M_MRTABLE
);
520 bzero((caddr_t
)mf6ctable
, sizeof(mf6ctable
));
523 * Reset de-encapsulation cache
534 log(LOG_DEBUG
, "ip6_mrouter_done\n");
540 static struct sockaddr_in6 sin6
= { sizeof(sin6
), AF_INET6
};
543 * Add a mif to the mif table
547 struct mif6ctl
*mifcp
;
553 struct tbf
*m_tbf
= tbftable
+ mifcp
->mif6c_mifi
;
556 if (mifcp
->mif6c_mifi
>= MAXMIFS
)
558 mifp
= mif6table
+ mifcp
->mif6c_mifi
;
560 return EADDRINUSE
; /* XXX: is it appropriate? */
561 if (mifcp
->mif6c_pifi
== 0 || mifcp
->mif6c_pifi
> if_index
)
563 ifp
= ifindex2ifnet
[mifcp
->mif6c_pifi
];
565 if (mifcp
->mif6c_flags
& MIFF_REGISTER
) {
566 if (reg_mif_num
== (mifi_t
)-1) {
567 multicast_register_if
.if_name
= "register_mif";
568 multicast_register_if
.if_flags
|= IFF_LOOPBACK
;
569 multicast_register_if
.if_index
= mifcp
->mif6c_mifi
;
570 reg_mif_num
= mifcp
->mif6c_mifi
;
573 ifp
= &multicast_register_if
;
577 /* Make sure the interface supports multicast */
578 if ((ifp
->if_flags
& IFF_MULTICAST
) == 0)
582 error
= if_allmulti(ifp
, 1);
589 mifp
->m6_flags
= mifcp
->mif6c_flags
;
592 /* scaling up here allows division by 1024 in critical code */
593 mifp
->m6_rate_limit
= mifcp
->mif6c_rate_limit
* 1024 / 1000;
595 /* initialize per mif pkt counters */
597 mifp
->m6_pkt_out
= 0;
598 mifp
->m6_bytes_in
= 0;
599 mifp
->m6_bytes_out
= 0;
602 /* Adjust nummifs up if the mifi is higher than nummifs */
603 if (nummifs
<= mifcp
->mif6c_mifi
)
604 nummifs
= mifcp
->mif6c_mifi
+ 1;
609 "add_mif #%d, phyint %s%d\n",
611 ifp
->if_name
, ifp
->if_unit
);
618 * Delete a mif from the mif table
624 struct mif6
*mifp
= mif6table
+ *mifip
;
629 if (*mifip
>= nummifs
)
631 if (mifp
->m6_ifp
== NULL
)
636 if (!(mifp
->m6_flags
& MIFF_REGISTER
)) {
638 * XXX: what if there is yet IPv4 multicast daemon
639 * using the interface?
647 bzero((caddr_t
)qtable
[*mifip
], sizeof(qtable
[*mifip
]));
648 bzero((caddr_t
)mifp
->m6_tbf
, sizeof(*(mifp
->m6_tbf
)));
650 bzero((caddr_t
)mifp
, sizeof (*mifp
));
652 /* Adjust nummifs down */
653 for (mifi
= nummifs
; mifi
> 0; mifi
--)
654 if (mif6table
[mifi
- 1].m6_ifp
)
662 log(LOG_DEBUG
, "del_m6if %d, nummifs %d\n", *mifip
, nummifs
);
673 struct mf6cctl
*mfccp
;
681 MF6CFIND(mfccp
->mf6cc_origin
.sin6_addr
,
682 mfccp
->mf6cc_mcastgrp
.sin6_addr
, rt
);
684 /* If an entry already exists, just update the fields */
687 if (mrt6debug
& DEBUG_MFC
)
688 log(LOG_DEBUG
,"add_m6fc update o %s g %s p %x\n",
689 ip6_sprintf(&mfccp
->mf6cc_origin
.sin6_addr
),
690 ip6_sprintf(&mfccp
->mf6cc_mcastgrp
.sin6_addr
),
691 mfccp
->mf6cc_parent
);
695 rt
->mf6c_parent
= mfccp
->mf6cc_parent
;
696 rt
->mf6c_ifset
= mfccp
->mf6cc_ifset
;
702 * Find the entry for which the upcall was made and update
705 hash
= MF6CHASH(mfccp
->mf6cc_origin
.sin6_addr
,
706 mfccp
->mf6cc_mcastgrp
.sin6_addr
);
707 for (rt
= mf6ctable
[hash
], nstl
= 0; rt
; rt
= rt
->mf6c_next
) {
708 if (IN6_ARE_ADDR_EQUAL(&rt
->mf6c_origin
.sin6_addr
,
709 &mfccp
->mf6cc_origin
.sin6_addr
) &&
710 IN6_ARE_ADDR_EQUAL(&rt
->mf6c_mcastgrp
.sin6_addr
,
711 &mfccp
->mf6cc_mcastgrp
.sin6_addr
) &&
712 (rt
->mf6c_stall
!= NULL
)) {
716 "add_m6fc: %s o %s g %s p %x dbx %p\n",
717 "multiple kernel entries",
718 ip6_sprintf(&mfccp
->mf6cc_origin
.sin6_addr
),
719 ip6_sprintf(&mfccp
->mf6cc_mcastgrp
.sin6_addr
),
720 mfccp
->mf6cc_parent
, rt
->mf6c_stall
);
723 if (mrt6debug
& DEBUG_MFC
)
725 "add_m6fc o %s g %s p %x dbg %x\n",
726 ip6_sprintf(&mfccp
->mf6cc_origin
.sin6_addr
),
727 ip6_sprintf(&mfccp
->mf6cc_mcastgrp
.sin6_addr
),
728 mfccp
->mf6cc_parent
, rt
->mf6c_stall
);
731 rt
->mf6c_origin
= mfccp
->mf6cc_origin
;
732 rt
->mf6c_mcastgrp
= mfccp
->mf6cc_mcastgrp
;
733 rt
->mf6c_parent
= mfccp
->mf6cc_parent
;
734 rt
->mf6c_ifset
= mfccp
->mf6cc_ifset
;
735 /* initialize pkt counters per src-grp */
736 rt
->mf6c_pkt_cnt
= 0;
737 rt
->mf6c_byte_cnt
= 0;
738 rt
->mf6c_wrong_if
= 0;
740 rt
->mf6c_expire
= 0; /* Don't clean this guy up */
743 /* free packets Qed at the end of this entry */
744 for (rte
= rt
->mf6c_stall
; rte
!= NULL
; ) {
745 struct rtdetq
*n
= rte
->next
;
746 ip6_mdq(rte
->m
, rte
->ifp
, rt
);
750 #endif /* UPCALL_TIMING */
751 FREE(rte
, M_MRTABLE
);
754 rt
->mf6c_stall
= NULL
;
759 * It is possible that an entry is being inserted without an upcall
763 if (mrt6debug
& DEBUG_MFC
)
764 log(LOG_DEBUG
,"add_mfc no upcall h %d o %s g %s p %x\n",
766 ip6_sprintf(&mfccp
->mf6cc_origin
.sin6_addr
),
767 ip6_sprintf(&mfccp
->mf6cc_mcastgrp
.sin6_addr
),
768 mfccp
->mf6cc_parent
);
771 for (rt
= mf6ctable
[hash
]; rt
; rt
= rt
->mf6c_next
) {
773 if (IN6_ARE_ADDR_EQUAL(&rt
->mf6c_origin
.sin6_addr
,
774 &mfccp
->mf6cc_origin
.sin6_addr
)&&
775 IN6_ARE_ADDR_EQUAL(&rt
->mf6c_mcastgrp
.sin6_addr
,
776 &mfccp
->mf6cc_mcastgrp
.sin6_addr
)) {
778 rt
->mf6c_origin
= mfccp
->mf6cc_origin
;
779 rt
->mf6c_mcastgrp
= mfccp
->mf6cc_mcastgrp
;
780 rt
->mf6c_parent
= mfccp
->mf6cc_parent
;
781 rt
->mf6c_ifset
= mfccp
->mf6cc_ifset
;
782 /* initialize pkt counters per src-grp */
783 rt
->mf6c_pkt_cnt
= 0;
784 rt
->mf6c_byte_cnt
= 0;
785 rt
->mf6c_wrong_if
= 0;
793 /* no upcall, so make a new entry */
794 rt
= (struct mf6c
*)_MALLOC(sizeof(*rt
), M_MRTABLE
,
801 /* insert new entry at head of hash chain */
802 rt
->mf6c_origin
= mfccp
->mf6cc_origin
;
803 rt
->mf6c_mcastgrp
= mfccp
->mf6cc_mcastgrp
;
804 rt
->mf6c_parent
= mfccp
->mf6cc_parent
;
805 rt
->mf6c_ifset
= mfccp
->mf6cc_ifset
;
806 /* initialize pkt counters per src-grp */
807 rt
->mf6c_pkt_cnt
= 0;
808 rt
->mf6c_byte_cnt
= 0;
809 rt
->mf6c_wrong_if
= 0;
811 rt
->mf6c_stall
= NULL
;
813 /* link into table */
814 rt
->mf6c_next
= mf6ctable
[hash
];
815 mf6ctable
[hash
] = rt
;
824 * collect delay statistics on the upcalls
838 TV_DELTA(tp
, *t
, delta
);
847 #endif /* UPCALL_TIMING */
850 * Delete an mfc entry
854 struct mf6cctl
*mfccp
;
856 struct sockaddr_in6 origin
;
857 struct sockaddr_in6 mcastgrp
;
863 origin
= mfccp
->mf6cc_origin
;
864 mcastgrp
= mfccp
->mf6cc_mcastgrp
;
865 hash
= MF6CHASH(origin
.sin6_addr
, mcastgrp
.sin6_addr
);
868 if (mrt6debug
& DEBUG_MFC
)
869 log(LOG_DEBUG
,"del_m6fc orig %s mcastgrp %s\n",
870 ip6_sprintf(&origin
.sin6_addr
),
871 ip6_sprintf(&mcastgrp
.sin6_addr
));
876 nptr
= &mf6ctable
[hash
];
877 while ((rt
= *nptr
) != NULL
) {
878 if (IN6_ARE_ADDR_EQUAL(&origin
.sin6_addr
,
879 &rt
->mf6c_origin
.sin6_addr
) &&
880 IN6_ARE_ADDR_EQUAL(&mcastgrp
.sin6_addr
,
881 &rt
->mf6c_mcastgrp
.sin6_addr
) &&
882 rt
->mf6c_stall
== NULL
)
885 nptr
= &rt
->mf6c_next
;
889 return EADDRNOTAVAIL
;
892 *nptr
= rt
->mf6c_next
;
901 socket_send(s
, mm
, src
)
904 struct sockaddr_in6
*src
;
907 if (sbappendaddr(&s
->so_rcv
,
908 (struct sockaddr
*)src
,
909 mm
, (struct mbuf
*)0) != 0) {
919 * IPv6 multicast forwarding function. This function assumes that the packet
920 * pointed to by "ip6" has arrived on (or is about to be sent to) the interface
921 * pointed to by "ifp", and the packet is to be relayed to other networks
922 * that have members of the packet's destination IPv6 multicast group.
924 * The packet is returned unscathed to the caller, unless it is
925 * erroneous, in which case a non-zero return value tells the caller to
930 ip6_mforward(ip6
, ifp
, m
)
942 if (mrt6debug
& DEBUG_FORWARD
)
943 log(LOG_DEBUG
, "ip6_mforward: src %s, dst %s, ifindex %d\n",
944 ip6_sprintf(&ip6
->ip6_src
), ip6_sprintf(&ip6
->ip6_dst
),
949 * Don't forward a packet with Hop limit of zero or one,
950 * or a packet destined to a local-only group.
952 if (ip6
->ip6_hlim
<= 1 || IN6_IS_ADDR_MC_NODELOCAL(&ip6
->ip6_dst
) ||
953 IN6_IS_ADDR_MC_LINKLOCAL(&ip6
->ip6_dst
))
958 * Source address check: do not forward packets with unspecified
959 * source. It was discussed in July 2000, on ipngwg mailing list.
960 * This is rather more serious than unicast cases, because some
961 * MLD packets can be sent with the unspecified source address
962 * (although such packets must normally set 1 to the hop limit field).
964 if (IN6_IS_ADDR_UNSPECIFIED(&ip6
->ip6_src
)) {
965 ip6stat
.ip6s_cantforward
++;
966 if (ip6_log_time
+ ip6_log_interval
< time_second
) {
967 ip6_log_time
= time_second
;
970 "from %s to %s nxt %d received on %s\n",
971 ip6_sprintf(&ip6
->ip6_src
),
972 ip6_sprintf(&ip6
->ip6_dst
),
974 if_name(m
->m_pkthdr
.rcvif
));
980 * Determine forwarding mifs from the forwarding cache table
983 MF6CFIND(ip6
->ip6_src
, ip6
->ip6_dst
, rt
);
985 /* Entry exists, so forward if necessary */
988 return (ip6_mdq(m
, ifp
, rt
));
991 * If we don't have a route for packet's origin,
992 * Make a copy of the packet &
993 * send message to routing daemon
1004 #endif /* UPCALL_TIMING */
1006 mrt6stat
.mrt6s_no_route
++;
1008 if (mrt6debug
& (DEBUG_FORWARD
| DEBUG_MFC
))
1009 log(LOG_DEBUG
, "ip6_mforward: no rte s %s g %s\n",
1010 ip6_sprintf(&ip6
->ip6_src
),
1011 ip6_sprintf(&ip6
->ip6_dst
));
1015 * Allocate mbufs early so that we don't do extra work if we
1016 * are just going to fail anyway.
1018 rte
= (struct rtdetq
*)_MALLOC(sizeof(*rte
), M_MRTABLE
,
1024 mb0
= m_copy(m
, 0, M_COPYALL
);
1026 * Pullup packet header if needed before storing it,
1027 * as other references may modify it in the meantime.
1030 (M_HASCL(mb0
) || mb0
->m_len
< sizeof(struct ip6_hdr
)))
1031 mb0
= m_pullup(mb0
, sizeof(struct ip6_hdr
));
1033 FREE(rte
, M_MRTABLE
);
1038 /* is there an upcall waiting for this packet? */
1039 hash
= MF6CHASH(ip6
->ip6_src
, ip6
->ip6_dst
);
1040 for (rt
= mf6ctable
[hash
]; rt
; rt
= rt
->mf6c_next
) {
1041 if (IN6_ARE_ADDR_EQUAL(&ip6
->ip6_src
,
1042 &rt
->mf6c_origin
.sin6_addr
) &&
1043 IN6_ARE_ADDR_EQUAL(&ip6
->ip6_dst
,
1044 &rt
->mf6c_mcastgrp
.sin6_addr
) &&
1045 (rt
->mf6c_stall
!= NULL
))
1052 struct omrt6msg
*oim
;
1055 /* no upcall, so make a new entry */
1056 rt
= (struct mf6c
*)_MALLOC(sizeof(*rt
), M_MRTABLE
,
1059 FREE(rte
, M_MRTABLE
);
1065 * Make a copy of the header to send to the user
1068 mm
= m_copy(mb0
, 0, sizeof(struct ip6_hdr
));
1071 FREE(rte
, M_MRTABLE
);
1073 FREE(rt
, M_MRTABLE
);
1079 * Send message to routing daemon
1081 sin6
.sin6_addr
= ip6
->ip6_src
;
1087 switch (ip6_mrouter_ver
) {
1090 oim
= mtod(mm
, struct omrt6msg
*);
1091 oim
->im6_msgtype
= MRT6MSG_NOCACHE
;
1096 im
= mtod(mm
, struct mrt6msg
*);
1097 im
->im6_msgtype
= MRT6MSG_NOCACHE
;
1101 FREE(rte
, M_MRTABLE
);
1103 FREE(rt
, M_MRTABLE
);
1109 if (mrt6debug
& DEBUG_FORWARD
)
1111 "getting the iif info in the kernel\n");
1114 for (mifp
= mif6table
, mifi
= 0;
1115 mifi
< nummifs
&& mifp
->m6_ifp
!= ifp
;
1119 switch (ip6_mrouter_ver
) {
1122 oim
->im6_mif
= mifi
;
1130 if (socket_send(ip6_mrouter
, mm
, &sin6
) < 0) {
1131 log(LOG_WARNING
, "ip6_mforward: ip6_mrouter "
1132 "socket queue full\n");
1133 mrt6stat
.mrt6s_upq_sockfull
++;
1134 FREE(rte
, M_MRTABLE
);
1136 FREE(rt
, M_MRTABLE
);
1141 mrt6stat
.mrt6s_upcalls
++;
1143 /* insert new entry at head of hash chain */
1144 bzero(rt
, sizeof(*rt
));
1145 rt
->mf6c_origin
.sin6_family
= AF_INET6
;
1146 rt
->mf6c_origin
.sin6_len
= sizeof(struct sockaddr_in6
);
1147 rt
->mf6c_origin
.sin6_addr
= ip6
->ip6_src
;
1148 rt
->mf6c_mcastgrp
.sin6_family
= AF_INET6
;
1149 rt
->mf6c_mcastgrp
.sin6_len
= sizeof(struct sockaddr_in6
);
1150 rt
->mf6c_mcastgrp
.sin6_addr
= ip6
->ip6_dst
;
1151 rt
->mf6c_expire
= UPCALL_EXPIRE
;
1153 rt
->mf6c_parent
= MF6C_INCOMPLETE_PARENT
;
1155 /* link into table */
1156 rt
->mf6c_next
= mf6ctable
[hash
];
1157 mf6ctable
[hash
] = rt
;
1158 /* Add this entry to the end of the queue */
1159 rt
->mf6c_stall
= rte
;
1161 /* determine if q has overflowed */
1165 for (p
= &rt
->mf6c_stall
; *p
!= NULL
; p
= &(*p
)->next
)
1166 if (++npkts
> MAX_UPQ6
) {
1167 mrt6stat
.mrt6s_upq_ovflw
++;
1168 FREE(rte
, M_MRTABLE
);
1174 /* Add this entry to the end of the queue */
1183 #endif /* UPCALL_TIMING */
1192 expire_upcalls_funneled(unused
)
1196 boolean_t funnel_state
;
1197 funnel_state
= thread_funnel_set(network_flock
, TRUE
);
1199 expire_upcalls(unused
);
1201 (void) thread_funnel_set(network_flock
, FALSE
);
1206 * Clean up cache entries if upcalls are not serviced
1207 * Call from the Slow Timeout mechanism, every half second.
1210 expire_upcalls(unused
)
1214 struct mf6c
*mfc
, **nptr
;
1219 for (i
= 0; i
< MF6CTBLSIZ
; i
++) {
1220 if (nexpire
[i
] == 0)
1222 nptr
= &mf6ctable
[i
];
1223 while ((mfc
= *nptr
) != NULL
) {
1224 rte
= mfc
->mf6c_stall
;
1226 * Skip real cache entries
1227 * Make sure it wasn't marked to not expire (shouldn't happen)
1231 mfc
->mf6c_expire
!= 0 &&
1232 --mfc
->mf6c_expire
== 0) {
1234 if (mrt6debug
& DEBUG_EXPIRE
)
1235 log(LOG_DEBUG
, "expire_upcalls: expiring (%s %s)\n",
1236 ip6_sprintf(&mfc
->mf6c_origin
.sin6_addr
),
1237 ip6_sprintf(&mfc
->mf6c_mcastgrp
.sin6_addr
));
1240 * drop all the packets
1241 * free the mbuf with the pkt, if, timing info
1244 struct rtdetq
*n
= rte
->next
;
1246 FREE(rte
, M_MRTABLE
);
1248 } while (rte
!= NULL
);
1249 mrt6stat
.mrt6s_cache_cleanups
++;
1252 *nptr
= mfc
->mf6c_next
;
1253 FREE(mfc
, M_MRTABLE
);
1255 nptr
= &mfc
->mf6c_next
;
1262 callout_reset(&expire_upcalls_ch
, EXPIRE_TIMEOUT
,
1263 expire_upcalls
, NULL
);
1265 timeout(expire_upcalls_funneled
, (caddr_t
)NULL
, EXPIRE_TIMEOUT
);
1270 * Packet forwarding routine once entry in the cache is made
1278 struct ip6_hdr
*ip6
= mtod(m
, struct ip6_hdr
*);
1281 int plen
= m
->m_pkthdr
.len
;
1284 * Macro to send packet on mif. Since RSVP packets don't get counted on
1285 * input, they shouldn't get counted on output, so statistics keeping is
1289 #define MC6_SEND(ip6, mifp, m) do { \
1290 if ((mifp)->m6_flags & MIFF_REGISTER) \
1291 register_send((ip6), (mifp), (m)); \
1293 phyint_send((ip6), (mifp), (m)); \
1297 * Don't forward if it didn't arrive from the parent mif
1300 mifi
= rt
->mf6c_parent
;
1301 if ((mifi
>= nummifs
) || (mif6table
[mifi
].m6_ifp
!= ifp
)) {
1302 /* came in the wrong interface */
1304 if (mrt6debug
& DEBUG_FORWARD
)
1306 "wrong if: ifid %d mifi %d mififid %x\n",
1307 ifp
->if_index
, mifi
,
1308 mif6table
[mifi
].m6_ifp
->if_index
);
1310 mrt6stat
.mrt6s_wrong_if
++;
1311 rt
->mf6c_wrong_if
++;
1313 * If we are doing PIM processing, and we are forwarding
1314 * packets on this interface, send a message to the
1317 /* have to make sure this is a valid mif */
1318 if (mifi
< nummifs
&& mif6table
[mifi
].m6_ifp
)
1319 if (pim6
&& (m
->m_flags
& M_LOOP
) == 0) {
1321 * Check the M_LOOP flag to avoid an
1322 * unnecessary PIM assert.
1323 * XXX: M_LOOP is an ad-hoc hack...
1325 static struct sockaddr_in6 sin6
=
1326 { sizeof(sin6
), AF_INET6
};
1331 struct omrt6msg
*oim
;
1334 mm
= m_copy(m
, 0, sizeof(struct ip6_hdr
));
1337 mm
->m_len
< sizeof(struct ip6_hdr
)))
1338 mm
= m_pullup(mm
, sizeof(struct ip6_hdr
));
1346 switch (ip6_mrouter_ver
) {
1349 oim
= mtod(mm
, struct omrt6msg
*);
1350 oim
->im6_msgtype
= MRT6MSG_WRONGMIF
;
1355 im
= mtod(mm
, struct mrt6msg
*);
1356 im
->im6_msgtype
= MRT6MSG_WRONGMIF
;
1364 for (mifp
= mif6table
, iif
= 0;
1365 iif
< nummifs
&& mifp
&&
1366 mifp
->m6_ifp
!= ifp
;
1370 switch (ip6_mrouter_ver
) {
1374 sin6
.sin6_addr
= oim
->im6_src
;
1379 sin6
.sin6_addr
= im
->im6_src
;
1383 mrt6stat
.mrt6s_upcalls
++;
1385 if (socket_send(ip6_mrouter
, mm
, &sin6
) < 0) {
1388 log(LOG_WARNING
, "mdq, ip6_mrouter socket queue full\n");
1390 ++mrt6stat
.mrt6s_upq_sockfull
;
1392 } /* if socket Q full */
1395 } /* if wrong iif */
1397 /* If I sourced this packet, it counts as output, else it was input. */
1398 if (m
->m_pkthdr
.rcvif
== NULL
) {
1399 /* XXX: is rcvif really NULL when output?? */
1400 mif6table
[mifi
].m6_pkt_out
++;
1401 mif6table
[mifi
].m6_bytes_out
+= plen
;
1403 mif6table
[mifi
].m6_pkt_in
++;
1404 mif6table
[mifi
].m6_bytes_in
+= plen
;
1407 rt
->mf6c_byte_cnt
+= plen
;
1410 * For each mif, forward a copy of the packet if there are group
1411 * members downstream on the interface.
1413 for (mifp
= mif6table
, mifi
= 0; mifi
< nummifs
; mifp
++, mifi
++)
1414 if (IF_ISSET(mifi
, &rt
->mf6c_ifset
)) {
1416 * check if the outgoing packet is going to break
1418 * XXX For packets through PIM register tunnel
1419 * interface, we believe a routing daemon.
1421 if ((mif6table
[rt
->mf6c_parent
].m6_flags
&
1422 MIFF_REGISTER
) == 0 &&
1423 (mif6table
[mifi
].m6_flags
& MIFF_REGISTER
) == 0 &&
1424 (in6_addr2scopeid(ifp
, &ip6
->ip6_dst
) !=
1425 in6_addr2scopeid(mif6table
[mifi
].m6_ifp
,
1427 in6_addr2scopeid(ifp
, &ip6
->ip6_src
) !=
1428 in6_addr2scopeid(mif6table
[mifi
].m6_ifp
,
1430 ip6stat
.ip6s_badscope
++;
1435 mifp
->m6_bytes_out
+= plen
;
1436 MC6_SEND(ip6
, mifp
, m
);
1442 phyint_send(ip6
, mifp
, m
)
1443 struct ip6_hdr
*ip6
;
1447 struct mbuf
*mb_copy
;
1448 struct ifnet
*ifp
= mifp
->m6_ifp
;
1450 int s
= splnet(); /* needs to protect static "ro" below. */
1451 static struct route_in6 ro
;
1452 struct in6_multi
*in6m
;
1453 struct sockaddr_in6
*dst6
;
1456 * Make a new reference to the packet; make sure that
1457 * the IPv6 header is actually copied, not just referenced,
1458 * so that ip6_output() only scribbles on the copy.
1460 mb_copy
= m_copy(m
, 0, M_COPYALL
);
1462 (M_HASCL(mb_copy
) || mb_copy
->m_len
< sizeof(struct ip6_hdr
)))
1463 mb_copy
= m_pullup(mb_copy
, sizeof(struct ip6_hdr
));
1464 if (mb_copy
== NULL
) {
1468 /* set MCAST flag to the outgoing packet */
1469 mb_copy
->m_flags
|= M_MCAST
;
1472 * If we sourced the packet, call ip6_output since we may devide
1473 * the packet into fragments when the packet is too big for the
1474 * outgoing interface.
1475 * Otherwise, we can simply send the packet to the interface
1478 if (m
->m_pkthdr
.rcvif
== NULL
) {
1479 struct ip6_moptions im6o
;
1481 im6o
.im6o_multicast_ifp
= ifp
;
1482 /* XXX: ip6_output will override ip6->ip6_hlim */
1483 im6o
.im6o_multicast_hlim
= ip6
->ip6_hlim
;
1484 im6o
.im6o_multicast_loop
= 1;
1485 error
= ip6_output(mb_copy
, NULL
, &ro
,
1486 IPV6_FORWARDING
, &im6o
, NULL
);
1489 if (mrt6debug
& DEBUG_XMIT
)
1490 log(LOG_DEBUG
, "phyint_send on mif %d err %d\n",
1491 mifp
- mif6table
, error
);
1498 * If we belong to the destination multicast group
1499 * on the outgoing interface, loop back a copy.
1501 dst6
= (struct sockaddr_in6
*)&ro
.ro_dst
;
1502 IN6_LOOKUP_MULTI(ip6
->ip6_dst
, ifp
, in6m
);
1504 dst6
->sin6_len
= sizeof(struct sockaddr_in6
);
1505 dst6
->sin6_family
= AF_INET6
;
1506 dst6
->sin6_addr
= ip6
->ip6_dst
;
1507 ip6_mloopback(ifp
, m
, (struct sockaddr_in6
*)&ro
.ro_dst
);
1510 * Put the packet into the sending queue of the outgoing interface
1511 * if it would fit in the MTU of the interface.
1513 if (mb_copy
->m_pkthdr
.len
< ifp
->if_mtu
|| ifp
->if_mtu
< IPV6_MMTU
) {
1514 dst6
->sin6_len
= sizeof(struct sockaddr_in6
);
1515 dst6
->sin6_family
= AF_INET6
;
1516 dst6
->sin6_addr
= ip6
->ip6_dst
;
1518 * We just call if_output instead of nd6_output here, since
1519 * we need no ND for a multicast forwarded packet...right?
1522 /* Make sure the HW checksum flags are cleaned before sending the packet */
1524 mb_copy
->m_pkthdr
.rcvif
= (struct ifnet
*)0;
1525 mb_copy
->m_pkthdr
.csum_data
= 0;
1526 mb_copy
->m_pkthdr
.csum_flags
= 0;
1528 error
= dlil_output(ifptodlt(ifp
, PF_INET6
), mb_copy
,
1529 NULL
, (struct sockaddr
*)&ro
.ro_dst
, 0);
1531 error
= (*ifp
->if_output
)(ifp
, mb_copy
,
1532 (struct sockaddr
*)&ro
.ro_dst
,
1536 if (mrt6debug
& DEBUG_XMIT
)
1537 log(LOG_DEBUG
, "phyint_send on mif %d err %d\n",
1538 mifp
- mif6table
, error
);
1542 icmp6_error(mb_copy
, ICMP6_PACKET_TOO_BIG
, 0, ifp
->if_mtu
);
1545 if (mrt6debug
& DEBUG_XMIT
)
1547 "phyint_send: packet too big on %s o %s g %s"
1548 " size %d(discarded)\n",
1550 ip6_sprintf(&ip6
->ip6_src
),
1551 ip6_sprintf(&ip6
->ip6_dst
),
1552 mb_copy
->m_pkthdr
.len
);
1553 #endif /* MRT6DEBUG */
1554 m_freem(mb_copy
); /* simply discard the packet */
1562 register_send(ip6
, mif
, m
)
1563 struct ip6_hdr
*ip6
;
1568 int i
, len
= m
->m_pkthdr
.len
;
1569 static struct sockaddr_in6 sin6
= { sizeof(sin6
), AF_INET6
};
1570 struct mrt6msg
*im6
;
1574 log(LOG_DEBUG
, "** IPv6 register_send **\n src %s dst %s\n",
1575 ip6_sprintf(&ip6
->ip6_src
), ip6_sprintf(&ip6
->ip6_dst
));
1577 ++pim6stat
.pim6s_snd_registers
;
1579 /* Make a copy of the packet to send to the user level process */
1580 MGETHDR(mm
, M_DONTWAIT
, MT_HEADER
);
1583 mm
->m_pkthdr
.rcvif
= NULL
;
1584 mm
->m_data
+= max_linkhdr
;
1585 mm
->m_len
= sizeof(struct ip6_hdr
);
1587 if ((mm
->m_next
= m_copy(m
, 0, M_COPYALL
)) == NULL
) {
1591 i
= MHLEN
- M_LEADINGSPACE(mm
);
1594 mm
= m_pullup(mm
, i
);
1599 /* TODO: check it! */
1600 mm
->m_pkthdr
.len
= len
+ sizeof(struct ip6_hdr
);
1603 * Send message to routing daemon
1605 sin6
.sin6_addr
= ip6
->ip6_src
;
1607 im6
= mtod(mm
, struct mrt6msg
*);
1608 im6
->im6_msgtype
= MRT6MSG_WHOLEPKT
;
1611 im6
->im6_mif
= mif
- mif6table
;
1613 /* iif info is not given for reg. encap.n */
1614 mrt6stat
.mrt6s_upcalls
++;
1616 if (socket_send(ip6_mrouter
, mm
, &sin6
) < 0) {
1620 "register_send: ip_mrouter socket queue full\n");
1622 ++mrt6stat
.mrt6s_upq_sockfull
;
1629 * PIM sparse mode hook
1630 * Receives the pim control messages, and passes them up to the listening
1631 * socket, using rip6_input.
1632 * The only message processed is the REGISTER pim message; the pim header
1633 * is stripped off, and the inner packet is passed to register_mforward.
1636 pim6_input(mp
, offp
)
1640 struct pim
*pim
; /* pointer to a pim struct */
1641 struct ip6_hdr
*ip6
;
1643 struct mbuf
*m
= *mp
;
1648 ++pim6stat
.pim6s_rcv_total
;
1650 ip6
= mtod(m
, struct ip6_hdr
*);
1651 pimlen
= m
->m_pkthdr
.len
- *offp
;
1652 proto
= ip6
->ip6_nxt
;
1657 if (pimlen
< PIM_MINLEN
) {
1658 ++pim6stat
.pim6s_rcv_tooshort
;
1660 if (mrt6debug
& DEBUG_PIM
)
1661 log(LOG_DEBUG
,"pim6_input: PIM packet too short\n");
1664 return(IPPROTO_DONE
);
1668 * if the packet is at least as big as a REGISTER, go ahead
1669 * and grab the PIM REGISTER header size, to avoid another
1670 * possible m_pullup() later.
1672 * PIM_MINLEN == pimhdr + u_int32 == 8
1673 * PIM6_REG_MINLEN == pimhdr + reghdr + eip6hdr == 4 + 4 + 40
1675 minlen
= (pimlen
>= PIM6_REG_MINLEN
) ? PIM6_REG_MINLEN
: PIM_MINLEN
;
1678 * Make sure that the IP6 and PIM headers in contiguous memory, and
1679 * possibly the PIM REGISTER header
1681 #ifndef PULLDOWN_TEST
1682 IP6_EXTHDR_CHECK(m
, off
, minlen
, IPPROTO_DONE
);
1683 /* adjust pointer */
1684 ip6
= mtod(m
, struct ip6_hdr
*);
1686 /* adjust mbuf to point to the PIM header */
1687 pim
= (struct pim
*)((caddr_t
)ip6
+ off
);
1689 IP6_EXTHDR_GET(pim
, struct pim
*, m
, off
, minlen
);
1691 pim6stat
.pim6s_rcv_tooshort
++;
1692 return IPPROTO_DONE
;
1696 #define PIM6_CHECKSUM
1697 #ifdef PIM6_CHECKSUM
1702 * Validate checksum.
1703 * If PIM REGISTER, exclude the data packet
1705 if (pim
->pim_type
== PIM_REGISTER
)
1706 cksumlen
= PIM_MINLEN
;
1710 if (in6_cksum(m
, IPPROTO_PIM
, off
, cksumlen
)) {
1711 ++pim6stat
.pim6s_rcv_badsum
;
1713 if (mrt6debug
& DEBUG_PIM
)
1715 "pim6_input: invalid checksum\n");
1718 return(IPPROTO_DONE
);
1721 #endif /* PIM_CHECKSUM */
1723 /* PIM version check */
1724 if (pim
->pim_ver
!= PIM_VERSION
) {
1725 ++pim6stat
.pim6s_rcv_badversion
;
1728 "pim6_input: incorrect version %d, expecting %d\n",
1729 pim
->pim_ver
, PIM_VERSION
);
1732 return(IPPROTO_DONE
);
1735 if (pim
->pim_type
== PIM_REGISTER
) {
1737 * since this is a REGISTER, we'll make a copy of the register
1738 * headers ip6+pim+u_int32_t+encap_ip6, to be passed up to the
1741 static struct sockaddr_in6 dst
= { sizeof(dst
), AF_INET6
};
1744 struct ip6_hdr
*eip6
;
1748 ++pim6stat
.pim6s_rcv_registers
;
1750 if ((reg_mif_num
>= nummifs
) || (reg_mif_num
== (mifi_t
) -1)) {
1752 if (mrt6debug
& DEBUG_PIM
)
1754 "pim6_input: register mif not set: %d\n",
1758 return(IPPROTO_DONE
);
1761 reghdr
= (u_int32_t
*)(pim
+ 1);
1763 if ((ntohl(*reghdr
) & PIM_NULL_REGISTER
))
1764 goto pim6_input_to_daemon
;
1769 if (pimlen
< PIM6_REG_MINLEN
) {
1770 ++pim6stat
.pim6s_rcv_tooshort
;
1771 ++pim6stat
.pim6s_rcv_badregisters
;
1774 "pim6_input: register packet size too "
1775 "small %d from %s\n",
1776 pimlen
, ip6_sprintf(&ip6
->ip6_src
));
1779 return(IPPROTO_DONE
);
1782 eip6
= (struct ip6_hdr
*) (reghdr
+ 1);
1784 if (mrt6debug
& DEBUG_PIM
)
1786 "pim6_input[register], eip6: %s -> %s, "
1788 ip6_sprintf(&eip6
->ip6_src
),
1789 ip6_sprintf(&eip6
->ip6_dst
),
1790 ntohs(eip6
->ip6_plen
));
1793 /* verify the version number of the inner packet */
1794 if ((eip6
->ip6_vfc
& IPV6_VERSION_MASK
) != IPV6_VERSION
) {
1795 ++pim6stat
.pim6s_rcv_badregisters
;
1797 log(LOG_DEBUG
, "pim6_input: invalid IP version (%d) "
1798 "of the inner packet\n",
1799 (eip6
->ip6_vfc
& IPV6_VERSION
));
1802 return(IPPROTO_NONE
);
1805 /* verify the inner packet is destined to a mcast group */
1806 if (!IN6_IS_ADDR_MULTICAST(&eip6
->ip6_dst
)) {
1807 ++pim6stat
.pim6s_rcv_badregisters
;
1809 if (mrt6debug
& DEBUG_PIM
)
1811 "pim6_input: inner packet of register "
1812 "is not multicast %s\n",
1813 ip6_sprintf(&eip6
->ip6_dst
));
1816 return(IPPROTO_DONE
);
1820 * make a copy of the whole header to pass to the daemon later.
1822 mcp
= m_copy(m
, 0, off
+ PIM6_REG_MINLEN
);
1826 "pim6_input: pim register: "
1827 "could not copy register head\n");
1830 return(IPPROTO_DONE
);
1834 * forward the inner ip6 packet; point m_data at the inner ip6.
1836 m_adj(m
, off
+ PIM_MINLEN
);
1838 if (mrt6debug
& DEBUG_PIM
) {
1840 "pim6_input: forwarding decapsulated register: "
1841 "src %s, dst %s, mif %d\n",
1842 ip6_sprintf(&eip6
->ip6_src
),
1843 ip6_sprintf(&eip6
->ip6_dst
),
1851 dlil_find_dltag(APPLE_IF_FAM_LOOPBACK
, 0, PF_INET
, &lo_dl_tag
);
1854 dlil_output(lo_dl_tag
, m
, 0, (struct sockaddr
*)&dst
, 0);
1856 printf("Warning: pim6_input call to dlil_find_dltag failed!\n");
1860 rc
= if_simloop(mif6table
[reg_mif_num
].m6_ifp
, m
,
1861 dst
.sin6_family
, NULL
);
1864 /* prepare the register head to send to the mrouting daemon */
1869 * Pass the PIM message up to the daemon; if it is a register message
1870 * pass the 'head' only up to the daemon. This includes the
1871 * encapsulator ip6 header, pim header, register header and the
1872 * encapsulated ip6 header.
1874 pim6_input_to_daemon
:
1875 rip6_input(&m
, offp
);
1876 return(IPPROTO_DONE
);