1 /* $FreeBSD: src/sys/netinet6/ip6_mroute.c,v 1.16.2.1 2002/12/18 21:39:40 suz Exp $ */
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 * 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>
61 #include <kern/locks.h>
64 #include <net/route.h>
65 #include <net/raw_cb.h>
67 #include <netinet/in.h>
68 #include <netinet/in_var.h>
70 #include <netinet/ip6.h>
71 #include <netinet6/ip6_var.h>
72 #include <netinet6/ip6_mroute.h>
73 #include <netinet6/pim6.h>
74 #include <netinet6/pim6_var.h>
77 static MALLOC_DEFINE(M_MRTABLE
, "mf6c", "multicast forwarding cache entry");
80 #define M_HASCL(m) ((m)->m_flags & M_EXT)
82 static int ip6_mdq(struct mbuf
*, struct ifnet
*, struct mf6c
*);
83 static void phyint_send(struct ip6_hdr
*, struct mif6
*, struct mbuf
*);
85 static int set_pim6(int *);
86 static int socket_send(struct socket
*, struct mbuf
*,
87 struct sockaddr_in6
*);
88 static int register_send(struct ip6_hdr
*, struct mif6
*,
91 extern lck_mtx_t
*ip6_mutex
;
93 * Globals. All but ip6_mrouter, ip6_mrtproto and mrt6stat could be static,
94 * except for netstat or debugging purposes.
96 struct socket
*ip6_mrouter
= NULL
;
97 int ip6_mrouter_ver
= 0;
98 int ip6_mrtproto
= IPPROTO_PIM
; /* for netstat only */
99 struct mrt6stat mrt6stat
;
101 #define NO_RTE_FOUND 0x1
102 #define RTE_FOUND 0x2
104 struct mf6c
*mf6ctable
[MF6CTBLSIZ
];
105 u_char n6expire
[MF6CTBLSIZ
];
106 static struct mif6 mif6table
[MAXMIFS
];
108 u_int mrt6debug
= 0; /* debug level */
109 #define DEBUG_MFC 0x02
110 #define DEBUG_FORWARD 0x04
111 #define DEBUG_EXPIRE 0x08
112 #define DEBUG_XMIT 0x10
113 #define DEBUG_REG 0x20
114 #define DEBUG_PIM 0x40
117 static void expire_upcalls(void *);
119 #define EXPIRE_TIMEOUT (hz / 4) /* 4x / second */
120 #define UPCALL_EXPIRE 6 /* number of timeouts */
124 extern struct socket
*ip_mrouter
;
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
;
150 * Hash function for a source, group entry
152 #define MF6CHASH(a, g) MF6CHASHMOD((a).s6_addr32[0] ^ (a).s6_addr32[1] ^ \
153 (a).s6_addr32[2] ^ (a).s6_addr32[3] ^ \
154 (g).s6_addr32[0] ^ (g).s6_addr32[1] ^ \
155 (g).s6_addr32[2] ^ (g).s6_addr32[3])
158 * Find a route for a given origin IPv6 address and Multicast group address.
159 * Quality of service parameter to be added in the future!!!
162 #define MF6CFIND(o, g, rt) do { \
163 struct mf6c *_rt = mf6ctable[MF6CHASH(o,g)]; \
165 mrt6stat.mrt6s_mfc_lookups++; \
167 if (IN6_ARE_ADDR_EQUAL(&_rt->mf6c_origin.sin6_addr, &(o)) && \
168 IN6_ARE_ADDR_EQUAL(&_rt->mf6c_mcastgrp.sin6_addr, &(g)) && \
169 (_rt->mf6c_stall == NULL)) { \
173 _rt = _rt->mf6c_next; \
176 mrt6stat.mrt6s_mfc_misses++; \
181 * Macros to compute elapsed time efficiently
182 * Borrowed from Van Jacobson's scheduling code
184 #define TV_DELTA(a, b, delta) do { \
187 delta = (a).tv_usec - (b).tv_usec; \
188 if ((xxs = (a).tv_sec - (b).tv_sec)) { \
197 delta += (1000000 * xxs); \
202 #define TV_LT(a, b) (((a).tv_usec < (b).tv_usec && \
203 (a).tv_sec <= (b).tv_sec) || (a).tv_sec < (b).tv_sec)
206 #define UPCALL_MAX 50
207 u_long upcall_data
[UPCALL_MAX
+ 1];
208 static void collate();
209 #endif /* UPCALL_TIMING */
211 static int get_sg_cnt(struct sioc_sg_req6
*);
212 static int get_mif6_cnt(struct sioc_mif_req6
*);
213 static int ip6_mrouter_init(struct socket
*, int, int);
214 static int add_m6if(struct mif6ctl
*);
215 static int del_m6if(mifi_t
*);
216 static int add_m6fc(struct mf6cctl
*);
217 static int del_m6fc(struct mf6cctl
*);
220 static struct callout expire_upcalls_ch
;
223 * Handle MRT setsockopt commands to modify the multicast routing tables.
226 ip6_mrouter_set(so
, sopt
)
228 struct sockopt
*sopt
;
236 if (so
!= ip6_mrouter
&& sopt
->sopt_name
!= MRT6_INIT
)
239 switch (sopt
->sopt_name
) {
244 error
= sooptcopyin(sopt
, &optval
, sizeof(optval
),
248 error
= ip6_mrouter_init(so
, optval
, sopt
->sopt_name
);
251 error
= ip6_mrouter_done();
254 error
= sooptcopyin(sopt
, &mifc
, sizeof(mifc
), sizeof(mifc
));
257 error
= add_m6if(&mifc
);
260 error
= sooptcopyin(sopt
, &mfcc
, sizeof(mfcc
), sizeof(mfcc
));
263 error
= add_m6fc(&mfcc
);
266 error
= sooptcopyin(sopt
, &mfcc
, sizeof(mfcc
), sizeof(mfcc
));
269 error
= del_m6fc(&mfcc
);
272 error
= sooptcopyin(sopt
, &mifi
, sizeof(mifi
), sizeof(mifi
));
275 error
= del_m6if(&mifi
);
278 error
= sooptcopyin(sopt
, &optval
, sizeof(optval
),
282 error
= set_pim6(&optval
);
293 * Handle MRT getsockopt commands
296 ip6_mrouter_get(so
, sopt
)
298 struct sockopt
*sopt
;
302 if (so
!= ip6_mrouter
) return EACCES
;
304 switch (sopt
->sopt_name
) {
306 error
= sooptcopyout(sopt
, &pim6
, sizeof(pim6
));
313 * Handle ioctl commands to obtain information from the cache
316 mrt6_ioctl(cmd
, data
)
323 case SIOCGETSGCNT_IN6
:
324 return(get_sg_cnt((struct sioc_sg_req6
*)data
));
325 break; /* for safety */
326 case SIOCGETMIFCNT_IN6
:
327 return(get_mif6_cnt((struct sioc_mif_req6
*)data
));
328 break; /* for safety */
337 * returns the packet, byte, rpf-failure count for the source group provided
341 struct sioc_sg_req6
*req
;
345 MF6CFIND(req
->src
.sin6_addr
, req
->grp
.sin6_addr
, rt
);
347 req
->pktcnt
= rt
->mf6c_pkt_cnt
;
348 req
->bytecnt
= rt
->mf6c_byte_cnt
;
349 req
->wrong_if
= rt
->mf6c_wrong_if
;
353 req
->pktcnt
= req
->bytecnt
= req
->wrong_if
= 0xffffffff;
360 * returns the input and output packet and byte counts on the mif provided
364 struct sioc_mif_req6
*req
;
366 mifi_t mifi
= req
->mifi
;
371 req
->icount
= mif6table
[mifi
].m6_pkt_in
;
372 req
->ocount
= mif6table
[mifi
].m6_pkt_out
;
373 req
->ibytes
= mif6table
[mifi
].m6_bytes_in
;
374 req
->obytes
= mif6table
[mifi
].m6_bytes_out
;
383 if ((*i
!= 1) && (*i
!= 0))
392 * Enable multicast routing
395 ip6_mrouter_init(so
, v
, cmd
)
403 "ip6_mrouter_init: so_type = %d, pr_protocol = %d\n",
404 so
->so_type
, so
->so_proto
->pr_protocol
);
407 if (so
->so_type
!= SOCK_RAW
||
408 so
->so_proto
->pr_protocol
!= IPPROTO_ICMPV6
)
412 return (ENOPROTOOPT
);
414 if (ip6_mrouter
!= NULL
) return EADDRINUSE
;
417 ip6_mrouter_ver
= cmd
;
419 bzero((caddr_t
)mf6ctable
, sizeof(mf6ctable
));
420 bzero((caddr_t
)n6expire
, sizeof(n6expire
));
422 pim6
= 0;/* used for stubbing out/in pim stuff */
425 callout_reset(&expire_upcalls_ch
, EXPIRE_TIMEOUT
,
426 expire_upcalls
, NULL
);
428 timeout(expire_upcalls
, (caddr_t
)NULL
, EXPIRE_TIMEOUT
);
433 log(LOG_DEBUG
, "ip6_mrouter_init\n");
440 * Disable multicast routing
448 struct in6_ifreq ifr
;
454 * For each phyint in use, disable promiscuous reception of all IPv6
460 * If there is still IPv4 multicast routing daemon,
461 * we remain interfaces to receive all muliticasted packets.
462 * XXX: there may be an interface in which the IPv4 multicast
463 * daemon is not interested...
469 for (mifi
= 0; mifi
< nummifs
; mifi
++) {
470 if (mif6table
[mifi
].m6_ifp
&&
471 !(mif6table
[mifi
].m6_flags
& MIFF_REGISTER
)) {
472 ifr
.ifr_addr
.sin6_family
= AF_INET6
;
473 ifr
.ifr_addr
.sin6_addr
= in6addr_any
;
474 ifp
= mif6table
[mifi
].m6_ifp
;
476 dlil_ioctl(0, ifp
, SIOCDELMULTI
,
479 (*ifp
->if_ioctl
)(ifp
, SIOCDELMULTI
,
486 bzero((caddr_t
)qtable
, sizeof(qtable
));
487 bzero((caddr_t
)tbftable
, sizeof(tbftable
));
489 bzero((caddr_t
)mif6table
, sizeof(mif6table
));
492 pim6
= 0; /* used to stub out/in pim specific code */
495 callout_stop(&expire_upcalls_ch
);
497 untimeout(expire_upcalls
, (caddr_t
)NULL
);
501 * Free all multicast forwarding cache entries.
502 *###LD 5/27 needs locking
504 for (i
= 0; i
< MF6CTBLSIZ
; i
++) {
509 for (rte
= rt
->mf6c_stall
; rte
!= NULL
; ) {
510 struct rtdetq
*n
= rte
->next
;
513 FREE(rte
, M_MRTABLE
);
518 FREE(frt
, M_MRTABLE
);
522 bzero((caddr_t
)mf6ctable
, sizeof(mf6ctable
));
525 * Reset de-encapsulation cache
535 log(LOG_DEBUG
, "ip6_mrouter_done\n");
541 static struct sockaddr_in6 sin6
= { sizeof(sin6
), AF_INET6
};
544 * Add a mif to the mif table
548 struct mif6ctl
*mifcp
;
554 struct tbf
*m_tbf
= tbftable
+ mifcp
->mif6c_mifi
;
557 if (mifcp
->mif6c_mifi
>= MAXMIFS
)
559 mifp
= mif6table
+ mifcp
->mif6c_mifi
;
561 return EADDRINUSE
; /* XXX: is it appropriate? */
562 if (mifcp
->mif6c_pifi
== 0 || mifcp
->mif6c_pifi
> if_index
)
564 ifp
= ifindex2ifnet
[mifcp
->mif6c_pifi
];
566 if (mifcp
->mif6c_flags
& MIFF_REGISTER
) {
567 if (reg_mif_num
== (mifi_t
)-1) {
568 multicast_register_if
.if_name
= "register_mif";
569 multicast_register_if
.if_flags
|= IFF_LOOPBACK
;
570 multicast_register_if
.if_index
= mifcp
->mif6c_mifi
;
571 reg_mif_num
= mifcp
->mif6c_mifi
;
574 ifp
= &multicast_register_if
;
578 /* Make sure the interface supports multicast */
579 if ((ifp
->if_flags
& IFF_MULTICAST
) == 0)
582 error
= if_allmulti(ifp
, 1);
587 mifp
->m6_flags
= mifcp
->mif6c_flags
;
590 /* scaling up here allows division by 1024 in critical code */
591 mifp
->m6_rate_limit
= mifcp
->mif6c_rate_limit
* 1024 / 1000;
593 /* initialize per mif pkt counters */
595 mifp
->m6_pkt_out
= 0;
596 mifp
->m6_bytes_in
= 0;
597 mifp
->m6_bytes_out
= 0;
599 /* Adjust nummifs up if the mifi is higher than nummifs */
600 if (nummifs
<= mifcp
->mif6c_mifi
)
601 nummifs
= mifcp
->mif6c_mifi
+ 1;
606 "add_mif #%d, phyint %s%d\n",
608 ifp
->if_name
, ifp
->if_unit
);
615 * Delete a mif from the mif table
621 struct mif6
*mifp
= mif6table
+ *mifip
;
625 if (*mifip
>= nummifs
)
627 if (mifp
->m6_ifp
== NULL
)
631 if (!(mifp
->m6_flags
& MIFF_REGISTER
)) {
633 * XXX: what if there is yet IPv4 multicast daemon
634 * using the interface?
642 bzero((caddr_t
)qtable
[*mifip
], sizeof(qtable
[*mifip
]));
643 bzero((caddr_t
)mifp
->m6_tbf
, sizeof(*(mifp
->m6_tbf
)));
645 bzero((caddr_t
)mifp
, sizeof(*mifp
));
647 /* Adjust nummifs down */
648 for (mifi
= nummifs
; mifi
> 0; mifi
--)
649 if (mif6table
[mifi
- 1].m6_ifp
)
656 log(LOG_DEBUG
, "del_m6if %d, nummifs %d\n", *mifip
, nummifs
);
667 struct mf6cctl
*mfccp
;
675 MF6CFIND(mfccp
->mf6cc_origin
.sin6_addr
,
676 mfccp
->mf6cc_mcastgrp
.sin6_addr
, rt
);
678 /* If an entry already exists, just update the fields */
681 if (mrt6debug
& DEBUG_MFC
)
683 "add_m6fc no upcall h %d o %s g %s p %x\n",
684 ip6_sprintf(&mfccp
->mf6cc_origin
.sin6_addr
),
685 ip6_sprintf(&mfccp
->mf6cc_mcastgrp
.sin6_addr
),
686 mfccp
->mf6cc_parent
);
689 rt
->mf6c_parent
= mfccp
->mf6cc_parent
;
690 rt
->mf6c_ifset
= mfccp
->mf6cc_ifset
;
695 * Find the entry for which the upcall was made and update
697 hash
= MF6CHASH(mfccp
->mf6cc_origin
.sin6_addr
,
698 mfccp
->mf6cc_mcastgrp
.sin6_addr
);
699 for (rt
= mf6ctable
[hash
], nstl
= 0; rt
; rt
= rt
->mf6c_next
) {
700 if (IN6_ARE_ADDR_EQUAL(&rt
->mf6c_origin
.sin6_addr
,
701 &mfccp
->mf6cc_origin
.sin6_addr
) &&
702 IN6_ARE_ADDR_EQUAL(&rt
->mf6c_mcastgrp
.sin6_addr
,
703 &mfccp
->mf6cc_mcastgrp
.sin6_addr
) &&
704 (rt
->mf6c_stall
!= NULL
)) {
708 "add_m6fc: %s o %s g %s p %x dbx %p\n",
709 "multiple kernel entries",
710 ip6_sprintf(&mfccp
->mf6cc_origin
.sin6_addr
),
711 ip6_sprintf(&mfccp
->mf6cc_mcastgrp
.sin6_addr
),
712 mfccp
->mf6cc_parent
, rt
->mf6c_stall
);
715 if (mrt6debug
& DEBUG_MFC
)
717 "add_m6fc o %s g %s p %x dbg %x\n",
718 ip6_sprintf(&mfccp
->mf6cc_origin
.sin6_addr
),
719 ip6_sprintf(&mfccp
->mf6cc_mcastgrp
.sin6_addr
),
720 mfccp
->mf6cc_parent
, rt
->mf6c_stall
);
723 rt
->mf6c_origin
= mfccp
->mf6cc_origin
;
724 rt
->mf6c_mcastgrp
= mfccp
->mf6cc_mcastgrp
;
725 rt
->mf6c_parent
= mfccp
->mf6cc_parent
;
726 rt
->mf6c_ifset
= mfccp
->mf6cc_ifset
;
727 /* initialize pkt counters per src-grp */
728 rt
->mf6c_pkt_cnt
= 0;
729 rt
->mf6c_byte_cnt
= 0;
730 rt
->mf6c_wrong_if
= 0;
732 rt
->mf6c_expire
= 0; /* Don't clean this guy up */
735 /* free packets Qed at the end of this entry */
736 for (rte
= rt
->mf6c_stall
; rte
!= NULL
; ) {
737 struct rtdetq
*n
= rte
->next
;
738 ip6_mdq(rte
->m
, rte
->ifp
, rt
);
742 #endif /* UPCALL_TIMING */
743 FREE(rte
, M_MRTABLE
);
746 rt
->mf6c_stall
= NULL
;
751 * It is possible that an entry is being inserted without an upcall
755 if (mrt6debug
& DEBUG_MFC
)
756 log(LOG_DEBUG
,"add_mfc no upcall h %d o %s g %s p %x\n",
758 ip6_sprintf(&mfccp
->mf6cc_origin
.sin6_addr
),
759 ip6_sprintf(&mfccp
->mf6cc_mcastgrp
.sin6_addr
),
760 mfccp
->mf6cc_parent
);
763 for (rt
= mf6ctable
[hash
]; 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
)) {
770 rt
->mf6c_origin
= mfccp
->mf6cc_origin
;
771 rt
->mf6c_mcastgrp
= mfccp
->mf6cc_mcastgrp
;
772 rt
->mf6c_parent
= mfccp
->mf6cc_parent
;
773 rt
->mf6c_ifset
= mfccp
->mf6cc_ifset
;
774 /* initialize pkt counters per src-grp */
775 rt
->mf6c_pkt_cnt
= 0;
776 rt
->mf6c_byte_cnt
= 0;
777 rt
->mf6c_wrong_if
= 0;
785 /* no upcall, so make a new entry */
786 rt
= (struct mf6c
*)_MALLOC(sizeof(*rt
), M_MRTABLE
,
793 /* insert new entry at head of hash chain */
794 rt
->mf6c_origin
= mfccp
->mf6cc_origin
;
795 rt
->mf6c_mcastgrp
= mfccp
->mf6cc_mcastgrp
;
796 rt
->mf6c_parent
= mfccp
->mf6cc_parent
;
797 rt
->mf6c_ifset
= mfccp
->mf6cc_ifset
;
798 /* initialize pkt counters per src-grp */
799 rt
->mf6c_pkt_cnt
= 0;
800 rt
->mf6c_byte_cnt
= 0;
801 rt
->mf6c_wrong_if
= 0;
803 rt
->mf6c_stall
= NULL
;
805 /* link into table */
806 rt
->mf6c_next
= mf6ctable
[hash
];
807 mf6ctable
[hash
] = rt
;
815 * collect delay statistics on the upcalls
829 TV_DELTA(tp
, *t
, delta
);
838 #endif /* UPCALL_TIMING */
841 * Delete an mfc entry
845 struct mf6cctl
*mfccp
;
847 struct sockaddr_in6 origin
;
848 struct sockaddr_in6 mcastgrp
;
853 origin
= mfccp
->mf6cc_origin
;
854 mcastgrp
= mfccp
->mf6cc_mcastgrp
;
855 hash
= MF6CHASH(origin
.sin6_addr
, mcastgrp
.sin6_addr
);
858 if (mrt6debug
& DEBUG_MFC
)
859 log(LOG_DEBUG
,"del_m6fc orig %s mcastgrp %s\n",
860 ip6_sprintf(&origin
.sin6_addr
),
861 ip6_sprintf(&mcastgrp
.sin6_addr
));
865 nptr
= &mf6ctable
[hash
];
866 while ((rt
= *nptr
) != NULL
) {
867 if (IN6_ARE_ADDR_EQUAL(&origin
.sin6_addr
,
868 &rt
->mf6c_origin
.sin6_addr
) &&
869 IN6_ARE_ADDR_EQUAL(&mcastgrp
.sin6_addr
,
870 &rt
->mf6c_mcastgrp
.sin6_addr
) &&
871 rt
->mf6c_stall
== NULL
)
874 nptr
= &rt
->mf6c_next
;
877 return EADDRNOTAVAIL
;
880 *nptr
= rt
->mf6c_next
;
888 socket_send(s
, mm
, src
)
891 struct sockaddr_in6
*src
;
893 //### LD 5/27/04 needs locking!
896 if (sbappendaddr(&s
->so_rcv
,
897 (struct sockaddr
*)src
,
898 mm
, (struct mbuf
*)0, NULL
) != 0) {
907 * IPv6 multicast forwarding function. This function assumes that the packet
908 * pointed to by "ip6" has arrived on (or is about to be sent to) the interface
909 * pointed to by "ifp", and the packet is to be relayed to other networks
910 * that have members of the packet's destination IPv6 multicast group.
912 * The packet is returned unscathed to the caller, unless it is
913 * erroneous, in which case a non-zero return value tells the caller to
918 ip6_mforward(ip6
, ifp
, m
)
928 struct timeval timenow
;
931 if (mrt6debug
& DEBUG_FORWARD
)
932 log(LOG_DEBUG
, "ip6_mforward: src %s, dst %s, ifindex %d\n",
933 ip6_sprintf(&ip6
->ip6_src
), ip6_sprintf(&ip6
->ip6_dst
),
938 * Don't forward a packet with Hop limit of zero or one,
939 * or a packet destined to a local-only group.
941 if (ip6
->ip6_hlim
<= 1 || IN6_IS_ADDR_MC_NODELOCAL(&ip6
->ip6_dst
) ||
942 IN6_IS_ADDR_MC_LINKLOCAL(&ip6
->ip6_dst
))
947 * Source address check: do not forward packets with unspecified
948 * source. It was discussed in July 2000, on ipngwg mailing list.
949 * This is rather more serious than unicast cases, because some
950 * MLD packets can be sent with the unspecified source address
951 * (although such packets must normally set 1 to the hop limit field).
953 getmicrotime(&timenow
);
954 if (IN6_IS_ADDR_UNSPECIFIED(&ip6
->ip6_src
)) {
955 ip6stat
.ip6s_cantforward
++;
956 if (ip6_log_time
+ ip6_log_interval
< timenow
.tv_sec
) {
957 ip6_log_time
= timenow
.tv_sec
;
960 "from %s to %s nxt %d received on %s\n",
961 ip6_sprintf(&ip6
->ip6_src
),
962 ip6_sprintf(&ip6
->ip6_dst
),
964 if_name(m
->m_pkthdr
.rcvif
));
970 * Determine forwarding mifs from the forwarding cache table
973 MF6CFIND(ip6
->ip6_src
, ip6
->ip6_dst
, rt
);
975 /* Entry exists, so forward if necessary */
978 return (ip6_mdq(m
, ifp
, rt
));
981 * If we don't have a route for packet's origin,
982 * Make a copy of the packet &
983 * send message to routing daemon
994 #endif /* UPCALL_TIMING */
996 mrt6stat
.mrt6s_no_route
++;
998 if (mrt6debug
& (DEBUG_FORWARD
| DEBUG_MFC
))
999 log(LOG_DEBUG
, "ip6_mforward: no rte s %s g %s\n",
1000 ip6_sprintf(&ip6
->ip6_src
),
1001 ip6_sprintf(&ip6
->ip6_dst
));
1005 * Allocate mbufs early so that we don't do extra work if we
1006 * are just going to fail anyway.
1008 rte
= (struct rtdetq
*)_MALLOC(sizeof(*rte
), M_MRTABLE
,
1014 mb0
= m_copy(m
, 0, M_COPYALL
);
1016 * Pullup packet header if needed before storing it,
1017 * as other references may modify it in the meantime.
1020 (M_HASCL(mb0
) || mb0
->m_len
< sizeof(struct ip6_hdr
)))
1021 mb0
= m_pullup(mb0
, sizeof(struct ip6_hdr
));
1023 FREE(rte
, M_MRTABLE
);
1028 /* is there an upcall waiting for this packet? */
1029 hash
= MF6CHASH(ip6
->ip6_src
, ip6
->ip6_dst
);
1030 for (rt
= mf6ctable
[hash
]; rt
; rt
= rt
->mf6c_next
) {
1031 if (IN6_ARE_ADDR_EQUAL(&ip6
->ip6_src
,
1032 &rt
->mf6c_origin
.sin6_addr
) &&
1033 IN6_ARE_ADDR_EQUAL(&ip6
->ip6_dst
,
1034 &rt
->mf6c_mcastgrp
.sin6_addr
) &&
1035 (rt
->mf6c_stall
!= NULL
))
1042 struct omrt6msg
*oim
;
1045 /* no upcall, so make a new entry */
1046 rt
= (struct mf6c
*)_MALLOC(sizeof(*rt
), M_MRTABLE
,
1049 FREE(rte
, M_MRTABLE
);
1055 * Make a copy of the header to send to the user
1058 mm
= m_copy(mb0
, 0, sizeof(struct ip6_hdr
));
1061 FREE(rte
, M_MRTABLE
);
1063 FREE(rt
, M_MRTABLE
);
1069 * Send message to routing daemon
1071 sin6
.sin6_addr
= ip6
->ip6_src
;
1077 switch (ip6_mrouter_ver
) {
1080 oim
= mtod(mm
, struct omrt6msg
*);
1081 oim
->im6_msgtype
= MRT6MSG_NOCACHE
;
1086 im
= mtod(mm
, struct mrt6msg
*);
1087 im
->im6_msgtype
= MRT6MSG_NOCACHE
;
1091 FREE(rte
, M_MRTABLE
);
1093 FREE(rt
, M_MRTABLE
);
1099 if (mrt6debug
& DEBUG_FORWARD
)
1101 "getting the iif info in the kernel\n");
1104 for (mifp
= mif6table
, mifi
= 0;
1105 mifi
< nummifs
&& mifp
->m6_ifp
!= ifp
;
1109 switch (ip6_mrouter_ver
) {
1112 oim
->im6_mif
= mifi
;
1120 if (socket_send(ip6_mrouter
, mm
, &sin6
) < 0) {
1121 log(LOG_WARNING
, "ip6_mforward: ip6_mrouter "
1122 "socket queue full\n");
1123 mrt6stat
.mrt6s_upq_sockfull
++;
1124 FREE(rte
, M_MRTABLE
);
1126 FREE(rt
, M_MRTABLE
);
1131 mrt6stat
.mrt6s_upcalls
++;
1133 /* insert new entry at head of hash chain */
1134 bzero(rt
, sizeof(*rt
));
1135 rt
->mf6c_origin
.sin6_family
= AF_INET6
;
1136 rt
->mf6c_origin
.sin6_len
= sizeof(struct sockaddr_in6
);
1137 rt
->mf6c_origin
.sin6_addr
= ip6
->ip6_src
;
1138 rt
->mf6c_mcastgrp
.sin6_family
= AF_INET6
;
1139 rt
->mf6c_mcastgrp
.sin6_len
= sizeof(struct sockaddr_in6
);
1140 rt
->mf6c_mcastgrp
.sin6_addr
= ip6
->ip6_dst
;
1141 rt
->mf6c_expire
= UPCALL_EXPIRE
;
1143 rt
->mf6c_parent
= MF6C_INCOMPLETE_PARENT
;
1145 /* link into table */
1146 rt
->mf6c_next
= mf6ctable
[hash
];
1147 mf6ctable
[hash
] = rt
;
1148 /* Add this entry to the end of the queue */
1149 rt
->mf6c_stall
= rte
;
1151 /* determine if q has overflowed */
1155 for (p
= &rt
->mf6c_stall
; *p
!= NULL
; p
= &(*p
)->next
)
1156 if (++npkts
> MAX_UPQ6
) {
1157 mrt6stat
.mrt6s_upq_ovflw
++;
1158 FREE(rte
, M_MRTABLE
);
1164 /* Add this entry to the end of the queue */
1173 #endif /* UPCALL_TIMING */
1182 * Clean up cache entries if upcalls are not serviced
1183 * Call from the Slow Timeout mechanism, every half second.
1186 expire_upcalls(unused
)
1190 struct mf6c
*mfc
, **nptr
;
1195 for (i
= 0; i
< MF6CTBLSIZ
; i
++) {
1196 if (n6expire
[i
] == 0)
1198 nptr
= &mf6ctable
[i
];
1199 while ((mfc
= *nptr
) != NULL
) {
1200 rte
= mfc
->mf6c_stall
;
1202 * Skip real cache entries
1203 * Make sure it wasn't marked to not expire (shouldn't happen)
1207 mfc
->mf6c_expire
!= 0 &&
1208 --mfc
->mf6c_expire
== 0) {
1210 if (mrt6debug
& DEBUG_EXPIRE
)
1211 log(LOG_DEBUG
, "expire_upcalls: expiring (%s %s)\n",
1212 ip6_sprintf(&mfc
->mf6c_origin
.sin6_addr
),
1213 ip6_sprintf(&mfc
->mf6c_mcastgrp
.sin6_addr
));
1216 * drop all the packets
1217 * free the mbuf with the pkt, if, timing info
1220 struct rtdetq
*n
= rte
->next
;
1222 FREE(rte
, M_MRTABLE
);
1224 } while (rte
!= NULL
);
1225 mrt6stat
.mrt6s_cache_cleanups
++;
1228 *nptr
= mfc
->mf6c_next
;
1229 FREE(mfc
, M_MRTABLE
);
1231 nptr
= &mfc
->mf6c_next
;
1238 callout_reset(&expire_upcalls_ch
, EXPIRE_TIMEOUT
,
1239 expire_upcalls
, NULL
);
1241 timeout(expire_upcalls
, (caddr_t
)NULL
, EXPIRE_TIMEOUT
);
1246 * Packet forwarding routine once entry in the cache is made
1254 struct ip6_hdr
*ip6
= mtod(m
, struct ip6_hdr
*);
1257 int plen
= m
->m_pkthdr
.len
;
1260 * Macro to send packet on mif. Since RSVP packets don't get counted on
1261 * input, they shouldn't get counted on output, so statistics keeping is
1265 #define MC6_SEND(ip6, mifp, m) do { \
1266 if ((mifp)->m6_flags & MIFF_REGISTER) \
1267 register_send((ip6), (mifp), (m)); \
1269 phyint_send((ip6), (mifp), (m)); \
1273 * Don't forward if it didn't arrive from the parent mif
1276 mifi
= rt
->mf6c_parent
;
1277 if ((mifi
>= nummifs
) || (mif6table
[mifi
].m6_ifp
!= ifp
)) {
1278 /* came in the wrong interface */
1280 if (mrt6debug
& DEBUG_FORWARD
)
1282 "wrong if: ifid %d mifi %d mififid %x\n",
1283 ifp
->if_index
, mifi
,
1284 mif6table
[mifi
].m6_ifp
->if_index
);
1286 mrt6stat
.mrt6s_wrong_if
++;
1287 rt
->mf6c_wrong_if
++;
1289 * If we are doing PIM processing, and we are forwarding
1290 * packets on this interface, send a message to the
1293 /* have to make sure this is a valid mif */
1294 if (mifi
< nummifs
&& mif6table
[mifi
].m6_ifp
)
1295 if (pim6
&& (m
->m_flags
& M_LOOP
) == 0) {
1297 * Check the M_LOOP flag to avoid an
1298 * unnecessary PIM assert.
1299 * XXX: M_LOOP is an ad-hoc hack...
1301 static struct sockaddr_in6 sin6
=
1302 { sizeof(sin6
), AF_INET6
};
1307 struct omrt6msg
*oim
;
1310 mm
= m_copy(m
, 0, sizeof(struct ip6_hdr
));
1313 mm
->m_len
< sizeof(struct ip6_hdr
)))
1314 mm
= m_pullup(mm
, sizeof(struct ip6_hdr
));
1322 switch (ip6_mrouter_ver
) {
1325 oim
= mtod(mm
, struct omrt6msg
*);
1326 oim
->im6_msgtype
= MRT6MSG_WRONGMIF
;
1331 im
= mtod(mm
, struct mrt6msg
*);
1332 im
->im6_msgtype
= MRT6MSG_WRONGMIF
;
1340 for (mifp
= mif6table
, iif
= 0;
1341 iif
< nummifs
&& mifp
&&
1342 mifp
->m6_ifp
!= ifp
;
1346 switch (ip6_mrouter_ver
) {
1350 sin6
.sin6_addr
= oim
->im6_src
;
1355 sin6
.sin6_addr
= im
->im6_src
;
1359 mrt6stat
.mrt6s_upcalls
++;
1361 if (socket_send(ip6_mrouter
, mm
, &sin6
) < 0) {
1364 log(LOG_WARNING
, "mdq, ip6_mrouter socket queue full\n");
1366 ++mrt6stat
.mrt6s_upq_sockfull
;
1368 } /* if socket Q full */
1371 } /* if wrong iif */
1373 /* If I sourced this packet, it counts as output, else it was input. */
1374 if (m
->m_pkthdr
.rcvif
== NULL
) {
1375 /* XXX: is rcvif really NULL when output?? */
1376 mif6table
[mifi
].m6_pkt_out
++;
1377 mif6table
[mifi
].m6_bytes_out
+= plen
;
1379 mif6table
[mifi
].m6_pkt_in
++;
1380 mif6table
[mifi
].m6_bytes_in
+= plen
;
1383 rt
->mf6c_byte_cnt
+= plen
;
1386 * For each mif, forward a copy of the packet if there are group
1387 * members downstream on the interface.
1389 for (mifp
= mif6table
, mifi
= 0; mifi
< nummifs
; mifp
++, mifi
++)
1390 if (IF_ISSET(mifi
, &rt
->mf6c_ifset
)) {
1392 * check if the outgoing packet is going to break
1394 * XXX For packets through PIM register tunnel
1395 * interface, we believe a routing daemon.
1397 if ((mif6table
[rt
->mf6c_parent
].m6_flags
&
1398 MIFF_REGISTER
) == 0 &&
1399 (mif6table
[mifi
].m6_flags
& MIFF_REGISTER
) == 0 &&
1400 (in6_addr2scopeid(ifp
, &ip6
->ip6_dst
) !=
1401 in6_addr2scopeid(mif6table
[mifi
].m6_ifp
,
1403 in6_addr2scopeid(ifp
, &ip6
->ip6_src
) !=
1404 in6_addr2scopeid(mif6table
[mifi
].m6_ifp
,
1406 ip6stat
.ip6s_badscope
++;
1411 mifp
->m6_bytes_out
+= plen
;
1412 MC6_SEND(ip6
, mifp
, m
);
1418 phyint_send(ip6
, mifp
, m
)
1419 struct ip6_hdr
*ip6
;
1423 struct mbuf
*mb_copy
;
1424 struct ifnet
*ifp
= mifp
->m6_ifp
;
1426 int s
= splnet(); /* needs to protect static "ro" below. */
1427 static struct route_in6 ro
;
1428 struct in6_multi
*in6m
;
1429 struct sockaddr_in6
*dst6
;
1432 * Make a new reference to the packet; make sure that
1433 * the IPv6 header is actually copied, not just referenced,
1434 * so that ip6_output() only scribbles on the copy.
1436 mb_copy
= m_copy(m
, 0, M_COPYALL
);
1438 (M_HASCL(mb_copy
) || mb_copy
->m_len
< sizeof(struct ip6_hdr
)))
1439 mb_copy
= m_pullup(mb_copy
, sizeof(struct ip6_hdr
));
1440 if (mb_copy
== NULL
) {
1444 /* set MCAST flag to the outgoing packet */
1445 mb_copy
->m_flags
|= M_MCAST
;
1448 * If we sourced the packet, call ip6_output since we may devide
1449 * the packet into fragments when the packet is too big for the
1450 * outgoing interface.
1451 * Otherwise, we can simply send the packet to the interface
1454 if (m
->m_pkthdr
.rcvif
== NULL
) {
1455 struct ip6_moptions im6o
;
1457 im6o
.im6o_multicast_ifp
= ifp
;
1458 /* XXX: ip6_output will override ip6->ip6_hlim */
1459 im6o
.im6o_multicast_hlim
= ip6
->ip6_hlim
;
1460 im6o
.im6o_multicast_loop
= 1;
1461 error
= ip6_output(mb_copy
, NULL
, &ro
,
1462 IPV6_FORWARDING
, &im6o
, NULL
, 0);
1466 if (mrt6debug
& DEBUG_XMIT
)
1467 log(LOG_DEBUG
, "phyint_send on mif %d err %d\n",
1468 mifp
- mif6table
, error
);
1475 * If we belong to the destination multicast group
1476 * on the outgoing interface, loop back a copy.
1478 dst6
= (struct sockaddr_in6
*)&ro
.ro_dst
;
1479 IN6_LOOKUP_MULTI(ip6
->ip6_dst
, ifp
, in6m
);
1481 dst6
->sin6_len
= sizeof(struct sockaddr_in6
);
1482 dst6
->sin6_family
= AF_INET6
;
1483 dst6
->sin6_addr
= ip6
->ip6_dst
;
1484 ip6_mloopback(ifp
, m
, (struct sockaddr_in6
*)&ro
.ro_dst
);
1487 * Put the packet into the sending queue of the outgoing interface
1488 * if it would fit in the MTU of the interface.
1490 if (mb_copy
->m_pkthdr
.len
<= ifp
->if_mtu
|| ifp
->if_mtu
< IPV6_MMTU
) {
1491 dst6
->sin6_len
= sizeof(struct sockaddr_in6
);
1492 dst6
->sin6_family
= AF_INET6
;
1493 dst6
->sin6_addr
= ip6
->ip6_dst
;
1495 * We just call if_output instead of nd6_output here, since
1496 * we need no ND for a multicast forwarded packet...right?
1499 /* Make sure the HW checksum flags are cleaned before sending the packet */
1501 mb_copy
->m_pkthdr
.rcvif
= 0;
1502 mb_copy
->m_pkthdr
.csum_data
= 0;
1503 mb_copy
->m_pkthdr
.csum_flags
= 0;
1505 lck_mtx_unlock(ip6_mutex
);
1506 error
= dlil_output(ifp
, PF_INET6
, mb_copy
,
1507 NULL
, (struct sockaddr
*)&ro
.ro_dst
, 0);
1508 lck_mtx_lock(ip6_mutex
);
1510 error
= (*ifp
->if_output
)(ifp
, mb_copy
,
1511 (struct sockaddr
*)&ro
.ro_dst
,
1515 if (mrt6debug
& DEBUG_XMIT
)
1516 log(LOG_DEBUG
, "phyint_send on mif %d err %d\n",
1517 mifp
- mif6table
, error
);
1521 icmp6_error(mb_copy
, ICMP6_PACKET_TOO_BIG
, 0, ifp
->if_mtu
);
1524 if (mrt6debug
& DEBUG_XMIT
)
1526 "phyint_send: packet too big on %s o %s g %s"
1527 " size %d(discarded)\n",
1529 ip6_sprintf(&ip6
->ip6_src
),
1530 ip6_sprintf(&ip6
->ip6_dst
),
1531 mb_copy
->m_pkthdr
.len
);
1532 #endif /* MRT6DEBUG */
1533 m_freem(mb_copy
); /* simply discard the packet */
1541 register_send(ip6
, mif
, m
)
1542 struct ip6_hdr
*ip6
;
1547 int i
, len
= m
->m_pkthdr
.len
;
1548 static struct sockaddr_in6 sin6
= { sizeof(sin6
), AF_INET6
};
1549 struct mrt6msg
*im6
;
1553 log(LOG_DEBUG
, "** IPv6 register_send **\n src %s dst %s\n",
1554 ip6_sprintf(&ip6
->ip6_src
), ip6_sprintf(&ip6
->ip6_dst
));
1556 ++pim6stat
.pim6s_snd_registers
;
1558 /* Make a copy of the packet to send to the user level process */
1559 MGETHDR(mm
, M_DONTWAIT
, MT_HEADER
);
1562 mm
->m_pkthdr
.rcvif
= NULL
;
1563 mm
->m_data
+= max_linkhdr
;
1564 mm
->m_len
= sizeof(struct ip6_hdr
);
1566 if ((mm
->m_next
= m_copy(m
, 0, M_COPYALL
)) == NULL
) {
1570 i
= MHLEN
- M_LEADINGSPACE(mm
);
1573 mm
= m_pullup(mm
, i
);
1578 /* TODO: check it! */
1579 mm
->m_pkthdr
.len
= len
+ sizeof(struct ip6_hdr
);
1582 * Send message to routing daemon
1584 sin6
.sin6_addr
= ip6
->ip6_src
;
1586 im6
= mtod(mm
, struct mrt6msg
*);
1587 im6
->im6_msgtype
= MRT6MSG_WHOLEPKT
;
1590 im6
->im6_mif
= mif
- mif6table
;
1592 /* iif info is not given for reg. encap.n */
1593 mrt6stat
.mrt6s_upcalls
++;
1595 if (socket_send(ip6_mrouter
, mm
, &sin6
) < 0) {
1599 "register_send: ip6_mrouter socket queue full\n");
1601 ++mrt6stat
.mrt6s_upq_sockfull
;
1608 * PIM sparse mode hook
1609 * Receives the pim control messages, and passes them up to the listening
1610 * socket, using rip6_input.
1611 * The only message processed is the REGISTER pim message; the pim header
1612 * is stripped off, and the inner packet is passed to register_mforward.
1615 pim6_input(mp
, offp
)
1619 struct pim
*pim
; /* pointer to a pim struct */
1620 struct ip6_hdr
*ip6
;
1622 struct mbuf
*m
= *mp
;
1627 ++pim6stat
.pim6s_rcv_total
;
1629 ip6
= mtod(m
, struct ip6_hdr
*);
1630 pimlen
= m
->m_pkthdr
.len
- *offp
;
1631 proto
= ip6
->ip6_nxt
;
1636 if (pimlen
< PIM_MINLEN
) {
1637 ++pim6stat
.pim6s_rcv_tooshort
;
1639 if (mrt6debug
& DEBUG_PIM
)
1640 log(LOG_DEBUG
,"pim6_input: PIM packet too short\n");
1643 return(IPPROTO_DONE
);
1647 * if the packet is at least as big as a REGISTER, go ahead
1648 * and grab the PIM REGISTER header size, to avoid another
1649 * possible m_pullup() later.
1651 * PIM_MINLEN == pimhdr + u_int32 == 8
1652 * PIM6_REG_MINLEN == pimhdr + reghdr + eip6hdr == 4 + 4 + 40
1654 minlen
= (pimlen
>= PIM6_REG_MINLEN
) ? PIM6_REG_MINLEN
: PIM_MINLEN
;
1657 * Make sure that the IP6 and PIM headers in contiguous memory, and
1658 * possibly the PIM REGISTER header
1660 #ifndef PULLDOWN_TEST
1661 IP6_EXTHDR_CHECK(m
, off
, minlen
, return IPPROTO_DONE
);
1662 /* adjust pointer */
1663 ip6
= mtod(m
, struct ip6_hdr
*);
1665 /* adjust mbuf to point to the PIM header */
1666 pim
= (struct pim
*)((caddr_t
)ip6
+ off
);
1668 IP6_EXTHDR_GET(pim
, struct pim
*, m
, off
, minlen
);
1670 pim6stat
.pim6s_rcv_tooshort
++;
1671 return IPPROTO_DONE
;
1675 #define PIM6_CHECKSUM
1676 #ifdef PIM6_CHECKSUM
1681 * Validate checksum.
1682 * If PIM REGISTER, exclude the data packet
1684 if (pim
->pim_type
== PIM_REGISTER
)
1685 cksumlen
= PIM_MINLEN
;
1689 if (in6_cksum(m
, IPPROTO_PIM
, off
, cksumlen
)) {
1690 ++pim6stat
.pim6s_rcv_badsum
;
1692 if (mrt6debug
& DEBUG_PIM
)
1694 "pim6_input: invalid checksum\n");
1697 return(IPPROTO_DONE
);
1700 #endif /* PIM_CHECKSUM */
1702 /* PIM version check */
1703 if (pim
->pim_ver
!= PIM_VERSION
) {
1704 ++pim6stat
.pim6s_rcv_badversion
;
1707 "pim6_input: incorrect version %d, expecting %d\n",
1708 pim
->pim_ver
, PIM_VERSION
);
1711 return(IPPROTO_DONE
);
1714 if (pim
->pim_type
== PIM_REGISTER
) {
1716 * since this is a REGISTER, we'll make a copy of the register
1717 * headers ip6+pim+u_int32_t+encap_ip6, to be passed up to the
1720 static struct sockaddr_in6 dst
= { sizeof(dst
), AF_INET6
};
1723 struct ip6_hdr
*eip6
;
1727 ++pim6stat
.pim6s_rcv_registers
;
1729 if ((reg_mif_num
>= nummifs
) || (reg_mif_num
== (mifi_t
) -1)) {
1731 if (mrt6debug
& DEBUG_PIM
)
1733 "pim6_input: register mif not set: %d\n",
1737 return(IPPROTO_DONE
);
1740 reghdr
= (u_int32_t
*)(pim
+ 1);
1742 if ((ntohl(*reghdr
) & PIM_NULL_REGISTER
))
1743 goto pim6_input_to_daemon
;
1748 if (pimlen
< PIM6_REG_MINLEN
) {
1749 ++pim6stat
.pim6s_rcv_tooshort
;
1750 ++pim6stat
.pim6s_rcv_badregisters
;
1753 "pim6_input: register packet size too "
1754 "small %d from %s\n",
1755 pimlen
, ip6_sprintf(&ip6
->ip6_src
));
1758 return(IPPROTO_DONE
);
1761 eip6
= (struct ip6_hdr
*) (reghdr
+ 1);
1763 if (mrt6debug
& DEBUG_PIM
)
1765 "pim6_input[register], eip6: %s -> %s, "
1767 ip6_sprintf(&eip6
->ip6_src
),
1768 ip6_sprintf(&eip6
->ip6_dst
),
1769 ntohs(eip6
->ip6_plen
));
1772 /* verify the version number of the inner packet */
1773 if ((eip6
->ip6_vfc
& IPV6_VERSION_MASK
) != IPV6_VERSION
) {
1774 ++pim6stat
.pim6s_rcv_badregisters
;
1776 log(LOG_DEBUG
, "pim6_input: invalid IP version (%d) "
1777 "of the inner packet\n",
1778 (eip6
->ip6_vfc
& IPV6_VERSION
));
1781 return(IPPROTO_NONE
);
1784 /* verify the inner packet is destined to a mcast group */
1785 if (!IN6_IS_ADDR_MULTICAST(&eip6
->ip6_dst
)) {
1786 ++pim6stat
.pim6s_rcv_badregisters
;
1788 if (mrt6debug
& DEBUG_PIM
)
1790 "pim6_input: inner packet of register "
1791 "is not multicast %s\n",
1792 ip6_sprintf(&eip6
->ip6_dst
));
1795 return(IPPROTO_DONE
);
1799 * make a copy of the whole header to pass to the daemon later.
1801 mcp
= m_copy(m
, 0, off
+ PIM6_REG_MINLEN
);
1805 "pim6_input: pim register: "
1806 "could not copy register head\n");
1809 return(IPPROTO_DONE
);
1813 * forward the inner ip6 packet; point m_data at the inner ip6.
1815 m_adj(m
, off
+ PIM_MINLEN
);
1817 if (mrt6debug
& DEBUG_PIM
) {
1819 "pim6_input: forwarding decapsulated register: "
1820 "src %s, dst %s, mif %d\n",
1821 ip6_sprintf(&eip6
->ip6_src
),
1822 ip6_sprintf(&eip6
->ip6_dst
),
1830 lck_mtx_unlock(ip6_mutex
);
1831 dlil_output(lo_ifp
, PF_INET6
, m
, 0, (struct sockaddr
*)&dst
, 0);
1832 lck_mtx_lock(ip6_mutex
);
1835 printf("Warning: pim6_input call to dlil_find_dltag failed!\n");
1839 rc
= if_simloop(mif6table
[reg_mif_num
].m6_ifp
, m
,
1840 dst
.sin6_family
, NULL
);
1843 /* prepare the register head to send to the mrouting daemon */
1848 * Pass the PIM message up to the daemon; if it is a register message
1849 * pass the 'head' only up to the daemon. This includes the
1850 * encapsulator ip6 header, pim header, register header and the
1851 * encapsulated ip6 header.
1853 pim6_input_to_daemon
:
1854 rip6_input(&m
, offp
);
1855 return(IPPROTO_DONE
);