1 /* $OpenBSD: in6_proto.c,v 1.119 2024/08/20 07:46:27 mvs 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/if_var.h> 73 #include <net/route.h> 74 #include <net/rtable.h> 75 76 #include <netinet/in.h> 77 #include <netinet/ip.h> 78 #include <netinet/ip_var.h> 79 #include <netinet/in_pcb.h> 80 #include <netinet/ip6.h> 81 #include <netinet6/ip6_var.h> 82 #include <netinet/icmp6.h> 83 84 #include <netinet/tcp.h> 85 #include <netinet/tcp_timer.h> 86 #include <netinet/tcp_var.h> 87 #include <netinet/udp.h> 88 #include <netinet/udp_var.h> 89 #include <netinet/ip_ipsp.h> 90 #include <netinet/ip_ah.h> 91 #include <netinet/ip_esp.h> 92 #include <netinet/ip_ipip.h> 93 94 #include <netinet6/in6_var.h> 95 #include <netinet6/nd6.h> 96 97 #include "gif.h" 98 #if NGIF > 0 99 #include <net/if_gif.h> 100 #endif 101 102 #include "carp.h" 103 #if NCARP > 0 104 #include <netinet/ip_carp.h> 105 #endif 106 107 #include "pf.h" 108 #if NPF > 0 109 #include <netinet6/ip6_divert.h> 110 #endif 111 112 #include "etherip.h" 113 #if NETHERIP > 0 114 #include <net/if_etherip.h> 115 #endif 116 117 #include "gre.h" 118 #if NGRE > 0 119 #include <net/if_gre.h> 120 #endif 121 122 /* 123 * TCP/IP protocol family: IP6, ICMP6, UDP, TCP. 124 */ 125 u_char ip6_protox[IPPROTO_MAX]; 126 127 const struct protosw inet6sw[] = { 128 { 129 .pr_domain = &inet6domain, 130 .pr_protocol = IPPROTO_IPV6, 131 .pr_init = ip6_init, 132 .pr_slowtimo = frag6_slowtimo, 133 .pr_sysctl = ip6_sysctl 134 }, 135 { 136 .pr_type = SOCK_DGRAM, 137 .pr_domain = &inet6domain, 138 .pr_protocol = IPPROTO_UDP, 139 .pr_flags = PR_ATOMIC|PR_ADDR|PR_SPLICE|PR_MPINPUT|PR_MPSOCKET, 140 .pr_input = udp_input, 141 .pr_ctlinput = udp6_ctlinput, 142 .pr_ctloutput = ip6_ctloutput, 143 .pr_usrreqs = &udp6_usrreqs, 144 .pr_sysctl = udp_sysctl 145 }, 146 { 147 .pr_type = SOCK_STREAM, 148 .pr_domain = &inet6domain, 149 .pr_protocol = IPPROTO_TCP, 150 .pr_flags = PR_CONNREQUIRED|PR_WANTRCVD|PR_ABRTACPTDIS|PR_SPLICE, 151 .pr_input = tcp_input, 152 .pr_ctlinput = tcp6_ctlinput, 153 .pr_ctloutput = tcp_ctloutput, 154 .pr_usrreqs = &tcp6_usrreqs, 155 .pr_sysctl = tcp_sysctl 156 }, 157 { 158 .pr_type = SOCK_RAW, 159 .pr_domain = &inet6domain, 160 .pr_protocol = IPPROTO_RAW, 161 .pr_flags = PR_ATOMIC|PR_ADDR|PR_MPINPUT|PR_MPSOCKET|PR_MPSYSCTL, 162 .pr_input = rip6_input, 163 .pr_ctlinput = rip6_ctlinput, 164 .pr_ctloutput = rip6_ctloutput, 165 .pr_usrreqs = &rip6_usrreqs, 166 .pr_sysctl = rip6_sysctl 167 }, 168 { 169 .pr_type = SOCK_RAW, 170 .pr_domain = &inet6domain, 171 .pr_protocol = IPPROTO_ICMPV6, 172 .pr_flags = PR_ATOMIC|PR_ADDR|PR_MPSOCKET, 173 .pr_input = icmp6_input, 174 .pr_ctlinput = rip6_ctlinput, 175 .pr_ctloutput = rip6_ctloutput, 176 .pr_usrreqs = &rip6_usrreqs, 177 .pr_init = icmp6_init, 178 .pr_fasttimo = icmp6_fasttimo, 179 .pr_sysctl = icmp6_sysctl 180 }, 181 { 182 .pr_type = SOCK_RAW, 183 .pr_domain = &inet6domain, 184 .pr_protocol = IPPROTO_DSTOPTS, 185 .pr_flags = PR_ATOMIC|PR_ADDR, 186 .pr_input = dest6_input 187 }, 188 { 189 .pr_type = SOCK_RAW, 190 .pr_domain = &inet6domain, 191 .pr_protocol = IPPROTO_ROUTING, 192 .pr_flags = PR_ATOMIC|PR_ADDR, 193 .pr_input = route6_input 194 }, 195 { 196 .pr_type = SOCK_RAW, 197 .pr_domain = &inet6domain, 198 .pr_protocol = IPPROTO_FRAGMENT, 199 .pr_flags = PR_ATOMIC|PR_ADDR, 200 .pr_input = frag6_input 201 }, 202 #ifdef IPSEC 203 { 204 .pr_type = SOCK_RAW, 205 .pr_domain = &inet6domain, 206 .pr_protocol = IPPROTO_AH, 207 .pr_flags = PR_ATOMIC|PR_ADDR|PR_MPSOCKET, 208 .pr_input = ah46_input, 209 .pr_ctloutput = rip6_ctloutput, 210 .pr_usrreqs = &rip6_usrreqs, 211 .pr_sysctl = ah_sysctl 212 }, 213 { 214 .pr_type = SOCK_RAW, 215 .pr_domain = &inet6domain, 216 .pr_protocol = IPPROTO_ESP, 217 .pr_flags = PR_ATOMIC|PR_ADDR|PR_MPSOCKET, 218 .pr_input = esp46_input, 219 .pr_ctloutput = rip6_ctloutput, 220 .pr_usrreqs = &rip6_usrreqs, 221 .pr_sysctl = esp_sysctl 222 }, 223 { 224 .pr_type = SOCK_RAW, 225 .pr_domain = &inet6domain, 226 .pr_protocol = IPPROTO_IPCOMP, 227 .pr_flags = PR_ATOMIC|PR_ADDR|PR_MPSOCKET, 228 .pr_input = ipcomp46_input, 229 .pr_ctloutput = rip6_ctloutput, 230 .pr_usrreqs = &rip6_usrreqs, 231 .pr_sysctl = ipcomp_sysctl 232 }, 233 #endif /* IPSEC */ 234 { 235 .pr_type = SOCK_RAW, 236 .pr_domain = &inet6domain, 237 .pr_protocol = IPPROTO_IPV4, 238 .pr_flags = PR_ATOMIC|PR_ADDR|PR_MPSOCKET, 239 #if NGIF > 0 240 .pr_input = in6_gif_input, 241 #else 242 .pr_input = ipip_input, 243 #endif 244 .pr_ctloutput = rip6_ctloutput, 245 .pr_usrreqs = &rip6_usrreqs, /* XXX */ 246 }, 247 { 248 .pr_type = SOCK_RAW, 249 .pr_domain = &inet6domain, 250 .pr_protocol = IPPROTO_IPV6, 251 .pr_flags = PR_ATOMIC|PR_ADDR|PR_MPSOCKET, 252 #if NGIF > 0 253 .pr_input = in6_gif_input, 254 #else 255 .pr_input = ipip_input, 256 #endif 257 .pr_ctloutput = rip6_ctloutput, 258 .pr_usrreqs = &rip6_usrreqs, /* XXX */ 259 }, 260 #if defined(MPLS) && NGIF > 0 261 { 262 .pr_type = SOCK_RAW, 263 .pr_domain = &inet6domain, 264 .pr_protocol = IPPROTO_MPLS, 265 .pr_flags = PR_ATOMIC|PR_ADDR|PR_MPSOCKET, 266 #if NGIF > 0 267 .pr_input = in6_gif_input, 268 #else 269 .pr_input = ipip_input, 270 #endif 271 .pr_ctloutput = rip6_ctloutput, 272 .pr_usrreqs = &rip6_usrreqs, /* XXX */ 273 }, 274 #endif /* MPLS */ 275 #if NCARP > 0 276 { 277 .pr_type = SOCK_RAW, 278 .pr_domain = &inet6domain, 279 .pr_protocol = IPPROTO_CARP, 280 .pr_flags = PR_ATOMIC|PR_ADDR|PR_MPSOCKET, 281 .pr_input = carp6_proto_input, 282 .pr_ctloutput = rip6_ctloutput, 283 .pr_usrreqs = &rip6_usrreqs, 284 .pr_sysctl = carp_sysctl 285 }, 286 #endif /* NCARP */ 287 #if NPF > 0 288 { 289 .pr_type = SOCK_RAW, 290 .pr_domain = &inet6domain, 291 .pr_protocol = IPPROTO_DIVERT, 292 .pr_flags = PR_ATOMIC|PR_ADDR|PR_MPSOCKET|PR_MPSYSCTL, 293 .pr_ctloutput = rip6_ctloutput, 294 .pr_usrreqs = &divert6_usrreqs, 295 .pr_init = divert6_init, 296 .pr_sysctl = divert6_sysctl 297 }, 298 #endif /* NPF > 0 */ 299 #if NETHERIP > 0 300 { 301 .pr_type = SOCK_RAW, 302 .pr_domain = &inet6domain, 303 .pr_protocol = IPPROTO_ETHERIP, 304 .pr_flags = PR_ATOMIC|PR_ADDR|PR_MPSOCKET, 305 .pr_input = ip6_etherip_input, 306 .pr_ctloutput = rip6_ctloutput, 307 .pr_usrreqs = &rip6_usrreqs, 308 }, 309 #endif /* NETHERIP */ 310 #if NGRE > 0 311 { 312 .pr_type = SOCK_RAW, 313 .pr_domain = &inet6domain, 314 .pr_protocol = IPPROTO_GRE, 315 .pr_flags = PR_ATOMIC|PR_ADDR|PR_MPSOCKET, 316 .pr_input = gre_input6, 317 .pr_ctloutput = rip6_ctloutput, 318 .pr_usrreqs = &rip6_usrreqs, 319 }, 320 #endif /* NGRE */ 321 { 322 /* raw wildcard */ 323 .pr_type = SOCK_RAW, 324 .pr_domain = &inet6domain, 325 .pr_flags = PR_ATOMIC|PR_ADDR|PR_MPINPUT|PR_MPSOCKET, 326 .pr_input = rip6_input, 327 .pr_ctloutput = rip6_ctloutput, 328 .pr_usrreqs = &rip6_usrreqs, 329 .pr_init = rip6_init 330 } 331 }; 332 333 const struct domain inet6domain = { 334 .dom_family = AF_INET6, 335 .dom_name = "inet6", 336 .dom_protosw = inet6sw, 337 .dom_protoswNPROTOSW = &inet6sw[nitems(inet6sw)], 338 .dom_sasize = sizeof(struct sockaddr_in6), 339 .dom_rtoffset = offsetof(struct sockaddr_in6, sin6_addr), 340 .dom_maxplen = 128, 341 }; 342 343 /* 344 * Internet configuration info 345 */ 346 int ip6_forwarding = 0; /* [a] no forwarding unless sysctl to enable */ 347 int ip6_mforwarding = 0; /* no multicast forwarding unless ... */ 348 int ip6_multipath = 0; /* no using multipath routes unless ... */ 349 int ip6_sendredirects = 1; /* [a] */ 350 int ip6_defhlim = IPV6_DEFHLIM; 351 int ip6_defmcasthlim = IPV6_DEFAULT_MULTICAST_HOPS; 352 int ip6_maxfragpackets = 200; 353 int ip6_maxfrags = 200; 354 int ip6_log_interval = 5; 355 int ip6_hdrnestlimit = 10; /* appropriate? */ 356 int ip6_dad_count = 1; /* DupAddrDetectionTransmits */ 357 int ip6_dad_pending; /* number of currently running DADs */ 358 int ip6_auto_flowlabel = 1; 359 int ip6_use_deprecated = 1; /* allow deprecated addr (RFC2462 5.5.4) */ 360 int ip6_mcast_pmtu = 0; /* enable pMTU discovery for multicast? */ 361 int ip6_neighborgcthresh = 2048; /* Threshold # of NDP entries for GC */ 362 int ip6_maxdynroutes = 4096; /* Max # of routes created via redirect */ 363 time_t ip6_log_time = (time_t)0L; 364 365 /* raw IP6 parameters */ 366 /* 367 * Nominal space allocated to a raw ip socket. 368 */ 369 #define RIPV6SNDQ 8192 370 #define RIPV6RCVQ 8192 371 372 u_long rip6_sendspace = RIPV6SNDQ; 373 u_long rip6_recvspace = RIPV6RCVQ; 374 375 /* ICMPV6 parameters */ 376 int icmp6_redirtimeout = 10 * 60; /* 10 minutes */ 377 int icmp6errppslim = 100; /* 100pps */ 378 int ip6_mtudisc_timeout = IPMTUDISCTIMEOUT; 379