1 /* $NetBSD: in_proto.c,v 1.48 2001/03/21 19:22:28 thorpej Exp $ */ 2 3 /* 4 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. Neither the name of the project nor the names of its contributors 16 * may be used to endorse or promote products derived from this software 17 * without specific prior written permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 * SUCH DAMAGE. 30 */ 31 32 /* 33 * Copyright (c) 1982, 1986, 1993 34 * The Regents of the University of California. All rights reserved. 35 * 36 * Redistribution and use in source and binary forms, with or without 37 * modification, are permitted provided that the following conditions 38 * are met: 39 * 1. Redistributions of source code must retain the above copyright 40 * notice, this list of conditions and the following disclaimer. 41 * 2. Redistributions in binary form must reproduce the above copyright 42 * notice, this list of conditions and the following disclaimer in the 43 * documentation and/or other materials provided with the distribution. 44 * 3. All advertising materials mentioning features or use of this software 45 * must display the following acknowledgement: 46 * This product includes software developed by the University of 47 * California, Berkeley and its contributors. 48 * 4. Neither the name of the University nor the names of its contributors 49 * may be used to endorse or promote products derived from this software 50 * without specific prior written permission. 51 * 52 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 53 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 54 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 55 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 56 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 57 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 58 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 59 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 60 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 61 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 62 * SUCH DAMAGE. 63 * 64 * @(#)in_proto.c 8.2 (Berkeley) 2/9/95 65 */ 66 67 #include "opt_mrouting.h" 68 #include "opt_eon.h" /* ISO CLNL over IP */ 69 #include "opt_iso.h" /* ISO TP tunneled over IP */ 70 #include "opt_ns.h" /* NSIP: XNS tunneled over IP */ 71 #include "opt_inet.h" 72 #include "opt_ipsec.h" 73 74 #include <sys/param.h> 75 #include <sys/socket.h> 76 #include <sys/protosw.h> 77 #include <sys/domain.h> 78 #include <sys/mbuf.h> 79 80 #include <net/if.h> 81 #include <net/radix.h> 82 #include <net/route.h> 83 84 #include <netinet/in.h> 85 #include <netinet/in_systm.h> 86 #include <netinet/ip.h> 87 #include <netinet/ip_var.h> 88 #include <netinet/ip_icmp.h> 89 #include <netinet/in_pcb.h> 90 91 #ifdef INET6 92 #ifndef INET 93 #include <netinet/in.h> 94 #endif 95 #include <netinet/ip6.h> 96 #endif 97 98 #include <netinet/igmp_var.h> 99 #include <netinet/tcp.h> 100 #include <netinet/tcp_fsm.h> 101 #include <netinet/tcp_seq.h> 102 #include <netinet/tcp_timer.h> 103 #include <netinet/tcp_var.h> 104 #include <netinet/tcpip.h> 105 #include <netinet/tcp_debug.h> 106 #include <netinet/udp.h> 107 #include <netinet/udp_var.h> 108 #include <netinet/ip_encap.h> 109 /* 110 * TCP/IP protocol family: IP, ICMP, UDP, TCP. 111 */ 112 113 #ifdef IPSEC 114 #include <netinet6/ah.h> 115 #ifdef IPSEC_ESP 116 #include <netinet6/esp.h> 117 #endif 118 #include <netinet6/ipcomp.h> 119 #endif /* IPSEC */ 120 121 #include "gif.h" 122 #if NGIF > 0 123 #include <netinet/in_gif.h> 124 #endif 125 126 #ifdef NSIP 127 #include <netns/ns_var.h> 128 #include <netns/idp_var.h> 129 #endif /* NSIP */ 130 131 #ifdef TPIP 132 #include <netiso/tp_param.h> 133 #include <netiso/tp_var.h> 134 #endif /* TPIP */ 135 136 #ifdef EON 137 #include <netiso/eonvar.h> 138 #endif /* EON */ 139 140 #include "ipip.h" 141 #if NIPIP > 0 || defined(MROUTING) 142 #include <netinet/ip_ipip.h> 143 #endif /* NIPIP > 0 || MROUTING */ 144 145 #include "gre.h" 146 #if NGRE > 0 147 #include <netinet/ip_gre.h> 148 #endif 149 150 #include "stf.h" 151 #if NSTF > 0 152 #include <net/if_stf.h> 153 #endif 154 155 extern struct domain inetdomain; 156 157 struct protosw inetsw[] = { 158 { 0, &inetdomain, 0, 0, 159 0, ip_output, 0, 0, 160 0, 161 ip_init, 0, ip_slowtimo, ip_drain, ip_sysctl 162 }, 163 { SOCK_DGRAM, &inetdomain, IPPROTO_UDP, PR_ATOMIC|PR_ADDR, 164 udp_input, 0, udp_ctlinput, ip_ctloutput, 165 udp_usrreq, 166 udp_init, 0, 0, 0, udp_sysctl 167 }, 168 { SOCK_STREAM, &inetdomain, IPPROTO_TCP, PR_CONNREQUIRED|PR_WANTRCVD|PR_LISTEN|PR_ABRTACPTDIS, 169 tcp_input, 0, tcp_ctlinput, tcp_ctloutput, 170 tcp_usrreq, 171 tcp_init, tcp_fasttimo, tcp_slowtimo, tcp_drain, tcp_sysctl 172 }, 173 { SOCK_RAW, &inetdomain, IPPROTO_RAW, PR_ATOMIC|PR_ADDR, 174 rip_input, rip_output, 0, rip_ctloutput, 175 rip_usrreq, 176 0, 0, 0, 0, 177 }, 178 { SOCK_RAW, &inetdomain, IPPROTO_ICMP, PR_ATOMIC|PR_ADDR|PR_LASTHDR, 179 icmp_input, rip_output, 0, rip_ctloutput, 180 rip_usrreq, 181 0, 0, 0, 0, icmp_sysctl 182 }, 183 #ifdef IPSEC 184 { SOCK_RAW, &inetdomain, IPPROTO_AH, PR_ATOMIC|PR_ADDR, 185 ah4_input, 0, ah4_ctlinput, 0, 186 0, 187 0, 0, 0, 0, ipsec_sysctl 188 }, 189 #ifdef IPSEC_ESP 190 { SOCK_RAW, &inetdomain, IPPROTO_ESP, PR_ATOMIC|PR_ADDR, 191 esp4_input, 0, esp4_ctlinput, 0, 192 0, 193 0, 0, 0, 0, ipsec_sysctl 194 }, 195 #endif 196 { SOCK_RAW, &inetdomain, IPPROTO_IPCOMP, PR_ATOMIC|PR_ADDR, 197 ipcomp4_input, 0, 0, 0, 198 0, 199 0, 0, 0, 0, ipsec_sysctl 200 }, 201 #endif /* IPSEC */ 202 { SOCK_RAW, &inetdomain, IPPROTO_IPV4, PR_ATOMIC|PR_ADDR|PR_LASTHDR, 203 encap4_input, rip_output, 0, rip_ctloutput, 204 rip_usrreq, /*XXX*/ 205 encap_init, 0, 0, 0, 206 }, 207 #ifdef INET6 208 { SOCK_RAW, &inetdomain, IPPROTO_IPV6, PR_ATOMIC|PR_ADDR|PR_LASTHDR, 209 encap4_input, rip_output, 0, rip_ctloutput, 210 rip_usrreq, /*XXX*/ 211 0, 0, 0, 0, 212 }, 213 #endif /* INET6 */ 214 #if NGRE > 0 215 { SOCK_RAW, &inetdomain, IPPROTO_GRE, PR_ATOMIC|PR_ADDR|PR_LASTHDR, 216 gre_input, rip_output, 0, rip_ctloutput, 217 rip_usrreq, 218 0, 0, 0, 0, 219 }, 220 { SOCK_RAW, &inetdomain, IPPROTO_MOBILE, PR_ATOMIC|PR_ADDR|PR_LASTHDR, 221 gre_mobile_input, rip_output, 0, rip_ctloutput, 222 rip_usrreq, 223 0, 0, 0, 0, 224 }, 225 #endif /* NGRE > 0 */ 226 { SOCK_RAW, &inetdomain, IPPROTO_IGMP, PR_ATOMIC|PR_ADDR|PR_LASTHDR, 227 igmp_input, rip_output, 0, rip_ctloutput, 228 rip_usrreq, 229 igmp_init, igmp_fasttimo, igmp_slowtimo, 0, 230 }, 231 #ifdef TPIP 232 { SOCK_SEQPACKET,&inetdomain, IPPROTO_TP, PR_CONNREQUIRED|PR_WANTRCVD|PR_LISTEN|PR_LASTHDR|PR_ABRTACPTDIS, 233 tpip_input, 0, tpip_ctlinput, tp_ctloutput, 234 tp_usrreq, 235 tp_init, 0, tp_slowtimo, tp_drain, 236 }, 237 #endif /* TPIP */ 238 #ifdef ISO 239 /* EON (ISO CLNL over IP) */ 240 #ifdef EON 241 { SOCK_RAW, &inetdomain, IPPROTO_EON, PR_LASTHDR, 242 eoninput, 0, eonctlinput, 0, 243 0, 244 eonprotoinit, 0, 0, 0, 245 }, 246 #else 247 { SOCK_RAW, &inetdomain, IPPROTO_EON, PR_ATOMIC|PR_ADDR|PR_LASTHDR, 248 encap4_input, rip_output, 0, rip_ctloutput, 249 rip_usrreq, /*XXX*/ 250 0, 0, 0, 0, 251 }, 252 #endif /* EON */ 253 #endif /* ISO */ 254 #ifdef NSIP 255 { SOCK_RAW, &inetdomain, IPPROTO_IDP, PR_ATOMIC|PR_ADDR|PR_LASTHDR, 256 idpip_input, NULL, nsip_ctlinput, 0, 257 rip_usrreq, 258 0, 0, 0, 0, 259 }, 260 #endif /* NSIP */ 261 /* raw wildcard */ 262 { SOCK_RAW, &inetdomain, 0, PR_ATOMIC|PR_ADDR, 263 rip_input, rip_output, 0, rip_ctloutput, 264 rip_usrreq, 265 rip_init, 0, 0, 0, 266 }, 267 }; 268 269 #if NIPIP > 0 270 struct protosw ipip_protosw = 271 { SOCK_RAW, &inetdomain, IPPROTO_IPIP, PR_ATOMIC|PR_ADDR, 272 ipip_input, rip_output, 0, rip_ctloutput, 273 rip_usrreq, /* XXX */ 274 0, 0, 0, 0, 275 }; 276 #endif /* NIPIP */ 277 278 #if NGIF > 0 279 struct protosw in_gif_protosw = 280 { SOCK_RAW, &inetdomain, 0/*IPPROTO_IPV[46]*/, PR_ATOMIC|PR_ADDR, 281 in_gif_input, rip_output, 0, rip_ctloutput, 282 rip_usrreq, 283 0, 0, 0, 0, 284 }; 285 #endif /*NGIF*/ 286 287 #if NSTF > 0 288 struct protosw in_stf_protosw = 289 { SOCK_RAW, &inetdomain, IPPROTO_IPV6, PR_ATOMIC|PR_ADDR, 290 in_stf_input, rip_output, 0, rip_ctloutput, 291 rip_usrreq, 292 0, 0, 0, 0 293 }; 294 #endif /*NSTF*/ 295 296 struct domain inetdomain = 297 { PF_INET, "internet", 0, 0, 0, 298 inetsw, &inetsw[sizeof(inetsw)/sizeof(inetsw[0])], 0, 299 rn_inithead, 32, sizeof(struct sockaddr_in) }; 300 301 u_char ip_protox[IPPROTO_MAX]; 302 303 int icmperrppslim = 100; /* 100pps */ 304