ip6_forward.c revision 1.64 1 /* $NetBSD: ip6_forward.c,v 1.64 2008/04/15 03:57:04 thorpej Exp $ */
2 /* $KAME: ip6_forward.c,v 1.109 2002/09/11 08:10:17 sakane 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 <sys/cdefs.h>
34 __KERNEL_RCSID(0, "$NetBSD: ip6_forward.c,v 1.64 2008/04/15 03:57:04 thorpej Exp $");
35
36 #include "opt_ipsec.h"
37 #include "opt_pfil_hooks.h"
38
39 #include <sys/param.h>
40 #include <sys/systm.h>
41 #include <sys/malloc.h>
42 #include <sys/mbuf.h>
43 #include <sys/domain.h>
44 #include <sys/protosw.h>
45 #include <sys/socket.h>
46 #include <sys/errno.h>
47 #include <sys/time.h>
48 #include <sys/kernel.h>
49 #include <sys/syslog.h>
50
51 #include <net/if.h>
52 #include <net/route.h>
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 <netinet6/ip6_private.h>
60 #include <netinet6/scope6_var.h>
61 #include <netinet/icmp6.h>
62 #include <netinet6/nd6.h>
63
64 #ifdef IPSEC
65 #include <netinet6/ipsec.h>
66 #include <netkey/key.h>
67 #endif /* IPSEC */
68
69 #ifdef FAST_IPSEC
70 #include <netipsec/ipsec.h>
71 #include <netipsec/ipsec6.h>
72 #include <netipsec/key.h>
73 #include <netipsec/xform.h>
74 #endif /* FAST_IPSEC */
75
76 #ifdef PFIL_HOOKS
77 #include <net/pfil.h>
78 #endif
79
80 #include <net/net_osdep.h>
81
82 struct route ip6_forward_rt;
83
84 #ifdef PFIL_HOOKS
85 extern struct pfil_head inet6_pfil_hook; /* XXX */
86 #endif
87
88 /*
89 * Forward a packet. If some error occurs return the sender
90 * an icmp packet. Note we can't always generate a meaningful
91 * icmp message because icmp doesn't have a large enough repertoire
92 * of codes and types.
93 *
94 * If not forwarding, just drop the packet. This could be confusing
95 * if ipforwarding was zero but some routing protocol was advancing
96 * us as a gateway to somewhere. However, we must let the routing
97 * protocol deal with that.
98 *
99 */
100
101 void
102 ip6_forward(struct mbuf *m, int srcrt)
103 {
104 struct ip6_hdr *ip6 = mtod(m, struct ip6_hdr *);
105 const struct sockaddr_in6 *dst;
106 struct rtentry *rt;
107 int error = 0, type = 0, code = 0;
108 struct mbuf *mcopy = NULL;
109 struct ifnet *origifp; /* maybe unnecessary */
110 u_int32_t inzone, outzone;
111 struct in6_addr src_in6, dst_in6;
112 #ifdef IPSEC
113 struct secpolicy *sp = NULL;
114 int ipsecrt = 0;
115 #endif
116 #ifdef FAST_IPSEC
117 struct secpolicy *sp = NULL;
118 int needipsec = 0;
119 int s;
120 #endif
121
122
123 #ifdef IPSEC
124 /*
125 * Check AH/ESP integrity.
126 */
127 /*
128 * Don't increment ip6s_cantforward because this is the check
129 * before forwarding packet actually.
130 */
131 if (ipsec6_in_reject(m, NULL)) {
132 ipsec6stat.in_polvio++;
133 m_freem(m);
134 return;
135 }
136 #endif /* IPSEC */
137
138 /*
139 * Do not forward packets to multicast destination (should be handled
140 * by ip6_mforward().
141 * Do not forward packets with unspecified source. It was discussed
142 * in July 2000, on ipngwg mailing list.
143 */
144 if ((m->m_flags & (M_BCAST|M_MCAST)) != 0 ||
145 IN6_IS_ADDR_MULTICAST(&ip6->ip6_dst) ||
146 IN6_IS_ADDR_UNSPECIFIED(&ip6->ip6_src)) {
147 IP6_STATINC(IP6_STAT_CANTFORWARD);
148 /* XXX in6_ifstat_inc(rt->rt_ifp, ifs6_in_discard) */
149 if (ip6_log_time + ip6_log_interval < time_second) {
150 ip6_log_time = time_second;
151 log(LOG_DEBUG,
152 "cannot forward "
153 "from %s to %s nxt %d received on %s\n",
154 ip6_sprintf(&ip6->ip6_src),
155 ip6_sprintf(&ip6->ip6_dst),
156 ip6->ip6_nxt,
157 if_name(m->m_pkthdr.rcvif));
158 }
159 m_freem(m);
160 return;
161 }
162
163 if (ip6->ip6_hlim <= IPV6_HLIMDEC) {
164 /* XXX in6_ifstat_inc(rt->rt_ifp, ifs6_in_discard) */
165 icmp6_error(m, ICMP6_TIME_EXCEEDED,
166 ICMP6_TIME_EXCEED_TRANSIT, 0);
167 return;
168 }
169 ip6->ip6_hlim -= IPV6_HLIMDEC;
170
171 /*
172 * Save at most ICMPV6_PLD_MAXLEN (= the min IPv6 MTU -
173 * size of IPv6 + ICMPv6 headers) bytes of the packet in case
174 * we need to generate an ICMP6 message to the src.
175 * Thanks to M_EXT, in most cases copy will not occur.
176 *
177 * It is important to save it before IPsec processing as IPsec
178 * processing may modify the mbuf.
179 */
180 mcopy = m_copy(m, 0, imin(m->m_pkthdr.len, ICMPV6_PLD_MAXLEN));
181
182 #ifdef IPSEC
183 /* get a security policy for this packet */
184 sp = ipsec6_getpolicybyaddr(m, IPSEC_DIR_OUTBOUND,
185 IP_FORWARDING, &error);
186 if (sp == NULL) {
187 ipsec6stat.out_inval++;
188 IP6_STATINC(IP6_STAT_CANTFORWARD);
189 if (mcopy) {
190 #if 0
191 /* XXX: what icmp ? */
192 #else
193 m_freem(mcopy);
194 #endif
195 }
196 m_freem(m);
197 return;
198 }
199
200 error = 0;
201
202 /* check policy */
203 switch (sp->policy) {
204 case IPSEC_POLICY_DISCARD:
205 /*
206 * This packet is just discarded.
207 */
208 ipsec6stat.out_polvio++;
209 IP6_STATINC(IP6_STAT_CANTFORWARD);
210 key_freesp(sp);
211 if (mcopy) {
212 #if 0
213 /* XXX: what icmp ? */
214 #else
215 m_freem(mcopy);
216 #endif
217 }
218 m_freem(m);
219 return;
220
221 case IPSEC_POLICY_BYPASS:
222 case IPSEC_POLICY_NONE:
223 /* no need to do IPsec. */
224 key_freesp(sp);
225 goto skip_ipsec;
226
227 case IPSEC_POLICY_IPSEC:
228 if (sp->req == NULL) {
229 /* XXX should be panic ? */
230 printf("ip6_forward: No IPsec request specified.\n");
231 IP6_STATINC(IP6_STAT_CANTFORWARD);
232 key_freesp(sp);
233 if (mcopy) {
234 #if 0
235 /* XXX: what icmp ? */
236 #else
237 m_freem(mcopy);
238 #endif
239 }
240 m_freem(m);
241 return;
242 }
243 /* do IPsec */
244 break;
245
246 case IPSEC_POLICY_ENTRUST:
247 default:
248 /* should be panic ?? */
249 printf("ip6_forward: Invalid policy found. %d\n", sp->policy);
250 key_freesp(sp);
251 goto skip_ipsec;
252 }
253
254 {
255 struct ipsecrequest *isr = NULL;
256 struct ipsec_output_state state;
257
258 /*
259 * when the kernel forwards a packet, it is not proper to apply
260 * IPsec transport mode to the packet is not proper. this check
261 * avoid from this.
262 * at present, if there is even a transport mode SA request in the
263 * security policy, the kernel does not apply IPsec to the packet.
264 * this check is not enough because the following case is valid.
265 * ipsec esp/tunnel/xxx-xxx/require esp/transport//require;
266 */
267 for (isr = sp->req; isr; isr = isr->next) {
268 if (isr->saidx.mode == IPSEC_MODE_ANY)
269 goto doipsectunnel;
270 if (isr->saidx.mode == IPSEC_MODE_TUNNEL)
271 goto doipsectunnel;
272 }
273
274 /*
275 * if there's no need for tunnel mode IPsec, skip.
276 */
277 if (!isr)
278 goto skip_ipsec;
279
280 doipsectunnel:
281 /*
282 * All the extension headers will become inaccessible
283 * (since they can be encrypted).
284 * Don't panic, we need no more updates to extension headers
285 * on inner IPv6 packet (since they are now encapsulated).
286 *
287 * IPv6 [ESP|AH] IPv6 [extension headers] payload
288 */
289 bzero(&state, sizeof(state));
290 state.m = m;
291 state.ro = NULL; /* update at ipsec6_output_tunnel() */
292 state.dst = NULL; /* update at ipsec6_output_tunnel() */
293
294 error = ipsec6_output_tunnel(&state, sp, 0);
295
296 m = state.m;
297 key_freesp(sp);
298
299 if (error) {
300 /* mbuf is already reclaimed in ipsec6_output_tunnel. */
301 switch (error) {
302 case EHOSTUNREACH:
303 case ENETUNREACH:
304 case EMSGSIZE:
305 case ENOBUFS:
306 case ENOMEM:
307 break;
308 default:
309 printf("ip6_forward (ipsec): error code %d\n", error);
310 /* FALLTHROUGH */
311 case ENOENT:
312 /* don't show these error codes to the user */
313 break;
314 }
315 IP6_STATINC(IP6_STAT_CANTFORWARD);
316 if (mcopy) {
317 #if 0
318 /* XXX: what icmp ? */
319 #else
320 m_freem(mcopy);
321 #endif
322 }
323 m_freem(m);
324 return;
325 }
326
327 if (ip6 != mtod(m, struct ip6_hdr *)) {
328 /*
329 * now tunnel mode headers are added. we are originating
330 * packet instead of forwarding the packet.
331 */
332 ip6_output(m, NULL, NULL, IPV6_FORWARDING/*XXX*/, NULL, NULL,
333 NULL);
334 goto freecopy;
335 }
336
337 /* adjust pointer */
338 rt = state.ro ? rtcache_validate(state.ro) : NULL;
339 dst = (const struct sockaddr_in6 *)state.dst;
340 if (dst != NULL && rt != NULL) {
341 ipsecrt = 1;
342 goto skip_routing;
343 }
344 }
345 skip_ipsec:
346 #endif /* IPSEC */
347 #ifdef FAST_IPSEC
348 /* Check the security policy (SP) for the packet */
349
350 sp = ipsec6_check_policy(m,NULL,0,&needipsec,&error);
351 if (error != 0) {
352 /*
353 * Hack: -EINVAL is used to signal that a packet
354 * should be silently discarded. This is typically
355 * because we asked key management for an SA and
356 * it was delayed (e.g. kicked up to IKE).
357 */
358 if (error == -EINVAL)
359 error = 0;
360 goto freecopy;
361 }
362 #endif /* FAST_IPSEC */
363
364 if (srcrt) {
365 union {
366 struct sockaddr dst;
367 struct sockaddr_in6 dst6;
368 } u;
369
370 sockaddr_in6_init(&u.dst6, &ip6->ip6_dst, 0, 0, 0);
371 if ((rt = rtcache_lookup(&ip6_forward_rt, &u.dst)) == NULL) {
372 IP6_STATINC(IP6_STAT_NOROUTE);
373 /* XXX in6_ifstat_inc(rt->rt_ifp, ifs6_in_noroute) */
374 if (mcopy) {
375 icmp6_error(mcopy, ICMP6_DST_UNREACH,
376 ICMP6_DST_UNREACH_NOROUTE, 0);
377 }
378 m_freem(m);
379 return;
380 }
381 } else if ((rt = rtcache_validate(&ip6_forward_rt)) == NULL &&
382 (rt = rtcache_update(&ip6_forward_rt, 1)) == NULL) {
383 /*
384 * rtcache_getdst(ip6_forward_rt)->sin6_addr was equal to
385 * ip6->ip6_dst
386 */
387 IP6_STATINC(IP6_STAT_NOROUTE);
388 /* XXX in6_ifstat_inc(rt->rt_ifp, ifs6_in_noroute) */
389 if (mcopy) {
390 icmp6_error(mcopy, ICMP6_DST_UNREACH,
391 ICMP6_DST_UNREACH_NOROUTE, 0);
392 }
393 m_freem(m);
394 return;
395 }
396 dst = satocsin6(rtcache_getdst(&ip6_forward_rt));
397 #ifdef IPSEC
398 skip_routing:;
399 #endif /* IPSEC */
400
401 /*
402 * Source scope check: if a packet can't be delivered to its
403 * destination for the reason that the destination is beyond the scope
404 * of the source address, discard the packet and return an icmp6
405 * destination unreachable error with Code 2 (beyond scope of source
406 * address). We use a local copy of ip6_src, since in6_setscope()
407 * will possibly modify its first argument.
408 * [draft-ietf-ipngwg-icmp-v3-07, Section 3.1]
409 */
410 src_in6 = ip6->ip6_src;
411 if (in6_setscope(&src_in6, rt->rt_ifp, &outzone)) {
412 /* XXX: this should not happen */
413 uint64_t *ip6s = IP6_STAT_GETREF();
414 ip6s[IP6_STAT_CANTFORWARD]++;
415 ip6s[IP6_STAT_BADSCOPE]++;
416 IP6_STAT_PUTREF();
417 m_freem(m);
418 return;
419 }
420 if (in6_setscope(&src_in6, m->m_pkthdr.rcvif, &inzone)) {
421 uint64_t *ip6s = IP6_STAT_GETREF();
422 ip6s[IP6_STAT_CANTFORWARD]++;
423 ip6s[IP6_STAT_BADSCOPE]++;
424 IP6_STAT_PUTREF();
425 m_freem(m);
426 return;
427 }
428 if (inzone != outzone
429 #ifdef IPSEC
430 && !ipsecrt
431 #endif
432 ) {
433 uint64_t *ip6s = IP6_STAT_GETREF();
434 ip6s[IP6_STAT_CANTFORWARD]++;
435 ip6s[IP6_STAT_BADSCOPE]++;
436 IP6_STAT_PUTREF();
437 in6_ifstat_inc(rt->rt_ifp, ifs6_in_discard);
438
439 if (ip6_log_time + ip6_log_interval < time_second) {
440 ip6_log_time = time_second;
441 log(LOG_DEBUG,
442 "cannot forward "
443 "src %s, dst %s, nxt %d, rcvif %s, outif %s\n",
444 ip6_sprintf(&ip6->ip6_src),
445 ip6_sprintf(&ip6->ip6_dst),
446 ip6->ip6_nxt,
447 if_name(m->m_pkthdr.rcvif), if_name(rt->rt_ifp));
448 }
449 if (mcopy)
450 icmp6_error(mcopy, ICMP6_DST_UNREACH,
451 ICMP6_DST_UNREACH_BEYONDSCOPE, 0);
452 m_freem(m);
453 return;
454 }
455 #ifdef FAST_IPSEC
456 /*
457 * If we need to encapsulate the packet, do it here
458 * ipsec6_proces_packet will send the packet using ip6_output
459 */
460 if (needipsec) {
461 s = splsoftnet();
462 error = ipsec6_process_packet(m,sp->req);
463 splx(s);
464 if (mcopy)
465 goto freecopy;
466 }
467 #endif
468
469
470
471 /*
472 * Destination scope check: if a packet is going to break the scope
473 * zone of packet's destination address, discard it. This case should
474 * usually be prevented by appropriately-configured routing table, but
475 * we need an explicit check because we may mistakenly forward the
476 * packet to a different zone by (e.g.) a default route.
477 */
478 dst_in6 = ip6->ip6_dst;
479 if (in6_setscope(&dst_in6, m->m_pkthdr.rcvif, &inzone) != 0 ||
480 in6_setscope(&dst_in6, rt->rt_ifp, &outzone) != 0 ||
481 inzone != outzone) {
482 uint64_t *ip6s = IP6_STAT_GETREF();
483 ip6s[IP6_STAT_CANTFORWARD]++;
484 ip6s[IP6_STAT_BADSCOPE]++;
485 IP6_STAT_PUTREF();
486 m_freem(m);
487 return;
488 }
489
490 if (m->m_pkthdr.len > IN6_LINKMTU(rt->rt_ifp)) {
491 in6_ifstat_inc(rt->rt_ifp, ifs6_in_toobig);
492 if (mcopy) {
493 u_long mtu;
494 #ifdef IPSEC
495 struct secpolicy *xsp;
496 int ipsecerror;
497 size_t ipsechdrsiz;
498 #endif
499
500 mtu = IN6_LINKMTU(rt->rt_ifp);
501 #ifdef IPSEC
502 /*
503 * When we do IPsec tunnel ingress, we need to play
504 * with the link value (decrement IPsec header size
505 * from mtu value). The code is much simpler than v4
506 * case, as we have the outgoing interface for
507 * encapsulated packet as "rt->rt_ifp".
508 */
509 xsp = ipsec6_getpolicybyaddr(mcopy, IPSEC_DIR_OUTBOUND,
510 IP_FORWARDING, &ipsecerror);
511 if (xsp) {
512 ipsechdrsiz = ipsec6_hdrsiz(mcopy,
513 IPSEC_DIR_OUTBOUND, NULL);
514 if (ipsechdrsiz < mtu)
515 mtu -= ipsechdrsiz;
516 }
517
518 /*
519 * if mtu becomes less than minimum MTU,
520 * tell minimum MTU (and I'll need to fragment it).
521 */
522 if (mtu < IPV6_MMTU)
523 mtu = IPV6_MMTU;
524 #endif
525 icmp6_error(mcopy, ICMP6_PACKET_TOO_BIG, 0, mtu);
526 }
527 m_freem(m);
528 return;
529 }
530
531 if (rt->rt_flags & RTF_GATEWAY)
532 dst = (struct sockaddr_in6 *)rt->rt_gateway;
533
534 /*
535 * If we are to forward the packet using the same interface
536 * as one we got the packet from, perhaps we should send a redirect
537 * to sender to shortcut a hop.
538 * Only send redirect if source is sending directly to us,
539 * and if packet was not source routed (or has any options).
540 * Also, don't send redirect if forwarding using a route
541 * modified by a redirect.
542 */
543 if (rt->rt_ifp == m->m_pkthdr.rcvif && !srcrt && ip6_sendredirects &&
544 #ifdef IPSEC
545 !ipsecrt &&
546 #endif
547 (rt->rt_flags & (RTF_DYNAMIC|RTF_MODIFIED)) == 0) {
548 if ((rt->rt_ifp->if_flags & IFF_POINTOPOINT) &&
549 nd6_is_addr_neighbor(
550 satocsin6(rtcache_getdst(&ip6_forward_rt)),
551 rt->rt_ifp)) {
552 /*
553 * If the incoming interface is equal to the outgoing
554 * one, the link attached to the interface is
555 * point-to-point, and the IPv6 destination is
556 * regarded as on-link on the link, then it will be
557 * highly probable that the destination address does
558 * not exist on the link and that the packet is going
559 * to loop. Thus, we immediately drop the packet and
560 * send an ICMPv6 error message.
561 * For other routing loops, we dare to let the packet
562 * go to the loop, so that a remote diagnosing host
563 * can detect the loop by traceroute.
564 * type/code is based on suggestion by Rich Draves.
565 * not sure if it is the best pick.
566 */
567 icmp6_error(mcopy, ICMP6_DST_UNREACH,
568 ICMP6_DST_UNREACH_ADDR, 0);
569 m_freem(m);
570 return;
571 }
572 type = ND_REDIRECT;
573 }
574
575 /*
576 * Fake scoped addresses. Note that even link-local source or
577 * destinaion can appear, if the originating node just sends the
578 * packet to us (without address resolution for the destination).
579 * Since both icmp6_error and icmp6_redirect_output fill the embedded
580 * link identifiers, we can do this stuff after making a copy for
581 * returning an error.
582 */
583 if ((rt->rt_ifp->if_flags & IFF_LOOPBACK) != 0) {
584 /*
585 * See corresponding comments in ip6_output.
586 * XXX: but is it possible that ip6_forward() sends a packet
587 * to a loopback interface? I don't think so, and thus
588 * I bark here. (jinmei (at) kame.net)
589 * XXX: it is common to route invalid packets to loopback.
590 * also, the codepath will be visited on use of ::1 in
591 * rthdr. (itojun)
592 */
593 #if 1
594 if (0)
595 #else
596 if ((rt->rt_flags & (RTF_BLACKHOLE|RTF_REJECT)) == 0)
597 #endif
598 {
599 printf("ip6_forward: outgoing interface is loopback. "
600 "src %s, dst %s, nxt %d, rcvif %s, outif %s\n",
601 ip6_sprintf(&ip6->ip6_src),
602 ip6_sprintf(&ip6->ip6_dst),
603 ip6->ip6_nxt, if_name(m->m_pkthdr.rcvif),
604 if_name(rt->rt_ifp));
605 }
606
607 /* we can just use rcvif in forwarding. */
608 origifp = m->m_pkthdr.rcvif;
609 }
610 else
611 origifp = rt->rt_ifp;
612 /*
613 * clear embedded scope identifiers if necessary.
614 * in6_clearscope will touch the addresses only when necessary.
615 */
616 in6_clearscope(&ip6->ip6_src);
617 in6_clearscope(&ip6->ip6_dst);
618
619 #ifdef PFIL_HOOKS
620 /*
621 * Run through list of hooks for output packets.
622 */
623 if ((error = pfil_run_hooks(&inet6_pfil_hook, &m, rt->rt_ifp,
624 PFIL_OUT)) != 0)
625 goto senderr;
626 if (m == NULL)
627 goto freecopy;
628 ip6 = mtod(m, struct ip6_hdr *);
629 #endif /* PFIL_HOOKS */
630
631 error = nd6_output(rt->rt_ifp, origifp, m, dst, rt);
632 if (error) {
633 in6_ifstat_inc(rt->rt_ifp, ifs6_out_discard);
634 IP6_STATINC(IP6_STAT_CANTFORWARD);
635 } else {
636 IP6_STATINC(IP6_STAT_FORWARD);
637 in6_ifstat_inc(rt->rt_ifp, ifs6_out_forward);
638 if (type)
639 IP6_STATINC(IP6_STAT_REDIRECTSENT);
640 else {
641 #ifdef GATEWAY
642 if (m->m_flags & M_CANFASTFWD)
643 ip6flow_create(&ip6_forward_rt, m);
644 #endif
645 if (mcopy)
646 goto freecopy;
647 }
648 }
649
650 #ifdef PFIL_HOOKS
651 senderr:
652 #endif
653 if (mcopy == NULL)
654 return;
655 switch (error) {
656 case 0:
657 if (type == ND_REDIRECT) {
658 icmp6_redirect_output(mcopy, rt);
659 return;
660 }
661 goto freecopy;
662
663 case EMSGSIZE:
664 /* xxx MTU is constant in PPP? */
665 goto freecopy;
666
667 case ENOBUFS:
668 /* Tell source to slow down like source quench in IP? */
669 goto freecopy;
670
671 case ENETUNREACH: /* shouldn't happen, checked above */
672 case EHOSTUNREACH:
673 case ENETDOWN:
674 case EHOSTDOWN:
675 default:
676 type = ICMP6_DST_UNREACH;
677 code = ICMP6_DST_UNREACH_ADDR;
678 break;
679 }
680 icmp6_error(mcopy, type, code, 0);
681 return;
682
683 freecopy:
684 m_freem(mcopy);
685 return;
686 }
687