Home | History | Annotate | Line # | Download | only in netinet
in_proto.c revision 1.48.4.1
      1  1.48.4.1      fvdl /*	$NetBSD: in_proto.c,v 1.48.4.1 2001/10/01 12:47:40 fvdl Exp $	*/
      2      1.32    itojun 
      3      1.32    itojun /*
      4      1.32    itojun  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
      5      1.32    itojun  * All rights reserved.
      6      1.32    itojun  *
      7      1.32    itojun  * Redistribution and use in source and binary forms, with or without
      8      1.32    itojun  * modification, are permitted provided that the following conditions
      9      1.32    itojun  * are met:
     10      1.32    itojun  * 1. Redistributions of source code must retain the above copyright
     11      1.32    itojun  *    notice, this list of conditions and the following disclaimer.
     12      1.32    itojun  * 2. Redistributions in binary form must reproduce the above copyright
     13      1.32    itojun  *    notice, this list of conditions and the following disclaimer in the
     14      1.32    itojun  *    documentation and/or other materials provided with the distribution.
     15      1.32    itojun  * 3. Neither the name of the project nor the names of its contributors
     16      1.32    itojun  *    may be used to endorse or promote products derived from this software
     17      1.32    itojun  *    without specific prior written permission.
     18      1.32    itojun  *
     19      1.32    itojun  * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
     20      1.32    itojun  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     21      1.32    itojun  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     22      1.32    itojun  * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
     23      1.32    itojun  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     24      1.32    itojun  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     25      1.32    itojun  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     26      1.32    itojun  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     27      1.32    itojun  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     28      1.32    itojun  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     29      1.32    itojun  * SUCH DAMAGE.
     30      1.32    itojun  */
     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.32    itojun #include "opt_inet.h"
     72      1.33   thorpej #include "opt_ipsec.h"
     73       1.1       cgd 
     74       1.5   mycroft #include <sys/param.h>
     75       1.5   mycroft #include <sys/socket.h>
     76       1.5   mycroft #include <sys/protosw.h>
     77       1.5   mycroft #include <sys/domain.h>
     78       1.5   mycroft #include <sys/mbuf.h>
     79       1.1       cgd 
     80       1.8   mycroft #include <net/if.h>
     81       1.8   mycroft #include <net/radix.h>
     82       1.8   mycroft #include <net/route.h>
     83       1.8   mycroft 
     84       1.5   mycroft #include <netinet/in.h>
     85       1.5   mycroft #include <netinet/in_systm.h>
     86       1.8   mycroft #include <netinet/ip.h>
     87       1.8   mycroft #include <netinet/ip_var.h>
     88       1.8   mycroft #include <netinet/ip_icmp.h>
     89       1.8   mycroft #include <netinet/in_pcb.h>
     90      1.32    itojun 
     91      1.32    itojun #ifdef INET6
     92      1.32    itojun #ifndef INET
     93      1.32    itojun #include <netinet/in.h>
     94      1.32    itojun #endif
     95      1.32    itojun #include <netinet/ip6.h>
     96      1.32    itojun #endif
     97      1.32    itojun 
     98       1.8   mycroft #include <netinet/igmp_var.h>
     99       1.8   mycroft #include <netinet/tcp.h>
    100       1.8   mycroft #include <netinet/tcp_fsm.h>
    101       1.8   mycroft #include <netinet/tcp_seq.h>
    102       1.8   mycroft #include <netinet/tcp_timer.h>
    103       1.8   mycroft #include <netinet/tcp_var.h>
    104       1.8   mycroft #include <netinet/tcpip.h>
    105       1.8   mycroft #include <netinet/tcp_debug.h>
    106       1.8   mycroft #include <netinet/udp.h>
    107       1.8   mycroft #include <netinet/udp_var.h>
    108      1.39    itojun #include <netinet/ip_encap.h>
    109       1.1       cgd /*
    110       1.1       cgd  * TCP/IP protocol family: IP, ICMP, UDP, TCP.
    111       1.1       cgd  */
    112       1.1       cgd 
    113      1.32    itojun #ifdef IPSEC
    114      1.32    itojun #include <netinet6/ah.h>
    115      1.32    itojun #ifdef IPSEC_ESP
    116      1.32    itojun #include <netinet6/esp.h>
    117      1.32    itojun #endif
    118      1.32    itojun #include <netinet6/ipcomp.h>
    119      1.32    itojun #endif /* IPSEC */
    120      1.32    itojun 
    121      1.32    itojun #include "gif.h"
    122      1.32    itojun #if NGIF > 0
    123      1.32    itojun #include <netinet/in_gif.h>
    124      1.32    itojun #endif
    125      1.32    itojun 
    126       1.1       cgd #ifdef NSIP
    127      1.13  christos #include <netns/ns_var.h>
    128      1.13  christos #include <netns/idp_var.h>
    129      1.11   mycroft #endif /* NSIP */
    130       1.1       cgd 
    131       1.1       cgd #ifdef TPIP
    132      1.13  christos #include <netiso/tp_param.h>
    133      1.13  christos #include <netiso/tp_var.h>
    134      1.11   mycroft #endif /* TPIP */
    135       1.1       cgd 
    136       1.1       cgd #ifdef EON
    137      1.13  christos #include <netiso/eonvar.h>
    138       1.8   mycroft #endif /* EON */
    139       1.1       cgd 
    140      1.28   thorpej #include "ipip.h"
    141      1.28   thorpej #if NIPIP > 0 || defined(MROUTING)
    142      1.28   thorpej #include <netinet/ip_ipip.h>
    143      1.28   thorpej #endif /* NIPIP > 0 || MROUTING */
    144      1.11   mycroft 
    145      1.25       hwr #include "gre.h"
    146      1.28   thorpej #if NGRE > 0
    147      1.28   thorpej #include <netinet/ip_gre.h>
    148      1.25       hwr #endif
    149      1.25       hwr 
    150      1.39    itojun #include "stf.h"
    151      1.39    itojun #if NSTF > 0
    152      1.39    itojun #include <net/if_stf.h>
    153      1.39    itojun #endif
    154      1.39    itojun 
    155       1.1       cgd extern	struct domain inetdomain;
    156       1.1       cgd 
    157       1.1       cgd struct protosw inetsw[] = {
    158       1.1       cgd { 0,		&inetdomain,	0,		0,
    159       1.1       cgd   0,		ip_output,	0,		0,
    160       1.1       cgd   0,
    161       1.8   mycroft   ip_init,	0,		ip_slowtimo,	ip_drain,	ip_sysctl
    162       1.1       cgd },
    163       1.1       cgd { SOCK_DGRAM,	&inetdomain,	IPPROTO_UDP,	PR_ATOMIC|PR_ADDR,
    164       1.1       cgd   udp_input,	0,		udp_ctlinput,	ip_ctloutput,
    165       1.1       cgd   udp_usrreq,
    166       1.8   mycroft   udp_init,	0,		0,		0,		udp_sysctl
    167       1.1       cgd },
    168      1.48   thorpej { SOCK_STREAM,	&inetdomain,	IPPROTO_TCP,	PR_CONNREQUIRED|PR_WANTRCVD|PR_LISTEN|PR_ABRTACPTDIS,
    169       1.1       cgd   tcp_input,	0,		tcp_ctlinput,	tcp_ctloutput,
    170       1.1       cgd   tcp_usrreq,
    171  1.48.4.1      fvdl   tcp_init,	0,		tcp_slowtimo,	tcp_drain,	tcp_sysctl
    172       1.1       cgd },
    173       1.1       cgd { SOCK_RAW,	&inetdomain,	IPPROTO_RAW,	PR_ATOMIC|PR_ADDR,
    174       1.1       cgd   rip_input,	rip_output,	0,		rip_ctloutput,
    175       1.1       cgd   rip_usrreq,
    176       1.1       cgd   0,		0,		0,		0,
    177       1.1       cgd },
    178      1.47    itojun { SOCK_RAW,	&inetdomain,	IPPROTO_ICMP,	PR_ATOMIC|PR_ADDR|PR_LASTHDR,
    179       1.1       cgd   icmp_input,	rip_output,	0,		rip_ctloutput,
    180       1.1       cgd   rip_usrreq,
    181       1.8   mycroft   0,		0,		0,		0,		icmp_sysctl
    182       1.8   mycroft },
    183      1.32    itojun #ifdef IPSEC
    184      1.32    itojun { SOCK_RAW,	&inetdomain,	IPPROTO_AH,	PR_ATOMIC|PR_ADDR,
    185      1.44   thorpej   ah4_input,	0,	 	ah4_ctlinput,	0,
    186      1.32    itojun   0,
    187      1.32    itojun   0,		0,		0,		0,		ipsec_sysctl
    188      1.32    itojun },
    189      1.32    itojun #ifdef IPSEC_ESP
    190      1.32    itojun { SOCK_RAW,	&inetdomain,	IPPROTO_ESP,	PR_ATOMIC|PR_ADDR,
    191      1.44   thorpej   esp4_input,	0,	 	esp4_ctlinput,	0,
    192      1.32    itojun   0,
    193      1.32    itojun   0,		0,		0,		0,		ipsec_sysctl
    194      1.32    itojun },
    195      1.32    itojun #endif
    196      1.32    itojun { SOCK_RAW,	&inetdomain,	IPPROTO_IPCOMP,	PR_ATOMIC|PR_ADDR,
    197      1.32    itojun   ipcomp4_input, 0,	 	0,		0,
    198      1.32    itojun   0,
    199      1.32    itojun   0,		0,		0,		0,		ipsec_sysctl
    200      1.32    itojun },
    201      1.32    itojun #endif /* IPSEC */
    202      1.47    itojun { SOCK_RAW,	&inetdomain,	IPPROTO_IPV4,	PR_ATOMIC|PR_ADDR|PR_LASTHDR,
    203      1.39    itojun   encap4_input,	rip_output, 	0,		rip_ctloutput,
    204      1.34    itojun   rip_usrreq,	/*XXX*/
    205      1.39    itojun   encap_init,	0,		0,		0,
    206      1.32    itojun },
    207      1.32    itojun #ifdef INET6
    208      1.47    itojun { SOCK_RAW,	&inetdomain,	IPPROTO_IPV6,	PR_ATOMIC|PR_ADDR|PR_LASTHDR,
    209      1.39    itojun   encap4_input,	rip_output, 	0,		rip_ctloutput,
    210      1.34    itojun   rip_usrreq,	/*XXX*/
    211      1.32    itojun   0,		0,		0,		0,
    212      1.32    itojun },
    213      1.32    itojun #endif /* INET6 */
    214      1.25       hwr #if NGRE > 0
    215      1.47    itojun { SOCK_RAW,	&inetdomain,	IPPROTO_GRE,	PR_ATOMIC|PR_ADDR|PR_LASTHDR,
    216      1.25       hwr   gre_input,	rip_output,	0,		rip_ctloutput,
    217      1.26       hwr   rip_usrreq,
    218      1.26       hwr   0,		0,		0,		0,
    219      1.26       hwr },
    220      1.47    itojun { SOCK_RAW,	&inetdomain,	IPPROTO_MOBILE,	PR_ATOMIC|PR_ADDR|PR_LASTHDR,
    221      1.26       hwr   gre_mobile_input,	rip_output,	0,		rip_ctloutput,
    222      1.26       hwr   rip_usrreq,
    223      1.25       hwr   0,		0,		0,		0,
    224      1.25       hwr },
    225      1.28   thorpej #endif /* NGRE > 0 */
    226      1.47    itojun { SOCK_RAW,	&inetdomain,	IPPROTO_IGMP,	PR_ATOMIC|PR_ADDR|PR_LASTHDR,
    227       1.8   mycroft   igmp_input,	rip_output,	0,		rip_ctloutput,
    228       1.8   mycroft   rip_usrreq,
    229      1.10   mycroft   igmp_init,	igmp_fasttimo,	igmp_slowtimo,	0,
    230       1.1       cgd },
    231       1.1       cgd #ifdef TPIP
    232      1.48   thorpej { SOCK_SEQPACKET,&inetdomain,	IPPROTO_TP,	PR_CONNREQUIRED|PR_WANTRCVD|PR_LISTEN|PR_LASTHDR|PR_ABRTACPTDIS,
    233       1.8   mycroft   tpip_input,	0,		tpip_ctlinput,	tp_ctloutput,
    234       1.1       cgd   tp_usrreq,
    235       1.1       cgd   tp_init,	0,		tp_slowtimo,	tp_drain,
    236       1.1       cgd },
    237      1.11   mycroft #endif /* TPIP */
    238      1.45    itojun #ifdef ISO
    239       1.1       cgd /* EON (ISO CLNL over IP) */
    240       1.1       cgd #ifdef EON
    241      1.47    itojun { SOCK_RAW,	&inetdomain,	IPPROTO_EON,	PR_LASTHDR,
    242      1.45    itojun   eoninput,	0,		eonctlinput,	0,
    243       1.1       cgd   0,
    244       1.1       cgd   eonprotoinit,	0,		0,		0,
    245       1.4   hpeyerl },
    246      1.45    itojun #else
    247      1.47    itojun { SOCK_RAW,	&inetdomain,	IPPROTO_EON,	PR_ATOMIC|PR_ADDR|PR_LASTHDR,
    248      1.45    itojun   encap4_input,	rip_output,	0,		rip_ctloutput,
    249      1.45    itojun   rip_usrreq,	/*XXX*/
    250      1.45    itojun   0,		0,		0,		0,
    251      1.45    itojun },
    252      1.11   mycroft #endif /* EON */
    253      1.45    itojun #endif /* ISO */
    254       1.1       cgd #ifdef NSIP
    255      1.47    itojun { SOCK_RAW,	&inetdomain,	IPPROTO_IDP,	PR_ATOMIC|PR_ADDR|PR_LASTHDR,
    256      1.16  christos   idpip_input,	NULL,		nsip_ctlinput,	0,
    257       1.1       cgd   rip_usrreq,
    258       1.1       cgd   0,		0,		0,		0,
    259       1.1       cgd },
    260      1.11   mycroft #endif /* NSIP */
    261      1.11   mycroft /* raw wildcard */
    262       1.1       cgd { SOCK_RAW,	&inetdomain,	0,		PR_ATOMIC|PR_ADDR,
    263       1.1       cgd   rip_input,	rip_output,	0,		rip_ctloutput,
    264       1.1       cgd   rip_usrreq,
    265       1.8   mycroft   rip_init,	0,		0,		0,
    266       1.1       cgd },
    267       1.1       cgd };
    268      1.39    itojun 
    269      1.39    itojun #if NIPIP > 0
    270      1.39    itojun struct protosw ipip_protosw =
    271      1.39    itojun { SOCK_RAW,	&inetdomain,	IPPROTO_IPIP,	PR_ATOMIC|PR_ADDR,
    272      1.39    itojun   ipip_input,	rip_output,	0,		rip_ctloutput,
    273      1.39    itojun   rip_usrreq,	/* XXX */
    274      1.39    itojun   0,		0,		0,		0,
    275      1.39    itojun };
    276      1.39    itojun #endif /* NIPIP */
    277      1.39    itojun 
    278      1.39    itojun #if NGIF > 0
    279      1.39    itojun struct protosw in_gif_protosw =
    280      1.39    itojun { SOCK_RAW,	&inetdomain,	0/*IPPROTO_IPV[46]*/,	PR_ATOMIC|PR_ADDR,
    281      1.39    itojun   in_gif_input, rip_output,	0,		rip_ctloutput,
    282      1.39    itojun   rip_usrreq,
    283      1.39    itojun   0,            0,              0,              0,
    284      1.39    itojun };
    285      1.39    itojun #endif /*NGIF*/
    286      1.39    itojun 
    287      1.39    itojun #if NSTF > 0
    288      1.39    itojun struct protosw in_stf_protosw =
    289      1.39    itojun { SOCK_RAW,	&inetdomain,	IPPROTO_IPV6,	PR_ATOMIC|PR_ADDR,
    290      1.39    itojun   in_stf_input, rip_output,	0,		rip_ctloutput,
    291      1.39    itojun   rip_usrreq,
    292      1.39    itojun   0,            0,              0,              0
    293      1.39    itojun };
    294      1.39    itojun #endif /*NSTF*/
    295       1.1       cgd 
    296       1.1       cgd struct domain inetdomain =
    297      1.29   thorpej     { PF_INET, "internet", 0, 0, 0,
    298       1.8   mycroft       inetsw, &inetsw[sizeof(inetsw)/sizeof(inetsw[0])], 0,
    299       1.8   mycroft       rn_inithead, 32, sizeof(struct sockaddr_in) };
    300      1.38   darrenr 
    301      1.38   darrenr u_char	ip_protox[IPPROTO_MAX];
    302      1.36   thorpej 
    303      1.40    itojun int icmperrppslim = 100;			/* 100pps */
    304