xref: /f-stack/tools/compat/include/netinet/in_pcb.h (revision d4a07e70)
11eaf0ac3Slogwang /*-
2*d4a07e70Sfengbojiang  * SPDX-License-Identifier: BSD-3-Clause
3*d4a07e70Sfengbojiang  *
41eaf0ac3Slogwang  * Copyright (c) 1982, 1986, 1990, 1993
51eaf0ac3Slogwang  *	The Regents of the University of California.
61eaf0ac3Slogwang  * Copyright (c) 2010-2011 Juniper Networks, Inc.
71eaf0ac3Slogwang  * All rights reserved.
81eaf0ac3Slogwang  *
91eaf0ac3Slogwang  * Portions of this software were developed by Robert N. M. Watson under
101eaf0ac3Slogwang  * contract to Juniper Networks, Inc.
111eaf0ac3Slogwang  *
121eaf0ac3Slogwang  * Redistribution and use in source and binary forms, with or without
131eaf0ac3Slogwang  * modification, are permitted provided that the following conditions
141eaf0ac3Slogwang  * are met:
151eaf0ac3Slogwang  * 1. Redistributions of source code must retain the above copyright
161eaf0ac3Slogwang  *    notice, this list of conditions and the following disclaimer.
171eaf0ac3Slogwang  * 2. Redistributions in binary form must reproduce the above copyright
181eaf0ac3Slogwang  *    notice, this list of conditions and the following disclaimer in the
191eaf0ac3Slogwang  *    documentation and/or other materials provided with the distribution.
20*d4a07e70Sfengbojiang  * 3. Neither the name of the University nor the names of its contributors
211eaf0ac3Slogwang  *    may be used to endorse or promote products derived from this software
221eaf0ac3Slogwang  *    without specific prior written permission.
231eaf0ac3Slogwang  *
241eaf0ac3Slogwang  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
251eaf0ac3Slogwang  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
261eaf0ac3Slogwang  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
271eaf0ac3Slogwang  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
281eaf0ac3Slogwang  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
291eaf0ac3Slogwang  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
301eaf0ac3Slogwang  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
311eaf0ac3Slogwang  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
321eaf0ac3Slogwang  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
331eaf0ac3Slogwang  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
341eaf0ac3Slogwang  * SUCH DAMAGE.
351eaf0ac3Slogwang  *
361eaf0ac3Slogwang  *	@(#)in_pcb.h	8.1 (Berkeley) 6/10/93
371eaf0ac3Slogwang  * $FreeBSD$
381eaf0ac3Slogwang  */
391eaf0ac3Slogwang 
401eaf0ac3Slogwang #ifndef _NETINET_IN_PCB_H_
411eaf0ac3Slogwang #define _NETINET_IN_PCB_H_
421eaf0ac3Slogwang 
431eaf0ac3Slogwang #include <sys/queue.h>
44*d4a07e70Sfengbojiang #include <sys/epoch.h>
451eaf0ac3Slogwang #include <sys/_lock.h>
461eaf0ac3Slogwang #include <sys/_mutex.h>
471eaf0ac3Slogwang #include <sys/_rwlock.h>
481eaf0ac3Slogwang #include <net/route.h>
491eaf0ac3Slogwang 
501eaf0ac3Slogwang #ifdef _KERNEL
511eaf0ac3Slogwang #include <sys/lock.h>
521eaf0ac3Slogwang #include <sys/rwlock.h>
531eaf0ac3Slogwang #include <net/vnet.h>
541eaf0ac3Slogwang #include <vm/uma.h>
551eaf0ac3Slogwang #endif
56*d4a07e70Sfengbojiang #include <sys/ck.h>
571eaf0ac3Slogwang 
581eaf0ac3Slogwang /*
591eaf0ac3Slogwang  * struct inpcb is the common protocol control block structure used in most
601eaf0ac3Slogwang  * IP transport protocols.
611eaf0ac3Slogwang  *
621eaf0ac3Slogwang  * Pointers to local and foreign host table entries, local and foreign socket
631eaf0ac3Slogwang  * numbers, and pointers up (to a socket structure) and down (to a
641eaf0ac3Slogwang  * protocol-specific control block) are stored here.
651eaf0ac3Slogwang  */
66*d4a07e70Sfengbojiang CK_LIST_HEAD(inpcbhead, inpcb);
67*d4a07e70Sfengbojiang CK_LIST_HEAD(inpcbporthead, inpcbport);
68*d4a07e70Sfengbojiang CK_LIST_HEAD(inpcblbgrouphead, inpcblbgroup);
69*d4a07e70Sfengbojiang typedef	uint64_t	inp_gen_t;
701eaf0ac3Slogwang 
711eaf0ac3Slogwang /*
721eaf0ac3Slogwang  * PCB with AF_INET6 null bind'ed laddr can receive AF_INET input packet.
731eaf0ac3Slogwang  * So, AF_INET6 null laddr is also used as AF_INET null laddr, by utilizing
741eaf0ac3Slogwang  * the following structure.
751eaf0ac3Slogwang  */
761eaf0ac3Slogwang struct in_addr_4in6 {
771eaf0ac3Slogwang 	u_int32_t	ia46_pad32[3];
781eaf0ac3Slogwang 	struct	in_addr	ia46_addr4;
791eaf0ac3Slogwang };
801eaf0ac3Slogwang 
81*d4a07e70Sfengbojiang union in_dependaddr {
82*d4a07e70Sfengbojiang 	struct in_addr_4in6 id46_addr;
83*d4a07e70Sfengbojiang 	struct in6_addr	id6_addr;
84*d4a07e70Sfengbojiang };
85*d4a07e70Sfengbojiang 
861eaf0ac3Slogwang /*
871eaf0ac3Slogwang  * NOTE: ipv6 addrs should be 64-bit aligned, per RFC 2553.  in_conninfo has
881eaf0ac3Slogwang  * some extra padding to accomplish this.
891eaf0ac3Slogwang  * NOTE 2: tcp_syncache.c uses first 5 32-bit words, which identify fport,
901eaf0ac3Slogwang  * lport, faddr to generate hash, so these fields shouldn't be moved.
911eaf0ac3Slogwang  */
921eaf0ac3Slogwang struct in_endpoints {
931eaf0ac3Slogwang 	u_int16_t	ie_fport;		/* foreign port */
941eaf0ac3Slogwang 	u_int16_t	ie_lport;		/* local port */
951eaf0ac3Slogwang 	/* protocol dependent part, local and foreign addr */
96*d4a07e70Sfengbojiang 	union in_dependaddr ie_dependfaddr;	/* foreign host table entry */
97*d4a07e70Sfengbojiang 	union in_dependaddr ie_dependladdr;	/* local host table entry */
98*d4a07e70Sfengbojiang #define	ie_faddr	ie_dependfaddr.id46_addr.ia46_addr4
99*d4a07e70Sfengbojiang #define	ie_laddr	ie_dependladdr.id46_addr.ia46_addr4
100*d4a07e70Sfengbojiang #define	ie6_faddr	ie_dependfaddr.id6_addr
101*d4a07e70Sfengbojiang #define	ie6_laddr	ie_dependladdr.id6_addr
1021eaf0ac3Slogwang 	u_int32_t	ie6_zoneid;		/* scope zone id */
1031eaf0ac3Slogwang };
1041eaf0ac3Slogwang 
1051eaf0ac3Slogwang /*
1061eaf0ac3Slogwang  * XXX The defines for inc_* are hacks and should be changed to direct
1071eaf0ac3Slogwang  * references.
1081eaf0ac3Slogwang  */
1091eaf0ac3Slogwang struct in_conninfo {
1101eaf0ac3Slogwang 	u_int8_t	inc_flags;
1111eaf0ac3Slogwang 	u_int8_t	inc_len;
1121eaf0ac3Slogwang 	u_int16_t	inc_fibnum;	/* XXX was pad, 16 bits is plenty */
1131eaf0ac3Slogwang 	/* protocol dependent part */
1141eaf0ac3Slogwang 	struct	in_endpoints inc_ie;
1151eaf0ac3Slogwang };
1161eaf0ac3Slogwang 
1171eaf0ac3Slogwang /*
1181eaf0ac3Slogwang  * Flags for inc_flags.
1191eaf0ac3Slogwang  */
1201eaf0ac3Slogwang #define	INC_ISIPV6	0x01
121*d4a07e70Sfengbojiang #define	INC_IPV6MINMTU	0x02
1221eaf0ac3Slogwang 
1231eaf0ac3Slogwang #define	inc_fport	inc_ie.ie_fport
1241eaf0ac3Slogwang #define	inc_lport	inc_ie.ie_lport
1251eaf0ac3Slogwang #define	inc_faddr	inc_ie.ie_faddr
1261eaf0ac3Slogwang #define	inc_laddr	inc_ie.ie_laddr
1271eaf0ac3Slogwang #define	inc6_faddr	inc_ie.ie6_faddr
1281eaf0ac3Slogwang #define	inc6_laddr	inc_ie.ie6_laddr
1291eaf0ac3Slogwang #define	inc6_zoneid	inc_ie.ie6_zoneid
1301eaf0ac3Slogwang 
131*d4a07e70Sfengbojiang #if defined(_KERNEL) || defined(_WANT_INPCB)
132*d4a07e70Sfengbojiang /*
1331eaf0ac3Slogwang  * struct inpcb captures the network layer state for TCP, UDP, and raw IPv4 and
1341eaf0ac3Slogwang  * IPv6 sockets.  In the case of TCP and UDP, further per-connection state is
1351eaf0ac3Slogwang  * hung off of inp_ppcb most of the time.  Almost all fields of struct inpcb
1361eaf0ac3Slogwang  * are static after creation or protected by a per-inpcb rwlock, inp_lock.  A
1371eaf0ac3Slogwang  * few fields are protected by multiple locks as indicated in the locking notes
1381eaf0ac3Slogwang  * below.  For these fields, all of the listed locks must be write-locked for
1391eaf0ac3Slogwang  * any modifications.  However, these fields can be safely read while any one of
1401eaf0ac3Slogwang  * the listed locks are read-locked.  This model can permit greater concurrency
1411eaf0ac3Slogwang  * for read operations.  For example, connections can be looked up while only
1421eaf0ac3Slogwang  * holding a read lock on the global pcblist lock.  This is important for
1431eaf0ac3Slogwang  * performance when attempting to find the connection for a packet given its IP
1441eaf0ac3Slogwang  * and port tuple.
1451eaf0ac3Slogwang  *
1461eaf0ac3Slogwang  * One noteworthy exception is that the global pcbinfo lock follows a different
1471eaf0ac3Slogwang  * set of rules in relation to the inp_list field.  Rather than being
1481eaf0ac3Slogwang  * write-locked for modifications and read-locked for list iterations, it must
1491eaf0ac3Slogwang  * be read-locked during modifications and write-locked during list iterations.
1501eaf0ac3Slogwang  * This ensures that the relatively rare global list iterations safely walk a
1511eaf0ac3Slogwang  * stable snapshot of connections while allowing more common list modifications
1521eaf0ac3Slogwang  * to safely grab the pcblist lock just while adding or removing a connection
1531eaf0ac3Slogwang  * from the global list.
1541eaf0ac3Slogwang  *
1551eaf0ac3Slogwang  * Key:
156*d4a07e70Sfengbojiang  * (b) - Protected by the hpts lock.
1571eaf0ac3Slogwang  * (c) - Constant after initialization
158*d4a07e70Sfengbojiang  * (e) - Protected by the net_epoch_prempt epoch
1591eaf0ac3Slogwang  * (g) - Protected by the pcbgroup lock
1601eaf0ac3Slogwang  * (i) - Protected by the inpcb lock
1611eaf0ac3Slogwang  * (p) - Protected by the pcbinfo lock for the inpcb
1621eaf0ac3Slogwang  * (l) - Protected by the pcblist lock for the inpcb
1631eaf0ac3Slogwang  * (h) - Protected by the pcbhash lock for the inpcb
1641eaf0ac3Slogwang  * (s) - Protected by another subsystem's locks
1651eaf0ac3Slogwang  * (x) - Undefined locking
1661eaf0ac3Slogwang  *
167*d4a07e70Sfengbojiang  * Notes on the tcp_hpts:
168*d4a07e70Sfengbojiang  *
169*d4a07e70Sfengbojiang  * First Hpts lock order is
170*d4a07e70Sfengbojiang  * 1) INP_WLOCK()
171*d4a07e70Sfengbojiang  * 2) HPTS_LOCK() i.e. hpts->pmtx
172*d4a07e70Sfengbojiang  *
173*d4a07e70Sfengbojiang  * To insert a TCB on the hpts you *must* be holding the INP_WLOCK().
174*d4a07e70Sfengbojiang  * You may check the inp->inp_in_hpts flag without the hpts lock.
175*d4a07e70Sfengbojiang  * The hpts is the only one that will clear this flag holding
176*d4a07e70Sfengbojiang  * only the hpts lock. This means that in your tcp_output()
177*d4a07e70Sfengbojiang  * routine when you test for the inp_in_hpts flag to be 1
178*d4a07e70Sfengbojiang  * it may be transitioning to 0 (by the hpts).
179*d4a07e70Sfengbojiang  * That's ok since that will just mean an extra call to tcp_output
180*d4a07e70Sfengbojiang  * that most likely will find the call you executed
181*d4a07e70Sfengbojiang  * (when the mis-match occured) will have put the TCB back
182*d4a07e70Sfengbojiang  * on the hpts and it will return. If your
183*d4a07e70Sfengbojiang  * call did not add the inp back to the hpts then you will either
184*d4a07e70Sfengbojiang  * over-send or the cwnd will block you from sending more.
185*d4a07e70Sfengbojiang  *
186*d4a07e70Sfengbojiang  * Note you should also be holding the INP_WLOCK() when you
187*d4a07e70Sfengbojiang  * call the remove from the hpts as well. Though usually
188*d4a07e70Sfengbojiang  * you are either doing this from a timer, where you need and have
189*d4a07e70Sfengbojiang  * the INP_WLOCK() or from destroying your TCB where again
190*d4a07e70Sfengbojiang  * you should already have the INP_WLOCK().
191*d4a07e70Sfengbojiang  *
192*d4a07e70Sfengbojiang  * The inp_hpts_cpu, inp_hpts_cpu_set, inp_input_cpu and
193*d4a07e70Sfengbojiang  * inp_input_cpu_set fields are controlled completely by
194*d4a07e70Sfengbojiang  * the hpts. Do not ever set these. The inp_hpts_cpu_set
195*d4a07e70Sfengbojiang  * and inp_input_cpu_set fields indicate if the hpts has
196*d4a07e70Sfengbojiang  * setup the respective cpu field. It is advised if this
197*d4a07e70Sfengbojiang  * field is 0, to enqueue the packet with the appropriate
198*d4a07e70Sfengbojiang  * hpts_immediate() call. If the _set field is 1, then
199*d4a07e70Sfengbojiang  * you may compare the inp_*_cpu field to the curcpu and
200*d4a07e70Sfengbojiang  * may want to again insert onto the hpts if these fields
201*d4a07e70Sfengbojiang  * are not equal (i.e. you are not on the expected CPU).
202*d4a07e70Sfengbojiang  *
203*d4a07e70Sfengbojiang  * A note on inp_hpts_calls and inp_input_calls, these
204*d4a07e70Sfengbojiang  * flags are set when the hpts calls either the output
205*d4a07e70Sfengbojiang  * or do_segment routines respectively. If the routine
206*d4a07e70Sfengbojiang  * being called wants to use this, then it needs to
207*d4a07e70Sfengbojiang  * clear the flag before returning. The hpts will not
208*d4a07e70Sfengbojiang  * clear the flag. The flags can be used to tell if
209*d4a07e70Sfengbojiang  * the hpts is the function calling the respective
210*d4a07e70Sfengbojiang  * routine.
211*d4a07e70Sfengbojiang  *
2121eaf0ac3Slogwang  * A few other notes:
2131eaf0ac3Slogwang  *
2141eaf0ac3Slogwang  * When a read lock is held, stability of the field is guaranteed; to write
2151eaf0ac3Slogwang  * to a field, a write lock must generally be held.
2161eaf0ac3Slogwang  *
2171eaf0ac3Slogwang  * netinet/netinet6-layer code should not assume that the inp_socket pointer
2181eaf0ac3Slogwang  * is safe to dereference without inp_lock being held, even for protocols
2191eaf0ac3Slogwang  * other than TCP (where the inpcb persists during TIMEWAIT even after the
2201eaf0ac3Slogwang  * socket has been freed), or there may be close(2)-related races.
2211eaf0ac3Slogwang  *
2221eaf0ac3Slogwang  * The inp_vflag field is overloaded, and would otherwise ideally be (c).
2231eaf0ac3Slogwang  *
2241eaf0ac3Slogwang  * TODO:  Currently only the TCP stack is leveraging the global pcbinfo lock
2251eaf0ac3Slogwang  * read-lock usage during modification, this model can be applied to other
2261eaf0ac3Slogwang  * protocols (especially SCTP).
2271eaf0ac3Slogwang  */
228*d4a07e70Sfengbojiang struct icmp6_filter;
229*d4a07e70Sfengbojiang struct inpcbpolicy;
230*d4a07e70Sfengbojiang struct m_snd_tag;
2311eaf0ac3Slogwang struct inpcb {
232*d4a07e70Sfengbojiang 	/* Cache line #1 (amd64) */
233*d4a07e70Sfengbojiang 	CK_LIST_ENTRY(inpcb) inp_hash;	/* [w](h/i) [r](e/i)  hash list */
234*d4a07e70Sfengbojiang 	CK_LIST_ENTRY(inpcb) inp_pcbgrouphash;	/* (g/i) hash list */
235*d4a07e70Sfengbojiang 	struct rwlock	inp_lock;
236*d4a07e70Sfengbojiang 	/* Cache line #2 (amd64) */
237*d4a07e70Sfengbojiang #define	inp_start_zero	inp_hpts
238*d4a07e70Sfengbojiang #define	inp_zero_size	(sizeof(struct inpcb) - \
239*d4a07e70Sfengbojiang 			    offsetof(struct inpcb, inp_start_zero))
240*d4a07e70Sfengbojiang 	TAILQ_ENTRY(inpcb) inp_hpts;	/* pacing out queue next lock(b) */
241*d4a07e70Sfengbojiang 
242*d4a07e70Sfengbojiang 	uint32_t inp_hpts_request;	/* Current hpts request, zero if
243*d4a07e70Sfengbojiang 					 * fits in the pacing window (i&b). */
244*d4a07e70Sfengbojiang 	/*
245*d4a07e70Sfengbojiang 	 * Note the next fields are protected by a
246*d4a07e70Sfengbojiang 	 * different lock (hpts-lock). This means that
247*d4a07e70Sfengbojiang 	 * they must correspond in size to the smallest
248*d4a07e70Sfengbojiang 	 * protectable bit field (uint8_t on x86, and
249*d4a07e70Sfengbojiang 	 * other platfomrs potentially uint32_t?). Also
250*d4a07e70Sfengbojiang 	 * since CPU switches can occur at different times the two
251*d4a07e70Sfengbojiang 	 * fields can *not* be collapsed into a signal bit field.
252*d4a07e70Sfengbojiang 	 */
253*d4a07e70Sfengbojiang #if defined(__amd64__) || defined(__i386__)
254*d4a07e70Sfengbojiang 	volatile uint8_t inp_in_hpts; /* on output hpts (lock b) */
255*d4a07e70Sfengbojiang 	volatile uint8_t inp_in_input; /* on input hpts (lock b) */
256*d4a07e70Sfengbojiang #else
257*d4a07e70Sfengbojiang 	volatile uint32_t inp_in_hpts; /* on output hpts (lock b) */
258*d4a07e70Sfengbojiang 	volatile uint32_t inp_in_input; /* on input hpts (lock b) */
259*d4a07e70Sfengbojiang #endif
260*d4a07e70Sfengbojiang 	volatile uint16_t  inp_hpts_cpu; /* Lock (i) */
261*d4a07e70Sfengbojiang 	u_int	inp_refcount;		/* (i) refcount */
2621eaf0ac3Slogwang 	int	inp_flags;		/* (i) generic IP/datagram flags */
2631eaf0ac3Slogwang 	int	inp_flags2;		/* (i) generic IP/datagram flags #2*/
264*d4a07e70Sfengbojiang 	volatile uint16_t  inp_input_cpu; /* Lock (i) */
265*d4a07e70Sfengbojiang 	volatile uint8_t inp_hpts_cpu_set :1,  /* on output hpts (i) */
266*d4a07e70Sfengbojiang 			 inp_input_cpu_set : 1,	/* on input hpts (i) */
267*d4a07e70Sfengbojiang 			 inp_hpts_calls :1,	/* (i) from output hpts */
268*d4a07e70Sfengbojiang 			 inp_input_calls :1,	/* (i) from input hpts */
269*d4a07e70Sfengbojiang 			 inp_spare_bits2 : 4;
270*d4a07e70Sfengbojiang 	uint8_t inp_numa_domain;	/* numa domain */
271*d4a07e70Sfengbojiang 	void	*inp_ppcb;		/* (i) pointer to per-protocol pcb */
272*d4a07e70Sfengbojiang 	struct	socket *inp_socket;	/* (i) back pointer to socket */
273*d4a07e70Sfengbojiang 	uint32_t 	 inp_hptsslot;	/* Hpts wheel slot this tcb is Lock(i&b) */
274*d4a07e70Sfengbojiang 	uint32_t         inp_hpts_drop_reas;	/* reason we are dropping the PCB (lock i&b) */
275*d4a07e70Sfengbojiang 	TAILQ_ENTRY(inpcb) inp_input;	/* pacing in  queue next lock(b) */
276*d4a07e70Sfengbojiang 	struct	inpcbinfo *inp_pcbinfo;	/* (c) PCB list info */
277*d4a07e70Sfengbojiang 	struct	inpcbgroup *inp_pcbgroup; /* (g/i) PCB group list */
278*d4a07e70Sfengbojiang 	CK_LIST_ENTRY(inpcb) inp_pcbgroup_wild; /* (g/i/h) group wildcard entry */
279*d4a07e70Sfengbojiang 	struct	ucred	*inp_cred;	/* (c) cache of socket cred */
280*d4a07e70Sfengbojiang 	u_int32_t inp_flow;		/* (i) IPv6 flow information */
2811eaf0ac3Slogwang 	u_char	inp_vflag;		/* (i) IP version flag (v4/v6) */
2821eaf0ac3Slogwang 	u_char	inp_ip_ttl;		/* (i) time to live proto */
2831eaf0ac3Slogwang 	u_char	inp_ip_p;		/* (c) protocol proto */
2841eaf0ac3Slogwang 	u_char	inp_ip_minttl;		/* (i) minimum TTL or drop */
2851eaf0ac3Slogwang 	uint32_t inp_flowid;		/* (x) flow id / queue id */
286*d4a07e70Sfengbojiang 	struct m_snd_tag *inp_snd_tag;	/* (i) send tag for outgoing mbufs */
2871eaf0ac3Slogwang 	uint32_t inp_flowtype;		/* (x) M_HASHTYPE value */
2881eaf0ac3Slogwang 	uint32_t inp_rss_listen_bucket;	/* (x) overridden RSS listen bucket */
2891eaf0ac3Slogwang 
2901eaf0ac3Slogwang 	/* Local and foreign ports, local and foreign addr. */
2911eaf0ac3Slogwang 	struct	in_conninfo inp_inc;	/* (i) list for PCB's local port */
2921eaf0ac3Slogwang 
2931eaf0ac3Slogwang 	/* MAC and IPSEC policy information. */
2941eaf0ac3Slogwang 	struct	label *inp_label;	/* (i) MAC label */
2951eaf0ac3Slogwang 	struct	inpcbpolicy *inp_sp;    /* (s) for IPSEC */
2961eaf0ac3Slogwang 
2971eaf0ac3Slogwang 	/* Protocol-dependent part; options. */
2981eaf0ac3Slogwang 	struct {
299*d4a07e70Sfengbojiang 		u_char	inp_ip_tos;		/* (i) type of service proto */
300*d4a07e70Sfengbojiang 		struct mbuf		*inp_options;	/* (i) IP options */
301*d4a07e70Sfengbojiang 		struct ip_moptions	*inp_moptions;	/* (i) mcast options */
302*d4a07e70Sfengbojiang 	};
3031eaf0ac3Slogwang 	struct {
3041eaf0ac3Slogwang 		/* (i) IP options */
305*d4a07e70Sfengbojiang 		struct mbuf		*in6p_options;
3061eaf0ac3Slogwang 		/* (i) IP6 options for outgoing packets */
307*d4a07e70Sfengbojiang 		struct ip6_pktopts	*in6p_outputopts;
3081eaf0ac3Slogwang 		/* (i) IP multicast options */
309*d4a07e70Sfengbojiang 		struct ip6_moptions	*in6p_moptions;
3101eaf0ac3Slogwang 		/* (i) ICMPv6 code type filter */
311*d4a07e70Sfengbojiang 		struct icmp6_filter	*in6p_icmp6filt;
3121eaf0ac3Slogwang 		/* (i) IPV6_CHECKSUM setsockopt */
313*d4a07e70Sfengbojiang 		int	in6p_cksum;
314*d4a07e70Sfengbojiang 		short	in6p_hops;
315*d4a07e70Sfengbojiang 	};
316*d4a07e70Sfengbojiang 	CK_LIST_ENTRY(inpcb) inp_portlist;	/* (i/h) */
3171eaf0ac3Slogwang 	struct	inpcbport *inp_phd;	/* (i/h) head of this list */
3181eaf0ac3Slogwang 	inp_gen_t	inp_gencnt;	/* (c) generation count */
319*d4a07e70Sfengbojiang 	void		*spare_ptr;	/* Spare pointer. */
3201eaf0ac3Slogwang 	rt_gen_t	inp_rt_cookie;	/* generation for route entry */
3211eaf0ac3Slogwang 	union {				/* cached L3 information */
322*d4a07e70Sfengbojiang 		struct route inp_route;
323*d4a07e70Sfengbojiang 		struct route_in6 inp_route6;
3241eaf0ac3Slogwang 	};
325*d4a07e70Sfengbojiang 	CK_LIST_ENTRY(inpcb) inp_list;	/* (p/l) list for all PCBs for proto */
326*d4a07e70Sfengbojiang 	                                /* (e[r]) for list iteration */
327*d4a07e70Sfengbojiang 	                                /* (p[w]/l) for addition/removal */
328*d4a07e70Sfengbojiang 	struct epoch_context inp_epoch_ctx;
329*d4a07e70Sfengbojiang };
330*d4a07e70Sfengbojiang #endif	/* _KERNEL */
331*d4a07e70Sfengbojiang 
3321eaf0ac3Slogwang #define	inp_fport	inp_inc.inc_fport
3331eaf0ac3Slogwang #define	inp_lport	inp_inc.inc_lport
3341eaf0ac3Slogwang #define	inp_faddr	inp_inc.inc_faddr
3351eaf0ac3Slogwang #define	inp_laddr	inp_inc.inc_laddr
3361eaf0ac3Slogwang 
3371eaf0ac3Slogwang #define	in6p_faddr	inp_inc.inc6_faddr
3381eaf0ac3Slogwang #define	in6p_laddr	inp_inc.inc6_laddr
3391eaf0ac3Slogwang #define	in6p_zoneid	inp_inc.inc6_zoneid
3401eaf0ac3Slogwang 
3411eaf0ac3Slogwang #define	inp_vnet	inp_pcbinfo->ipi_vnet
3421eaf0ac3Slogwang 
3431eaf0ac3Slogwang /*
3441eaf0ac3Slogwang  * The range of the generation count, as used in this implementation, is 9e19.
3451eaf0ac3Slogwang  * We would have to create 300 billion connections per second for this number
3461eaf0ac3Slogwang  * to roll over in a year.  This seems sufficiently unlikely that we simply
3471eaf0ac3Slogwang  * don't concern ourselves with that possibility.
3481eaf0ac3Slogwang  */
3491eaf0ac3Slogwang 
3501eaf0ac3Slogwang /*
3511eaf0ac3Slogwang  * Interface exported to userland by various protocols which use inpcbs.  Hack
3521eaf0ac3Slogwang  * alert -- only define if struct xsocket is in scope.
353*d4a07e70Sfengbojiang  * Fields prefixed with "xi_" are unique to this structure, and the rest
354*d4a07e70Sfengbojiang  * match fields in the struct inpcb, to ease coding and porting.
355*d4a07e70Sfengbojiang  *
356*d4a07e70Sfengbojiang  * Legend:
357*d4a07e70Sfengbojiang  * (s) - used by userland utilities in src
358*d4a07e70Sfengbojiang  * (p) - used by utilities in ports
359*d4a07e70Sfengbojiang  * (3) - is known to be used by third party software not in ports
360*d4a07e70Sfengbojiang  * (n) - no known usage
3611eaf0ac3Slogwang  */
3621eaf0ac3Slogwang #ifdef _SYS_SOCKETVAR_H_
3631eaf0ac3Slogwang struct xinpcb {
364*d4a07e70Sfengbojiang 	ksize_t		xi_len;			/* length of this structure */
365*d4a07e70Sfengbojiang 	struct xsocket	xi_socket;		/* (s,p) */
366*d4a07e70Sfengbojiang 	struct in_conninfo inp_inc;		/* (s,p) */
367*d4a07e70Sfengbojiang 	uint64_t	inp_gencnt;		/* (s,p) */
368*d4a07e70Sfengbojiang 	kvaddr_t	inp_ppcb;		/* (s) netstat(1) */
369*d4a07e70Sfengbojiang 	int64_t		inp_spare64[4];
370*d4a07e70Sfengbojiang 	uint32_t	inp_flow;		/* (s) */
371*d4a07e70Sfengbojiang 	uint32_t	inp_flowid;		/* (s) */
372*d4a07e70Sfengbojiang 	uint32_t	inp_flowtype;		/* (s) */
373*d4a07e70Sfengbojiang 	int32_t		inp_flags;		/* (s,p) */
374*d4a07e70Sfengbojiang 	int32_t		inp_flags2;		/* (s) */
375*d4a07e70Sfengbojiang 	int32_t		inp_rss_listen_bucket;	/* (n) */
376*d4a07e70Sfengbojiang 	int32_t		in6p_cksum;		/* (n) */
377*d4a07e70Sfengbojiang 	int32_t		inp_spare32[4];
378*d4a07e70Sfengbojiang 	uint16_t	in6p_hops;		/* (n) */
379*d4a07e70Sfengbojiang 	uint8_t		inp_ip_tos;		/* (n) */
380*d4a07e70Sfengbojiang 	int8_t		pad8;
381*d4a07e70Sfengbojiang 	uint8_t		inp_vflag;		/* (s,p) */
382*d4a07e70Sfengbojiang 	uint8_t		inp_ip_ttl;		/* (n) */
383*d4a07e70Sfengbojiang 	uint8_t		inp_ip_p;		/* (n) */
384*d4a07e70Sfengbojiang 	uint8_t		inp_ip_minttl;		/* (n) */
385*d4a07e70Sfengbojiang 	int8_t		inp_spare8[4];
386*d4a07e70Sfengbojiang } __attribute__((__aligned__(8)));
3871eaf0ac3Slogwang 
3881eaf0ac3Slogwang struct xinpgen {
389*d4a07e70Sfengbojiang 	ksize_t	xig_len;	/* length of this structure */
3901eaf0ac3Slogwang 	u_int		xig_count;	/* number of PCBs at this time */
391*d4a07e70Sfengbojiang 	uint32_t	_xig_spare32;
3921eaf0ac3Slogwang 	inp_gen_t	xig_gen;	/* generation count at this time */
393*d4a07e70Sfengbojiang 	so_gen_t	xig_sogen;	/* socket generation count this time */
394*d4a07e70Sfengbojiang 	uint64_t	_xig_spare64[4];
395*d4a07e70Sfengbojiang } __attribute__((__aligned__(8)));
396*d4a07e70Sfengbojiang #ifdef	_KERNEL
397*d4a07e70Sfengbojiang void	in_pcbtoxinpcb(const struct inpcb *, struct xinpcb *);
398*d4a07e70Sfengbojiang #endif
3991eaf0ac3Slogwang #endif /* _SYS_SOCKETVAR_H_ */
4001eaf0ac3Slogwang 
4011eaf0ac3Slogwang struct inpcbport {
402*d4a07e70Sfengbojiang 	struct epoch_context phd_epoch_ctx;
403*d4a07e70Sfengbojiang 	CK_LIST_ENTRY(inpcbport) phd_hash;
4041eaf0ac3Slogwang 	struct inpcbhead phd_pcblist;
4051eaf0ac3Slogwang 	u_short phd_port;
4061eaf0ac3Slogwang };
4071eaf0ac3Slogwang 
408*d4a07e70Sfengbojiang struct in_pcblist {
409*d4a07e70Sfengbojiang 	int il_count;
410*d4a07e70Sfengbojiang 	struct epoch_context il_epoch_ctx;
411*d4a07e70Sfengbojiang 	struct inpcbinfo *il_pcbinfo;
412*d4a07e70Sfengbojiang 	struct inpcb *il_inp_list[0];
413*d4a07e70Sfengbojiang };
414*d4a07e70Sfengbojiang 
4151eaf0ac3Slogwang /*-
4161eaf0ac3Slogwang  * Global data structure for each high-level protocol (UDP, TCP, ...) in both
4171eaf0ac3Slogwang  * IPv4 and IPv6.  Holds inpcb lists and information for managing them.
4181eaf0ac3Slogwang  *
4191eaf0ac3Slogwang  * Each pcbinfo is protected by three locks: ipi_lock, ipi_hash_lock and
4201eaf0ac3Slogwang  * ipi_list_lock:
4211eaf0ac3Slogwang  *  - ipi_lock covering the global pcb list stability during loop iteration,
4221eaf0ac3Slogwang  *  - ipi_hash_lock covering the hashed lookup tables,
4231eaf0ac3Slogwang  *  - ipi_list_lock covering mutable global fields (such as the global
4241eaf0ac3Slogwang  *    pcb list)
4251eaf0ac3Slogwang  *
4261eaf0ac3Slogwang  * The lock order is:
4271eaf0ac3Slogwang  *
4281eaf0ac3Slogwang  *    ipi_lock (before)
4291eaf0ac3Slogwang  *        inpcb locks (before)
4301eaf0ac3Slogwang  *            ipi_list locks (before)
4311eaf0ac3Slogwang  *                {ipi_hash_lock, pcbgroup locks}
4321eaf0ac3Slogwang  *
4331eaf0ac3Slogwang  * Locking key:
4341eaf0ac3Slogwang  *
4351eaf0ac3Slogwang  * (c) Constant or nearly constant after initialisation
436*d4a07e70Sfengbojiang  * (e) - Protected by the net_epoch_prempt epoch
4371eaf0ac3Slogwang  * (g) Locked by ipi_lock
4381eaf0ac3Slogwang  * (l) Locked by ipi_list_lock
439*d4a07e70Sfengbojiang  * (h) Read using either net_epoch_preempt or inpcb lock; write requires both ipi_hash_lock and inpcb lock
4401eaf0ac3Slogwang  * (p) Protected by one or more pcbgroup locks
4411eaf0ac3Slogwang  * (x) Synchronisation properties poorly defined
4421eaf0ac3Slogwang  */
4431eaf0ac3Slogwang struct inpcbinfo {
4441eaf0ac3Slogwang 	/*
445*d4a07e70Sfengbojiang 	 * Global lock protecting inpcb list modification
4461eaf0ac3Slogwang 	 */
447*d4a07e70Sfengbojiang 	struct mtx		 ipi_lock;
4481eaf0ac3Slogwang 
4491eaf0ac3Slogwang 	/*
4501eaf0ac3Slogwang 	 * Global list of inpcbs on the protocol.
4511eaf0ac3Slogwang 	 */
452*d4a07e70Sfengbojiang 	struct inpcbhead	*ipi_listhead;		/* [r](e) [w](g/l) */
4531eaf0ac3Slogwang 	u_int			 ipi_count;		/* (l) */
4541eaf0ac3Slogwang 
4551eaf0ac3Slogwang 	/*
4561eaf0ac3Slogwang 	 * Generation count -- incremented each time a connection is allocated
4571eaf0ac3Slogwang 	 * or freed.
4581eaf0ac3Slogwang 	 */
4591eaf0ac3Slogwang 	u_quad_t		 ipi_gencnt;		/* (l) */
4601eaf0ac3Slogwang 
4611eaf0ac3Slogwang 	/*
4621eaf0ac3Slogwang 	 * Fields associated with port lookup and allocation.
4631eaf0ac3Slogwang 	 */
4641eaf0ac3Slogwang 	u_short			 ipi_lastport;		/* (x) */
4651eaf0ac3Slogwang 	u_short			 ipi_lastlow;		/* (x) */
4661eaf0ac3Slogwang 	u_short			 ipi_lasthi;		/* (x) */
4671eaf0ac3Slogwang 
4681eaf0ac3Slogwang 	/*
4691eaf0ac3Slogwang 	 * UMA zone from which inpcbs are allocated for this protocol.
4701eaf0ac3Slogwang 	 */
4711eaf0ac3Slogwang 	struct	uma_zone	*ipi_zone;		/* (c) */
4721eaf0ac3Slogwang 
4731eaf0ac3Slogwang 	/*
4741eaf0ac3Slogwang 	 * Connection groups associated with this protocol.  These fields are
4751eaf0ac3Slogwang 	 * constant, but pcbgroup structures themselves are protected by
4761eaf0ac3Slogwang 	 * per-pcbgroup locks.
4771eaf0ac3Slogwang 	 */
4781eaf0ac3Slogwang 	struct inpcbgroup	*ipi_pcbgroups;		/* (c) */
4791eaf0ac3Slogwang 	u_int			 ipi_npcbgroups;	/* (c) */
4801eaf0ac3Slogwang 	u_int			 ipi_hashfields;	/* (c) */
4811eaf0ac3Slogwang 
4821eaf0ac3Slogwang 	/*
483*d4a07e70Sfengbojiang 	 * Global lock protecting modification non-pcbgroup hash lookup tables.
4841eaf0ac3Slogwang 	 */
485*d4a07e70Sfengbojiang 	struct mtx		 ipi_hash_lock;
4861eaf0ac3Slogwang 
4871eaf0ac3Slogwang 	/*
4881eaf0ac3Slogwang 	 * Global hash of inpcbs, hashed by local and foreign addresses and
4891eaf0ac3Slogwang 	 * port numbers.
4901eaf0ac3Slogwang 	 */
4911eaf0ac3Slogwang 	struct inpcbhead	*ipi_hashbase;		/* (h) */
4921eaf0ac3Slogwang 	u_long			 ipi_hashmask;		/* (h) */
4931eaf0ac3Slogwang 
4941eaf0ac3Slogwang 	/*
4951eaf0ac3Slogwang 	 * Global hash of inpcbs, hashed by only local port number.
4961eaf0ac3Slogwang 	 */
4971eaf0ac3Slogwang 	struct inpcbporthead	*ipi_porthashbase;	/* (h) */
4981eaf0ac3Slogwang 	u_long			 ipi_porthashmask;	/* (h) */
4991eaf0ac3Slogwang 
5001eaf0ac3Slogwang 	/*
5011eaf0ac3Slogwang 	 * List of wildcard inpcbs for use with pcbgroups.  In the past, was
5021eaf0ac3Slogwang 	 * per-pcbgroup but is now global.  All pcbgroup locks must be held
5031eaf0ac3Slogwang 	 * to modify the list, so any is sufficient to read it.
5041eaf0ac3Slogwang 	 */
5051eaf0ac3Slogwang 	struct inpcbhead	*ipi_wildbase;		/* (p) */
5061eaf0ac3Slogwang 	u_long			 ipi_wildmask;		/* (p) */
5071eaf0ac3Slogwang 
5081eaf0ac3Slogwang 	/*
509*d4a07e70Sfengbojiang 	 * Load balance groups used for the SO_REUSEPORT_LB option,
510*d4a07e70Sfengbojiang 	 * hashed by local port.
511*d4a07e70Sfengbojiang 	 */
512*d4a07e70Sfengbojiang 	struct	inpcblbgrouphead *ipi_lbgrouphashbase;	/* (h) */
513*d4a07e70Sfengbojiang 	u_long			 ipi_lbgrouphashmask;	/* (h) */
514*d4a07e70Sfengbojiang 
515*d4a07e70Sfengbojiang 	/*
5161eaf0ac3Slogwang 	 * Pointer to network stack instance
5171eaf0ac3Slogwang 	 */
5181eaf0ac3Slogwang 	struct vnet		*ipi_vnet;		/* (c) */
5191eaf0ac3Slogwang 
5201eaf0ac3Slogwang 	/*
5211eaf0ac3Slogwang 	 * general use 2
5221eaf0ac3Slogwang 	 */
5231eaf0ac3Slogwang 	void 			*ipi_pspare[2];
5241eaf0ac3Slogwang 
5251eaf0ac3Slogwang 	/*
5261eaf0ac3Slogwang 	 * Global lock protecting global inpcb list, inpcb count, etc.
5271eaf0ac3Slogwang 	 */
5281eaf0ac3Slogwang 	struct rwlock		 ipi_list_lock;
5291eaf0ac3Slogwang };
5301eaf0ac3Slogwang 
5311eaf0ac3Slogwang #ifdef _KERNEL
5321eaf0ac3Slogwang /*
5331eaf0ac3Slogwang  * Connection groups hold sets of connections that have similar CPU/thread
5341eaf0ac3Slogwang  * affinity.  Each connection belongs to exactly one connection group.
5351eaf0ac3Slogwang  */
5361eaf0ac3Slogwang struct inpcbgroup {
5371eaf0ac3Slogwang 	/*
5381eaf0ac3Slogwang 	 * Per-connection group hash of inpcbs, hashed by local and foreign
5391eaf0ac3Slogwang 	 * addresses and port numbers.
5401eaf0ac3Slogwang 	 */
5411eaf0ac3Slogwang 	struct inpcbhead	*ipg_hashbase;		/* (c) */
5421eaf0ac3Slogwang 	u_long			 ipg_hashmask;		/* (c) */
5431eaf0ac3Slogwang 
5441eaf0ac3Slogwang 	/*
5451eaf0ac3Slogwang 	 * Notional affinity of this pcbgroup.
5461eaf0ac3Slogwang 	 */
5471eaf0ac3Slogwang 	u_int			 ipg_cpu;		/* (p) */
5481eaf0ac3Slogwang 
5491eaf0ac3Slogwang 	/*
5501eaf0ac3Slogwang 	 * Per-connection group lock, not to be confused with ipi_lock.
5511eaf0ac3Slogwang 	 * Protects the hash table hung off the group, but also the global
5521eaf0ac3Slogwang 	 * wildcard list in inpcbinfo.
5531eaf0ac3Slogwang 	 */
5541eaf0ac3Slogwang 	struct mtx		 ipg_lock;
555*d4a07e70Sfengbojiang } __attribute__((__aligned__(CACHE_LINE_SIZE)));
556*d4a07e70Sfengbojiang 
557*d4a07e70Sfengbojiang /*
558*d4a07e70Sfengbojiang  * Load balance groups used for the SO_REUSEPORT_LB socket option. Each group
559*d4a07e70Sfengbojiang  * (or unique address:port combination) can be re-used at most
560*d4a07e70Sfengbojiang  * INPCBLBGROUP_SIZMAX (256) times. The inpcbs are stored in il_inp which
561*d4a07e70Sfengbojiang  * is dynamically resized as processes bind/unbind to that specific group.
562*d4a07e70Sfengbojiang  */
563*d4a07e70Sfengbojiang struct inpcblbgroup {
564*d4a07e70Sfengbojiang 	CK_LIST_ENTRY(inpcblbgroup) il_list;
565*d4a07e70Sfengbojiang 	struct epoch_context il_epoch_ctx;
566*d4a07e70Sfengbojiang 	uint16_t	il_lport;			/* (c) */
567*d4a07e70Sfengbojiang 	u_char		il_vflag;			/* (c) */
568*d4a07e70Sfengbojiang 	u_int8_t		il_numa_domain;
569*d4a07e70Sfengbojiang 	uint32_t	il_pad2;
570*d4a07e70Sfengbojiang 	union in_dependaddr il_dependladdr;		/* (c) */
571*d4a07e70Sfengbojiang #define	il_laddr	il_dependladdr.id46_addr.ia46_addr4
572*d4a07e70Sfengbojiang #define	il6_laddr	il_dependladdr.id6_addr
573*d4a07e70Sfengbojiang 	uint32_t	il_inpsiz; /* max count in il_inp[] (h) */
574*d4a07e70Sfengbojiang 	uint32_t	il_inpcnt; /* cur count in il_inp[] (h) */
575*d4a07e70Sfengbojiang 	struct inpcb	*il_inp[];			/* (h) */
576*d4a07e70Sfengbojiang };
5771eaf0ac3Slogwang 
5781eaf0ac3Slogwang #define INP_LOCK_INIT(inp, d, t) \
5791eaf0ac3Slogwang 	rw_init_flags(&(inp)->inp_lock, (t), RW_RECURSE |  RW_DUPOK)
5801eaf0ac3Slogwang #define INP_LOCK_DESTROY(inp)	rw_destroy(&(inp)->inp_lock)
5811eaf0ac3Slogwang #define INP_RLOCK(inp)		rw_rlock(&(inp)->inp_lock)
5821eaf0ac3Slogwang #define INP_WLOCK(inp)		rw_wlock(&(inp)->inp_lock)
5831eaf0ac3Slogwang #define INP_TRY_RLOCK(inp)	rw_try_rlock(&(inp)->inp_lock)
5841eaf0ac3Slogwang #define INP_TRY_WLOCK(inp)	rw_try_wlock(&(inp)->inp_lock)
5851eaf0ac3Slogwang #define INP_RUNLOCK(inp)	rw_runlock(&(inp)->inp_lock)
5861eaf0ac3Slogwang #define INP_WUNLOCK(inp)	rw_wunlock(&(inp)->inp_lock)
587*d4a07e70Sfengbojiang #define INP_UNLOCK(inp)		rw_unlock(&(inp)->inp_lock)
5881eaf0ac3Slogwang #define	INP_TRY_UPGRADE(inp)	rw_try_upgrade(&(inp)->inp_lock)
5891eaf0ac3Slogwang #define	INP_DOWNGRADE(inp)	rw_downgrade(&(inp)->inp_lock)
5901eaf0ac3Slogwang #define	INP_WLOCKED(inp)	rw_wowned(&(inp)->inp_lock)
5911eaf0ac3Slogwang #define	INP_LOCK_ASSERT(inp)	rw_assert(&(inp)->inp_lock, RA_LOCKED)
5921eaf0ac3Slogwang #define	INP_RLOCK_ASSERT(inp)	rw_assert(&(inp)->inp_lock, RA_RLOCKED)
5931eaf0ac3Slogwang #define	INP_WLOCK_ASSERT(inp)	rw_assert(&(inp)->inp_lock, RA_WLOCKED)
5941eaf0ac3Slogwang #define	INP_UNLOCK_ASSERT(inp)	rw_assert(&(inp)->inp_lock, RA_UNLOCKED)
5951eaf0ac3Slogwang 
5961eaf0ac3Slogwang /*
5971eaf0ac3Slogwang  * These locking functions are for inpcb consumers outside of sys/netinet,
5981eaf0ac3Slogwang  * more specifically, they were added for the benefit of TOE drivers. The
5991eaf0ac3Slogwang  * macros are reserved for use by the stack.
6001eaf0ac3Slogwang  */
6011eaf0ac3Slogwang void inp_wlock(struct inpcb *);
6021eaf0ac3Slogwang void inp_wunlock(struct inpcb *);
6031eaf0ac3Slogwang void inp_rlock(struct inpcb *);
6041eaf0ac3Slogwang void inp_runlock(struct inpcb *);
6051eaf0ac3Slogwang 
606*d4a07e70Sfengbojiang #ifdef INVARIANT_SUPPORT
6071eaf0ac3Slogwang void inp_lock_assert(struct inpcb *);
6081eaf0ac3Slogwang void inp_unlock_assert(struct inpcb *);
6091eaf0ac3Slogwang #else
610*d4a07e70Sfengbojiang #define	inp_lock_assert(inp)	do {} while (0)
611*d4a07e70Sfengbojiang #define	inp_unlock_assert(inp)	do {} while (0)
6121eaf0ac3Slogwang #endif
6131eaf0ac3Slogwang 
6141eaf0ac3Slogwang void	inp_apply_all(void (*func)(struct inpcb *, void *), void *arg);
6151eaf0ac3Slogwang int 	inp_ip_tos_get(const struct inpcb *inp);
6161eaf0ac3Slogwang void 	inp_ip_tos_set(struct inpcb *inp, int val);
6171eaf0ac3Slogwang struct socket *
6181eaf0ac3Slogwang 	inp_inpcbtosocket(struct inpcb *inp);
6191eaf0ac3Slogwang struct tcpcb *
6201eaf0ac3Slogwang 	inp_inpcbtotcpcb(struct inpcb *inp);
6211eaf0ac3Slogwang void 	inp_4tuple_get(struct inpcb *inp, uint32_t *laddr, uint16_t *lp,
6221eaf0ac3Slogwang 		uint32_t *faddr, uint16_t *fp);
623*d4a07e70Sfengbojiang int	inp_so_options(const struct inpcb *inp);
6241eaf0ac3Slogwang 
6251eaf0ac3Slogwang #endif /* _KERNEL */
6261eaf0ac3Slogwang 
6271eaf0ac3Slogwang #define INP_INFO_LOCK_INIT(ipi, d) \
628*d4a07e70Sfengbojiang 	mtx_init(&(ipi)->ipi_lock, (d), NULL, MTX_DEF| MTX_RECURSE)
629*d4a07e70Sfengbojiang #define INP_INFO_LOCK_DESTROY(ipi)  mtx_destroy(&(ipi)->ipi_lock)
630*d4a07e70Sfengbojiang #define INP_INFO_WLOCK(ipi) mtx_lock(&(ipi)->ipi_lock)
631*d4a07e70Sfengbojiang #define INP_INFO_TRY_WLOCK(ipi)	mtx_trylock(&(ipi)->ipi_lock)
632*d4a07e70Sfengbojiang #define INP_INFO_WLOCKED(ipi)	mtx_owned(&(ipi)->ipi_lock)
633*d4a07e70Sfengbojiang #define INP_INFO_WUNLOCK(ipi)	mtx_unlock(&(ipi)->ipi_lock)
634*d4a07e70Sfengbojiang #define	INP_INFO_LOCK_ASSERT(ipi)	MPASS(in_epoch(net_epoch_preempt) || mtx_owned(&(ipi)->ipi_lock))
635*d4a07e70Sfengbojiang #define INP_INFO_WLOCK_ASSERT(ipi)	mtx_assert(&(ipi)->ipi_lock, MA_OWNED)
636*d4a07e70Sfengbojiang #define INP_INFO_WUNLOCK_ASSERT(ipi)	\
637*d4a07e70Sfengbojiang 	mtx_assert(&(ipi)->ipi_lock, MA_NOTOWNED)
6381eaf0ac3Slogwang 
6391eaf0ac3Slogwang #define INP_LIST_LOCK_INIT(ipi, d) \
6401eaf0ac3Slogwang         rw_init_flags(&(ipi)->ipi_list_lock, (d), 0)
6411eaf0ac3Slogwang #define INP_LIST_LOCK_DESTROY(ipi)  rw_destroy(&(ipi)->ipi_list_lock)
6421eaf0ac3Slogwang #define INP_LIST_RLOCK(ipi)     rw_rlock(&(ipi)->ipi_list_lock)
6431eaf0ac3Slogwang #define INP_LIST_WLOCK(ipi)     rw_wlock(&(ipi)->ipi_list_lock)
6441eaf0ac3Slogwang #define INP_LIST_TRY_RLOCK(ipi) rw_try_rlock(&(ipi)->ipi_list_lock)
6451eaf0ac3Slogwang #define INP_LIST_TRY_WLOCK(ipi) rw_try_wlock(&(ipi)->ipi_list_lock)
6461eaf0ac3Slogwang #define INP_LIST_TRY_UPGRADE(ipi)       rw_try_upgrade(&(ipi)->ipi_list_lock)
6471eaf0ac3Slogwang #define INP_LIST_RUNLOCK(ipi)   rw_runlock(&(ipi)->ipi_list_lock)
6481eaf0ac3Slogwang #define INP_LIST_WUNLOCK(ipi)   rw_wunlock(&(ipi)->ipi_list_lock)
6491eaf0ac3Slogwang #define INP_LIST_LOCK_ASSERT(ipi) \
6501eaf0ac3Slogwang 	rw_assert(&(ipi)->ipi_list_lock, RA_LOCKED)
6511eaf0ac3Slogwang #define INP_LIST_RLOCK_ASSERT(ipi) \
6521eaf0ac3Slogwang 	rw_assert(&(ipi)->ipi_list_lock, RA_RLOCKED)
6531eaf0ac3Slogwang #define INP_LIST_WLOCK_ASSERT(ipi) \
6541eaf0ac3Slogwang 	rw_assert(&(ipi)->ipi_list_lock, RA_WLOCKED)
6551eaf0ac3Slogwang #define INP_LIST_UNLOCK_ASSERT(ipi) \
6561eaf0ac3Slogwang 	rw_assert(&(ipi)->ipi_list_lock, RA_UNLOCKED)
6571eaf0ac3Slogwang 
658*d4a07e70Sfengbojiang #define	INP_HASH_LOCK_INIT(ipi, d) mtx_init(&(ipi)->ipi_hash_lock, (d), NULL, MTX_DEF)
659*d4a07e70Sfengbojiang #define	INP_HASH_LOCK_DESTROY(ipi)	mtx_destroy(&(ipi)->ipi_hash_lock)
660*d4a07e70Sfengbojiang #define	INP_HASH_WLOCK(ipi)		mtx_lock(&(ipi)->ipi_hash_lock)
661*d4a07e70Sfengbojiang #define	INP_HASH_WUNLOCK(ipi)		mtx_unlock(&(ipi)->ipi_hash_lock)
662*d4a07e70Sfengbojiang #define	INP_HASH_LOCK_ASSERT(ipi)	MPASS(in_epoch(net_epoch_preempt) || mtx_owned(&(ipi)->ipi_hash_lock))
663*d4a07e70Sfengbojiang #define	INP_HASH_WLOCK_ASSERT(ipi)	mtx_assert(&(ipi)->ipi_hash_lock, MA_OWNED);
6641eaf0ac3Slogwang 
6651eaf0ac3Slogwang #define	INP_GROUP_LOCK_INIT(ipg, d)	mtx_init(&(ipg)->ipg_lock, (d), NULL, \
6661eaf0ac3Slogwang 					    MTX_DEF | MTX_DUPOK)
6671eaf0ac3Slogwang #define	INP_GROUP_LOCK_DESTROY(ipg)	mtx_destroy(&(ipg)->ipg_lock)
6681eaf0ac3Slogwang 
6691eaf0ac3Slogwang #define	INP_GROUP_LOCK(ipg)		mtx_lock(&(ipg)->ipg_lock)
6701eaf0ac3Slogwang #define	INP_GROUP_LOCK_ASSERT(ipg)	mtx_assert(&(ipg)->ipg_lock, MA_OWNED)
6711eaf0ac3Slogwang #define	INP_GROUP_UNLOCK(ipg)		mtx_unlock(&(ipg)->ipg_lock)
6721eaf0ac3Slogwang 
6731eaf0ac3Slogwang #define INP_PCBHASH(faddr, lport, fport, mask) \
6741eaf0ac3Slogwang 	(((faddr) ^ ((faddr) >> 16) ^ ntohs((lport) ^ (fport))) & (mask))
6751eaf0ac3Slogwang #define INP_PCBPORTHASH(lport, mask) \
6761eaf0ac3Slogwang 	(ntohs((lport)) & (mask))
677*d4a07e70Sfengbojiang #define	INP_PCBLBGROUP_PKTHASH(faddr, lport, fport) \
678*d4a07e70Sfengbojiang 	((faddr) ^ ((faddr) >> 16) ^ ntohs((lport) ^ (fport)))
6791eaf0ac3Slogwang #define	INP6_PCBHASHKEY(faddr)	((faddr)->s6_addr32[3])
6801eaf0ac3Slogwang 
6811eaf0ac3Slogwang /*
6821eaf0ac3Slogwang  * Flags for inp_vflags -- historically version flags only
6831eaf0ac3Slogwang  */
6841eaf0ac3Slogwang #define	INP_IPV4	0x1
6851eaf0ac3Slogwang #define	INP_IPV6	0x2
6861eaf0ac3Slogwang #define	INP_IPV6PROTO	0x4		/* opened under IPv6 protocol */
6871eaf0ac3Slogwang 
6881eaf0ac3Slogwang /*
6891eaf0ac3Slogwang  * Flags for inp_flags.
6901eaf0ac3Slogwang  */
6911eaf0ac3Slogwang #define	INP_RECVOPTS		0x00000001 /* receive incoming IP options */
6921eaf0ac3Slogwang #define	INP_RECVRETOPTS		0x00000002 /* receive IP options for reply */
6931eaf0ac3Slogwang #define	INP_RECVDSTADDR		0x00000004 /* receive IP dst address */
6941eaf0ac3Slogwang #define	INP_HDRINCL		0x00000008 /* user supplies entire IP header */
6951eaf0ac3Slogwang #define	INP_HIGHPORT		0x00000010 /* user wants "high" port binding */
6961eaf0ac3Slogwang #define	INP_LOWPORT		0x00000020 /* user wants "low" port binding */
6971eaf0ac3Slogwang #define	INP_ANONPORT		0x00000040 /* port chosen for user */
6981eaf0ac3Slogwang #define	INP_RECVIF		0x00000080 /* receive incoming interface */
6991eaf0ac3Slogwang #define	INP_MTUDISC		0x00000100 /* user can do MTU discovery */
7001eaf0ac3Slogwang 				   	   /* 0x000200 unused: was INP_FAITH */
7011eaf0ac3Slogwang #define	INP_RECVTTL		0x00000400 /* receive incoming IP TTL */
7021eaf0ac3Slogwang #define	INP_DONTFRAG		0x00000800 /* don't fragment packet */
7031eaf0ac3Slogwang #define	INP_BINDANY		0x00001000 /* allow bind to any address */
7041eaf0ac3Slogwang #define	INP_INHASHLIST		0x00002000 /* in_pcbinshash() has been called */
7051eaf0ac3Slogwang #define	INP_RECVTOS		0x00004000 /* receive incoming IP TOS */
7061eaf0ac3Slogwang #define	IN6P_IPV6_V6ONLY	0x00008000 /* restrict AF_INET6 socket for v6 */
7071eaf0ac3Slogwang #define	IN6P_PKTINFO		0x00010000 /* receive IP6 dst and I/F */
7081eaf0ac3Slogwang #define	IN6P_HOPLIMIT		0x00020000 /* receive hoplimit */
7091eaf0ac3Slogwang #define	IN6P_HOPOPTS		0x00040000 /* receive hop-by-hop options */
7101eaf0ac3Slogwang #define	IN6P_DSTOPTS		0x00080000 /* receive dst options after rthdr */
7111eaf0ac3Slogwang #define	IN6P_RTHDR		0x00100000 /* receive routing header */
7121eaf0ac3Slogwang #define	IN6P_RTHDRDSTOPTS	0x00200000 /* receive dstoptions before rthdr */
7131eaf0ac3Slogwang #define	IN6P_TCLASS		0x00400000 /* receive traffic class value */
7141eaf0ac3Slogwang #define	IN6P_AUTOFLOWLABEL	0x00800000 /* attach flowlabel automatically */
7151eaf0ac3Slogwang #define	INP_TIMEWAIT		0x01000000 /* in TIMEWAIT, ppcb is tcptw */
7161eaf0ac3Slogwang #define	INP_ONESBCAST		0x02000000 /* send all-ones broadcast */
7171eaf0ac3Slogwang #define	INP_DROPPED		0x04000000 /* protocol drop flag */
7181eaf0ac3Slogwang #define	INP_SOCKREF		0x08000000 /* strong socket reference */
7191eaf0ac3Slogwang #define	INP_RESERVED_0          0x10000000 /* reserved field */
7201eaf0ac3Slogwang #define	INP_RESERVED_1          0x20000000 /* reserved field */
7211eaf0ac3Slogwang #define	IN6P_RFC2292		0x40000000 /* used RFC2292 API on the socket */
7221eaf0ac3Slogwang #define	IN6P_MTU		0x80000000 /* receive path MTU */
7231eaf0ac3Slogwang 
7241eaf0ac3Slogwang #define	INP_CONTROLOPTS		(INP_RECVOPTS|INP_RECVRETOPTS|INP_RECVDSTADDR|\
7251eaf0ac3Slogwang 				 INP_RECVIF|INP_RECVTTL|INP_RECVTOS|\
7261eaf0ac3Slogwang 				 IN6P_PKTINFO|IN6P_HOPLIMIT|IN6P_HOPOPTS|\
7271eaf0ac3Slogwang 				 IN6P_DSTOPTS|IN6P_RTHDR|IN6P_RTHDRDSTOPTS|\
7281eaf0ac3Slogwang 				 IN6P_TCLASS|IN6P_AUTOFLOWLABEL|IN6P_RFC2292|\
7291eaf0ac3Slogwang 				 IN6P_MTU)
7301eaf0ac3Slogwang 
7311eaf0ac3Slogwang /*
7321eaf0ac3Slogwang  * Flags for inp_flags2.
7331eaf0ac3Slogwang  */
734*d4a07e70Sfengbojiang #define	INP_2UNUSED1		0x00000001
735*d4a07e70Sfengbojiang #define	INP_2UNUSED2		0x00000002
7361eaf0ac3Slogwang #define	INP_PCBGROUPWILD	0x00000004 /* in pcbgroup wildcard list */
7371eaf0ac3Slogwang #define	INP_REUSEPORT		0x00000008 /* SO_REUSEPORT option is set */
7381eaf0ac3Slogwang #define	INP_FREED		0x00000010 /* inp itself is not valid */
7391eaf0ac3Slogwang #define	INP_REUSEADDR		0x00000020 /* SO_REUSEADDR option is set */
7401eaf0ac3Slogwang #define	INP_BINDMULTI		0x00000040 /* IP_BINDMULTI option is set */
7411eaf0ac3Slogwang #define	INP_RSS_BUCKET_SET	0x00000080 /* IP_RSS_LISTEN_BUCKET is set */
7421eaf0ac3Slogwang #define	INP_RECVFLOWID		0x00000100 /* populate recv datagram with flow info */
7431eaf0ac3Slogwang #define	INP_RECVRSSBUCKETID	0x00000200 /* populate recv datagram with bucket id */
744*d4a07e70Sfengbojiang #define	INP_RATE_LIMIT_CHANGED	0x00000400 /* rate limit needs attention */
745*d4a07e70Sfengbojiang #define	INP_ORIGDSTADDR		0x00000800 /* receive IP dst address/port */
746*d4a07e70Sfengbojiang #define INP_CANNOT_DO_ECN	0x00001000 /* The stack does not do ECN */
747*d4a07e70Sfengbojiang #define	INP_REUSEPORT_LB	0x00002000 /* SO_REUSEPORT_LB option is set */
748*d4a07e70Sfengbojiang #define INP_SUPPORTS_MBUFQ	0x00004000 /* Supports the mbuf queue method of LRO */
749*d4a07e70Sfengbojiang #define INP_MBUF_QUEUE_READY	0x00008000 /* The transport is pacing, inputs can be queued */
750*d4a07e70Sfengbojiang #define INP_DONT_SACK_QUEUE	0x00010000 /* If a sack arrives do not wake me */
751*d4a07e70Sfengbojiang #define INP_2PCP_SET		0x00020000 /* If the Eth PCP should be set explicitly */
752*d4a07e70Sfengbojiang #define INP_2PCP_BIT0		0x00040000 /* Eth PCP Bit 0 */
753*d4a07e70Sfengbojiang #define INP_2PCP_BIT1		0x00080000 /* Eth PCP Bit 1 */
754*d4a07e70Sfengbojiang #define INP_2PCP_BIT2		0x00100000 /* Eth PCP Bit 2 */
755*d4a07e70Sfengbojiang #define INP_2PCP_BASE	INP_2PCP_BIT0
756*d4a07e70Sfengbojiang #define INP_2PCP_MASK	(INP_2PCP_BIT0 | INP_2PCP_BIT1 | INP_2PCP_BIT2)
757*d4a07e70Sfengbojiang #define INP_2PCP_SHIFT		18         /* shift PCP field in/out of inp_flags2 */
7581eaf0ac3Slogwang /*
7591eaf0ac3Slogwang  * Flags passed to in_pcblookup*() functions.
7601eaf0ac3Slogwang  */
7611eaf0ac3Slogwang #define	INPLOOKUP_WILDCARD	0x00000001	/* Allow wildcard sockets. */
7621eaf0ac3Slogwang #define	INPLOOKUP_RLOCKPCB	0x00000002	/* Return inpcb read-locked. */
7631eaf0ac3Slogwang #define	INPLOOKUP_WLOCKPCB	0x00000004	/* Return inpcb write-locked. */
7641eaf0ac3Slogwang 
7651eaf0ac3Slogwang #define	INPLOOKUP_MASK	(INPLOOKUP_WILDCARD | INPLOOKUP_RLOCKPCB | \
7661eaf0ac3Slogwang 			    INPLOOKUP_WLOCKPCB)
7671eaf0ac3Slogwang 
7681eaf0ac3Slogwang #define	sotoinpcb(so)	((struct inpcb *)(so)->so_pcb)
7691eaf0ac3Slogwang 
7701eaf0ac3Slogwang #define	INP_SOCKAF(so) so->so_proto->pr_domain->dom_family
7711eaf0ac3Slogwang 
7721eaf0ac3Slogwang #define	INP_CHECK_SOCKAF(so, af)	(INP_SOCKAF(so) == af)
7731eaf0ac3Slogwang 
7741eaf0ac3Slogwang /*
7751eaf0ac3Slogwang  * Constants for pcbinfo.ipi_hashfields.
7761eaf0ac3Slogwang  */
7771eaf0ac3Slogwang #define	IPI_HASHFIELDS_NONE	0
7781eaf0ac3Slogwang #define	IPI_HASHFIELDS_2TUPLE	1
7791eaf0ac3Slogwang #define	IPI_HASHFIELDS_4TUPLE	2
7801eaf0ac3Slogwang 
7811eaf0ac3Slogwang #ifdef _KERNEL
7821eaf0ac3Slogwang VNET_DECLARE(int, ipport_reservedhigh);
7831eaf0ac3Slogwang VNET_DECLARE(int, ipport_reservedlow);
7841eaf0ac3Slogwang VNET_DECLARE(int, ipport_lowfirstauto);
7851eaf0ac3Slogwang VNET_DECLARE(int, ipport_lowlastauto);
7861eaf0ac3Slogwang VNET_DECLARE(int, ipport_firstauto);
7871eaf0ac3Slogwang VNET_DECLARE(int, ipport_lastauto);
7881eaf0ac3Slogwang VNET_DECLARE(int, ipport_hifirstauto);
7891eaf0ac3Slogwang VNET_DECLARE(int, ipport_hilastauto);
7901eaf0ac3Slogwang VNET_DECLARE(int, ipport_randomized);
7911eaf0ac3Slogwang VNET_DECLARE(int, ipport_randomcps);
7921eaf0ac3Slogwang VNET_DECLARE(int, ipport_randomtime);
7931eaf0ac3Slogwang VNET_DECLARE(int, ipport_stoprandom);
7941eaf0ac3Slogwang VNET_DECLARE(int, ipport_tcpallocs);
7951eaf0ac3Slogwang 
7961eaf0ac3Slogwang #define	V_ipport_reservedhigh	VNET(ipport_reservedhigh)
7971eaf0ac3Slogwang #define	V_ipport_reservedlow	VNET(ipport_reservedlow)
7981eaf0ac3Slogwang #define	V_ipport_lowfirstauto	VNET(ipport_lowfirstauto)
7991eaf0ac3Slogwang #define	V_ipport_lowlastauto	VNET(ipport_lowlastauto)
8001eaf0ac3Slogwang #define	V_ipport_firstauto	VNET(ipport_firstauto)
8011eaf0ac3Slogwang #define	V_ipport_lastauto	VNET(ipport_lastauto)
8021eaf0ac3Slogwang #define	V_ipport_hifirstauto	VNET(ipport_hifirstauto)
8031eaf0ac3Slogwang #define	V_ipport_hilastauto	VNET(ipport_hilastauto)
8041eaf0ac3Slogwang #define	V_ipport_randomized	VNET(ipport_randomized)
8051eaf0ac3Slogwang #define	V_ipport_randomcps	VNET(ipport_randomcps)
8061eaf0ac3Slogwang #define	V_ipport_randomtime	VNET(ipport_randomtime)
8071eaf0ac3Slogwang #define	V_ipport_stoprandom	VNET(ipport_stoprandom)
8081eaf0ac3Slogwang #define	V_ipport_tcpallocs	VNET(ipport_tcpallocs)
8091eaf0ac3Slogwang 
8101eaf0ac3Slogwang void	in_pcbinfo_destroy(struct inpcbinfo *);
8111eaf0ac3Slogwang void	in_pcbinfo_init(struct inpcbinfo *, const char *, struct inpcbhead *,
812*d4a07e70Sfengbojiang 	    int, int, char *, uma_init, u_int);
8131eaf0ac3Slogwang 
8141eaf0ac3Slogwang int	in_pcbbind_check_bindmulti(const struct inpcb *ni,
8151eaf0ac3Slogwang 	    const struct inpcb *oi);
8161eaf0ac3Slogwang 
8171eaf0ac3Slogwang struct inpcbgroup *
8181eaf0ac3Slogwang 	in_pcbgroup_byhash(struct inpcbinfo *, u_int, uint32_t);
8191eaf0ac3Slogwang struct inpcbgroup *
8201eaf0ac3Slogwang 	in_pcbgroup_byinpcb(struct inpcb *);
8211eaf0ac3Slogwang struct inpcbgroup *
8221eaf0ac3Slogwang 	in_pcbgroup_bytuple(struct inpcbinfo *, struct in_addr, u_short,
8231eaf0ac3Slogwang 	    struct in_addr, u_short);
8241eaf0ac3Slogwang void	in_pcbgroup_destroy(struct inpcbinfo *);
8251eaf0ac3Slogwang int	in_pcbgroup_enabled(struct inpcbinfo *);
8261eaf0ac3Slogwang void	in_pcbgroup_init(struct inpcbinfo *, u_int, int);
8271eaf0ac3Slogwang void	in_pcbgroup_remove(struct inpcb *);
8281eaf0ac3Slogwang void	in_pcbgroup_update(struct inpcb *);
8291eaf0ac3Slogwang void	in_pcbgroup_update_mbuf(struct inpcb *, struct mbuf *);
8301eaf0ac3Slogwang 
8311eaf0ac3Slogwang void	in_pcbpurgeif0(struct inpcbinfo *, struct ifnet *);
8321eaf0ac3Slogwang int	in_pcballoc(struct socket *, struct inpcbinfo *);
8331eaf0ac3Slogwang int	in_pcbbind(struct inpcb *, struct sockaddr *, struct ucred *);
834*d4a07e70Sfengbojiang int	in_pcb_lport_dest(struct inpcb *inp, struct sockaddr *lsa,
835*d4a07e70Sfengbojiang 	    u_short *lportp, struct sockaddr *fsa, u_short fport,
836*d4a07e70Sfengbojiang 	    struct ucred *cred, int lookupflags);
8371eaf0ac3Slogwang int	in_pcb_lport(struct inpcb *, struct in_addr *, u_short *,
8381eaf0ac3Slogwang 	    struct ucred *, int);
8391eaf0ac3Slogwang int	in_pcbbind_setup(struct inpcb *, struct sockaddr *, in_addr_t *,
8401eaf0ac3Slogwang 	    u_short *, struct ucred *);
8411eaf0ac3Slogwang int	in_pcbconnect(struct inpcb *, struct sockaddr *, struct ucred *);
8421eaf0ac3Slogwang int	in_pcbconnect_mbuf(struct inpcb *, struct sockaddr *, struct ucred *,
843*d4a07e70Sfengbojiang 	    struct mbuf *, bool);
8441eaf0ac3Slogwang int	in_pcbconnect_setup(struct inpcb *, struct sockaddr *, in_addr_t *,
8451eaf0ac3Slogwang 	    u_short *, in_addr_t *, u_short *, struct inpcb **,
8461eaf0ac3Slogwang 	    struct ucred *);
8471eaf0ac3Slogwang void	in_pcbdetach(struct inpcb *);
8481eaf0ac3Slogwang void	in_pcbdisconnect(struct inpcb *);
8491eaf0ac3Slogwang void	in_pcbdrop(struct inpcb *);
8501eaf0ac3Slogwang void	in_pcbfree(struct inpcb *);
8511eaf0ac3Slogwang int	in_pcbinshash(struct inpcb *);
852*d4a07e70Sfengbojiang int	in_pcbinshash_mbuf(struct inpcb *, struct mbuf *);
8531eaf0ac3Slogwang int	in_pcbladdr(struct inpcb *, struct in_addr *, struct in_addr *,
8541eaf0ac3Slogwang 	    struct ucred *);
855*d4a07e70Sfengbojiang int	in_pcblbgroup_numa(struct inpcb *, int arg);
8561eaf0ac3Slogwang struct inpcb *
8571eaf0ac3Slogwang 	in_pcblookup_local(struct inpcbinfo *,
8581eaf0ac3Slogwang 	    struct in_addr, u_short, int, struct ucred *);
8591eaf0ac3Slogwang struct inpcb *
8601eaf0ac3Slogwang 	in_pcblookup(struct inpcbinfo *, struct in_addr, u_int,
8611eaf0ac3Slogwang 	    struct in_addr, u_int, int, struct ifnet *);
8621eaf0ac3Slogwang struct inpcb *
8631eaf0ac3Slogwang 	in_pcblookup_mbuf(struct inpcbinfo *, struct in_addr, u_int,
8641eaf0ac3Slogwang 	    struct in_addr, u_int, int, struct ifnet *, struct mbuf *);
8651eaf0ac3Slogwang void	in_pcbnotifyall(struct inpcbinfo *pcbinfo, struct in_addr,
8661eaf0ac3Slogwang 	    int, struct inpcb *(*)(struct inpcb *, int));
8671eaf0ac3Slogwang void	in_pcbref(struct inpcb *);
8681eaf0ac3Slogwang void	in_pcbrehash(struct inpcb *);
8691eaf0ac3Slogwang void	in_pcbrehash_mbuf(struct inpcb *, struct mbuf *);
8701eaf0ac3Slogwang int	in_pcbrele(struct inpcb *);
8711eaf0ac3Slogwang int	in_pcbrele_rlocked(struct inpcb *);
8721eaf0ac3Slogwang int	in_pcbrele_wlocked(struct inpcb *);
873*d4a07e70Sfengbojiang void	in_pcblist_rele_rlocked(epoch_context_t ctx);
8741eaf0ac3Slogwang void	in_losing(struct inpcb *);
8751eaf0ac3Slogwang void	in_pcbsetsolabel(struct socket *so);
8761eaf0ac3Slogwang int	in_getpeeraddr(struct socket *so, struct sockaddr **nam);
8771eaf0ac3Slogwang int	in_getsockaddr(struct socket *so, struct sockaddr **nam);
8781eaf0ac3Slogwang struct sockaddr *
8791eaf0ac3Slogwang 	in_sockaddr(in_port_t port, struct in_addr *addr);
8801eaf0ac3Slogwang void	in_pcbsosetlabel(struct socket *so);
881*d4a07e70Sfengbojiang #ifdef RATELIMIT
882*d4a07e70Sfengbojiang int
883*d4a07e70Sfengbojiang in_pcboutput_txrtlmt_locked(struct inpcb *, struct ifnet *,
884*d4a07e70Sfengbojiang 	    struct mbuf *, uint32_t);
885*d4a07e70Sfengbojiang int	in_pcbattach_txrtlmt(struct inpcb *, struct ifnet *, uint32_t, uint32_t,
886*d4a07e70Sfengbojiang 	    uint32_t, struct m_snd_tag **);
887*d4a07e70Sfengbojiang void	in_pcbdetach_txrtlmt(struct inpcb *);
888*d4a07e70Sfengbojiang void    in_pcbdetach_tag(struct m_snd_tag *);
889*d4a07e70Sfengbojiang int	in_pcbmodify_txrtlmt(struct inpcb *, uint32_t);
890*d4a07e70Sfengbojiang int	in_pcbquery_txrtlmt(struct inpcb *, uint32_t *);
891*d4a07e70Sfengbojiang int	in_pcbquery_txrlevel(struct inpcb *, uint32_t *);
892*d4a07e70Sfengbojiang void	in_pcboutput_txrtlmt(struct inpcb *, struct ifnet *, struct mbuf *);
893*d4a07e70Sfengbojiang void	in_pcboutput_eagain(struct inpcb *);
894*d4a07e70Sfengbojiang #endif
8951eaf0ac3Slogwang #endif /* _KERNEL */
8961eaf0ac3Slogwang 
8971eaf0ac3Slogwang #endif /* !_NETINET_IN_PCB_H_ */
898