Home | History | Annotate | Line # | Download | only in netinet
in_proto.c revision 1.29.2.1.2.2
      1  1.29.2.1.2.2   thorpej /*	$NetBSD: in_proto.c,v 1.29.2.1.2.2 1999/07/01 23:47:00 thorpej Exp $	*/
      2  1.29.2.1.2.2   thorpej 
      3  1.29.2.1.2.2   thorpej /*
      4  1.29.2.1.2.2   thorpej  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
      5  1.29.2.1.2.2   thorpej  * All rights reserved.
      6  1.29.2.1.2.2   thorpej  *
      7  1.29.2.1.2.2   thorpej  * Redistribution and use in source and binary forms, with or without
      8  1.29.2.1.2.2   thorpej  * modification, are permitted provided that the following conditions
      9  1.29.2.1.2.2   thorpej  * are met:
     10  1.29.2.1.2.2   thorpej  * 1. Redistributions of source code must retain the above copyright
     11  1.29.2.1.2.2   thorpej  *    notice, this list of conditions and the following disclaimer.
     12  1.29.2.1.2.2   thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.29.2.1.2.2   thorpej  *    notice, this list of conditions and the following disclaimer in the
     14  1.29.2.1.2.2   thorpej  *    documentation and/or other materials provided with the distribution.
     15  1.29.2.1.2.2   thorpej  * 3. Neither the name of the project nor the names of its contributors
     16  1.29.2.1.2.2   thorpej  *    may be used to endorse or promote products derived from this software
     17  1.29.2.1.2.2   thorpej  *    without specific prior written permission.
     18  1.29.2.1.2.2   thorpej  *
     19  1.29.2.1.2.2   thorpej  * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
     20  1.29.2.1.2.2   thorpej  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     21  1.29.2.1.2.2   thorpej  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     22  1.29.2.1.2.2   thorpej  * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
     23  1.29.2.1.2.2   thorpej  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     24  1.29.2.1.2.2   thorpej  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     25  1.29.2.1.2.2   thorpej  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     26  1.29.2.1.2.2   thorpej  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     27  1.29.2.1.2.2   thorpej  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     28  1.29.2.1.2.2   thorpej  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     29  1.29.2.1.2.2   thorpej  * SUCH DAMAGE.
     30  1.29.2.1.2.2   thorpej  */
     31           1.9       cgd 
     32           1.1       cgd /*
     33           1.8   mycroft  * Copyright (c) 1982, 1986, 1993
     34           1.8   mycroft  *	The Regents of the University of California.  All rights reserved.
     35           1.1       cgd  *
     36           1.1       cgd  * Redistribution and use in source and binary forms, with or without
     37           1.1       cgd  * modification, are permitted provided that the following conditions
     38           1.1       cgd  * are met:
     39           1.1       cgd  * 1. Redistributions of source code must retain the above copyright
     40           1.1       cgd  *    notice, this list of conditions and the following disclaimer.
     41           1.1       cgd  * 2. Redistributions in binary form must reproduce the above copyright
     42           1.1       cgd  *    notice, this list of conditions and the following disclaimer in the
     43           1.1       cgd  *    documentation and/or other materials provided with the distribution.
     44           1.1       cgd  * 3. All advertising materials mentioning features or use of this software
     45           1.1       cgd  *    must display the following acknowledgement:
     46           1.1       cgd  *	This product includes software developed by the University of
     47           1.1       cgd  *	California, Berkeley and its contributors.
     48           1.1       cgd  * 4. Neither the name of the University nor the names of its contributors
     49           1.1       cgd  *    may be used to endorse or promote products derived from this software
     50           1.1       cgd  *    without specific prior written permission.
     51           1.1       cgd  *
     52           1.1       cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     53           1.1       cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     54           1.1       cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     55           1.1       cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     56           1.1       cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     57           1.1       cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     58           1.1       cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     59           1.1       cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     60           1.1       cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     61           1.1       cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     62           1.1       cgd  * SUCH DAMAGE.
     63           1.1       cgd  *
     64          1.18   thorpej  *	@(#)in_proto.c	8.2 (Berkeley) 2/9/95
     65           1.1       cgd  */
     66          1.19    scottr 
     67          1.19    scottr #include "opt_mrouting.h"
     68          1.22  jonathan #include "opt_eon.h"			/* ISO CLNL over IP */
     69          1.22  jonathan #include "opt_iso.h"			/* ISO TP tunneled over IP */
     70          1.23  jonathan #include "opt_ns.h"			/* NSIP: XNS tunneled over IP */
     71  1.29.2.1.2.2   thorpej #include "opt_inet.h"
     72           1.1       cgd 
     73           1.5   mycroft #include <sys/param.h>
     74           1.5   mycroft #include <sys/socket.h>
     75           1.5   mycroft #include <sys/protosw.h>
     76           1.5   mycroft #include <sys/domain.h>
     77           1.5   mycroft #include <sys/mbuf.h>
     78           1.1       cgd 
     79           1.8   mycroft #include <net/if.h>
     80           1.8   mycroft #include <net/radix.h>
     81           1.8   mycroft #include <net/route.h>
     82           1.8   mycroft 
     83           1.5   mycroft #include <netinet/in.h>
     84           1.5   mycroft #include <netinet/in_systm.h>
     85           1.8   mycroft #include <netinet/ip.h>
     86           1.8   mycroft #include <netinet/ip_var.h>
     87           1.8   mycroft #include <netinet/ip_icmp.h>
     88           1.8   mycroft #include <netinet/in_pcb.h>
     89  1.29.2.1.2.2   thorpej 
     90  1.29.2.1.2.2   thorpej #ifdef INET6
     91  1.29.2.1.2.2   thorpej #ifndef INET
     92  1.29.2.1.2.2   thorpej #include <netinet/in.h>
     93  1.29.2.1.2.2   thorpej #endif
     94  1.29.2.1.2.2   thorpej #include <netinet/ip6.h>
     95  1.29.2.1.2.2   thorpej #endif
     96  1.29.2.1.2.2   thorpej 
     97           1.8   mycroft #include <netinet/igmp_var.h>
     98           1.8   mycroft #include <netinet/tcp.h>
     99           1.8   mycroft #include <netinet/tcp_fsm.h>
    100           1.8   mycroft #include <netinet/tcp_seq.h>
    101           1.8   mycroft #include <netinet/tcp_timer.h>
    102           1.8   mycroft #include <netinet/tcp_var.h>
    103           1.8   mycroft #include <netinet/tcpip.h>
    104           1.8   mycroft #include <netinet/tcp_debug.h>
    105           1.8   mycroft #include <netinet/udp.h>
    106           1.8   mycroft #include <netinet/udp_var.h>
    107           1.1       cgd /*
    108           1.1       cgd  * TCP/IP protocol family: IP, ICMP, UDP, TCP.
    109           1.1       cgd  */
    110           1.1       cgd 
    111  1.29.2.1.2.2   thorpej #ifdef IPSEC
    112  1.29.2.1.2.2   thorpej #include <netinet6/ah.h>
    113  1.29.2.1.2.2   thorpej #ifdef IPSEC_ESP
    114  1.29.2.1.2.2   thorpej #include <netinet6/esp.h>
    115  1.29.2.1.2.2   thorpej #endif
    116  1.29.2.1.2.2   thorpej #include <netinet6/ipcomp.h>
    117  1.29.2.1.2.2   thorpej #endif /* IPSEC */
    118  1.29.2.1.2.2   thorpej 
    119  1.29.2.1.2.2   thorpej #include "gif.h"
    120  1.29.2.1.2.2   thorpej #if NGIF > 0
    121  1.29.2.1.2.2   thorpej #include <netinet/in_gif.h>
    122  1.29.2.1.2.2   thorpej #endif
    123  1.29.2.1.2.2   thorpej 
    124           1.1       cgd #ifdef NSIP
    125          1.13  christos #include <netns/ns_var.h>
    126          1.13  christos #include <netns/idp_var.h>
    127          1.11   mycroft #endif /* NSIP */
    128           1.1       cgd 
    129           1.1       cgd #ifdef TPIP
    130          1.13  christos #include <netiso/tp_param.h>
    131          1.13  christos #include <netiso/tp_var.h>
    132          1.11   mycroft #endif /* TPIP */
    133           1.1       cgd 
    134           1.1       cgd #ifdef EON
    135          1.13  christos #include <netiso/eonvar.h>
    136           1.8   mycroft #endif /* EON */
    137           1.1       cgd 
    138          1.28   thorpej #include "ipip.h"
    139          1.28   thorpej #if NIPIP > 0 || defined(MROUTING)
    140          1.28   thorpej #include <netinet/ip_ipip.h>
    141          1.28   thorpej #endif /* NIPIP > 0 || MROUTING */
    142          1.11   mycroft 
    143          1.25       hwr #include "gre.h"
    144          1.28   thorpej #if NGRE > 0
    145          1.28   thorpej #include <netinet/ip_gre.h>
    146          1.25       hwr #endif
    147          1.25       hwr 
    148           1.1       cgd extern	struct domain inetdomain;
    149           1.1       cgd 
    150           1.1       cgd struct protosw inetsw[] = {
    151           1.1       cgd { 0,		&inetdomain,	0,		0,
    152           1.1       cgd   0,		ip_output,	0,		0,
    153           1.1       cgd   0,
    154           1.8   mycroft   ip_init,	0,		ip_slowtimo,	ip_drain,	ip_sysctl
    155           1.1       cgd },
    156           1.1       cgd { SOCK_DGRAM,	&inetdomain,	IPPROTO_UDP,	PR_ATOMIC|PR_ADDR,
    157           1.1       cgd   udp_input,	0,		udp_ctlinput,	ip_ctloutput,
    158           1.1       cgd   udp_usrreq,
    159           1.8   mycroft   udp_init,	0,		0,		0,		udp_sysctl
    160           1.1       cgd },
    161  1.29.2.1.2.2   thorpej { SOCK_STREAM,	&inetdomain,	IPPROTO_TCP,	PR_CONNREQUIRED|PR_WANTRCVD|PR_LISTEN,
    162           1.1       cgd   tcp_input,	0,		tcp_ctlinput,	tcp_ctloutput,
    163           1.1       cgd   tcp_usrreq,
    164          1.12   thorpej   tcp_init,	tcp_fasttimo,	tcp_slowtimo,	tcp_drain,	tcp_sysctl
    165           1.1       cgd },
    166           1.1       cgd { SOCK_RAW,	&inetdomain,	IPPROTO_RAW,	PR_ATOMIC|PR_ADDR,
    167           1.1       cgd   rip_input,	rip_output,	0,		rip_ctloutput,
    168           1.1       cgd   rip_usrreq,
    169           1.1       cgd   0,		0,		0,		0,
    170           1.1       cgd },
    171           1.1       cgd { SOCK_RAW,	&inetdomain,	IPPROTO_ICMP,	PR_ATOMIC|PR_ADDR,
    172           1.1       cgd   icmp_input,	rip_output,	0,		rip_ctloutput,
    173           1.1       cgd   rip_usrreq,
    174           1.8   mycroft   0,		0,		0,		0,		icmp_sysctl
    175           1.8   mycroft },
    176  1.29.2.1.2.2   thorpej #ifdef IPSEC
    177  1.29.2.1.2.2   thorpej { SOCK_RAW,	&inetdomain,	IPPROTO_AH,	PR_ATOMIC|PR_ADDR,
    178  1.29.2.1.2.2   thorpej   ah4_input,	0,	 	0,		0,
    179  1.29.2.1.2.2   thorpej   0,
    180  1.29.2.1.2.2   thorpej   0,		0,		0,		0,		ipsec_sysctl
    181  1.29.2.1.2.2   thorpej },
    182  1.29.2.1.2.2   thorpej #ifdef IPSEC_ESP
    183  1.29.2.1.2.2   thorpej { SOCK_RAW,	&inetdomain,	IPPROTO_ESP,	PR_ATOMIC|PR_ADDR,
    184  1.29.2.1.2.2   thorpej   esp4_input,	0,	 	0,		0,
    185  1.29.2.1.2.2   thorpej   0,
    186  1.29.2.1.2.2   thorpej   0,		0,		0,		0,		ipsec_sysctl
    187  1.29.2.1.2.2   thorpej },
    188  1.29.2.1.2.2   thorpej #endif
    189  1.29.2.1.2.2   thorpej { SOCK_RAW,	&inetdomain,	IPPROTO_IPCOMP,	PR_ATOMIC|PR_ADDR,
    190  1.29.2.1.2.2   thorpej   ipcomp4_input, 0,	 	0,		0,
    191  1.29.2.1.2.2   thorpej   0,
    192  1.29.2.1.2.2   thorpej   0,		0,		0,		0,		ipsec_sysctl
    193  1.29.2.1.2.2   thorpej },
    194  1.29.2.1.2.2   thorpej #endif /* IPSEC */
    195  1.29.2.1.2.2   thorpej #if NGIF > 0
    196  1.29.2.1.2.2   thorpej { SOCK_RAW,	&inetdomain,	IPPROTO_IPV4,	PR_ATOMIC|PR_ADDR,
    197  1.29.2.1.2.2   thorpej   in_gif_input,	0,	 	0,		0,
    198  1.29.2.1.2.2   thorpej   0,
    199  1.29.2.1.2.2   thorpej   0,		0,		0,		0,
    200  1.29.2.1.2.2   thorpej },
    201  1.29.2.1.2.2   thorpej #ifdef INET6
    202  1.29.2.1.2.2   thorpej { SOCK_RAW,	&inetdomain,	IPPROTO_IPV6,	PR_ATOMIC|PR_ADDR,
    203  1.29.2.1.2.2   thorpej   in_gif_input,	0,	 	0,		0,
    204  1.29.2.1.2.2   thorpej   0,
    205  1.29.2.1.2.2   thorpej   0,		0,		0,		0,
    206  1.29.2.1.2.2   thorpej },
    207  1.29.2.1.2.2   thorpej #endif /* INET6 */
    208  1.29.2.1.2.2   thorpej #else /* NGIF */
    209          1.28   thorpej #if NIPIP > 0 || defined(MROUTING)
    210          1.11   mycroft { SOCK_RAW,	&inetdomain,	IPPROTO_IPIP,	PR_ATOMIC|PR_ADDR,
    211          1.28   thorpej   ipip_input,	rip_output,	0,		rip_ctloutput,
    212          1.11   mycroft   rip_usrreq,	/* XXX */
    213          1.11   mycroft   0,		0,		0,		0,
    214          1.11   mycroft },
    215          1.28   thorpej #endif /* NIPIP > 0 || MROUTING */
    216          1.25       hwr #if NGRE > 0
    217          1.25       hwr { SOCK_RAW,	&inetdomain,	IPPROTO_GRE,	PR_ATOMIC|PR_ADDR,
    218          1.25       hwr   gre_input,	rip_output,	0,		rip_ctloutput,
    219          1.26       hwr   rip_usrreq,
    220          1.26       hwr   0,		0,		0,		0,
    221          1.26       hwr },
    222          1.26       hwr { SOCK_RAW,	&inetdomain,	IPPROTO_MOBILE,	PR_ATOMIC|PR_ADDR,
    223          1.26       hwr   gre_mobile_input,	rip_output,	0,		rip_ctloutput,
    224          1.26       hwr   rip_usrreq,
    225          1.25       hwr   0,		0,		0,		0,
    226          1.25       hwr },
    227          1.28   thorpej #endif /* NGRE > 0 */
    228  1.29.2.1.2.2   thorpej #endif /* NGIF */
    229           1.8   mycroft { SOCK_RAW,	&inetdomain,	IPPROTO_IGMP,	PR_ATOMIC|PR_ADDR,
    230           1.8   mycroft   igmp_input,	rip_output,	0,		rip_ctloutput,
    231           1.8   mycroft   rip_usrreq,
    232          1.10   mycroft   igmp_init,	igmp_fasttimo,	igmp_slowtimo,	0,
    233           1.1       cgd },
    234           1.1       cgd #ifdef TPIP
    235  1.29.2.1.2.2   thorpej { SOCK_SEQPACKET,&inetdomain,	IPPROTO_TP,	PR_CONNREQUIRED|PR_WANTRCVD|PR_LISTEN,
    236           1.8   mycroft   tpip_input,	0,		tpip_ctlinput,	tp_ctloutput,
    237           1.1       cgd   tp_usrreq,
    238           1.1       cgd   tp_init,	0,		tp_slowtimo,	tp_drain,
    239           1.1       cgd },
    240          1.11   mycroft #endif /* TPIP */
    241           1.1       cgd /* EON (ISO CLNL over IP) */
    242           1.1       cgd #ifdef EON
    243           1.1       cgd { SOCK_RAW,	&inetdomain,	IPPROTO_EON,	0,
    244           1.1       cgd   eoninput,	0,		eonctlinput,		0,
    245           1.1       cgd   0,
    246           1.1       cgd   eonprotoinit,	0,		0,		0,
    247           1.4   hpeyerl },
    248          1.11   mycroft #endif /* EON */
    249           1.1       cgd #ifdef NSIP
    250           1.1       cgd { SOCK_RAW,	&inetdomain,	IPPROTO_IDP,	PR_ATOMIC|PR_ADDR,
    251          1.16  christos   idpip_input,	NULL,		nsip_ctlinput,	0,
    252           1.1       cgd   rip_usrreq,
    253           1.1       cgd   0,		0,		0,		0,
    254           1.1       cgd },
    255          1.11   mycroft #endif /* NSIP */
    256          1.11   mycroft /* raw wildcard */
    257           1.1       cgd { SOCK_RAW,	&inetdomain,	0,		PR_ATOMIC|PR_ADDR,
    258           1.1       cgd   rip_input,	rip_output,	0,		rip_ctloutput,
    259           1.1       cgd   rip_usrreq,
    260           1.8   mycroft   rip_init,	0,		0,		0,
    261           1.1       cgd },
    262           1.1       cgd };
    263           1.1       cgd 
    264           1.1       cgd struct domain inetdomain =
    265          1.29   thorpej     { PF_INET, "internet", 0, 0, 0,
    266           1.8   mycroft       inetsw, &inetsw[sizeof(inetsw)/sizeof(inetsw[0])], 0,
    267           1.8   mycroft       rn_inithead, 32, sizeof(struct sockaddr_in) };
    268          1.17   thorpej 
    269          1.17   thorpej #define	TCP_SYN_HASH_SIZE	293
    270          1.17   thorpej #define	TCP_SYN_BUCKET_SIZE	35
    271          1.17   thorpej 
    272          1.17   thorpej int	tcp_syn_cache_size = TCP_SYN_HASH_SIZE;
    273          1.17   thorpej int	tcp_syn_cache_limit = TCP_SYN_HASH_SIZE*TCP_SYN_BUCKET_SIZE;
    274          1.17   thorpej int	tcp_syn_bucket_limit = 3*TCP_SYN_BUCKET_SIZE;
    275          1.17   thorpej struct	syn_cache_head tcp_syn_cache[TCP_SYN_HASH_SIZE];
    276      1.29.2.1     perry int	tcp_syn_cache_interval = 1;	/* runs timer twice a second */
    277