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