1 /*- 2 * Copyright (c) 1982, 1986, 1990, 1993 3 * The Regents of the University of California. 4 * Copyright (c) 2010-2011 Juniper Networks, Inc. 5 * All rights reserved. 6 * 7 * Portions of this software were developed by Robert N. M. Watson under 8 * contract to Juniper Networks, Inc. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 4. Neither the name of the University nor the names of its contributors 19 * may be used to endorse or promote products derived from this software 20 * without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 * 34 * @(#)in_pcb.h 8.1 (Berkeley) 6/10/93 35 * $FreeBSD$ 36 */ 37 38 #ifndef _NETINET_IN_PCB_H_ 39 #define _NETINET_IN_PCB_H_ 40 41 #include <sys/queue.h> 42 #include <sys/_lock.h> 43 #include <sys/_mutex.h> 44 #include <sys/_rwlock.h> 45 46 #ifdef _KERNEL 47 #include <sys/lock.h> 48 #include <sys/rwlock.h> 49 #include <net/vnet.h> 50 #include <vm/uma.h> 51 #endif 52 53 #define in6pcb inpcb /* for KAME src sync over BSD*'s */ 54 #define in6p_sp inp_sp /* for KAME src sync over BSD*'s */ 55 struct inpcbpolicy; 56 57 /* 58 * struct inpcb is the common protocol control block structure used in most 59 * IP transport protocols. 60 * 61 * Pointers to local and foreign host table entries, local and foreign socket 62 * numbers, and pointers up (to a socket structure) and down (to a 63 * protocol-specific control block) are stored here. 64 */ 65 LIST_HEAD(inpcbhead, inpcb); 66 LIST_HEAD(inpcbporthead, inpcbport); 67 typedef u_quad_t inp_gen_t; 68 69 /* 70 * PCB with AF_INET6 null bind'ed laddr can receive AF_INET input packet. 71 * So, AF_INET6 null laddr is also used as AF_INET null laddr, by utilizing 72 * the following structure. 73 */ 74 struct in_addr_4in6 { 75 u_int32_t ia46_pad32[3]; 76 struct in_addr ia46_addr4; 77 }; 78 79 /* 80 * NOTE: ipv6 addrs should be 64-bit aligned, per RFC 2553. in_conninfo has 81 * some extra padding to accomplish this. 82 */ 83 struct in_endpoints { 84 u_int16_t ie_fport; /* foreign port */ 85 u_int16_t ie_lport; /* local port */ 86 /* protocol dependent part, local and foreign addr */ 87 union { 88 /* foreign host table entry */ 89 struct in_addr_4in6 ie46_foreign; 90 struct in6_addr ie6_foreign; 91 } ie_dependfaddr; 92 union { 93 /* local host table entry */ 94 struct in_addr_4in6 ie46_local; 95 struct in6_addr ie6_local; 96 } ie_dependladdr; 97 }; 98 #define ie_faddr ie_dependfaddr.ie46_foreign.ia46_addr4 99 #define ie_laddr ie_dependladdr.ie46_local.ia46_addr4 100 #define ie6_faddr ie_dependfaddr.ie6_foreign 101 #define ie6_laddr ie_dependladdr.ie6_local 102 103 /* 104 * XXX The defines for inc_* are hacks and should be changed to direct 105 * references. 106 */ 107 struct in_conninfo { 108 u_int8_t inc_flags; 109 u_int8_t inc_len; 110 u_int16_t inc_fibnum; /* XXX was pad, 16 bits is plenty */ 111 /* protocol dependent part */ 112 struct in_endpoints inc_ie; 113 }; 114 115 /* 116 * Flags for inc_flags. 117 */ 118 #define INC_ISIPV6 0x01 119 120 #define inc_isipv6 inc_flags /* temp compatability */ 121 #define inc_fport inc_ie.ie_fport 122 #define inc_lport inc_ie.ie_lport 123 #define inc_faddr inc_ie.ie_faddr 124 #define inc_laddr inc_ie.ie_laddr 125 #define inc6_faddr inc_ie.ie6_faddr 126 #define inc6_laddr inc_ie.ie6_laddr 127 128 struct icmp6_filter; 129 130 /*- 131 * struct inpcb captures the network layer state for TCP, UDP, and raw IPv4 132 * and IPv6 sockets. In the case of TCP, further per-connection state is 133 * hung off of inp_ppcb most of the time. Almost all fields of struct inpcb 134 * are static after creation or protected by a per-inpcb rwlock, inp_lock. A 135 * few fields also require the global pcbinfo lock for the inpcb to be held, 136 * when modified, such as the global connection lists and hashes, as well as 137 * binding information (which affects which hash a connection is on). This 138 * model means that connections can be looked up without holding the 139 * per-connection lock, which is important for performance when attempting to 140 * find the connection for a packet given its IP and port tuple. Writing to 141 * these fields that write locks be held on both the inpcb and global locks. 142 * 143 * Key: 144 * (c) - Constant after initialization 145 * (g) - Protected by the pcbgroup lock 146 * (i) - Protected by the inpcb lock 147 * (p) - Protected by the pcbinfo lock for the inpcb 148 * (s) - Protected by another subsystem's locks 149 * (x) - Undefined locking 150 * 151 * A few other notes: 152 * 153 * When a read lock is held, stability of the field is guaranteed; to write 154 * to a field, a write lock must generally be held. 155 * 156 * netinet/netinet6-layer code should not assume that the inp_socket pointer 157 * is safe to dereference without inp_lock being held, even for protocols 158 * other than TCP (where the inpcb persists during TIMEWAIT even after the 159 * socket has been freed), or there may be close(2)-related races. 160 * 161 * The inp_vflag field is overloaded, and would otherwise ideally be (c). 162 */ 163 struct inpcb { 164 LIST_ENTRY(inpcb) inp_hash; /* (i/p) hash list */ 165 LIST_ENTRY(inpcb) inp_pcbgrouphash; /* (g/i) hash list */ 166 LIST_ENTRY(inpcb) inp_list; /* (i/p) list for all PCBs for proto */ 167 void *inp_ppcb; /* (i) pointer to per-protocol pcb */ 168 struct inpcbinfo *inp_pcbinfo; /* (c) PCB list info */ 169 struct inpcbgroup *inp_pcbgroup; /* (g/i) PCB group list */ 170 LIST_ENTRY(inpcb) inp_pcbgroup_wild; /* (g/i/p) group wildcard entry */ 171 struct socket *inp_socket; /* (i) back pointer to socket */ 172 struct ucred *inp_cred; /* (c) cache of socket cred */ 173 u_int32_t inp_flow; /* (i) IPv6 flow information */ 174 int inp_flags; /* (i) generic IP/datagram flags */ 175 int inp_flags2; /* (i) generic IP/datagram flags #2*/ 176 u_char inp_vflag; /* (i) IP version flag (v4/v6) */ 177 u_char inp_ip_ttl; /* (i) time to live proto */ 178 u_char inp_ip_p; /* (c) protocol proto */ 179 u_char inp_ip_minttl; /* (i) minimum TTL or drop */ 180 uint32_t inp_flowid; /* (x) flow id / queue id */ 181 u_int inp_refcount; /* (i) refcount */ 182 void *inp_pspare[4]; /* (x) rtentry / general use */ 183 u_int inp_ispare[4]; /* general use */ 184 185 /* Local and foreign ports, local and foreign addr. */ 186 struct in_conninfo inp_inc; /* (i/p) list for PCB's local port */ 187 188 /* MAC and IPSEC policy information. */ 189 struct label *inp_label; /* (i) MAC label */ 190 struct inpcbpolicy *inp_sp; /* (s) for IPSEC */ 191 192 /* Protocol-dependent part; options. */ 193 struct { 194 u_char inp4_ip_tos; /* (i) type of service proto */ 195 struct mbuf *inp4_options; /* (i) IP options */ 196 struct ip_moptions *inp4_moptions; /* (i) IP mcast options */ 197 } inp_depend4; 198 struct { 199 /* (i) IP options */ 200 struct mbuf *inp6_options; 201 /* (i) IP6 options for outgoing packets */ 202 struct ip6_pktopts *inp6_outputopts; 203 /* (i) IP multicast options */ 204 struct ip6_moptions *inp6_moptions; 205 /* (i) ICMPv6 code type filter */ 206 struct icmp6_filter *inp6_icmp6filt; 207 /* (i) IPV6_CHECKSUM setsockopt */ 208 int inp6_cksum; 209 short inp6_hops; 210 } inp_depend6; 211 LIST_ENTRY(inpcb) inp_portlist; /* (i/p) */ 212 struct inpcbport *inp_phd; /* (i/p) head of this list */ 213 #define inp_zero_size offsetof(struct inpcb, inp_gencnt) 214 inp_gen_t inp_gencnt; /* (c) generation count */ 215 struct llentry *inp_lle; /* cached L2 information */ 216 struct rtentry *inp_rt; /* cached L3 information */ 217 struct rwlock inp_lock; 218 }; 219 #define inp_fport inp_inc.inc_fport 220 #define inp_lport inp_inc.inc_lport 221 #define inp_faddr inp_inc.inc_faddr 222 #define inp_laddr inp_inc.inc_laddr 223 #define inp_ip_tos inp_depend4.inp4_ip_tos 224 #define inp_options inp_depend4.inp4_options 225 #define inp_moptions inp_depend4.inp4_moptions 226 227 #define in6p_faddr inp_inc.inc6_faddr 228 #define in6p_laddr inp_inc.inc6_laddr 229 #define in6p_hops inp_depend6.inp6_hops /* default hop limit */ 230 #define in6p_flowinfo inp_flow 231 #define in6p_options inp_depend6.inp6_options 232 #define in6p_outputopts inp_depend6.inp6_outputopts 233 #define in6p_moptions inp_depend6.inp6_moptions 234 #define in6p_icmp6filt inp_depend6.inp6_icmp6filt 235 #define in6p_cksum inp_depend6.inp6_cksum 236 237 #define inp_vnet inp_pcbinfo->ipi_vnet 238 239 /* 240 * The range of the generation count, as used in this implementation, is 9e19. 241 * We would have to create 300 billion connections per second for this number 242 * to roll over in a year. This seems sufficiently unlikely that we simply 243 * don't concern ourselves with that possibility. 244 */ 245 246 /* 247 * Interface exported to userland by various protocols which use inpcbs. Hack 248 * alert -- only define if struct xsocket is in scope. 249 */ 250 #ifdef _SYS_SOCKETVAR_H_ 251 struct xinpcb { 252 size_t xi_len; /* length of this structure */ 253 struct inpcb xi_inp; 254 struct xsocket xi_socket; 255 u_quad_t xi_alignment_hack; 256 }; 257 258 struct xinpgen { 259 size_t xig_len; /* length of this structure */ 260 u_int xig_count; /* number of PCBs at this time */ 261 inp_gen_t xig_gen; /* generation count at this time */ 262 so_gen_t xig_sogen; /* socket generation count at this time */ 263 }; 264 #endif /* _SYS_SOCKETVAR_H_ */ 265 266 struct inpcbport { 267 LIST_ENTRY(inpcbport) phd_hash; 268 struct inpcbhead phd_pcblist; 269 u_short phd_port; 270 }; 271 272 /*- 273 * Global data structure for each high-level protocol (UDP, TCP, ...) in both 274 * IPv4 and IPv6. Holds inpcb lists and information for managing them. 275 * 276 * Each pcbinfo is protected by two locks: ipi_lock and ipi_hash_lock, 277 * the former covering mutable global fields (such as the global pcb list), 278 * and the latter covering the hashed lookup tables. The lock order is: 279 * 280 * ipi_lock (before) inpcb locks (before) {ipi_hash_lock, pcbgroup locks} 281 * 282 * Locking key: 283 * 284 * (c) Constant or nearly constant after initialisation 285 * (g) Locked by ipi_lock 286 * (h) Read using either ipi_hash_lock or inpcb lock; write requires both 287 * (p) Protected by one or more pcbgroup locks 288 * (x) Synchronisation properties poorly defined 289 */ 290 struct inpcbinfo { 291 /* 292 * Global lock protecting global inpcb list, inpcb count, etc. 293 */ 294 struct rwlock ipi_lock; 295 296 /* 297 * Global list of inpcbs on the protocol. 298 */ 299 struct inpcbhead *ipi_listhead; /* (g) */ 300 u_int ipi_count; /* (g) */ 301 302 /* 303 * Generation count -- incremented each time a connection is allocated 304 * or freed. 305 */ 306 u_quad_t ipi_gencnt; /* (g) */ 307 308 /* 309 * Fields associated with port lookup and allocation. 310 */ 311 u_short ipi_lastport; /* (x) */ 312 u_short ipi_lastlow; /* (x) */ 313 u_short ipi_lasthi; /* (x) */ 314 315 /* 316 * UMA zone from which inpcbs are allocated for this protocol. 317 */ 318 struct uma_zone *ipi_zone; /* (c) */ 319 320 /* 321 * Connection groups associated with this protocol. These fields are 322 * constant, but pcbgroup structures themselves are protected by 323 * per-pcbgroup locks. 324 */ 325 struct inpcbgroup *ipi_pcbgroups; /* (c) */ 326 u_int ipi_npcbgroups; /* (c) */ 327 u_int ipi_hashfields; /* (c) */ 328 329 /* 330 * Global lock protecting non-pcbgroup hash lookup tables. 331 */ 332 struct rwlock ipi_hash_lock; 333 334 /* 335 * Global hash of inpcbs, hashed by local and foreign addresses and 336 * port numbers. 337 */ 338 struct inpcbhead *ipi_hashbase; /* (h) */ 339 u_long ipi_hashmask; /* (h) */ 340 341 /* 342 * Global hash of inpcbs, hashed by only local port number. 343 */ 344 struct inpcbporthead *ipi_porthashbase; /* (h) */ 345 u_long ipi_porthashmask; /* (h) */ 346 347 /* 348 * List of wildcard inpcbs for use with pcbgroups. In the past, was 349 * per-pcbgroup but is now global. All pcbgroup locks must be held 350 * to modify the list, so any is sufficient to read it. 351 */ 352 struct inpcbhead *ipi_wildbase; /* (p) */ 353 u_long ipi_wildmask; /* (p) */ 354 355 /* 356 * Pointer to network stack instance 357 */ 358 struct vnet *ipi_vnet; /* (c) */ 359 360 /* 361 * general use 2 362 */ 363 void *ipi_pspare[2]; 364 }; 365 366 /* 367 * Connection groups hold sets of connections that have similar CPU/thread 368 * affinity. Each connection belongs to exactly one connection group. 369 */ 370 struct inpcbgroup { 371 /* 372 * Per-connection group hash of inpcbs, hashed by local and foreign 373 * addresses and port numbers. 374 */ 375 struct inpcbhead *ipg_hashbase; /* (c) */ 376 u_long ipg_hashmask; /* (c) */ 377 378 /* 379 * Notional affinity of this pcbgroup. 380 */ 381 u_int ipg_cpu; /* (p) */ 382 383 /* 384 * Per-connection group lock, not to be confused with ipi_lock. 385 * Protects the hash table hung off the group, but also the global 386 * wildcard list in inpcbinfo. 387 */ 388 struct mtx ipg_lock; 389 } __aligned(CACHE_LINE_SIZE); 390 391 #define INP_LOCK_INIT(inp, d, t) \ 392 rw_init_flags(&(inp)->inp_lock, (t), RW_RECURSE | RW_DUPOK) 393 #define INP_LOCK_DESTROY(inp) rw_destroy(&(inp)->inp_lock) 394 #define INP_RLOCK(inp) rw_rlock(&(inp)->inp_lock) 395 #define INP_WLOCK(inp) rw_wlock(&(inp)->inp_lock) 396 #define INP_TRY_RLOCK(inp) rw_try_rlock(&(inp)->inp_lock) 397 #define INP_TRY_WLOCK(inp) rw_try_wlock(&(inp)->inp_lock) 398 #define INP_RUNLOCK(inp) rw_runlock(&(inp)->inp_lock) 399 #define INP_WUNLOCK(inp) rw_wunlock(&(inp)->inp_lock) 400 #define INP_TRY_UPGRADE(inp) rw_try_upgrade(&(inp)->inp_lock) 401 #define INP_DOWNGRADE(inp) rw_downgrade(&(inp)->inp_lock) 402 #define INP_WLOCKED(inp) rw_wowned(&(inp)->inp_lock) 403 #define INP_LOCK_ASSERT(inp) rw_assert(&(inp)->inp_lock, RA_LOCKED) 404 #define INP_RLOCK_ASSERT(inp) rw_assert(&(inp)->inp_lock, RA_RLOCKED) 405 #define INP_WLOCK_ASSERT(inp) rw_assert(&(inp)->inp_lock, RA_WLOCKED) 406 #define INP_UNLOCK_ASSERT(inp) rw_assert(&(inp)->inp_lock, RA_UNLOCKED) 407 408 #ifdef _KERNEL 409 /* 410 * These locking functions are for inpcb consumers outside of sys/netinet, 411 * more specifically, they were added for the benefit of TOE drivers. The 412 * macros are reserved for use by the stack. 413 */ 414 void inp_wlock(struct inpcb *); 415 void inp_wunlock(struct inpcb *); 416 void inp_rlock(struct inpcb *); 417 void inp_runlock(struct inpcb *); 418 419 #ifdef INVARIANTS 420 void inp_lock_assert(struct inpcb *); 421 void inp_unlock_assert(struct inpcb *); 422 #else 423 static __inline void 424 inp_lock_assert(struct inpcb *inp __unused) 425 { 426 } 427 428 static __inline void 429 inp_unlock_assert(struct inpcb *inp __unused) 430 { 431 } 432 433 #endif 434 435 void inp_apply_all(void (*func)(struct inpcb *, void *), void *arg); 436 int inp_ip_tos_get(const struct inpcb *inp); 437 void inp_ip_tos_set(struct inpcb *inp, int val); 438 struct socket * 439 inp_inpcbtosocket(struct inpcb *inp); 440 struct tcpcb * 441 inp_inpcbtotcpcb(struct inpcb *inp); 442 void inp_4tuple_get(struct inpcb *inp, uint32_t *laddr, uint16_t *lp, 443 uint32_t *faddr, uint16_t *fp); 444 445 #endif /* _KERNEL */ 446 447 #define INP_INFO_LOCK_INIT(ipi, d) \ 448 rw_init_flags(&(ipi)->ipi_lock, (d), RW_RECURSE) 449 #define INP_INFO_LOCK_DESTROY(ipi) rw_destroy(&(ipi)->ipi_lock) 450 #define INP_INFO_RLOCK(ipi) rw_rlock(&(ipi)->ipi_lock) 451 #define INP_INFO_WLOCK(ipi) rw_wlock(&(ipi)->ipi_lock) 452 #define INP_INFO_TRY_RLOCK(ipi) rw_try_rlock(&(ipi)->ipi_lock) 453 #define INP_INFO_TRY_WLOCK(ipi) rw_try_wlock(&(ipi)->ipi_lock) 454 #define INP_INFO_TRY_UPGRADE(ipi) rw_try_upgrade(&(ipi)->ipi_lock) 455 #define INP_INFO_RUNLOCK(ipi) rw_runlock(&(ipi)->ipi_lock) 456 #define INP_INFO_WUNLOCK(ipi) rw_wunlock(&(ipi)->ipi_lock) 457 #define INP_INFO_LOCK_ASSERT(ipi) rw_assert(&(ipi)->ipi_lock, RA_LOCKED) 458 #define INP_INFO_RLOCK_ASSERT(ipi) rw_assert(&(ipi)->ipi_lock, RA_RLOCKED) 459 #define INP_INFO_WLOCK_ASSERT(ipi) rw_assert(&(ipi)->ipi_lock, RA_WLOCKED) 460 #define INP_INFO_UNLOCK_ASSERT(ipi) rw_assert(&(ipi)->ipi_lock, RA_UNLOCKED) 461 462 #define INP_HASH_LOCK_INIT(ipi, d) \ 463 rw_init_flags(&(ipi)->ipi_hash_lock, (d), 0) 464 #define INP_HASH_LOCK_DESTROY(ipi) rw_destroy(&(ipi)->ipi_hash_lock) 465 #define INP_HASH_RLOCK(ipi) rw_rlock(&(ipi)->ipi_hash_lock) 466 #define INP_HASH_WLOCK(ipi) rw_wlock(&(ipi)->ipi_hash_lock) 467 #define INP_HASH_RUNLOCK(ipi) rw_runlock(&(ipi)->ipi_hash_lock) 468 #define INP_HASH_WUNLOCK(ipi) rw_wunlock(&(ipi)->ipi_hash_lock) 469 #define INP_HASH_LOCK_ASSERT(ipi) rw_assert(&(ipi)->ipi_hash_lock, \ 470 RA_LOCKED) 471 #define INP_HASH_WLOCK_ASSERT(ipi) rw_assert(&(ipi)->ipi_hash_lock, \ 472 RA_WLOCKED) 473 474 #define INP_GROUP_LOCK_INIT(ipg, d) mtx_init(&(ipg)->ipg_lock, (d), NULL, \ 475 MTX_DEF | MTX_DUPOK) 476 #define INP_GROUP_LOCK_DESTROY(ipg) mtx_destroy(&(ipg)->ipg_lock) 477 478 #define INP_GROUP_LOCK(ipg) mtx_lock(&(ipg)->ipg_lock) 479 #define INP_GROUP_LOCK_ASSERT(ipg) mtx_assert(&(ipg)->ipg_lock, MA_OWNED) 480 #define INP_GROUP_UNLOCK(ipg) mtx_unlock(&(ipg)->ipg_lock) 481 482 #define INP_PCBHASH(faddr, lport, fport, mask) \ 483 (((faddr) ^ ((faddr) >> 16) ^ ntohs((lport) ^ (fport))) & (mask)) 484 #define INP_PCBPORTHASH(lport, mask) \ 485 (ntohs((lport)) & (mask)) 486 487 /* 488 * Flags for inp_vflags -- historically version flags only 489 */ 490 #define INP_IPV4 0x1 491 #define INP_IPV6 0x2 492 #define INP_IPV6PROTO 0x4 /* opened under IPv6 protocol */ 493 494 /* 495 * Flags for inp_flags. 496 */ 497 #define INP_RECVOPTS 0x00000001 /* receive incoming IP options */ 498 #define INP_RECVRETOPTS 0x00000002 /* receive IP options for reply */ 499 #define INP_RECVDSTADDR 0x00000004 /* receive IP dst address */ 500 #define INP_HDRINCL 0x00000008 /* user supplies entire IP header */ 501 #define INP_HIGHPORT 0x00000010 /* user wants "high" port binding */ 502 #define INP_LOWPORT 0x00000020 /* user wants "low" port binding */ 503 #define INP_ANONPORT 0x00000040 /* port chosen for user */ 504 #define INP_RECVIF 0x00000080 /* receive incoming interface */ 505 #define INP_MTUDISC 0x00000100 /* user can do MTU discovery */ 506 #define INP_FAITH 0x00000200 /* accept FAITH'ed connections */ 507 #define INP_RECVTTL 0x00000400 /* receive incoming IP TTL */ 508 #define INP_DONTFRAG 0x00000800 /* don't fragment packet */ 509 #define INP_BINDANY 0x00001000 /* allow bind to any address */ 510 #define INP_INHASHLIST 0x00002000 /* in_pcbinshash() has been called */ 511 #define IN6P_IPV6_V6ONLY 0x00008000 /* restrict AF_INET6 socket for v6 */ 512 #define IN6P_PKTINFO 0x00010000 /* receive IP6 dst and I/F */ 513 #define IN6P_HOPLIMIT 0x00020000 /* receive hoplimit */ 514 #define IN6P_HOPOPTS 0x00040000 /* receive hop-by-hop options */ 515 #define IN6P_DSTOPTS 0x00080000 /* receive dst options after rthdr */ 516 #define IN6P_RTHDR 0x00100000 /* receive routing header */ 517 #define IN6P_RTHDRDSTOPTS 0x00200000 /* receive dstoptions before rthdr */ 518 #define IN6P_TCLASS 0x00400000 /* receive traffic class value */ 519 #define IN6P_AUTOFLOWLABEL 0x00800000 /* attach flowlabel automatically */ 520 #define INP_TIMEWAIT 0x01000000 /* in TIMEWAIT, ppcb is tcptw */ 521 #define INP_ONESBCAST 0x02000000 /* send all-ones broadcast */ 522 #define INP_DROPPED 0x04000000 /* protocol drop flag */ 523 #define INP_SOCKREF 0x08000000 /* strong socket reference */ 524 #define INP_SW_FLOWID 0x10000000 /* software generated flow id */ 525 #define INP_HW_FLOWID 0x20000000 /* hardware generated flow id */ 526 #define IN6P_RFC2292 0x40000000 /* used RFC2292 API on the socket */ 527 #define IN6P_MTU 0x80000000 /* receive path MTU */ 528 529 #define INP_CONTROLOPTS (INP_RECVOPTS|INP_RECVRETOPTS|INP_RECVDSTADDR|\ 530 INP_RECVIF|INP_RECVTTL|\ 531 IN6P_PKTINFO|IN6P_HOPLIMIT|IN6P_HOPOPTS|\ 532 IN6P_DSTOPTS|IN6P_RTHDR|IN6P_RTHDRDSTOPTS|\ 533 IN6P_TCLASS|IN6P_AUTOFLOWLABEL|IN6P_RFC2292|\ 534 IN6P_MTU) 535 536 /* 537 * Flags for inp_flags2. 538 */ 539 #define INP_LLE_VALID 0x00000001 /* cached lle is valid */ 540 #define INP_RT_VALID 0x00000002 /* cached rtentry is valid */ 541 #define INP_PCBGROUPWILD 0x00000004 /* in pcbgroup wildcard list */ 542 543 /* 544 * Flags passed to in_pcblookup*() functions. 545 */ 546 #define INPLOOKUP_WILDCARD 0x00000001 /* Allow wildcard sockets. */ 547 #define INPLOOKUP_RLOCKPCB 0x00000002 /* Return inpcb read-locked. */ 548 #define INPLOOKUP_WLOCKPCB 0x00000004 /* Return inpcb write-locked. */ 549 550 #define INPLOOKUP_MASK (INPLOOKUP_WILDCARD | INPLOOKUP_RLOCKPCB | \ 551 INPLOOKUP_WLOCKPCB) 552 553 #define sotoinpcb(so) ((struct inpcb *)(so)->so_pcb) 554 #define sotoin6pcb(so) sotoinpcb(so) /* for KAME src sync over BSD*'s */ 555 556 #define INP_SOCKAF(so) so->so_proto->pr_domain->dom_family 557 558 #define INP_CHECK_SOCKAF(so, af) (INP_SOCKAF(so) == af) 559 560 /* 561 * Constants for pcbinfo.ipi_hashfields. 562 */ 563 #define IPI_HASHFIELDS_NONE 0 564 #define IPI_HASHFIELDS_2TUPLE 1 565 #define IPI_HASHFIELDS_4TUPLE 2 566 567 #ifdef _KERNEL 568 VNET_DECLARE(int, ipport_reservedhigh); 569 VNET_DECLARE(int, ipport_reservedlow); 570 VNET_DECLARE(int, ipport_lowfirstauto); 571 VNET_DECLARE(int, ipport_lowlastauto); 572 VNET_DECLARE(int, ipport_firstauto); 573 VNET_DECLARE(int, ipport_lastauto); 574 VNET_DECLARE(int, ipport_hifirstauto); 575 VNET_DECLARE(int, ipport_hilastauto); 576 VNET_DECLARE(int, ipport_randomized); 577 VNET_DECLARE(int, ipport_randomcps); 578 VNET_DECLARE(int, ipport_randomtime); 579 VNET_DECLARE(int, ipport_stoprandom); 580 VNET_DECLARE(int, ipport_tcpallocs); 581 582 #define V_ipport_reservedhigh VNET(ipport_reservedhigh) 583 #define V_ipport_reservedlow VNET(ipport_reservedlow) 584 #define V_ipport_lowfirstauto VNET(ipport_lowfirstauto) 585 #define V_ipport_lowlastauto VNET(ipport_lowlastauto) 586 #define V_ipport_firstauto VNET(ipport_firstauto) 587 #define V_ipport_lastauto VNET(ipport_lastauto) 588 #define V_ipport_hifirstauto VNET(ipport_hifirstauto) 589 #define V_ipport_hilastauto VNET(ipport_hilastauto) 590 #define V_ipport_randomized VNET(ipport_randomized) 591 #define V_ipport_randomcps VNET(ipport_randomcps) 592 #define V_ipport_randomtime VNET(ipport_randomtime) 593 #define V_ipport_stoprandom VNET(ipport_stoprandom) 594 #define V_ipport_tcpallocs VNET(ipport_tcpallocs) 595 596 void in_pcbinfo_destroy(struct inpcbinfo *); 597 void in_pcbinfo_init(struct inpcbinfo *, const char *, struct inpcbhead *, 598 int, int, char *, uma_init, uma_fini, uint32_t, u_int); 599 600 struct inpcbgroup * 601 in_pcbgroup_byhash(struct inpcbinfo *, u_int, uint32_t); 602 struct inpcbgroup * 603 in_pcbgroup_byinpcb(struct inpcb *); 604 struct inpcbgroup * 605 in_pcbgroup_bytuple(struct inpcbinfo *, struct in_addr, u_short, 606 struct in_addr, u_short); 607 void in_pcbgroup_destroy(struct inpcbinfo *); 608 int in_pcbgroup_enabled(struct inpcbinfo *); 609 void in_pcbgroup_init(struct inpcbinfo *, u_int, int); 610 void in_pcbgroup_remove(struct inpcb *); 611 void in_pcbgroup_update(struct inpcb *); 612 void in_pcbgroup_update_mbuf(struct inpcb *, struct mbuf *); 613 614 void in_pcbpurgeif0(struct inpcbinfo *, struct ifnet *); 615 int in_pcballoc(struct socket *, struct inpcbinfo *); 616 int in_pcbbind(struct inpcb *, struct sockaddr *, struct ucred *); 617 int in_pcb_lport(struct inpcb *, struct in_addr *, u_short *, 618 struct ucred *, int); 619 int in_pcbbind_setup(struct inpcb *, struct sockaddr *, in_addr_t *, 620 u_short *, struct ucred *); 621 int in_pcbconnect(struct inpcb *, struct sockaddr *, struct ucred *); 622 int in_pcbconnect_mbuf(struct inpcb *, struct sockaddr *, struct ucred *, 623 struct mbuf *); 624 int in_pcbconnect_setup(struct inpcb *, struct sockaddr *, in_addr_t *, 625 u_short *, in_addr_t *, u_short *, struct inpcb **, 626 struct ucred *); 627 void in_pcbdetach(struct inpcb *); 628 void in_pcbdisconnect(struct inpcb *); 629 void in_pcbdrop(struct inpcb *); 630 void in_pcbfree(struct inpcb *); 631 int in_pcbinshash(struct inpcb *); 632 int in_pcbinshash_nopcbgroup(struct inpcb *); 633 struct inpcb * 634 in_pcblookup_local(struct inpcbinfo *, 635 struct in_addr, u_short, int, struct ucred *); 636 struct inpcb * 637 in_pcblookup(struct inpcbinfo *, struct in_addr, u_int, 638 struct in_addr, u_int, int, struct ifnet *); 639 struct inpcb * 640 in_pcblookup_mbuf(struct inpcbinfo *, struct in_addr, u_int, 641 struct in_addr, u_int, int, struct ifnet *, struct mbuf *); 642 void in_pcbnotifyall(struct inpcbinfo *pcbinfo, struct in_addr, 643 int, struct inpcb *(*)(struct inpcb *, int)); 644 void in_pcbref(struct inpcb *); 645 void in_pcbrehash(struct inpcb *); 646 void in_pcbrehash_mbuf(struct inpcb *, struct mbuf *); 647 int in_pcbrele(struct inpcb *); 648 int in_pcbrele_rlocked(struct inpcb *); 649 int in_pcbrele_wlocked(struct inpcb *); 650 void in_pcbsetsolabel(struct socket *so); 651 int in_getpeeraddr(struct socket *so, struct sockaddr **nam); 652 int in_getsockaddr(struct socket *so, struct sockaddr **nam); 653 struct sockaddr * 654 in_sockaddr(in_port_t port, struct in_addr *addr); 655 void in_pcbsosetlabel(struct socket *so); 656 #endif /* _KERNEL */ 657 658 #endif /* !_NETINET_IN_PCB_H_ */ 659