2 * Copyright (c) 2000-2013 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>
76 #ifdef BSD_KERNEL_PRIVATE
77 #include <sys/bitstring.h>
79 #include <kern/locks.h>
80 #include <kern/zalloc.h>
81 #endif /* BSD_KERNEL_PRIVATE */
83 #include <netinet6/ipsec.h> /* for IPSEC */
85 #ifdef BSD_KERNEL_PRIVATE
87 * struct inpcb is the common protocol control block structure used in most
88 * IP transport protocols.
90 * Pointers to local and foreign host table entries, local and foreign socket
91 * numbers, and pointers up (to a socket structure) and down (to a
92 * protocol-specific control block) are stored here.
94 LIST_HEAD(inpcbhead
, inpcb
);
95 LIST_HEAD(inpcbporthead
, inpcbport
);
96 #endif /* BSD_KERNEL_PRIVATE */
97 typedef u_quad_t inp_gen_t
;
100 * PCB with AF_INET6 null bind'ed laddr can receive AF_INET input packet.
101 * So, AF_INET6 null laddr is also used as AF_INET null laddr, by utilizing
102 * the following structure.
104 struct in_addr_4in6
{
105 u_int32_t ia46_pad32
[3];
106 struct in_addr ia46_addr4
;
109 #ifdef BSD_KERNEL_PRIVATE
111 * NB: the zone allocator is type-stable EXCEPT FOR THE FIRST TWO LONGS
112 * of the structure. Therefore, it is important that the members in
113 * that position not contain any information which is required to be
130 * struct inpcb captures the network layer state for TCP, UDP and raw IPv6
131 * and IPv6 sockets. In the case of TCP, further per-connection state is
132 * hung off of inp_ppcb most of the time.
135 decl_lck_mtx_data(, inpcb_mtx
); /* inpcb per-socket mutex */
136 LIST_ENTRY(inpcb
) inp_hash
; /* hash list */
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 LIST_ENTRY(inpcb
) inp_portlist
; /* list for this PCB's local port */
142 RB_ENTRY(inpcb
) infc_link
; /* link for flowhash RB tree */
143 struct inpcbport
*inp_phd
; /* head of this list */
144 inp_gen_t inp_gencnt
; /* generation count of this instance */
145 int inp_hash_element
; /* array index of pcb's hash list */
146 int inp_wantcnt
; /* wanted count; atomically updated */
147 int inp_state
; /* state (INUSE/CACHED/DEAD) */
148 u_short inp_fport
; /* foreign port */
149 u_short inp_lport
; /* local port */
150 u_int32_t inp_flags
; /* generic IP/datagram flags */
151 u_int32_t inp_flags2
; /* generic IP/datagram flags #2 */
152 u_int32_t inp_flow
; /* IPv6 flow information */
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 */
160 struct ifnet
*inp_boundifp
; /* interface for INP_BOUND_IF */
161 struct ifnet
*inp_last_outifp
; /* last known outgoing interface */
162 u_int32_t inp_flowhash
; /* flow hash */
164 /* Protocol-dependent part */
166 /* foreign host table entry */
167 struct in_addr_4in6 inp46_foreign
;
168 struct in6_addr inp6_foreign
;
171 /* local host table entry */
172 struct in_addr_4in6 inp46_local
;
173 struct in6_addr inp6_local
;
176 /* placeholder for routing entry */
177 struct route inp4_route
;
178 struct route_in6 inp6_route
;
181 /* type of service proto */
184 struct mbuf
*inp4_options
;
185 /* IP multicast options */
186 struct ip_moptions
*inp4_moptions
;
190 struct mbuf
*inp6_options
;
191 /* IP6 options for outgoing packets */
192 struct ip6_pktopts
*inp6_outputopts
;
193 /* IP multicast options */
194 struct ip6_moptions
*inp6_moptions
;
195 /* ICMPv6 code type filter */
196 struct icmp6_filter
*inp6_icmp6filt
;
197 /* IPV6_CHECKSUM setsockopt */
202 caddr_t inp_saved_ppcb
; /* place to save pointer while cached */
204 struct label
*inp_label
; /* MAC label */
207 struct inpcbpolicy
*inp_sp
; /* for IPSec */
209 struct inp_stat
*inp_stat
;
210 struct inp_stat
*inp_cstat
; /* cellular data */
211 struct inp_stat
*inp_wstat
; /* Wi-Fi data */
212 u_int8_t inp_stat_store
[sizeof (struct inp_stat
) + sizeof (u_int64_t
)];
213 u_int8_t inp_cstat_store
[sizeof (struct inp_stat
) + sizeof (u_int64_t
)];
214 u_int8_t inp_wstat_store
[sizeof (struct inp_stat
) + sizeof (u_int64_t
)];
217 #define INP_ADD_STAT(_inp, _cnt_cellular, _cnt_wifi, _a, _n) do { \
218 locked_add_64(&((_inp)->inp_stat->_a), (_n)); \
220 locked_add_64(&((_inp)->inp_cstat->_a), (_n)); \
222 locked_add_64(&((_inp)->inp_wstat->_a), (_n)); \
224 #endif /* BSD_KERNEL_PRIVATE */
227 * Interface exported to userland by various protocols which use
228 * inpcbs. Hack alert -- only define if struct xsocket is in scope.
232 #if defined(__LP64__)
233 struct _inpcb_list_entry
{
237 #define _INPCB_PTR(x) u_int32_t
238 #define _INPCB_LIST_ENTRY(x) struct _inpcb_list_entry
239 #else /* !__LP64__ */
240 #define _INPCB_PTR(x) x
241 #define _INPCB_LIST_ENTRY(x) LIST_ENTRY(x)
242 #endif /* !__LP64__ */
244 #ifdef XNU_KERNEL_PRIVATE
246 * This is a copy of the inpcb as it shipped in Panther. This structure
247 * is filled out in a copy function. This allows the inpcb to change
248 * without breaking userland tools.
250 * CAUTION: Many fields may not be filled out. Fewer may be filled out
251 * in the future. Code defensively.
253 struct inpcb_compat
{
264 #endif /* KERNEL_PRIVATE */
265 _INPCB_LIST_ENTRY(inpcb
) inp_hash
; /* hash list */
266 struct in_addr reserved1
; /* reserved */
267 struct in_addr reserved2
; /* reserved */
268 u_short inp_fport
; /* foreign port */
269 u_short inp_lport
; /* local port */
270 _INPCB_LIST_ENTRY(inpcb
) inp_list
; /* list for all peer PCBs */
271 _INPCB_PTR(caddr_t
) inp_ppcb
; /* per-protocol pcb */
272 _INPCB_PTR(struct inpcbinfo
*) inp_pcbinfo
; /* PCB list info */
273 _INPCB_PTR(void *) inp_socket
; /* back pointer to socket */
274 u_char nat_owner
; /* Used to NAT TCP/UDP traffic */
275 u_int32_t nat_cookie
; /* Cookie stored and returned to NAT */
276 _INPCB_LIST_ENTRY(inpcb
) inp_portlist
; /* this PCB's local port list */
277 _INPCB_PTR(struct inpcbport
*) inp_phd
; /* head of this list */
278 inp_gen_t inp_gencnt
; /* generation count of this instance */
279 int inp_flags
; /* generic IP/datagram flags */
284 u_char inp_ip_ttl
; /* time to live proto */
285 u_char inp_ip_p
; /* protocol proto */
286 /* protocol dependent part */
288 /* foreign host table entry */
289 struct in_addr_4in6 inp46_foreign
;
290 struct in6_addr inp6_foreign
;
293 /* local host table entry */
294 struct in_addr_4in6 inp46_local
;
295 struct in6_addr inp6_local
;
298 /* placeholder for routing entry */
299 u_char inp4_route
[20];
300 u_char inp6_route
[32];
303 /* type of service proto */
306 _INPCB_PTR(struct mbuf
*) inp4_options
;
307 /* IP multicast options */
308 _INPCB_PTR(struct ip_moptions
*) inp4_moptions
;
313 _INPCB_PTR(struct mbuf
*) inp6_options
;
315 u_int8_t unused_uint8_1
;
316 ushort unused_uint16_1
;
317 /* IP6 options for outgoing packets */
318 _INPCB_PTR(struct ip6_pktopts
*) inp6_outputopts
;
319 /* IP multicast options */
320 _INPCB_PTR(struct ip6_moptions
*) inp6_moptions
;
321 /* ICMPv6 code type filter */
322 _INPCB_PTR(struct icmp6_filter
*) inp6_icmp6filt
;
323 /* IPV6_CHECKSUM setsockopt */
325 u_short inp6_ifindex
;
329 int hash_element
; /* Array index of pcb's hash list */
330 _INPCB_PTR(caddr_t
) inp_saved_ppcb
; /* pointer while cached */
331 _INPCB_PTR(struct inpcbpolicy
*) inp_sp
;
332 u_int32_t reserved
[3]; /* reserved */
336 u_int32_t xi_len
; /* length of this structure */
337 #ifdef XNU_KERNEL_PRIVATE
338 struct inpcb_compat xi_inp
;
342 struct xsocket xi_socket
;
343 u_quad_t xi_alignment_hack
;
346 struct inpcb64_list_entry
{
352 u_int64_t xi_len
; /* length of this structure */
354 u_short inp_fport
; /* foreign port */
355 u_short inp_lport
; /* local port */
356 struct inpcb64_list_entry inp_list
; /* list for all PCBs */
357 u_int64_t inp_ppcb
; /* ptr to per-protocol PCB */
358 u_int64_t inp_pcbinfo
; /* PCB list info */
359 struct inpcb64_list_entry inp_portlist
; /* this PCB's local port list */
360 u_int64_t inp_phd
; /* head of this list */
361 inp_gen_t inp_gencnt
; /* current generation count */
362 int inp_flags
; /* generic IP/datagram flags */
365 u_char inp_ip_ttl
; /* time to live */
366 u_char inp_ip_p
; /* protocol */
367 union { /* foreign host table entry */
368 struct in_addr_4in6 inp46_foreign
;
369 struct in6_addr inp6_foreign
;
371 union { /* local host table entry */
372 struct in_addr_4in6 inp46_local
;
373 struct in6_addr inp6_local
;
376 u_char inp4_ip_tos
; /* type of service */
381 u_short inp6_ifindex
;
384 struct xsocket64 xi_socket
;
385 u_quad_t xi_alignment_hack
;
389 struct xinpcb_list_entry
{
395 u_int32_t xi_len
; /* length of this structure */
396 u_int32_t xi_kind
; /* XSO_INPCB */
398 u_short inp_fport
; /* foreign port */
399 u_short inp_lport
; /* local port */
400 u_int64_t inp_ppcb
; /* pointer to per-protocol pcb */
401 inp_gen_t inp_gencnt
; /* generation count of this instance */
402 int inp_flags
; /* generic IP/datagram flags */
405 u_char inp_ip_ttl
; /* time to live */
406 u_char inp_ip_p
; /* protocol */
407 union { /* foreign host table entry */
408 struct in_addr_4in6 inp46_foreign
;
409 struct in6_addr inp6_foreign
;
411 union { /* local host table entry */
412 struct in_addr_4in6 inp46_local
;
413 struct in6_addr inp6_local
;
416 u_char inp4_ip_tos
; /* type of service */
421 u_short inp6_ifindex
;
424 u_int32_t inp_flowhash
;
429 u_int32_t xig_len
; /* length of this structure */
430 u_int xig_count
; /* number of PCBs at this time */
431 inp_gen_t xig_gen
; /* generation count at this time */
432 so_gen_t xig_sogen
; /* current socket generation count */
438 * These defines are for use with the inpcb.
442 #define inp_faddr inp_dependfaddr.inp46_foreign.ia46_addr4
443 #define inp_laddr inp_dependladdr.inp46_local.ia46_addr4
444 #define in6p_faddr inp_dependfaddr.inp6_foreign
445 #define in6p_laddr inp_dependladdr.inp6_local
447 #ifdef BSD_KERNEL_PRIVATE
448 #define inp_route inp_dependroute.inp4_route
449 #define inp_ip_tos inp_depend4.inp4_ip_tos
450 #define inp_options inp_depend4.inp4_options
451 #define inp_moptions inp_depend4.inp4_moptions
452 #define in6p_route inp_dependroute.inp6_route
453 #define in6p_ip6_hlim inp_depend6.inp6_hlim
454 #define in6p_hops inp_depend6.inp6_hops /* default hop limit */
455 #define in6p_ip6_nxt inp_ip_p
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
464 #define in6p_flags2 inp_flags2
465 #define in6p_socket inp_socket
466 #define in6p_lport inp_lport
467 #define in6p_fport inp_fport
468 #define in6p_ppcb inp_ppcb
469 #define in6p_state inp_state
470 #define in6p_wantcnt inp_wantcnt
471 #define in6p_last_outifp inp_last_outifp
474 #define in6p_sp inp_sp
478 LIST_ENTRY(inpcbport
) phd_hash
;
479 struct inpcbhead phd_pcblist
;
483 struct intimercount
{
484 u_int32_t intimer_lazy
; /* lazy requests for timer scheduling */
485 u_int32_t intimer_fast
; /* fast requests, can be coalesced */
486 u_int32_t intimer_nodelay
; /* fast requests, never coalesced */
489 typedef void (*inpcb_timer_func_t
)(struct inpcbinfo
*);
492 * Global data structure for each high-level protocol (UDP, TCP, ...) in both
493 * IPv4 and IPv6. Holds inpcb lists and information for managing them. Each
494 * pcbinfo is protected by a RW lock: ipi_lock.
496 * All INPCB pcbinfo entries are linked together via ipi_entry.
500 * Glue to all PCB infos, as well as garbage collector and
501 * timer callbacks, protected by inpcb_lock. Callout request
502 * counts are atomically updated.
504 TAILQ_ENTRY(inpcbinfo
) ipi_entry
;
505 inpcb_timer_func_t ipi_gc
;
506 inpcb_timer_func_t ipi_timer
;
507 struct intimercount ipi_gc_req
;
508 struct intimercount ipi_timer_req
;
511 * Per-protocol lock protecting pcb list, pcb count, etc.
516 * List and count of pcbs on the protocol.
518 struct inpcbhead
*ipi_listhead
;
522 * Count of pcbs marked with INP2_TIMEWAIT flag.
524 uint32_t ipi_twcount
;
527 * Generation count -- incremented each time a connection is
528 * allocated or freed.
533 * Fields associated with port lookup and allocation.
535 uint16_t ipi_lastport
;
536 uint16_t ipi_lastlow
;
540 * Zone from which inpcbs are allocated for this protocol.
542 struct zone
*ipi_zone
;
545 * Per-protocol hash of pcbs, hashed by local and foreign
546 * addresses and port numbers.
548 struct inpcbhead
*ipi_hashbase
;
552 * Per-protocol hash of pcbs, hashed by only local port number.
554 struct inpcbporthead
*ipi_porthashbase
;
555 u_long ipi_porthashmask
;
560 lck_attr_t
*ipi_lock_attr
;
561 lck_grp_t
*ipi_lock_grp
;
562 lck_grp_attr_t
*ipi_lock_grp_attr
;
565 #define INP_PCBHASH(faddr, lport, fport, mask) \
566 (((faddr) ^ ((faddr) >> 16) ^ ntohs((lport) ^ (fport))) & (mask))
567 #define INP_PCBPORTHASH(lport, mask) \
568 (ntohs((lport)) & (mask))
570 #define INP_IS_FLOW_CONTROLLED(_inp_) \
571 ((_inp_)->inp_flags & INP_FLOW_CONTROLLED)
572 #define INP_IS_FLOW_SUSPENDED(_inp_) \
573 (((_inp_)->inp_flags & INP_FLOW_SUSPENDED) || \
574 ((_inp_)->inp_socket->so_flags & SOF_SUSPENDED))
575 #define INP_WAIT_FOR_IF_FEEDBACK(_inp_) \
576 (((_inp_)->inp_flags & (INP_FLOW_CONTROLLED | INP_FLOW_SUSPENDED)) != 0)
578 #endif /* BSD_KERNEL_PRIVATE */
581 * Flags for inp_flags.
583 * Some of these are publicly defined for legacy reasons, as they are
584 * (unfortunately) used by certain applications to determine, at compile
585 * time, whether or not the OS supports certain features.
587 #ifdef BSD_KERNEL_PRIVATE
588 #define INP_RECVOPTS 0x00000001 /* receive incoming IP options */
589 #define INP_RECVRETOPTS 0x00000002 /* receive IP options for reply */
590 #define INP_RECVDSTADDR 0x00000004 /* receive IP dst address */
591 #define INP_HDRINCL 0x00000008 /* user supplies entire IP header */
592 #define INP_HIGHPORT 0x00000010 /* user wants "high" port binding */
593 #define INP_LOWPORT 0x00000020 /* user wants "low" port binding */
594 #endif /* BSD_KERNEL_PRIVATE */
596 #define INP_ANONPORT 0x00000040 /* port chosen for user */
598 #ifdef BSD_KERNEL_PRIVATE
599 #define INP_RECVIF 0x00000080 /* receive incoming interface */
600 #define INP_MTUDISC 0x00000100 /* unused */
601 #define INP_STRIPHDR 0x00000200 /* strip hdrs in raw_ip (for OT) */
602 #define INP_RECV_ANYIF 0x00000400 /* don't restrict inbound iface */
603 #define INP_INADDR_ANY 0x00000800 /* local address wasn't specified */
604 #define INP_IN6ADDR_ANY INP_INADDR_ANY
605 #define INP_RECVTTL 0x00001000 /* receive incoming IP TTL */
606 #define INP_UDP_NOCKSUM 0x00002000 /* turn off outbound UDP checksum */
607 #define INP_BOUND_IF 0x00004000 /* bind socket to an interface */
608 #endif /* BSD_KERNEL_PRIVATE */
610 #define IN6P_IPV6_V6ONLY 0x00008000 /* restrict AF_INET6 socket for v6 */
612 #ifdef BSD_KERNEL_PRIVATE
613 #define IN6P_PKTINFO 0x00010000 /* receive IP6 dst and I/F */
614 #define IN6P_HOPLIMIT 0x00020000 /* receive hoplimit */
615 #define IN6P_HOPOPTS 0x00040000 /* receive hop-by-hop options */
616 #define IN6P_DSTOPTS 0x00080000 /* receive dst options after rthdr */
617 #define IN6P_RTHDR 0x00100000 /* receive routing header */
618 #define IN6P_RTHDRDSTOPTS 0x00200000 /* receive dstoptions before rthdr */
619 #define IN6P_TCLASS 0x00400000 /* receive traffic class value */
620 #define IN6P_AUTOFLOWLABEL 0x00800000 /* attach flowlabel automatically */
621 #endif /* BSD_KERNEL_PRIVATE */
623 #define IN6P_BINDV6ONLY 0x01000000 /* do not grab IPv4 traffic */
625 #ifdef BSD_KERNEL_PRIVATE
626 #define IN6P_RFC2292 0x02000000 /* used RFC2292 API on the socket */
627 #define IN6P_MTU 0x04000000 /* receive path MTU */
628 #define INP_PKTINFO 0x08000000 /* rcv and snd PKTINFO for IPv4 */
629 #define INP_FLOW_SUSPENDED 0x10000000 /* flow suspended */
630 #define INP_NO_IFT_CELLULAR 0x20000000 /* do not use cellular interface */
631 #define INP_FLOW_CONTROLLED 0x40000000 /* flow controlled */
632 #define INP_FC_FEEDBACK 0x80000000 /* got interface flow adv feedback */
634 #define INP_CONTROLOPTS \
635 (INP_RECVOPTS|INP_RECVRETOPTS|INP_RECVDSTADDR|INP_RECVIF|INP_RECVTTL| \
636 INP_PKTINFO|IN6P_PKTINFO|IN6P_HOPLIMIT|IN6P_HOPOPTS|IN6P_DSTOPTS| \
637 IN6P_RTHDR|IN6P_RTHDRDSTOPTS|IN6P_TCLASS|IN6P_RFC2292|IN6P_MTU)
639 #define INP_UNMAPPABLEOPTS \
640 (IN6P_HOPOPTS|IN6P_DSTOPTS|IN6P_RTHDR| IN6P_TCLASS|IN6P_AUTOFLOWLABEL)
643 * Flags for inp_flags2.
645 * Overflowed INP flags; use INP2 prefix to avoid misuse.
647 #define INP2_TIMEWAIT 0x00000001 /* in TIMEWAIT */
648 #define INP2_IN_FCTREE 0x00000002 /* in inp_fc_tree */
649 #define INP2_WANT_FLOW_DIVERT 0x00000004 /* flow divert is desired */
652 * Flags passed to in_pcblookup*() functions.
654 #define INPLOOKUP_WILDCARD 1
656 #define sotoinpcb(so) ((struct inpcb *)(so)->so_pcb)
657 #define sotoin6pcb(so) sotoinpcb(so)
661 extern int ipport_lowfirstauto
;
662 extern int ipport_lowlastauto
;
663 extern int ipport_firstauto
;
664 extern int ipport_lastauto
;
665 extern int ipport_hifirstauto
;
666 extern int ipport_hilastauto
;
668 /* freshly allocated PCB, it's in use */
669 #define INPCB_STATE_INUSE 0x1
670 /* this pcb is sitting in a a cache */
671 #define INPCB_STATE_CACHED 0x2
672 /* should treat as gone, will be garbage collected and freed */
673 #define INPCB_STATE_DEAD 0x3
675 /* marked as ready to be garbaged collected, should be treated as not found */
676 #define WNT_STOPUSING 0xffff
677 /* that pcb is being acquired, do not recycle this time */
678 #define WNT_ACQUIRE 0x1
679 /* release acquired mode, can be garbage collected when wantcnt is null */
680 #define WNT_RELEASE 0x2
682 extern void in_pcbinit(void);
683 extern void in_pcbinfo_attach(struct inpcbinfo
*);
684 extern int in_pcbinfo_detach(struct inpcbinfo
*);
686 /* type of timer to be scheduled by inpcb_gc_sched and inpcb_timer_sched */
688 INPCB_TIMER_LAZY
= 0x1,
692 extern void inpcb_gc_sched(struct inpcbinfo
*, u_int32_t type
);
693 extern void inpcb_timer_sched(struct inpcbinfo
*, u_int32_t type
);
695 extern void in_losing(struct inpcb
*);
696 extern void in_rtchange(struct inpcb
*, int);
697 extern int in_pcballoc(struct socket
*, struct inpcbinfo
*, struct proc
*);
698 extern int in_pcbbind(struct inpcb
*, struct sockaddr
*, struct proc
*);
699 extern int in_pcbconnect(struct inpcb
*, struct sockaddr
*, struct proc
*,
700 unsigned int, struct ifnet
**);
701 extern void in_pcbdetach(struct inpcb
*);
702 extern void in_pcbdispose(struct inpcb
*);
703 extern void in_pcbdisconnect(struct inpcb
*);
704 extern int in_pcbinshash(struct inpcb
*, int);
705 extern int in_pcbladdr(struct inpcb
*, struct sockaddr
*, struct in_addr
*,
706 unsigned int, struct ifnet
**);
707 extern struct inpcb
*in_pcblookup_local(struct inpcbinfo
*, struct in_addr
,
709 extern struct inpcb
*in_pcblookup_local_and_cleanup(struct inpcbinfo
*,
710 struct in_addr
, u_int
, int);
711 extern struct inpcb
*in_pcblookup_hash(struct inpcbinfo
*, struct in_addr
,
712 u_int
, struct in_addr
, u_int
, int, struct ifnet
*);
713 extern int in_pcblookup_hash_exists(struct inpcbinfo
*, struct in_addr
,
714 u_int
, struct in_addr
, u_int
, int, uid_t
*, gid_t
*, struct ifnet
*);
715 extern void in_pcbnotifyall(struct inpcbinfo
*, struct in_addr
, int,
716 void (*)(struct inpcb
*, int));
717 extern void in_pcbrehash(struct inpcb
*);
718 extern int in_getpeeraddr(struct socket
*, struct sockaddr
**);
719 extern int in_getpeeraddr_s(struct socket
*, struct sockaddr_storage
*);
720 extern int in_getsockaddr(struct socket
*, struct sockaddr
**);
721 extern int in_getsockaddr_s(struct socket
*, struct sockaddr_storage
*);
722 extern int in_pcb_checkstate(struct inpcb
*, int, int);
723 extern void in_pcbremlists(struct inpcb
*);
724 extern void inpcb_to_compat(struct inpcb
*, struct inpcb_compat
*);
725 extern void inpcb_to_xinpcb64(struct inpcb
*, struct xinpcb64
*);
726 extern int get_pcblist_n(short, struct sysctl_req
*, struct inpcbinfo
*);
727 extern void inpcb_get_ports_used(u_int32_t
, int, u_int32_t
, bitstr_t
*,
729 #define INPCB_OPPORTUNISTIC_THROTTLEON 0x0001
730 #define INPCB_OPPORTUNISTIC_SETCMD 0x0002
731 extern uint32_t inpcb_count_opportunistic(unsigned int, struct inpcbinfo
*,
733 extern uint32_t inpcb_find_anypcb_byaddr(struct ifaddr
*, struct inpcbinfo
*);
734 extern void inp_route_copyout(struct inpcb
*, struct route
*);
735 extern void inp_route_copyin(struct inpcb
*, struct route
*);
736 extern int inp_bindif(struct inpcb
*, unsigned int, struct ifnet
**);
737 extern void inp_set_nocellular(struct inpcb
*);
738 extern void inp_clear_nocellular(struct inpcb
*);
740 extern void inp_set_flow_divert(struct inpcb
*);
741 extern void inp_clear_flow_divert(struct inpcb
*);
742 #endif /* FLOW_DIVERT */
743 extern u_int32_t
inp_calc_flowhash(struct inpcb
*);
744 extern void inp_reset_fc_state(struct inpcb
*);
745 extern int inp_set_fc_state(struct inpcb
*, int advcode
);
746 extern void inp_fc_unthrottle_tcp(struct inpcb
*);
747 extern void inp_flowadv(uint32_t);
748 extern int inp_flush(struct inpcb
*, int);
749 extern int inp_findinpcb_procinfo(struct inpcbinfo
*, uint32_t, struct so_procinfo
*);
750 extern void inp_get_soprocinfo(struct inpcb
*, struct so_procinfo
*);
751 extern int inp_update_policy(struct inpcb
*);
752 extern boolean_t
inp_restricted(struct inpcb
*, struct ifnet
*);
753 #endif /* BSD_KERNEL_PRIVATE */
754 #ifdef KERNEL_PRIVATE
755 /* exported for PPP */
756 extern void inp_clear_INP_INADDR_ANY(struct socket
*);
757 #endif /* KERNEL_PRIVATE */
758 #endif /* !_NETINET_IN_PCB_H_ */