VirtualBox

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

Last change on this file since 3021 was 1076, checked in by vboxsync, 18 years ago

Removed tons of ifdef VBOX conditionals to make slirp readable again

  • Property svn:eol-style set to native
File size: 9.9 KB
Line 
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/*
81 * bitfield types must be u_int8_t for MSVC, otherwise it will use a full dword (for u_int)
82 */
83#ifdef WORDS_BIGENDIAN
84 u_int ip_v:4, /* version */
85 ip_hl:4; /* header length */
86#else
87#ifdef _MSC_VER
88 u_int8_t ip_hl:4, /* header length */
89#else
90 u_int ip_hl:4, /* header length */
91#endif
92 ip_v:4; /* version */
93#endif
94 u_int8_t ip_tos; /* type of service */
95 u_int16_t ip_len; /* total length */
96 u_int16_t ip_id; /* identification */
97 u_int16_t ip_off; /* fragment offset field */
98#define IP_DF 0x4000 /* don't fragment flag */
99#define IP_MF 0x2000 /* more fragments flag */
100#define IP_OFFMASK 0x1fff /* mask for fragmenting bits */
101 u_int8_t ip_ttl; /* time to live */
102 u_int8_t ip_p; /* protocol */
103 u_int16_t ip_sum; /* checksum */
104 struct in_addr ip_src,ip_dst; /* source and dest address */
105};
106
107#define IP_MAXPACKET 65535 /* maximum packet size */
108
109/*
110 * Definitions for IP type of service (ip_tos)
111 */
112#define IPTOS_LOWDELAY 0x10
113#define IPTOS_THROUGHPUT 0x08
114#define IPTOS_RELIABILITY 0x04
115
116/*
117 * Definitions for options.
118 */
119#define IPOPT_COPIED(o) ((o)&0x80)
120#define IPOPT_CLASS(o) ((o)&0x60)
121#define IPOPT_NUMBER(o) ((o)&0x1f)
122
123#define IPOPT_CONTROL 0x00
124#define IPOPT_RESERVED1 0x20
125#define IPOPT_DEBMEAS 0x40
126#define IPOPT_RESERVED2 0x60
127
128#define IPOPT_EOL 0 /* end of option list */
129#define IPOPT_NOP 1 /* no operation */
130
131#define IPOPT_RR 7 /* record packet route */
132#define IPOPT_TS 68 /* timestamp */
133#define IPOPT_SECURITY 130 /* provide s,c,h,tcc */
134#define IPOPT_LSRR 131 /* loose source route */
135#define IPOPT_SATID 136 /* satnet id */
136#define IPOPT_SSRR 137 /* strict source route */
137
138/*
139 * Offsets to fields in options other than EOL and NOP.
140 */
141#define IPOPT_OPTVAL 0 /* option ID */
142#define IPOPT_OLEN 1 /* option length */
143#define IPOPT_OFFSET 2 /* offset within option */
144#define IPOPT_MINOFF 4 /* min value of above */
145
146/*
147 * Time stamp option structure.
148 */
149struct ip_timestamp {
150 u_int8_t ipt_code; /* IPOPT_TS */
151 u_int8_t ipt_len; /* size of structure (variable) */
152 u_int8_t ipt_ptr; /* index of current entry */
153/*
154 * bitfield types must be u_int8_t for MSVC, otherwise it will use a full dword (for u_int)
155 */
156#ifdef WORDS_BIGENDIAN
157 u_int ipt_oflw:4, /* overflow counter */
158 ipt_flg:4; /* flags, see below */
159#else
160#ifdef _MSC_VER
161 u_int8_t ipt_flg:4, /* flags, see below */
162#else
163 u_int ipt_flg:4, /* flags, see below */
164#endif
165 ipt_oflw:4; /* overflow counter */
166#endif
167 union ipt_timestamp {
168 n_long ipt_time[1];
169 struct ipt_ta {
170 struct in_addr ipt_addr;
171 n_long ipt_time;
172 } ipt_ta[1];
173 } ipt_timestamp;
174};
175
176/* flag bits for ipt_flg */
177#define IPOPT_TS_TSONLY 0 /* timestamps only */
178#define IPOPT_TS_TSANDADDR 1 /* timestamps and addresses */
179#define IPOPT_TS_PRESPEC 3 /* specified modules only */
180
181/* bits for security (not byte swapped) */
182#define IPOPT_SECUR_UNCLASS 0x0000
183#define IPOPT_SECUR_CONFID 0xf135
184#define IPOPT_SECUR_EFTO 0x789a
185#define IPOPT_SECUR_MMMM 0xbc4d
186#define IPOPT_SECUR_RESTR 0xaf13
187#define IPOPT_SECUR_SECRET 0xd788
188#define IPOPT_SECUR_TOPSECRET 0x6bc5
189
190/*
191 * Internet implementation parameters.
192 */
193#define MAXTTL 255 /* maximum time to live (seconds) */
194#define IPDEFTTL 64 /* default ttl, from RFC 1340 */
195#define IPFRAGTTL 60 /* time to live for frags, slowhz */
196#define IPTTLDEC 1 /* subtracted when forwarding */
197
198#define IP_MSS 576 /* default maximum segment size */
199
200#ifdef HAVE_SYS_TYPES32_H /* Overcome some Solaris 2.x junk */
201#include <sys/types32.h>
202#else
203#if SIZEOF_CHAR_P == 4
204typedef caddr_t caddr32_t;
205#else
206typedef u_int32_t caddr32_t;
207#endif
208#endif
209
210#if SIZEOF_CHAR_P == 4
211typedef struct ipq_t *ipqp_32;
212typedef struct ipasfrag *ipasfragp_32;
213#else
214typedef caddr32_t ipqp_32;
215typedef caddr32_t ipasfragp_32;
216#endif
217
218/*
219 * Overlay for ip header used by other protocols (tcp, udp).
220 */
221struct ipovly {
222 caddr32_t ih_next, ih_prev; /* for protocol sequence q's */
223 u_int8_t ih_x1; /* (unused) */
224 u_int8_t ih_pr; /* protocol */
225 u_int16_t ih_len; /* protocol length */
226 struct in_addr ih_src; /* source internet address */
227 struct in_addr ih_dst; /* destination internet address */
228};
229
230/*
231 * Ip reassembly queue structure. Each fragment
232 * being reassembled is attached to one of these structures.
233 * They are timed out after ipq_ttl drops to 0, and may also
234 * be reclaimed if memory becomes tight.
235 * size 28 bytes
236 */
237struct ipq_t {
238 ipqp_32 next,prev; /* to other reass headers */
239 u_int8_t ipq_ttl; /* time for reass q to live */
240 u_int8_t ipq_p; /* protocol of this fragment */
241 u_int16_t ipq_id; /* sequence id for reassembly */
242 ipasfragp_32 ipq_next,ipq_prev;
243 /* to ip headers of fragments */
244 struct in_addr ipq_src,ipq_dst;
245};
246
247/*
248 * Ip header, when holding a fragment.
249 *
250 * Note: ipf_next must be at same offset as ipq_next above
251 */
252struct ipasfrag {
253#ifdef WORDS_BIGENDIAN
254 u_int ip_v:4,
255 ip_hl:4;
256#else
257#ifdef _MSC_VER
258 u_int8_t ip_hl:4,
259#else
260 u_int ip_hl:4,
261#endif
262 ip_v:4;
263#endif
264 /* BUG : u_int changed to u_int8_t.
265 * sizeof(u_int)==4 on linux 2.0
266 */
267 u_int8_t ipf_mff; /* XXX overlays ip_tos: use low bit
268 * to avoid destroying tos (PPPDTRuu);
269 * copied from (ip_off&IP_MF) */
270 u_int16_t ip_len;
271 u_int16_t ip_id;
272 u_int16_t ip_off;
273 u_int8_t ip_ttl;
274 u_int8_t ip_p;
275 u_int16_t ip_sum;
276 ipasfragp_32 ipf_next; /* next fragment */
277 ipasfragp_32 ipf_prev; /* previous fragment */
278};
279
280/*
281 * Structure stored in mbuf in inpcb.ip_options
282 * and passed to ip_output when ip options are in use.
283 * The actual length of the options (including ipopt_dst)
284 * is in m_len.
285 */
286#define MAX_IPOPTLEN 40
287
288struct ipoption {
289 struct in_addr ipopt_dst; /* first-hop dst if source routed */
290 int8_t ipopt_list[MAX_IPOPTLEN]; /* options proper */
291};
292
293/*
294 * Structure attached to inpcb.ip_moptions and
295 * passed to ip_output when IP multicast options are in use.
296 */
297
298struct ipstat_t {
299 u_long ips_total; /* total packets received */
300 u_long ips_badsum; /* checksum bad */
301 u_long ips_tooshort; /* packet too short */
302 u_long ips_toosmall; /* not enough data */
303 u_long ips_badhlen; /* ip header length < data size */
304 u_long ips_badlen; /* ip length < ip header length */
305 u_long ips_fragments; /* fragments received */
306 u_long ips_fragdropped; /* frags dropped (dups, out of space) */
307 u_long ips_fragtimeout; /* fragments timed out */
308 u_long ips_forward; /* packets forwarded */
309 u_long ips_cantforward; /* packets rcvd for unreachable dest */
310 u_long ips_redirectsent; /* packets forwarded on same net */
311 u_long ips_noproto; /* unknown or unsupported protocol */
312 u_long ips_delivered; /* datagrams delivered to upper level*/
313 u_long ips_localout; /* total ip packets generated here */
314 u_long ips_odropped; /* lost packets due to nobufs, etc. */
315 u_long ips_reassembled; /* total packets reassembled ok */
316 u_long ips_fragmented; /* datagrams successfully fragmented */
317 u_long ips_ofragments; /* output fragments created */
318 u_long ips_cantfrag; /* don't fragment flag was set, etc. */
319 u_long ips_badoptions; /* error in option processing */
320 u_long ips_noroute; /* packets discarded due to no route */
321 u_long ips_badvers; /* ip version != 4 */
322 u_long ips_rawout; /* total raw ip packets generated */
323 u_long ips_unaligned; /* times the ip packet was not aligned */
324};
325
326
327#endif
Note: See TracBrowser for help on using the repository browser.

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