xref: /freebsd/sys/netinet/in_pcb.h (revision 8501a69cc940a7d32d9299da26baf0b1863e0fa9)
1c398230bSWarner Losh /*-
2df8bae1dSRodney W. Grimes  * Copyright (c) 1982, 1986, 1990, 1993
3df8bae1dSRodney W. Grimes  *	The Regents of the University of California.  All rights reserved.
4df8bae1dSRodney W. Grimes  *
5df8bae1dSRodney W. Grimes  * Redistribution and use in source and binary forms, with or without
6df8bae1dSRodney W. Grimes  * modification, are permitted provided that the following conditions
7df8bae1dSRodney W. Grimes  * are met:
8df8bae1dSRodney W. Grimes  * 1. Redistributions of source code must retain the above copyright
9df8bae1dSRodney W. Grimes  *    notice, this list of conditions and the following disclaimer.
10df8bae1dSRodney W. Grimes  * 2. Redistributions in binary form must reproduce the above copyright
11df8bae1dSRodney W. Grimes  *    notice, this list of conditions and the following disclaimer in the
12df8bae1dSRodney W. Grimes  *    documentation and/or other materials provided with the distribution.
13df8bae1dSRodney W. Grimes  * 4. Neither the name of the University nor the names of its contributors
14df8bae1dSRodney W. Grimes  *    may be used to endorse or promote products derived from this software
15df8bae1dSRodney W. Grimes  *    without specific prior written permission.
16df8bae1dSRodney W. Grimes  *
17df8bae1dSRodney W. Grimes  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18df8bae1dSRodney W. Grimes  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19df8bae1dSRodney W. Grimes  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20df8bae1dSRodney W. Grimes  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21df8bae1dSRodney W. Grimes  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22df8bae1dSRodney W. Grimes  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23df8bae1dSRodney W. Grimes  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24df8bae1dSRodney W. Grimes  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25df8bae1dSRodney W. Grimes  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26df8bae1dSRodney W. Grimes  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27df8bae1dSRodney W. Grimes  * SUCH DAMAGE.
28df8bae1dSRodney W. Grimes  *
29df8bae1dSRodney W. Grimes  *	@(#)in_pcb.h	8.1 (Berkeley) 6/10/93
30c3aac50fSPeter Wemm  * $FreeBSD$
31df8bae1dSRodney W. Grimes  */
32df8bae1dSRodney W. Grimes 
33707f139eSPaul Richards #ifndef _NETINET_IN_PCB_H_
34707f139eSPaul Richards #define _NETINET_IN_PCB_H_
35707f139eSPaul Richards 
36f1844d4cSBruce Evans #include <sys/queue.h>
3740545cf5SBruce Evans #include <sys/_lock.h>
3840545cf5SBruce Evans #include <sys/_mutex.h>
398501a69cSRobert Watson #include <sys/_rwlock.h>
40f1844d4cSBruce Evans 
4138e04732SRobert Watson #include <net/route.h>
4282cd038dSYoshinobu Inoue 
438501a69cSRobert Watson #ifdef _KERNEL
448501a69cSRobert Watson #include <sys/rwlock.h>
458501a69cSRobert Watson #endif
468501a69cSRobert Watson 
4782cd038dSYoshinobu Inoue #define	in6pcb		inpcb	/* for KAME src sync over BSD*'s */
4882cd038dSYoshinobu Inoue #define	in6p_sp		inp_sp	/* for KAME src sync over BSD*'s */
49b9234fafSSam Leffler struct inpcbpolicy;
5082cd038dSYoshinobu Inoue 
51df8bae1dSRodney W. Grimes /*
52712fc218SRobert Watson  * Struct inpcb is the ommon structure pcb for the Internet Protocol
53712fc218SRobert Watson  * implementation.
54712fc218SRobert Watson  *
55712fc218SRobert Watson  * Pointers to local and foreign host table entries, local and foreign socket
56712fc218SRobert Watson  * numbers, and pointers up (to a socket structure) and down (to a
57712fc218SRobert Watson  * protocol-specific control block) are stored here.
58df8bae1dSRodney W. Grimes  */
59e3975643SJake Burkholder LIST_HEAD(inpcbhead, inpcb);
60e3975643SJake Burkholder LIST_HEAD(inpcbporthead, inpcbport);
6198271db4SGarrett Wollman typedef	u_quad_t	inp_gen_t;
6215bd2b43SDavid Greenman 
633d4d47f3SGarrett Wollman /*
6482cd038dSYoshinobu Inoue  * PCB with AF_INET6 null bind'ed laddr can receive AF_INET input packet.
65712fc218SRobert Watson  * So, AF_INET6 null laddr is also used as AF_INET null laddr, by utilizing
66712fc218SRobert Watson  * the following structure.
6782cd038dSYoshinobu Inoue  */
6882cd038dSYoshinobu Inoue struct in_addr_4in6 {
6982cd038dSYoshinobu Inoue 	u_int32_t	ia46_pad32[3];
7082cd038dSYoshinobu Inoue 	struct	in_addr	ia46_addr4;
7182cd038dSYoshinobu Inoue };
7282cd038dSYoshinobu Inoue 
7382cd038dSYoshinobu Inoue /*
74712fc218SRobert Watson  * NOTE: ipv6 addrs should be 64-bit aligned, per RFC 2553.  in_conninfo has
75712fc218SRobert Watson  * some extra padding to accomplish this.
76be2ac88cSJonathan Lemon  */
77be2ac88cSJonathan Lemon struct in_endpoints {
78be2ac88cSJonathan Lemon 	u_int16_t	ie_fport;		/* foreign port */
79be2ac88cSJonathan Lemon 	u_int16_t	ie_lport;		/* local port */
80be2ac88cSJonathan Lemon 	/* protocol dependent part, local and foreign addr */
81be2ac88cSJonathan Lemon 	union {
82be2ac88cSJonathan Lemon 		/* foreign host table entry */
83be2ac88cSJonathan Lemon 		struct	in_addr_4in6 ie46_foreign;
84be2ac88cSJonathan Lemon 		struct	in6_addr ie6_foreign;
85be2ac88cSJonathan Lemon 	} ie_dependfaddr;
86be2ac88cSJonathan Lemon 	union {
87be2ac88cSJonathan Lemon 		/* local host table entry */
88be2ac88cSJonathan Lemon 		struct	in_addr_4in6 ie46_local;
89be2ac88cSJonathan Lemon 		struct	in6_addr ie6_local;
90be2ac88cSJonathan Lemon 	} ie_dependladdr;
91be2ac88cSJonathan Lemon #define	ie_faddr	ie_dependfaddr.ie46_foreign.ia46_addr4
92be2ac88cSJonathan Lemon #define	ie_laddr	ie_dependladdr.ie46_local.ia46_addr4
93be2ac88cSJonathan Lemon #define	ie6_faddr	ie_dependfaddr.ie6_foreign
94be2ac88cSJonathan Lemon #define	ie6_laddr	ie_dependladdr.ie6_local
95be2ac88cSJonathan Lemon };
96be2ac88cSJonathan Lemon 
97be2ac88cSJonathan Lemon /*
98712fc218SRobert Watson  * XXX The defines for inc_* are hacks and should be changed to direct
99712fc218SRobert Watson  * references.
100be2ac88cSJonathan Lemon  */
101be2ac88cSJonathan Lemon struct in_conninfo {
102be2ac88cSJonathan Lemon 	u_int8_t	inc_flags;
103be2ac88cSJonathan Lemon 	u_int8_t	inc_len;
104be2ac88cSJonathan Lemon 	u_int16_t	inc_pad;	/* XXX alignment for in_endpoints */
10597d8d152SAndre Oppermann 	/* protocol dependent part */
106be2ac88cSJonathan Lemon 	struct	in_endpoints inc_ie;
107be2ac88cSJonathan Lemon };
108be2ac88cSJonathan Lemon #define inc_isipv6	inc_flags	/* temp compatability */
109be2ac88cSJonathan Lemon #define	inc_fport	inc_ie.ie_fport
110be2ac88cSJonathan Lemon #define	inc_lport	inc_ie.ie_lport
111be2ac88cSJonathan Lemon #define	inc_faddr	inc_ie.ie_faddr
112be2ac88cSJonathan Lemon #define	inc_laddr	inc_ie.ie_laddr
113be2ac88cSJonathan Lemon #define	inc6_faddr	inc_ie.ie6_faddr
114be2ac88cSJonathan Lemon #define	inc6_laddr	inc_ie.ie6_laddr
115be2ac88cSJonathan Lemon 
11682cd038dSYoshinobu Inoue struct	icmp6_filter;
11782cd038dSYoshinobu Inoue 
118df8bae1dSRodney W. Grimes struct inpcb {
119e3975643SJake Burkholder 	LIST_ENTRY(inpcb) inp_hash;	/* hash list */
120e3975643SJake Burkholder 	LIST_ENTRY(inpcb) inp_list;	/* list for all PCBs of this proto */
121afa39e25SRobert Watson 	void	*inp_ppcb;		/* pointer to per-protocol pcb */
122c3229e05SDavid Greenman 	struct	inpcbinfo *inp_pcbinfo;	/* PCB list info */
123ca98b82cSDavid Greenman 	struct	socket *inp_socket;	/* back pointer to socket */
1242de2af32SKip Macy 
1252de2af32SKip Macy 	u_int32_t	inp_flow;
126df8bae1dSRodney W. Grimes 	int	inp_flags;		/* generic IP/datagram flags */
12782cd038dSYoshinobu Inoue 
1286d53e163SAlfred Perlstein 	u_char	inp_vflag;		/* IP version flag (v4/v6) */
12982cd038dSYoshinobu Inoue #define	INP_IPV4	0x1
13082cd038dSYoshinobu Inoue #define	INP_IPV6	0x2
131340c35deSJonathan Lemon #define	INP_IPV6PROTO	0x4		/* opened under IPv6 protocol */
132340c35deSJonathan Lemon #define	INP_TIMEWAIT	0x8		/* .. probably doesn't go here */
1338afa2304SBruce M Simpson #define	INP_ONESBCAST	0x10		/* send all-ones broadcast */
1346882aa2cSRobert Watson #define	INP_DROPPED	0x20		/* protocol drop flag */
1356882aa2cSRobert Watson #define	INP_SOCKREF	0x40		/* strong socket reference */
136ca98b82cSDavid Greenman 	u_char	inp_ip_ttl;		/* time to live proto */
137ca98b82cSDavid Greenman 	u_char	inp_ip_p;		/* protocol proto */
138936cd18dSAndre Oppermann 	u_char	inp_ip_minttl;		/* minimum TTL or drop */
1392de2af32SKip Macy 	uint32_t inp_ispare1;		/* connection id / queue id */
1402de2af32SKip Macy 	void	*inp_pspare[2];		/* rtentry / general use */
1412de2af32SKip Macy 
1422de2af32SKip Macy 	/* Local and foreign ports, local and foreign addr. */
1432de2af32SKip Macy 	struct	in_conninfo inp_inc;
1442de2af32SKip Macy 
1452de2af32SKip Macy 					/* list for this PCB's local port */
1462de2af32SKip Macy 	struct	label *inp_label;	/* MAC label */
1472de2af32SKip Macy 	struct	inpcbpolicy *inp_sp;    /* for IPSEC */
14882cd038dSYoshinobu Inoue 
149712fc218SRobert Watson 	/* Protocol-dependent part; options. */
15082cd038dSYoshinobu Inoue 	struct {
15182cd038dSYoshinobu Inoue 		u_char	inp4_ip_tos;		/* type of service proto */
15282cd038dSYoshinobu Inoue 		struct	mbuf *inp4_options;	/* IP options */
15382cd038dSYoshinobu Inoue 		struct	ip_moptions *inp4_moptions; /* IP multicast options */
15482cd038dSYoshinobu Inoue 	} inp_depend4;
155be2ac88cSJonathan Lemon #define	inp_fport	inp_inc.inc_fport
156be2ac88cSJonathan Lemon #define	inp_lport	inp_inc.inc_lport
157be2ac88cSJonathan Lemon #define	inp_faddr	inp_inc.inc_faddr
158be2ac88cSJonathan Lemon #define	inp_laddr	inp_inc.inc_laddr
15982cd038dSYoshinobu Inoue #define	inp_ip_tos	inp_depend4.inp4_ip_tos
16082cd038dSYoshinobu Inoue #define	inp_options	inp_depend4.inp4_options
16182cd038dSYoshinobu Inoue #define	inp_moptions	inp_depend4.inp4_moptions
16282cd038dSYoshinobu Inoue 	struct {
16382cd038dSYoshinobu Inoue 		/* IP options */
16482cd038dSYoshinobu Inoue 		struct	mbuf *inp6_options;
16582cd038dSYoshinobu Inoue 		/* IP6 options for outgoing packets */
16682cd038dSYoshinobu Inoue 		struct	ip6_pktopts *inp6_outputopts;
16782cd038dSYoshinobu Inoue 		/* IP multicast options */
16882cd038dSYoshinobu Inoue 		struct	ip6_moptions *inp6_moptions;
16982cd038dSYoshinobu Inoue 		/* ICMPv6 code type filter */
17082cd038dSYoshinobu Inoue 		struct	icmp6_filter *inp6_icmp6filt;
17182cd038dSYoshinobu Inoue 		/* IPV6_CHECKSUM setsockopt */
17282cd038dSYoshinobu Inoue 		int	inp6_cksum;
17382cd038dSYoshinobu Inoue 		short	inp6_hops;
17482cd038dSYoshinobu Inoue 	} inp_depend6;
175e3975643SJake Burkholder 	LIST_ENTRY(inpcb) inp_portlist;
1768781d8e9SBruce Evans 	struct	inpcbport *inp_phd;	/* head of this list */
177d915b280SStephan Uphoff #define inp_zero_size offsetof(struct inpcb, inp_gencnt)
17898271db4SGarrett Wollman 	inp_gen_t	inp_gencnt;	/* generation count of this instance */
1798501a69cSRobert Watson 	struct rwlock	inp_lock;
180f76fcf6dSJeffrey Hsu 
181be2ac88cSJonathan Lemon #define	in6p_faddr	inp_inc.inc6_faddr
182be2ac88cSJonathan Lemon #define	in6p_laddr	inp_inc.inc6_laddr
18382cd038dSYoshinobu Inoue #define	in6p_hops	inp_depend6.inp6_hops	/* default hop limit */
18482cd038dSYoshinobu Inoue #define	in6p_ip6_nxt	inp_ip_p
18582cd038dSYoshinobu Inoue #define	in6p_flowinfo	inp_flow
18682cd038dSYoshinobu Inoue #define	in6p_vflag	inp_vflag
18782cd038dSYoshinobu Inoue #define	in6p_options	inp_depend6.inp6_options
18882cd038dSYoshinobu Inoue #define	in6p_outputopts	inp_depend6.inp6_outputopts
18982cd038dSYoshinobu Inoue #define	in6p_moptions	inp_depend6.inp6_moptions
19082cd038dSYoshinobu Inoue #define	in6p_icmp6filt	inp_depend6.inp6_icmp6filt
19182cd038dSYoshinobu Inoue #define	in6p_cksum	inp_depend6.inp6_cksum
19282cd038dSYoshinobu Inoue #define	in6p_flags	inp_flags  /* for KAME src sync over BSD*'s */
19382cd038dSYoshinobu Inoue #define	in6p_socket	inp_socket  /* for KAME src sync over BSD*'s */
19482cd038dSYoshinobu Inoue #define	in6p_lport	inp_lport  /* for KAME src sync over BSD*'s */
19582cd038dSYoshinobu Inoue #define	in6p_fport	inp_fport  /* for KAME src sync over BSD*'s */
19682cd038dSYoshinobu Inoue #define	in6p_ppcb	inp_ppcb  /* for KAME src sync over BSD*'s */
197c3229e05SDavid Greenman };
1983d4d47f3SGarrett Wollman /*
199712fc218SRobert Watson  * The range of the generation count, as used in this implementation, is 9e19.
200712fc218SRobert Watson  * We would have to create 300 billion connections per second for this number
201712fc218SRobert Watson  * to roll over in a year.  This seems sufficiently unlikely that we simply
202712fc218SRobert Watson  * don't concern ourselves with that possibility.
2033d4d47f3SGarrett Wollman  */
204c3229e05SDavid Greenman 
20598271db4SGarrett Wollman /*
206712fc218SRobert Watson  * Interface exported to userland by various protocols which use inpcbs.  Hack
207712fc218SRobert Watson  * alert -- only define if struct xsocket is in scope.
20898271db4SGarrett Wollman  */
20998271db4SGarrett Wollman #ifdef _SYS_SOCKETVAR_H_
21098271db4SGarrett Wollman struct	xinpcb {
21198271db4SGarrett Wollman 	size_t	xi_len;		/* length of this structure */
21298271db4SGarrett Wollman 	struct	inpcb xi_inp;
21398271db4SGarrett Wollman 	struct	xsocket xi_socket;
21498271db4SGarrett Wollman 	u_quad_t	xi_alignment_hack;
21598271db4SGarrett Wollman };
21698271db4SGarrett Wollman 
21798271db4SGarrett Wollman struct	xinpgen {
21898271db4SGarrett Wollman 	size_t	xig_len;	/* length of this structure */
21998271db4SGarrett Wollman 	u_int	xig_count;	/* number of PCBs at this time */
22098271db4SGarrett Wollman 	inp_gen_t xig_gen;	/* generation count at this time */
22198271db4SGarrett Wollman 	so_gen_t xig_sogen;	/* socket generation count at this time */
22298271db4SGarrett Wollman };
22398271db4SGarrett Wollman #endif /* _SYS_SOCKETVAR_H_ */
22498271db4SGarrett Wollman 
225c3229e05SDavid Greenman struct inpcbport {
226e3975643SJake Burkholder 	LIST_ENTRY(inpcbport) phd_hash;
227c3229e05SDavid Greenman 	struct inpcbhead phd_pcblist;
228c3229e05SDavid Greenman 	u_short phd_port;
229df8bae1dSRodney W. Grimes };
230df8bae1dSRodney W. Grimes 
231712fc218SRobert Watson /*
232712fc218SRobert Watson  * Global data structure for each high-level protocol (UDP, TCP, ...) in both
233712fc218SRobert Watson  * IPv4 and IPv6.  Holds inpcb lists and information for managing them.
234712fc218SRobert Watson  */
235712fc218SRobert Watson struct inpcbinfo {
236712fc218SRobert Watson 	/*
237712fc218SRobert Watson 	 * Global list of inpcbs on the protocol.
238712fc218SRobert Watson 	 */
239712fc218SRobert Watson 	struct inpcbhead	*ipi_listhead;
240712fc218SRobert Watson 	u_int			 ipi_count;
241712fc218SRobert Watson 
242712fc218SRobert Watson 	/*
243712fc218SRobert Watson 	 * Global hash of inpcbs, hashed by local and foreign addresses and
244712fc218SRobert Watson 	 * port numbers.
245712fc218SRobert Watson 	 */
246712fc218SRobert Watson 	struct inpcbhead	*ipi_hashbase;
247712fc218SRobert Watson 	u_long			 ipi_hashmask;
248712fc218SRobert Watson 
249712fc218SRobert Watson 	/*
250712fc218SRobert Watson 	 * Global hash of inpcbs, hashed by only local port number.
251712fc218SRobert Watson 	 */
252712fc218SRobert Watson 	struct inpcbporthead	*ipi_porthashbase;
253712fc218SRobert Watson 	u_long			 ipi_porthashmask;
254712fc218SRobert Watson 
255712fc218SRobert Watson 	/*
256712fc218SRobert Watson 	 * Fields associated with port lookup and allocation.
257712fc218SRobert Watson 	 */
258712fc218SRobert Watson 	u_short			 ipi_lastport;
259712fc218SRobert Watson 	u_short			 ipi_lastlow;
260712fc218SRobert Watson 	u_short			 ipi_lasthi;
261712fc218SRobert Watson 
262712fc218SRobert Watson 	/*
263712fc218SRobert Watson 	 * UMA zone from which inpcbs are allocated for this protocol.
264712fc218SRobert Watson 	 */
265712fc218SRobert Watson 	struct	uma_zone	*ipi_zone;
266712fc218SRobert Watson 
267712fc218SRobert Watson 	/*
268712fc218SRobert Watson 	 * Generation count--incremented each time a connection is allocated
269712fc218SRobert Watson 	 * or freed.
270712fc218SRobert Watson 	 */
271712fc218SRobert Watson 	u_quad_t		 ipi_gencnt;
2728501a69cSRobert Watson 	struct rwlock		 ipi_lock;
2732de2af32SKip Macy 
2742de2af32SKip Macy 	/*
2752de2af32SKip Macy 	 * vimage 1
2762de2af32SKip Macy 	 * general use 1
2772de2af32SKip Macy 	 */
2782de2af32SKip Macy 	void 			*ipi_pspare[2];
27915bd2b43SDavid Greenman };
28015bd2b43SDavid Greenman 
2815bd311a5SSam Leffler #define INP_LOCK_INIT(inp, d, t) \
2828501a69cSRobert Watson 	rw_init_flags(&(inp)->inp_lock, (t), RW_RECURSE |  RW_DUPOK)
2838501a69cSRobert Watson #define INP_LOCK_DESTROY(inp)	rw_destroy(&(inp)->inp_lock)
2848501a69cSRobert Watson #define INP_RLOCK(inp)		rw_rlock(&(inp)->inp_lock)
2858501a69cSRobert Watson #define INP_WLOCK(inp)		rw_wlock(&(inp)->inp_lock)
2868501a69cSRobert Watson #define INP_RUNLOCK(inp)	rw_runlock(&(inp)->inp_lock)
2878501a69cSRobert Watson #define INP_WUNLOCK(inp)	rw_wunlock(&(inp)->inp_lock)
2888501a69cSRobert Watson #define INP_LOCK_ASSERT(inp)	rw_assert(&(inp)->inp_lock, RA_LOCKED)
2898501a69cSRobert Watson #define	INP_RLOCK_ASSERT(inp)	rw_assert(&(inp)->inp_lock, RA_RLOCKED)
2908501a69cSRobert Watson #define	INP_WLOCK_ASSERT(inp)	rw_assert(&(inp)->inp_lock, RA_WLOCKED)
2918501a69cSRobert Watson #define	INP_UNLOCK_ASSERT(inp)	rw_assert(&(inp)->inp_lock, RA_UNLOCKED)
292f76fcf6dSJeffrey Hsu 
293e79dd20dSKip Macy #ifdef _KERNEL
2943d585327SKip Macy /*
2953d585327SKip Macy  * These locking functions are for inpcb consumers outside of sys/netinet,
2963d585327SKip Macy  * more specifically, they were added for the benefit of TOE drivers. The
2973d585327SKip Macy  * macros are reserved for use by the stack.
2983d585327SKip Macy  */
2993d585327SKip Macy void inp_wlock(struct inpcb *);
3003d585327SKip Macy void inp_wunlock(struct inpcb *);
3013d585327SKip Macy void inp_rlock(struct inpcb *);
3023d585327SKip Macy void inp_runlock(struct inpcb *);
3033d585327SKip Macy 
3043d585327SKip Macy #ifdef INVARIANTS
305e79dd20dSKip Macy void inp_lock_assert(struct inpcb *);
306e79dd20dSKip Macy void inp_unlock_assert(struct inpcb *);
3073d585327SKip Macy #else
3083d585327SKip Macy static __inline void
309e79dd20dSKip Macy inp_lock_assert(struct inpcb *inp __unused)
3103d585327SKip Macy {
3113d585327SKip Macy }
3123d585327SKip Macy 
3133d585327SKip Macy static __inline void
314e79dd20dSKip Macy inp_unlock_assert(struct inpcb *inp __unused)
3153d585327SKip Macy {
3163d585327SKip Macy }
317e79dd20dSKip Macy 
3183d585327SKip Macy #endif
319e79dd20dSKip Macy #endif /* _KERNEL */
320e79dd20dSKip Macy 
3213d585327SKip Macy 
322f76fcf6dSJeffrey Hsu #define INP_INFO_LOCK_INIT(ipi, d) \
3238501a69cSRobert Watson 	rw_init_flags(&(ipi)->ipi_lock, (d), RW_RECURSE)
3248501a69cSRobert Watson #define INP_INFO_LOCK_DESTROY(ipi)  rw_destroy(&(ipi)->ipi_lock)
3258501a69cSRobert Watson #define INP_INFO_RLOCK(ipi)	rw_rlock(&(ipi)->ipi_lock)
3268501a69cSRobert Watson #define INP_INFO_WLOCK(ipi)	rw_wlock(&(ipi)->ipi_lock)
3278501a69cSRobert Watson #define INP_INFO_RUNLOCK(ipi)	rw_runlock(&(ipi)->ipi_lock)
3288501a69cSRobert Watson #define INP_INFO_WUNLOCK(ipi)	rw_wunlock(&(ipi)->ipi_lock)
3298501a69cSRobert Watson #define	INP_INFO_LOCK_ASSERT(ipi)	rw_assert(&(ipi)->ipi_lock, RA_LOCKED)
3308501a69cSRobert Watson #define INP_INFO_RLOCK_ASSERT(ipi)	rw_assert(&(ipi)->ipi_lock, RA_RLOCKED)
3318501a69cSRobert Watson #define INP_INFO_WLOCK_ASSERT(ipi)	rw_assert(&(ipi)->ipi_lock, RA_WLOCKED)
3328501a69cSRobert Watson #define INP_INFO_UNLOCK_ASSERT(ipi)	rw_assert(&(ipi)->ipi_lock, RA_UNLOCKED)
333f76fcf6dSJeffrey Hsu 
334ddd79a97SDavid Greenman #define INP_PCBHASH(faddr, lport, fport, mask) \
335c3229e05SDavid Greenman 	(((faddr) ^ ((faddr) >> 16) ^ ntohs((lport) ^ (fport))) & (mask))
336c3229e05SDavid Greenman #define INP_PCBPORTHASH(lport, mask) \
337c3229e05SDavid Greenman 	(ntohs((lport)) & (mask))
338ddd79a97SDavid Greenman 
339df8bae1dSRodney W. Grimes /* flags in inp_flags: */
340df8bae1dSRodney W. Grimes #define	INP_RECVOPTS		0x01	/* receive incoming IP options */
341df8bae1dSRodney W. Grimes #define	INP_RECVRETOPTS		0x02	/* receive IP options for reply */
342df8bae1dSRodney W. Grimes #define	INP_RECVDSTADDR		0x04	/* receive IP dst address */
343df8bae1dSRodney W. Grimes #define	INP_HDRINCL		0x08	/* user supplies entire IP header */
34433b3ac06SPeter Wemm #define	INP_HIGHPORT		0x10	/* user wants "high" port binding */
34533b3ac06SPeter Wemm #define	INP_LOWPORT		0x20	/* user wants "low" port binding */
346321a2846SPoul-Henning Kamp #define	INP_ANONPORT		0x40	/* port chosen for user */
34782c23ebaSBill Fenner #define	INP_RECVIF		0x80	/* receive incoming interface */
34857bf258eSGarrett Wollman #define	INP_MTUDISC		0x100	/* user can do MTU discovery */
34982cd038dSYoshinobu Inoue #define	INP_FAITH		0x200	/* accept FAITH'ed connections */
3504957466bSMatthew N. Dodd #define	INP_RECVTTL		0x400	/* receive incoming IP TTL */
351b2828ad2SAndre Oppermann #define	INP_DONTFRAG		0x800	/* don't fragment packet */
35233841545SHajimu UMEMOTO 
35333841545SHajimu UMEMOTO #define IN6P_IPV6_V6ONLY	0x008000 /* restrict AF_INET6 socket for v6 */
35433841545SHajimu UMEMOTO 
35533841545SHajimu UMEMOTO #define	IN6P_PKTINFO		0x010000 /* receive IP6 dst and I/F */
35633841545SHajimu UMEMOTO #define	IN6P_HOPLIMIT		0x020000 /* receive hoplimit */
35733841545SHajimu UMEMOTO #define	IN6P_HOPOPTS		0x040000 /* receive hop-by-hop options */
35833841545SHajimu UMEMOTO #define	IN6P_DSTOPTS		0x080000 /* receive dst options after rthdr */
35933841545SHajimu UMEMOTO #define	IN6P_RTHDR		0x100000 /* receive routing header */
36033841545SHajimu UMEMOTO #define	IN6P_RTHDRDSTOPTS	0x200000 /* receive dstoptions before rthdr */
3615434eaa2SHajimu UMEMOTO #define	IN6P_TCLASS		0x400000 /* receive traffic class value */
36233841545SHajimu UMEMOTO #define	IN6P_AUTOFLOWLABEL	0x800000 /* attach flowlabel automatically */
363f95d4633SHajimu UMEMOTO #define	IN6P_RFC2292		0x40000000 /* used RFC2292 API on the socket */
364f95d4633SHajimu UMEMOTO #define	IN6P_MTU		0x80000000 /* receive path MTU */
36533841545SHajimu UMEMOTO 
36682c23ebaSBill Fenner #define	INP_CONTROLOPTS		(INP_RECVOPTS|INP_RECVRETOPTS|INP_RECVDSTADDR|\
3674957466bSMatthew N. Dodd 				 INP_RECVIF|INP_RECVTTL|\
36833841545SHajimu UMEMOTO 				 IN6P_PKTINFO|IN6P_HOPLIMIT|IN6P_HOPOPTS|\
36933841545SHajimu UMEMOTO 				 IN6P_DSTOPTS|IN6P_RTHDR|IN6P_RTHDRDSTOPTS|\
370f95d4633SHajimu UMEMOTO 				 IN6P_TCLASS|IN6P_AUTOFLOWLABEL|IN6P_RFC2292|\
371f95d4633SHajimu UMEMOTO 				 IN6P_MTU)
37233841545SHajimu UMEMOTO #define	INP_UNMAPPABLEOPTS	(IN6P_HOPOPTS|IN6P_DSTOPTS|IN6P_RTHDR|\
373f95d4633SHajimu UMEMOTO 				 IN6P_TCLASS|IN6P_AUTOFLOWLABEL)
37482cd038dSYoshinobu Inoue 
37582cd038dSYoshinobu Inoue  /* for KAME src sync over BSD*'s */
37682cd038dSYoshinobu Inoue #define	IN6P_HIGHPORT		INP_HIGHPORT
37782cd038dSYoshinobu Inoue #define	IN6P_LOWPORT		INP_LOWPORT
37882cd038dSYoshinobu Inoue #define	IN6P_ANONPORT		INP_ANONPORT
37982cd038dSYoshinobu Inoue #define	IN6P_RECVIF		INP_RECVIF
38082cd038dSYoshinobu Inoue #define	IN6P_MTUDISC		INP_MTUDISC
38182cd038dSYoshinobu Inoue #define	IN6P_FAITH		INP_FAITH
38282cd038dSYoshinobu Inoue #define	IN6P_CONTROLOPTS INP_CONTROLOPTS
38382cd038dSYoshinobu Inoue 	/*
38482cd038dSYoshinobu Inoue 	 * socket AF version is {newer than,or include}
38582cd038dSYoshinobu Inoue 	 * actual datagram AF version
38682cd038dSYoshinobu Inoue 	 */
387df8bae1dSRodney W. Grimes 
388df8bae1dSRodney W. Grimes #define	INPLOOKUP_WILDCARD	1
389df8bae1dSRodney W. Grimes #define	sotoinpcb(so)	((struct inpcb *)(so)->so_pcb)
39082cd038dSYoshinobu Inoue #define	sotoin6pcb(so)	sotoinpcb(so) /* for KAME src sync over BSD*'s */
39182cd038dSYoshinobu Inoue 
39282cd038dSYoshinobu Inoue #define	INP_SOCKAF(so) so->so_proto->pr_domain->dom_family
39382cd038dSYoshinobu Inoue 
39482cd038dSYoshinobu Inoue #define	INP_CHECK_SOCKAF(so, af)	(INP_SOCKAF(so) == af)
395df8bae1dSRodney W. Grimes 
396664a31e4SPeter Wemm #ifdef _KERNEL
397fcd1001cSDavid Malone extern int	ipport_reservedhigh;
398fcd1001cSDavid Malone extern int	ipport_reservedlow;
39982cd038dSYoshinobu Inoue extern int	ipport_lowfirstauto;
40082cd038dSYoshinobu Inoue extern int	ipport_lowlastauto;
40182cd038dSYoshinobu Inoue extern int	ipport_firstauto;
40282cd038dSYoshinobu Inoue extern int	ipport_lastauto;
40382cd038dSYoshinobu Inoue extern int	ipport_hifirstauto;
40482cd038dSYoshinobu Inoue extern int	ipport_hilastauto;
4055f311da2SMike Silbersack extern struct callout ipport_tick_callout;
40682cd038dSYoshinobu Inoue 
407f76fcf6dSJeffrey Hsu void	in_pcbpurgeif0(struct inpcbinfo *, struct ifnet *);
408d915b280SStephan Uphoff int	in_pcballoc(struct socket *, struct inpcbinfo *);
409b0330ed9SPawel Jakub Dawidek int	in_pcbbind(struct inpcb *, struct sockaddr *, struct ucred *);
4104b932371SIan Dowse int	in_pcbbind_setup(struct inpcb *, struct sockaddr *, in_addr_t *,
411b0330ed9SPawel Jakub Dawidek 	    u_short *, struct ucred *);
412b0330ed9SPawel Jakub Dawidek int	in_pcbconnect(struct inpcb *, struct sockaddr *, struct ucred *);
4135200e00eSIan Dowse int	in_pcbconnect_setup(struct inpcb *, struct sockaddr *, in_addr_t *,
4145200e00eSIan Dowse 	    u_short *, in_addr_t *, u_short *, struct inpcb **,
415b0330ed9SPawel Jakub Dawidek 	    struct ucred *);
4164d77a549SAlfred Perlstein void	in_pcbdetach(struct inpcb *);
4174d77a549SAlfred Perlstein void	in_pcbdisconnect(struct inpcb *);
41810702a28SRobert Watson void	in_pcbdrop(struct inpcb *);
4194c7c478dSRobert Watson void	in_pcbfree(struct inpcb *);
4204d77a549SAlfred Perlstein int	in_pcbinshash(struct inpcb *);
421df8bae1dSRodney W. Grimes struct inpcb *
4224d77a549SAlfred Perlstein 	in_pcblookup_local(struct inpcbinfo *,
4234d77a549SAlfred Perlstein 	    struct in_addr, u_int, int);
42415bd2b43SDavid Greenman struct inpcb *
425c1cd65baSBruce Evans 	in_pcblookup_hash(struct inpcbinfo *, struct in_addr, u_int,
426c1cd65baSBruce Evans 	    struct in_addr, u_int, int, struct ifnet *);
427f76fcf6dSJeffrey Hsu void	in_pcbnotifyall(struct inpcbinfo *pcbinfo, struct in_addr,
4283ce144eaSJeffrey Hsu 	    int, struct inpcb *(*)(struct inpcb *, int));
4294d77a549SAlfred Perlstein void	in_pcbrehash(struct inpcb *);
430a557af22SRobert Watson void	in_pcbsetsolabel(struct socket *so);
43154d642bbSRobert Watson int	in_getpeeraddr(struct socket *so, struct sockaddr **nam);
43254d642bbSRobert Watson int	in_getsockaddr(struct socket *so, struct sockaddr **nam);
43326ef6ac4SDon Lewis struct sockaddr *
43426ef6ac4SDon Lewis 	in_sockaddr(in_port_t port, struct in_addr *addr);
435a557af22SRobert Watson void	in_pcbsosetlabel(struct socket *so);
4364d77a549SAlfred Perlstein void	in_pcbremlists(struct inpcb *inp);
4375f311da2SMike Silbersack void	ipport_tick(void *xtp);
438497057eeSRobert Watson 
439497057eeSRobert Watson /*
440497057eeSRobert Watson  * Debugging routines compiled in when DDB is present.
441497057eeSRobert Watson  */
442497057eeSRobert Watson void	db_print_inpcb(struct inpcb *inp, const char *name, int indent);
443497057eeSRobert Watson 
444664a31e4SPeter Wemm #endif /* _KERNEL */
4453d4d47f3SGarrett Wollman 
4468781d8e9SBruce Evans #endif /* !_NETINET_IN_PCB_H_ */
447