Home | History | Annotate | Line # | Download | only in netinet
in_proto.c revision 1.60
      1 /*	$NetBSD: in_proto.c,v 1.60 2003/08/14 07:57:40 itojun 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. Neither the name of the University nor the names of its contributors
     45  *    may be used to endorse or promote products derived from this software
     46  *    without specific prior written permission.
     47  *
     48  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     49  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     50  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     51  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     52  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     53  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     54  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     55  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     56  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     57  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     58  * SUCH DAMAGE.
     59  *
     60  *	@(#)in_proto.c	8.2 (Berkeley) 2/9/95
     61  */
     62 
     63 #include <sys/cdefs.h>
     64 __KERNEL_RCSID(0, "$NetBSD: in_proto.c,v 1.60 2003/08/14 07:57:40 itojun Exp $");
     65 
     66 #include "opt_mrouting.h"
     67 #include "opt_eon.h"			/* ISO CLNL over IP */
     68 #include "opt_iso.h"			/* ISO TP tunneled over IP */
     69 #include "opt_ns.h"			/* NSIP: XNS tunneled over IP */
     70 #include "opt_inet.h"
     71 #include "opt_ipsec.h"
     72 
     73 #include <sys/param.h>
     74 #include <sys/socket.h>
     75 #include <sys/protosw.h>
     76 #include <sys/domain.h>
     77 #include <sys/mbuf.h>
     78 
     79 #include <net/if.h>
     80 #include <net/radix.h>
     81 #include <net/route.h>
     82 
     83 #include <netinet/in.h>
     84 #include <netinet/in_systm.h>
     85 #include <netinet/ip.h>
     86 #include <netinet/ip_var.h>
     87 #include <netinet/ip_icmp.h>
     88 #include <netinet/in_pcb.h>
     89 
     90 #ifdef INET6
     91 #ifndef INET
     92 #include <netinet/in.h>
     93 #endif
     94 #include <netinet/ip6.h>
     95 #endif
     96 
     97 #include <netinet/igmp_var.h>
     98 #include <netinet/tcp.h>
     99 #include <netinet/tcp_fsm.h>
    100 #include <netinet/tcp_seq.h>
    101 #include <netinet/tcp_timer.h>
    102 #include <netinet/tcp_var.h>
    103 #include <netinet/tcpip.h>
    104 #include <netinet/tcp_debug.h>
    105 #include <netinet/udp.h>
    106 #include <netinet/udp_var.h>
    107 #include <netinet/ip_encap.h>
    108 /*
    109  * TCP/IP protocol family: IP, ICMP, UDP, TCP.
    110  */
    111 
    112 #ifdef IPSEC
    113 #include <netinet6/ipsec.h>
    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 #ifdef NSIP
    122 #include <netns/ns_var.h>
    123 #include <netns/idp_var.h>
    124 #endif /* NSIP */
    125 
    126 #ifdef TPIP
    127 #include <netiso/tp_param.h>
    128 #include <netiso/tp_var.h>
    129 #endif /* TPIP */
    130 
    131 #ifdef EON
    132 #include <netiso/eonvar.h>
    133 #endif /* EON */
    134 
    135 #include "gre.h"
    136 #if NGRE > 0
    137 #include <netinet/ip_gre.h>
    138 #endif
    139 
    140 extern	struct domain inetdomain;
    141 
    142 struct protosw inetsw[] = {
    143 { 0,		&inetdomain,	0,		0,
    144   0,		ip_output,	0,		0,
    145   0,
    146   ip_init,	0,		ip_slowtimo,	ip_drain,	ip_sysctl
    147 },
    148 { SOCK_DGRAM,	&inetdomain,	IPPROTO_UDP,	PR_ATOMIC|PR_ADDR,
    149   udp_input,	0,		udp_ctlinput,	ip_ctloutput,
    150   udp_usrreq,
    151   udp_init,	0,		0,		0,		udp_sysctl
    152 },
    153 { SOCK_STREAM,	&inetdomain,	IPPROTO_TCP,	PR_CONNREQUIRED|PR_WANTRCVD|PR_LISTEN|PR_ABRTACPTDIS,
    154   tcp_input,	0,		tcp_ctlinput,	tcp_ctloutput,
    155   tcp_usrreq,
    156   tcp_init,	0,		tcp_slowtimo,	tcp_drain,	tcp_sysctl
    157 },
    158 { SOCK_RAW,	&inetdomain,	IPPROTO_RAW,	PR_ATOMIC|PR_ADDR,
    159   rip_input,	rip_output,	rip_ctlinput,	rip_ctloutput,
    160   rip_usrreq,
    161   0,		0,		0,		0,
    162 },
    163 { SOCK_RAW,	&inetdomain,	IPPROTO_ICMP,	PR_ATOMIC|PR_ADDR|PR_LASTHDR,
    164   icmp_input,	rip_output,	rip_ctlinput,	rip_ctloutput,
    165   rip_usrreq,
    166   icmp_init,	0,		0,		0,		icmp_sysctl
    167 },
    168 #ifdef IPSEC
    169 { SOCK_RAW,	&inetdomain,	IPPROTO_AH,	PR_ATOMIC|PR_ADDR,
    170   ah4_input,	0,	 	ah4_ctlinput,	0,
    171   0,
    172   0,		0,		0,		0,		ipsec_sysctl
    173 },
    174 #ifdef IPSEC_ESP
    175 { SOCK_RAW,	&inetdomain,	IPPROTO_ESP,	PR_ATOMIC|PR_ADDR,
    176   esp4_input,	0,	 	esp4_ctlinput,	0,
    177   0,
    178   0,		0,		0,		0,		ipsec_sysctl
    179 },
    180 #endif
    181 { SOCK_RAW,	&inetdomain,	IPPROTO_IPCOMP,	PR_ATOMIC|PR_ADDR,
    182   ipcomp4_input, 0,	 	0,		0,
    183   0,
    184   0,		0,		0,		0,		ipsec_sysctl
    185 },
    186 #endif /* IPSEC */
    187 { SOCK_RAW,	&inetdomain,	IPPROTO_IPV4,	PR_ATOMIC|PR_ADDR|PR_LASTHDR,
    188   encap4_input,	rip_output, 	rip_ctlinput,	rip_ctloutput,
    189   rip_usrreq,	/*XXX*/
    190   encap_init,	0,		0,		0,
    191 },
    192 #ifdef INET6
    193 { SOCK_RAW,	&inetdomain,	IPPROTO_IPV6,	PR_ATOMIC|PR_ADDR|PR_LASTHDR,
    194   encap4_input,	rip_output, 	rip_ctlinput,	rip_ctloutput,
    195   rip_usrreq,	/*XXX*/
    196   encap_init,	0,		0,		0,
    197 },
    198 #endif /* INET6 */
    199 #if NGRE > 0
    200 { SOCK_RAW,	&inetdomain,	IPPROTO_GRE,	PR_ATOMIC|PR_ADDR|PR_LASTHDR,
    201   gre_input,	rip_output,	rip_ctlinput,	rip_ctloutput,
    202   rip_usrreq,
    203   0,		0,		0,		0,
    204 },
    205 { SOCK_RAW,	&inetdomain,	IPPROTO_MOBILE,	PR_ATOMIC|PR_ADDR|PR_LASTHDR,
    206   gre_mobile_input,	rip_output,	rip_ctlinput,	rip_ctloutput,
    207   rip_usrreq,
    208   0,		0,		0,		0,
    209 },
    210 #endif /* NGRE > 0 */
    211 { SOCK_RAW,	&inetdomain,	IPPROTO_IGMP,	PR_ATOMIC|PR_ADDR|PR_LASTHDR,
    212   igmp_input,	rip_output,	rip_ctlinput,	rip_ctloutput,
    213   rip_usrreq,
    214   igmp_init,	igmp_fasttimo,	igmp_slowtimo,	0,
    215 },
    216 #ifdef TPIP
    217 { SOCK_SEQPACKET,&inetdomain,	IPPROTO_TP,	PR_CONNREQUIRED|PR_WANTRCVD|PR_LISTEN|PR_LASTHDR|PR_ABRTACPTDIS,
    218   tpip_input,	0,		tpip_ctlinput,	tp_ctloutput,
    219   tp_usrreq,
    220   tp_init,	0,		tp_slowtimo,	tp_drain,
    221 },
    222 #endif /* TPIP */
    223 #ifdef ISO
    224 /* EON (ISO CLNL over IP) */
    225 #ifdef EON
    226 { SOCK_RAW,	&inetdomain,	IPPROTO_EON,	PR_LASTHDR,
    227   eoninput,	0,		eonctlinput,	0,
    228   0,
    229   eonprotoinit,	0,		0,		0,
    230 },
    231 #else
    232 { SOCK_RAW,	&inetdomain,	IPPROTO_EON,	PR_ATOMIC|PR_ADDR|PR_LASTHDR,
    233   encap4_input,	rip_output,	rip_ctlinput,	rip_ctloutput,
    234   rip_usrreq,	/*XXX*/
    235   encap_init,	0,		0,		0,
    236 },
    237 #endif /* EON */
    238 #endif /* ISO */
    239 #ifdef NSIP
    240 { SOCK_RAW,	&inetdomain,	IPPROTO_IDP,	PR_ATOMIC|PR_ADDR|PR_LASTHDR,
    241   idpip_input,	NULL,		nsip_ctlinput,	0,
    242   rip_usrreq,
    243   0,		0,		0,		0,
    244 },
    245 #endif /* NSIP */
    246 /* raw wildcard */
    247 { SOCK_RAW,	&inetdomain,	0,		PR_ATOMIC|PR_ADDR|PR_LASTHDR,
    248   rip_input,	rip_output,	rip_ctlinput,	rip_ctloutput,
    249   rip_usrreq,
    250   rip_init,	0,		0,		0,
    251 },
    252 };
    253 
    254 struct domain inetdomain =
    255     { PF_INET, "internet", 0, 0, 0,
    256       inetsw, &inetsw[sizeof(inetsw)/sizeof(inetsw[0])], 0,
    257       rn_inithead, 32, sizeof(struct sockaddr_in) };
    258 
    259 u_char	ip_protox[IPPROTO_MAX];
    260 
    261 int icmperrppslim = 100;			/* 100pps */
    262