]> git.saurik.com Git - apple/xnu.git/blame - bsd/netinet6/in6_proto.c
xnu-6153.141.1.tar.gz
[apple/xnu.git] / bsd / netinet6 / in6_proto.c
CommitLineData
b0d623f7 1/*
cb323159 2 * Copyright (c) 2008-2019 Apple Inc. All rights reserved.
b0d623f7
A
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
39236c6e 5 *
b0d623f7
A
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.
39236c6e 14 *
b0d623f7
A
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
39236c6e 17 *
b0d623f7
A
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.
39236c6e 25 *
b0d623f7
A
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28
1c79356b
A
29/*
30 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
31 * All rights reserved.
32 *
33 * Redistribution and use in source and binary forms, with or without
34 * modification, are permitted provided that the following conditions
35 * are met:
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.
44 *
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
55 * SUCH DAMAGE.
56 */
57
58/*
59 * Copyright (c) 1982, 1986, 1993
60 * The Regents of the University of California. All rights reserved.
61 *
62 * Redistribution and use in source and binary forms, with or without
63 * modification, are permitted provided that the following conditions
64 * are met:
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.
77 *
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
88 * SUCH DAMAGE.
89 *
90 * @(#)in_proto.c 8.1 (Berkeley) 6/10/93
91 */
92
1c79356b
A
93
94#include <sys/param.h>
95#include <sys/socket.h>
1c79356b 96#include <sys/socketvar.h>
1c79356b
A
97#include <sys/protosw.h>
98#include <sys/kernel.h>
99#include <sys/domain.h>
100#include <sys/mbuf.h>
1c79356b
A
101#include <sys/systm.h>
102#include <sys/sysctl.h>
1c79356b
A
103
104#include <net/if.h>
105#include <net/radix.h>
106#include <net/route.h>
d9a64523 107#include <net/nat464_utils.h>
1c79356b
A
108
109#include <netinet/in.h>
110#include <netinet/in_systm.h>
111#include <netinet/in_var.h>
112#include <netinet/ip_encap.h>
1c79356b
A
113#include <netinet/ip.h>
114#include <netinet/ip_var.h>
1c79356b
A
115#include <netinet/ip6.h>
116#include <netinet6/ip6_var.h>
39236c6e 117#include <netinet6/in6_var.h>
1c79356b
A
118#include <netinet/icmp6.h>
119
1c79356b
A
120#include <netinet/tcp.h>
121#include <netinet/tcp_timer.h>
122#include <netinet/tcp_var.h>
123#include <netinet/udp.h>
124#include <netinet/udp_var.h>
1c79356b 125#include <netinet6/tcp6_var.h>
9bccf70c 126#include <netinet6/raw_ip6.h>
1c79356b 127#include <netinet6/udp6_var.h>
1c79356b 128#include <netinet6/nd6.h>
6d2010ae 129#include <netinet6/mld6_var.h>
1c79356b
A
130
131#if IPSEC
132#include <netinet6/ipsec.h>
9bccf70c
A
133#if INET6
134#include <netinet6/ipsec6.h>
135#endif
1c79356b 136#include <netinet6/ah.h>
9bccf70c
A
137#if INET6
138#include <netinet6/ah6.h>
139#endif
1c79356b
A
140#if IPSEC_ESP
141#include <netinet6/esp.h>
9bccf70c
A
142#if INET6
143#include <netinet6/esp6.h>
144#endif
1c79356b 145#endif
1c79356b
A
146#endif /*IPSEC*/
147
148#include <netinet6/ip6protosw.h>
1c79356b
A
149
150#include <net/net_osdep.h>
151
1c79356b
A
152/*
153 * TCP/IP protocol family: IP6, ICMP6, UDP, TCP.
154 */
155
39236c6e
A
156extern struct domain inet6domain_s;
157struct domain *inet6domain = NULL;
158
1c79356b 159static struct pr_usrreqs nousrreqs;
91447636 160lck_mtx_t *inet6_domain_mutex;
9bccf70c 161
39236c6e
A
162static void in6_dinit(struct domain *);
163static int rip6_pr_output(struct mbuf *, struct socket *,
164 struct sockaddr_in6 *, struct mbuf *);
55e303ae 165
1c79356b 166struct ip6protosw inet6sw[] = {
0a7de745
A
167 {
168 .pr_type = 0,
169 .pr_protocol = IPPROTO_IPV6,
170 .pr_init = ip6_init,
171 .pr_drain = ip6_drain,
172 .pr_usrreqs = &nousrreqs,
173 },
174 {
175 .pr_type = SOCK_DGRAM,
176 .pr_protocol = IPPROTO_UDP,
177 .pr_flags = PR_ATOMIC | PR_ADDR | PR_PROTOLOCK | PR_PCBLOCK |
178 PR_EVCONNINFO | PR_PRECONN_WRITE,
179 .pr_input = udp6_input,
180 .pr_ctlinput = udp6_ctlinput,
181 .pr_ctloutput = ip6_ctloutput,
182#if !INET /* don't call initialization twice */
183 .pr_init = udp_init,
39236c6e 184#endif /* !INET */
0a7de745
A
185 .pr_usrreqs = &udp6_usrreqs,
186 .pr_lock = udp_lock,
187 .pr_unlock = udp_unlock,
188 .pr_getlock = udp_getlock,
cb323159
A
189 .pr_update_last_owner = inp_update_last_owner,
190 .pr_copy_last_owner = inp_copy_last_owner,
0a7de745
A
191 },
192 {
193 .pr_type = SOCK_STREAM,
194 .pr_protocol = IPPROTO_TCP,
195 .pr_flags = PR_CONNREQUIRED | PR_WANTRCVD | PR_PCBLOCK |
196 PR_PROTOLOCK | PR_DISPOSE | PR_EVCONNINFO |
197 PR_PRECONN_WRITE | PR_DATA_IDEMPOTENT,
198 .pr_input = tcp6_input,
199 .pr_ctlinput = tcp6_ctlinput,
200 .pr_ctloutput = tcp_ctloutput,
201#if !INET /* don't call initialization and timeout routines twice */
202 .pr_init = tcp_init,
39236c6e 203#endif /* !INET */
0a7de745
A
204 .pr_drain = tcp_drain,
205 .pr_usrreqs = &tcp6_usrreqs,
206 .pr_lock = tcp_lock,
207 .pr_unlock = tcp_unlock,
208 .pr_getlock = tcp_getlock,
cb323159
A
209 .pr_update_last_owner = inp_update_last_owner,
210 .pr_copy_last_owner = inp_copy_last_owner,
0a7de745
A
211 },
212 {
213 .pr_type = SOCK_RAW,
214 .pr_protocol = IPPROTO_RAW,
215 .pr_flags = PR_ATOMIC | PR_ADDR,
216 .pr_input = rip6_input,
217 .pr_output = rip6_pr_output,
218 .pr_ctlinput = rip6_ctlinput,
219 .pr_ctloutput = rip6_ctloutput,
220#if !INET /* don't call initialization and timeout routines twice */
221 .pr_init = rip_init,
39236c6e 222#endif /* !INET */
0a7de745
A
223 .pr_usrreqs = &rip6_usrreqs,
224 .pr_unlock = rip_unlock,
cb323159
A
225 .pr_update_last_owner = inp_update_last_owner,
226 .pr_copy_last_owner = inp_copy_last_owner,
0a7de745
A
227 },
228 {
229 .pr_type = SOCK_RAW,
230 .pr_protocol = IPPROTO_ICMPV6,
231 .pr_flags = PR_ATOMIC | PR_ADDR | PR_LASTHDR,
232 .pr_input = icmp6_input,
233 .pr_output = rip6_pr_output,
234 .pr_ctlinput = rip6_ctlinput,
235 .pr_ctloutput = rip6_ctloutput,
236 .pr_init = icmp6_init,
237 .pr_usrreqs = &rip6_usrreqs,
238 .pr_unlock = rip_unlock,
cb323159
A
239 .pr_update_last_owner = inp_update_last_owner,
240 .pr_copy_last_owner = inp_copy_last_owner,
0a7de745
A
241 },
242 {
243 .pr_type = SOCK_DGRAM,
244 .pr_protocol = IPPROTO_ICMPV6,
245 .pr_flags = PR_ATOMIC | PR_ADDR | PR_LASTHDR,
246 .pr_input = icmp6_input,
247 .pr_output = rip6_pr_output,
248 .pr_ctlinput = rip6_ctlinput,
249 .pr_ctloutput = icmp6_dgram_ctloutput,
250 .pr_init = icmp6_init,
251 .pr_usrreqs = &icmp6_dgram_usrreqs,
252 .pr_unlock = rip_unlock,
cb323159
A
253 .pr_update_last_owner = inp_update_last_owner,
254 .pr_copy_last_owner = inp_copy_last_owner,
0a7de745
A
255 },
256 {
257 .pr_type = SOCK_RAW,
258 .pr_protocol = IPPROTO_DSTOPTS,
259 .pr_flags = PR_ATOMIC | PR_ADDR,
260 .pr_input = dest6_input,
261 .pr_usrreqs = &nousrreqs,
262 },
263 {
264 .pr_type = SOCK_RAW,
265 .pr_protocol = IPPROTO_ROUTING,
266 .pr_flags = PR_ATOMIC | PR_ADDR,
267 .pr_input = route6_input,
268 .pr_usrreqs = &nousrreqs,
269 },
270 {
271 .pr_type = SOCK_RAW,
272 .pr_protocol = IPPROTO_FRAGMENT,
273 .pr_flags = PR_ATOMIC | PR_ADDR | PR_PROTOLOCK,
274 .pr_input = frag6_input,
275 .pr_usrreqs = &nousrreqs,
276 },
1c79356b 277#if IPSEC
0a7de745
A
278 {
279 .pr_type = SOCK_RAW,
280 .pr_protocol = IPPROTO_AH,
281 .pr_flags = PR_ATOMIC | PR_ADDR | PR_PROTOLOCK,
282 .pr_input = ah6_input,
283 .pr_usrreqs = &nousrreqs,
284 },
1c79356b 285#if IPSEC_ESP
0a7de745
A
286 {
287 .pr_type = SOCK_RAW,
288 .pr_protocol = IPPROTO_ESP,
289 .pr_flags = PR_ATOMIC | PR_ADDR | PR_PROTOLOCK,
290 .pr_input = esp6_input,
291 .pr_ctlinput = esp6_ctlinput,
292 .pr_usrreqs = &nousrreqs,
293 },
39236c6e 294#endif /* IPSEC_ESP */
1c79356b 295#endif /* IPSEC */
9bccf70c 296#if INET
0a7de745
A
297 {
298 .pr_type = SOCK_RAW,
299 .pr_protocol = IPPROTO_IPV4,
300 .pr_flags = PR_ATOMIC | PR_ADDR | PR_LASTHDR,
301 .pr_input = encap6_input,
302 .pr_output = rip6_pr_output,
303 .pr_ctloutput = rip6_ctloutput,
304 .pr_init = encap6_init,
305 .pr_usrreqs = &rip6_usrreqs,
306 .pr_unlock = rip_unlock,
cb323159
A
307 .pr_update_last_owner = inp_update_last_owner,
308 .pr_copy_last_owner = inp_copy_last_owner,
0a7de745 309 },
9bccf70c 310#endif /*INET*/
0a7de745
A
311 {
312 .pr_type = SOCK_RAW,
313 .pr_protocol = IPPROTO_IPV6,
314 .pr_flags = PR_ATOMIC | PR_ADDR | PR_LASTHDR,
315 .pr_input = encap6_input,
316 .pr_output = rip6_pr_output,
317 .pr_ctloutput = rip6_ctloutput,
318 .pr_init = encap6_init,
319 .pr_usrreqs = &rip6_usrreqs,
320 .pr_unlock = rip_unlock,
cb323159
A
321 .pr_update_last_owner = inp_update_last_owner,
322 .pr_copy_last_owner = inp_copy_last_owner,
0a7de745 323 },
1c79356b 324/* raw wildcard */
0a7de745
A
325 {
326 .pr_type = SOCK_RAW,
327 .pr_protocol = 0,
328 .pr_flags = PR_ATOMIC | PR_ADDR | PR_LASTHDR,
329 .pr_input = rip6_input,
330 .pr_output = rip6_pr_output,
331 .pr_ctloutput = rip6_ctloutput,
332 .pr_usrreqs = &rip6_usrreqs,
333 .pr_unlock = rip_unlock,
cb323159
A
334 .pr_update_last_owner = inp_update_last_owner,
335 .pr_copy_last_owner = inp_copy_last_owner,
0a7de745 336 },
1c79356b
A
337};
338
0a7de745 339int in6_proto_count = (sizeof(inet6sw) / sizeof(struct ip6protosw));
1c79356b 340
39236c6e 341struct domain inet6domain_s = {
0a7de745
A
342 .dom_family = PF_INET6,
343 .dom_flags = DOM_REENTRANT,
344 .dom_name = "internet6",
345 .dom_init = in6_dinit,
346 .dom_rtattach = in6_inithead,
347 .dom_rtoffset = offsetof(struct sockaddr_in6, sin6_addr) << 3,
348 .dom_maxrtkey = sizeof(struct sockaddr_in6),
349 .dom_protohdrlen = sizeof(struct sockaddr_in6),
39236c6e 350};
1c79356b 351
9bccf70c
A
352/* Initialize the PF_INET6 domain, and add in the pre-defined protos */
353void
39236c6e 354in6_dinit(struct domain *dp)
9bccf70c 355{
39236c6e
A
356 struct ip6protosw *pr;
357 int i;
358
359 VERIFY(!(dp->dom_flags & DOM_INITIALIZED));
360 VERIFY(inet6domain == NULL);
361
362 inet6domain = dp;
363
0a7de745 364 _CASSERT(sizeof(struct protosw) == sizeof(struct ip6protosw));
39236c6e
A
365 _CASSERT(offsetof(struct ip6protosw, pr_entry) ==
366 offsetof(struct protosw, pr_entry));
367 _CASSERT(offsetof(struct ip6protosw, pr_domain) ==
368 offsetof(struct protosw, pr_domain));
369 _CASSERT(offsetof(struct ip6protosw, pr_protosw) ==
370 offsetof(struct protosw, pr_protosw));
371 _CASSERT(offsetof(struct ip6protosw, pr_type) ==
372 offsetof(struct protosw, pr_type));
373 _CASSERT(offsetof(struct ip6protosw, pr_protocol) ==
374 offsetof(struct protosw, pr_protocol));
375 _CASSERT(offsetof(struct ip6protosw, pr_flags) ==
376 offsetof(struct protosw, pr_flags));
377 _CASSERT(offsetof(struct ip6protosw, pr_input) ==
378 offsetof(struct protosw, pr_input));
379 _CASSERT(offsetof(struct ip6protosw, pr_output) ==
380 offsetof(struct protosw, pr_output));
381 _CASSERT(offsetof(struct ip6protosw, pr_ctlinput) ==
382 offsetof(struct protosw, pr_ctlinput));
383 _CASSERT(offsetof(struct ip6protosw, pr_ctloutput) ==
384 offsetof(struct protosw, pr_ctloutput));
385 _CASSERT(offsetof(struct ip6protosw, pr_usrreqs) ==
386 offsetof(struct protosw, pr_usrreqs));
387 _CASSERT(offsetof(struct ip6protosw, pr_init) ==
388 offsetof(struct protosw, pr_init));
389 _CASSERT(offsetof(struct ip6protosw, pr_drain) ==
390 offsetof(struct protosw, pr_drain));
391 _CASSERT(offsetof(struct ip6protosw, pr_sysctl) ==
392 offsetof(struct protosw, pr_sysctl));
393 _CASSERT(offsetof(struct ip6protosw, pr_lock) ==
394 offsetof(struct protosw, pr_lock));
395 _CASSERT(offsetof(struct ip6protosw, pr_unlock) ==
396 offsetof(struct protosw, pr_unlock));
397 _CASSERT(offsetof(struct ip6protosw, pr_getlock) ==
398 offsetof(struct protosw, pr_getlock));
399 _CASSERT(offsetof(struct ip6protosw, pr_filter_head) ==
400 offsetof(struct protosw, pr_filter_head));
401 _CASSERT(offsetof(struct ip6protosw, pr_old) ==
402 offsetof(struct protosw, pr_old));
cb323159
A
403 _CASSERT(offsetof(struct ip6protosw, pr_update_last_owner) ==
404 offsetof(struct protosw, pr_update_last_owner));
405 _CASSERT(offsetof(struct ip6protosw, pr_copy_last_owner) ==
406 offsetof(struct protosw, pr_copy_last_owner));
39236c6e
A
407
408 /*
409 * Attach first, then initialize. ip6_init() needs raw IP6 handler.
410 */
0a7de745 411 for (i = 0, pr = &inet6sw[0]; i < in6_proto_count; i++, pr++) {
39236c6e 412 net_add_proto((struct protosw *)pr, dp, 0);
0a7de745
A
413 }
414 for (i = 0, pr = &inet6sw[0]; i < in6_proto_count; i++, pr++) {
39236c6e 415 net_init_proto((struct protosw *)pr, dp);
0a7de745 416 }
39236c6e
A
417
418 inet6_domain_mutex = dp->dom_mtx;
9bccf70c
A
419}
420
39236c6e
A
421static int
422rip6_pr_output(struct mbuf *m, struct socket *so, struct sockaddr_in6 *sin6,
423 struct mbuf *m1)
55e303ae 424{
39236c6e
A
425#pragma unused(m, so, sin6, m1)
426 panic("%s\n", __func__);
427 /* NOTREACHED */
0a7de745 428 return 0;
55e303ae 429}
9bccf70c 430
1c79356b
A
431/*
432 * Internet configuration info
433 */
0a7de745 434#ifndef IPV6FORWARDING
1c79356b 435#if GATEWAY6
0a7de745 436#define IPV6FORWARDING 1 /* forward IP6 packets not for us */
1c79356b 437#else
0a7de745 438#define IPV6FORWARDING 0 /* don't forward IP6 packets not for us */
1c79356b
A
439#endif /* GATEWAY6 */
440#endif /* !IPV6FORWARDING */
441
0a7de745
A
442#ifndef IPV6_SENDREDIRECTS
443#define IPV6_SENDREDIRECTS 1
1c79356b
A
444#endif
445
0a7de745
A
446int ip6_forwarding = IPV6FORWARDING; /* act as router? */
447int ip6_sendredirects = IPV6_SENDREDIRECTS;
448int ip6_defhlim = IPV6_DEFHLIM;
449int ip6_defmcasthlim = IPV6_DEFAULT_MULTICAST_HOPS;
450int ip6_accept_rtadv = 1; /* deprecated */
451int ip6_log_interval = 5;
452int ip6_hdrnestlimit = 15; /* How many header options will we process? */
453int ip6_dad_count = 1; /* DupAddrDetectionTransmits */
454int ip6_auto_flowlabel = 1;
455int ip6_gif_hlim = 0;
456int ip6_use_deprecated = 1; /* allow deprecated addr [RFC 4862, 5.5.4] */
457int ip6_rr_prune = 5; /* router renumbering prefix
458 * walk list every 5 sec. */
459int ip6_mcast_pmtu = 0; /* enable pMTU discovery for multicast? */
460int ip6_v6only = 0; /* Mapped addresses off by default - Radar 3347718 -- REVISITING FOR 10.7 -- TESTING WITH MAPPED@ OFF */
461
462int ip6_neighborgcthresh = 1024; /* Threshold # of NDP entries for GC */
463int ip6_maxifprefixes = 16; /* Max acceptable prefixes via RA per IF */
464int ip6_maxifdefrouters = 16; /* Max acceptable def routers via RA */
465int ip6_maxdynroutes = 1024; /* Max # of routes created via redirect */
466int ip6_only_allow_rfc4193_prefix = 0; /* Only allow RFC4193 style Unique Local IPv6 Unicast prefixes */
e2fac8b1 467
316670eb 468static int ip6_keepfaith = 0;
39236c6e 469uint64_t ip6_log_time = 0;
0a7de745 470int nd6_onlink_ns_rfc4861 = 0; /* allow 'on-link' nd6 NS (as in RFC 4861) */
1c79356b
A
471
472/* icmp6 */
1c79356b
A
473/*
474 * BSDI4 defines these variables in in_proto.c...
475 * XXX: what if we don't define INET? Should we define pmtu6_expire
476 * or so? (jinmei@kame.net 19990310)
477 */
0a7de745
A
478int pmtu_expire = 60 * 10;
479int pmtu_probe = 60 * 2;
1c79356b
A
480
481/* raw IP6 parameters */
482/*
483 * Nominal space allocated to a raw ip socket.
484 */
0a7de745
A
485#define RIPV6SNDQ 8192
486#define RIPV6RCVQ 8192
1c79356b 487
0a7de745
A
488u_int32_t rip6_sendspace = RIPV6SNDQ;
489u_int32_t rip6_recvspace = RIPV6RCVQ;
1c79356b
A
490
491/* ICMPV6 parameters */
0a7de745
A
492int icmp6_rediraccept = 1; /* accept and process redirects */
493int icmp6_redirtimeout = 10 * 60; /* 10 minutes */
494int icmp6errppslim = 500; /* 500 packets per second */
495int icmp6rappslim = 10; /* 10 packets per second */
496int icmp6_nodeinfo = 3; /* enable/disable NI response */
1c79356b 497
1c79356b 498/* UDP on IP6 parameters */
0a7de745
A
499int udp6_sendspace = 9216; /* really max datagram size */
500int udp6_recvspace = 40 * (1024 + sizeof(struct sockaddr_in6));
501/* 40 1K datagrams */
1c79356b 502
1c79356b
A
503/*
504 * sysctl related items.
505 */
39236c6e 506SYSCTL_NODE(_net, PF_INET6, inet6,
0a7de745 507 CTLFLAG_RW | CTLFLAG_LOCKED, 0, "Internet6 Family");
1c79356b
A
508
509/* net.inet6 */
0a7de745
A
510SYSCTL_NODE(_net_inet6, IPPROTO_IPV6, ip6,
511 CTLFLAG_RW | CTLFLAG_LOCKED, 0, "IP6");
512SYSCTL_NODE(_net_inet6, IPPROTO_ICMPV6, icmp6,
513 CTLFLAG_RW | CTLFLAG_LOCKED, 0, "ICMP6");
514SYSCTL_NODE(_net_inet6, IPPROTO_UDP, udp6,
515 CTLFLAG_RW | CTLFLAG_LOCKED, 0, "UDP6");
516SYSCTL_NODE(_net_inet6, IPPROTO_TCP, tcp6,
517 CTLFLAG_RW | CTLFLAG_LOCKED, 0, "TCP6");
1c79356b 518#if IPSEC
0a7de745
A
519SYSCTL_NODE(_net_inet6, IPPROTO_ESP, ipsec6,
520 CTLFLAG_RW | CTLFLAG_LOCKED, 0, "IPSEC6");
1c79356b
A
521#endif /* IPSEC */
522
523/* net.inet6.ip6 */
524static int
9bccf70c 525sysctl_ip6_temppltime SYSCTL_HANDLER_ARGS
1c79356b 526{
b0d623f7 527#pragma unused(oidp, arg2)
1c79356b 528 int error = 0;
9bccf70c 529 int old;
1c79356b
A
530
531 error = SYSCTL_OUT(req, arg1, sizeof(int));
0a7de745
A
532 if (error || !req->newptr) {
533 return error;
534 }
9bccf70c 535 old = ip6_temp_preferred_lifetime;
1c79356b 536 error = SYSCTL_IN(req, arg1, sizeof(int));
6d2010ae
A
537 if (ip6_temp_preferred_lifetime > ND6_MAX_LIFETIME ||
538 ip6_temp_preferred_lifetime <
9bccf70c
A
539 ip6_desync_factor + ip6_temp_regen_advance) {
540 ip6_temp_preferred_lifetime = old;
0a7de745 541 return EINVAL;
1c79356b 542 }
0a7de745 543 return error;
9bccf70c 544}
1c79356b 545
9bccf70c
A
546static int
547sysctl_ip6_tempvltime SYSCTL_HANDLER_ARGS
548{
b0d623f7 549#pragma unused(oidp, arg2)
9bccf70c
A
550 int error = 0;
551 int old;
552
553 error = SYSCTL_OUT(req, arg1, sizeof(int));
0a7de745
A
554 if (error || !req->newptr) {
555 return error;
556 }
9bccf70c
A
557 old = ip6_temp_valid_lifetime;
558 error = SYSCTL_IN(req, arg1, sizeof(int));
6d2010ae
A
559 if (ip6_temp_valid_lifetime > ND6_MAX_LIFETIME ||
560 ip6_temp_valid_lifetime < ip6_temp_preferred_lifetime) {
39236c6e 561 ip6_temp_valid_lifetime = old;
0a7de745 562 return EINVAL;
9bccf70c 563 }
0a7de745 564 return error;
39236c6e
A
565}
566
567static int
568ip6_getstat SYSCTL_HANDLER_ARGS
569{
570#pragma unused(oidp, arg1, arg2)
0a7de745
A
571 if (req->oldptr == USER_ADDR_NULL) {
572 req->oldlen = (size_t)sizeof(struct ip6stat);
573 }
39236c6e 574
0a7de745 575 return SYSCTL_OUT(req, &ip6stat, MIN(sizeof(ip6stat), req->oldlen));
1c79356b
A
576}
577
9bccf70c 578SYSCTL_INT(_net_inet6_ip6, IPV6CTL_FORWARDING,
0a7de745 579 forwarding, CTLFLAG_RW | CTLFLAG_LOCKED, &ip6_forwarding, 0, "");
1c79356b 580SYSCTL_INT(_net_inet6_ip6, IPV6CTL_SENDREDIRECTS,
0a7de745 581 redirect, CTLFLAG_RW | CTLFLAG_LOCKED, &ip6_sendredirects, 0, "");
1c79356b 582SYSCTL_INT(_net_inet6_ip6, IPV6CTL_DEFHLIM,
0a7de745 583 hlim, CTLFLAG_RW | CTLFLAG_LOCKED, &ip6_defhlim, 0, "");
fe8ab488 584SYSCTL_PROC(_net_inet6_ip6, IPV6CTL_STATS, stats,
0a7de745
A
585 CTLTYPE_STRUCT | CTLFLAG_RD | CTLFLAG_LOCKED,
586 0, 0, ip6_getstat, "S,ip6stat", "");
5ba3f43e
A
587
588#if (DEVELOPMENT || DEBUG)
589SYSCTL_INT(_net_inet6_ip6, IPV6CTL_ACCEPT_RTADV,
0a7de745
A
590 accept_rtadv, CTLFLAG_RW | CTLFLAG_LOCKED,
591 &ip6_accept_rtadv, 0, "");
5ba3f43e 592#else
1c79356b 593SYSCTL_INT(_net_inet6_ip6, IPV6CTL_ACCEPT_RTADV,
0a7de745
A
594 accept_rtadv, CTLFLAG_RD | CTLFLAG_LOCKED,
595 &ip6_accept_rtadv, 0, "");
5ba3f43e 596#endif /* (DEVELOPMENT || DEBUG) */
1c79356b 597SYSCTL_INT(_net_inet6_ip6, IPV6CTL_KEEPFAITH,
0a7de745 598 keepfaith, CTLFLAG_RD | CTLFLAG_LOCKED, &ip6_keepfaith, 0, "");
1c79356b 599SYSCTL_INT(_net_inet6_ip6, IPV6CTL_LOG_INTERVAL,
0a7de745 600 log_interval, CTLFLAG_RW | CTLFLAG_LOCKED, &ip6_log_interval, 0, "");
1c79356b 601SYSCTL_INT(_net_inet6_ip6, IPV6CTL_HDRNESTLIMIT,
0a7de745 602 hdrnestlimit, CTLFLAG_RW | CTLFLAG_LOCKED, &ip6_hdrnestlimit, 0, "");
1c79356b 603SYSCTL_INT(_net_inet6_ip6, IPV6CTL_DAD_COUNT,
0a7de745 604 dad_count, CTLFLAG_RW | CTLFLAG_LOCKED, &ip6_dad_count, 0, "");
1c79356b 605SYSCTL_INT(_net_inet6_ip6, IPV6CTL_AUTO_FLOWLABEL,
0a7de745 606 auto_flowlabel, CTLFLAG_RW | CTLFLAG_LOCKED, &ip6_auto_flowlabel, 0, "");
1c79356b 607SYSCTL_INT(_net_inet6_ip6, IPV6CTL_DEFMCASTHLIM,
0a7de745 608 defmcasthlim, CTLFLAG_RW | CTLFLAG_LOCKED, &ip6_defmcasthlim, 0, "");
1c79356b 609SYSCTL_INT(_net_inet6_ip6, IPV6CTL_GIF_HLIM,
0a7de745 610 gifhlim, CTLFLAG_RW | CTLFLAG_LOCKED, &ip6_gif_hlim, 0, "");
1c79356b 611SYSCTL_STRING(_net_inet6_ip6, IPV6CTL_KAME_VERSION,
0a7de745 612 kame_version, CTLFLAG_RD | CTLFLAG_LOCKED, (void *)((uintptr_t)(__KAME_VERSION)), 0, "");
1c79356b 613SYSCTL_INT(_net_inet6_ip6, IPV6CTL_USE_DEPRECATED,
0a7de745 614 use_deprecated, CTLFLAG_RW | CTLFLAG_LOCKED, &ip6_use_deprecated, 0, "");
1c79356b 615SYSCTL_INT(_net_inet6_ip6, IPV6CTL_RR_PRUNE,
0a7de745 616 rr_prune, CTLFLAG_RW | CTLFLAG_LOCKED, &ip6_rr_prune, 0, "");
9bccf70c 617SYSCTL_INT(_net_inet6_ip6, IPV6CTL_USETEMPADDR,
0a7de745 618 use_tempaddr, CTLFLAG_RW | CTLFLAG_LOCKED, &ip6_use_tempaddr, 0, "");
9bccf70c 619SYSCTL_OID(_net_inet6_ip6, IPV6CTL_TEMPPLTIME, temppltime,
0a7de745
A
620 CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_LOCKED, &ip6_temp_preferred_lifetime, 0,
621 sysctl_ip6_temppltime, "I", "");
9bccf70c 622SYSCTL_OID(_net_inet6_ip6, IPV6CTL_TEMPVLTIME, tempvltime,
0a7de745
A
623 CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_LOCKED, &ip6_temp_valid_lifetime, 0,
624 sysctl_ip6_tempvltime, "I", "");
9bccf70c 625SYSCTL_INT(_net_inet6_ip6, IPV6CTL_V6ONLY,
0a7de745 626 v6only, CTLFLAG_RW | CTLFLAG_LOCKED, &ip6_v6only, 0, "");
9bccf70c 627SYSCTL_INT(_net_inet6_ip6, IPV6CTL_AUTO_LINKLOCAL,
0a7de745 628 auto_linklocal, CTLFLAG_RW | CTLFLAG_LOCKED, &ip6_auto_linklocal, 0, "");
6d2010ae 629SYSCTL_STRUCT(_net_inet6_ip6, IPV6CTL_RIP6STATS, rip6stats, CTLFLAG_RD | CTLFLAG_LOCKED,
0a7de745 630 &rip6stat, rip6stat, "");
6d2010ae 631SYSCTL_INT(_net_inet6_ip6, IPV6CTL_PREFER_TEMPADDR,
0a7de745 632 prefer_tempaddr, CTLFLAG_RW | CTLFLAG_LOCKED, &ip6_prefer_tempaddr, 0, "");
6d2010ae 633SYSCTL_INT(_net_inet6_ip6, IPV6CTL_USE_DEFAULTZONE,
0a7de745 634 use_defaultzone, CTLFLAG_RW | CTLFLAG_LOCKED, &ip6_use_defzone, 0, "");
6d2010ae 635SYSCTL_INT(_net_inet6_ip6, IPV6CTL_MCAST_PMTU,
0a7de745 636 mcast_pmtu, CTLFLAG_RW | CTLFLAG_LOCKED, &ip6_mcast_pmtu, 0, "");
e2fac8b1 637SYSCTL_INT(_net_inet6_ip6, IPV6CTL_NEIGHBORGCTHRESH,
0a7de745 638 neighborgcthresh, CTLFLAG_RW | CTLFLAG_LOCKED, &ip6_neighborgcthresh, 0, "");
e2fac8b1 639SYSCTL_INT(_net_inet6_ip6, IPV6CTL_MAXIFPREFIXES,
0a7de745 640 maxifprefixes, CTLFLAG_RW | CTLFLAG_LOCKED, &ip6_maxifprefixes, 0, "");
e2fac8b1 641SYSCTL_INT(_net_inet6_ip6, IPV6CTL_MAXIFDEFROUTERS,
0a7de745 642 maxifdefrouters, CTLFLAG_RW | CTLFLAG_LOCKED, &ip6_maxifdefrouters, 0, "");
e2fac8b1 643SYSCTL_INT(_net_inet6_ip6, IPV6CTL_MAXDYNROUTES,
0a7de745 644 maxdynroutes, CTLFLAG_RW | CTLFLAG_LOCKED, &ip6_maxdynroutes, 0, "");
6d2010ae 645SYSCTL_INT(_net_inet6_ip6, OID_AUTO,
0a7de745
A
646 only_allow_rfc4193_prefixes, CTLFLAG_RW | CTLFLAG_LOCKED,
647 &ip6_only_allow_rfc4193_prefix, 0, "");
d9a64523 648SYSCTL_INT(_net_inet6_ip6, OID_AUTO,
0a7de745 649 clat_debug, CTLFLAG_RW | CTLFLAG_LOCKED, &clat_debug, 0, "");
1c79356b
A
650
651/* net.inet6.icmp6 */
652SYSCTL_INT(_net_inet6_icmp6, ICMPV6CTL_REDIRACCEPT,
0a7de745 653 rediraccept, CTLFLAG_RW | CTLFLAG_LOCKED, &icmp6_rediraccept, 0, "");
1c79356b 654SYSCTL_INT(_net_inet6_icmp6, ICMPV6CTL_REDIRTIMEOUT,
0a7de745 655 redirtimeout, CTLFLAG_RW | CTLFLAG_LOCKED, &icmp6_redirtimeout, 0, "");
6d2010ae 656SYSCTL_STRUCT(_net_inet6_icmp6, ICMPV6CTL_STATS, stats, CTLFLAG_RD | CTLFLAG_LOCKED,
0a7de745 657 &icmp6stat, icmp6stat, "");
1c79356b 658SYSCTL_INT(_net_inet6_icmp6, ICMPV6CTL_ND6_PRUNE,
0a7de745 659 nd6_prune, CTLFLAG_RW | CTLFLAG_LOCKED, &nd6_prune, 0, "");
39236c6e 660SYSCTL_INT(_net_inet6_icmp6, OID_AUTO,
0a7de745 661 nd6_prune_lazy, CTLFLAG_RW | CTLFLAG_LOCKED, &nd6_prune_lazy, 0, "");
1c79356b 662SYSCTL_INT(_net_inet6_icmp6, ICMPV6CTL_ND6_DELAY,
0a7de745 663 nd6_delay, CTLFLAG_RW | CTLFLAG_LOCKED, &nd6_delay, 0, "");
1c79356b 664SYSCTL_INT(_net_inet6_icmp6, ICMPV6CTL_ND6_UMAXTRIES,
0a7de745 665 nd6_umaxtries, CTLFLAG_RW | CTLFLAG_LOCKED, &nd6_umaxtries, 0, "");
1c79356b 666SYSCTL_INT(_net_inet6_icmp6, ICMPV6CTL_ND6_MMAXTRIES,
0a7de745 667 nd6_mmaxtries, CTLFLAG_RW | CTLFLAG_LOCKED, &nd6_mmaxtries, 0, "");
1c79356b 668SYSCTL_INT(_net_inet6_icmp6, ICMPV6CTL_ND6_USELOOPBACK,
0a7de745 669 nd6_useloopback, CTLFLAG_RW | CTLFLAG_LOCKED, &nd6_useloopback, 0, "");
6d2010ae 670SYSCTL_INT(_net_inet6_icmp6, ICMPV6CTL_ND6_ACCEPT_6TO4,
0a7de745 671 nd6_accept_6to4, CTLFLAG_RW | CTLFLAG_LOCKED, &nd6_accept_6to4, 0, "");
1c79356b 672SYSCTL_INT(_net_inet6_icmp6, ICMPV6CTL_NODEINFO,
0a7de745 673 nodeinfo, CTLFLAG_RW | CTLFLAG_LOCKED, &icmp6_nodeinfo, 0, "");
9bccf70c 674SYSCTL_INT(_net_inet6_icmp6, ICMPV6CTL_ERRPPSLIMIT,
0a7de745 675 errppslimit, CTLFLAG_RW | CTLFLAG_LOCKED, &icmp6errppslim, 0, "");
fe8ab488 676SYSCTL_INT(_net_inet6_icmp6, OID_AUTO,
0a7de745 677 rappslimit, CTLFLAG_RW | CTLFLAG_LOCKED, &icmp6rappslim, 0, "");
9bccf70c 678SYSCTL_INT(_net_inet6_icmp6, ICMPV6CTL_ND6_DEBUG,
0a7de745 679 nd6_debug, CTLFLAG_RW | CTLFLAG_LOCKED, &nd6_debug, 0, "");
6d2010ae 680SYSCTL_INT(_net_inet6_icmp6, ICMPV6CTL_ND6_ONLINKNSRFC4861,
0a7de745
A
681 nd6_onlink_ns_rfc4861, CTLFLAG_RW | CTLFLAG_LOCKED, &nd6_onlink_ns_rfc4861, 0,
682 "Accept 'on-link' nd6 NS in compliance with RFC 4861.");
316670eb 683SYSCTL_INT(_net_inet6_icmp6, ICMPV6CTL_ND6_OPTIMISTIC_DAD,
0a7de745 684 nd6_optimistic_dad, CTLFLAG_RW | CTLFLAG_LOCKED, &nd6_optimistic_dad, 0, "");