]> git.saurik.com Git - apple/xnu.git/blame - bsd/netinet/in_pcb.h
xnu-1228.9.59.tar.gz
[apple/xnu.git] / bsd / netinet / in_pcb.h
CommitLineData
1c79356b 1/*
2d21ac55 2 * Copyright (c) 2000-2007 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.
103 * So, AF_INET6 null laddr is also used as AF_INET null laddr,
104 * by utilize following structure. (At last, same as INRIA)
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
A
122
123struct inpcb {
124 LIST_ENTRY(inpcb) inp_hash; /* hash list */
91447636
A
125 int inp_wantcnt; /* pcb wanted count. protected by pcb list lock */
126 int inp_state; /* state of this pcb, in use, recycled, ready for recycling... */
1c79356b
A
127 u_short inp_fport; /* foreign port */
128 u_short inp_lport; /* local port */
129 LIST_ENTRY(inpcb) inp_list; /* list for all PCBs of this proto */
130 caddr_t inp_ppcb; /* pointer to per-protocol pcb */
131 struct inpcbinfo *inp_pcbinfo; /* PCB list info */
132 struct socket *inp_socket; /* back pointer to socket */
133 u_char nat_owner; /* Used to NAT TCP/UDP traffic */
2d21ac55 134 u_int32_t nat_cookie; /* Cookie stored and returned to NAT */
1c79356b
A
135 LIST_ENTRY(inpcb) inp_portlist; /* list for this PCB's local port */
136 struct inpcbport *inp_phd; /* head of this list */
137 inp_gen_t inp_gencnt; /* generation count of this instance */
138 int inp_flags; /* generic IP/datagram flags */
139 u_int32_t inp_flow;
140
91447636 141 u_char inp_vflag; /* INP_IPV4 or INP_IPV6 */
1c79356b
A
142
143 u_char inp_ip_ttl; /* time to live proto */
144 u_char inp_ip_p; /* protocol proto */
145 /* protocol dependent part */
146 union {
147 /* foreign host table entry */
9bccf70c
A
148 struct in_addr_4in6 inp46_foreign;
149 struct in6_addr inp6_foreign;
1c79356b
A
150 } inp_dependfaddr;
151 union {
152 /* local host table entry */
9bccf70c
A
153 struct in_addr_4in6 inp46_local;
154 struct in6_addr inp6_local;
1c79356b
A
155 } inp_dependladdr;
156 union {
157 /* placeholder for routing entry */
9bccf70c
A
158 struct route inp4_route;
159 struct route_in6 inp6_route;
1c79356b
A
160 } inp_dependroute;
161 struct {
162 /* type of service proto */
163 u_char inp4_ip_tos;
164 /* IP options */
165 struct mbuf *inp4_options;
166 /* IP multicast options */
167 struct ip_moptions *inp4_moptions;
168 } inp_depend4;
1c79356b
A
169 struct {
170 /* IP options */
171 struct mbuf *inp6_options;
9bccf70c
A
172 u_int8_t inp6_hlim;
173 u_int8_t unused_uint8_1;
174 ushort unused_uint16_1;
1c79356b 175 /* IP6 options for outgoing packets */
9bccf70c 176 struct ip6_pktopts *inp6_outputopts;
1c79356b 177 /* IP multicast options */
9bccf70c 178 struct ip6_moptions *inp6_moptions;
1c79356b 179 /* ICMPv6 code type filter */
9bccf70c 180 struct icmp6_filter *inp6_icmp6filt;
1c79356b 181 /* IPV6_CHECKSUM setsockopt */
9bccf70c 182 int inp6_cksum;
1c79356b
A
183 u_short inp6_ifindex;
184 short inp6_hops;
185 } inp_depend6;
9bccf70c 186
1c79356b
A
187 int hash_element; /* Array index of pcb's hash list */
188 caddr_t inp_saved_ppcb; /* place to save pointer while cached */
9bccf70c 189 struct inpcbpolicy *inp_sp;
91447636
A
190#ifdef _KERN_LOCKS_H_
191 lck_mtx_t *inpcb_mtx; /* inpcb per-socket mutex */
192#else
193 void *inpcb_mtx;
194#endif
2d21ac55
A
195 u_int32_t reserved[4]; /* future use (some already used) */
196#if CONFIG_MACF_NET
197 struct label *inp_label; /* MAC label */
198#endif
199#if CONFIG_FORCE_OUT_IFP
200#ifdef _KERN_SYS_KERNELTYPES_H_
201 ifnet_t pdp_ifp;
202#else
203 void *pdp_ifp;
204#endif /* _KERN_SYS_KERNELTYPES_H_ */
205#endif /* CONFIG_EMBEDDED */
593a1d5f
A
206#if CONFIG_IP_EDGEHOLE
207 u_int32_t inpcb_edgehole_flags;
208 u_int32_t inpcb_edgehole_mask;
209#endif
1c79356b 210};
91447636
A
211
212#endif /* KERNEL_PRIVATE */
213
1c79356b
A
214/*
215 * The range of the generation count, as used in this implementation,
216 * is 9e19. We would have to create 300 billion connections per
217 * second for this number to roll over in a year. This seems sufficiently
218 * unlikely that we simply don't concern ourselves with that possibility.
219 */
220
221/*
222 * Interface exported to userland by various protocols which use
223 * inpcbs. Hack alert -- only define if struct xsocket is in scope.
224 */
91447636
A
225
226/*
227 * This is a copy of the inpcb as it shipped in Panther. This structure
228 * is filled out in a copy function. This allows the inpcb to change
229 * without breaking userland tools.
230 *
231 * CAUTION: Many fields may not be filled out. Fewer may be filled out
232 * in the future. Code defensively.
233 */
2d21ac55
A
234
235#pragma pack(4)
236
237#if defined(__LP64__)
238struct _inpcb_list_entry {
239 u_int32_t le_next;
240 u_int32_t le_prev;
241};
242#define _INPCB_PTR(x) u_int32_t
243#define _INPCB_LIST_ENTRY(x) struct _inpcb_list_entry
244#else
245#define _INPCB_PTR(x) x
246#define _INPCB_LIST_ENTRY(x) LIST_ENTRY(x)
247#endif
248
91447636
A
249#ifdef KERNEL_PRIVATE
250struct inpcb_compat {
251#else
252struct inpcbinfo;
253struct inpcbport;
254struct mbuf;
2d21ac55
A
255struct ip6_pktopts;
256struct ip6_moptions;
257struct icmp6_filter;
91447636
A
258struct inpcbpolicy;
259
260struct inpcb {
261#endif /* KERNEL_PRIVATE */
2d21ac55 262 _INPCB_LIST_ENTRY(inpcb) inp_hash; /* hash list */
91447636
A
263 struct in_addr reserved1; /* APPLE reserved: inp_faddr defined in protcol indep. part */
264 struct in_addr reserved2; /* APPLE reserved */
265 u_short inp_fport; /* foreign port */
266 u_short inp_lport; /* local port */
2d21ac55
A
267 _INPCB_LIST_ENTRY(inpcb) inp_list; /* list for all PCBs of this proto */
268 _INPCB_PTR(caddr_t) inp_ppcb; /* pointer to per-protocol pcb */
269 _INPCB_PTR(struct inpcbinfo *) inp_pcbinfo; /* PCB list info */
270 _INPCB_PTR(void *) inp_socket; /* back pointer to socket */
91447636 271 u_char nat_owner; /* Used to NAT TCP/UDP traffic */
2d21ac55
A
272 u_int32_t nat_cookie; /* Cookie stored and returned to NAT */
273 _INPCB_LIST_ENTRY(inpcb) inp_portlist; /* list for this PCB's local port */
274 _INPCB_PTR(struct inpcbport *) inp_phd; /* head of this list */
91447636
A
275 inp_gen_t inp_gencnt; /* generation count of this instance */
276 int inp_flags; /* generic IP/datagram flags */
277 u_int32_t inp_flow;
278
279 u_char inp_vflag;
280
281 u_char inp_ip_ttl; /* time to live proto */
282 u_char inp_ip_p; /* protocol proto */
283 /* protocol dependent part */
284 union {
285 /* foreign host table entry */
286 struct in_addr_4in6 inp46_foreign;
287 struct in6_addr inp6_foreign;
288 } inp_dependfaddr;
289 union {
290 /* local host table entry */
291 struct in_addr_4in6 inp46_local;
292 struct in6_addr inp6_local;
293 } inp_dependladdr;
294 union {
295 /* placeholder for routing entry */
296 u_char inp4_route[20];
297 u_char inp6_route[32];
298 } inp_dependroute;
299 struct {
300 /* type of service proto */
301 u_char inp4_ip_tos;
302 /* IP options */
2d21ac55 303 _INPCB_PTR(struct mbuf *) inp4_options;
91447636 304 /* IP multicast options */
2d21ac55 305 _INPCB_PTR(struct ip_moptions *) inp4_moptions;
91447636
A
306 } inp_depend4;
307
308 struct {
309 /* IP options */
2d21ac55 310 _INPCB_PTR(struct mbuf *) inp6_options;
91447636
A
311 u_int8_t inp6_hlim;
312 u_int8_t unused_uint8_1;
313 ushort unused_uint16_1;
314 /* IP6 options for outgoing packets */
2d21ac55 315 _INPCB_PTR(struct ip6_pktopts *) inp6_outputopts;
91447636 316 /* IP multicast options */
2d21ac55 317 _INPCB_PTR(struct ip6_moptions *) inp6_moptions;
91447636 318 /* ICMPv6 code type filter */
2d21ac55 319 _INPCB_PTR(struct icmp6_filter *) inp6_icmp6filt;
91447636
A
320 /* IPV6_CHECKSUM setsockopt */
321 int inp6_cksum;
322 u_short inp6_ifindex;
323 short inp6_hops;
324 } inp_depend6;
325
326 int hash_element; /* Array index of pcb's hash list */
2d21ac55
A
327 _INPCB_PTR(caddr_t) inp_saved_ppcb; /* place to save pointer while cached */
328 _INPCB_PTR(struct inpcbpolicy *) inp_sp;
329 u_int32_t reserved[3]; /* For future use */
91447636
A
330};
331
1c79356b 332struct xinpcb {
2d21ac55 333 u_int32_t xi_len; /* length of this structure */
91447636
A
334#ifdef KERNEL_PRIVATE
335 struct inpcb_compat xi_inp;
336#else
1c79356b 337 struct inpcb xi_inp;
91447636 338#endif
1c79356b
A
339 struct xsocket xi_socket;
340 u_quad_t xi_alignment_hack;
341};
342
343struct xinpgen {
2d21ac55 344 u_int32_t xig_len; /* length of this structure */
1c79356b
A
345 u_int xig_count; /* number of PCBs at this time */
346 inp_gen_t xig_gen; /* generation count at this time */
347 so_gen_t xig_sogen; /* socket generation count at this time */
348};
1c79356b 349
2d21ac55
A
350#pragma pack()
351
91447636
A
352/*
353 * These defines are for use with the inpcb.
354 */
355#define INP_IPV4 0x1
356#define INP_IPV6 0x2
357#define inp_faddr inp_dependfaddr.inp46_foreign.ia46_addr4
358#define inp_laddr inp_dependladdr.inp46_local.ia46_addr4
359#define inp_route inp_dependroute.inp4_route
360#define inp_ip_tos inp_depend4.inp4_ip_tos
361#define inp_options inp_depend4.inp4_options
362#define inp_moptions inp_depend4.inp4_moptions
363#define in6p_faddr inp_dependfaddr.inp6_foreign
364#define in6p_laddr inp_dependladdr.inp6_local
365#define in6p_route inp_dependroute.inp6_route
366#define in6p_ip6_hlim inp_depend6.inp6_hlim
367#define in6p_hops inp_depend6.inp6_hops /* default hop limit */
368#define in6p_ip6_nxt inp_ip_p
369#define in6p_flowinfo inp_flow
370#define in6p_vflag inp_vflag
371#define in6p_options inp_depend6.inp6_options
372#define in6p_outputopts inp_depend6.inp6_outputopts
373#define in6p_moptions inp_depend6.inp6_moptions
374#define in6p_icmp6filt inp_depend6.inp6_icmp6filt
375#define in6p_cksum inp_depend6.inp6_cksum
376#define inp6_ifindex inp_depend6.inp6_ifindex
377#define in6p_flags inp_flags /* for KAME src sync over BSD*'s */
378#define in6p_socket inp_socket /* for KAME src sync over BSD*'s */
379#define in6p_lport inp_lport /* for KAME src sync over BSD*'s */
380#define in6p_fport inp_fport /* for KAME src sync over BSD*'s */
381#define in6p_ppcb inp_ppcb /* for KAME src sync over BSD*'s */
382#define in6p_state inp_state
383#define in6p_wantcnt inp_wantcnt
384
385#ifdef KERNEL_PRIVATE
1c79356b
A
386struct inpcbport {
387 LIST_ENTRY(inpcbport) phd_hash;
388 struct inpcbhead phd_pcblist;
389 u_short phd_port;
390};
391
392struct inpcbinfo { /* XXX documentation, prefixes */
393 struct inpcbhead *hashbase;
9bccf70c 394#ifdef __APPLE__
1c79356b 395 u_long hashsize; /* in elements */
9bccf70c 396#endif
1c79356b
A
397 u_long hashmask;
398 struct inpcbporthead *porthashbase;
399 u_long porthashmask;
400 struct inpcbhead *listhead;
401 u_short lastport;
402 u_short lastlow;
403 u_short lasthi;
404 void *ipi_zone; /* zone to allocate pcbs from */
405 u_int ipi_count; /* number of pcbs in this list */
406 u_quad_t ipi_gencnt; /* current generation count */
9bccf70c 407#ifdef __APPLE__
91447636
A
408 u_char all_owners;
409 struct socket nat_dummy_socket; /* fake socket for NAT pcb backpointer */
410 struct inpcb *nat_dummy_pcb; /* fake pcb for finding NAT mutex */
411 caddr_t dummy_cb;
412#ifdef _KERN_LOCKS_H_
413 lck_attr_t *mtx_attr; /* mutex attributes */
414 lck_grp_t *mtx_grp; /* mutex group definition */
415 lck_grp_attr_t *mtx_grp_attr; /* mutex group attributes */
416 lck_rw_t *mtx; /* global mutex for the pcblist*/
417#else
418 void *mtx_attr; /* mutex attributes */
419 void *mtx_grp; /* mutex group definition */
420 void *mtx_grp_attr; /* mutex group attributes */
421 void *mtx; /* global mutex for the pcblist*/
422#endif
9bccf70c 423#endif
1c79356b
A
424};
425
426#define INP_PCBHASH(faddr, lport, fport, mask) \
427 (((faddr) ^ ((faddr) >> 16) ^ ntohs((lport) ^ (fport))) & (mask))
428#define INP_PCBPORTHASH(lport, mask) \
429 (ntohs((lport)) & (mask))
430
91447636
A
431#endif /* KERNEL_PRIVATE */
432
1c79356b
A
433/* flags in inp_flags: */
434#define INP_RECVOPTS 0x01 /* receive incoming IP options */
435#define INP_RECVRETOPTS 0x02 /* receive IP options for reply */
436#define INP_RECVDSTADDR 0x04 /* receive IP dst address */
437#define INP_HDRINCL 0x08 /* user supplies entire IP header */
438#define INP_HIGHPORT 0x10 /* user wants "high" port binding */
439#define INP_LOWPORT 0x20 /* user wants "low" port binding */
440#define INP_ANONPORT 0x40 /* port chosen for user */
441#define INP_RECVIF 0x80 /* receive incoming interface */
442#define INP_MTUDISC 0x100 /* user can do MTU discovery */
9bccf70c 443#ifdef __APPLE__
91447636 444#define INP_STRIPHDR 0x200 /* Strip headers in raw_ip, for OT support */
9bccf70c 445#endif
55e303ae
A
446#define INP_FAITH 0x400 /* accept FAITH'ed connections */
447#define INP_INADDR_ANY 0x800 /* local address wasn't specified */
448
91447636 449#define INP_RECVTTL 0x1000
2d21ac55 450#define INP_UDP_NOCKSUM 0x2000 /* Turn off outbound UDP checksum */
9bccf70c
A
451
452#define IN6P_IPV6_V6ONLY 0x008000 /* restrict AF_INET6 socket for v6 */
453
454#define IN6P_PKTINFO 0x010000 /* receive IP6 dst and I/F */
455#define IN6P_HOPLIMIT 0x020000 /* receive hoplimit */
456#define IN6P_HOPOPTS 0x040000 /* receive hop-by-hop options */
457#define IN6P_DSTOPTS 0x080000 /* receive dst options after rthdr */
458#define IN6P_RTHDR 0x100000 /* receive routing header */
459#define IN6P_RTHDRDSTOPTS 0x200000 /* receive dstoptions before rthdr */
460#define IN6P_AUTOFLOWLABEL 0x800000 /* attach flowlabel automatically */
461#define IN6P_BINDV6ONLY 0x10000000 /* do not grab IPv4 traffic */
1c79356b 462
91447636 463#ifdef KERNEL_PRIVATE
1c79356b
A
464#define INP_CONTROLOPTS (INP_RECVOPTS|INP_RECVRETOPTS|INP_RECVDSTADDR|\
465 INP_RECVIF|\
466 IN6P_PKTINFO|IN6P_HOPLIMIT|IN6P_HOPOPTS|\
9bccf70c 467 IN6P_DSTOPTS|IN6P_RTHDR|IN6P_RTHDRDSTOPTS|\
55e303ae 468 IN6P_AUTOFLOWLABEL|INP_RECVTTL)
9bccf70c
A
469#define INP_UNMAPPABLEOPTS (IN6P_HOPOPTS|IN6P_DSTOPTS|IN6P_RTHDR|\
470 IN6P_AUTOFLOWLABEL)
1c79356b
A
471
472 /* for KAME src sync over BSD*'s */
473#define IN6P_HIGHPORT INP_HIGHPORT
474#define IN6P_LOWPORT INP_LOWPORT
475#define IN6P_ANONPORT INP_ANONPORT
476#define IN6P_RECVIF INP_RECVIF
477#define IN6P_MTUDISC INP_MTUDISC
478#define IN6P_FAITH INP_FAITH
9bccf70c 479#define IN6P_CONTROLOPTS INP_CONTROLOPTS
1c79356b 480 /*
9bccf70c 481 * socket AF version is {newer than,or include}
1c79356b
A
482 * actual datagram AF version
483 */
484
485#define INPLOOKUP_WILDCARD 1
9bccf70c 486#ifdef __APPLE__
1c79356b
A
487#define INPCB_ALL_OWNERS 0xff
488#define INPCB_NO_OWNER 0x0
489#define INPCB_OWNED_BY_X 0x80
490#define INPCB_MAX_IDS 7
91447636 491#endif /* __APPLE__ */
1c79356b
A
492
493#define sotoinpcb(so) ((struct inpcb *)(so)->so_pcb)
494#define sotoin6pcb(so) sotoinpcb(so) /* for KAME src sync over BSD*'s */
495
9bccf70c 496#define INP_SOCKAF(so) so->so_proto->pr_domain->dom_family
1c79356b 497
9bccf70c 498#define INP_CHECK_SOCKAF(so, af) (INP_SOCKAF(so) == af)
1c79356b
A
499
500#ifdef KERNEL
9bccf70c
A
501extern int ipport_lowfirstauto;
502extern int ipport_lowlastauto;
503extern int ipport_firstauto;
504extern int ipport_lastauto;
505extern int ipport_hifirstauto;
506extern int ipport_hilastauto;
507
91447636
A
508#define INPCB_STATE_INUSE 0x1 /* freshly allocated PCB, it's in use */
509#define INPCB_STATE_CACHED 0x2 /* this pcb is sitting in a a cache */
510#define INPCB_STATE_DEAD 0x3 /* should treat as gone, will be garbage collected and freed */
511
512#define WNT_STOPUSING 0xffff /* marked as ready to be garbaged collected, should be treated as not found */
513#define WNT_ACQUIRE 0x1 /* that pcb is being acquired, do not recycle this time */
514#define WNT_RELEASE 0x2 /* release acquired mode, can be garbage collected when wantcnt is null */
515
516
517void in_pcbpurgeif0(struct inpcb *, struct ifnet *);
518void in_losing(struct inpcb *);
519void in_rtchange(struct inpcb *, int);
520int in_pcballoc(struct socket *, struct inpcbinfo *, struct proc *);
521int in_pcbbind(struct inpcb *, struct sockaddr *, struct proc *);
522int in_pcbconnect(struct inpcb *, struct sockaddr *, struct proc *);
523void in_pcbdetach(struct inpcb *);
524void in_pcbdispose (struct inpcb *);
525void in_pcbdisconnect(struct inpcb *);
526int in_pcbinshash(struct inpcb *, int);
527int in_pcbladdr(struct inpcb *, struct sockaddr *, struct sockaddr_in **);
1c79356b 528struct inpcb *
91447636 529 in_pcblookup_local(struct inpcbinfo *, struct in_addr, u_int, int);
2d21ac55
A
530struct inpcb *
531 in_pcblookup_local_and_cleanup(struct inpcbinfo *, struct in_addr, u_int, int);
1c79356b 532struct inpcb *
91447636 533 in_pcblookup_hash(struct inpcbinfo *,
9bccf70c 534 struct in_addr, u_int, struct in_addr, u_int,
91447636
A
535 int, struct ifnet *);
536void in_pcbnotifyall(struct inpcbinfo *, struct in_addr,
537 int, void (*)(struct inpcb *, int));
538void in_pcbrehash(struct inpcb *);
539int in_setpeeraddr(struct socket *so, struct sockaddr **nam);
540int in_setsockaddr(struct socket *so, struct sockaddr **nam);
541int in_pcb_checkstate(struct inpcb *pcb, int mode, int locked);
1c79356b 542
91447636
A
543int
544in_pcb_grab_port (struct inpcbinfo *pcbinfo,
1c79356b
A
545 u_short options,
546 struct in_addr laddr,
547 u_short *lport,
548 struct in_addr faddr,
549 u_short fport,
550 u_int cookie,
91447636 551 u_char owner_id);
1c79356b
A
552
553int
91447636 554in_pcb_letgo_port(struct inpcbinfo *pcbinfo,
1c79356b
A
555 struct in_addr laddr,
556 u_short lport,
557 struct in_addr faddr,
91447636 558 u_short fport, u_char owner_id);
1c79356b
A
559
560u_char
91447636 561in_pcb_get_owner(struct inpcbinfo *pcbinfo,
1c79356b
A
562 struct in_addr laddr,
563 u_short lport,
564 struct in_addr faddr,
565 u_short fport,
91447636 566 u_int *cookie);
1c79356b
A
567
568void in_pcb_nat_init(struct inpcbinfo *pcbinfo, int afamily, int pfamily,
569 int protocol);
570
571int
572in_pcb_new_share_client(struct inpcbinfo *pcbinfo, u_char *owner_id);
573
574int
575in_pcb_rem_share_client(struct inpcbinfo *pcbinfo, u_char owner_id);
576
91447636
A
577void in_pcbremlists(struct inpcb *inp);
578int in_pcb_ckeckstate(struct inpcb *, int, int);
579void inpcb_to_compat(struct inpcb *inp, struct inpcb_compat *inp_compat);
2d21ac55
A
580#if CONFIG_FORCE_OUT_IFP
581void pdp_context_route_locked(ifnet_t ifp, struct route *ro);
582#endif
91447636
A
583
584#endif /* KERNEL */
585#endif /* KERNEL_PRIVATE */
1c79356b
A
586
587#endif /* !_NETINET_IN_PCB_H_ */