Home | History | Annotate | Line # | Download | only in netinet
in_proto.c revision 1.29
      1 /*	$NetBSD: in_proto.c,v 1.29 1999/01/14 01:16:55 thorpej Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1982, 1986, 1993
      5  *	The Regents of the University of California.  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. All advertising materials mentioning features or use of this software
     16  *    must display the following acknowledgement:
     17  *	This product includes software developed by the University of
     18  *	California, Berkeley and its contributors.
     19  * 4. Neither the name of the University nor the names of its contributors
     20  *    may be used to endorse or promote products derived from this software
     21  *    without specific prior written permission.
     22  *
     23  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33  * SUCH DAMAGE.
     34  *
     35  *	@(#)in_proto.c	8.2 (Berkeley) 2/9/95
     36  */
     37 
     38 #include "opt_mrouting.h"
     39 #include "opt_eon.h"			/* ISO CLNL over IP */
     40 #include "opt_iso.h"			/* ISO TP tunneled over IP */
     41 #include "opt_ns.h"			/* NSIP: XNS tunneled over IP */
     42 
     43 #include <sys/param.h>
     44 #include <sys/socket.h>
     45 #include <sys/protosw.h>
     46 #include <sys/domain.h>
     47 #include <sys/mbuf.h>
     48 
     49 #include <net/if.h>
     50 #include <net/radix.h>
     51 #include <net/route.h>
     52 
     53 #include <netinet/in.h>
     54 #include <netinet/in_systm.h>
     55 #include <netinet/ip.h>
     56 #include <netinet/ip_var.h>
     57 #include <netinet/ip_icmp.h>
     58 #include <netinet/in_pcb.h>
     59 #include <netinet/igmp_var.h>
     60 #include <netinet/tcp.h>
     61 #include <netinet/tcp_fsm.h>
     62 #include <netinet/tcp_seq.h>
     63 #include <netinet/tcp_timer.h>
     64 #include <netinet/tcp_var.h>
     65 #include <netinet/tcpip.h>
     66 #include <netinet/tcp_debug.h>
     67 #include <netinet/udp.h>
     68 #include <netinet/udp_var.h>
     69 /*
     70  * TCP/IP protocol family: IP, ICMP, UDP, TCP.
     71  */
     72 
     73 #ifdef NSIP
     74 #include <netns/ns_var.h>
     75 #include <netns/idp_var.h>
     76 #endif /* NSIP */
     77 
     78 #ifdef TPIP
     79 #include <netiso/tp_param.h>
     80 #include <netiso/tp_var.h>
     81 #endif /* TPIP */
     82 
     83 #ifdef EON
     84 #include <netiso/eonvar.h>
     85 #endif /* EON */
     86 
     87 #include "ipip.h"
     88 #if NIPIP > 0 || defined(MROUTING)
     89 #include <netinet/ip_ipip.h>
     90 #endif /* NIPIP > 0 || MROUTING */
     91 
     92 #include "gre.h"
     93 #if NGRE > 0
     94 #include <netinet/ip_gre.h>
     95 #endif
     96 
     97 extern	struct domain inetdomain;
     98 
     99 struct protosw inetsw[] = {
    100 { 0,		&inetdomain,	0,		0,
    101   0,		ip_output,	0,		0,
    102   0,
    103   ip_init,	0,		ip_slowtimo,	ip_drain,	ip_sysctl
    104 },
    105 { SOCK_DGRAM,	&inetdomain,	IPPROTO_UDP,	PR_ATOMIC|PR_ADDR,
    106   udp_input,	0,		udp_ctlinput,	ip_ctloutput,
    107   udp_usrreq,
    108   udp_init,	0,		0,		0,		udp_sysctl
    109 },
    110 { SOCK_STREAM,	&inetdomain,	IPPROTO_TCP,	PR_CONNREQUIRED|PR_WANTRCVD,
    111   tcp_input,	0,		tcp_ctlinput,	tcp_ctloutput,
    112   tcp_usrreq,
    113   tcp_init,	tcp_fasttimo,	tcp_slowtimo,	tcp_drain,	tcp_sysctl
    114 },
    115 { SOCK_RAW,	&inetdomain,	IPPROTO_RAW,	PR_ATOMIC|PR_ADDR,
    116   rip_input,	rip_output,	0,		rip_ctloutput,
    117   rip_usrreq,
    118   0,		0,		0,		0,
    119 },
    120 { SOCK_RAW,	&inetdomain,	IPPROTO_ICMP,	PR_ATOMIC|PR_ADDR,
    121   icmp_input,	rip_output,	0,		rip_ctloutput,
    122   rip_usrreq,
    123   0,		0,		0,		0,		icmp_sysctl
    124 },
    125 #if NIPIP > 0 || defined(MROUTING)
    126 { SOCK_RAW,	&inetdomain,	IPPROTO_IPIP,	PR_ATOMIC|PR_ADDR,
    127   ipip_input,	rip_output,	0,		rip_ctloutput,
    128   rip_usrreq,	/* XXX */
    129   0,		0,		0,		0,
    130 },
    131 #endif /* NIPIP > 0 || MROUTING */
    132 #if NGRE > 0
    133 { SOCK_RAW,	&inetdomain,	IPPROTO_GRE,	PR_ATOMIC|PR_ADDR,
    134   gre_input,	rip_output,	0,		rip_ctloutput,
    135   rip_usrreq,
    136   0,		0,		0,		0,
    137 },
    138 { SOCK_RAW,	&inetdomain,	IPPROTO_MOBILE,	PR_ATOMIC|PR_ADDR,
    139   gre_mobile_input,	rip_output,	0,		rip_ctloutput,
    140   rip_usrreq,
    141   0,		0,		0,		0,
    142 },
    143 #endif /* NGRE > 0 */
    144 { SOCK_RAW,	&inetdomain,	IPPROTO_IGMP,	PR_ATOMIC|PR_ADDR,
    145   igmp_input,	rip_output,	0,		rip_ctloutput,
    146   rip_usrreq,
    147   igmp_init,	igmp_fasttimo,	igmp_slowtimo,	0,
    148 },
    149 #ifdef TPIP
    150 { SOCK_SEQPACKET,&inetdomain,	IPPROTO_TP,	PR_CONNREQUIRED|PR_WANTRCVD,
    151   tpip_input,	0,		tpip_ctlinput,	tp_ctloutput,
    152   tp_usrreq,
    153   tp_init,	0,		tp_slowtimo,	tp_drain,
    154 },
    155 #endif /* TPIP */
    156 /* EON (ISO CLNL over IP) */
    157 #ifdef EON
    158 { SOCK_RAW,	&inetdomain,	IPPROTO_EON,	0,
    159   eoninput,	0,		eonctlinput,		0,
    160   0,
    161   eonprotoinit,	0,		0,		0,
    162 },
    163 #endif /* EON */
    164 #ifdef NSIP
    165 { SOCK_RAW,	&inetdomain,	IPPROTO_IDP,	PR_ATOMIC|PR_ADDR,
    166   idpip_input,	NULL,		nsip_ctlinput,	0,
    167   rip_usrreq,
    168   0,		0,		0,		0,
    169 },
    170 #endif /* NSIP */
    171 /* raw wildcard */
    172 { SOCK_RAW,	&inetdomain,	0,		PR_ATOMIC|PR_ADDR,
    173   rip_input,	rip_output,	0,		rip_ctloutput,
    174   rip_usrreq,
    175   rip_init,	0,		0,		0,
    176 },
    177 };
    178 
    179 struct domain inetdomain =
    180     { PF_INET, "internet", 0, 0, 0,
    181       inetsw, &inetsw[sizeof(inetsw)/sizeof(inetsw[0])], 0,
    182       rn_inithead, 32, sizeof(struct sockaddr_in) };
    183 
    184 #define	TCP_SYN_HASH_SIZE	293
    185 #define	TCP_SYN_BUCKET_SIZE	35
    186 
    187 int	tcp_syn_cache_size = TCP_SYN_HASH_SIZE;
    188 int	tcp_syn_cache_limit = TCP_SYN_HASH_SIZE*TCP_SYN_BUCKET_SIZE;
    189 int	tcp_syn_bucket_limit = 3*TCP_SYN_BUCKET_SIZE;
    190 struct	syn_cache_head tcp_syn_cache[TCP_SYN_HASH_SIZE];
    191 int	tcp_syn_cache_interval = 8;	/* runs timer every 4 seconds */
    192 int	tcp_syn_cache_timeo = TCPTV_KEEP_INIT;
    193