Statistics
| Branch: | Revision:

root / slirp / ip.h @ ed23fbd9

History | View | Annotate | Download (9.6 kB)

1 f0cbd3ec bellard
/*
2 f0cbd3ec bellard
 * Copyright (c) 1982, 1986, 1993
3 f0cbd3ec bellard
 *        The Regents of the University of California.  All rights reserved.
4 f0cbd3ec bellard
 *
5 f0cbd3ec bellard
 * Redistribution and use in source and binary forms, with or without
6 f0cbd3ec bellard
 * modification, are permitted provided that the following conditions
7 f0cbd3ec bellard
 * are met:
8 f0cbd3ec bellard
 * 1. Redistributions of source code must retain the above copyright
9 f0cbd3ec bellard
 *    notice, this list of conditions and the following disclaimer.
10 f0cbd3ec bellard
 * 2. Redistributions in binary form must reproduce the above copyright
11 f0cbd3ec bellard
 *    notice, this list of conditions and the following disclaimer in the
12 f0cbd3ec bellard
 *    documentation and/or other materials provided with the distribution.
13 f0cbd3ec bellard
 * 3. All advertising materials mentioning features or use of this software
14 f0cbd3ec bellard
 *    must display the following acknowledgement:
15 f0cbd3ec bellard
 *        This product includes software developed by the University of
16 f0cbd3ec bellard
 *        California, Berkeley and its contributors.
17 f0cbd3ec bellard
 * 4. Neither the name of the University nor the names of its contributors
18 f0cbd3ec bellard
 *    may be used to endorse or promote products derived from this software
19 f0cbd3ec bellard
 *    without specific prior written permission.
20 f0cbd3ec bellard
 *
21 f0cbd3ec bellard
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 f0cbd3ec bellard
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 f0cbd3ec bellard
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 f0cbd3ec bellard
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 f0cbd3ec bellard
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 f0cbd3ec bellard
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 f0cbd3ec bellard
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 f0cbd3ec bellard
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 f0cbd3ec bellard
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 f0cbd3ec bellard
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 f0cbd3ec bellard
 * SUCH DAMAGE.
32 f0cbd3ec bellard
 *
33 f0cbd3ec bellard
 *        @(#)ip.h        8.1 (Berkeley) 6/10/93
34 f0cbd3ec bellard
 * ip.h,v 1.3 1994/08/21 05:27:30 paul Exp
35 f0cbd3ec bellard
 */
36 f0cbd3ec bellard
37 f0cbd3ec bellard
#ifndef _IP_H_
38 f0cbd3ec bellard
#define _IP_H_
39 f0cbd3ec bellard
40 f0cbd3ec bellard
#ifdef WORDS_BIGENDIAN
41 f0cbd3ec bellard
# ifndef NTOHL
42 f0cbd3ec bellard
#  define NTOHL(d)
43 f0cbd3ec bellard
# endif
44 f0cbd3ec bellard
# ifndef NTOHS
45 f0cbd3ec bellard
#  define NTOHS(d)
46 f0cbd3ec bellard
# endif
47 f0cbd3ec bellard
# ifndef HTONL
48 f0cbd3ec bellard
#  define HTONL(d)
49 f0cbd3ec bellard
# endif
50 f0cbd3ec bellard
# ifndef HTONS
51 f0cbd3ec bellard
#  define HTONS(d)
52 f0cbd3ec bellard
# endif
53 f0cbd3ec bellard
#else
54 f0cbd3ec bellard
# ifndef NTOHL
55 f0cbd3ec bellard
#  define NTOHL(d) ((d) = ntohl((d)))
56 f0cbd3ec bellard
# endif
57 f0cbd3ec bellard
# ifndef NTOHS
58 f0cbd3ec bellard
#  define NTOHS(d) ((d) = ntohs((u_int16_t)(d)))
59 f0cbd3ec bellard
# endif
60 f0cbd3ec bellard
# ifndef HTONL
61 f0cbd3ec bellard
#  define HTONL(d) ((d) = htonl((d)))
62 f0cbd3ec bellard
# endif
63 f0cbd3ec bellard
# ifndef HTONS
64 f0cbd3ec bellard
#  define HTONS(d) ((d) = htons((u_int16_t)(d)))
65 f0cbd3ec bellard
# endif
66 f0cbd3ec bellard
#endif
67 f0cbd3ec bellard
68 f0cbd3ec bellard
typedef u_int32_t n_long;                 /* long as received from the net */
69 f0cbd3ec bellard
70 f0cbd3ec bellard
/*
71 f0cbd3ec bellard
 * Definitions for internet protocol version 4.
72 f0cbd3ec bellard
 * Per RFC 791, September 1981.
73 f0cbd3ec bellard
 */
74 f0cbd3ec bellard
#define        IPVERSION        4
75 f0cbd3ec bellard
76 f0cbd3ec bellard
/*
77 f0cbd3ec bellard
 * Structure of an internet header, naked of options.
78 f0cbd3ec bellard
 */
79 f0cbd3ec bellard
struct ip {
80 f0cbd3ec bellard
#ifdef WORDS_BIGENDIAN
81 f0cbd3ec bellard
        u_int ip_v:4,                        /* version */
82 f0cbd3ec bellard
                ip_hl:4;                /* header length */
83 f0cbd3ec bellard
#else
84 f0cbd3ec bellard
        u_int ip_hl:4,                /* header length */
85 f0cbd3ec bellard
                ip_v:4;                        /* version */
86 f0cbd3ec bellard
#endif
87 f0cbd3ec bellard
        u_int8_t ip_tos;                        /* type of service */
88 e553272d bellard
        u_int16_t        ip_len;                        /* total length */
89 f0cbd3ec bellard
        u_int16_t        ip_id;                        /* identification */
90 e553272d bellard
        u_int16_t        ip_off;                        /* fragment offset field */
91 f0cbd3ec bellard
#define        IP_DF 0x4000                        /* don't fragment flag */
92 f0cbd3ec bellard
#define        IP_MF 0x2000                        /* more fragments flag */
93 f0cbd3ec bellard
#define        IP_OFFMASK 0x1fff                /* mask for fragmenting bits */
94 f0cbd3ec bellard
        u_int8_t ip_ttl;                        /* time to live */
95 f0cbd3ec bellard
        u_int8_t ip_p;                        /* protocol */
96 f0cbd3ec bellard
        u_int16_t        ip_sum;                        /* checksum */
97 f0cbd3ec bellard
        struct        in_addr ip_src,ip_dst;        /* source and dest address */
98 f0cbd3ec bellard
};
99 f0cbd3ec bellard
100 f0cbd3ec bellard
#define        IP_MAXPACKET        65535                /* maximum packet size */
101 f0cbd3ec bellard
102 f0cbd3ec bellard
/*
103 f0cbd3ec bellard
 * Definitions for IP type of service (ip_tos)
104 f0cbd3ec bellard
 */
105 f0cbd3ec bellard
#define        IPTOS_LOWDELAY                0x10
106 f0cbd3ec bellard
#define        IPTOS_THROUGHPUT        0x08
107 f0cbd3ec bellard
#define        IPTOS_RELIABILITY        0x04
108 f0cbd3ec bellard
109 f0cbd3ec bellard
/*
110 f0cbd3ec bellard
 * Definitions for options.
111 f0cbd3ec bellard
 */
112 f0cbd3ec bellard
#define        IPOPT_COPIED(o)                ((o)&0x80)
113 f0cbd3ec bellard
#define        IPOPT_CLASS(o)                ((o)&0x60)
114 f0cbd3ec bellard
#define        IPOPT_NUMBER(o)                ((o)&0x1f)
115 f0cbd3ec bellard
116 f0cbd3ec bellard
#define        IPOPT_CONTROL                0x00
117 f0cbd3ec bellard
#define        IPOPT_RESERVED1                0x20
118 f0cbd3ec bellard
#define        IPOPT_DEBMEAS                0x40
119 f0cbd3ec bellard
#define        IPOPT_RESERVED2                0x60
120 f0cbd3ec bellard
121 f0cbd3ec bellard
#define        IPOPT_EOL                0                /* end of option list */
122 f0cbd3ec bellard
#define        IPOPT_NOP                1                /* no operation */
123 f0cbd3ec bellard
124 f0cbd3ec bellard
#define        IPOPT_RR                7                /* record packet route */
125 f0cbd3ec bellard
#define        IPOPT_TS                68                /* timestamp */
126 f0cbd3ec bellard
#define        IPOPT_SECURITY                130                /* provide s,c,h,tcc */
127 f0cbd3ec bellard
#define        IPOPT_LSRR                131                /* loose source route */
128 f0cbd3ec bellard
#define        IPOPT_SATID                136                /* satnet id */
129 f0cbd3ec bellard
#define        IPOPT_SSRR                137                /* strict source route */
130 f0cbd3ec bellard
131 f0cbd3ec bellard
/*
132 f0cbd3ec bellard
 * Offsets to fields in options other than EOL and NOP.
133 f0cbd3ec bellard
 */
134 f0cbd3ec bellard
#define        IPOPT_OPTVAL                0                /* option ID */
135 f0cbd3ec bellard
#define        IPOPT_OLEN                1                /* option length */
136 f0cbd3ec bellard
#define IPOPT_OFFSET                2                /* offset within option */
137 f0cbd3ec bellard
#define        IPOPT_MINOFF                4                /* min value of above */
138 f0cbd3ec bellard
139 f0cbd3ec bellard
/*
140 f0cbd3ec bellard
 * Time stamp option structure.
141 f0cbd3ec bellard
 */
142 f0cbd3ec bellard
struct        ip_timestamp {
143 f0cbd3ec bellard
        u_int8_t        ipt_code;                /* IPOPT_TS */
144 f0cbd3ec bellard
        u_int8_t        ipt_len;                /* size of structure (variable) */
145 f0cbd3ec bellard
        u_int8_t        ipt_ptr;                /* index of current entry */
146 f0cbd3ec bellard
#ifdef WORDS_BIGENDIAN
147 f0cbd3ec bellard
        u_int        ipt_oflw:4,                /* overflow counter */
148 f0cbd3ec bellard
                ipt_flg:4;                /* flags, see below */
149 f0cbd3ec bellard
#else
150 f0cbd3ec bellard
        u_int        ipt_flg:4,                /* flags, see below */
151 f0cbd3ec bellard
                ipt_oflw:4;                /* overflow counter */
152 f0cbd3ec bellard
#endif
153 f0cbd3ec bellard
        union ipt_timestamp {
154 f0cbd3ec bellard
                n_long        ipt_time[1];
155 f0cbd3ec bellard
                struct        ipt_ta {
156 f0cbd3ec bellard
                        struct in_addr ipt_addr;
157 f0cbd3ec bellard
                        n_long ipt_time;
158 f0cbd3ec bellard
                } ipt_ta[1];
159 f0cbd3ec bellard
        } ipt_timestamp;
160 f0cbd3ec bellard
};
161 f0cbd3ec bellard
162 f0cbd3ec bellard
/* flag bits for ipt_flg */
163 f0cbd3ec bellard
#define        IPOPT_TS_TSONLY                0                /* timestamps only */
164 f0cbd3ec bellard
#define        IPOPT_TS_TSANDADDR        1                /* timestamps and addresses */
165 f0cbd3ec bellard
#define        IPOPT_TS_PRESPEC        3                /* specified modules only */
166 f0cbd3ec bellard
167 f0cbd3ec bellard
/* bits for security (not byte swapped) */
168 f0cbd3ec bellard
#define        IPOPT_SECUR_UNCLASS        0x0000
169 f0cbd3ec bellard
#define        IPOPT_SECUR_CONFID        0xf135
170 f0cbd3ec bellard
#define        IPOPT_SECUR_EFTO        0x789a
171 f0cbd3ec bellard
#define        IPOPT_SECUR_MMMM        0xbc4d
172 f0cbd3ec bellard
#define        IPOPT_SECUR_RESTR        0xaf13
173 f0cbd3ec bellard
#define        IPOPT_SECUR_SECRET        0xd788
174 f0cbd3ec bellard
#define        IPOPT_SECUR_TOPSECRET        0x6bc5
175 f0cbd3ec bellard
176 f0cbd3ec bellard
/*
177 f0cbd3ec bellard
 * Internet implementation parameters.
178 f0cbd3ec bellard
 */
179 f0cbd3ec bellard
#define        MAXTTL                255                /* maximum time to live (seconds) */
180 f0cbd3ec bellard
#define        IPDEFTTL        64                /* default ttl, from RFC 1340 */
181 f0cbd3ec bellard
#define        IPFRAGTTL        60                /* time to live for frags, slowhz */
182 f0cbd3ec bellard
#define        IPTTLDEC        1                /* subtracted when forwarding */
183 f0cbd3ec bellard
184 f0cbd3ec bellard
#define        IP_MSS                576                /* default maximum segment size */
185 f0cbd3ec bellard
186 f0cbd3ec bellard
#ifdef HAVE_SYS_TYPES32_H  /* Overcome some Solaris 2.x junk */
187 f0cbd3ec bellard
#include <sys/types32.h>
188 f0cbd3ec bellard
#else
189 f0cbd3ec bellard
#if SIZEOF_CHAR_P == 4
190 f0cbd3ec bellard
typedef caddr_t caddr32_t;
191 f0cbd3ec bellard
#else
192 f0cbd3ec bellard
typedef u_int32_t caddr32_t;
193 f0cbd3ec bellard
#endif
194 f0cbd3ec bellard
#endif
195 f0cbd3ec bellard
196 f0cbd3ec bellard
#if SIZEOF_CHAR_P == 4
197 f0cbd3ec bellard
typedef struct ipq *ipqp_32;
198 f0cbd3ec bellard
typedef struct ipasfrag *ipasfragp_32;
199 f0cbd3ec bellard
#else
200 f0cbd3ec bellard
typedef caddr32_t ipqp_32;
201 f0cbd3ec bellard
typedef caddr32_t ipasfragp_32;
202 f0cbd3ec bellard
#endif
203 f0cbd3ec bellard
204 f0cbd3ec bellard
/*
205 f0cbd3ec bellard
 * Overlay for ip header used by other protocols (tcp, udp).
206 f0cbd3ec bellard
 */
207 f0cbd3ec bellard
struct ipovly {
208 f0cbd3ec bellard
        caddr32_t        ih_next, ih_prev;        /* for protocol sequence q's */
209 f0cbd3ec bellard
        u_int8_t        ih_x1;                        /* (unused) */
210 f0cbd3ec bellard
        u_int8_t        ih_pr;                        /* protocol */
211 e553272d bellard
        u_int16_t        ih_len;                        /* protocol length */
212 f0cbd3ec bellard
        struct        in_addr ih_src;                /* source internet address */
213 f0cbd3ec bellard
        struct        in_addr ih_dst;                /* destination internet address */
214 f0cbd3ec bellard
};
215 f0cbd3ec bellard
216 f0cbd3ec bellard
/*
217 f0cbd3ec bellard
 * Ip reassembly queue structure.  Each fragment
218 f0cbd3ec bellard
 * being reassembled is attached to one of these structures.
219 f0cbd3ec bellard
 * They are timed out after ipq_ttl drops to 0, and may also
220 f0cbd3ec bellard
 * be reclaimed if memory becomes tight.
221 f0cbd3ec bellard
 * size 28 bytes
222 f0cbd3ec bellard
 */
223 f0cbd3ec bellard
struct ipq {
224 f0cbd3ec bellard
        ipqp_32 next,prev;        /* to other reass headers */
225 f0cbd3ec bellard
        u_int8_t        ipq_ttl;                /* time for reass q to live */
226 f0cbd3ec bellard
        u_int8_t        ipq_p;                        /* protocol of this fragment */
227 f0cbd3ec bellard
        u_int16_t        ipq_id;                        /* sequence id for reassembly */
228 f0cbd3ec bellard
        ipasfragp_32 ipq_next,ipq_prev;
229 f0cbd3ec bellard
                                        /* to ip headers of fragments */
230 f0cbd3ec bellard
        struct        in_addr ipq_src,ipq_dst;
231 f0cbd3ec bellard
};
232 f0cbd3ec bellard
233 f0cbd3ec bellard
/*
234 f0cbd3ec bellard
 * Ip header, when holding a fragment.
235 f0cbd3ec bellard
 *
236 f0cbd3ec bellard
 * Note: ipf_next must be at same offset as ipq_next above
237 f0cbd3ec bellard
 */
238 f0cbd3ec bellard
struct        ipasfrag {
239 f0cbd3ec bellard
#ifdef WORDS_BIGENDIAN
240 f0cbd3ec bellard
        u_int        ip_v:4,
241 f0cbd3ec bellard
                 ip_hl:4;
242 f0cbd3ec bellard
#else
243 f0cbd3ec bellard
        u_int        ip_hl:4,
244 f0cbd3ec bellard
                ip_v:4;
245 f0cbd3ec bellard
#endif
246 f0cbd3ec bellard
                                        /* BUG : u_int changed to u_int8_t.
247 f0cbd3ec bellard
                                         * sizeof(u_int)==4 on linux 2.0
248 f0cbd3ec bellard
                                         */
249 f0cbd3ec bellard
        u_int8_t ipf_mff;                /* XXX overlays ip_tos: use low bit
250 f0cbd3ec bellard
                                         * to avoid destroying tos (PPPDTRuu);
251 f0cbd3ec bellard
                                         * copied from (ip_off&IP_MF) */
252 e553272d bellard
        u_int16_t        ip_len;
253 f0cbd3ec bellard
        u_int16_t        ip_id;
254 e553272d bellard
        u_int16_t        ip_off;
255 f0cbd3ec bellard
        u_int8_t        ip_ttl;
256 f0cbd3ec bellard
        u_int8_t        ip_p;
257 f0cbd3ec bellard
        u_int16_t        ip_sum;
258 f0cbd3ec bellard
        ipasfragp_32 ipf_next;                /* next fragment */
259 f0cbd3ec bellard
        ipasfragp_32 ipf_prev;                /* previous fragment */
260 f0cbd3ec bellard
};
261 f0cbd3ec bellard
262 f0cbd3ec bellard
/*
263 f0cbd3ec bellard
 * Structure stored in mbuf in inpcb.ip_options
264 f0cbd3ec bellard
 * and passed to ip_output when ip options are in use.
265 f0cbd3ec bellard
 * The actual length of the options (including ipopt_dst)
266 f0cbd3ec bellard
 * is in m_len.
267 f0cbd3ec bellard
 */
268 f0cbd3ec bellard
#define MAX_IPOPTLEN        40
269 f0cbd3ec bellard
270 f0cbd3ec bellard
struct ipoption {
271 f0cbd3ec bellard
        struct        in_addr ipopt_dst;        /* first-hop dst if source routed */
272 f0cbd3ec bellard
        int8_t        ipopt_list[MAX_IPOPTLEN];        /* options proper */
273 f0cbd3ec bellard
};
274 f0cbd3ec bellard
275 31a60e22 blueswir1
#ifdef LOG_ENABLED
276 f0cbd3ec bellard
/*
277 f0cbd3ec bellard
 * Structure attached to inpcb.ip_moptions and
278 f0cbd3ec bellard
 * passed to ip_output when IP multicast options are in use.
279 f0cbd3ec bellard
 */
280 f0cbd3ec bellard
281 f0cbd3ec bellard
struct        ipstat {
282 f0cbd3ec bellard
        u_long        ips_total;                /* total packets received */
283 f0cbd3ec bellard
        u_long        ips_badsum;                /* checksum bad */
284 f0cbd3ec bellard
        u_long        ips_tooshort;                /* packet too short */
285 f0cbd3ec bellard
        u_long        ips_toosmall;                /* not enough data */
286 f0cbd3ec bellard
        u_long        ips_badhlen;                /* ip header length < data size */
287 f0cbd3ec bellard
        u_long        ips_badlen;                /* ip length < ip header length */
288 f0cbd3ec bellard
        u_long        ips_fragments;                /* fragments received */
289 f0cbd3ec bellard
        u_long        ips_fragdropped;        /* frags dropped (dups, out of space) */
290 f0cbd3ec bellard
        u_long        ips_fragtimeout;        /* fragments timed out */
291 f0cbd3ec bellard
        u_long        ips_forward;                /* packets forwarded */
292 f0cbd3ec bellard
        u_long        ips_cantforward;        /* packets rcvd for unreachable dest */
293 f0cbd3ec bellard
        u_long        ips_redirectsent;        /* packets forwarded on same net */
294 f0cbd3ec bellard
        u_long        ips_noproto;                /* unknown or unsupported protocol */
295 f0cbd3ec bellard
        u_long        ips_delivered;                /* datagrams delivered to upper level*/
296 f0cbd3ec bellard
        u_long        ips_localout;                /* total ip packets generated here */
297 f0cbd3ec bellard
        u_long        ips_odropped;                /* lost packets due to nobufs, etc. */
298 f0cbd3ec bellard
        u_long        ips_reassembled;        /* total packets reassembled ok */
299 f0cbd3ec bellard
        u_long        ips_fragmented;                /* datagrams successfully fragmented */
300 f0cbd3ec bellard
        u_long        ips_ofragments;                /* output fragments created */
301 f0cbd3ec bellard
        u_long        ips_cantfrag;                /* don't fragment flag was set, etc. */
302 f0cbd3ec bellard
        u_long        ips_badoptions;                /* error in option processing */
303 f0cbd3ec bellard
        u_long        ips_noroute;                /* packets discarded due to no route */
304 f0cbd3ec bellard
        u_long        ips_badvers;                /* ip version != 4 */
305 f0cbd3ec bellard
        u_long        ips_rawout;                /* total raw ip packets generated */
306 f0cbd3ec bellard
        u_long        ips_unaligned;                /* times the ip packet was not aligned */
307 f0cbd3ec bellard
};
308 f0cbd3ec bellard
309 f0cbd3ec bellard
extern struct        ipstat        ipstat;
310 31a60e22 blueswir1
#endif
311 31a60e22 blueswir1
312 f0cbd3ec bellard
extern struct        ipq        ipq;                        /* ip reass. queue */
313 f0cbd3ec bellard
extern u_int16_t        ip_id;                                /* ip packet ctr, for ids */
314 31a60e22 blueswir1
315 f0cbd3ec bellard
#endif