1 /* $OpenBSD: in_proto.c,v 1.36 2003/06/02 23:28:14 millert 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 109 #include <netinet/in.h> 110 #include <netinet/in_systm.h> 111 #include <netinet/ip.h> 112 #include <netinet/ip_var.h> 113 #include <netinet/ip_icmp.h> 114 #include <netinet/in_pcb.h> 115 116 #ifdef INET6 117 #ifndef INET 118 #include <netinet/in.h> 119 #endif 120 #include <netinet/ip6.h> 121 #endif 122 123 #include <netinet/igmp_var.h> 124 #include <netinet/tcp.h> 125 #include <netinet/tcp_timer.h> 126 #include <netinet/tcp_var.h> 127 #include <netinet/udp.h> 128 #include <netinet/udp_var.h> 129 130 /* 131 * TCP/IP protocol family: IP, ICMP, UDP, TCP. 132 */ 133 134 #include "gif.h" 135 #if NGIF > 0 136 #include <netinet/in_gif.h> 137 #endif 138 139 #ifdef NSIP 140 #include <netns/ns_var.h> 141 #include <netns/idp_var.h> 142 #endif /* NSIP */ 143 144 #ifdef IPXIP 145 #include <netipx/ipx.h> 146 #include <netipx/ipx_ip.h> 147 #endif /* NSIP */ 148 149 #ifdef TPIP 150 #include <netiso/tp_param.h> 151 #include <netiso/tp_var.h> 152 #endif /* TPIP */ 153 154 #ifdef EON 155 #include <netiso/eonvar.h> 156 #endif /* EON */ 157 158 #ifdef MROUTING 159 #include <netinet/ip_mroute.h> 160 #endif /* MROUTING */ 161 162 #ifdef INET6 163 #include <netinet6/ip6_var.h> 164 #endif /* INET6 */ 165 166 #ifdef IPSEC 167 #include <netinet/ip_ipsp.h> 168 #include <netinet/ip_ether.h> 169 #endif 170 171 #include <netinet/ip_ipip.h> 172 173 #include "gre.h" 174 #if NGRE > 0 175 #include <netinet/ip_gre.h> 176 #include <net/if_gre.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, 193 tcp_input, 0, tcp_ctlinput, tcp_ctloutput, 194 tcp_usrreq, 195 tcp_init, 0, tcp_slowtimo, tcp_drain, 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 #ifdef INET6 214 { SOCK_RAW, &inetdomain, IPPROTO_IPV6, PR_ATOMIC|PR_ADDR, 215 in_gif_input, rip_output, 0, 0, 216 rip_usrreq, /*XXX*/ 217 0, 0, 0, 0, 218 }, 219 #endif /* INET6 */ 220 #else /* NGIF */ 221 { SOCK_RAW, &inetdomain, IPPROTO_IPIP, PR_ATOMIC|PR_ADDR, 222 ip4_input, rip_output, 0, rip_ctloutput, 223 rip_usrreq, 224 0, 0, 0, 0, ipip_sysctl 225 }, 226 #ifdef INET6 227 { SOCK_RAW, &inetdomain, IPPROTO_IPV6, PR_ATOMIC|PR_ADDR, 228 ip4_input, rip_output, 0, rip_ctloutput, 229 rip_usrreq, /*XXX*/ 230 0, 0, 0, 0, 231 }, 232 #endif /* INET6 */ 233 #endif /*NGIF*/ 234 { SOCK_RAW, &inetdomain, IPPROTO_IGMP, PR_ATOMIC|PR_ADDR, 235 igmp_input, rip_output, 0, rip_ctloutput, 236 rip_usrreq, 237 igmp_init, igmp_fasttimo, igmp_slowtimo, 0, 238 }, 239 #ifdef TPIP 240 { SOCK_SEQPACKET,&inetdomain, IPPROTO_TP, PR_CONNREQUIRED|PR_WANTRCVD|PR_ABRTACPTDIS, 241 tpip_input, 0, tpip_ctlinput, tp_ctloutput, 242 tp_usrreq, 243 tp_init, 0, tp_slowtimo, tp_drain, 244 }, 245 #endif /* TPIP */ 246 /* EON (ISO CLNL over IP) */ 247 #ifdef EON 248 { SOCK_RAW, &inetdomain, IPPROTO_EON, 0, 249 eoninput, 0, eonctlinput, 0, 250 0, 251 eonprotoinit, 0, 0, 0, 252 }, 253 #endif /* EON */ 254 #ifdef IPXIP 255 { SOCK_RAW, &inetdomain, IPPROTO_IDP, PR_ATOMIC|PR_ADDR, 256 ipxip_input, rip_output, ipxip_ctlinput, 0, 257 rip_usrreq, 258 ipxipprotoinit,0, 0, 0, 259 }, 260 #endif /* NSIP */ 261 #ifdef NSIP 262 { SOCK_RAW, &inetdomain, IPPROTO_IDP, PR_ATOMIC|PR_ADDR, 263 idpip_input, rip_output, nsip_ctlinput, 0, 264 rip_usrreq, 265 0, 0, 0, 0, 266 }, 267 #endif /* NSIP */ 268 #ifdef IPSEC 269 { SOCK_RAW, &inetdomain, IPPROTO_AH, PR_ATOMIC|PR_ADDR, 270 ah4_input, rip_output, ah4_ctlinput, rip_ctloutput, 271 rip_usrreq, 272 0, 0, 0, 0, ah_sysctl 273 }, 274 { SOCK_RAW, &inetdomain, IPPROTO_ESP, PR_ATOMIC|PR_ADDR, 275 esp4_input, rip_output, esp4_ctlinput, rip_ctloutput, 276 rip_usrreq, 277 0, 0, 0, 0, esp_sysctl 278 }, 279 { SOCK_RAW, &inetdomain, IPPROTO_ETHERIP, PR_ATOMIC|PR_ADDR, 280 etherip_input, rip_output, 0, rip_ctloutput, 281 rip_usrreq, 282 0, 0, 0, 0, etherip_sysctl 283 }, 284 { SOCK_RAW, &inetdomain, IPPROTO_IPCOMP, PR_ATOMIC|PR_ADDR, 285 ipcomp4_input, rip_output, 0, rip_ctloutput, 286 rip_usrreq, 287 0, 0, 0, 0, ipcomp_sysctl 288 }, 289 #endif /* IPSEC */ 290 #if NGRE > 0 291 { SOCK_RAW, &inetdomain, IPPROTO_GRE, PR_ATOMIC|PR_ADDR, 292 gre_input, rip_output, 0, rip_ctloutput, 293 rip_usrreq, 294 0, 0, 0, 0, gre_sysctl 295 }, 296 { SOCK_RAW, &inetdomain, IPPROTO_MOBILE, PR_ATOMIC|PR_ADDR, 297 gre_mobile_input, rip_output, 0, rip_ctloutput, 298 rip_usrreq, 299 0, 0, 0, 0, ipmobile_sysctl 300 }, 301 #endif /* NGRE > 0 */ 302 /* raw wildcard */ 303 { SOCK_RAW, &inetdomain, 0, PR_ATOMIC|PR_ADDR, 304 rip_input, rip_output, 0, rip_ctloutput, 305 rip_usrreq, 306 rip_init, 0, 0, 0, 307 }, 308 }; 309 310 struct domain inetdomain = 311 { AF_INET, "internet", 0, 0, 0, 312 inetsw, &inetsw[sizeof(inetsw)/sizeof(inetsw[0])], 0, 313 rn_inithead, 32, sizeof(struct sockaddr_in) }; 314 315 #ifdef notyet /* XXXX */ 316 #include "hy.h" 317 #if NHY > 0 318 /* 319 * HYPERchannel protocol family: raw interface. 320 */ 321 int rhy_output(); 322 extern struct domain hydomain; 323 324 struct protosw hysw[] = { 325 { SOCK_RAW, &hydomain, 0, PR_ATOMIC|PR_ADDR, 326 0, rhy_output, 0, 0, 327 rip_usrreq, 328 0, 0, 0, 0, 329 }, 330 }; 331 332 struct domain hydomain = 333 { AF_HYLINK, "hy", 0, 0, 0, hysw, &hysw[sizeof (hysw)/sizeof(hysw[0])] }; 334 #endif 335 #endif 336