in_pcb.h revision 1.27 1 1.27 itojun /* $NetBSD: in_pcb.h,v 1.27 1999/07/01 08:12:50 itojun Exp $ */
2 1.27 itojun
3 1.27 itojun /*
4 1.27 itojun * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
5 1.27 itojun * All rights reserved.
6 1.27 itojun *
7 1.27 itojun * Redistribution and use in source and binary forms, with or without
8 1.27 itojun * modification, are permitted provided that the following conditions
9 1.27 itojun * are met:
10 1.27 itojun * 1. Redistributions of source code must retain the above copyright
11 1.27 itojun * notice, this list of conditions and the following disclaimer.
12 1.27 itojun * 2. Redistributions in binary form must reproduce the above copyright
13 1.27 itojun * notice, this list of conditions and the following disclaimer in the
14 1.27 itojun * documentation and/or other materials provided with the distribution.
15 1.27 itojun * 3. Neither the name of the project nor the names of its contributors
16 1.27 itojun * may be used to endorse or promote products derived from this software
17 1.27 itojun * without specific prior written permission.
18 1.27 itojun *
19 1.27 itojun * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
20 1.27 itojun * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 1.27 itojun * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 1.27 itojun * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
23 1.27 itojun * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 1.27 itojun * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 1.27 itojun * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 1.27 itojun * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 1.27 itojun * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 1.27 itojun * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 1.27 itojun * SUCH DAMAGE.
30 1.27 itojun */
31 1.7 cgd
32 1.1 cgd /*
33 1.6 mycroft * Copyright (c) 1982, 1986, 1990, 1993
34 1.6 mycroft * The Regents of the University of California. All rights reserved.
35 1.1 cgd *
36 1.1 cgd * Redistribution and use in source and binary forms, with or without
37 1.1 cgd * modification, are permitted provided that the following conditions
38 1.1 cgd * are met:
39 1.1 cgd * 1. Redistributions of source code must retain the above copyright
40 1.1 cgd * notice, this list of conditions and the following disclaimer.
41 1.1 cgd * 2. Redistributions in binary form must reproduce the above copyright
42 1.1 cgd * notice, this list of conditions and the following disclaimer in the
43 1.1 cgd * documentation and/or other materials provided with the distribution.
44 1.1 cgd * 3. All advertising materials mentioning features or use of this software
45 1.1 cgd * must display the following acknowledgement:
46 1.1 cgd * This product includes software developed by the University of
47 1.1 cgd * California, Berkeley and its contributors.
48 1.1 cgd * 4. Neither the name of the University nor the names of its contributors
49 1.1 cgd * may be used to endorse or promote products derived from this software
50 1.1 cgd * without specific prior written permission.
51 1.1 cgd *
52 1.1 cgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
53 1.1 cgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
54 1.1 cgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
55 1.1 cgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
56 1.1 cgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
57 1.1 cgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
58 1.1 cgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
59 1.1 cgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
60 1.1 cgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
61 1.1 cgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
62 1.1 cgd * SUCH DAMAGE.
63 1.1 cgd *
64 1.7 cgd * @(#)in_pcb.h 8.1 (Berkeley) 6/10/93
65 1.1 cgd */
66 1.1 cgd
67 1.24 perry #ifndef _NETINET_IN_PCB_H_
68 1.24 perry #define _NETINET_IN_PCB_H_
69 1.24 perry
70 1.10 mycroft #include <sys/queue.h>
71 1.27 itojun #if 1 /*IPSEC*/
72 1.27 itojun #include <netinet6/ipsec.h>
73 1.27 itojun #endif
74 1.10 mycroft
75 1.1 cgd /*
76 1.1 cgd * Common structure pcb for internet protocol implementation.
77 1.1 cgd * Here are stored pointers to local and foreign host table
78 1.1 cgd * entries, local and foreign socket numbers, and pointers
79 1.1 cgd * up (to a socket structure) and down (to a protocol-specific)
80 1.1 cgd * control block.
81 1.1 cgd */
82 1.1 cgd struct inpcb {
83 1.13 mycroft LIST_ENTRY(inpcb) inp_hash;
84 1.12 cgd CIRCLEQ_ENTRY(inpcb) inp_queue;
85 1.25 matt caddr_t inp_ppcb; /* pointer to per-protocol pcb */
86 1.17 mycroft int inp_state; /* bind/connect state */
87 1.9 cgd u_int16_t inp_fport; /* foreign port */
88 1.9 cgd u_int16_t inp_lport; /* local port */
89 1.9 cgd struct socket *inp_socket; /* back pointer to socket */
90 1.9 cgd struct route inp_route; /* placeholder for routing entry */
91 1.9 cgd int inp_flags; /* generic IP/datagram flags */
92 1.9 cgd struct ip inp_ip; /* header prototype; should have more */
93 1.9 cgd struct mbuf *inp_options; /* IP options */
94 1.9 cgd struct ip_moptions *inp_moptions; /* IP multicast options */
95 1.22 matt int inp_errormtu; /* MTU of last xmit status = EMSGSIZE */
96 1.25 matt struct inpcbtable *inp_table;
97 1.27 itojun #if 1 /*IPSEC*/
98 1.27 itojun struct secpolicy *inp_sp; /* security policy. It may not be
99 1.27 itojun * used according to policy selection.
100 1.27 itojun */
101 1.27 itojun #endif
102 1.1 cgd };
103 1.18 mycroft #define inp_faddr inp_ip.ip_dst
104 1.18 mycroft #define inp_laddr inp_ip.ip_src
105 1.1 cgd
106 1.17 mycroft LIST_HEAD(inpcbhead, inpcb);
107 1.17 mycroft
108 1.10 mycroft struct inpcbtable {
109 1.13 mycroft CIRCLEQ_HEAD(, inpcb) inpt_queue;
110 1.17 mycroft struct inpcbhead *inpt_bindhashtbl;
111 1.17 mycroft struct inpcbhead *inpt_connecthashtbl;
112 1.17 mycroft u_long inpt_bindhash;
113 1.17 mycroft u_long inpt_connecthash;
114 1.10 mycroft u_int16_t inpt_lastport;
115 1.23 lukem u_int16_t inpt_lastlow;
116 1.10 mycroft };
117 1.23 lukem #define inpt_lasthi inpt_lastport
118 1.10 mycroft
119 1.17 mycroft /* states in inp_state: */
120 1.17 mycroft #define INP_ATTACHED 0
121 1.17 mycroft #define INP_BOUND 1
122 1.17 mycroft #define INP_CONNECTED 2
123 1.17 mycroft
124 1.1 cgd /* flags in inp_flags: */
125 1.1 cgd #define INP_RECVOPTS 0x01 /* receive incoming IP options */
126 1.1 cgd #define INP_RECVRETOPTS 0x02 /* receive IP options for reply */
127 1.1 cgd #define INP_RECVDSTADDR 0x04 /* receive IP dst address */
128 1.6 mycroft #define INP_HDRINCL 0x08 /* user supplies entire IP header */
129 1.23 lukem #define INP_HIGHPORT 0x10 /* (unused; FreeBSD compat) */
130 1.23 lukem #define INP_LOWPORT 0x20 /* user wants "low" port binding */
131 1.23 lukem #define INP_ANONPORT 0x40 /* port chosen for user */
132 1.19 thorpej #define INP_RECVIF 0x80 /* receive incoming interface */
133 1.19 thorpej #define INP_CONTROLOPTS (INP_RECVOPTS|INP_RECVRETOPTS|INP_RECVDSTADDR|\
134 1.19 thorpej INP_RECVIF)
135 1.1 cgd
136 1.16 mycroft #define sotoinpcb(so) ((struct inpcb *)(so)->so_pcb)
137 1.1 cgd
138 1.8 jtc #ifdef _KERNEL
139 1.17 mycroft void in_losing __P((struct inpcb *));
140 1.17 mycroft int in_pcballoc __P((struct socket *, void *));
141 1.17 mycroft int in_pcbbind __P((void *, struct mbuf *, struct proc *));
142 1.17 mycroft int in_pcbconnect __P((void *, struct mbuf *));
143 1.17 mycroft void in_pcbdetach __P((void *));
144 1.17 mycroft void in_pcbdisconnect __P((void *));
145 1.17 mycroft void in_pcbinit __P((struct inpcbtable *, int, int));
146 1.13 mycroft struct inpcb *
147 1.17 mycroft in_pcblookup_bind __P((struct inpcbtable *,
148 1.17 mycroft struct in_addr, u_int));
149 1.17 mycroft struct inpcb *
150 1.17 mycroft in_pcblookup_connect __P((struct inpcbtable *,
151 1.16 mycroft struct in_addr, u_int, struct in_addr, u_int));
152 1.20 thorpej int in_pcbnotify __P((struct inpcbtable *, struct in_addr, u_int,
153 1.16 mycroft struct in_addr, u_int, int, void (*)(struct inpcb *, int)));
154 1.17 mycroft void in_pcbnotifyall __P((struct inpcbtable *, struct in_addr, int,
155 1.16 mycroft void (*)(struct inpcb *, int)));
156 1.17 mycroft void in_pcbstate __P((struct inpcb *, int));
157 1.17 mycroft void in_rtchange __P((struct inpcb *, int));
158 1.17 mycroft void in_setpeeraddr __P((struct inpcb *, struct mbuf *));
159 1.17 mycroft void in_setsockaddr __P((struct inpcb *, struct mbuf *));
160 1.21 thorpej struct rtentry *
161 1.21 thorpej in_pcbrtentry __P((struct inpcb *));
162 1.27 itojun extern struct sockaddr_in *in_selectsrc __P((struct sockaddr_in *,
163 1.27 itojun struct route *, int, struct ip_moptions *, int *));
164 1.1 cgd #endif
165 1.24 perry
166 1.24 perry #endif /* _NETINET_IN_PCB_H_ */
167