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