Home | History | Annotate | Line # | Download | only in netinet
in_proto.c revision 1.19
      1 /*	$NetBSD: in_proto.c,v 1.19 1998/01/12 03:02:50 scottr 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 
     40 #include <sys/param.h>
     41 #include <sys/socket.h>
     42 #include <sys/protosw.h>
     43 #include <sys/domain.h>
     44 #include <sys/mbuf.h>
     45 
     46 #include <net/if.h>
     47 #include <net/radix.h>
     48 #include <net/route.h>
     49 
     50 #include <netinet/in.h>
     51 #include <netinet/in_systm.h>
     52 #include <netinet/ip.h>
     53 #include <netinet/ip_var.h>
     54 #include <netinet/ip_icmp.h>
     55 #include <netinet/in_pcb.h>
     56 #include <netinet/igmp_var.h>
     57 #include <netinet/tcp.h>
     58 #include <netinet/tcp_fsm.h>
     59 #include <netinet/tcp_seq.h>
     60 #include <netinet/tcp_timer.h>
     61 #include <netinet/tcp_var.h>
     62 #include <netinet/tcpip.h>
     63 #include <netinet/tcp_debug.h>
     64 #include <netinet/udp.h>
     65 #include <netinet/udp_var.h>
     66 /*
     67  * TCP/IP protocol family: IP, ICMP, UDP, TCP.
     68  */
     69 
     70 #ifdef NSIP
     71 #include <netns/ns_var.h>
     72 #include <netns/idp_var.h>
     73 #endif /* NSIP */
     74 
     75 #ifdef TPIP
     76 #include <netiso/tp_param.h>
     77 #include <netiso/tp_var.h>
     78 #endif /* TPIP */
     79 
     80 #ifdef EON
     81 #include <netiso/eonvar.h>
     82 #endif /* EON */
     83 
     84 #ifdef MROUTING
     85 #include <netinet/ip_mroute.h>
     86 #endif /* MROUTING */
     87 
     88 extern	struct domain inetdomain;
     89 
     90 struct protosw inetsw[] = {
     91 { 0,		&inetdomain,	0,		0,
     92   0,		ip_output,	0,		0,
     93   0,
     94   ip_init,	0,		ip_slowtimo,	ip_drain,	ip_sysctl
     95 },
     96 { SOCK_DGRAM,	&inetdomain,	IPPROTO_UDP,	PR_ATOMIC|PR_ADDR,
     97   udp_input,	0,		udp_ctlinput,	ip_ctloutput,
     98   udp_usrreq,
     99   udp_init,	0,		0,		0,		udp_sysctl
    100 },
    101 { SOCK_STREAM,	&inetdomain,	IPPROTO_TCP,	PR_CONNREQUIRED|PR_WANTRCVD,
    102   tcp_input,	0,		tcp_ctlinput,	tcp_ctloutput,
    103   tcp_usrreq,
    104   tcp_init,	tcp_fasttimo,	tcp_slowtimo,	tcp_drain,	tcp_sysctl
    105 },
    106 { SOCK_RAW,	&inetdomain,	IPPROTO_RAW,	PR_ATOMIC|PR_ADDR,
    107   rip_input,	rip_output,	0,		rip_ctloutput,
    108   rip_usrreq,
    109   0,		0,		0,		0,
    110 },
    111 { SOCK_RAW,	&inetdomain,	IPPROTO_ICMP,	PR_ATOMIC|PR_ADDR,
    112   icmp_input,	rip_output,	0,		rip_ctloutput,
    113   rip_usrreq,
    114   0,		0,		0,		0,		icmp_sysctl
    115 },
    116 #ifdef MROUTING
    117 { SOCK_RAW,	&inetdomain,	IPPROTO_IPIP,	PR_ATOMIC|PR_ADDR,
    118   ipip_input,	rip_output,	0,		rip_ctloutput,
    119   rip_usrreq,	/* XXX */
    120   0,		0,		0,		0,
    121 },
    122 #endif /* MROUTING */
    123 { SOCK_RAW,	&inetdomain,	IPPROTO_IGMP,	PR_ATOMIC|PR_ADDR,
    124   igmp_input,	rip_output,	0,		rip_ctloutput,
    125   rip_usrreq,
    126   igmp_init,	igmp_fasttimo,	igmp_slowtimo,	0,
    127 },
    128 #ifdef TPIP
    129 { SOCK_SEQPACKET,&inetdomain,	IPPROTO_TP,	PR_CONNREQUIRED|PR_WANTRCVD,
    130   tpip_input,	0,		tpip_ctlinput,	tp_ctloutput,
    131   tp_usrreq,
    132   tp_init,	0,		tp_slowtimo,	tp_drain,
    133 },
    134 #endif /* TPIP */
    135 /* EON (ISO CLNL over IP) */
    136 #ifdef EON
    137 { SOCK_RAW,	&inetdomain,	IPPROTO_EON,	0,
    138   eoninput,	0,		eonctlinput,		0,
    139   0,
    140   eonprotoinit,	0,		0,		0,
    141 },
    142 #endif /* EON */
    143 #ifdef NSIP
    144 { SOCK_RAW,	&inetdomain,	IPPROTO_IDP,	PR_ATOMIC|PR_ADDR,
    145   idpip_input,	NULL,		nsip_ctlinput,	0,
    146   rip_usrreq,
    147   0,		0,		0,		0,
    148 },
    149 #endif /* NSIP */
    150 /* raw wildcard */
    151 { SOCK_RAW,	&inetdomain,	0,		PR_ATOMIC|PR_ADDR,
    152   rip_input,	rip_output,	0,		rip_ctloutput,
    153   rip_usrreq,
    154   rip_init,	0,		0,		0,
    155 },
    156 };
    157 
    158 struct domain inetdomain =
    159     { AF_INET, "internet", 0, 0, 0,
    160       inetsw, &inetsw[sizeof(inetsw)/sizeof(inetsw[0])], 0,
    161       rn_inithead, 32, sizeof(struct sockaddr_in) };
    162 
    163 #ifdef notyet /* XXXX */
    164 #include "imp.h"
    165 #if NIMP > 0
    166 extern	struct domain impdomain;
    167 int	rimp_output(), hostslowtimo();
    168 
    169 struct protosw impsw[] = {
    170 { SOCK_RAW,	&impdomain,	0,		PR_ATOMIC|PR_ADDR,
    171   0,		rimp_output,	0,		0,
    172   rip_usrreq,
    173   0,		0,		hostslowtimo,	0,
    174 },
    175 };
    176 
    177 struct domain impdomain =
    178     { AF_IMPLINK, "imp", 0, 0, 0,
    179       impsw, &impsw[sizeof (impsw)/sizeof(impsw[0])] };
    180 #endif
    181 
    182 #include "hy.h"
    183 #if NHY > 0
    184 /*
    185  * HYPERchannel protocol family: raw interface.
    186  */
    187 int	rhy_output();
    188 extern	struct domain hydomain;
    189 
    190 struct protosw hysw[] = {
    191 { SOCK_RAW,	&hydomain,	0,		PR_ATOMIC|PR_ADDR,
    192   0,		rhy_output,	0,		0,
    193   rip_usrreq,
    194   0,		0,		0,		0,
    195 },
    196 };
    197 
    198 struct domain hydomain =
    199     { AF_HYLINK, "hy", 0, 0, 0, hysw, &hysw[sizeof (hysw)/sizeof(hysw[0])] };
    200 #endif
    201 #endif
    202 
    203 
    204 #define	TCP_SYN_HASH_SIZE	293
    205 #define	TCP_SYN_BUCKET_SIZE	35
    206 
    207 int	tcp_syn_cache_size = TCP_SYN_HASH_SIZE;
    208 int	tcp_syn_cache_limit = TCP_SYN_HASH_SIZE*TCP_SYN_BUCKET_SIZE;
    209 int	tcp_syn_bucket_limit = 3*TCP_SYN_BUCKET_SIZE;
    210 struct	syn_cache_head tcp_syn_cache[TCP_SYN_HASH_SIZE];
    211 struct	syn_cache_head *tcp_syn_cache_first;
    212 int	tcp_syn_cache_interval = 8;	/* runs timer every 4 seconds */
    213 int	tcp_syn_cache_timeo = TCPTV_KEEP_INIT;
    214