in6_proto.c revision 1.1.2.3 1 /*
2 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the project nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29
30 /*
31 * Copyright (c) 1982, 1986, 1993
32 * The Regents of the University of California. All rights reserved.
33 *
34 * Redistribution and use in source and binary forms, with or without
35 * modification, are permitted provided that the following conditions
36 * are met:
37 * 1. Redistributions of source code must retain the above copyright
38 * notice, this list of conditions and the following disclaimer.
39 * 2. Redistributions in binary form must reproduce the above copyright
40 * notice, this list of conditions and the following disclaimer in the
41 * documentation and/or other materials provided with the distribution.
42 * 3. All advertising materials mentioning features or use of this software
43 * must display the following acknowledgement:
44 * This product includes software developed by the University of
45 * California, Berkeley and its contributors.
46 * 4. Neither the name of the University nor the names of its contributors
47 * may be used to endorse or promote products derived from this software
48 * without specific prior written permission.
49 *
50 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
51 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
52 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
53 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
54 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
55 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
56 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
57 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
58 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
59 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
60 * SUCH DAMAGE.
61 *
62 * @(#)in_proto.c 8.1 (Berkeley) 6/10/93
63 */
64
65 #if (defined(__FreeBSD__) && __FreeBSD__ >= 3) || defined(__NetBSD__)
66 #include "opt_inet.h"
67 #ifdef __NetBSD__ /*XXX*/
68 #include "opt_ipsec.h"
69 #endif
70 #endif
71
72 #include <sys/param.h>
73 #include <sys/socket.h>
74 #if defined(__FreeBSD__)
75 #include <sys/socketvar.h>
76 #endif
77 #include <sys/protosw.h>
78 #include <sys/kernel.h>
79 #include <sys/domain.h>
80 #include <sys/mbuf.h>
81 #ifdef __FreeBSD__
82 #include <sys/systm.h>
83 #include <sys/sysctl.h>
84 #endif
85
86 #include <net/if.h>
87 #include <net/radix.h>
88 #include <net/route.h>
89
90 #include <netinet/in.h>
91 #include <netinet/in_systm.h>
92 #include <netinet/in_var.h>
93 #if (defined(__FreeBSD__) && __FreeBSD__ >= 3) || (defined(__NetBSD__) && !defined(TCP6)) || defined(__OpenBSD__) || (defined(__bsdi__) && _BSDI_VERSION >= 199802)
94 #include <netinet/ip.h>
95 #include <netinet/ip_var.h>
96 #endif
97 #if (defined(__NetBSD__) && !defined(TCP6)) || defined(__OpenBSD__) || (defined(__bsdi__) && _BSDI_VERSION >= 199802)
98 #include <netinet/in_pcb.h>
99 #endif
100 #include <netinet6/ip6.h>
101 #include <netinet6/ip6_var.h>
102 #include <netinet6/icmp6.h>
103 #if !(defined(__FreeBSD__) && __FreeBSD__ >= 3) && !defined(__OpenBSD__) && !(defined(__bsdi__) && _BSDI_VERSION >= 199802)
104 #include <netinet6/in6_pcb.h>
105 #endif
106
107 #if (defined(__FreeBSD__) && __FreeBSD__ >= 3) || defined(__OpenBSD__) || (defined(__bsdi__) && _BSDI_VERSION >= 199802)
108 #include <netinet/tcp.h>
109 #include <netinet/tcp_timer.h>
110 #include <netinet/tcp_var.h>
111 #include <netinet/udp.h>
112 #include <netinet/udp_var.h>
113 #else
114 #if defined(__NetBSD__) && !defined(TCP6)
115 #include <netinet/tcp.h>
116 #include <netinet/tcp_fsm.h>
117 #include <netinet/tcp_seq.h>
118 #include <netinet/tcp_timer.h>
119 #include <netinet/tcp_var.h>
120 #include <netinet/tcpip.h>
121 #include <netinet/tcp_debug.h>
122 #else
123 #include <netinet6/tcp6.h>
124 #include <netinet6/tcp6_fsm.h>
125 #include <netinet6/tcp6_seq.h>
126 #include <netinet6/tcp6_timer.h>
127 #include <netinet6/tcp6_var.h>
128 #endif
129 #endif
130
131 #if !defined(__OpenBSD__) && !(defined(__bsdi__) && _BSDI_VERSION >= 199802)
132 #include <netinet6/udp6.h>
133 #include <netinet6/udp6_var.h>
134 #endif
135
136 #include <netinet6/pim6_var.h>
137
138 #include <netinet6/nd6.h>
139 #ifdef __FreeBSD__
140 #include <netinet6/in6_prefix.h>
141 #endif
142
143 #ifdef __OpenBSD__ /*KAME IPSEC*/
144 #undef IPSEC
145 #endif
146
147 #ifdef IPSEC
148 #include <netinet6/ipsec.h>
149 #include <netinet6/ah.h>
150 #ifdef IPSEC_ESP
151 #include <netinet6/esp.h>
152 #endif
153 #include <netinet6/ipcomp.h>
154 #endif /*IPSEC*/
155
156 #include <netinet6/ip6protosw.h>
157
158 #include "gif.h"
159 #if NGIF > 0
160 #include <netinet6/in6_gif.h>
161 #endif
162
163 #include <net/net_osdep.h>
164
165 #define offsetof(type, member) ((size_t)(&((type *)0)->member))
166
167 /*
168 * TCP/IP protocol family: IP6, ICMP6, UDP, TCP.
169 */
170
171 extern struct domain inet6domain;
172 #if defined(__FreeBSD__) && __FreeBSD__ >= 3
173 static struct pr_usrreqs nousrreqs;
174 #endif
175
176 struct ip6protosw inet6sw[] = {
177 { 0, &inet6domain, IPPROTO_IPV6, 0,
178 0, 0, 0, 0,
179 0,
180 ip6_init, 0, frag6_slowtimo, frag6_drain,
181 #ifndef __FreeBSD__
182 ip6_sysctl,
183 #else
184 # if __FreeBSD__ >= 3
185 &nousrreqs,
186 # endif
187 #endif
188 },
189 { SOCK_DGRAM, &inet6domain, IPPROTO_UDP, PR_ATOMIC | PR_ADDR,
190 udp6_input, 0, udp6_ctlinput, ip6_ctloutput,
191 #if defined(__FreeBSD__) && __FreeBSD__ >= 3
192 0, 0,
193 #elif defined(HAVE_NRL_INPCB)
194 udp6_usrreq, 0,
195 #else
196 udp6_usrreq, udp6_init,
197 #endif
198 0, 0, 0,
199 #ifndef __FreeBSD__
200 #ifdef HAVE_NRL_INPCB
201 udp_sysctl,
202 #else
203 udp6_sysctl,
204 #endif
205 #else
206 # if __FreeBSD__ >= 3
207 &udp6_usrreqs,
208 # endif
209 #endif
210 },
211 #ifdef TCP6
212 { SOCK_STREAM, &inet6domain, IPPROTO_TCP, PR_CONNREQUIRED | PR_WANTRCVD,
213 tcp6_input, 0, tcp6_ctlinput, tcp6_ctloutput,
214 tcp6_usrreq,
215 tcp6_init, tcp6_fasttimo, tcp6_slowtimo, tcp6_drain,
216 #ifndef __FreeBSD__
217 tcp6_sysctl,
218 #else
219 # if __FreeBSD__ >= 3
220 &tcp6_usrreqs,
221 # endif
222 #endif
223 },
224 #else
225 { SOCK_STREAM, &inet6domain, IPPROTO_TCP, PR_CONNREQUIRED | PR_WANTRCVD,
226 tcp6_input, 0, tcp6_ctlinput, tcp_ctloutput,
227 #if defined(__FreeBSD__) && __FreeBSD__ >= 3
228 0,
229 #elif defined(HAVE_NRL_INPCB)
230 tcp6_usrreq,
231 #else
232 tcp_usrreq,
233 #endif
234 #ifdef INET /* don't call timeout routines twice */
235 tcp_init, 0, 0, tcp_drain,
236 #else
237 tcp_init, tcp_fasttimo, tcp_slowtimo, tcp_drain,
238 #endif
239 #ifndef __FreeBSD__
240 tcp_sysctl,
241 #else
242 # if __FreeBSD__ >= 3
243 &tcp6_usrreqs,
244 # endif
245 #endif
246 },
247 #endif /*TCP6*/
248 { SOCK_RAW, &inet6domain, IPPROTO_RAW, PR_ATOMIC | PR_ADDR,
249 rip6_input, rip6_output, 0, rip6_ctloutput,
250 #if defined(__FreeBSD__) && __FreeBSD__ >= 3
251 0,
252 #else
253 rip6_usrreq,
254 #endif
255 0, 0, 0, 0,
256 #if defined(__FreeBSD__) && __FreeBSD__ >= 3
257 &rip6_usrreqs
258 #endif
259 },
260 { SOCK_RAW, &inet6domain, IPPROTO_ICMPV6, PR_ATOMIC | PR_ADDR,
261 icmp6_input, rip6_output, 0, rip6_ctloutput,
262 #if defined(__FreeBSD__) && __FreeBSD__ >= 3
263 0,
264 #else
265 rip6_usrreq,
266 #endif
267 icmp6_init, icmp6_fasttimo, 0, 0,
268 #ifndef __FreeBSD__
269 icmp6_sysctl,
270 #else
271 # if __FreeBSD__ >= 3
272 &rip6_usrreqs
273 # endif
274 #endif
275 },
276 { SOCK_RAW, &inet6domain, IPPROTO_DSTOPTS,PR_ATOMIC|PR_ADDR,
277 dest6_input, 0, 0, 0,
278 0,
279 0, 0, 0, 0,
280 #if defined(__FreeBSD__) && __FreeBSD__ >= 3
281 &nousrreqs
282 #endif
283 },
284 { SOCK_RAW, &inet6domain, IPPROTO_ROUTING,PR_ATOMIC|PR_ADDR,
285 route6_input, 0, 0, 0,
286 0,
287 0, 0, 0, 0,
288 #if defined(__FreeBSD__) && __FreeBSD__ >= 3
289 &nousrreqs
290 #endif
291 },
292 { SOCK_RAW, &inet6domain, IPPROTO_FRAGMENT,PR_ATOMIC|PR_ADDR,
293 frag6_input, 0, 0, 0,
294 0,
295 0, 0, 0, 0,
296 #if defined(__FreeBSD__) && __FreeBSD__ >= 3
297 &nousrreqs
298 #endif
299 },
300 #ifdef IPSEC
301 { SOCK_RAW, &inet6domain, IPPROTO_AH, PR_ATOMIC|PR_ADDR,
302 ah6_input, 0, 0, 0,
303 0,
304 0, 0, 0, 0,
305 #ifndef __FreeBSD__
306 ipsec6_sysctl,
307 #else
308 # if __FreeBSD__ >= 3
309 &nousrreqs,
310 # endif
311 #endif
312 },
313 #ifdef IPSEC_ESP
314 { SOCK_RAW, &inet6domain, IPPROTO_ESP, PR_ATOMIC|PR_ADDR,
315 esp6_input, 0, 0, 0,
316 0,
317 0, 0, 0, 0,
318 #ifndef __FreeBSD__
319 ipsec6_sysctl,
320 #else
321 # if __FreeBSD__ >= 3
322 &nousrreqs,
323 # endif
324 #endif
325 },
326 #endif
327 { SOCK_RAW, &inet6domain, IPPROTO_IPCOMP, PR_ATOMIC|PR_ADDR,
328 ipcomp6_input, 0, 0, 0,
329 0,
330 0, 0, 0, 0,
331 #ifndef __FreeBSD__
332 ipsec6_sysctl,
333 #else
334 # if __FreeBSD__ >= 3
335 &nousrreqs,
336 # endif
337 #endif
338 },
339 #endif /* IPSEC */
340 #if NGIF > 0
341 { SOCK_RAW, &inet6domain, IPPROTO_IPV4, PR_ATOMIC|PR_ADDR,
342 in6_gif_input,0, 0, 0,
343 0,
344 0, 0, 0, 0,
345 #if defined(__FreeBSD__) && __FreeBSD__ >= 3
346 &nousrreqs
347 #endif
348 },
349 #ifdef INET6
350 { SOCK_RAW, &inet6domain, IPPROTO_IPV6, PR_ATOMIC|PR_ADDR,
351 in6_gif_input,0, 0, 0,
352 0,
353 0, 0, 0, 0,
354 #if defined(__FreeBSD__) && __FreeBSD__ >= 3
355 &nousrreqs
356 #endif
357 },
358 #endif /* INET6 */
359 #endif /* GIF */
360 { SOCK_RAW, &inet6domain, IPPROTO_PIM, PR_ATOMIC|PR_ADDR,
361 pim6_input, rip6_output, 0, rip6_ctloutput,
362 #if defined(__FreeBSD__) && __FreeBSD__ >= 3
363 0,
364 #else
365 rip6_usrreq,
366 #endif
367 0, 0, 0, 0,
368 #if defined(__FreeBSD__) && __FreeBSD__ >= 3
369 &rip6_usrreqs
370 # endif
371 },
372 /* raw wildcard */
373 { SOCK_RAW, &inet6domain, 0, PR_ATOMIC | PR_ADDR,
374 rip6_input, rip6_output, 0, rip6_ctloutput,
375 #if defined(__FreeBSD__) && __FreeBSD__ >= 3
376 0, 0,
377 #else
378 rip6_usrreq, rip6_init,
379 #endif
380 0, 0, 0,
381 #if defined(__FreeBSD__) && __FreeBSD__ >= 3
382 &rip6_usrreqs
383 #endif
384 },
385 };
386
387 #ifdef __FreeBSD__
388 extern int in6_inithead __P((void **, int));
389 #endif
390
391 struct domain inet6domain =
392 { AF_INET6, "internet6", 0, 0, 0,
393 (struct protosw *)inet6sw,
394 (struct protosw *)&inet6sw[sizeof(inet6sw)/sizeof(inet6sw[0])], 0,
395 #ifdef __FreeBSD__
396 in6_inithead,
397 #else
398 rn_inithead,
399 #endif
400 offsetof(struct sockaddr_in6, sin6_addr) << 3,
401 sizeof(struct sockaddr_in6) };
402
403 #ifdef __FreeBSD__
404 DOMAIN_SET(inet6);
405 #endif
406
407 /*
408 * Internet configuration info
409 */
410 #ifndef IPV6FORWARDING
411 #ifdef GATEWAY6
412 #define IPV6FORWARDING 1 /* forward IP6 packets not for us */
413 #else
414 #define IPV6FORWARDING 0 /* don't forward IP6 packets not for us */
415 #endif /* GATEWAY6 */
416 #endif /* !IPV6FORWARDING */
417
418 #ifndef IPV6_SENDREDIRECTS
419 #define IPV6_SENDREDIRECTS 1
420 #endif
421
422 int ip6_forwarding = IPV6FORWARDING; /* act as router? */
423 int ip6_sendredirects = IPV6_SENDREDIRECTS;
424 int ip6_defhlim = IPV6_DEFHLIM;
425 int ip6_defmcasthlim = IPV6_DEFAULT_MULTICAST_HOPS;
426 int ip6_accept_rtadv = 0; /* "IPV6FORWARDING ? 0 : 1" is dangerous */
427 int ip6_maxfragpackets = 200;
428 int ip6_log_interval = 5;
429 int ip6_hdrnestlimit = 50; /* appropriate? */
430 int ip6_dad_count = 1; /* DupAddrDetectionTransmits */
431 u_int32_t ip6_flow_seq;
432 int ip6_auto_flowlabel = 1;
433 #if NGIF > 0
434 int ip6_gif_hlim = GIF_HLIM;
435 #else
436 int ip6_gif_hlim = 0;
437 #endif
438 int ip6_use_deprecated = 1; /* allow deprecated addr (RFC2462 5.5.4) */
439 int ip6_rr_prune = 5; /* router renumbering prefix
440 * walk list every 5 sec. */
441 #ifdef MAPPED_ADDR_ENABLED
442 int ip6_mapped_addr_on = 1;
443 #endif /* MAPPED_ADDR_ENABLED */
444
445 u_int32_t ip6_id = 0UL;
446 int ip6_keepfaith = 0;
447 time_t ip6_log_time = (time_t)0L;
448
449 /* icmp6 */
450 #ifndef __bsdi__
451 /*
452 * BSDI4 defines these variables in in_proto.c...
453 * XXX: what if we don't define INET? Should we define pmtu6_expire
454 * or so? (jinmei (at) kame.net 19990310)
455 */
456 int pmtu_expire = 60*10;
457 int pmtu_probe = 60*2;
458 #endif
459
460 /* raw IP6 parameters */
461 /*
462 * Nominal space allocated to a raw ip socket.
463 */
464 #define RIPV6SNDQ 8192
465 #define RIPV6RCVQ 8192
466
467 u_long rip6_sendspace = RIPV6SNDQ;
468 u_long rip6_recvspace = RIPV6RCVQ;
469
470 /* ICMPV6 parameters */
471 int icmp6_rediraccept = 1; /* accept and process redirects */
472 int icmp6_redirtimeout = 10 * 60; /* 10 minutes */
473 u_int icmp6errratelim = 1000; /* 1000usec = 1msec */
474
475 #ifdef TCP6
476 /* TCP on IP6 parameters */
477 int tcp6_sendspace = 1024 * 8;
478 int tcp6_recvspace = 1024 * 8;
479 int tcp6_mssdflt = TCP6_MSS;
480 int tcp6_rttdflt = TCP6TV_SRTTDFLT / PR_SLOWHZ;
481 int tcp6_do_rfc1323 = 1;
482 int tcp6_conntimeo = TCP6TV_KEEP_INIT; /* initial connection timeout */
483 int tcp6_43maxseg = 0;
484 int tcp6_pmtu = 0;
485
486 /*
487 * Parameters for keepalive option.
488 * Connections for which SO_KEEPALIVE is set will be probed
489 * after being idle for a time of tcp6_keepidle (in units of PR_SLOWHZ).
490 * Starting at that time, the connection is probed at intervals
491 * of tcp6_keepintvl (same units) until a response is received
492 * or until tcp6_keepcnt probes have been made, at which time
493 * the connection is dropped. Note that a tcp6_keepidle value
494 * under 2 hours is nonconformant with RFC-1122, Internet Host Requirements.
495 */
496 int tcp6_keepidle = TCP6TV_KEEP_IDLE; /* time before probing idle */
497 int tcp6_keepintvl = TCP6TV_KEEPINTVL; /* interval betwn idle probes */
498 int tcp6_keepcnt = TCP6TV_KEEPCNT; /* max idle probes */
499 int tcp6_maxpersistidle = TCP6TV_KEEP_IDLE; /* max idle time in persist */
500
501 #ifndef INET_SERVER
502 #define TCP6_LISTEN_HASH_SIZE 17
503 #define TCP6_CONN_HASH_SIZE 97
504 #define TCP6_SYN_HASH_SIZE 293
505 #define TCP6_SYN_BUCKET_SIZE 35
506 #else
507 #define TCP6_LISTEN_HASH_SIZE 97
508 #define TCP6_CONN_HASH_SIZE 9973
509 #define TCP6_SYN_HASH_SIZE 997
510 #define TCP6_SYN_BUCKET_SIZE 35
511 #endif
512 int tcp6_listen_hash_size = TCP6_LISTEN_HASH_SIZE;
513 int tcp6_conn_hash_size = TCP6_CONN_HASH_SIZE;
514 struct tcp6_hash_list tcp6_listen_hash[TCP6_LISTEN_HASH_SIZE],
515 tcp6_conn_hash[TCP6_CONN_HASH_SIZE];
516
517 int tcp6_syn_cache_size = TCP6_SYN_HASH_SIZE;
518 int tcp6_syn_cache_limit = TCP6_SYN_HASH_SIZE*TCP6_SYN_BUCKET_SIZE;
519 int tcp6_syn_bucket_limit = 3*TCP6_SYN_BUCKET_SIZE;
520 struct syn_cache_head6 tcp6_syn_cache[TCP6_SYN_HASH_SIZE];
521 struct syn_cache_head6 *tcp6_syn_cache_first;
522 int tcp6_syn_cache_interval = 8; /* runs timer every 4 seconds */
523 int tcp6_syn_cache_timeo = TCP6TV_KEEP_INIT;
524
525 /*
526 * Parameters for computing a desirable data segment size
527 * given an upper bound (either interface MTU, or peer's MSS option)_.
528 * As applications tend to use a buffer size that is a multiple
529 * of kilobytes, try for something that divides evenly. However,
530 * do not round down too much.
531 *
532 * Round segment size down to a multiple of TCP6_ROUNDSIZE if this
533 * does not result in lowering by more than (size/TCP6_ROUNDFRAC).
534 * For example, round 536 to 512. Older versions of the system
535 * effectively used MCLBYTES (1K or 2K) as TCP6_ROUNDSIZE, with
536 * a value of 1 for TCP6_ROUNDFRAC (eliminating its effect).
537 * We round to a multiple of 256 for SLIP.
538 */
539 #ifndef TCP6_ROUNDSIZE
540 #define TCP6_ROUNDSIZE 256 /* round to multiple of 256 */
541 #endif
542 #ifndef TCP6_ROUNDFRAC
543 #define TCP6_ROUNDFRAC 10 /* round down at most N/10, or 10% */
544 #endif
545
546 int tcp6_roundsize = TCP6_ROUNDSIZE;
547 int tcp6_roundfrac = TCP6_ROUNDFRAC;
548 #endif /*TCP6*/
549
550 /* UDP on IP6 parameters */
551 int udp6_sendspace = 9216; /* really max datagram size */
552 int udp6_recvspace = 40 * (1024 + sizeof(struct sockaddr_in6));
553 /* 40 1K datagrams */
554
555 #ifdef __FreeBSD__
556 /*
557 * sysctl related items.
558 */
559 SYSCTL_NODE(_net, PF_INET6, inet6, CTLFLAG_RW, 0,
560 "Internet6 Family");
561
562 /* net.inet6 */
563 SYSCTL_NODE(_net_inet6, IPPROTO_IPV6, ip6, CTLFLAG_RW, 0, "IP6");
564 SYSCTL_NODE(_net_inet6, IPPROTO_ICMPV6, icmp6, CTLFLAG_RW, 0, "ICMP6");
565 SYSCTL_NODE(_net_inet6, IPPROTO_UDP, udp6, CTLFLAG_RW, 0, "UDP6");
566 SYSCTL_NODE(_net_inet6, IPPROTO_TCP, tcp6, CTLFLAG_RW, 0, "TCP6");
567 #ifdef IPSEC
568 SYSCTL_NODE(_net_inet6, IPPROTO_ESP, ipsec6, CTLFLAG_RW, 0, "IPSEC6");
569 #endif /* IPSEC */
570
571 /* net.inet6.ip6 */
572 static int
573 sysctl_ip6_forwarding SYSCTL_HANDLER_ARGS
574 {
575 int error = 0;
576 int old_ip6_forwarding;
577 int changed;
578
579 error = SYSCTL_OUT(req, arg1, sizeof(int));
580 if (error || !req->newptr)
581 return (error);
582 old_ip6_forwarding = ip6_forwarding;
583 error = SYSCTL_IN(req, arg1, sizeof(int));
584 if (error != 0)
585 return (error);
586 changed = (ip6_forwarding ? 1 : 0) ^ (old_ip6_forwarding ? 1 : 0);
587 if (changed == 0)
588 return (error);
589 if (ip6_forwarding != 0) { /* host becomes router */
590 int s = splnet();
591 struct nd_prefix *pr, *next;
592
593 for (pr = nd_prefix.lh_first; pr; pr = next) {
594 next = pr->ndpr_next;
595 if (!IN6_IS_ADDR_UNSPECIFIED(&pr->ndpr_addr))
596 in6_ifdel(pr->ndpr_ifp, &pr->ndpr_addr);
597 prelist_remove(pr);
598 }
599 splx(s);
600 } else { /* router becomes host */
601 struct socket so;
602
603 /* XXX: init dummy so */
604 bzero(&so, sizeof(so));
605 while(!LIST_EMPTY(&rr_prefix))
606 delete_each_prefix(&so, LIST_FIRST(&rr_prefix),
607 PR_ORIG_KERNEL);
608 }
609
610 return (error);
611 }
612
613 SYSCTL_OID(_net_inet6_ip6, IPV6CTL_FORWARDING, forwarding,
614 CTLTYPE_INT|CTLFLAG_RW, &ip6_forwarding, 0, sysctl_ip6_forwarding,
615 "I", "");
616 SYSCTL_INT(_net_inet6_ip6, IPV6CTL_SENDREDIRECTS,
617 redirect, CTLFLAG_RW, &ip6_sendredirects, 0, "");
618 SYSCTL_INT(_net_inet6_ip6, IPV6CTL_DEFHLIM,
619 hlim, CTLFLAG_RW, &ip6_defhlim, 0, "");
620 SYSCTL_INT(_net_inet6_ip6, IPV6CTL_MAXFRAGPACKETS,
621 maxfragpackets, CTLFLAG_RW, &ip6_maxfragpackets, 0, "");
622 SYSCTL_INT(_net_inet6_ip6, IPV6CTL_ACCEPT_RTADV,
623 accept_rtadv, CTLFLAG_RW, &ip6_accept_rtadv, 0, "");
624 SYSCTL_INT(_net_inet6_ip6, IPV6CTL_KEEPFAITH,
625 keepfaith, CTLFLAG_RW, &ip6_keepfaith, 0, "");
626 SYSCTL_INT(_net_inet6_ip6, IPV6CTL_LOG_INTERVAL,
627 log_interval, CTLFLAG_RW, &ip6_log_interval, 0, "");
628 SYSCTL_INT(_net_inet6_ip6, IPV6CTL_HDRNESTLIMIT,
629 hdrnestlimit, CTLFLAG_RW, &ip6_hdrnestlimit, 0, "");
630 SYSCTL_INT(_net_inet6_ip6, IPV6CTL_DAD_COUNT,
631 dad_count, CTLFLAG_RW, &ip6_dad_count, 0, "");
632 SYSCTL_INT(_net_inet6_ip6, IPV6CTL_AUTO_FLOWLABEL,
633 auto_flowlabel, CTLFLAG_RW, &ip6_auto_flowlabel, 0, "");
634 SYSCTL_INT(_net_inet6_ip6, IPV6CTL_DEFMCASTHLIM,
635 defmcasthlim, CTLFLAG_RW, &ip6_defmcasthlim, 0, "");
636 SYSCTL_INT(_net_inet6_ip6, IPV6CTL_GIF_HLIM,
637 gifhlim, CTLFLAG_RW, &ip6_gif_hlim, 0, "");
638 SYSCTL_STRING(_net_inet6_ip6, IPV6CTL_KAME_VERSION,
639 kame_version, CTLFLAG_RD, __KAME_VERSION, 0, "");
640 SYSCTL_INT(_net_inet6_ip6, IPV6CTL_USE_DEPRECATED,
641 use_deprecated, CTLFLAG_RW, &ip6_use_deprecated, 0, "");
642 SYSCTL_INT(_net_inet6_ip6, IPV6CTL_RR_PRUNE,
643 rr_prune, CTLFLAG_RW, &ip6_rr_prune, 0, "");
644 #ifdef MAPPED_ADDR_ENABLED
645 SYSCTL_INT(_net_inet6_ip6, IPV6CTL_MAPPED_ADDR,
646 mapped_addr, CTLFLAG_RW, &ip6_mapped_addr_on, 0, "");
647 #endif /* MAPPED_ADDR_ENABLED */
648
649 /* net.inet6.icmp6 */
650 SYSCTL_INT(_net_inet6_icmp6, ICMPV6CTL_REDIRACCEPT,
651 rediraccept, CTLFLAG_RW, &icmp6_rediraccept, 0, "");
652 SYSCTL_INT(_net_inet6_icmp6, ICMPV6CTL_REDIRTIMEOUT,
653 redirtimeout, CTLFLAG_RW, &icmp6_redirtimeout, 0, "");
654 SYSCTL_STRUCT(_net_inet6_icmp6, ICMPV6CTL_STATS, stats, CTLFLAG_RD,
655 &icmp6stat, icmp6stat, "");
656 SYSCTL_INT(_net_inet6_icmp6, ICMPV6CTL_ERRRATELIMIT,
657 errratelimit, CTLFLAG_RW, &icmp6errratelim, 0, "");
658 SYSCTL_INT(_net_inet6_icmp6, ICMPV6CTL_ND6_PRUNE,
659 nd6_prune, CTLFLAG_RW, &nd6_prune, 0, "");
660 SYSCTL_INT(_net_inet6_icmp6, ICMPV6CTL_ND6_DELAY,
661 nd6_delay, CTLFLAG_RW, &nd6_delay, 0, "");
662 SYSCTL_INT(_net_inet6_icmp6, ICMPV6CTL_ND6_UMAXTRIES,
663 nd6_umaxtries, CTLFLAG_RW, &nd6_umaxtries, 0, "");
664 SYSCTL_INT(_net_inet6_icmp6, ICMPV6CTL_ND6_MMAXTRIES,
665 nd6_mmaxtries, CTLFLAG_RW, &nd6_mmaxtries, 0, "");
666 SYSCTL_INT(_net_inet6_icmp6, ICMPV6CTL_ND6_USELOOPBACK,
667 nd6_useloopback, CTLFLAG_RW, &nd6_useloopback, 0, "");
668 SYSCTL_INT(_net_inet6_icmp6, ICMPV6CTL_ND6_PROXYALL,
669 nd6_proxyall, CTLFLAG_RW, &nd6_proxyall, 0, "");
670
671 #if __FreeBSD__ < 3
672 /* net.inet6.udp6 */
673 SYSCTL_INT(_net_inet6_udp6, UDP6CTL_SENDMAX,
674 sendmax, CTLFLAG_RW, &udp6_sendspace, 0, "");
675 SYSCTL_INT(_net_inet6_udp6, UDP6CTL_RECVSPACE,
676 recvspace, CTLFLAG_RW, &udp6_recvspace, 0, "");
677
678 /* net.inet6.tcp6 */
679 SYSCTL_INT(_net_inet6_tcp6, TCP6CTL_MSSDFLT,
680 mssdflt, CTLFLAG_RW, &tcp6_mssdflt, 0, "");
681 SYSCTL_INT(_net_inet6_tcp6, TCP6CTL_DO_RFC1323,
682 do_rfc1323, CTLFLAG_RW, &tcp6_do_rfc1323, 0, "");
683 SYSCTL_INT(_net_inet6_tcp6, TCP6CTL_KEEPIDLE,
684 keepidle, CTLFLAG_RW, &tcp6_keepidle, 0, "");
685 SYSCTL_INT(_net_inet6_tcp6, TCP6CTL_KEEPINTVL,
686 keepintvl, CTLFLAG_RW, &tcp6_keepintvl, 0, "");
687 SYSCTL_INT(_net_inet6_tcp6, TCP6CTL_KEEPCNT,
688 keepcnt, CTLFLAG_RW, &tcp6_keepcnt, 0, "");
689 SYSCTL_INT(_net_inet6_tcp6, TCP6CTL_MAXPERSISTIDLE,
690 maxpersistidle, CTLFLAG_RW, &tcp6_maxpersistidle, 0, "");
691 SYSCTL_INT(_net_inet6_tcp6, TCP6CTL_SENDSPACE,
692 sendspace, CTLFLAG_RW, &tcp6_sendspace, 0, "");
693 SYSCTL_INT(_net_inet6_tcp6, TCP6CTL_RECVSPACE,
694 recvspace, CTLFLAG_RW, &tcp6_recvspace, 0, "");
695 SYSCTL_INT(_net_inet6_tcp6, TCP6CTL_CONNTIMEO,
696 conntimeo, CTLFLAG_RW, &tcp6_conntimeo, 0, "");
697 SYSCTL_INT(_net_inet6_tcp6, TCP6CTL_PMTU,
698 pmtu, CTLFLAG_RW, &tcp6_pmtu, 0, "");
699 SYSCTL_INT(_net_inet6_tcp6, TCP6CTL_PMTU_EXPIRE,
700 pmtu_expire, CTLFLAG_RW, &pmtu_expire, 0, "");
701 SYSCTL_INT(_net_inet6_tcp6, TCP6CTL_PMTU_PROBE,
702 pmtu_probe, CTLFLAG_RW, &pmtu_probe, 0, "");
703 SYSCTL_INT(_net_inet6_tcp6, TCP6CTL_43MAXSEG,
704 pmtu_43maxseg, CTLFLAG_RW, &tcp6_43maxseg, 0, "");
705 SYSCTL_STRUCT(_net_inet6_tcp6, TCP6CTL_STATS, stats, CTLFLAG_RD,
706 &tcp6stat, tcp6stat, "");
707 SYSCTL_INT(_net_inet6_tcp6, TCP6CTL_SYN_CACHE_LIMIT,
708 syn_cache_limit, CTLFLAG_RW, &tcp6_syn_cache_limit, 0, "");
709 SYSCTL_INT(_net_inet6_tcp6, TCP6CTL_SYN_BUCKET_LIMIT,
710 syn_bucket_limit, CTLFLAG_RW, &tcp6_syn_bucket_limit, 0, "");
711 SYSCTL_INT(_net_inet6_tcp6, TCP6CTL_SYN_CACHE_INTER,
712 syn_cache_interval, CTLFLAG_RW, &tcp6_syn_cache_interval, 0, "");
713 #endif /* !(defined(__FreeBSD__) && __FreeBSD__ >= 3) */
714
715 #endif /* __FreeBSD__ */
716