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 VBOX_WITH_BSD_REASS
|
---|
41 | # include "queue.h"
|
---|
42 | #endif
|
---|
43 |
|
---|
44 | #ifdef WORDS_BIGENDIAN
|
---|
45 | # ifndef NTOHL
|
---|
46 | # define NTOHL(d)
|
---|
47 | # endif
|
---|
48 | # ifndef NTOHS
|
---|
49 | # define NTOHS(d)
|
---|
50 | # endif
|
---|
51 | # ifndef HTONL
|
---|
52 | # define HTONL(d)
|
---|
53 | # endif
|
---|
54 | # ifndef HTONS
|
---|
55 | # define HTONS(d)
|
---|
56 | # endif
|
---|
57 | #else
|
---|
58 | # ifndef NTOHL
|
---|
59 | # define NTOHL(d) ((d) = ntohl((d)))
|
---|
60 | # endif
|
---|
61 | # ifndef NTOHS
|
---|
62 | # define NTOHS(d) ((d) = ntohs((u_int16_t)(d)))
|
---|
63 | # endif
|
---|
64 | # ifndef HTONL
|
---|
65 | # define HTONL(d) ((d) = htonl((d)))
|
---|
66 | # endif
|
---|
67 | # ifndef HTONS
|
---|
68 | # define HTONS(d) ((d) = htons((u_int16_t)(d)))
|
---|
69 | # endif
|
---|
70 | #endif
|
---|
71 |
|
---|
72 | /*
|
---|
73 | * Definitions for internet protocol version 4.
|
---|
74 | * Per RFC 791, September 1981.
|
---|
75 | */
|
---|
76 | #define IPVERSION 4
|
---|
77 |
|
---|
78 | /*
|
---|
79 | * Structure of an internet header, naked of options.
|
---|
80 | */
|
---|
81 | struct ip
|
---|
82 | {
|
---|
83 | #ifdef WORDS_BIGENDIAN
|
---|
84 | # ifdef _MSC_VER
|
---|
85 | uint8_t ip_v:4; /* version */
|
---|
86 | uint8_t ip_hl:4; /* header length */
|
---|
87 | # else
|
---|
88 | unsigned ip_v:4; /* version */
|
---|
89 | unsigned ip_hl:4; /* header length */
|
---|
90 | # endif
|
---|
91 | #else
|
---|
92 | # ifdef _MSC_VER
|
---|
93 | uint8_t ip_hl:4; /* header length */
|
---|
94 | uint8_t ip_v:4; /* version */
|
---|
95 | # else
|
---|
96 | unsigned ip_hl:4; /* header length */
|
---|
97 | unsigned ip_v:4; /* version */
|
---|
98 | # endif
|
---|
99 | #endif
|
---|
100 | uint8_t ip_tos; /* type of service */
|
---|
101 | uint16_t ip_len; /* total length */
|
---|
102 | uint16_t ip_id; /* identification */
|
---|
103 | uint16_t ip_off; /* fragment offset field */
|
---|
104 | #define IP_DF 0x4000 /* don't fragment flag */
|
---|
105 | #define IP_MF 0x2000 /* more fragments flag */
|
---|
106 | #define IP_OFFMASK 0x1fff /* mask for fragmenting bits */
|
---|
107 | uint8_t ip_ttl; /* time to live */
|
---|
108 | uint8_t ip_p; /* protocol */
|
---|
109 | uint16_t ip_sum; /* checksum */
|
---|
110 | struct in_addr ip_src; /* source address */
|
---|
111 | struct in_addr ip_dst; /* destination address */
|
---|
112 | };
|
---|
113 | AssertCompileSize(struct ip, 20);
|
---|
114 |
|
---|
115 | #define IP_MAXPACKET 65535 /* maximum packet size */
|
---|
116 |
|
---|
117 | /*
|
---|
118 | * Definitions for IP type of service (ip_tos)
|
---|
119 | */
|
---|
120 | #define IPTOS_LOWDELAY 0x10
|
---|
121 | #define IPTOS_THROUGHPUT 0x08
|
---|
122 | #define IPTOS_RELIABILITY 0x04
|
---|
123 |
|
---|
124 | /*
|
---|
125 | * Definitions for options.
|
---|
126 | */
|
---|
127 | #define IPOPT_COPIED(o) ((o)&0x80)
|
---|
128 | #define IPOPT_CLASS(o) ((o)&0x60)
|
---|
129 | #define IPOPT_NUMBER(o) ((o)&0x1f)
|
---|
130 |
|
---|
131 | #define IPOPT_CONTROL 0x00
|
---|
132 | #define IPOPT_RESERVED1 0x20
|
---|
133 | #define IPOPT_DEBMEAS 0x40
|
---|
134 | #define IPOPT_RESERVED2 0x60
|
---|
135 |
|
---|
136 | #define IPOPT_EOL 0 /* end of option list */
|
---|
137 | #define IPOPT_NOP 1 /* no operation */
|
---|
138 |
|
---|
139 | #define IPOPT_RR 7 /* record packet route */
|
---|
140 | #define IPOPT_TS 68 /* timestamp */
|
---|
141 | #define IPOPT_SECURITY 130 /* provide s,c,h,tcc */
|
---|
142 | #define IPOPT_LSRR 131 /* loose source route */
|
---|
143 | #define IPOPT_SATID 136 /* satnet id */
|
---|
144 | #define IPOPT_SSRR 137 /* strict source route */
|
---|
145 |
|
---|
146 | /*
|
---|
147 | * Offsets to fields in options other than EOL and NOP.
|
---|
148 | */
|
---|
149 | #define IPOPT_OPTVAL 0 /* option ID */
|
---|
150 | #define IPOPT_OLEN 1 /* option length */
|
---|
151 | #define IPOPT_OFFSET 2 /* offset within option */
|
---|
152 | #define IPOPT_MINOFF 4 /* min value of above */
|
---|
153 |
|
---|
154 | /*
|
---|
155 | * Time stamp option structure.
|
---|
156 | */
|
---|
157 | struct ip_timestamp
|
---|
158 | {
|
---|
159 | uint8_t ipt_code; /* IPOPT_TS */
|
---|
160 | uint8_t ipt_len; /* size of structure (variable) */
|
---|
161 | uint8_t ipt_ptr; /* index of current entry */
|
---|
162 | #ifdef WORDS_BIGENDIAN
|
---|
163 | # ifdef _MSC_VER
|
---|
164 | uint8_t ipt_oflw:4; /* overflow counter */
|
---|
165 | uint8_t ipt_flg:4; /* flags, see below */
|
---|
166 | # else
|
---|
167 | unsigned ipt_oflw:4; /* overflow counter */
|
---|
168 | unsigned ipt_flg:4; /* flags, see below */
|
---|
169 | # endif
|
---|
170 | #else
|
---|
171 | # ifdef _MSC_VER
|
---|
172 | uint8_t ipt_flg:4; /* flags, see below */
|
---|
173 | uint8_t ipt_oflw:4; /* overflow counter */
|
---|
174 | # else
|
---|
175 | unsigned ipt_flg:4; /* flags, see below */
|
---|
176 | unsigned ipt_oflw:4; /* overflow counter */
|
---|
177 | # endif
|
---|
178 | #endif
|
---|
179 | union ipt_timestamp
|
---|
180 | {
|
---|
181 | uint32_t ipt_time[1];
|
---|
182 | struct ipt_ta
|
---|
183 | {
|
---|
184 | struct in_addr ipt_addr;
|
---|
185 | uint32_t ipt_time;
|
---|
186 | } ipt_ta[1];
|
---|
187 | } ipt_timestamp;
|
---|
188 | };
|
---|
189 | AssertCompileSize(struct ip_timestamp, 12);
|
---|
190 |
|
---|
191 | /* flag bits for ipt_flg */
|
---|
192 | #define IPOPT_TS_TSONLY 0 /* timestamps only */
|
---|
193 | #define IPOPT_TS_TSANDADDR 1 /* timestamps and addresses */
|
---|
194 | #define IPOPT_TS_PRESPEC 3 /* specified modules only */
|
---|
195 |
|
---|
196 | /* bits for security (not byte swapped) */
|
---|
197 | #define IPOPT_SECUR_UNCLASS 0x0000
|
---|
198 | #define IPOPT_SECUR_CONFID 0xf135
|
---|
199 | #define IPOPT_SECUR_EFTO 0x789a
|
---|
200 | #define IPOPT_SECUR_MMMM 0xbc4d
|
---|
201 | #define IPOPT_SECUR_RESTR 0xaf13
|
---|
202 | #define IPOPT_SECUR_SECRET 0xd788
|
---|
203 | #define IPOPT_SECUR_TOPSECRET 0x6bc5
|
---|
204 |
|
---|
205 | /*
|
---|
206 | * Internet implementation parameters.
|
---|
207 | */
|
---|
208 | #define MAXTTL 255 /* maximum time to live (seconds) */
|
---|
209 | #define IPDEFTTL 64 /* default ttl, from RFC 1340 */
|
---|
210 | #define IPFRAGTTL 60 /* time to live for frags, slowhz */
|
---|
211 | #define IPTTLDEC 1 /* subtracted when forwarding */
|
---|
212 |
|
---|
213 | #define IP_MSS 576 /* default maximum segment size */
|
---|
214 |
|
---|
215 | #ifdef HAVE_SYS_TYPES32_H /* Overcome some Solaris 2.x junk */
|
---|
216 | # include <sys/types32.h>
|
---|
217 | #else
|
---|
218 | # if SIZEOF_CHAR_P == 4
|
---|
219 | typedef caddr_t caddr32_t;
|
---|
220 | # else
|
---|
221 | # if !defined(VBOX_WITH_BSD_REASS)
|
---|
222 | typedef u_int32_t caddr32_t;
|
---|
223 | # else /* VBOX_WITH_BSD_REASS */
|
---|
224 | typedef caddr_t caddr32_t;
|
---|
225 | # endif /* VBOX_WITH_BSD_REASS */
|
---|
226 | # endif
|
---|
227 | #endif
|
---|
228 |
|
---|
229 | #if SIZEOF_CHAR_P == 4
|
---|
230 | typedef struct ipq_t *ipqp_32;
|
---|
231 | typedef struct ipasfrag *ipasfragp_32;
|
---|
232 | #else
|
---|
233 | typedef caddr32_t ipqp_32;
|
---|
234 | typedef caddr32_t ipasfragp_32;
|
---|
235 | #endif
|
---|
236 |
|
---|
237 | /*
|
---|
238 | * Overlay for ip header used by other protocols (tcp, udp).
|
---|
239 | */
|
---|
240 | struct ipovly
|
---|
241 | {
|
---|
242 | #if !defined(VBOX_WITH_BSD_REASS)
|
---|
243 | caddr32_t ih_next;
|
---|
244 | caddr32_t ih_prev; /* for protocol sequence q's */
|
---|
245 | u_int8_t ih_x1; /* (unused) */
|
---|
246 | #else /* VBOX_WITH_BSD_REASS */
|
---|
247 | u_int8_t ih_x1[9]; /* (unused) */
|
---|
248 | #endif /* VBOX_WITH_BSD_REASS */
|
---|
249 | u_int8_t ih_pr; /* protocol */
|
---|
250 | u_int16_t ih_len; /* protocol length */
|
---|
251 | struct in_addr ih_src; /* source internet address */
|
---|
252 | struct in_addr ih_dst; /* destination internet address */
|
---|
253 | };
|
---|
254 | AssertCompileSize(struct ipovly, 20);
|
---|
255 |
|
---|
256 | /*
|
---|
257 | * Ip reassembly queue structure. Each fragment being reassembled is
|
---|
258 | * attached to one of these structures. They are timed out after ipq_ttl
|
---|
259 | * drops to 0, and may also be reclaimed if memory becomes tight.
|
---|
260 | * size 28 bytes
|
---|
261 | */
|
---|
262 | struct ipq_t
|
---|
263 | {
|
---|
264 | #ifndef VBOX_WITH_BSD_REASS
|
---|
265 | ipqp_32 next;
|
---|
266 | ipqp_32 prev; /* to other reass headers */
|
---|
267 | #else /* VBOX_WITH_BSD_REASS */
|
---|
268 | TAILQ_ENTRY(ipq_t) ipq_list;
|
---|
269 | #endif /* VBOX_WITH_BSD_REASS */
|
---|
270 | u_int8_t ipq_ttl; /* time for reass q to live */
|
---|
271 | u_int8_t ipq_p; /* protocol of this fragment */
|
---|
272 | u_int16_t ipq_id; /* sequence id for reassembly */
|
---|
273 | #ifndef VBOX_WITH_BSD_REASS
|
---|
274 | ipasfragp_32 ipq_next;
|
---|
275 | ipasfragp_32 ipq_prev; /* to ip headers of fragments */
|
---|
276 | #else /* VBOX_WITH_BSD_REASS */
|
---|
277 | struct mbuf *ipq_frags; /* to ip headers of fragments */
|
---|
278 | uint8_t ipq_nfrags; /* # of fragments in this packet */
|
---|
279 | #endif /* VBOX_WITH_BSD_REASS */
|
---|
280 | struct in_addr ipq_src;
|
---|
281 | struct in_addr ipq_dst;
|
---|
282 | };
|
---|
283 |
|
---|
284 | #ifdef VBOX_WITH_BSD_REASS
|
---|
285 | /*
|
---|
286 | * IP datagram reassembly.
|
---|
287 | */
|
---|
288 | #define IPREASS_NHASH_LOG2 6
|
---|
289 | #define IPREASS_NHASH (1 << IPREASS_NHASH_LOG2)
|
---|
290 | #define IPREASS_HMASK (IPREASS_NHASH - 1)
|
---|
291 | #define IPREASS_HASH(x,y) \
|
---|
292 | (((((x) & 0xF) | ((((x) >> 8) & 0xF) << 4)) ^ (y)) & IPREASS_HMASK)
|
---|
293 | TAILQ_HEAD(ipqhead,ipq_t);
|
---|
294 | #endif /* VBOX_WITH_BSD_REASS */
|
---|
295 |
|
---|
296 | /*
|
---|
297 | * Ip header, when holding a fragment.
|
---|
298 | *
|
---|
299 | * Note: ipf_next must be at same offset as ipq_next above
|
---|
300 | */
|
---|
301 | struct ipasfrag
|
---|
302 | {
|
---|
303 | #ifdef WORDS_BIGENDIAN
|
---|
304 | # ifdef _MSC_VER
|
---|
305 | uint8_t ip_v:4;
|
---|
306 | uint8_t ip_hl:4;
|
---|
307 | # else
|
---|
308 | unsigned ip_v:4;
|
---|
309 | unsigned ip_hl:4;
|
---|
310 | # endif
|
---|
311 | #else
|
---|
312 | # ifdef _MSC_VER
|
---|
313 | uint8_t ip_hl:4;
|
---|
314 | uint8_t ip_v:4;
|
---|
315 | # else
|
---|
316 | unsigned ip_hl:4;
|
---|
317 | unsigned ip_v:4;
|
---|
318 | # endif
|
---|
319 | #endif
|
---|
320 | u_int8_t ipf_mff; /* XXX overlays ip_tos: use low bit
|
---|
321 | * to avoid destroying tos (PPPDTRuu);
|
---|
322 | * copied from (ip_off & IP_MF) */
|
---|
323 | u_int16_t ip_len;
|
---|
324 | u_int16_t ip_id;
|
---|
325 | u_int16_t ip_off;
|
---|
326 | u_int8_t ip_ttl;
|
---|
327 | u_int8_t ip_p;
|
---|
328 | u_int16_t ip_sum;
|
---|
329 | ipasfragp_32 ipf_next; /* next fragment */
|
---|
330 | ipasfragp_32 ipf_prev; /* previous fragment */
|
---|
331 | };
|
---|
332 | #ifdef RT_ARCH_X86 || !defined(VBOX_WITH_BSD_REASS)
|
---|
333 | AssertCompileSize(struct ipasfrag, 20);
|
---|
334 | #else
|
---|
335 | AssertCompileSize(struct ipasfrag, 32);
|
---|
336 | #endif
|
---|
337 |
|
---|
338 | /*
|
---|
339 | * Structure stored in mbuf in inpcb.ip_options
|
---|
340 | * and passed to ip_output when ip options are in use.
|
---|
341 | * The actual length of the options (including ipopt_dst)
|
---|
342 | * is in m_len.
|
---|
343 | */
|
---|
344 | #define MAX_IPOPTLEN 40
|
---|
345 |
|
---|
346 | struct ipoption
|
---|
347 | {
|
---|
348 | struct in_addr ipopt_dst; /* first-hop dst if source routed */
|
---|
349 | int8_t ipopt_list[MAX_IPOPTLEN]; /* options proper */
|
---|
350 | };
|
---|
351 |
|
---|
352 | /*
|
---|
353 | * Structure attached to inpcb.ip_moptions and
|
---|
354 | * passed to ip_output when IP multicast options are in use.
|
---|
355 | */
|
---|
356 |
|
---|
357 | struct ipstat_t
|
---|
358 | {
|
---|
359 | u_long ips_total; /* total packets received */
|
---|
360 | u_long ips_badsum; /* checksum bad */
|
---|
361 | u_long ips_tooshort; /* packet too short */
|
---|
362 | u_long ips_toosmall; /* not enough data */
|
---|
363 | u_long ips_badhlen; /* ip header length < data size */
|
---|
364 | u_long ips_badlen; /* ip length < ip header length */
|
---|
365 | u_long ips_fragments; /* fragments received */
|
---|
366 | u_long ips_fragdropped; /* frags dropped (dups, out of space) */
|
---|
367 | u_long ips_fragtimeout; /* fragments timed out */
|
---|
368 | u_long ips_forward; /* packets forwarded */
|
---|
369 | u_long ips_cantforward; /* packets rcvd for unreachable dest */
|
---|
370 | u_long ips_redirectsent; /* packets forwarded on same net */
|
---|
371 | u_long ips_noproto; /* unknown or unsupported protocol */
|
---|
372 | u_long ips_delivered; /* datagrams delivered to upper level*/
|
---|
373 | u_long ips_localout; /* total ip packets generated here */
|
---|
374 | u_long ips_odropped; /* lost packets due to nobufs, etc. */
|
---|
375 | u_long ips_reassembled; /* total packets reassembled ok */
|
---|
376 | u_long ips_fragmented; /* datagrams successfully fragmented */
|
---|
377 | u_long ips_ofragments; /* output fragments created */
|
---|
378 | u_long ips_cantfrag; /* don't fragment flag was set, etc. */
|
---|
379 | u_long ips_badoptions; /* error in option processing */
|
---|
380 | u_long ips_noroute; /* packets discarded due to no route */
|
---|
381 | u_long ips_badvers; /* ip version != 4 */
|
---|
382 | u_long ips_rawout; /* total raw ip packets generated */
|
---|
383 | u_long ips_unaligned; /* times the ip packet was not aligned */
|
---|
384 | };
|
---|
385 |
|
---|
386 | #endif
|
---|