xref: /freebsd/sys/netinet/in_proto.c (revision fbd1372a0bacc9ed390cd76c61a59f9a8b7b02ef)
1df8bae1dSRodney W. Grimes /*
2df8bae1dSRodney W. Grimes  * Copyright (c) 1982, 1986, 1993
3df8bae1dSRodney W. Grimes  *	The Regents of the University of California.  All rights reserved.
4df8bae1dSRodney W. Grimes  *
5df8bae1dSRodney W. Grimes  * Redistribution and use in source and binary forms, with or without
6df8bae1dSRodney W. Grimes  * modification, are permitted provided that the following conditions
7df8bae1dSRodney W. Grimes  * are met:
8df8bae1dSRodney W. Grimes  * 1. Redistributions of source code must retain the above copyright
9df8bae1dSRodney W. Grimes  *    notice, this list of conditions and the following disclaimer.
10df8bae1dSRodney W. Grimes  * 2. Redistributions in binary form must reproduce the above copyright
11df8bae1dSRodney W. Grimes  *    notice, this list of conditions and the following disclaimer in the
12df8bae1dSRodney W. Grimes  *    documentation and/or other materials provided with the distribution.
13df8bae1dSRodney W. Grimes  * 3. All advertising materials mentioning features or use of this software
14df8bae1dSRodney W. Grimes  *    must display the following acknowledgement:
15df8bae1dSRodney W. Grimes  *	This product includes software developed by the University of
16df8bae1dSRodney W. Grimes  *	California, Berkeley and its contributors.
17df8bae1dSRodney W. Grimes  * 4. Neither the name of the University nor the names of its contributors
18df8bae1dSRodney W. Grimes  *    may be used to endorse or promote products derived from this software
19df8bae1dSRodney W. Grimes  *    without specific prior written permission.
20df8bae1dSRodney W. Grimes  *
21df8bae1dSRodney W. Grimes  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22df8bae1dSRodney W. Grimes  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23df8bae1dSRodney W. Grimes  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24df8bae1dSRodney W. Grimes  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25df8bae1dSRodney W. Grimes  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26df8bae1dSRodney W. Grimes  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27df8bae1dSRodney W. Grimes  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28df8bae1dSRodney W. Grimes  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29df8bae1dSRodney W. Grimes  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30df8bae1dSRodney W. Grimes  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31df8bae1dSRodney W. Grimes  * SUCH DAMAGE.
32df8bae1dSRodney W. Grimes  *
33425f123eSGarrett Wollman  *	@(#)in_proto.c	8.2 (Berkeley) 2/9/95
34fbd1372aSJoerg Wunsch  *	$Id: in_proto.c,v 1.43 1997/10/28 15:58:43 bde Exp $
35df8bae1dSRodney W. Grimes  */
36df8bae1dSRodney W. Grimes 
37fbd1372aSJoerg Wunsch #include "opt_ipdivert.h"
38fbd1372aSJoerg Wunsch 
39df8bae1dSRodney W. Grimes #include <sys/param.h>
40748e0b0aSGarrett Wollman #include <sys/kernel.h>
41df8bae1dSRodney W. Grimes #include <sys/socket.h>
42df8bae1dSRodney W. Grimes #include <sys/domain.h>
43dcc3cb75SPoul-Henning Kamp #include <sys/protosw.h>
4498163b98SPoul-Henning Kamp #include <sys/sysctl.h>
45df8bae1dSRodney W. Grimes 
46df8bae1dSRodney W. Grimes #include <net/if.h>
47df8bae1dSRodney W. Grimes #include <net/route.h>
48df8bae1dSRodney W. Grimes 
49df8bae1dSRodney W. Grimes #include <netinet/in.h>
50df8bae1dSRodney W. Grimes #include <netinet/in_systm.h>
51df8bae1dSRodney W. Grimes #include <netinet/ip.h>
52df8bae1dSRodney W. Grimes #include <netinet/ip_var.h>
53df8bae1dSRodney W. Grimes #include <netinet/ip_icmp.h>
54df8bae1dSRodney W. Grimes #include <netinet/igmp_var.h>
55df8bae1dSRodney W. Grimes #include <netinet/tcp.h>
56df8bae1dSRodney W. Grimes #include <netinet/tcp_timer.h>
57df8bae1dSRodney W. Grimes #include <netinet/tcp_var.h>
58df8bae1dSRodney W. Grimes #include <netinet/udp.h>
59df8bae1dSRodney W. Grimes #include <netinet/udp_var.h>
60df8bae1dSRodney W. Grimes /*
61df8bae1dSRodney W. Grimes  * TCP/IP protocol family: IP, ICMP, UDP, TCP.
62df8bae1dSRodney W. Grimes  */
63df8bae1dSRodney W. Grimes 
64cc6a66f2SJulian Elischer #ifdef IPXIP
65ce7609a4SBruce Evans #include <netipx/ipx_ip.h>
66cc6a66f2SJulian Elischer #endif
67cc6a66f2SJulian Elischer 
68df8bae1dSRodney W. Grimes #ifdef NSIP
69ce7609a4SBruce Evans #include <netns/ns.h>
70ce7609a4SBruce Evans #include <netns/ns_if.h>
71df8bae1dSRodney W. Grimes #endif
72df8bae1dSRodney W. Grimes 
73df8bae1dSRodney W. Grimes #ifdef TPIP
74425f123eSGarrett Wollman void	tpip_input(), tpip_ctlinput(), tp_init(), tp_slowtimo(), tp_drain();
75425f123eSGarrett Wollman int	tp_ctloutput(), tp_usrreq();
76df8bae1dSRodney W. Grimes #endif
77df8bae1dSRodney W. Grimes 
78df8bae1dSRodney W. Grimes #ifdef EON
79df8bae1dSRodney W. Grimes void	eoninput(), eonctlinput(), eonprotoinit();
80df8bae1dSRodney W. Grimes #endif /* EON */
81df8bae1dSRodney W. Grimes 
82afed1b49SDarren Reed #ifdef        IPFILTER
83afed1b49SDarren Reed void	iplinit();
84afed1b49SDarren Reed #define	ip_init	iplinit
85afed1b49SDarren Reed #endif
86afed1b49SDarren Reed 
87afed1b49SDarren Reed 
88df8bae1dSRodney W. Grimes extern	struct domain inetdomain;
89a29f300eSGarrett Wollman static	struct pr_usrreqs nousrreqs;
90df8bae1dSRodney W. Grimes 
91df8bae1dSRodney W. Grimes struct protosw inetsw[] = {
92df8bae1dSRodney W. Grimes { 0,		&inetdomain,	0,		0,
93dbe4b3f0SGarrett Wollman   0,		0,		0,		0,
94df8bae1dSRodney W. Grimes   0,
95a29f300eSGarrett Wollman   ip_init,	0,		ip_slowtimo,	ip_drain,
96a29f300eSGarrett Wollman   &nousrreqs
97df8bae1dSRodney W. Grimes },
98df8bae1dSRodney W. Grimes { SOCK_DGRAM,	&inetdomain,	IPPROTO_UDP,	PR_ATOMIC|PR_ADDR,
99df8bae1dSRodney W. Grimes   udp_input,	0,		udp_ctlinput,	ip_ctloutput,
100d0390e05SGarrett Wollman   0,
101d0390e05SGarrett Wollman   udp_init,	0,		0,		0,
102d0390e05SGarrett Wollman   &udp_usrreqs
103df8bae1dSRodney W. Grimes },
104999f1343SGarrett Wollman { SOCK_STREAM,	&inetdomain,	IPPROTO_TCP,
105999f1343SGarrett Wollman 	PR_CONNREQUIRED|PR_IMPLOPCL|PR_WANTRCVD,
106df8bae1dSRodney W. Grimes   tcp_input,	0,		tcp_ctlinput,	tcp_ctloutput,
1072c37256eSGarrett Wollman   0,
1082c37256eSGarrett Wollman   tcp_init,	tcp_fasttimo,	tcp_slowtimo,	tcp_drain,
1092c37256eSGarrett Wollman   &tcp_usrreqs
110df8bae1dSRodney W. Grimes },
111df8bae1dSRodney W. Grimes { SOCK_RAW,	&inetdomain,	IPPROTO_RAW,	PR_ATOMIC|PR_ADDR,
11239191c8eSGarrett Wollman   rip_input,	0,		rip_ctlinput,	rip_ctloutput,
113117bcae7SGarrett Wollman   0,
114df8bae1dSRodney W. Grimes   0,		0,		0,		0,
115117bcae7SGarrett Wollman   &rip_usrreqs
116df8bae1dSRodney W. Grimes },
117df8bae1dSRodney W. Grimes { SOCK_RAW,	&inetdomain,	IPPROTO_ICMP,	PR_ATOMIC|PR_ADDR,
118b1e8a2c5SGary Palmer   icmp_input,	0,		0,		rip_ctloutput,
119117bcae7SGarrett Wollman   0,
120117bcae7SGarrett Wollman   0,		0,		0,		0,
121117bcae7SGarrett Wollman   &rip_usrreqs
122df8bae1dSRodney W. Grimes },
123df8bae1dSRodney W. Grimes { SOCK_RAW,	&inetdomain,	IPPROTO_IGMP,	PR_ATOMIC|PR_ADDR,
124b1e8a2c5SGary Palmer   igmp_input,	0,		0,		rip_ctloutput,
125117bcae7SGarrett Wollman   0,
126117bcae7SGarrett Wollman   igmp_init,	igmp_fasttimo,	igmp_slowtimo,	0,
127117bcae7SGarrett Wollman   &rip_usrreqs
128df8bae1dSRodney W. Grimes },
129f0068c4aSGarrett Wollman { SOCK_RAW,	&inetdomain,	IPPROTO_RSVP,	PR_ATOMIC|PR_ADDR,
130b1e8a2c5SGary Palmer   rsvp_input,	0,		0,		rip_ctloutput,
131117bcae7SGarrett Wollman   0,
132f0068c4aSGarrett Wollman   0,		0,		0,		0,
133117bcae7SGarrett Wollman   &rip_usrreqs
134f0068c4aSGarrett Wollman },
135fba14c2eSGarrett Wollman { SOCK_RAW,	&inetdomain,	IPPROTO_IPIP,	PR_ATOMIC|PR_ADDR,
136b1e8a2c5SGary Palmer   ipip_input,	0,	 	0,		rip_ctloutput,
137117bcae7SGarrett Wollman   0,
138f0068c4aSGarrett Wollman   0,		0,		0,		0,
139117bcae7SGarrett Wollman   &rip_usrreqs
140f0068c4aSGarrett Wollman },
14193e0e116SJulian Elischer #ifdef IPDIVERT
14293e0e116SJulian Elischer { SOCK_RAW,	&inetdomain,	IPPROTO_DIVERT,	PR_ATOMIC|PR_ADDR,
14393e0e116SJulian Elischer   div_input,	0,	 	0,		ip_ctloutput,
14477d1915bSPeter Wemm   0,
14593e0e116SJulian Elischer   div_init,	0,		0,		0,
14677d1915bSPeter Wemm   &div_usrreqs,
14793e0e116SJulian Elischer },
14893e0e116SJulian Elischer #endif
149df8bae1dSRodney W. Grimes #ifdef TPIP
150df8bae1dSRodney W. Grimes { SOCK_SEQPACKET,&inetdomain,	IPPROTO_TP,	PR_CONNREQUIRED|PR_WANTRCVD,
151df8bae1dSRodney W. Grimes   tpip_input,	0,		tpip_ctlinput,	tp_ctloutput,
152df8bae1dSRodney W. Grimes   tp_usrreq,
153df8bae1dSRodney W. Grimes   tp_init,	0,		tp_slowtimo,	tp_drain,
154df8bae1dSRodney W. Grimes },
155df8bae1dSRodney W. Grimes #endif
156df8bae1dSRodney W. Grimes /* EON (ISO CLNL over IP) */
157df8bae1dSRodney W. Grimes #ifdef EON
158df8bae1dSRodney W. Grimes { SOCK_RAW,	&inetdomain,	IPPROTO_EON,	0,
159df8bae1dSRodney W. Grimes   eoninput,	0,		eonctlinput,		0,
160df8bae1dSRodney W. Grimes   0,
161df8bae1dSRodney W. Grimes   eonprotoinit,	0,		0,		0,
162df8bae1dSRodney W. Grimes },
163df8bae1dSRodney W. Grimes #endif
164cc6a66f2SJulian Elischer #ifdef IPXIP
165cc6a66f2SJulian Elischer { SOCK_RAW,	&inetdomain,	IPPROTO_IDP,	PR_ATOMIC|PR_ADDR,
166b1e8a2c5SGary Palmer   ipxip_input,	0,		ipxip_ctlinput,	0,
167117bcae7SGarrett Wollman   0,
168cc6a66f2SJulian Elischer   0,		0,		0,		0,
169117bcae7SGarrett Wollman   &rip_usrreqs
170cc6a66f2SJulian Elischer },
171cc6a66f2SJulian Elischer #endif
172df8bae1dSRodney W. Grimes #ifdef NSIP
173df8bae1dSRodney W. Grimes { SOCK_RAW,	&inetdomain,	IPPROTO_IDP,	PR_ATOMIC|PR_ADDR,
174d7e74838SBill Fenner   idpip_input,	0,		nsip_ctlinput,	0,
175117bcae7SGarrett Wollman   0,
176df8bae1dSRodney W. Grimes   0,		0,		0,		0,
177117bcae7SGarrett Wollman   &rip_usrreqs
178df8bae1dSRodney W. Grimes },
179df8bae1dSRodney W. Grimes #endif
180df8bae1dSRodney W. Grimes 	/* raw wildcard */
181df8bae1dSRodney W. Grimes { SOCK_RAW,	&inetdomain,	0,		PR_ATOMIC|PR_ADDR,
182b1e8a2c5SGary Palmer   rip_input,	0,		0,		rip_ctloutput,
183117bcae7SGarrett Wollman   0,
184df8bae1dSRodney W. Grimes   rip_init,	0,		0,		0,
185117bcae7SGarrett Wollman   &rip_usrreqs
186df8bae1dSRodney W. Grimes },
187df8bae1dSRodney W. Grimes };
188df8bae1dSRodney W. Grimes 
189514ede09SBruce Evans extern int in_inithead __P((void **, int));
1905c2dae8eSGarrett Wollman 
191df8bae1dSRodney W. Grimes struct domain inetdomain =
192df8bae1dSRodney W. Grimes     { AF_INET, "internet", 0, 0, 0,
193df8bae1dSRodney W. Grimes       inetsw, &inetsw[sizeof(inetsw)/sizeof(inetsw[0])], 0,
1945c2dae8eSGarrett Wollman       in_inithead, 32, sizeof(struct sockaddr_in)
1955c2dae8eSGarrett Wollman     };
196df8bae1dSRodney W. Grimes 
197748e0b0aSGarrett Wollman DOMAIN_SET(inet);
198748e0b0aSGarrett Wollman 
199602d513cSGarrett Wollman SYSCTL_NODE(_net,      PF_INET,		inet,	CTLFLAG_RW, 0,
200602d513cSGarrett Wollman 	"Internet Family");
20198163b98SPoul-Henning Kamp 
20298163b98SPoul-Henning Kamp SYSCTL_NODE(_net_inet, IPPROTO_IP,	ip,	CTLFLAG_RW, 0,	"IP");
20398163b98SPoul-Henning Kamp SYSCTL_NODE(_net_inet, IPPROTO_ICMP,	icmp,	CTLFLAG_RW, 0,	"ICMP");
20498163b98SPoul-Henning Kamp SYSCTL_NODE(_net_inet, IPPROTO_UDP,	udp,	CTLFLAG_RW, 0,	"UDP");
20598163b98SPoul-Henning Kamp SYSCTL_NODE(_net_inet, IPPROTO_TCP,	tcp,	CTLFLAG_RW, 0,	"TCP");
20698163b98SPoul-Henning Kamp SYSCTL_NODE(_net_inet, IPPROTO_IGMP,	igmp,	CTLFLAG_RW, 0,	"IGMP");
207117bcae7SGarrett Wollman SYSCTL_NODE(_net_inet, IPPROTO_RAW,	raw,	CTLFLAG_RW, 0,	"RAW");
20893e0e116SJulian Elischer #ifdef IPDIVERT
20993e0e116SJulian Elischer SYSCTL_NODE(_net_inet, IPPROTO_DIVERT,	div,	CTLFLAG_RW, 0,	"DIVERT");
21093e0e116SJulian Elischer #endif
21198163b98SPoul-Henning Kamp 
212