VirtualBox

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

Last change on this file was 98103, checked in by vboxsync, 16 months ago

Copyright year updates by scm.

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

© 2023 Oracle
ContactPrivacy policyTerms of Use