]> git.saurik.com Git - apple/xnu.git/blob - bsd/netinet/in_pcb.h
xnu-1699.24.23.tar.gz
[apple/xnu.git] / bsd / netinet / in_pcb.h
1 /*
2 * Copyright (c) 2000-2011 Apple Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_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. 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.
14 *
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
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
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.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
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
61 * $FreeBSD: src/sys/netinet/in_pcb.h,v 1.32.2.4 2001/08/13 16:26:17 ume Exp $
62 */
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 */
69
70 #ifndef _NETINET_IN_PCB_H_
71 #define _NETINET_IN_PCB_H_
72 #include <sys/appleapiopts.h>
73
74 #include <sys/types.h>
75 #include <sys/queue.h>
76 #ifdef KERNEL_PRIVATE
77 #ifdef KERNEL
78 #include <kern/locks.h>
79 #endif
80 #endif /* KERNEL_PRIVATE */
81
82 #include <netinet6/ipsec.h> /* for IPSEC */
83
84 #ifdef KERNEL_PRIVATE
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 */
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 */
96 LIST_HEAD(inpcbhead, inpcb);
97 LIST_HEAD(inpcbporthead, inpcbport);
98 #endif /* KERNEL_PRIVATE */
99 typedef 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, by utilizing
104 * the following structure.
105 */
106 struct in_addr_4in6 {
107 u_int32_t ia46_pad32[3];
108 struct in_addr ia46_addr4;
109 };
110
111 #ifdef KERNEL_PRIVATE
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 */
118 struct icmp6_filter;
119 #if CONFIG_MACF_NET
120 struct label;
121 #endif
122
123 struct 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
131 struct inpcb {
132 LIST_ENTRY(inpcb) inp_hash; /* hash list */
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... */
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 */
138 void *inp_ppcb; /* pointer to per-protocol pcb */
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 */
142 u_int32_t nat_cookie; /* Cookie stored and returned to NAT */
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
149 u_char inp_vflag; /* INP_IPV4 or INP_IPV6 */
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 */
156 struct in_addr_4in6 inp46_foreign;
157 struct in6_addr inp6_foreign;
158 } inp_dependfaddr;
159 union {
160 /* local host table entry */
161 struct in_addr_4in6 inp46_local;
162 struct in6_addr inp6_local;
163 } inp_dependladdr;
164 union {
165 /* placeholder for routing entry */
166 struct route inp4_route;
167 struct route_in6 inp6_route;
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;
177 struct {
178 /* IP options */
179 struct mbuf *inp6_options;
180 u_int8_t inp6_hlim;
181 u_int8_t unused_uint8_1;
182 ushort unused_uint16_1;
183 /* IP6 options for outgoing packets */
184 struct ip6_pktopts *inp6_outputopts;
185 /* IP multicast options */
186 struct ip6_moptions *inp6_moptions;
187 /* ICMPv6 code type filter */
188 struct icmp6_filter *inp6_icmp6filt;
189 /* IPV6_CHECKSUM setsockopt */
190 int inp6_cksum;
191 u_short inp6_ifindex;
192 short inp6_hops;
193 } inp_depend6;
194
195 int hash_element; /* Array index of pcb's hash list */
196 caddr_t inp_saved_ppcb; /* place to save pointer while cached */
197 struct inpcbpolicy *inp_sp;
198 decl_lck_mtx_data( ,inpcb_mtx); /* inpcb per-socket mutex */
199 unsigned int inp_boundif; /* interface scope for INP_BOUND_IF */
200 unsigned int inp_last_outif; /* last known outgoing interface */
201 u_int32_t inp_reserved[2]; /* reserved for future use */
202 #if CONFIG_MACF_NET
203 struct label *inp_label; /* MAC label */
204 #endif
205 struct inp_stat *inp_stat;
206 u_int8_t inp_stat_store[sizeof(struct inp_stat) + sizeof(u_int64_t)];
207 };
208
209 #endif /* KERNEL_PRIVATE */
210
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 */
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 */
231
232 #pragma pack(4)
233
234 #if defined(__LP64__)
235 struct _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
246 #ifdef KERNEL_PRIVATE
247 struct inpcb_compat {
248 #else
249 struct inpcbinfo;
250 struct inpcbport;
251 struct mbuf;
252 struct ip6_pktopts;
253 struct ip6_moptions;
254 struct icmp6_filter;
255 struct inpcbpolicy;
256
257 struct inpcb {
258 #endif /* KERNEL_PRIVATE */
259 _INPCB_LIST_ENTRY(inpcb) inp_hash; /* hash list */
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 */
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 */
268 u_char nat_owner; /* Used to NAT TCP/UDP traffic */
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 */
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 */
300 _INPCB_PTR(struct mbuf *) inp4_options;
301 /* IP multicast options */
302 _INPCB_PTR(struct ip_moptions *) inp4_moptions;
303 } inp_depend4;
304
305 struct {
306 /* IP options */
307 _INPCB_PTR(struct mbuf *) inp6_options;
308 u_int8_t inp6_hlim;
309 u_int8_t unused_uint8_1;
310 ushort unused_uint16_1;
311 /* IP6 options for outgoing packets */
312 _INPCB_PTR(struct ip6_pktopts *) inp6_outputopts;
313 /* IP multicast options */
314 _INPCB_PTR(struct ip6_moptions *) inp6_moptions;
315 /* ICMPv6 code type filter */
316 _INPCB_PTR(struct icmp6_filter *) inp6_icmp6filt;
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 */
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 */
327 };
328
329 struct xinpcb {
330 u_int32_t xi_len; /* length of this structure */
331 #ifdef KERNEL_PRIVATE
332 struct inpcb_compat xi_inp;
333 #else
334 struct inpcb xi_inp;
335 #endif
336 struct xsocket xi_socket;
337 u_quad_t xi_alignment_hack;
338 };
339
340 #if !CONFIG_EMBEDDED
341
342 struct inpcb64_list_entry {
343 u_int64_t le_next;
344 u_int64_t le_prev;
345 };
346
347 struct 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 */
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;
383 u_quad_t xi_alignment_hack;
384 };
385
386 #endif /* !CONFIG_EMBEDDED */
387
388 #ifdef PRIVATE
389
390 struct xinpcb_list_entry {
391 u_int64_t le_next;
392 u_int64_t le_prev;
393 };
394
395 struct 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
429 struct xinpgen {
430 u_int32_t xig_len; /* length of this structure */
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 };
435
436 #pragma pack()
437
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
462 #define in6p_ifindex inp_depend6.inp6_ifindex
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
470 #define in6p_last_outif inp_last_outif
471
472 #ifdef KERNEL_PRIVATE
473 struct inpcbport {
474 LIST_ENTRY(inpcbport) phd_hash;
475 struct inpcbhead phd_pcblist;
476 u_short phd_port;
477 };
478
479 struct inpcbinfo { /* XXX documentation, prefixes */
480 struct inpcbhead *hashbase;
481 #ifdef __APPLE__
482 u_int32_t hashsize; /* in elements */
483 #endif
484 u_long hashmask; /* needs to be u_long as expected by hash functions */
485 struct inpcbporthead *porthashbase;
486 u_long porthashmask; /* needs to be u_long as expected by hash functions */
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 */
494 #ifdef __APPLE__
495 #ifdef _KERN_LOCKS_H_
496 lck_attr_t *mtx_attr; /* mutex attributes */
497 lck_grp_t *mtx_grp; /* mutex group definition */
498 lck_grp_attr_t *mtx_grp_attr; /* mutex group attributes */
499 lck_rw_t *mtx; /* global mutex for the pcblist*/
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
506 #endif
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
514 #endif /* KERNEL_PRIVATE */
515
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 */
526 #ifdef __APPLE__
527 #define INP_STRIPHDR 0x200 /* Strip headers in raw_ip, for OT support */
528 #endif
529 #define INP_FAITH 0x400 /* accept FAITH'ed connections */
530 #define INP_INADDR_ANY 0x800 /* local address wasn't specified */
531
532 #define INP_RECVTTL 0x1000
533 #define INP_UDP_NOCKSUM 0x2000 /* Turn off outbound UDP checksum */
534 #define INP_BOUND_IF 0x4000 /* bind socket to an ifindex */
535
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 */
542 #define IN6P_RTHDRDSTOPTS 0x200000 /* receive dstoptions before rthdr */
543 #define IN6P_TCLASS 0x400000 /* receive traffic class value */
544 #define IN6P_AUTOFLOWLABEL 0x800000 /* attach flowlabel automatically */
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 */
551
552 #ifdef KERNEL_PRIVATE
553 #define INP_CONTROLOPTS (INP_RECVOPTS|INP_RECVRETOPTS|INP_RECVDSTADDR|\
554 INP_RECVIF|INP_RECVTTL|INP_PKTINFO|\
555 IN6P_PKTINFO|IN6P_HOPLIMIT|IN6P_HOPOPTS|\
556 IN6P_DSTOPTS|IN6P_RTHDR|IN6P_RTHDRDSTOPTS|\
557 IN6P_TCLASS|IN6P_RFC2292|IN6P_MTU)
558
559 #define INP_UNMAPPABLEOPTS (IN6P_HOPOPTS|IN6P_DSTOPTS|IN6P_RTHDR|\
560 IN6P_TCLASS|IN6P_AUTOFLOWLABEL)
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
569 #define IN6P_CONTROLOPTS INP_CONTROLOPTS
570 #define IN6P_NO_IFT_CELLULAR INP_NO_IFT_CELLULAR
571 /*
572 * socket AF version is {newer than,or include}
573 * actual datagram AF version
574 */
575
576 #define INPLOOKUP_WILDCARD 1
577 #ifdef __APPLE__
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
582 #endif /* __APPLE__ */
583
584 #define sotoinpcb(so) ((struct inpcb *)(so)->so_pcb)
585 #define sotoin6pcb(so) sotoinpcb(so) /* for KAME src sync over BSD*'s */
586
587 #define INP_SOCKAF(so) so->so_proto->pr_domain->dom_family
588 #define INP_SOCKTYPE(so) so->so_proto->pr_type
589
590 #define INP_CHECK_SOCKAF(so, af) (INP_SOCKAF(so) == af)
591
592 #ifdef KERNEL
593 extern int ipport_lowfirstauto;
594 extern int ipport_lowlastauto;
595 extern int ipport_firstauto;
596 extern int ipport_lastauto;
597 extern int ipport_hifirstauto;
598 extern int ipport_hilastauto;
599
600 struct sysctl_req;
601
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
610 extern void in_losing(struct inpcb *);
611 extern void in_rtchange(struct inpcb *, int);
612 extern int in_pcballoc(struct socket *, struct inpcbinfo *, struct proc *);
613 extern int in_pcbbind(struct inpcb *, struct sockaddr *, struct proc *);
614 extern int in_pcbconnect(struct inpcb *, struct sockaddr *, struct proc *, unsigned int *);
615 extern void in_pcbdetach(struct inpcb *);
616 extern void in_pcbdispose (struct inpcb *);
617 extern void in_pcbdisconnect(struct inpcb *);
618 extern int in_pcbinshash(struct inpcb *, int);
619 extern int in_pcbladdr(struct inpcb *, struct sockaddr *,
620 struct sockaddr_in *, unsigned int *);
621 extern struct inpcb *in_pcblookup_local(struct inpcbinfo *, struct in_addr,
622 u_int, int);
623 extern struct inpcb *in_pcblookup_local_and_cleanup(struct inpcbinfo *,
624 struct in_addr, u_int, int);
625 extern struct inpcb *in_pcblookup_hash(struct inpcbinfo *, struct in_addr,
626 u_int, struct in_addr, u_int, int, struct ifnet *);
627 extern 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 *);
629 extern void in_pcbnotifyall(struct inpcbinfo *, struct in_addr, int,
630 void (*)(struct inpcb *, int));
631 extern void in_pcbrehash(struct inpcb *);
632 extern int in_setpeeraddr(struct socket *so, struct sockaddr **nam);
633 extern int in_setsockaddr(struct socket *so, struct sockaddr **nam);
634 extern int in_pcb_checkstate(struct inpcb *pcb, int mode, int locked);
635
636 extern void in_pcbremlists(struct inpcb *inp);
637 extern void inpcb_to_compat(struct inpcb *inp,
638 struct inpcb_compat *inp_compat);
639 #if !CONFIG_EMBEDDED
640 extern void inpcb_to_xinpcb64(struct inpcb *inp,
641 struct xinpcb64 *xinp);
642 #endif
643 extern int get_pcblist_n(short , struct sysctl_req *, struct inpcbinfo *);
644 extern void inp_route_copyout(struct inpcb *, struct route *);
645 extern void inp_route_copyin(struct inpcb *, struct route *);
646 extern void inp_bindif(struct inpcb *, unsigned int);
647 extern int inp_nocellular(struct inpcb *, unsigned int);
648
649 #endif /* KERNEL */
650 #endif /* KERNEL_PRIVATE */
651
652 #endif /* !_NETINET_IN_PCB_H_ */