]> git.saurik.com Git - apple/xnu.git/blob - bsd/netinet/in_proto.c
xnu-344.21.73.tar.gz
[apple/xnu.git] / bsd / netinet / in_proto.c
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25 /*
26 * Copyright (c) 1982, 1986, 1993
27 * The Regents of the University of California. All rights reserved.
28 *
29 * Redistribution and use in source and binary forms, with or without
30 * modification, are permitted provided that the following conditions
31 * are met:
32 * 1. Redistributions of source code must retain the above copyright
33 * notice, this list of conditions and the following disclaimer.
34 * 2. Redistributions in binary form must reproduce the above copyright
35 * notice, this list of conditions and the following disclaimer in the
36 * documentation and/or other materials provided with the distribution.
37 * 3. All advertising materials mentioning features or use of this software
38 * must display the following acknowledgement:
39 * This product includes software developed by the University of
40 * California, Berkeley and its contributors.
41 * 4. Neither the name of the University nor the names of its contributors
42 * may be used to endorse or promote products derived from this software
43 * without specific prior written permission.
44 *
45 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
46 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
47 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
48 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
49 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
50 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
51 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
52 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
53 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
54 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
55 * SUCH DAMAGE.
56 *
57 * @(#)in_proto.c 8.2 (Berkeley) 2/9/95
58 */
59
60 #include <sys/param.h>
61 #include <sys/kernel.h>
62 #include <sys/socket.h>
63 #include <sys/domain.h>
64 #include <sys/protosw.h>
65 #include <sys/queue.h>
66 #include <sys/sysctl.h>
67
68 #include <net/if.h>
69 #include <net/route.h>
70
71 #include <netinet/in.h>
72 #include <netinet/in_systm.h>
73 #include <netinet/ip.h>
74 #include <netinet/ip_var.h>
75 #include <netinet/ip_icmp.h>
76 #include <netinet/igmp_var.h>
77 #include <netinet/tcp.h>
78 #include <netinet/tcp_timer.h>
79 #include <netinet/tcp_var.h>
80 #include <netinet/tcpip.h>
81 #include <netinet/udp.h>
82 #include <netinet/udp_var.h>
83 #include <netinet/ip_encap.h>
84
85
86 /*
87 * TCP/IP protocol family: IP, ICMP, UDP, TCP.
88 */
89
90 #if IPSEC
91 #include <netinet6/ipsec.h>
92 #include <netinet6/ah.h>
93 #if IPSEC_ESP
94 #include <netinet6/esp.h>
95 #endif
96 #include <netinet6/ipcomp.h>
97 #endif /* IPSEC */
98
99 #if IPXIP
100 #include <netipx/ipx_ip.h>
101 #endif
102
103 extern struct domain inetdomain;
104 static struct pr_usrreqs nousrreqs;
105 extern struct pr_usrreqs icmp_dgram_usrreqs;
106 extern int icmp_dgram_ctloutput(struct socket *, struct sockopt *);
107
108 struct protosw inetsw[] = {
109 { 0, &inetdomain, 0, 0,
110 0, 0, 0, 0,
111 0,
112 ip_init, 0, ip_slowtimo, ip_drain,
113 0, &nousrreqs
114 },
115 { SOCK_DGRAM, &inetdomain, IPPROTO_UDP, PR_ATOMIC|PR_ADDR,
116 udp_input, 0, udp_ctlinput, ip_ctloutput,
117 0,
118 udp_init, 0, 0, 0,
119 0, &udp_usrreqs
120 },
121 { SOCK_STREAM, &inetdomain, IPPROTO_TCP,
122 PR_CONNREQUIRED|PR_IMPLOPCL|PR_WANTRCVD,
123 tcp_input, 0, tcp_ctlinput, tcp_ctloutput,
124 0,
125 tcp_init, tcp_fasttimo, tcp_slowtimo, tcp_drain,
126 0, &tcp_usrreqs
127 },
128 { SOCK_RAW, &inetdomain, IPPROTO_RAW, PR_ATOMIC|PR_ADDR,
129 rip_input, 0, rip_ctlinput, rip_ctloutput,
130 0,
131 0, 0, 0, 0,
132 0, &rip_usrreqs
133 },
134 { SOCK_RAW, &inetdomain, IPPROTO_ICMP, PR_ATOMIC|PR_ADDR|PR_LASTHDR,
135 icmp_input, 0, 0, rip_ctloutput,
136 0,
137 0, 0, 0, 0,
138 0, &rip_usrreqs
139 },
140 { SOCK_DGRAM, &inetdomain, IPPROTO_ICMP, PR_ATOMIC|PR_ADDR|PR_LASTHDR,
141 icmp_input, 0, 0, icmp_dgram_ctloutput,
142 0,
143 0, 0, 0, 0,
144 0, &icmp_dgram_usrreqs
145 },
146 { SOCK_RAW, &inetdomain, IPPROTO_IGMP, PR_ATOMIC|PR_ADDR|PR_LASTHDR,
147 igmp_input, 0, 0, rip_ctloutput,
148 0,
149 igmp_init, igmp_fasttimo, igmp_slowtimo, 0,
150 0, &rip_usrreqs
151 },
152 { SOCK_RAW, &inetdomain, IPPROTO_RSVP, PR_ATOMIC|PR_ADDR|PR_LASTHDR,
153 rsvp_input, 0, 0, rip_ctloutput,
154 0,
155 0, 0, 0, 0,
156 0, &rip_usrreqs
157 },
158 #if IPSEC
159 { SOCK_RAW, &inetdomain, IPPROTO_AH, PR_ATOMIC|PR_ADDR,
160 ah4_input, 0, 0, 0,
161 0,
162 0, 0, 0, 0,
163 0, &nousrreqs
164 },
165 #if IPSEC_ESP
166 { SOCK_RAW, &inetdomain, IPPROTO_ESP, PR_ATOMIC|PR_ADDR,
167 esp4_input, 0, 0, 0,
168 0,
169 0, 0, 0, 0,
170 0, &nousrreqs
171 },
172 #endif
173 { SOCK_RAW, &inetdomain, IPPROTO_IPCOMP, PR_ATOMIC|PR_ADDR,
174 ipcomp4_input, 0, 0, 0,
175 0,
176 0, 0, 0, 0,
177 0, &nousrreqs
178 },
179 #endif /* IPSEC */
180 { SOCK_RAW, &inetdomain, IPPROTO_IPV4, PR_ATOMIC|PR_ADDR|PR_LASTHDR,
181 encap4_input, 0, 0, rip_ctloutput,
182 0,
183 encap_init, 0, 0, 0,
184 0, &rip_usrreqs
185 },
186 # if INET6
187 { SOCK_RAW, &inetdomain, IPPROTO_IPV6, PR_ATOMIC|PR_ADDR|PR_LASTHDR,
188 encap4_input, 0, 0, rip_ctloutput,
189 0,
190 encap_init, 0, 0, 0,
191 0, &rip_usrreqs
192 },
193 #endif
194 #if IPDIVERT
195 { SOCK_RAW, &inetdomain, IPPROTO_DIVERT, PR_ATOMIC|PR_ADDR,
196 div_input, 0, 0, ip_ctloutput,
197 0,
198 div_init, 0, 0, 0,
199 0, &div_usrreqs,
200 },
201 #endif
202 #if IPXIP
203 { SOCK_RAW, &inetdomain, IPPROTO_IDP, PR_ATOMIC|PR_ADDR|PR_LASTHDR,
204 ipxip_input, 0, ipxip_ctlinput, 0,
205 0,
206 0, 0, 0, 0,
207 0, &rip_usrreqs
208 },
209 #endif
210 #if NSIP
211 { SOCK_RAW, &inetdomain, IPPROTO_IDP, PR_ATOMIC|PR_ADDR|PR_LASTHDR,
212 idpip_input, 0, nsip_ctlinput, 0,
213 0,
214 0, 0, 0, 0,
215 0, &rip_usrreqs
216 },
217 #endif
218 /* raw wildcard */
219 { SOCK_RAW, &inetdomain, 0, PR_ATOMIC|PR_ADDR,
220 rip_input, 0, 0, rip_ctloutput,
221 0,
222 rip_init, 0, 0, 0,
223 0, &rip_usrreqs
224 },
225 };
226
227 extern int in_inithead __P((void **, int));
228
229 int in_proto_count = (sizeof (inetsw) / sizeof (struct protosw));
230
231 extern void in_dinit(void);
232 /* A routing init function, and a header size */
233 struct domain inetdomain =
234 { AF_INET, "internet", in_dinit, 0, 0,
235 inetsw, 0,
236 in_inithead, 32, sizeof(struct sockaddr_in),
237 sizeof(struct tcpiphdr), 0
238 };
239
240 DOMAIN_SET(inet);
241
242 SYSCTL_NODE(_net, PF_INET, inet, CTLFLAG_RW, 0,
243 "Internet Family");
244
245 SYSCTL_NODE(_net_inet, IPPROTO_IP, ip, CTLFLAG_RW, 0, "IP");
246 SYSCTL_NODE(_net_inet, IPPROTO_ICMP, icmp, CTLFLAG_RW, 0, "ICMP");
247 SYSCTL_NODE(_net_inet, IPPROTO_UDP, udp, CTLFLAG_RW, 0, "UDP");
248 SYSCTL_NODE(_net_inet, IPPROTO_TCP, tcp, CTLFLAG_RW, 0, "TCP");
249 SYSCTL_NODE(_net_inet, IPPROTO_IGMP, igmp, CTLFLAG_RW, 0, "IGMP");
250 #if IPSEC
251 SYSCTL_NODE(_net_inet, IPPROTO_AH, ipsec, CTLFLAG_RW, 0, "IPSEC");
252 #endif /* IPSEC */
253 SYSCTL_NODE(_net_inet, IPPROTO_RAW, raw, CTLFLAG_RW, 0, "RAW");
254 #if IPDIVERT
255 SYSCTL_NODE(_net_inet, IPPROTO_DIVERT, div, CTLFLAG_RW, 0, "DIVERT");
256 #endif
257