root / slirp / ip.h @ 64e58fe5
History | View | Annotate | Download (7.2 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 | 2f5f8996 | aliguori | * 3. Neither the name of the University nor the names of its contributors
|
14 | f0cbd3ec | bellard | * may be used to endorse or promote products derived from this software
|
15 | f0cbd3ec | bellard | * without specific prior written permission.
|
16 | f0cbd3ec | bellard | *
|
17 | f0cbd3ec | bellard | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
18 | f0cbd3ec | bellard | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
19 | f0cbd3ec | bellard | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
20 | f0cbd3ec | bellard | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
21 | f0cbd3ec | bellard | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
22 | f0cbd3ec | bellard | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
23 | f0cbd3ec | bellard | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
24 | f0cbd3ec | bellard | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
25 | f0cbd3ec | bellard | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
26 | f0cbd3ec | bellard | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
27 | f0cbd3ec | bellard | * SUCH DAMAGE.
|
28 | f0cbd3ec | bellard | *
|
29 | f0cbd3ec | bellard | * @(#)ip.h 8.1 (Berkeley) 6/10/93
|
30 | f0cbd3ec | bellard | * ip.h,v 1.3 1994/08/21 05:27:30 paul Exp
|
31 | f0cbd3ec | bellard | */
|
32 | f0cbd3ec | bellard | |
33 | f0cbd3ec | bellard | #ifndef _IP_H_
|
34 | f0cbd3ec | bellard | #define _IP_H_
|
35 | f0cbd3ec | bellard | |
36 | e2542fe2 | Juan Quintela | #ifdef HOST_WORDS_BIGENDIAN
|
37 | f0cbd3ec | bellard | # ifndef NTOHL
|
38 | f0cbd3ec | bellard | # define NTOHL(d)
|
39 | f0cbd3ec | bellard | # endif
|
40 | f0cbd3ec | bellard | # ifndef NTOHS
|
41 | f0cbd3ec | bellard | # define NTOHS(d)
|
42 | f0cbd3ec | bellard | # endif
|
43 | f0cbd3ec | bellard | # ifndef HTONL
|
44 | f0cbd3ec | bellard | # define HTONL(d)
|
45 | f0cbd3ec | bellard | # endif
|
46 | f0cbd3ec | bellard | # ifndef HTONS
|
47 | f0cbd3ec | bellard | # define HTONS(d)
|
48 | f0cbd3ec | bellard | # endif
|
49 | f0cbd3ec | bellard | #else
|
50 | f0cbd3ec | bellard | # ifndef NTOHL
|
51 | f0cbd3ec | bellard | # define NTOHL(d) ((d) = ntohl((d)))
|
52 | f0cbd3ec | bellard | # endif
|
53 | f0cbd3ec | bellard | # ifndef NTOHS
|
54 | f0cbd3ec | bellard | # define NTOHS(d) ((d) = ntohs((u_int16_t)(d)))
|
55 | f0cbd3ec | bellard | # endif
|
56 | f0cbd3ec | bellard | # ifndef HTONL
|
57 | f0cbd3ec | bellard | # define HTONL(d) ((d) = htonl((d)))
|
58 | f0cbd3ec | bellard | # endif
|
59 | f0cbd3ec | bellard | # ifndef HTONS
|
60 | f0cbd3ec | bellard | # define HTONS(d) ((d) = htons((u_int16_t)(d)))
|
61 | f0cbd3ec | bellard | # endif
|
62 | f0cbd3ec | bellard | #endif
|
63 | f0cbd3ec | bellard | |
64 | f0cbd3ec | bellard | typedef u_int32_t n_long; /* long as received from the net */ |
65 | f0cbd3ec | bellard | |
66 | f0cbd3ec | bellard | /*
|
67 | f0cbd3ec | bellard | * Definitions for internet protocol version 4.
|
68 | f0cbd3ec | bellard | * Per RFC 791, September 1981.
|
69 | f0cbd3ec | bellard | */
|
70 | f0cbd3ec | bellard | #define IPVERSION 4 |
71 | f0cbd3ec | bellard | |
72 | f0cbd3ec | bellard | /*
|
73 | f0cbd3ec | bellard | * Structure of an internet header, naked of options.
|
74 | f0cbd3ec | bellard | */
|
75 | f0cbd3ec | bellard | struct ip {
|
76 | e2542fe2 | Juan Quintela | #ifdef HOST_WORDS_BIGENDIAN
|
77 | f0cbd3ec | bellard | u_int ip_v:4, /* version */ |
78 | f0cbd3ec | bellard | ip_hl:4; /* header length */ |
79 | f0cbd3ec | bellard | #else
|
80 | f0cbd3ec | bellard | u_int ip_hl:4, /* header length */ |
81 | f0cbd3ec | bellard | ip_v:4; /* version */ |
82 | f0cbd3ec | bellard | #endif
|
83 | f0cbd3ec | bellard | u_int8_t ip_tos; /* type of service */
|
84 | e553272d | bellard | u_int16_t ip_len; /* total length */
|
85 | f0cbd3ec | bellard | u_int16_t ip_id; /* identification */
|
86 | e553272d | bellard | u_int16_t ip_off; /* fragment offset field */
|
87 | f0cbd3ec | bellard | #define IP_DF 0x4000 /* don't fragment flag */ |
88 | f0cbd3ec | bellard | #define IP_MF 0x2000 /* more fragments flag */ |
89 | f0cbd3ec | bellard | #define IP_OFFMASK 0x1fff /* mask for fragmenting bits */ |
90 | f0cbd3ec | bellard | u_int8_t ip_ttl; /* time to live */
|
91 | f0cbd3ec | bellard | u_int8_t ip_p; /* protocol */
|
92 | f0cbd3ec | bellard | u_int16_t ip_sum; /* checksum */
|
93 | f0cbd3ec | bellard | struct in_addr ip_src,ip_dst; /* source and dest address */ |
94 | f0cbd3ec | bellard | }; |
95 | f0cbd3ec | bellard | |
96 | f0cbd3ec | bellard | #define IP_MAXPACKET 65535 /* maximum packet size */ |
97 | f0cbd3ec | bellard | |
98 | f0cbd3ec | bellard | /*
|
99 | f0cbd3ec | bellard | * Definitions for IP type of service (ip_tos)
|
100 | f0cbd3ec | bellard | */
|
101 | f0cbd3ec | bellard | #define IPTOS_LOWDELAY 0x10 |
102 | f0cbd3ec | bellard | #define IPTOS_THROUGHPUT 0x08 |
103 | f0cbd3ec | bellard | #define IPTOS_RELIABILITY 0x04 |
104 | f0cbd3ec | bellard | |
105 | f0cbd3ec | bellard | /*
|
106 | f0cbd3ec | bellard | * Definitions for options.
|
107 | f0cbd3ec | bellard | */
|
108 | f0cbd3ec | bellard | #define IPOPT_COPIED(o) ((o)&0x80) |
109 | f0cbd3ec | bellard | #define IPOPT_CLASS(o) ((o)&0x60) |
110 | f0cbd3ec | bellard | #define IPOPT_NUMBER(o) ((o)&0x1f) |
111 | f0cbd3ec | bellard | |
112 | f0cbd3ec | bellard | #define IPOPT_CONTROL 0x00 |
113 | f0cbd3ec | bellard | #define IPOPT_RESERVED1 0x20 |
114 | f0cbd3ec | bellard | #define IPOPT_DEBMEAS 0x40 |
115 | f0cbd3ec | bellard | #define IPOPT_RESERVED2 0x60 |
116 | f0cbd3ec | bellard | |
117 | f0cbd3ec | bellard | #define IPOPT_EOL 0 /* end of option list */ |
118 | f0cbd3ec | bellard | #define IPOPT_NOP 1 /* no operation */ |
119 | f0cbd3ec | bellard | |
120 | f0cbd3ec | bellard | #define IPOPT_RR 7 /* record packet route */ |
121 | f0cbd3ec | bellard | #define IPOPT_TS 68 /* timestamp */ |
122 | f0cbd3ec | bellard | #define IPOPT_SECURITY 130 /* provide s,c,h,tcc */ |
123 | f0cbd3ec | bellard | #define IPOPT_LSRR 131 /* loose source route */ |
124 | f0cbd3ec | bellard | #define IPOPT_SATID 136 /* satnet id */ |
125 | f0cbd3ec | bellard | #define IPOPT_SSRR 137 /* strict source route */ |
126 | f0cbd3ec | bellard | |
127 | f0cbd3ec | bellard | /*
|
128 | f0cbd3ec | bellard | * Offsets to fields in options other than EOL and NOP.
|
129 | f0cbd3ec | bellard | */
|
130 | f0cbd3ec | bellard | #define IPOPT_OPTVAL 0 /* option ID */ |
131 | f0cbd3ec | bellard | #define IPOPT_OLEN 1 /* option length */ |
132 | f0cbd3ec | bellard | #define IPOPT_OFFSET 2 /* offset within option */ |
133 | f0cbd3ec | bellard | #define IPOPT_MINOFF 4 /* min value of above */ |
134 | f0cbd3ec | bellard | |
135 | f0cbd3ec | bellard | /*
|
136 | f0cbd3ec | bellard | * Time stamp option structure.
|
137 | f0cbd3ec | bellard | */
|
138 | f0cbd3ec | bellard | struct ip_timestamp {
|
139 | f0cbd3ec | bellard | u_int8_t ipt_code; /* IPOPT_TS */
|
140 | f0cbd3ec | bellard | u_int8_t ipt_len; /* size of structure (variable) */
|
141 | f0cbd3ec | bellard | u_int8_t ipt_ptr; /* index of current entry */
|
142 | e2542fe2 | Juan Quintela | #ifdef HOST_WORDS_BIGENDIAN
|
143 | f0cbd3ec | bellard | u_int ipt_oflw:4, /* overflow counter */ |
144 | f0cbd3ec | bellard | ipt_flg:4; /* flags, see below */ |
145 | f0cbd3ec | bellard | #else
|
146 | f0cbd3ec | bellard | u_int ipt_flg:4, /* flags, see below */ |
147 | f0cbd3ec | bellard | ipt_oflw:4; /* overflow counter */ |
148 | f0cbd3ec | bellard | #endif
|
149 | f0cbd3ec | bellard | union ipt_timestamp {
|
150 | f0cbd3ec | bellard | n_long ipt_time[1];
|
151 | f0cbd3ec | bellard | struct ipt_ta {
|
152 | f0cbd3ec | bellard | struct in_addr ipt_addr;
|
153 | f0cbd3ec | bellard | n_long ipt_time; |
154 | f0cbd3ec | bellard | } ipt_ta[1];
|
155 | f0cbd3ec | bellard | } ipt_timestamp; |
156 | f0cbd3ec | bellard | }; |
157 | f0cbd3ec | bellard | |
158 | f0cbd3ec | bellard | /* flag bits for ipt_flg */
|
159 | f0cbd3ec | bellard | #define IPOPT_TS_TSONLY 0 /* timestamps only */ |
160 | f0cbd3ec | bellard | #define IPOPT_TS_TSANDADDR 1 /* timestamps and addresses */ |
161 | f0cbd3ec | bellard | #define IPOPT_TS_PRESPEC 3 /* specified modules only */ |
162 | f0cbd3ec | bellard | |
163 | f0cbd3ec | bellard | /* bits for security (not byte swapped) */
|
164 | f0cbd3ec | bellard | #define IPOPT_SECUR_UNCLASS 0x0000 |
165 | f0cbd3ec | bellard | #define IPOPT_SECUR_CONFID 0xf135 |
166 | f0cbd3ec | bellard | #define IPOPT_SECUR_EFTO 0x789a |
167 | f0cbd3ec | bellard | #define IPOPT_SECUR_MMMM 0xbc4d |
168 | f0cbd3ec | bellard | #define IPOPT_SECUR_RESTR 0xaf13 |
169 | f0cbd3ec | bellard | #define IPOPT_SECUR_SECRET 0xd788 |
170 | f0cbd3ec | bellard | #define IPOPT_SECUR_TOPSECRET 0x6bc5 |
171 | f0cbd3ec | bellard | |
172 | f0cbd3ec | bellard | /*
|
173 | f0cbd3ec | bellard | * Internet implementation parameters.
|
174 | f0cbd3ec | bellard | */
|
175 | f0cbd3ec | bellard | #define MAXTTL 255 /* maximum time to live (seconds) */ |
176 | f0cbd3ec | bellard | #define IPDEFTTL 64 /* default ttl, from RFC 1340 */ |
177 | f0cbd3ec | bellard | #define IPFRAGTTL 60 /* time to live for frags, slowhz */ |
178 | f0cbd3ec | bellard | #define IPTTLDEC 1 /* subtracted when forwarding */ |
179 | f0cbd3ec | bellard | |
180 | f0cbd3ec | bellard | #define IP_MSS 576 /* default maximum segment size */ |
181 | f0cbd3ec | bellard | |
182 | f0cbd3ec | bellard | #if SIZEOF_CHAR_P == 4 |
183 | 429d0a3d | blueswir1 | struct mbuf_ptr {
|
184 | 429d0a3d | blueswir1 | struct mbuf *mptr;
|
185 | 429d0a3d | blueswir1 | uint32_t dummy; |
186 | 429d0a3d | blueswir1 | }; |
187 | f0cbd3ec | bellard | #else
|
188 | 429d0a3d | blueswir1 | struct mbuf_ptr {
|
189 | 429d0a3d | blueswir1 | struct mbuf *mptr;
|
190 | 429d0a3d | blueswir1 | }; |
191 | f0cbd3ec | bellard | #endif
|
192 | 429d0a3d | blueswir1 | struct qlink {
|
193 | 429d0a3d | blueswir1 | void *next, *prev;
|
194 | 429d0a3d | blueswir1 | }; |
195 | f0cbd3ec | bellard | |
196 | f0cbd3ec | bellard | /*
|
197 | f0cbd3ec | bellard | * Overlay for ip header used by other protocols (tcp, udp).
|
198 | f0cbd3ec | bellard | */
|
199 | f0cbd3ec | bellard | struct ipovly {
|
200 | 429d0a3d | blueswir1 | struct mbuf_ptr ih_mbuf; /* backpointer to mbuf */ |
201 | f0cbd3ec | bellard | u_int8_t ih_x1; /* (unused) */
|
202 | f0cbd3ec | bellard | u_int8_t ih_pr; /* protocol */
|
203 | e553272d | bellard | u_int16_t ih_len; /* protocol length */
|
204 | f0cbd3ec | bellard | struct in_addr ih_src; /* source internet address */ |
205 | f0cbd3ec | bellard | struct in_addr ih_dst; /* destination internet address */ |
206 | 429d0a3d | blueswir1 | } __attribute__((packed)); |
207 | f0cbd3ec | bellard | |
208 | f0cbd3ec | bellard | /*
|
209 | f0cbd3ec | bellard | * Ip reassembly queue structure. Each fragment
|
210 | f0cbd3ec | bellard | * being reassembled is attached to one of these structures.
|
211 | f0cbd3ec | bellard | * They are timed out after ipq_ttl drops to 0, and may also
|
212 | f0cbd3ec | bellard | * be reclaimed if memory becomes tight.
|
213 | f0cbd3ec | bellard | * size 28 bytes
|
214 | f0cbd3ec | bellard | */
|
215 | f0cbd3ec | bellard | struct ipq {
|
216 | 429d0a3d | blueswir1 | struct qlink frag_link; /* to ip headers of fragments */ |
217 | 429d0a3d | blueswir1 | struct qlink ip_link; /* to other reass headers */ |
218 | f0cbd3ec | bellard | u_int8_t ipq_ttl; /* time for reass q to live */
|
219 | f0cbd3ec | bellard | u_int8_t ipq_p; /* protocol of this fragment */
|
220 | f0cbd3ec | bellard | u_int16_t ipq_id; /* sequence id for reassembly */
|
221 | f0cbd3ec | bellard | struct in_addr ipq_src,ipq_dst;
|
222 | f0cbd3ec | bellard | }; |
223 | f0cbd3ec | bellard | |
224 | f0cbd3ec | bellard | /*
|
225 | f0cbd3ec | bellard | * Ip header, when holding a fragment.
|
226 | f0cbd3ec | bellard | *
|
227 | 429d0a3d | blueswir1 | * Note: ipf_link must be at same offset as frag_link above
|
228 | f0cbd3ec | bellard | */
|
229 | f0cbd3ec | bellard | struct ipasfrag {
|
230 | 429d0a3d | blueswir1 | struct qlink ipf_link;
|
231 | 429d0a3d | blueswir1 | struct ip ipf_ip;
|
232 | f0cbd3ec | bellard | }; |
233 | f0cbd3ec | bellard | |
234 | 429d0a3d | blueswir1 | #define ipf_off ipf_ip.ip_off
|
235 | 429d0a3d | blueswir1 | #define ipf_tos ipf_ip.ip_tos
|
236 | 429d0a3d | blueswir1 | #define ipf_len ipf_ip.ip_len
|
237 | 429d0a3d | blueswir1 | #define ipf_next ipf_link.next
|
238 | 429d0a3d | blueswir1 | #define ipf_prev ipf_link.prev
|
239 | 429d0a3d | blueswir1 | |
240 | f0cbd3ec | bellard | /*
|
241 | f0cbd3ec | bellard | * Structure stored in mbuf in inpcb.ip_options
|
242 | f0cbd3ec | bellard | * and passed to ip_output when ip options are in use.
|
243 | f0cbd3ec | bellard | * The actual length of the options (including ipopt_dst)
|
244 | f0cbd3ec | bellard | * is in m_len.
|
245 | f0cbd3ec | bellard | */
|
246 | f0cbd3ec | bellard | #define MAX_IPOPTLEN 40 |
247 | f0cbd3ec | bellard | |
248 | f0cbd3ec | bellard | struct ipoption {
|
249 | f0cbd3ec | bellard | struct in_addr ipopt_dst; /* first-hop dst if source routed */ |
250 | f0cbd3ec | bellard | int8_t ipopt_list[MAX_IPOPTLEN]; /* options proper */
|
251 | f0cbd3ec | bellard | }; |
252 | f0cbd3ec | bellard | |
253 | f0cbd3ec | bellard | #endif |