1 /* $OpenBSD: in_proto.c,v 1.56 2011/03/31 10:36:42 jasper 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/route.h> 108 #include <net/radix.h> 109 #ifndef SMALL_KERNEL 110 #include <net/radix_mpath.h> 111 #endif 112 113 #include <netinet/in.h> 114 #include <netinet/in_systm.h> 115 #include <netinet/ip.h> 116 #include <netinet/ip_var.h> 117 #include <netinet/ip_icmp.h> 118 #include <netinet/in_pcb.h> 119 120 #ifdef INET6 121 #ifndef INET 122 #include <netinet/in.h> 123 #endif 124 #include <netinet/ip6.h> 125 #endif 126 127 #include <netinet/igmp_var.h> 128 #ifdef PIM 129 #include <netinet/pim_var.h> 130 #endif 131 #include <netinet/tcp.h> 132 #include <netinet/tcp_timer.h> 133 #include <netinet/tcp_var.h> 134 #include <netinet/udp.h> 135 #include <netinet/udp_var.h> 136 137 /* 138 * TCP/IP protocol family: IP, ICMP, UDP, TCP. 139 */ 140 141 #include "gif.h" 142 #if NGIF > 0 143 #include <netinet/in_gif.h> 144 #endif 145 146 #ifdef INET6 147 #include <netinet6/ip6_var.h> 148 #endif /* INET6 */ 149 150 #ifdef IPSEC 151 #include <netinet/ip_ipsp.h> 152 #endif 153 154 #include <netinet/ip_ether.h> 155 #include <netinet/ip_ipip.h> 156 157 #include "gre.h" 158 #if NGRE > 0 159 #include <netinet/ip_gre.h> 160 #include <net/if_gre.h> 161 #endif 162 163 #include "carp.h" 164 #if NCARP > 0 165 #include <netinet/ip_carp.h> 166 #endif 167 168 #include "pfsync.h" 169 #if NPFSYNC > 0 170 #include <net/pfvar.h> 171 #include <net/if_pfsync.h> 172 #endif 173 174 #include "pf.h" 175 #if NPF > 0 176 #include <netinet/ip_divert.h> 177 #endif 178 179 extern struct domain inetdomain; 180 181 struct protosw inetsw[] = { 182 { 0, &inetdomain, 0, 0, 183 0, ip_output, 0, 0, 184 0, 185 ip_init, 0, ip_slowtimo, ip_drain, ip_sysctl 186 }, 187 { SOCK_DGRAM, &inetdomain, IPPROTO_UDP, PR_ATOMIC|PR_ADDR, 188 udp_input, 0, udp_ctlinput, ip_ctloutput, 189 udp_usrreq, 190 udp_init, 0, 0, 0, udp_sysctl 191 }, 192 { SOCK_STREAM, &inetdomain, IPPROTO_TCP, PR_CONNREQUIRED|PR_WANTRCVD|PR_ABRTACPTDIS|PR_SPLICE, 193 tcp_input, 0, tcp_ctlinput, tcp_ctloutput, 194 tcp_usrreq, 195 tcp_init, 0, tcp_slowtimo, 0, tcp_sysctl 196 }, 197 { SOCK_RAW, &inetdomain, IPPROTO_RAW, PR_ATOMIC|PR_ADDR, 198 rip_input, rip_output, 0, rip_ctloutput, 199 rip_usrreq, 200 0, 0, 0, 0, 201 }, 202 { SOCK_RAW, &inetdomain, IPPROTO_ICMP, PR_ATOMIC|PR_ADDR, 203 icmp_input, rip_output, 0, rip_ctloutput, 204 rip_usrreq, 205 icmp_init, 0, 0, 0, icmp_sysctl 206 }, 207 #if NGIF > 0 208 { SOCK_RAW, &inetdomain, IPPROTO_IPV4, PR_ATOMIC|PR_ADDR, 209 in_gif_input, rip_output, 0, rip_ctloutput, 210 rip_usrreq, 211 0, 0, 0, 0, ipip_sysctl 212 }, 213 { SOCK_RAW, &inetdomain, IPPROTO_ETHERIP, PR_ATOMIC|PR_ADDR, 214 etherip_input, rip_output, 0, rip_ctloutput, 215 rip_usrreq, 216 0, 0, 0, 0, etherip_sysctl 217 }, 218 #ifdef INET6 219 { SOCK_RAW, &inetdomain, IPPROTO_IPV6, PR_ATOMIC|PR_ADDR, 220 in_gif_input, rip_output, 0, 0, 221 rip_usrreq, /*XXX*/ 222 0, 0, 0, 0, 223 }, 224 #endif 225 #ifdef MPLS 226 { SOCK_RAW, &inetdomain, IPPROTO_MPLS, PR_ATOMIC|PR_ADDR, 227 etherip_input, rip_output, 0, 0, 228 rip_usrreq, 229 0, 0, 0, 0, 230 }, 231 #endif 232 #else /* NGIF */ 233 { SOCK_RAW, &inetdomain, IPPROTO_IPIP, PR_ATOMIC|PR_ADDR, 234 ip4_input, rip_output, 0, rip_ctloutput, 235 rip_usrreq, 236 0, 0, 0, 0, ipip_sysctl 237 }, 238 #ifdef INET6 239 { SOCK_RAW, &inetdomain, IPPROTO_IPV6, PR_ATOMIC|PR_ADDR, 240 ip4_input, rip_output, 0, rip_ctloutput, 241 rip_usrreq, /*XXX*/ 242 0, 0, 0, 0, 243 }, 244 #endif 245 #endif /*NGIF*/ 246 { SOCK_RAW, &inetdomain, IPPROTO_IGMP, PR_ATOMIC|PR_ADDR, 247 igmp_input, rip_output, 0, rip_ctloutput, 248 rip_usrreq, 249 igmp_init, igmp_fasttimo, igmp_slowtimo, 0, igmp_sysctl 250 }, 251 #ifdef PIM 252 { SOCK_RAW, &inetdomain, IPPROTO_PIM, PR_ATOMIC|PR_ADDR, 253 pim_input, rip_output, 0, rip_ctloutput, 254 rip_usrreq, 255 0, 0, 0, 0, pim_sysctl 256 }, 257 #endif /* PIM */ 258 #ifdef IPSEC 259 { SOCK_RAW, &inetdomain, IPPROTO_AH, PR_ATOMIC|PR_ADDR, 260 ah4_input, rip_output, ah4_ctlinput, rip_ctloutput, 261 rip_usrreq, 262 0, 0, 0, 0, ah_sysctl 263 }, 264 { SOCK_RAW, &inetdomain, IPPROTO_ESP, PR_ATOMIC|PR_ADDR, 265 esp4_input, rip_output, esp4_ctlinput, rip_ctloutput, 266 rip_usrreq, 267 0, 0, 0, 0, esp_sysctl 268 }, 269 { SOCK_RAW, &inetdomain, IPPROTO_IPCOMP, PR_ATOMIC|PR_ADDR, 270 ipcomp4_input, rip_output, 0, rip_ctloutput, 271 rip_usrreq, 272 0, 0, 0, 0, ipcomp_sysctl 273 }, 274 #endif /* IPSEC */ 275 #if NGRE > 0 276 { SOCK_RAW, &inetdomain, IPPROTO_GRE, PR_ATOMIC|PR_ADDR, 277 gre_input, rip_output, 0, rip_ctloutput, 278 gre_usrreq, 279 0, 0, 0, 0, gre_sysctl 280 }, 281 { SOCK_RAW, &inetdomain, IPPROTO_MOBILE, PR_ATOMIC|PR_ADDR, 282 gre_mobile_input, rip_output, 0, rip_ctloutput, 283 rip_usrreq, 284 0, 0, 0, 0, ipmobile_sysctl 285 }, 286 #endif /* NGRE > 0 */ 287 #if NCARP > 0 288 { SOCK_RAW, &inetdomain, IPPROTO_CARP, PR_ATOMIC|PR_ADDR, 289 carp_proto_input, rip_output, 0, rip_ctloutput, 290 rip_usrreq, 291 0, 0, 0, 0, carp_sysctl 292 }, 293 #endif /* NCARP > 0 */ 294 #if NPFSYNC > 0 295 { SOCK_RAW, &inetdomain, IPPROTO_PFSYNC, PR_ATOMIC|PR_ADDR, 296 pfsync_input, rip_output, 0, rip_ctloutput, 297 rip_usrreq, 298 0, 0, 0, 0, pfsync_sysctl 299 }, 300 #endif /* NPFSYNC > 0 */ 301 #if NPF > 0 302 { SOCK_RAW, &inetdomain, IPPROTO_DIVERT, PR_ATOMIC|PR_ADDR, 303 divert_input, 0, 0, rip_ctloutput, 304 divert_usrreq, 305 divert_init, 0, 0, 0, divert_sysctl 306 }, 307 #endif /* NPF > 0 */ 308 /* raw wildcard */ 309 { SOCK_RAW, &inetdomain, 0, PR_ATOMIC|PR_ADDR, 310 rip_input, rip_output, 0, rip_ctloutput, 311 rip_usrreq, 312 rip_init, 0, 0, 0, 313 }, 314 }; 315 316 struct domain inetdomain = 317 { AF_INET, "internet", 0, 0, 0, 318 inetsw, &inetsw[nitems(inetsw)], 0, 319 #ifndef SMALL_KERNEL 320 rn_mpath_inithead, 321 #else 322 rn_inithead, 323 #endif 324 32, sizeof(struct sockaddr_in) }; 325 326 #ifdef notyet /* XXXX */ 327 #include "hy.h" 328 #if NHY > 0 329 /* 330 * HYPERchannel protocol family: raw interface. 331 */ 332 int rhy_output(); 333 extern struct domain hydomain; 334 335 struct protosw hysw[] = { 336 { SOCK_RAW, &hydomain, 0, PR_ATOMIC|PR_ADDR, 337 0, rhy_output, 0, 0, 338 rip_usrreq, 339 0, 0, 0, 0, 340 }, 341 }; 342 343 struct domain hydomain = 344 { AF_HYLINK, "hy", 0, 0, 0, hysw, &hysw[nitems(hysw)] }; 345 #endif 346 #endif 347