Home | History | Annotate | Line # | Download | only in netinet6
ip6_forward.c revision 1.12.2.12
      1 /*	$NetBSD: ip6_forward.c,v 1.12.2.12 2004/04/07 22:07:34 jmc Exp $	*/
      2 /*	$KAME: ip6_forward.c,v 1.56 2000/09/22 04:01:37 itojun Exp $	*/
      3 
      4 /*
      5  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
      6  * All rights reserved.
      7  *
      8  * Redistribution and use in source and binary forms, with or without
      9  * modification, are permitted provided that the following conditions
     10  * are met:
     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.
     19  *
     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
     30  * SUCH DAMAGE.
     31  */
     32 
     33 #include "opt_ipsec.h"
     34 #include "opt_pfil_hooks.h"
     35 
     36 #include <sys/param.h>
     37 #include <sys/systm.h>
     38 #include <sys/malloc.h>
     39 #include <sys/mbuf.h>
     40 #include <sys/domain.h>
     41 #include <sys/protosw.h>
     42 #include <sys/socket.h>
     43 #include <sys/errno.h>
     44 #include <sys/time.h>
     45 #include <sys/kernel.h>
     46 #include <sys/syslog.h>
     47 
     48 #include <net/if.h>
     49 #include <net/route.h>
     50 #ifdef PFIL_HOOKS
     51 #include <net/pfil.h>
     52 #endif
     53 
     54 #include <netinet/in.h>
     55 #include <netinet/in_var.h>
     56 #include <netinet/ip_var.h>
     57 #include <netinet/ip6.h>
     58 #include <netinet6/ip6_var.h>
     59 #include <netinet/icmp6.h>
     60 #include <netinet6/nd6.h>
     61 #include <netinet6/ip6protosw.h>
     62 
     63 #ifdef IPSEC
     64 #include <netinet6/ipsec.h>
     65 #include <netkey/key.h>
     66 #endif /* IPSEC */
     67 
     68 #ifdef IPV6FIREWALL
     69 #include <netinet6/ip6_fw.h>
     70 #endif
     71 
     72 #include <net/net_osdep.h>
     73 
     74 struct	route_in6 ip6_forward_rt;
     75 
     76 /*
     77  * Forward a packet.  If some error occurs return the sender
     78  * an icmp packet.  Note we can't always generate a meaningful
     79  * icmp message because icmp doesn't have a large enough repertoire
     80  * of codes and types.
     81  *
     82  * If not forwarding, just drop the packet.  This could be confusing
     83  * if ipforwarding was zero but some routing protocol was advancing
     84  * us as a gateway to somewhere.  However, we must let the routing
     85  * protocol deal with that.
     86  *
     87  */
     88 
     89 void
     90 ip6_forward(m, srcrt)
     91 	struct mbuf *m;
     92 	int srcrt;
     93 {
     94 	struct ip6_hdr *ip6 = mtod(m, struct ip6_hdr *);
     95 	register struct sockaddr_in6 *dst;
     96 	register struct rtentry *rt;
     97 	int error, type = 0, code = 0;
     98 	struct mbuf *mcopy = NULL;
     99 	struct ifnet *origifp;	/* maybe unnecessary */
    100 #ifdef PFIL_HOOKS
    101 	struct packet_filter_hook *pfh;
    102 	struct mbuf *m1;
    103 	int rv;
    104 #endif /* PFIL_HOOKS */
    105 #ifdef IPSEC
    106 	struct secpolicy *sp = NULL;
    107 	int ipsecrt = 0;
    108 #endif
    109 	long time_second = time.tv_sec;
    110 
    111 #ifdef IPSEC
    112 	/*
    113 	 * Check AH/ESP integrity.
    114 	 */
    115 	/*
    116 	 * Don't increment ip6s_cantforward because this is the check
    117 	 * before forwarding packet actually.
    118 	 */
    119 	if (ipsec6_in_reject(m, NULL)) {
    120 		ipsec6stat.in_polvio++;
    121 		m_freem(m);
    122 		return;
    123 	}
    124 #endif /*IPSEC*/
    125 
    126 	/*
    127 	 * Do not forward packets to multicast destination (should be handled
    128 	 * by ip6_mforward().
    129 	 * Do not forward packets with unspecified source.  It was discussed
    130 	 * in July 2000, on ipngwg mailing list.
    131 	 */
    132 	if ((m->m_flags & (M_BCAST|M_MCAST)) != 0 ||
    133 	    IN6_IS_ADDR_MULTICAST(&ip6->ip6_dst) ||
    134 	    IN6_IS_ADDR_UNSPECIFIED(&ip6->ip6_src)) {
    135 		ip6stat.ip6s_cantforward++;
    136 		/* XXX in6_ifstat_inc(rt->rt_ifp, ifs6_in_discard) */
    137 		if (ip6_log_time + ip6_log_interval < time_second) {
    138 			ip6_log_time = time_second;
    139 			log(LOG_DEBUG,
    140 			    "cannot forward "
    141 			    "from %s to %s nxt %d received on %s\n",
    142 			    ip6_sprintf(&ip6->ip6_src),
    143 			    ip6_sprintf(&ip6->ip6_dst),
    144 			    ip6->ip6_nxt,
    145 			    if_name(m->m_pkthdr.rcvif));
    146 		}
    147 		m_freem(m);
    148 		return;
    149 	}
    150 
    151 	if (ip6->ip6_hlim <= IPV6_HLIMDEC) {
    152 		/* XXX in6_ifstat_inc(rt->rt_ifp, ifs6_in_discard) */
    153 		icmp6_error(m, ICMP6_TIME_EXCEEDED,
    154 				ICMP6_TIME_EXCEED_TRANSIT, 0);
    155 		return;
    156 	}
    157 	ip6->ip6_hlim -= IPV6_HLIMDEC;
    158 
    159 	/*
    160 	 * Save at most ICMPV6_PLD_MAXLEN (= the min IPv6 MTU -
    161 	 * size of IPv6 + ICMPv6 headers) bytes of the packet in case
    162 	 * we need to generate an ICMP6 message to the src.
    163 	 * Thanks to M_EXT, in most cases copy will not occur.
    164 	 *
    165 	 * It is important to save it before IPsec processing as IPsec
    166 	 * processing may modify the mbuf.
    167 	 */
    168 	mcopy = m_copy(m, 0, imin(m->m_pkthdr.len, ICMPV6_PLD_MAXLEN));
    169 
    170 #ifdef IPSEC
    171 	/* get a security policy for this packet */
    172 	sp = ipsec6_getpolicybyaddr(m, IPSEC_DIR_OUTBOUND, IP_FORWARDING,
    173 	    &error);
    174 	if (sp == NULL) {
    175 		ipsec6stat.out_inval++;
    176 		ip6stat.ip6s_cantforward++;
    177 		if (mcopy) {
    178 #if 0
    179 			/* XXX: what icmp ? */
    180 #else
    181 			m_freem(mcopy);
    182 #endif
    183 		}
    184 		m_freem(m);
    185 		return;
    186 	}
    187 
    188 	error = 0;
    189 
    190 	/* check policy */
    191 	switch (sp->policy) {
    192 	case IPSEC_POLICY_DISCARD:
    193 		/*
    194 		 * This packet is just discarded.
    195 		 */
    196 		ipsec6stat.out_polvio++;
    197 		ip6stat.ip6s_cantforward++;
    198 		key_freesp(sp);
    199 		if (mcopy) {
    200 #if 0
    201 			/* XXX: what icmp ? */
    202 #else
    203 			m_freem(mcopy);
    204 #endif
    205 		}
    206 		m_freem(m);
    207 		return;
    208 
    209 	case IPSEC_POLICY_BYPASS:
    210 	case IPSEC_POLICY_NONE:
    211 		/* no need to do IPsec. */
    212 		key_freesp(sp);
    213 		goto skip_ipsec;
    214 
    215 	case IPSEC_POLICY_IPSEC:
    216 		if (sp->req == NULL) {
    217 			/* XXX should be panic ? */
    218 			printf("ip6_forward: No IPsec request specified.\n");
    219 			ip6stat.ip6s_cantforward++;
    220 			key_freesp(sp);
    221 			if (mcopy) {
    222 #if 0
    223 				/* XXX: what icmp ? */
    224 #else
    225 				m_freem(mcopy);
    226 #endif
    227 			}
    228 			m_freem(m);
    229 			return;
    230 		}
    231 		/* do IPsec */
    232 		break;
    233 
    234 	case IPSEC_POLICY_ENTRUST:
    235 	default:
    236 		/* should be panic ?? */
    237 		printf("ip6_forward: Invalid policy found. %d\n", sp->policy);
    238 		key_freesp(sp);
    239 		goto skip_ipsec;
    240 	}
    241 
    242     {
    243 	struct ipsec_output_state state;
    244 
    245 	/*
    246 	 * All the extension headers will become inaccessible
    247 	 * (since they can be encrypted).
    248 	 * Don't panic, we need no more updates to extension headers
    249 	 * on inner IPv6 packet (since they are now encapsulated).
    250 	 *
    251 	 * IPv6 [ESP|AH] IPv6 [extension headers] payload
    252 	 */
    253 	bzero(&state, sizeof(state));
    254 	state.m = m;
    255 	state.ro = NULL;	/* update at ipsec6_output_tunnel() */
    256 	state.dst = NULL;	/* update at ipsec6_output_tunnel() */
    257 
    258 	error = ipsec6_output_tunnel(&state, sp, 0);
    259 
    260 	m = state.m;
    261 	key_freesp(sp);
    262 
    263 	if (error) {
    264 		/* mbuf is already reclaimed in ipsec6_output_tunnel. */
    265 		switch (error) {
    266 		case EHOSTUNREACH:
    267 		case ENETUNREACH:
    268 		case EMSGSIZE:
    269 		case ENOBUFS:
    270 		case ENOMEM:
    271 			break;
    272 		default:
    273 			printf("ip6_output (ipsec): error code %d\n", error);
    274 			/*fall through*/
    275 		case ENOENT:
    276 			/* don't show these error codes to the user */
    277 			break;
    278 		}
    279 		ip6stat.ip6s_cantforward++;
    280 		if (mcopy) {
    281 #if 0
    282 			/* XXX: what icmp ? */
    283 #else
    284 			m_freem(mcopy);
    285 #endif
    286 		}
    287 		m_freem(m);
    288 		return;
    289 	}
    290 
    291 	/* adjust pointer */
    292 	ip6 = mtod(m, struct ip6_hdr *);
    293 	rt = state.ro ? state.ro->ro_rt : NULL;
    294 	dst = (struct sockaddr_in6 *)state.dst;
    295 	if (dst != NULL && rt != NULL)
    296 		ipsecrt = 1;
    297     }
    298     skip_ipsec:
    299 
    300 	if (ipsecrt)
    301 		goto skip_routing;
    302 #endif /* IPSEC */
    303 
    304 	dst = &ip6_forward_rt.ro_dst;
    305 	if (!srcrt) {
    306 		/*
    307 		 * ip6_forward_rt.ro_dst.sin6_addr is equal to ip6->ip6_dst
    308 		 */
    309 		if (ip6_forward_rt.ro_rt == 0 ||
    310 		    (ip6_forward_rt.ro_rt->rt_flags & RTF_UP) == 0) {
    311 			if (ip6_forward_rt.ro_rt) {
    312 				RTFREE(ip6_forward_rt.ro_rt);
    313 				ip6_forward_rt.ro_rt = 0;
    314 			}
    315 			/* this probably fails but give it a try again */
    316 			rtalloc((struct route *)&ip6_forward_rt);
    317 		}
    318 
    319 		if (ip6_forward_rt.ro_rt == 0) {
    320 			ip6stat.ip6s_noroute++;
    321 			/* XXX in6_ifstat_inc(rt->rt_ifp, ifs6_in_noroute) */
    322 			if (mcopy) {
    323 				icmp6_error(mcopy, ICMP6_DST_UNREACH,
    324 					    ICMP6_DST_UNREACH_NOROUTE, 0);
    325 			}
    326 			m_freem(m);
    327 			return;
    328 		}
    329 	} else if ((rt = ip6_forward_rt.ro_rt) == 0 ||
    330 		 !IN6_ARE_ADDR_EQUAL(&ip6->ip6_dst, &dst->sin6_addr)) {
    331 		if (ip6_forward_rt.ro_rt) {
    332 			RTFREE(ip6_forward_rt.ro_rt);
    333 			ip6_forward_rt.ro_rt = 0;
    334 		}
    335 		bzero(dst, sizeof(*dst));
    336 		dst->sin6_len = sizeof(struct sockaddr_in6);
    337 		dst->sin6_family = AF_INET6;
    338 		dst->sin6_addr = ip6->ip6_dst;
    339 
    340 		rtalloc((struct route *)&ip6_forward_rt);
    341 		if (ip6_forward_rt.ro_rt == 0) {
    342 			ip6stat.ip6s_noroute++;
    343 			/* XXX in6_ifstat_inc(rt->rt_ifp, ifs6_in_noroute) */
    344 			if (mcopy) {
    345 				icmp6_error(mcopy, ICMP6_DST_UNREACH,
    346 					    ICMP6_DST_UNREACH_NOROUTE, 0);
    347 			}
    348 			m_freem(m);
    349 			return;
    350 		}
    351 	}
    352 	rt = ip6_forward_rt.ro_rt;
    353 #ifdef IPSEC
    354     skip_routing:;
    355 #endif /* IPSEC */
    356 
    357 	/*
    358 	 * Scope check: if a packet can't be delivered to its destination
    359 	 * for the reason that the destination is beyond the scope of the
    360 	 * source address, discard the packet and return an icmp6 destination
    361 	 * unreachable error with Code 2 (beyond scope of source address).
    362 	 * [draft-ietf-ipngwg-icmp-v3-00.txt, Section 3.1]
    363 	 */
    364 	if (in6_addr2scopeid(m->m_pkthdr.rcvif, &ip6->ip6_src) !=
    365 	    in6_addr2scopeid(rt->rt_ifp, &ip6->ip6_src)) {
    366 		ip6stat.ip6s_cantforward++;
    367 		ip6stat.ip6s_badscope++;
    368 		in6_ifstat_inc(rt->rt_ifp, ifs6_in_discard);
    369 
    370 		if (ip6_log_time + ip6_log_interval < time_second) {
    371 			ip6_log_time = time_second;
    372 			log(LOG_DEBUG,
    373 			    "cannot forward "
    374 			    "src %s, dst %s, nxt %d, rcvif %s, outif %s\n",
    375 			    ip6_sprintf(&ip6->ip6_src),
    376 			    ip6_sprintf(&ip6->ip6_dst),
    377 			    ip6->ip6_nxt,
    378 			    if_name(m->m_pkthdr.rcvif), if_name(rt->rt_ifp));
    379 		}
    380 		if (mcopy)
    381 			icmp6_error(mcopy, ICMP6_DST_UNREACH,
    382 				    ICMP6_DST_UNREACH_BEYONDSCOPE, 0);
    383 		m_freem(m);
    384 		return;
    385 	}
    386 
    387 	if (m->m_pkthdr.len > rt->rt_ifp->if_mtu) {
    388 		in6_ifstat_inc(rt->rt_ifp, ifs6_in_toobig);
    389 		if (mcopy) {
    390 			u_long mtu;
    391 #ifdef IPSEC
    392 			struct secpolicy *sp;
    393 			int ipsecerror;
    394 			size_t ipsechdrsiz;
    395 #endif
    396 
    397 			mtu = rt->rt_ifp->if_mtu;
    398 #ifdef IPSEC
    399 			/*
    400 			 * When we do IPsec tunnel ingress, we need to play
    401 			 * with if_mtu value (decrement IPsec header size
    402 			 * from mtu value).  The code is much simpler than v4
    403 			 * case, as we have the outgoing interface for
    404 			 * encapsulated packet as "rt->rt_ifp".
    405 			 */
    406 			sp = ipsec6_getpolicybyaddr(mcopy, IPSEC_DIR_OUTBOUND,
    407 				IP_FORWARDING, &ipsecerror);
    408 			if (sp) {
    409 				ipsechdrsiz = ipsec6_hdrsiz(mcopy,
    410 					IPSEC_DIR_OUTBOUND, NULL);
    411 				if (ipsechdrsiz < mtu)
    412 					mtu -= ipsechdrsiz;
    413 			}
    414 
    415 			/*
    416 			 * if mtu becomes less than minimum MTU,
    417 			 * tell minimum MTU (and I'll need to fragment it).
    418 			 */
    419 			if (mtu < IPV6_MMTU)
    420 				mtu = IPV6_MMTU;
    421 #endif
    422 			icmp6_error(mcopy, ICMP6_PACKET_TOO_BIG, 0, mtu);
    423 		}
    424 		m_freem(m);
    425 		return;
    426  	}
    427 
    428 	if (rt->rt_flags & RTF_GATEWAY)
    429 		dst = (struct sockaddr_in6 *)rt->rt_gateway;
    430 
    431 	/*
    432 	 * If we are to forward the packet using the same interface
    433 	 * as one we got the packet from, perhaps we should send a redirect
    434 	 * to sender to shortcut a hop.
    435 	 * Only send redirect if source is sending directly to us,
    436 	 * and if packet was not source routed (or has any options).
    437 	 * Also, don't send redirect if forwarding using a route
    438 	 * modified by a redirect.
    439 	 */
    440 	if (rt->rt_ifp == m->m_pkthdr.rcvif && !srcrt &&
    441 #ifdef IPSEC
    442 	    !ipsecrt &&
    443 #endif
    444 	    (rt->rt_flags & (RTF_DYNAMIC|RTF_MODIFIED)) == 0) {
    445 		if ((rt->rt_ifp->if_flags & IFF_POINTOPOINT) != 0) {
    446 			/*
    447 			 * If the incoming interface is equal to the outgoing
    448 			 * one, and the link attached to the interface is
    449 			 * point-to-point, then it will be highly probable
    450 			 * that a routing loop occurs. Thus, we immediately
    451 			 * drop the packet and send an ICMPv6 error message.
    452 			 *
    453 			 * type/code is based on suggestion by Rich Draves.
    454 			 * not sure if it is the best pick.
    455 			 */
    456 			icmp6_error(mcopy, ICMP6_DST_UNREACH,
    457 				    ICMP6_DST_UNREACH_ADDR, 0);
    458 			m_freem(m);
    459 			return;
    460 		}
    461 		type = ND_REDIRECT;
    462 	}
    463 
    464 #ifdef IPV6FIREWALL
    465 	/*
    466 	 * Check with the firewall...
    467 	 */
    468 	if (ip6_fw_chk_ptr) {
    469 		u_short port = 0;
    470 		/* If ipfw says divert, we have to just drop packet */
    471 		if ((*ip6_fw_chk_ptr)(&ip6, rt->rt_ifp, &port, &m)) {
    472 			m_freem(m);
    473 			goto freecopy;
    474 		}
    475 		if (!m)
    476 			goto freecopy;
    477 	}
    478 #endif
    479 
    480 	/*
    481 	 * Fake scoped addresses. Note that even link-local source or
    482 	 * destinaion can appear, if the originating node just sends the
    483 	 * packet to us (without address resolution for the destination).
    484 	 * Since both icmp6_error and icmp6_redirect_output fill the embedded
    485 	 * link identifiers, we can do this stuff after make a copy for
    486 	 * returning error.
    487 	 */
    488 	if ((rt->rt_ifp->if_flags & IFF_LOOPBACK) != 0) {
    489 		/*
    490 		 * See corresponding comments in ip6_output.
    491 		 * XXX: but is it possible that ip6_forward() sends a packet
    492 		 *      to a loopback interface? I don't think so, and thus
    493 		 *      I bark here. (jinmei (at) kame.net)
    494 		 * XXX: it is common to route invalid packets to loopback.
    495 		 *	also, the codepath will be visited on use of ::1 in
    496 		 *	rthdr. (itojun)
    497 		 */
    498 #if 1
    499 		if (0)
    500 #else
    501 		if ((rt->rt_flags & (RTF_BLACKHOLE|RTF_REJECT)) == 0)
    502 #endif
    503 		{
    504 			printf("ip6_forward: outgoing interface is loopback. "
    505 			       "src %s, dst %s, nxt %d, rcvif %s, outif %s\n",
    506 			       ip6_sprintf(&ip6->ip6_src),
    507 			       ip6_sprintf(&ip6->ip6_dst),
    508 			       ip6->ip6_nxt, if_name(m->m_pkthdr.rcvif),
    509 			       if_name(rt->rt_ifp));
    510 		}
    511 
    512 		if (IN6_IS_SCOPE_LINKLOCAL(&ip6->ip6_src))
    513 			origifp = ifindex2ifnet[ntohs(ip6->ip6_src.s6_addr16[1])];
    514 		else if (IN6_IS_SCOPE_LINKLOCAL(&ip6->ip6_dst))
    515 			origifp = ifindex2ifnet[ntohs(ip6->ip6_dst.s6_addr16[1])];
    516 		else
    517 			origifp = rt->rt_ifp;
    518 	}
    519 	else
    520 		origifp = rt->rt_ifp;
    521 #ifndef FAKE_LOOPBACK_IF
    522 	if ((rt->rt_ifp->if_flags & IFF_LOOPBACK) == 0)
    523 #else
    524 	if (1)
    525 #endif
    526 	{
    527 		if (IN6_IS_SCOPE_LINKLOCAL(&ip6->ip6_src))
    528 			ip6->ip6_src.s6_addr16[1] = 0;
    529 		if (IN6_IS_SCOPE_LINKLOCAL(&ip6->ip6_dst))
    530 			ip6->ip6_dst.s6_addr16[1] = 0;
    531 	}
    532 
    533 #ifdef PFIL_HOOKS
    534 	/*
    535 	 * Run through list of hooks for output packets.
    536 	 */
    537 	m1 = m;
    538 	pfh = pfil_hook_get(PFIL_OUT,
    539 		&inet6sw[ip6_protox[IPPROTO_IPV6]].pr_pfh);
    540 	for (; pfh; pfh = pfh->pfil_link.tqe_next)
    541 		if (pfh->pfil_func) {
    542 			rv = pfh->pfil_func(ip6, sizeof(*ip6),
    543 					    rt->rt_ifp, 1, &m1);
    544 			m = m1;
    545 			if (m == NULL)
    546 				goto freecopy;
    547 			if (rv) {
    548 				error = EHOSTUNREACH;
    549 				goto senderr;
    550 			}
    551 			ip6 = mtod(m, struct ip6_hdr *);
    552 		}
    553 #endif /* PFIL_HOOKS */
    554 
    555 #ifdef OLDIP6OUTPUT
    556 	error = (*rt->rt_ifp->if_output)(rt->rt_ifp, m,
    557 					 (struct sockaddr *)dst,
    558 					 ip6_forward_rt.ro_rt);
    559 #else
    560 	error = nd6_output(rt->rt_ifp, origifp, m, dst, rt);
    561 #endif
    562 	if (error) {
    563 		in6_ifstat_inc(rt->rt_ifp, ifs6_out_discard);
    564 		ip6stat.ip6s_cantforward++;
    565 	} else {
    566 		ip6stat.ip6s_forward++;
    567 		in6_ifstat_inc(rt->rt_ifp, ifs6_out_forward);
    568 		if (type)
    569 			ip6stat.ip6s_redirectsent++;
    570 		else {
    571 			if (mcopy)
    572 				goto freecopy;
    573 		}
    574 	}
    575 
    576 #ifdef PFIL_HOOKS
    577  senderr:
    578 #endif
    579 	if (mcopy == NULL)
    580 		return;
    581 
    582 	switch (error) {
    583 	case 0:
    584 #if 1
    585 		if (type == ND_REDIRECT) {
    586 			icmp6_redirect_output(mcopy, rt);
    587 			return;
    588 		}
    589 #endif
    590 		goto freecopy;
    591 
    592 	case EMSGSIZE:
    593 		/* xxx MTU is constant in PPP? */
    594 		goto freecopy;
    595 
    596 	case ENOBUFS:
    597 		/* Tell source to slow down like source quench in IP? */
    598 		goto freecopy;
    599 
    600 	case ENETUNREACH:	/* shouldn't happen, checked above */
    601 	case EHOSTUNREACH:
    602 	case ENETDOWN:
    603 	case EHOSTDOWN:
    604 	default:
    605 		type = ICMP6_DST_UNREACH;
    606 		code = ICMP6_DST_UNREACH_ADDR;
    607 		break;
    608 	}
    609 	icmp6_error(mcopy, type, code, 0);
    610 	return;
    611 
    612  freecopy:
    613 	m_freem(mcopy);
    614 	return;
    615 }
    616