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