2 * Copyright (c) 2003-2016 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>
124 #include <net/net_perf.h>
126 #include <netinet/in.h>
127 #include <netinet/in_systm.h>
129 #include <netinet/ip.h>
130 #include <netinet/ip_icmp.h>
132 #include <netinet/kpi_ipfilter_var.h>
133 #include <netinet/ip6.h>
134 #include <netinet6/in6_var.h>
135 #include <netinet6/ip6_var.h>
136 #include <netinet/in_pcb.h>
137 #include <netinet/icmp6.h>
138 #include <netinet6/in6_ifattach.h>
139 #include <netinet6/nd6.h>
140 #include <netinet6/scope6_var.h>
141 #include <netinet6/ip6protosw.h>
144 #include <netinet6/ipsec.h>
145 #include <netinet6/ipsec6.h>
146 extern int ipsec_bypass
;
150 #include <netinet/ip_fw.h>
151 #include <netinet/ip_dummynet.h>
152 #endif /* DUMMYNET */
154 /* we need it for NLOOP. */
158 #include <net/pfvar.h>
161 struct ip6protosw
*ip6_protox
[IPPROTO_MAX
];
163 static lck_grp_attr_t
*in6_ifaddr_rwlock_grp_attr
;
164 static lck_grp_t
*in6_ifaddr_rwlock_grp
;
165 static lck_attr_t
*in6_ifaddr_rwlock_attr
;
166 decl_lck_rw_data(, in6_ifaddr_rwlock
);
168 /* Protected by in6_ifaddr_rwlock */
169 struct in6_ifaddr
*in6_ifaddrs
= NULL
;
171 #define IN6_IFSTAT_REQUIRE_ALIGNED_64(f) \
172 _CASSERT(!(offsetof(struct in6_ifstat, f) % sizeof (uint64_t)))
174 #define ICMP6_IFSTAT_REQUIRE_ALIGNED_64(f) \
175 _CASSERT(!(offsetof(struct icmp6_ifstat, f) % sizeof (uint64_t)))
177 struct ip6stat ip6stat
;
179 decl_lck_mtx_data(, proxy6_lock
);
180 decl_lck_mtx_data(static, dad6_mutex_data
);
181 decl_lck_mtx_data(static, nd6_mutex_data
);
182 decl_lck_mtx_data(static, prefix6_mutex_data
);
183 lck_mtx_t
*dad6_mutex
= &dad6_mutex_data
;
184 lck_mtx_t
*nd6_mutex
= &nd6_mutex_data
;
185 lck_mtx_t
*prefix6_mutex
= &prefix6_mutex_data
;
186 #ifdef ENABLE_ADDRSEL
187 decl_lck_mtx_data(static, addrsel_mutex_data
);
188 lck_mtx_t
*addrsel_mutex
= &addrsel_mutex_data
;
190 static lck_attr_t
*ip6_mutex_attr
;
191 static lck_grp_t
*ip6_mutex_grp
;
192 static lck_grp_attr_t
*ip6_mutex_grp_attr
;
194 extern int loopattach_done
;
195 extern void addrsel_policy_init(void);
197 static int sysctl_reset_ip6_input_stats SYSCTL_HANDLER_ARGS
;
198 static int sysctl_ip6_input_measure_bins SYSCTL_HANDLER_ARGS
;
199 static int sysctl_ip6_input_getperf SYSCTL_HANDLER_ARGS
;
200 static void ip6_init_delayed(void);
201 static int ip6_hopopts_input(u_int32_t
*, u_int32_t
*, struct mbuf
**, int *);
204 extern void stfattach(void);
207 SYSCTL_DECL(_net_inet6_ip6
);
209 static uint32_t ip6_adj_clear_hwcksum
= 0;
210 SYSCTL_UINT(_net_inet6_ip6
, OID_AUTO
, adj_clear_hwcksum
,
211 CTLFLAG_RW
| CTLFLAG_LOCKED
, &ip6_adj_clear_hwcksum
, 0,
212 "Invalidate hwcksum info when adjusting length");
214 static int ip6_input_measure
= 0;
215 SYSCTL_PROC(_net_inet6_ip6
, OID_AUTO
, input_perf
,
216 CTLTYPE_INT
| CTLFLAG_RW
| CTLFLAG_LOCKED
,
217 &ip6_input_measure
, 0, sysctl_reset_ip6_input_stats
, "I", "Do time measurement");
219 static uint64_t ip6_input_measure_bins
= 0;
220 SYSCTL_PROC(_net_inet6_ip6
, OID_AUTO
, input_perf_bins
,
221 CTLTYPE_QUAD
| CTLFLAG_RW
| CTLFLAG_LOCKED
, &ip6_input_measure_bins
, 0,
222 sysctl_ip6_input_measure_bins
, "I",
223 "bins for chaining performance data histogram");
225 static net_perf_t net_perf
;
226 SYSCTL_PROC(_net_inet6_ip6
, OID_AUTO
, input_perf_data
,
227 CTLTYPE_STRUCT
| CTLFLAG_RD
| CTLFLAG_LOCKED
,
228 0, 0, sysctl_ip6_input_getperf
, "S,net_perf",
229 "IP6 input performance data (struct net_perf, net/net_perf.h)");
232 * On platforms which require strict alignment (currently for anything but
233 * i386 or x86_64), check if the IP header pointer is 32-bit aligned; if not,
234 * copy the contents of the mbuf chain into a new chain, and free the original
235 * one. Create some head room in the first mbuf of the new chain, in case
236 * it's needed later on.
238 * RFC 2460 says that IPv6 headers are 64-bit aligned, but network interfaces
239 * mostly align to 32-bit boundaries. Care should be taken never to use 64-bit
240 * load/store operations on the fields in IPv6 headers.
242 #if defined(__i386__) || defined(__x86_64__)
243 #define IP6_HDR_ALIGNMENT_FIXUP(_m, _ifp, _action) do { } while (0)
244 #else /* !__i386__ && !__x86_64__ */
245 #define IP6_HDR_ALIGNMENT_FIXUP(_m, _ifp, _action) do { \
246 if (!IP6_HDR_ALIGNED_P(mtod(_m, caddr_t))) { \
248 struct ifnet *__ifp = (_ifp); \
249 atomic_add_64(&(__ifp)->if_alignerrs, 1); \
250 if (((_m)->m_flags & M_PKTHDR) && \
251 (_m)->m_pkthdr.pkt_hdr != NULL) \
252 (_m)->m_pkthdr.pkt_hdr = NULL; \
253 _n = m_defrag_offset(_m, max_linkhdr, M_NOWAIT); \
255 ip6stat.ip6s_toosmall++; \
260 VERIFY(_n != (_m)); \
265 #endif /* !__i386__ && !__x86_64__ */
268 ip6_proto_input(protocol_family_t protocol
, mbuf_t packet
)
270 #pragma unused(protocol)
272 struct timeval start_tv
;
273 if (ip6_input_measure
)
274 net_perf_start_time(&net_perf
, &start_tv
);
278 if (ip6_input_measure
) {
279 net_perf_measure_time(&net_perf
, &start_tv
, 1);
280 net_perf_histogram(&net_perf
, 1);
286 * IP6 initialization: fill in IP6 protocol switch table.
287 * All protocols not implemented in kernel go to raw IP6 protocol handler.
290 ip6_init(struct ip6protosw
*pp
, struct domain
*dp
)
292 static int ip6_initialized
= 0;
296 domain_unguard_t unguard
;
298 domain_proto_mtx_lock_assert_held();
299 VERIFY((pp
->pr_flags
& (PR_INITIALIZED
|PR_ATTACHED
)) == PR_ATTACHED
);
301 _CASSERT((sizeof (struct ip6_hdr
) +
302 sizeof (struct icmp6_hdr
)) <= _MHLEN
);
308 pr
= pffindproto_locked(PF_INET6
, IPPROTO_RAW
, SOCK_RAW
);
310 panic("%s: Unable to find [PF_INET6,IPPROTO_RAW,SOCK_RAW]\n",
315 /* Initialize the entire ip6_protox[] array to IPPROTO_RAW. */
316 for (i
= 0; i
< IPPROTO_MAX
; i
++)
317 ip6_protox
[i
] = (struct ip6protosw
*)pr
;
319 * Cycle through IP protocols and put them into the appropriate place
320 * in ip6_protox[], skipping protocols IPPROTO_{IP,RAW}.
322 VERIFY(dp
== inet6domain
&& dp
->dom_family
== PF_INET6
);
323 TAILQ_FOREACH(pr
, &dp
->dom_protosw
, pr_entry
) {
324 VERIFY(pr
->pr_domain
== dp
);
325 if (pr
->pr_protocol
!= 0 && pr
->pr_protocol
!= IPPROTO_RAW
) {
326 /* Be careful to only index valid IP protocols. */
327 if (pr
->pr_protocol
< IPPROTO_MAX
)
328 ip6_protox
[pr
->pr_protocol
] =
329 (struct ip6protosw
*)pr
;
333 ip6_mutex_grp_attr
= lck_grp_attr_alloc_init();
335 ip6_mutex_grp
= lck_grp_alloc_init("ip6", ip6_mutex_grp_attr
);
336 ip6_mutex_attr
= lck_attr_alloc_init();
338 lck_mtx_init(dad6_mutex
, ip6_mutex_grp
, ip6_mutex_attr
);
339 lck_mtx_init(nd6_mutex
, ip6_mutex_grp
, ip6_mutex_attr
);
340 lck_mtx_init(prefix6_mutex
, ip6_mutex_grp
, ip6_mutex_attr
);
341 scope6_init(ip6_mutex_grp
, ip6_mutex_attr
);
343 #ifdef ENABLE_ADDRSEL
344 lck_mtx_init(addrsel_mutex
, ip6_mutex_grp
, ip6_mutex_attr
);
347 lck_mtx_init(&proxy6_lock
, ip6_mutex_grp
, ip6_mutex_attr
);
349 in6_ifaddr_rwlock_grp_attr
= lck_grp_attr_alloc_init();
350 in6_ifaddr_rwlock_grp
= lck_grp_alloc_init("in6_ifaddr_rwlock",
351 in6_ifaddr_rwlock_grp_attr
);
352 in6_ifaddr_rwlock_attr
= lck_attr_alloc_init();
353 lck_rw_init(&in6_ifaddr_rwlock
, in6_ifaddr_rwlock_grp
,
354 in6_ifaddr_rwlock_attr
);
356 IN6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_in_receive
);
357 IN6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_in_hdrerr
);
358 IN6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_in_toobig
);
359 IN6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_in_noroute
);
360 IN6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_in_addrerr
);
361 IN6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_in_protounknown
);
362 IN6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_in_truncated
);
363 IN6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_in_discard
);
364 IN6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_in_deliver
);
365 IN6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_out_forward
);
366 IN6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_out_request
);
367 IN6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_out_discard
);
368 IN6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_out_fragok
);
369 IN6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_out_fragfail
);
370 IN6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_out_fragcreat
);
371 IN6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_reass_reqd
);
372 IN6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_reass_ok
);
373 IN6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_reass_fail
);
374 IN6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_in_mcast
);
375 IN6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_out_mcast
);
377 ICMP6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_in_msg
);
378 ICMP6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_in_error
);
379 ICMP6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_in_dstunreach
);
380 ICMP6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_in_adminprohib
);
381 ICMP6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_in_timeexceed
);
382 ICMP6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_in_paramprob
);
383 ICMP6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_in_pkttoobig
);
384 ICMP6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_in_echo
);
385 ICMP6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_in_echoreply
);
386 ICMP6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_in_routersolicit
);
387 ICMP6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_in_routeradvert
);
388 ICMP6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_in_neighborsolicit
);
389 ICMP6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_in_neighboradvert
);
390 ICMP6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_in_redirect
);
391 ICMP6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_in_mldquery
);
392 ICMP6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_in_mldreport
);
393 ICMP6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_in_mlddone
);
395 ICMP6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_out_msg
);
396 ICMP6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_out_error
);
397 ICMP6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_out_dstunreach
);
398 ICMP6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_out_adminprohib
);
399 ICMP6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_out_timeexceed
);
400 ICMP6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_out_paramprob
);
401 ICMP6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_out_pkttoobig
);
402 ICMP6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_out_echo
);
403 ICMP6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_out_echoreply
);
404 ICMP6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_out_routersolicit
);
405 ICMP6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_out_routeradvert
);
406 ICMP6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_out_neighborsolicit
);
407 ICMP6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_out_neighboradvert
);
408 ICMP6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_out_redirect
);
409 ICMP6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_out_mldquery
);
410 ICMP6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_out_mldreport
);
411 ICMP6_IFSTAT_REQUIRE_ALIGNED_64(ifs6_out_mlddone
);
415 (RandomULong() ^ tv
.tv_usec
) % MAX_TEMP_DESYNC_FACTOR
;
421 icmp6_init(NULL
, dp
);
422 addrsel_policy_init();
425 * P2P interfaces often route the local address to the loopback
426 * interface. At this point, lo0 hasn't been initialized yet, which
427 * means that we need to delay the IPv6 configuration of lo0.
429 net_init_add(ip6_init_delayed
);
431 unguard
= domain_unguard_deploy();
432 i
= proto_register_input(PF_INET6
, ip6_proto_input
, NULL
, 0);
434 panic("%s: failed to register PF_INET6 protocol: %d\n",
438 domain_unguard_release(unguard
);
442 ip6_init_delayed(void)
444 (void) in6_ifattach_prelim(lo_ifp
);
446 /* timer for regeneranation of temporary addresses randomize ID */
447 timeout(in6_tmpaddrtimer
, NULL
,
448 (ip6_temp_preferred_lifetime
- ip6_desync_factor
-
449 ip6_temp_regen_advance
) * hz
);
457 ip6_input(struct mbuf
*m
)
460 int off
= sizeof (struct ip6_hdr
), nest
;
462 u_int32_t rtalert
= ~0;
463 int nxt
= 0, ours
= 0;
464 struct ifnet
*inifp
, *deliverifp
= NULL
;
465 ipfilter_t inject_ipfref
= NULL
;
467 struct in6_ifaddr
*ia6
= NULL
;
468 struct sockaddr_in6
*dst6
;
471 #endif /* DUMMYNET */
473 struct route_in6 rin6
;
475 struct ip_fw_args args
;
476 #endif /* DUMMYNET */
478 #define rin6 ip6ibz.rin6
479 #define args ip6ibz.args
481 /* zero out {rin6, args} */
482 bzero(&ip6ibz
, sizeof (ip6ibz
));
485 * Check if the packet we received is valid after interface filter
488 MBUF_INPUT_CHECK(m
, m
->m_pkthdr
.rcvif
);
489 inifp
= m
->m_pkthdr
.rcvif
;
490 VERIFY(inifp
!= NULL
);
492 /* Perform IP header alignment fixup, if needed */
493 IP6_HDR_ALIGNMENT_FIXUP(m
, inifp
, return);
495 m
->m_pkthdr
.pkt_flags
&= ~PKTF_FORWARDED
;
498 * should the inner packet be considered authentic?
499 * see comment in ah4_input().
501 m
->m_flags
&= ~M_AUTHIPHDR
;
502 m
->m_flags
&= ~M_AUTHIPDGM
;
506 * make sure we don't have onion peering information into m_aux.
511 if ((tag
= m_tag_locate(m
, KERNEL_MODULE_TAG_ID
,
512 KERNEL_TAG_TYPE_DUMMYNET
, NULL
)) != NULL
) {
513 struct dn_pkt_tag
*dn_tag
;
515 dn_tag
= (struct dn_pkt_tag
*)(tag
+1);
517 args
.fwa_pf_rule
= dn_tag
->dn_pf_rule
;
519 m_tag_delete(m
, tag
);
522 if (args
.fwa_pf_rule
) {
523 ip6
= mtod(m
, struct ip6_hdr
*); /* In case PF got disabled */
527 #endif /* DUMMYNET */
530 * No need to proccess packet twice if we've already seen it.
532 inject_ipfref
= ipf_get_inject_filter(m
);
533 if (inject_ipfref
!= NULL
) {
534 ip6
= mtod(m
, struct ip6_hdr
*);
545 if (m
->m_flags
& M_EXT
) {
546 if (m
->m_next
!= NULL
)
547 ip6stat
.ip6s_mext2m
++;
549 ip6stat
.ip6s_mext1
++;
551 #define M2MMAX (sizeof (ip6stat.ip6s_m2m) / sizeof (ip6stat.ip6s_m2m[0]))
552 if (m
->m_next
!= NULL
) {
553 if (m
->m_pkthdr
.pkt_flags
& PKTF_LOOP
) {
555 ip6stat
.ip6s_m2m
[ifnet_index(lo_ifp
)]++;
556 } else if (inifp
->if_index
< M2MMAX
) {
557 ip6stat
.ip6s_m2m
[inifp
->if_index
]++;
559 ip6stat
.ip6s_m2m
[0]++;
568 * Drop the packet if IPv6 operation is disabled on the interface.
570 if (inifp
->if_eflags
& IFEF_IPV6_DISABLED
)
573 in6_ifstat_inc_na(inifp
, ifs6_in_receive
);
574 ip6stat
.ip6s_total
++;
577 * L2 bridge code and some other code can return mbuf chain
578 * that does not conform to KAME requirement. too bad.
579 * XXX: fails to join if interface MTU > MCLBYTES. jumbogram?
581 if (m
->m_next
!= NULL
&& m
->m_pkthdr
.len
< MCLBYTES
) {
584 MGETHDR(n
, M_DONTWAIT
, MT_HEADER
); /* MAC-OK */
587 if (n
&& m
->m_pkthdr
.len
> MHLEN
) {
588 MCLGET(n
, M_DONTWAIT
);
589 if ((n
->m_flags
& M_EXT
) == 0) {
597 m_copydata(m
, 0, m
->m_pkthdr
.len
, mtod(n
, caddr_t
));
598 n
->m_len
= m
->m_pkthdr
.len
;
602 IP6_EXTHDR_CHECK(m
, 0, sizeof (struct ip6_hdr
), { goto done
; });
604 if (m
->m_len
< sizeof (struct ip6_hdr
)) {
605 if ((m
= m_pullup(m
, sizeof (struct ip6_hdr
))) == 0) {
606 ip6stat
.ip6s_toosmall
++;
607 in6_ifstat_inc(inifp
, ifs6_in_hdrerr
);
612 ip6
= mtod(m
, struct ip6_hdr
*);
614 if ((ip6
->ip6_vfc
& IPV6_VERSION_MASK
) != IPV6_VERSION
) {
615 ip6stat
.ip6s_badvers
++;
616 in6_ifstat_inc(inifp
, ifs6_in_hdrerr
);
620 ip6stat
.ip6s_nxthist
[ip6
->ip6_nxt
]++;
623 * Check against address spoofing/corruption.
625 if (!(m
->m_pkthdr
.pkt_flags
& PKTF_LOOP
) &&
626 IN6_IS_ADDR_LOOPBACK(&ip6
->ip6_src
)) {
627 ip6stat
.ip6s_badscope
++;
628 in6_ifstat_inc(inifp
, ifs6_in_addrerr
);
631 if (IN6_IS_ADDR_MULTICAST(&ip6
->ip6_src
) ||
632 IN6_IS_ADDR_UNSPECIFIED(&ip6
->ip6_dst
)) {
634 * XXX: "badscope" is not very suitable for a multicast source.
636 ip6stat
.ip6s_badscope
++;
637 in6_ifstat_inc(inifp
, ifs6_in_addrerr
);
640 if (IN6_IS_ADDR_MC_INTFACELOCAL(&ip6
->ip6_dst
) &&
641 !(m
->m_pkthdr
.pkt_flags
& PKTF_LOOP
)) {
643 * In this case, the packet should come from the loopback
644 * interface. However, we cannot just check the if_flags,
645 * because ip6_mloopback() passes the "actual" interface
646 * as the outgoing/incoming interface.
648 ip6stat
.ip6s_badscope
++;
649 in6_ifstat_inc(inifp
, ifs6_in_addrerr
);
654 * The following check is not documented in specs. A malicious
655 * party may be able to use IPv4 mapped addr to confuse tcp/udp stack
656 * and bypass security checks (act as if it was from 127.0.0.1 by using
657 * IPv6 src ::ffff:127.0.0.1). Be cautious.
659 * This check chokes if we are in an SIIT cloud. As none of BSDs
660 * support IPv4-less kernel compilation, we cannot support SIIT
661 * environment at all. So, it makes more sense for us to reject any
662 * malicious packets for non-SIIT environment, than try to do a
663 * partial support for SIIT environment.
665 if (IN6_IS_ADDR_V4MAPPED(&ip6
->ip6_src
) ||
666 IN6_IS_ADDR_V4MAPPED(&ip6
->ip6_dst
)) {
667 ip6stat
.ip6s_badscope
++;
668 in6_ifstat_inc(inifp
, ifs6_in_addrerr
);
673 * Reject packets with IPv4 compatible addresses (auto tunnel).
675 * The code forbids auto tunnel relay case in RFC1933 (the check is
676 * stronger than RFC1933). We may want to re-enable it if mech-xx
677 * is revised to forbid relaying case.
679 if (IN6_IS_ADDR_V4COMPAT(&ip6
->ip6_src
) ||
680 IN6_IS_ADDR_V4COMPAT(&ip6
->ip6_dst
)) {
681 ip6stat
.ip6s_badscope
++;
682 in6_ifstat_inc(inifp
, ifs6_in_addrerr
);
688 * Naively assume we can attribute inbound data to the route we would
689 * use to send to this destination. Asymetric routing breaks this
690 * assumption, but it still allows us to account for traffic from
691 * a remote node in the routing table.
692 * this has a very significant performance impact so we bypass
693 * if nstat_collect is disabled. We may also bypass if the
694 * protocol is tcp in the future because tcp will have a route that
695 * we can use to attribute the data to. That does mean we would not
696 * account for forwarded tcp traffic.
699 struct rtentry
*rte
=
700 ifnet_cached_rtlookup_inet6(inifp
, &ip6
->ip6_src
);
702 nstat_route_rx(rte
, 1, m
->m_pkthdr
.len
, 0);
707 /* for consistency */
708 m
->m_pkthdr
.pkt_proto
= ip6
->ip6_nxt
;
712 #endif /* DUMMYNET */
714 /* Invoke inbound packet filter */
718 error
= pf_af_hook(inifp
, NULL
, &m
, AF_INET6
, TRUE
, &args
);
719 #else /* !DUMMYNET */
720 error
= pf_af_hook(inifp
, NULL
, &m
, AF_INET6
, TRUE
, NULL
);
721 #endif /* !DUMMYNET */
722 if (error
!= 0 || m
== NULL
) {
724 panic("%s: unexpected packet %p\n",
728 /* Already freed by callee */
731 ip6
= mtod(m
, struct ip6_hdr
*);
735 /* drop packets if interface ID portion is already filled */
736 if (!(inifp
->if_flags
& IFF_LOOPBACK
) &&
737 !(m
->m_pkthdr
.pkt_flags
& PKTF_LOOP
)) {
738 if (IN6_IS_SCOPE_LINKLOCAL(&ip6
->ip6_src
) &&
739 ip6
->ip6_src
.s6_addr16
[1]) {
740 ip6stat
.ip6s_badscope
++;
743 if (IN6_IS_SCOPE_EMBED(&ip6
->ip6_dst
) &&
744 ip6
->ip6_dst
.s6_addr16
[1]) {
745 ip6stat
.ip6s_badscope
++;
750 if (m
->m_pkthdr
.pkt_flags
& PKTF_IFAINFO
) {
751 if (IN6_IS_SCOPE_LINKLOCAL(&ip6
->ip6_src
))
752 ip6
->ip6_src
.s6_addr16
[1] =
753 htons(m
->m_pkthdr
.src_ifindex
);
754 if (IN6_IS_SCOPE_EMBED(&ip6
->ip6_dst
))
755 ip6
->ip6_dst
.s6_addr16
[1] =
756 htons(m
->m_pkthdr
.dst_ifindex
);
758 if (IN6_IS_SCOPE_LINKLOCAL(&ip6
->ip6_src
))
759 ip6
->ip6_src
.s6_addr16
[1] = htons(inifp
->if_index
);
760 if (IN6_IS_SCOPE_EMBED(&ip6
->ip6_dst
))
761 ip6
->ip6_dst
.s6_addr16
[1] = htons(inifp
->if_index
);
767 if (IN6_IS_ADDR_MULTICAST(&ip6
->ip6_dst
)) {
768 struct in6_multi
*in6m
= NULL
;
770 in6_ifstat_inc_na(inifp
, ifs6_in_mcast
);
772 * See if we belong to the destination multicast group on the
775 in6_multihead_lock_shared();
776 IN6_LOOKUP_MULTI(&ip6
->ip6_dst
, inifp
, in6m
);
777 in6_multihead_lock_done();
781 } else if (!nd6_prproxy
) {
782 ip6stat
.ip6s_notmember
++;
783 ip6stat
.ip6s_cantforward
++;
784 in6_ifstat_inc(inifp
, ifs6_in_discard
);
795 * Fast path: see if the target is ourselves.
797 lck_rw_lock_shared(&in6_ifaddr_rwlock
);
798 for (ia6
= in6_ifaddrs
; ia6
!= NULL
; ia6
= ia6
->ia_next
) {
800 * No reference is held on the address, as we just need
801 * to test for a few things while holding the RW lock.
803 if (IN6_ARE_ADDR_EQUAL(&ia6
->ia_addr
.sin6_addr
, &ip6
->ip6_dst
))
809 * For performance, test without acquiring the address lock;
810 * a lot of things in the address are set once and never
811 * changed (e.g. ia_ifp.)
813 if (!(ia6
->ia6_flags
& IN6_IFF_NOTREADY
)) {
814 /* this address is ready */
816 deliverifp
= ia6
->ia_ifp
;
818 * record dst address information into mbuf.
820 (void) ip6_setdstifaddr_info(m
, 0, ia6
);
821 lck_rw_done(&in6_ifaddr_rwlock
);
824 lck_rw_done(&in6_ifaddr_rwlock
);
826 /* address is not ready, so discard the packet. */
827 nd6log((LOG_INFO
, "%s: packet to an unready address %s->%s\n",
828 __func__
, ip6_sprintf(&ip6
->ip6_src
),
829 ip6_sprintf(&ip6
->ip6_dst
)));
832 lck_rw_done(&in6_ifaddr_rwlock
);
835 * Slow path: route lookup.
837 dst6
= SIN6(&rin6
.ro_dst
);
838 dst6
->sin6_len
= sizeof (struct sockaddr_in6
);
839 dst6
->sin6_family
= AF_INET6
;
840 dst6
->sin6_addr
= ip6
->ip6_dst
;
842 rtalloc_scoped_ign((struct route
*)&rin6
,
843 RTF_PRCLONING
, IFSCOPE_NONE
);
844 if (rin6
.ro_rt
!= NULL
)
845 RT_LOCK_SPIN(rin6
.ro_rt
);
847 #define rt6_key(r) (SIN6((r)->rt_nodes->rn_key))
850 * Accept the packet if the forwarding interface to the destination
851 * according to the routing table is the loopback interface,
852 * unless the associated route has a gateway.
853 * Note that this approach causes to accept a packet if there is a
854 * route to the loopback interface for the destination of the packet.
855 * But we think it's even useful in some situations, e.g. when using
856 * a special daemon which wants to intercept the packet.
858 * XXX: some OSes automatically make a cloned route for the destination
859 * of an outgoing packet. If the outgoing interface of the packet
860 * is a loopback one, the kernel would consider the packet to be
861 * accepted, even if we have no such address assinged on the interface.
862 * We check the cloned flag of the route entry to reject such cases,
863 * assuming that route entries for our own addresses are not made by
864 * cloning (it should be true because in6_addloop explicitly installs
865 * the host route). However, we might have to do an explicit check
866 * while it would be less efficient. Or, should we rather install a
867 * reject route for such a case?
869 if (rin6
.ro_rt
!= NULL
&&
870 (rin6
.ro_rt
->rt_flags
& (RTF_HOST
|RTF_GATEWAY
)) == RTF_HOST
&&
872 !(rin6
.ro_rt
->rt_flags
& RTF_WASCLONED
) &&
874 rin6
.ro_rt
->rt_ifp
->if_type
== IFT_LOOP
) {
875 ia6
= (struct in6_ifaddr
*)rin6
.ro_rt
->rt_ifa
;
877 * Packets to a tentative, duplicated, or somehow invalid
878 * address must not be accepted.
880 * For performance, test without acquiring the address lock;
881 * a lot of things in the address are set once and never
882 * changed (e.g. ia_ifp.)
884 if (!(ia6
->ia6_flags
& IN6_IFF_NOTREADY
)) {
885 /* this address is ready */
887 deliverifp
= ia6
->ia_ifp
; /* correct? */
889 * record dst address information into mbuf.
891 (void) ip6_setdstifaddr_info(m
, 0, ia6
);
892 RT_UNLOCK(rin6
.ro_rt
);
895 RT_UNLOCK(rin6
.ro_rt
);
897 /* address is not ready, so discard the packet. */
898 nd6log((LOG_INFO
, "%s: packet to an unready address %s->%s\n",
899 __func__
, ip6_sprintf(&ip6
->ip6_src
),
900 ip6_sprintf(&ip6
->ip6_dst
)));
904 if (rin6
.ro_rt
!= NULL
)
905 RT_UNLOCK(rin6
.ro_rt
);
908 * Now there is no reason to process the packet if it's not our own
909 * and we're not a router.
911 if (!ip6_forwarding
) {
912 ip6stat
.ip6s_cantforward
++;
913 in6_ifstat_inc(inifp
, ifs6_in_discard
);
919 * record dst address information into mbuf, if we don't have one yet.
920 * note that we are unable to record it, if the address is not listed
921 * as our interface address (e.g. multicast addresses, etc.)
923 if (deliverifp
!= NULL
&& ia6
== NULL
) {
924 ia6
= in6_ifawithifp(deliverifp
, &ip6
->ip6_dst
);
926 (void) ip6_setdstifaddr_info(m
, 0, ia6
);
927 IFA_REMREF(&ia6
->ia_ifa
);
932 * Process Hop-by-Hop options header if it's contained.
933 * m may be modified in ip6_hopopts_input().
934 * If a JumboPayload option is included, plen will also be modified.
936 plen
= (u_int32_t
)ntohs(ip6
->ip6_plen
);
937 if (ip6
->ip6_nxt
== IPPROTO_HOPOPTS
) {
940 if (ip6_hopopts_input(&plen
, &rtalert
, &m
, &off
)) {
941 #if 0 /* touches NULL pointer */
942 in6_ifstat_inc(inifp
, ifs6_in_discard
);
944 goto done
; /* m have already been freed */
948 ip6
= mtod(m
, struct ip6_hdr
*);
951 * if the payload length field is 0 and the next header field
952 * indicates Hop-by-Hop Options header, then a Jumbo Payload
953 * option MUST be included.
955 if (ip6
->ip6_plen
== 0 && plen
== 0) {
957 * Note that if a valid jumbo payload option is
958 * contained, ip6_hopopts_input() must set a valid
959 * (non-zero) payload length to the variable plen.
961 ip6stat
.ip6s_badoptions
++;
962 in6_ifstat_inc(inifp
, ifs6_in_discard
);
963 in6_ifstat_inc(inifp
, ifs6_in_hdrerr
);
964 icmp6_error(m
, ICMP6_PARAM_PROB
, ICMP6_PARAMPROB_HEADER
,
965 (caddr_t
)&ip6
->ip6_plen
- (caddr_t
)ip6
);
968 /* ip6_hopopts_input() ensures that mbuf is contiguous */
969 hbh
= (struct ip6_hbh
*)(ip6
+ 1);
973 * If we are acting as a router and the packet contains a
974 * router alert option, see if we know the option value.
975 * Currently, we only support the option value for MLD, in which
976 * case we should pass the packet to the multicast routing
979 if (rtalert
!= ~0 && ip6_forwarding
) {
981 case IP6OPT_RTALERT_MLD
:
986 * RFC2711 requires unrecognized values must be
996 * Check that the amount of data in the buffers
997 * is as at least much as the IPv6 header would have us expect.
998 * Trim mbufs if longer than we expect.
999 * Drop packet if shorter than we expect.
1001 if (m
->m_pkthdr
.len
- sizeof (struct ip6_hdr
) < plen
) {
1002 ip6stat
.ip6s_tooshort
++;
1003 in6_ifstat_inc(inifp
, ifs6_in_truncated
);
1006 if (m
->m_pkthdr
.len
> sizeof (struct ip6_hdr
) + plen
) {
1008 * Invalidate hardware checksum info if ip6_adj_clear_hwcksum
1009 * is set; useful to handle buggy drivers. Note that this
1010 * should not be enabled by default, as we may get here due
1011 * to link-layer padding.
1013 if (ip6_adj_clear_hwcksum
&&
1014 (m
->m_pkthdr
.csum_flags
& CSUM_DATA_VALID
) &&
1015 !(inifp
->if_flags
& IFF_LOOPBACK
) &&
1016 !(m
->m_pkthdr
.pkt_flags
& PKTF_LOOP
)) {
1017 m
->m_pkthdr
.csum_flags
&= ~CSUM_DATA_VALID
;
1018 m
->m_pkthdr
.csum_data
= 0;
1019 ip6stat
.ip6s_adj_hwcsum_clr
++;
1023 if (m
->m_len
== m
->m_pkthdr
.len
) {
1024 m
->m_len
= sizeof (struct ip6_hdr
) + plen
;
1025 m
->m_pkthdr
.len
= sizeof (struct ip6_hdr
) + plen
;
1027 m_adj(m
, sizeof (struct ip6_hdr
) + plen
-
1033 * Forward if desirable.
1035 if (IN6_IS_ADDR_MULTICAST(&ip6
->ip6_dst
)) {
1036 if (!ours
&& nd6_prproxy
) {
1038 * If this isn't for us, this might be a Neighbor
1039 * Solicitation (dst is solicited-node multicast)
1040 * against an address in one of the proxied prefixes;
1041 * if so, claim the packet and let icmp6_input()
1044 ours
= nd6_prproxy_isours(m
, ip6
, NULL
, IFSCOPE_NONE
);
1046 (m
->m_pkthdr
.pkt_flags
& PKTF_PROXY_DST
));
1052 * The unicast forwarding function might return the packet
1053 * if we are proxying prefix(es), and if the packet is an
1054 * ICMPv6 packet that has failed the zone checks, but is
1055 * targetted towards a proxied address (this is optimized by
1056 * way of RTF_PROXY test.) If so, claim the packet as ours
1057 * and let icmp6_input() handle the rest. The packet's hop
1058 * limit value is kept intact (it's not decremented). This
1059 * is for supporting Neighbor Unreachability Detection between
1060 * proxied nodes on different links (src is link-local, dst
1061 * is target address.)
1063 if ((m
= ip6_forward(m
, &rin6
, 0)) == NULL
)
1065 VERIFY(rin6
.ro_rt
!= NULL
);
1066 VERIFY(m
->m_pkthdr
.pkt_flags
& PKTF_PROXY_DST
);
1067 deliverifp
= rin6
.ro_rt
->rt_ifp
;
1071 ip6
= mtod(m
, struct ip6_hdr
*);
1074 * Malicious party may be able to use IPv4 mapped addr to confuse
1075 * tcp/udp stack and bypass security checks (act as if it was from
1076 * 127.0.0.1 by using IPv6 src ::ffff:127.0.0.1). Be cautious.
1078 * For SIIT end node behavior, you may want to disable the check.
1079 * However, you will become vulnerable to attacks using IPv4 mapped
1082 if (IN6_IS_ADDR_V4MAPPED(&ip6
->ip6_src
) ||
1083 IN6_IS_ADDR_V4MAPPED(&ip6
->ip6_dst
)) {
1084 ip6stat
.ip6s_badscope
++;
1085 in6_ifstat_inc(inifp
, ifs6_in_addrerr
);
1090 * Tell launch routine the next header
1092 ip6stat
.ip6s_delivered
++;
1093 in6_ifstat_inc_na(deliverifp
, ifs6_in_deliver
);
1099 * Perform IP header alignment fixup again, if needed. Note that
1100 * we do it once for the outermost protocol, and we assume each
1101 * protocol handler wouldn't mess with the alignment afterwards.
1103 IP6_HDR_ALIGNMENT_FIXUP(m
, inifp
, return);
1105 while (nxt
!= IPPROTO_DONE
) {
1106 struct ipfilter
*filter
;
1107 int (*pr_input
)(struct mbuf
**, int *, int);
1109 if (ip6_hdrnestlimit
&& (++nest
> ip6_hdrnestlimit
)) {
1110 ip6stat
.ip6s_toomanyhdr
++;
1115 * protection against faulty packet - there should be
1116 * more sanity checks in header chain processing.
1118 if (m
->m_pkthdr
.len
< off
) {
1119 ip6stat
.ip6s_tooshort
++;
1120 in6_ifstat_inc(inifp
, ifs6_in_truncated
);
1127 * enforce IPsec policy checking if we are seeing last header.
1128 * note that we do not visit this with protocols with pcb layer
1129 * code - like udp/tcp/raw ip.
1131 if ((ipsec_bypass
== 0) &&
1132 (ip6_protox
[nxt
]->pr_flags
& PR_LASTHDR
) != 0) {
1133 if (ipsec6_in_reject(m
, NULL
)) {
1134 IPSEC_STAT_INCREMENT(ipsec6stat
.in_polvio
);
1143 if (!TAILQ_EMPTY(&ipv6_filters
) && !IFNET_IS_INTCOPROC(inifp
)) {
1145 TAILQ_FOREACH(filter
, &ipv6_filters
, ipf_link
) {
1147 if ((struct ipfilter
*)inject_ipfref
==
1150 } else if (filter
->ipf_filter
.ipf_input
) {
1153 result
= filter
->ipf_filter
.ipf_input(
1154 filter
->ipf_filter
.cookie
,
1155 (mbuf_t
*)&m
, off
, nxt
);
1156 if (result
== EJUSTRETURN
) {
1169 DTRACE_IP6(receive
, struct mbuf
*, m
, struct inpcb
*, NULL
,
1170 struct ip6_hdr
*, ip6
, struct ifnet
*, inifp
,
1171 struct ip
*, NULL
, struct ip6_hdr
*, ip6
);
1173 if ((pr_input
= ip6_protox
[nxt
]->pr_input
) == NULL
) {
1177 } else if (!(ip6_protox
[nxt
]->pr_flags
& PR_PROTOLOCK
)) {
1178 lck_mtx_lock(inet6_domain_mutex
);
1179 nxt
= pr_input(&m
, &off
, nxt
);
1180 lck_mtx_unlock(inet6_domain_mutex
);
1182 nxt
= pr_input(&m
, &off
, nxt
);
1186 ROUTE_RELEASE(&rin6
);
1194 ip6_setsrcifaddr_info(struct mbuf
*m
, uint32_t src_idx
, struct in6_ifaddr
*ia6
)
1196 VERIFY(m
->m_flags
& M_PKTHDR
);
1199 * If the source ifaddr is specified, pick up the information
1200 * from there; otherwise just grab the passed-in ifindex as the
1201 * caller may not have the ifaddr available.
1204 m
->m_pkthdr
.pkt_flags
|= PKTF_IFAINFO
;
1205 m
->m_pkthdr
.src_ifindex
= ia6
->ia_ifp
->if_index
;
1207 /* See IN6_IFF comments in in6_var.h */
1208 m
->m_pkthdr
.src_iff
= (ia6
->ia6_flags
& 0xffff);
1210 m
->m_pkthdr
.src_iff
= 0;
1211 m
->m_pkthdr
.src_ifindex
= src_idx
;
1213 m
->m_pkthdr
.pkt_flags
|= PKTF_IFAINFO
;
1218 ip6_setdstifaddr_info(struct mbuf
*m
, uint32_t dst_idx
, struct in6_ifaddr
*ia6
)
1220 VERIFY(m
->m_flags
& M_PKTHDR
);
1223 * If the destination ifaddr is specified, pick up the information
1224 * from there; otherwise just grab the passed-in ifindex as the
1225 * caller may not have the ifaddr available.
1228 m
->m_pkthdr
.pkt_flags
|= PKTF_IFAINFO
;
1229 m
->m_pkthdr
.dst_ifindex
= ia6
->ia_ifp
->if_index
;
1231 /* See IN6_IFF comments in in6_var.h */
1232 m
->m_pkthdr
.dst_iff
= (ia6
->ia6_flags
& 0xffff);
1234 m
->m_pkthdr
.dst_iff
= 0;
1235 m
->m_pkthdr
.dst_ifindex
= dst_idx
;
1237 m
->m_pkthdr
.pkt_flags
|= PKTF_IFAINFO
;
1242 ip6_getsrcifaddr_info(struct mbuf
*m
, uint32_t *src_idx
, uint32_t *ia6f
)
1244 VERIFY(m
->m_flags
& M_PKTHDR
);
1246 if (!(m
->m_pkthdr
.pkt_flags
& PKTF_IFAINFO
))
1249 if (src_idx
!= NULL
)
1250 *src_idx
= m
->m_pkthdr
.src_ifindex
;
1253 *ia6f
= m
->m_pkthdr
.src_iff
;
1259 ip6_getdstifaddr_info(struct mbuf
*m
, uint32_t *dst_idx
, uint32_t *ia6f
)
1261 VERIFY(m
->m_flags
& M_PKTHDR
);
1263 if (!(m
->m_pkthdr
.pkt_flags
& PKTF_IFAINFO
))
1266 if (dst_idx
!= NULL
)
1267 *dst_idx
= m
->m_pkthdr
.dst_ifindex
;
1270 *ia6f
= m
->m_pkthdr
.dst_iff
;
1276 * Hop-by-Hop options header processing. If a valid jumbo payload option is
1277 * included, the real payload length will be stored in plenp.
1280 ip6_hopopts_input(uint32_t *plenp
, uint32_t *rtalertp
, struct mbuf
**mp
,
1283 struct mbuf
*m
= *mp
;
1284 int off
= *offp
, hbhlen
;
1285 struct ip6_hbh
*hbh
;
1288 /* validation of the length of the header */
1289 IP6_EXTHDR_CHECK(m
, off
, sizeof (*hbh
), return (-1));
1290 hbh
= (struct ip6_hbh
*)(mtod(m
, caddr_t
) + off
);
1291 hbhlen
= (hbh
->ip6h_len
+ 1) << 3;
1293 IP6_EXTHDR_CHECK(m
, off
, hbhlen
, return (-1));
1294 hbh
= (struct ip6_hbh
*)(mtod(m
, caddr_t
) + off
);
1296 hbhlen
-= sizeof (struct ip6_hbh
);
1297 opt
= (u_int8_t
*)hbh
+ sizeof (struct ip6_hbh
);
1299 if (ip6_process_hopopts(m
, (u_int8_t
*)hbh
+ sizeof (struct ip6_hbh
),
1300 hbhlen
, rtalertp
, plenp
) < 0)
1309 * Search header for all Hop-by-hop options and process each option.
1310 * This function is separate from ip6_hopopts_input() in order to
1311 * handle a case where the sending node itself process its hop-by-hop
1312 * options header. In such a case, the function is called from ip6_output().
1314 * The function assumes that hbh header is located right after the IPv6 header
1315 * (RFC2460 p7), opthead is pointer into data content in m, and opthead to
1316 * opthead + hbhlen is located in continuous memory region.
1319 ip6_process_hopopts(struct mbuf
*m
, u_int8_t
*opthead
, int hbhlen
,
1320 u_int32_t
*rtalertp
, u_int32_t
*plenp
)
1322 struct ip6_hdr
*ip6
;
1324 u_int8_t
*opt
= opthead
;
1325 u_int16_t rtalert_val
;
1326 u_int32_t jumboplen
;
1327 const int erroff
= sizeof (struct ip6_hdr
) + sizeof (struct ip6_hbh
);
1329 for (; hbhlen
> 0; hbhlen
-= optlen
, opt
+= optlen
) {
1335 if (hbhlen
< IP6OPT_MINLEN
) {
1336 ip6stat
.ip6s_toosmall
++;
1339 optlen
= *(opt
+ 1) + 2;
1341 case IP6OPT_ROUTER_ALERT
:
1342 /* XXX may need check for alignment */
1343 if (hbhlen
< IP6OPT_RTALERT_LEN
) {
1344 ip6stat
.ip6s_toosmall
++;
1347 if (*(opt
+ 1) != IP6OPT_RTALERT_LEN
- 2) {
1349 icmp6_error(m
, ICMP6_PARAM_PROB
,
1350 ICMP6_PARAMPROB_HEADER
,
1351 erroff
+ opt
+ 1 - opthead
);
1354 optlen
= IP6OPT_RTALERT_LEN
;
1355 bcopy((caddr_t
)(opt
+ 2), (caddr_t
)&rtalert_val
, 2);
1356 *rtalertp
= ntohs(rtalert_val
);
1359 /* XXX may need check for alignment */
1360 if (hbhlen
< IP6OPT_JUMBO_LEN
) {
1361 ip6stat
.ip6s_toosmall
++;
1364 if (*(opt
+ 1) != IP6OPT_JUMBO_LEN
- 2) {
1366 icmp6_error(m
, ICMP6_PARAM_PROB
,
1367 ICMP6_PARAMPROB_HEADER
,
1368 erroff
+ opt
+ 1 - opthead
);
1371 optlen
= IP6OPT_JUMBO_LEN
;
1374 * IPv6 packets that have non 0 payload length
1375 * must not contain a jumbo payload option.
1377 ip6
= mtod(m
, struct ip6_hdr
*);
1378 if (ip6
->ip6_plen
) {
1379 ip6stat
.ip6s_badoptions
++;
1380 icmp6_error(m
, ICMP6_PARAM_PROB
,
1381 ICMP6_PARAMPROB_HEADER
,
1382 erroff
+ opt
- opthead
);
1387 * We may see jumbolen in unaligned location, so
1388 * we'd need to perform bcopy().
1390 bcopy(opt
+ 2, &jumboplen
, sizeof (jumboplen
));
1391 jumboplen
= (u_int32_t
)htonl(jumboplen
);
1395 * if there are multiple jumbo payload options,
1396 * *plenp will be non-zero and the packet will be
1398 * the behavior may need some debate in ipngwg -
1399 * multiple options does not make sense, however,
1400 * there's no explicit mention in specification.
1403 ip6stat
.ip6s_badoptions
++;
1404 icmp6_error(m
, ICMP6_PARAM_PROB
,
1405 ICMP6_PARAMPROB_HEADER
,
1406 erroff
+ opt
+ 2 - opthead
);
1412 * jumbo payload length must be larger than 65535.
1414 if (jumboplen
<= IPV6_MAXPACKET
) {
1415 ip6stat
.ip6s_badoptions
++;
1416 icmp6_error(m
, ICMP6_PARAM_PROB
,
1417 ICMP6_PARAMPROB_HEADER
,
1418 erroff
+ opt
+ 2 - opthead
);
1424 default: /* unknown option */
1425 if (hbhlen
< IP6OPT_MINLEN
) {
1426 ip6stat
.ip6s_toosmall
++;
1429 optlen
= ip6_unknown_opt(opt
, m
,
1430 erroff
+ opt
- opthead
);
1447 * Unknown option processing.
1448 * The third argument `off' is the offset from the IPv6 header to the option,
1449 * which is necessary if the IPv6 header the and option header and IPv6 header
1450 * is not continuous in order to return an ICMPv6 error.
1453 ip6_unknown_opt(uint8_t *optp
, struct mbuf
*m
, int off
)
1455 struct ip6_hdr
*ip6
;
1457 switch (IP6OPT_TYPE(*optp
)) {
1458 case IP6OPT_TYPE_SKIP
: /* ignore the option */
1459 return ((int)*(optp
+ 1));
1461 case IP6OPT_TYPE_DISCARD
: /* silently discard */
1465 case IP6OPT_TYPE_FORCEICMP
: /* send ICMP even if multicasted */
1466 ip6stat
.ip6s_badoptions
++;
1467 icmp6_error(m
, ICMP6_PARAM_PROB
, ICMP6_PARAMPROB_OPTION
, off
);
1470 case IP6OPT_TYPE_ICMP
: /* send ICMP if not multicasted */
1471 ip6stat
.ip6s_badoptions
++;
1472 ip6
= mtod(m
, struct ip6_hdr
*);
1473 if (IN6_IS_ADDR_MULTICAST(&ip6
->ip6_dst
) ||
1474 (m
->m_flags
& (M_BCAST
|M_MCAST
))) {
1477 icmp6_error(m
, ICMP6_PARAM_PROB
,
1478 ICMP6_PARAMPROB_OPTION
, off
);
1483 m_freem(m
); /* XXX: NOTREACHED */
1488 * Create the "control" list for this pcb.
1489 * These functions will not modify mbuf chain at all.
1491 * With KAME mbuf chain restriction:
1492 * The routine will be called from upper layer handlers like tcp6_input().
1493 * Thus the routine assumes that the caller (tcp6_input) have already
1494 * called IP6_EXTHDR_CHECK() and all the extension headers are located in the
1495 * very first mbuf on the mbuf chain.
1497 * ip6_savecontrol_v4 will handle those options that are possible to be
1498 * set on a v4-mapped socket.
1499 * ip6_savecontrol will directly call ip6_savecontrol_v4 to handle those
1500 * options and handle the v6-only ones itself.
1503 ip6_savecontrol_v4(struct inpcb
*inp
, struct mbuf
*m
, struct mbuf
**mp
,
1506 struct ip6_hdr
*ip6
= mtod(m
, struct ip6_hdr
*);
1508 if ((inp
->inp_socket
->so_options
& SO_TIMESTAMP
) != 0) {
1512 mp
= sbcreatecontrol_mbuf((caddr_t
)&tv
, sizeof (tv
),
1513 SCM_TIMESTAMP
, SOL_SOCKET
, mp
);
1517 if ((inp
->inp_socket
->so_options
& SO_TIMESTAMP_MONOTONIC
) != 0) {
1520 time
= mach_absolute_time();
1521 mp
= sbcreatecontrol_mbuf((caddr_t
)&time
, sizeof (time
),
1522 SCM_TIMESTAMP_MONOTONIC
, SOL_SOCKET
, mp
);
1526 if ((inp
->inp_socket
->so_flags
& SOF_RECV_TRAFFIC_CLASS
) != 0) {
1527 int tc
= m_get_traffic_class(m
);
1529 mp
= sbcreatecontrol_mbuf((caddr_t
)&tc
, sizeof (tc
),
1530 SO_TRAFFIC_CLASS
, SOL_SOCKET
, mp
);
1535 if ((ip6
->ip6_vfc
& IPV6_VERSION_MASK
) != IPV6_VERSION
) {
1541 #define IS2292(inp, x, y) (((inp)->inp_flags & IN6P_RFC2292) ? (x) : (y))
1542 /* RFC 2292 sec. 5 */
1543 if ((inp
->inp_flags
& IN6P_PKTINFO
) != 0) {
1544 struct in6_pktinfo pi6
;
1546 bcopy(&ip6
->ip6_dst
, &pi6
.ipi6_addr
, sizeof (struct in6_addr
));
1547 in6_clearscope(&pi6
.ipi6_addr
); /* XXX */
1549 (m
&& m
->m_pkthdr
.rcvif
) ? m
->m_pkthdr
.rcvif
->if_index
: 0;
1551 mp
= sbcreatecontrol_mbuf((caddr_t
)&pi6
,
1552 sizeof (struct in6_pktinfo
),
1553 IS2292(inp
, IPV6_2292PKTINFO
, IPV6_PKTINFO
),
1559 if ((inp
->inp_flags
& IN6P_HOPLIMIT
) != 0) {
1560 int hlim
= ip6
->ip6_hlim
& 0xff;
1562 mp
= sbcreatecontrol_mbuf((caddr_t
)&hlim
, sizeof (int),
1563 IS2292(inp
, IPV6_2292HOPLIMIT
, IPV6_HOPLIMIT
),
1575 ip6_savecontrol(struct inpcb
*in6p
, struct mbuf
*m
, struct mbuf
**mp
)
1578 struct ip6_hdr
*ip6
= mtod(m
, struct ip6_hdr
*);
1582 np
= ip6_savecontrol_v4(in6p
, m
, mp
, &v4only
);
1590 if ((in6p
->inp_flags
& IN6P_TCLASS
) != 0) {
1594 flowinfo
= (u_int32_t
)ntohl(ip6
->ip6_flow
& IPV6_FLOWINFO_MASK
);
1597 tclass
= flowinfo
& 0xff;
1598 mp
= sbcreatecontrol_mbuf((caddr_t
)&tclass
, sizeof (tclass
),
1599 IPV6_TCLASS
, IPPROTO_IPV6
, mp
);
1605 * IPV6_HOPOPTS socket option. Recall that we required super-user
1606 * privilege for the option (see ip6_ctloutput), but it might be too
1607 * strict, since there might be some hop-by-hop options which can be
1608 * returned to normal user.
1609 * See also RFC 2292 section 6 (or RFC 3542 section 8).
1611 if ((in6p
->inp_flags
& IN6P_HOPOPTS
) != 0) {
1613 * Check if a hop-by-hop options header is contatined in the
1614 * received packet, and if so, store the options as ancillary
1615 * data. Note that a hop-by-hop options header must be
1616 * just after the IPv6 header, which is assured through the
1617 * IPv6 input processing.
1619 ip6
= mtod(m
, struct ip6_hdr
*);
1620 if (ip6
->ip6_nxt
== IPPROTO_HOPOPTS
) {
1621 struct ip6_hbh
*hbh
;
1623 hbh
= (struct ip6_hbh
*)(ip6
+ 1);
1624 hbhlen
= (hbh
->ip6h_len
+ 1) << 3;
1627 * XXX: We copy the whole header even if a
1628 * jumbo payload option is included, the option which
1629 * is to be removed before returning according to
1631 * Note: this constraint is removed in RFC3542
1633 mp
= sbcreatecontrol_mbuf((caddr_t
)hbh
, hbhlen
,
1634 IS2292(in6p
, IPV6_2292HOPOPTS
, IPV6_HOPOPTS
),
1643 if ((in6p
->inp_flags
& (IN6P_RTHDR
| IN6P_DSTOPTS
)) != 0) {
1644 int nxt
= ip6
->ip6_nxt
, off
= sizeof (struct ip6_hdr
);
1647 * Search for destination options headers or routing
1648 * header(s) through the header chain, and stores each
1649 * header as ancillary data.
1650 * Note that the order of the headers remains in
1651 * the chain of ancillary data.
1653 while (1) { /* is explicit loop prevention necessary? */
1654 struct ip6_ext
*ip6e
= NULL
;
1658 * if it is not an extension header, don't try to
1659 * pull it from the chain.
1662 case IPPROTO_DSTOPTS
:
1663 case IPPROTO_ROUTING
:
1664 case IPPROTO_HOPOPTS
:
1665 case IPPROTO_AH
: /* is it possible? */
1671 if (off
+ sizeof (*ip6e
) > m
->m_len
)
1673 ip6e
= (struct ip6_ext
*)(mtod(m
, caddr_t
) + off
);
1674 if (nxt
== IPPROTO_AH
)
1675 elen
= (ip6e
->ip6e_len
+ 2) << 2;
1677 elen
= (ip6e
->ip6e_len
+ 1) << 3;
1678 if (off
+ elen
> m
->m_len
)
1682 case IPPROTO_DSTOPTS
:
1683 if (!(in6p
->inp_flags
& IN6P_DSTOPTS
))
1686 mp
= sbcreatecontrol_mbuf((caddr_t
)ip6e
, elen
,
1687 IS2292(in6p
, IPV6_2292DSTOPTS
,
1688 IPV6_DSTOPTS
), IPPROTO_IPV6
, mp
);
1693 case IPPROTO_ROUTING
:
1694 if (!(in6p
->inp_flags
& IN6P_RTHDR
))
1697 mp
= sbcreatecontrol_mbuf((caddr_t
)ip6e
, elen
,
1698 IS2292(in6p
, IPV6_2292RTHDR
, IPV6_RTHDR
),
1704 case IPPROTO_HOPOPTS
:
1705 case IPPROTO_AH
: /* is it possible? */
1710 * other cases have been filtered in the above.
1711 * none will visit this case. here we supply
1712 * the code just in case (nxt overwritten or
1719 /* proceed with the next header. */
1721 nxt
= ip6e
->ip6e_nxt
;
1729 ip6stat
.ip6s_pktdropcntrl
++;
1730 /* XXX increment a stat to show the failure */
1736 ip6_notify_pmtu(struct inpcb
*in6p
, struct sockaddr_in6
*dst
, u_int32_t
*mtu
)
1740 struct ip6_mtuinfo mtuctl
;
1742 so
= in6p
->inp_socket
;
1748 if (so
== NULL
) { /* I believe this is impossible */
1749 panic("ip6_notify_pmtu: socket is NULL");
1754 bzero(&mtuctl
, sizeof (mtuctl
)); /* zero-clear for safety */
1755 mtuctl
.ip6m_mtu
= *mtu
;
1756 mtuctl
.ip6m_addr
= *dst
;
1757 if (sa6_recoverscope(&mtuctl
.ip6m_addr
, TRUE
))
1760 if ((m_mtu
= sbcreatecontrol((caddr_t
)&mtuctl
, sizeof (mtuctl
),
1761 IPV6_PATHMTU
, IPPROTO_IPV6
)) == NULL
)
1764 if (sbappendaddr(&so
->so_rcv
, SA(dst
), NULL
, m_mtu
, NULL
) == 0) {
1766 /* XXX: should count statistics */
1773 * Get pointer to the previous header followed by the header
1774 * currently processed.
1775 * XXX: This function supposes that
1776 * M includes all headers,
1777 * the next header field and the header length field of each header
1779 * the sum of each header length equals to OFF.
1780 * Because of these assumptions, this function must be called very
1781 * carefully. Moreover, it will not be used in the near future when
1782 * we develop `neater' mechanism to process extension headers.
1785 ip6_get_prevhdr(struct mbuf
*m
, int off
)
1787 struct ip6_hdr
*ip6
= mtod(m
, struct ip6_hdr
*);
1789 if (off
== sizeof (struct ip6_hdr
)) {
1790 return ((char *)&ip6
->ip6_nxt
);
1793 struct ip6_ext
*ip6e
= NULL
;
1796 len
= sizeof (struct ip6_hdr
);
1798 ip6e
= (struct ip6_ext
*)(mtod(m
, caddr_t
) + len
);
1801 case IPPROTO_FRAGMENT
:
1802 len
+= sizeof (struct ip6_frag
);
1805 len
+= (ip6e
->ip6e_len
+ 2) << 2;
1808 len
+= (ip6e
->ip6e_len
+ 1) << 3;
1811 nxt
= ip6e
->ip6e_nxt
;
1814 return ((char *)&ip6e
->ip6e_nxt
);
1821 * get next header offset. m will be retained.
1824 ip6_nexthdr(struct mbuf
*m
, int off
, int proto
, int *nxtp
)
1827 struct ip6_ext ip6e
;
1832 if ((m
->m_flags
& M_PKTHDR
) == 0 || m
->m_pkthdr
.len
< off
)
1837 if (m
->m_pkthdr
.len
< off
+ sizeof (ip6
))
1839 m_copydata(m
, off
, sizeof (ip6
), (caddr_t
)&ip6
);
1841 *nxtp
= ip6
.ip6_nxt
;
1842 off
+= sizeof (ip6
);
1845 case IPPROTO_FRAGMENT
:
1847 * terminate parsing if it is not the first fragment,
1848 * it does not make sense to parse through it.
1850 if (m
->m_pkthdr
.len
< off
+ sizeof (fh
))
1852 m_copydata(m
, off
, sizeof (fh
), (caddr_t
)&fh
);
1853 /* IP6F_OFF_MASK = 0xfff8(BigEndian), 0xf8ff(LittleEndian) */
1854 if (fh
.ip6f_offlg
& IP6F_OFF_MASK
)
1857 *nxtp
= fh
.ip6f_nxt
;
1858 off
+= sizeof (struct ip6_frag
);
1862 if (m
->m_pkthdr
.len
< off
+ sizeof (ip6e
))
1864 m_copydata(m
, off
, sizeof (ip6e
), (caddr_t
)&ip6e
);
1866 *nxtp
= ip6e
.ip6e_nxt
;
1867 off
+= (ip6e
.ip6e_len
+ 2) << 2;
1870 case IPPROTO_HOPOPTS
:
1871 case IPPROTO_ROUTING
:
1872 case IPPROTO_DSTOPTS
:
1873 if (m
->m_pkthdr
.len
< off
+ sizeof (ip6e
))
1875 m_copydata(m
, off
, sizeof (ip6e
), (caddr_t
)&ip6e
);
1877 *nxtp
= ip6e
.ip6e_nxt
;
1878 off
+= (ip6e
.ip6e_len
+ 1) << 3;
1883 case IPPROTO_IPCOMP
:
1893 * get offset for the last header in the chain. m will be kept untainted.
1896 ip6_lasthdr(struct mbuf
*m
, int off
, int proto
, int *nxtp
)
1906 newoff
= ip6_nexthdr(m
, off
, proto
, nxtp
);
1909 else if (newoff
< off
)
1910 return (-1); /* invalid */
1911 else if (newoff
== off
)
1920 ip6_addaux(struct mbuf
*m
)
1924 /* Check if one is already allocated */
1925 tag
= m_tag_locate(m
, KERNEL_MODULE_TAG_ID
,
1926 KERNEL_TAG_TYPE_INET6
, NULL
);
1928 /* Allocate a tag */
1929 tag
= m_tag_create(KERNEL_MODULE_TAG_ID
, KERNEL_TAG_TYPE_INET6
,
1930 sizeof (struct ip6aux
), M_DONTWAIT
, m
);
1932 /* Attach it to the mbuf */
1934 m_tag_prepend(m
, tag
);
1938 return (tag
? (struct ip6aux
*)(tag
+ 1) : NULL
);
1942 ip6_findaux(struct mbuf
*m
)
1946 tag
= m_tag_locate(m
, KERNEL_MODULE_TAG_ID
,
1947 KERNEL_TAG_TYPE_INET6
, NULL
);
1949 return (tag
? (struct ip6aux
*)(tag
+ 1) : NULL
);
1953 ip6_delaux(struct mbuf
*m
)
1957 tag
= m_tag_locate(m
, KERNEL_MODULE_TAG_ID
,
1958 KERNEL_TAG_TYPE_INET6
, NULL
);
1960 m_tag_delete(m
, tag
);
1970 frag6_drain(); /* fragments */
1971 in6_rtqdrain(); /* protocol cloned routes */
1972 nd6_drain(NULL
); /* cloned routes: ND6 */
1976 * System control for IP6
1979 u_char inet6ctlerrmap
[PRC_NCMDS
] = {
1981 0, EMSGSIZE
, EHOSTDOWN
, EHOSTUNREACH
,
1982 EHOSTUNREACH
, EHOSTUNREACH
, ECONNREFUSED
, ECONNREFUSED
,
1983 EMSGSIZE
, EHOSTUNREACH
, 0, 0,
1989 sysctl_reset_ip6_input_stats SYSCTL_HANDLER_ARGS
1991 #pragma unused(arg1, arg2)
1994 i
= ip6_input_measure
;
1995 error
= sysctl_handle_int(oidp
, &i
, 0, req
);
1996 if (error
|| req
->newptr
== USER_ADDR_NULL
)
1999 if (i
< 0 || i
> 1) {
2003 if (ip6_input_measure
!= i
&& i
== 1) {
2004 net_perf_initialize(&net_perf
, ip6_input_measure_bins
);
2006 ip6_input_measure
= i
;
2012 sysctl_ip6_input_measure_bins SYSCTL_HANDLER_ARGS
2014 #pragma unused(arg1, arg2)
2018 i
= ip6_input_measure_bins
;
2019 error
= sysctl_handle_quad(oidp
, &i
, 0, req
);
2020 if (error
|| req
->newptr
== USER_ADDR_NULL
)
2023 if (!net_perf_validate_bins(i
)) {
2027 ip6_input_measure_bins
= i
;
2033 sysctl_ip6_input_getperf SYSCTL_HANDLER_ARGS
2035 #pragma unused(oidp, arg1, arg2)
2036 if (req
->oldptr
== USER_ADDR_NULL
)
2037 req
->oldlen
= (size_t)sizeof (struct ipstat
);
2039 return (SYSCTL_OUT(req
, &net_perf
, MIN(sizeof (net_perf
), req
->oldlen
)));