1 /* $FreeBSD: src/sys/netinet6/in6_proto.c,v 1.19 2002/10/16 02:25:05 sam Exp $ */
2 /* $KAME: in6_proto.c,v 1.91 2001/05/27 13:28:35 itojun Exp $ */
5 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of the project nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * Copyright (c) 1982, 1986, 1993
35 * The Regents of the University of California. All rights reserved.
37 * Redistribution and use in source and binary forms, with or without
38 * modification, are permitted provided that the following conditions
40 * 1. Redistributions of source code must retain the above copyright
41 * notice, this list of conditions and the following disclaimer.
42 * 2. Redistributions in binary form must reproduce the above copyright
43 * notice, this list of conditions and the following disclaimer in the
44 * documentation and/or other materials provided with the distribution.
45 * 3. All advertising materials mentioning features or use of this software
46 * must display the following acknowledgement:
47 * This product includes software developed by the University of
48 * California, Berkeley and its contributors.
49 * 4. Neither the name of the University nor the names of its contributors
50 * may be used to endorse or promote products derived from this software
51 * without specific prior written permission.
53 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
54 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
55 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
56 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
57 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
58 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
59 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
60 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
61 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
62 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
65 * @(#)in_proto.c 8.1 (Berkeley) 6/10/93
69 #include <sys/param.h>
70 #include <sys/socket.h>
71 #include <sys/socketvar.h>
72 #include <sys/protosw.h>
73 #include <sys/kernel.h>
74 #include <sys/domain.h>
76 #include <sys/systm.h>
77 #include <sys/sysctl.h>
80 #include <net/radix.h>
81 #include <net/route.h>
83 #include <netinet/in.h>
84 #include <netinet/in_systm.h>
85 #include <netinet/in_var.h>
86 #include <netinet/ip_encap.h>
87 #include <netinet/ip.h>
88 #include <netinet/ip_var.h>
89 #include <netinet/ip6.h>
90 #include <netinet6/ip6_var.h>
91 #include <netinet/icmp6.h>
93 #include <netinet/tcp.h>
94 #include <netinet/tcp_timer.h>
95 #include <netinet/tcp_var.h>
96 #include <netinet/udp.h>
97 #include <netinet/udp_var.h>
98 #include <netinet6/tcp6_var.h>
99 #include <netinet6/raw_ip6.h>
100 #include <netinet6/udp6_var.h>
101 #include <netinet6/pim6_var.h>
102 #include <netinet6/nd6.h>
103 #include <netinet6/in6_prefix.h>
105 #include <netinet6/ip6_mroute.h>
108 #include <netinet6/ipsec.h>
110 #include <netinet6/ipsec6.h>
112 #include <netinet6/ah.h>
114 #include <netinet6/ah6.h>
117 #include <netinet6/esp.h>
119 #include <netinet6/esp6.h>
122 #include <netinet6/ipcomp.h>
124 #include <netinet6/ipcomp6.h>
128 #include <netinet6/ip6protosw.h>
130 #include <net/net_osdep.h>
133 * TCP/IP protocol family: IP6, ICMP6, UDP, TCP.
136 extern struct domain inet6domain
;
137 static struct pr_usrreqs nousrreqs
;
138 lck_mtx_t
*inet6_domain_mutex
;
141 #define PR_ABRTACPTDIS 0
143 extern struct domain inet6domain
;
144 extern int in6_inithead(void **, int);
145 void in6_dinit(void);
147 static int rip6_pr_output(struct mbuf
*m
, struct socket
*so
, struct sockaddr_in6
*, struct mbuf
*);
149 struct ip6protosw inet6sw
[] = {
150 { 0, &inet6domain
, IPPROTO_IPV6
, 0,
153 ip6_init
, 0, frag6_slowtimo
, frag6_drain
,
159 { SOCK_DGRAM
, &inet6domain
, IPPROTO_UDP
, PR_ATOMIC
|PR_ADDR
|PR_PROTOLOCK
|PR_PCBLOCK
,
160 udp6_input
, 0, udp6_ctlinput
, ip6_ctloutput
,
165 udp_lock
, udp_unlock
, udp_getlock
168 { SOCK_STREAM
, &inet6domain
, IPPROTO_TCP
, PR_CONNREQUIRED
|PR_WANTRCVD
|PR_LISTEN
|PR_PROTOLOCK
|PR_PCBLOCK
|PR_DISPOSE
,
169 tcp6_input
, 0, tcp6_ctlinput
, tcp_ctloutput
,
171 #if INET /* don't call initialization and timeout routines twice */
174 tcp_init
, tcp_fasttimo
, tcp_slowtimo
, tcp_drain
,
178 tcp_lock
, tcp_unlock
, tcp_getlock
181 { SOCK_RAW
, &inet6domain
, IPPROTO_RAW
, PR_ATOMIC
|PR_ADDR
,
182 rip6_input
, rip6_pr_output
, rip6_ctlinput
, rip6_ctloutput
,
189 { SOCK_RAW
, &inet6domain
, IPPROTO_ICMPV6
, PR_ATOMIC
|PR_ADDR
|PR_LASTHDR
,
190 icmp6_input
, rip6_pr_output
, rip6_ctlinput
, rip6_ctloutput
,
192 icmp6_init
, icmp6_fasttimo
, 0, 0,
197 { SOCK_RAW
, &inet6domain
, IPPROTO_DSTOPTS
,PR_ATOMIC
|PR_ADDR
,
198 dest6_input
, 0, 0, 0,
205 { SOCK_RAW
, &inet6domain
, IPPROTO_ROUTING
,PR_ATOMIC
|PR_ADDR
,
206 route6_input
, 0, 0, 0,
213 { SOCK_RAW
, &inet6domain
, IPPROTO_FRAGMENT
,PR_ATOMIC
|PR_ADDR
,
214 frag6_input
, 0, 0, 0,
222 { SOCK_RAW
, &inet6domain
, IPPROTO_AH
, PR_ATOMIC
|PR_ADDR
|PR_PROTOLOCK
,
231 { SOCK_RAW
, &inet6domain
, IPPROTO_ESP
, PR_ATOMIC
|PR_ADDR
|PR_PROTOLOCK
,
242 { SOCK_RAW
, &inet6domain
, IPPROTO_IPCOMP
, PR_ATOMIC
|PR_ADDR
|PR_PROTOLOCK
,
243 ipcomp6_input
, 0, 0, 0,
252 { SOCK_RAW
, &inet6domain
, IPPROTO_IPV4
, PR_ATOMIC
|PR_ADDR
|PR_LASTHDR
,
253 encap6_input
, rip6_pr_output
, 0, rip6_ctloutput
,
261 { SOCK_RAW
, &inet6domain
, IPPROTO_IPV6
, PR_ATOMIC
|PR_ADDR
|PR_LASTHDR
,
262 encap6_input
, rip6_pr_output
, 0, rip6_ctloutput
,
269 { SOCK_RAW
, &inet6domain
, IPPROTO_PIM
, PR_ATOMIC
|PR_ADDR
|PR_LASTHDR
,
270 pim6_input
, rip6_pr_output
, 0, rip6_ctloutput
,
278 { SOCK_RAW
, &inet6domain
, 0, PR_ATOMIC
|PR_ADDR
|PR_LASTHDR
,
279 rip6_input
, rip6_pr_output
, 0, rip6_ctloutput
,
289 int in6_proto_count
= (sizeof (inet6sw
) / sizeof (struct ip6protosw
));
291 struct domain inet6domain
=
292 { AF_INET6
, "internet6", in6_dinit
, 0, 0,
293 (struct protosw
*)inet6sw
, 0,
294 in6_inithead
, offsetof(struct sockaddr_in6
, sin6_addr
) << 3, sizeof(struct sockaddr_in6
) ,
295 sizeof(struct sockaddr_in6
), 0
300 /* Initialize the PF_INET6 domain, and add in the pre-defined protos */
305 register struct ip6protosw
*pr
;
306 register struct domain
*dp
;
307 static inet6domain_initted
= 0;
309 if (!inet6domain_initted
) {
312 for (i
=0, pr
= &inet6sw
[0]; i
<in6_proto_count
; i
++, pr
++)
313 net_add_proto((struct protosw
*)pr
, dp
);
315 inet6_domain_mutex
= dp
->dom_mtx
;
316 inet6domain_initted
= 1;
320 int rip6_pr_output(struct mbuf
*m
, struct socket
*so
, struct sockaddr_in6
*sin6
, struct mbuf
*m1
)
322 panic("rip6_pr_output\n");
327 * Internet configuration info
329 #ifndef IPV6FORWARDING
331 #define IPV6FORWARDING 1 /* forward IP6 packets not for us */
333 #define IPV6FORWARDING 0 /* don't forward IP6 packets not for us */
334 #endif /* GATEWAY6 */
335 #endif /* !IPV6FORWARDING */
337 #ifndef IPV6_SENDREDIRECTS
338 #define IPV6_SENDREDIRECTS 1
341 int ip6_forwarding
= IPV6FORWARDING
; /* act as router? */
342 int ip6_sendredirects
= IPV6_SENDREDIRECTS
;
343 int ip6_defhlim
= IPV6_DEFHLIM
;
344 int ip6_defmcasthlim
= IPV6_DEFAULT_MULTICAST_HOPS
;
345 int ip6_accept_rtadv
= 0; /* "IPV6FORWARDING ? 0 : 1" is dangerous */
346 int ip6_maxfragpackets
; /* initialized in frag6.c:frag6_init() */
348 int ip6_log_interval
= 5;
349 int ip6_hdrnestlimit
= 50; /* appropriate? */
350 int ip6_dad_count
= 1; /* DupAddrDetectionTransmits */
351 u_int32_t ip6_flow_seq
;
352 int ip6_auto_flowlabel
= 1;
353 int ip6_gif_hlim
= 0;
354 int ip6_use_deprecated
= 1; /* allow deprecated addr (RFC2462 5.5.4) */
355 int ip6_rr_prune
= 5; /* router renumbering prefix
356 * walk list every 5 sec. */
357 int ip6_v6only
= 0; /* Mapped addresses on by default - Radar 3347718 */
359 u_int32_t ip6_id
= 0UL;
360 int ip6_keepfaith
= 0;
361 time_t ip6_log_time
= (time_t)0L;
365 * BSDI4 defines these variables in in_proto.c...
366 * XXX: what if we don't define INET? Should we define pmtu6_expire
367 * or so? (jinmei@kame.net 19990310)
369 int pmtu_expire
= 60*10;
370 int pmtu_probe
= 60*2;
372 /* raw IP6 parameters */
374 * Nominal space allocated to a raw ip socket.
376 #define RIPV6SNDQ 8192
377 #define RIPV6RCVQ 8192
379 u_long rip6_sendspace
= RIPV6SNDQ
;
380 u_long rip6_recvspace
= RIPV6RCVQ
;
382 /* ICMPV6 parameters */
383 int icmp6_rediraccept
= 1; /* accept and process redirects */
384 int icmp6_redirtimeout
= 10 * 60; /* 10 minutes */
385 int icmp6errppslim
= 100; /* 100pps */
386 int icmp6_nodeinfo
= 3; /* enable/disable NI response */
388 /* UDP on IP6 parameters */
389 int udp6_sendspace
= 9216; /* really max datagram size */
390 int udp6_recvspace
= 40 * (1024 + sizeof(struct sockaddr_in6
));
391 /* 40 1K datagrams */
394 * sysctl related items.
396 SYSCTL_NODE(_net
, PF_INET6
, inet6
, CTLFLAG_RW
, 0,
400 SYSCTL_NODE(_net_inet6
, IPPROTO_IPV6
, ip6
, CTLFLAG_RW
, 0, "IP6");
401 SYSCTL_NODE(_net_inet6
, IPPROTO_ICMPV6
, icmp6
, CTLFLAG_RW
, 0, "ICMP6");
402 SYSCTL_NODE(_net_inet6
, IPPROTO_UDP
, udp6
, CTLFLAG_RW
, 0, "UDP6");
403 SYSCTL_NODE(_net_inet6
, IPPROTO_TCP
, tcp6
, CTLFLAG_RW
, 0, "TCP6");
405 SYSCTL_NODE(_net_inet6
, IPPROTO_ESP
, ipsec6
, CTLFLAG_RW
, 0, "IPSEC6");
410 sysctl_ip6_temppltime SYSCTL_HANDLER_ARGS
415 error
= SYSCTL_OUT(req
, arg1
, sizeof(int));
416 if (error
|| !req
->newptr
)
418 old
= ip6_temp_preferred_lifetime
;
419 error
= SYSCTL_IN(req
, arg1
, sizeof(int));
420 if (ip6_temp_preferred_lifetime
<
421 ip6_desync_factor
+ ip6_temp_regen_advance
) {
422 ip6_temp_preferred_lifetime
= old
;
429 sysctl_ip6_tempvltime SYSCTL_HANDLER_ARGS
434 error
= SYSCTL_OUT(req
, arg1
, sizeof(int));
435 if (error
|| !req
->newptr
)
437 old
= ip6_temp_valid_lifetime
;
438 error
= SYSCTL_IN(req
, arg1
, sizeof(int));
439 if (ip6_temp_valid_lifetime
< ip6_temp_preferred_lifetime
) {
440 ip6_temp_preferred_lifetime
= old
;
446 SYSCTL_INT(_net_inet6_ip6
, IPV6CTL_FORWARDING
,
447 forwarding
, CTLFLAG_RW
, &ip6_forwarding
, 0, "");
448 SYSCTL_INT(_net_inet6_ip6
, IPV6CTL_SENDREDIRECTS
,
449 redirect
, CTLFLAG_RW
, &ip6_sendredirects
, 0, "");
450 SYSCTL_INT(_net_inet6_ip6
, IPV6CTL_DEFHLIM
,
451 hlim
, CTLFLAG_RW
, &ip6_defhlim
, 0, "");
452 SYSCTL_STRUCT(_net_inet6_ip6
, IPV6CTL_STATS
, stats
, CTLFLAG_RD
,
453 &ip6stat
, ip6stat
, "");
454 SYSCTL_INT(_net_inet6_ip6
, IPV6CTL_MAXFRAGPACKETS
,
455 maxfragpackets
, CTLFLAG_RW
, &ip6_maxfragpackets
, 0, "");
456 SYSCTL_INT(_net_inet6_ip6
, IPV6CTL_MAXFRAGS
,
457 maxfrags
, CTLFLAG_RW
, &ip6_maxfrags
, 0, "");
458 SYSCTL_INT(_net_inet6_ip6
, IPV6CTL_ACCEPT_RTADV
,
459 accept_rtadv
, CTLFLAG_RW
, &ip6_accept_rtadv
, 0, "");
460 SYSCTL_INT(_net_inet6_ip6
, IPV6CTL_KEEPFAITH
,
461 keepfaith
, CTLFLAG_RW
, &ip6_keepfaith
, 0, "");
462 SYSCTL_INT(_net_inet6_ip6
, IPV6CTL_LOG_INTERVAL
,
463 log_interval
, CTLFLAG_RW
, &ip6_log_interval
, 0, "");
464 SYSCTL_INT(_net_inet6_ip6
, IPV6CTL_HDRNESTLIMIT
,
465 hdrnestlimit
, CTLFLAG_RW
, &ip6_hdrnestlimit
, 0, "");
466 SYSCTL_INT(_net_inet6_ip6
, IPV6CTL_DAD_COUNT
,
467 dad_count
, CTLFLAG_RW
, &ip6_dad_count
, 0, "");
468 SYSCTL_INT(_net_inet6_ip6
, IPV6CTL_AUTO_FLOWLABEL
,
469 auto_flowlabel
, CTLFLAG_RW
, &ip6_auto_flowlabel
, 0, "");
470 SYSCTL_INT(_net_inet6_ip6
, IPV6CTL_DEFMCASTHLIM
,
471 defmcasthlim
, CTLFLAG_RW
, &ip6_defmcasthlim
, 0, "");
472 SYSCTL_INT(_net_inet6_ip6
, IPV6CTL_GIF_HLIM
,
473 gifhlim
, CTLFLAG_RW
, &ip6_gif_hlim
, 0, "");
474 SYSCTL_STRING(_net_inet6_ip6
, IPV6CTL_KAME_VERSION
,
475 kame_version
, CTLFLAG_RD
, __KAME_VERSION
, 0, "");
476 SYSCTL_INT(_net_inet6_ip6
, IPV6CTL_USE_DEPRECATED
,
477 use_deprecated
, CTLFLAG_RW
, &ip6_use_deprecated
, 0, "");
478 SYSCTL_INT(_net_inet6_ip6
, IPV6CTL_RR_PRUNE
,
479 rr_prune
, CTLFLAG_RW
, &ip6_rr_prune
, 0, "");
480 SYSCTL_INT(_net_inet6_ip6
, IPV6CTL_USETEMPADDR
,
481 use_tempaddr
, CTLFLAG_RW
, &ip6_use_tempaddr
, 0, "");
482 SYSCTL_OID(_net_inet6_ip6
, IPV6CTL_TEMPPLTIME
, temppltime
,
483 CTLTYPE_INT
|CTLFLAG_RW
, &ip6_temp_preferred_lifetime
, 0,
484 sysctl_ip6_temppltime
, "I", "");
485 SYSCTL_OID(_net_inet6_ip6
, IPV6CTL_TEMPVLTIME
, tempvltime
,
486 CTLTYPE_INT
|CTLFLAG_RW
, &ip6_temp_valid_lifetime
, 0,
487 sysctl_ip6_tempvltime
, "I", "");
488 SYSCTL_INT(_net_inet6_ip6
, IPV6CTL_V6ONLY
,
489 v6only
, CTLFLAG_RW
, &ip6_v6only
, 0, "");
490 SYSCTL_INT(_net_inet6_ip6
, IPV6CTL_AUTO_LINKLOCAL
,
491 auto_linklocal
, CTLFLAG_RW
, &ip6_auto_linklocal
, 0, "");
492 SYSCTL_STRUCT(_net_inet6_ip6
, IPV6CTL_RIP6STATS
, rip6stats
, CTLFLAG_RD
,
493 &rip6stat
, rip6stat
, "");
494 SYSCTL_STRUCT(_net_inet6_ip6
, OID_AUTO
, mrt6stat
, CTLFLAG_RD
,
495 &mrt6stat
, mrt6stat
, "");
498 /* net.inet6.icmp6 */
499 SYSCTL_INT(_net_inet6_icmp6
, ICMPV6CTL_REDIRACCEPT
,
500 rediraccept
, CTLFLAG_RW
, &icmp6_rediraccept
, 0, "");
501 SYSCTL_INT(_net_inet6_icmp6
, ICMPV6CTL_REDIRTIMEOUT
,
502 redirtimeout
, CTLFLAG_RW
, &icmp6_redirtimeout
, 0, "");
503 SYSCTL_STRUCT(_net_inet6_icmp6
, ICMPV6CTL_STATS
, stats
, CTLFLAG_RD
,
504 &icmp6stat
, icmp6stat
, "");
505 SYSCTL_INT(_net_inet6_icmp6
, ICMPV6CTL_ND6_PRUNE
,
506 nd6_prune
, CTLFLAG_RW
, &nd6_prune
, 0, "");
507 SYSCTL_INT(_net_inet6_icmp6
, ICMPV6CTL_ND6_DELAY
,
508 nd6_delay
, CTLFLAG_RW
, &nd6_delay
, 0, "");
509 SYSCTL_INT(_net_inet6_icmp6
, ICMPV6CTL_ND6_UMAXTRIES
,
510 nd6_umaxtries
, CTLFLAG_RW
, &nd6_umaxtries
, 0, "");
511 SYSCTL_INT(_net_inet6_icmp6
, ICMPV6CTL_ND6_MMAXTRIES
,
512 nd6_mmaxtries
, CTLFLAG_RW
, &nd6_mmaxtries
, 0, "");
513 SYSCTL_INT(_net_inet6_icmp6
, ICMPV6CTL_ND6_USELOOPBACK
,
514 nd6_useloopback
, CTLFLAG_RW
, &nd6_useloopback
, 0, "");
515 SYSCTL_INT(_net_inet6_icmp6
, ICMPV6CTL_NODEINFO
,
516 nodeinfo
, CTLFLAG_RW
, &icmp6_nodeinfo
, 0, "");
517 SYSCTL_INT(_net_inet6_icmp6
, ICMPV6CTL_ERRPPSLIMIT
,
518 errppslimit
, CTLFLAG_RW
, &icmp6errppslim
, 0, "");
519 SYSCTL_INT(_net_inet6_icmp6
, ICMPV6CTL_ND6_MAXNUDHINT
,
520 nd6_maxnudhint
, CTLFLAG_RW
, &nd6_maxnudhint
, 0, "");
521 SYSCTL_INT(_net_inet6_icmp6
, ICMPV6CTL_ND6_DEBUG
,
522 nd6_debug
, CTLFLAG_RW
, &nd6_debug
, 0, "");