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