1 /* $FreeBSD: src/sys/netinet6/in6_proto.c,v 1.6.2.9 2003/01/24 05:11:35 sam Exp $ */
2 /* $DragonFly: src/sys/netinet6/in6_proto.c,v 1.14 2008/10/27 02:56:30 sephe Exp $ */
3 /* $KAME: in6_proto.c,v 1.91 2001/05/27 13:28:35 itojun Exp $ */
6 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the project nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 * Copyright (c) 1982, 1986, 1993
36 * The Regents of the University of California. All rights reserved.
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions
41 * 1. Redistributions of source code must retain the above copyright
42 * notice, this list of conditions and the following disclaimer.
43 * 2. Redistributions in binary form must reproduce the above copyright
44 * notice, this list of conditions and the following disclaimer in the
45 * documentation and/or other materials provided with the distribution.
46 * 3. All advertising materials mentioning features or use of this software
47 * must display the following acknowledgement:
48 * This product includes software developed by the University of
49 * California, Berkeley and its contributors.
50 * 4. Neither the name of the University nor the names of its contributors
51 * may be used to endorse or promote products derived from this software
52 * without specific prior written permission.
54 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
55 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
56 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
57 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
58 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
59 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
60 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
61 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
62 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
63 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
66 * @(#)in_proto.c 8.1 (Berkeley) 6/10/93
70 #include "opt_inet6.h"
71 #include "opt_ipsec.h"
74 #include <sys/param.h>
75 #include <sys/socket.h>
76 #include <sys/socketvar.h>
77 #include <sys/protosw.h>
78 #include <sys/kernel.h>
79 #include <sys/domain.h>
81 #include <sys/systm.h>
82 #include <sys/sysctl.h>
85 #include <net/radix.h>
86 #include <net/route.h>
88 #include <netinet/in.h>
89 #include <netinet/in_systm.h>
90 #include <netinet/in_var.h>
91 #include <netinet/ip_encap.h>
92 #include <netinet/ip.h>
93 #include <netinet/ip_var.h>
94 #include <netinet/ip6.h>
95 #include <netinet6/ip6_var.h>
96 #include <netinet/icmp6.h>
98 #include <netinet/tcp.h>
99 #include <netinet/tcp_timer.h>
100 #include <netinet/tcp_var.h>
101 #include <netinet/udp.h>
102 #include <netinet/udp_var.h>
103 #include <netinet6/tcp6_var.h>
104 #include <netinet6/raw_ip6.h>
105 #include <netinet6/udp6_var.h>
106 #include <netinet6/pim6_var.h>
107 #include <netinet6/nd6.h>
108 #include <netinet6/in6_prefix.h>
111 #include <netinet6/ipsec.h>
113 #include <netinet6/ipsec6.h>
115 #include <netinet6/ah.h>
117 #include <netinet6/ah6.h>
120 #include <netinet6/esp.h>
122 #include <netinet6/esp6.h>
125 #include <netinet6/ipcomp.h>
127 #include <netinet6/ipcomp6.h>
132 #include <netproto/ipsec/ipsec6.h>
135 #define ah6_input ipsec6_common_input
136 #define esp6_input ipsec6_common_input
137 #define ipcomp6_input ipsec6_common_input
138 #endif /* FAST_IPSEC */
140 #include <netinet6/ip6protosw.h>
142 #include <net/net_osdep.h>
145 #include <netinet/ip_carp.h>
150 * TCP/IP protocol family: IP6, ICMP6, UDP, TCP.
153 extern struct domain inet6domain;
154 static struct pr_usrreqs nousrreqs;
157 #define PR_ABRTACPTDIS 0
159 struct ip6protosw inet6sw[] = {
160 { 0, &inet6domain, IPPROTO_IPV6, 0,
163 ip6_init, 0, frag6_slowtimo, frag6_drain,
166 { SOCK_DGRAM, &inet6domain, IPPROTO_UDP, PR_ATOMIC|PR_ADDR,
167 udp6_input, 0, udp6_ctlinput, ip6_ctloutput,
168 cpu0_soport, cpu0_ctlport,
172 { SOCK_STREAM, &inet6domain, IPPROTO_TCP, PR_CONNREQUIRED|PR_WANTRCVD|PR_LISTEN,
173 tcp6_input, 0, tcp6_ctlinput, tcp_ctloutput,
174 tcp6_soport, cpu0_ctlport,
175 #ifdef INET /* don't call initialization and timeout routines twice */
178 tcp_init, tcp_fasttimo, tcp_slowtimo, tcp_drain,
182 { SOCK_RAW, &inet6domain, IPPROTO_RAW, PR_ATOMIC|PR_ADDR,
183 rip6_input, rip6_output, rip6_ctlinput, rip6_ctloutput,
184 cpu0_soport, cpu0_ctlport,
188 { SOCK_RAW, &inet6domain, IPPROTO_ICMPV6, PR_ATOMIC|PR_ADDR|PR_LASTHDR,
189 icmp6_input, rip6_output, rip6_ctlinput, rip6_ctloutput,
190 cpu0_soport, cpu0_ctlport,
191 icmp6_init, icmp6_fasttimo, 0, 0,
194 { SOCK_RAW, &inet6domain, IPPROTO_DSTOPTS, PR_ATOMIC|PR_ADDR,
195 dest6_input, 0, 0, 0,
200 { SOCK_RAW, &inet6domain, IPPROTO_ROUTING, PR_ATOMIC|PR_ADDR,
201 route6_input, 0, 0, 0,
206 { SOCK_RAW, &inet6domain, IPPROTO_FRAGMENT, PR_ATOMIC|PR_ADDR,
207 frag6_input, 0, 0, 0,
213 { SOCK_RAW, &inet6domain, IPPROTO_AH, PR_ATOMIC|PR_ADDR,
220 { SOCK_RAW, &inet6domain, IPPROTO_ESP, PR_ATOMIC|PR_ADDR,
229 { SOCK_RAW, &inet6domain, IPPROTO_IPCOMP, PR_ATOMIC|PR_ADDR,
230 ipcomp6_input, 0, 0, 0,
237 { SOCK_RAW, &inet6domain, IPPROTO_IPV4, PR_ATOMIC|PR_ADDR|PR_LASTHDR,
238 encap6_input, rip6_output, 0, rip6_ctloutput,
244 { SOCK_RAW, &inet6domain, IPPROTO_IPV6, PR_ATOMIC|PR_ADDR|PR_LASTHDR,
245 encap6_input, rip6_output, 0, rip6_ctloutput,
250 { SOCK_RAW, &inet6domain, IPPROTO_PIM, PR_ATOMIC|PR_ADDR|PR_LASTHDR,
251 pim6_input, rip6_output, 0, rip6_ctloutput,
257 { SOCK_RAW, &inet6domain, IPPROTO_CARP, PR_ATOMIC|PR_ADDR,
258 carp6_input, rip6_output, 0, rip6_ctloutput,
266 { SOCK_RAW, &inet6domain, 0, PR_ATOMIC|PR_ADDR,
267 rip6_input, rip6_output, 0, rip6_ctloutput,
274 extern int in6_inithead (void **, int);
276 struct domain inet6domain = {
277 AF_INET6, "internet6", NULL, NULL, NULL,
278 (struct protosw *)inet6sw,
279 (struct protosw *)&inet6sw[sizeof(inet6sw)/sizeof(inet6sw[0])],
280 SLIST_ENTRY_INITIALIZER,
281 in6_inithead, offsetof(struct sockaddr_in6, sin6_addr) << 3,
282 sizeof(struct sockaddr_in6), in6_domifattach, in6_domifdetach
288 * Internet configuration info
290 #ifndef IPV6FORWARDING
292 #define IPV6FORWARDING 1 /* forward IP6 packets not for us */
294 #define IPV6FORWARDING 0 /* don't forward IP6 packets not for us */
295 #endif /* GATEWAY6 */
296 #endif /* !IPV6FORWARDING */
298 #ifndef IPV6_SENDREDIRECTS
299 #define IPV6_SENDREDIRECTS 1
302 int ip6_forwarding = IPV6FORWARDING; /* act as router? */
303 int ip6_sendredirects = IPV6_SENDREDIRECTS;
304 int ip6_defhlim = IPV6_DEFHLIM;
305 int ip6_defmcasthlim = IPV6_DEFAULT_MULTICAST_HOPS;
306 int ip6_accept_rtadv = 0; /* "IPV6FORWARDING ? 0 : 1" is dangerous */
307 int ip6_maxfragpackets; /* initialized in frag6.c:frag6_init() */
308 int ip6_log_interval = 5;
309 int ip6_hdrnestlimit = 50; /* appropriate? */
310 int ip6_dad_count = 1; /* DupAddrDetectionTransmits */
311 u_int32_t ip6_flow_seq;
312 int ip6_auto_flowlabel = 1;
313 int ip6_gif_hlim = 0;
314 int ip6_use_deprecated = 1; /* allow deprecated addr (RFC2462 5.5.4) */
315 int ip6_rr_prune = 5; /* router renumbering prefix
316 * walk list every 5 sec. */
319 u_int32_t ip6_id = 0UL;
320 int ip6_keepfaith = 0;
321 time_t ip6_log_time = (time_t)0L;
325 * BSDI4 defines these variables in in_proto.c...
326 * XXX: what if we don't define INET? Should we define pmtu6_expire
327 * or so? (jinmei@kame.net 19990310)
329 int pmtu_expire = 60*10;
330 int pmtu_probe = 60*2;
332 /* raw IP6 parameters */
334 * Nominal space allocated to a raw ip socket.
336 #define RIPV6SNDQ 8192
337 #define RIPV6RCVQ 8192
339 u_long rip6_sendspace = RIPV6SNDQ;
340 u_long rip6_recvspace = RIPV6RCVQ;
342 /* ICMPV6 parameters */
343 int icmp6_rediraccept = 1; /* accept and process redirects */
344 int icmp6_redirtimeout = 10 * 60; /* 10 minutes */
345 int icmp6errppslim = 100; /* 100pps */
346 int icmp6_nodeinfo = 3; /* enable/disable NI response */
348 /* UDP on IP6 parameters */
349 int udp6_sendspace = 9216; /* really max datagram size */
350 int udp6_recvspace = 40 * (1024 + sizeof(struct sockaddr_in6));
351 /* 40 1K datagrams */
354 * sysctl related items.
356 SYSCTL_NODE(_net, PF_INET6, inet6, CTLFLAG_RW, 0,
360 SYSCTL_NODE(_net_inet6, IPPROTO_IPV6, ip6, CTLFLAG_RW, 0, "IP6");
361 SYSCTL_NODE(_net_inet6, IPPROTO_ICMPV6, icmp6, CTLFLAG_RW, 0, "ICMP6");
362 SYSCTL_NODE(_net_inet6, IPPROTO_UDP, udp6, CTLFLAG_RW, 0, "UDP6");
363 SYSCTL_NODE(_net_inet6, IPPROTO_TCP, tcp6, CTLFLAG_RW, 0, "TCP6");
365 SYSCTL_NODE(_net_inet6, IPPROTO_ESP, ipsec6, CTLFLAG_RW, 0, "IPSEC6");
370 sysctl_ip6_temppltime(SYSCTL_HANDLER_ARGS)
375 error = SYSCTL_OUT(req, arg1, sizeof(int));
376 if (error || !req->newptr)
378 old = ip6_temp_preferred_lifetime;
379 error = SYSCTL_IN(req, arg1, sizeof(int));
380 if (ip6_temp_preferred_lifetime <
381 ip6_desync_factor + ip6_temp_regen_advance) {
382 ip6_temp_preferred_lifetime = old;
389 sysctl_ip6_tempvltime(SYSCTL_HANDLER_ARGS)
394 error = SYSCTL_OUT(req, arg1, sizeof(int));
395 if (error || !req->newptr)
397 old = ip6_temp_valid_lifetime;
398 error = SYSCTL_IN(req, arg1, sizeof(int));
399 if (ip6_temp_valid_lifetime < ip6_temp_preferred_lifetime) {
400 ip6_temp_preferred_lifetime = old;
406 SYSCTL_INT(_net_inet6_ip6, IPV6CTL_FORWARDING,
407 forwarding, CTLFLAG_RW, &ip6_forwarding, 0, "");
408 SYSCTL_INT(_net_inet6_ip6, IPV6CTL_SENDREDIRECTS,
409 redirect, CTLFLAG_RW, &ip6_sendredirects, 0, "");
410 SYSCTL_INT(_net_inet6_ip6, IPV6CTL_DEFHLIM,
411 hlim, CTLFLAG_RW, &ip6_defhlim, 0, "");
412 SYSCTL_STRUCT(_net_inet6_ip6, IPV6CTL_STATS, stats, CTLFLAG_RD,
413 &ip6stat, ip6stat, "");
414 SYSCTL_INT(_net_inet6_ip6, IPV6CTL_MAXFRAGPACKETS,
415 maxfragpackets, CTLFLAG_RW, &ip6_maxfragpackets, 0, "");
416 SYSCTL_INT(_net_inet6_ip6, IPV6CTL_ACCEPT_RTADV,
417 accept_rtadv, CTLFLAG_RW, &ip6_accept_rtadv, 0, "");
418 SYSCTL_INT(_net_inet6_ip6, IPV6CTL_KEEPFAITH,
419 keepfaith, CTLFLAG_RW, &ip6_keepfaith, 0, "");
420 SYSCTL_INT(_net_inet6_ip6, IPV6CTL_LOG_INTERVAL,
421 log_interval, CTLFLAG_RW, &ip6_log_interval, 0, "");
422 SYSCTL_INT(_net_inet6_ip6, IPV6CTL_HDRNESTLIMIT,
423 hdrnestlimit, CTLFLAG_RW, &ip6_hdrnestlimit, 0, "");
424 SYSCTL_INT(_net_inet6_ip6, IPV6CTL_DAD_COUNT,
425 dad_count, CTLFLAG_RW, &ip6_dad_count, 0, "");
426 SYSCTL_INT(_net_inet6_ip6, IPV6CTL_AUTO_FLOWLABEL,
427 auto_flowlabel, CTLFLAG_RW, &ip6_auto_flowlabel, 0, "");
428 SYSCTL_INT(_net_inet6_ip6, IPV6CTL_DEFMCASTHLIM,
429 defmcasthlim, CTLFLAG_RW, &ip6_defmcasthlim, 0, "");
430 SYSCTL_INT(_net_inet6_ip6, IPV6CTL_GIF_HLIM,
431 gifhlim, CTLFLAG_RW, &ip6_gif_hlim, 0, "");
432 SYSCTL_STRING(_net_inet6_ip6, IPV6CTL_KAME_VERSION,
433 kame_version, CTLFLAG_RD, __KAME_VERSION, 0, "");
434 SYSCTL_INT(_net_inet6_ip6, IPV6CTL_USE_DEPRECATED,
435 use_deprecated, CTLFLAG_RW, &ip6_use_deprecated, 0, "");
436 SYSCTL_INT(_net_inet6_ip6, IPV6CTL_RR_PRUNE,
437 rr_prune, CTLFLAG_RW, &ip6_rr_prune, 0, "");
438 SYSCTL_INT(_net_inet6_ip6, IPV6CTL_USETEMPADDR,
439 use_tempaddr, CTLFLAG_RW, &ip6_use_tempaddr, 0, "");
440 SYSCTL_OID(_net_inet6_ip6, IPV6CTL_TEMPPLTIME, temppltime,
441 CTLTYPE_INT|CTLFLAG_RW, &ip6_temp_preferred_lifetime, 0,
442 sysctl_ip6_temppltime, "I", "");
443 SYSCTL_OID(_net_inet6_ip6, IPV6CTL_TEMPVLTIME, tempvltime,
444 CTLTYPE_INT|CTLFLAG_RW, &ip6_temp_valid_lifetime, 0,
445 sysctl_ip6_tempvltime, "I", "");
446 SYSCTL_INT(_net_inet6_ip6, IPV6CTL_V6ONLY,
447 v6only, CTLFLAG_RW, &ip6_v6only, 0, "");
448 SYSCTL_INT(_net_inet6_ip6, IPV6CTL_AUTO_LINKLOCAL,
449 auto_linklocal, CTLFLAG_RW, &ip6_auto_linklocal, 0, "");
450 SYSCTL_STRUCT(_net_inet6_ip6, IPV6CTL_RIP6STATS, rip6stats, CTLFLAG_RD,
451 &rip6stat, rip6stat, "");
453 /* net.inet6.icmp6 */
454 SYSCTL_INT(_net_inet6_icmp6, ICMPV6CTL_REDIRACCEPT,
455 rediraccept, CTLFLAG_RW, &icmp6_rediraccept, 0, "");
456 SYSCTL_INT(_net_inet6_icmp6, ICMPV6CTL_REDIRTIMEOUT,
457 redirtimeout, CTLFLAG_RW, &icmp6_redirtimeout, 0, "");
458 SYSCTL_STRUCT(_net_inet6_icmp6, ICMPV6CTL_STATS, stats, CTLFLAG_RD,
459 &icmp6stat, icmp6stat, "");
460 SYSCTL_INT(_net_inet6_icmp6, ICMPV6CTL_ND6_PRUNE,
461 nd6_prune, CTLFLAG_RW, &nd6_prune, 0, "");
462 SYSCTL_INT(_net_inet6_icmp6, ICMPV6CTL_ND6_DELAY,
463 nd6_delay, CTLFLAG_RW, &nd6_delay, 0, "");
464 SYSCTL_INT(_net_inet6_icmp6, ICMPV6CTL_ND6_UMAXTRIES,
465 nd6_umaxtries, CTLFLAG_RW, &nd6_umaxtries, 0, "");
466 SYSCTL_INT(_net_inet6_icmp6, ICMPV6CTL_ND6_MMAXTRIES,
467 nd6_mmaxtries, CTLFLAG_RW, &nd6_mmaxtries, 0, "");
468 SYSCTL_INT(_net_inet6_icmp6, ICMPV6CTL_ND6_USELOOPBACK,
469 nd6_useloopback, CTLFLAG_RW, &nd6_useloopback, 0, "");
470 SYSCTL_INT(_net_inet6_icmp6, ICMPV6CTL_NODEINFO,
471 nodeinfo, CTLFLAG_RW, &icmp6_nodeinfo, 0, "");
472 SYSCTL_INT(_net_inet6_icmp6, ICMPV6CTL_ERRPPSLIMIT,
473 errppslimit, CTLFLAG_RW, &icmp6errppslim, 0, "");
474 SYSCTL_INT(_net_inet6_icmp6, ICMPV6CTL_ND6_MAXNUDHINT,
475 nd6_maxnudhint, CTLFLAG_RW, &nd6_maxnudhint, 0, "");
476 SYSCTL_INT(_net_inet6_icmp6, ICMPV6CTL_ND6_DEBUG,
477 nd6_debug, CTLFLAG_RW, &nd6_debug, 0, "");