xref: /freebsd/sys/netinet/in_pcb.h (revision 82c23eba89cf4963f60f4fb2b1f416904145edeb)
1df8bae1dSRodney W. Grimes /*
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  * 3. All advertising materials mentioning features or use of this software
14df8bae1dSRodney W. Grimes  *    must display the following acknowledgement:
15df8bae1dSRodney W. Grimes  *	This product includes software developed by the University of
16df8bae1dSRodney W. Grimes  *	California, Berkeley and its contributors.
17df8bae1dSRodney W. Grimes  * 4. Neither the name of the University nor the names of its contributors
18df8bae1dSRodney W. Grimes  *    may be used to endorse or promote products derived from this software
19df8bae1dSRodney W. Grimes  *    without specific prior written permission.
20df8bae1dSRodney W. Grimes  *
21df8bae1dSRodney W. Grimes  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22df8bae1dSRodney W. Grimes  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23df8bae1dSRodney W. Grimes  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24df8bae1dSRodney W. Grimes  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25df8bae1dSRodney W. Grimes  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26df8bae1dSRodney W. Grimes  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27df8bae1dSRodney W. Grimes  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28df8bae1dSRodney W. Grimes  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29df8bae1dSRodney W. Grimes  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30df8bae1dSRodney W. Grimes  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31df8bae1dSRodney W. Grimes  * SUCH DAMAGE.
32df8bae1dSRodney W. Grimes  *
33df8bae1dSRodney W. Grimes  *	@(#)in_pcb.h	8.1 (Berkeley) 6/10/93
3482c23ebaSBill Fenner  * $Id: in_pcb.h,v 1.14 1996/10/30 06:13:10 peter Exp $
35df8bae1dSRodney W. Grimes  */
36df8bae1dSRodney W. Grimes 
37707f139eSPaul Richards #ifndef _NETINET_IN_PCB_H_
38707f139eSPaul Richards #define _NETINET_IN_PCB_H_
39707f139eSPaul Richards 
40f1844d4cSBruce Evans #include <sys/queue.h>
41f1844d4cSBruce Evans 
42df8bae1dSRodney W. Grimes /*
43df8bae1dSRodney W. Grimes  * Common structure pcb for internet protocol implementation.
44df8bae1dSRodney W. Grimes  * Here are stored pointers to local and foreign host table
45df8bae1dSRodney W. Grimes  * entries, local and foreign socket numbers, and pointers
46df8bae1dSRodney W. Grimes  * up (to a socket structure) and down (to a protocol-specific)
47df8bae1dSRodney W. Grimes  * control block.
48df8bae1dSRodney W. Grimes  */
4915bd2b43SDavid Greenman LIST_HEAD(inpcbhead, inpcb);
5015bd2b43SDavid Greenman 
51df8bae1dSRodney W. Grimes struct inpcb {
5215bd2b43SDavid Greenman 	LIST_ENTRY(inpcb) inp_list;		/* list for all PCBs of this proto */
5315bd2b43SDavid Greenman 	LIST_ENTRY(inpcb) inp_hash;		/* hash list */
5415bd2b43SDavid Greenman 	struct	inpcbinfo *inp_pcbinfo;
55df8bae1dSRodney W. Grimes 	struct	in_addr inp_faddr;	/* foreign host table entry */
56df8bae1dSRodney W. Grimes 	u_short	inp_fport;		/* foreign port */
57df8bae1dSRodney W. Grimes 	struct	in_addr inp_laddr;	/* local host table entry */
58df8bae1dSRodney W. Grimes 	u_short	inp_lport;		/* local port */
59df8bae1dSRodney W. Grimes 	struct	socket *inp_socket;	/* back pointer to socket */
60df8bae1dSRodney W. Grimes 	caddr_t	inp_ppcb;		/* pointer to per-protocol pcb */
61df8bae1dSRodney W. Grimes 	struct	route inp_route;	/* placeholder for routing entry */
62df8bae1dSRodney W. Grimes 	int	inp_flags;		/* generic IP/datagram flags */
63df8bae1dSRodney W. Grimes 	struct	ip inp_ip;		/* header prototype; should have more */
64df8bae1dSRodney W. Grimes 	struct	mbuf *inp_options;	/* IP options */
65df8bae1dSRodney W. Grimes 	struct	ip_moptions *inp_moptions; /* IP multicast options */
66df8bae1dSRodney W. Grimes };
67df8bae1dSRodney W. Grimes 
6815bd2b43SDavid Greenman struct inpcbinfo {
6915bd2b43SDavid Greenman 	struct inpcbhead *listhead;
7015bd2b43SDavid Greenman 	struct inpcbhead *hashbase;
7115bd2b43SDavid Greenman 	unsigned long hashsize;
7215bd2b43SDavid Greenman 	unsigned short lastport;
7337bd2b30SPeter Wemm 	unsigned short lastlow;
7437bd2b30SPeter Wemm 	unsigned short lasthi;
7515bd2b43SDavid Greenman };
7615bd2b43SDavid Greenman 
77df8bae1dSRodney W. Grimes /* flags in inp_flags: */
78df8bae1dSRodney W. Grimes #define	INP_RECVOPTS		0x01	/* receive incoming IP options */
79df8bae1dSRodney W. Grimes #define	INP_RECVRETOPTS		0x02	/* receive IP options for reply */
80df8bae1dSRodney W. Grimes #define	INP_RECVDSTADDR		0x04	/* receive IP dst address */
81df8bae1dSRodney W. Grimes #define	INP_HDRINCL		0x08	/* user supplies entire IP header */
8233b3ac06SPeter Wemm #define	INP_HIGHPORT		0x10	/* user wants "high" port binding */
8333b3ac06SPeter Wemm #define	INP_LOWPORT		0x20	/* user wants "low" port binding */
84321a2846SPoul-Henning Kamp #define	INP_ANONPORT		0x40	/* port chosen for user */
8582c23ebaSBill Fenner #define	INP_RECVIF		0x80	/* receive incoming interface */
8682c23ebaSBill Fenner #define	INP_CONTROLOPTS		(INP_RECVOPTS|INP_RECVRETOPTS|INP_RECVDSTADDR|\
8782c23ebaSBill Fenner 					INP_RECVIF)
88df8bae1dSRodney W. Grimes 
89df8bae1dSRodney W. Grimes #define	INPLOOKUP_WILDCARD	1
90df8bae1dSRodney W. Grimes 
91df8bae1dSRodney W. Grimes #define	sotoinpcb(so)	((struct inpcb *)(so)->so_pcb)
92df8bae1dSRodney W. Grimes 
93df8bae1dSRodney W. Grimes #ifdef KERNEL
9426f9a767SRodney W. Grimes void	 in_losing __P((struct inpcb *));
9515bd2b43SDavid Greenman int	 in_pcballoc __P((struct socket *, struct inpcbinfo *));
96df8bae1dSRodney W. Grimes int	 in_pcbbind __P((struct inpcb *, struct mbuf *));
97df8bae1dSRodney W. Grimes int	 in_pcbconnect __P((struct inpcb *, struct mbuf *));
9826f9a767SRodney W. Grimes void	 in_pcbdetach __P((struct inpcb *));
9926f9a767SRodney W. Grimes void	 in_pcbdisconnect __P((struct inpcb *));
100b5e8ce9fSBruce Evans int	 in_pcbladdr __P((struct inpcb *, struct mbuf *,
101b5e8ce9fSBruce Evans 	    struct sockaddr_in **));
102df8bae1dSRodney W. Grimes struct inpcb *
1036d6a026bSDavid Greenman 	 in_pcblookup __P((struct inpcbinfo *,
104df8bae1dSRodney W. Grimes 	    struct in_addr, u_int, struct in_addr, u_int, int));
10515bd2b43SDavid Greenman struct inpcb *
10615bd2b43SDavid Greenman 	 in_pcblookuphash __P((struct inpcbinfo *,
1076d6a026bSDavid Greenman 	    struct in_addr, u_int, struct in_addr, u_int, int));
10815bd2b43SDavid Greenman void	 in_pcbnotify __P((struct inpcbhead *, struct sockaddr *,
109df8bae1dSRodney W. Grimes 	    u_int, struct in_addr, u_int, int, void (*)(struct inpcb *, int)));
11015bd2b43SDavid Greenman void	 in_pcbrehash __P((struct inpcb *));
11126f9a767SRodney W. Grimes void	 in_setpeeraddr __P((struct inpcb *, struct mbuf *));
11226f9a767SRodney W. Grimes void	 in_setsockaddr __P((struct inpcb *, struct mbuf *));
113df8bae1dSRodney W. Grimes #endif
114707f139eSPaul Richards 
115707f139eSPaul Richards #endif
116