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