Home | History | Annotate | Line # | Download | only in netinet
in_proto.c revision 1.29.2.1.4.1
      1 /*	$NetBSD: in_proto.c,v 1.29.2.1.4.1 1999/06/28 06:36:59 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. 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 
     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 #ifdef RADISH
     81 #include <net/radish.h>
     82 #else /* RADISH */
     83 #include <net/radix.h>
     84 #endif /* RADISH */
     85 #include <net/route.h>
     86 
     87 #include <netinet/in.h>
     88 #include <netinet/in_systm.h>
     89 #include <netinet/ip.h>
     90 #include <netinet/ip_var.h>
     91 #include <netinet/ip_icmp.h>
     92 #include <netinet/in_pcb.h>
     93 
     94 #ifdef INET6
     95 #ifndef INET
     96 #include <netinet/in.h>
     97 #endif
     98 #include <netinet/ip6.h>
     99 #endif
    100 
    101 #include <netinet/igmp_var.h>
    102 #include <netinet/tcp.h>
    103 #include <netinet/tcp_fsm.h>
    104 #include <netinet/tcp_seq.h>
    105 #include <netinet/tcp_timer.h>
    106 #include <netinet/tcp_var.h>
    107 #include <netinet/tcpip.h>
    108 #include <netinet/tcp_debug.h>
    109 #include <netinet/udp.h>
    110 #include <netinet/udp_var.h>
    111 /*
    112  * TCP/IP protocol family: IP, ICMP, UDP, TCP.
    113  */
    114 
    115 #ifdef IPSEC
    116 #include <netinet6/ah.h>
    117 #ifdef IPSEC_ESP
    118 #include <netinet6/esp.h>
    119 #endif
    120 #include <netinet6/ipcomp.h>
    121 #endif /* IPSEC */
    122 
    123 #include "gif.h"
    124 #if NGIF > 0
    125 #include <netinet/in_gif.h>
    126 #endif
    127 
    128 #ifdef NSIP
    129 #include <netns/ns_var.h>
    130 #include <netns/idp_var.h>
    131 #endif /* NSIP */
    132 
    133 #ifdef TPIP
    134 #include <netiso/tp_param.h>
    135 #include <netiso/tp_var.h>
    136 #endif /* TPIP */
    137 
    138 #ifdef EON
    139 #include <netiso/eonvar.h>
    140 #endif /* EON */
    141 
    142 #include "ipip.h"
    143 #if NIPIP > 0 || defined(MROUTING)
    144 #include <netinet/ip_ipip.h>
    145 #endif /* NIPIP > 0 || MROUTING */
    146 
    147 #include "gre.h"
    148 #if NGRE > 0
    149 #include <netinet/ip_gre.h>
    150 #endif
    151 
    152 extern	struct domain inetdomain;
    153 
    154 struct protosw inetsw[] = {
    155 { 0,		&inetdomain,	0,		0,
    156   0,		ip_output,	0,		0,
    157   0,
    158   ip_init,	0,		ip_slowtimo,	ip_drain,	ip_sysctl
    159 },
    160 { SOCK_DGRAM,	&inetdomain,	IPPROTO_UDP,	PR_ATOMIC|PR_ADDR,
    161   udp_input,	0,		udp_ctlinput,	ip_ctloutput,
    162   udp_usrreq,
    163   udp_init,	0,		0,		0,		udp_sysctl
    164 },
    165 { SOCK_STREAM,	&inetdomain,	IPPROTO_TCP,	PR_CONNREQUIRED|PR_WANTRCVD,
    166   tcp_input,	0,		tcp_ctlinput,	tcp_ctloutput,
    167   tcp_usrreq,
    168   tcp_init,	tcp_fasttimo,	tcp_slowtimo,	tcp_drain,	tcp_sysctl
    169 },
    170 { SOCK_RAW,	&inetdomain,	IPPROTO_RAW,	PR_ATOMIC|PR_ADDR,
    171   rip_input,	rip_output,	0,		rip_ctloutput,
    172   rip_usrreq,
    173   0,		0,		0,		0,
    174 },
    175 { SOCK_RAW,	&inetdomain,	IPPROTO_ICMP,	PR_ATOMIC|PR_ADDR,
    176   icmp_input,	rip_output,	0,		rip_ctloutput,
    177   rip_usrreq,
    178   0,		0,		0,		0,		icmp_sysctl
    179 },
    180 #ifdef IPSEC
    181 { SOCK_RAW,	&inetdomain,	IPPROTO_AH,	PR_ATOMIC|PR_ADDR,
    182   ah4_input,	0,	 	0,		0,
    183   0,
    184   0,		0,		0,		0,		ipsec_sysctl
    185 },
    186 #ifdef IPSEC_ESP
    187 { SOCK_RAW,	&inetdomain,	IPPROTO_ESP,	PR_ATOMIC|PR_ADDR,
    188   esp4_input,	0,	 	0,		0,
    189   0,
    190   0,		0,		0,		0,		ipsec_sysctl
    191 },
    192 #endif
    193 { SOCK_RAW,	&inetdomain,	IPPROTO_IPCOMP,	PR_ATOMIC|PR_ADDR,
    194   ipcomp4_input, 0,	 	0,		0,
    195   0,
    196   0,		0,		0,		0,		ipsec_sysctl
    197 },
    198 #endif /* IPSEC */
    199 #if NGIF > 0
    200 { SOCK_RAW,	&inetdomain,	IPPROTO_IPV4,	PR_ATOMIC|PR_ADDR,
    201   in_gif_input,	0,	 	0,		0,
    202   0,
    203   0,		0,		0,		0,
    204 },
    205 #ifdef INET6
    206 { SOCK_RAW,	&inetdomain,	IPPROTO_IPV6,	PR_ATOMIC|PR_ADDR,
    207   in_gif_input,	0,	 	0,		0,
    208   0,
    209   0,		0,		0,		0,
    210 },
    211 #endif /* INET6 */
    212 #else /* NGIF */
    213 #if NIPIP > 0 || defined(MROUTING)
    214 { SOCK_RAW,	&inetdomain,	IPPROTO_IPIP,	PR_ATOMIC|PR_ADDR,
    215   ipip_input,	rip_output,	0,		rip_ctloutput,
    216   rip_usrreq,	/* XXX */
    217   0,		0,		0,		0,
    218 },
    219 #endif /* NIPIP > 0 || MROUTING */
    220 #if NGRE > 0
    221 { SOCK_RAW,	&inetdomain,	IPPROTO_GRE,	PR_ATOMIC|PR_ADDR,
    222   gre_input,	rip_output,	0,		rip_ctloutput,
    223   rip_usrreq,
    224   0,		0,		0,		0,
    225 },
    226 { SOCK_RAW,	&inetdomain,	IPPROTO_MOBILE,	PR_ATOMIC|PR_ADDR,
    227   gre_mobile_input,	rip_output,	0,		rip_ctloutput,
    228   rip_usrreq,
    229   0,		0,		0,		0,
    230 },
    231 #endif /* NGRE > 0 */
    232 #endif /* NGIF */
    233 { SOCK_RAW,	&inetdomain,	IPPROTO_IGMP,	PR_ATOMIC|PR_ADDR,
    234   igmp_input,	rip_output,	0,		rip_ctloutput,
    235   rip_usrreq,
    236   igmp_init,	igmp_fasttimo,	igmp_slowtimo,	0,
    237 },
    238 #ifdef TPIP
    239 { SOCK_SEQPACKET,&inetdomain,	IPPROTO_TP,	PR_CONNREQUIRED|PR_WANTRCVD,
    240   tpip_input,	0,		tpip_ctlinput,	tp_ctloutput,
    241   tp_usrreq,
    242   tp_init,	0,		tp_slowtimo,	tp_drain,
    243 },
    244 #endif /* TPIP */
    245 /* EON (ISO CLNL over IP) */
    246 #ifdef EON
    247 { SOCK_RAW,	&inetdomain,	IPPROTO_EON,	0,
    248   eoninput,	0,		eonctlinput,		0,
    249   0,
    250   eonprotoinit,	0,		0,		0,
    251 },
    252 #endif /* EON */
    253 #ifdef NSIP
    254 { SOCK_RAW,	&inetdomain,	IPPROTO_IDP,	PR_ATOMIC|PR_ADDR,
    255   idpip_input,	NULL,		nsip_ctlinput,	0,
    256   rip_usrreq,
    257   0,		0,		0,		0,
    258 },
    259 #endif /* NSIP */
    260 /* raw wildcard */
    261 { SOCK_RAW,	&inetdomain,	0,		PR_ATOMIC|PR_ADDR,
    262   rip_input,	rip_output,	0,		rip_ctloutput,
    263   rip_usrreq,
    264   rip_init,	0,		0,		0,
    265 },
    266 };
    267 
    268 struct domain inetdomain =
    269     { PF_INET, "internet", 0, 0, 0,
    270       inetsw, &inetsw[sizeof(inetsw)/sizeof(inetsw[0])], 0,
    271       rn_inithead, 32, sizeof(struct sockaddr_in) };
    272 
    273 #define	TCP_SYN_HASH_SIZE	293
    274 #define	TCP_SYN_BUCKET_SIZE	35
    275 
    276 int	tcp_syn_cache_size = TCP_SYN_HASH_SIZE;
    277 int	tcp_syn_cache_limit = TCP_SYN_HASH_SIZE*TCP_SYN_BUCKET_SIZE;
    278 int	tcp_syn_bucket_limit = 3*TCP_SYN_BUCKET_SIZE;
    279 struct	syn_cache_head tcp_syn_cache[TCP_SYN_HASH_SIZE];
    280 int	tcp_syn_cache_interval = 1;	/* runs timer twice a second */
    281