VirtualBox

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

Last change on this file since 28449 was 28449, checked in by vboxsync, 15 years ago

NAT: slirp file headers

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.8 KB
Line 
1/* $Id: ip.h 28449 2010-04-19 09:52:59Z vboxsync $ */
2/** @file
3 * NAT - IP handling (declarations/defines).
4 */
5
6/*
7 * Copyright (C) 2006-2010 Sun Microsystems, Inc.
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
18 * Clara, CA 95054 USA or visit http://www.sun.com if you need
19 * additional information or have any questions.
20 */
21
22/*
23 * This code is based on:
24 *
25 * Copyright (c) 1982, 1986, 1993
26 * The Regents of the University of California. All rights reserved.
27 *
28 * Redistribution and use in source and binary forms, with or without
29 * modification, are permitted provided that the following conditions
30 * are met:
31 * 1. Redistributions of source code must retain the above copyright
32 * notice, this list of conditions and the following disclaimer.
33 * 2. Redistributions in binary form must reproduce the above copyright
34 * notice, this list of conditions and the following disclaimer in the
35 * documentation and/or other materials provided with the distribution.
36 * 3. All advertising materials mentioning features or use of this software
37 * must display the following acknowledgement:
38 * This product includes software developed by the University of
39 * California, Berkeley and its contributors.
40 * 4. Neither the name of the University nor the names of its contributors
41 * may be used to endorse or promote products derived from this software
42 * without specific prior written permission.
43 *
44 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
45 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
46 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
47 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
48 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
49 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
50 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
51 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
52 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
53 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
54 * SUCH DAMAGE.
55 *
56 * @(#)ip.h 8.1 (Berkeley) 6/10/93
57 * ip.h,v 1.3 1994/08/21 05:27:30 paul Exp
58 */
59
60#ifndef _IP_H_
61#define _IP_H_
62
63#include "queue.h"
64
65#ifdef WORDS_BIGENDIAN
66# ifndef NTOHL
67# define NTOHL(d)
68# endif
69# ifndef NTOHS
70# define NTOHS(d)
71# endif
72# ifndef HTONL
73# define HTONL(d)
74# endif
75# ifndef HTONS
76# define HTONS(d)
77# endif
78#else
79# ifndef NTOHL
80# define NTOHL(d) ((d) = RT_N2H_U32((d)))
81# endif
82# ifndef NTOHS
83# define NTOHS(d) ((d) = RT_N2H_U16((u_int16_t)(d)))
84# endif
85# ifndef HTONL
86# define HTONL(d) ((d) = RT_H2N_U32((d)))
87# endif
88# ifndef HTONS
89# define HTONS(d) ((d) = RT_H2N_U16((u_int16_t)(d)))
90# endif
91#endif
92
93/*
94 * Definitions for internet protocol version 4.
95 * Per RFC 791, September 1981.
96 */
97#define IPVERSION 4
98
99/*
100 * Structure of an internet header, naked of options.
101 */
102struct ip
103{
104#ifdef WORDS_BIGENDIAN
105# ifdef _MSC_VER
106 uint8_t ip_v:4; /* version */
107 uint8_t ip_hl:4; /* header length */
108# else
109 unsigned ip_v:4; /* version */
110 unsigned ip_hl:4; /* header length */
111# endif
112#else
113# ifdef _MSC_VER
114 uint8_t ip_hl:4; /* header length */
115 uint8_t ip_v:4; /* version */
116# else
117 unsigned ip_hl:4; /* header length */
118 unsigned ip_v:4; /* version */
119# endif
120#endif
121 uint8_t ip_tos; /* type of service */
122 uint16_t ip_len; /* total length */
123 uint16_t ip_id; /* identification */
124 uint16_t ip_off; /* fragment offset field */
125#define IP_DF 0x4000 /* don't fragment flag */
126#define IP_MF 0x2000 /* more fragments flag */
127#define IP_OFFMASK 0x1fff /* mask for fragmenting bits */
128 uint8_t ip_ttl; /* time to live */
129 uint8_t ip_p; /* protocol */
130 uint16_t ip_sum; /* checksum */
131 struct in_addr ip_src; /* source address */
132 struct in_addr ip_dst; /* destination address */
133};
134AssertCompileSize(struct ip, 20);
135
136#define IP_MAXPACKET 65535 /* maximum packet size */
137
138/*
139 * Definitions for IP type of service (ip_tos)
140 */
141#define IPTOS_LOWDELAY 0x10
142#define IPTOS_THROUGHPUT 0x08
143#define IPTOS_RELIABILITY 0x04
144
145
146/*
147 * Time stamp option structure.
148 */
149struct ip_timestamp
150{
151 uint8_t ipt_code; /* IPOPT_TS */
152 uint8_t ipt_len; /* size of structure (variable) */
153 uint8_t ipt_ptr; /* index of current entry */
154#ifdef WORDS_BIGENDIAN
155# ifdef _MSC_VER
156 uint8_t ipt_oflw:4; /* overflow counter */
157 uint8_t ipt_flg:4; /* flags, see below */
158# else
159 unsigned ipt_oflw:4; /* overflow counter */
160 unsigned ipt_flg:4; /* flags, see below */
161# endif
162#else
163# ifdef _MSC_VER
164 uint8_t ipt_flg:4; /* flags, see below */
165 uint8_t ipt_oflw:4; /* overflow counter */
166# else
167 unsigned ipt_flg:4; /* flags, see below */
168 unsigned ipt_oflw:4; /* overflow counter */
169# endif
170#endif
171 union ipt_timestamp
172 {
173 uint32_t ipt_time[1];
174 struct ipt_ta
175 {
176 struct in_addr ipt_addr;
177 uint32_t ipt_time;
178 } ipt_ta[1];
179 } ipt_timestamp;
180};
181AssertCompileSize(struct ip_timestamp, 12);
182
183/*
184 * Internet implementation parameters.
185 */
186#define MAXTTL 255 /* maximum time to live (seconds) */
187#define IPDEFTTL 64 /* default ttl, from RFC 1340 */
188#define IPFRAGTTL 60 /* time to live for frags, slowhz */
189#define IPTTLDEC 1 /* subtracted when forwarding */
190
191#define IP_MSS 576 /* default maximum segment size */
192
193#ifdef HAVE_SYS_TYPES32_H /* Overcome some Solaris 2.x junk */
194# include <sys/types32.h>
195#else
196typedef caddr_t caddr32_t;
197#endif
198
199#if SIZEOF_CHAR_P == 4
200typedef struct ipq_t *ipqp_32;
201typedef struct ipasfrag *ipasfragp_32;
202#else
203typedef caddr32_t ipqp_32;
204typedef caddr32_t ipasfragp_32;
205#endif
206
207/*
208 * Overlay for ip header used by other protocols (tcp, udp).
209 */
210struct ipovly
211{
212 u_int8_t ih_x1[9]; /* (unused) */
213 u_int8_t ih_pr; /* protocol */
214 u_int16_t ih_len; /* protocol length */
215 struct in_addr ih_src; /* source internet address */
216 struct in_addr ih_dst; /* destination internet address */
217};
218AssertCompileSize(struct ipovly, 20);
219
220/*
221 * Ip reassembly queue structure. Each fragment being reassembled is
222 * attached to one of these structures. They are timed out after ipq_ttl
223 * drops to 0, and may also be reclaimed if memory becomes tight.
224 * size 28 bytes
225 */
226struct ipq_t
227{
228 TAILQ_ENTRY(ipq_t) ipq_list;
229 u_int8_t ipq_ttl; /* time for reass q to live */
230 u_int8_t ipq_p; /* protocol of this fragment */
231 u_int16_t ipq_id; /* sequence id for reassembly */
232 struct mbuf *ipq_frags; /* to ip headers of fragments */
233 uint8_t ipq_nfrags; /* # of fragments in this packet */
234 struct in_addr ipq_src;
235 struct in_addr ipq_dst;
236};
237
238
239/*
240* IP datagram reassembly.
241*/
242#define IPREASS_NHASH_LOG2 6
243#define IPREASS_NHASH (1 << IPREASS_NHASH_LOG2)
244#define IPREASS_HMASK (IPREASS_NHASH - 1)
245#define IPREASS_HASH(x,y) \
246(((((x) & 0xF) | ((((x) >> 8) & 0xF) << 4)) ^ (y)) & IPREASS_HMASK)
247TAILQ_HEAD(ipqhead, ipq_t);
248
249/*
250 * Structure attached to inpcb.ip_moptions and
251 * passed to ip_output when IP multicast options are in use.
252 */
253
254struct ipstat_t
255{
256 u_long ips_total; /* total packets received */
257 u_long ips_badsum; /* checksum bad */
258 u_long ips_tooshort; /* packet too short */
259 u_long ips_toosmall; /* not enough data */
260 u_long ips_badhlen; /* ip header length < data size */
261 u_long ips_badlen; /* ip length < ip header length */
262 u_long ips_fragments; /* fragments received */
263 u_long ips_fragdropped; /* frags dropped (dups, out of space) */
264 u_long ips_fragtimeout; /* fragments timed out */
265 u_long ips_forward; /* packets forwarded */
266 u_long ips_cantforward; /* packets rcvd for unreachable dest */
267 u_long ips_redirectsent; /* packets forwarded on same net */
268 u_long ips_noproto; /* unknown or unsupported protocol */
269 u_long ips_delivered; /* datagrams delivered to upper level*/
270 u_long ips_localout; /* total ip packets generated here */
271 u_long ips_odropped; /* lost packets due to nobufs, etc. */
272 u_long ips_reassembled; /* total packets reassembled ok */
273 u_long ips_fragmented; /* datagrams successfully fragmented */
274 u_long ips_ofragments; /* output fragments created */
275 u_long ips_cantfrag; /* don't fragment flag was set, etc. */
276 u_long ips_badoptions; /* error in option processing */
277 u_long ips_noroute; /* packets discarded due to no route */
278 u_long ips_badvers; /* ip version != 4 */
279 u_long ips_rawout; /* total raw ip packets generated */
280 u_long ips_unaligned; /* times the ip packet was not aligned */
281};
282
283#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