in_pcb.h revision 32821
1272343Sngie/*
2272343Sngie * Copyright (c) 1982, 1986, 1990, 1993
3272343Sngie *	The Regents of the University of California.  All rights reserved.
4272343Sngie *
5272343Sngie * Redistribution and use in source and binary forms, with or without
6272343Sngie * modification, are permitted provided that the following conditions
7272343Sngie * are met:
8272343Sngie * 1. Redistributions of source code must retain the above copyright
9272343Sngie *    notice, this list of conditions and the following disclaimer.
10272343Sngie * 2. Redistributions in binary form must reproduce the above copyright
11272343Sngie *    notice, this list of conditions and the following disclaimer in the
12272343Sngie *    documentation and/or other materials provided with the distribution.
13272343Sngie * 3. All advertising materials mentioning features or use of this software
14272343Sngie *    must display the following acknowledgement:
15272343Sngie *	This product includes software developed by the University of
16272343Sngie *	California, Berkeley and its contributors.
17272343Sngie * 4. Neither the name of the University nor the names of its contributors
18272343Sngie *    may be used to endorse or promote products derived from this software
19272343Sngie *    without specific prior written permission.
20272343Sngie *
21272343Sngie * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22272343Sngie * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23272343Sngie * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24272343Sngie * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25272343Sngie * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26272343Sngie * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27272343Sngie * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28272343Sngie * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29272343Sngie * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30272343Sngie * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31272343Sngie * SUCH DAMAGE.
32272343Sngie *
33272343Sngie *	@(#)in_pcb.h	8.1 (Berkeley) 6/10/93
34272343Sngie * $Id: in_pcb.h,v 1.22 1997/08/16 19:15:36 wollman Exp $
35272343Sngie */
36272343Sngie
37272343Sngie#ifndef _NETINET_IN_PCB_H_
38272343Sngie#define _NETINET_IN_PCB_H_
39272343Sngie
40272343Sngie#include <sys/queue.h>
41272343Sngie
42272343Sngie/*
43272343Sngie * Common structure pcb for internet protocol implementation.
44272343Sngie * Here are stored pointers to local and foreign host table
45272343Sngie * entries, local and foreign socket numbers, and pointers
46272343Sngie * up (to a socket structure) and down (to a protocol-specific)
47272343Sngie * control block.
48272343Sngie */
49272343SngieLIST_HEAD(inpcbhead, inpcb);
50272343SngieLIST_HEAD(inpcbporthead, inpcbport);
51272343Sngie
52272343Sngiestruct inpcb {
53272343Sngie	LIST_ENTRY(inpcb) inp_hash;	/* hash list */
54272343Sngie	struct	in_addr inp_faddr;	/* foreign host table entry */
55272343Sngie	struct	in_addr inp_laddr;	/* local host table entry */
56272343Sngie	u_short	inp_fport;		/* foreign port */
57272343Sngie	u_short	inp_lport;		/* local port */
58272343Sngie	LIST_ENTRY(inpcb) inp_list;	/* list for all PCBs of this proto */
59272343Sngie	caddr_t	inp_ppcb;		/* pointer to per-protocol pcb */
60272343Sngie	struct	inpcbinfo *inp_pcbinfo;	/* PCB list info */
61272343Sngie	struct	socket *inp_socket;	/* back pointer to socket */
62272343Sngie	struct	mbuf *inp_options;	/* IP options */
63272343Sngie	struct	route inp_route;	/* placeholder for routing entry */
64272343Sngie	int	inp_flags;		/* generic IP/datagram flags */
65272343Sngie	u_char	inp_ip_tos;		/* type of service proto */
66272343Sngie	u_char	inp_ip_ttl;		/* time to live proto */
67272343Sngie	u_char	inp_ip_p;		/* protocol proto */
68272343Sngie	u_char	pad[1];			/* alignment */
69272343Sngie	struct	ip_moptions *inp_moptions; /* IP multicast options */
70272343Sngie	LIST_ENTRY(inpcb) inp_portlist;	/* list for this PCB's local port */
71272343Sngie	struct	inpcbport *inp_phd;	/* head of list for this PCB's local port */
72272343Sngie};
73272343Sngie
74272343Sngiestruct inpcbport {
75272343Sngie	LIST_ENTRY(inpcbport) phd_hash;
76272343Sngie	struct inpcbhead phd_pcblist;
77272343Sngie	u_short phd_port;
78272343Sngie};
79272343Sngie
80272343Sngiestruct inpcbinfo {
81272343Sngie	struct inpcbhead *hashbase;
82272343Sngie	unsigned long hashmask;
83272343Sngie	struct inpcbporthead *porthashbase;
84272343Sngie	unsigned long porthashmask;
85272343Sngie	struct inpcbhead *listhead;
86272343Sngie	unsigned short lastport;
87272343Sngie	unsigned short lastlow;
88272343Sngie	unsigned short lasthi;
89272343Sngie};
90272343Sngie
91272343Sngie#define INP_PCBHASH(faddr, lport, fport, mask) \
92272343Sngie	(((faddr) ^ ((faddr) >> 16) ^ ntohs((lport) ^ (fport))) & (mask))
93272343Sngie#define INP_PCBPORTHASH(lport, mask) \
94272343Sngie	(ntohs((lport)) & (mask))
95272343Sngie
96272343Sngie/* flags in inp_flags: */
97272343Sngie#define	INP_RECVOPTS		0x01	/* receive incoming IP options */
98272343Sngie#define	INP_RECVRETOPTS		0x02	/* receive IP options for reply */
99272343Sngie#define	INP_RECVDSTADDR		0x04	/* receive IP dst address */
100272343Sngie#define	INP_HDRINCL		0x08	/* user supplies entire IP header */
101272343Sngie#define	INP_HIGHPORT		0x10	/* user wants "high" port binding */
102272343Sngie#define	INP_LOWPORT		0x20	/* user wants "low" port binding */
103272343Sngie#define	INP_ANONPORT		0x40	/* port chosen for user */
104272343Sngie#define	INP_RECVIF		0x80	/* receive incoming interface */
105272343Sngie#define	INP_MTUDISC		0x100	/* user can do MTU discovery */
106272343Sngie#define	INP_CONTROLOPTS		(INP_RECVOPTS|INP_RECVRETOPTS|INP_RECVDSTADDR|\
107272343Sngie					INP_RECVIF)
108272343Sngie
109272343Sngie#define	INPLOOKUP_WILDCARD	1
110272343Sngie
111272343Sngie#define	sotoinpcb(so)	((struct inpcb *)(so)->so_pcb)
112272343Sngie
113272343Sngie#ifdef KERNEL
114272343Sngievoid	in_losing __P((struct inpcb *));
115272343Sngieint	in_pcballoc __P((struct socket *, struct inpcbinfo *, struct proc *));
116272343Sngieint	in_pcbbind __P((struct inpcb *, struct sockaddr *, struct proc *));
117272343Sngieint	in_pcbconnect __P((struct inpcb *, struct sockaddr *, struct proc *));
118272343Sngievoid	in_pcbdetach __P((struct inpcb *));
119272343Sngievoid	in_pcbdisconnect __P((struct inpcb *));
120272343Sngieint	in_pcbinshash __P((struct inpcb *));
121272343Sngieint	in_pcbladdr __P((struct inpcb *, struct sockaddr *,
122272343Sngie	    struct sockaddr_in **));
123272343Sngiestruct inpcb *
124272343Sngie	in_pcblookup_local __P((struct inpcbinfo *,
125272343Sngie	    struct in_addr, u_int, int));
126272343Sngiestruct inpcb *
127272343Sngie	in_pcblookup_hash __P((struct inpcbinfo *,
128272343Sngie	    struct in_addr, u_int, struct in_addr, u_int, int));
129272343Sngievoid	in_pcbnotify __P((struct inpcbhead *, struct sockaddr *,
130272343Sngie	    u_int, struct in_addr, u_int, int, void (*)(struct inpcb *, int)));
131272343Sngievoid	in_pcbrehash __P((struct inpcb *));
132272343Sngieint	in_setpeeraddr __P((struct socket *so, struct sockaddr **nam));
133272343Sngieint	in_setsockaddr __P((struct socket *so, struct sockaddr **nam));
134272343Sngie#endif
135272343Sngie
136272343Sngie#endif
137272343Sngie