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(unused
)
1275 struct mf6c
*mfc
, **nptr
;
1279 boolean_t funnel_state
;
1280 funnel_state
= thread_set_funneled(TRUE
);
1288 for (i
= 0; i
< MF6CTBLSIZ
; i
++) {
1289 if (nexpire
[i
] == 0)
1291 nptr
= &mf6ctable
[i
];
1292 while ((mfc
= *nptr
) != NULL
) {
1293 rte
= mfc
->mf6c_stall
;
1295 * Skip real cache entries
1296 * Make sure it wasn't marked to not expire (shouldn't happen)
1300 mfc
->mf6c_expire
!= 0 &&
1301 --mfc
->mf6c_expire
== 0) {
1303 if (mrt6debug
& DEBUG_EXPIRE
)
1304 log(LOG_DEBUG
, "expire_upcalls: expiring (%s %s)\n",
1305 ip6_sprintf(&mfc
->mf6c_origin
.sin6_addr
),
1306 ip6_sprintf(&mfc
->mf6c_mcastgrp
.sin6_addr
));
1309 * drop all the packets
1310 * free the mbuf with the pkt, if, timing info
1313 struct rtdetq
*n
= rte
->next
;
1315 _FREE(rte
, M_MRTABLE
);
1317 } while (rte
!= NULL
);
1318 mrt6stat
.mrt6s_cache_cleanups
++;
1321 *nptr
= mfc
->mf6c_next
;
1322 _FREE(mfc
, M_MRTABLE
);
1324 nptr
= &mfc
->mf6c_next
;
1329 #if defined(__FreeBSD__) && __FreeBSD__ >= 3
1332 timeout(expire_upcalls
, (caddr_t
)NULL
, EXPIRE_TIMEOUT
);
1334 (void) thread_set_funneled(funnel_state
);
1339 * Packet forwarding routine once entry in the cache is made
1343 register struct mbuf
*m
;
1344 register struct ifnet
*ifp
;
1345 register struct mf6c
*rt
;
1347 register struct ip6_hdr
*ip6
= mtod(m
, struct ip6_hdr
*);
1348 register mifi_t mifi
, iif
;
1349 register struct mif6
*mifp
;
1350 register int plen
= m
->m_pkthdr
.len
;
1353 * Macro to send packet on mif. Since RSVP packets don't get counted on
1354 * input, they shouldn't get counted on output, so statistics keeping is
1358 #define MC6_SEND(ip6,mifp,m) { \
1359 if ((mifp)->m6_flags & MIFF_REGISTER) \
1360 register_send((ip6), (mifp), (m)); \
1362 phyint_send((ip6), (mifp), (m)); \
1366 * Don't forward if it didn't arrive from the parent mif
1369 mifi
= rt
->mf6c_parent
;
1370 if ((mifi
>= nummifs
) || (mif6table
[mifi
].m6_ifp
!= ifp
)) {
1371 /* came in the wrong interface */
1373 if (mrt6debug
& DEBUG_FORWARD
)
1375 "wrong if: ifid %d mifi %d mififid %x\n",
1376 ifp
->if_index
, mifi
,
1377 mif6table
[mifi
].m6_ifp
->if_index
);
1379 mrt6stat
.mrt6s_wrong_if
++;
1380 rt
->mf6c_wrong_if
++;
1382 * If we are doing PIM processing, and we are forwarding
1383 * packets on this interface, send a message to the
1386 if(mifi
< nummifs
) /* have to make sure this is a valid mif */
1387 if(mif6table
[mifi
].m6_ifp
)
1389 if (pim6
&& (m
->m_flags
& M_LOOP
) == 0) {
1391 * Check the M_LOOP flag to avoid an
1392 * unnecessary PIM assert.
1393 * XXX: M_LOOP is an ad-hoc hack...
1395 static struct sockaddr_in6 sin6
=
1396 { sizeof(sin6
), AF_INET6
};
1398 register struct mbuf
*mm
;
1402 sizeof(struct ip6_hdr
));
1405 mm
->m_len
< sizeof(struct ip6_hdr
)))
1406 mm
= m_pullup(mm
, sizeof(struct ip6_hdr
));
1410 im
= mtod(mm
, struct mrt6msg
*);
1411 im
->im6_msgtype
= MRT6MSG_WRONGMIF
;
1414 for (mifp
= mif6table
, iif
= 0;
1415 iif
< nummifs
&& mifp
&&
1416 mifp
->m6_ifp
!= ifp
;
1421 sin6
.sin6_addr
= im
->im6_src
;
1423 mrt6stat
.mrt6s_upcalls
++;
1425 if (socket_send(ip6_mrouter
, mm
,
1429 log(LOG_WARNING
, "mdq, ip6_mrouter socket queue full\n");
1431 ++mrt6stat
.mrt6s_upq_sockfull
;
1433 } /* if socket Q full */
1436 } /* if wrong iif */
1438 /* If I sourced this packet, it counts as output, else it was input. */
1439 if (m
->m_pkthdr
.rcvif
== NULL
) {
1440 /* XXX: is rcvif really NULL when output?? */
1441 mif6table
[mifi
].m6_pkt_out
++;
1442 mif6table
[mifi
].m6_bytes_out
+= plen
;
1444 mif6table
[mifi
].m6_pkt_in
++;
1445 mif6table
[mifi
].m6_bytes_in
+= plen
;
1448 rt
->mf6c_byte_cnt
+= plen
;
1451 * For each mif, forward a copy of the packet if there are group
1452 * members downstream on the interface.
1454 for (mifp
= mif6table
, mifi
= 0; mifi
< nummifs
; mifp
++, mifi
++)
1455 if (IF_ISSET(mifi
, &rt
->mf6c_ifset
)) {
1457 mifp
->m6_bytes_out
+= plen
;
1458 MC6_SEND(ip6
, mifp
, m
);
1464 phyint_send(ip6
, mifp
, m
)
1465 struct ip6_hdr
*ip6
;
1469 register struct mbuf
*mb_copy
;
1470 struct ifnet
*ifp
= mifp
->m6_ifp
;
1473 int s
= splsoftnet();
1477 static struct route_in6 ro6
;
1478 struct in6_multi
*in6m
;
1481 * Make a new reference to the packet; make sure that
1482 * the IPv6 header is actually copied, not just referenced,
1483 * so that ip6_output() only scribbles on the copy.
1485 mb_copy
= m_copy(m
, 0, M_COPYALL
);
1487 (M_HASCL(mb_copy
) || mb_copy
->m_len
< sizeof(struct ip6_hdr
)))
1488 mb_copy
= m_pullup(mb_copy
, sizeof(struct ip6_hdr
));
1489 if (mb_copy
== NULL
)
1491 /* set MCAST flag to the outgoing packet */
1492 mb_copy
->m_flags
|= M_MCAST
;
1495 * If we sourced the packet, call ip6_output since we may devide
1496 * the packet into fragments when the packet is too big for the
1497 * outgoing interface.
1498 * Otherwise, we can simply send the packet to the interface
1501 if (m
->m_pkthdr
.rcvif
== NULL
) {
1502 struct ip6_moptions im6o
;
1504 im6o
.im6o_multicast_ifp
= ifp
;
1505 /* XXX: ip6_output will override ip6->ip6_hlim */
1506 im6o
.im6o_multicast_hlim
= ip6
->ip6_hlim
;
1507 im6o
.im6o_multicast_loop
= 1;
1508 error
= ip6_output(mb_copy
, NULL
, &ro6
,
1509 IPV6_FORWARDING
, &im6o
, NULL
);
1512 if (mrt6debug
& DEBUG_XMIT
)
1513 log(LOG_DEBUG
, "phyint_send on mif %d err %d\n",
1514 mifp
- mif6table
, error
);
1521 * If we belong to the destination multicast group
1522 * on the outgoing interface, loop back a copy.
1524 IN6_LOOKUP_MULTI(ip6
->ip6_dst
, ifp
, in6m
);
1526 ro6
.ro_dst
.sin6_len
= sizeof(struct sockaddr_in6
);
1527 ro6
.ro_dst
.sin6_family
= AF_INET6
;
1528 ro6
.ro_dst
.sin6_addr
= ip6
->ip6_dst
;
1529 ip6_mloopback(ifp
, m
, &ro6
.ro_dst
);
1532 * Put the packet into the sending queue of the outgoing interface
1533 * if it would fit in the MTU of the interface.
1535 if (mb_copy
->m_pkthdr
.len
< ifp
->if_mtu
|| ifp
->if_mtu
< IPV6_MMTU
) {
1536 ro6
.ro_dst
.sin6_len
= sizeof(struct sockaddr_in6
);
1537 ro6
.ro_dst
.sin6_family
= AF_INET6
;
1538 ro6
.ro_dst
.sin6_addr
= ip6
->ip6_dst
;
1540 * We just call if_output instead of nd6_output here, since
1541 * we need no ND for a multicast forwarded packet...right?
1544 error
= dlil_output(ifptodlt(ifp
, PF_INET6
), mb_copy
,
1545 NULL
, (struct sockaddr
*)&ro6
.ro_dst
, 0);
1547 error
= (*ifp
->if_output
)(ifp
, mb_copy
,
1548 (struct sockaddr
*)&ro6
.ro_dst
,
1552 if (mrt6debug
& DEBUG_XMIT
)
1553 log(LOG_DEBUG
, "phyint_send on mif %d err %d\n",
1554 mifp
- mif6table
, error
);
1559 icmp6_error(mb_copy
, ICMP6_PACKET_TOO_BIG
, 0, ifp
->if_mtu
);
1564 if (mrt6debug
& DEBUG_DEBUG_XMIT
)
1566 "phyint_send: packet too big on %s o %s g %s"
1567 " size %d(discarded)\n",
1569 ip6_sprintf(&ip6
->ip6_src
),
1570 ip6_sprintf(&ip6
->ip6_dst
),
1571 mb_copy
->m_pkthdr
.len
);
1573 if (mrt6debug
& DEBUG_XMIT
)
1575 "phyint_send: packet too big on %s%u o %s g %s"
1576 " size %d(discarded)\n",
1577 ifp
->if_name
, ifp
->if_unit
,
1578 ip6_sprintf(&ip6
->ip6_src
),
1579 ip6_sprintf(&ip6
->ip6_dst
),
1580 mb_copy
->m_pkthdr
.len
);
1581 #endif /* __NetBSD__ */
1582 #endif /* MRT6DEBUG */
1583 m_freem(mb_copy
); /* simply discard the packet */
1590 register_send(ip6
, mif
, m
)
1591 register struct ip6_hdr
*ip6
;
1593 register struct mbuf
*m
;
1595 register struct mbuf
*mm
;
1596 register int i
, len
= m
->m_pkthdr
.len
;
1597 static struct sockaddr_in6 sin6
= { sizeof(sin6
), AF_INET6
};
1598 struct mrt6msg
*im6
;
1602 log(LOG_DEBUG
, "** IPv6 register_send **\n src %s dst %s\n",
1603 ip6_sprintf(&ip6
->ip6_src
), ip6_sprintf(&ip6
->ip6_dst
));
1605 ++pim6stat
.pim6s_snd_registers
;
1607 /* Make a copy of the packet to send to the user level process */
1608 MGETHDR(mm
, M_DONTWAIT
, MT_HEADER
);
1611 mm
->m_data
+= max_linkhdr
;
1612 mm
->m_len
= sizeof(struct ip6_hdr
);
1614 if ((mm
->m_next
= m_copy(m
, 0, M_COPYALL
)) == NULL
) {
1618 i
= MHLEN
- M_LEADINGSPACE(mm
);
1621 mm
= m_pullup(mm
, i
);
1626 /* TODO: check it! */
1627 mm
->m_pkthdr
.len
= len
+ sizeof(struct ip6_hdr
);
1630 * Send message to routing daemon
1632 sin6
.sin6_addr
= ip6
->ip6_src
;
1634 im6
= mtod(mm
, struct mrt6msg
*);
1635 im6
->im6_msgtype
= MRT6MSG_WHOLEPKT
;
1638 im6
->im6_mif
= mif
- mif6table
;
1640 /* iif info is not given for reg. encap.n */
1641 mrt6stat
.mrt6s_upcalls
++;
1643 if (socket_send(ip6_mrouter
, mm
, &sin6
) < 0) {
1647 "register_send: ip_mrouter socket queue full\n");
1649 ++mrt6stat
.mrt6s_upq_sockfull
;
1656 * PIM sparse mode hook
1657 * Receives the pim control messages, and passes them up to the listening
1658 * socket, using rip6_input.
1659 * The only message processed is the REGISTER pim message; the pim header
1660 * is stripped off, and the inner packet is passed to register_mforward.
1663 pim6_input(mp
, offp
, proto
)
1667 register struct pim
*pim
; /* pointer to a pim struct */
1668 register struct ip6_hdr
*ip6
;
1669 register int pimlen
;
1670 struct mbuf
*m
= *mp
;
1674 ++pim6stat
.pim6s_rcv_total
;
1676 ip6
= mtod(m
, struct ip6_hdr
*);
1677 pimlen
= m
->m_pkthdr
.len
- *offp
;
1682 if (pimlen
< PIM_MINLEN
) {
1683 ++pim6stat
.pim6s_rcv_tooshort
;
1685 if (mrt6debug
& DEBUG_PIM
)
1686 log(LOG_DEBUG
,"pim6_input: PIM packet too short\n");
1689 return(IPPROTO_DONE
);
1693 * if the packet is at least as big as a REGISTER, go ahead
1694 * and grab the PIM REGISTER header size, to avoid another
1695 * possible m_pullup() later.
1697 * PIM_MINLEN == pimhdr + u_int32 == 8
1698 * PIM6_REG_MINLEN == pimhdr + reghdr + eip6hdr == 4 + 4 + 40
1700 minlen
= (pimlen
>= PIM6_REG_MINLEN
) ? PIM6_REG_MINLEN
: PIM_MINLEN
;
1703 * Make sure that the IP6 and PIM headers in contiguous memory, and
1704 * possibly the PIM REGISTER header
1706 #ifndef PULLDOWN_TEST
1707 IP6_EXTHDR_CHECK(m
, off
, minlen
, IPPROTO_DONE
);
1708 /* adjust pointer */
1709 ip6
= mtod(m
, struct ip6_hdr
*);
1711 /* adjust mbuf to point to the PIM header */
1712 pim
= (struct pim
*)((caddr_t
)ip6
+ off
);
1714 IP6_EXTHDR_GET(pim
, struct pim
*, m
, off
, minlen
);
1716 pim6stat
.pim6s_rcv_tooshort
++;
1717 return IPPROTO_DONE
;
1722 #define PIM6_CHECKSUM 1
1728 * Validate checksum.
1729 * If PIM REGISTER, exclude the data packet
1731 if (pim
->pim_type
== PIM_REGISTER
)
1732 cksumlen
= PIM_MINLEN
;
1736 if (in6_cksum(m
, IPPROTO_PIM
, off
, cksumlen
)) {
1737 ++pim6stat
.pim6s_rcv_badsum
;
1739 if (mrt6debug
& DEBUG_PIM
)
1741 "pim6_input: invalid checksum\n");
1744 return(IPPROTO_DONE
);
1747 #endif /* PIM_CHECKSUM */
1749 /* PIM version check */
1750 if (pim
->pim_ver
!= PIM_VERSION
) {
1751 ++pim6stat
.pim6s_rcv_badversion
;
1754 "pim6_input: incorrect version %d, expecting %d\n",
1755 pim
->pim_ver
, PIM_VERSION
);
1758 return(IPPROTO_DONE
);
1761 if (pim
->pim_type
== PIM_REGISTER
) {
1763 * since this is a REGISTER, we'll make a copy of the register
1764 * headers ip6+pim+u_int32_t+encap_ip6, to be passed up to the
1767 static struct sockaddr_in6 dst
= { sizeof(dst
), AF_INET6
};
1770 struct ip6_hdr
*eip6
;
1774 ++pim6stat
.pim6s_rcv_registers
;
1776 if ((reg_mif_num
>= nummifs
) || (reg_mif_num
== (mifi_t
) -1)) {
1778 if (mrt6debug
& DEBUG_PIM
)
1780 "pim6_input: register mif not set: %d\n",
1784 return(IPPROTO_DONE
);
1787 reghdr
= (u_int32_t
*)(pim
+ 1);
1789 if ((ntohl(*reghdr
) & PIM_NULL_REGISTER
))
1790 goto pim6_input_to_daemon
;
1795 if (pimlen
< PIM6_REG_MINLEN
) {
1796 ++pim6stat
.pim6s_rcv_tooshort
;
1797 ++pim6stat
.pim6s_rcv_badregisters
;
1800 "pim6_input: register packet size too "
1801 "small %d from %s\n",
1802 pimlen
, ip6_sprintf(&ip6
->ip6_src
));
1805 return(IPPROTO_DONE
);
1808 eip6
= (struct ip6_hdr
*) (reghdr
+ 1);
1810 if (mrt6debug
& DEBUG_PIM
)
1812 "pim6_input[register], eip6: %s -> %s, "
1814 ip6_sprintf(&eip6
->ip6_src
),
1815 ip6_sprintf(&eip6
->ip6_dst
),
1816 ntohs(eip6
->ip6_plen
));
1819 /* verify the inner packet is destined to a mcast group */
1820 if (!IN6_IS_ADDR_MULTICAST(&eip6
->ip6_dst
)) {
1821 ++pim6stat
.pim6s_rcv_badregisters
;
1823 if (mrt6debug
& DEBUG_PIM
)
1825 "pim6_input: inner packet of register "
1826 "is not multicast %s\n",
1827 ip6_sprintf(&eip6
->ip6_dst
));
1830 return(IPPROTO_DONE
);
1834 * make a copy of the whole header to pass to the daemon later.
1836 mcp
= m_copy(m
, 0, off
+ PIM6_REG_MINLEN
);
1840 "pim6_input: pim register: "
1841 "could not copy register head\n");
1844 return(IPPROTO_DONE
);
1848 * forward the inner ip6 packet; point m_data at the inner ip6.
1850 m_adj(m
, off
+ PIM_MINLEN
);
1852 if (mrt6debug
& DEBUG_PIM
) {
1854 "pim6_input: forwarding decapsulated register: "
1855 "src %s, dst %s, mif %d\n",
1856 ip6_sprintf(&eip6
->ip6_src
),
1857 ip6_sprintf(&eip6
->ip6_dst
),
1862 #if defined(__FreeBSD__) && __FreeBSD__ >= 3
1863 rc
= if_simloop(mif6table
[reg_mif_num
].m6_ifp
, m
,
1864 (struct sockaddr
*) &dst
, NULL
);
1866 #if defined (__APPLE__)
1868 dlil_find_dltag(APPLE_IF_FAM_LOOPBACK
, 0, PF_INET6
, &lo_dl_tag
);
1871 dlil_output(lo_dl_tag
, m
, 0, (struct sockaddr
*) &dst
, 0);
1873 printf("Warning: pim6_input call to dlil_find_dltag failed!\n");
1877 rc
= looutput(mif6table
[reg_mif_num
].m6_ifp
, m
,
1878 (struct sockaddr
*) &dst
,
1879 (struct rtentry
*) NULL
);
1883 /* prepare the register head to send to the mrouting daemon */
1888 * Pass the PIM message up to the daemon; if it is a register message
1889 * pass the 'head' only up to the daemon. This includes the
1890 * encapsulator ip6 header, pim header, register header and the
1891 * encapsulated ip6 header.
1893 pim6_input_to_daemon
:
1894 rip6_input(&m
, offp
, proto
);
1895 return(IPPROTO_DONE
);