1 |
1254 |
phoenix |
//==========================================================================
|
2 |
|
|
//
|
3 |
|
|
// include/netinet/in_pcb.h
|
4 |
|
|
//
|
5 |
|
|
//==========================================================================
|
6 |
|
|
//####BSDCOPYRIGHTBEGIN####
|
7 |
|
|
//
|
8 |
|
|
// -------------------------------------------
|
9 |
|
|
//
|
10 |
|
|
// Portions of this software may have been derived from OpenBSD,
|
11 |
|
|
// FreeBSD or other sources, and are covered by the appropriate
|
12 |
|
|
// copyright disclaimers included herein.
|
13 |
|
|
//
|
14 |
|
|
// Portions created by Red Hat are
|
15 |
|
|
// Copyright (C) 2002 Red Hat, Inc. All Rights Reserved.
|
16 |
|
|
//
|
17 |
|
|
// -------------------------------------------
|
18 |
|
|
//
|
19 |
|
|
//####BSDCOPYRIGHTEND####
|
20 |
|
|
//==========================================================================
|
21 |
|
|
|
22 |
|
|
/*
|
23 |
|
|
* Copyright (c) 1982, 1986, 1990, 1993
|
24 |
|
|
* The Regents of the University of California. All rights reserved.
|
25 |
|
|
*
|
26 |
|
|
* Redistribution and use in source and binary forms, with or without
|
27 |
|
|
* modification, are permitted provided that the following conditions
|
28 |
|
|
* are met:
|
29 |
|
|
* 1. Redistributions of source code must retain the above copyright
|
30 |
|
|
* notice, this list of conditions and the following disclaimer.
|
31 |
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
32 |
|
|
* notice, this list of conditions and the following disclaimer in the
|
33 |
|
|
* documentation and/or other materials provided with the distribution.
|
34 |
|
|
* 3. All advertising materials mentioning features or use of this software
|
35 |
|
|
* must display the following acknowledgement:
|
36 |
|
|
* This product includes software developed by the University of
|
37 |
|
|
* California, Berkeley and its contributors.
|
38 |
|
|
* 4. Neither the name of the University nor the names of its contributors
|
39 |
|
|
* may be used to endorse or promote products derived from this software
|
40 |
|
|
* without specific prior written permission.
|
41 |
|
|
*
|
42 |
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
43 |
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
44 |
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
45 |
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
46 |
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
47 |
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
48 |
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
49 |
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
50 |
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
51 |
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
52 |
|
|
* SUCH DAMAGE.
|
53 |
|
|
*
|
54 |
|
|
* @(#)in_pcb.h 8.1 (Berkeley) 6/10/93
|
55 |
|
|
* $FreeBSD: src/sys/netinet/in_pcb.h,v 1.32.2.4 2001/08/13 16:26:17 ume Exp $
|
56 |
|
|
*/
|
57 |
|
|
|
58 |
|
|
#ifndef _NETINET_IN_PCB_H_
|
59 |
|
|
#define _NETINET_IN_PCB_H_
|
60 |
|
|
|
61 |
|
|
#include <sys/queue.h>
|
62 |
|
|
|
63 |
|
|
//#include <netinet6/ipsec.h> /* for IPSEC */
|
64 |
|
|
|
65 |
|
|
#define in6pcb inpcb /* for KAME src sync over BSD*'s */
|
66 |
|
|
#define in6p_sp inp_sp /* for KAME src sync over BSD*'s */
|
67 |
|
|
|
68 |
|
|
/*
|
69 |
|
|
* Common structure pcb for internet protocol implementation.
|
70 |
|
|
* Here are stored pointers to local and foreign host table
|
71 |
|
|
* entries, local and foreign socket numbers, and pointers
|
72 |
|
|
* up (to a socket structure) and down (to a protocol-specific)
|
73 |
|
|
* control block.
|
74 |
|
|
*/
|
75 |
|
|
LIST_HEAD(inpcbhead, inpcb);
|
76 |
|
|
LIST_HEAD(inpcbporthead, inpcbport);
|
77 |
|
|
typedef u_quad_t inp_gen_t;
|
78 |
|
|
|
79 |
|
|
/*
|
80 |
|
|
* PCB with AF_INET6 null bind'ed laddr can receive AF_INET input packet.
|
81 |
|
|
* So, AF_INET6 null laddr is also used as AF_INET null laddr,
|
82 |
|
|
* by utilize following structure. (At last, same as INRIA)
|
83 |
|
|
*/
|
84 |
|
|
struct in_addr_4in6 {
|
85 |
|
|
u_int32_t ia46_pad32[3];
|
86 |
|
|
struct in_addr ia46_addr4;
|
87 |
|
|
};
|
88 |
|
|
|
89 |
|
|
/*
|
90 |
|
|
* NB: the zone allocator is type-stable EXCEPT FOR THE FIRST TWO LONGS
|
91 |
|
|
* of the structure. Therefore, it is important that the members in
|
92 |
|
|
* that position not contain any information which is required to be
|
93 |
|
|
* stable.
|
94 |
|
|
*/
|
95 |
|
|
struct icmp6_filter;
|
96 |
|
|
|
97 |
|
|
struct inpcb {
|
98 |
|
|
LIST_ENTRY(inpcb) inp_hash; /* hash list */
|
99 |
|
|
u_short inp_fport; /* foreign port */
|
100 |
|
|
u_short inp_lport; /* local port */
|
101 |
|
|
LIST_ENTRY(inpcb) inp_list; /* list for all PCBs of this proto */
|
102 |
|
|
u_int32_t inp_flow;
|
103 |
|
|
|
104 |
|
|
/* protocol dependent part, local and foreign addr */
|
105 |
|
|
union {
|
106 |
|
|
/* foreign host table entry */
|
107 |
|
|
struct in_addr_4in6 inp46_foreign;
|
108 |
|
|
struct in6_addr inp6_foreign;
|
109 |
|
|
} inp_dependfaddr;
|
110 |
|
|
union {
|
111 |
|
|
/* local host table entry */
|
112 |
|
|
struct in_addr_4in6 inp46_local;
|
113 |
|
|
struct in6_addr inp6_local;
|
114 |
|
|
} inp_dependladdr;
|
115 |
|
|
|
116 |
|
|
caddr_t inp_ppcb; /* pointer to per-protocol pcb */
|
117 |
|
|
struct inpcbinfo *inp_pcbinfo; /* PCB list info */
|
118 |
|
|
struct socket *inp_socket; /* back pointer to socket */
|
119 |
|
|
/* list for this PCB's local port */
|
120 |
|
|
int inp_flags; /* generic IP/datagram flags */
|
121 |
|
|
|
122 |
|
|
/* protocol dependent part; cached route */
|
123 |
|
|
union {
|
124 |
|
|
/* placeholder for routing entry */
|
125 |
|
|
struct route inp4_route;
|
126 |
|
|
struct route inp6_route;
|
127 |
|
|
} inp_dependroute;
|
128 |
|
|
|
129 |
|
|
struct inpcbpolicy *inp_sp; /* for IPSEC */
|
130 |
|
|
u_char inp_vflag;
|
131 |
|
|
#define INP_IPV4 0x1
|
132 |
|
|
#define INP_IPV6 0x2
|
133 |
|
|
u_char inp_ip_ttl; /* time to live proto */
|
134 |
|
|
u_char inp_ip_p; /* protocol proto */
|
135 |
|
|
|
136 |
|
|
/* protocol dependent part; options */
|
137 |
|
|
struct {
|
138 |
|
|
u_char inp4_ip_tos; /* type of service proto */
|
139 |
|
|
struct mbuf *inp4_options; /* IP options */
|
140 |
|
|
struct ip_moptions *inp4_moptions; /* IP multicast options */
|
141 |
|
|
} inp_depend4;
|
142 |
|
|
#define inp_faddr inp_dependfaddr.inp46_foreign.ia46_addr4
|
143 |
|
|
#define inp_laddr inp_dependladdr.inp46_local.ia46_addr4
|
144 |
|
|
#define inp_route inp_dependroute.inp4_route
|
145 |
|
|
#define inp_ip_tos inp_depend4.inp4_ip_tos
|
146 |
|
|
#define inp_options inp_depend4.inp4_options
|
147 |
|
|
#define inp_moptions inp_depend4.inp4_moptions
|
148 |
|
|
struct {
|
149 |
|
|
/* IP options */
|
150 |
|
|
struct mbuf *inp6_options;
|
151 |
|
|
/* IP6 options for incoming packets */
|
152 |
|
|
struct ip6_recvpktopts *inp6_inputopts;
|
153 |
|
|
/* IP6 options for outgoing packets */
|
154 |
|
|
struct ip6_pktopts *inp6_outputopts;
|
155 |
|
|
/* IP multicast options */
|
156 |
|
|
struct ip6_moptions *inp6_moptions;
|
157 |
|
|
/* ICMPv6 code type filter */
|
158 |
|
|
struct icmp6_filter *inp6_icmp6filt;
|
159 |
|
|
/* IPV6_CHECKSUM setsockopt */
|
160 |
|
|
int inp6_cksum;
|
161 |
|
|
u_short inp6_ifindex;
|
162 |
|
|
short inp6_hops;
|
163 |
|
|
} inp_depend6;
|
164 |
|
|
LIST_ENTRY(inpcb) inp_portlist;
|
165 |
|
|
struct inpcbport *inp_phd; /* head of this list */
|
166 |
|
|
inp_gen_t inp_gencnt; /* generation count of this instance */
|
167 |
|
|
#define in6p_faddr inp_dependfaddr.inp6_foreign
|
168 |
|
|
#define in6p_laddr inp_dependladdr.inp6_local
|
169 |
|
|
#define in6p_route inp_dependroute.inp6_route
|
170 |
|
|
#define in6p_hops inp_depend6.inp6_hops /* default hop limit */
|
171 |
|
|
#define in6p_ip6_nxt inp_ip_p
|
172 |
|
|
#define in6p_flowinfo inp_flow
|
173 |
|
|
#define in6p_vflag inp_vflag
|
174 |
|
|
#define in6p_options inp_depend6.inp6_options
|
175 |
|
|
#define in6p_inputopts inp_depend6.inp6_inputopts
|
176 |
|
|
#define in6p_outputopts inp_depend6.inp6_outputopts
|
177 |
|
|
#define in6p_moptions inp_depend6.inp6_moptions
|
178 |
|
|
#define in6p_icmp6filt inp_depend6.inp6_icmp6filt
|
179 |
|
|
#define in6p_cksum inp_depend6.inp6_cksum
|
180 |
|
|
#define inp6_ifindex inp_depend6.inp6_ifindex
|
181 |
|
|
#define in6p_flags inp_flags /* for KAME src sync over BSD*'s */
|
182 |
|
|
#define in6p_socket inp_socket /* for KAME src sync over BSD*'s */
|
183 |
|
|
#define in6p_lport inp_lport /* for KAME src sync over BSD*'s */
|
184 |
|
|
#define in6p_fport inp_fport /* for KAME src sync over BSD*'s */
|
185 |
|
|
#define in6p_ppcb inp_ppcb /* for KAME src sync over BSD*'s */
|
186 |
|
|
};
|
187 |
|
|
/*
|
188 |
|
|
* The range of the generation count, as used in this implementation,
|
189 |
|
|
* is 9e19. We would have to create 300 billion connections per
|
190 |
|
|
* second for this number to roll over in a year. This seems sufficiently
|
191 |
|
|
* unlikely that we simply don't concern ourselves with that possibility.
|
192 |
|
|
*/
|
193 |
|
|
|
194 |
|
|
/*
|
195 |
|
|
* Interface exported to userland by various protocols which use
|
196 |
|
|
* inpcbs. Hack alert -- only define if struct xsocket is in scope.
|
197 |
|
|
*/
|
198 |
|
|
#ifdef _SYS_SOCKETVAR_H_
|
199 |
|
|
struct xinpcb {
|
200 |
|
|
size_t xi_len; /* length of this structure */
|
201 |
|
|
struct inpcb xi_inp;
|
202 |
|
|
struct xsocket xi_socket;
|
203 |
|
|
u_quad_t xi_alignment_hack;
|
204 |
|
|
};
|
205 |
|
|
|
206 |
|
|
struct xinpgen {
|
207 |
|
|
size_t xig_len; /* length of this structure */
|
208 |
|
|
u_int xig_count; /* number of PCBs at this time */
|
209 |
|
|
inp_gen_t xig_gen; /* generation count at this time */
|
210 |
|
|
so_gen_t xig_sogen; /* socket generation count at this time */
|
211 |
|
|
};
|
212 |
|
|
#endif /* _SYS_SOCKETVAR_H_ */
|
213 |
|
|
|
214 |
|
|
struct inpcbport {
|
215 |
|
|
LIST_ENTRY(inpcbport) phd_hash;
|
216 |
|
|
struct inpcbhead phd_pcblist;
|
217 |
|
|
u_short phd_port;
|
218 |
|
|
};
|
219 |
|
|
|
220 |
|
|
struct inpcbinfo { /* XXX documentation, prefixes */
|
221 |
|
|
struct inpcbhead *hashbase;
|
222 |
|
|
u_long hashmask;
|
223 |
|
|
struct inpcbporthead *porthashbase;
|
224 |
|
|
u_long porthashmask;
|
225 |
|
|
struct inpcbhead *listhead;
|
226 |
|
|
u_short lastport;
|
227 |
|
|
u_short lastlow;
|
228 |
|
|
u_short lasthi;
|
229 |
|
|
struct vm_zone *ipi_zone; /* zone to allocate pcbs from */
|
230 |
|
|
u_int ipi_count; /* number of pcbs in this list */
|
231 |
|
|
u_quad_t ipi_gencnt; /* current generation count */
|
232 |
|
|
};
|
233 |
|
|
|
234 |
|
|
#define INP_PCBHASH(faddr, lport, fport, mask) \
|
235 |
|
|
(((faddr) ^ ((faddr) >> 16) ^ ntohs((lport) ^ (fport))) & (mask))
|
236 |
|
|
#define INP_PCBPORTHASH(lport, mask) \
|
237 |
|
|
(ntohs((lport)) & (mask))
|
238 |
|
|
|
239 |
|
|
/* flags in inp_flags: */
|
240 |
|
|
#define INP_RECVOPTS 0x01 /* receive incoming IP options */
|
241 |
|
|
#define INP_RECVRETOPTS 0x02 /* receive IP options for reply */
|
242 |
|
|
#define INP_RECVDSTADDR 0x04 /* receive IP dst address */
|
243 |
|
|
#define INP_HDRINCL 0x08 /* user supplies entire IP header */
|
244 |
|
|
#define INP_HIGHPORT 0x10 /* user wants "high" port binding */
|
245 |
|
|
#define INP_LOWPORT 0x20 /* user wants "low" port binding */
|
246 |
|
|
#define INP_ANONPORT 0x40 /* port chosen for user */
|
247 |
|
|
#define INP_RECVIF 0x80 /* receive incoming interface */
|
248 |
|
|
#define INP_MTUDISC 0x100 /* user can do MTU discovery */
|
249 |
|
|
#define INP_FAITH 0x200 /* accept FAITH'ed connections */
|
250 |
|
|
|
251 |
|
|
#define IN6P_IPV6_V6ONLY 0x008000 /* restrict AF_INET6 socket for v6 */
|
252 |
|
|
|
253 |
|
|
#define IN6P_PKTINFO 0x010000 /* receive IP6 dst and I/F */
|
254 |
|
|
#define IN6P_HOPLIMIT 0x020000 /* receive hoplimit */
|
255 |
|
|
#define IN6P_HOPOPTS 0x040000 /* receive hop-by-hop options */
|
256 |
|
|
#define IN6P_DSTOPTS 0x080000 /* receive dst options after rthdr */
|
257 |
|
|
#define IN6P_RTHDR 0x100000 /* receive routing header */
|
258 |
|
|
#define IN6P_RTHDRDSTOPTS 0x200000 /* receive dstoptions before rthdr */
|
259 |
|
|
#define IN6P_TCLASS 0x400000 /* receive traffic class value */
|
260 |
|
|
#define IN6P_AUTOFLOWLABEL 0x800000 /* attach flowlabel automatically */
|
261 |
|
|
#if 0
|
262 |
|
|
/*
|
263 |
|
|
* IN6P_BINDV6ONLY should be obsoleted by IN6P_IPV6_V6ONLY.
|
264 |
|
|
* Once we are sure that this macro is not referred from anywhere, we should
|
265 |
|
|
* completely delete the definition.
|
266 |
|
|
* jinmei@kame.net, 20010625.
|
267 |
|
|
*/
|
268 |
|
|
#define IN6P_BINDV6ONLY 0x10000000 /* do not grab IPv4 traffic */
|
269 |
|
|
#endif
|
270 |
|
|
#define IN6P_MINMTU 0x20000000 /* use minimum MTU */
|
271 |
|
|
#define IN6P_RFC2292 0x40000000 /* used RFC2292 API on the socket */
|
272 |
|
|
#define IN6P_MTU 0x80000000 /* receive path MTU */
|
273 |
|
|
|
274 |
|
|
#define INP_CONTROLOPTS (INP_RECVOPTS|INP_RECVRETOPTS|INP_RECVDSTADDR|\
|
275 |
|
|
INP_RECVIF|\
|
276 |
|
|
IN6P_PKTINFO|IN6P_HOPLIMIT|IN6P_HOPOPTS|\
|
277 |
|
|
IN6P_DSTOPTS|IN6P_RTHDR|IN6P_RTHDRDSTOPTS|\
|
278 |
|
|
IN6P_TCLASS|IN6P_AUTOFLOWLABEL|IN6P_RFC2292|\
|
279 |
|
|
IN6P_MTU)
|
280 |
|
|
#define INP_UNMAPPABLEOPTS (IN6P_HOPOPTS|IN6P_DSTOPTS|IN6P_RTHDR|\
|
281 |
|
|
IN6P_TCLASS|IN6P_AUTOFLOWLABEL)
|
282 |
|
|
|
283 |
|
|
/* for KAME src sync over BSD*'s */
|
284 |
|
|
#define IN6P_HIGHPORT INP_HIGHPORT
|
285 |
|
|
#define IN6P_LOWPORT INP_LOWPORT
|
286 |
|
|
#define IN6P_ANONPORT INP_ANONPORT
|
287 |
|
|
#define IN6P_RECVIF INP_RECVIF
|
288 |
|
|
#define IN6P_MTUDISC INP_MTUDISC
|
289 |
|
|
#define IN6P_FAITH INP_FAITH
|
290 |
|
|
#define IN6P_CONTROLOPTS INP_CONTROLOPTS
|
291 |
|
|
/*
|
292 |
|
|
* socket AF version is {newer than,or include}
|
293 |
|
|
* actual datagram AF version
|
294 |
|
|
*/
|
295 |
|
|
|
296 |
|
|
#define INPLOOKUP_WILDCARD 1
|
297 |
|
|
#define sotoinpcb(so) ((struct inpcb *)(so)->so_pcb)
|
298 |
|
|
#define sotoin6pcb(so) sotoinpcb(so) /* for KAME src sync over BSD*'s */
|
299 |
|
|
|
300 |
|
|
#define INP_SOCKAF(so) so->so_proto->pr_domain->dom_family
|
301 |
|
|
|
302 |
|
|
#define INP_CHECK_SOCKAF(so, af) (INP_SOCKAF(so) == af)
|
303 |
|
|
|
304 |
|
|
#ifdef _KERNEL
|
305 |
|
|
extern int ipport_lowfirstauto;
|
306 |
|
|
extern int ipport_lowlastauto;
|
307 |
|
|
extern int ipport_firstauto;
|
308 |
|
|
extern int ipport_lastauto;
|
309 |
|
|
extern int ipport_hifirstauto;
|
310 |
|
|
extern int ipport_hilastauto;
|
311 |
|
|
|
312 |
|
|
void in_pcbpurgeif0 __P((struct inpcb *, struct ifnet *));
|
313 |
|
|
void in_losing __P((struct inpcb *));
|
314 |
|
|
void in_rtchange __P((struct inpcb *, int));
|
315 |
|
|
int in_pcballoc __P((struct socket *, struct inpcbinfo *, struct proc *));
|
316 |
|
|
int in_pcbbind __P((struct inpcb *, struct sockaddr *, struct proc *));
|
317 |
|
|
int in_pcbconnect __P((struct inpcb *, struct sockaddr *, struct proc *));
|
318 |
|
|
void in_pcbdetach __P((struct inpcb *));
|
319 |
|
|
void in_pcbdisconnect __P((struct inpcb *));
|
320 |
|
|
int in_pcbinshash __P((struct inpcb *));
|
321 |
|
|
int in_pcbladdr __P((struct inpcb *, struct sockaddr *,
|
322 |
|
|
struct sockaddr_in **));
|
323 |
|
|
struct inpcb *
|
324 |
|
|
in_pcblookup_local __P((struct inpcbinfo *,
|
325 |
|
|
struct in_addr, u_int, int));
|
326 |
|
|
struct inpcb *
|
327 |
|
|
in_pcblookup_hash __P((struct inpcbinfo *,
|
328 |
|
|
struct in_addr, u_int, struct in_addr, u_int,
|
329 |
|
|
int, struct ifnet *));
|
330 |
|
|
void in_pcbnotifyall __P((struct inpcbhead *, struct in_addr,
|
331 |
|
|
int, void (*)(struct inpcb *, int)));
|
332 |
|
|
void in_pcbrehash __P((struct inpcb *));
|
333 |
|
|
int in_setpeeraddr __P((struct socket *so, struct sockaddr **nam));
|
334 |
|
|
int in_setsockaddr __P((struct socket *so, struct sockaddr **nam));
|
335 |
|
|
void in_pcbremlists __P((struct inpcb *inp));
|
336 |
|
|
int prison_xinpcb __P((struct proc *p, struct inpcb *inp));
|
337 |
|
|
|
338 |
|
|
int in6_selectroute __P((struct sockaddr_in6 *, struct ip6_pktopts *,
|
339 |
|
|
struct ip6_moptions *, struct route *,
|
340 |
|
|
struct ifnet **, struct rtentry **, int));
|
341 |
|
|
#endif /* _KERNEL */
|
342 |
|
|
|
343 |
|
|
#endif /* !_NETINET_IN_PCB_H_ */
|