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 | # ifndef RT_OS_WINDOWS
|
---|
42 | # include <sys/queue.h>
|
---|
43 | # else
|
---|
44 | /* XXX: Windows has own queue types declared in winnt.h (should look at them once again) */
|
---|
45 | # endif
|
---|
46 | #endif
|
---|
47 |
|
---|
48 | #ifdef WORDS_BIGENDIAN
|
---|
49 | # ifndef NTOHL
|
---|
50 | # define NTOHL(d)
|
---|
51 | # endif
|
---|
52 | # ifndef NTOHS
|
---|
53 | # define NTOHS(d)
|
---|
54 | # endif
|
---|
55 | # ifndef HTONL
|
---|
56 | # define HTONL(d)
|
---|
57 | # endif
|
---|
58 | # ifndef HTONS
|
---|
59 | # define HTONS(d)
|
---|
60 | # endif
|
---|
61 | #else
|
---|
62 | # ifndef NTOHL
|
---|
63 | # define NTOHL(d) ((d) = ntohl((d)))
|
---|
64 | # endif
|
---|
65 | # ifndef NTOHS
|
---|
66 | # define NTOHS(d) ((d) = ntohs((u_int16_t)(d)))
|
---|
67 | # endif
|
---|
68 | # ifndef HTONL
|
---|
69 | # define HTONL(d) ((d) = htonl((d)))
|
---|
70 | # endif
|
---|
71 | # ifndef HTONS
|
---|
72 | # define HTONS(d) ((d) = htons((u_int16_t)(d)))
|
---|
73 | # endif
|
---|
74 | #endif
|
---|
75 |
|
---|
76 | typedef u_int32_t n_long; /* long as received from the net */
|
---|
77 |
|
---|
78 | /*
|
---|
79 | * Definitions for internet protocol version 4.
|
---|
80 | * Per RFC 791, September 1981.
|
---|
81 | */
|
---|
82 | #define IPVERSION 4
|
---|
83 |
|
---|
84 | /*
|
---|
85 | * Structure of an internet header, naked of options.
|
---|
86 | */
|
---|
87 | struct ip {
|
---|
88 | /*
|
---|
89 | * bitfield types must be u_int8_t for MSVC, otherwise it will use a full dword (for u_int)
|
---|
90 | */
|
---|
91 | #ifdef WORDS_BIGENDIAN
|
---|
92 | u_int ip_v:4, /* version */
|
---|
93 | ip_hl:4; /* header length */
|
---|
94 | #else
|
---|
95 | #ifdef _MSC_VER
|
---|
96 | u_int8_t ip_hl:4, /* header length */
|
---|
97 | #else
|
---|
98 | u_int ip_hl:4, /* header length */
|
---|
99 | #endif
|
---|
100 | ip_v:4; /* version */
|
---|
101 | #endif
|
---|
102 | u_int8_t ip_tos; /* type of service */
|
---|
103 | u_int16_t ip_len; /* total length */
|
---|
104 | u_int16_t ip_id; /* identification */
|
---|
105 | u_int16_t ip_off; /* fragment offset field */
|
---|
106 | #define IP_DF 0x4000 /* don't fragment flag */
|
---|
107 | #define IP_MF 0x2000 /* more fragments flag */
|
---|
108 | #define IP_OFFMASK 0x1fff /* mask for fragmenting bits */
|
---|
109 | u_int8_t ip_ttl; /* time to live */
|
---|
110 | u_int8_t ip_p; /* protocol */
|
---|
111 | u_int16_t ip_sum; /* checksum */
|
---|
112 | struct in_addr ip_src,ip_dst; /* source and dest address */
|
---|
113 | };
|
---|
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 | u_int8_t ipt_code; /* IPOPT_TS */
|
---|
159 | u_int8_t ipt_len; /* size of structure (variable) */
|
---|
160 | u_int8_t ipt_ptr; /* index of current entry */
|
---|
161 | /*
|
---|
162 | * bitfield types must be u_int8_t for MSVC, otherwise it will use a full dword (for u_int)
|
---|
163 | */
|
---|
164 | #ifdef WORDS_BIGENDIAN
|
---|
165 | u_int ipt_oflw:4, /* overflow counter */
|
---|
166 | ipt_flg:4; /* flags, see below */
|
---|
167 | #else
|
---|
168 | #ifdef _MSC_VER
|
---|
169 | u_int8_t ipt_flg:4, /* flags, see below */
|
---|
170 | #else
|
---|
171 | u_int ipt_flg:4, /* flags, see below */
|
---|
172 | #endif
|
---|
173 | ipt_oflw:4; /* overflow counter */
|
---|
174 | #endif
|
---|
175 | union ipt_timestamp {
|
---|
176 | n_long ipt_time[1];
|
---|
177 | struct ipt_ta {
|
---|
178 | struct in_addr ipt_addr;
|
---|
179 | n_long ipt_time;
|
---|
180 | } ipt_ta[1];
|
---|
181 | } ipt_timestamp;
|
---|
182 | };
|
---|
183 |
|
---|
184 | /* flag bits for ipt_flg */
|
---|
185 | #define IPOPT_TS_TSONLY 0 /* timestamps only */
|
---|
186 | #define IPOPT_TS_TSANDADDR 1 /* timestamps and addresses */
|
---|
187 | #define IPOPT_TS_PRESPEC 3 /* specified modules only */
|
---|
188 |
|
---|
189 | /* bits for security (not byte swapped) */
|
---|
190 | #define IPOPT_SECUR_UNCLASS 0x0000
|
---|
191 | #define IPOPT_SECUR_CONFID 0xf135
|
---|
192 | #define IPOPT_SECUR_EFTO 0x789a
|
---|
193 | #define IPOPT_SECUR_MMMM 0xbc4d
|
---|
194 | #define IPOPT_SECUR_RESTR 0xaf13
|
---|
195 | #define IPOPT_SECUR_SECRET 0xd788
|
---|
196 | #define IPOPT_SECUR_TOPSECRET 0x6bc5
|
---|
197 |
|
---|
198 | /*
|
---|
199 | * Internet implementation parameters.
|
---|
200 | */
|
---|
201 | #define MAXTTL 255 /* maximum time to live (seconds) */
|
---|
202 | #define IPDEFTTL 64 /* default ttl, from RFC 1340 */
|
---|
203 | #define IPFRAGTTL 60 /* time to live for frags, slowhz */
|
---|
204 | #define IPTTLDEC 1 /* subtracted when forwarding */
|
---|
205 |
|
---|
206 | #define IP_MSS 576 /* default maximum segment size */
|
---|
207 |
|
---|
208 | #ifdef HAVE_SYS_TYPES32_H /* Overcome some Solaris 2.x junk */
|
---|
209 | #include <sys/types32.h>
|
---|
210 | #else
|
---|
211 | #if SIZEOF_CHAR_P == 4
|
---|
212 | typedef caddr_t caddr32_t;
|
---|
213 | #else
|
---|
214 | typedef u_int32_t caddr32_t;
|
---|
215 | #endif
|
---|
216 | #endif
|
---|
217 |
|
---|
218 | #if SIZEOF_CHAR_P == 4
|
---|
219 | typedef struct ipq_t *ipqp_32;
|
---|
220 | typedef struct ipasfrag *ipasfragp_32;
|
---|
221 | #else
|
---|
222 | typedef caddr32_t ipqp_32;
|
---|
223 | typedef caddr32_t ipasfragp_32;
|
---|
224 | #endif
|
---|
225 |
|
---|
226 | /*
|
---|
227 | * Overlay for ip header used by other protocols (tcp, udp).
|
---|
228 | */
|
---|
229 | struct ipovly {
|
---|
230 | caddr32_t ih_next, ih_prev; /* for protocol sequence q's */
|
---|
231 | u_int8_t ih_x1; /* (unused) */
|
---|
232 | u_int8_t ih_pr; /* protocol */
|
---|
233 | u_int16_t ih_len; /* protocol length */
|
---|
234 | struct in_addr ih_src; /* source internet address */
|
---|
235 | struct in_addr ih_dst; /* destination internet address */
|
---|
236 | };
|
---|
237 |
|
---|
238 | /*
|
---|
239 | * Ip reassembly queue structure. Each fragment
|
---|
240 | * being reassembled is attached to one of these structures.
|
---|
241 | * They are timed out after ipq_ttl drops to 0, and may also
|
---|
242 | * be reclaimed if memory becomes tight.
|
---|
243 | * size 28 bytes
|
---|
244 | */
|
---|
245 | struct ipq_t {
|
---|
246 | #ifndef VBOX_WITH_BSD_REASS
|
---|
247 | ipqp_32 next,prev; /* to other reass headers */
|
---|
248 | #else /* VBOX_WITH_BSD_REASS */
|
---|
249 | TAILQ_ENTRY(ipq_t) ipq_list;
|
---|
250 | #endif /* VBOX_WITH_BSD_REASS */
|
---|
251 | u_int8_t ipq_ttl; /* time for reass q to live */
|
---|
252 | u_int8_t ipq_p; /* protocol of this fragment */
|
---|
253 | u_int16_t ipq_id; /* sequence id for reassembly */
|
---|
254 | #ifndef VBOX_WITH_BSD_REASS
|
---|
255 | ipasfragp_32 ipq_next,ipq_prev; /* to ip headers of fragments */
|
---|
256 | #else /* VBOX_WITH_BSD_REASS */
|
---|
257 | u_int8_t ipq_nfrags; /* # of fragments in this packet */
|
---|
258 | struct mbuf *ipq_frags; /* to ip headers of fragments */
|
---|
259 | #endif /* VBOX_WITH_BSD_REASS */
|
---|
260 |
|
---|
261 | struct in_addr ipq_src,ipq_dst;
|
---|
262 | };
|
---|
263 |
|
---|
264 | #ifdef VBOX_WITH_BSD_REASS
|
---|
265 | /*
|
---|
266 | * IP datagram reassembly.
|
---|
267 | */
|
---|
268 | #define IPREASS_NHASH_LOG2 6
|
---|
269 | #define IPREASS_NHASH (1 << IPREASS_NHASH_LOG2)
|
---|
270 | #define IPREASS_HMASK (IPREASS_NHASH - 1)
|
---|
271 | #define IPREASS_HASH(x,y) \
|
---|
272 | (((((x) & 0xF) | ((((x) >> 8) & 0xF) << 4)) ^ (y)) & IPREASS_HMASK)
|
---|
273 | TAILQ_HEAD(ipqhead,ipq_t);
|
---|
274 | #endif /* VBOX_WITH_BSD_REASS */
|
---|
275 |
|
---|
276 | /*
|
---|
277 | * Ip header, when holding a fragment.
|
---|
278 | *
|
---|
279 | * Note: ipf_next must be at same offset as ipq_next above
|
---|
280 | */
|
---|
281 | struct ipasfrag {
|
---|
282 | #ifdef WORDS_BIGENDIAN
|
---|
283 | u_int ip_v:4,
|
---|
284 | ip_hl:4;
|
---|
285 | #else
|
---|
286 | #ifdef _MSC_VER
|
---|
287 | u_int8_t ip_hl:4,
|
---|
288 | #else
|
---|
289 | u_int ip_hl:4,
|
---|
290 | #endif
|
---|
291 | ip_v:4;
|
---|
292 | #endif
|
---|
293 | /* BUG : u_int changed to u_int8_t.
|
---|
294 | * sizeof(u_int)==4 on linux 2.0
|
---|
295 | */
|
---|
296 | u_int8_t ipf_mff; /* XXX overlays ip_tos: use low bit
|
---|
297 | * to avoid destroying tos (PPPDTRuu);
|
---|
298 | * copied from (ip_off&IP_MF) */
|
---|
299 | u_int16_t ip_len;
|
---|
300 | u_int16_t ip_id;
|
---|
301 | u_int16_t ip_off;
|
---|
302 | u_int8_t ip_ttl;
|
---|
303 | u_int8_t ip_p;
|
---|
304 | u_int16_t ip_sum;
|
---|
305 | ipasfragp_32 ipf_next; /* next fragment */
|
---|
306 | ipasfragp_32 ipf_prev; /* previous fragment */
|
---|
307 | };
|
---|
308 |
|
---|
309 | /*
|
---|
310 | * Structure stored in mbuf in inpcb.ip_options
|
---|
311 | * and passed to ip_output when ip options are in use.
|
---|
312 | * The actual length of the options (including ipopt_dst)
|
---|
313 | * is in m_len.
|
---|
314 | */
|
---|
315 | #define MAX_IPOPTLEN 40
|
---|
316 |
|
---|
317 | struct ipoption {
|
---|
318 | struct in_addr ipopt_dst; /* first-hop dst if source routed */
|
---|
319 | int8_t ipopt_list[MAX_IPOPTLEN]; /* options proper */
|
---|
320 | };
|
---|
321 |
|
---|
322 | /*
|
---|
323 | * Structure attached to inpcb.ip_moptions and
|
---|
324 | * passed to ip_output when IP multicast options are in use.
|
---|
325 | */
|
---|
326 |
|
---|
327 | struct ipstat_t {
|
---|
328 | u_long ips_total; /* total packets received */
|
---|
329 | u_long ips_badsum; /* checksum bad */
|
---|
330 | u_long ips_tooshort; /* packet too short */
|
---|
331 | u_long ips_toosmall; /* not enough data */
|
---|
332 | u_long ips_badhlen; /* ip header length < data size */
|
---|
333 | u_long ips_badlen; /* ip length < ip header length */
|
---|
334 | u_long ips_fragments; /* fragments received */
|
---|
335 | u_long ips_fragdropped; /* frags dropped (dups, out of space) */
|
---|
336 | u_long ips_fragtimeout; /* fragments timed out */
|
---|
337 | u_long ips_forward; /* packets forwarded */
|
---|
338 | u_long ips_cantforward; /* packets rcvd for unreachable dest */
|
---|
339 | u_long ips_redirectsent; /* packets forwarded on same net */
|
---|
340 | u_long ips_noproto; /* unknown or unsupported protocol */
|
---|
341 | u_long ips_delivered; /* datagrams delivered to upper level*/
|
---|
342 | u_long ips_localout; /* total ip packets generated here */
|
---|
343 | u_long ips_odropped; /* lost packets due to nobufs, etc. */
|
---|
344 | u_long ips_reassembled; /* total packets reassembled ok */
|
---|
345 | u_long ips_fragmented; /* datagrams successfully fragmented */
|
---|
346 | u_long ips_ofragments; /* output fragments created */
|
---|
347 | u_long ips_cantfrag; /* don't fragment flag was set, etc. */
|
---|
348 | u_long ips_badoptions; /* error in option processing */
|
---|
349 | u_long ips_noroute; /* packets discarded due to no route */
|
---|
350 | u_long ips_badvers; /* ip version != 4 */
|
---|
351 | u_long ips_rawout; /* total raw ip packets generated */
|
---|
352 | u_long ips_unaligned; /* times the ip packet was not aligned */
|
---|
353 | };
|
---|
354 |
|
---|
355 |
|
---|
356 | #endif
|
---|