xref: /freebsd/sys/netinet/in_pcb.h (revision 1a43cff92a20d22b5a767f5c06e9cdf461cd0a2f)
1c398230bSWarner Losh /*-
251369649SPedro F. Giffuni  * SPDX-License-Identifier: BSD-3-Clause
351369649SPedro F. Giffuni  *
4df8bae1dSRodney W. Grimes  * Copyright (c) 1982, 1986, 1990, 1993
5a5654bb2SRobert Watson  *	The Regents of the University of California.
682a5be49SRobert Watson  * Copyright (c) 2010-2011 Juniper Networks, Inc.
7a5654bb2SRobert Watson  * All rights reserved.
8df8bae1dSRodney W. Grimes  *
982a5be49SRobert Watson  * Portions of this software were developed by Robert N. M. Watson under
1082a5be49SRobert Watson  * contract to Juniper Networks, Inc.
1182a5be49SRobert Watson  *
12df8bae1dSRodney W. Grimes  * Redistribution and use in source and binary forms, with or without
13df8bae1dSRodney W. Grimes  * modification, are permitted provided that the following conditions
14df8bae1dSRodney W. Grimes  * are met:
15df8bae1dSRodney W. Grimes  * 1. Redistributions of source code must retain the above copyright
16df8bae1dSRodney W. Grimes  *    notice, this list of conditions and the following disclaimer.
17df8bae1dSRodney W. Grimes  * 2. Redistributions in binary form must reproduce the above copyright
18df8bae1dSRodney W. Grimes  *    notice, this list of conditions and the following disclaimer in the
19df8bae1dSRodney W. Grimes  *    documentation and/or other materials provided with the distribution.
20fbbd9655SWarner Losh  * 3. Neither the name of the University nor the names of its contributors
21df8bae1dSRodney W. Grimes  *    may be used to endorse or promote products derived from this software
22df8bae1dSRodney W. Grimes  *    without specific prior written permission.
23df8bae1dSRodney W. Grimes  *
24df8bae1dSRodney W. Grimes  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25df8bae1dSRodney W. Grimes  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26df8bae1dSRodney W. Grimes  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27df8bae1dSRodney W. Grimes  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28df8bae1dSRodney W. Grimes  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29df8bae1dSRodney W. Grimes  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30df8bae1dSRodney W. Grimes  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31df8bae1dSRodney W. Grimes  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32df8bae1dSRodney W. Grimes  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33df8bae1dSRodney W. Grimes  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34df8bae1dSRodney W. Grimes  * SUCH DAMAGE.
35df8bae1dSRodney W. Grimes  *
36df8bae1dSRodney W. Grimes  *	@(#)in_pcb.h	8.1 (Berkeley) 6/10/93
37c3aac50fSPeter Wemm  * $FreeBSD$
38df8bae1dSRodney W. Grimes  */
39df8bae1dSRodney W. Grimes 
40707f139eSPaul Richards #ifndef _NETINET_IN_PCB_H_
41707f139eSPaul Richards #define _NETINET_IN_PCB_H_
42707f139eSPaul Richards 
43f1844d4cSBruce Evans #include <sys/queue.h>
44ddece765SMatt Macy #include <sys/epoch.h>
4540545cf5SBruce Evans #include <sys/_lock.h>
4640545cf5SBruce Evans #include <sys/_mutex.h>
478501a69cSRobert Watson #include <sys/_rwlock.h>
4884cc0778SGeorge V. Neville-Neil #include <net/route.h>
49f1844d4cSBruce Evans 
508501a69cSRobert Watson #ifdef _KERNEL
511417604eSBjoern A. Zeeb #include <sys/lock.h>
528501a69cSRobert Watson #include <sys/rwlock.h>
53eddfbb76SRobert Watson #include <net/vnet.h>
549bcd427bSRobert Watson #include <vm/uma.h>
558501a69cSRobert Watson #endif
568501a69cSRobert Watson 
5782cd038dSYoshinobu Inoue #define	in6pcb		inpcb	/* for KAME src sync over BSD*'s */
5882cd038dSYoshinobu Inoue #define	in6p_sp		inp_sp	/* for KAME src sync over BSD*'s */
5982cd038dSYoshinobu Inoue 
60df8bae1dSRodney W. Grimes /*
61fc18af96SRobert Watson  * struct inpcb is the common protocol control block structure used in most
62fc18af96SRobert Watson  * IP transport protocols.
63712fc218SRobert Watson  *
64712fc218SRobert Watson  * Pointers to local and foreign host table entries, local and foreign socket
65712fc218SRobert Watson  * numbers, and pointers up (to a socket structure) and down (to a
66712fc218SRobert Watson  * protocol-specific control block) are stored here.
67df8bae1dSRodney W. Grimes  */
68e3975643SJake Burkholder LIST_HEAD(inpcbhead, inpcb);
69e3975643SJake Burkholder LIST_HEAD(inpcbporthead, inpcbport);
70cc65eb4eSGleb Smirnoff typedef	uint64_t	inp_gen_t;
7115bd2b43SDavid Greenman 
723d4d47f3SGarrett Wollman /*
7382cd038dSYoshinobu Inoue  * PCB with AF_INET6 null bind'ed laddr can receive AF_INET input packet.
74712fc218SRobert Watson  * So, AF_INET6 null laddr is also used as AF_INET null laddr, by utilizing
75712fc218SRobert Watson  * the following structure.
7682cd038dSYoshinobu Inoue  */
7782cd038dSYoshinobu Inoue struct in_addr_4in6 {
7882cd038dSYoshinobu Inoue 	u_int32_t	ia46_pad32[3];
7982cd038dSYoshinobu Inoue 	struct	in_addr	ia46_addr4;
8082cd038dSYoshinobu Inoue };
8182cd038dSYoshinobu Inoue 
82*1a43cff9SSean Bruno union in_dependaddr {
83*1a43cff9SSean Bruno 	struct in_addr_4in6 id46_addr;
84*1a43cff9SSean Bruno 	struct in6_addr	id6_addr;
85*1a43cff9SSean Bruno };
86*1a43cff9SSean Bruno 
8782cd038dSYoshinobu Inoue /*
88712fc218SRobert Watson  * NOTE: ipv6 addrs should be 64-bit aligned, per RFC 2553.  in_conninfo has
89712fc218SRobert Watson  * some extra padding to accomplish this.
90388909a1SGleb Smirnoff  * NOTE 2: tcp_syncache.c uses first 5 32-bit words, which identify fport,
91388909a1SGleb Smirnoff  * lport, faddr to generate hash, so these fields shouldn't be moved.
92be2ac88cSJonathan Lemon  */
93be2ac88cSJonathan Lemon struct in_endpoints {
94be2ac88cSJonathan Lemon 	u_int16_t	ie_fport;		/* foreign port */
95be2ac88cSJonathan Lemon 	u_int16_t	ie_lport;		/* local port */
96be2ac88cSJonathan Lemon 	/* protocol dependent part, local and foreign addr */
97*1a43cff9SSean Bruno 	union in_dependaddr ie_dependfaddr;	/* foreign host table entry */
98*1a43cff9SSean Bruno 	union in_dependaddr ie_dependladdr;	/* local host table entry */
99*1a43cff9SSean Bruno #define	ie_faddr	ie_dependfaddr.id46_addr.ia46_addr4
100*1a43cff9SSean Bruno #define	ie_laddr	ie_dependladdr.id46_addr.ia46_addr4
101*1a43cff9SSean Bruno #define	ie6_faddr	ie_dependfaddr.id6_addr
102*1a43cff9SSean Bruno #define	ie6_laddr	ie_dependladdr.id6_addr
103028bdf28SAndrey V. Elsukov 	u_int32_t	ie6_zoneid;		/* scope zone id */
104a5654bb2SRobert Watson };
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:
1573ee9c3c4SRandall Stewart  * (b) - Protected by the hpts lock.
1587b709f8aSRobert Watson  * (c) - Constant after initialization
15952cd27cbSRobert Watson  * (g) - Protected by the pcbgroup lock
1607b709f8aSRobert Watson  * (i) - Protected by the inpcb lock
1617b709f8aSRobert Watson  * (p) - Protected by the pcbinfo lock for the inpcb
162ff9b006dSJulien Charbon  * (l) - Protected by the pcblist lock for the inpcb
163ff9b006dSJulien Charbon  * (h) - Protected by the pcbhash lock for the inpcb
1647b709f8aSRobert Watson  * (s) - Protected by another subsystem's locks
1657b709f8aSRobert Watson  * (x) - Undefined locking
1667b709f8aSRobert Watson  *
1673ee9c3c4SRandall Stewart  * Notes on the tcp_hpts:
1683ee9c3c4SRandall Stewart  *
1693ee9c3c4SRandall Stewart  * First Hpts lock order is
1703ee9c3c4SRandall Stewart  * 1) INP_WLOCK()
1713ee9c3c4SRandall Stewart  * 2) HPTS_LOCK() i.e. hpts->pmtx
1723ee9c3c4SRandall Stewart  *
1733ee9c3c4SRandall Stewart  * To insert a TCB on the hpts you *must* be holding the INP_WLOCK().
1743ee9c3c4SRandall Stewart  * You may check the inp->inp_in_hpts flag without the hpts lock.
1753ee9c3c4SRandall Stewart  * The hpts is the only one that will clear this flag holding
1763ee9c3c4SRandall Stewart  * only the hpts lock. This means that in your tcp_output()
1773ee9c3c4SRandall Stewart  * routine when you test for the inp_in_hpts flag to be 1
1783ee9c3c4SRandall Stewart  * it may be transitioning to 0 (by the hpts).
1793ee9c3c4SRandall Stewart  * That's ok since that will just mean an extra call to tcp_output
1803ee9c3c4SRandall Stewart  * that most likely will find the call you executed
1813ee9c3c4SRandall Stewart  * (when the mis-match occured) will have put the TCB back
1823ee9c3c4SRandall Stewart  * on the hpts and it will return. If your
1833ee9c3c4SRandall Stewart  * call did not add the inp back to the hpts then you will either
1843ee9c3c4SRandall Stewart  * over-send or the cwnd will block you from sending more.
1853ee9c3c4SRandall Stewart  *
1863ee9c3c4SRandall Stewart  * Note you should also be holding the INP_WLOCK() when you
1873ee9c3c4SRandall Stewart  * call the remove from the hpts as well. Though usually
1883ee9c3c4SRandall Stewart  * you are either doing this from a timer, where you need and have
1893ee9c3c4SRandall Stewart  * the INP_WLOCK() or from destroying your TCB where again
1903ee9c3c4SRandall Stewart  * you should already have the INP_WLOCK().
1913ee9c3c4SRandall Stewart  *
1923ee9c3c4SRandall Stewart  * The inp_hpts_cpu, inp_hpts_cpu_set, inp_input_cpu and
1933ee9c3c4SRandall Stewart  * inp_input_cpu_set fields are controlled completely by
1943ee9c3c4SRandall Stewart  * the hpts. Do not ever set these. The inp_hpts_cpu_set
1953ee9c3c4SRandall Stewart  * and inp_input_cpu_set fields indicate if the hpts has
1963ee9c3c4SRandall Stewart  * setup the respective cpu field. It is advised if this
1973ee9c3c4SRandall Stewart  * field is 0, to enqueue the packet with the appropriate
1983ee9c3c4SRandall Stewart  * hpts_immediate() call. If the _set field is 1, then
1993ee9c3c4SRandall Stewart  * you may compare the inp_*_cpu field to the curcpu and
2003ee9c3c4SRandall Stewart  * may want to again insert onto the hpts if these fields
2013ee9c3c4SRandall Stewart  * are not equal (i.e. you are not on the expected CPU).
2023ee9c3c4SRandall Stewart  *
2033ee9c3c4SRandall Stewart  * A note on inp_hpts_calls and inp_input_calls, these
2043ee9c3c4SRandall Stewart  * flags are set when the hpts calls either the output
2053ee9c3c4SRandall Stewart  * or do_segment routines respectively. If the routine
2063ee9c3c4SRandall Stewart  * being called wants to use this, then it needs to
2073ee9c3c4SRandall Stewart  * clear the flag before returning. The hpts will not
2083ee9c3c4SRandall Stewart  * clear the flag. The flags can be used to tell if
2093ee9c3c4SRandall Stewart  * the hpts is the function calling the respective
2103ee9c3c4SRandall Stewart  * routine.
2113ee9c3c4SRandall Stewart  *
2127b709f8aSRobert Watson  * A few other notes:
2137b709f8aSRobert Watson  *
2147b709f8aSRobert Watson  * When a read lock is held, stability of the field is guaranteed; to write
2157b709f8aSRobert Watson  * to a field, a write lock must generally be held.
2167b709f8aSRobert Watson  *
2177b709f8aSRobert Watson  * netinet/netinet6-layer code should not assume that the inp_socket pointer
2187b709f8aSRobert Watson  * is safe to dereference without inp_lock being held, even for protocols
2197b709f8aSRobert Watson  * other than TCP (where the inpcb persists during TIMEWAIT even after the
2207b709f8aSRobert Watson  * socket has been freed), or there may be close(2)-related races.
2217b709f8aSRobert Watson  *
2227b709f8aSRobert Watson  * The inp_vflag field is overloaded, and would otherwise ideally be (c).
223ff9b006dSJulien Charbon  *
224ff9b006dSJulien Charbon  * TODO:  Currently only the TCP stack is leveraging the global pcbinfo lock
225ff9b006dSJulien Charbon  * read-lock usage during modification, this model can be applied to other
226ff9b006dSJulien Charbon  * protocols (especially SCTP).
2277b709f8aSRobert Watson  */
228cc65eb4eSGleb Smirnoff struct icmp6_filter;
229cc65eb4eSGleb Smirnoff struct inpcbpolicy;
230f3e7afe2SHans Petter Selasky struct m_snd_tag;
231df8bae1dSRodney W. Grimes struct inpcb {
2326a6cefacSGleb Smirnoff 	/* Cache line #1 (amd64) */
233ff9b006dSJulien Charbon 	LIST_ENTRY(inpcb) inp_hash;	/* (h/i) hash list */
23452cd27cbSRobert Watson 	LIST_ENTRY(inpcb) inp_pcbgrouphash;	/* (g/i) hash list */
2356a6cefacSGleb Smirnoff 	struct rwlock	inp_lock;
2366a6cefacSGleb Smirnoff 	/* Cache line #2 (amd64) */
2373ee9c3c4SRandall Stewart #define	inp_start_zero	inp_hpts
2386a6cefacSGleb Smirnoff #define	inp_zero_size	(sizeof(struct inpcb) - \
2396a6cefacSGleb Smirnoff 			    offsetof(struct inpcb, inp_start_zero))
2403ee9c3c4SRandall Stewart 	TAILQ_ENTRY(inpcb) inp_hpts;	/* pacing out queue next lock(b) */
2413ee9c3c4SRandall Stewart 
2423ee9c3c4SRandall Stewart 	uint32_t inp_hpts_request;	/* Current hpts request, zero if
2433ee9c3c4SRandall Stewart 					 * fits in the pacing window (i&b). */
2443ee9c3c4SRandall Stewart 	/*
2453ee9c3c4SRandall Stewart 	 * Note the next fields are protected by a
2463ee9c3c4SRandall Stewart 	 * different lock (hpts-lock). This means that
2473ee9c3c4SRandall Stewart 	 * they must correspond in size to the smallest
2483ee9c3c4SRandall Stewart 	 * protectable bit field (uint8_t on x86, and
2493ee9c3c4SRandall Stewart 	 * other platfomrs potentially uint32_t?). Also
2503ee9c3c4SRandall Stewart 	 * since CPU switches can occur at different times the two
2513ee9c3c4SRandall Stewart 	 * fields can *not* be collapsed into a signal bit field.
2523ee9c3c4SRandall Stewart 	 */
2533ee9c3c4SRandall Stewart #if defined(__amd64__) || defined(__i386__)
2543ee9c3c4SRandall Stewart 	volatile uint8_t inp_in_hpts; /* on output hpts (lock b) */
2553ee9c3c4SRandall Stewart 	volatile uint8_t inp_in_input; /* on input hpts (lock b) */
2563ee9c3c4SRandall Stewart #else
2573ee9c3c4SRandall Stewart 	volatile uint32_t inp_in_hpts; /* on output hpts (lock b) */
2583ee9c3c4SRandall Stewart 	volatile uint32_t inp_in_input; /* on input hpts (lock b) */
2593ee9c3c4SRandall Stewart #endif
2603ee9c3c4SRandall Stewart 	volatile uint16_t  inp_hpts_cpu; /* Lock (i) */
2616a6cefacSGleb Smirnoff 	u_int	inp_refcount;		/* (i) refcount */
2626a6cefacSGleb Smirnoff 	int	inp_flags;		/* (i) generic IP/datagram flags */
2636a6cefacSGleb Smirnoff 	int	inp_flags2;		/* (i) generic IP/datagram flags #2*/
2643ee9c3c4SRandall Stewart 	volatile uint16_t  inp_input_cpu; /* Lock (i) */
2653ee9c3c4SRandall Stewart 	volatile uint8_t inp_hpts_cpu_set :1,  /* on output hpts (i) */
2663ee9c3c4SRandall Stewart 			 inp_input_cpu_set : 1,	/* on input hpts (i) */
2673ee9c3c4SRandall Stewart 			 inp_hpts_calls :1,	/* (i) from output hpts */
2683ee9c3c4SRandall Stewart 			 inp_input_calls :1,	/* (i) from input hpts */
2693ee9c3c4SRandall Stewart 			 inp_spare_bits2 : 4;
2703ee9c3c4SRandall Stewart 	uint8_t inp_spare_byte;		/* Compiler hole */
2717b709f8aSRobert Watson 	void	*inp_ppcb;		/* (i) pointer to per-protocol pcb */
2726a6cefacSGleb Smirnoff 	struct	socket *inp_socket;	/* (i) back pointer to socket */
2733ee9c3c4SRandall Stewart 	uint32_t 	 inp_hptsslot;	/* Hpts wheel slot this tcb is Lock(i&b) */
2743ee9c3c4SRandall Stewart 	uint32_t         inp_hpts_drop_reas;	/* reason we are dropping the PCB (lock i&b) */
2753ee9c3c4SRandall Stewart 	TAILQ_ENTRY(inpcb) inp_input;	/* pacing in  queue next lock(b) */
2767b709f8aSRobert Watson 	struct	inpcbinfo *inp_pcbinfo;	/* (c) PCB list info */
27752cd27cbSRobert Watson 	struct	inpcbgroup *inp_pcbgroup; /* (g/i) PCB group list */
278ff9b006dSJulien Charbon 	LIST_ENTRY(inpcb) inp_pcbgroup_wild; /* (g/i/h) group wildcard entry */
27986d02c5cSBjoern A. Zeeb 	struct	ucred	*inp_cred;	/* (c) cache of socket cred */
2807b709f8aSRobert Watson 	u_int32_t inp_flow;		/* (i) IPv6 flow information */
2817b709f8aSRobert Watson 	u_char	inp_vflag;		/* (i) IP version flag (v4/v6) */
2827b709f8aSRobert Watson 	u_char	inp_ip_ttl;		/* (i) time to live proto */
2837b709f8aSRobert Watson 	u_char	inp_ip_p;		/* (c) protocol proto */
2847b709f8aSRobert Watson 	u_char	inp_ip_minttl;		/* (i) minimum TTL or drop */
28580cb9f21SKip Macy 	uint32_t inp_flowid;		/* (x) flow id / queue id */
286f3e7afe2SHans Petter Selasky 	struct m_snd_tag *inp_snd_tag;	/* (i) send tag for outgoing mbufs */
28734e3dcedSAdrian Chadd 	uint32_t inp_flowtype;		/* (x) M_HASHTYPE value */
2880a100a6fSAdrian Chadd 	uint32_t inp_rss_listen_bucket;	/* (x) overridden RSS listen bucket */
2892de2af32SKip Macy 
2902de2af32SKip Macy 	/* Local and foreign ports, local and foreign addr. */
291ff9b006dSJulien Charbon 	struct	in_conninfo inp_inc;	/* (i) list for PCB's local port */
2922de2af32SKip Macy 
293a5654bb2SRobert Watson 	/* MAC and IPSEC policy information. */
2947b709f8aSRobert Watson 	struct	label *inp_label;	/* (i) MAC label */
2957b709f8aSRobert Watson 	struct	inpcbpolicy *inp_sp;    /* (s) for IPSEC */
29682cd038dSYoshinobu Inoue 
297712fc218SRobert Watson 	/* Protocol-dependent part; options. */
29882cd038dSYoshinobu Inoue 	struct {
299cc65eb4eSGleb Smirnoff 		u_char	inp_ip_tos;		/* (i) type of service proto */
300cc65eb4eSGleb Smirnoff 		struct mbuf		*inp_options;	/* (i) IP options */
301cc65eb4eSGleb Smirnoff 		struct ip_moptions	*inp_moptions;	/* (i) mcast options */
302cc65eb4eSGleb Smirnoff 	};
30382cd038dSYoshinobu Inoue 	struct {
3047b709f8aSRobert Watson 		/* (i) IP options */
305cc65eb4eSGleb Smirnoff 		struct mbuf		*in6p_options;
3067b709f8aSRobert Watson 		/* (i) IP6 options for outgoing packets */
307cc65eb4eSGleb Smirnoff 		struct ip6_pktopts	*in6p_outputopts;
3087b709f8aSRobert Watson 		/* (i) IP multicast options */
309cc65eb4eSGleb Smirnoff 		struct ip6_moptions	*in6p_moptions;
3107b709f8aSRobert Watson 		/* (i) ICMPv6 code type filter */
311cc65eb4eSGleb Smirnoff 		struct icmp6_filter	*in6p_icmp6filt;
3127b709f8aSRobert Watson 		/* (i) IPV6_CHECKSUM setsockopt */
313cc65eb4eSGleb Smirnoff 		int	in6p_cksum;
314cc65eb4eSGleb Smirnoff 		short	in6p_hops;
315cc65eb4eSGleb Smirnoff 	};
316ff9b006dSJulien Charbon 	LIST_ENTRY(inpcb) inp_portlist;	/* (i/h) */
317ff9b006dSJulien Charbon 	struct	inpcbport *inp_phd;	/* (i/h) head of this list */
318a5654bb2SRobert Watson 	inp_gen_t	inp_gencnt;	/* (c) generation count */
319114f15c6SKip Macy 	struct llentry	*inp_lle;	/* cached L2 information */
32084cc0778SGeorge V. Neville-Neil 	rt_gen_t	inp_rt_cookie;	/* generation for route entry */
32184cc0778SGeorge V. Neville-Neil 	union {				/* cached L3 information */
3226a6cefacSGleb Smirnoff 		struct route inp_route;
3236a6cefacSGleb Smirnoff 		struct route_in6 inp_route6;
3246a6cefacSGleb Smirnoff 	};
3256a6cefacSGleb Smirnoff 	LIST_ENTRY(inpcb) inp_list;	/* (p/l) list for all PCBs for proto */
3266a6cefacSGleb Smirnoff 	                                /* (p[w]) for list iteration */
3276a6cefacSGleb Smirnoff 	                                /* (p[r]/l) for addition/removal */
328a5654bb2SRobert Watson };
329cc65eb4eSGleb Smirnoff #endif	/* _KERNEL */
330cc65eb4eSGleb Smirnoff 
331a5654bb2SRobert Watson #define	inp_fport	inp_inc.inc_fport
332a5654bb2SRobert Watson #define	inp_lport	inp_inc.inc_lport
333a5654bb2SRobert Watson #define	inp_faddr	inp_inc.inc_faddr
334a5654bb2SRobert Watson #define	inp_laddr	inp_inc.inc_laddr
335f76fcf6dSJeffrey Hsu 
336be2ac88cSJonathan Lemon #define	in6p_faddr	inp_inc.inc6_faddr
337be2ac88cSJonathan Lemon #define	in6p_laddr	inp_inc.inc6_laddr
338028bdf28SAndrey V. Elsukov #define	in6p_zoneid	inp_inc.inc6_zoneid
33982cd038dSYoshinobu Inoue #define	in6p_flowinfo	inp_flow
340a5654bb2SRobert Watson 
341f6dfe47aSMarko Zec #define	inp_vnet	inp_pcbinfo->ipi_vnet
342f6dfe47aSMarko Zec 
3433d4d47f3SGarrett Wollman /*
344712fc218SRobert Watson  * The range of the generation count, as used in this implementation, is 9e19.
345712fc218SRobert Watson  * We would have to create 300 billion connections per second for this number
346712fc218SRobert Watson  * to roll over in a year.  This seems sufficiently unlikely that we simply
347712fc218SRobert Watson  * don't concern ourselves with that possibility.
3483d4d47f3SGarrett Wollman  */
349c3229e05SDavid Greenman 
35098271db4SGarrett Wollman /*
351712fc218SRobert Watson  * Interface exported to userland by various protocols which use inpcbs.  Hack
352712fc218SRobert Watson  * alert -- only define if struct xsocket is in scope.
353cc65eb4eSGleb Smirnoff  * Fields prefixed with "xi_" are unique to this structure, and the rest
354cc65eb4eSGleb Smirnoff  * match fields in the struct inpcb, to ease coding and porting.
355cc65eb4eSGleb Smirnoff  *
356cc65eb4eSGleb Smirnoff  * Legend:
357cc65eb4eSGleb Smirnoff  * (s) - used by userland utilities in src
358cc65eb4eSGleb Smirnoff  * (p) - used by utilities in ports
359cc65eb4eSGleb Smirnoff  * (3) - is known to be used by third party software not in ports
360cc65eb4eSGleb Smirnoff  * (n) - no known usage
36198271db4SGarrett Wollman  */
36298271db4SGarrett Wollman #ifdef _SYS_SOCKETVAR_H_
36398271db4SGarrett Wollman struct xinpcb {
36498271db4SGarrett Wollman 	size_t		xi_len;		/* length of this structure */
365cc65eb4eSGleb Smirnoff 	struct xsocket	xi_socket;		/* (s,p) */
366cc65eb4eSGleb Smirnoff 	struct in_conninfo inp_inc;		/* (s,p) */
367cc65eb4eSGleb Smirnoff 	uint64_t	inp_gencnt;		/* (s,p) */
368cc65eb4eSGleb Smirnoff 	union {
369cc65eb4eSGleb Smirnoff 		void	*inp_ppcb;		/* (s) netstat(1) */
370cc65eb4eSGleb Smirnoff 		int64_t	ph_ppcb;
37198271db4SGarrett Wollman 	};
372cc65eb4eSGleb Smirnoff 	int64_t		inp_spare64[4];
373cc65eb4eSGleb Smirnoff 	uint32_t	inp_flow;		/* (s) */
374cc65eb4eSGleb Smirnoff 	uint32_t	inp_flowid;		/* (s) */
375cc65eb4eSGleb Smirnoff 	uint32_t	inp_flowtype;		/* (s) */
376cc65eb4eSGleb Smirnoff 	int32_t		inp_flags;		/* (s,p) */
377cc65eb4eSGleb Smirnoff 	int32_t		inp_flags2;		/* (s) */
378cc65eb4eSGleb Smirnoff 	int32_t		inp_rss_listen_bucket;	/* (n) */
379cc65eb4eSGleb Smirnoff 	int32_t		in6p_cksum;		/* (n) */
380cc65eb4eSGleb Smirnoff 	int32_t		inp_spare32[4];
381cc65eb4eSGleb Smirnoff 	uint16_t	in6p_hops;		/* (n) */
382cc65eb4eSGleb Smirnoff 	uint8_t		inp_ip_tos;		/* (n) */
383cc65eb4eSGleb Smirnoff 	int8_t		pad8;
384cc65eb4eSGleb Smirnoff 	uint8_t		inp_vflag;		/* (s,p) */
385cc65eb4eSGleb Smirnoff 	uint8_t		inp_ip_ttl;		/* (n) */
386cc65eb4eSGleb Smirnoff 	uint8_t		inp_ip_p;		/* (n) */
387cc65eb4eSGleb Smirnoff 	uint8_t		inp_ip_minttl;		/* (n) */
388cc65eb4eSGleb Smirnoff 	int8_t		inp_spare8[4];
389cc65eb4eSGleb Smirnoff } __aligned(8);
39098271db4SGarrett Wollman 
39198271db4SGarrett Wollman struct xinpgen {
39298271db4SGarrett Wollman 	size_t		xig_len;	/* length of this structure */
39398271db4SGarrett Wollman 	u_int		xig_count;	/* number of PCBs at this time */
39498271db4SGarrett Wollman 	inp_gen_t	xig_gen;	/* generation count at this time */
395cc65eb4eSGleb Smirnoff 	so_gen_t	xig_sogen;	/* socket generation count this time */
3963ae4b0e7SGleb Smirnoff } __aligned(8);
397cc65eb4eSGleb Smirnoff #ifdef	_KERNEL
398cc65eb4eSGleb Smirnoff void	in_pcbtoxinpcb(const struct inpcb *, struct xinpcb *);
399cc65eb4eSGleb Smirnoff #endif
40098271db4SGarrett Wollman #endif /* _SYS_SOCKETVAR_H_ */
40198271db4SGarrett Wollman 
402c3229e05SDavid Greenman struct inpcbport {
403e3975643SJake Burkholder 	LIST_ENTRY(inpcbport) phd_hash;
404c3229e05SDavid Greenman 	struct inpcbhead phd_pcblist;
405c3229e05SDavid Greenman 	u_short phd_port;
406df8bae1dSRodney W. Grimes };
407df8bae1dSRodney W. Grimes 
408ddece765SMatt Macy struct in_pcblist {
409ddece765SMatt Macy 	int il_count;
410ddece765SMatt Macy 	struct epoch_context il_epoch_ctx;
411ddece765SMatt Macy 	struct inpcbinfo *il_pcbinfo;
412ddece765SMatt Macy 	struct inpcb *il_inp_list[0];
413ddece765SMatt Macy };
414ddece765SMatt Macy 
41582a5be49SRobert Watson /*-
416712fc218SRobert Watson  * Global data structure for each high-level protocol (UDP, TCP, ...) in both
417712fc218SRobert Watson  * IPv4 and IPv6.  Holds inpcb lists and information for managing them.
41882a5be49SRobert Watson  *
419ff9b006dSJulien Charbon  * Each pcbinfo is protected by three locks: ipi_lock, ipi_hash_lock and
420ff9b006dSJulien Charbon  * ipi_list_lock:
421ff9b006dSJulien Charbon  *  - ipi_lock covering the global pcb list stability during loop iteration,
422ff9b006dSJulien Charbon  *  - ipi_hash_lock covering the hashed lookup tables,
423ff9b006dSJulien Charbon  *  - ipi_list_lock covering mutable global fields (such as the global
424ff9b006dSJulien Charbon  *    pcb list)
42582a5be49SRobert Watson  *
426ff9b006dSJulien Charbon  * The lock order is:
427ff9b006dSJulien Charbon  *
428ff9b006dSJulien Charbon  *    ipi_lock (before)
429ff9b006dSJulien Charbon  *        inpcb locks (before)
430ff9b006dSJulien Charbon  *            ipi_list locks (before)
431ff9b006dSJulien Charbon  *                {ipi_hash_lock, pcbgroup locks}
43282a5be49SRobert Watson  *
43382a5be49SRobert Watson  * Locking key:
43482a5be49SRobert Watson  *
43582a5be49SRobert Watson  * (c) Constant or nearly constant after initialisation
43682a5be49SRobert Watson  * (g) Locked by ipi_lock
437ff9b006dSJulien Charbon  * (l) Locked by ipi_list_lock
43852cd27cbSRobert Watson  * (h) Read using either ipi_hash_lock or inpcb lock; write requires both
43952cd27cbSRobert Watson  * (p) Protected by one or more pcbgroup locks
44082a5be49SRobert Watson  * (x) Synchronisation properties poorly defined
441712fc218SRobert Watson  */
442712fc218SRobert Watson struct inpcbinfo {
443712fc218SRobert Watson 	/*
444ff9b006dSJulien Charbon 	 * Global lock protecting full inpcb list traversal
44582a5be49SRobert Watson 	 */
44682a5be49SRobert Watson 	struct rwlock		 ipi_lock;
44782a5be49SRobert Watson 
44882a5be49SRobert Watson 	/*
449712fc218SRobert Watson 	 * Global list of inpcbs on the protocol.
450712fc218SRobert Watson 	 */
451ff9b006dSJulien Charbon 	struct inpcbhead	*ipi_listhead;		/* (g/l) */
452ff9b006dSJulien Charbon 	u_int			 ipi_count;		/* (l) */
453712fc218SRobert Watson 
454712fc218SRobert Watson 	/*
455712fc218SRobert Watson 	 * Generation count -- incremented each time a connection is allocated
456712fc218SRobert Watson 	 * or freed.
457712fc218SRobert Watson 	 */
458ff9b006dSJulien Charbon 	u_quad_t		 ipi_gencnt;		/* (l) */
45982a5be49SRobert Watson 
46082a5be49SRobert Watson 	/*
46182a5be49SRobert Watson 	 * Fields associated with port lookup and allocation.
46282a5be49SRobert Watson 	 */
46382a5be49SRobert Watson 	u_short			 ipi_lastport;		/* (x) */
46482a5be49SRobert Watson 	u_short			 ipi_lastlow;		/* (x) */
46582a5be49SRobert Watson 	u_short			 ipi_lasthi;		/* (x) */
46682a5be49SRobert Watson 
46782a5be49SRobert Watson 	/*
46882a5be49SRobert Watson 	 * UMA zone from which inpcbs are allocated for this protocol.
46982a5be49SRobert Watson 	 */
47082a5be49SRobert Watson 	struct	uma_zone	*ipi_zone;		/* (c) */
47182a5be49SRobert Watson 
47282a5be49SRobert Watson 	/*
47352cd27cbSRobert Watson 	 * Connection groups associated with this protocol.  These fields are
47452cd27cbSRobert Watson 	 * constant, but pcbgroup structures themselves are protected by
47552cd27cbSRobert Watson 	 * per-pcbgroup locks.
47652cd27cbSRobert Watson 	 */
47752cd27cbSRobert Watson 	struct inpcbgroup	*ipi_pcbgroups;		/* (c) */
47852cd27cbSRobert Watson 	u_int			 ipi_npcbgroups;	/* (c) */
47952cd27cbSRobert Watson 	u_int			 ipi_hashfields;	/* (c) */
48052cd27cbSRobert Watson 
48152cd27cbSRobert Watson 	/*
48252cd27cbSRobert Watson 	 * Global lock protecting non-pcbgroup hash lookup tables.
483fa046d87SRobert Watson 	 */
484f89d4c3aSAndre Oppermann 	struct rwlock		 ipi_hash_lock;
485fa046d87SRobert Watson 
486fa046d87SRobert Watson 	/*
48782a5be49SRobert Watson 	 * Global hash of inpcbs, hashed by local and foreign addresses and
48882a5be49SRobert Watson 	 * port numbers.
48982a5be49SRobert Watson 	 */
490fa046d87SRobert Watson 	struct inpcbhead	*ipi_hashbase;		/* (h) */
491fa046d87SRobert Watson 	u_long			 ipi_hashmask;		/* (h) */
49282a5be49SRobert Watson 
49382a5be49SRobert Watson 	/*
49482a5be49SRobert Watson 	 * Global hash of inpcbs, hashed by only local port number.
49582a5be49SRobert Watson 	 */
496fa046d87SRobert Watson 	struct inpcbporthead	*ipi_porthashbase;	/* (h) */
497fa046d87SRobert Watson 	u_long			 ipi_porthashmask;	/* (h) */
4982de2af32SKip Macy 
4992de2af32SKip Macy 	/*
50052cd27cbSRobert Watson 	 * List of wildcard inpcbs for use with pcbgroups.  In the past, was
50152cd27cbSRobert Watson 	 * per-pcbgroup but is now global.  All pcbgroup locks must be held
50252cd27cbSRobert Watson 	 * to modify the list, so any is sufficient to read it.
50352cd27cbSRobert Watson 	 */
50452cd27cbSRobert Watson 	struct inpcbhead	*ipi_wildbase;		/* (p) */
50552cd27cbSRobert Watson 	u_long			 ipi_wildmask;		/* (p) */
50652cd27cbSRobert Watson 
50752cd27cbSRobert Watson 	/*
508*1a43cff9SSean Bruno 	 * Load balance groups used for the SO_REUSEPORT_LB option,
509*1a43cff9SSean Bruno 	 * hashed by local port.
510*1a43cff9SSean Bruno 	 */
511*1a43cff9SSean Bruno 	struct	inpcblbgrouphead *ipi_lbgrouphashbase;	/* (h) */
512*1a43cff9SSean Bruno 	u_long			 ipi_lbgrouphashmask;	/* (h) */
513*1a43cff9SSean Bruno 
514*1a43cff9SSean Bruno 	/*
515f6dfe47aSMarko Zec 	 * Pointer to network stack instance
516f6dfe47aSMarko Zec 	 */
51782a5be49SRobert Watson 	struct vnet		*ipi_vnet;		/* (c) */
518f6dfe47aSMarko Zec 
519f6dfe47aSMarko Zec 	/*
520f6dfe47aSMarko Zec 	 * general use 2
5212de2af32SKip Macy 	 */
5222de2af32SKip Macy 	void 			*ipi_pspare[2];
523ff9b006dSJulien Charbon 
524ff9b006dSJulien Charbon 	/*
525ff9b006dSJulien Charbon 	 * Global lock protecting global inpcb list, inpcb count, etc.
526ff9b006dSJulien Charbon 	 */
527ff9b006dSJulien Charbon 	struct rwlock		 ipi_list_lock;
52815bd2b43SDavid Greenman };
52915bd2b43SDavid Greenman 
53075410f02SRobert Millan #ifdef _KERNEL
53152cd27cbSRobert Watson /*
53252cd27cbSRobert Watson  * Connection groups hold sets of connections that have similar CPU/thread
53352cd27cbSRobert Watson  * affinity.  Each connection belongs to exactly one connection group.
53452cd27cbSRobert Watson  */
53552cd27cbSRobert Watson struct inpcbgroup {
53652cd27cbSRobert Watson 	/*
53752cd27cbSRobert Watson 	 * Per-connection group hash of inpcbs, hashed by local and foreign
53852cd27cbSRobert Watson 	 * addresses and port numbers.
53952cd27cbSRobert Watson 	 */
54052cd27cbSRobert Watson 	struct inpcbhead	*ipg_hashbase;		/* (c) */
54152cd27cbSRobert Watson 	u_long			 ipg_hashmask;		/* (c) */
54252cd27cbSRobert Watson 
54352cd27cbSRobert Watson 	/*
54452cd27cbSRobert Watson 	 * Notional affinity of this pcbgroup.
54552cd27cbSRobert Watson 	 */
54652cd27cbSRobert Watson 	u_int			 ipg_cpu;		/* (p) */
54752cd27cbSRobert Watson 
54852cd27cbSRobert Watson 	/*
54952cd27cbSRobert Watson 	 * Per-connection group lock, not to be confused with ipi_lock.
55052cd27cbSRobert Watson 	 * Protects the hash table hung off the group, but also the global
55152cd27cbSRobert Watson 	 * wildcard list in inpcbinfo.
55252cd27cbSRobert Watson 	 */
55352cd27cbSRobert Watson 	struct mtx		 ipg_lock;
55452cd27cbSRobert Watson } __aligned(CACHE_LINE_SIZE);
55552cd27cbSRobert Watson 
556*1a43cff9SSean Bruno /*
557*1a43cff9SSean Bruno  * Load balance groups used for the SO_REUSEPORT_LB socket option. Each group
558*1a43cff9SSean Bruno  * (or unique address:port combination) can be re-used at most
559*1a43cff9SSean Bruno  * INPCBLBGROUP_SIZMAX (256) times. The inpcbs are stored in il_inp which
560*1a43cff9SSean Bruno  * is dynamically resized as processes bind/unbind to that specific group.
561*1a43cff9SSean Bruno  */
562*1a43cff9SSean Bruno struct inpcblbgroup {
563*1a43cff9SSean Bruno 	LIST_ENTRY(inpcblbgroup) il_list;
564*1a43cff9SSean Bruno 	uint16_t	il_lport;			/* (c) */
565*1a43cff9SSean Bruno 	u_char		il_vflag;			/* (c) */
566*1a43cff9SSean Bruno 	u_char		il_pad;
567*1a43cff9SSean Bruno 	uint32_t	il_pad2;
568*1a43cff9SSean Bruno 	union in_dependaddr il_dependladdr;		/* (c) */
569*1a43cff9SSean Bruno #define	il_laddr	il_dependladdr.id46_addr.ia46_addr4
570*1a43cff9SSean Bruno #define	il6_laddr	il_dependladdr.id6_addr
571*1a43cff9SSean Bruno 	uint32_t	il_inpsiz; /* max count in il_inp[] (h) */
572*1a43cff9SSean Bruno 	uint32_t	il_inpcnt; /* cur count in il_inp[] (h) */
573*1a43cff9SSean Bruno 	struct inpcb	*il_inp[];			/* (h) */
574*1a43cff9SSean Bruno };
575*1a43cff9SSean Bruno LIST_HEAD(inpcblbgrouphead, inpcblbgroup);
576*1a43cff9SSean Bruno 
5775bd311a5SSam Leffler #define INP_LOCK_INIT(inp, d, t) \
5788501a69cSRobert Watson 	rw_init_flags(&(inp)->inp_lock, (t), RW_RECURSE |  RW_DUPOK)
5798501a69cSRobert Watson #define INP_LOCK_DESTROY(inp)	rw_destroy(&(inp)->inp_lock)
5808501a69cSRobert Watson #define INP_RLOCK(inp)		rw_rlock(&(inp)->inp_lock)
5818501a69cSRobert Watson #define INP_WLOCK(inp)		rw_wlock(&(inp)->inp_lock)
58243cc0bc1SRobert Watson #define INP_TRY_RLOCK(inp)	rw_try_rlock(&(inp)->inp_lock)
58343cc0bc1SRobert Watson #define INP_TRY_WLOCK(inp)	rw_try_wlock(&(inp)->inp_lock)
5848501a69cSRobert Watson #define INP_RUNLOCK(inp)	rw_runlock(&(inp)->inp_lock)
5858501a69cSRobert Watson #define INP_WUNLOCK(inp)	rw_wunlock(&(inp)->inp_lock)
58682c33e73SKip Macy #define	INP_TRY_UPGRADE(inp)	rw_try_upgrade(&(inp)->inp_lock)
58782c33e73SKip Macy #define	INP_DOWNGRADE(inp)	rw_downgrade(&(inp)->inp_lock)
58882c33e73SKip Macy #define	INP_WLOCKED(inp)	rw_wowned(&(inp)->inp_lock)
5898501a69cSRobert Watson #define	INP_LOCK_ASSERT(inp)	rw_assert(&(inp)->inp_lock, RA_LOCKED)
5908501a69cSRobert Watson #define	INP_RLOCK_ASSERT(inp)	rw_assert(&(inp)->inp_lock, RA_RLOCKED)
5918501a69cSRobert Watson #define	INP_WLOCK_ASSERT(inp)	rw_assert(&(inp)->inp_lock, RA_WLOCKED)
5928501a69cSRobert Watson #define	INP_UNLOCK_ASSERT(inp)	rw_assert(&(inp)->inp_lock, RA_UNLOCKED)
593f76fcf6dSJeffrey Hsu 
5943d585327SKip Macy /*
5953d585327SKip Macy  * These locking functions are for inpcb consumers outside of sys/netinet,
5963d585327SKip Macy  * more specifically, they were added for the benefit of TOE drivers. The
5973d585327SKip Macy  * macros are reserved for use by the stack.
5983d585327SKip Macy  */
5993d585327SKip Macy void inp_wlock(struct inpcb *);
6003d585327SKip Macy void inp_wunlock(struct inpcb *);
6013d585327SKip Macy void inp_rlock(struct inpcb *);
6023d585327SKip Macy void inp_runlock(struct inpcb *);
6033d585327SKip Macy 
604c75e2666SGleb Smirnoff #ifdef INVARIANT_SUPPORT
605e79dd20dSKip Macy void inp_lock_assert(struct inpcb *);
606e79dd20dSKip Macy void inp_unlock_assert(struct inpcb *);
6073d585327SKip Macy #else
608c75e2666SGleb Smirnoff #define	inp_lock_assert(inp)	do {} while (0)
609c75e2666SGleb Smirnoff #define	inp_unlock_assert(inp)	do {} while (0)
6103d585327SKip Macy #endif
6119378e437SKip Macy 
6129378e437SKip Macy void	inp_apply_all(void (*func)(struct inpcb *, void *), void *arg);
6139378e437SKip Macy int 	inp_ip_tos_get(const struct inpcb *inp);
6149378e437SKip Macy void 	inp_ip_tos_set(struct inpcb *inp, int val);
6159d29c635SKip Macy struct socket *
6169d29c635SKip Macy 	inp_inpcbtosocket(struct inpcb *inp);
6179d29c635SKip Macy struct tcpcb *
6189d29c635SKip Macy 	inp_inpcbtotcpcb(struct inpcb *inp);
619df9cf830STai-hwa Liang void 	inp_4tuple_get(struct inpcb *inp, uint32_t *laddr, uint16_t *lp,
6209d29c635SKip Macy 		uint32_t *faddr, uint16_t *fp);
621*1a43cff9SSean Bruno int	inp_so_options(const struct inpcb *inp);
6229378e437SKip Macy 
623e79dd20dSKip Macy #endif /* _KERNEL */
6243d585327SKip Macy 
625f76fcf6dSJeffrey Hsu #define INP_INFO_LOCK_INIT(ipi, d) \
6268501a69cSRobert Watson 	rw_init_flags(&(ipi)->ipi_lock, (d), RW_RECURSE)
6278501a69cSRobert Watson #define INP_INFO_LOCK_DESTROY(ipi)  rw_destroy(&(ipi)->ipi_lock)
6288501a69cSRobert Watson #define INP_INFO_RLOCK(ipi)	rw_rlock(&(ipi)->ipi_lock)
6298501a69cSRobert Watson #define INP_INFO_WLOCK(ipi)	rw_wlock(&(ipi)->ipi_lock)
63043cc0bc1SRobert Watson #define INP_INFO_TRY_RLOCK(ipi)	rw_try_rlock(&(ipi)->ipi_lock)
63143cc0bc1SRobert Watson #define INP_INFO_TRY_WLOCK(ipi)	rw_try_wlock(&(ipi)->ipi_lock)
63266f80e90SRobert Watson #define INP_INFO_TRY_UPGRADE(ipi)	rw_try_upgrade(&(ipi)->ipi_lock)
633079672cbSJulien Charbon #define INP_INFO_WLOCKED(ipi)	rw_wowned(&(ipi)->ipi_lock)
6348501a69cSRobert Watson #define INP_INFO_RUNLOCK(ipi)	rw_runlock(&(ipi)->ipi_lock)
6358501a69cSRobert Watson #define INP_INFO_WUNLOCK(ipi)	rw_wunlock(&(ipi)->ipi_lock)
6368501a69cSRobert Watson #define	INP_INFO_LOCK_ASSERT(ipi)	rw_assert(&(ipi)->ipi_lock, RA_LOCKED)
6378501a69cSRobert Watson #define INP_INFO_RLOCK_ASSERT(ipi)	rw_assert(&(ipi)->ipi_lock, RA_RLOCKED)
6388501a69cSRobert Watson #define INP_INFO_WLOCK_ASSERT(ipi)	rw_assert(&(ipi)->ipi_lock, RA_WLOCKED)
6398501a69cSRobert Watson #define INP_INFO_UNLOCK_ASSERT(ipi)	rw_assert(&(ipi)->ipi_lock, RA_UNLOCKED)
640f76fcf6dSJeffrey Hsu 
641ff9b006dSJulien Charbon #define INP_LIST_LOCK_INIT(ipi, d) \
642ff9b006dSJulien Charbon         rw_init_flags(&(ipi)->ipi_list_lock, (d), 0)
643ff9b006dSJulien Charbon #define INP_LIST_LOCK_DESTROY(ipi)  rw_destroy(&(ipi)->ipi_list_lock)
644ff9b006dSJulien Charbon #define INP_LIST_RLOCK(ipi)     rw_rlock(&(ipi)->ipi_list_lock)
645ff9b006dSJulien Charbon #define INP_LIST_WLOCK(ipi)     rw_wlock(&(ipi)->ipi_list_lock)
646ff9b006dSJulien Charbon #define INP_LIST_TRY_RLOCK(ipi) rw_try_rlock(&(ipi)->ipi_list_lock)
647ff9b006dSJulien Charbon #define INP_LIST_TRY_WLOCK(ipi) rw_try_wlock(&(ipi)->ipi_list_lock)
648ff9b006dSJulien Charbon #define INP_LIST_TRY_UPGRADE(ipi)       rw_try_upgrade(&(ipi)->ipi_list_lock)
649ff9b006dSJulien Charbon #define INP_LIST_RUNLOCK(ipi)   rw_runlock(&(ipi)->ipi_list_lock)
650ff9b006dSJulien Charbon #define INP_LIST_WUNLOCK(ipi)   rw_wunlock(&(ipi)->ipi_list_lock)
651ff9b006dSJulien Charbon #define INP_LIST_LOCK_ASSERT(ipi) \
652ff9b006dSJulien Charbon 	rw_assert(&(ipi)->ipi_list_lock, RA_LOCKED)
653ff9b006dSJulien Charbon #define INP_LIST_RLOCK_ASSERT(ipi) \
654ff9b006dSJulien Charbon 	rw_assert(&(ipi)->ipi_list_lock, RA_RLOCKED)
655ff9b006dSJulien Charbon #define INP_LIST_WLOCK_ASSERT(ipi) \
656ff9b006dSJulien Charbon 	rw_assert(&(ipi)->ipi_list_lock, RA_WLOCKED)
657ff9b006dSJulien Charbon #define INP_LIST_UNLOCK_ASSERT(ipi) \
658ff9b006dSJulien Charbon 	rw_assert(&(ipi)->ipi_list_lock, RA_UNLOCKED)
659ff9b006dSJulien Charbon 
660fa046d87SRobert Watson #define	INP_HASH_LOCK_INIT(ipi, d) \
661fa046d87SRobert Watson 	rw_init_flags(&(ipi)->ipi_hash_lock, (d), 0)
662fa046d87SRobert Watson #define	INP_HASH_LOCK_DESTROY(ipi)	rw_destroy(&(ipi)->ipi_hash_lock)
663fa046d87SRobert Watson #define	INP_HASH_RLOCK(ipi)		rw_rlock(&(ipi)->ipi_hash_lock)
664fa046d87SRobert Watson #define	INP_HASH_WLOCK(ipi)		rw_wlock(&(ipi)->ipi_hash_lock)
665fa046d87SRobert Watson #define	INP_HASH_RUNLOCK(ipi)		rw_runlock(&(ipi)->ipi_hash_lock)
666fa046d87SRobert Watson #define	INP_HASH_WUNLOCK(ipi)		rw_wunlock(&(ipi)->ipi_hash_lock)
667fa046d87SRobert Watson #define	INP_HASH_LOCK_ASSERT(ipi)	rw_assert(&(ipi)->ipi_hash_lock, \
668fa046d87SRobert Watson 					    RA_LOCKED)
669fa046d87SRobert Watson #define	INP_HASH_WLOCK_ASSERT(ipi)	rw_assert(&(ipi)->ipi_hash_lock, \
670fa046d87SRobert Watson 					    RA_WLOCKED)
671fa046d87SRobert Watson 
67252cd27cbSRobert Watson #define	INP_GROUP_LOCK_INIT(ipg, d)	mtx_init(&(ipg)->ipg_lock, (d), NULL, \
67352cd27cbSRobert Watson 					    MTX_DEF | MTX_DUPOK)
67452cd27cbSRobert Watson #define	INP_GROUP_LOCK_DESTROY(ipg)	mtx_destroy(&(ipg)->ipg_lock)
67552cd27cbSRobert Watson 
67652cd27cbSRobert Watson #define	INP_GROUP_LOCK(ipg)		mtx_lock(&(ipg)->ipg_lock)
67752cd27cbSRobert Watson #define	INP_GROUP_LOCK_ASSERT(ipg)	mtx_assert(&(ipg)->ipg_lock, MA_OWNED)
67852cd27cbSRobert Watson #define	INP_GROUP_UNLOCK(ipg)		mtx_unlock(&(ipg)->ipg_lock)
67952cd27cbSRobert Watson 
680ddd79a97SDavid Greenman #define INP_PCBHASH(faddr, lport, fport, mask) \
681c3229e05SDavid Greenman 	(((faddr) ^ ((faddr) >> 16) ^ ntohs((lport) ^ (fport))) & (mask))
682c3229e05SDavid Greenman #define INP_PCBPORTHASH(lport, mask) \
683c3229e05SDavid Greenman 	(ntohs((lport)) & (mask))
684*1a43cff9SSean Bruno #define	INP_PCBLBGROUP_PORTHASH(lport, mask) \
685*1a43cff9SSean Bruno 	(ntohs((lport)) & (mask))
686*1a43cff9SSean Bruno #define	INP_PCBLBGROUP_PKTHASH(faddr, lport, fport) \
687*1a43cff9SSean Bruno 	((faddr) ^ ((faddr) >> 16) ^ ntohs((lport) ^ (fport)))
6881b44e5ffSAndrey V. Elsukov #define	INP6_PCBHASHKEY(faddr)	((faddr)->s6_addr32[3])
689ddd79a97SDavid Greenman 
690a5654bb2SRobert Watson /*
691773b573aSKip Macy  * Flags for inp_vflags -- historically version flags only
692a5654bb2SRobert Watson  */
693a5654bb2SRobert Watson #define	INP_IPV4	0x1
694a5654bb2SRobert Watson #define	INP_IPV6	0x2
695a5654bb2SRobert Watson #define	INP_IPV6PROTO	0x4		/* opened under IPv6 protocol */
696a5654bb2SRobert Watson 
697a5654bb2SRobert Watson /*
698773b573aSKip Macy  * Flags for inp_flags.
699a5654bb2SRobert Watson  */
700ad71fe3cSRobert Watson #define	INP_RECVOPTS		0x00000001 /* receive incoming IP options */
701ad71fe3cSRobert Watson #define	INP_RECVRETOPTS		0x00000002 /* receive IP options for reply */
702ad71fe3cSRobert Watson #define	INP_RECVDSTADDR		0x00000004 /* receive IP dst address */
703ad71fe3cSRobert Watson #define	INP_HDRINCL		0x00000008 /* user supplies entire IP header */
704ad71fe3cSRobert Watson #define	INP_HIGHPORT		0x00000010 /* user wants "high" port binding */
705ad71fe3cSRobert Watson #define	INP_LOWPORT		0x00000020 /* user wants "low" port binding */
706ad71fe3cSRobert Watson #define	INP_ANONPORT		0x00000040 /* port chosen for user */
707ad71fe3cSRobert Watson #define	INP_RECVIF		0x00000080 /* receive incoming interface */
708ad71fe3cSRobert Watson #define	INP_MTUDISC		0x00000100 /* user can do MTU discovery */
709603eaf79SAlexander V. Chernikov 				   	   /* 0x000200 unused: was INP_FAITH */
710ad71fe3cSRobert Watson #define	INP_RECVTTL		0x00000400 /* receive incoming IP TTL */
711ad71fe3cSRobert Watson #define	INP_DONTFRAG		0x00000800 /* don't fragment packet */
712f44270e7SPawel Jakub Dawidek #define	INP_BINDANY		0x00001000 /* allow bind to any address */
713ad71fe3cSRobert Watson #define	INP_INHASHLIST		0x00002000 /* in_pcbinshash() has been called */
7143cca425bSMichael Tuexen #define	INP_RECVTOS		0x00004000 /* receive incoming IP TOS */
715ad71fe3cSRobert Watson #define	IN6P_IPV6_V6ONLY	0x00008000 /* restrict AF_INET6 socket for v6 */
716ad71fe3cSRobert Watson #define	IN6P_PKTINFO		0x00010000 /* receive IP6 dst and I/F */
717ad71fe3cSRobert Watson #define	IN6P_HOPLIMIT		0x00020000 /* receive hoplimit */
718ad71fe3cSRobert Watson #define	IN6P_HOPOPTS		0x00040000 /* receive hop-by-hop options */
719ad71fe3cSRobert Watson #define	IN6P_DSTOPTS		0x00080000 /* receive dst options after rthdr */
720ad71fe3cSRobert Watson #define	IN6P_RTHDR		0x00100000 /* receive routing header */
721ad71fe3cSRobert Watson #define	IN6P_RTHDRDSTOPTS	0x00200000 /* receive dstoptions before rthdr */
722ad71fe3cSRobert Watson #define	IN6P_TCLASS		0x00400000 /* receive traffic class value */
723ad71fe3cSRobert Watson #define	IN6P_AUTOFLOWLABEL	0x00800000 /* attach flowlabel automatically */
724ad71fe3cSRobert Watson #define	INP_TIMEWAIT		0x01000000 /* in TIMEWAIT, ppcb is tcptw */
725ad71fe3cSRobert Watson #define	INP_ONESBCAST		0x02000000 /* send all-ones broadcast */
726ad71fe3cSRobert Watson #define	INP_DROPPED		0x04000000 /* protocol drop flag */
727ad71fe3cSRobert Watson #define	INP_SOCKREF		0x08000000 /* strong socket reference */
728c2529042SHans Petter Selasky #define	INP_RESERVED_0          0x10000000 /* reserved field */
729c2529042SHans Petter Selasky #define	INP_RESERVED_1          0x20000000 /* reserved field */
730f95d4633SHajimu UMEMOTO #define	IN6P_RFC2292		0x40000000 /* used RFC2292 API on the socket */
731f95d4633SHajimu UMEMOTO #define	IN6P_MTU		0x80000000 /* receive path MTU */
73233841545SHajimu UMEMOTO 
73382c23ebaSBill Fenner #define	INP_CONTROLOPTS		(INP_RECVOPTS|INP_RECVRETOPTS|INP_RECVDSTADDR|\
7343cca425bSMichael Tuexen 				 INP_RECVIF|INP_RECVTTL|INP_RECVTOS|\
73533841545SHajimu UMEMOTO 				 IN6P_PKTINFO|IN6P_HOPLIMIT|IN6P_HOPOPTS|\
73633841545SHajimu UMEMOTO 				 IN6P_DSTOPTS|IN6P_RTHDR|IN6P_RTHDRDSTOPTS|\
737f95d4633SHajimu UMEMOTO 				 IN6P_TCLASS|IN6P_AUTOFLOWLABEL|IN6P_RFC2292|\
738f95d4633SHajimu UMEMOTO 				 IN6P_MTU)
73982cd038dSYoshinobu Inoue 
740773b573aSKip Macy /*
741773b573aSKip Macy  * Flags for inp_flags2.
742773b573aSKip Macy  */
7438b12a7c2SKip Macy #define	INP_LLE_VALID		0x00000001 /* cached lle is valid */
7448b12a7c2SKip Macy #define	INP_RT_VALID		0x00000002 /* cached rtentry is valid */
74552cd27cbSRobert Watson #define	INP_PCBGROUPWILD	0x00000004 /* in pcbgroup wildcard list */
746fc06cd42SMikolaj Golub #define	INP_REUSEPORT		0x00000008 /* SO_REUSEPORT option is set */
747df4e91d3SGleb Smirnoff #define	INP_FREED		0x00000010 /* inp itself is not valid */
748efdf104bSMikolaj Golub #define	INP_REUSEADDR		0x00000020 /* SO_REUSEADDR option is set */
7490a100a6fSAdrian Chadd #define	INP_BINDMULTI		0x00000040 /* IP_BINDMULTI option is set */
7500a100a6fSAdrian Chadd #define	INP_RSS_BUCKET_SET	0x00000080 /* IP_RSS_LISTEN_BUCKET is set */
7519d3ddf43SAdrian Chadd #define	INP_RECVFLOWID		0x00000100 /* populate recv datagram with flow info */
7529d3ddf43SAdrian Chadd #define	INP_RECVRSSBUCKETID	0x00000200 /* populate recv datagram with bucket id */
753f3e7afe2SHans Petter Selasky #define	INP_RATE_LIMIT_CHANGED	0x00000400 /* rate limit needs attention */
754dce33a45SErmal Luçi #define	INP_ORIGDSTADDR		0x00000800 /* receive IP dst address/port */
7553ee9c3c4SRandall Stewart #define INP_CANNOT_DO_ECN	0x00001000 /* The stack does not do ECN */
756*1a43cff9SSean Bruno #define	INP_REUSEPORT_LB	0x00002000 /* SO_REUSEPORT_LB option is set */
757773b573aSKip Macy 
758fa046d87SRobert Watson /*
759fa046d87SRobert Watson  * Flags passed to in_pcblookup*() functions.
760fa046d87SRobert Watson  */
761fa046d87SRobert Watson #define	INPLOOKUP_WILDCARD	0x00000001	/* Allow wildcard sockets. */
762fa046d87SRobert Watson #define	INPLOOKUP_RLOCKPCB	0x00000002	/* Return inpcb read-locked. */
763fa046d87SRobert Watson #define	INPLOOKUP_WLOCKPCB	0x00000004	/* Return inpcb write-locked. */
764fa046d87SRobert Watson 
765fa046d87SRobert Watson #define	INPLOOKUP_MASK	(INPLOOKUP_WILDCARD | INPLOOKUP_RLOCKPCB | \
766fa046d87SRobert Watson 			    INPLOOKUP_WLOCKPCB)
767fa046d87SRobert Watson 
768df8bae1dSRodney W. Grimes #define	sotoinpcb(so)	((struct inpcb *)(so)->so_pcb)
76982cd038dSYoshinobu Inoue #define	sotoin6pcb(so)	sotoinpcb(so) /* for KAME src sync over BSD*'s */
77082cd038dSYoshinobu Inoue 
77182cd038dSYoshinobu Inoue #define	INP_SOCKAF(so) so->so_proto->pr_domain->dom_family
77282cd038dSYoshinobu Inoue 
77382cd038dSYoshinobu Inoue #define	INP_CHECK_SOCKAF(so, af)	(INP_SOCKAF(so) == af)
774df8bae1dSRodney W. Grimes 
77552cd27cbSRobert Watson /*
77652cd27cbSRobert Watson  * Constants for pcbinfo.ipi_hashfields.
77752cd27cbSRobert Watson  */
77852cd27cbSRobert Watson #define	IPI_HASHFIELDS_NONE	0
77952cd27cbSRobert Watson #define	IPI_HASHFIELDS_2TUPLE	1
78052cd27cbSRobert Watson #define	IPI_HASHFIELDS_4TUPLE	2
78152cd27cbSRobert Watson 
782664a31e4SPeter Wemm #ifdef _KERNEL
783eddfbb76SRobert Watson VNET_DECLARE(int, ipport_reservedhigh);
784eddfbb76SRobert Watson VNET_DECLARE(int, ipport_reservedlow);
785eddfbb76SRobert Watson VNET_DECLARE(int, ipport_lowfirstauto);
786eddfbb76SRobert Watson VNET_DECLARE(int, ipport_lowlastauto);
787eddfbb76SRobert Watson VNET_DECLARE(int, ipport_firstauto);
788eddfbb76SRobert Watson VNET_DECLARE(int, ipport_lastauto);
789eddfbb76SRobert Watson VNET_DECLARE(int, ipport_hifirstauto);
790eddfbb76SRobert Watson VNET_DECLARE(int, ipport_hilastauto);
791eddfbb76SRobert Watson VNET_DECLARE(int, ipport_randomized);
792eddfbb76SRobert Watson VNET_DECLARE(int, ipport_randomcps);
793eddfbb76SRobert Watson VNET_DECLARE(int, ipport_randomtime);
794eddfbb76SRobert Watson VNET_DECLARE(int, ipport_stoprandom);
795eddfbb76SRobert Watson VNET_DECLARE(int, ipport_tcpallocs);
796eddfbb76SRobert Watson 
7971e77c105SRobert Watson #define	V_ipport_reservedhigh	VNET(ipport_reservedhigh)
7981e77c105SRobert Watson #define	V_ipport_reservedlow	VNET(ipport_reservedlow)
7991e77c105SRobert Watson #define	V_ipport_lowfirstauto	VNET(ipport_lowfirstauto)
8001e77c105SRobert Watson #define	V_ipport_lowlastauto	VNET(ipport_lowlastauto)
8011e77c105SRobert Watson #define	V_ipport_firstauto	VNET(ipport_firstauto)
8021e77c105SRobert Watson #define	V_ipport_lastauto	VNET(ipport_lastauto)
8031e77c105SRobert Watson #define	V_ipport_hifirstauto	VNET(ipport_hifirstauto)
8041e77c105SRobert Watson #define	V_ipport_hilastauto	VNET(ipport_hilastauto)
8051e77c105SRobert Watson #define	V_ipport_randomized	VNET(ipport_randomized)
8061e77c105SRobert Watson #define	V_ipport_randomcps	VNET(ipport_randomcps)
8071e77c105SRobert Watson #define	V_ipport_randomtime	VNET(ipport_randomtime)
8081e77c105SRobert Watson #define	V_ipport_stoprandom	VNET(ipport_stoprandom)
8091e77c105SRobert Watson #define	V_ipport_tcpallocs	VNET(ipport_tcpallocs)
810eddfbb76SRobert Watson 
8119bcd427bSRobert Watson void	in_pcbinfo_destroy(struct inpcbinfo *);
8129bcd427bSRobert Watson void	in_pcbinfo_init(struct inpcbinfo *, const char *, struct inpcbhead *,
813cc487c16SGleb Smirnoff 	    int, int, char *, uma_init, u_int);
81452cd27cbSRobert Watson 
815d5bb8bd3SAdrian Chadd int	in_pcbbind_check_bindmulti(const struct inpcb *ni,
816d5bb8bd3SAdrian Chadd 	    const struct inpcb *oi);
817d5bb8bd3SAdrian Chadd 
81852cd27cbSRobert Watson struct inpcbgroup *
81952cd27cbSRobert Watson 	in_pcbgroup_byhash(struct inpcbinfo *, u_int, uint32_t);
82052cd27cbSRobert Watson struct inpcbgroup *
82152cd27cbSRobert Watson 	in_pcbgroup_byinpcb(struct inpcb *);
82252cd27cbSRobert Watson struct inpcbgroup *
82352cd27cbSRobert Watson 	in_pcbgroup_bytuple(struct inpcbinfo *, struct in_addr, u_short,
82452cd27cbSRobert Watson 	    struct in_addr, u_short);
82552cd27cbSRobert Watson void	in_pcbgroup_destroy(struct inpcbinfo *);
82652cd27cbSRobert Watson int	in_pcbgroup_enabled(struct inpcbinfo *);
82752cd27cbSRobert Watson void	in_pcbgroup_init(struct inpcbinfo *, u_int, int);
82852cd27cbSRobert Watson void	in_pcbgroup_remove(struct inpcb *);
82952cd27cbSRobert Watson void	in_pcbgroup_update(struct inpcb *);
83052cd27cbSRobert Watson void	in_pcbgroup_update_mbuf(struct inpcb *, struct mbuf *);
8319bcd427bSRobert Watson 
832f76fcf6dSJeffrey Hsu void	in_pcbpurgeif0(struct inpcbinfo *, struct ifnet *);
833d915b280SStephan Uphoff int	in_pcballoc(struct socket *, struct inpcbinfo *);
834b0330ed9SPawel Jakub Dawidek int	in_pcbbind(struct inpcb *, struct sockaddr *, struct ucred *);
8354616026fSErmal Luçi int	in_pcb_lport(struct inpcb *, struct in_addr *, u_short *,
8364616026fSErmal Luçi 	    struct ucred *, int);
8374b932371SIan Dowse int	in_pcbbind_setup(struct inpcb *, struct sockaddr *, in_addr_t *,
838b0330ed9SPawel Jakub Dawidek 	    u_short *, struct ucred *);
839b0330ed9SPawel Jakub Dawidek int	in_pcbconnect(struct inpcb *, struct sockaddr *, struct ucred *);
840d3c1f003SRobert Watson int	in_pcbconnect_mbuf(struct inpcb *, struct sockaddr *, struct ucred *,
841d3c1f003SRobert Watson 	    struct mbuf *);
8425200e00eSIan Dowse int	in_pcbconnect_setup(struct inpcb *, struct sockaddr *, in_addr_t *,
8435200e00eSIan Dowse 	    u_short *, in_addr_t *, u_short *, struct inpcb **,
844b0330ed9SPawel Jakub Dawidek 	    struct ucred *);
8454d77a549SAlfred Perlstein void	in_pcbdetach(struct inpcb *);
8464d77a549SAlfred Perlstein void	in_pcbdisconnect(struct inpcb *);
84710702a28SRobert Watson void	in_pcbdrop(struct inpcb *);
8484c7c478dSRobert Watson void	in_pcbfree(struct inpcb *);
8494d77a549SAlfred Perlstein int	in_pcbinshash(struct inpcb *);
85052cd27cbSRobert Watson int	in_pcbinshash_nopcbgroup(struct inpcb *);
851ae190832SSteven Hartland int	in_pcbladdr(struct inpcb *, struct in_addr *, struct in_addr *,
852ae190832SSteven Hartland 	    struct ucred *);
853df8bae1dSRodney W. Grimes struct inpcb *
8544d77a549SAlfred Perlstein 	in_pcblookup_local(struct inpcbinfo *,
855078b7042SBjoern A. Zeeb 	    struct in_addr, u_short, int, struct ucred *);
85615bd2b43SDavid Greenman struct inpcb *
857fa046d87SRobert Watson 	in_pcblookup(struct inpcbinfo *, struct in_addr, u_int,
858c1cd65baSBruce Evans 	    struct in_addr, u_int, int, struct ifnet *);
859d3c1f003SRobert Watson struct inpcb *
860d3c1f003SRobert Watson 	in_pcblookup_mbuf(struct inpcbinfo *, struct in_addr, u_int,
861d3c1f003SRobert Watson 	    struct in_addr, u_int, int, struct ifnet *, struct mbuf *);
862f76fcf6dSJeffrey Hsu void	in_pcbnotifyall(struct inpcbinfo *pcbinfo, struct in_addr,
8633ce144eaSJeffrey Hsu 	    int, struct inpcb *(*)(struct inpcb *, int));
86428696211SRobert Watson void	in_pcbref(struct inpcb *);
8654d77a549SAlfred Perlstein void	in_pcbrehash(struct inpcb *);
866d3c1f003SRobert Watson void	in_pcbrehash_mbuf(struct inpcb *, struct mbuf *);
86728696211SRobert Watson int	in_pcbrele(struct inpcb *);
86879bdc6e5SRobert Watson int	in_pcbrele_rlocked(struct inpcb *);
86979bdc6e5SRobert Watson int	in_pcbrele_wlocked(struct inpcb *);
870ddece765SMatt Macy void	in_pcblist_rele_rlocked(epoch_context_t ctx);
87184cc0778SGeorge V. Neville-Neil void	in_losing(struct inpcb *);
872a557af22SRobert Watson void	in_pcbsetsolabel(struct socket *so);
87354d642bbSRobert Watson int	in_getpeeraddr(struct socket *so, struct sockaddr **nam);
87454d642bbSRobert Watson int	in_getsockaddr(struct socket *so, struct sockaddr **nam);
87526ef6ac4SDon Lewis struct sockaddr *
87626ef6ac4SDon Lewis 	in_sockaddr(in_port_t port, struct in_addr *addr);
877a557af22SRobert Watson void	in_pcbsosetlabel(struct socket *so);
878f3e7afe2SHans Petter Selasky #ifdef RATELIMIT
879f3e7afe2SHans Petter Selasky int	in_pcbattach_txrtlmt(struct inpcb *, struct ifnet *, uint32_t, uint32_t, uint32_t);
880f3e7afe2SHans Petter Selasky void	in_pcbdetach_txrtlmt(struct inpcb *);
881f3e7afe2SHans Petter Selasky int	in_pcbmodify_txrtlmt(struct inpcb *, uint32_t);
882f3e7afe2SHans Petter Selasky int	in_pcbquery_txrtlmt(struct inpcb *, uint32_t *);
88395ed5015SHans Petter Selasky int	in_pcbquery_txrlevel(struct inpcb *, uint32_t *);
884f3e7afe2SHans Petter Selasky void	in_pcboutput_txrtlmt(struct inpcb *, struct ifnet *, struct mbuf *);
885f3e7afe2SHans Petter Selasky void	in_pcboutput_eagain(struct inpcb *);
886f3e7afe2SHans Petter Selasky #endif
887664a31e4SPeter Wemm #endif /* _KERNEL */
8883d4d47f3SGarrett Wollman 
8898781d8e9SBruce Evans #endif /* !_NETINET_IN_PCB_H_ */
890