1 /* $OpenBSD: in_proto.c,v 1.32 2001/08/08 15:07:04 jjbg 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. All advertising materials mentioning features or use of this software 46 * must display the following acknowledgement: 47 * This product includes software developed by the University of 48 * California, Berkeley and its contributors. 49 * 4. Neither the name of the University nor the names of its contributors 50 * may be used to endorse or promote products derived from this software 51 * without specific prior written permission. 52 * 53 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 54 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 55 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 56 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 57 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 58 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 59 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 60 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 61 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 62 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 63 * SUCH DAMAGE. 64 * 65 * @(#)COPYRIGHT 1.1 (NRL) 17 January 1995 66 * 67 * NRL grants permission for redistribution and use in source and binary 68 * forms, with or without modification, of the software and documentation 69 * created at NRL provided that the following conditions are met: 70 * 71 * 1. Redistributions of source code must retain the above copyright 72 * notice, this list of conditions and the following disclaimer. 73 * 2. Redistributions in binary form must reproduce the above copyright 74 * notice, this list of conditions and the following disclaimer in the 75 * documentation and/or other materials provided with the distribution. 76 * 3. All advertising materials mentioning features or use of this software 77 * must display the following acknowledgements: 78 * This product includes software developed by the University of 79 * California, Berkeley and its contributors. 80 * This product includes software developed at the Information 81 * Technology Division, US Naval Research Laboratory. 82 * 4. Neither the name of the NRL nor the names of its contributors 83 * may be used to endorse or promote products derived from this software 84 * without specific prior written permission. 85 * 86 * THE SOFTWARE PROVIDED BY NRL IS PROVIDED BY NRL AND CONTRIBUTORS ``AS 87 * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 88 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 89 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NRL OR 90 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 91 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 92 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 93 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 94 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 95 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 96 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 97 * 98 * The views and conclusions contained in the software and documentation 99 * are those of the authors and should not be interpreted as representing 100 * official policies, either expressed or implied, of the US Naval 101 * Research Laboratory (NRL). 102 */ 103 104 #include <sys/param.h> 105 #include <sys/socket.h> 106 #include <sys/protosw.h> 107 #include <sys/domain.h> 108 #include <sys/mbuf.h> 109 110 #include <net/if.h> 111 #include <net/route.h> 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 #include <netinet/tcp.h> 129 #include <netinet/tcp_timer.h> 130 #include <netinet/tcp_var.h> 131 #include <netinet/udp.h> 132 #include <netinet/udp_var.h> 133 134 /* 135 * TCP/IP protocol family: IP, ICMP, UDP, TCP. 136 */ 137 138 #include "gif.h" 139 #if NGIF > 0 140 #include <netinet/in_gif.h> 141 #endif 142 143 #ifdef NSIP 144 #include <netns/ns_var.h> 145 #include <netns/idp_var.h> 146 #endif /* NSIP */ 147 148 #ifdef IPXIP 149 #include <netipx/ipx.h> 150 #include <netipx/ipx_ip.h> 151 #endif /* NSIP */ 152 153 #ifdef TPIP 154 #include <netiso/tp_param.h> 155 #include <netiso/tp_var.h> 156 #endif /* TPIP */ 157 158 #ifdef EON 159 #include <netiso/eonvar.h> 160 #endif /* EON */ 161 162 #ifdef MROUTING 163 #include <netinet/ip_mroute.h> 164 #endif /* MROUTING */ 165 166 #ifdef INET6 167 #include <netinet6/ip6_var.h> 168 #endif /* INET6 */ 169 170 #ifdef IPSEC 171 #include <netinet/ip_ipsp.h> 172 #include <netinet/ip_ether.h> 173 #endif 174 175 #include <netinet/ip_ipip.h> 176 177 #include "gre.h" 178 #if NGRE > 0 179 #include <netinet/ip_gre.h> 180 #include <net/if_gre.h> 181 #endif 182 183 extern struct domain inetdomain; 184 185 struct protosw inetsw[] = { 186 { 0, &inetdomain, 0, 0, 187 0, ip_output, 0, 0, 188 0, 189 ip_init, 0, ip_slowtimo, ip_drain, ip_sysctl 190 }, 191 { SOCK_DGRAM, &inetdomain, IPPROTO_UDP, PR_ATOMIC|PR_ADDR, 192 udp_input, 0, udp_ctlinput, ip_ctloutput, 193 udp_usrreq, 194 udp_init, 0, 0, 0, udp_sysctl 195 }, 196 { SOCK_STREAM, &inetdomain, IPPROTO_TCP, PR_CONNREQUIRED|PR_WANTRCVD|PR_ABRTACPTDIS, 197 tcp_input, 0, tcp_ctlinput, tcp_ctloutput, 198 tcp_usrreq, 199 tcp_init, tcp_fasttimo, tcp_slowtimo, tcp_drain, tcp_sysctl 200 }, 201 { SOCK_RAW, &inetdomain, IPPROTO_RAW, PR_ATOMIC|PR_ADDR, 202 rip_input, rip_output, 0, rip_ctloutput, 203 rip_usrreq, 204 0, 0, 0, 0, 205 }, 206 { SOCK_RAW, &inetdomain, IPPROTO_ICMP, PR_ATOMIC|PR_ADDR, 207 icmp_input, rip_output, 0, rip_ctloutput, 208 rip_usrreq, 209 0, 0, 0, 0, icmp_sysctl 210 }, 211 #if NGIF > 0 212 { SOCK_RAW, &inetdomain, IPPROTO_IPV4, PR_ATOMIC|PR_ADDR, 213 in_gif_input, rip_output, 0, rip_ctloutput, 214 rip_usrreq, 215 0, 0, 0, 0, ipip_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 /* INET6 */ 224 #else /* NGIF */ 225 { SOCK_RAW, &inetdomain, IPPROTO_IPIP, PR_ATOMIC|PR_ADDR, 226 ip4_input, rip_output, 0, rip_ctloutput, 227 rip_usrreq, 228 0, 0, 0, 0, ipip_sysctl 229 }, 230 #ifdef INET6 231 { SOCK_RAW, &inetdomain, IPPROTO_IPV6, PR_ATOMIC|PR_ADDR, 232 ip4_input, rip_output, 0, rip_ctloutput, 233 rip_usrreq, /*XXX*/ 234 0, 0, 0, 0, 235 }, 236 #endif /* INET6 */ 237 #endif /*NGIF*/ 238 { SOCK_RAW, &inetdomain, IPPROTO_IGMP, PR_ATOMIC|PR_ADDR, 239 igmp_input, rip_output, 0, rip_ctloutput, 240 rip_usrreq, 241 igmp_init, igmp_fasttimo, igmp_slowtimo, 0, 242 }, 243 #ifdef TPIP 244 { SOCK_SEQPACKET,&inetdomain, IPPROTO_TP, PR_CONNREQUIRED|PR_WANTRCVD|PR_ABRTACPTDIS, 245 tpip_input, 0, tpip_ctlinput, tp_ctloutput, 246 tp_usrreq, 247 tp_init, 0, tp_slowtimo, tp_drain, 248 }, 249 #endif /* TPIP */ 250 /* EON (ISO CLNL over IP) */ 251 #ifdef EON 252 { SOCK_RAW, &inetdomain, IPPROTO_EON, 0, 253 eoninput, 0, eonctlinput, 0, 254 0, 255 eonprotoinit, 0, 0, 0, 256 }, 257 #endif /* EON */ 258 #ifdef IPXIP 259 { SOCK_RAW, &inetdomain, IPPROTO_IDP, PR_ATOMIC|PR_ADDR, 260 ipxip_input, rip_output, ipxip_ctlinput, 0, 261 rip_usrreq, 262 ipxipprotoinit,0, 0, 0, 263 }, 264 #endif /* NSIP */ 265 #ifdef NSIP 266 { SOCK_RAW, &inetdomain, IPPROTO_IDP, PR_ATOMIC|PR_ADDR, 267 idpip_input, rip_output, nsip_ctlinput, 0, 268 rip_usrreq, 269 0, 0, 0, 0, 270 }, 271 #endif /* NSIP */ 272 #ifdef IPSEC 273 { SOCK_RAW, &inetdomain, IPPROTO_AH, PR_ATOMIC|PR_ADDR, 274 ah4_input, rip_output, ah4_ctlinput, rip_ctloutput, 275 rip_usrreq, 276 0, 0, 0, 0, ah_sysctl 277 }, 278 { SOCK_RAW, &inetdomain, IPPROTO_ESP, PR_ATOMIC|PR_ADDR, 279 esp4_input, rip_output, esp4_ctlinput, rip_ctloutput, 280 rip_usrreq, 281 0, 0, 0, 0, esp_sysctl 282 }, 283 { SOCK_RAW, &inetdomain, IPPROTO_ETHERIP, PR_ATOMIC|PR_ADDR, 284 etherip_input, rip_output, 0, rip_ctloutput, 285 rip_usrreq, 286 0, 0, 0, 0, etherip_sysctl 287 }, 288 { SOCK_RAW, &inetdomain, IPPROTO_IPCOMP, PR_ATOMIC|PR_ADDR, 289 ipcomp4_input, rip_output, 0, rip_ctloutput, 290 rip_usrreq, 291 0, 0, 0, 0, ipcomp_sysctl 292 }, 293 #endif /* IPSEC */ 294 #if NGRE > 0 295 { SOCK_RAW, &inetdomain, IPPROTO_GRE, PR_ATOMIC|PR_ADDR, 296 gre_input, rip_output, 0, rip_ctloutput, 297 rip_usrreq, 298 0, 0, 0, 0, gre_sysctl 299 }, 300 { SOCK_RAW, &inetdomain, IPPROTO_MOBILE, PR_ATOMIC|PR_ADDR, 301 gre_mobile_input, rip_output, 0, rip_ctloutput, 302 rip_usrreq, 303 0, 0, 0, 0, ipmobile_sysctl 304 }, 305 #endif /* NGRE > 0 */ 306 /* raw wildcard */ 307 { SOCK_RAW, &inetdomain, 0, PR_ATOMIC|PR_ADDR, 308 rip_input, rip_output, 0, rip_ctloutput, 309 rip_usrreq, 310 rip_init, 0, 0, 0, 311 }, 312 }; 313 314 struct domain inetdomain = 315 { AF_INET, "internet", 0, 0, 0, 316 inetsw, &inetsw[sizeof(inetsw)/sizeof(inetsw[0])], 0, 317 rn_inithead, 32, sizeof(struct sockaddr_in) }; 318 319 #ifdef notyet /* XXXX */ 320 #include "hy.h" 321 #if NHY > 0 322 /* 323 * HYPERchannel protocol family: raw interface. 324 */ 325 int rhy_output(); 326 extern struct domain hydomain; 327 328 struct protosw hysw[] = { 329 { SOCK_RAW, &hydomain, 0, PR_ATOMIC|PR_ADDR, 330 0, rhy_output, 0, 0, 331 rip_usrreq, 332 0, 0, 0, 0, 333 }, 334 }; 335 336 struct domain hydomain = 337 { AF_HYLINK, "hy", 0, 0, 0, hysw, &hysw[sizeof (hysw)/sizeof(hysw[0])] }; 338 #endif 339 #endif 340