VirtualBox

source: vbox/trunk/src/VBox/Devices/Network/slirp/ip.h@ 15035

最後變更 在這個檔案從15035是 14638,由 vboxsync 提交於 16 年 前

NAT: some reformatting for better readability; merged VBOX_WITH_BSD_TCP_REASS with VBOX_WITH_BSD_REASS

  • 屬性 svn:eol-style 設為 native
檔案大小: 13.1 KB
 
1/*
2 * Copyright (c) 1982, 1986, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 * @(#)ip.h 8.1 (Berkeley) 6/10/93
34 * ip.h,v 1.3 1994/08/21 05:27:30 paul Exp
35 */
36
37#ifndef _IP_H_
38#define _IP_H_
39
40#ifdef VBOX_WITH_BSD_REASS
41# include "queue.h"
42#endif
43
44#ifdef WORDS_BIGENDIAN
45# ifndef NTOHL
46# define NTOHL(d)
47# endif
48# ifndef NTOHS
49# define NTOHS(d)
50# endif
51# ifndef HTONL
52# define HTONL(d)
53# endif
54# ifndef HTONS
55# define HTONS(d)
56# endif
57#else
58# ifndef NTOHL
59# define NTOHL(d) ((d) = ntohl((d)))
60# endif
61# ifndef NTOHS
62# define NTOHS(d) ((d) = ntohs((u_int16_t)(d)))
63# endif
64# ifndef HTONL
65# define HTONL(d) ((d) = htonl((d)))
66# endif
67# ifndef HTONS
68# define HTONS(d) ((d) = htons((u_int16_t)(d)))
69# endif
70#endif
71
72typedef u_int32_t n_long; /* long as received from the net */
73
74/*
75 * Definitions for internet protocol version 4.
76 * Per RFC 791, September 1981.
77 */
78#define IPVERSION 4
79
80/*
81 * Structure of an internet header, naked of options.
82 */
83struct ip {
84/*
85 * bitfield types must be u_int8_t for MSVC, otherwise it will use a full dword (for u_int)
86 */
87#ifdef WORDS_BIGENDIAN
88 u_int ip_v:4, /* version */
89 ip_hl:4; /* header length */
90#else
91#ifdef _MSC_VER
92 u_int8_t ip_hl:4, /* header length */
93#else
94 u_int ip_hl:4, /* header length */
95#endif
96 ip_v:4; /* version */
97#endif
98 u_int8_t ip_tos; /* type of service */
99 u_int16_t ip_len; /* total length */
100 u_int16_t ip_id; /* identification */
101 u_int16_t ip_off; /* fragment offset field */
102#define IP_DF 0x4000 /* don't fragment flag */
103#define IP_MF 0x2000 /* more fragments flag */
104#define IP_OFFMASK 0x1fff /* mask for fragmenting bits */
105 u_int8_t ip_ttl; /* time to live */
106 u_int8_t ip_p; /* protocol */
107 u_int16_t ip_sum; /* checksum */
108 struct in_addr ip_src,ip_dst; /* source and dest address */
109};
110
111#define IP_MAXPACKET 65535 /* maximum packet size */
112
113/*
114 * Definitions for IP type of service (ip_tos)
115 */
116#define IPTOS_LOWDELAY 0x10
117#define IPTOS_THROUGHPUT 0x08
118#define IPTOS_RELIABILITY 0x04
119
120/*
121 * Definitions for options.
122 */
123#define IPOPT_COPIED(o) ((o)&0x80)
124#define IPOPT_CLASS(o) ((o)&0x60)
125#define IPOPT_NUMBER(o) ((o)&0x1f)
126
127#define IPOPT_CONTROL 0x00
128#define IPOPT_RESERVED1 0x20
129#define IPOPT_DEBMEAS 0x40
130#define IPOPT_RESERVED2 0x60
131
132#define IPOPT_EOL 0 /* end of option list */
133#define IPOPT_NOP 1 /* no operation */
134
135#define IPOPT_RR 7 /* record packet route */
136#define IPOPT_TS 68 /* timestamp */
137#define IPOPT_SECURITY 130 /* provide s,c,h,tcc */
138#define IPOPT_LSRR 131 /* loose source route */
139#define IPOPT_SATID 136 /* satnet id */
140#define IPOPT_SSRR 137 /* strict source route */
141
142/*
143 * Offsets to fields in options other than EOL and NOP.
144 */
145#define IPOPT_OPTVAL 0 /* option ID */
146#define IPOPT_OLEN 1 /* option length */
147#define IPOPT_OFFSET 2 /* offset within option */
148#define IPOPT_MINOFF 4 /* min value of above */
149
150/*
151 * Time stamp option structure.
152 */
153struct ip_timestamp {
154 u_int8_t ipt_code; /* IPOPT_TS */
155 u_int8_t ipt_len; /* size of structure (variable) */
156 u_int8_t ipt_ptr; /* index of current entry */
157/*
158 * bitfield types must be u_int8_t for MSVC, otherwise it will use a full dword (for u_int)
159 */
160#ifdef WORDS_BIGENDIAN
161 u_int ipt_oflw:4, /* overflow counter */
162 ipt_flg:4; /* flags, see below */
163#else
164#ifdef _MSC_VER
165 u_int8_t ipt_flg:4, /* flags, see below */
166#else
167 u_int ipt_flg:4, /* flags, see below */
168#endif
169 ipt_oflw:4; /* overflow counter */
170#endif
171 union ipt_timestamp {
172 n_long ipt_time[1];
173 struct ipt_ta {
174 struct in_addr ipt_addr;
175 n_long ipt_time;
176 } ipt_ta[1];
177 } ipt_timestamp;
178};
179
180/* flag bits for ipt_flg */
181#define IPOPT_TS_TSONLY 0 /* timestamps only */
182#define IPOPT_TS_TSANDADDR 1 /* timestamps and addresses */
183#define IPOPT_TS_PRESPEC 3 /* specified modules only */
184
185/* bits for security (not byte swapped) */
186#define IPOPT_SECUR_UNCLASS 0x0000
187#define IPOPT_SECUR_CONFID 0xf135
188#define IPOPT_SECUR_EFTO 0x789a
189#define IPOPT_SECUR_MMMM 0xbc4d
190#define IPOPT_SECUR_RESTR 0xaf13
191#define IPOPT_SECUR_SECRET 0xd788
192#define IPOPT_SECUR_TOPSECRET 0x6bc5
193
194/*
195 * Internet implementation parameters.
196 */
197#define MAXTTL 255 /* maximum time to live (seconds) */
198#define IPDEFTTL 64 /* default ttl, from RFC 1340 */
199#define IPFRAGTTL 60 /* time to live for frags, slowhz */
200#define IPTTLDEC 1 /* subtracted when forwarding */
201
202#define IP_MSS 576 /* default maximum segment size */
203
204#ifdef HAVE_SYS_TYPES32_H /* Overcome some Solaris 2.x junk */
205# include <sys/types32.h>
206#else
207# if SIZEOF_CHAR_P == 4
208typedef caddr_t caddr32_t;
209# else
210# if !defined(VBOX_WITH_BSD_REASS)
211typedef u_int32_t caddr32_t;
212# else /* VBOX_WITH_BSD_REASS */
213typedef caddr_t caddr32_t;
214# endif /* VBOX_WITH_BSD_REASS */
215# endif
216#endif
217
218#if SIZEOF_CHAR_P == 4
219typedef struct ipq_t *ipqp_32;
220typedef struct ipasfrag *ipasfragp_32;
221#else
222typedef caddr32_t ipqp_32;
223typedef caddr32_t ipasfragp_32;
224#endif
225
226/*
227 * Overlay for ip header used by other protocols (tcp, udp).
228 */
229struct ipovly {
230#if !defined(VBOX_WITH_BSD_REASS)
231 caddr32_t ih_next, ih_prev; /* for protocol sequence q's */
232 u_int8_t ih_x1; /* (unused) */
233#else /* VBOX_WITH_BSD_REASS */
234 u_int8_t ih_x1[9]; /* (unused) */
235#endif /* VBOX_WITH_BSD_REASS */
236 u_int8_t ih_pr; /* protocol */
237 u_int16_t ih_len; /* protocol length */
238 struct in_addr ih_src; /* source internet address */
239 struct in_addr ih_dst; /* destination internet address */
240};
241
242/*
243 * Ip reassembly queue structure. Each fragment
244 * being reassembled is attached to one of these structures.
245 * They are timed out after ipq_ttl drops to 0, and may also
246 * be reclaimed if memory becomes tight.
247 * size 28 bytes
248 */
249struct ipq_t {
250#ifndef VBOX_WITH_BSD_REASS
251 ipqp_32 next,prev; /* to other reass headers */
252#else /* VBOX_WITH_BSD_REASS */
253 TAILQ_ENTRY(ipq_t) ipq_list;
254#endif /* VBOX_WITH_BSD_REASS */
255 u_int8_t ipq_ttl; /* time for reass q to live */
256 u_int8_t ipq_p; /* protocol of this fragment */
257 u_int16_t ipq_id; /* sequence id for reassembly */
258#ifndef VBOX_WITH_BSD_REASS
259 ipasfragp_32 ipq_next,ipq_prev; /* to ip headers of fragments */
260#else /* VBOX_WITH_BSD_REASS */
261 u_int8_t ipq_nfrags; /* # of fragments in this packet */
262 struct mbuf *ipq_frags; /* to ip headers of fragments */
263#endif /* VBOX_WITH_BSD_REASS */
264
265 struct in_addr ipq_src,ipq_dst;
266};
267
268#ifdef VBOX_WITH_BSD_REASS
269/*
270* IP datagram reassembly.
271*/
272#define IPREASS_NHASH_LOG2 6
273#define IPREASS_NHASH (1 << IPREASS_NHASH_LOG2)
274#define IPREASS_HMASK (IPREASS_NHASH - 1)
275#define IPREASS_HASH(x,y) \
276(((((x) & 0xF) | ((((x) >> 8) & 0xF) << 4)) ^ (y)) & IPREASS_HMASK)
277TAILQ_HEAD(ipqhead,ipq_t);
278#endif /* VBOX_WITH_BSD_REASS */
279
280/*
281 * Ip header, when holding a fragment.
282 *
283 * Note: ipf_next must be at same offset as ipq_next above
284 */
285struct ipasfrag {
286#ifdef WORDS_BIGENDIAN
287 u_int ip_v:4,
288 ip_hl:4;
289#else
290#ifdef _MSC_VER
291 u_int8_t ip_hl:4,
292#else
293 u_int ip_hl:4,
294#endif
295 ip_v:4;
296#endif
297 /* BUG : u_int changed to u_int8_t.
298 * sizeof(u_int)==4 on linux 2.0
299 */
300 u_int8_t ipf_mff; /* XXX overlays ip_tos: use low bit
301 * to avoid destroying tos (PPPDTRuu);
302 * copied from (ip_off&IP_MF) */
303 u_int16_t ip_len;
304 u_int16_t ip_id;
305 u_int16_t ip_off;
306 u_int8_t ip_ttl;
307 u_int8_t ip_p;
308 u_int16_t ip_sum;
309 ipasfragp_32 ipf_next; /* next fragment */
310 ipasfragp_32 ipf_prev; /* previous fragment */
311};
312
313/*
314 * Structure stored in mbuf in inpcb.ip_options
315 * and passed to ip_output when ip options are in use.
316 * The actual length of the options (including ipopt_dst)
317 * is in m_len.
318 */
319#define MAX_IPOPTLEN 40
320
321struct ipoption {
322 struct in_addr ipopt_dst; /* first-hop dst if source routed */
323 int8_t ipopt_list[MAX_IPOPTLEN]; /* options proper */
324};
325
326/*
327 * Structure attached to inpcb.ip_moptions and
328 * passed to ip_output when IP multicast options are in use.
329 */
330
331struct ipstat_t {
332 u_long ips_total; /* total packets received */
333 u_long ips_badsum; /* checksum bad */
334 u_long ips_tooshort; /* packet too short */
335 u_long ips_toosmall; /* not enough data */
336 u_long ips_badhlen; /* ip header length < data size */
337 u_long ips_badlen; /* ip length < ip header length */
338 u_long ips_fragments; /* fragments received */
339 u_long ips_fragdropped; /* frags dropped (dups, out of space) */
340 u_long ips_fragtimeout; /* fragments timed out */
341 u_long ips_forward; /* packets forwarded */
342 u_long ips_cantforward; /* packets rcvd for unreachable dest */
343 u_long ips_redirectsent; /* packets forwarded on same net */
344 u_long ips_noproto; /* unknown or unsupported protocol */
345 u_long ips_delivered; /* datagrams delivered to upper level*/
346 u_long ips_localout; /* total ip packets generated here */
347 u_long ips_odropped; /* lost packets due to nobufs, etc. */
348 u_long ips_reassembled; /* total packets reassembled ok */
349 u_long ips_fragmented; /* datagrams successfully fragmented */
350 u_long ips_ofragments; /* output fragments created */
351 u_long ips_cantfrag; /* don't fragment flag was set, etc. */
352 u_long ips_badoptions; /* error in option processing */
353 u_long ips_noroute; /* packets discarded due to no route */
354 u_long ips_badvers; /* ip version != 4 */
355 u_long ips_rawout; /* total raw ip packets generated */
356 u_long ips_unaligned; /* times the ip packet was not aligned */
357};
358
359
360#endif
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette