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