1 /* $OpenBSD: in_proto.c,v 1.51 2009/10/04 16:08:37 michele 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 #include <netinet/ip_ether.h> 153 #endif 154 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, 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 #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, igmp_sysctl 238 }, 239 #ifdef PIM 240 { SOCK_RAW, &inetdomain, IPPROTO_PIM, PR_ATOMIC|PR_ADDR, 241 pim_input, rip_output, 0, rip_ctloutput, 242 rip_usrreq, 243 0, 0, 0, 0, pim_sysctl 244 }, 245 #endif /* PIM */ 246 #ifdef IPSEC 247 { SOCK_RAW, &inetdomain, IPPROTO_AH, PR_ATOMIC|PR_ADDR, 248 ah4_input, rip_output, ah4_ctlinput, rip_ctloutput, 249 rip_usrreq, 250 0, 0, 0, 0, ah_sysctl 251 }, 252 { SOCK_RAW, &inetdomain, IPPROTO_ESP, PR_ATOMIC|PR_ADDR, 253 esp4_input, rip_output, esp4_ctlinput, rip_ctloutput, 254 rip_usrreq, 255 0, 0, 0, 0, esp_sysctl 256 }, 257 { SOCK_RAW, &inetdomain, IPPROTO_ETHERIP, PR_ATOMIC|PR_ADDR, 258 etherip_input, rip_output, 0, rip_ctloutput, 259 rip_usrreq, 260 0, 0, 0, 0, etherip_sysctl 261 }, 262 { SOCK_RAW, &inetdomain, IPPROTO_IPCOMP, PR_ATOMIC|PR_ADDR, 263 ipcomp4_input, rip_output, 0, rip_ctloutput, 264 rip_usrreq, 265 0, 0, 0, 0, ipcomp_sysctl 266 }, 267 #endif /* IPSEC */ 268 #if NGRE > 0 269 { SOCK_RAW, &inetdomain, IPPROTO_GRE, PR_ATOMIC|PR_ADDR, 270 gre_input, rip_output, 0, rip_ctloutput, 271 rip_usrreq, 272 0, 0, 0, 0, gre_sysctl 273 }, 274 { SOCK_RAW, &inetdomain, IPPROTO_MOBILE, PR_ATOMIC|PR_ADDR, 275 gre_mobile_input, rip_output, 0, rip_ctloutput, 276 rip_usrreq, 277 0, 0, 0, 0, ipmobile_sysctl 278 }, 279 #endif /* NGRE > 0 */ 280 #if NCARP > 0 281 { SOCK_RAW, &inetdomain, IPPROTO_CARP, PR_ATOMIC|PR_ADDR, 282 carp_proto_input, rip_output, 0, rip_ctloutput, 283 rip_usrreq, 284 0, 0, 0, 0, carp_sysctl 285 }, 286 #endif /* NCARP > 0 */ 287 #if NPFSYNC > 0 288 { SOCK_RAW, &inetdomain, IPPROTO_PFSYNC, PR_ATOMIC|PR_ADDR, 289 pfsync_input, rip_output, 0, rip_ctloutput, 290 rip_usrreq, 291 0, 0, 0, 0, pfsync_sysctl 292 }, 293 #endif /* NPFSYNC > 0 */ 294 #if NPF > 0 295 { SOCK_RAW, &inetdomain, IPPROTO_DIVERT, PR_ATOMIC|PR_ADDR, 296 divert_input, 0, 0, rip_ctloutput, 297 divert_usrreq, 298 divert_init, 0, 0, 0, divert_sysctl 299 }, 300 #endif /* NPF > 0 */ 301 /* raw wildcard */ 302 { SOCK_RAW, &inetdomain, 0, PR_ATOMIC|PR_ADDR, 303 rip_input, rip_output, 0, rip_ctloutput, 304 rip_usrreq, 305 rip_init, 0, 0, 0, 306 }, 307 }; 308 309 struct domain inetdomain = 310 { AF_INET, "internet", 0, 0, 0, 311 inetsw, &inetsw[sizeof(inetsw)/sizeof(inetsw[0])], 0, 312 #ifndef SMALL_KERNEL 313 rn_mpath_inithead, 314 #else 315 rn_inithead, 316 #endif 317 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