2 * Copyright (c) 2003-2013 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
30 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
31 * All rights reserved.
33 * Redistribution and use in source and binary forms, with or without
34 * modification, are permitted provided that the following conditions
36 * 1. Redistributions of source code must retain the above copyright
37 * notice, this list of conditions and the following disclaimer.
38 * 2. Redistributions in binary form must reproduce the above copyright
39 * notice, this list of conditions and the following disclaimer in the
40 * documentation and/or other materials provided with the distribution.
41 * 3. Neither the name of the project nor the names of its contributors
42 * may be used to endorse or promote products derived from this software
43 * without specific prior written permission.
45 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
46 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
47 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
48 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
49 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
50 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
51 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
52 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
53 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
54 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
59 * Copyright (c) 1982, 1986, 1988, 1993
60 * The Regents of the University of California. All rights reserved.
62 * Redistribution and use in source and binary forms, with or without
63 * modification, are permitted provided that the following conditions
65 * 1. Redistributions of source code must retain the above copyright
66 * notice, this list of conditions and the following disclaimer.
67 * 2. Redistributions in binary form must reproduce the above copyright
68 * notice, this list of conditions and the following disclaimer in the
69 * documentation and/or other materials provided with the distribution.
70 * 3. All advertising materials mentioning features or use of this software
71 * must display the following acknowledgement:
72 * This product includes software developed by the University of
73 * California, Berkeley and its contributors.
74 * 4. Neither the name of the University nor the names of its contributors
75 * may be used to endorse or promote products derived from this software
76 * without specific prior written permission.
78 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
79 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
80 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
81 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
82 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
83 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
84 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
85 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
86 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
87 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
90 * @(#)ip_input.c 8.2 (Berkeley) 1/4/94
93 #include <sys/param.h>
94 #include <sys/systm.h>
95 #include <sys/malloc.h>
97 #include <sys/domain.h>
98 #include <sys/protosw.h>
99 #include <sys/socket.h>
100 #include <sys/socketvar.h>
101 #include <sys/errno.h>
102 #include <sys/time.h>
103 #include <sys/kernel.h>
104 #include <sys/syslog.h>
105 #include <sys/sysctl.h>
106 #include <sys/proc.h>
107 #include <sys/kauth.h>
108 #include <sys/mcache.h>
110 #include <mach/mach_time.h>
111 #include <mach/sdt.h>
112 #include <pexpert/pexpert.h>
113 #include <dev/random/randomdev.h>
116 #include <net/if_var.h>
117 #include <net/if_types.h>
118 #include <net/if_dl.h>
119 #include <net/route.h>
120 #include <net/kpi_protocol.h>
121 #include <net/ntstat.h>
122 #include <net/init.h>
123 #include <net/net_osdep.h>
125 #include <netinet/in.h>
126 #include <netinet/in_systm.h>
128 #include <netinet/ip.h>
129 #include <netinet/ip_icmp.h>
131 #include <netinet/kpi_ipfilter_var.h>
132 #include <netinet/ip6.h>
133 #include <netinet6/in6_var.h>
134 #include <netinet6/ip6_var.h>
135 #include <netinet/in_pcb.h>
136 #include <netinet/icmp6.h>
137 #include <netinet6/in6_ifattach.h>
138 #include <netinet6/nd6.h>
139 #include <netinet6/scope6_var.h>
140 #include <netinet6/ip6protosw.h>
143 #include <netinet6/ipsec.h>
144 #include <netinet6/ipsec6.h>
145 extern int ipsec_bypass
;
149 #include <netinet6/ip6_fw.h>
153 #include <netinet/ip_fw.h>
154 #include <netinet/ip_dummynet.h>
155 #endif /* DUMMYNET */
157 /* we need it for NLOOP. */
161 #include <net/pfvar.h>
164 struct ip6protosw
*ip6_protox
[IPPROTO_MAX
];
166 static lck_grp_attr_t
*in6_ifaddr_rwlock_grp_attr
;
167 static lck_grp_t
*in6_ifaddr_rwlock_grp
;
168 static lck_attr_t
*in6_ifaddr_rwlock_attr
;
169 decl_lck_rw_data(, in6_ifaddr_rwlock
);
171 /* Protected by in6_ifaddr_rwlock */
172 struct in6_ifaddr
*in6_ifaddrs
= NULL
;
174 #define IN6_IFSTAT_REQUIRE_ALIGNED_64(f) \
175 _CASSERT(!(offsetof(struct in6_ifstat, f) % sizeof (uint64_t)))
177 #define ICMP6_IFSTAT_REQUIRE_ALIGNED_64(f) \
178 _CASSERT(!(offsetof(struct icmp6_ifstat, f) % sizeof (uint64_t)))
182 ip6_fw_chk_t
*ip6_fw_chk_ptr
;
183 ip6_fw_ctl_t
*ip6_fw_ctl_ptr
;
184 int ip6_fw_enable
= 1;
187 struct ip6stat ip6stat
;
189 decl_lck_mtx_data(, proxy6_lock
);
190 decl_lck_mtx_data(static, dad6_mutex_data
);
191 decl_lck_mtx_data(static, nd6_mutex_data
);
192 decl_lck_mtx_data(static, prefix6_mutex_data
);
193 lck_mtx_t
*dad6_mutex
= &dad6_mutex_data
;
194 lck_mtx_t
*nd6_mutex
= &nd6_mutex_data
;
195 lck_mtx_t
*prefix6_mutex
= &prefix6_mutex_data
;
196 #ifdef ENABLE_ADDRSEL
197 decl_lck_mtx_data(static, addrsel_mutex_data
);
198 lck_mtx_t
*addrsel_mutex
= &addrsel_mutex_data
;
200 static lck_attr_t
*ip6_mutex_attr
;
201 static lck_grp_t
*ip6_mutex_grp
;
202 static lck_grp_attr_t
*ip6_mutex_grp_attr
;
204 extern int loopattach_done
;
205 extern void addrsel_policy_init(void);
207 static void ip6_init_delayed(void);
208 static int ip6_hopopts_input(u_int32_t
*, u_int32_t
*, struct mbuf
**, int *);
210 static struct mbuf
*ip6_pullexthdr(struct mbuf
*, size_t, int);
214 extern void stfattach(void);
217 SYSCTL_DECL(_net_inet6_ip6
);
219 int ip6_doscopedroute
= 1;
220 SYSCTL_INT(_net_inet6_ip6
, OID_AUTO
, scopedroute
,
221 CTLFLAG_RD
| CTLFLAG_LOCKED
, &ip6_doscopedroute
, 0,
222 "Enable IPv6 scoped routing");
224 static uint32_t ip6_adj_clear_hwcksum
= 0;
225 SYSCTL_UINT(_net_inet6_ip6
, OID_AUTO
, adj_clear_hwcksum
,
226 CTLFLAG_RW
| CTLFLAG_LOCKED
, &ip6_adj_clear_hwcksum
, 0,
227 "Invalidate hwcksum info when adjusting length");
230 * On platforms which require strict alignment (currently for anything but
231 * i386 or x86_64), check if the IP header pointer is 32-bit aligned; if not,
232 * copy the contents of the mbuf chain into a new chain, and free the original
233 * one. Create some head room in the first mbuf of the new chain, in case
234 * it's needed later on.
236 * RFC 2460 says that IPv6 headers are 64-bit aligned, but network interfaces
237 * mostly align to 32-bit boundaries. Care should be taken never to use 64-bit
238 * load/store operations on the fields in IPv6 headers.
240 #if defined(__i386__) || defined(__x86_64__)
241 #define IP6_HDR_ALIGNMENT_FIXUP(_m, _ifp, _action) do { } while (0)
242 #else /* !__i386__ && !__x86_64__ */
243 #define IP6_HDR_ALIGNMENT_FIXUP(_m, _ifp, _action) do { \
244 if (!IP6_HDR_ALIGNED_P(mtod(_m, caddr_t))) { \
246 struct ifnet *__ifp = (_ifp); \
247 atomic_add_64(&(__ifp)->if_alignerrs, 1); \
248 if (((_m)->m_flags & M_PKTHDR) && \
249 (_m)->m_pkthdr.pkt_hdr != NULL) \
250 (_m)->m_pkthdr.pkt_hdr = NULL; \
251 _n = m_defrag_offset(_m, max_linkhdr, M_NOWAIT); \
253 ip6stat.ip6s_toosmall++; \
258 VERIFY(_n != (_m)); \
263 #endif /* !__i386__ && !__x86_64__ */
266 ip6_proto_input(protocol_family_t protocol
, mbuf_t packet
)
268 #pragma unused(protocol)
273 * IP6 initialization: fill in IP6 protocol switch table.
274 * All protocols not implemented in kernel go to raw IP6 protocol handler.
277 ip6_init(struct ip6protosw
*pp
, struct domain
*dp
)
279 static int ip6_initialized
= 0;
283 domain_unguard_t unguard
;
285 domain_proto_mtx_lock_assert_held();
286 VERIFY((pp
->pr_flags
& (PR_INITIALIZED
|PR_ATTACHED
)) == PR_ATTACHED
);
288 _CASSERT((sizeof (struct ip6_hdr
) +
289 sizeof (struct icmp6_hdr
)) <= _MHLEN
);
295 PE_parse_boot_argn("net.inet6.ip6.scopedroute", &ip6_doscopedroute
,
296 sizeof (ip6_doscopedroute
));
298 pr
= pffindproto_locked(PF_INET6
, IPPROTO_RAW
, SOCK_RAW
);
300 panic("%s: Unable to find [PF_INET6,IPPROTO_RAW,SOCK_RAW]\n",
305 /* Initialize the entire ip6_protox[] array to IPPROTO_RAW. */
306 for (i
= 0; i
< IPPROTO_MAX
; i
++)
307 ip6_protox
[i
] = (struct ip6protosw
*)pr
;
309 * Cycle through IP protocols and put them into the appropriate place
310 * in ip6_protox[], skipping protocols IPPROTO_{IP,RAW}.
312 VERIFY(dp
== inet6domain
&& dp
->dom_family
== PF_INET6
);
313 TAILQ_FOREACH(pr
, &dp
->dom_protosw
, pr_entry
) {
314 VERIFY(pr
->pr_domain
== dp
);
315 if (pr
->pr_protocol
!= 0 && pr
->pr_protocol
!= IPPROTO_RAW
) {
316 /* Be careful to only index valid IP protocols. */
317 if (pr
->pr_protocol
< IPPROTO_MAX
)
318 ip6_protox
[pr
->pr_protocol
] =
319 (struct ip6protosw
*)pr
;
323 ip6_mutex_grp_attr
= lck_grp_attr_alloc_init();
325 ip6_mutex_grp
= lck_grp_alloc_init("ip6", ip6_mutex_grp_attr
);
326 ip6_mutex_attr
= lck_attr_alloc_init();
328 lck_mtx_init(dad6_mutex
, ip6_mutex_grp
, ip6_mutex_attr
);
329 lck_mtx_init(nd6_mutex
, ip6_mutex_grp
, ip6_mutex_attr
);
330 lck_mtx_init(prefix6_mutex
, ip6_mutex_grp
, ip6_mutex_attr
);
331 scope6_init(ip6_mutex_grp
, ip6_mutex_attr
);
333 #ifdef ENABLE_ADDRSEL
334 lck_mtx_init(addrsel_mutex
, ip6_mutex_grp
, ip6_mutex_attr
);
337 lck_mtx_init(&proxy6_lock
, ip6_mutex_grp
, ip6_mutex_attr
);
339 in6_ifaddr_rwlock_grp_attr
= lck_grp_attr_alloc_init();
340 in6_ifaddr_rwlock_grp
= lck_grp_alloc_init("in6_ifaddr_rwlock",
341 in6_ifaddr_rwlock_grp_attr
);
342 in6_ifaddr_rwlock_attr
= lck_attr_alloc_init();
343 lck_rw_init(&in6_ifaddr_rwlock
, in6_ifaddr_rwlock_grp
,
344 in6_ifaddr_rwlock_attr
);
346 IN6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_in_receive
);
347 IN6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_in_hdrerr
);
348 IN6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_in_toobig
);
349 IN6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_in_noroute
);
350 IN6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_in_addrerr
);
351 IN6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_in_protounknown
);
352 IN6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_in_truncated
);
353 IN6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_in_discard
);
354 IN6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_in_deliver
);
355 IN6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_out_forward
);
356 IN6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_out_request
);
357 IN6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_out_discard
);
358 IN6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_out_fragok
);
359 IN6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_out_fragfail
);
360 IN6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_out_fragcreat
);
361 IN6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_reass_reqd
);
362 IN6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_reass_ok
);
363 IN6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_reass_fail
);
364 IN6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_in_mcast
);
365 IN6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_out_mcast
);
367 ICMP6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_in_msg
);
368 ICMP6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_in_error
);
369 ICMP6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_in_dstunreach
);
370 ICMP6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_in_adminprohib
);
371 ICMP6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_in_timeexceed
);
372 ICMP6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_in_paramprob
);
373 ICMP6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_in_pkttoobig
);
374 ICMP6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_in_echo
);
375 ICMP6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_in_echoreply
);
376 ICMP6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_in_routersolicit
);
377 ICMP6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_in_routeradvert
);
378 ICMP6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_in_neighborsolicit
);
379 ICMP6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_in_neighboradvert
);
380 ICMP6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_in_redirect
);
381 ICMP6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_in_mldquery
);
382 ICMP6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_in_mldreport
);
383 ICMP6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_in_mlddone
);
385 ICMP6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_out_msg
);
386 ICMP6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_out_error
);
387 ICMP6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_out_dstunreach
);
388 ICMP6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_out_adminprohib
);
389 ICMP6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_out_timeexceed
);
390 ICMP6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_out_paramprob
);
391 ICMP6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_out_pkttoobig
);
392 ICMP6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_out_echo
);
393 ICMP6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_out_echoreply
);
394 ICMP6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_out_routersolicit
);
395 ICMP6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_out_routeradvert
);
396 ICMP6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_out_neighborsolicit
);
397 ICMP6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_out_neighboradvert
);
398 ICMP6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_out_redirect
);
399 ICMP6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_out_mldquery
);
400 ICMP6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_out_mldreport
);
401 ICMP6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_out_mlddone
);
405 (RandomULong() ^ tv
.tv_usec
) % MAX_TEMP_DESYNC_FACTOR
;
411 icmp6_init(NULL
, dp
);
412 addrsel_policy_init();
415 * P2P interfaces often route the local address to the loopback
416 * interface. At this point, lo0 hasn't been initialized yet, which
417 * means that we need to delay the IPv6 configuration of lo0.
419 net_init_add(ip6_init_delayed
);
421 unguard
= domain_unguard_deploy();
422 i
= proto_register_input(PF_INET6
, ip6_proto_input
, NULL
, 0);
424 panic("%s: failed to register PF_INET6 protocol: %d\n",
428 domain_unguard_release(unguard
);
432 ip6_init_delayed(void)
434 (void) in6_ifattach_prelim(lo_ifp
);
436 /* timer for regeneranation of temporary addresses randomize ID */
437 timeout(in6_tmpaddrtimer
, NULL
,
438 (ip6_temp_preferred_lifetime
- ip6_desync_factor
-
439 ip6_temp_regen_advance
) * hz
);
447 ip6_input(struct mbuf
*m
)
450 int off
= sizeof (struct ip6_hdr
), nest
;
452 u_int32_t rtalert
= ~0;
453 int nxt
= 0, ours
= 0;
454 struct ifnet
*inifp
, *deliverifp
= NULL
;
455 ipfilter_t inject_ipfref
= NULL
;
457 struct in6_ifaddr
*ia6
= NULL
;
458 struct sockaddr_in6
*dst6
;
461 #endif /* DUMMYNET */
463 struct route_in6 rin6
;
465 struct ip_fw_args args
;
466 #endif /* DUMMYNET */
468 #define rin6 ip6ibz.rin6
469 #define args ip6ibz.args
471 /* zero out {rin6, args} */
472 bzero(&ip6ibz
, sizeof (ip6ibz
));
475 * Check if the packet we received is valid after interface filter
478 MBUF_INPUT_CHECK(m
, m
->m_pkthdr
.rcvif
);
479 inifp
= m
->m_pkthdr
.rcvif
;
480 VERIFY(inifp
!= NULL
);
482 /* Perform IP header alignment fixup, if needed */
483 IP6_HDR_ALIGNMENT_FIXUP(m
, inifp
, return);
485 m
->m_pkthdr
.pkt_flags
&= ~PKTF_FORWARDED
;
488 * should the inner packet be considered authentic?
489 * see comment in ah4_input().
491 m
->m_flags
&= ~M_AUTHIPHDR
;
492 m
->m_flags
&= ~M_AUTHIPDGM
;
496 * make sure we don't have onion peering information into m_aux.
501 if ((tag
= m_tag_locate(m
, KERNEL_MODULE_TAG_ID
,
502 KERNEL_TAG_TYPE_DUMMYNET
, NULL
)) != NULL
) {
503 struct dn_pkt_tag
*dn_tag
;
505 dn_tag
= (struct dn_pkt_tag
*)(tag
+1);
507 args
.fwa_pf_rule
= dn_tag
->dn_pf_rule
;
509 m_tag_delete(m
, tag
);
512 if (args
.fwa_pf_rule
) {
513 ip6
= mtod(m
, struct ip6_hdr
*); /* In case PF got disabled */
517 #endif /* DUMMYNET */
520 * No need to proccess packet twice if we've already seen it.
522 inject_ipfref
= ipf_get_inject_filter(m
);
523 if (inject_ipfref
!= NULL
) {
524 ip6
= mtod(m
, struct ip6_hdr
*);
535 if (m
->m_flags
& M_EXT
) {
536 if (m
->m_next
!= NULL
)
537 ip6stat
.ip6s_mext2m
++;
539 ip6stat
.ip6s_mext1
++;
541 #define M2MMAX (sizeof (ip6stat.ip6s_m2m) / sizeof (ip6stat.ip6s_m2m[0]))
542 if (m
->m_next
!= NULL
) {
543 if (m
->m_pkthdr
.pkt_flags
& PKTF_LOOP
) {
545 ip6stat
.ip6s_m2m
[ifnet_index(lo_ifp
)]++;
546 } else if (inifp
->if_index
< M2MMAX
) {
547 ip6stat
.ip6s_m2m
[inifp
->if_index
]++;
549 ip6stat
.ip6s_m2m
[0]++;
558 * Drop the packet if IPv6 operation is disabled on the interface.
560 if (inifp
->if_eflags
& IFEF_IPV6_DISABLED
)
563 in6_ifstat_inc_na(inifp
, ifs6_in_receive
);
564 ip6stat
.ip6s_total
++;
566 #ifndef PULLDOWN_TEST
568 * L2 bridge code and some other code can return mbuf chain
569 * that does not conform to KAME requirement. too bad.
570 * XXX: fails to join if interface MTU > MCLBYTES. jumbogram?
572 if (m
->m_next
!= NULL
&& m
->m_pkthdr
.len
< MCLBYTES
) {
575 MGETHDR(n
, M_DONTWAIT
, MT_HEADER
); /* MAC-OK */
578 if (n
&& m
->m_pkthdr
.len
> MHLEN
) {
579 MCLGET(n
, M_DONTWAIT
);
580 if ((n
->m_flags
& M_EXT
) == 0) {
588 m_copydata(m
, 0, m
->m_pkthdr
.len
, mtod(n
, caddr_t
));
589 n
->m_len
= m
->m_pkthdr
.len
;
593 IP6_EXTHDR_CHECK(m
, 0, sizeof (struct ip6_hdr
), { goto done
; });
596 if (m
->m_len
< sizeof (struct ip6_hdr
)) {
597 if ((m
= m_pullup(m
, sizeof (struct ip6_hdr
))) == 0) {
598 ip6stat
.ip6s_toosmall
++;
599 in6_ifstat_inc(inifp
, ifs6_in_hdrerr
);
604 ip6
= mtod(m
, struct ip6_hdr
*);
606 if ((ip6
->ip6_vfc
& IPV6_VERSION_MASK
) != IPV6_VERSION
) {
607 ip6stat
.ip6s_badvers
++;
608 in6_ifstat_inc(inifp
, ifs6_in_hdrerr
);
612 ip6stat
.ip6s_nxthist
[ip6
->ip6_nxt
]++;
616 * Check with the firewall...
618 if (ip6_fw_enable
&& ip6_fw_chk_ptr
) {
620 /* If ipfw says divert, we have to just drop packet */
621 /* use port as a dummy argument */
622 if ((*ip6_fw_chk_ptr
)(&ip6
, NULL
, &port
, &m
)) {
632 * Check against address spoofing/corruption.
634 if (IN6_IS_ADDR_MULTICAST(&ip6
->ip6_src
) ||
635 IN6_IS_ADDR_UNSPECIFIED(&ip6
->ip6_dst
)) {
637 * XXX: "badscope" is not very suitable for a multicast source.
639 ip6stat
.ip6s_badscope
++;
640 in6_ifstat_inc(inifp
, ifs6_in_addrerr
);
643 if (IN6_IS_ADDR_MC_INTFACELOCAL(&ip6
->ip6_dst
) &&
644 !(m
->m_pkthdr
.pkt_flags
& PKTF_LOOP
)) {
646 * In this case, the packet should come from the loopback
647 * interface. However, we cannot just check the if_flags,
648 * because ip6_mloopback() passes the "actual" interface
649 * as the outgoing/incoming interface.
651 ip6stat
.ip6s_badscope
++;
652 in6_ifstat_inc(inifp
, ifs6_in_addrerr
);
657 * The following check is not documented in specs. A malicious
658 * party may be able to use IPv4 mapped addr to confuse tcp/udp stack
659 * and bypass security checks (act as if it was from 127.0.0.1 by using
660 * IPv6 src ::ffff:127.0.0.1). Be cautious.
662 * This check chokes if we are in an SIIT cloud. As none of BSDs
663 * support IPv4-less kernel compilation, we cannot support SIIT
664 * environment at all. So, it makes more sense for us to reject any
665 * malicious packets for non-SIIT environment, than try to do a
666 * partial support for SIIT environment.
668 if (IN6_IS_ADDR_V4MAPPED(&ip6
->ip6_src
) ||
669 IN6_IS_ADDR_V4MAPPED(&ip6
->ip6_dst
)) {
670 ip6stat
.ip6s_badscope
++;
671 in6_ifstat_inc(inifp
, ifs6_in_addrerr
);
676 * Reject packets with IPv4 compatible addresses (auto tunnel).
678 * The code forbids auto tunnel relay case in RFC1933 (the check is
679 * stronger than RFC1933). We may want to re-enable it if mech-xx
680 * is revised to forbid relaying case.
682 if (IN6_IS_ADDR_V4COMPAT(&ip6
->ip6_src
) ||
683 IN6_IS_ADDR_V4COMPAT(&ip6
->ip6_dst
)) {
684 ip6stat
.ip6s_badscope
++;
685 in6_ifstat_inc(inifp
, ifs6_in_addrerr
);
691 * Naively assume we can attribute inbound data to the route we would
692 * use to send to this destination. Asymetric routing breaks this
693 * assumption, but it still allows us to account for traffic from
694 * a remote node in the routing table.
695 * this has a very significant performance impact so we bypass
696 * if nstat_collect is disabled. We may also bypass if the
697 * protocol is tcp in the future because tcp will have a route that
698 * we can use to attribute the data to. That does mean we would not
699 * account for forwarded tcp traffic.
702 struct rtentry
*rte
=
703 ifnet_cached_rtlookup_inet6(inifp
, &ip6
->ip6_src
);
705 nstat_route_rx(rte
, 1, m
->m_pkthdr
.len
, 0);
710 /* for consistency */
711 m
->m_pkthdr
.pkt_proto
= ip6
->ip6_nxt
;
715 #endif /* DUMMYNET */
717 /* Invoke inbound packet filter */
721 error
= pf_af_hook(inifp
, NULL
, &m
, AF_INET6
, TRUE
, &args
);
722 #else /* !DUMMYNET */
723 error
= pf_af_hook(inifp
, NULL
, &m
, AF_INET6
, TRUE
, NULL
);
724 #endif /* !DUMMYNET */
725 if (error
!= 0 || m
== NULL
) {
727 panic("%s: unexpected packet %p\n",
731 /* Already freed by callee */
734 ip6
= mtod(m
, struct ip6_hdr
*);
738 /* drop packets if interface ID portion is already filled */
739 if (!(inifp
->if_flags
& IFF_LOOPBACK
) &&
740 !(m
->m_pkthdr
.pkt_flags
& PKTF_LOOP
)) {
741 if (IN6_IS_SCOPE_LINKLOCAL(&ip6
->ip6_src
) &&
742 ip6
->ip6_src
.s6_addr16
[1]) {
743 ip6stat
.ip6s_badscope
++;
746 if (IN6_IS_SCOPE_LINKLOCAL(&ip6
->ip6_dst
) &&
747 ip6
->ip6_dst
.s6_addr16
[1]) {
748 ip6stat
.ip6s_badscope
++;
753 if (m
->m_pkthdr
.pkt_flags
& PKTF_IFAINFO
) {
754 if (IN6_IS_SCOPE_LINKLOCAL(&ip6
->ip6_src
))
755 ip6
->ip6_src
.s6_addr16
[1] =
756 htons(m
->m_pkthdr
.src_ifindex
);
757 if (IN6_IS_SCOPE_LINKLOCAL(&ip6
->ip6_dst
))
758 ip6
->ip6_dst
.s6_addr16
[1] =
759 htons(m
->m_pkthdr
.dst_ifindex
);
761 if (IN6_IS_SCOPE_LINKLOCAL(&ip6
->ip6_src
))
762 ip6
->ip6_src
.s6_addr16
[1] = htons(inifp
->if_index
);
763 if (IN6_IS_SCOPE_LINKLOCAL(&ip6
->ip6_dst
))
764 ip6
->ip6_dst
.s6_addr16
[1] = htons(inifp
->if_index
);
770 if (IN6_IS_ADDR_MULTICAST(&ip6
->ip6_dst
)) {
771 struct in6_multi
*in6m
= NULL
;
773 in6_ifstat_inc_na(inifp
, ifs6_in_mcast
);
775 * See if we belong to the destination multicast group on the
778 in6_multihead_lock_shared();
779 IN6_LOOKUP_MULTI(&ip6
->ip6_dst
, inifp
, in6m
);
780 in6_multihead_lock_done();
784 } else if (!nd6_prproxy
787 #endif /* MROUTING */
789 ip6stat
.ip6s_notmember
++;
790 ip6stat
.ip6s_cantforward
++;
791 in6_ifstat_inc(inifp
, ifs6_in_discard
);
802 * Fast path: see if the target is ourselves.
804 lck_rw_lock_shared(&in6_ifaddr_rwlock
);
805 for (ia6
= in6_ifaddrs
; ia6
!= NULL
; ia6
= ia6
->ia_next
) {
807 * No reference is held on the address, as we just need
808 * to test for a few things while holding the RW lock.
810 if (IN6_ARE_ADDR_EQUAL(&ia6
->ia_addr
.sin6_addr
, &ip6
->ip6_dst
))
816 * For performance, test without acquiring the address lock;
817 * a lot of things in the address are set once and never
818 * changed (e.g. ia_ifp.)
820 if (!(ia6
->ia6_flags
& IN6_IFF_NOTREADY
)) {
821 /* this address is ready */
823 deliverifp
= ia6
->ia_ifp
;
825 * record dst address information into mbuf.
827 (void) ip6_setdstifaddr_info(m
, 0, ia6
);
828 lck_rw_done(&in6_ifaddr_rwlock
);
831 lck_rw_done(&in6_ifaddr_rwlock
);
833 /* address is not ready, so discard the packet. */
834 nd6log((LOG_INFO
, "%s: packet to an unready address %s->%s\n",
835 __func__
, ip6_sprintf(&ip6
->ip6_src
),
836 ip6_sprintf(&ip6
->ip6_dst
)));
839 lck_rw_done(&in6_ifaddr_rwlock
);
842 * Slow path: route lookup.
844 dst6
= SIN6(&rin6
.ro_dst
);
845 dst6
->sin6_len
= sizeof (struct sockaddr_in6
);
846 dst6
->sin6_family
= AF_INET6
;
847 dst6
->sin6_addr
= ip6
->ip6_dst
;
849 rtalloc_scoped_ign((struct route
*)&rin6
,
850 RTF_PRCLONING
, IFSCOPE_NONE
);
851 if (rin6
.ro_rt
!= NULL
)
852 RT_LOCK_SPIN(rin6
.ro_rt
);
854 #define rt6_key(r) (SIN6((r)->rt_nodes->rn_key))
857 * Accept the packet if the forwarding interface to the destination
858 * according to the routing table is the loopback interface,
859 * unless the associated route has a gateway.
860 * Note that this approach causes to accept a packet if there is a
861 * route to the loopback interface for the destination of the packet.
862 * But we think it's even useful in some situations, e.g. when using
863 * a special daemon which wants to intercept the packet.
865 * XXX: some OSes automatically make a cloned route for the destination
866 * of an outgoing packet. If the outgoing interface of the packet
867 * is a loopback one, the kernel would consider the packet to be
868 * accepted, even if we have no such address assinged on the interface.
869 * We check the cloned flag of the route entry to reject such cases,
870 * assuming that route entries for our own addresses are not made by
871 * cloning (it should be true because in6_addloop explicitly installs
872 * the host route). However, we might have to do an explicit check
873 * while it would be less efficient. Or, should we rather install a
874 * reject route for such a case?
876 if (rin6
.ro_rt
!= NULL
&&
877 (rin6
.ro_rt
->rt_flags
& (RTF_HOST
|RTF_GATEWAY
)) == RTF_HOST
&&
879 !(rin6
.ro_rt
->rt_flags
& RTF_WASCLONED
) &&
881 rin6
.ro_rt
->rt_ifp
->if_type
== IFT_LOOP
) {
882 ia6
= (struct in6_ifaddr
*)rin6
.ro_rt
->rt_ifa
;
884 * Packets to a tentative, duplicated, or somehow invalid
885 * address must not be accepted.
887 * For performance, test without acquiring the address lock;
888 * a lot of things in the address are set once and never
889 * changed (e.g. ia_ifp.)
891 if (!(ia6
->ia6_flags
& IN6_IFF_NOTREADY
)) {
892 /* this address is ready */
894 deliverifp
= ia6
->ia_ifp
; /* correct? */
896 * record dst address information into mbuf.
898 (void) ip6_setdstifaddr_info(m
, 0, ia6
);
899 RT_UNLOCK(rin6
.ro_rt
);
902 RT_UNLOCK(rin6
.ro_rt
);
904 /* address is not ready, so discard the packet. */
905 nd6log((LOG_INFO
, "%s: packet to an unready address %s->%s\n",
906 __func__
, ip6_sprintf(&ip6
->ip6_src
),
907 ip6_sprintf(&ip6
->ip6_dst
)));
911 if (rin6
.ro_rt
!= NULL
)
912 RT_UNLOCK(rin6
.ro_rt
);
915 * Now there is no reason to process the packet if it's not our own
916 * and we're not a router.
918 if (!ip6_forwarding
) {
919 ip6stat
.ip6s_cantforward
++;
920 in6_ifstat_inc(inifp
, ifs6_in_discard
);
926 * record dst address information into mbuf, if we don't have one yet.
927 * note that we are unable to record it, if the address is not listed
928 * as our interface address (e.g. multicast addresses, etc.)
930 if (deliverifp
!= NULL
&& ia6
== NULL
) {
931 ia6
= in6_ifawithifp(deliverifp
, &ip6
->ip6_dst
);
933 (void) ip6_setdstifaddr_info(m
, 0, ia6
);
934 IFA_REMREF(&ia6
->ia_ifa
);
939 * Process Hop-by-Hop options header if it's contained.
940 * m may be modified in ip6_hopopts_input().
941 * If a JumboPayload option is included, plen will also be modified.
943 plen
= (u_int32_t
)ntohs(ip6
->ip6_plen
);
944 if (ip6
->ip6_nxt
== IPPROTO_HOPOPTS
) {
947 if (ip6_hopopts_input(&plen
, &rtalert
, &m
, &off
)) {
948 #if 0 /* touches NULL pointer */
949 in6_ifstat_inc(inifp
, ifs6_in_discard
);
951 goto done
; /* m have already been freed */
955 ip6
= mtod(m
, struct ip6_hdr
*);
958 * if the payload length field is 0 and the next header field
959 * indicates Hop-by-Hop Options header, then a Jumbo Payload
960 * option MUST be included.
962 if (ip6
->ip6_plen
== 0 && plen
== 0) {
964 * Note that if a valid jumbo payload option is
965 * contained, ip6_hopopts_input() must set a valid
966 * (non-zero) payload length to the variable plen.
968 ip6stat
.ip6s_badoptions
++;
969 in6_ifstat_inc(inifp
, ifs6_in_discard
);
970 in6_ifstat_inc(inifp
, ifs6_in_hdrerr
);
971 icmp6_error(m
, ICMP6_PARAM_PROB
, ICMP6_PARAMPROB_HEADER
,
972 (caddr_t
)&ip6
->ip6_plen
- (caddr_t
)ip6
);
975 #ifndef PULLDOWN_TEST
976 /* ip6_hopopts_input() ensures that mbuf is contiguous */
977 hbh
= (struct ip6_hbh
*)(ip6
+ 1);
979 IP6_EXTHDR_GET(hbh
, struct ip6_hbh
*, m
,
980 sizeof (struct ip6_hdr
), sizeof (struct ip6_hbh
));
982 ip6stat
.ip6s_tooshort
++;
989 * If we are acting as a router and the packet contains a
990 * router alert option, see if we know the option value.
991 * Currently, we only support the option value for MLD, in which
992 * case we should pass the packet to the multicast routing
995 if (rtalert
!= ~0 && ip6_forwarding
) {
997 case IP6OPT_RTALERT_MLD
:
1002 * RFC2711 requires unrecognized values must be
1012 * Check that the amount of data in the buffers
1013 * is as at least much as the IPv6 header would have us expect.
1014 * Trim mbufs if longer than we expect.
1015 * Drop packet if shorter than we expect.
1017 if (m
->m_pkthdr
.len
- sizeof (struct ip6_hdr
) < plen
) {
1018 ip6stat
.ip6s_tooshort
++;
1019 in6_ifstat_inc(inifp
, ifs6_in_truncated
);
1022 if (m
->m_pkthdr
.len
> sizeof (struct ip6_hdr
) + plen
) {
1024 * Invalidate hardware checksum info if ip6_adj_clear_hwcksum
1025 * is set; useful to handle buggy drivers. Note that this
1026 * should not be enabled by default, as we may get here due
1027 * to link-layer padding.
1029 if (ip6_adj_clear_hwcksum
&&
1030 (m
->m_pkthdr
.csum_flags
& CSUM_DATA_VALID
) &&
1031 !(inifp
->if_flags
& IFF_LOOPBACK
) &&
1032 !(m
->m_pkthdr
.pkt_flags
& PKTF_LOOP
)) {
1033 m
->m_pkthdr
.csum_flags
&= ~CSUM_DATA_VALID
;
1034 m
->m_pkthdr
.csum_data
= 0;
1035 ip6stat
.ip6s_adj_hwcsum_clr
++;
1039 if (m
->m_len
== m
->m_pkthdr
.len
) {
1040 m
->m_len
= sizeof (struct ip6_hdr
) + plen
;
1041 m
->m_pkthdr
.len
= sizeof (struct ip6_hdr
) + plen
;
1043 m_adj(m
, sizeof (struct ip6_hdr
) + plen
-
1049 * Forward if desirable.
1051 if (IN6_IS_ADDR_MULTICAST(&ip6
->ip6_dst
)) {
1053 * If we are acting as a multicast router, all
1054 * incoming multicast packets are passed to the
1055 * kernel-level multicast forwarding function.
1056 * The packet is returned (relatively) intact; if
1057 * ip6_mforward() returns a non-zero value, the packet
1058 * must be discarded, else it may be accepted below.
1061 if (ip6_mrouter
&& ip6_mforward(ip6
, inifp
, m
)) {
1062 ip6stat
.ip6s_cantforward
++;
1065 #endif /* MROUTING */
1066 if (!ours
&& nd6_prproxy
) {
1068 * If this isn't for us, this might be a Neighbor
1069 * Solicitation (dst is solicited-node multicast)
1070 * against an address in one of the proxied prefixes;
1071 * if so, claim the packet and let icmp6_input()
1074 ours
= nd6_prproxy_isours(m
, ip6
, NULL
, IFSCOPE_NONE
);
1076 (m
->m_pkthdr
.pkt_flags
& PKTF_PROXY_DST
));
1082 * The unicast forwarding function might return the packet
1083 * if we are proxying prefix(es), and if the packet is an
1084 * ICMPv6 packet that has failed the zone checks, but is
1085 * targetted towards a proxied address (this is optimized by
1086 * way of RTF_PROXY test.) If so, claim the packet as ours
1087 * and let icmp6_input() handle the rest. The packet's hop
1088 * limit value is kept intact (it's not decremented). This
1089 * is for supporting Neighbor Unreachability Detection between
1090 * proxied nodes on different links (src is link-local, dst
1091 * is target address.)
1093 if ((m
= ip6_forward(m
, &rin6
, 0)) == NULL
)
1095 VERIFY(rin6
.ro_rt
!= NULL
);
1096 VERIFY(m
->m_pkthdr
.pkt_flags
& PKTF_PROXY_DST
);
1097 deliverifp
= rin6
.ro_rt
->rt_ifp
;
1101 ip6
= mtod(m
, struct ip6_hdr
*);
1104 * Malicious party may be able to use IPv4 mapped addr to confuse
1105 * tcp/udp stack and bypass security checks (act as if it was from
1106 * 127.0.0.1 by using IPv6 src ::ffff:127.0.0.1). Be cautious.
1108 * For SIIT end node behavior, you may want to disable the check.
1109 * However, you will become vulnerable to attacks using IPv4 mapped
1112 if (IN6_IS_ADDR_V4MAPPED(&ip6
->ip6_src
) ||
1113 IN6_IS_ADDR_V4MAPPED(&ip6
->ip6_dst
)) {
1114 ip6stat
.ip6s_badscope
++;
1115 in6_ifstat_inc(inifp
, ifs6_in_addrerr
);
1120 * Tell launch routine the next header
1122 ip6stat
.ip6s_delivered
++;
1123 in6_ifstat_inc_na(deliverifp
, ifs6_in_deliver
);
1129 * Perform IP header alignment fixup again, if needed. Note that
1130 * we do it once for the outermost protocol, and we assume each
1131 * protocol handler wouldn't mess with the alignment afterwards.
1133 IP6_HDR_ALIGNMENT_FIXUP(m
, inifp
, return);
1135 while (nxt
!= IPPROTO_DONE
) {
1136 struct ipfilter
*filter
;
1137 int (*pr_input
)(struct mbuf
**, int *, int);
1139 if (ip6_hdrnestlimit
&& (++nest
> ip6_hdrnestlimit
)) {
1140 ip6stat
.ip6s_toomanyhdr
++;
1145 * protection against faulty packet - there should be
1146 * more sanity checks in header chain processing.
1148 if (m
->m_pkthdr
.len
< off
) {
1149 ip6stat
.ip6s_tooshort
++;
1150 in6_ifstat_inc(inifp
, ifs6_in_truncated
);
1157 * enforce IPsec policy checking if we are seeing last header.
1158 * note that we do not visit this with protocols with pcb layer
1159 * code - like udp/tcp/raw ip.
1161 if ((ipsec_bypass
== 0) &&
1162 (ip6_protox
[nxt
]->pr_flags
& PR_LASTHDR
) != 0) {
1163 if (ipsec6_in_reject(m
, NULL
)) {
1164 IPSEC_STAT_INCREMENT(ipsec6stat
.in_polvio
);
1173 if (!TAILQ_EMPTY(&ipv6_filters
)) {
1175 TAILQ_FOREACH(filter
, &ipv6_filters
, ipf_link
) {
1177 if ((struct ipfilter
*)inject_ipfref
==
1180 } else if (filter
->ipf_filter
.ipf_input
) {
1183 result
= filter
->ipf_filter
.ipf_input(
1184 filter
->ipf_filter
.cookie
,
1185 (mbuf_t
*)&m
, off
, nxt
);
1186 if (result
== EJUSTRETURN
) {
1199 DTRACE_IP6(receive
, struct mbuf
*, m
, struct inpcb
*, NULL
,
1200 struct ip6_hdr
*, ip6
, struct ifnet
*, inifp
,
1201 struct ip
*, NULL
, struct ip6_hdr
*, ip6
);
1203 if ((pr_input
= ip6_protox
[nxt
]->pr_input
) == NULL
) {
1207 } else if (!(ip6_protox
[nxt
]->pr_flags
& PR_PROTOLOCK
)) {
1208 lck_mtx_lock(inet6_domain_mutex
);
1209 nxt
= pr_input(&m
, &off
, nxt
);
1210 lck_mtx_unlock(inet6_domain_mutex
);
1212 nxt
= pr_input(&m
, &off
, nxt
);
1216 ROUTE_RELEASE(&rin6
);
1224 ip6_setsrcifaddr_info(struct mbuf
*m
, uint32_t src_idx
, struct in6_ifaddr
*ia6
)
1226 VERIFY(m
->m_flags
& M_PKTHDR
);
1229 * If the source ifaddr is specified, pick up the information
1230 * from there; otherwise just grab the passed-in ifindex as the
1231 * caller may not have the ifaddr available.
1234 m
->m_pkthdr
.pkt_flags
|= PKTF_IFAINFO
;
1235 m
->m_pkthdr
.src_ifindex
= ia6
->ia_ifp
->if_index
;
1237 /* See IN6_IFF comments in in6_var.h */
1238 m
->m_pkthdr
.src_iff
= (ia6
->ia6_flags
& 0xffff);
1240 m
->m_pkthdr
.src_iff
= 0;
1241 m
->m_pkthdr
.src_ifindex
= src_idx
;
1243 m
->m_pkthdr
.pkt_flags
|= PKTF_IFAINFO
;
1248 ip6_setdstifaddr_info(struct mbuf
*m
, uint32_t dst_idx
, struct in6_ifaddr
*ia6
)
1250 VERIFY(m
->m_flags
& M_PKTHDR
);
1253 * If the destination ifaddr is specified, pick up the information
1254 * from there; otherwise just grab the passed-in ifindex as the
1255 * caller may not have the ifaddr available.
1258 m
->m_pkthdr
.pkt_flags
|= PKTF_IFAINFO
;
1259 m
->m_pkthdr
.dst_ifindex
= ia6
->ia_ifp
->if_index
;
1261 /* See IN6_IFF comments in in6_var.h */
1262 m
->m_pkthdr
.dst_iff
= (ia6
->ia6_flags
& 0xffff);
1264 m
->m_pkthdr
.dst_iff
= 0;
1265 m
->m_pkthdr
.dst_ifindex
= dst_idx
;
1267 m
->m_pkthdr
.pkt_flags
|= PKTF_IFAINFO
;
1272 ip6_getsrcifaddr_info(struct mbuf
*m
, uint32_t *src_idx
, uint32_t *ia6f
)
1274 VERIFY(m
->m_flags
& M_PKTHDR
);
1276 if (!(m
->m_pkthdr
.pkt_flags
& PKTF_IFAINFO
))
1279 if (src_idx
!= NULL
)
1280 *src_idx
= m
->m_pkthdr
.src_ifindex
;
1283 *ia6f
= m
->m_pkthdr
.src_iff
;
1289 ip6_getdstifaddr_info(struct mbuf
*m
, uint32_t *dst_idx
, uint32_t *ia6f
)
1291 VERIFY(m
->m_flags
& M_PKTHDR
);
1293 if (!(m
->m_pkthdr
.pkt_flags
& PKTF_IFAINFO
))
1296 if (dst_idx
!= NULL
)
1297 *dst_idx
= m
->m_pkthdr
.dst_ifindex
;
1300 *ia6f
= m
->m_pkthdr
.dst_iff
;
1306 * Hop-by-Hop options header processing. If a valid jumbo payload option is
1307 * included, the real payload length will be stored in plenp.
1310 ip6_hopopts_input(uint32_t *plenp
, uint32_t *rtalertp
, struct mbuf
**mp
,
1313 struct mbuf
*m
= *mp
;
1314 int off
= *offp
, hbhlen
;
1315 struct ip6_hbh
*hbh
;
1318 /* validation of the length of the header */
1319 #ifndef PULLDOWN_TEST
1320 IP6_EXTHDR_CHECK(m
, off
, sizeof (*hbh
), return (-1));
1321 hbh
= (struct ip6_hbh
*)(mtod(m
, caddr_t
) + off
);
1322 hbhlen
= (hbh
->ip6h_len
+ 1) << 3;
1324 IP6_EXTHDR_CHECK(m
, off
, hbhlen
, return (-1));
1325 hbh
= (struct ip6_hbh
*)(mtod(m
, caddr_t
) + off
);
1327 IP6_EXTHDR_GET(hbh
, struct ip6_hbh
*, m
, sizeof (struct ip6_hdr
),
1328 sizeof (struct ip6_hbh
));
1330 ip6stat
.ip6s_tooshort
++;
1333 hbhlen
= (hbh
->ip6h_len
+ 1) << 3;
1334 IP6_EXTHDR_GET(hbh
, struct ip6_hbh
*, m
, sizeof (struct ip6_hdr
),
1337 ip6stat
.ip6s_tooshort
++;
1342 hbhlen
-= sizeof (struct ip6_hbh
);
1343 opt
= (u_int8_t
*)hbh
+ sizeof (struct ip6_hbh
);
1345 if (ip6_process_hopopts(m
, (u_int8_t
*)hbh
+ sizeof (struct ip6_hbh
),
1346 hbhlen
, rtalertp
, plenp
) < 0)
1355 * Search header for all Hop-by-hop options and process each option.
1356 * This function is separate from ip6_hopopts_input() in order to
1357 * handle a case where the sending node itself process its hop-by-hop
1358 * options header. In such a case, the function is called from ip6_output().
1360 * The function assumes that hbh header is located right after the IPv6 header
1361 * (RFC2460 p7), opthead is pointer into data content in m, and opthead to
1362 * opthead + hbhlen is located in continuous memory region.
1365 ip6_process_hopopts(m
, opthead
, hbhlen
, rtalertp
, plenp
)
1369 u_int32_t
*rtalertp
;
1372 struct ip6_hdr
*ip6
;
1374 u_int8_t
*opt
= opthead
;
1375 u_int16_t rtalert_val
;
1376 u_int32_t jumboplen
;
1377 const int erroff
= sizeof (struct ip6_hdr
) + sizeof (struct ip6_hbh
);
1379 for (; hbhlen
> 0; hbhlen
-= optlen
, opt
+= optlen
) {
1385 if (hbhlen
< IP6OPT_MINLEN
) {
1386 ip6stat
.ip6s_toosmall
++;
1389 optlen
= *(opt
+ 1) + 2;
1391 case IP6OPT_ROUTER_ALERT
:
1392 /* XXX may need check for alignment */
1393 if (hbhlen
< IP6OPT_RTALERT_LEN
) {
1394 ip6stat
.ip6s_toosmall
++;
1397 if (*(opt
+ 1) != IP6OPT_RTALERT_LEN
- 2) {
1399 icmp6_error(m
, ICMP6_PARAM_PROB
,
1400 ICMP6_PARAMPROB_HEADER
,
1401 erroff
+ opt
+ 1 - opthead
);
1404 optlen
= IP6OPT_RTALERT_LEN
;
1405 bcopy((caddr_t
)(opt
+ 2), (caddr_t
)&rtalert_val
, 2);
1406 *rtalertp
= ntohs(rtalert_val
);
1409 /* XXX may need check for alignment */
1410 if (hbhlen
< IP6OPT_JUMBO_LEN
) {
1411 ip6stat
.ip6s_toosmall
++;
1414 if (*(opt
+ 1) != IP6OPT_JUMBO_LEN
- 2) {
1416 icmp6_error(m
, ICMP6_PARAM_PROB
,
1417 ICMP6_PARAMPROB_HEADER
,
1418 erroff
+ opt
+ 1 - opthead
);
1421 optlen
= IP6OPT_JUMBO_LEN
;
1424 * IPv6 packets that have non 0 payload length
1425 * must not contain a jumbo payload option.
1427 ip6
= mtod(m
, struct ip6_hdr
*);
1428 if (ip6
->ip6_plen
) {
1429 ip6stat
.ip6s_badoptions
++;
1430 icmp6_error(m
, ICMP6_PARAM_PROB
,
1431 ICMP6_PARAMPROB_HEADER
,
1432 erroff
+ opt
- opthead
);
1437 * We may see jumbolen in unaligned location, so
1438 * we'd need to perform bcopy().
1440 bcopy(opt
+ 2, &jumboplen
, sizeof (jumboplen
));
1441 jumboplen
= (u_int32_t
)htonl(jumboplen
);
1445 * if there are multiple jumbo payload options,
1446 * *plenp will be non-zero and the packet will be
1448 * the behavior may need some debate in ipngwg -
1449 * multiple options does not make sense, however,
1450 * there's no explicit mention in specification.
1453 ip6stat
.ip6s_badoptions
++;
1454 icmp6_error(m
, ICMP6_PARAM_PROB
,
1455 ICMP6_PARAMPROB_HEADER
,
1456 erroff
+ opt
+ 2 - opthead
);
1462 * jumbo payload length must be larger than 65535.
1464 if (jumboplen
<= IPV6_MAXPACKET
) {
1465 ip6stat
.ip6s_badoptions
++;
1466 icmp6_error(m
, ICMP6_PARAM_PROB
,
1467 ICMP6_PARAMPROB_HEADER
,
1468 erroff
+ opt
+ 2 - opthead
);
1474 default: /* unknown option */
1475 if (hbhlen
< IP6OPT_MINLEN
) {
1476 ip6stat
.ip6s_toosmall
++;
1479 optlen
= ip6_unknown_opt(opt
, m
,
1480 erroff
+ opt
- opthead
);
1497 * Unknown option processing.
1498 * The third argument `off' is the offset from the IPv6 header to the option,
1499 * which is necessary if the IPv6 header the and option header and IPv6 header
1500 * is not continuous in order to return an ICMPv6 error.
1503 ip6_unknown_opt(uint8_t *optp
, struct mbuf
*m
, int off
)
1505 struct ip6_hdr
*ip6
;
1507 switch (IP6OPT_TYPE(*optp
)) {
1508 case IP6OPT_TYPE_SKIP
: /* ignore the option */
1509 return ((int)*(optp
+ 1));
1511 case IP6OPT_TYPE_DISCARD
: /* silently discard */
1515 case IP6OPT_TYPE_FORCEICMP
: /* send ICMP even if multicasted */
1516 ip6stat
.ip6s_badoptions
++;
1517 icmp6_error(m
, ICMP6_PARAM_PROB
, ICMP6_PARAMPROB_OPTION
, off
);
1520 case IP6OPT_TYPE_ICMP
: /* send ICMP if not multicasted */
1521 ip6stat
.ip6s_badoptions
++;
1522 ip6
= mtod(m
, struct ip6_hdr
*);
1523 if (IN6_IS_ADDR_MULTICAST(&ip6
->ip6_dst
) ||
1524 (m
->m_flags
& (M_BCAST
|M_MCAST
))) {
1527 icmp6_error(m
, ICMP6_PARAM_PROB
,
1528 ICMP6_PARAMPROB_OPTION
, off
);
1533 m_freem(m
); /* XXX: NOTREACHED */
1538 * Create the "control" list for this pcb.
1539 * These functions will not modify mbuf chain at all.
1541 * With KAME mbuf chain restriction:
1542 * The routine will be called from upper layer handlers like tcp6_input().
1543 * Thus the routine assumes that the caller (tcp6_input) have already
1544 * called IP6_EXTHDR_CHECK() and all the extension headers are located in the
1545 * very first mbuf on the mbuf chain.
1547 * ip6_savecontrol_v4 will handle those options that are possible to be
1548 * set on a v4-mapped socket.
1549 * ip6_savecontrol will directly call ip6_savecontrol_v4 to handle those
1550 * options and handle the v6-only ones itself.
1553 ip6_savecontrol_v4(struct inpcb
*inp
, struct mbuf
*m
, struct mbuf
**mp
,
1556 struct ip6_hdr
*ip6
= mtod(m
, struct ip6_hdr
*);
1558 if ((inp
->inp_socket
->so_options
& SO_TIMESTAMP
) != 0) {
1562 mp
= sbcreatecontrol_mbuf((caddr_t
)&tv
, sizeof (tv
),
1563 SCM_TIMESTAMP
, SOL_SOCKET
, mp
);
1567 if ((inp
->inp_socket
->so_options
& SO_TIMESTAMP_MONOTONIC
) != 0) {
1570 time
= mach_absolute_time();
1571 mp
= sbcreatecontrol_mbuf((caddr_t
)&time
, sizeof (time
),
1572 SCM_TIMESTAMP_MONOTONIC
, SOL_SOCKET
, mp
);
1576 if ((inp
->inp_socket
->so_flags
& SOF_RECV_TRAFFIC_CLASS
) != 0) {
1577 int tc
= m_get_traffic_class(m
);
1579 mp
= sbcreatecontrol_mbuf((caddr_t
)&tc
, sizeof (tc
),
1580 SO_TRAFFIC_CLASS
, SOL_SOCKET
, mp
);
1585 if ((ip6
->ip6_vfc
& IPV6_VERSION_MASK
) != IPV6_VERSION
) {
1591 #define IS2292(inp, x, y) (((inp)->inp_flags & IN6P_RFC2292) ? (x) : (y))
1592 /* RFC 2292 sec. 5 */
1593 if ((inp
->inp_flags
& IN6P_PKTINFO
) != 0) {
1594 struct in6_pktinfo pi6
;
1596 bcopy(&ip6
->ip6_dst
, &pi6
.ipi6_addr
, sizeof (struct in6_addr
));
1597 in6_clearscope(&pi6
.ipi6_addr
); /* XXX */
1599 (m
&& m
->m_pkthdr
.rcvif
) ? m
->m_pkthdr
.rcvif
->if_index
: 0;
1601 mp
= sbcreatecontrol_mbuf((caddr_t
)&pi6
,
1602 sizeof (struct in6_pktinfo
),
1603 IS2292(inp
, IPV6_2292PKTINFO
, IPV6_PKTINFO
),
1609 if ((inp
->inp_flags
& IN6P_HOPLIMIT
) != 0) {
1610 int hlim
= ip6
->ip6_hlim
& 0xff;
1612 mp
= sbcreatecontrol_mbuf((caddr_t
)&hlim
, sizeof (int),
1613 IS2292(inp
, IPV6_2292HOPLIMIT
, IPV6_HOPLIMIT
),
1625 ip6_savecontrol(struct inpcb
*in6p
, struct mbuf
*m
, struct mbuf
**mp
)
1628 struct ip6_hdr
*ip6
= mtod(m
, struct ip6_hdr
*);
1632 np
= ip6_savecontrol_v4(in6p
, m
, mp
, &v4only
);
1640 if ((in6p
->inp_flags
& IN6P_TCLASS
) != 0) {
1644 flowinfo
= (u_int32_t
)ntohl(ip6
->ip6_flow
& IPV6_FLOWINFO_MASK
);
1647 tclass
= flowinfo
& 0xff;
1648 mp
= sbcreatecontrol_mbuf((caddr_t
)&tclass
, sizeof (tclass
),
1649 IPV6_TCLASS
, IPPROTO_IPV6
, mp
);
1655 * IPV6_HOPOPTS socket option. Recall that we required super-user
1656 * privilege for the option (see ip6_ctloutput), but it might be too
1657 * strict, since there might be some hop-by-hop options which can be
1658 * returned to normal user.
1659 * See also RFC 2292 section 6 (or RFC 3542 section 8).
1661 if ((in6p
->inp_flags
& IN6P_HOPOPTS
) != 0) {
1663 * Check if a hop-by-hop options header is contatined in the
1664 * received packet, and if so, store the options as ancillary
1665 * data. Note that a hop-by-hop options header must be
1666 * just after the IPv6 header, which is assured through the
1667 * IPv6 input processing.
1669 ip6
= mtod(m
, struct ip6_hdr
*);
1670 if (ip6
->ip6_nxt
== IPPROTO_HOPOPTS
) {
1671 struct ip6_hbh
*hbh
;
1677 #ifndef PULLDOWN_TEST
1678 hbh
= (struct ip6_hbh
*)(ip6
+ 1);
1679 hbhlen
= (hbh
->ip6h_len
+ 1) << 3;
1681 ext
= ip6_pullexthdr(m
, sizeof (struct ip6_hdr
),
1684 ip6stat
.ip6s_tooshort
++;
1687 hbh
= mtod(ext
, struct ip6_hbh
*);
1688 hbhlen
= (hbh
->ip6h_len
+ 1) << 3;
1689 if (hbhlen
!= ext
->m_len
) {
1691 ip6stat
.ip6s_tooshort
++;
1697 * XXX: We copy the whole header even if a
1698 * jumbo payload option is included, the option which
1699 * is to be removed before returning according to
1701 * Note: this constraint is removed in RFC3542
1703 mp
= sbcreatecontrol_mbuf((caddr_t
)hbh
, hbhlen
,
1704 IS2292(in6p
, IPV6_2292HOPOPTS
, IPV6_HOPOPTS
),
1716 if ((in6p
->inp_flags
& (IN6P_RTHDR
| IN6P_DSTOPTS
)) != 0) {
1717 int nxt
= ip6
->ip6_nxt
, off
= sizeof (struct ip6_hdr
);
1720 * Search for destination options headers or routing
1721 * header(s) through the header chain, and stores each
1722 * header as ancillary data.
1723 * Note that the order of the headers remains in
1724 * the chain of ancillary data.
1726 while (1) { /* is explicit loop prevention necessary? */
1727 struct ip6_ext
*ip6e
= NULL
;
1730 struct mbuf
*ext
= NULL
;
1734 * if it is not an extension header, don't try to
1735 * pull it from the chain.
1738 case IPPROTO_DSTOPTS
:
1739 case IPPROTO_ROUTING
:
1740 case IPPROTO_HOPOPTS
:
1741 case IPPROTO_AH
: /* is it possible? */
1747 #ifndef PULLDOWN_TEST
1748 if (off
+ sizeof (*ip6e
) > m
->m_len
)
1750 ip6e
= (struct ip6_ext
*)(mtod(m
, caddr_t
) + off
);
1751 if (nxt
== IPPROTO_AH
)
1752 elen
= (ip6e
->ip6e_len
+ 2) << 2;
1754 elen
= (ip6e
->ip6e_len
+ 1) << 3;
1755 if (off
+ elen
> m
->m_len
)
1758 ext
= ip6_pullexthdr(m
, off
, nxt
);
1760 ip6stat
.ip6s_tooshort
++;
1763 ip6e
= mtod(ext
, struct ip6_ext
*);
1764 if (nxt
== IPPROTO_AH
)
1765 elen
= (ip6e
->ip6e_len
+ 2) << 2;
1767 elen
= (ip6e
->ip6e_len
+ 1) << 3;
1768 if (elen
!= ext
->m_len
) {
1770 ip6stat
.ip6s_tooshort
++;
1776 case IPPROTO_DSTOPTS
:
1777 if (!(in6p
->inp_flags
& IN6P_DSTOPTS
))
1780 mp
= sbcreatecontrol_mbuf((caddr_t
)ip6e
, elen
,
1781 IS2292(in6p
, IPV6_2292DSTOPTS
,
1782 IPV6_DSTOPTS
), IPPROTO_IPV6
, mp
);
1790 case IPPROTO_ROUTING
:
1791 if (!in6p
->inp_flags
& IN6P_RTHDR
)
1794 mp
= sbcreatecontrol_mbuf((caddr_t
)ip6e
, elen
,
1795 IS2292(in6p
, IPV6_2292RTHDR
, IPV6_RTHDR
),
1804 case IPPROTO_HOPOPTS
:
1805 case IPPROTO_AH
: /* is it possible? */
1810 * other cases have been filtered in the above.
1811 * none will visit this case. here we supply
1812 * the code just in case (nxt overwritten or
1822 /* proceed with the next header. */
1824 nxt
= ip6e
->ip6e_nxt
;
1836 ip6stat
.ip6s_pktdropcntrl
++;
1837 /* XXX increment a stat to show the failure */
1843 ip6_notify_pmtu(struct inpcb
*in6p
, struct sockaddr_in6
*dst
, u_int32_t
*mtu
)
1847 struct ip6_mtuinfo mtuctl
;
1849 so
= in6p
->inp_socket
;
1855 if (so
== NULL
) { /* I believe this is impossible */
1856 panic("ip6_notify_pmtu: socket is NULL");
1861 bzero(&mtuctl
, sizeof (mtuctl
)); /* zero-clear for safety */
1862 mtuctl
.ip6m_mtu
= *mtu
;
1863 mtuctl
.ip6m_addr
= *dst
;
1864 if (sa6_recoverscope(&mtuctl
.ip6m_addr
, TRUE
))
1867 if ((m_mtu
= sbcreatecontrol((caddr_t
)&mtuctl
, sizeof (mtuctl
),
1868 IPV6_PATHMTU
, IPPROTO_IPV6
)) == NULL
)
1871 if (sbappendaddr(&so
->so_rcv
, SA(dst
), NULL
, m_mtu
, NULL
) == 0) {
1873 /* XXX: should count statistics */
1881 * pull single extension header from mbuf chain. returns single mbuf that
1882 * contains the result, or NULL on error.
1884 static struct mbuf
*
1885 ip6_pullexthdr(m
, off
, nxt
)
1890 struct ip6_ext ip6e
;
1896 case IPPROTO_DSTOPTS
:
1897 case IPPROTO_ROUTING
:
1898 case IPPROTO_HOPOPTS
:
1899 case IPPROTO_AH
: /* is it possible? */
1902 printf("ip6_pullexthdr: invalid nxt=%d\n", nxt
);
1906 m_copydata(m
, off
, sizeof (ip6e
), (caddr_t
)&ip6e
);
1907 if (nxt
== IPPROTO_AH
)
1908 elen
= (ip6e
.ip6e_len
+ 2) << 2;
1910 elen
= (ip6e
.ip6e_len
+ 1) << 3;
1912 MGET(n
, M_DONTWAIT
, MT_DATA
);
1913 if (n
&& elen
>= MLEN
) {
1914 MCLGET(n
, M_DONTWAIT
);
1915 if ((n
->m_flags
& M_EXT
) == 0) {
1924 if (elen
>= M_TRAILINGSPACE(n
)) {
1929 m_copydata(m
, off
, elen
, mtod(n
, caddr_t
));
1936 * Get pointer to the previous header followed by the header
1937 * currently processed.
1938 * XXX: This function supposes that
1939 * M includes all headers,
1940 * the next header field and the header length field of each header
1942 * the sum of each header length equals to OFF.
1943 * Because of these assumptions, this function must be called very
1944 * carefully. Moreover, it will not be used in the near future when
1945 * we develop `neater' mechanism to process extension headers.
1948 ip6_get_prevhdr(m
, off
)
1952 struct ip6_hdr
*ip6
= mtod(m
, struct ip6_hdr
*);
1954 if (off
== sizeof (struct ip6_hdr
)) {
1955 return ((char *)&ip6
->ip6_nxt
);
1958 struct ip6_ext
*ip6e
= NULL
;
1961 len
= sizeof (struct ip6_hdr
);
1963 ip6e
= (struct ip6_ext
*)(mtod(m
, caddr_t
) + len
);
1966 case IPPROTO_FRAGMENT
:
1967 len
+= sizeof (struct ip6_frag
);
1970 len
+= (ip6e
->ip6e_len
+ 2) << 2;
1973 len
+= (ip6e
->ip6e_len
+ 1) << 3;
1976 nxt
= ip6e
->ip6e_nxt
;
1979 return ((char *)&ip6e
->ip6e_nxt
);
1986 * get next header offset. m will be retained.
1989 ip6_nexthdr(struct mbuf
*m
, int off
, int proto
, int *nxtp
)
1992 struct ip6_ext ip6e
;
1997 if ((m
->m_flags
& M_PKTHDR
) == 0 || m
->m_pkthdr
.len
< off
)
2002 if (m
->m_pkthdr
.len
< off
+ sizeof (ip6
))
2004 m_copydata(m
, off
, sizeof (ip6
), (caddr_t
)&ip6
);
2006 *nxtp
= ip6
.ip6_nxt
;
2007 off
+= sizeof (ip6
);
2010 case IPPROTO_FRAGMENT
:
2012 * terminate parsing if it is not the first fragment,
2013 * it does not make sense to parse through it.
2015 if (m
->m_pkthdr
.len
< off
+ sizeof (fh
))
2017 m_copydata(m
, off
, sizeof (fh
), (caddr_t
)&fh
);
2018 /* IP6F_OFF_MASK = 0xfff8(BigEndian), 0xf8ff(LittleEndian) */
2019 if (fh
.ip6f_offlg
& IP6F_OFF_MASK
)
2022 *nxtp
= fh
.ip6f_nxt
;
2023 off
+= sizeof (struct ip6_frag
);
2027 if (m
->m_pkthdr
.len
< off
+ sizeof (ip6e
))
2029 m_copydata(m
, off
, sizeof (ip6e
), (caddr_t
)&ip6e
);
2031 *nxtp
= ip6e
.ip6e_nxt
;
2032 off
+= (ip6e
.ip6e_len
+ 2) << 2;
2035 case IPPROTO_HOPOPTS
:
2036 case IPPROTO_ROUTING
:
2037 case IPPROTO_DSTOPTS
:
2038 if (m
->m_pkthdr
.len
< off
+ sizeof (ip6e
))
2040 m_copydata(m
, off
, sizeof (ip6e
), (caddr_t
)&ip6e
);
2042 *nxtp
= ip6e
.ip6e_nxt
;
2043 off
+= (ip6e
.ip6e_len
+ 1) << 3;
2048 case IPPROTO_IPCOMP
:
2060 * get offset for the last header in the chain. m will be kept untainted.
2063 ip6_lasthdr(struct mbuf
*m
, int off
, int proto
, int *nxtp
)
2073 newoff
= ip6_nexthdr(m
, off
, proto
, nxtp
);
2076 else if (newoff
< off
)
2077 return (-1); /* invalid */
2078 else if (newoff
== off
)
2087 ip6_addaux(struct mbuf
*m
)
2091 /* Check if one is already allocated */
2092 tag
= m_tag_locate(m
, KERNEL_MODULE_TAG_ID
,
2093 KERNEL_TAG_TYPE_INET6
, NULL
);
2095 /* Allocate a tag */
2096 tag
= m_tag_create(KERNEL_MODULE_TAG_ID
, KERNEL_TAG_TYPE_INET6
,
2097 sizeof (struct ip6aux
), M_DONTWAIT
, m
);
2099 /* Attach it to the mbuf */
2101 m_tag_prepend(m
, tag
);
2105 return (tag
? (struct ip6aux
*)(tag
+ 1) : NULL
);
2109 ip6_findaux(struct mbuf
*m
)
2113 tag
= m_tag_locate(m
, KERNEL_MODULE_TAG_ID
,
2114 KERNEL_TAG_TYPE_INET6
, NULL
);
2116 return (tag
? (struct ip6aux
*)(tag
+ 1) : NULL
);
2120 ip6_delaux(struct mbuf
*m
)
2124 tag
= m_tag_locate(m
, KERNEL_MODULE_TAG_ID
,
2125 KERNEL_TAG_TYPE_INET6
, NULL
);
2127 m_tag_delete(m
, tag
);
2137 frag6_drain(); /* fragments */
2138 in6_rtqdrain(); /* protocol cloned routes */
2139 nd6_drain(NULL
); /* cloned routes: ND6 */
2143 * System control for IP6
2146 u_char inet6ctlerrmap
[PRC_NCMDS
] = {
2148 0, EMSGSIZE
, EHOSTDOWN
, EHOSTUNREACH
,
2149 EHOSTUNREACH
, EHOSTUNREACH
, ECONNREFUSED
, ECONNREFUSED
,
2150 EMSGSIZE
, EHOSTUNREACH
, 0, 0,