VirtualBox

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

Last change on this file since 95573 was 95573, checked in by vboxsync, 2 years ago

Network/slirp: Advertising clause for Danny Gasparovsky was unintentional, should have always been 3-clause BSD. Replace 4-clause BSD license by 3-clause, see retroactive license change by UC Berkeley https://www.freebsd.org/copyright/license/

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