Home | History | Annotate | Line # | Download | only in netinet
in_proto.c revision 1.69.2.3
      1  1.69.2.3      yamt /*	$NetBSD: in_proto.c,v 1.69.2.3 2007/09/03 14:42:48 yamt 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.69.2.3      yamt __KERNEL_RCSID(0, "$NetBSD: in_proto.c,v 1.69.2.3 2007/09/03 14:42:48 yamt 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.69.2.2      yamt #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.32    itojun 
     92      1.32    itojun #ifdef INET6
     93      1.32    itojun #ifndef INET
     94      1.32    itojun #include <netinet/in.h>
     95      1.32    itojun #endif
     96      1.32    itojun #include <netinet/ip6.h>
     97      1.32    itojun #endif
     98      1.32    itojun 
     99       1.8   mycroft #include <netinet/igmp_var.h>
    100      1.65      manu #ifdef PIM
    101      1.65      manu #include <netinet/pim_var.h>
    102      1.65      manu #endif
    103       1.8   mycroft #include <netinet/tcp.h>
    104       1.8   mycroft #include <netinet/tcp_fsm.h>
    105       1.8   mycroft #include <netinet/tcp_seq.h>
    106       1.8   mycroft #include <netinet/tcp_timer.h>
    107       1.8   mycroft #include <netinet/tcp_var.h>
    108       1.8   mycroft #include <netinet/tcpip.h>
    109       1.8   mycroft #include <netinet/tcp_debug.h>
    110       1.8   mycroft #include <netinet/udp.h>
    111       1.8   mycroft #include <netinet/udp_var.h>
    112      1.39    itojun #include <netinet/ip_encap.h>
    113  1.69.2.2      yamt 
    114       1.1       cgd /*
    115       1.1       cgd  * TCP/IP protocol family: IP, ICMP, UDP, TCP.
    116       1.1       cgd  */
    117       1.1       cgd 
    118      1.32    itojun #ifdef IPSEC
    119      1.58    itojun #include <netinet6/ipsec.h>
    120      1.32    itojun #include <netinet6/ah.h>
    121      1.32    itojun #ifdef IPSEC_ESP
    122      1.32    itojun #include <netinet6/esp.h>
    123      1.32    itojun #endif
    124      1.32    itojun #include <netinet6/ipcomp.h>
    125      1.32    itojun #endif /* IPSEC */
    126      1.32    itojun 
    127      1.61  jonathan #ifdef FAST_IPSEC
    128      1.61  jonathan #include <netipsec/ipsec.h>
    129      1.61  jonathan #include <netipsec/key.h>
    130      1.61  jonathan #endif	/* FAST_IPSEC */
    131      1.61  jonathan 
    132       1.1       cgd #ifdef TPIP
    133      1.13  christos #include <netiso/tp_param.h>
    134      1.13  christos #include <netiso/tp_var.h>
    135      1.11   mycroft #endif /* TPIP */
    136       1.1       cgd 
    137       1.1       cgd #ifdef EON
    138      1.13  christos #include <netiso/eonvar.h>
    139       1.8   mycroft #endif /* EON */
    140       1.1       cgd 
    141      1.25       hwr #include "gre.h"
    142      1.28   thorpej #if NGRE > 0
    143      1.28   thorpej #include <netinet/ip_gre.h>
    144      1.25       hwr #endif
    145      1.25       hwr 
    146  1.69.2.1      yamt #include "carp.h"
    147  1.69.2.1      yamt #if NCARP > 0
    148  1.69.2.1      yamt #include <netinet/ip_carp.h>
    149  1.69.2.1      yamt #endif
    150  1.69.2.1      yamt 
    151  1.69.2.2      yamt #include "etherip.h"
    152  1.69.2.2      yamt #if NETHERIP > 0
    153  1.69.2.2      yamt #include <netinet/ip_etherip.h>
    154  1.69.2.2      yamt #endif
    155      1.67       kim 
    156      1.66      matt DOMAIN_DEFINE(inetdomain);	/* forward declare and add to link set */
    157      1.66      matt 
    158      1.63      matt const struct protosw inetsw[] = {
    159  1.69.2.3      yamt {	.pr_domain = &inetdomain,
    160  1.69.2.3      yamt 	.pr_init = ip_init,
    161  1.69.2.3      yamt 	.pr_output = ip_output,
    162  1.69.2.3      yamt 	.pr_slowtimo = ip_slowtimo,
    163  1.69.2.3      yamt 	.pr_drain = ip_drain,
    164  1.69.2.3      yamt },
    165  1.69.2.3      yamt {	.pr_type = SOCK_DGRAM,
    166  1.69.2.3      yamt 	.pr_domain = &inetdomain,
    167  1.69.2.3      yamt 	.pr_protocol = IPPROTO_UDP,
    168  1.69.2.3      yamt 	.pr_flags = PR_ATOMIC|PR_ADDR|PR_PURGEIF,
    169  1.69.2.3      yamt 	.pr_input = udp_input,
    170  1.69.2.3      yamt 	.pr_ctlinput = udp_ctlinput,
    171  1.69.2.3      yamt 	.pr_ctloutput = udp_ctloutput,
    172  1.69.2.3      yamt 	.pr_usrreq = udp_usrreq,
    173  1.69.2.3      yamt 	.pr_init = udp_init,
    174  1.69.2.3      yamt },
    175  1.69.2.3      yamt {	.pr_type = SOCK_STREAM,
    176  1.69.2.3      yamt 	.pr_domain = &inetdomain,
    177  1.69.2.3      yamt 	.pr_protocol = IPPROTO_TCP,
    178  1.69.2.3      yamt 	.pr_flags = PR_CONNREQUIRED|PR_WANTRCVD|PR_LISTEN|PR_ABRTACPTDIS|PR_PURGEIF,
    179  1.69.2.3      yamt 	.pr_input = tcp_input,
    180  1.69.2.3      yamt 	.pr_ctlinput = tcp_ctlinput,
    181  1.69.2.3      yamt 	.pr_ctloutput = tcp_ctloutput,
    182  1.69.2.3      yamt 	.pr_usrreq = tcp_usrreq,
    183  1.69.2.3      yamt 	.pr_init = tcp_init,
    184  1.69.2.3      yamt 	.pr_slowtimo = tcp_slowtimo,
    185  1.69.2.3      yamt 	.pr_drain = tcp_drain,
    186  1.69.2.3      yamt },
    187  1.69.2.3      yamt {	.pr_type = SOCK_RAW,
    188  1.69.2.3      yamt 	.pr_domain = &inetdomain,
    189  1.69.2.3      yamt 	.pr_protocol = IPPROTO_RAW,
    190  1.69.2.3      yamt 	.pr_flags = PR_ATOMIC|PR_ADDR|PR_PURGEIF,
    191  1.69.2.3      yamt 	.pr_input = rip_input,
    192  1.69.2.3      yamt 	.pr_output = rip_output,
    193  1.69.2.3      yamt 	.pr_ctlinput = rip_ctlinput,
    194  1.69.2.3      yamt 	.pr_ctloutput = rip_ctloutput,
    195  1.69.2.3      yamt 	.pr_usrreq = rip_usrreq,
    196  1.69.2.3      yamt },
    197  1.69.2.3      yamt {	.pr_type = SOCK_RAW,
    198  1.69.2.3      yamt 	.pr_domain = &inetdomain,
    199  1.69.2.3      yamt 	.pr_protocol = IPPROTO_ICMP,
    200  1.69.2.3      yamt 	.pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
    201  1.69.2.3      yamt 	.pr_input = icmp_input,
    202  1.69.2.3      yamt 	.pr_output = rip_output,
    203  1.69.2.3      yamt 	.pr_ctlinput = rip_ctlinput,
    204  1.69.2.3      yamt 	.pr_ctloutput = rip_ctloutput,
    205  1.69.2.3      yamt 	.pr_usrreq = rip_usrreq,
    206  1.69.2.3      yamt 	.pr_init = icmp_init,
    207  1.69.2.3      yamt },
    208  1.69.2.3      yamt #ifdef GATEWAY
    209  1.69.2.3      yamt {	.pr_domain = &inetdomain,
    210  1.69.2.3      yamt 	.pr_protocol = IPPROTO_IP,
    211  1.69.2.3      yamt 	.pr_slowtimo = ipflow_slowtimo,
    212       1.8   mycroft },
    213  1.69.2.3      yamt #endif /* GATEWAY */
    214      1.32    itojun #ifdef IPSEC
    215  1.69.2.3      yamt {	.pr_type = SOCK_RAW,
    216  1.69.2.3      yamt 	.pr_domain = &inetdomain,
    217  1.69.2.3      yamt 	.pr_protocol = IPPROTO_AH,
    218  1.69.2.3      yamt 	.pr_flags = PR_ATOMIC|PR_ADDR,
    219  1.69.2.3      yamt 	.pr_input = ah4_input,
    220  1.69.2.3      yamt 	.pr_ctlinput = ah4_ctlinput,
    221      1.32    itojun },
    222      1.32    itojun #ifdef IPSEC_ESP
    223  1.69.2.3      yamt {	.pr_type = SOCK_RAW,
    224  1.69.2.3      yamt 	.pr_domain = &inetdomain,
    225  1.69.2.3      yamt 	.pr_protocol = IPPROTO_ESP,
    226  1.69.2.3      yamt 	.pr_flags = PR_ATOMIC|PR_ADDR,
    227  1.69.2.3      yamt 	.pr_input = esp4_input,
    228  1.69.2.3      yamt 	.pr_ctlinput = esp4_ctlinput,
    229  1.69.2.3      yamt },
    230  1.69.2.3      yamt #endif /* IPSEC_ESP */
    231  1.69.2.3      yamt {	.pr_type = SOCK_RAW,
    232  1.69.2.3      yamt 	.pr_domain = &inetdomain,
    233  1.69.2.3      yamt 	.pr_protocol = IPPROTO_IPCOMP,
    234  1.69.2.3      yamt 	.pr_flags = PR_ATOMIC|PR_ADDR,
    235  1.69.2.3      yamt 	.pr_input = ipcomp4_input,
    236      1.32    itojun },
    237      1.32    itojun #endif /* IPSEC */
    238      1.61  jonathan #ifdef FAST_IPSEC
    239  1.69.2.3      yamt {	.pr_type = SOCK_RAW,
    240  1.69.2.3      yamt 	.pr_domain = &inetdomain,
    241  1.69.2.3      yamt 	.pr_protocol = IPPROTO_AH,
    242  1.69.2.3      yamt 	.pr_flags = PR_ATOMIC|PR_ADDR,
    243  1.69.2.3      yamt 	.pr_input = ipsec4_common_input,
    244  1.69.2.3      yamt 	.pr_ctlinput = ah4_ctlinput,
    245  1.69.2.3      yamt },
    246  1.69.2.3      yamt {	.pr_type = SOCK_RAW,
    247  1.69.2.3      yamt 	.pr_domain = &inetdomain,
    248  1.69.2.3      yamt 	.pr_protocol = IPPROTO_ESP,
    249  1.69.2.3      yamt 	.pr_flags = PR_ATOMIC|PR_ADDR,
    250  1.69.2.3      yamt 	.pr_input = ipsec4_common_input,
    251  1.69.2.3      yamt 	.pr_ctlinput = esp4_ctlinput,
    252  1.69.2.3      yamt },
    253  1.69.2.3      yamt {	.pr_type = SOCK_RAW,
    254  1.69.2.3      yamt 	.pr_domain = &inetdomain,
    255  1.69.2.3      yamt 	.pr_protocol = IPPROTO_IPCOMP,
    256  1.69.2.3      yamt 	.pr_flags = PR_ATOMIC|PR_ADDR,
    257  1.69.2.3      yamt 	.pr_input = ipsec4_common_input,
    258      1.61  jonathan },
    259      1.61  jonathan #endif /* FAST_IPSEC */
    260  1.69.2.3      yamt {	.pr_type = SOCK_RAW,
    261  1.69.2.3      yamt 	.pr_domain = &inetdomain,
    262  1.69.2.3      yamt 	.pr_protocol = IPPROTO_IPV4,
    263  1.69.2.3      yamt 	.pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
    264  1.69.2.3      yamt 	.pr_input = encap4_input,
    265  1.69.2.3      yamt 	.pr_output = rip_output,
    266  1.69.2.3      yamt 	.pr_ctlinput = rip_ctlinput,
    267  1.69.2.3      yamt 	.pr_ctloutput = rip_ctloutput,
    268  1.69.2.3      yamt 	.pr_usrreq = rip_usrreq,
    269  1.69.2.3      yamt 	.pr_init = encap_init,
    270      1.32    itojun },
    271      1.32    itojun #ifdef INET6
    272  1.69.2.3      yamt {	.pr_type = SOCK_RAW,
    273  1.69.2.3      yamt 	.pr_domain = &inetdomain,
    274  1.69.2.3      yamt 	.pr_protocol = IPPROTO_IPV6,
    275  1.69.2.3      yamt 	.pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
    276  1.69.2.3      yamt 	.pr_input = encap4_input,
    277  1.69.2.3      yamt 	.pr_output = rip_output,
    278  1.69.2.3      yamt 	.pr_ctlinput = rip_ctlinput,
    279  1.69.2.3      yamt 	.pr_ctloutput = rip_ctloutput,
    280  1.69.2.3      yamt 	.pr_usrreq = rip_usrreq,
    281  1.69.2.3      yamt 	.pr_init = encap_init,
    282      1.32    itojun },
    283      1.32    itojun #endif /* INET6 */
    284  1.69.2.2      yamt #if NETHERIP > 0
    285  1.69.2.3      yamt {	.pr_type = SOCK_RAW,
    286  1.69.2.3      yamt 	.pr_domain = &inetdomain,
    287  1.69.2.3      yamt 	.pr_protocol = IPPROTO_ETHERIP,
    288  1.69.2.3      yamt 	.pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
    289  1.69.2.3      yamt 	.pr_input = ip_etherip_input,
    290  1.69.2.3      yamt 	.pr_output = rip_output,
    291  1.69.2.3      yamt 	.pr_ctlinput = rip_ctlinput,
    292  1.69.2.3      yamt 	.pr_ctloutput = rip_ctloutput,
    293  1.69.2.3      yamt 	.pr_usrreq = rip_usrreq,
    294      1.67       kim },
    295  1.69.2.3      yamt #endif /* NETHERIP > 0 */
    296  1.69.2.1      yamt #if NCARP > 0
    297  1.69.2.3      yamt {	.pr_type = SOCK_RAW,
    298  1.69.2.3      yamt 	.pr_domain = &inetdomain,
    299  1.69.2.3      yamt 	.pr_protocol = IPPROTO_CARP,
    300  1.69.2.3      yamt 	.pr_flags = PR_ATOMIC|PR_ADDR,
    301  1.69.2.3      yamt 	.pr_input = carp_proto_input,
    302  1.69.2.3      yamt 	.pr_output = rip_output,
    303  1.69.2.3      yamt 	.pr_ctloutput = rip_ctloutput,
    304  1.69.2.3      yamt 	.pr_usrreq = rip_usrreq,
    305  1.69.2.1      yamt },
    306  1.69.2.3      yamt #endif /* NCARP > 0 */
    307      1.25       hwr #if NGRE > 0
    308  1.69.2.3      yamt {	.pr_type = SOCK_RAW,
    309  1.69.2.3      yamt 	.pr_domain = &inetdomain,
    310  1.69.2.3      yamt 	.pr_protocol = IPPROTO_GRE,
    311  1.69.2.3      yamt 	.pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
    312  1.69.2.3      yamt 	.pr_input = gre_input,
    313  1.69.2.3      yamt 	.pr_output = rip_output,
    314  1.69.2.3      yamt 	.pr_ctloutput = rip_ctloutput,
    315  1.69.2.3      yamt 	.pr_ctlinput = rip_ctlinput,
    316  1.69.2.3      yamt 	.pr_usrreq = rip_usrreq,
    317  1.69.2.3      yamt },
    318  1.69.2.3      yamt {	.pr_type = SOCK_RAW,
    319  1.69.2.3      yamt 	.pr_domain = &inetdomain,
    320  1.69.2.3      yamt 	.pr_protocol = IPPROTO_MOBILE,
    321  1.69.2.3      yamt 	.pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
    322  1.69.2.3      yamt 	.pr_input = gre_mobile_input,
    323  1.69.2.3      yamt 	.pr_output = rip_output,
    324  1.69.2.3      yamt 	.pr_ctloutput = rip_ctloutput,
    325  1.69.2.3      yamt 	.pr_ctlinput = rip_ctlinput,
    326  1.69.2.3      yamt 	.pr_usrreq = rip_usrreq,
    327      1.25       hwr },
    328      1.28   thorpej #endif /* NGRE > 0 */
    329  1.69.2.3      yamt {	.pr_type = SOCK_RAW,
    330  1.69.2.3      yamt 	.pr_domain = &inetdomain,
    331  1.69.2.3      yamt 	.pr_protocol = IPPROTO_IGMP,
    332  1.69.2.3      yamt 	.pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
    333  1.69.2.3      yamt 	.pr_input = igmp_input,
    334  1.69.2.3      yamt 	.pr_output = rip_output,
    335  1.69.2.3      yamt 	.pr_ctloutput = rip_ctloutput,
    336  1.69.2.3      yamt 	.pr_ctlinput = rip_ctlinput,
    337  1.69.2.3      yamt 	.pr_usrreq = rip_usrreq,
    338  1.69.2.3      yamt 	.pr_fasttimo = igmp_fasttimo,
    339  1.69.2.3      yamt 	.pr_slowtimo = igmp_slowtimo,
    340       1.1       cgd },
    341      1.65      manu #ifdef PIM
    342  1.69.2.3      yamt {	.pr_type = SOCK_RAW,
    343  1.69.2.3      yamt 	.pr_domain = &inetdomain,
    344  1.69.2.3      yamt 	.pr_protocol = IPPROTO_PIM,
    345  1.69.2.3      yamt 	.pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
    346  1.69.2.3      yamt 	.pr_input = pim_input,
    347  1.69.2.3      yamt 	.pr_output = rip_output,
    348  1.69.2.3      yamt 	.pr_ctloutput = rip_ctloutput,
    349  1.69.2.3      yamt 	.pr_ctlinput = rip_ctlinput,
    350  1.69.2.3      yamt 	.pr_usrreq = rip_usrreq,
    351      1.65      manu },
    352      1.65      manu #endif /* PIM */
    353       1.1       cgd #ifdef TPIP
    354  1.69.2.3      yamt {	.pr_type = SOCK_SEQPACKET,
    355  1.69.2.3      yamt 	.pr_domain = &inetdomain,
    356  1.69.2.3      yamt 	.pr_protocol = IPPROTO_TP,
    357  1.69.2.3      yamt 	.pr_flags = PR_CONNREQUIRED|PR_WANTRCVD|PR_LISTEN|PR_LASTHDR|PR_ABRTACPTDIS,
    358  1.69.2.3      yamt 	.pr_input = tpip_input,
    359  1.69.2.3      yamt 	.pr_ctloutput = tp_ctloutput,
    360  1.69.2.3      yamt 	.pr_ctlinput = tpip_ctlinput,
    361  1.69.2.3      yamt 	.pr_usrreq = tp_usrreq,
    362  1.69.2.3      yamt 	.pr_init = tp_init,
    363  1.69.2.3      yamt 	.pr_slowtimo = tp_slowtimo,
    364  1.69.2.3      yamt 	.pr_drain = tp_drain,
    365       1.1       cgd },
    366      1.11   mycroft #endif /* TPIP */
    367      1.45    itojun #ifdef ISO
    368       1.1       cgd /* EON (ISO CLNL over IP) */
    369       1.1       cgd #ifdef EON
    370  1.69.2.3      yamt {	.pr_type = SOCK_RAW,
    371  1.69.2.3      yamt 	.pr_domain = &inetdomain,
    372  1.69.2.3      yamt 	.pr_protocol = IPPROTO_EON,
    373  1.69.2.3      yamt 	.pr_flags = PR_LASTHDR,
    374  1.69.2.3      yamt 	.pr_input = eoninput,
    375  1.69.2.3      yamt 	.pr_ctlinput = eonctlinput,
    376  1.69.2.3      yamt 	.pr_init = eonprotoinit,
    377       1.4   hpeyerl },
    378      1.45    itojun #else
    379  1.69.2.3      yamt {	.pr_type = SOCK_RAW,
    380  1.69.2.3      yamt 	.pr_domain = &inetdomain,
    381  1.69.2.3      yamt 	.pr_protocol = IPPROTO_EON,
    382  1.69.2.3      yamt 	.pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
    383  1.69.2.3      yamt 	.pr_input = encap4_input,
    384  1.69.2.3      yamt 	.pr_output = rip_output,
    385  1.69.2.3      yamt 	.pr_ctloutput = rip_ctloutput,
    386  1.69.2.3      yamt 	.pr_ctlinput = rip_ctlinput,
    387  1.69.2.3      yamt 	.pr_usrreq = rip_usrreq,
    388  1.69.2.3      yamt 	.pr_init = encap_init,
    389      1.45    itojun },
    390      1.11   mycroft #endif /* EON */
    391      1.45    itojun #endif /* ISO */
    392      1.11   mycroft /* raw wildcard */
    393  1.69.2.3      yamt {	.pr_type = SOCK_RAW,
    394  1.69.2.3      yamt 	.pr_domain = &inetdomain,
    395  1.69.2.3      yamt 	.pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
    396  1.69.2.3      yamt 	.pr_input = rip_input,
    397  1.69.2.3      yamt 	.pr_output = rip_output,
    398  1.69.2.3      yamt 	.pr_ctloutput = rip_ctloutput,
    399  1.69.2.3      yamt 	.pr_ctlinput = rip_ctlinput,
    400  1.69.2.3      yamt 	.pr_usrreq = rip_usrreq,
    401  1.69.2.3      yamt 	.pr_init = rip_init,
    402       1.1       cgd },
    403       1.1       cgd };
    404       1.1       cgd 
    405  1.69.2.2      yamt extern struct ifqueue ipintrq;
    406  1.69.2.2      yamt 
    407  1.69.2.2      yamt struct domain inetdomain = {
    408  1.69.2.2      yamt 	.dom_family = PF_INET, .dom_name = "internet", .dom_init = NULL,
    409  1.69.2.2      yamt 	.dom_externalize = NULL, .dom_dispose = NULL,
    410  1.69.2.2      yamt 	.dom_protosw = inetsw,
    411  1.69.2.3      yamt 	.dom_protoswNPROTOSW = &inetsw[__arraycount(inetsw)],
    412  1.69.2.2      yamt 	.dom_rtattach = rn_inithead,
    413  1.69.2.2      yamt 	.dom_rtoffset = 32, .dom_maxrtkey = sizeof(struct sockaddr_in),
    414  1.69.2.2      yamt #ifdef IPSELSRC
    415  1.69.2.2      yamt 	.dom_ifattach = in_domifattach,
    416  1.69.2.2      yamt 	.dom_ifdetach = in_domifdetach,
    417  1.69.2.2      yamt #else
    418  1.69.2.2      yamt 	.dom_ifattach = NULL,
    419  1.69.2.2      yamt 	.dom_ifdetach = NULL,
    420  1.69.2.2      yamt #endif
    421  1.69.2.2      yamt 	.dom_ifqueues = { &ipintrq, NULL },
    422  1.69.2.2      yamt 	.dom_link = { NULL },
    423  1.69.2.2      yamt 	.dom_mowner = MOWNER_INIT("",""),
    424  1.69.2.3      yamt 	.dom_sa_cmpofs = offsetof(struct sockaddr_in, sin_addr),
    425  1.69.2.3      yamt 	.dom_sa_cmplen = sizeof(struct in_addr),
    426  1.69.2.3      yamt 	.dom_rtcache = LIST_HEAD_INITIALIZER(inetdomain.dom_rtcache)
    427  1.69.2.2      yamt };
    428      1.38   darrenr 
    429      1.38   darrenr u_char	ip_protox[IPPROTO_MAX];
    430      1.36   thorpej 
    431      1.40    itojun int icmperrppslim = 100;			/* 100pps */
    432  1.69.2.3      yamt 
    433  1.69.2.3      yamt int
    434  1.69.2.3      yamt sockaddr_in_cmp(const struct sockaddr *sa1, const struct sockaddr *sa2)
    435  1.69.2.3      yamt {
    436  1.69.2.3      yamt 	uint_fast8_t len;
    437  1.69.2.3      yamt 	const uint_fast8_t addrofs = offsetof(struct sockaddr_in, sin_addr),
    438  1.69.2.3      yamt 			   addrend = addrofs + sizeof(struct in_addr);
    439  1.69.2.3      yamt 	int rc;
    440  1.69.2.3      yamt 	const struct sockaddr_in *sin1, *sin2;
    441  1.69.2.3      yamt 
    442  1.69.2.3      yamt 	sin1 = satocsin(sa1);
    443  1.69.2.3      yamt 	sin2 = satocsin(sa2);
    444  1.69.2.3      yamt 
    445  1.69.2.3      yamt 	len = MIN(addrend, MIN(sin1->sin_len, sin2->sin_len));
    446  1.69.2.3      yamt 
    447  1.69.2.3      yamt 	if (len > addrofs &&
    448  1.69.2.3      yamt 	     (rc = memcmp(&sin1->sin_addr, &sin2->sin_addr,
    449  1.69.2.3      yamt 	                  len - addrofs)) != 0)
    450  1.69.2.3      yamt 		return rc;
    451  1.69.2.3      yamt 
    452  1.69.2.3      yamt 	return sin1->sin_len - sin2->sin_len;
    453  1.69.2.3      yamt }
    454