1 /* $KAME: ip6_mroute.c,v 1.15 2000/02/22 14:04:21 itojun Exp $ */
4 * Copyright (C) 1998 WIDE Project.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the project nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 /* BSDI ip_mroute.c,v 2.10 1996/11/14 00:29:52 jch Exp */
35 * IP multicast forwarding procedures
37 * Written by David Waitzman, BBN Labs, August 1988.
38 * Modified by Steve Deering, Stanford, February 1989.
39 * Modified by Mark J. Steiglitz, Stanford, May, 1991
40 * Modified by Van Jacobson, LBL, January 1993
41 * Modified by Ajit Thyagarajan, PARC, August 1993
42 * Modified by Bill Fenenr, PARC, April 1994
44 * MROUTING Revision: 3.5.1.2 + PIM-SMv2 (pimd) Support
47 #if (defined(__FreeBSD__) && __FreeBSD__ >= 3) || defined(__NetBSD__)
57 #include <sys/param.h>
58 #include <sys/systm.h>
59 #if defined(__FreeBSD__) && __FreeBSD__ >= 3 || defined (__APPLE__)
60 #include <sys/malloc.h>
63 #include <sys/socket.h>
64 #include <sys/socketvar.h>
65 #include <sys/sockio.h>
66 #include <sys/protosw.h>
67 #include <sys/errno.h>
69 #include <sys/kernel.h>
70 #if !(defined(__FreeBSD__) && __FreeBSD__ >= 3)
71 #include <sys/ioctl.h>
73 #include <sys/syslog.h>
76 #include <net/route.h>
77 #include <net/raw_cb.h>
79 #include <netinet/in.h>
80 #include <netinet/in_var.h>
82 #include <netinet/ip6.h>
83 #include <netinet6/ip6_var.h>
84 #include <netinet6/ip6_mroute.h>
85 #include <netinet6/pim6.h>
86 #include <netinet6/pim6_var.h>
88 #if defined(__FreeBSD__) && __FreeBSD__ >= 3
89 static MALLOC_DEFINE(M_MRTABLE
, "mf6c", "multicast forwarding cache entry");
92 #define M_HASCL(m) ((m)->m_flags & M_EXT)
94 static int ip6_mdq
__P((struct mbuf
*, struct ifnet
*, struct mf6c
*));
95 static void phyint_send
__P((struct ip6_hdr
*, struct mif6
*, struct mbuf
*));
97 static int set_pim6
__P((int *));
98 #if !(defined(__FreeBSD__) && __FreeBSD__ >= 3) && !defined(__APPLE__)
99 static int get_pim6
__P((struct mbuf
*));
101 static int socket_send
__P((struct socket
*, struct mbuf
*,
102 struct sockaddr_in6
*));
103 static int register_send
__P((struct ip6_hdr
*, struct mif6
*,
107 * Globals. All but ip6_mrouter, ip6_mrtproto and mrt6stat could be static,
108 * except for netstat or debugging purposes.
110 struct socket
*ip6_mrouter
= NULL
;
111 int ip6_mrtproto
= IPPROTO_PIM
; /* for netstat only */
112 struct mrt6stat mrt6stat
;
114 #define NO_RTE_FOUND 0x1
115 #define RTE_FOUND 0x2
117 struct mf6c
*mf6ctable
[MF6CTBLSIZ
];
118 u_char nexpire
[MF6CTBLSIZ
];
119 static struct mif6 mif6table
[MAXMIFS
];
121 u_int mrt6debug
= 0; /* debug level */
122 #define DEBUG_MFC 0x02
123 #define DEBUG_FORWARD 0x04
124 #define DEBUG_EXPIRE 0x08
125 #define DEBUG_XMIT 0x10
126 #define DEBUG_REG 0x20
127 #define DEBUG_PIM 0x40
130 static void expire_upcalls
__P((void *));
131 #define EXPIRE_TIMEOUT (hz / 4) /* 4x / second */
132 #define UPCALL_EXPIRE 6 /* number of timeouts */
136 extern struct socket
*ip_mrouter
;
140 static u_long lo_dl_tag
= 0;
142 * 'Interfaces' associated with decapsulator (so we can tell
143 * packets that went through it from ones that get reflected
144 * by a broken gateway). These interfaces are never linked into
145 * the system ifnet list & no routes point to them. I.e., packets
146 * can't be sent this way. They only exist as a placeholder for
147 * multicast source verification.
149 struct ifnet multicast_register_if
;
151 #define ENCAP_HOPS 64
156 static mifi_t nummifs
= 0;
157 static mifi_t reg_mif_num
= (mifi_t
)-1;
159 static struct pim6stat pim6stat
;
161 #if defined(__FreeBSD__) && __FreeBSD__ >= 3
162 static struct callout_handle expire_upcalls_ch
;
166 * one-back cache used by ipip_input to locate a tunnel's mif
167 * given a datagram's src ip address.
172 * Hash function for a source, group entry
174 #define MF6CHASH(a, g) MF6CHASHMOD((a).s6_addr32[0] ^ (a).s6_addr32[1] ^ \
175 (a).s6_addr32[2] ^ (a).s6_addr32[3] ^ \
176 (g).s6_addr32[0] ^ (g).s6_addr32[1] ^ \
177 (g).s6_addr32[2] ^ (g).s6_addr32[3])
180 * Find a route for a given origin IPv6 address and Multicast group address.
181 * Quality of service parameter to be added in the future!!!
184 #define MF6CFIND(o, g, rt) { \
185 register struct mf6c *_rt = mf6ctable[MF6CHASH(o,g)]; \
187 mrt6stat.mrt6s_mfc_lookups++; \
189 if (IN6_ARE_ADDR_EQUAL(&_rt->mf6c_origin.sin6_addr, &(o)) && \
190 IN6_ARE_ADDR_EQUAL(&_rt->mf6c_mcastgrp.sin6_addr, &(g)) && \
191 (_rt->mf6c_stall == NULL)) { \
195 _rt = _rt->mf6c_next; \
198 mrt6stat.mrt6s_mfc_misses++; \
203 * Macros to compute elapsed time efficiently
204 * Borrowed from Van Jacobson's scheduling code
206 #define TV_DELTA(a, b, delta) { \
209 delta = (a).tv_usec - (b).tv_usec; \
210 if ((xxs = (a).tv_sec - (b).tv_sec)) { \
219 delta += (1000000 * xxs); \
224 #define TV_LT(a, b) (((a).tv_usec < (b).tv_usec && \
225 (a).tv_sec <= (b).tv_sec) || (a).tv_sec < (b).tv_sec)
228 #define UPCALL_MAX 50
229 u_long upcall_data
[UPCALL_MAX
+ 1];
230 static void collate();
231 #endif /* UPCALL_TIMING */
233 static int get_sg_cnt
__P((struct sioc_sg_req6
*));
234 static int get_mif6_cnt
__P((struct sioc_mif_req6
*));
235 static int ip6_mrouter_init
__P((struct socket
*, struct mbuf
*));
236 static int add_m6if
__P((struct mif6ctl
*));
237 static int del_m6if
__P((mifi_t
*));
238 static int add_m6fc
__P((struct mf6cctl
*));
239 static int del_m6fc
__P((struct mf6cctl
*));
242 * Handle MRT setsockopt commands to modify the multicast routing tables.
244 #if defined(__FreeBSD__) && __FreeBSD__ >= 3 || defined (__APPLE__)
246 ip6_mrouter_set(so
, sopt
)
248 struct sockopt
*sopt
;
253 if (so
!= ip6_mrouter
&& sopt
->sopt_name
!= MRT6_INIT
)
256 if (error
= sooptgetm(sopt
, &m
)) /* XXX */
258 if (error
= sooptmcopyin(sopt
, m
)) /* XXX */
261 switch (sopt
->sopt_name
) {
263 error
= ip6_mrouter_init(so
, m
);
266 error
= ip6_mrouter_done();
269 error
= add_m6if(mtod(m
, struct mif6ctl
*));
272 error
= del_m6if(mtod(m
, mifi_t
*));
275 error
= add_m6fc(mtod(m
, struct mf6cctl
*));
278 error
= del_m6fc(mtod(m
, struct mf6cctl
*));
281 error
= set_pim6(mtod(m
, int *));
293 ip6_mrouter_set(cmd
, so
, m
)
298 if (cmd
!= MRT6_INIT
&& so
!= ip6_mrouter
)
302 case MRT6_INIT
: return ip6_mrouter_init(so
, m
);
303 case MRT6_DONE
: return ip6_mrouter_done();
304 case MRT6_ADD_MIF
: return add_m6if(mtod(m
, struct mif6ctl
*));
305 case MRT6_DEL_MIF
: return del_m6if(mtod(m
, mifi_t
*));
306 case MRT6_ADD_MFC
: return add_m6fc(mtod(m
, struct mf6cctl
*));
307 case MRT6_DEL_MFC
: return del_m6fc(mtod(m
, struct mf6cctl
*));
308 case MRT6_PIM
: return set_pim6(mtod(m
, int *));
309 default: return EOPNOTSUPP
;
315 * Handle MRT getsockopt commands
317 #if defined(__FreeBSD__) && __FreeBSD__ >= 3 || defined (__APPLE__)
319 ip6_mrouter_get(so
, sopt
)
321 struct sockopt
*sopt
;
325 if (so
!= ip6_mrouter
) return EACCES
;
327 switch (sopt
->sopt_name
) {
329 error
= sooptcopyout(sopt
, &pim6
, sizeof(pim6
));
336 ip6_mrouter_get(cmd
, so
, m
)
343 if (so
!= ip6_mrouter
) return EACCES
;
345 *m
= mb
= m_get(M_WAIT
, MT_SOOPTS
);
348 case MRT6_PIM
: return get_pim6(mb
);
357 * Handle ioctl commands to obtain information from the cache
360 mrt6_ioctl(cmd
, data
)
367 case SIOCGETSGCNT_IN6
:
368 return(get_sg_cnt((struct sioc_sg_req6
*)data
));
369 break; /* for safety */
370 case SIOCGETMIFCNT_IN6
:
371 return(get_mif6_cnt((struct sioc_mif_req6
*)data
));
372 break; /* for safety */
381 * returns the packet, byte, rpf-failure count for the source group provided
385 register struct sioc_sg_req6
*req
;
387 register struct mf6c
*rt
;
395 MF6CFIND(req
->src
.sin6_addr
, req
->grp
.sin6_addr
, rt
);
398 req
->pktcnt
= rt
->mf6c_pkt_cnt
;
399 req
->bytecnt
= rt
->mf6c_byte_cnt
;
400 req
->wrong_if
= rt
->mf6c_wrong_if
;
404 req
->pktcnt
= req
->bytecnt
= req
->wrong_if
= 0xffffffff;
411 * returns the input and output packet and byte counts on the mif provided
415 register struct sioc_mif_req6
*req
;
417 register mifi_t mifi
= req
->mifi
;
422 req
->icount
= mif6table
[mifi
].m6_pkt_in
;
423 req
->ocount
= mif6table
[mifi
].m6_pkt_out
;
424 req
->ibytes
= mif6table
[mifi
].m6_bytes_in
;
425 req
->obytes
= mif6table
[mifi
].m6_bytes_out
;
430 #if !(defined(__FreeBSD__) && __FreeBSD__ >=3) || !defined(__APPLE__)
432 * Get PIM processiong global
452 if ((*i
!= 1) && (*i
!= 0))
461 * Enable multicast routing
464 ip6_mrouter_init(so
, m
)
473 "ip6_mrouter_init: so_type = %d, pr_protocol = %d\n",
474 so
->so_type
, so
->so_proto
->pr_protocol
);
477 if (so
->so_type
!= SOCK_RAW
||
478 so
->so_proto
->pr_protocol
!= IPPROTO_ICMPV6
)
481 if (!m
|| (m
->m_len
!= sizeof(int *)))
488 if (ip6_mrouter
!= NULL
) return EADDRINUSE
;
492 bzero((caddr_t
)mf6ctable
, sizeof(mf6ctable
));
493 bzero((caddr_t
)nexpire
, sizeof(nexpire
));
495 pim6
= 0;/* used for stubbing out/in pim stuff */
497 #if defined(__FreeBSD__) && __FreeBSD__ >= 3
500 timeout(expire_upcalls
, (caddr_t
)NULL
, EXPIRE_TIMEOUT
);
504 log(LOG_DEBUG
, "ip6_mrouter_init\n");
511 * Disable multicast routing
519 struct in6_ifreq ifr
;
531 * For each phyint in use, disable promiscuous reception of all IPv6
537 * If there is still IPv4 multicast routing daemon,
538 * we remain interfaces to receive all muliticasted packets.
539 * XXX: there may be an interface in which the IPv4 multicast
540 * daemon is not interested...
546 for (mifi
= 0; mifi
< nummifs
; mifi
++) {
547 if (mif6table
[mifi
].m6_ifp
&&
548 !(mif6table
[mifi
].m6_flags
& MIFF_REGISTER
)) {
549 ifr
.ifr_addr
.sin6_family
= AF_INET6
;
550 ifr
.ifr_addr
.sin6_addr
= in6addr_any
;
551 ifp
= mif6table
[mifi
].m6_ifp
;
553 dlil_ioctl(0, ifp
, SIOCDELMULTI
,
556 (*ifp
->if_ioctl
)(ifp
, SIOCDELMULTI
,
563 bzero((caddr_t
)qtable
, sizeof(qtable
));
564 bzero((caddr_t
)tbftable
, sizeof(tbftable
));
566 bzero((caddr_t
)mif6table
, sizeof(mif6table
));
569 pim6
= 0; /* used to stub out/in pim specific code */
571 untimeout(expire_upcalls
, (caddr_t
)NULL
572 #if defined(__FreeBSD__) && __FreeBSD__ >= 3
578 * Free all multicast forwarding cache entries.
580 for (i
= 0; i
< MF6CTBLSIZ
; i
++) {
585 for (rte
= rt
->mf6c_stall
; rte
!= NULL
; ) {
586 struct rtdetq
*n
= rte
->next
;
589 _FREE(rte
, M_MRTABLE
);
594 _FREE(frt
, M_MRTABLE
);
598 bzero((caddr_t
)mf6ctable
, sizeof(mf6ctable
));
601 * Reset de-encapsulation cache
611 log(LOG_DEBUG
, "ip6_mrouter_done\n");
617 static struct sockaddr_in6 sin6
= { sizeof(sin6
), AF_INET6
};
620 * Add a mif to the mif table
624 register struct mif6ctl
*mifcp
;
626 register struct mif6
*mifp
;
628 #if !(defined(__FreeBSD__) && __FreeBSD__ >= 3) && !defined(__APPLE__)
629 struct in6_ifreq ifr
;
633 struct tbf
*m_tbf
= tbftable
+ mifcp
->mif6c_mifi
;
636 if (mifcp
->mif6c_mifi
>= MAXMIFS
)
638 mifp
= mif6table
+ mifcp
->mif6c_mifi
;
640 return EADDRINUSE
; /* XXX: is it appropriate? */
641 if (mifcp
->mif6c_pifi
== 0 || mifcp
->mif6c_pifi
> if_index
)
643 ifp
= ifindex2ifnet
[mifcp
->mif6c_pifi
];
645 if (mifcp
->mif6c_flags
& MIFF_REGISTER
) {
646 if (reg_mif_num
== (mifi_t
)-1) {
647 #if defined(__NetBSD__) || defined(__OpenBSD__)
648 strcpy(multicast_register_if
.if_xname
,
649 "register_mif"); /* XXX */
651 multicast_register_if
.if_name
= "register_mif";
653 multicast_register_if
.if_flags
|= IFF_LOOPBACK
;
654 multicast_register_if
.if_index
= mifcp
->mif6c_mifi
;
655 reg_mif_num
= mifcp
->mif6c_mifi
;
658 ifp
= &multicast_register_if
;
662 /* Make sure the interface supports multicast */
663 if ((ifp
->if_flags
& IFF_MULTICAST
) == 0)
671 #if (defined(__FreeBSD__) && __FreeBSD__ >= 3) || defined (__APPLE__)
672 error
= if_allmulti(ifp
, 1);
675 * Enable promiscuous reception of all IPv6 multicasts
676 * from the interface.
678 ifr
.ifr_addr
.sin6_family
= AF_INET6
;
679 ifr
.ifr_addr
.sin6_addr
= in6addr_any
;
680 error
= (*ifp
->if_ioctl
)(ifp
, SIOCADDMULTI
, (caddr_t
)&ifr
);
692 mifp
->m6_flags
= mifcp
->mif6c_flags
;
695 /* scaling up here allows division by 1024 in critical code */
696 mifp
->m6_rate_limit
= mifcp
->mif6c_rate_limit
* 1024 / 1000;
698 /* initialize per mif pkt counters */
700 mifp
->m6_pkt_out
= 0;
701 mifp
->m6_bytes_in
= 0;
702 mifp
->m6_bytes_out
= 0;
705 /* Adjust nummifs up if the mifi is higher than nummifs */
706 if (nummifs
<= mifcp
->mif6c_mifi
)
707 nummifs
= mifcp
->mif6c_mifi
+ 1;
712 "add_mif #%d, phyint %s%d\n",
714 ifp
->if_name
, ifp
->if_unit
);
721 * Delete a mif from the mif table
727 register struct mif6
*mifp
= mif6table
+ *mifip
;
728 register mifi_t mifi
;
730 #if !(defined(__FreeBSD__) && __FreeBSD__ >= 3) && !defined(__APPLE__)
731 struct in6_ifreq ifr
;
735 if (*mifip
>= nummifs
)
737 if (mifp
->m6_ifp
== NULL
)
746 if (!(mifp
->m6_flags
& MIFF_REGISTER
)) {
748 * XXX: what if there is yet IPv4 multicast daemon
749 * using the interface?
753 #if (defined(__FreeBSD__) && __FreeBSD__ >= 3) || defined (__APPLE__)
756 ifr
.ifr_addr
.sin6_family
= AF_INET6
;
757 ifr
.ifr_addr
.sin6_addr
= in6addr_any
;
758 (*ifp
->if_ioctl
)(ifp
, SIOCDELMULTI
, (caddr_t
)&ifr
);
763 bzero((caddr_t
)qtable
[*mifip
], sizeof(qtable
[*mifip
]));
764 bzero((caddr_t
)mifp
->m6_tbf
, sizeof(*(mifp
->m6_tbf
)));
766 bzero((caddr_t
)mifp
, sizeof (*mifp
));
768 /* Adjust nummifs down */
769 for (mifi
= nummifs
; mifi
> 0; mifi
--)
770 if (mif6table
[mifi
- 1].m6_ifp
)
778 log(LOG_DEBUG
, "del_m6if %d, nummifs %d\n", *mifip
, nummifs
);
789 struct mf6cctl
*mfccp
;
794 register u_short nstl
;
797 MF6CFIND(mfccp
->mf6cc_origin
.sin6_addr
,
798 mfccp
->mf6cc_mcastgrp
.sin6_addr
, rt
);
800 /* If an entry already exists, just update the fields */
803 if (mrt6debug
& DEBUG_MFC
)
804 log(LOG_DEBUG
,"add_m6fc update o %s g %s p %x\n",
805 ip6_sprintf(&mfccp
->mf6cc_origin
.sin6_addr
),
806 ip6_sprintf(&mfccp
->mf6cc_mcastgrp
.sin6_addr
),
807 mfccp
->mf6cc_parent
);
815 rt
->mf6c_parent
= mfccp
->mf6cc_parent
;
816 rt
->mf6c_ifset
= mfccp
->mf6cc_ifset
;
822 * Find the entry for which the upcall was made and update
829 hash
= MF6CHASH(mfccp
->mf6cc_origin
.sin6_addr
,
830 mfccp
->mf6cc_mcastgrp
.sin6_addr
);
831 for (rt
= mf6ctable
[hash
], nstl
= 0; rt
; rt
= rt
->mf6c_next
) {
832 if (IN6_ARE_ADDR_EQUAL(&rt
->mf6c_origin
.sin6_addr
,
833 &mfccp
->mf6cc_origin
.sin6_addr
) &&
834 IN6_ARE_ADDR_EQUAL(&rt
->mf6c_mcastgrp
.sin6_addr
,
835 &mfccp
->mf6cc_mcastgrp
.sin6_addr
) &&
836 (rt
->mf6c_stall
!= NULL
)) {
840 "add_m6fc: %s o %s g %s p %x dbx %p\n",
841 "multiple kernel entries",
842 ip6_sprintf(&mfccp
->mf6cc_origin
.sin6_addr
),
843 ip6_sprintf(&mfccp
->mf6cc_mcastgrp
.sin6_addr
),
844 mfccp
->mf6cc_parent
, rt
->mf6c_stall
);
847 if (mrt6debug
& DEBUG_MFC
)
849 "add_m6fc o %s g %s p %x dbg %x\n",
850 ip6_sprintf(&mfccp
->mf6cc_origin
.sin6_addr
),
851 ip6_sprintf(&mfccp
->mf6cc_mcastgrp
.sin6_addr
),
852 mfccp
->mf6cc_parent
, rt
->mf6c_stall
);
855 rt
->mf6c_origin
= mfccp
->mf6cc_origin
;
856 rt
->mf6c_mcastgrp
= mfccp
->mf6cc_mcastgrp
;
857 rt
->mf6c_parent
= mfccp
->mf6cc_parent
;
858 rt
->mf6c_ifset
= mfccp
->mf6cc_ifset
;
859 /* initialize pkt counters per src-grp */
860 rt
->mf6c_pkt_cnt
= 0;
861 rt
->mf6c_byte_cnt
= 0;
862 rt
->mf6c_wrong_if
= 0;
864 rt
->mf6c_expire
= 0; /* Don't clean this guy up */
867 /* free packets Qed at the end of this entry */
868 for (rte
= rt
->mf6c_stall
; rte
!= NULL
; ) {
869 struct rtdetq
*n
= rte
->next
;
870 ip6_mdq(rte
->m
, rte
->ifp
, rt
);
874 #endif /* UPCALL_TIMING */
875 _FREE(rte
, M_MRTABLE
);
878 rt
->mf6c_stall
= NULL
;
883 * It is possible that an entry is being inserted without an upcall
887 if (mrt6debug
& DEBUG_MFC
)
888 log(LOG_DEBUG
,"add_mfc no upcall h %d o %s g %s p %x\n",
890 ip6_sprintf(&mfccp
->mf6cc_origin
.sin6_addr
),
891 ip6_sprintf(&mfccp
->mf6cc_mcastgrp
.sin6_addr
),
892 mfccp
->mf6cc_parent
);
895 for (rt
= mf6ctable
[hash
]; rt
; rt
= rt
->mf6c_next
) {
897 if (IN6_ARE_ADDR_EQUAL(&rt
->mf6c_origin
.sin6_addr
,
898 &mfccp
->mf6cc_origin
.sin6_addr
)&&
899 IN6_ARE_ADDR_EQUAL(&rt
->mf6c_mcastgrp
.sin6_addr
,
900 &mfccp
->mf6cc_mcastgrp
.sin6_addr
)) {
902 rt
->mf6c_origin
= mfccp
->mf6cc_origin
;
903 rt
->mf6c_mcastgrp
= mfccp
->mf6cc_mcastgrp
;
904 rt
->mf6c_parent
= mfccp
->mf6cc_parent
;
905 /* initialize pkt counters per src-grp */
906 rt
->mf6c_pkt_cnt
= 0;
907 rt
->mf6c_byte_cnt
= 0;
908 rt
->mf6c_wrong_if
= 0;
916 /* no upcall, so make a new entry */
917 rt
= (struct mf6c
*)_MALLOC(sizeof(*rt
), M_MRTABLE
,
924 /* insert new entry at head of hash chain */
925 rt
->mf6c_origin
= mfccp
->mf6cc_origin
;
926 rt
->mf6c_mcastgrp
= mfccp
->mf6cc_mcastgrp
;
927 rt
->mf6c_parent
= mfccp
->mf6cc_parent
;
928 /* initialize pkt counters per src-grp */
929 rt
->mf6c_pkt_cnt
= 0;
930 rt
->mf6c_byte_cnt
= 0;
931 rt
->mf6c_wrong_if
= 0;
933 rt
->mf6c_stall
= NULL
;
935 /* link into table */
936 rt
->mf6c_next
= mf6ctable
[hash
];
937 mf6ctable
[hash
] = rt
;
946 * collect delay statistics on the upcalls
950 register struct timeval
*t
;
953 register struct timeval tp
;
954 register u_long delta
;
960 TV_DELTA(tp
, *t
, delta
);
969 #endif /* UPCALL_TIMING */
972 * Delete an mfc entry
976 struct mf6cctl
*mfccp
;
978 struct sockaddr_in6 origin
;
979 struct sockaddr_in6 mcastgrp
;
985 origin
= mfccp
->mf6cc_origin
;
986 mcastgrp
= mfccp
->mf6cc_mcastgrp
;
987 hash
= MF6CHASH(origin
.sin6_addr
, mcastgrp
.sin6_addr
);
990 if (mrt6debug
& DEBUG_MFC
)
991 log(LOG_DEBUG
,"del_m6fc orig %s mcastgrp %s\n",
992 ip6_sprintf(&origin
.sin6_addr
),
993 ip6_sprintf(&mcastgrp
.sin6_addr
));
1002 nptr
= &mf6ctable
[hash
];
1003 while ((rt
= *nptr
) != NULL
) {
1004 if (IN6_ARE_ADDR_EQUAL(&origin
.sin6_addr
,
1005 &rt
->mf6c_origin
.sin6_addr
) &&
1006 IN6_ARE_ADDR_EQUAL(&mcastgrp
.sin6_addr
,
1007 &rt
->mf6c_mcastgrp
.sin6_addr
) &&
1008 rt
->mf6c_stall
== NULL
)
1011 nptr
= &rt
->mf6c_next
;
1015 return EADDRNOTAVAIL
;
1018 *nptr
= rt
->mf6c_next
;
1019 _FREE(rt
, M_MRTABLE
);
1027 socket_send(s
, mm
, src
)
1030 struct sockaddr_in6
*src
;
1033 if (sbappendaddr(&s
->so_rcv
,
1034 (struct sockaddr
*)src
,
1035 mm
, (struct mbuf
*)0) != 0) {
1045 * IPv6 multicast forwarding function. This function assumes that the packet
1046 * pointed to by "ip6" has arrived on (or is about to be sent to) the interface
1047 * pointed to by "ifp", and the packet is to be relayed to other networks
1048 * that have members of the packet's destination IPv6 multicast group.
1050 * The packet is returned unscathed to the caller, unless it is
1051 * erroneous, in which case a non-zero return value tells the caller to
1056 ip6_mforward(ip6
, ifp
, m
)
1057 register struct ip6_hdr
*ip6
;
1061 register struct mf6c
*rt
;
1062 register struct mif6
*mifp
;
1063 register struct mbuf
*mm
;
1068 if (mrt6debug
& DEBUG_FORWARD
)
1069 log(LOG_DEBUG
, "ip6_mforward: src %s, dst %s, ifindex %d\n",
1070 ip6_sprintf(&ip6
->ip6_src
), ip6_sprintf(&ip6
->ip6_dst
),
1075 * Don't forward a packet with Hop limit of zero or one,
1076 * or a packet destined to a local-only group.
1078 if (ip6
->ip6_hlim
<= 1 || IN6_IS_ADDR_MC_NODELOCAL(&ip6
->ip6_dst
) ||
1079 IN6_IS_ADDR_MC_LINKLOCAL(&ip6
->ip6_dst
))
1084 * Determine forwarding mifs from the forwarding cache table
1091 MF6CFIND(ip6
->ip6_src
, ip6
->ip6_dst
, rt
);
1093 /* Entry exists, so forward if necessary */
1096 return (ip6_mdq(m
, ifp
, rt
));
1099 * If we don't have a route for packet's origin,
1100 * Make a copy of the packet &
1101 * send message to routing daemon
1104 register struct mbuf
*mb0
;
1105 register struct rtdetq
*rte
;
1106 register u_long hash
;
1107 /* register int i, npkts;*/
1112 #endif /* UPCALL_TIMING */
1114 mrt6stat
.mrt6s_no_route
++;
1116 if (mrt6debug
& (DEBUG_FORWARD
| DEBUG_MFC
))
1117 log(LOG_DEBUG
, "ip6_mforward: no rte s %s g %s\n",
1118 ip6_sprintf(&ip6
->ip6_src
),
1119 ip6_sprintf(&ip6
->ip6_dst
));
1123 * Allocate mbufs early so that we don't do extra work if we
1124 * are just going to fail anyway.
1126 rte
= (struct rtdetq
*)_MALLOC(sizeof(*rte
), M_MRTABLE
,
1132 mb0
= m_copy(m
, 0, M_COPYALL
);
1134 * Pullup packet header if needed before storing it,
1135 * as other references may modify it in the meantime.
1138 (M_HASCL(mb0
) || mb0
->m_len
< sizeof(struct ip6_hdr
)))
1139 mb0
= m_pullup(mb0
, sizeof(struct ip6_hdr
));
1141 _FREE(rte
, M_MRTABLE
);
1146 /* is there an upcall waiting for this packet? */
1147 hash
= MF6CHASH(ip6
->ip6_src
, ip6
->ip6_dst
);
1148 for (rt
= mf6ctable
[hash
]; rt
; rt
= rt
->mf6c_next
) {
1149 if (IN6_ARE_ADDR_EQUAL(&ip6
->ip6_src
,
1150 &rt
->mf6c_origin
.sin6_addr
) &&
1151 IN6_ARE_ADDR_EQUAL(&ip6
->ip6_dst
,
1152 &rt
->mf6c_mcastgrp
.sin6_addr
) &&
1153 (rt
->mf6c_stall
!= NULL
))
1160 /* no upcall, so make a new entry */
1161 rt
= (struct mf6c
*)_MALLOC(sizeof(*rt
), M_MRTABLE
,
1164 _FREE(rte
, M_MRTABLE
);
1170 * Make a copy of the header to send to the user
1173 mm
= m_copy(mb0
, 0, sizeof(struct ip6_hdr
));
1176 _FREE(rte
, M_MRTABLE
);
1178 _FREE(rt
, M_MRTABLE
);
1184 * Send message to routing daemon
1186 sin6
.sin6_addr
= ip6
->ip6_src
;
1188 im
= mtod(mm
, struct mrt6msg
*);
1189 im
->im6_msgtype
= MRT6MSG_NOCACHE
;
1193 if (mrt6debug
& DEBUG_FORWARD
)
1195 "getting the iif info in the kernel\n");
1198 for (mifp
= mif6table
, mifi
= 0;
1199 mifi
< nummifs
&& mifp
->m6_ifp
!= ifp
;
1205 if (socket_send(ip6_mrouter
, mm
, &sin6
) < 0) {
1206 log(LOG_WARNING
, "ip6_mforward: ip6_mrouter "
1207 "socket queue full\n");
1208 mrt6stat
.mrt6s_upq_sockfull
++;
1209 _FREE(rte
, M_MRTABLE
);
1211 _FREE(rt
, M_MRTABLE
);
1216 mrt6stat
.mrt6s_upcalls
++;
1218 /* insert new entry at head of hash chain */
1219 bzero(rt
, sizeof(*rt
));
1220 rt
->mf6c_origin
.sin6_family
= AF_INET6
;
1221 rt
->mf6c_origin
.sin6_len
= sizeof(struct sockaddr_in6
);
1222 rt
->mf6c_origin
.sin6_addr
= ip6
->ip6_src
;
1223 rt
->mf6c_mcastgrp
.sin6_family
= AF_INET6
;
1224 rt
->mf6c_mcastgrp
.sin6_len
= sizeof(struct sockaddr_in6
);
1225 rt
->mf6c_mcastgrp
.sin6_addr
= ip6
->ip6_dst
;
1226 rt
->mf6c_expire
= UPCALL_EXPIRE
;
1228 rt
->mf6c_parent
= MF6C_INCOMPLETE_PARENT
;
1230 /* link into table */
1231 rt
->mf6c_next
= mf6ctable
[hash
];
1232 mf6ctable
[hash
] = rt
;
1233 /* Add this entry to the end of the queue */
1234 rt
->mf6c_stall
= rte
;
1236 /* determine if q has overflowed */
1238 register int npkts
= 0;
1240 for (p
= &rt
->mf6c_stall
; *p
!= NULL
; p
= &(*p
)->next
)
1241 if (++npkts
> MAX_UPQ6
) {
1242 mrt6stat
.mrt6s_upq_ovflw
++;
1243 _FREE(rte
, M_MRTABLE
);
1249 /* Add this entry to the end of the queue */
1258 #endif /* UPCALL_TIMING */
1267 * Clean up cache entries if upcalls are not serviced
1268 * Call from the Slow Timeout mechanism, every half second.
1271 expire_upcalls_funneled(unused
)
1275 boolean_t funnel_state
;
1276 funnel_state
= thread_funnel_set(network_flock
, TRUE
);
1278 expire_upcalls(unused
);
1280 (void) thread_funnel_set(network_flock
, FALSE
);
1285 expire_upcalls(unused
)
1289 struct mf6c
*mfc
, **nptr
;
1298 for (i
= 0; i
< MF6CTBLSIZ
; i
++) {
1299 if (nexpire
[i
] == 0)
1301 nptr
= &mf6ctable
[i
];
1302 while ((mfc
= *nptr
) != NULL
) {
1303 rte
= mfc
->mf6c_stall
;
1305 * Skip real cache entries
1306 * Make sure it wasn't marked to not expire (shouldn't happen)
1310 mfc
->mf6c_expire
!= 0 &&
1311 --mfc
->mf6c_expire
== 0) {
1313 if (mrt6debug
& DEBUG_EXPIRE
)
1314 log(LOG_DEBUG
, "expire_upcalls: expiring (%s %s)\n",
1315 ip6_sprintf(&mfc
->mf6c_origin
.sin6_addr
),
1316 ip6_sprintf(&mfc
->mf6c_mcastgrp
.sin6_addr
));
1319 * drop all the packets
1320 * free the mbuf with the pkt, if, timing info
1323 struct rtdetq
*n
= rte
->next
;
1325 _FREE(rte
, M_MRTABLE
);
1327 } while (rte
!= NULL
);
1328 mrt6stat
.mrt6s_cache_cleanups
++;
1331 *nptr
= mfc
->mf6c_next
;
1332 _FREE(mfc
, M_MRTABLE
);
1334 nptr
= &mfc
->mf6c_next
;
1339 #if defined(__FreeBSD__) && __FreeBSD__ >= 3
1342 timeout(expire_upcalls_funneled
, (caddr_t
)NULL
, EXPIRE_TIMEOUT
);
1346 * Packet forwarding routine once entry in the cache is made
1350 register struct mbuf
*m
;
1351 register struct ifnet
*ifp
;
1352 register struct mf6c
*rt
;
1354 register struct ip6_hdr
*ip6
= mtod(m
, struct ip6_hdr
*);
1355 register mifi_t mifi
, iif
;
1356 register struct mif6
*mifp
;
1357 register int plen
= m
->m_pkthdr
.len
;
1360 * Macro to send packet on mif. Since RSVP packets don't get counted on
1361 * input, they shouldn't get counted on output, so statistics keeping is
1365 #define MC6_SEND(ip6,mifp,m) { \
1366 if ((mifp)->m6_flags & MIFF_REGISTER) \
1367 register_send((ip6), (mifp), (m)); \
1369 phyint_send((ip6), (mifp), (m)); \
1373 * Don't forward if it didn't arrive from the parent mif
1376 mifi
= rt
->mf6c_parent
;
1377 if ((mifi
>= nummifs
) || (mif6table
[mifi
].m6_ifp
!= ifp
)) {
1378 /* came in the wrong interface */
1380 if (mrt6debug
& DEBUG_FORWARD
)
1382 "wrong if: ifid %d mifi %d mififid %x\n",
1383 ifp
->if_index
, mifi
,
1384 mif6table
[mifi
].m6_ifp
->if_index
);
1386 mrt6stat
.mrt6s_wrong_if
++;
1387 rt
->mf6c_wrong_if
++;
1389 * If we are doing PIM processing, and we are forwarding
1390 * packets on this interface, send a message to the
1393 if(mifi
< nummifs
) /* have to make sure this is a valid mif */
1394 if(mif6table
[mifi
].m6_ifp
)
1396 if (pim6
&& (m
->m_flags
& M_LOOP
) == 0) {
1398 * Check the M_LOOP flag to avoid an
1399 * unnecessary PIM assert.
1400 * XXX: M_LOOP is an ad-hoc hack...
1402 static struct sockaddr_in6 sin6
=
1403 { sizeof(sin6
), AF_INET6
};
1405 register struct mbuf
*mm
;
1409 sizeof(struct ip6_hdr
));
1412 mm
->m_len
< sizeof(struct ip6_hdr
)))
1413 mm
= m_pullup(mm
, sizeof(struct ip6_hdr
));
1417 im
= mtod(mm
, struct mrt6msg
*);
1418 im
->im6_msgtype
= MRT6MSG_WRONGMIF
;
1421 for (mifp
= mif6table
, iif
= 0;
1422 iif
< nummifs
&& mifp
&&
1423 mifp
->m6_ifp
!= ifp
;
1428 sin6
.sin6_addr
= im
->im6_src
;
1430 mrt6stat
.mrt6s_upcalls
++;
1432 if (socket_send(ip6_mrouter
, mm
,
1436 log(LOG_WARNING
, "mdq, ip6_mrouter socket queue full\n");
1438 ++mrt6stat
.mrt6s_upq_sockfull
;
1440 } /* if socket Q full */
1443 } /* if wrong iif */
1445 /* If I sourced this packet, it counts as output, else it was input. */
1446 if (m
->m_pkthdr
.rcvif
== NULL
) {
1447 /* XXX: is rcvif really NULL when output?? */
1448 mif6table
[mifi
].m6_pkt_out
++;
1449 mif6table
[mifi
].m6_bytes_out
+= plen
;
1451 mif6table
[mifi
].m6_pkt_in
++;
1452 mif6table
[mifi
].m6_bytes_in
+= plen
;
1455 rt
->mf6c_byte_cnt
+= plen
;
1458 * For each mif, forward a copy of the packet if there are group
1459 * members downstream on the interface.
1461 for (mifp
= mif6table
, mifi
= 0; mifi
< nummifs
; mifp
++, mifi
++)
1462 if (IF_ISSET(mifi
, &rt
->mf6c_ifset
)) {
1464 mifp
->m6_bytes_out
+= plen
;
1465 MC6_SEND(ip6
, mifp
, m
);
1471 phyint_send(ip6
, mifp
, m
)
1472 struct ip6_hdr
*ip6
;
1476 register struct mbuf
*mb_copy
;
1477 struct ifnet
*ifp
= mifp
->m6_ifp
;
1480 int s
= splsoftnet();
1484 static struct route_in6 ro6
;
1485 struct in6_multi
*in6m
;
1488 * Make a new reference to the packet; make sure that
1489 * the IPv6 header is actually copied, not just referenced,
1490 * so that ip6_output() only scribbles on the copy.
1492 mb_copy
= m_copy(m
, 0, M_COPYALL
);
1494 (M_HASCL(mb_copy
) || mb_copy
->m_len
< sizeof(struct ip6_hdr
)))
1495 mb_copy
= m_pullup(mb_copy
, sizeof(struct ip6_hdr
));
1496 if (mb_copy
== NULL
)
1498 /* set MCAST flag to the outgoing packet */
1499 mb_copy
->m_flags
|= M_MCAST
;
1502 * If we sourced the packet, call ip6_output since we may devide
1503 * the packet into fragments when the packet is too big for the
1504 * outgoing interface.
1505 * Otherwise, we can simply send the packet to the interface
1508 if (m
->m_pkthdr
.rcvif
== NULL
) {
1509 struct ip6_moptions im6o
;
1511 im6o
.im6o_multicast_ifp
= ifp
;
1512 /* XXX: ip6_output will override ip6->ip6_hlim */
1513 im6o
.im6o_multicast_hlim
= ip6
->ip6_hlim
;
1514 im6o
.im6o_multicast_loop
= 1;
1515 error
= ip6_output(mb_copy
, NULL
, &ro6
,
1516 IPV6_FORWARDING
, &im6o
, NULL
);
1519 if (mrt6debug
& DEBUG_XMIT
)
1520 log(LOG_DEBUG
, "phyint_send on mif %d err %d\n",
1521 mifp
- mif6table
, error
);
1528 * If we belong to the destination multicast group
1529 * on the outgoing interface, loop back a copy.
1531 IN6_LOOKUP_MULTI(ip6
->ip6_dst
, ifp
, in6m
);
1533 ro6
.ro_dst
.sin6_len
= sizeof(struct sockaddr_in6
);
1534 ro6
.ro_dst
.sin6_family
= AF_INET6
;
1535 ro6
.ro_dst
.sin6_addr
= ip6
->ip6_dst
;
1536 ip6_mloopback(ifp
, m
, &ro6
.ro_dst
);
1539 * Put the packet into the sending queue of the outgoing interface
1540 * if it would fit in the MTU of the interface.
1542 if (mb_copy
->m_pkthdr
.len
< ifp
->if_mtu
|| ifp
->if_mtu
< IPV6_MMTU
) {
1543 ro6
.ro_dst
.sin6_len
= sizeof(struct sockaddr_in6
);
1544 ro6
.ro_dst
.sin6_family
= AF_INET6
;
1545 ro6
.ro_dst
.sin6_addr
= ip6
->ip6_dst
;
1547 * We just call if_output instead of nd6_output here, since
1548 * we need no ND for a multicast forwarded packet...right?
1551 error
= dlil_output(ifptodlt(ifp
, PF_INET6
), mb_copy
,
1552 NULL
, (struct sockaddr
*)&ro6
.ro_dst
, 0);
1554 error
= (*ifp
->if_output
)(ifp
, mb_copy
,
1555 (struct sockaddr
*)&ro6
.ro_dst
,
1559 if (mrt6debug
& DEBUG_XMIT
)
1560 log(LOG_DEBUG
, "phyint_send on mif %d err %d\n",
1561 mifp
- mif6table
, error
);
1566 icmp6_error(mb_copy
, ICMP6_PACKET_TOO_BIG
, 0, ifp
->if_mtu
);
1571 if (mrt6debug
& DEBUG_DEBUG_XMIT
)
1573 "phyint_send: packet too big on %s o %s g %s"
1574 " size %d(discarded)\n",
1576 ip6_sprintf(&ip6
->ip6_src
),
1577 ip6_sprintf(&ip6
->ip6_dst
),
1578 mb_copy
->m_pkthdr
.len
);
1580 if (mrt6debug
& DEBUG_XMIT
)
1582 "phyint_send: packet too big on %s%u o %s g %s"
1583 " size %d(discarded)\n",
1584 ifp
->if_name
, ifp
->if_unit
,
1585 ip6_sprintf(&ip6
->ip6_src
),
1586 ip6_sprintf(&ip6
->ip6_dst
),
1587 mb_copy
->m_pkthdr
.len
);
1588 #endif /* __NetBSD__ */
1589 #endif /* MRT6DEBUG */
1590 m_freem(mb_copy
); /* simply discard the packet */
1597 register_send(ip6
, mif
, m
)
1598 register struct ip6_hdr
*ip6
;
1600 register struct mbuf
*m
;
1602 register struct mbuf
*mm
;
1603 register int i
, len
= m
->m_pkthdr
.len
;
1604 static struct sockaddr_in6 sin6
= { sizeof(sin6
), AF_INET6
};
1605 struct mrt6msg
*im6
;
1609 log(LOG_DEBUG
, "** IPv6 register_send **\n src %s dst %s\n",
1610 ip6_sprintf(&ip6
->ip6_src
), ip6_sprintf(&ip6
->ip6_dst
));
1612 ++pim6stat
.pim6s_snd_registers
;
1614 /* Make a copy of the packet to send to the user level process */
1615 MGETHDR(mm
, M_DONTWAIT
, MT_HEADER
);
1618 mm
->m_data
+= max_linkhdr
;
1619 mm
->m_len
= sizeof(struct ip6_hdr
);
1621 if ((mm
->m_next
= m_copy(m
, 0, M_COPYALL
)) == NULL
) {
1625 i
= MHLEN
- M_LEADINGSPACE(mm
);
1628 mm
= m_pullup(mm
, i
);
1633 /* TODO: check it! */
1634 mm
->m_pkthdr
.len
= len
+ sizeof(struct ip6_hdr
);
1637 * Send message to routing daemon
1639 sin6
.sin6_addr
= ip6
->ip6_src
;
1641 im6
= mtod(mm
, struct mrt6msg
*);
1642 im6
->im6_msgtype
= MRT6MSG_WHOLEPKT
;
1645 im6
->im6_mif
= mif
- mif6table
;
1647 /* iif info is not given for reg. encap.n */
1648 mrt6stat
.mrt6s_upcalls
++;
1650 if (socket_send(ip6_mrouter
, mm
, &sin6
) < 0) {
1654 "register_send: ip_mrouter socket queue full\n");
1656 ++mrt6stat
.mrt6s_upq_sockfull
;
1663 * PIM sparse mode hook
1664 * Receives the pim control messages, and passes them up to the listening
1665 * socket, using rip6_input.
1666 * The only message processed is the REGISTER pim message; the pim header
1667 * is stripped off, and the inner packet is passed to register_mforward.
1670 pim6_input(mp
, offp
, proto
)
1674 register struct pim
*pim
; /* pointer to a pim struct */
1675 register struct ip6_hdr
*ip6
;
1676 register int pimlen
;
1677 struct mbuf
*m
= *mp
;
1681 ++pim6stat
.pim6s_rcv_total
;
1683 ip6
= mtod(m
, struct ip6_hdr
*);
1684 pimlen
= m
->m_pkthdr
.len
- *offp
;
1689 if (pimlen
< PIM_MINLEN
) {
1690 ++pim6stat
.pim6s_rcv_tooshort
;
1692 if (mrt6debug
& DEBUG_PIM
)
1693 log(LOG_DEBUG
,"pim6_input: PIM packet too short\n");
1696 return(IPPROTO_DONE
);
1700 * if the packet is at least as big as a REGISTER, go ahead
1701 * and grab the PIM REGISTER header size, to avoid another
1702 * possible m_pullup() later.
1704 * PIM_MINLEN == pimhdr + u_int32 == 8
1705 * PIM6_REG_MINLEN == pimhdr + reghdr + eip6hdr == 4 + 4 + 40
1707 minlen
= (pimlen
>= PIM6_REG_MINLEN
) ? PIM6_REG_MINLEN
: PIM_MINLEN
;
1710 * Make sure that the IP6 and PIM headers in contiguous memory, and
1711 * possibly the PIM REGISTER header
1713 #ifndef PULLDOWN_TEST
1714 IP6_EXTHDR_CHECK(m
, off
, minlen
, IPPROTO_DONE
);
1715 /* adjust pointer */
1716 ip6
= mtod(m
, struct ip6_hdr
*);
1718 /* adjust mbuf to point to the PIM header */
1719 pim
= (struct pim
*)((caddr_t
)ip6
+ off
);
1721 IP6_EXTHDR_GET(pim
, struct pim
*, m
, off
, minlen
);
1723 pim6stat
.pim6s_rcv_tooshort
++;
1724 return IPPROTO_DONE
;
1729 #define PIM6_CHECKSUM 1
1735 * Validate checksum.
1736 * If PIM REGISTER, exclude the data packet
1738 if (pim
->pim_type
== PIM_REGISTER
)
1739 cksumlen
= PIM_MINLEN
;
1743 if (in6_cksum(m
, IPPROTO_PIM
, off
, cksumlen
)) {
1744 ++pim6stat
.pim6s_rcv_badsum
;
1746 if (mrt6debug
& DEBUG_PIM
)
1748 "pim6_input: invalid checksum\n");
1751 return(IPPROTO_DONE
);
1754 #endif /* PIM_CHECKSUM */
1756 /* PIM version check */
1757 if (pim
->pim_ver
!= PIM_VERSION
) {
1758 ++pim6stat
.pim6s_rcv_badversion
;
1761 "pim6_input: incorrect version %d, expecting %d\n",
1762 pim
->pim_ver
, PIM_VERSION
);
1765 return(IPPROTO_DONE
);
1768 if (pim
->pim_type
== PIM_REGISTER
) {
1770 * since this is a REGISTER, we'll make a copy of the register
1771 * headers ip6+pim+u_int32_t+encap_ip6, to be passed up to the
1774 static struct sockaddr_in6 dst
= { sizeof(dst
), AF_INET6
};
1777 struct ip6_hdr
*eip6
;
1781 ++pim6stat
.pim6s_rcv_registers
;
1783 if ((reg_mif_num
>= nummifs
) || (reg_mif_num
== (mifi_t
) -1)) {
1785 if (mrt6debug
& DEBUG_PIM
)
1787 "pim6_input: register mif not set: %d\n",
1791 return(IPPROTO_DONE
);
1794 reghdr
= (u_int32_t
*)(pim
+ 1);
1796 if ((ntohl(*reghdr
) & PIM_NULL_REGISTER
))
1797 goto pim6_input_to_daemon
;
1802 if (pimlen
< PIM6_REG_MINLEN
) {
1803 ++pim6stat
.pim6s_rcv_tooshort
;
1804 ++pim6stat
.pim6s_rcv_badregisters
;
1807 "pim6_input: register packet size too "
1808 "small %d from %s\n",
1809 pimlen
, ip6_sprintf(&ip6
->ip6_src
));
1812 return(IPPROTO_DONE
);
1815 eip6
= (struct ip6_hdr
*) (reghdr
+ 1);
1817 if (mrt6debug
& DEBUG_PIM
)
1819 "pim6_input[register], eip6: %s -> %s, "
1821 ip6_sprintf(&eip6
->ip6_src
),
1822 ip6_sprintf(&eip6
->ip6_dst
),
1823 ntohs(eip6
->ip6_plen
));
1826 /* verify the inner packet is destined to a mcast group */
1827 if (!IN6_IS_ADDR_MULTICAST(&eip6
->ip6_dst
)) {
1828 ++pim6stat
.pim6s_rcv_badregisters
;
1830 if (mrt6debug
& DEBUG_PIM
)
1832 "pim6_input: inner packet of register "
1833 "is not multicast %s\n",
1834 ip6_sprintf(&eip6
->ip6_dst
));
1837 return(IPPROTO_DONE
);
1841 * make a copy of the whole header to pass to the daemon later.
1843 mcp
= m_copy(m
, 0, off
+ PIM6_REG_MINLEN
);
1847 "pim6_input: pim register: "
1848 "could not copy register head\n");
1851 return(IPPROTO_DONE
);
1855 * forward the inner ip6 packet; point m_data at the inner ip6.
1857 m_adj(m
, off
+ PIM_MINLEN
);
1859 if (mrt6debug
& DEBUG_PIM
) {
1861 "pim6_input: forwarding decapsulated register: "
1862 "src %s, dst %s, mif %d\n",
1863 ip6_sprintf(&eip6
->ip6_src
),
1864 ip6_sprintf(&eip6
->ip6_dst
),
1869 #if defined(__FreeBSD__) && __FreeBSD__ >= 3
1870 rc
= if_simloop(mif6table
[reg_mif_num
].m6_ifp
, m
,
1871 (struct sockaddr
*) &dst
, NULL
);
1873 #if defined (__APPLE__)
1875 dlil_find_dltag(APPLE_IF_FAM_LOOPBACK
, 0, PF_INET6
, &lo_dl_tag
);
1878 dlil_output(lo_dl_tag
, m
, 0, (struct sockaddr
*) &dst
, 0);
1880 printf("Warning: pim6_input call to dlil_find_dltag failed!\n");
1884 rc
= looutput(mif6table
[reg_mif_num
].m6_ifp
, m
,
1885 (struct sockaddr
*) &dst
,
1886 (struct rtentry
*) NULL
);
1890 /* prepare the register head to send to the mrouting daemon */
1895 * Pass the PIM message up to the daemon; if it is a register message
1896 * pass the 'head' only up to the daemon. This includes the
1897 * encapsulator ip6 header, pim header, register header and the
1898 * encapsulated ip6 header.
1900 pim6_input_to_daemon
:
1901 rip6_input(&m
, offp
, proto
);
1902 return(IPPROTO_DONE
);