2 * Copyright (c) 2000-2012 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
29 * Copyright (c) 1982, 1986, 1990, 1993
30 * The Regents of the University of California. All rights reserved.
32 * Redistribution and use in source and binary forms, with or without
33 * modification, are permitted provided that the following conditions
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.
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
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 $
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,
70 #ifndef _NETINET_IN_PCB_H_
71 #define _NETINET_IN_PCB_H_
72 #include <sys/appleapiopts.h>
74 #include <sys/types.h>
75 #include <sys/queue.h>
77 #ifdef BSD_KERNEL_PRIVATE
79 #endif /* BSD_KERNEL_PRIVATE */
80 #include <kern/locks.h>
81 #endif /* KERNEL_PRIVATE */
83 #include <netinet6/ipsec.h> /* for IPSEC */
87 #define in6pcb inpcb /* for KAME src sync over BSD*'s */
88 #define in6p_sp inp_sp /* for KAME src sync over BSD*'s */
89 #endif /* KERNEL_PRIVATE */
91 #ifdef BSD_KERNEL_PRIVATE
93 * Common structure pcb for internet protocol implementation.
94 * Here are stored pointers to local and foreign host table
95 * entries, local and foreign socket numbers, and pointers
96 * up (to a socket structure) and down (to a protocol-specific)
99 LIST_HEAD(inpcbhead
, inpcb
);
100 LIST_HEAD(inpcbporthead
, inpcbport
);
101 #endif /* BSD_KERNEL_PRIVATE */
103 typedef u_quad_t inp_gen_t
;
105 * PCB with AF_INET6 null bind'ed laddr can receive AF_INET input packet.
106 * So, AF_INET6 null laddr is also used as AF_INET null laddr, by utilizing
107 * the following structure.
109 struct in_addr_4in6
{
110 u_int32_t ia46_pad32
[3];
111 struct in_addr ia46_addr4
;
114 #ifdef KERNEL_PRIVATE
116 * NB: the zone allocator is type-stable EXCEPT FOR THE FIRST TWO LONGS
117 * of the structure. Therefore, it is important that the members in
118 * that position not contain any information which is required to be
136 LIST_ENTRY(inpcb
) inp_hash
; /* hash list */
137 int inp_wantcnt
; /* pcb wanted count. protected by pcb list lock */
138 int inp_state
; /* state of this pcb, in use, recycled, ready for recycling... */
139 u_short inp_fport
; /* foreign port */
140 u_short inp_lport
; /* local port */
141 LIST_ENTRY(inpcb
) inp_list
; /* list for all PCBs of this proto */
142 void *inp_ppcb
; /* pointer to per-protocol pcb */
143 struct inpcbinfo
*inp_pcbinfo
; /* PCB list info */
144 struct socket
*inp_socket
; /* back pointer to socket */
145 u_int32_t nat_cookie
; /* Cookie stored and returned to NAT */
146 LIST_ENTRY(inpcb
) inp_portlist
; /* list for this PCB's local port */
147 RB_ENTRY(inpcb
) infc_link
; /* link for flowhash RB tree */
148 struct inpcbport
*inp_phd
; /* head of this list */
149 inp_gen_t inp_gencnt
; /* generation count of this instance */
150 u_int32_t inp_flags
; /* generic IP/datagram flags */
151 u_int32_t inp_flags2
; /* generic IP/datagram flags #2 */
154 u_char inp_sndinprog_cnt
; /* outstanding send operations */
155 u_char inp_vflag
; /* INP_IPV4 or INP_IPV6 */
157 u_char inp_ip_ttl
; /* time to live proto */
158 u_char inp_ip_p
; /* protocol proto */
159 /* protocol dependent part */
161 /* foreign host table entry */
162 struct in_addr_4in6 inp46_foreign
;
163 struct in6_addr inp6_foreign
;
166 /* local host table entry */
167 struct in_addr_4in6 inp46_local
;
168 struct in6_addr inp6_local
;
171 /* placeholder for routing entry */
172 struct route inp4_route
;
173 struct route_in6 inp6_route
;
176 /* type of service proto */
179 struct mbuf
*inp4_options
;
180 /* IP multicast options */
181 struct ip_moptions
*inp4_moptions
;
185 struct mbuf
*inp6_options
;
187 u_int8_t unused_uint8_1
;
188 ushort unused_uint16_1
;
189 /* IP6 options for outgoing packets */
190 struct ip6_pktopts
*inp6_outputopts
;
191 /* IP multicast options */
192 struct ip6_moptions
*inp6_moptions
;
193 /* ICMPv6 code type filter */
194 struct icmp6_filter
*inp6_icmp6filt
;
195 /* IPV6_CHECKSUM setsockopt */
197 u_short inp6_ifindex
;
201 int hash_element
; /* Array index of pcb's hash list */
202 caddr_t inp_saved_ppcb
; /* place to save pointer while cached */
203 struct inpcbpolicy
*inp_sp
;
204 decl_lck_mtx_data( ,inpcb_mtx
); /* inpcb per-socket mutex */
205 struct ifnet
*inp_boundifp
; /* interface for INP_BOUND_IF */
206 struct ifnet
*inp_last_outifp
; /* last known outgoing interface */
207 u_int32_t inp_reserved
[2]; /* reserved for future use */
208 u_int32_t inp_flowhash
; /* flow hash */
211 struct label
*inp_label
; /* MAC label */
213 struct inp_stat
*inp_stat
;
214 u_int8_t inp_stat_store
[sizeof(struct inp_stat
) + sizeof(u_int64_t
)];
217 #endif /* KERNEL_PRIVATE */
220 * The range of the generation count, as used in this implementation,
221 * is 9e19. We would have to create 300 billion connections per
222 * second for this number to roll over in a year. This seems sufficiently
223 * unlikely that we simply don't concern ourselves with that possibility.
227 * Interface exported to userland by various protocols which use
228 * inpcbs. Hack alert -- only define if struct xsocket is in scope.
232 * This is a copy of the inpcb as it shipped in Panther. This structure
233 * is filled out in a copy function. This allows the inpcb to change
234 * without breaking userland tools.
236 * CAUTION: Many fields may not be filled out. Fewer may be filled out
237 * in the future. Code defensively.
242 #if defined(__LP64__)
243 struct _inpcb_list_entry
{
247 #define _INPCB_PTR(x) u_int32_t
248 #define _INPCB_LIST_ENTRY(x) struct _inpcb_list_entry
250 #define _INPCB_PTR(x) x
251 #define _INPCB_LIST_ENTRY(x) LIST_ENTRY(x)
254 #ifdef KERNEL_PRIVATE
255 struct inpcb_compat
{
266 #endif /* KERNEL_PRIVATE */
267 _INPCB_LIST_ENTRY(inpcb
) inp_hash
; /* hash list */
268 struct in_addr reserved1
; /* APPLE reserved: inp_faddr defined in protcol indep. part */
269 struct in_addr reserved2
; /* APPLE reserved */
270 u_short inp_fport
; /* foreign port */
271 u_short inp_lport
; /* local port */
272 _INPCB_LIST_ENTRY(inpcb
) inp_list
; /* list for all PCBs of this proto */
273 _INPCB_PTR(caddr_t
) inp_ppcb
; /* pointer to per-protocol pcb */
274 _INPCB_PTR(struct inpcbinfo
*) inp_pcbinfo
; /* PCB list info */
275 _INPCB_PTR(void *) inp_socket
; /* back pointer to socket */
276 u_char nat_owner
; /* Used to NAT TCP/UDP traffic */
277 u_int32_t nat_cookie
; /* Cookie stored and returned to NAT */
278 _INPCB_LIST_ENTRY(inpcb
) inp_portlist
; /* list for this PCB's local port */
279 _INPCB_PTR(struct inpcbport
*) inp_phd
; /* head of this list */
280 inp_gen_t inp_gencnt
; /* generation count of this instance */
281 int inp_flags
; /* generic IP/datagram flags */
286 u_char inp_ip_ttl
; /* time to live proto */
287 u_char inp_ip_p
; /* protocol proto */
288 /* protocol dependent part */
290 /* foreign host table entry */
291 struct in_addr_4in6 inp46_foreign
;
292 struct in6_addr inp6_foreign
;
295 /* local host table entry */
296 struct in_addr_4in6 inp46_local
;
297 struct in6_addr inp6_local
;
300 /* placeholder for routing entry */
301 u_char inp4_route
[20];
302 u_char inp6_route
[32];
305 /* type of service proto */
308 _INPCB_PTR(struct mbuf
*) inp4_options
;
309 /* IP multicast options */
310 _INPCB_PTR(struct ip_moptions
*) inp4_moptions
;
315 _INPCB_PTR(struct mbuf
*) inp6_options
;
317 u_int8_t unused_uint8_1
;
318 ushort unused_uint16_1
;
319 /* IP6 options for outgoing packets */
320 _INPCB_PTR(struct ip6_pktopts
*) inp6_outputopts
;
321 /* IP multicast options */
322 _INPCB_PTR(struct ip6_moptions
*) inp6_moptions
;
323 /* ICMPv6 code type filter */
324 _INPCB_PTR(struct icmp6_filter
*) inp6_icmp6filt
;
325 /* IPV6_CHECKSUM setsockopt */
327 u_short inp6_ifindex
;
331 int hash_element
; /* Array index of pcb's hash list */
332 _INPCB_PTR(caddr_t
) inp_saved_ppcb
; /* place to save pointer while cached */
333 _INPCB_PTR(struct inpcbpolicy
*) inp_sp
;
334 u_int32_t reserved
[3]; /* For future use */
338 u_int32_t xi_len
; /* length of this structure */
339 #ifdef KERNEL_PRIVATE
340 struct inpcb_compat xi_inp
;
344 struct xsocket xi_socket
;
345 u_quad_t xi_alignment_hack
;
350 struct inpcb64_list_entry
{
356 u_int64_t xi_len
; /* length of this structure */
358 u_short inp_fport
; /* foreign port */
359 u_short inp_lport
; /* local port */
360 struct inpcb64_list_entry
361 inp_list
; /* list for all PCBs of this proto */
362 u_int64_t inp_ppcb
; /* pointer to per-protocol pcb */
363 u_int64_t inp_pcbinfo
; /* PCB list info */
364 struct inpcb64_list_entry
365 inp_portlist
; /* list for this PCB's local port */
366 u_int64_t inp_phd
; /* head of this list */
367 inp_gen_t inp_gencnt
; /* generation count of this instance */
368 int inp_flags
; /* generic IP/datagram flags */
371 u_char inp_ip_ttl
; /* time to live */
372 u_char inp_ip_p
; /* protocol */
373 union { /* foreign host table entry */
374 struct in_addr_4in6 inp46_foreign
;
375 struct in6_addr inp6_foreign
;
377 union { /* local host table entry */
378 struct in_addr_4in6 inp46_local
;
379 struct in6_addr inp6_local
;
382 u_char inp4_ip_tos
; /* type of service */
387 u_short inp6_ifindex
;
390 struct xsocket64 xi_socket
;
391 u_quad_t xi_alignment_hack
;
394 #endif /* !CONFIG_EMBEDDED */
398 struct xinpcb_list_entry
{
404 u_int32_t xi_len
; /* length of this structure */
405 u_int32_t xi_kind
; /* XSO_INPCB */
407 u_short inp_fport
; /* foreign port */
408 u_short inp_lport
; /* local port */
409 u_int64_t inp_ppcb
; /* pointer to per-protocol pcb */
410 inp_gen_t inp_gencnt
; /* generation count of this instance */
411 int inp_flags
; /* generic IP/datagram flags */
414 u_char inp_ip_ttl
; /* time to live */
415 u_char inp_ip_p
; /* protocol */
416 union { /* foreign host table entry */
417 struct in_addr_4in6 inp46_foreign
;
418 struct in6_addr inp6_foreign
;
420 union { /* local host table entry */
421 struct in_addr_4in6 inp46_local
;
422 struct in6_addr inp6_local
;
425 u_char inp4_ip_tos
; /* type of service */
430 u_short inp6_ifindex
;
433 u_int32_t inp_flowhash
;
439 u_int32_t xig_len
; /* length of this structure */
440 u_int xig_count
; /* number of PCBs at this time */
441 inp_gen_t xig_gen
; /* generation count at this time */
442 so_gen_t xig_sogen
; /* socket generation count at this time */
448 * These defines are for use with the inpcb.
452 #define inp_faddr inp_dependfaddr.inp46_foreign.ia46_addr4
453 #define inp_laddr inp_dependladdr.inp46_local.ia46_addr4
454 #define in6p_faddr inp_dependfaddr.inp6_foreign
455 #define in6p_laddr inp_dependladdr.inp6_local
457 #ifdef BSD_KERNEL_PRIVATE
458 #define inp_route inp_dependroute.inp4_route
459 #define inp_ip_tos inp_depend4.inp4_ip_tos
460 #define inp_options inp_depend4.inp4_options
461 #define inp_moptions inp_depend4.inp4_moptions
462 #define in6p_route inp_dependroute.inp6_route
463 #define in6p_ip6_hlim inp_depend6.inp6_hlim
464 #define in6p_hops inp_depend6.inp6_hops /* default hop limit */
465 #define in6p_ip6_nxt inp_ip_p
466 #define in6p_flowinfo inp_flow
467 #define in6p_vflag inp_vflag
468 #define in6p_options inp_depend6.inp6_options
469 #define in6p_outputopts inp_depend6.inp6_outputopts
470 #define in6p_moptions inp_depend6.inp6_moptions
471 #define in6p_icmp6filt inp_depend6.inp6_icmp6filt
472 #define in6p_cksum inp_depend6.inp6_cksum
473 #define in6p_ifindex inp_depend6.inp6_ifindex
474 #define in6p_flags inp_flags /* for KAME src sync over BSD*'s */
475 #define in6p_socket inp_socket /* for KAME src sync over BSD*'s */
476 #endif /* BSD_KERNEL_PRIVATE */
478 #define in6p_lport inp_lport /* for KAME src sync over BSD*'s */
479 #define in6p_fport inp_fport /* for KAME src sync over BSD*'s */
480 #define in6p_ppcb inp_ppcb /* for KAME src sync over BSD*'s */
482 #ifdef BSD_KERNEL_PRIVATE
483 #define in6p_state inp_state
484 #define in6p_wantcnt inp_wantcnt
485 #define in6p_last_outifp inp_last_outifp
486 #endif /* BSD_KERNEL_PRIVATE */
488 #ifdef BSD_KERNEL_PRIVATE
490 LIST_ENTRY(inpcbport
) phd_hash
;
491 struct inpcbhead phd_pcblist
;
495 struct inpcbinfo
{ /* XXX documentation, prefixes */
496 struct inpcbhead
*hashbase
;
498 u_int32_t hashsize
; /* in elements */
500 u_long hashmask
; /* u_long as expected by hash functions */
501 struct inpcbporthead
*porthashbase
;
502 u_long porthashmask
; /* u_long as expected by hash functions */
503 struct inpcbhead
*listhead
;
507 void *ipi_zone
; /* zone to allocate pcbs from */
508 u_int ipi_count
; /* number of pcbs in this list */
509 u_quad_t ipi_gencnt
; /* current generation count */
511 #ifdef _KERN_LOCKS_H_
512 lck_attr_t
*mtx_attr
; /* mutex attributes */
513 lck_grp_t
*mtx_grp
; /* mutex group definition */
514 lck_grp_attr_t
*mtx_grp_attr
; /* mutex group attributes */
515 lck_rw_t
*mtx
; /* global mutex for the pcblist*/
517 void *mtx_attr
; /* mutex attributes */
518 void *mtx_grp
; /* mutex group definition */
519 void *mtx_grp_attr
; /* mutex group attributes */
520 void *mtx
; /* global mutex for the pcblist*/
525 #define INP_PCBHASH(faddr, lport, fport, mask) \
526 (((faddr) ^ ((faddr) >> 16) ^ ntohs((lport) ^ (fport))) & (mask))
527 #define INP_PCBPORTHASH(lport, mask) \
528 (ntohs((lport)) & (mask))
530 #define INP_IS_FLOW_CONTROLLED(_inp_) ((_inp_)->inp_flags & INP_FLOW_CONTROLLED)
531 #define INP_IS_FLOW_SUSPENDED(_inp_) \
532 (((_inp_)->inp_flags & INP_FLOW_SUSPENDED) || \
533 ((_inp_)->inp_socket->so_flags & SOF_SUSPENDED))
534 #define INP_WAIT_FOR_IF_FEEDBACK(_inp_) \
535 (((_inp_)->inp_flags & (INP_FLOW_CONTROLLED | INP_FLOW_SUSPENDED)) != 0)
537 #endif /* BSD_KERNEL_PRIVATE */
539 /* flags in inp_flags: */
540 #ifdef BSD_KERNEL_PRIVATE
541 #define INP_RECVOPTS 0x01 /* receive incoming IP options */
542 #define INP_RECVRETOPTS 0x02 /* receive IP options for reply */
543 #define INP_RECVDSTADDR 0x04 /* receive IP dst address */
544 #define INP_HDRINCL 0x08 /* user supplies entire IP header */
545 #define INP_HIGHPORT 0x10 /* user wants "high" port binding */
546 #define INP_LOWPORT 0x20 /* user wants "low" port binding */
547 #endif /* BSD_KERNEL_PRIVATE */
548 #define INP_ANONPORT 0x40 /* port chosen for user */
549 #ifdef BSD_KERNEL_PRIVATE
550 #define INP_RECVIF 0x80 /* receive incoming interface */
551 #define INP_MTUDISC 0x100 /* user can do MTU discovery */
553 #define INP_STRIPHDR 0x200 /* Strip headers in raw_ip, for OT support */
555 #define INP_RECV_ANYIF 0x400 /* don't restrict inbound interface */
556 #endif /* BSD_KERNEL_PRIVATE */
557 #define INP_INADDR_ANY 0x800 /* local address wasn't specified */
559 #ifdef BSD_KERNEL_PRIVATE
560 #define INP_RECVTTL 0x1000
561 #define INP_UDP_NOCKSUM 0x2000 /* Turn off outbound UDP checksum */
562 #define INP_BOUND_IF 0x4000 /* bind socket to an ifindex */
563 #endif /* BSD_KERNEL_PRIVATE */
565 #define IN6P_IPV6_V6ONLY 0x8000 /* restrict AF_INET6 socket for v6 */
567 #ifdef BSD_KERNEL_PRIVATE
568 #define IN6P_PKTINFO 0x10000 /* receive IP6 dst and I/F */
569 #define IN6P_HOPLIMIT 0x20000 /* receive hoplimit */
570 #define IN6P_HOPOPTS 0x40000 /* receive hop-by-hop options */
571 #define IN6P_DSTOPTS 0x80000 /* receive dst options after rthdr */
572 #define IN6P_RTHDR 0x100000 /* receive routing header */
573 #define IN6P_RTHDRDSTOPTS 0x200000 /* receive dstoptions before rthdr */
574 #define IN6P_TCLASS 0x400000 /* receive traffic class value */
575 #define IN6P_AUTOFLOWLABEL 0x800000 /* attach flowlabel automatically */
576 #endif /* BSD_KERNEL_PRIVATE */
578 #define IN6P_BINDV6ONLY 0x1000000 /* do not grab IPv4 traffic */
580 #ifdef BSD_KERNEL_PRIVATE
581 #define IN6P_RFC2292 0x2000000 /* used RFC2292 API on the socket */
582 #define IN6P_MTU 0x4000000 /* receive path MTU */
583 #define INP_PKTINFO 0x8000000 /* receive and send PKTINFO for IPv4 */
584 #define INP_FLOW_SUSPENDED 0x10000000 /* flow suspended */
585 #define INP_NO_IFT_CELLULAR 0x20000000 /* do not use IFT_CELLULAR route */
586 #define INP_FLOW_CONTROLLED 0x40000000 /* flow controlled */
587 #define INP_FC_FEEDBACK 0x80000000 /* got interface flow adv feedback */
589 #define INP_CONTROLOPTS (INP_RECVOPTS|INP_RECVRETOPTS|INP_RECVDSTADDR|\
590 INP_RECVIF|INP_RECVTTL|INP_PKTINFO|\
591 IN6P_PKTINFO|IN6P_HOPLIMIT|IN6P_HOPOPTS|\
592 IN6P_DSTOPTS|IN6P_RTHDR|IN6P_RTHDRDSTOPTS|\
593 IN6P_TCLASS|IN6P_RFC2292|IN6P_MTU)
595 #define INP_UNMAPPABLEOPTS (IN6P_HOPOPTS|IN6P_DSTOPTS|IN6P_RTHDR|\
596 IN6P_TCLASS|IN6P_AUTOFLOWLABEL)
598 /* for KAME src sync over BSD*'s */
599 #define IN6P_HIGHPORT INP_HIGHPORT
600 #define IN6P_LOWPORT INP_LOWPORT
601 #define IN6P_ANONPORT INP_ANONPORT
602 #define IN6P_RECVIF INP_RECVIF
603 #define IN6P_MTUDISC INP_MTUDISC
604 #define IN6P_RECV_ANYIF INP_RECV_ANYIF
605 #define IN6P_CONTROLOPTS INP_CONTROLOPTS
606 #define IN6P_NO_IFT_CELLULAR INP_NO_IFT_CELLULAR
608 /* Overflowed INP flags; use INP2 prefix to avoid misuse */
609 #define INP2_IN_FCTREE 0x2 /* in inp_fc_tree */
611 * socket AF version is {newer than,or include}
612 * actual datagram AF version
615 #define INPLOOKUP_WILDCARD 1
617 #define INPCB_ALL_OWNERS 0xff
618 #define INPCB_NO_OWNER 0x0
619 #define INPCB_OWNED_BY_X 0x80
620 #define INPCB_MAX_IDS 7
621 #endif /* __APPLE__ */
622 #endif /* BSD_KERNEL_PRIVATE */
624 #define sotoinpcb(so) ((struct inpcb *)(so)->so_pcb)
625 #define sotoin6pcb(so) sotoinpcb(so) /* for KAME src sync over BSD*'s */
627 #ifdef BSD_KERNEL_PRIVATE
628 #define INP_SOCKAF(so) so->so_proto->pr_domain->dom_family
629 #define INP_SOCKTYPE(so) so->so_proto->pr_type
631 #define INP_CHECK_SOCKAF(so, af) (INP_SOCKAF(so) == af)
632 #define INP_CHECK_SOCKTYPE(so, type) (INP_SOCKTYPE(so) == type)
634 extern int ipport_lowfirstauto
;
635 extern int ipport_lowlastauto
;
636 extern int ipport_firstauto
;
637 extern int ipport_lastauto
;
638 #endif /* BSD_KERNEL_PRIVATE */
640 extern int ipport_hifirstauto
;
641 extern int ipport_hilastauto
;
645 #ifdef BSD_KERNEL_PRIVATE
647 #define INPCB_STATE_INUSE 0x1 /* freshly allocated PCB, it's in use */
648 #define INPCB_STATE_CACHED 0x2 /* this pcb is sitting in a a cache */
649 #define INPCB_STATE_DEAD 0x3 /* should treat as gone, will be garbage collected and freed */
651 #define WNT_STOPUSING 0xffff /* marked as ready to be garbaged collected, should be treated as not found */
652 #define WNT_ACQUIRE 0x1 /* that pcb is being acquired, do not recycle this time */
653 #define WNT_RELEASE 0x2 /* release acquired mode, can be garbage collected when wantcnt is null */
655 extern void in_losing(struct inpcb
*);
656 extern void in_rtchange(struct inpcb
*, int);
657 extern int in_pcballoc(struct socket
*, struct inpcbinfo
*, struct proc
*);
658 extern int in_pcbbind(struct inpcb
*, struct sockaddr
*, struct proc
*);
659 extern int in_pcbconnect(struct inpcb
*, struct sockaddr
*, struct proc
*,
661 extern void in_pcbdetach(struct inpcb
*);
662 extern void in_pcbdispose (struct inpcb
*);
663 extern void in_pcbdisconnect(struct inpcb
*);
664 extern int in_pcbinshash(struct inpcb
*, int);
665 extern int in_pcbladdr(struct inpcb
*, struct sockaddr
*,
666 struct sockaddr_in
*, struct ifnet
**);
667 extern struct inpcb
*in_pcblookup_local(struct inpcbinfo
*, struct in_addr
,
669 extern struct inpcb
*in_pcblookup_local_and_cleanup(struct inpcbinfo
*,
670 struct in_addr
, u_int
, int);
671 extern struct inpcb
*in_pcblookup_hash(struct inpcbinfo
*, struct in_addr
,
672 u_int
, struct in_addr
, u_int
, int, struct ifnet
*);
673 extern int in_pcblookup_hash_exists(struct inpcbinfo
*, struct in_addr
,
674 u_int
, struct in_addr
, u_int
, int, uid_t
*, gid_t
*, struct ifnet
*);
675 extern void in_pcbnotifyall(struct inpcbinfo
*, struct in_addr
, int,
676 void (*)(struct inpcb
*, int));
677 extern void in_pcbrehash(struct inpcb
*);
678 extern int in_setpeeraddr(struct socket
*so
, struct sockaddr
**nam
);
679 extern int in_setsockaddr(struct socket
*so
, struct sockaddr
**nam
);
680 extern int in_pcb_checkstate(struct inpcb
*pcb
, int mode
, int locked
);
682 extern void in_pcbremlists(struct inpcb
*inp
);
683 extern void inpcb_to_compat(struct inpcb
*inp
,
684 struct inpcb_compat
*inp_compat
);
686 extern void inpcb_to_xinpcb64(struct inpcb
*inp
,
687 struct xinpcb64
*xinp
);
689 extern int get_pcblist_n(short , struct sysctl_req
*, struct inpcbinfo
*);
690 extern void inpcb_get_ports_used(unsigned int , uint8_t *, struct inpcbinfo
*);
692 #define INPCB_OPPORTUNISTIC_THROTTLEON 0x0001
693 #define INPCB_OPPORTUNISTIC_SETCMD 0x0002
694 extern uint32_t inpcb_count_opportunistic(unsigned int , struct inpcbinfo
*, u_int32_t
);
695 extern void inp_route_copyout(struct inpcb
*, struct route
*);
696 extern void inp_route_copyin(struct inpcb
*, struct route
*);
697 extern int inp_bindif(struct inpcb
*, unsigned int);
698 extern int inp_nocellular(struct inpcb
*, unsigned int);
699 extern u_int32_t
inp_calc_flowhash(struct inpcb
*);
700 extern void socket_flowadv_init(void);
702 /* Flags used by inp_fc_getinp */
703 #define INPFC_SOLOCKED 0x1
704 #define INPFC_REMOVE 0x2
705 extern struct inpcb
*inp_fc_getinp(u_int32_t
, u_int32_t
);
706 extern void inp_fc_feedback(struct inpcb
*);
707 extern void inp_reset_fc_state(struct inpcb
*);
708 extern int inp_set_fc_state(struct inpcb
*, int advcode
);
709 extern void inp_fc_unthrottle_tcp(struct inpcb
*);
710 extern int inp_flush(struct inpcb
*, int);
711 #endif /* BSD_KERNEL_PRIVATE */
713 #ifdef KERNEL_PRIVATE
714 extern void inp_clear_INP_INADDR_ANY(struct socket
*so
);
715 #endif /* KERNEL_PRIVATE */
717 #endif /* !_NETINET_IN_PCB_H_ */