in_proto.c revision 25201
11849Swollman/*
21849Swollman * Copyright (c) 1982, 1986, 1993
31849Swollman *	The Regents of the University of California.  All rights reserved.
41849Swollman *
51849Swollman * Redistribution and use in source and binary forms, with or without
61849Swollman * modification, are permitted provided that the following conditions
71849Swollman * are met:
81849Swollman * 1. Redistributions of source code must retain the above copyright
91849Swollman *    notice, this list of conditions and the following disclaimer.
101849Swollman * 2. Redistributions in binary form must reproduce the above copyright
111849Swollman *    notice, this list of conditions and the following disclaimer in the
121849Swollman *    documentation and/or other materials provided with the distribution.
131849Swollman * 3. All advertising materials mentioning features or use of this software
141849Swollman *    must display the following acknowledgement:
151849Swollman *	This product includes software developed by the University of
161849Swollman *	California, Berkeley and its contributors.
171849Swollman * 4. Neither the name of the University nor the names of its contributors
181849Swollman *    may be used to endorse or promote products derived from this software
191849Swollman *    without specific prior written permission.
201849Swollman *
211849Swollman * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
221849Swollman * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
231849Swollman * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
241849Swollman * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
251849Swollman * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
261849Swollman * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
271849Swollman * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
281849Swollman * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
291849Swollman * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
301849Swollman * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
311849Swollman * SUCH DAMAGE.
325790Sdg *
3350476Speter *	@(#)in_proto.c	8.2 (Berkeley) 2/9/95
341849Swollman *	$Id: in_proto.c,v 1.38 1997/02/18 20:46:22 wollman Exp $
351849Swollman */
3685437Speter
371849Swollman#include <sys/param.h>
381849Swollman#include <sys/queue.h>
391849Swollman#include <sys/kernel.h>
401849Swollman#include <sys/socket.h>
411849Swollman#include <sys/socketvar.h>
421849Swollman#include <sys/domain.h>
431849Swollman#include <sys/mbuf.h>
441849Swollman#include <sys/protosw.h>
451849Swollman#include <sys/sysctl.h>
461849Swollman
471849Swollman#include <net/if.h>
481849Swollman#include <net/radix.h>
491849Swollman#include <net/route.h>
501849Swollman
511849Swollman#include <netinet/in.h>
521849Swollman#include <netinet/in_systm.h>
531849Swollman#include <netinet/ip.h>
541849Swollman#include <netinet/ip_var.h>
551849Swollman#include <netinet/ip_icmp.h>
561849Swollman#include <netinet/in_pcb.h>
571849Swollman#include <netinet/igmp_var.h>
581849Swollman#include <netinet/tcp.h>
591849Swollman#include <netinet/tcp_fsm.h>
601849Swollman#include <netinet/tcp_seq.h>
611849Swollman#include <netinet/tcp_timer.h>
621849Swollman#include <netinet/tcp_var.h>
631849Swollman#include <netinet/tcpip.h>
641849Swollman#ifdef TCPDEBUG
651849Swollman#include <netinet/tcp_debug.h>
661849Swollman#endif
671849Swollman#include <netinet/udp.h>
681849Swollman#include <netinet/udp_var.h>
69/*
70 * TCP/IP protocol family: IP, ICMP, UDP, TCP.
71 */
72
73#ifdef IPXIP
74#include <netipx/ipx.h>
75#include <netipx/ipx_ip.h>
76#endif
77
78#ifdef NSIP
79#include <netns/ns.h>
80#include <netns/ns_if.h>
81#endif
82
83#ifdef TPIP
84void	tpip_input(), tpip_ctlinput(), tp_init(), tp_slowtimo(), tp_drain();
85int	tp_ctloutput(), tp_usrreq();
86#endif
87
88#ifdef EON
89void	eoninput(), eonctlinput(), eonprotoinit();
90#endif /* EON */
91
92#ifdef        IPFILTER
93void	iplinit();
94#define	ip_init	iplinit
95#endif
96
97
98extern	struct domain inetdomain;
99static	struct pr_usrreqs nousrreqs;
100
101struct protosw inetsw[] = {
102{ 0,		&inetdomain,	0,		0,
103  0,		0,		0,		0,
104  0,
105  ip_init,	0,		ip_slowtimo,	ip_drain,
106  &nousrreqs
107},
108{ SOCK_DGRAM,	&inetdomain,	IPPROTO_UDP,	PR_ATOMIC|PR_ADDR,
109  udp_input,	0,		udp_ctlinput,	ip_ctloutput,
110  0,
111  udp_init,	0,		0,		0,
112  &udp_usrreqs
113},
114{ SOCK_STREAM,	&inetdomain,	IPPROTO_TCP,
115	PR_CONNREQUIRED|PR_IMPLOPCL|PR_WANTRCVD,
116  tcp_input,	0,		tcp_ctlinput,	tcp_ctloutput,
117  0,
118  tcp_init,	tcp_fasttimo,	tcp_slowtimo,	tcp_drain,
119  &tcp_usrreqs
120},
121{ SOCK_RAW,	&inetdomain,	IPPROTO_RAW,	PR_ATOMIC|PR_ADDR,
122  rip_input,	0,		rip_ctlinput,	rip_ctloutput,
123  0,
124  0,		0,		0,		0,
125  &rip_usrreqs
126},
127{ SOCK_RAW,	&inetdomain,	IPPROTO_ICMP,	PR_ATOMIC|PR_ADDR,
128  icmp_input,	0,		0,		rip_ctloutput,
129  0,
130  0,		0,		0,		0,
131  &rip_usrreqs
132},
133{ SOCK_RAW,	&inetdomain,	IPPROTO_IGMP,	PR_ATOMIC|PR_ADDR,
134  igmp_input,	0,		0,		rip_ctloutput,
135  0,
136  igmp_init,	igmp_fasttimo,	igmp_slowtimo,	0,
137  &rip_usrreqs
138},
139{ SOCK_RAW,	&inetdomain,	IPPROTO_RSVP,	PR_ATOMIC|PR_ADDR,
140  rsvp_input,	0,		0,		rip_ctloutput,
141  0,
142  0,		0,		0,		0,
143  &rip_usrreqs
144},
145{ SOCK_RAW,	&inetdomain,	IPPROTO_IPIP,	PR_ATOMIC|PR_ADDR,
146  ipip_input,	0,	 	0,		rip_ctloutput,
147  0,
148  0,		0,		0,		0,
149  &rip_usrreqs
150},
151#ifdef IPDIVERT
152{ SOCK_RAW,	&inetdomain,	IPPROTO_DIVERT,	PR_ATOMIC|PR_ADDR,
153  div_input,	0,	 	0,		ip_ctloutput,
154  div_usrreq,
155  div_init,	0,		0,		0,
156},
157#endif
158#ifdef TPIP
159{ SOCK_SEQPACKET,&inetdomain,	IPPROTO_TP,	PR_CONNREQUIRED|PR_WANTRCVD,
160  tpip_input,	0,		tpip_ctlinput,	tp_ctloutput,
161  tp_usrreq,
162  tp_init,	0,		tp_slowtimo,	tp_drain,
163},
164#endif
165/* EON (ISO CLNL over IP) */
166#ifdef EON
167{ SOCK_RAW,	&inetdomain,	IPPROTO_EON,	0,
168  eoninput,	0,		eonctlinput,		0,
169  0,
170  eonprotoinit,	0,		0,		0,
171},
172#endif
173#ifdef IPXIP
174{ SOCK_RAW,	&inetdomain,	IPPROTO_IDP,	PR_ATOMIC|PR_ADDR,
175  ipxip_input,	0,		ipxip_ctlinput,	0,
176  0,
177  0,		0,		0,		0,
178  &rip_usrreqs
179},
180#endif
181#ifdef NSIP
182{ SOCK_RAW,	&inetdomain,	IPPROTO_IDP,	PR_ATOMIC|PR_ADDR,
183  idpip_input,	0,		nsip_ctlinput,	0,
184  0,
185  0,		0,		0,		0,
186  &rip_usrreqs
187},
188#endif
189	/* raw wildcard */
190{ SOCK_RAW,	&inetdomain,	0,		PR_ATOMIC|PR_ADDR,
191  rip_input,	0,		0,		rip_ctloutput,
192  0,
193  rip_init,	0,		0,		0,
194  &rip_usrreqs
195},
196};
197
198extern int in_inithead(void **, int);
199
200struct domain inetdomain =
201    { AF_INET, "internet", 0, 0, 0,
202      inetsw, &inetsw[sizeof(inetsw)/sizeof(inetsw[0])], 0,
203      in_inithead, 32, sizeof(struct sockaddr_in)
204    };
205
206DOMAIN_SET(inet);
207
208SYSCTL_NODE(_net,      PF_INET,		inet,	CTLFLAG_RW, 0,
209	"Internet Family");
210
211SYSCTL_NODE(_net_inet, IPPROTO_IP,	ip,	CTLFLAG_RW, 0,	"IP");
212SYSCTL_NODE(_net_inet, IPPROTO_ICMP,	icmp,	CTLFLAG_RW, 0,	"ICMP");
213SYSCTL_NODE(_net_inet, IPPROTO_UDP,	udp,	CTLFLAG_RW, 0,	"UDP");
214SYSCTL_NODE(_net_inet, IPPROTO_TCP,	tcp,	CTLFLAG_RW, 0,	"TCP");
215SYSCTL_NODE(_net_inet, IPPROTO_IGMP,	igmp,	CTLFLAG_RW, 0,	"IGMP");
216SYSCTL_NODE(_net_inet, IPPROTO_RAW,	raw,	CTLFLAG_RW, 0,	"RAW");
217#ifdef IPDIVERT
218SYSCTL_NODE(_net_inet, IPPROTO_DIVERT,	div,	CTLFLAG_RW, 0,	"DIVERT");
219#endif
220
221