Home | History | Annotate | Line # | Download | only in netinet
in_proto.c revision 1.91.18.2
      1  1.91.18.1       mjf /*	$NetBSD: in_proto.c,v 1.91.18.2 2009/01/17 13:29:32 mjf 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.91.18.1       mjf __KERNEL_RCSID(0, "$NetBSD: in_proto.c,v 1.91.18.2 2009/01/17 13:29:32 mjf 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.78    dyoung #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.79    rpaulo 
    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.72  liamjfoy #include "carp.h"
    142       1.72  liamjfoy #if NCARP > 0
    143       1.72  liamjfoy #include <netinet/ip_carp.h>
    144       1.72  liamjfoy #endif
    145       1.72  liamjfoy 
    146       1.79    rpaulo #include "etherip.h"
    147       1.79    rpaulo #if NETHERIP > 0
    148       1.79    rpaulo #include <netinet/ip_etherip.h>
    149       1.79    rpaulo #endif
    150       1.67       kim 
    151       1.66      matt DOMAIN_DEFINE(inetdomain);	/* forward declare and add to link set */
    152       1.66      matt 
    153  1.91.18.1       mjf /* Wrappers to acquire kernel_lock. */
    154  1.91.18.1       mjf 
    155  1.91.18.1       mjf PR_WRAP_USRREQ(rip_usrreq)
    156  1.91.18.1       mjf PR_WRAP_USRREQ(udp_usrreq)
    157  1.91.18.1       mjf PR_WRAP_USRREQ(tcp_usrreq)
    158  1.91.18.1       mjf 
    159  1.91.18.1       mjf #define	rip_usrreq 	rip_usrreq_wrapper
    160  1.91.18.1       mjf #define	udp_usrreq 	udp_usrreq_wrapper
    161  1.91.18.1       mjf #define	tcp_usrreq 	tcp_usrreq_wrapper
    162  1.91.18.1       mjf 
    163  1.91.18.1       mjf PR_WRAP_CTLINPUT(rip_ctlinput)
    164  1.91.18.1       mjf PR_WRAP_CTLINPUT(udp_ctlinput)
    165  1.91.18.1       mjf PR_WRAP_CTLINPUT(tcp_ctlinput)
    166  1.91.18.1       mjf 
    167  1.91.18.1       mjf #define	rip_ctlinput	rip_ctlinput_wrapper
    168  1.91.18.1       mjf #define	udp_ctlinput	udp_ctlinput_wrapper
    169  1.91.18.1       mjf #define	tcp_ctlinput	tcp_ctlinput_wrapper
    170  1.91.18.1       mjf 
    171  1.91.18.1       mjf PR_WRAP_CTLOUTPUT(rip_ctloutput)
    172  1.91.18.1       mjf PR_WRAP_CTLOUTPUT(udp_ctloutput)
    173  1.91.18.1       mjf PR_WRAP_CTLOUTPUT(tcp_ctloutput)
    174  1.91.18.1       mjf 
    175  1.91.18.1       mjf #define	rip_ctloutput	rip_ctloutput_wrapper
    176  1.91.18.1       mjf #define	udp_ctloutput	udp_ctloutput_wrapper
    177  1.91.18.1       mjf #define	tcp_ctloutput	tcp_ctloutput_wrapper
    178  1.91.18.1       mjf 
    179  1.91.18.1       mjf #if defined(IPSEC) || defined(FAST_IPSEC)
    180  1.91.18.1       mjf PR_WRAP_CTLINPUT(ah4_ctlinput)
    181  1.91.18.1       mjf 
    182  1.91.18.1       mjf #define	ah4_ctlinput	ah4_ctlinput_wrapper
    183  1.91.18.1       mjf #endif
    184  1.91.18.1       mjf 
    185  1.91.18.1       mjf #if defined(IPSEC_ESP) || defined(FAST_IPSEC)
    186  1.91.18.1       mjf PR_WRAP_CTLINPUT(esp4_ctlinput)
    187  1.91.18.1       mjf 
    188  1.91.18.1       mjf #define	esp4_ctlinput	esp4_ctlinput_wrapper
    189  1.91.18.1       mjf #endif
    190  1.91.18.1       mjf 
    191  1.91.18.1       mjf #ifdef TPIP
    192  1.91.18.1       mjf PR_WRAP_CTLOUTPUT(tp_ctloutput)
    193  1.91.18.1       mjf 
    194  1.91.18.1       mjf #define	tp_ctloutput	tp_ctloutput_wrapper
    195  1.91.18.1       mjf 
    196  1.91.18.1       mjf PR_WRAP_CTLINPUT(tpip_ctlinput)
    197  1.91.18.1       mjf 
    198  1.91.18.1       mjf #define	tpip_ctlinput	tpip_ctlinput_wrapper
    199  1.91.18.1       mjf #endif
    200  1.91.18.1       mjf 
    201  1.91.18.1       mjf #ifdef EON
    202  1.91.18.1       mjf PR_WRAP_CTLINPUT(eonctlinput)
    203  1.91.18.1       mjf 
    204  1.91.18.1       mjf #define	eonctlinput	eonctlinput_wrapper
    205  1.91.18.1       mjf #endif
    206  1.91.18.1       mjf 
    207       1.63      matt const struct protosw inetsw[] = {
    208       1.81  liamjfoy {	.pr_domain = &inetdomain,
    209       1.81  liamjfoy 	.pr_init = ip_init,
    210       1.81  liamjfoy 	.pr_output = ip_output,
    211       1.81  liamjfoy 	.pr_slowtimo = ip_slowtimo,
    212       1.81  liamjfoy 	.pr_drain = ip_drain,
    213       1.81  liamjfoy },
    214       1.81  liamjfoy {	.pr_type = SOCK_DGRAM,
    215       1.81  liamjfoy 	.pr_domain = &inetdomain,
    216       1.81  liamjfoy 	.pr_protocol = IPPROTO_UDP,
    217       1.81  liamjfoy 	.pr_flags = PR_ATOMIC|PR_ADDR|PR_PURGEIF,
    218       1.81  liamjfoy 	.pr_input = udp_input,
    219       1.81  liamjfoy 	.pr_ctlinput = udp_ctlinput,
    220       1.81  liamjfoy 	.pr_ctloutput = udp_ctloutput,
    221       1.81  liamjfoy 	.pr_usrreq = udp_usrreq,
    222       1.81  liamjfoy 	.pr_init = udp_init,
    223       1.81  liamjfoy },
    224       1.81  liamjfoy {	.pr_type = SOCK_STREAM,
    225       1.81  liamjfoy 	.pr_domain = &inetdomain,
    226       1.81  liamjfoy 	.pr_protocol = IPPROTO_TCP,
    227       1.81  liamjfoy 	.pr_flags = PR_CONNREQUIRED|PR_WANTRCVD|PR_LISTEN|PR_ABRTACPTDIS|PR_PURGEIF,
    228       1.81  liamjfoy 	.pr_input = tcp_input,
    229       1.81  liamjfoy 	.pr_ctlinput = tcp_ctlinput,
    230       1.81  liamjfoy 	.pr_ctloutput = tcp_ctloutput,
    231       1.81  liamjfoy 	.pr_usrreq = tcp_usrreq,
    232       1.81  liamjfoy 	.pr_init = tcp_init,
    233       1.81  liamjfoy 	.pr_slowtimo = tcp_slowtimo,
    234       1.81  liamjfoy 	.pr_drain = tcp_drain,
    235       1.81  liamjfoy },
    236       1.81  liamjfoy {	.pr_type = SOCK_RAW,
    237       1.81  liamjfoy 	.pr_domain = &inetdomain,
    238       1.81  liamjfoy 	.pr_protocol = IPPROTO_RAW,
    239       1.81  liamjfoy 	.pr_flags = PR_ATOMIC|PR_ADDR|PR_PURGEIF,
    240       1.81  liamjfoy 	.pr_input = rip_input,
    241       1.81  liamjfoy 	.pr_output = rip_output,
    242       1.81  liamjfoy 	.pr_ctlinput = rip_ctlinput,
    243       1.81  liamjfoy 	.pr_ctloutput = rip_ctloutput,
    244       1.81  liamjfoy 	.pr_usrreq = rip_usrreq,
    245       1.81  liamjfoy },
    246       1.81  liamjfoy {	.pr_type = SOCK_RAW,
    247       1.81  liamjfoy 	.pr_domain = &inetdomain,
    248       1.81  liamjfoy 	.pr_protocol = IPPROTO_ICMP,
    249       1.81  liamjfoy 	.pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
    250       1.81  liamjfoy 	.pr_input = icmp_input,
    251       1.81  liamjfoy 	.pr_output = rip_output,
    252       1.81  liamjfoy 	.pr_ctlinput = rip_ctlinput,
    253       1.81  liamjfoy 	.pr_ctloutput = rip_ctloutput,
    254       1.81  liamjfoy 	.pr_usrreq = rip_usrreq,
    255       1.81  liamjfoy 	.pr_init = icmp_init,
    256        1.8   mycroft },
    257       1.83  liamjfoy #ifdef GATEWAY
    258       1.83  liamjfoy {	.pr_domain = &inetdomain,
    259       1.83  liamjfoy 	.pr_protocol = IPPROTO_IP,
    260       1.83  liamjfoy 	.pr_slowtimo = ipflow_slowtimo,
    261       1.83  liamjfoy },
    262       1.83  liamjfoy #endif /* GATEWAY */
    263       1.32    itojun #ifdef IPSEC
    264       1.81  liamjfoy {	.pr_type = SOCK_RAW,
    265       1.81  liamjfoy 	.pr_domain = &inetdomain,
    266       1.81  liamjfoy 	.pr_protocol = IPPROTO_AH,
    267       1.81  liamjfoy 	.pr_flags = PR_ATOMIC|PR_ADDR,
    268       1.81  liamjfoy 	.pr_input = ah4_input,
    269       1.81  liamjfoy 	.pr_ctlinput = ah4_ctlinput,
    270  1.91.18.1       mjf 	.pr_init = ah4_init,
    271       1.32    itojun },
    272       1.32    itojun #ifdef IPSEC_ESP
    273       1.81  liamjfoy {	.pr_type = SOCK_RAW,
    274       1.81  liamjfoy 	.pr_domain = &inetdomain,
    275       1.81  liamjfoy 	.pr_protocol = IPPROTO_ESP,
    276       1.81  liamjfoy 	.pr_flags = PR_ATOMIC|PR_ADDR,
    277       1.81  liamjfoy 	.pr_input = esp4_input,
    278       1.81  liamjfoy 	.pr_ctlinput = esp4_ctlinput,
    279  1.91.18.1       mjf 	.pr_init = esp4_init,
    280       1.81  liamjfoy },
    281       1.81  liamjfoy #endif /* IPSEC_ESP */
    282       1.81  liamjfoy {	.pr_type = SOCK_RAW,
    283       1.82  liamjfoy 	.pr_domain = &inetdomain,
    284       1.81  liamjfoy 	.pr_protocol = IPPROTO_IPCOMP,
    285       1.81  liamjfoy 	.pr_flags = PR_ATOMIC|PR_ADDR,
    286       1.81  liamjfoy 	.pr_input = ipcomp4_input,
    287  1.91.18.1       mjf 	.pr_init = ipcomp4_init,
    288       1.32    itojun },
    289       1.32    itojun #endif /* IPSEC */
    290       1.61  jonathan #ifdef FAST_IPSEC
    291       1.81  liamjfoy {	.pr_type = SOCK_RAW,
    292       1.81  liamjfoy 	.pr_domain = &inetdomain,
    293       1.81  liamjfoy 	.pr_protocol = IPPROTO_AH,
    294       1.81  liamjfoy 	.pr_flags = PR_ATOMIC|PR_ADDR,
    295       1.81  liamjfoy 	.pr_input = ipsec4_common_input,
    296       1.81  liamjfoy 	.pr_ctlinput = ah4_ctlinput,
    297       1.81  liamjfoy },
    298       1.81  liamjfoy {	.pr_type = SOCK_RAW,
    299       1.81  liamjfoy 	.pr_domain = &inetdomain,
    300       1.81  liamjfoy 	.pr_protocol = IPPROTO_ESP,
    301       1.81  liamjfoy 	.pr_flags = PR_ATOMIC|PR_ADDR,
    302       1.81  liamjfoy 	.pr_input = ipsec4_common_input,
    303       1.81  liamjfoy 	.pr_ctlinput = esp4_ctlinput,
    304       1.81  liamjfoy },
    305       1.81  liamjfoy {	.pr_type = SOCK_RAW,
    306       1.81  liamjfoy 	.pr_domain = &inetdomain,
    307       1.81  liamjfoy 	.pr_protocol = IPPROTO_IPCOMP,
    308       1.81  liamjfoy 	.pr_flags = PR_ATOMIC|PR_ADDR,
    309       1.81  liamjfoy 	.pr_input = ipsec4_common_input,
    310       1.61  jonathan },
    311       1.61  jonathan #endif /* FAST_IPSEC */
    312       1.81  liamjfoy {	.pr_type = SOCK_RAW,
    313       1.81  liamjfoy 	.pr_domain = &inetdomain,
    314       1.81  liamjfoy 	.pr_protocol = IPPROTO_IPV4,
    315       1.81  liamjfoy 	.pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
    316       1.81  liamjfoy 	.pr_input = encap4_input,
    317       1.81  liamjfoy 	.pr_output = rip_output,
    318       1.81  liamjfoy 	.pr_ctlinput = rip_ctlinput,
    319       1.81  liamjfoy 	.pr_ctloutput = rip_ctloutput,
    320       1.81  liamjfoy 	.pr_usrreq = rip_usrreq,
    321       1.81  liamjfoy 	.pr_init = encap_init,
    322       1.32    itojun },
    323       1.32    itojun #ifdef INET6
    324       1.81  liamjfoy {	.pr_type = SOCK_RAW,
    325       1.81  liamjfoy 	.pr_domain = &inetdomain,
    326       1.81  liamjfoy 	.pr_protocol = IPPROTO_IPV6,
    327       1.81  liamjfoy 	.pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
    328       1.81  liamjfoy 	.pr_input = encap4_input,
    329       1.81  liamjfoy 	.pr_output = rip_output,
    330       1.81  liamjfoy 	.pr_ctlinput = rip_ctlinput,
    331       1.81  liamjfoy 	.pr_ctloutput = rip_ctloutput,
    332       1.81  liamjfoy 	.pr_usrreq = rip_usrreq,
    333       1.81  liamjfoy 	.pr_init = encap_init,
    334       1.32    itojun },
    335       1.32    itojun #endif /* INET6 */
    336       1.79    rpaulo #if NETHERIP > 0
    337       1.81  liamjfoy {	.pr_type = SOCK_RAW,
    338       1.81  liamjfoy 	.pr_domain = &inetdomain,
    339       1.81  liamjfoy 	.pr_protocol = IPPROTO_ETHERIP,
    340       1.81  liamjfoy 	.pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
    341       1.81  liamjfoy 	.pr_input = ip_etherip_input,
    342       1.81  liamjfoy 	.pr_output = rip_output,
    343       1.81  liamjfoy 	.pr_ctlinput = rip_ctlinput,
    344       1.81  liamjfoy 	.pr_ctloutput = rip_ctloutput,
    345       1.81  liamjfoy 	.pr_usrreq = rip_usrreq,
    346       1.67       kim },
    347       1.81  liamjfoy #endif /* NETHERIP > 0 */
    348       1.72  liamjfoy #if NCARP > 0
    349       1.81  liamjfoy {	.pr_type = SOCK_RAW,
    350       1.81  liamjfoy 	.pr_domain = &inetdomain,
    351       1.81  liamjfoy 	.pr_protocol = IPPROTO_CARP,
    352       1.81  liamjfoy 	.pr_flags = PR_ATOMIC|PR_ADDR,
    353       1.81  liamjfoy 	.pr_input = carp_proto_input,
    354       1.81  liamjfoy 	.pr_output = rip_output,
    355       1.81  liamjfoy 	.pr_ctloutput = rip_ctloutput,
    356       1.81  liamjfoy 	.pr_usrreq = rip_usrreq,
    357       1.72  liamjfoy },
    358       1.81  liamjfoy #endif /* NCARP > 0 */
    359       1.81  liamjfoy {	.pr_type = SOCK_RAW,
    360       1.81  liamjfoy 	.pr_domain = &inetdomain,
    361       1.81  liamjfoy 	.pr_protocol = IPPROTO_IGMP,
    362       1.81  liamjfoy 	.pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
    363       1.81  liamjfoy 	.pr_input = igmp_input,
    364       1.81  liamjfoy 	.pr_output = rip_output,
    365       1.81  liamjfoy 	.pr_ctloutput = rip_ctloutput,
    366       1.81  liamjfoy 	.pr_ctlinput = rip_ctlinput,
    367       1.81  liamjfoy 	.pr_usrreq = rip_usrreq,
    368       1.81  liamjfoy 	.pr_fasttimo = igmp_fasttimo,
    369       1.81  liamjfoy 	.pr_slowtimo = igmp_slowtimo,
    370  1.91.18.1       mjf 	.pr_init = igmp_init,
    371        1.1       cgd },
    372       1.65      manu #ifdef PIM
    373       1.81  liamjfoy {	.pr_type = SOCK_RAW,
    374       1.81  liamjfoy 	.pr_domain = &inetdomain,
    375       1.81  liamjfoy 	.pr_protocol = IPPROTO_PIM,
    376       1.81  liamjfoy 	.pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
    377       1.81  liamjfoy 	.pr_input = pim_input,
    378       1.81  liamjfoy 	.pr_output = rip_output,
    379       1.81  liamjfoy 	.pr_ctloutput = rip_ctloutput,
    380       1.81  liamjfoy 	.pr_ctlinput = rip_ctlinput,
    381       1.81  liamjfoy 	.pr_usrreq = rip_usrreq,
    382       1.65      manu },
    383       1.65      manu #endif /* PIM */
    384        1.1       cgd #ifdef TPIP
    385       1.81  liamjfoy {	.pr_type = SOCK_SEQPACKET,
    386       1.81  liamjfoy 	.pr_domain = &inetdomain,
    387       1.81  liamjfoy 	.pr_protocol = IPPROTO_TP,
    388       1.81  liamjfoy 	.pr_flags = PR_CONNREQUIRED|PR_WANTRCVD|PR_LISTEN|PR_LASTHDR|PR_ABRTACPTDIS,
    389       1.81  liamjfoy 	.pr_input = tpip_input,
    390       1.81  liamjfoy 	.pr_ctloutput = tp_ctloutput,
    391       1.81  liamjfoy 	.pr_ctlinput = tpip_ctlinput,
    392       1.81  liamjfoy 	.pr_usrreq = tp_usrreq,
    393       1.81  liamjfoy 	.pr_init = tp_init,
    394       1.81  liamjfoy 	.pr_slowtimo = tp_slowtimo,
    395       1.81  liamjfoy 	.pr_drain = tp_drain,
    396        1.1       cgd },
    397       1.11   mycroft #endif /* TPIP */
    398       1.45    itojun #ifdef ISO
    399        1.1       cgd /* EON (ISO CLNL over IP) */
    400        1.1       cgd #ifdef EON
    401       1.81  liamjfoy {	.pr_type = SOCK_RAW,
    402       1.81  liamjfoy 	.pr_domain = &inetdomain,
    403       1.81  liamjfoy 	.pr_protocol = IPPROTO_EON,
    404       1.81  liamjfoy 	.pr_flags = PR_LASTHDR,
    405       1.81  liamjfoy 	.pr_input = eoninput,
    406       1.81  liamjfoy 	.pr_ctlinput = eonctlinput,
    407       1.81  liamjfoy 	.pr_init = eonprotoinit,
    408        1.4   hpeyerl },
    409       1.45    itojun #else
    410       1.81  liamjfoy {	.pr_type = SOCK_RAW,
    411       1.81  liamjfoy 	.pr_domain = &inetdomain,
    412       1.81  liamjfoy 	.pr_protocol = IPPROTO_EON,
    413       1.81  liamjfoy 	.pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
    414       1.81  liamjfoy 	.pr_input = encap4_input,
    415       1.81  liamjfoy 	.pr_output = rip_output,
    416       1.81  liamjfoy 	.pr_ctloutput = rip_ctloutput,
    417       1.81  liamjfoy 	.pr_ctlinput = rip_ctlinput,
    418       1.81  liamjfoy 	.pr_usrreq = rip_usrreq,
    419       1.81  liamjfoy 	.pr_init = encap_init,
    420       1.45    itojun },
    421       1.11   mycroft #endif /* EON */
    422       1.45    itojun #endif /* ISO */
    423       1.11   mycroft /* raw wildcard */
    424       1.81  liamjfoy {	.pr_type = SOCK_RAW,
    425       1.81  liamjfoy 	.pr_domain = &inetdomain,
    426       1.81  liamjfoy 	.pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
    427       1.81  liamjfoy 	.pr_input = rip_input,
    428       1.81  liamjfoy 	.pr_output = rip_output,
    429       1.81  liamjfoy 	.pr_ctloutput = rip_ctloutput,
    430       1.81  liamjfoy 	.pr_ctlinput = rip_ctlinput,
    431       1.81  liamjfoy 	.pr_usrreq = rip_usrreq,
    432       1.81  liamjfoy 	.pr_init = rip_init,
    433        1.1       cgd },
    434        1.1       cgd };
    435        1.1       cgd 
    436       1.73      matt extern struct ifqueue ipintrq;
    437       1.73      matt 
    438       1.89    dyoung const struct sockaddr_in in_any = {
    439       1.89    dyoung 	  .sin_len = sizeof(struct sockaddr_in)
    440       1.89    dyoung 	, .sin_family = AF_INET
    441       1.89    dyoung 	, .sin_port = 0
    442       1.90    dyoung 	, .sin_addr = {.s_addr = 0 /* INADDR_ANY */}
    443       1.89    dyoung };
    444       1.89    dyoung 
    445       1.73      matt struct domain inetdomain = {
    446       1.80    dyoung 	.dom_family = PF_INET, .dom_name = "internet", .dom_init = NULL,
    447       1.80    dyoung 	.dom_externalize = NULL, .dom_dispose = NULL,
    448       1.80    dyoung 	.dom_protosw = inetsw,
    449       1.87    dyoung 	.dom_protoswNPROTOSW = &inetsw[__arraycount(inetsw)],
    450       1.80    dyoung 	.dom_rtattach = rn_inithead,
    451  1.91.18.2       mjf 	.dom_rtoffset = 32,
    452  1.91.18.2       mjf 	.dom_maxrtkey = sizeof(struct ip_pack4),
    453       1.78    dyoung #ifdef IPSELSRC
    454       1.80    dyoung 	.dom_ifattach = in_domifattach,
    455       1.80    dyoung 	.dom_ifdetach = in_domifdetach,
    456       1.78    dyoung #else
    457       1.80    dyoung 	.dom_ifattach = NULL,
    458       1.80    dyoung 	.dom_ifdetach = NULL,
    459       1.78    dyoung #endif
    460       1.80    dyoung 	.dom_ifqueues = { &ipintrq, NULL },
    461       1.80    dyoung 	.dom_link = { NULL },
    462       1.80    dyoung 	.dom_mowner = MOWNER_INIT("",""),
    463       1.86    dyoung 	.dom_sa_cmpofs = offsetof(struct sockaddr_in, sin_addr),
    464       1.86    dyoung 	.dom_sa_cmplen = sizeof(struct in_addr),
    465       1.89    dyoung 	.dom_sa_any = (const struct sockaddr *)&in_any,
    466       1.89    dyoung 	.dom_sockaddr_const_addr = sockaddr_in_const_addr,
    467       1.89    dyoung 	.dom_sockaddr_addr = sockaddr_in_addr,
    468       1.84    dyoung 	.dom_rtcache = LIST_HEAD_INITIALIZER(inetdomain.dom_rtcache)
    469       1.73      matt };
    470       1.38   darrenr 
    471       1.38   darrenr u_char	ip_protox[IPPROTO_MAX];
    472       1.36   thorpej 
    473       1.40    itojun int icmperrppslim = 100;			/* 100pps */
    474       1.84    dyoung 
    475       1.89    dyoung static void
    476       1.89    dyoung sockaddr_in_addrlen(const struct sockaddr *sa, socklen_t *slenp)
    477       1.89    dyoung {
    478       1.89    dyoung 	socklen_t slen;
    479       1.89    dyoung 
    480       1.89    dyoung 	if (slenp == NULL)
    481       1.89    dyoung 		return;
    482       1.89    dyoung 
    483       1.89    dyoung 	slen = sockaddr_getlen(sa);
    484       1.89    dyoung 	*slenp = (socklen_t)MIN(sizeof(struct in_addr),
    485       1.89    dyoung 	    slen - MIN(slen, offsetof(struct sockaddr_in, sin_addr)));
    486       1.89    dyoung }
    487       1.89    dyoung 
    488       1.89    dyoung const void *
    489       1.89    dyoung sockaddr_in_const_addr(const struct sockaddr *sa, socklen_t *slenp)
    490       1.89    dyoung {
    491       1.89    dyoung 	const struct sockaddr_in *sin;
    492       1.89    dyoung 
    493       1.89    dyoung 	sockaddr_in_addrlen(sa, slenp);
    494       1.89    dyoung 	sin = (const struct sockaddr_in *)sa;
    495       1.89    dyoung 	return &sin->sin_addr;
    496       1.89    dyoung }
    497       1.89    dyoung 
    498       1.89    dyoung void *
    499       1.89    dyoung sockaddr_in_addr(struct sockaddr *sa, socklen_t *slenp)
    500       1.89    dyoung {
    501       1.89    dyoung 	struct sockaddr_in *sin;
    502       1.89    dyoung 
    503       1.89    dyoung 	sockaddr_in_addrlen(sa, slenp);
    504       1.89    dyoung 	sin = (struct sockaddr_in *)sa;
    505       1.89    dyoung 	return &sin->sin_addr;
    506       1.89    dyoung }
    507       1.89    dyoung 
    508       1.84    dyoung int
    509       1.84    dyoung sockaddr_in_cmp(const struct sockaddr *sa1, const struct sockaddr *sa2)
    510       1.84    dyoung {
    511       1.84    dyoung 	uint_fast8_t len;
    512       1.84    dyoung 	const uint_fast8_t addrofs = offsetof(struct sockaddr_in, sin_addr),
    513       1.84    dyoung 			   addrend = addrofs + sizeof(struct in_addr);
    514       1.84    dyoung 	int rc;
    515       1.84    dyoung 	const struct sockaddr_in *sin1, *sin2;
    516       1.84    dyoung 
    517       1.84    dyoung 	sin1 = satocsin(sa1);
    518       1.84    dyoung 	sin2 = satocsin(sa2);
    519       1.84    dyoung 
    520       1.84    dyoung 	len = MIN(addrend, MIN(sin1->sin_len, sin2->sin_len));
    521       1.84    dyoung 
    522       1.84    dyoung 	if (len > addrofs &&
    523       1.84    dyoung 	     (rc = memcmp(&sin1->sin_addr, &sin2->sin_addr,
    524       1.84    dyoung 	                  len - addrofs)) != 0)
    525       1.84    dyoung 		return rc;
    526       1.84    dyoung 
    527       1.84    dyoung 	return sin1->sin_len - sin2->sin_len;
    528       1.84    dyoung }
    529