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