ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/slirp/ip.h
Revision: 1.4
Committed: 2007-11-03T11:11:42Z (16 years, 8 months ago) by gbeauche
Content type: text/plain
Branch: MAIN
Changes since 1.3: +5 -9 lines
Log Message:
Update to slirp sources from QEMU 0.8.2:
- set slirp client hostname
- fix slirp redirection on systems without a useful host IP address
- separate alias_addr (10.0.2.2) from our_addr (Ed Swierk)
- fix 32+ KB packets handling (Ed Swierk)
- fix UDP broadcast translation error
- solaris port (Ben Taylor)

File Contents

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