VirtualBox

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

最後變更 在這個檔案從1048是 1033,由 vboxsync 提交於 18 年 前

Big change to make slirp fully instantiatable (replace all global
variables with local ones, passing a reference to the state/config
structure to all places which are interested). You can now have as many
cards in the guest configured for NAT networking as you want.

  • 屬性 svn:eol-style 設為 native
檔案大小: 10.2 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 WORDS_BIGENDIAN
41# ifndef NTOHL
42# define NTOHL(d)
43# endif
44# ifndef NTOHS
45# define NTOHS(d)
46# endif
47# ifndef HTONL
48# define HTONL(d)
49# endif
50# ifndef HTONS
51# define HTONS(d)
52# endif
53#else
54# ifndef NTOHL
55# define NTOHL(d) ((d) = ntohl((d)))
56# endif
57# ifndef NTOHS
58# define NTOHS(d) ((d) = ntohs((u_int16_t)(d)))
59# endif
60# ifndef HTONL
61# define HTONL(d) ((d) = htonl((d)))
62# endif
63# ifndef HTONS
64# define HTONS(d) ((d) = htons((u_int16_t)(d)))
65# endif
66#endif
67
68typedef u_int32_t n_long; /* long as received from the net */
69
70/*
71 * Definitions for internet protocol version 4.
72 * Per RFC 791, September 1981.
73 */
74#define IPVERSION 4
75
76/*
77 * Structure of an internet header, naked of options.
78 */
79struct ip {
80#ifdef VBOX
81/*
82 * bitfield types must be u_int8_t for MSVC, otherwise it will use a full dword (for u_int)
83 */
84#endif
85#ifdef WORDS_BIGENDIAN
86 u_int ip_v:4, /* version */
87 ip_hl:4; /* header length */
88#else
89#ifdef _MSC_VER
90 u_int8_t ip_hl:4, /* header length */
91#else
92 u_int ip_hl:4, /* header length */
93#endif
94 ip_v:4; /* version */
95#endif
96 u_int8_t ip_tos; /* type of service */
97 u_int16_t ip_len; /* total length */
98 u_int16_t ip_id; /* identification */
99 u_int16_t ip_off; /* fragment offset field */
100#define IP_DF 0x4000 /* don't fragment flag */
101#define IP_MF 0x2000 /* more fragments flag */
102#define IP_OFFMASK 0x1fff /* mask for fragmenting bits */
103 u_int8_t ip_ttl; /* time to live */
104 u_int8_t ip_p; /* protocol */
105 u_int16_t ip_sum; /* checksum */
106 struct in_addr ip_src,ip_dst; /* source and dest address */
107};
108
109#define IP_MAXPACKET 65535 /* maximum packet size */
110
111/*
112 * Definitions for IP type of service (ip_tos)
113 */
114#define IPTOS_LOWDELAY 0x10
115#define IPTOS_THROUGHPUT 0x08
116#define IPTOS_RELIABILITY 0x04
117
118/*
119 * Definitions for options.
120 */
121#define IPOPT_COPIED(o) ((o)&0x80)
122#define IPOPT_CLASS(o) ((o)&0x60)
123#define IPOPT_NUMBER(o) ((o)&0x1f)
124
125#define IPOPT_CONTROL 0x00
126#define IPOPT_RESERVED1 0x20
127#define IPOPT_DEBMEAS 0x40
128#define IPOPT_RESERVED2 0x60
129
130#define IPOPT_EOL 0 /* end of option list */
131#define IPOPT_NOP 1 /* no operation */
132
133#define IPOPT_RR 7 /* record packet route */
134#define IPOPT_TS 68 /* timestamp */
135#define IPOPT_SECURITY 130 /* provide s,c,h,tcc */
136#define IPOPT_LSRR 131 /* loose source route */
137#define IPOPT_SATID 136 /* satnet id */
138#define IPOPT_SSRR 137 /* strict source route */
139
140/*
141 * Offsets to fields in options other than EOL and NOP.
142 */
143#define IPOPT_OPTVAL 0 /* option ID */
144#define IPOPT_OLEN 1 /* option length */
145#define IPOPT_OFFSET 2 /* offset within option */
146#define IPOPT_MINOFF 4 /* min value of above */
147
148/*
149 * Time stamp option structure.
150 */
151struct ip_timestamp {
152 u_int8_t ipt_code; /* IPOPT_TS */
153 u_int8_t ipt_len; /* size of structure (variable) */
154 u_int8_t ipt_ptr; /* index of current entry */
155#ifdef VBOX
156/*
157 * bitfield types must be u_int8_t for MSVC, otherwise it will use a full dword (for u_int)
158 */
159#endif
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
210typedef u_int32_t caddr32_t;
211#endif
212#endif
213
214#if SIZEOF_CHAR_P == 4
215typedef struct ipq_t *ipqp_32;
216typedef struct ipasfrag *ipasfragp_32;
217#else
218typedef caddr32_t ipqp_32;
219typedef caddr32_t ipasfragp_32;
220#endif
221
222/*
223 * Overlay for ip header used by other protocols (tcp, udp).
224 */
225struct ipovly {
226 caddr32_t ih_next, ih_prev; /* for protocol sequence q's */
227 u_int8_t ih_x1; /* (unused) */
228 u_int8_t ih_pr; /* protocol */
229 u_int16_t ih_len; /* protocol length */
230 struct in_addr ih_src; /* source internet address */
231 struct in_addr ih_dst; /* destination internet address */
232};
233
234/*
235 * Ip reassembly queue structure. Each fragment
236 * being reassembled is attached to one of these structures.
237 * They are timed out after ipq_ttl drops to 0, and may also
238 * be reclaimed if memory becomes tight.
239 * size 28 bytes
240 */
241struct ipq_t {
242 ipqp_32 next,prev; /* to other reass headers */
243 u_int8_t ipq_ttl; /* time for reass q to live */
244 u_int8_t ipq_p; /* protocol of this fragment */
245 u_int16_t ipq_id; /* sequence id for reassembly */
246 ipasfragp_32 ipq_next,ipq_prev;
247 /* to ip headers of fragments */
248 struct in_addr ipq_src,ipq_dst;
249};
250
251/*
252 * Ip header, when holding a fragment.
253 *
254 * Note: ipf_next must be at same offset as ipq_next above
255 */
256struct ipasfrag {
257#ifdef WORDS_BIGENDIAN
258 u_int ip_v:4,
259 ip_hl:4;
260#else
261#ifdef _MSC_VER
262 u_int8_t ip_hl:4,
263#else
264 u_int ip_hl:4,
265#endif
266 ip_v:4;
267#endif
268 /* BUG : u_int changed to u_int8_t.
269 * sizeof(u_int)==4 on linux 2.0
270 */
271 u_int8_t ipf_mff; /* XXX overlays ip_tos: use low bit
272 * to avoid destroying tos (PPPDTRuu);
273 * copied from (ip_off&IP_MF) */
274 u_int16_t ip_len;
275 u_int16_t ip_id;
276 u_int16_t ip_off;
277 u_int8_t ip_ttl;
278 u_int8_t ip_p;
279 u_int16_t ip_sum;
280 ipasfragp_32 ipf_next; /* next fragment */
281 ipasfragp_32 ipf_prev; /* previous fragment */
282};
283
284/*
285 * Structure stored in mbuf in inpcb.ip_options
286 * and passed to ip_output when ip options are in use.
287 * The actual length of the options (including ipopt_dst)
288 * is in m_len.
289 */
290#define MAX_IPOPTLEN 40
291
292struct ipoption {
293 struct in_addr ipopt_dst; /* first-hop dst if source routed */
294 int8_t ipopt_list[MAX_IPOPTLEN]; /* options proper */
295};
296
297/*
298 * Structure attached to inpcb.ip_moptions and
299 * passed to ip_output when IP multicast options are in use.
300 */
301
302#ifdef VBOX
303struct ipstat_t {
304#else /* !VBOX */
305struct ipstat {
306#endif /* !VBOX */
307 u_long ips_total; /* total packets received */
308 u_long ips_badsum; /* checksum bad */
309 u_long ips_tooshort; /* packet too short */
310 u_long ips_toosmall; /* not enough data */
311 u_long ips_badhlen; /* ip header length < data size */
312 u_long ips_badlen; /* ip length < ip header length */
313 u_long ips_fragments; /* fragments received */
314 u_long ips_fragdropped; /* frags dropped (dups, out of space) */
315 u_long ips_fragtimeout; /* fragments timed out */
316 u_long ips_forward; /* packets forwarded */
317 u_long ips_cantforward; /* packets rcvd for unreachable dest */
318 u_long ips_redirectsent; /* packets forwarded on same net */
319 u_long ips_noproto; /* unknown or unsupported protocol */
320 u_long ips_delivered; /* datagrams delivered to upper level*/
321 u_long ips_localout; /* total ip packets generated here */
322 u_long ips_odropped; /* lost packets due to nobufs, etc. */
323 u_long ips_reassembled; /* total packets reassembled ok */
324 u_long ips_fragmented; /* datagrams successfully fragmented */
325 u_long ips_ofragments; /* output fragments created */
326 u_long ips_cantfrag; /* don't fragment flag was set, etc. */
327 u_long ips_badoptions; /* error in option processing */
328 u_long ips_noroute; /* packets discarded due to no route */
329 u_long ips_badvers; /* ip version != 4 */
330 u_long ips_rawout; /* total raw ip packets generated */
331 u_long ips_unaligned; /* times the ip packet was not aligned */
332};
333
334#ifndef VBOX
335extern struct ipstat ipstat;
336extern struct ipq ipq; /* ip reass. queue */
337extern u_int16_t ip_id; /* ip packet ctr, for ids */
338extern int ip_defttl; /* default IP ttl */
339#endif /* !VBOX */
340
341#endif
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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