]> git.saurik.com Git - apple/xnu.git/blame - bsd/netinet/in_pcb.h
xnu-1699.22.81.tar.gz
[apple/xnu.git] / bsd / netinet / in_pcb.h
CommitLineData
1c79356b 1/*
6d2010ae 2 * Copyright (c) 2000-2011 Apple Inc. All rights reserved.
5d5c5d0d 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, 1990, 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_pcb.h 8.1 (Berkeley) 6/10/93
9bccf70c 61 * $FreeBSD: src/sys/netinet/in_pcb.h,v 1.32.2.4 2001/08/13 16:26:17 ume Exp $
1c79356b 62 */
2d21ac55
A
63/*
64 * NOTICE: This file was modified by SPARTA, Inc. in 2007 to introduce
65 * support for mandatory and extensible security protections. This notice
66 * is included in support of clause 2.2 (b) of the Apple Public License,
67 * Version 2.0.
68 */
1c79356b
A
69
70#ifndef _NETINET_IN_PCB_H_
71#define _NETINET_IN_PCB_H_
9bccf70c 72#include <sys/appleapiopts.h>
1c79356b 73
91447636 74#include <sys/types.h>
1c79356b 75#include <sys/queue.h>
91447636
A
76#ifdef KERNEL_PRIVATE
77#ifdef KERNEL
78#include <kern/locks.h>
79#endif
80#endif /* KERNEL_PRIVATE */
9bccf70c
A
81
82#include <netinet6/ipsec.h> /* for IPSEC */
83
91447636 84#ifdef KERNEL_PRIVATE
9bccf70c
A
85
86#define in6pcb inpcb /* for KAME src sync over BSD*'s */
87#define in6p_sp inp_sp /* for KAME src sync over BSD*'s */
1c79356b
A
88
89/*
90 * Common structure pcb for internet protocol implementation.
91 * Here are stored pointers to local and foreign host table
92 * entries, local and foreign socket numbers, and pointers
93 * up (to a socket structure) and down (to a protocol-specific)
94 * control block.
95 */
96LIST_HEAD(inpcbhead, inpcb);
97LIST_HEAD(inpcbporthead, inpcbport);
91447636 98#endif /* KERNEL_PRIVATE */
1c79356b
A
99typedef u_quad_t inp_gen_t;
100
101/*
102 * PCB with AF_INET6 null bind'ed laddr can receive AF_INET input packet.
6d2010ae
A
103 * So, AF_INET6 null laddr is also used as AF_INET null laddr, by utilizing
104 * the following structure.
1c79356b
A
105 */
106struct in_addr_4in6 {
9bccf70c
A
107 u_int32_t ia46_pad32[3];
108 struct in_addr ia46_addr4;
1c79356b
A
109};
110
91447636 111#ifdef KERNEL_PRIVATE
1c79356b
A
112/*
113 * NB: the zone allocator is type-stable EXCEPT FOR THE FIRST TWO LONGS
114 * of the structure. Therefore, it is important that the members in
115 * that position not contain any information which is required to be
116 * stable.
117 */
9bccf70c 118struct icmp6_filter;
2d21ac55
A
119#if CONFIG_MACF_NET
120struct label;
121#endif
1c79356b 122
6d2010ae
A
123struct inp_stat
124{
125 u_int64_t rxpackets;
126 u_int64_t rxbytes;
127 u_int64_t txpackets;
128 u_int64_t txbytes;
129};
130
1c79356b
A
131struct inpcb {
132 LIST_ENTRY(inpcb) inp_hash; /* hash list */
91447636
A
133 int inp_wantcnt; /* pcb wanted count. protected by pcb list lock */
134 int inp_state; /* state of this pcb, in use, recycled, ready for recycling... */
1c79356b
A
135 u_short inp_fport; /* foreign port */
136 u_short inp_lport; /* local port */
137 LIST_ENTRY(inpcb) inp_list; /* list for all PCBs of this proto */
6d2010ae 138 void *inp_ppcb; /* pointer to per-protocol pcb */
1c79356b
A
139 struct inpcbinfo *inp_pcbinfo; /* PCB list info */
140 struct socket *inp_socket; /* back pointer to socket */
141 u_char nat_owner; /* Used to NAT TCP/UDP traffic */
2d21ac55 142 u_int32_t nat_cookie; /* Cookie stored and returned to NAT */
1c79356b
A
143 LIST_ENTRY(inpcb) inp_portlist; /* list for this PCB's local port */
144 struct inpcbport *inp_phd; /* head of this list */
145 inp_gen_t inp_gencnt; /* generation count of this instance */
146 int inp_flags; /* generic IP/datagram flags */
147 u_int32_t inp_flow;
148
91447636 149 u_char inp_vflag; /* INP_IPV4 or INP_IPV6 */
1c79356b
A
150
151 u_char inp_ip_ttl; /* time to live proto */
152 u_char inp_ip_p; /* protocol proto */
153 /* protocol dependent part */
154 union {
155 /* foreign host table entry */
9bccf70c
A
156 struct in_addr_4in6 inp46_foreign;
157 struct in6_addr inp6_foreign;
1c79356b
A
158 } inp_dependfaddr;
159 union {
160 /* local host table entry */
9bccf70c
A
161 struct in_addr_4in6 inp46_local;
162 struct in6_addr inp6_local;
1c79356b
A
163 } inp_dependladdr;
164 union {
165 /* placeholder for routing entry */
9bccf70c
A
166 struct route inp4_route;
167 struct route_in6 inp6_route;
1c79356b
A
168 } inp_dependroute;
169 struct {
170 /* type of service proto */
171 u_char inp4_ip_tos;
172 /* IP options */
173 struct mbuf *inp4_options;
174 /* IP multicast options */
175 struct ip_moptions *inp4_moptions;
176 } inp_depend4;
1c79356b
A
177 struct {
178 /* IP options */
179 struct mbuf *inp6_options;
9bccf70c
A
180 u_int8_t inp6_hlim;
181 u_int8_t unused_uint8_1;
182 ushort unused_uint16_1;
1c79356b 183 /* IP6 options for outgoing packets */
9bccf70c 184 struct ip6_pktopts *inp6_outputopts;
1c79356b 185 /* IP multicast options */
9bccf70c 186 struct ip6_moptions *inp6_moptions;
1c79356b 187 /* ICMPv6 code type filter */
9bccf70c 188 struct icmp6_filter *inp6_icmp6filt;
1c79356b 189 /* IPV6_CHECKSUM setsockopt */
9bccf70c 190 int inp6_cksum;
1c79356b
A
191 u_short inp6_ifindex;
192 short inp6_hops;
193 } inp_depend6;
9bccf70c 194
1c79356b
A
195 int hash_element; /* Array index of pcb's hash list */
196 caddr_t inp_saved_ppcb; /* place to save pointer while cached */
9bccf70c 197 struct inpcbpolicy *inp_sp;
6d2010ae 198 decl_lck_mtx_data( ,inpcb_mtx); /* inpcb per-socket mutex */
c910b4d9 199 unsigned int inp_boundif; /* interface scope for INP_BOUND_IF */
6d2010ae
A
200 unsigned int inp_last_outif; /* last known outgoing interface */
201 u_int32_t inp_reserved[2]; /* reserved for future use */
2d21ac55
A
202#if CONFIG_MACF_NET
203 struct label *inp_label; /* MAC label */
204#endif
6d2010ae
A
205 struct inp_stat *inp_stat;
206 u_int8_t inp_stat_store[sizeof(struct inp_stat) + sizeof(u_int64_t)];
1c79356b 207};
91447636
A
208
209#endif /* KERNEL_PRIVATE */
210
1c79356b
A
211/*
212 * The range of the generation count, as used in this implementation,
213 * is 9e19. We would have to create 300 billion connections per
214 * second for this number to roll over in a year. This seems sufficiently
215 * unlikely that we simply don't concern ourselves with that possibility.
216 */
217
218/*
219 * Interface exported to userland by various protocols which use
220 * inpcbs. Hack alert -- only define if struct xsocket is in scope.
221 */
91447636
A
222
223/*
224 * This is a copy of the inpcb as it shipped in Panther. This structure
225 * is filled out in a copy function. This allows the inpcb to change
226 * without breaking userland tools.
227 *
228 * CAUTION: Many fields may not be filled out. Fewer may be filled out
229 * in the future. Code defensively.
230 */
2d21ac55
A
231
232#pragma pack(4)
233
234#if defined(__LP64__)
235struct _inpcb_list_entry {
236 u_int32_t le_next;
237 u_int32_t le_prev;
238};
239#define _INPCB_PTR(x) u_int32_t
240#define _INPCB_LIST_ENTRY(x) struct _inpcb_list_entry
241#else
242#define _INPCB_PTR(x) x
243#define _INPCB_LIST_ENTRY(x) LIST_ENTRY(x)
244#endif
245
91447636
A
246#ifdef KERNEL_PRIVATE
247struct inpcb_compat {
248#else
249struct inpcbinfo;
250struct inpcbport;
251struct mbuf;
2d21ac55
A
252struct ip6_pktopts;
253struct ip6_moptions;
254struct icmp6_filter;
91447636
A
255struct inpcbpolicy;
256
257struct inpcb {
258#endif /* KERNEL_PRIVATE */
2d21ac55 259 _INPCB_LIST_ENTRY(inpcb) inp_hash; /* hash list */
91447636
A
260 struct in_addr reserved1; /* APPLE reserved: inp_faddr defined in protcol indep. part */
261 struct in_addr reserved2; /* APPLE reserved */
262 u_short inp_fport; /* foreign port */
263 u_short inp_lport; /* local port */
2d21ac55
A
264 _INPCB_LIST_ENTRY(inpcb) inp_list; /* list for all PCBs of this proto */
265 _INPCB_PTR(caddr_t) inp_ppcb; /* pointer to per-protocol pcb */
266 _INPCB_PTR(struct inpcbinfo *) inp_pcbinfo; /* PCB list info */
267 _INPCB_PTR(void *) inp_socket; /* back pointer to socket */
91447636 268 u_char nat_owner; /* Used to NAT TCP/UDP traffic */
2d21ac55
A
269 u_int32_t nat_cookie; /* Cookie stored and returned to NAT */
270 _INPCB_LIST_ENTRY(inpcb) inp_portlist; /* list for this PCB's local port */
271 _INPCB_PTR(struct inpcbport *) inp_phd; /* head of this list */
91447636
A
272 inp_gen_t inp_gencnt; /* generation count of this instance */
273 int inp_flags; /* generic IP/datagram flags */
274 u_int32_t inp_flow;
275
276 u_char inp_vflag;
277
278 u_char inp_ip_ttl; /* time to live proto */
279 u_char inp_ip_p; /* protocol proto */
280 /* protocol dependent part */
281 union {
282 /* foreign host table entry */
283 struct in_addr_4in6 inp46_foreign;
284 struct in6_addr inp6_foreign;
285 } inp_dependfaddr;
286 union {
287 /* local host table entry */
288 struct in_addr_4in6 inp46_local;
289 struct in6_addr inp6_local;
290 } inp_dependladdr;
291 union {
292 /* placeholder for routing entry */
293 u_char inp4_route[20];
294 u_char inp6_route[32];
295 } inp_dependroute;
296 struct {
297 /* type of service proto */
298 u_char inp4_ip_tos;
299 /* IP options */
2d21ac55 300 _INPCB_PTR(struct mbuf *) inp4_options;
91447636 301 /* IP multicast options */
2d21ac55 302 _INPCB_PTR(struct ip_moptions *) inp4_moptions;
91447636
A
303 } inp_depend4;
304
305 struct {
306 /* IP options */
2d21ac55 307 _INPCB_PTR(struct mbuf *) inp6_options;
91447636
A
308 u_int8_t inp6_hlim;
309 u_int8_t unused_uint8_1;
310 ushort unused_uint16_1;
311 /* IP6 options for outgoing packets */
2d21ac55 312 _INPCB_PTR(struct ip6_pktopts *) inp6_outputopts;
91447636 313 /* IP multicast options */
2d21ac55 314 _INPCB_PTR(struct ip6_moptions *) inp6_moptions;
91447636 315 /* ICMPv6 code type filter */
2d21ac55 316 _INPCB_PTR(struct icmp6_filter *) inp6_icmp6filt;
91447636
A
317 /* IPV6_CHECKSUM setsockopt */
318 int inp6_cksum;
319 u_short inp6_ifindex;
320 short inp6_hops;
321 } inp_depend6;
322
323 int hash_element; /* Array index of pcb's hash list */
2d21ac55
A
324 _INPCB_PTR(caddr_t) inp_saved_ppcb; /* place to save pointer while cached */
325 _INPCB_PTR(struct inpcbpolicy *) inp_sp;
326 u_int32_t reserved[3]; /* For future use */
91447636
A
327};
328
1c79356b 329struct xinpcb {
2d21ac55 330 u_int32_t xi_len; /* length of this structure */
91447636
A
331#ifdef KERNEL_PRIVATE
332 struct inpcb_compat xi_inp;
333#else
1c79356b 334 struct inpcb xi_inp;
91447636 335#endif
1c79356b
A
336 struct xsocket xi_socket;
337 u_quad_t xi_alignment_hack;
338};
339
b0d623f7
A
340#if !CONFIG_EMBEDDED
341
342struct inpcb64_list_entry {
343 u_int64_t le_next;
344 u_int64_t le_prev;
345};
346
347struct xinpcb64 {
348 u_int64_t xi_len; /* length of this structure */
349 u_int64_t xi_inpp;
350 u_short inp_fport; /* foreign port */
351 u_short inp_lport; /* local port */
352 struct inpcb64_list_entry
353 inp_list; /* list for all PCBs of this proto */
354 u_int64_t inp_ppcb; /* pointer to per-protocol pcb */
355 u_int64_t inp_pcbinfo; /* PCB list info */
356 struct inpcb64_list_entry
357 inp_portlist; /* list for this PCB's local port */
358 u_int64_t inp_phd; /* head of this list */
359 inp_gen_t inp_gencnt; /* generation count of this instance */
360 int inp_flags; /* generic IP/datagram flags */
361 u_int32_t inp_flow;
362 u_char inp_vflag;
363 u_char inp_ip_ttl; /* time to live */
364 u_char inp_ip_p; /* protocol */
6d2010ae
A
365 union { /* foreign host table entry */
366 struct in_addr_4in6 inp46_foreign;
367 struct in6_addr inp6_foreign;
368 } inp_dependfaddr;
369 union { /* local host table entry */
370 struct in_addr_4in6 inp46_local;
371 struct in6_addr inp6_local;
372 } inp_dependladdr;
373 struct {
374 u_char inp4_ip_tos; /* type of service */
375 } inp_depend4;
376 struct {
377 u_int8_t inp6_hlim;
378 int inp6_cksum;
379 u_short inp6_ifindex;
380 short inp6_hops;
381 } inp_depend6;
382 struct xsocket64 xi_socket;
b0d623f7
A
383 u_quad_t xi_alignment_hack;
384};
385
386#endif /* !CONFIG_EMBEDDED */
387
6d2010ae
A
388#ifdef PRIVATE
389
390struct xinpcb_list_entry {
391 u_int64_t le_next;
392 u_int64_t le_prev;
393};
394
395struct xinpcb_n {
396 u_int32_t xi_len; /* length of this structure */
397 u_int32_t xi_kind; /* XSO_INPCB */
398 u_int64_t xi_inpp;
399 u_short inp_fport; /* foreign port */
400 u_short inp_lport; /* local port */
401 u_int64_t inp_ppcb; /* pointer to per-protocol pcb */
402 inp_gen_t inp_gencnt; /* generation count of this instance */
403 int inp_flags; /* generic IP/datagram flags */
404 u_int32_t inp_flow;
405 u_char inp_vflag;
406 u_char inp_ip_ttl; /* time to live */
407 u_char inp_ip_p; /* protocol */
408 union { /* foreign host table entry */
409 struct in_addr_4in6 inp46_foreign;
410 struct in6_addr inp6_foreign;
411 } inp_dependfaddr;
412 union { /* local host table entry */
413 struct in_addr_4in6 inp46_local;
414 struct in6_addr inp6_local;
415 } inp_dependladdr;
416 struct {
417 u_char inp4_ip_tos; /* type of service */
418 } inp_depend4;
419 struct {
420 u_int8_t inp6_hlim;
421 int inp6_cksum;
422 u_short inp6_ifindex;
423 short inp6_hops;
424 } inp_depend6;
425};
426
427#endif /* PRIVATE */
428
1c79356b 429struct xinpgen {
2d21ac55 430 u_int32_t xig_len; /* length of this structure */
1c79356b
A
431 u_int xig_count; /* number of PCBs at this time */
432 inp_gen_t xig_gen; /* generation count at this time */
433 so_gen_t xig_sogen; /* socket generation count at this time */
434};
1c79356b 435
2d21ac55
A
436#pragma pack()
437
91447636
A
438/*
439 * These defines are for use with the inpcb.
440 */
441#define INP_IPV4 0x1
442#define INP_IPV6 0x2
443#define inp_faddr inp_dependfaddr.inp46_foreign.ia46_addr4
444#define inp_laddr inp_dependladdr.inp46_local.ia46_addr4
445#define inp_route inp_dependroute.inp4_route
446#define inp_ip_tos inp_depend4.inp4_ip_tos
447#define inp_options inp_depend4.inp4_options
448#define inp_moptions inp_depend4.inp4_moptions
449#define in6p_faddr inp_dependfaddr.inp6_foreign
450#define in6p_laddr inp_dependladdr.inp6_local
451#define in6p_route inp_dependroute.inp6_route
452#define in6p_ip6_hlim inp_depend6.inp6_hlim
453#define in6p_hops inp_depend6.inp6_hops /* default hop limit */
454#define in6p_ip6_nxt inp_ip_p
455#define in6p_flowinfo inp_flow
456#define in6p_vflag inp_vflag
457#define in6p_options inp_depend6.inp6_options
458#define in6p_outputopts inp_depend6.inp6_outputopts
459#define in6p_moptions inp_depend6.inp6_moptions
460#define in6p_icmp6filt inp_depend6.inp6_icmp6filt
461#define in6p_cksum inp_depend6.inp6_cksum
b0d623f7 462#define in6p_ifindex inp_depend6.inp6_ifindex
91447636
A
463#define in6p_flags inp_flags /* for KAME src sync over BSD*'s */
464#define in6p_socket inp_socket /* for KAME src sync over BSD*'s */
465#define in6p_lport inp_lport /* for KAME src sync over BSD*'s */
466#define in6p_fport inp_fport /* for KAME src sync over BSD*'s */
467#define in6p_ppcb inp_ppcb /* for KAME src sync over BSD*'s */
468#define in6p_state inp_state
469#define in6p_wantcnt inp_wantcnt
6d2010ae 470#define in6p_last_outif inp_last_outif
91447636
A
471
472#ifdef KERNEL_PRIVATE
1c79356b
A
473struct inpcbport {
474 LIST_ENTRY(inpcbport) phd_hash;
475 struct inpcbhead phd_pcblist;
476 u_short phd_port;
477};
478
479struct inpcbinfo { /* XXX documentation, prefixes */
480 struct inpcbhead *hashbase;
9bccf70c 481#ifdef __APPLE__
b0d623f7 482 u_int32_t hashsize; /* in elements */
9bccf70c 483#endif
b0d623f7 484 u_long hashmask; /* needs to be u_long as expected by hash functions */
1c79356b 485 struct inpcbporthead *porthashbase;
b0d623f7 486 u_long porthashmask; /* needs to be u_long as expected by hash functions */
1c79356b
A
487 struct inpcbhead *listhead;
488 u_short lastport;
489 u_short lastlow;
490 u_short lasthi;
491 void *ipi_zone; /* zone to allocate pcbs from */
492 u_int ipi_count; /* number of pcbs in this list */
493 u_quad_t ipi_gencnt; /* current generation count */
9bccf70c 494#ifdef __APPLE__
91447636 495#ifdef _KERN_LOCKS_H_
b0d623f7
A
496 lck_attr_t *mtx_attr; /* mutex attributes */
497 lck_grp_t *mtx_grp; /* mutex group definition */
91447636 498 lck_grp_attr_t *mtx_grp_attr; /* mutex group attributes */
b0d623f7 499 lck_rw_t *mtx; /* global mutex for the pcblist*/
91447636
A
500#else
501 void *mtx_attr; /* mutex attributes */
502 void *mtx_grp; /* mutex group definition */
503 void *mtx_grp_attr; /* mutex group attributes */
504 void *mtx; /* global mutex for the pcblist*/
505#endif
9bccf70c 506#endif
1c79356b
A
507};
508
509#define INP_PCBHASH(faddr, lport, fport, mask) \
510 (((faddr) ^ ((faddr) >> 16) ^ ntohs((lport) ^ (fport))) & (mask))
511#define INP_PCBPORTHASH(lport, mask) \
512 (ntohs((lport)) & (mask))
513
91447636
A
514#endif /* KERNEL_PRIVATE */
515
1c79356b
A
516/* flags in inp_flags: */
517#define INP_RECVOPTS 0x01 /* receive incoming IP options */
518#define INP_RECVRETOPTS 0x02 /* receive IP options for reply */
519#define INP_RECVDSTADDR 0x04 /* receive IP dst address */
520#define INP_HDRINCL 0x08 /* user supplies entire IP header */
521#define INP_HIGHPORT 0x10 /* user wants "high" port binding */
522#define INP_LOWPORT 0x20 /* user wants "low" port binding */
523#define INP_ANONPORT 0x40 /* port chosen for user */
524#define INP_RECVIF 0x80 /* receive incoming interface */
525#define INP_MTUDISC 0x100 /* user can do MTU discovery */
9bccf70c 526#ifdef __APPLE__
91447636 527#define INP_STRIPHDR 0x200 /* Strip headers in raw_ip, for OT support */
9bccf70c 528#endif
6d2010ae 529#define INP_FAITH 0x400 /* accept FAITH'ed connections */
55e303ae
A
530#define INP_INADDR_ANY 0x800 /* local address wasn't specified */
531
91447636 532#define INP_RECVTTL 0x1000
2d21ac55 533#define INP_UDP_NOCKSUM 0x2000 /* Turn off outbound UDP checksum */
c910b4d9 534#define INP_BOUND_IF 0x4000 /* bind socket to an ifindex */
9bccf70c 535
6d2010ae
A
536#define IN6P_IPV6_V6ONLY 0x8000 /* restrict AF_INET6 socket for v6 */
537#define IN6P_PKTINFO 0x10000 /* receive IP6 dst and I/F */
538#define IN6P_HOPLIMIT 0x20000 /* receive hoplimit */
539#define IN6P_HOPOPTS 0x40000 /* receive hop-by-hop options */
540#define IN6P_DSTOPTS 0x80000 /* receive dst options after rthdr */
541#define IN6P_RTHDR 0x100000 /* receive routing header */
9bccf70c 542#define IN6P_RTHDRDSTOPTS 0x200000 /* receive dstoptions before rthdr */
6d2010ae 543#define IN6P_TCLASS 0x400000 /* receive traffic class value */
b0d623f7 544#define IN6P_AUTOFLOWLABEL 0x800000 /* attach flowlabel automatically */
6d2010ae
A
545#define IN6P_BINDV6ONLY 0x1000000 /* do not grab IPv4 traffic */
546#define IN6P_RFC2292 0x2000000 /* used RFC2292 API on the socket */
547#define IN6P_MTU 0x4000000 /* receive path MTU */
548#define INP_PKTINFO 0x8000000 /* receive and send PKTINFO for IPv4 */
549
550#define INP_NO_IFT_CELLULAR 0x20000000 /* do not use IFT_CELLULAR route */
1c79356b 551
91447636 552#ifdef KERNEL_PRIVATE
1c79356b 553#define INP_CONTROLOPTS (INP_RECVOPTS|INP_RECVRETOPTS|INP_RECVDSTADDR|\
6d2010ae 554 INP_RECVIF|INP_RECVTTL|INP_PKTINFO|\
1c79356b 555 IN6P_PKTINFO|IN6P_HOPLIMIT|IN6P_HOPOPTS|\
9bccf70c 556 IN6P_DSTOPTS|IN6P_RTHDR|IN6P_RTHDRDSTOPTS|\
6d2010ae
A
557 IN6P_TCLASS|IN6P_RFC2292|IN6P_MTU)
558
9bccf70c 559#define INP_UNMAPPABLEOPTS (IN6P_HOPOPTS|IN6P_DSTOPTS|IN6P_RTHDR|\
b0d623f7 560 IN6P_TCLASS|IN6P_AUTOFLOWLABEL)
1c79356b
A
561
562 /* for KAME src sync over BSD*'s */
563#define IN6P_HIGHPORT INP_HIGHPORT
564#define IN6P_LOWPORT INP_LOWPORT
565#define IN6P_ANONPORT INP_ANONPORT
566#define IN6P_RECVIF INP_RECVIF
567#define IN6P_MTUDISC INP_MTUDISC
568#define IN6P_FAITH INP_FAITH
9bccf70c 569#define IN6P_CONTROLOPTS INP_CONTROLOPTS
6d2010ae 570#define IN6P_NO_IFT_CELLULAR INP_NO_IFT_CELLULAR
1c79356b 571 /*
9bccf70c 572 * socket AF version is {newer than,or include}
1c79356b
A
573 * actual datagram AF version
574 */
575
576#define INPLOOKUP_WILDCARD 1
9bccf70c 577#ifdef __APPLE__
1c79356b
A
578#define INPCB_ALL_OWNERS 0xff
579#define INPCB_NO_OWNER 0x0
580#define INPCB_OWNED_BY_X 0x80
581#define INPCB_MAX_IDS 7
91447636 582#endif /* __APPLE__ */
1c79356b
A
583
584#define sotoinpcb(so) ((struct inpcb *)(so)->so_pcb)
585#define sotoin6pcb(so) sotoinpcb(so) /* for KAME src sync over BSD*'s */
586
9bccf70c 587#define INP_SOCKAF(so) so->so_proto->pr_domain->dom_family
6d2010ae 588#define INP_SOCKTYPE(so) so->so_proto->pr_type
1c79356b 589
9bccf70c 590#define INP_CHECK_SOCKAF(so, af) (INP_SOCKAF(so) == af)
1c79356b
A
591
592#ifdef KERNEL
9bccf70c
A
593extern int ipport_lowfirstauto;
594extern int ipport_lowlastauto;
595extern int ipport_firstauto;
596extern int ipport_lastauto;
597extern int ipport_hifirstauto;
598extern int ipport_hilastauto;
599
6d2010ae
A
600struct sysctl_req;
601
91447636
A
602#define INPCB_STATE_INUSE 0x1 /* freshly allocated PCB, it's in use */
603#define INPCB_STATE_CACHED 0x2 /* this pcb is sitting in a a cache */
604#define INPCB_STATE_DEAD 0x3 /* should treat as gone, will be garbage collected and freed */
605
606#define WNT_STOPUSING 0xffff /* marked as ready to be garbaged collected, should be treated as not found */
607#define WNT_ACQUIRE 0x1 /* that pcb is being acquired, do not recycle this time */
608#define WNT_RELEASE 0x2 /* release acquired mode, can be garbage collected when wantcnt is null */
609
b0d623f7
A
610extern void in_losing(struct inpcb *);
611extern void in_rtchange(struct inpcb *, int);
612extern int in_pcballoc(struct socket *, struct inpcbinfo *, struct proc *);
613extern int in_pcbbind(struct inpcb *, struct sockaddr *, struct proc *);
6d2010ae 614extern int in_pcbconnect(struct inpcb *, struct sockaddr *, struct proc *, unsigned int *);
b0d623f7
A
615extern void in_pcbdetach(struct inpcb *);
616extern void in_pcbdispose (struct inpcb *);
617extern void in_pcbdisconnect(struct inpcb *);
618extern int in_pcbinshash(struct inpcb *, int);
619extern int in_pcbladdr(struct inpcb *, struct sockaddr *,
6d2010ae 620 struct sockaddr_in *, unsigned int *);
b0d623f7
A
621extern struct inpcb *in_pcblookup_local(struct inpcbinfo *, struct in_addr,
622 u_int, int);
623extern struct inpcb *in_pcblookup_local_and_cleanup(struct inpcbinfo *,
624 struct in_addr, u_int, int);
625extern struct inpcb *in_pcblookup_hash(struct inpcbinfo *, struct in_addr,
626 u_int, struct in_addr, u_int, int, struct ifnet *);
6d2010ae
A
627extern int in_pcblookup_hash_exists(struct inpcbinfo *, struct in_addr,
628 u_int, struct in_addr, u_int, int, uid_t *, gid_t *, struct ifnet *);
b0d623f7
A
629extern void in_pcbnotifyall(struct inpcbinfo *, struct in_addr, int,
630 void (*)(struct inpcb *, int));
631extern void in_pcbrehash(struct inpcb *);
632extern int in_setpeeraddr(struct socket *so, struct sockaddr **nam);
633extern int in_setsockaddr(struct socket *so, struct sockaddr **nam);
634extern int in_pcb_checkstate(struct inpcb *pcb, int mode, int locked);
635
636extern void in_pcbremlists(struct inpcb *inp);
637extern void inpcb_to_compat(struct inpcb *inp,
638 struct inpcb_compat *inp_compat);
639#if !CONFIG_EMBEDDED
640extern void inpcb_to_xinpcb64(struct inpcb *inp,
641 struct xinpcb64 *xinp);
642#endif
6d2010ae 643extern int get_pcblist_n(short , struct sysctl_req *, struct inpcbinfo *);
b0d623f7
A
644extern void inp_route_copyout(struct inpcb *, struct route *);
645extern void inp_route_copyin(struct inpcb *, struct route *);
6d2010ae
A
646extern void inp_bindif(struct inpcb *, unsigned int);
647extern int inp_nocellular(struct inpcb *, unsigned int);
91447636
A
648
649#endif /* KERNEL */
650#endif /* KERNEL_PRIVATE */
1c79356b
A
651
652#endif /* !_NETINET_IN_PCB_H_ */