1c398230bSWarner Losh /*- 2df8bae1dSRodney W. Grimes * Copyright (c) 1982, 1986, 1990, 1993 3a5654bb2SRobert Watson * The Regents of the University of California. 482a5be49SRobert Watson * Copyright (c) 2010-2011 Juniper Networks, Inc. 5a5654bb2SRobert Watson * All rights reserved. 6df8bae1dSRodney W. Grimes * 782a5be49SRobert Watson * Portions of this software were developed by Robert N. M. Watson under 882a5be49SRobert Watson * contract to Juniper Networks, Inc. 982a5be49SRobert Watson * 10df8bae1dSRodney W. Grimes * Redistribution and use in source and binary forms, with or without 11df8bae1dSRodney W. Grimes * modification, are permitted provided that the following conditions 12df8bae1dSRodney W. Grimes * are met: 13df8bae1dSRodney W. Grimes * 1. Redistributions of source code must retain the above copyright 14df8bae1dSRodney W. Grimes * notice, this list of conditions and the following disclaimer. 15df8bae1dSRodney W. Grimes * 2. Redistributions in binary form must reproduce the above copyright 16df8bae1dSRodney W. Grimes * notice, this list of conditions and the following disclaimer in the 17df8bae1dSRodney W. Grimes * documentation and/or other materials provided with the distribution. 18fbbd9655SWarner Losh * 3. Neither the name of the University nor the names of its contributors 19df8bae1dSRodney W. Grimes * may be used to endorse or promote products derived from this software 20df8bae1dSRodney W. Grimes * without specific prior written permission. 21df8bae1dSRodney W. Grimes * 22df8bae1dSRodney W. Grimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23df8bae1dSRodney W. Grimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24df8bae1dSRodney W. Grimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25df8bae1dSRodney W. Grimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26df8bae1dSRodney W. Grimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27df8bae1dSRodney W. Grimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28df8bae1dSRodney W. Grimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29df8bae1dSRodney W. Grimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30df8bae1dSRodney W. Grimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31df8bae1dSRodney W. Grimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32df8bae1dSRodney W. Grimes * SUCH DAMAGE. 33df8bae1dSRodney W. Grimes * 34df8bae1dSRodney W. Grimes * @(#)in_pcb.h 8.1 (Berkeley) 6/10/93 35c3aac50fSPeter Wemm * $FreeBSD$ 36df8bae1dSRodney W. Grimes */ 37df8bae1dSRodney W. Grimes 38707f139eSPaul Richards #ifndef _NETINET_IN_PCB_H_ 39707f139eSPaul Richards #define _NETINET_IN_PCB_H_ 40707f139eSPaul Richards 41f1844d4cSBruce Evans #include <sys/queue.h> 4240545cf5SBruce Evans #include <sys/_lock.h> 4340545cf5SBruce Evans #include <sys/_mutex.h> 448501a69cSRobert Watson #include <sys/_rwlock.h> 4584cc0778SGeorge V. Neville-Neil #include <net/route.h> 46f1844d4cSBruce Evans 478501a69cSRobert Watson #ifdef _KERNEL 481417604eSBjoern A. Zeeb #include <sys/lock.h> 498501a69cSRobert Watson #include <sys/rwlock.h> 50eddfbb76SRobert Watson #include <net/vnet.h> 519bcd427bSRobert Watson #include <vm/uma.h> 528501a69cSRobert Watson #endif 538501a69cSRobert Watson 5482cd038dSYoshinobu Inoue #define in6pcb inpcb /* for KAME src sync over BSD*'s */ 5582cd038dSYoshinobu Inoue #define in6p_sp inp_sp /* for KAME src sync over BSD*'s */ 5682cd038dSYoshinobu Inoue 57df8bae1dSRodney W. Grimes /* 58fc18af96SRobert Watson * struct inpcb is the common protocol control block structure used in most 59fc18af96SRobert Watson * IP transport protocols. 60712fc218SRobert Watson * 61712fc218SRobert Watson * Pointers to local and foreign host table entries, local and foreign socket 62712fc218SRobert Watson * numbers, and pointers up (to a socket structure) and down (to a 63712fc218SRobert Watson * protocol-specific control block) are stored here. 64df8bae1dSRodney W. Grimes */ 65e3975643SJake Burkholder LIST_HEAD(inpcbhead, inpcb); 66e3975643SJake Burkholder LIST_HEAD(inpcbporthead, inpcbport); 67cc65eb4eSGleb Smirnoff typedef uint64_t inp_gen_t; 6815bd2b43SDavid Greenman 693d4d47f3SGarrett Wollman /* 7082cd038dSYoshinobu Inoue * PCB with AF_INET6 null bind'ed laddr can receive AF_INET input packet. 71712fc218SRobert Watson * So, AF_INET6 null laddr is also used as AF_INET null laddr, by utilizing 72712fc218SRobert Watson * the following structure. 7382cd038dSYoshinobu Inoue */ 7482cd038dSYoshinobu Inoue struct in_addr_4in6 { 7582cd038dSYoshinobu Inoue u_int32_t ia46_pad32[3]; 7682cd038dSYoshinobu Inoue struct in_addr ia46_addr4; 7782cd038dSYoshinobu Inoue }; 7882cd038dSYoshinobu Inoue 7982cd038dSYoshinobu Inoue /* 80712fc218SRobert Watson * NOTE: ipv6 addrs should be 64-bit aligned, per RFC 2553. in_conninfo has 81712fc218SRobert Watson * some extra padding to accomplish this. 82388909a1SGleb Smirnoff * NOTE 2: tcp_syncache.c uses first 5 32-bit words, which identify fport, 83388909a1SGleb Smirnoff * lport, faddr to generate hash, so these fields shouldn't be moved. 84be2ac88cSJonathan Lemon */ 85be2ac88cSJonathan Lemon struct in_endpoints { 86be2ac88cSJonathan Lemon u_int16_t ie_fport; /* foreign port */ 87be2ac88cSJonathan Lemon u_int16_t ie_lport; /* local port */ 88be2ac88cSJonathan Lemon /* protocol dependent part, local and foreign addr */ 89be2ac88cSJonathan Lemon union { 90be2ac88cSJonathan Lemon /* foreign host table entry */ 91be2ac88cSJonathan Lemon struct in_addr_4in6 ie46_foreign; 92be2ac88cSJonathan Lemon struct in6_addr ie6_foreign; 93be2ac88cSJonathan Lemon } ie_dependfaddr; 94be2ac88cSJonathan Lemon union { 95be2ac88cSJonathan Lemon /* local host table entry */ 96be2ac88cSJonathan Lemon struct in_addr_4in6 ie46_local; 97be2ac88cSJonathan Lemon struct in6_addr ie6_local; 98be2ac88cSJonathan Lemon } ie_dependladdr; 99028bdf28SAndrey V. Elsukov u_int32_t ie6_zoneid; /* scope zone id */ 100a5654bb2SRobert Watson }; 101be2ac88cSJonathan Lemon #define ie_faddr ie_dependfaddr.ie46_foreign.ia46_addr4 102be2ac88cSJonathan Lemon #define ie_laddr ie_dependladdr.ie46_local.ia46_addr4 103be2ac88cSJonathan Lemon #define ie6_faddr ie_dependfaddr.ie6_foreign 104be2ac88cSJonathan Lemon #define ie6_laddr ie_dependladdr.ie6_local 105be2ac88cSJonathan Lemon 106be2ac88cSJonathan Lemon /* 107712fc218SRobert Watson * XXX The defines for inc_* are hacks and should be changed to direct 108712fc218SRobert Watson * references. 109be2ac88cSJonathan Lemon */ 110be2ac88cSJonathan Lemon struct in_conninfo { 111be2ac88cSJonathan Lemon u_int8_t inc_flags; 112be2ac88cSJonathan Lemon u_int8_t inc_len; 1138b07e49aSJulian Elischer u_int16_t inc_fibnum; /* XXX was pad, 16 bits is plenty */ 11497d8d152SAndre Oppermann /* protocol dependent part */ 115be2ac88cSJonathan Lemon struct in_endpoints inc_ie; 116be2ac88cSJonathan Lemon }; 117dcdb4371SBjoern A. Zeeb 118dcdb4371SBjoern A. Zeeb /* 119dcdb4371SBjoern A. Zeeb * Flags for inc_flags. 120dcdb4371SBjoern A. Zeeb */ 121dcdb4371SBjoern A. Zeeb #define INC_ISIPV6 0x01 122dcdb4371SBjoern A. Zeeb 123a4641f4eSPedro F. Giffuni #define inc_isipv6 inc_flags /* temp compatibility */ 124be2ac88cSJonathan Lemon #define inc_fport inc_ie.ie_fport 125be2ac88cSJonathan Lemon #define inc_lport inc_ie.ie_lport 126be2ac88cSJonathan Lemon #define inc_faddr inc_ie.ie_faddr 127be2ac88cSJonathan Lemon #define inc_laddr inc_ie.ie_laddr 128be2ac88cSJonathan Lemon #define inc6_faddr inc_ie.ie6_faddr 129be2ac88cSJonathan Lemon #define inc6_laddr inc_ie.ie6_laddr 130028bdf28SAndrey V. Elsukov #define inc6_zoneid inc_ie.ie6_zoneid 131be2ac88cSJonathan Lemon 132cc65eb4eSGleb Smirnoff #if defined(_KERNEL) || defined(_WANT_INPCB) 133cc65eb4eSGleb Smirnoff /* 134ff9b006dSJulien Charbon * struct inpcb captures the network layer state for TCP, UDP, and raw IPv4 and 135ff9b006dSJulien Charbon * IPv6 sockets. In the case of TCP and UDP, further per-connection state is 1367b709f8aSRobert Watson * hung off of inp_ppcb most of the time. Almost all fields of struct inpcb 1377b709f8aSRobert Watson * are static after creation or protected by a per-inpcb rwlock, inp_lock. A 138ff9b006dSJulien Charbon * few fields are protected by multiple locks as indicated in the locking notes 139ff9b006dSJulien Charbon * below. For these fields, all of the listed locks must be write-locked for 140ff9b006dSJulien Charbon * any modifications. However, these fields can be safely read while any one of 141ff9b006dSJulien Charbon * the listed locks are read-locked. This model can permit greater concurrency 142ff9b006dSJulien Charbon * for read operations. For example, connections can be looked up while only 143ff9b006dSJulien Charbon * holding a read lock on the global pcblist lock. This is important for 144ff9b006dSJulien Charbon * performance when attempting to find the connection for a packet given its IP 145ff9b006dSJulien Charbon * and port tuple. 146ff9b006dSJulien Charbon * 147ff9b006dSJulien Charbon * One noteworthy exception is that the global pcbinfo lock follows a different 148ff9b006dSJulien Charbon * set of rules in relation to the inp_list field. Rather than being 149ff9b006dSJulien Charbon * write-locked for modifications and read-locked for list iterations, it must 150ff9b006dSJulien Charbon * be read-locked during modifications and write-locked during list iterations. 151ff9b006dSJulien Charbon * This ensures that the relatively rare global list iterations safely walk a 152ff9b006dSJulien Charbon * stable snapshot of connections while allowing more common list modifications 153ff9b006dSJulien Charbon * to safely grab the pcblist lock just while adding or removing a connection 154ff9b006dSJulien Charbon * from the global list. 1557b709f8aSRobert Watson * 1567b709f8aSRobert Watson * Key: 1577b709f8aSRobert Watson * (c) - Constant after initialization 15852cd27cbSRobert Watson * (g) - Protected by the pcbgroup lock 1597b709f8aSRobert Watson * (i) - Protected by the inpcb lock 1607b709f8aSRobert Watson * (p) - Protected by the pcbinfo lock for the inpcb 161ff9b006dSJulien Charbon * (l) - Protected by the pcblist lock for the inpcb 162ff9b006dSJulien Charbon * (h) - Protected by the pcbhash lock for the inpcb 1637b709f8aSRobert Watson * (s) - Protected by another subsystem's locks 1647b709f8aSRobert Watson * (x) - Undefined locking 1657b709f8aSRobert Watson * 1667b709f8aSRobert Watson * A few other notes: 1677b709f8aSRobert Watson * 1687b709f8aSRobert Watson * When a read lock is held, stability of the field is guaranteed; to write 1697b709f8aSRobert Watson * to a field, a write lock must generally be held. 1707b709f8aSRobert Watson * 1717b709f8aSRobert Watson * netinet/netinet6-layer code should not assume that the inp_socket pointer 1727b709f8aSRobert Watson * is safe to dereference without inp_lock being held, even for protocols 1737b709f8aSRobert Watson * other than TCP (where the inpcb persists during TIMEWAIT even after the 1747b709f8aSRobert Watson * socket has been freed), or there may be close(2)-related races. 1757b709f8aSRobert Watson * 1767b709f8aSRobert Watson * The inp_vflag field is overloaded, and would otherwise ideally be (c). 177ff9b006dSJulien Charbon * 178ff9b006dSJulien Charbon * TODO: Currently only the TCP stack is leveraging the global pcbinfo lock 179ff9b006dSJulien Charbon * read-lock usage during modification, this model can be applied to other 180ff9b006dSJulien Charbon * protocols (especially SCTP). 1817b709f8aSRobert Watson */ 182cc65eb4eSGleb Smirnoff struct icmp6_filter; 183cc65eb4eSGleb Smirnoff struct inpcbpolicy; 184f3e7afe2SHans Petter Selasky struct m_snd_tag; 185df8bae1dSRodney W. Grimes struct inpcb { 1866a6cefacSGleb Smirnoff /* Cache line #1 (amd64) */ 187ff9b006dSJulien Charbon LIST_ENTRY(inpcb) inp_hash; /* (h/i) hash list */ 18852cd27cbSRobert Watson LIST_ENTRY(inpcb) inp_pcbgrouphash; /* (g/i) hash list */ 1896a6cefacSGleb Smirnoff struct rwlock inp_lock; 1906a6cefacSGleb Smirnoff /* Cache line #2 (amd64) */ 1916a6cefacSGleb Smirnoff #define inp_start_zero inp_refcount 1926a6cefacSGleb Smirnoff #define inp_zero_size (sizeof(struct inpcb) - \ 1936a6cefacSGleb Smirnoff offsetof(struct inpcb, inp_start_zero)) 1946a6cefacSGleb Smirnoff u_int inp_refcount; /* (i) refcount */ 1956a6cefacSGleb Smirnoff int inp_flags; /* (i) generic IP/datagram flags */ 1966a6cefacSGleb Smirnoff int inp_flags2; /* (i) generic IP/datagram flags #2*/ 1977b709f8aSRobert Watson void *inp_ppcb; /* (i) pointer to per-protocol pcb */ 1986a6cefacSGleb Smirnoff struct socket *inp_socket; /* (i) back pointer to socket */ 1997b709f8aSRobert Watson struct inpcbinfo *inp_pcbinfo; /* (c) PCB list info */ 20052cd27cbSRobert Watson struct inpcbgroup *inp_pcbgroup; /* (g/i) PCB group list */ 201ff9b006dSJulien Charbon LIST_ENTRY(inpcb) inp_pcbgroup_wild; /* (g/i/h) group wildcard entry */ 20286d02c5cSBjoern A. Zeeb struct ucred *inp_cred; /* (c) cache of socket cred */ 2037b709f8aSRobert Watson u_int32_t inp_flow; /* (i) IPv6 flow information */ 2047b709f8aSRobert Watson u_char inp_vflag; /* (i) IP version flag (v4/v6) */ 2057b709f8aSRobert Watson u_char inp_ip_ttl; /* (i) time to live proto */ 2067b709f8aSRobert Watson u_char inp_ip_p; /* (c) protocol proto */ 2077b709f8aSRobert Watson u_char inp_ip_minttl; /* (i) minimum TTL or drop */ 20880cb9f21SKip Macy uint32_t inp_flowid; /* (x) flow id / queue id */ 209f3e7afe2SHans Petter Selasky struct m_snd_tag *inp_snd_tag; /* (i) send tag for outgoing mbufs */ 21034e3dcedSAdrian Chadd uint32_t inp_flowtype; /* (x) M_HASHTYPE value */ 2110a100a6fSAdrian Chadd uint32_t inp_rss_listen_bucket; /* (x) overridden RSS listen bucket */ 2122de2af32SKip Macy 2132de2af32SKip Macy /* Local and foreign ports, local and foreign addr. */ 214ff9b006dSJulien Charbon struct in_conninfo inp_inc; /* (i) list for PCB's local port */ 2152de2af32SKip Macy 216a5654bb2SRobert Watson /* MAC and IPSEC policy information. */ 2177b709f8aSRobert Watson struct label *inp_label; /* (i) MAC label */ 2187b709f8aSRobert Watson struct inpcbpolicy *inp_sp; /* (s) for IPSEC */ 21982cd038dSYoshinobu Inoue 220712fc218SRobert Watson /* Protocol-dependent part; options. */ 22182cd038dSYoshinobu Inoue struct { 222cc65eb4eSGleb Smirnoff u_char inp_ip_tos; /* (i) type of service proto */ 223cc65eb4eSGleb Smirnoff struct mbuf *inp_options; /* (i) IP options */ 224cc65eb4eSGleb Smirnoff struct ip_moptions *inp_moptions; /* (i) mcast options */ 225cc65eb4eSGleb Smirnoff }; 22682cd038dSYoshinobu Inoue struct { 2277b709f8aSRobert Watson /* (i) IP options */ 228cc65eb4eSGleb Smirnoff struct mbuf *in6p_options; 2297b709f8aSRobert Watson /* (i) IP6 options for outgoing packets */ 230cc65eb4eSGleb Smirnoff struct ip6_pktopts *in6p_outputopts; 2317b709f8aSRobert Watson /* (i) IP multicast options */ 232cc65eb4eSGleb Smirnoff struct ip6_moptions *in6p_moptions; 2337b709f8aSRobert Watson /* (i) ICMPv6 code type filter */ 234cc65eb4eSGleb Smirnoff struct icmp6_filter *in6p_icmp6filt; 2357b709f8aSRobert Watson /* (i) IPV6_CHECKSUM setsockopt */ 236cc65eb4eSGleb Smirnoff int in6p_cksum; 237cc65eb4eSGleb Smirnoff short in6p_hops; 238cc65eb4eSGleb Smirnoff }; 239ff9b006dSJulien Charbon LIST_ENTRY(inpcb) inp_portlist; /* (i/h) */ 240ff9b006dSJulien Charbon struct inpcbport *inp_phd; /* (i/h) head of this list */ 241a5654bb2SRobert Watson inp_gen_t inp_gencnt; /* (c) generation count */ 242114f15c6SKip Macy struct llentry *inp_lle; /* cached L2 information */ 24384cc0778SGeorge V. Neville-Neil rt_gen_t inp_rt_cookie; /* generation for route entry */ 24484cc0778SGeorge V. Neville-Neil union { /* cached L3 information */ 2456a6cefacSGleb Smirnoff struct route inp_route; 2466a6cefacSGleb Smirnoff struct route_in6 inp_route6; 2476a6cefacSGleb Smirnoff }; 2486a6cefacSGleb Smirnoff LIST_ENTRY(inpcb) inp_list; /* (p/l) list for all PCBs for proto */ 2496a6cefacSGleb Smirnoff /* (p[w]) for list iteration */ 2506a6cefacSGleb Smirnoff /* (p[r]/l) for addition/removal */ 251a5654bb2SRobert Watson }; 252cc65eb4eSGleb Smirnoff #endif /* _KERNEL */ 253cc65eb4eSGleb Smirnoff 254a5654bb2SRobert Watson #define inp_fport inp_inc.inc_fport 255a5654bb2SRobert Watson #define inp_lport inp_inc.inc_lport 256a5654bb2SRobert Watson #define inp_faddr inp_inc.inc_faddr 257a5654bb2SRobert Watson #define inp_laddr inp_inc.inc_laddr 258f76fcf6dSJeffrey Hsu 259be2ac88cSJonathan Lemon #define in6p_faddr inp_inc.inc6_faddr 260be2ac88cSJonathan Lemon #define in6p_laddr inp_inc.inc6_laddr 261028bdf28SAndrey V. Elsukov #define in6p_zoneid inp_inc.inc6_zoneid 26282cd038dSYoshinobu Inoue #define in6p_flowinfo inp_flow 263a5654bb2SRobert Watson 264f6dfe47aSMarko Zec #define inp_vnet inp_pcbinfo->ipi_vnet 265f6dfe47aSMarko Zec 2663d4d47f3SGarrett Wollman /* 267712fc218SRobert Watson * The range of the generation count, as used in this implementation, is 9e19. 268712fc218SRobert Watson * We would have to create 300 billion connections per second for this number 269712fc218SRobert Watson * to roll over in a year. This seems sufficiently unlikely that we simply 270712fc218SRobert Watson * don't concern ourselves with that possibility. 2713d4d47f3SGarrett Wollman */ 272c3229e05SDavid Greenman 27398271db4SGarrett Wollman /* 274712fc218SRobert Watson * Interface exported to userland by various protocols which use inpcbs. Hack 275712fc218SRobert Watson * alert -- only define if struct xsocket is in scope. 276cc65eb4eSGleb Smirnoff * Fields prefixed with "xi_" are unique to this structure, and the rest 277cc65eb4eSGleb Smirnoff * match fields in the struct inpcb, to ease coding and porting. 278cc65eb4eSGleb Smirnoff * 279cc65eb4eSGleb Smirnoff * Legend: 280cc65eb4eSGleb Smirnoff * (s) - used by userland utilities in src 281cc65eb4eSGleb Smirnoff * (p) - used by utilities in ports 282cc65eb4eSGleb Smirnoff * (3) - is known to be used by third party software not in ports 283cc65eb4eSGleb Smirnoff * (n) - no known usage 28498271db4SGarrett Wollman */ 28598271db4SGarrett Wollman #ifdef _SYS_SOCKETVAR_H_ 28698271db4SGarrett Wollman struct xinpcb { 28798271db4SGarrett Wollman size_t xi_len; /* length of this structure */ 288cc65eb4eSGleb Smirnoff struct xsocket xi_socket; /* (s,p) */ 289cc65eb4eSGleb Smirnoff struct in_conninfo inp_inc; /* (s,p) */ 290cc65eb4eSGleb Smirnoff uint64_t inp_gencnt; /* (s,p) */ 291cc65eb4eSGleb Smirnoff union { 292cc65eb4eSGleb Smirnoff void *inp_ppcb; /* (s) netstat(1) */ 293cc65eb4eSGleb Smirnoff int64_t ph_ppcb; 29498271db4SGarrett Wollman }; 295cc65eb4eSGleb Smirnoff int64_t inp_spare64[4]; 296cc65eb4eSGleb Smirnoff uint32_t inp_flow; /* (s) */ 297cc65eb4eSGleb Smirnoff uint32_t inp_flowid; /* (s) */ 298cc65eb4eSGleb Smirnoff uint32_t inp_flowtype; /* (s) */ 299cc65eb4eSGleb Smirnoff int32_t inp_flags; /* (s,p) */ 300cc65eb4eSGleb Smirnoff int32_t inp_flags2; /* (s) */ 301cc65eb4eSGleb Smirnoff int32_t inp_rss_listen_bucket; /* (n) */ 302cc65eb4eSGleb Smirnoff int32_t in6p_cksum; /* (n) */ 303cc65eb4eSGleb Smirnoff int32_t inp_spare32[4]; 304cc65eb4eSGleb Smirnoff uint16_t in6p_hops; /* (n) */ 305cc65eb4eSGleb Smirnoff uint8_t inp_ip_tos; /* (n) */ 306cc65eb4eSGleb Smirnoff int8_t pad8; 307cc65eb4eSGleb Smirnoff uint8_t inp_vflag; /* (s,p) */ 308cc65eb4eSGleb Smirnoff uint8_t inp_ip_ttl; /* (n) */ 309cc65eb4eSGleb Smirnoff uint8_t inp_ip_p; /* (n) */ 310cc65eb4eSGleb Smirnoff uint8_t inp_ip_minttl; /* (n) */ 311cc65eb4eSGleb Smirnoff int8_t inp_spare8[4]; 312cc65eb4eSGleb Smirnoff } __aligned(8); 31398271db4SGarrett Wollman 31498271db4SGarrett Wollman struct xinpgen { 31598271db4SGarrett Wollman size_t xig_len; /* length of this structure */ 31698271db4SGarrett Wollman u_int xig_count; /* number of PCBs at this time */ 31798271db4SGarrett Wollman inp_gen_t xig_gen; /* generation count at this time */ 318cc65eb4eSGleb Smirnoff so_gen_t xig_sogen; /* socket generation count this time */ 3193ae4b0e7SGleb Smirnoff } __aligned(8); 320cc65eb4eSGleb Smirnoff #ifdef _KERNEL 321cc65eb4eSGleb Smirnoff void in_pcbtoxinpcb(const struct inpcb *, struct xinpcb *); 322cc65eb4eSGleb Smirnoff #endif 32398271db4SGarrett Wollman #endif /* _SYS_SOCKETVAR_H_ */ 32498271db4SGarrett Wollman 325c3229e05SDavid Greenman struct inpcbport { 326e3975643SJake Burkholder LIST_ENTRY(inpcbport) phd_hash; 327c3229e05SDavid Greenman struct inpcbhead phd_pcblist; 328c3229e05SDavid Greenman u_short phd_port; 329df8bae1dSRodney W. Grimes }; 330df8bae1dSRodney W. Grimes 33182a5be49SRobert Watson /*- 332712fc218SRobert Watson * Global data structure for each high-level protocol (UDP, TCP, ...) in both 333712fc218SRobert Watson * IPv4 and IPv6. Holds inpcb lists and information for managing them. 33482a5be49SRobert Watson * 335ff9b006dSJulien Charbon * Each pcbinfo is protected by three locks: ipi_lock, ipi_hash_lock and 336ff9b006dSJulien Charbon * ipi_list_lock: 337ff9b006dSJulien Charbon * - ipi_lock covering the global pcb list stability during loop iteration, 338ff9b006dSJulien Charbon * - ipi_hash_lock covering the hashed lookup tables, 339ff9b006dSJulien Charbon * - ipi_list_lock covering mutable global fields (such as the global 340ff9b006dSJulien Charbon * pcb list) 34182a5be49SRobert Watson * 342ff9b006dSJulien Charbon * The lock order is: 343ff9b006dSJulien Charbon * 344ff9b006dSJulien Charbon * ipi_lock (before) 345ff9b006dSJulien Charbon * inpcb locks (before) 346ff9b006dSJulien Charbon * ipi_list locks (before) 347ff9b006dSJulien Charbon * {ipi_hash_lock, pcbgroup locks} 34882a5be49SRobert Watson * 34982a5be49SRobert Watson * Locking key: 35082a5be49SRobert Watson * 35182a5be49SRobert Watson * (c) Constant or nearly constant after initialisation 35282a5be49SRobert Watson * (g) Locked by ipi_lock 353ff9b006dSJulien Charbon * (l) Locked by ipi_list_lock 35452cd27cbSRobert Watson * (h) Read using either ipi_hash_lock or inpcb lock; write requires both 35552cd27cbSRobert Watson * (p) Protected by one or more pcbgroup locks 35682a5be49SRobert Watson * (x) Synchronisation properties poorly defined 357712fc218SRobert Watson */ 358712fc218SRobert Watson struct inpcbinfo { 359712fc218SRobert Watson /* 360ff9b006dSJulien Charbon * Global lock protecting full inpcb list traversal 36182a5be49SRobert Watson */ 36282a5be49SRobert Watson struct rwlock ipi_lock; 36382a5be49SRobert Watson 36482a5be49SRobert Watson /* 365712fc218SRobert Watson * Global list of inpcbs on the protocol. 366712fc218SRobert Watson */ 367ff9b006dSJulien Charbon struct inpcbhead *ipi_listhead; /* (g/l) */ 368ff9b006dSJulien Charbon u_int ipi_count; /* (l) */ 369712fc218SRobert Watson 370712fc218SRobert Watson /* 371712fc218SRobert Watson * Generation count -- incremented each time a connection is allocated 372712fc218SRobert Watson * or freed. 373712fc218SRobert Watson */ 374ff9b006dSJulien Charbon u_quad_t ipi_gencnt; /* (l) */ 37582a5be49SRobert Watson 37682a5be49SRobert Watson /* 37782a5be49SRobert Watson * Fields associated with port lookup and allocation. 37882a5be49SRobert Watson */ 37982a5be49SRobert Watson u_short ipi_lastport; /* (x) */ 38082a5be49SRobert Watson u_short ipi_lastlow; /* (x) */ 38182a5be49SRobert Watson u_short ipi_lasthi; /* (x) */ 38282a5be49SRobert Watson 38382a5be49SRobert Watson /* 38482a5be49SRobert Watson * UMA zone from which inpcbs are allocated for this protocol. 38582a5be49SRobert Watson */ 38682a5be49SRobert Watson struct uma_zone *ipi_zone; /* (c) */ 38782a5be49SRobert Watson 38882a5be49SRobert Watson /* 38952cd27cbSRobert Watson * Connection groups associated with this protocol. These fields are 39052cd27cbSRobert Watson * constant, but pcbgroup structures themselves are protected by 39152cd27cbSRobert Watson * per-pcbgroup locks. 39252cd27cbSRobert Watson */ 39352cd27cbSRobert Watson struct inpcbgroup *ipi_pcbgroups; /* (c) */ 39452cd27cbSRobert Watson u_int ipi_npcbgroups; /* (c) */ 39552cd27cbSRobert Watson u_int ipi_hashfields; /* (c) */ 39652cd27cbSRobert Watson 39752cd27cbSRobert Watson /* 39852cd27cbSRobert Watson * Global lock protecting non-pcbgroup hash lookup tables. 399fa046d87SRobert Watson */ 400f89d4c3aSAndre Oppermann struct rwlock ipi_hash_lock; 401fa046d87SRobert Watson 402fa046d87SRobert Watson /* 40382a5be49SRobert Watson * Global hash of inpcbs, hashed by local and foreign addresses and 40482a5be49SRobert Watson * port numbers. 40582a5be49SRobert Watson */ 406fa046d87SRobert Watson struct inpcbhead *ipi_hashbase; /* (h) */ 407fa046d87SRobert Watson u_long ipi_hashmask; /* (h) */ 40882a5be49SRobert Watson 40982a5be49SRobert Watson /* 41082a5be49SRobert Watson * Global hash of inpcbs, hashed by only local port number. 41182a5be49SRobert Watson */ 412fa046d87SRobert Watson struct inpcbporthead *ipi_porthashbase; /* (h) */ 413fa046d87SRobert Watson u_long ipi_porthashmask; /* (h) */ 4142de2af32SKip Macy 4152de2af32SKip Macy /* 41652cd27cbSRobert Watson * List of wildcard inpcbs for use with pcbgroups. In the past, was 41752cd27cbSRobert Watson * per-pcbgroup but is now global. All pcbgroup locks must be held 41852cd27cbSRobert Watson * to modify the list, so any is sufficient to read it. 41952cd27cbSRobert Watson */ 42052cd27cbSRobert Watson struct inpcbhead *ipi_wildbase; /* (p) */ 42152cd27cbSRobert Watson u_long ipi_wildmask; /* (p) */ 42252cd27cbSRobert Watson 42352cd27cbSRobert Watson /* 424f6dfe47aSMarko Zec * Pointer to network stack instance 425f6dfe47aSMarko Zec */ 42682a5be49SRobert Watson struct vnet *ipi_vnet; /* (c) */ 427f6dfe47aSMarko Zec 428f6dfe47aSMarko Zec /* 429f6dfe47aSMarko Zec * general use 2 4302de2af32SKip Macy */ 4312de2af32SKip Macy void *ipi_pspare[2]; 432ff9b006dSJulien Charbon 433ff9b006dSJulien Charbon /* 434ff9b006dSJulien Charbon * Global lock protecting global inpcb list, inpcb count, etc. 435ff9b006dSJulien Charbon */ 436ff9b006dSJulien Charbon struct rwlock ipi_list_lock; 43715bd2b43SDavid Greenman }; 43815bd2b43SDavid Greenman 43975410f02SRobert Millan #ifdef _KERNEL 44052cd27cbSRobert Watson /* 44152cd27cbSRobert Watson * Connection groups hold sets of connections that have similar CPU/thread 44252cd27cbSRobert Watson * affinity. Each connection belongs to exactly one connection group. 44352cd27cbSRobert Watson */ 44452cd27cbSRobert Watson struct inpcbgroup { 44552cd27cbSRobert Watson /* 44652cd27cbSRobert Watson * Per-connection group hash of inpcbs, hashed by local and foreign 44752cd27cbSRobert Watson * addresses and port numbers. 44852cd27cbSRobert Watson */ 44952cd27cbSRobert Watson struct inpcbhead *ipg_hashbase; /* (c) */ 45052cd27cbSRobert Watson u_long ipg_hashmask; /* (c) */ 45152cd27cbSRobert Watson 45252cd27cbSRobert Watson /* 45352cd27cbSRobert Watson * Notional affinity of this pcbgroup. 45452cd27cbSRobert Watson */ 45552cd27cbSRobert Watson u_int ipg_cpu; /* (p) */ 45652cd27cbSRobert Watson 45752cd27cbSRobert Watson /* 45852cd27cbSRobert Watson * Per-connection group lock, not to be confused with ipi_lock. 45952cd27cbSRobert Watson * Protects the hash table hung off the group, but also the global 46052cd27cbSRobert Watson * wildcard list in inpcbinfo. 46152cd27cbSRobert Watson */ 46252cd27cbSRobert Watson struct mtx ipg_lock; 46352cd27cbSRobert Watson } __aligned(CACHE_LINE_SIZE); 46452cd27cbSRobert Watson 4655bd311a5SSam Leffler #define INP_LOCK_INIT(inp, d, t) \ 4668501a69cSRobert Watson rw_init_flags(&(inp)->inp_lock, (t), RW_RECURSE | RW_DUPOK) 4678501a69cSRobert Watson #define INP_LOCK_DESTROY(inp) rw_destroy(&(inp)->inp_lock) 4688501a69cSRobert Watson #define INP_RLOCK(inp) rw_rlock(&(inp)->inp_lock) 4698501a69cSRobert Watson #define INP_WLOCK(inp) rw_wlock(&(inp)->inp_lock) 47043cc0bc1SRobert Watson #define INP_TRY_RLOCK(inp) rw_try_rlock(&(inp)->inp_lock) 47143cc0bc1SRobert Watson #define INP_TRY_WLOCK(inp) rw_try_wlock(&(inp)->inp_lock) 4728501a69cSRobert Watson #define INP_RUNLOCK(inp) rw_runlock(&(inp)->inp_lock) 4738501a69cSRobert Watson #define INP_WUNLOCK(inp) rw_wunlock(&(inp)->inp_lock) 47482c33e73SKip Macy #define INP_TRY_UPGRADE(inp) rw_try_upgrade(&(inp)->inp_lock) 47582c33e73SKip Macy #define INP_DOWNGRADE(inp) rw_downgrade(&(inp)->inp_lock) 47682c33e73SKip Macy #define INP_WLOCKED(inp) rw_wowned(&(inp)->inp_lock) 4778501a69cSRobert Watson #define INP_LOCK_ASSERT(inp) rw_assert(&(inp)->inp_lock, RA_LOCKED) 4788501a69cSRobert Watson #define INP_RLOCK_ASSERT(inp) rw_assert(&(inp)->inp_lock, RA_RLOCKED) 4798501a69cSRobert Watson #define INP_WLOCK_ASSERT(inp) rw_assert(&(inp)->inp_lock, RA_WLOCKED) 4808501a69cSRobert Watson #define INP_UNLOCK_ASSERT(inp) rw_assert(&(inp)->inp_lock, RA_UNLOCKED) 481f76fcf6dSJeffrey Hsu 4823d585327SKip Macy /* 4833d585327SKip Macy * These locking functions are for inpcb consumers outside of sys/netinet, 4843d585327SKip Macy * more specifically, they were added for the benefit of TOE drivers. The 4853d585327SKip Macy * macros are reserved for use by the stack. 4863d585327SKip Macy */ 4873d585327SKip Macy void inp_wlock(struct inpcb *); 4883d585327SKip Macy void inp_wunlock(struct inpcb *); 4893d585327SKip Macy void inp_rlock(struct inpcb *); 4903d585327SKip Macy void inp_runlock(struct inpcb *); 4913d585327SKip Macy 492c75e2666SGleb Smirnoff #ifdef INVARIANT_SUPPORT 493e79dd20dSKip Macy void inp_lock_assert(struct inpcb *); 494e79dd20dSKip Macy void inp_unlock_assert(struct inpcb *); 4953d585327SKip Macy #else 496c75e2666SGleb Smirnoff #define inp_lock_assert(inp) do {} while (0) 497c75e2666SGleb Smirnoff #define inp_unlock_assert(inp) do {} while (0) 4983d585327SKip Macy #endif 4999378e437SKip Macy 5009378e437SKip Macy void inp_apply_all(void (*func)(struct inpcb *, void *), void *arg); 5019378e437SKip Macy int inp_ip_tos_get(const struct inpcb *inp); 5029378e437SKip Macy void inp_ip_tos_set(struct inpcb *inp, int val); 5039d29c635SKip Macy struct socket * 5049d29c635SKip Macy inp_inpcbtosocket(struct inpcb *inp); 5059d29c635SKip Macy struct tcpcb * 5069d29c635SKip Macy inp_inpcbtotcpcb(struct inpcb *inp); 507df9cf830STai-hwa Liang void inp_4tuple_get(struct inpcb *inp, uint32_t *laddr, uint16_t *lp, 5089d29c635SKip Macy uint32_t *faddr, uint16_t *fp); 509efdf104bSMikolaj Golub short inp_so_options(const struct inpcb *inp); 5109378e437SKip Macy 511e79dd20dSKip Macy #endif /* _KERNEL */ 5123d585327SKip Macy 513f76fcf6dSJeffrey Hsu #define INP_INFO_LOCK_INIT(ipi, d) \ 5148501a69cSRobert Watson rw_init_flags(&(ipi)->ipi_lock, (d), RW_RECURSE) 5158501a69cSRobert Watson #define INP_INFO_LOCK_DESTROY(ipi) rw_destroy(&(ipi)->ipi_lock) 5168501a69cSRobert Watson #define INP_INFO_RLOCK(ipi) rw_rlock(&(ipi)->ipi_lock) 5178501a69cSRobert Watson #define INP_INFO_WLOCK(ipi) rw_wlock(&(ipi)->ipi_lock) 51843cc0bc1SRobert Watson #define INP_INFO_TRY_RLOCK(ipi) rw_try_rlock(&(ipi)->ipi_lock) 51943cc0bc1SRobert Watson #define INP_INFO_TRY_WLOCK(ipi) rw_try_wlock(&(ipi)->ipi_lock) 52066f80e90SRobert Watson #define INP_INFO_TRY_UPGRADE(ipi) rw_try_upgrade(&(ipi)->ipi_lock) 521079672cbSJulien Charbon #define INP_INFO_WLOCKED(ipi) rw_wowned(&(ipi)->ipi_lock) 5228501a69cSRobert Watson #define INP_INFO_RUNLOCK(ipi) rw_runlock(&(ipi)->ipi_lock) 5238501a69cSRobert Watson #define INP_INFO_WUNLOCK(ipi) rw_wunlock(&(ipi)->ipi_lock) 5248501a69cSRobert Watson #define INP_INFO_LOCK_ASSERT(ipi) rw_assert(&(ipi)->ipi_lock, RA_LOCKED) 5258501a69cSRobert Watson #define INP_INFO_RLOCK_ASSERT(ipi) rw_assert(&(ipi)->ipi_lock, RA_RLOCKED) 5268501a69cSRobert Watson #define INP_INFO_WLOCK_ASSERT(ipi) rw_assert(&(ipi)->ipi_lock, RA_WLOCKED) 5278501a69cSRobert Watson #define INP_INFO_UNLOCK_ASSERT(ipi) rw_assert(&(ipi)->ipi_lock, RA_UNLOCKED) 528f76fcf6dSJeffrey Hsu 529ff9b006dSJulien Charbon #define INP_LIST_LOCK_INIT(ipi, d) \ 530ff9b006dSJulien Charbon rw_init_flags(&(ipi)->ipi_list_lock, (d), 0) 531ff9b006dSJulien Charbon #define INP_LIST_LOCK_DESTROY(ipi) rw_destroy(&(ipi)->ipi_list_lock) 532ff9b006dSJulien Charbon #define INP_LIST_RLOCK(ipi) rw_rlock(&(ipi)->ipi_list_lock) 533ff9b006dSJulien Charbon #define INP_LIST_WLOCK(ipi) rw_wlock(&(ipi)->ipi_list_lock) 534ff9b006dSJulien Charbon #define INP_LIST_TRY_RLOCK(ipi) rw_try_rlock(&(ipi)->ipi_list_lock) 535ff9b006dSJulien Charbon #define INP_LIST_TRY_WLOCK(ipi) rw_try_wlock(&(ipi)->ipi_list_lock) 536ff9b006dSJulien Charbon #define INP_LIST_TRY_UPGRADE(ipi) rw_try_upgrade(&(ipi)->ipi_list_lock) 537ff9b006dSJulien Charbon #define INP_LIST_RUNLOCK(ipi) rw_runlock(&(ipi)->ipi_list_lock) 538ff9b006dSJulien Charbon #define INP_LIST_WUNLOCK(ipi) rw_wunlock(&(ipi)->ipi_list_lock) 539ff9b006dSJulien Charbon #define INP_LIST_LOCK_ASSERT(ipi) \ 540ff9b006dSJulien Charbon rw_assert(&(ipi)->ipi_list_lock, RA_LOCKED) 541ff9b006dSJulien Charbon #define INP_LIST_RLOCK_ASSERT(ipi) \ 542ff9b006dSJulien Charbon rw_assert(&(ipi)->ipi_list_lock, RA_RLOCKED) 543ff9b006dSJulien Charbon #define INP_LIST_WLOCK_ASSERT(ipi) \ 544ff9b006dSJulien Charbon rw_assert(&(ipi)->ipi_list_lock, RA_WLOCKED) 545ff9b006dSJulien Charbon #define INP_LIST_UNLOCK_ASSERT(ipi) \ 546ff9b006dSJulien Charbon rw_assert(&(ipi)->ipi_list_lock, RA_UNLOCKED) 547ff9b006dSJulien Charbon 548fa046d87SRobert Watson #define INP_HASH_LOCK_INIT(ipi, d) \ 549fa046d87SRobert Watson rw_init_flags(&(ipi)->ipi_hash_lock, (d), 0) 550fa046d87SRobert Watson #define INP_HASH_LOCK_DESTROY(ipi) rw_destroy(&(ipi)->ipi_hash_lock) 551fa046d87SRobert Watson #define INP_HASH_RLOCK(ipi) rw_rlock(&(ipi)->ipi_hash_lock) 552fa046d87SRobert Watson #define INP_HASH_WLOCK(ipi) rw_wlock(&(ipi)->ipi_hash_lock) 553fa046d87SRobert Watson #define INP_HASH_RUNLOCK(ipi) rw_runlock(&(ipi)->ipi_hash_lock) 554fa046d87SRobert Watson #define INP_HASH_WUNLOCK(ipi) rw_wunlock(&(ipi)->ipi_hash_lock) 555fa046d87SRobert Watson #define INP_HASH_LOCK_ASSERT(ipi) rw_assert(&(ipi)->ipi_hash_lock, \ 556fa046d87SRobert Watson RA_LOCKED) 557fa046d87SRobert Watson #define INP_HASH_WLOCK_ASSERT(ipi) rw_assert(&(ipi)->ipi_hash_lock, \ 558fa046d87SRobert Watson RA_WLOCKED) 559fa046d87SRobert Watson 56052cd27cbSRobert Watson #define INP_GROUP_LOCK_INIT(ipg, d) mtx_init(&(ipg)->ipg_lock, (d), NULL, \ 56152cd27cbSRobert Watson MTX_DEF | MTX_DUPOK) 56252cd27cbSRobert Watson #define INP_GROUP_LOCK_DESTROY(ipg) mtx_destroy(&(ipg)->ipg_lock) 56352cd27cbSRobert Watson 56452cd27cbSRobert Watson #define INP_GROUP_LOCK(ipg) mtx_lock(&(ipg)->ipg_lock) 56552cd27cbSRobert Watson #define INP_GROUP_LOCK_ASSERT(ipg) mtx_assert(&(ipg)->ipg_lock, MA_OWNED) 56652cd27cbSRobert Watson #define INP_GROUP_UNLOCK(ipg) mtx_unlock(&(ipg)->ipg_lock) 56752cd27cbSRobert Watson 568ddd79a97SDavid Greenman #define INP_PCBHASH(faddr, lport, fport, mask) \ 569c3229e05SDavid Greenman (((faddr) ^ ((faddr) >> 16) ^ ntohs((lport) ^ (fport))) & (mask)) 570c3229e05SDavid Greenman #define INP_PCBPORTHASH(lport, mask) \ 571c3229e05SDavid Greenman (ntohs((lport)) & (mask)) 5721b44e5ffSAndrey V. Elsukov #define INP6_PCBHASHKEY(faddr) ((faddr)->s6_addr32[3]) 573ddd79a97SDavid Greenman 574a5654bb2SRobert Watson /* 575773b573aSKip Macy * Flags for inp_vflags -- historically version flags only 576a5654bb2SRobert Watson */ 577a5654bb2SRobert Watson #define INP_IPV4 0x1 578a5654bb2SRobert Watson #define INP_IPV6 0x2 579a5654bb2SRobert Watson #define INP_IPV6PROTO 0x4 /* opened under IPv6 protocol */ 580a5654bb2SRobert Watson 581a5654bb2SRobert Watson /* 582773b573aSKip Macy * Flags for inp_flags. 583a5654bb2SRobert Watson */ 584ad71fe3cSRobert Watson #define INP_RECVOPTS 0x00000001 /* receive incoming IP options */ 585ad71fe3cSRobert Watson #define INP_RECVRETOPTS 0x00000002 /* receive IP options for reply */ 586ad71fe3cSRobert Watson #define INP_RECVDSTADDR 0x00000004 /* receive IP dst address */ 587ad71fe3cSRobert Watson #define INP_HDRINCL 0x00000008 /* user supplies entire IP header */ 588ad71fe3cSRobert Watson #define INP_HIGHPORT 0x00000010 /* user wants "high" port binding */ 589ad71fe3cSRobert Watson #define INP_LOWPORT 0x00000020 /* user wants "low" port binding */ 590ad71fe3cSRobert Watson #define INP_ANONPORT 0x00000040 /* port chosen for user */ 591ad71fe3cSRobert Watson #define INP_RECVIF 0x00000080 /* receive incoming interface */ 592ad71fe3cSRobert Watson #define INP_MTUDISC 0x00000100 /* user can do MTU discovery */ 593603eaf79SAlexander V. Chernikov /* 0x000200 unused: was INP_FAITH */ 594ad71fe3cSRobert Watson #define INP_RECVTTL 0x00000400 /* receive incoming IP TTL */ 595ad71fe3cSRobert Watson #define INP_DONTFRAG 0x00000800 /* don't fragment packet */ 596f44270e7SPawel Jakub Dawidek #define INP_BINDANY 0x00001000 /* allow bind to any address */ 597ad71fe3cSRobert Watson #define INP_INHASHLIST 0x00002000 /* in_pcbinshash() has been called */ 5983cca425bSMichael Tuexen #define INP_RECVTOS 0x00004000 /* receive incoming IP TOS */ 599ad71fe3cSRobert Watson #define IN6P_IPV6_V6ONLY 0x00008000 /* restrict AF_INET6 socket for v6 */ 600ad71fe3cSRobert Watson #define IN6P_PKTINFO 0x00010000 /* receive IP6 dst and I/F */ 601ad71fe3cSRobert Watson #define IN6P_HOPLIMIT 0x00020000 /* receive hoplimit */ 602ad71fe3cSRobert Watson #define IN6P_HOPOPTS 0x00040000 /* receive hop-by-hop options */ 603ad71fe3cSRobert Watson #define IN6P_DSTOPTS 0x00080000 /* receive dst options after rthdr */ 604ad71fe3cSRobert Watson #define IN6P_RTHDR 0x00100000 /* receive routing header */ 605ad71fe3cSRobert Watson #define IN6P_RTHDRDSTOPTS 0x00200000 /* receive dstoptions before rthdr */ 606ad71fe3cSRobert Watson #define IN6P_TCLASS 0x00400000 /* receive traffic class value */ 607ad71fe3cSRobert Watson #define IN6P_AUTOFLOWLABEL 0x00800000 /* attach flowlabel automatically */ 608ad71fe3cSRobert Watson #define INP_TIMEWAIT 0x01000000 /* in TIMEWAIT, ppcb is tcptw */ 609ad71fe3cSRobert Watson #define INP_ONESBCAST 0x02000000 /* send all-ones broadcast */ 610ad71fe3cSRobert Watson #define INP_DROPPED 0x04000000 /* protocol drop flag */ 611ad71fe3cSRobert Watson #define INP_SOCKREF 0x08000000 /* strong socket reference */ 612c2529042SHans Petter Selasky #define INP_RESERVED_0 0x10000000 /* reserved field */ 613c2529042SHans Petter Selasky #define INP_RESERVED_1 0x20000000 /* reserved field */ 614f95d4633SHajimu UMEMOTO #define IN6P_RFC2292 0x40000000 /* used RFC2292 API on the socket */ 615f95d4633SHajimu UMEMOTO #define IN6P_MTU 0x80000000 /* receive path MTU */ 61633841545SHajimu UMEMOTO 61782c23ebaSBill Fenner #define INP_CONTROLOPTS (INP_RECVOPTS|INP_RECVRETOPTS|INP_RECVDSTADDR|\ 6183cca425bSMichael Tuexen INP_RECVIF|INP_RECVTTL|INP_RECVTOS|\ 61933841545SHajimu UMEMOTO IN6P_PKTINFO|IN6P_HOPLIMIT|IN6P_HOPOPTS|\ 62033841545SHajimu UMEMOTO IN6P_DSTOPTS|IN6P_RTHDR|IN6P_RTHDRDSTOPTS|\ 621f95d4633SHajimu UMEMOTO IN6P_TCLASS|IN6P_AUTOFLOWLABEL|IN6P_RFC2292|\ 622f95d4633SHajimu UMEMOTO IN6P_MTU) 62382cd038dSYoshinobu Inoue 624773b573aSKip Macy /* 625773b573aSKip Macy * Flags for inp_flags2. 626773b573aSKip Macy */ 6278b12a7c2SKip Macy #define INP_LLE_VALID 0x00000001 /* cached lle is valid */ 6288b12a7c2SKip Macy #define INP_RT_VALID 0x00000002 /* cached rtentry is valid */ 62952cd27cbSRobert Watson #define INP_PCBGROUPWILD 0x00000004 /* in pcbgroup wildcard list */ 630fc06cd42SMikolaj Golub #define INP_REUSEPORT 0x00000008 /* SO_REUSEPORT option is set */ 631df4e91d3SGleb Smirnoff #define INP_FREED 0x00000010 /* inp itself is not valid */ 632efdf104bSMikolaj Golub #define INP_REUSEADDR 0x00000020 /* SO_REUSEADDR option is set */ 6330a100a6fSAdrian Chadd #define INP_BINDMULTI 0x00000040 /* IP_BINDMULTI option is set */ 6340a100a6fSAdrian Chadd #define INP_RSS_BUCKET_SET 0x00000080 /* IP_RSS_LISTEN_BUCKET is set */ 6359d3ddf43SAdrian Chadd #define INP_RECVFLOWID 0x00000100 /* populate recv datagram with flow info */ 6369d3ddf43SAdrian Chadd #define INP_RECVRSSBUCKETID 0x00000200 /* populate recv datagram with bucket id */ 637f3e7afe2SHans Petter Selasky #define INP_RATE_LIMIT_CHANGED 0x00000400 /* rate limit needs attention */ 638dce33a45SErmal Luçi #define INP_ORIGDSTADDR 0x00000800 /* receive IP dst address/port */ 639773b573aSKip Macy 640fa046d87SRobert Watson /* 641fa046d87SRobert Watson * Flags passed to in_pcblookup*() functions. 642fa046d87SRobert Watson */ 643fa046d87SRobert Watson #define INPLOOKUP_WILDCARD 0x00000001 /* Allow wildcard sockets. */ 644fa046d87SRobert Watson #define INPLOOKUP_RLOCKPCB 0x00000002 /* Return inpcb read-locked. */ 645fa046d87SRobert Watson #define INPLOOKUP_WLOCKPCB 0x00000004 /* Return inpcb write-locked. */ 646fa046d87SRobert Watson 647fa046d87SRobert Watson #define INPLOOKUP_MASK (INPLOOKUP_WILDCARD | INPLOOKUP_RLOCKPCB | \ 648fa046d87SRobert Watson INPLOOKUP_WLOCKPCB) 649fa046d87SRobert Watson 650df8bae1dSRodney W. Grimes #define sotoinpcb(so) ((struct inpcb *)(so)->so_pcb) 65182cd038dSYoshinobu Inoue #define sotoin6pcb(so) sotoinpcb(so) /* for KAME src sync over BSD*'s */ 65282cd038dSYoshinobu Inoue 65382cd038dSYoshinobu Inoue #define INP_SOCKAF(so) so->so_proto->pr_domain->dom_family 65482cd038dSYoshinobu Inoue 65582cd038dSYoshinobu Inoue #define INP_CHECK_SOCKAF(so, af) (INP_SOCKAF(so) == af) 656df8bae1dSRodney W. Grimes 65752cd27cbSRobert Watson /* 65852cd27cbSRobert Watson * Constants for pcbinfo.ipi_hashfields. 65952cd27cbSRobert Watson */ 66052cd27cbSRobert Watson #define IPI_HASHFIELDS_NONE 0 66152cd27cbSRobert Watson #define IPI_HASHFIELDS_2TUPLE 1 66252cd27cbSRobert Watson #define IPI_HASHFIELDS_4TUPLE 2 66352cd27cbSRobert Watson 664664a31e4SPeter Wemm #ifdef _KERNEL 665eddfbb76SRobert Watson VNET_DECLARE(int, ipport_reservedhigh); 666eddfbb76SRobert Watson VNET_DECLARE(int, ipport_reservedlow); 667eddfbb76SRobert Watson VNET_DECLARE(int, ipport_lowfirstauto); 668eddfbb76SRobert Watson VNET_DECLARE(int, ipport_lowlastauto); 669eddfbb76SRobert Watson VNET_DECLARE(int, ipport_firstauto); 670eddfbb76SRobert Watson VNET_DECLARE(int, ipport_lastauto); 671eddfbb76SRobert Watson VNET_DECLARE(int, ipport_hifirstauto); 672eddfbb76SRobert Watson VNET_DECLARE(int, ipport_hilastauto); 673eddfbb76SRobert Watson VNET_DECLARE(int, ipport_randomized); 674eddfbb76SRobert Watson VNET_DECLARE(int, ipport_randomcps); 675eddfbb76SRobert Watson VNET_DECLARE(int, ipport_randomtime); 676eddfbb76SRobert Watson VNET_DECLARE(int, ipport_stoprandom); 677eddfbb76SRobert Watson VNET_DECLARE(int, ipport_tcpallocs); 678eddfbb76SRobert Watson 6791e77c105SRobert Watson #define V_ipport_reservedhigh VNET(ipport_reservedhigh) 6801e77c105SRobert Watson #define V_ipport_reservedlow VNET(ipport_reservedlow) 6811e77c105SRobert Watson #define V_ipport_lowfirstauto VNET(ipport_lowfirstauto) 6821e77c105SRobert Watson #define V_ipport_lowlastauto VNET(ipport_lowlastauto) 6831e77c105SRobert Watson #define V_ipport_firstauto VNET(ipport_firstauto) 6841e77c105SRobert Watson #define V_ipport_lastauto VNET(ipport_lastauto) 6851e77c105SRobert Watson #define V_ipport_hifirstauto VNET(ipport_hifirstauto) 6861e77c105SRobert Watson #define V_ipport_hilastauto VNET(ipport_hilastauto) 6871e77c105SRobert Watson #define V_ipport_randomized VNET(ipport_randomized) 6881e77c105SRobert Watson #define V_ipport_randomcps VNET(ipport_randomcps) 6891e77c105SRobert Watson #define V_ipport_randomtime VNET(ipport_randomtime) 6901e77c105SRobert Watson #define V_ipport_stoprandom VNET(ipport_stoprandom) 6911e77c105SRobert Watson #define V_ipport_tcpallocs VNET(ipport_tcpallocs) 692eddfbb76SRobert Watson 6939bcd427bSRobert Watson void in_pcbinfo_destroy(struct inpcbinfo *); 6949bcd427bSRobert Watson void in_pcbinfo_init(struct inpcbinfo *, const char *, struct inpcbhead *, 695cc487c16SGleb Smirnoff int, int, char *, uma_init, u_int); 69652cd27cbSRobert Watson 697d5bb8bd3SAdrian Chadd int in_pcbbind_check_bindmulti(const struct inpcb *ni, 698d5bb8bd3SAdrian Chadd const struct inpcb *oi); 699d5bb8bd3SAdrian Chadd 70052cd27cbSRobert Watson struct inpcbgroup * 70152cd27cbSRobert Watson in_pcbgroup_byhash(struct inpcbinfo *, u_int, uint32_t); 70252cd27cbSRobert Watson struct inpcbgroup * 70352cd27cbSRobert Watson in_pcbgroup_byinpcb(struct inpcb *); 70452cd27cbSRobert Watson struct inpcbgroup * 70552cd27cbSRobert Watson in_pcbgroup_bytuple(struct inpcbinfo *, struct in_addr, u_short, 70652cd27cbSRobert Watson struct in_addr, u_short); 70752cd27cbSRobert Watson void in_pcbgroup_destroy(struct inpcbinfo *); 70852cd27cbSRobert Watson int in_pcbgroup_enabled(struct inpcbinfo *); 70952cd27cbSRobert Watson void in_pcbgroup_init(struct inpcbinfo *, u_int, int); 71052cd27cbSRobert Watson void in_pcbgroup_remove(struct inpcb *); 71152cd27cbSRobert Watson void in_pcbgroup_update(struct inpcb *); 71252cd27cbSRobert Watson void in_pcbgroup_update_mbuf(struct inpcb *, struct mbuf *); 7139bcd427bSRobert Watson 714f76fcf6dSJeffrey Hsu void in_pcbpurgeif0(struct inpcbinfo *, struct ifnet *); 715d915b280SStephan Uphoff int in_pcballoc(struct socket *, struct inpcbinfo *); 716b0330ed9SPawel Jakub Dawidek int in_pcbbind(struct inpcb *, struct sockaddr *, struct ucred *); 7174616026fSErmal Luçi int in_pcb_lport(struct inpcb *, struct in_addr *, u_short *, 7184616026fSErmal Luçi struct ucred *, int); 7194b932371SIan Dowse int in_pcbbind_setup(struct inpcb *, struct sockaddr *, in_addr_t *, 720b0330ed9SPawel Jakub Dawidek u_short *, struct ucred *); 721b0330ed9SPawel Jakub Dawidek int in_pcbconnect(struct inpcb *, struct sockaddr *, struct ucred *); 722d3c1f003SRobert Watson int in_pcbconnect_mbuf(struct inpcb *, struct sockaddr *, struct ucred *, 723d3c1f003SRobert Watson struct mbuf *); 7245200e00eSIan Dowse int in_pcbconnect_setup(struct inpcb *, struct sockaddr *, in_addr_t *, 7255200e00eSIan Dowse u_short *, in_addr_t *, u_short *, struct inpcb **, 726b0330ed9SPawel Jakub Dawidek struct ucred *); 7274d77a549SAlfred Perlstein void in_pcbdetach(struct inpcb *); 7284d77a549SAlfred Perlstein void in_pcbdisconnect(struct inpcb *); 72910702a28SRobert Watson void in_pcbdrop(struct inpcb *); 7304c7c478dSRobert Watson void in_pcbfree(struct inpcb *); 7314d77a549SAlfred Perlstein int in_pcbinshash(struct inpcb *); 73252cd27cbSRobert Watson int in_pcbinshash_nopcbgroup(struct inpcb *); 733ae190832SSteven Hartland int in_pcbladdr(struct inpcb *, struct in_addr *, struct in_addr *, 734ae190832SSteven Hartland struct ucred *); 735df8bae1dSRodney W. Grimes struct inpcb * 7364d77a549SAlfred Perlstein in_pcblookup_local(struct inpcbinfo *, 737078b7042SBjoern A. Zeeb struct in_addr, u_short, int, struct ucred *); 73815bd2b43SDavid Greenman struct inpcb * 739fa046d87SRobert Watson in_pcblookup(struct inpcbinfo *, struct in_addr, u_int, 740c1cd65baSBruce Evans struct in_addr, u_int, int, struct ifnet *); 741d3c1f003SRobert Watson struct inpcb * 742d3c1f003SRobert Watson in_pcblookup_mbuf(struct inpcbinfo *, struct in_addr, u_int, 743d3c1f003SRobert Watson struct in_addr, u_int, int, struct ifnet *, struct mbuf *); 744f76fcf6dSJeffrey Hsu void in_pcbnotifyall(struct inpcbinfo *pcbinfo, struct in_addr, 7453ce144eaSJeffrey Hsu int, struct inpcb *(*)(struct inpcb *, int)); 74628696211SRobert Watson void in_pcbref(struct inpcb *); 7474d77a549SAlfred Perlstein void in_pcbrehash(struct inpcb *); 748d3c1f003SRobert Watson void in_pcbrehash_mbuf(struct inpcb *, struct mbuf *); 74928696211SRobert Watson int in_pcbrele(struct inpcb *); 75079bdc6e5SRobert Watson int in_pcbrele_rlocked(struct inpcb *); 75179bdc6e5SRobert Watson int in_pcbrele_wlocked(struct inpcb *); 75284cc0778SGeorge V. Neville-Neil void in_losing(struct inpcb *); 753a557af22SRobert Watson void in_pcbsetsolabel(struct socket *so); 75454d642bbSRobert Watson int in_getpeeraddr(struct socket *so, struct sockaddr **nam); 75554d642bbSRobert Watson int in_getsockaddr(struct socket *so, struct sockaddr **nam); 75626ef6ac4SDon Lewis struct sockaddr * 75726ef6ac4SDon Lewis in_sockaddr(in_port_t port, struct in_addr *addr); 758a557af22SRobert Watson void in_pcbsosetlabel(struct socket *so); 759f3e7afe2SHans Petter Selasky #ifdef RATELIMIT 760f3e7afe2SHans Petter Selasky int in_pcbattach_txrtlmt(struct inpcb *, struct ifnet *, uint32_t, uint32_t, uint32_t); 761f3e7afe2SHans Petter Selasky void in_pcbdetach_txrtlmt(struct inpcb *); 762f3e7afe2SHans Petter Selasky int in_pcbmodify_txrtlmt(struct inpcb *, uint32_t); 763f3e7afe2SHans Petter Selasky int in_pcbquery_txrtlmt(struct inpcb *, uint32_t *); 764*95ed5015SHans Petter Selasky int in_pcbquery_txrlevel(struct inpcb *, uint32_t *); 765f3e7afe2SHans Petter Selasky void in_pcboutput_txrtlmt(struct inpcb *, struct ifnet *, struct mbuf *); 766f3e7afe2SHans Petter Selasky void in_pcboutput_eagain(struct inpcb *); 767f3e7afe2SHans Petter Selasky #endif 768664a31e4SPeter Wemm #endif /* _KERNEL */ 7693d4d47f3SGarrett Wollman 7708781d8e9SBruce Evans #endif /* !_NETINET_IN_PCB_H_ */ 771