2005-01-07 01:45:51 +00:00
|
|
|
/*-
|
1994-09-15 10:36:56 +00:00
|
|
|
* Copyright (c) 1982, 1986, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
1995-09-21 17:58:07 +00:00
|
|
|
* @(#)in_proto.c 8.2 (Berkeley) 2/9/95
|
1999-08-28 01:08:13 +00:00
|
|
|
* $FreeBSD$
|
1994-09-15 10:36:56 +00:00
|
|
|
*/
|
1994-05-24 10:09:53 +00:00
|
|
|
|
1997-12-15 20:31:25 +00:00
|
|
|
#include "opt_ipx.h"
|
2003-08-07 18:16:59 +00:00
|
|
|
#include "opt_mrouting.h"
|
1999-12-22 19:13:38 +00:00
|
|
|
#include "opt_ipsec.h"
|
|
|
|
#include "opt_inet6.h"
|
2004-06-16 23:24:02 +00:00
|
|
|
#include "opt_pf.h"
|
1997-11-05 20:17:23 +00:00
|
|
|
|
1994-09-15 10:36:56 +00:00
|
|
|
#include <sys/param.h>
|
2003-02-19 22:32:43 +00:00
|
|
|
#include <sys/systm.h>
|
1995-05-11 00:13:26 +00:00
|
|
|
#include <sys/kernel.h>
|
1994-09-15 10:36:56 +00:00
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/domain.h>
|
1995-11-20 12:28:21 +00:00
|
|
|
#include <sys/protosw.h>
|
1999-02-16 10:49:55 +00:00
|
|
|
#include <sys/queue.h>
|
1995-11-09 20:23:09 +00:00
|
|
|
#include <sys/sysctl.h>
|
1994-05-24 10:09:53 +00:00
|
|
|
|
1994-09-15 10:36:56 +00:00
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/route.h>
|
1994-05-24 10:09:53 +00:00
|
|
|
|
1994-09-15 10:36:56 +00:00
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/in_systm.h>
|
|
|
|
#include <netinet/ip.h>
|
|
|
|
#include <netinet/ip_var.h>
|
|
|
|
#include <netinet/ip_icmp.h>
|
|
|
|
#include <netinet/igmp_var.h>
|
2003-08-07 18:16:59 +00:00
|
|
|
#ifdef PIM
|
|
|
|
#include <netinet/pim_var.h>
|
|
|
|
#endif
|
1994-09-15 10:36:56 +00:00
|
|
|
#include <netinet/tcp.h>
|
|
|
|
#include <netinet/tcp_timer.h>
|
|
|
|
#include <netinet/tcp_var.h>
|
|
|
|
#include <netinet/udp.h>
|
|
|
|
#include <netinet/udp_var.h>
|
2000-07-04 16:35:15 +00:00
|
|
|
#include <netinet/ip_encap.h>
|
1999-12-22 19:13:38 +00:00
|
|
|
|
1994-09-15 10:36:56 +00:00
|
|
|
/*
|
|
|
|
* TCP/IP protocol family: IP, ICMP, UDP, TCP.
|
|
|
|
*/
|
1994-05-24 10:09:53 +00:00
|
|
|
|
1999-12-22 19:13:38 +00:00
|
|
|
#ifdef IPSEC
|
|
|
|
#include <netinet6/ipsec.h>
|
|
|
|
#include <netinet6/ah.h>
|
|
|
|
#ifdef IPSEC_ESP
|
|
|
|
#include <netinet6/esp.h>
|
|
|
|
#endif
|
2001-06-11 12:39:29 +00:00
|
|
|
#include <netinet6/ipcomp.h>
|
1999-12-22 19:13:38 +00:00
|
|
|
#endif /* IPSEC */
|
|
|
|
|
2002-11-08 23:37:50 +00:00
|
|
|
#ifdef FAST_IPSEC
|
2002-10-16 02:25:05 +00:00
|
|
|
#include <netipsec/ipsec.h>
|
|
|
|
#endif /* FAST_IPSEC */
|
|
|
|
|
1995-10-26 20:31:59 +00:00
|
|
|
#ifdef IPXIP
|
1995-12-02 19:38:06 +00:00
|
|
|
#include <netipx/ipx_ip.h>
|
1995-10-26 20:31:59 +00:00
|
|
|
#endif
|
|
|
|
|
2004-06-16 23:24:02 +00:00
|
|
|
#ifdef DEV_PFSYNC
|
|
|
|
#include <net/pfvar.h>
|
|
|
|
#include <net/if_pfsync.h>
|
|
|
|
#endif
|
|
|
|
|
1994-09-15 10:36:56 +00:00
|
|
|
extern struct domain inetdomain;
|
2004-10-19 15:58:22 +00:00
|
|
|
|
|
|
|
/* Spacer for loadable protocols. */
|
|
|
|
#define IPPROTOSPACER \
|
|
|
|
{ 0, &inetdomain, PROTO_SPACER, 0, \
|
|
|
|
NULL, NULL, NULL, NULL, \
|
|
|
|
NULL, \
|
|
|
|
NULL, NULL, NULL, NULL, \
|
|
|
|
&nousrreqs \
|
|
|
|
}
|
1994-09-06 22:42:31 +00:00
|
|
|
|
2001-09-03 20:03:55 +00:00
|
|
|
struct protosw inetsw[] = {
|
1994-09-15 10:36:56 +00:00
|
|
|
{ 0, &inetdomain, 0, 0,
|
1996-04-18 15:41:51 +00:00
|
|
|
0, 0, 0, 0,
|
1994-09-15 10:36:56 +00:00
|
|
|
0,
|
1997-04-27 20:01:29 +00:00
|
|
|
ip_init, 0, ip_slowtimo, ip_drain,
|
|
|
|
&nousrreqs
|
1994-09-15 10:36:56 +00:00
|
|
|
},
|
|
|
|
{ SOCK_DGRAM, &inetdomain, IPPROTO_UDP, PR_ATOMIC|PR_ADDR,
|
|
|
|
udp_input, 0, udp_ctlinput, ip_ctloutput,
|
1997-02-14 18:15:53 +00:00
|
|
|
0,
|
|
|
|
udp_init, 0, 0, 0,
|
|
|
|
&udp_usrreqs
|
1994-09-15 10:36:56 +00:00
|
|
|
},
|
1995-02-08 20:22:09 +00:00
|
|
|
{ SOCK_STREAM, &inetdomain, IPPROTO_TCP,
|
|
|
|
PR_CONNREQUIRED|PR_IMPLOPCL|PR_WANTRCVD,
|
1994-09-15 10:36:56 +00:00
|
|
|
tcp_input, 0, tcp_ctlinput, tcp_ctloutput,
|
1996-07-11 16:32:50 +00:00
|
|
|
0,
|
1999-08-30 21:17:07 +00:00
|
|
|
tcp_init, 0, tcp_slowtimo, tcp_drain,
|
1996-07-11 16:32:50 +00:00
|
|
|
&tcp_usrreqs
|
1994-09-15 10:36:56 +00:00
|
|
|
},
|
|
|
|
{ SOCK_RAW, &inetdomain, IPPROTO_RAW, PR_ATOMIC|PR_ADDR,
|
1997-02-13 19:46:45 +00:00
|
|
|
rip_input, 0, rip_ctlinput, rip_ctloutput,
|
1997-02-18 20:46:36 +00:00
|
|
|
0,
|
1994-09-15 10:36:56 +00:00
|
|
|
0, 0, 0, 0,
|
1997-02-18 20:46:36 +00:00
|
|
|
&rip_usrreqs
|
1994-09-15 10:36:56 +00:00
|
|
|
},
|
2001-06-11 12:39:29 +00:00
|
|
|
{ SOCK_RAW, &inetdomain, IPPROTO_ICMP, PR_ATOMIC|PR_ADDR|PR_LASTHDR,
|
1996-05-08 04:34:03 +00:00
|
|
|
icmp_input, 0, 0, rip_ctloutput,
|
1997-02-18 20:46:36 +00:00
|
|
|
0,
|
|
|
|
0, 0, 0, 0,
|
|
|
|
&rip_usrreqs
|
1994-09-15 10:36:56 +00:00
|
|
|
},
|
2001-06-11 12:39:29 +00:00
|
|
|
{ SOCK_RAW, &inetdomain, IPPROTO_IGMP, PR_ATOMIC|PR_ADDR|PR_LASTHDR,
|
1996-05-08 04:34:03 +00:00
|
|
|
igmp_input, 0, 0, rip_ctloutput,
|
1997-02-18 20:46:36 +00:00
|
|
|
0,
|
|
|
|
igmp_init, igmp_fasttimo, igmp_slowtimo, 0,
|
|
|
|
&rip_usrreqs
|
1994-09-15 10:36:56 +00:00
|
|
|
},
|
2001-06-11 12:39:29 +00:00
|
|
|
{ SOCK_RAW, &inetdomain, IPPROTO_RSVP, PR_ATOMIC|PR_ADDR|PR_LASTHDR,
|
1996-05-08 04:34:03 +00:00
|
|
|
rsvp_input, 0, 0, rip_ctloutput,
|
1997-02-18 20:46:36 +00:00
|
|
|
0,
|
1994-09-15 10:36:56 +00:00
|
|
|
0, 0, 0, 0,
|
1997-02-18 20:46:36 +00:00
|
|
|
&rip_usrreqs
|
1994-09-15 10:36:56 +00:00
|
|
|
},
|
1999-12-22 19:13:38 +00:00
|
|
|
#ifdef IPSEC
|
|
|
|
{ SOCK_RAW, &inetdomain, IPPROTO_AH, PR_ATOMIC|PR_ADDR,
|
2004-08-16 18:32:07 +00:00
|
|
|
ah4_input, 0, 0, 0,
|
|
|
|
0,
|
1999-12-22 19:13:38 +00:00
|
|
|
0, 0, 0, 0,
|
|
|
|
&nousrreqs
|
|
|
|
},
|
|
|
|
#ifdef IPSEC_ESP
|
|
|
|
{ SOCK_RAW, &inetdomain, IPPROTO_ESP, PR_ATOMIC|PR_ADDR,
|
2004-08-16 18:32:07 +00:00
|
|
|
esp4_input, 0, 0, 0,
|
|
|
|
0,
|
1999-12-22 19:13:38 +00:00
|
|
|
0, 0, 0, 0,
|
|
|
|
&nousrreqs
|
|
|
|
},
|
|
|
|
#endif
|
2001-06-11 12:39:29 +00:00
|
|
|
{ SOCK_RAW, &inetdomain, IPPROTO_IPCOMP, PR_ATOMIC|PR_ADDR,
|
2004-08-16 18:32:07 +00:00
|
|
|
ipcomp4_input, 0, 0, 0,
|
|
|
|
0,
|
2001-06-11 12:39:29 +00:00
|
|
|
0, 0, 0, 0,
|
|
|
|
&nousrreqs
|
|
|
|
},
|
1999-12-22 19:13:38 +00:00
|
|
|
#endif /* IPSEC */
|
2002-11-08 23:37:50 +00:00
|
|
|
#ifdef FAST_IPSEC
|
|
|
|
{ SOCK_RAW, &inetdomain, IPPROTO_AH, PR_ATOMIC|PR_ADDR,
|
2004-08-16 18:32:07 +00:00
|
|
|
ah4_input, 0, ah4_ctlinput, 0,
|
|
|
|
0,
|
2002-11-08 23:37:50 +00:00
|
|
|
0, 0, 0, 0,
|
|
|
|
&nousrreqs
|
|
|
|
},
|
|
|
|
{ SOCK_RAW, &inetdomain, IPPROTO_ESP, PR_ATOMIC|PR_ADDR,
|
2004-08-16 18:32:07 +00:00
|
|
|
esp4_input, 0, esp4_ctlinput, 0,
|
|
|
|
0,
|
2002-11-08 23:37:50 +00:00
|
|
|
0, 0, 0, 0,
|
|
|
|
&nousrreqs
|
|
|
|
},
|
|
|
|
{ SOCK_RAW, &inetdomain, IPPROTO_IPCOMP, PR_ATOMIC|PR_ADDR,
|
2004-08-16 18:32:07 +00:00
|
|
|
ipcomp4_input, 0, 0, 0,
|
|
|
|
0,
|
2002-11-08 23:37:50 +00:00
|
|
|
0, 0, 0, 0,
|
|
|
|
&nousrreqs
|
|
|
|
},
|
|
|
|
#endif /* FAST_IPSEC */
|
2001-06-11 12:39:29 +00:00
|
|
|
{ SOCK_RAW, &inetdomain, IPPROTO_IPV4, PR_ATOMIC|PR_ADDR|PR_LASTHDR,
|
2004-08-16 18:32:07 +00:00
|
|
|
encap4_input, 0, 0, rip_ctloutput,
|
1999-12-07 17:39:16 +00:00
|
|
|
0,
|
2000-07-04 16:35:15 +00:00
|
|
|
encap_init, 0, 0, 0,
|
2001-06-11 12:39:29 +00:00
|
|
|
&rip_usrreqs
|
1999-12-07 17:39:16 +00:00
|
|
|
},
|
2002-09-06 17:12:50 +00:00
|
|
|
{ SOCK_RAW, &inetdomain, IPPROTO_MOBILE, PR_ATOMIC|PR_ADDR|PR_LASTHDR,
|
|
|
|
encap4_input, 0, 0, rip_ctloutput,
|
|
|
|
0,
|
|
|
|
encap_init, 0, 0, 0,
|
|
|
|
&rip_usrreqs
|
|
|
|
},
|
|
|
|
{ SOCK_RAW, &inetdomain, IPPROTO_GRE, PR_ATOMIC|PR_ADDR|PR_LASTHDR,
|
|
|
|
encap4_input, 0, 0, rip_ctloutput,
|
|
|
|
0,
|
|
|
|
encap_init, 0, 0, 0,
|
|
|
|
&rip_usrreqs
|
|
|
|
},
|
1999-12-07 17:39:16 +00:00
|
|
|
# ifdef INET6
|
2001-06-11 12:39:29 +00:00
|
|
|
{ SOCK_RAW, &inetdomain, IPPROTO_IPV6, PR_ATOMIC|PR_ADDR|PR_LASTHDR,
|
2004-08-16 18:32:07 +00:00
|
|
|
encap4_input, 0, 0, rip_ctloutput,
|
1999-12-07 17:39:16 +00:00
|
|
|
0,
|
2001-06-11 12:39:29 +00:00
|
|
|
encap_init, 0, 0, 0,
|
|
|
|
&rip_usrreqs
|
1999-12-07 17:39:16 +00:00
|
|
|
},
|
|
|
|
#endif
|
1995-10-26 20:31:59 +00:00
|
|
|
#ifdef IPXIP
|
2001-06-11 12:39:29 +00:00
|
|
|
{ SOCK_RAW, &inetdomain, IPPROTO_IDP, PR_ATOMIC|PR_ADDR|PR_LASTHDR,
|
1996-05-08 04:34:03 +00:00
|
|
|
ipxip_input, 0, ipxip_ctlinput, 0,
|
1997-02-18 20:46:36 +00:00
|
|
|
0,
|
1995-10-26 20:31:59 +00:00
|
|
|
0, 0, 0, 0,
|
1997-02-18 20:46:36 +00:00
|
|
|
&rip_usrreqs
|
1995-10-26 20:31:59 +00:00
|
|
|
},
|
1994-05-24 10:09:53 +00:00
|
|
|
#endif
|
2003-08-07 18:16:59 +00:00
|
|
|
#ifdef PIM
|
|
|
|
{ SOCK_RAW, &inetdomain, IPPROTO_PIM, PR_ATOMIC|PR_ADDR|PR_LASTHDR,
|
|
|
|
pim_input, 0, 0, rip_ctloutput,
|
|
|
|
0,
|
|
|
|
0, 0, 0, 0,
|
|
|
|
&rip_usrreqs
|
|
|
|
},
|
|
|
|
#endif /* PIM */
|
2004-06-16 23:24:02 +00:00
|
|
|
#ifdef DEV_PFSYNC
|
|
|
|
{ SOCK_RAW, &inetdomain, IPPROTO_PFSYNC, PR_ATOMIC|PR_ADDR,
|
|
|
|
pfsync_input, 0, 0, rip_ctloutput,
|
|
|
|
0,
|
|
|
|
0, 0, 0, 0,
|
|
|
|
&rip_usrreqs
|
|
|
|
},
|
|
|
|
#endif /* DEV_PFSYNC */
|
2004-10-19 15:58:22 +00:00
|
|
|
/* Spacer n-times for loadable protocols. */
|
|
|
|
IPPROTOSPACER,
|
|
|
|
IPPROTOSPACER,
|
|
|
|
IPPROTOSPACER,
|
|
|
|
IPPROTOSPACER,
|
|
|
|
IPPROTOSPACER,
|
|
|
|
IPPROTOSPACER,
|
|
|
|
IPPROTOSPACER,
|
|
|
|
IPPROTOSPACER,
|
|
|
|
/* raw wildcard */
|
1994-05-24 10:09:53 +00:00
|
|
|
{ SOCK_RAW, &inetdomain, 0, PR_ATOMIC|PR_ADDR,
|
1996-05-08 04:34:03 +00:00
|
|
|
rip_input, 0, 0, rip_ctloutput,
|
1997-02-18 20:46:36 +00:00
|
|
|
0,
|
1994-05-24 10:09:53 +00:00
|
|
|
rip_init, 0, 0, 0,
|
1997-02-18 20:46:36 +00:00
|
|
|
&rip_usrreqs
|
1994-05-24 10:09:53 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2002-03-19 21:25:46 +00:00
|
|
|
extern int in_inithead(void **, int);
|
1994-11-02 04:41:39 +00:00
|
|
|
|
1994-05-24 10:09:53 +00:00
|
|
|
struct domain inetdomain =
|
2004-08-16 18:32:07 +00:00
|
|
|
{ AF_INET, "internet", 0, 0, 0,
|
2001-09-03 20:03:55 +00:00
|
|
|
inetsw,
|
|
|
|
&inetsw[sizeof(inetsw)/sizeof(inetsw[0])], 0,
|
1994-11-02 04:41:39 +00:00
|
|
|
in_inithead, 32, sizeof(struct sockaddr_in)
|
|
|
|
};
|
1994-05-24 10:09:53 +00:00
|
|
|
|
1995-05-11 00:13:26 +00:00
|
|
|
DOMAIN_SET(inet);
|
|
|
|
|
1995-12-20 21:53:53 +00:00
|
|
|
SYSCTL_NODE(_net, PF_INET, inet, CTLFLAG_RW, 0,
|
|
|
|
"Internet Family");
|
1995-11-09 20:23:09 +00:00
|
|
|
|
1995-12-20 21:53:53 +00:00
|
|
|
SYSCTL_NODE(_net_inet, IPPROTO_IP, ip, CTLFLAG_RW, 0, "IP");
|
|
|
|
SYSCTL_NODE(_net_inet, IPPROTO_ICMP, icmp, CTLFLAG_RW, 0, "ICMP");
|
|
|
|
SYSCTL_NODE(_net_inet, IPPROTO_UDP, udp, CTLFLAG_RW, 0, "UDP");
|
|
|
|
SYSCTL_NODE(_net_inet, IPPROTO_TCP, tcp, CTLFLAG_RW, 0, "TCP");
|
|
|
|
SYSCTL_NODE(_net_inet, IPPROTO_IGMP, igmp, CTLFLAG_RW, 0, "IGMP");
|
2002-10-16 02:25:05 +00:00
|
|
|
#ifdef FAST_IPSEC
|
|
|
|
/* XXX no protocol # to use, pick something "reserved" */
|
|
|
|
SYSCTL_NODE(_net_inet, 253, ipsec, CTLFLAG_RW, 0, "IPSEC");
|
|
|
|
SYSCTL_NODE(_net_inet, IPPROTO_AH, ah, CTLFLAG_RW, 0, "AH");
|
|
|
|
SYSCTL_NODE(_net_inet, IPPROTO_ESP, esp, CTLFLAG_RW, 0, "ESP");
|
|
|
|
SYSCTL_NODE(_net_inet, IPPROTO_IPCOMP, ipcomp, CTLFLAG_RW, 0, "IPCOMP");
|
|
|
|
SYSCTL_NODE(_net_inet, IPPROTO_IPIP, ipip, CTLFLAG_RW, 0, "IPIP");
|
|
|
|
#else
|
1999-12-22 19:13:38 +00:00
|
|
|
#ifdef IPSEC
|
|
|
|
SYSCTL_NODE(_net_inet, IPPROTO_AH, ipsec, CTLFLAG_RW, 0, "IPSEC");
|
|
|
|
#endif /* IPSEC */
|
2002-10-16 02:25:05 +00:00
|
|
|
#endif /* !FAST_IPSEC */
|
1997-02-18 20:46:36 +00:00
|
|
|
SYSCTL_NODE(_net_inet, IPPROTO_RAW, raw, CTLFLAG_RW, 0, "RAW");
|
2003-08-07 18:16:59 +00:00
|
|
|
#ifdef PIM
|
|
|
|
SYSCTL_NODE(_net_inet, IPPROTO_PIM, pim, CTLFLAG_RW, 0, "PIM");
|
|
|
|
#endif
|