1 /* $OpenBSD: in_proto.c,v 1.70 2015/12/03 21:57:59 mpi Exp $ */ 2 /* $NetBSD: in_proto.c,v 1.14 1996/02/18 18:58:32 christos 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 * @(#)COPYRIGHT 1.1 (NRL) 17 January 1995 62 * 63 * NRL grants permission for redistribution and use in source and binary 64 * forms, with or without modification, of the software and documentation 65 * created at NRL provided that the following conditions are met: 66 * 67 * 1. Redistributions of source code must retain the above copyright 68 * notice, this list of conditions and the following disclaimer. 69 * 2. Redistributions in binary form must reproduce the above copyright 70 * notice, this list of conditions and the following disclaimer in the 71 * documentation and/or other materials provided with the distribution. 72 * 3. All advertising materials mentioning features or use of this software 73 * must display the following acknowledgements: 74 * This product includes software developed by the University of 75 * California, Berkeley and its contributors. 76 * This product includes software developed at the Information 77 * Technology Division, US Naval Research Laboratory. 78 * 4. Neither the name of the NRL nor the names of its contributors 79 * may be used to endorse or promote products derived from this software 80 * without specific prior written permission. 81 * 82 * THE SOFTWARE PROVIDED BY NRL IS PROVIDED BY NRL AND CONTRIBUTORS ``AS 83 * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 84 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 85 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NRL OR 86 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 87 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 88 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 89 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 90 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 91 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 92 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 93 * 94 * The views and conclusions contained in the software and documentation 95 * are those of the authors and should not be interpreted as representing 96 * official policies, either expressed or implied, of the US Naval 97 * Research Laboratory (NRL). 98 */ 99 100 #include <sys/param.h> 101 #include <sys/socket.h> 102 #include <sys/protosw.h> 103 #include <sys/domain.h> 104 #include <sys/mbuf.h> 105 106 #include <net/if.h> 107 #include <net/if_var.h> 108 #include <net/route.h> 109 #include <net/rtable.h> 110 111 #include <netinet/in.h> 112 #include <netinet/ip.h> 113 #include <netinet/ip_var.h> 114 #include <netinet/ip_icmp.h> 115 #include <netinet/in_pcb.h> 116 117 #ifdef INET6 118 #include <netinet/ip6.h> 119 #endif 120 121 #include <netinet/igmp_var.h> 122 #ifdef PIM 123 #include <netinet/pim_var.h> 124 #endif 125 #include <netinet/tcp.h> 126 #include <netinet/tcp_timer.h> 127 #include <netinet/tcp_var.h> 128 #include <netinet/udp.h> 129 #include <netinet/udp_var.h> 130 131 /* 132 * TCP/IP protocol family: IP, ICMP, UDP, TCP. 133 */ 134 135 #include "gif.h" 136 #if NGIF > 0 137 #include <net/if_gif.h> 138 #endif 139 140 #ifdef INET6 141 #include <netinet6/ip6_var.h> 142 #endif /* INET6 */ 143 144 #ifdef IPSEC 145 #include <netinet/ip_ipsp.h> 146 #endif 147 148 #include <netinet/ip_ether.h> 149 #include <netinet/ip_ipip.h> 150 151 #include "gre.h" 152 #if NGRE > 0 153 #include <netinet/ip_gre.h> 154 #include <net/if_gre.h> 155 #endif 156 157 #include "carp.h" 158 #if NCARP > 0 159 #include <netinet/ip_carp.h> 160 #endif 161 162 #include "pfsync.h" 163 #if NPFSYNC > 0 164 #include <net/pfvar.h> 165 #include <net/if_pfsync.h> 166 #endif 167 168 #include "pf.h" 169 #if NPF > 0 170 #include <netinet/ip_divert.h> 171 #endif 172 173 #include "etherip.h" 174 #if NETHERIP > 0 175 #include <net/if_etherip.h> 176 #endif 177 178 u_char ip_protox[IPPROTO_MAX]; 179 180 struct protosw inetsw[] = { 181 { 0, &inetdomain, 0, 0, 182 0, 0, 0, 0, 183 0, 184 ip_init, 0, ip_slowtimo, ip_drain, ip_sysctl 185 }, 186 { SOCK_DGRAM, &inetdomain, IPPROTO_UDP, PR_ATOMIC|PR_ADDR|PR_SPLICE, 187 udp_input, 0, udp_ctlinput, ip_ctloutput, 188 udp_usrreq, 189 udp_init, 0, 0, 0, udp_sysctl 190 }, 191 { SOCK_STREAM, &inetdomain, IPPROTO_TCP, PR_CONNREQUIRED|PR_WANTRCVD|PR_ABRTACPTDIS|PR_SPLICE, 192 tcp_input, 0, tcp_ctlinput, tcp_ctloutput, 193 tcp_usrreq, 194 tcp_init, 0, tcp_slowtimo, 0, tcp_sysctl 195 }, 196 { SOCK_RAW, &inetdomain, IPPROTO_RAW, PR_ATOMIC|PR_ADDR, 197 rip_input, rip_output, 0, rip_ctloutput, 198 rip_usrreq, 199 0, 0, 0, 0, 200 }, 201 { SOCK_RAW, &inetdomain, IPPROTO_ICMP, PR_ATOMIC|PR_ADDR, 202 icmp_input, rip_output, 0, rip_ctloutput, 203 rip_usrreq, 204 icmp_init, 0, 0, 0, icmp_sysctl 205 }, 206 #if NGIF > 0 207 { SOCK_RAW, &inetdomain, IPPROTO_IPV4, PR_ATOMIC|PR_ADDR, 208 in_gif_input, rip_output, 0, rip_ctloutput, 209 rip_usrreq, 210 0, 0, 0, 0, ipip_sysctl 211 }, 212 { SOCK_RAW, &inetdomain, IPPROTO_ETHERIP, PR_ATOMIC|PR_ADDR, 213 etherip_input, rip_output, 0, rip_ctloutput, 214 rip_usrreq, 215 0, 0, 0, 0, etherip_sysctl 216 }, 217 #ifdef INET6 218 { SOCK_RAW, &inetdomain, IPPROTO_IPV6, PR_ATOMIC|PR_ADDR, 219 in_gif_input, rip_output, 0, 0, 220 rip_usrreq, /*XXX*/ 221 0, 0, 0, 0, 222 }, 223 #endif 224 #ifdef MPLS 225 { SOCK_RAW, &inetdomain, IPPROTO_MPLS, PR_ATOMIC|PR_ADDR, 226 etherip_input, rip_output, 0, 0, 227 rip_usrreq, 228 0, 0, 0, 0, 229 }, 230 #endif 231 #else /* NGIF */ 232 { SOCK_RAW, &inetdomain, IPPROTO_IPIP, PR_ATOMIC|PR_ADDR, 233 ip4_input, rip_output, 0, rip_ctloutput, 234 rip_usrreq, 235 0, 0, 0, 0, ipip_sysctl 236 }, 237 #ifdef INET6 238 { SOCK_RAW, &inetdomain, IPPROTO_IPV6, PR_ATOMIC|PR_ADDR, 239 ip4_input, rip_output, 0, rip_ctloutput, 240 rip_usrreq, /*XXX*/ 241 0, 0, 0, 0, 242 }, 243 #endif 244 #endif /*NGIF*/ 245 { SOCK_RAW, &inetdomain, IPPROTO_IGMP, PR_ATOMIC|PR_ADDR, 246 igmp_input, rip_output, 0, rip_ctloutput, 247 rip_usrreq, 248 igmp_init, igmp_fasttimo, igmp_slowtimo, 0, igmp_sysctl 249 }, 250 #ifdef PIM 251 { SOCK_RAW, &inetdomain, IPPROTO_PIM, PR_ATOMIC|PR_ADDR, 252 pim_input, rip_output, 0, rip_ctloutput, 253 rip_usrreq, 254 0, 0, 0, 0, pim_sysctl 255 }, 256 #endif /* PIM */ 257 #ifdef IPSEC 258 { SOCK_RAW, &inetdomain, IPPROTO_AH, PR_ATOMIC|PR_ADDR, 259 ah4_input, rip_output, ah4_ctlinput, rip_ctloutput, 260 rip_usrreq, 261 0, 0, 0, 0, ah_sysctl 262 }, 263 { SOCK_RAW, &inetdomain, IPPROTO_ESP, PR_ATOMIC|PR_ADDR, 264 esp4_input, rip_output, esp4_ctlinput, rip_ctloutput, 265 rip_usrreq, 266 0, 0, 0, 0, esp_sysctl 267 }, 268 { SOCK_RAW, &inetdomain, IPPROTO_IPCOMP, PR_ATOMIC|PR_ADDR, 269 ipcomp4_input, rip_output, 0, rip_ctloutput, 270 rip_usrreq, 271 0, 0, 0, 0, ipcomp_sysctl 272 }, 273 #endif /* IPSEC */ 274 #if NGRE > 0 275 { SOCK_RAW, &inetdomain, IPPROTO_GRE, PR_ATOMIC|PR_ADDR, 276 gre_input, rip_output, 0, rip_ctloutput, 277 gre_usrreq, 278 0, 0, 0, 0, gre_sysctl 279 }, 280 { SOCK_RAW, &inetdomain, IPPROTO_MOBILE, PR_ATOMIC|PR_ADDR, 281 gre_mobile_input, rip_output, 0, rip_ctloutput, 282 rip_usrreq, 283 0, 0, 0, 0, ipmobile_sysctl 284 }, 285 #endif /* NGRE > 0 */ 286 #if NCARP > 0 287 { SOCK_RAW, &inetdomain, IPPROTO_CARP, PR_ATOMIC|PR_ADDR, 288 carp_proto_input, rip_output, 0, rip_ctloutput, 289 rip_usrreq, 290 0, 0, 0, 0, carp_sysctl 291 }, 292 #endif /* NCARP > 0 */ 293 #if NPFSYNC > 0 294 { SOCK_RAW, &inetdomain, IPPROTO_PFSYNC, PR_ATOMIC|PR_ADDR, 295 pfsync_input, rip_output, 0, rip_ctloutput, 296 rip_usrreq, 297 0, 0, 0, 0, pfsync_sysctl 298 }, 299 #endif /* NPFSYNC > 0 */ 300 #if NPF > 0 301 { SOCK_RAW, &inetdomain, IPPROTO_DIVERT, PR_ATOMIC|PR_ADDR, 302 divert_input, 0, 0, rip_ctloutput, 303 divert_usrreq, 304 divert_init, 0, 0, 0, divert_sysctl 305 }, 306 #endif /* NPF > 0 */ 307 #if NETHERIP > 0 308 { SOCK_RAW, &inetdomain, IPPROTO_ETHERIP, PR_ATOMIC|PR_ADDR, 309 ip_etherip_input, rip_output, 0, rip_ctloutput, 310 rip_usrreq, 311 0, 0, 0, 0, ip_etherip_sysctl 312 }, 313 #endif /* NETHERIP */ 314 /* raw wildcard */ 315 { SOCK_RAW, &inetdomain, 0, PR_ATOMIC|PR_ADDR, 316 rip_input, rip_output, 0, rip_ctloutput, 317 rip_usrreq, 318 rip_init, 0, 0, 0, 319 }, 320 }; 321 322 struct domain inetdomain = 323 { AF_INET, "internet", 0, 0, 0, 324 inetsw, &inetsw[nitems(inetsw)], 325 sizeof(struct sockaddr_in), 326 offsetof(struct sockaddr_in, sin_addr), 32 }; 327