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