1 /* $OpenBSD: in6_proto.c,v 1.63 2012/03/15 14:11:57 mikeb Exp $ */ 2 /* $KAME: in6_proto.c,v 1.66 2000/10/10 15:35:47 itojun Exp $ */ 3 4 /* 5 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 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. 19 * 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 30 * SUCH DAMAGE. 31 */ 32 33 /* 34 * Copyright (c) 1982, 1986, 1993 35 * The Regents of the University of California. All rights reserved. 36 * 37 * Redistribution and use in source and binary forms, with or without 38 * modification, are permitted provided that the following conditions 39 * are met: 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. Neither the name of the University nor the names of its contributors 46 * may be used to endorse or promote products derived from this software 47 * without specific prior written permission. 48 * 49 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 50 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 51 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 52 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 53 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 54 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 55 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 56 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 57 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 58 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 59 * SUCH DAMAGE. 60 * 61 * @(#)in_proto.c 8.1 (Berkeley) 6/10/93 62 */ 63 64 #include <sys/param.h> 65 #include <sys/socket.h> 66 #include <sys/protosw.h> 67 #include <sys/kernel.h> 68 #include <sys/domain.h> 69 #include <sys/mbuf.h> 70 71 #include <net/if.h> 72 #include <net/radix.h> 73 #ifndef SMALL_KERNEL 74 #include <net/radix_mpath.h> 75 #endif 76 #include <net/route.h> 77 78 #include <netinet/in.h> 79 #include <netinet/in_systm.h> 80 #include <netinet/in_var.h> 81 #include <netinet/ip.h> 82 #include <netinet/ip_var.h> 83 #include <netinet/in_pcb.h> 84 #include <netinet/ip6.h> 85 #include <netinet6/ip6_var.h> 86 #include <netinet/icmp6.h> 87 88 #include <netinet/tcp.h> 89 #include <netinet/tcp_timer.h> 90 #include <netinet/tcp_var.h> 91 #include <netinet/udp.h> 92 #include <netinet/udp_var.h> 93 #include <netinet/ip_ipsp.h> 94 #include <netinet/ip_ah.h> 95 #include <netinet/ip_esp.h> 96 #include <netinet/ip_ipip.h> 97 98 #ifdef MROUTING 99 #include <netinet6/pim6_var.h> 100 #endif 101 102 #include <netinet6/nd6.h> 103 104 #include <netinet6/ip6protosw.h> 105 106 #include "gif.h" 107 #if NGIF > 0 108 #include <netinet/ip_ether.h> 109 #include <netinet6/in6_gif.h> 110 #endif 111 112 #include "carp.h" 113 #if NCARP > 0 114 #include <netinet/ip_carp.h> 115 #endif 116 117 #include "pf.h" 118 #if NPF > 0 119 #include <netinet6/ip6_divert.h> 120 #endif 121 122 /* 123 * TCP/IP protocol family: IP6, ICMP6, UDP, TCP. 124 */ 125 126 extern struct domain inet6domain; 127 128 struct ip6protosw inet6sw[] = { 129 { 0, &inet6domain, IPPROTO_IPV6, 0, 130 0, 0, 0, 0, 131 0, 132 ip6_init, 0, frag6_slowtimo, frag6_drain, 133 ip6_sysctl, 134 }, 135 { SOCK_DGRAM, &inet6domain, IPPROTO_UDP, PR_ATOMIC|PR_ADDR, 136 udp6_input, 0, udp6_ctlinput, ip6_ctloutput, 137 udp_usrreq, 0, 138 0, 0, 0, 139 udp_sysctl, 140 }, 141 { SOCK_STREAM, &inet6domain, IPPROTO_TCP, PR_CONNREQUIRED|PR_WANTRCVD|PR_ABRTACPTDIS|PR_SPLICE, 142 tcp6_input, 0, tcp6_ctlinput, tcp_ctloutput, 143 tcp_usrreq, 144 #ifdef INET /* don't call initialization and timeout routines twice */ 145 0, 0, 0, 0, 146 #else 147 tcp_init, tcp_fasttimo, tcp_slowtimo, 0, 148 #endif 149 tcp_sysctl, 150 }, 151 { SOCK_RAW, &inet6domain, IPPROTO_RAW, PR_ATOMIC|PR_ADDR, 152 rip6_input, rip6_output, rip6_ctlinput, rip6_ctloutput, 153 rip6_usrreq, 154 0, 0, 0, 0, rip6_sysctl 155 }, 156 { SOCK_RAW, &inet6domain, IPPROTO_ICMPV6, PR_ATOMIC|PR_ADDR, 157 icmp6_input, rip6_output, rip6_ctlinput, rip6_ctloutput, 158 rip6_usrreq, 159 icmp6_init, icmp6_fasttimo, 0, 0, 160 icmp6_sysctl, 161 }, 162 { SOCK_RAW, &inet6domain, IPPROTO_DSTOPTS,PR_ATOMIC|PR_ADDR, 163 dest6_input, 0, 0, 0, 164 0, 165 0, 0, 0, 0, 166 }, 167 { SOCK_RAW, &inet6domain, IPPROTO_ROUTING,PR_ATOMIC|PR_ADDR, 168 route6_input, 0, 0, 0, 169 0, 170 0, 0, 0, 0, 171 }, 172 { SOCK_RAW, &inet6domain, IPPROTO_FRAGMENT,PR_ATOMIC|PR_ADDR, 173 frag6_input, 0, 0, 0, 174 0, 175 0, 0, 0, 0, 176 }, 177 #ifdef IPSEC 178 { SOCK_RAW, &inet6domain, IPPROTO_AH, PR_ATOMIC|PR_ADDR, 179 ah6_input, 0, 0, 0, 180 0, 181 0, 0, 0, 0, 182 ah_sysctl, 183 }, 184 { SOCK_RAW, &inet6domain, IPPROTO_ESP, PR_ATOMIC|PR_ADDR, 185 esp6_input, 0, 0, 0, 186 0, 187 0, 0, 0, 0, 188 esp_sysctl, 189 }, 190 { SOCK_RAW, &inet6domain, IPPROTO_IPCOMP, PR_ATOMIC|PR_ADDR, 191 ipcomp6_input, 0, 0, 0, 192 0, 193 0, 0, 0, 0, 194 ipcomp_sysctl, 195 }, 196 #endif /* IPSEC */ 197 #if NGIF > 0 198 { SOCK_RAW, &inet6domain, IPPROTO_ETHERIP,PR_ATOMIC|PR_ADDR, 199 etherip_input6, rip6_output, 0, rip6_ctloutput, 200 rip6_usrreq, 201 0, 0, 0, 0, etherip_sysctl 202 }, 203 { SOCK_RAW, &inet6domain, IPPROTO_IPV6, PR_ATOMIC|PR_ADDR, 204 in6_gif_input, rip6_output, 0, rip6_ctloutput, 205 rip6_usrreq, /* XXX */ 206 0, 0, 0, 0, 207 }, 208 #ifdef INET 209 { SOCK_RAW, &inet6domain, IPPROTO_IPV4, PR_ATOMIC|PR_ADDR, 210 in6_gif_input, rip6_output, 0, rip6_ctloutput, 211 rip6_usrreq, /* XXX */ 212 0, 0, 0, 0, 213 }, 214 #endif /* INET */ 215 #else /* NGIF */ 216 { SOCK_RAW, &inet6domain, IPPROTO_IPV6, PR_ATOMIC|PR_ADDR, 217 ip4_input6, rip6_output, 0, rip6_ctloutput, 218 rip6_usrreq, /* XXX */ 219 0, 0, 0, 0, ipip_sysctl 220 }, 221 #ifdef INET 222 { SOCK_RAW, &inet6domain, IPPROTO_IPV4, PR_ATOMIC|PR_ADDR, 223 ip4_input6, rip6_output, 0, rip6_ctloutput, 224 rip6_usrreq, /* XXX */ 225 0, 0, 0, 0, 226 }, 227 #endif /* INET */ 228 #endif /* GIF */ 229 #ifdef MROUTING 230 { SOCK_RAW, &inet6domain, IPPROTO_PIM, PR_ATOMIC|PR_ADDR, 231 pim6_input, rip6_output, 0, rip6_ctloutput, 232 rip6_usrreq, 233 0, 0, 0, 0, pim6_sysctl 234 }, 235 #endif 236 #if NCARP > 0 237 { SOCK_RAW, &inet6domain, IPPROTO_CARP, PR_ATOMIC|PR_ADDR, 238 carp6_proto_input, rip6_output, 0, rip6_ctloutput, 239 rip6_usrreq, 240 0, 0, 0, 0, carp_sysctl 241 }, 242 #endif /* NCARP */ 243 #if NPF > 0 244 { SOCK_RAW, &inet6domain, IPPROTO_DIVERT, PR_ATOMIC|PR_ADDR, 245 divert6_input, 0, 0, rip6_ctloutput, 246 divert6_usrreq, 247 divert6_init, 0, 0, 0, divert6_sysctl 248 }, 249 #endif /* NPF > 0 */ 250 /* raw wildcard */ 251 { SOCK_RAW, &inet6domain, 0, PR_ATOMIC|PR_ADDR, 252 rip6_input, rip6_output, 0, rip6_ctloutput, 253 rip6_usrreq, rip6_init, 254 0, 0, 0, 255 }, 256 }; 257 258 struct domain inet6domain = 259 { AF_INET6, "internet6", 0, 0, 0, 260 (struct protosw *)inet6sw, 261 (struct protosw *)&inet6sw[nitems(inet6sw)], 0, 262 #ifndef SMALL_KERNEL 263 rn_mpath_inithead, 264 #else 265 rn_inithead, 266 #endif 267 offsetof(struct sockaddr_in6, sin6_addr) << 3, 268 sizeof(struct sockaddr_in6), 269 in6_domifattach, in6_domifdetach, }; 270 271 /* 272 * Internet configuration info 273 */ 274 int ip6_forwarding = 0; /* no forwarding unless sysctl'd to enable */ 275 int ip6_mforwarding = 0; /* no multicast forwarding unless ... */ 276 int ip6_multipath = 0; /* no using multipath routes unless ... */ 277 int ip6_sendredirects = 1; 278 int ip6_defhlim = IPV6_DEFHLIM; 279 int ip6_defmcasthlim = IPV6_DEFAULT_MULTICAST_HOPS; 280 int ip6_accept_rtadv = 0; /* enabling forwarding and rtadv concurrently is dangerous */ 281 int ip6_maxfragpackets = 200; 282 int ip6_maxfrags = 200; 283 int ip6_log_interval = 5; 284 int ip6_hdrnestlimit = 10; /* appropriate? */ 285 int ip6_dad_count = 1; /* DupAddrDetectionTransmits */ 286 int ip6_dad_pending; /* number of currently running DADs */ 287 int ip6_auto_flowlabel = 1; 288 int ip6_use_deprecated = 1; /* allow deprecated addr (RFC2462 5.5.4) */ 289 int ip6_rr_prune = 5; /* router renumbering prefix 290 * walk list every 5 sec. */ 291 int ip6_mcast_pmtu = 0; /* enable pMTU discovery for multicast? */ 292 const int ip6_v6only = 1; 293 int ip6_neighborgcthresh = 2048; /* Threshold # of NDP entries for GC */ 294 int ip6_maxifprefixes = 16; /* Max acceptable prefixes via RA per IF */ 295 int ip6_maxifdefrouters = 16; /* Max acceptable def routers via RA */ 296 int ip6_maxdynroutes = 4096; /* Max # of routes created via redirect */ 297 int ip6_keepfaith = 0; 298 time_t ip6_log_time = (time_t)0L; 299 300 /* icmp6 */ 301 /* 302 * BSDI4 defines these variables in in_proto.c... 303 * XXX: what if we don't define INET? Should we define pmtu6_expire 304 * or so? (jinmei@kame.net 19990310) 305 */ 306 int pmtu_expire = 60*10; 307 308 /* raw IP6 parameters */ 309 /* 310 * Nominal space allocated to a raw ip socket. 311 */ 312 #define RIPV6SNDQ 8192 313 #define RIPV6RCVQ 8192 314 315 u_long rip6_sendspace = RIPV6SNDQ; 316 u_long rip6_recvspace = RIPV6RCVQ; 317 318 /* ICMPV6 parameters */ 319 int icmp6_rediraccept = 0; /* don't process redirects by default */ 320 int icmp6_redirtimeout = 10 * 60; /* 10 minutes */ 321 int icmp6errppslim = 100; /* 100pps */ 322 int icmp6_nodeinfo = 1; /* enable/disable NI response */ 323