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