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