ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/slirp/ip.h
Revision: 1.3
Committed: 2006-01-27T23:31:38Z (18 years, 9 months ago) by gbeauche
Content type: text/plain
Branch: MAIN
CVS Tags: nigel-build-19
Changes since 1.2: +6 -6 lines
Log Message:
Further unaligned access fixes on IRIX (Brian J. Johnson). Configury needed
to ensure compiler supports bit-field members of unsigned char type.

File Contents

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