1 /* $OpenBSD: in6_proto.c,v 1.72 2014/07/11 16:39:06 henning 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/ip.h> 81 #include <netinet/ip_var.h> 82 #include <netinet/in_pcb.h> 83 #include <netinet/ip6.h> 84 #include <netinet6/ip6_var.h> 85 #include <netinet/icmp6.h> 86 87 #include <netinet/tcp.h> 88 #include <netinet/tcp_timer.h> 89 #include <netinet/tcp_var.h> 90 #include <netinet/udp.h> 91 #include <netinet/udp_var.h> 92 #include <netinet/ip_ipsp.h> 93 #include <netinet/ip_ah.h> 94 #include <netinet/ip_esp.h> 95 #include <netinet/ip_ipip.h> 96 97 #ifdef MROUTING 98 #include <netinet6/pim6_var.h> 99 #endif 100 101 #include <netinet6/in6_var.h> 102 #include <netinet6/nd6.h> 103 #include <netinet6/ip6protosw.h> 104 105 #include "gif.h" 106 #if NGIF > 0 107 #include <netinet/ip_ether.h> 108 #include <netinet6/in6_gif.h> 109 #endif 110 111 #include "carp.h" 112 #if NCARP > 0 113 #include <netinet/ip_carp.h> 114 #endif 115 116 #include "pf.h" 117 #if NPF > 0 118 #include <netinet6/ip6_divert.h> 119 #endif 120 121 /* 122 * TCP/IP protocol family: IP6, ICMP6, UDP, TCP. 123 */ 124 u_char ip6_protox[IPPROTO_MAX]; 125 126 struct ip6protosw inet6sw[] = { 127 { 0, &inet6domain, IPPROTO_IPV6, 0, 128 0, 0, 0, 0, 129 0, 130 ip6_init, 0, frag6_slowtimo, frag6_drain, 131 ip6_sysctl, 132 }, 133 { SOCK_DGRAM, &inet6domain, IPPROTO_UDP, PR_ATOMIC|PR_ADDR|PR_SPLICE, 134 udp6_input, 0, udp6_ctlinput, ip6_ctloutput, 135 udp_usrreq, 0, 136 0, 0, 0, 137 udp_sysctl, 138 }, 139 { SOCK_STREAM, &inet6domain, IPPROTO_TCP, PR_CONNREQUIRED|PR_WANTRCVD|PR_ABRTACPTDIS|PR_SPLICE, 140 tcp6_input, 0, tcp6_ctlinput, tcp_ctloutput, 141 tcp_usrreq, 142 #ifdef INET /* don't call initialization and timeout routines twice */ 143 0, 0, 0, 0, 144 #else 145 tcp_init, tcp_fasttimo, tcp_slowtimo, 0, 146 #endif 147 tcp_sysctl, 148 }, 149 { SOCK_RAW, &inet6domain, IPPROTO_RAW, PR_ATOMIC|PR_ADDR, 150 rip6_input, rip6_output, rip6_ctlinput, rip6_ctloutput, 151 rip6_usrreq, 152 0, 0, 0, 0, rip6_sysctl 153 }, 154 { SOCK_RAW, &inet6domain, IPPROTO_ICMPV6, PR_ATOMIC|PR_ADDR, 155 icmp6_input, rip6_output, rip6_ctlinput, rip6_ctloutput, 156 rip6_usrreq, 157 icmp6_init, icmp6_fasttimo, 0, 0, 158 icmp6_sysctl, 159 }, 160 { SOCK_RAW, &inet6domain, IPPROTO_DSTOPTS,PR_ATOMIC|PR_ADDR, 161 dest6_input, 0, 0, 0, 162 0, 163 0, 0, 0, 0, 164 }, 165 { SOCK_RAW, &inet6domain, IPPROTO_ROUTING,PR_ATOMIC|PR_ADDR, 166 route6_input, 0, 0, 0, 167 0, 168 0, 0, 0, 0, 169 }, 170 { SOCK_RAW, &inet6domain, IPPROTO_FRAGMENT,PR_ATOMIC|PR_ADDR, 171 frag6_input, 0, 0, 0, 172 0, 173 0, 0, 0, 0, 174 }, 175 #ifdef IPSEC 176 { SOCK_RAW, &inet6domain, IPPROTO_AH, PR_ATOMIC|PR_ADDR, 177 ah6_input, rip6_output, 0, rip6_ctloutput, 178 rip6_usrreq, 179 0, 0, 0, 0, 180 ah_sysctl, 181 }, 182 { SOCK_RAW, &inet6domain, IPPROTO_ESP, PR_ATOMIC|PR_ADDR, 183 esp6_input, rip6_output, 0, rip6_ctloutput, 184 rip6_usrreq, 185 0, 0, 0, 0, 186 esp_sysctl, 187 }, 188 { SOCK_RAW, &inet6domain, IPPROTO_IPCOMP, PR_ATOMIC|PR_ADDR, 189 ipcomp6_input, rip6_output, 0, rip6_ctloutput, 190 rip6_usrreq, 191 0, 0, 0, 0, 192 ipcomp_sysctl, 193 }, 194 #endif /* IPSEC */ 195 #if NGIF > 0 196 { SOCK_RAW, &inet6domain, IPPROTO_ETHERIP,PR_ATOMIC|PR_ADDR, 197 etherip_input6, rip6_output, 0, rip6_ctloutput, 198 rip6_usrreq, 199 0, 0, 0, 0, etherip_sysctl 200 }, 201 { SOCK_RAW, &inet6domain, IPPROTO_IPV6, PR_ATOMIC|PR_ADDR, 202 in6_gif_input, rip6_output, 0, rip6_ctloutput, 203 rip6_usrreq, /* XXX */ 204 0, 0, 0, 0, 205 }, 206 #ifdef INET 207 { SOCK_RAW, &inet6domain, IPPROTO_IPV4, PR_ATOMIC|PR_ADDR, 208 in6_gif_input, rip6_output, 0, rip6_ctloutput, 209 rip6_usrreq, /* XXX */ 210 0, 0, 0, 0, 211 }, 212 #endif /* INET */ 213 #else /* NGIF */ 214 { SOCK_RAW, &inet6domain, IPPROTO_IPV6, PR_ATOMIC|PR_ADDR, 215 ip4_input6, rip6_output, 0, rip6_ctloutput, 216 rip6_usrreq, /* XXX */ 217 0, 0, 0, 0, ipip_sysctl 218 }, 219 #ifdef INET 220 { SOCK_RAW, &inet6domain, IPPROTO_IPV4, PR_ATOMIC|PR_ADDR, 221 ip4_input6, rip6_output, 0, rip6_ctloutput, 222 rip6_usrreq, /* XXX */ 223 0, 0, 0, 0, 224 }, 225 #endif /* INET */ 226 #endif /* GIF */ 227 #ifdef MROUTING 228 { SOCK_RAW, &inet6domain, IPPROTO_PIM, PR_ATOMIC|PR_ADDR, 229 pim6_input, rip6_output, 0, rip6_ctloutput, 230 rip6_usrreq, 231 0, 0, 0, 0, pim6_sysctl 232 }, 233 #endif 234 #if NCARP > 0 235 { SOCK_RAW, &inet6domain, IPPROTO_CARP, PR_ATOMIC|PR_ADDR, 236 carp6_proto_input, rip6_output, 0, rip6_ctloutput, 237 rip6_usrreq, 238 0, 0, 0, 0, carp_sysctl 239 }, 240 #endif /* NCARP */ 241 #if NPF > 0 242 { SOCK_RAW, &inet6domain, IPPROTO_DIVERT, PR_ATOMIC|PR_ADDR, 243 divert6_input, 0, 0, rip6_ctloutput, 244 divert6_usrreq, 245 divert6_init, 0, 0, 0, divert6_sysctl 246 }, 247 #endif /* NPF > 0 */ 248 /* raw wildcard */ 249 { SOCK_RAW, &inet6domain, 0, PR_ATOMIC|PR_ADDR, 250 rip6_input, rip6_output, 0, rip6_ctloutput, 251 rip6_usrreq, rip6_init, 252 0, 0, 0, 253 }, 254 }; 255 256 struct domain inet6domain = 257 { AF_INET6, "internet6", 0, 0, 0, 258 (struct protosw *)inet6sw, 259 (struct protosw *)&inet6sw[nitems(inet6sw)], 0, 260 #ifndef SMALL_KERNEL 261 rn_mpath_inithead, 262 #else 263 rn_inithead, 264 #endif 265 offsetof(struct sockaddr_in6, sin6_addr) << 3, 266 sizeof(struct sockaddr_in6), 267 in6_domifattach, in6_domifdetach, }; 268 269 /* 270 * Internet configuration info 271 */ 272 int ip6_forwarding = 0; /* no forwarding unless sysctl'd to enable */ 273 int ip6_mforwarding = 0; /* no multicast forwarding unless ... */ 274 int ip6_multipath = 0; /* no using multipath routes unless ... */ 275 int ip6_sendredirects = 1; 276 int ip6_defhlim = IPV6_DEFHLIM; 277 int ip6_defmcasthlim = IPV6_DEFAULT_MULTICAST_HOPS; 278 int ip6_maxfragpackets = 200; 279 int ip6_maxfrags = 200; 280 int ip6_log_interval = 5; 281 int ip6_hdrnestlimit = 10; /* appropriate? */ 282 int ip6_dad_count = 1; /* DupAddrDetectionTransmits */ 283 int ip6_dad_pending; /* number of currently running DADs */ 284 int ip6_auto_flowlabel = 1; 285 int ip6_use_deprecated = 1; /* allow deprecated addr (RFC2462 5.5.4) */ 286 int ip6_rr_prune = 5; /* router renumbering prefix 287 * walk list every 5 sec. */ 288 int ip6_mcast_pmtu = 0; /* enable pMTU discovery for multicast? */ 289 const int ip6_v6only = 1; 290 int ip6_neighborgcthresh = 2048; /* Threshold # of NDP entries for GC */ 291 int ip6_maxifprefixes = 16; /* Max acceptable prefixes via RA per IF */ 292 int ip6_maxifdefrouters = 16; /* Max acceptable def routers via RA */ 293 int ip6_maxdynroutes = 4096; /* Max # of routes created via redirect */ 294 time_t ip6_log_time = (time_t)0L; 295 296 /* raw IP6 parameters */ 297 /* 298 * Nominal space allocated to a raw ip socket. 299 */ 300 #define RIPV6SNDQ 8192 301 #define RIPV6RCVQ 8192 302 303 u_long rip6_sendspace = RIPV6SNDQ; 304 u_long rip6_recvspace = RIPV6RCVQ; 305 306 /* ICMPV6 parameters */ 307 int icmp6_rediraccept = 0; /* don't process redirects by default */ 308 int icmp6_redirtimeout = 10 * 60; /* 10 minutes */ 309 int icmp6errppslim = 100; /* 100pps */ 310 int ip6_mtudisc_timeout = IPMTUDISCTIMEOUT; 311