2 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the project nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * $KAME: ip6_input.c,v 1.259 2002/01/21 04:58:09 jinmei Exp $
33 * Copyright (c) 1982, 1986, 1988, 1993
34 * The Regents of the University of California. All rights reserved.
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
39 * 1. Redistributions of source code must retain the above copyright
40 * notice, this list of conditions and the following disclaimer.
41 * 2. Redistributions in binary form must reproduce the above copyright
42 * notice, this list of conditions and the following disclaimer in the
43 * documentation and/or other materials provided with the distribution.
44 * 4. Neither the name of the University nor the names of its contributors
45 * may be used to endorse or promote products derived from this software
46 * without specific prior written permission.
48 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
49 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
50 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
51 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
52 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
53 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
54 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
55 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
56 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
57 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
60 * @(#)ip_input.c 8.2 (Berkeley) 1/4/94
63 #include <sys/cdefs.h>
64 __FBSDID("$FreeBSD$");
67 #include "opt_inet6.h"
69 #include "opt_ipsec.h"
70 #include "opt_route.h"
72 #include <sys/param.h>
73 #include <sys/systm.h>
74 #include <sys/malloc.h>
77 #include <sys/domain.h>
78 #include <sys/protosw.h>
80 #include <sys/socket.h>
81 #include <sys/socketvar.h>
82 #include <sys/errno.h>
84 #include <sys/kernel.h>
86 #include <sys/rmlock.h>
87 #include <sys/syslog.h>
90 #include <net/if_var.h>
91 #include <net/if_types.h>
92 #include <net/if_dl.h>
93 #include <net/route.h>
94 #include <net/netisr.h>
98 #include <netinet/in.h>
99 #include <netinet/in_kdtrace.h>
100 #include <netinet/ip_var.h>
101 #include <netinet/in_systm.h>
102 #include <net/if_llatbl.h>
104 #include <netinet/ip.h>
105 #include <netinet/ip_icmp.h>
107 #include <netinet/ip6.h>
108 #include <netinet6/in6_var.h>
109 #include <netinet6/ip6_var.h>
110 #include <netinet/in_pcb.h>
111 #include <netinet/icmp6.h>
112 #include <netinet6/scope6_var.h>
113 #include <netinet6/in6_ifattach.h>
114 #include <netinet6/nd6.h>
117 #include <netipsec/ipsec.h>
118 #include <netinet6/ip6_ipsec.h>
119 #include <netipsec/ipsec6.h>
122 #include <netinet6/ip6protosw.h>
124 extern struct domain inet6domain;
126 u_char ip6_protox[IPPROTO_MAX];
127 VNET_DEFINE(struct in6_ifaddrhead, in6_ifaddrhead);
128 VNET_DEFINE(struct in6_ifaddrlisthead *, in6_ifaddrhashtbl);
129 VNET_DEFINE(u_long, in6_ifaddrhmask);
131 static struct netisr_handler ip6_nh = {
133 .nh_handler = ip6_input,
134 .nh_proto = NETISR_IPV6,
135 .nh_policy = NETISR_POLICY_FLOW,
138 VNET_DECLARE(struct callout, in6_tmpaddrtimer_ch);
139 #define V_in6_tmpaddrtimer_ch VNET(in6_tmpaddrtimer_ch)
141 VNET_DEFINE(struct pfil_head, inet6_pfil_hook);
143 VNET_PCPUSTAT_DEFINE(struct ip6stat, ip6stat);
144 VNET_PCPUSTAT_SYSINIT(ip6stat);
146 VNET_PCPUSTAT_SYSUNINIT(ip6stat);
149 struct rmlock in6_ifaddr_lock;
150 RM_SYSINIT(in6_ifaddr_lock, &in6_ifaddr_lock, "in6_ifaddr_lock");
152 static void ip6_init2(void *);
153 static int ip6_hopopts_input(u_int32_t *, u_int32_t *, struct mbuf **, int *);
155 static struct mbuf *ip6_pullexthdr(struct mbuf *, size_t, int);
159 * IP6 initialization: fill in IP6 protocol switch table.
160 * All protocols not implemented in kernel go to raw IP6 protocol handler.
168 TUNABLE_INT_FETCH("net.inet6.ip6.auto_linklocal",
169 &V_ip6_auto_linklocal);
170 TUNABLE_INT_FETCH("net.inet6.ip6.accept_rtadv", &V_ip6_accept_rtadv);
171 TUNABLE_INT_FETCH("net.inet6.ip6.no_radr", &V_ip6_no_radr);
173 TAILQ_INIT(&V_in6_ifaddrhead);
174 V_in6_ifaddrhashtbl = hashinit(IN6ADDR_NHASH, M_IFADDR,
177 /* Initialize packet filter hooks. */
178 V_inet6_pfil_hook.ph_type = PFIL_TYPE_AF;
179 V_inet6_pfil_hook.ph_af = AF_INET6;
180 if ((i = pfil_head_register(&V_inet6_pfil_hook)) != 0)
181 printf("%s: WARNING: unable to register pfil hook, "
182 "error %d\n", __func__, i);
185 addrsel_policy_init();
189 V_ip6_desync_factor = arc4random() % MAX_TEMP_DESYNC_FACTOR;
191 /* Skip global initialization stuff for non-default instances. */
192 if (!IS_DEFAULT_VNET(curvnet))
195 pr = pffindproto(PF_INET6, IPPROTO_RAW, SOCK_RAW);
199 /* Initialize the entire ip6_protox[] array to IPPROTO_RAW. */
200 for (i = 0; i < IPPROTO_MAX; i++)
201 ip6_protox[i] = pr - inet6sw;
203 * Cycle through IP protocols and put them into the appropriate place
206 for (pr = inet6domain.dom_protosw;
207 pr < inet6domain.dom_protoswNPROTOSW; pr++)
208 if (pr->pr_domain->dom_family == PF_INET6 &&
209 pr->pr_protocol && pr->pr_protocol != IPPROTO_RAW) {
210 /* Be careful to only index valid IP protocols. */
211 if (pr->pr_protocol < IPPROTO_MAX)
212 ip6_protox[pr->pr_protocol] = pr - inet6sw;
215 netisr_register(&ip6_nh);
219 * The protocol to be inserted into ip6_protox[] must be already registered
220 * in inet6sw[], either statically or through pf_proto_register().
223 ip6proto_register(short ip6proto)
228 if (ip6proto <= 0 || ip6proto >= IPPROTO_MAX)
229 return (EPROTONOSUPPORT);
232 * The protocol slot must not be occupied by another protocol
233 * already. An index pointing to IPPROTO_RAW is unused.
235 pr = pffindproto(PF_INET6, IPPROTO_RAW, SOCK_RAW);
237 return (EPFNOSUPPORT);
238 if (ip6_protox[ip6proto] != pr - inet6sw) /* IPPROTO_RAW */
242 * Find the protocol position in inet6sw[] and set the index.
244 for (pr = inet6domain.dom_protosw;
245 pr < inet6domain.dom_protoswNPROTOSW; pr++) {
246 if (pr->pr_domain->dom_family == PF_INET6 &&
247 pr->pr_protocol && pr->pr_protocol == ip6proto) {
248 ip6_protox[pr->pr_protocol] = pr - inet6sw;
252 return (EPROTONOSUPPORT);
256 ip6proto_unregister(short ip6proto)
261 if (ip6proto <= 0 || ip6proto >= IPPROTO_MAX)
262 return (EPROTONOSUPPORT);
264 /* Check if the protocol was indeed registered. */
265 pr = pffindproto(PF_INET6, IPPROTO_RAW, SOCK_RAW);
267 return (EPFNOSUPPORT);
268 if (ip6_protox[ip6proto] == pr - inet6sw) /* IPPROTO_RAW */
271 /* Reset the protocol slot to IPPROTO_RAW. */
272 ip6_protox[ip6proto] = pr - inet6sw;
282 if ((i = pfil_head_unregister(&V_inet6_pfil_hook)) != 0)
283 printf("%s: WARNING: unable to unregister pfil hook, "
284 "error %d\n", __func__, i);
285 hashdestroy(V_in6_ifaddrhashtbl, M_IFADDR, V_in6_ifaddrhmask);
287 callout_drain(&V_in6_tmpaddrtimer_ch);
292 ip6_init2_vnet(const void *unused __unused)
296 callout_init(&V_nd6_timer_ch, 0);
297 callout_reset(&V_nd6_timer_ch, hz, nd6_timer, curvnet);
299 /* timer for regeneranation of temporary addresses randomize ID */
300 callout_init(&V_in6_tmpaddrtimer_ch, 0);
301 callout_reset(&V_in6_tmpaddrtimer_ch,
302 (V_ip6_temp_preferred_lifetime - V_ip6_desync_factor -
303 V_ip6_temp_regen_advance) * hz,
304 in6_tmpaddrtimer, curvnet);
310 ip6_init2(void *dummy)
313 ip6_init2_vnet(NULL);
317 /* This must be after route_init(), which is now SI_ORDER_THIRD */
318 SYSINIT(netinet6init2, SI_SUB_PROTO_DOMAIN, SI_ORDER_MIDDLE, ip6_init2, NULL);
321 ip6_input_hbh(struct mbuf *m, uint32_t *plen, uint32_t *rtalert, int *off,
327 if (ip6_hopopts_input(plen, rtalert, &m, off)) {
328 #if 0 /*touches NULL pointer*/
329 in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_discard);
331 goto out; /* m have already been freed */
335 ip6 = mtod(m, struct ip6_hdr *);
338 * if the payload length field is 0 and the next header field
339 * indicates Hop-by-Hop Options header, then a Jumbo Payload
340 * option MUST be included.
342 if (ip6->ip6_plen == 0 && *plen == 0) {
344 * Note that if a valid jumbo payload option is
345 * contained, ip6_hopopts_input() must set a valid
346 * (non-zero) payload length to the variable plen.
348 IP6STAT_INC(ip6s_badoptions);
349 in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_discard);
350 in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_hdrerr);
351 icmp6_error(m, ICMP6_PARAM_PROB,
352 ICMP6_PARAMPROB_HEADER,
353 (caddr_t)&ip6->ip6_plen - (caddr_t)ip6);
356 #ifndef PULLDOWN_TEST
357 /* ip6_hopopts_input() ensures that mbuf is contiguous */
358 hbh = (struct ip6_hbh *)(ip6 + 1);
360 IP6_EXTHDR_GET(hbh, struct ip6_hbh *, m, sizeof(struct ip6_hdr),
361 sizeof(struct ip6_hbh));
363 IP6STAT_INC(ip6s_tooshort);
367 *nxt = hbh->ip6h_nxt;
370 * If we are acting as a router and the packet contains a
371 * router alert option, see if we know the option value.
372 * Currently, we only support the option value for MLD, in which
373 * case we should pass the packet to the multicast routing
376 if (*rtalert != ~0) {
378 case IP6OPT_RTALERT_MLD:
379 if (V_ip6_forwarding)
384 * RFC2711 requires unrecognized values must be
398 ip6_input(struct mbuf *m)
400 struct in6_addr odst;
402 struct in6_ifaddr *ia;
404 u_int32_t rtalert = ~0;
405 int off = sizeof(struct ip6_hdr), nest;
411 * should the inner packet be considered authentic?
412 * see comment in ah4_input().
413 * NB: m cannot be NULL when passed to the input routine
416 m->m_flags &= ~M_AUTHIPHDR;
417 m->m_flags &= ~M_AUTHIPDGM;
421 if (m->m_flags & M_FASTFWD_OURS) {
423 * Firewall changed destination to local.
425 m->m_flags &= ~M_FASTFWD_OURS;
427 ip6 = mtod(m, struct ip6_hdr *);
434 if (m->m_flags & M_EXT) {
436 IP6STAT_INC(ip6s_mext2m);
438 IP6STAT_INC(ip6s_mext1);
441 if (m->m_flags & M_LOOP) {
442 IP6STAT_INC(ip6s_m2m[V_loif->if_index]);
443 } else if (m->m_pkthdr.rcvif->if_index < IP6S_M2MMAX)
445 ip6s_m2m[m->m_pkthdr.rcvif->if_index]);
447 IP6STAT_INC(ip6s_m2m[0]);
449 IP6STAT_INC(ip6s_m1);
452 /* drop the packet if IPv6 operation is disabled on the IF */
453 if ((ND_IFINFO(m->m_pkthdr.rcvif)->flags & ND6_IFF_IFDISABLED))
456 in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_receive);
457 IP6STAT_INC(ip6s_total);
459 #ifndef PULLDOWN_TEST
461 * L2 bridge code and some other code can return mbuf chain
462 * that does not conform to KAME requirement. too bad.
463 * XXX: fails to join if interface MTU > MCLBYTES. jumbogram?
465 if (m && m->m_next != NULL && m->m_pkthdr.len < MCLBYTES) {
468 if (m->m_pkthdr.len > MHLEN)
469 n = m_getcl(M_NOWAIT, MT_DATA, M_PKTHDR);
471 n = m_gethdr(M_NOWAIT, MT_DATA);
474 return; /* ENOBUFS */
478 m_copydata(m, 0, n->m_pkthdr.len, mtod(n, caddr_t));
479 n->m_len = n->m_pkthdr.len;
483 IP6_EXTHDR_CHECK(m, 0, sizeof(struct ip6_hdr), /* nothing */);
486 if (m->m_len < sizeof(struct ip6_hdr)) {
488 inifp = m->m_pkthdr.rcvif;
489 if ((m = m_pullup(m, sizeof(struct ip6_hdr))) == NULL) {
490 IP6STAT_INC(ip6s_toosmall);
491 in6_ifstat_inc(inifp, ifs6_in_hdrerr);
496 ip6 = mtod(m, struct ip6_hdr *);
498 if ((ip6->ip6_vfc & IPV6_VERSION_MASK) != IPV6_VERSION) {
499 IP6STAT_INC(ip6s_badvers);
500 in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_hdrerr);
504 IP6STAT_INC(ip6s_nxthist[ip6->ip6_nxt]);
506 IP_PROBE(receive, NULL, NULL, ip6, m->m_pkthdr.rcvif, NULL, ip6);
509 * Check against address spoofing/corruption.
511 if (IN6_IS_ADDR_MULTICAST(&ip6->ip6_src) ||
512 IN6_IS_ADDR_UNSPECIFIED(&ip6->ip6_dst)) {
514 * XXX: "badscope" is not very suitable for a multicast source.
516 IP6STAT_INC(ip6s_badscope);
517 in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_addrerr);
520 if (IN6_IS_ADDR_MC_INTFACELOCAL(&ip6->ip6_dst) &&
521 !(m->m_flags & M_LOOP)) {
523 * In this case, the packet should come from the loopback
524 * interface. However, we cannot just check the if_flags,
525 * because ip6_mloopback() passes the "actual" interface
526 * as the outgoing/incoming interface.
528 IP6STAT_INC(ip6s_badscope);
529 in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_addrerr);
532 if (IN6_IS_ADDR_MULTICAST(&ip6->ip6_dst) &&
533 IPV6_ADDR_MC_SCOPE(&ip6->ip6_dst) == 0) {
536 * Nodes must not originate a packet to a multicast address
537 * whose scop field contains the reserved value 0; if such
538 * a packet is received, it must be silently dropped.
540 IP6STAT_INC(ip6s_badscope);
541 in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_addrerr);
545 if (altq_input != NULL && (*altq_input)(m, AF_INET6) == 0) {
546 /* packet is dropped by traffic conditioner */
551 * The following check is not documented in specs. A malicious
552 * party may be able to use IPv4 mapped addr to confuse tcp/udp stack
553 * and bypass security checks (act as if it was from 127.0.0.1 by using
554 * IPv6 src ::ffff:127.0.0.1). Be cautious.
556 * This check chokes if we are in an SIIT cloud. As none of BSDs
557 * support IPv4-less kernel compilation, we cannot support SIIT
558 * environment at all. So, it makes more sense for us to reject any
559 * malicious packets for non-SIIT environment, than try to do a
560 * partial support for SIIT environment.
562 if (IN6_IS_ADDR_V4MAPPED(&ip6->ip6_src) ||
563 IN6_IS_ADDR_V4MAPPED(&ip6->ip6_dst)) {
564 IP6STAT_INC(ip6s_badscope);
565 in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_addrerr);
570 * Reject packets with IPv4 compatible addresses (auto tunnel).
572 * The code forbids auto tunnel relay case in RFC1933 (the check is
573 * stronger than RFC1933). We may want to re-enable it if mech-xx
574 * is revised to forbid relaying case.
576 if (IN6_IS_ADDR_V4COMPAT(&ip6->ip6_src) ||
577 IN6_IS_ADDR_V4COMPAT(&ip6->ip6_dst)) {
578 IP6STAT_INC(ip6s_badscope);
579 in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_addrerr);
585 * Bypass packet filtering for packets previously handled by IPsec.
587 if (ip6_ipsec_filtertunnel(m))
592 * Run through list of hooks for input packets.
594 * NB: Beware of the destination address changing
595 * (e.g. by NAT rewriting). When this happens,
596 * tell ip6_forward to do the right thing.
600 /* Jump over all PFIL processing if hooks are not active. */
601 if (!PFIL_HOOKED(&V_inet6_pfil_hook))
604 if (pfil_run_hooks(&V_inet6_pfil_hook, &m,
605 m->m_pkthdr.rcvif, PFIL_IN, NULL))
607 if (m == NULL) /* consumed by filter */
609 ip6 = mtod(m, struct ip6_hdr *);
610 srcrt = !IN6_ARE_ADDR_EQUAL(&odst, &ip6->ip6_dst);
612 if (m->m_flags & M_FASTFWD_OURS) {
613 m->m_flags &= ~M_FASTFWD_OURS;
617 if ((m->m_flags & M_IP6_NEXTHOP) &&
618 m_tag_find(m, PACKET_TAG_IPFORWARD, NULL) != NULL) {
620 * Directly ship the packet on. This allows forwarding
621 * packets originally destined to us to some other directly
630 * Disambiguate address scope zones (if there is ambiguity).
631 * We first make sure that the original source or destination address
632 * is not in our internal form for scoped addresses. Such addresses
633 * are not necessarily invalid spec-wise, but we cannot accept them due
634 * to the usage conflict.
635 * in6_setscope() then also checks and rejects the cases where src or
636 * dst are the loopback address and the receiving interface
639 if (in6_clearscope(&ip6->ip6_src) || in6_clearscope(&ip6->ip6_dst)) {
640 IP6STAT_INC(ip6s_badscope); /* XXX */
643 if (in6_setscope(&ip6->ip6_src, m->m_pkthdr.rcvif, NULL) ||
644 in6_setscope(&ip6->ip6_dst, m->m_pkthdr.rcvif, NULL)) {
645 IP6STAT_INC(ip6s_badscope);
649 * Multicast check. Assume packet is for us to avoid
650 * prematurely taking locks.
652 if (IN6_IS_ADDR_MULTICAST(&ip6->ip6_dst)) {
654 in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_mcast);
659 * XXX: For now we keep link-local IPv6 addresses with embedded
660 * scope zone id, therefore we use zero zoneid here.
662 ia = in6ifa_ifwithaddr(&ip6->ip6_dst, 0 /* XXX */);
664 if (ia->ia6_flags & IN6_IFF_NOTREADY) {
665 char ip6bufs[INET6_ADDRSTRLEN];
666 char ip6bufd[INET6_ADDRSTRLEN];
667 /* address is not ready, so discard the packet. */
669 "ip6_input: packet to an unready address %s->%s\n",
670 ip6_sprintf(ip6bufs, &ip6->ip6_src),
671 ip6_sprintf(ip6bufd, &ip6->ip6_dst)));
672 ifa_free(&ia->ia_ifa);
675 /* Count the packet in the ip address stats */
676 counter_u64_add(ia->ia_ifa.ifa_ipackets, 1);
677 counter_u64_add(ia->ia_ifa.ifa_ibytes, m->m_pkthdr.len);
678 ifa_free(&ia->ia_ifa);
684 * Now there is no reason to process the packet if it's not our own
685 * and we're not a router.
687 if (!V_ip6_forwarding) {
688 IP6STAT_INC(ip6s_cantforward);
689 in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_discard);
695 * Process Hop-by-Hop options header if it's contained.
696 * m may be modified in ip6_hopopts_input().
697 * If a JumboPayload option is included, plen will also be modified.
699 plen = (u_int32_t)ntohs(ip6->ip6_plen);
700 if (ip6->ip6_nxt == IPPROTO_HOPOPTS) {
701 if (ip6_input_hbh(m, &plen, &rtalert, &off, &nxt, &ours) != 0)
707 * Check that the amount of data in the buffers
708 * is as at least much as the IPv6 header would have us expect.
709 * Trim mbufs if longer than we expect.
710 * Drop packet if shorter than we expect.
712 if (m->m_pkthdr.len - sizeof(struct ip6_hdr) < plen) {
713 IP6STAT_INC(ip6s_tooshort);
714 in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_truncated);
717 if (m->m_pkthdr.len > sizeof(struct ip6_hdr) + plen) {
718 if (m->m_len == m->m_pkthdr.len) {
719 m->m_len = sizeof(struct ip6_hdr) + plen;
720 m->m_pkthdr.len = sizeof(struct ip6_hdr) + plen;
722 m_adj(m, sizeof(struct ip6_hdr) + plen - m->m_pkthdr.len);
726 * Forward if desirable.
729 IN6_IS_ADDR_MULTICAST(&ip6->ip6_dst)) {
731 * If we are acting as a multicast router, all
732 * incoming multicast packets are passed to the
733 * kernel-level multicast forwarding function.
734 * The packet is returned (relatively) intact; if
735 * ip6_mforward() returns a non-zero value, the packet
736 * must be discarded, else it may be accepted below.
738 * XXX TODO: Check hlim and multicast scope here to avoid
739 * unnecessarily calling into ip6_mforward().
742 ip6_mforward(ip6, m->m_pkthdr.rcvif, m)) {
743 IP6STAT_INC(ip6s_cantforward);
744 in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_discard);
748 ip6_forward(m, srcrt);
752 ip6 = mtod(m, struct ip6_hdr *);
755 * Malicious party may be able to use IPv4 mapped addr to confuse
756 * tcp/udp stack and bypass security checks (act as if it was from
757 * 127.0.0.1 by using IPv6 src ::ffff:127.0.0.1). Be cautious.
759 * For SIIT end node behavior, you may want to disable the check.
760 * However, you will become vulnerable to attacks using IPv4 mapped
763 if (IN6_IS_ADDR_V4MAPPED(&ip6->ip6_src) ||
764 IN6_IS_ADDR_V4MAPPED(&ip6->ip6_dst)) {
765 IP6STAT_INC(ip6s_badscope);
766 in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_addrerr);
771 * Tell launch routine the next header
773 IP6STAT_INC(ip6s_delivered);
774 in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_deliver);
777 while (nxt != IPPROTO_DONE) {
778 if (V_ip6_hdrnestlimit && (++nest > V_ip6_hdrnestlimit)) {
779 IP6STAT_INC(ip6s_toomanyhdr);
784 * protection against faulty packet - there should be
785 * more sanity checks in header chain processing.
787 if (m->m_pkthdr.len < off) {
788 IP6STAT_INC(ip6s_tooshort);
789 in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_truncated);
795 * enforce IPsec policy checking if we are seeing last header.
796 * note that we do not visit this with protocols with pcb layer
797 * code - like udp/tcp/raw ip.
799 if (ip6_ipsec_input(m, nxt))
804 * Use mbuf flags to propagate Router Alert option to
805 * ICMPv6 layer, as hop-by-hop options have been stripped.
807 if (nxt == IPPROTO_ICMPV6 && rtalert != ~0)
808 m->m_flags |= M_RTALERT_MLD;
810 nxt = (*inet6sw[ip6_protox[nxt]].pr_input)(&m, &off, nxt);
818 * Hop-by-Hop options header processing. If a valid jumbo payload option is
819 * included, the real payload length will be stored in plenp.
821 * rtalertp - XXX: should be stored more smart way
824 ip6_hopopts_input(u_int32_t *plenp, u_int32_t *rtalertp,
825 struct mbuf **mp, int *offp)
827 struct mbuf *m = *mp;
828 int off = *offp, hbhlen;
831 /* validation of the length of the header */
832 #ifndef PULLDOWN_TEST
833 IP6_EXTHDR_CHECK(m, off, sizeof(*hbh), -1);
834 hbh = (struct ip6_hbh *)(mtod(m, caddr_t) + off);
835 hbhlen = (hbh->ip6h_len + 1) << 3;
837 IP6_EXTHDR_CHECK(m, off, hbhlen, -1);
838 hbh = (struct ip6_hbh *)(mtod(m, caddr_t) + off);
840 IP6_EXTHDR_GET(hbh, struct ip6_hbh *, m,
841 sizeof(struct ip6_hdr), sizeof(struct ip6_hbh));
843 IP6STAT_INC(ip6s_tooshort);
846 hbhlen = (hbh->ip6h_len + 1) << 3;
847 IP6_EXTHDR_GET(hbh, struct ip6_hbh *, m, sizeof(struct ip6_hdr),
850 IP6STAT_INC(ip6s_tooshort);
855 hbhlen -= sizeof(struct ip6_hbh);
856 if (ip6_process_hopopts(m, (u_int8_t *)hbh + sizeof(struct ip6_hbh),
857 hbhlen, rtalertp, plenp) < 0)
866 * Search header for all Hop-by-hop options and process each option.
867 * This function is separate from ip6_hopopts_input() in order to
868 * handle a case where the sending node itself process its hop-by-hop
869 * options header. In such a case, the function is called from ip6_output().
871 * The function assumes that hbh header is located right after the IPv6 header
872 * (RFC2460 p7), opthead is pointer into data content in m, and opthead to
873 * opthead + hbhlen is located in contiguous memory region.
876 ip6_process_hopopts(struct mbuf *m, u_int8_t *opthead, int hbhlen,
877 u_int32_t *rtalertp, u_int32_t *plenp)
881 u_int8_t *opt = opthead;
882 u_int16_t rtalert_val;
884 const int erroff = sizeof(struct ip6_hdr) + sizeof(struct ip6_hbh);
886 for (; hbhlen > 0; hbhlen -= optlen, opt += optlen) {
892 if (hbhlen < IP6OPT_MINLEN) {
893 IP6STAT_INC(ip6s_toosmall);
896 optlen = *(opt + 1) + 2;
898 case IP6OPT_ROUTER_ALERT:
899 /* XXX may need check for alignment */
900 if (hbhlen < IP6OPT_RTALERT_LEN) {
901 IP6STAT_INC(ip6s_toosmall);
904 if (*(opt + 1) != IP6OPT_RTALERT_LEN - 2) {
906 icmp6_error(m, ICMP6_PARAM_PROB,
907 ICMP6_PARAMPROB_HEADER,
908 erroff + opt + 1 - opthead);
911 optlen = IP6OPT_RTALERT_LEN;
912 bcopy((caddr_t)(opt + 2), (caddr_t)&rtalert_val, 2);
913 *rtalertp = ntohs(rtalert_val);
916 /* XXX may need check for alignment */
917 if (hbhlen < IP6OPT_JUMBO_LEN) {
918 IP6STAT_INC(ip6s_toosmall);
921 if (*(opt + 1) != IP6OPT_JUMBO_LEN - 2) {
923 icmp6_error(m, ICMP6_PARAM_PROB,
924 ICMP6_PARAMPROB_HEADER,
925 erroff + opt + 1 - opthead);
928 optlen = IP6OPT_JUMBO_LEN;
931 * IPv6 packets that have non 0 payload length
932 * must not contain a jumbo payload option.
934 ip6 = mtod(m, struct ip6_hdr *);
936 IP6STAT_INC(ip6s_badoptions);
937 icmp6_error(m, ICMP6_PARAM_PROB,
938 ICMP6_PARAMPROB_HEADER,
939 erroff + opt - opthead);
944 * We may see jumbolen in unaligned location, so
945 * we'd need to perform bcopy().
947 bcopy(opt + 2, &jumboplen, sizeof(jumboplen));
948 jumboplen = (u_int32_t)htonl(jumboplen);
952 * if there are multiple jumbo payload options,
953 * *plenp will be non-zero and the packet will be
955 * the behavior may need some debate in ipngwg -
956 * multiple options does not make sense, however,
957 * there's no explicit mention in specification.
960 IP6STAT_INC(ip6s_badoptions);
961 icmp6_error(m, ICMP6_PARAM_PROB,
962 ICMP6_PARAMPROB_HEADER,
963 erroff + opt + 2 - opthead);
969 * jumbo payload length must be larger than 65535.
971 if (jumboplen <= IPV6_MAXPACKET) {
972 IP6STAT_INC(ip6s_badoptions);
973 icmp6_error(m, ICMP6_PARAM_PROB,
974 ICMP6_PARAMPROB_HEADER,
975 erroff + opt + 2 - opthead);
981 default: /* unknown option */
982 if (hbhlen < IP6OPT_MINLEN) {
983 IP6STAT_INC(ip6s_toosmall);
986 optlen = ip6_unknown_opt(opt, m,
987 erroff + opt - opthead);
1003 * Unknown option processing.
1004 * The third argument `off' is the offset from the IPv6 header to the option,
1005 * which is necessary if the IPv6 header the and option header and IPv6 header
1006 * is not contiguous in order to return an ICMPv6 error.
1009 ip6_unknown_opt(u_int8_t *optp, struct mbuf *m, int off)
1011 struct ip6_hdr *ip6;
1013 switch (IP6OPT_TYPE(*optp)) {
1014 case IP6OPT_TYPE_SKIP: /* ignore the option */
1015 return ((int)*(optp + 1));
1016 case IP6OPT_TYPE_DISCARD: /* silently discard */
1019 case IP6OPT_TYPE_FORCEICMP: /* send ICMP even if multicasted */
1020 IP6STAT_INC(ip6s_badoptions);
1021 icmp6_error(m, ICMP6_PARAM_PROB, ICMP6_PARAMPROB_OPTION, off);
1023 case IP6OPT_TYPE_ICMP: /* send ICMP if not multicasted */
1024 IP6STAT_INC(ip6s_badoptions);
1025 ip6 = mtod(m, struct ip6_hdr *);
1026 if (IN6_IS_ADDR_MULTICAST(&ip6->ip6_dst) ||
1027 (m->m_flags & (M_BCAST|M_MCAST)))
1030 icmp6_error(m, ICMP6_PARAM_PROB,
1031 ICMP6_PARAMPROB_OPTION, off);
1035 m_freem(m); /* XXX: NOTREACHED */
1040 * Create the "control" list for this pcb.
1041 * These functions will not modify mbuf chain at all.
1043 * With KAME mbuf chain restriction:
1044 * The routine will be called from upper layer handlers like tcp6_input().
1045 * Thus the routine assumes that the caller (tcp6_input) have already
1046 * called IP6_EXTHDR_CHECK() and all the extension headers are located in the
1047 * very first mbuf on the mbuf chain.
1049 * ip6_savecontrol_v4 will handle those options that are possible to be
1050 * set on a v4-mapped socket.
1051 * ip6_savecontrol will directly call ip6_savecontrol_v4 to handle those
1052 * options and handle the v6-only ones itself.
1055 ip6_savecontrol_v4(struct inpcb *inp, struct mbuf *m, struct mbuf **mp,
1058 struct ip6_hdr *ip6 = mtod(m, struct ip6_hdr *);
1061 if ((inp->inp_socket->so_options & SO_TIMESTAMP) != 0) {
1065 *mp = sbcreatecontrol((caddr_t) &tv, sizeof(tv),
1066 SCM_TIMESTAMP, SOL_SOCKET);
1068 mp = &(*mp)->m_next;
1072 #define IS2292(inp, x, y) (((inp)->inp_flags & IN6P_RFC2292) ? (x) : (y))
1073 /* RFC 2292 sec. 5 */
1074 if ((inp->inp_flags & IN6P_PKTINFO) != 0) {
1075 struct in6_pktinfo pi6;
1077 if ((ip6->ip6_vfc & IPV6_VERSION_MASK) != IPV6_VERSION) {
1081 ip = mtod(m, struct ip *);
1082 pi6.ipi6_addr.s6_addr32[0] = 0;
1083 pi6.ipi6_addr.s6_addr32[1] = 0;
1084 pi6.ipi6_addr.s6_addr32[2] = IPV6_ADDR_INT32_SMP;
1085 pi6.ipi6_addr.s6_addr32[3] = ip->ip_dst.s_addr;
1087 /* We won't hit this code */
1088 bzero(&pi6.ipi6_addr, sizeof(struct in6_addr));
1091 bcopy(&ip6->ip6_dst, &pi6.ipi6_addr, sizeof(struct in6_addr));
1092 in6_clearscope(&pi6.ipi6_addr); /* XXX */
1095 (m && m->m_pkthdr.rcvif) ? m->m_pkthdr.rcvif->if_index : 0;
1097 *mp = sbcreatecontrol((caddr_t) &pi6,
1098 sizeof(struct in6_pktinfo),
1099 IS2292(inp, IPV6_2292PKTINFO, IPV6_PKTINFO), IPPROTO_IPV6);
1101 mp = &(*mp)->m_next;
1104 if ((inp->inp_flags & IN6P_HOPLIMIT) != 0) {
1107 if ((ip6->ip6_vfc & IPV6_VERSION_MASK) != IPV6_VERSION) {
1111 ip = mtod(m, struct ip *);
1114 /* We won't hit this code */
1118 hlim = ip6->ip6_hlim & 0xff;
1120 *mp = sbcreatecontrol((caddr_t) &hlim, sizeof(int),
1121 IS2292(inp, IPV6_2292HOPLIMIT, IPV6_HOPLIMIT),
1124 mp = &(*mp)->m_next;
1127 if ((inp->inp_flags & IN6P_TCLASS) != 0) {
1130 if ((ip6->ip6_vfc & IPV6_VERSION_MASK) != IPV6_VERSION) {
1134 ip = mtod(m, struct ip *);
1135 tclass = ip->ip_tos;
1137 /* We won't hit this code */
1143 flowinfo = (u_int32_t)ntohl(ip6->ip6_flow & IPV6_FLOWINFO_MASK);
1145 tclass = flowinfo & 0xff;
1147 *mp = sbcreatecontrol((caddr_t) &tclass, sizeof(int),
1148 IPV6_TCLASS, IPPROTO_IPV6);
1150 mp = &(*mp)->m_next;
1153 if (v4only != NULL) {
1154 if ((ip6->ip6_vfc & IPV6_VERSION_MASK) != IPV6_VERSION) {
1165 ip6_savecontrol(struct inpcb *in6p, struct mbuf *m, struct mbuf **mp)
1167 struct ip6_hdr *ip6 = mtod(m, struct ip6_hdr *);
1170 mp = ip6_savecontrol_v4(in6p, m, mp, &v4only);
1175 * IPV6_HOPOPTS socket option. Recall that we required super-user
1176 * privilege for the option (see ip6_ctloutput), but it might be too
1177 * strict, since there might be some hop-by-hop options which can be
1178 * returned to normal user.
1179 * See also RFC 2292 section 6 (or RFC 3542 section 8).
1181 if ((in6p->inp_flags & IN6P_HOPOPTS) != 0) {
1183 * Check if a hop-by-hop options header is contatined in the
1184 * received packet, and if so, store the options as ancillary
1185 * data. Note that a hop-by-hop options header must be
1186 * just after the IPv6 header, which is assured through the
1187 * IPv6 input processing.
1189 if (ip6->ip6_nxt == IPPROTO_HOPOPTS) {
1190 struct ip6_hbh *hbh;
1192 #ifdef PULLDOWN_TEST
1196 #ifndef PULLDOWN_TEST
1197 hbh = (struct ip6_hbh *)(ip6 + 1);
1198 hbhlen = (hbh->ip6h_len + 1) << 3;
1200 ext = ip6_pullexthdr(m, sizeof(struct ip6_hdr),
1203 IP6STAT_INC(ip6s_tooshort);
1206 hbh = mtod(ext, struct ip6_hbh *);
1207 hbhlen = (hbh->ip6h_len + 1) << 3;
1208 if (hbhlen != ext->m_len) {
1210 IP6STAT_INC(ip6s_tooshort);
1216 * XXX: We copy the whole header even if a
1217 * jumbo payload option is included, the option which
1218 * is to be removed before returning according to
1220 * Note: this constraint is removed in RFC3542
1222 *mp = sbcreatecontrol((caddr_t)hbh, hbhlen,
1223 IS2292(in6p, IPV6_2292HOPOPTS, IPV6_HOPOPTS),
1226 mp = &(*mp)->m_next;
1227 #ifdef PULLDOWN_TEST
1233 if ((in6p->inp_flags & (IN6P_RTHDR | IN6P_DSTOPTS)) != 0) {
1234 int nxt = ip6->ip6_nxt, off = sizeof(struct ip6_hdr);
1237 * Search for destination options headers or routing
1238 * header(s) through the header chain, and stores each
1239 * header as ancillary data.
1240 * Note that the order of the headers remains in
1241 * the chain of ancillary data.
1243 while (1) { /* is explicit loop prevention necessary? */
1244 struct ip6_ext *ip6e = NULL;
1246 #ifdef PULLDOWN_TEST
1247 struct mbuf *ext = NULL;
1251 * if it is not an extension header, don't try to
1252 * pull it from the chain.
1255 case IPPROTO_DSTOPTS:
1256 case IPPROTO_ROUTING:
1257 case IPPROTO_HOPOPTS:
1258 case IPPROTO_AH: /* is it possible? */
1264 #ifndef PULLDOWN_TEST
1265 if (off + sizeof(*ip6e) > m->m_len)
1267 ip6e = (struct ip6_ext *)(mtod(m, caddr_t) + off);
1268 if (nxt == IPPROTO_AH)
1269 elen = (ip6e->ip6e_len + 2) << 2;
1271 elen = (ip6e->ip6e_len + 1) << 3;
1272 if (off + elen > m->m_len)
1275 ext = ip6_pullexthdr(m, off, nxt);
1277 IP6STAT_INC(ip6s_tooshort);
1280 ip6e = mtod(ext, struct ip6_ext *);
1281 if (nxt == IPPROTO_AH)
1282 elen = (ip6e->ip6e_len + 2) << 2;
1284 elen = (ip6e->ip6e_len + 1) << 3;
1285 if (elen != ext->m_len) {
1287 IP6STAT_INC(ip6s_tooshort);
1293 case IPPROTO_DSTOPTS:
1294 if (!(in6p->inp_flags & IN6P_DSTOPTS))
1297 *mp = sbcreatecontrol((caddr_t)ip6e, elen,
1299 IPV6_2292DSTOPTS, IPV6_DSTOPTS),
1302 mp = &(*mp)->m_next;
1304 case IPPROTO_ROUTING:
1305 if (!(in6p->inp_flags & IN6P_RTHDR))
1308 *mp = sbcreatecontrol((caddr_t)ip6e, elen,
1309 IS2292(in6p, IPV6_2292RTHDR, IPV6_RTHDR),
1312 mp = &(*mp)->m_next;
1314 case IPPROTO_HOPOPTS:
1315 case IPPROTO_AH: /* is it possible? */
1320 * other cases have been filtered in the above.
1321 * none will visit this case. here we supply
1322 * the code just in case (nxt overwritten or
1325 #ifdef PULLDOWN_TEST
1332 /* proceed with the next header. */
1334 nxt = ip6e->ip6e_nxt;
1336 #ifdef PULLDOWN_TEST
1348 ip6_notify_pmtu(struct inpcb *inp, struct sockaddr_in6 *dst, u_int32_t mtu)
1352 struct ip6_mtuinfo mtuctl;
1354 KASSERT(inp != NULL, ("%s: inp == NULL", __func__));
1356 * Notify the error by sending IPV6_PATHMTU ancillary data if
1357 * application wanted to know the MTU value.
1358 * NOTE: we notify disconnected sockets, because some udp
1359 * applications keep sending sockets disconnected.
1360 * NOTE: our implementation doesn't notify connected sockets that has
1361 * foreign address that is different than given destination addresses
1362 * (this is permitted by RFC 3542).
1364 if ((inp->inp_flags & IN6P_MTU) == 0 || (
1365 !IN6_IS_ADDR_UNSPECIFIED(&inp->in6p_faddr) &&
1366 !IN6_ARE_ADDR_EQUAL(&inp->in6p_faddr, &dst->sin6_addr)))
1369 mtuctl.ip6m_mtu = mtu;
1370 mtuctl.ip6m_addr = *dst;
1371 if (sa6_recoverscope(&mtuctl.ip6m_addr))
1374 if ((m_mtu = sbcreatecontrol((caddr_t)&mtuctl, sizeof(mtuctl),
1375 IPV6_PATHMTU, IPPROTO_IPV6)) == NULL)
1378 so = inp->inp_socket;
1379 if (sbappendaddr(&so->so_rcv, (struct sockaddr *)dst, NULL, m_mtu)
1382 /* XXX: should count statistics */
1387 #ifdef PULLDOWN_TEST
1389 * pull single extension header from mbuf chain. returns single mbuf that
1390 * contains the result, or NULL on error.
1392 static struct mbuf *
1393 ip6_pullexthdr(struct mbuf *m, size_t off, int nxt)
1395 struct ip6_ext ip6e;
1401 case IPPROTO_DSTOPTS:
1402 case IPPROTO_ROUTING:
1403 case IPPROTO_HOPOPTS:
1404 case IPPROTO_AH: /* is it possible? */
1407 printf("ip6_pullexthdr: invalid nxt=%d\n", nxt);
1411 m_copydata(m, off, sizeof(ip6e), (caddr_t)&ip6e);
1412 if (nxt == IPPROTO_AH)
1413 elen = (ip6e.ip6e_len + 2) << 2;
1415 elen = (ip6e.ip6e_len + 1) << 3;
1418 n = m_getcl(M_NOWAIT, MT_DATA, 0);
1420 n = m_get(M_NOWAIT, MT_DATA);
1424 m_copydata(m, off, elen, mtod(n, caddr_t));
1431 * Get pointer to the previous header followed by the header
1432 * currently processed.
1433 * XXX: This function supposes that
1434 * M includes all headers,
1435 * the next header field and the header length field of each header
1437 * the sum of each header length equals to OFF.
1438 * Because of these assumptions, this function must be called very
1439 * carefully. Moreover, it will not be used in the near future when
1440 * we develop `neater' mechanism to process extension headers.
1443 ip6_get_prevhdr(struct mbuf *m, int off)
1445 struct ip6_hdr *ip6 = mtod(m, struct ip6_hdr *);
1447 if (off == sizeof(struct ip6_hdr))
1448 return (&ip6->ip6_nxt);
1451 struct ip6_ext *ip6e = NULL;
1454 len = sizeof(struct ip6_hdr);
1456 ip6e = (struct ip6_ext *)(mtod(m, caddr_t) + len);
1459 case IPPROTO_FRAGMENT:
1460 len += sizeof(struct ip6_frag);
1463 len += (ip6e->ip6e_len + 2) << 2;
1466 len += (ip6e->ip6e_len + 1) << 3;
1469 nxt = ip6e->ip6e_nxt;
1472 return (&ip6e->ip6e_nxt);
1479 * get next header offset. m will be retained.
1482 ip6_nexthdr(struct mbuf *m, int off, int proto, int *nxtp)
1485 struct ip6_ext ip6e;
1490 panic("ip6_nexthdr: m == NULL");
1491 if ((m->m_flags & M_PKTHDR) == 0 || m->m_pkthdr.len < off)
1496 if (m->m_pkthdr.len < off + sizeof(ip6))
1498 m_copydata(m, off, sizeof(ip6), (caddr_t)&ip6);
1500 *nxtp = ip6.ip6_nxt;
1504 case IPPROTO_FRAGMENT:
1506 * terminate parsing if it is not the first fragment,
1507 * it does not make sense to parse through it.
1509 if (m->m_pkthdr.len < off + sizeof(fh))
1511 m_copydata(m, off, sizeof(fh), (caddr_t)&fh);
1512 /* IP6F_OFF_MASK = 0xfff8(BigEndian), 0xf8ff(LittleEndian) */
1513 if (fh.ip6f_offlg & IP6F_OFF_MASK)
1516 *nxtp = fh.ip6f_nxt;
1517 off += sizeof(struct ip6_frag);
1521 if (m->m_pkthdr.len < off + sizeof(ip6e))
1523 m_copydata(m, off, sizeof(ip6e), (caddr_t)&ip6e);
1525 *nxtp = ip6e.ip6e_nxt;
1526 off += (ip6e.ip6e_len + 2) << 2;
1529 case IPPROTO_HOPOPTS:
1530 case IPPROTO_ROUTING:
1531 case IPPROTO_DSTOPTS:
1532 if (m->m_pkthdr.len < off + sizeof(ip6e))
1534 m_copydata(m, off, sizeof(ip6e), (caddr_t)&ip6e);
1536 *nxtp = ip6e.ip6e_nxt;
1537 off += (ip6e.ip6e_len + 1) << 3;
1542 case IPPROTO_IPCOMP:
1554 * get offset for the last header in the chain. m will be kept untainted.
1557 ip6_lasthdr(struct mbuf *m, int off, int proto, int *nxtp)
1567 newoff = ip6_nexthdr(m, off, proto, nxtp);
1570 else if (newoff < off)
1571 return -1; /* invalid */
1572 else if (newoff == off)
1581 * System control for IP6
1584 u_char inet6ctlerrmap[PRC_NCMDS] = {
1586 0, EMSGSIZE, EHOSTDOWN, EHOSTUNREACH,
1587 EHOSTUNREACH, EHOSTUNREACH, ECONNREFUSED, ECONNREFUSED,
1588 EMSGSIZE, EHOSTUNREACH, 0, 0,