Home | History | Annotate | Line # | Download | only in netinet
in_proto.c revision 1.76.2.2
      1  1.76.2.2        ad /*	$NetBSD: in_proto.c,v 1.76.2.2 2007/01/12 01:04:14 ad 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.56    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.56    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.59       agc  * 3. Neither the name of the University nor the names of its contributors
     45       1.1       cgd  *    may be used to endorse or promote products derived from this software
     46       1.1       cgd  *    without specific prior written permission.
     47       1.1       cgd  *
     48       1.1       cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     49       1.1       cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     50       1.1       cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     51       1.1       cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     52       1.1       cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     53       1.1       cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     54       1.1       cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     55       1.1       cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     56       1.1       cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     57       1.1       cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     58       1.1       cgd  * SUCH DAMAGE.
     59       1.1       cgd  *
     60      1.18   thorpej  *	@(#)in_proto.c	8.2 (Berkeley) 2/9/95
     61       1.1       cgd  */
     62      1.51     lukem 
     63      1.51     lukem #include <sys/cdefs.h>
     64  1.76.2.2        ad __KERNEL_RCSID(0, "$NetBSD: in_proto.c,v 1.76.2.2 2007/01/12 01:04:14 ad Exp $");
     65      1.19    scottr 
     66      1.19    scottr #include "opt_mrouting.h"
     67      1.22  jonathan #include "opt_eon.h"			/* ISO CLNL over IP */
     68      1.22  jonathan #include "opt_iso.h"			/* ISO TP tunneled over IP */
     69      1.32    itojun #include "opt_inet.h"
     70      1.33   thorpej #include "opt_ipsec.h"
     71      1.65      manu #include "opt_pim.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.76.2.1        ad #include <netinet/in_ifattach.h>
     89       1.8   mycroft #include <netinet/in_pcb.h>
     90      1.69      yamt #include <netinet/in_proto.h>
     91  1.76.2.2        ad #include <netinet/in_route.h>
     92      1.32    itojun 
     93      1.32    itojun #ifdef INET6
     94      1.32    itojun #ifndef INET
     95      1.32    itojun #include <netinet/in.h>
     96      1.32    itojun #endif
     97      1.32    itojun #include <netinet/ip6.h>
     98      1.32    itojun #endif
     99      1.32    itojun 
    100       1.8   mycroft #include <netinet/igmp_var.h>
    101      1.65      manu #ifdef PIM
    102      1.65      manu #include <netinet/pim_var.h>
    103      1.65      manu #endif
    104       1.8   mycroft #include <netinet/tcp.h>
    105       1.8   mycroft #include <netinet/tcp_fsm.h>
    106       1.8   mycroft #include <netinet/tcp_seq.h>
    107       1.8   mycroft #include <netinet/tcp_timer.h>
    108       1.8   mycroft #include <netinet/tcp_var.h>
    109       1.8   mycroft #include <netinet/tcpip.h>
    110       1.8   mycroft #include <netinet/tcp_debug.h>
    111       1.8   mycroft #include <netinet/udp.h>
    112       1.8   mycroft #include <netinet/udp_var.h>
    113      1.39    itojun #include <netinet/ip_encap.h>
    114  1.76.2.2        ad 
    115       1.1       cgd /*
    116       1.1       cgd  * TCP/IP protocol family: IP, ICMP, UDP, TCP.
    117       1.1       cgd  */
    118       1.1       cgd 
    119      1.32    itojun #ifdef IPSEC
    120      1.58    itojun #include <netinet6/ipsec.h>
    121      1.32    itojun #include <netinet6/ah.h>
    122      1.32    itojun #ifdef IPSEC_ESP
    123      1.32    itojun #include <netinet6/esp.h>
    124      1.32    itojun #endif
    125      1.32    itojun #include <netinet6/ipcomp.h>
    126      1.32    itojun #endif /* IPSEC */
    127      1.32    itojun 
    128      1.61  jonathan #ifdef FAST_IPSEC
    129      1.61  jonathan #include <netipsec/ipsec.h>
    130      1.61  jonathan #include <netipsec/key.h>
    131      1.61  jonathan #endif	/* FAST_IPSEC */
    132      1.61  jonathan 
    133       1.1       cgd #ifdef TPIP
    134      1.13  christos #include <netiso/tp_param.h>
    135      1.13  christos #include <netiso/tp_var.h>
    136      1.11   mycroft #endif /* TPIP */
    137       1.1       cgd 
    138       1.1       cgd #ifdef EON
    139      1.13  christos #include <netiso/eonvar.h>
    140       1.8   mycroft #endif /* EON */
    141       1.1       cgd 
    142      1.25       hwr #include "gre.h"
    143      1.28   thorpej #if NGRE > 0
    144      1.28   thorpej #include <netinet/ip_gre.h>
    145      1.25       hwr #endif
    146      1.25       hwr 
    147      1.72  liamjfoy #include "carp.h"
    148      1.72  liamjfoy #if NCARP > 0
    149      1.72  liamjfoy #include <netinet/ip_carp.h>
    150      1.72  liamjfoy #endif
    151      1.72  liamjfoy 
    152  1.76.2.2        ad #include "etherip.h"
    153  1.76.2.2        ad #if NETHERIP > 0
    154  1.76.2.2        ad #include <netinet/ip_etherip.h>
    155  1.76.2.2        ad #endif
    156      1.67       kim 
    157      1.66      matt DOMAIN_DEFINE(inetdomain);	/* forward declare and add to link set */
    158      1.66      matt 
    159      1.63      matt const struct protosw inetsw[] = {
    160       1.1       cgd { 0,		&inetdomain,	0,		0,
    161       1.1       cgd   0,		ip_output,	0,		0,
    162       1.1       cgd   0,
    163      1.74  christos   ip_init,	0,		ip_slowtimo,	ip_drain,
    164       1.1       cgd },
    165      1.70       gdt { SOCK_DGRAM,	&inetdomain,	IPPROTO_UDP,	PR_ATOMIC|PR_ADDR|PR_PURGEIF,
    166      1.68      manu   udp_input,	0,		udp_ctlinput,	udp_ctloutput,
    167       1.1       cgd   udp_usrreq,
    168      1.74  christos   udp_init,	0,		0,		0,
    169       1.1       cgd },
    170      1.70       gdt { SOCK_STREAM,	&inetdomain,	IPPROTO_TCP,	PR_CONNREQUIRED|PR_WANTRCVD|PR_LISTEN|PR_ABRTACPTDIS|PR_PURGEIF,
    171       1.1       cgd   tcp_input,	0,		tcp_ctlinput,	tcp_ctloutput,
    172       1.1       cgd   tcp_usrreq,
    173      1.74  christos   tcp_init,	0,		tcp_slowtimo,	tcp_drain,
    174       1.1       cgd },
    175      1.70       gdt { SOCK_RAW,	&inetdomain,	IPPROTO_RAW,	PR_ATOMIC|PR_ADDR|PR_PURGEIF,
    176      1.53    itojun   rip_input,	rip_output,	rip_ctlinput,	rip_ctloutput,
    177       1.1       cgd   rip_usrreq,
    178       1.1       cgd   0,		0,		0,		0,
    179       1.1       cgd },
    180      1.47    itojun { SOCK_RAW,	&inetdomain,	IPPROTO_ICMP,	PR_ATOMIC|PR_ADDR|PR_LASTHDR,
    181      1.53    itojun   icmp_input,	rip_output,	rip_ctlinput,	rip_ctloutput,
    182       1.1       cgd   rip_usrreq,
    183      1.74  christos   icmp_init,	0,		0,		0,
    184       1.8   mycroft },
    185      1.32    itojun #ifdef IPSEC
    186      1.32    itojun { SOCK_RAW,	&inetdomain,	IPPROTO_AH,	PR_ATOMIC|PR_ADDR,
    187      1.44   thorpej   ah4_input,	0,	 	ah4_ctlinput,	0,
    188      1.56    itojun   0,
    189      1.74  christos   0,		0,		0,		0,
    190      1.32    itojun },
    191      1.32    itojun #ifdef IPSEC_ESP
    192      1.32    itojun { SOCK_RAW,	&inetdomain,	IPPROTO_ESP,	PR_ATOMIC|PR_ADDR,
    193      1.61  jonathan   esp4_input,
    194      1.74  christos   0,	 	esp4_ctlinput,	0,
    195      1.56    itojun   0,
    196      1.74  christos   0,		0,		0,		0,
    197      1.32    itojun },
    198      1.32    itojun #endif
    199      1.32    itojun { SOCK_RAW,	&inetdomain,	IPPROTO_IPCOMP,	PR_ATOMIC|PR_ADDR,
    200      1.61  jonathan   ipcomp4_input,
    201      1.74  christos   0,	 	0,		0,
    202      1.56    itojun   0,
    203      1.74  christos   0,		0,		0,		0,
    204      1.32    itojun },
    205      1.32    itojun #endif /* IPSEC */
    206      1.61  jonathan #ifdef FAST_IPSEC
    207      1.61  jonathan { SOCK_RAW,	&inetdomain,	IPPROTO_AH,	PR_ATOMIC|PR_ADDR,
    208      1.61  jonathan   ipsec4_common_input,	0,	 	ah4_ctlinput,	0,
    209      1.74  christos   0, 0,		0,		0,		0,
    210      1.61  jonathan },
    211      1.61  jonathan { SOCK_RAW,	&inetdomain,	IPPROTO_ESP,	PR_ATOMIC|PR_ADDR,
    212      1.61  jonathan   ipsec4_common_input,    0,	 	esp4_ctlinput,	0,
    213      1.61  jonathan   0,
    214      1.74  christos   0,		0,		0,		0,
    215      1.61  jonathan },
    216      1.61  jonathan { SOCK_RAW,	&inetdomain,	IPPROTO_IPCOMP,	PR_ATOMIC|PR_ADDR,
    217      1.61  jonathan   ipsec4_common_input,    0,	 	0,		0,
    218      1.61  jonathan   0,
    219      1.74  christos   0,		0,		0,		0,
    220      1.61  jonathan },
    221      1.61  jonathan #endif /* FAST_IPSEC */
    222      1.47    itojun { SOCK_RAW,	&inetdomain,	IPPROTO_IPV4,	PR_ATOMIC|PR_ADDR|PR_LASTHDR,
    223      1.53    itojun   encap4_input,	rip_output, 	rip_ctlinput,	rip_ctloutput,
    224      1.34    itojun   rip_usrreq,	/*XXX*/
    225      1.39    itojun   encap_init,	0,		0,		0,
    226      1.32    itojun },
    227      1.32    itojun #ifdef INET6
    228      1.47    itojun { SOCK_RAW,	&inetdomain,	IPPROTO_IPV6,	PR_ATOMIC|PR_ADDR|PR_LASTHDR,
    229      1.53    itojun   encap4_input,	rip_output, 	rip_ctlinput,	rip_ctloutput,
    230      1.34    itojun   rip_usrreq,	/*XXX*/
    231      1.57    itojun   encap_init,	0,		0,		0,
    232      1.32    itojun },
    233      1.32    itojun #endif /* INET6 */
    234  1.76.2.2        ad #if NETHERIP > 0
    235      1.67       kim { SOCK_RAW,	&inetdomain,	IPPROTO_ETHERIP,	PR_ATOMIC|PR_ADDR|PR_LASTHDR,
    236  1.76.2.2        ad   ip_etherip_input,	rip_output,	rip_ctlinput,	rip_ctloutput,
    237      1.67       kim   rip_usrreq,
    238  1.76.2.2        ad   0,		0,		0,		0,
    239      1.67       kim },
    240      1.67       kim #endif
    241      1.72  liamjfoy #if NCARP > 0
    242      1.72  liamjfoy { SOCK_RAW,	&inetdomain,	IPPROTO_CARP,	PR_ATOMIC|PR_ADDR,
    243      1.72  liamjfoy   carp_proto_input,	rip_output,	0,		rip_ctloutput,
    244      1.72  liamjfoy   rip_usrreq,
    245      1.74  christos   0,		0,		0,		0,
    246      1.72  liamjfoy },
    247      1.72  liamjfoy #endif
    248      1.25       hwr #if NGRE > 0
    249      1.47    itojun { SOCK_RAW,	&inetdomain,	IPPROTO_GRE,	PR_ATOMIC|PR_ADDR|PR_LASTHDR,
    250      1.53    itojun   gre_input,	rip_output,	rip_ctlinput,	rip_ctloutput,
    251      1.26       hwr   rip_usrreq,
    252      1.26       hwr   0,		0,		0,		0,
    253      1.26       hwr },
    254      1.47    itojun { SOCK_RAW,	&inetdomain,	IPPROTO_MOBILE,	PR_ATOMIC|PR_ADDR|PR_LASTHDR,
    255      1.53    itojun   gre_mobile_input,	rip_output,	rip_ctlinput,	rip_ctloutput,
    256      1.26       hwr   rip_usrreq,
    257      1.25       hwr   0,		0,		0,		0,
    258      1.25       hwr },
    259      1.28   thorpej #endif /* NGRE > 0 */
    260      1.47    itojun { SOCK_RAW,	&inetdomain,	IPPROTO_IGMP,	PR_ATOMIC|PR_ADDR|PR_LASTHDR,
    261      1.53    itojun   igmp_input,	rip_output,	rip_ctlinput,	rip_ctloutput,
    262       1.8   mycroft   rip_usrreq,
    263      1.64    simonb   NULL,		igmp_fasttimo,	igmp_slowtimo,	0,
    264       1.1       cgd },
    265      1.65      manu #ifdef PIM
    266      1.65      manu { SOCK_RAW,	&inetdomain,	IPPROTO_PIM,	PR_ATOMIC|PR_ADDR|PR_LASTHDR,
    267      1.65      manu   pim_input,	rip_output,	rip_ctlinput,	rip_ctloutput,
    268      1.65      manu   rip_usrreq,
    269      1.65      manu   NULL,		0,		0,		0,
    270      1.65      manu },
    271      1.65      manu #endif /* PIM */
    272       1.1       cgd #ifdef TPIP
    273      1.48   thorpej { SOCK_SEQPACKET,&inetdomain,	IPPROTO_TP,	PR_CONNREQUIRED|PR_WANTRCVD|PR_LISTEN|PR_LASTHDR|PR_ABRTACPTDIS,
    274       1.8   mycroft   tpip_input,	0,		tpip_ctlinput,	tp_ctloutput,
    275       1.1       cgd   tp_usrreq,
    276       1.1       cgd   tp_init,	0,		tp_slowtimo,	tp_drain,
    277       1.1       cgd },
    278      1.11   mycroft #endif /* TPIP */
    279      1.45    itojun #ifdef ISO
    280       1.1       cgd /* EON (ISO CLNL over IP) */
    281       1.1       cgd #ifdef EON
    282      1.47    itojun { SOCK_RAW,	&inetdomain,	IPPROTO_EON,	PR_LASTHDR,
    283      1.45    itojun   eoninput,	0,		eonctlinput,	0,
    284       1.1       cgd   0,
    285       1.1       cgd   eonprotoinit,	0,		0,		0,
    286       1.4   hpeyerl },
    287      1.45    itojun #else
    288      1.47    itojun { SOCK_RAW,	&inetdomain,	IPPROTO_EON,	PR_ATOMIC|PR_ADDR|PR_LASTHDR,
    289      1.53    itojun   encap4_input,	rip_output,	rip_ctlinput,	rip_ctloutput,
    290      1.45    itojun   rip_usrreq,	/*XXX*/
    291      1.54    itojun   encap_init,	0,		0,		0,
    292      1.45    itojun },
    293      1.11   mycroft #endif /* EON */
    294      1.45    itojun #endif /* ISO */
    295      1.11   mycroft /* raw wildcard */
    296      1.60    itojun { SOCK_RAW,	&inetdomain,	0,		PR_ATOMIC|PR_ADDR|PR_LASTHDR,
    297      1.53    itojun   rip_input,	rip_output,	rip_ctlinput,	rip_ctloutput,
    298       1.1       cgd   rip_usrreq,
    299       1.8   mycroft   rip_init,	0,		0,		0,
    300       1.1       cgd },
    301       1.1       cgd };
    302       1.1       cgd 
    303      1.73      matt extern struct ifqueue ipintrq;
    304      1.73      matt 
    305      1.73      matt struct domain inetdomain = {
    306  1.76.2.2        ad 	.dom_family = PF_INET, .dom_name = "internet", .dom_init = NULL,
    307  1.76.2.2        ad 	.dom_externalize = NULL, .dom_dispose = NULL,
    308  1.76.2.2        ad 	.dom_protosw = inetsw,
    309  1.76.2.2        ad 	.dom_protoswNPROTOSW = &inetsw[sizeof(inetsw)/sizeof(inetsw[0])],
    310  1.76.2.2        ad 	.dom_rtattach = rn_inithead,
    311  1.76.2.2        ad 	.dom_rtoffset = 32, .dom_maxrtkey = sizeof(struct sockaddr_in),
    312  1.76.2.1        ad #ifdef IPSELSRC
    313  1.76.2.2        ad 	.dom_ifattach = in_domifattach,
    314  1.76.2.2        ad 	.dom_ifdetach = in_domifdetach,
    315  1.76.2.1        ad #else
    316  1.76.2.2        ad 	.dom_ifattach = NULL,
    317  1.76.2.2        ad 	.dom_ifdetach = NULL,
    318  1.76.2.1        ad #endif
    319  1.76.2.2        ad 	.dom_ifqueues = { &ipintrq, NULL },
    320  1.76.2.2        ad 	.dom_link = { NULL },
    321  1.76.2.2        ad 	.dom_mowner = MOWNER_INIT("",""),
    322  1.76.2.2        ad 	.dom_rtcache = in_rtcache,
    323  1.76.2.2        ad 	.dom_rtflush = in_rtflush,
    324  1.76.2.2        ad 	.dom_rtflushall = in_rtflushall
    325      1.73      matt };
    326      1.38   darrenr 
    327      1.38   darrenr u_char	ip_protox[IPPROTO_MAX];
    328      1.36   thorpej 
    329      1.40    itojun int icmperrppslim = 100;			/* 100pps */
    330