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 | #include "queue.h"
|
---|
41 |
|
---|
42 | #ifdef WORDS_BIGENDIAN
|
---|
43 | # ifndef NTOHL
|
---|
44 | # define NTOHL(d)
|
---|
45 | # endif
|
---|
46 | # ifndef NTOHS
|
---|
47 | # define NTOHS(d)
|
---|
48 | # endif
|
---|
49 | # ifndef HTONL
|
---|
50 | # define HTONL(d)
|
---|
51 | # endif
|
---|
52 | # ifndef HTONS
|
---|
53 | # define HTONS(d)
|
---|
54 | # endif
|
---|
55 | #else
|
---|
56 | # ifndef NTOHL
|
---|
57 | # define NTOHL(d) ((d) = ntohl((d)))
|
---|
58 | # endif
|
---|
59 | # ifndef NTOHS
|
---|
60 | # define NTOHS(d) ((d) = ntohs((u_int16_t)(d)))
|
---|
61 | # endif
|
---|
62 | # ifndef HTONL
|
---|
63 | # define HTONL(d) ((d) = htonl((d)))
|
---|
64 | # endif
|
---|
65 | # ifndef HTONS
|
---|
66 | # define HTONS(d) ((d) = htons((u_int16_t)(d)))
|
---|
67 | # endif
|
---|
68 | #endif
|
---|
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 | struct ip
|
---|
80 | {
|
---|
81 | #ifdef WORDS_BIGENDIAN
|
---|
82 | # ifdef _MSC_VER
|
---|
83 | uint8_t ip_v:4; /* version */
|
---|
84 | uint8_t ip_hl:4; /* header length */
|
---|
85 | # else
|
---|
86 | unsigned ip_v:4; /* version */
|
---|
87 | unsigned ip_hl:4; /* header length */
|
---|
88 | # endif
|
---|
89 | #else
|
---|
90 | # ifdef _MSC_VER
|
---|
91 | uint8_t ip_hl:4; /* header length */
|
---|
92 | uint8_t ip_v:4; /* version */
|
---|
93 | # else
|
---|
94 | unsigned ip_hl:4; /* header length */
|
---|
95 | unsigned ip_v:4; /* version */
|
---|
96 | # endif
|
---|
97 | #endif
|
---|
98 | uint8_t ip_tos; /* type of service */
|
---|
99 | uint16_t ip_len; /* total length */
|
---|
100 | uint16_t ip_id; /* identification */
|
---|
101 | uint16_t ip_off; /* fragment offset field */
|
---|
102 | #define IP_DF 0x4000 /* don't fragment flag */
|
---|
103 | #define IP_MF 0x2000 /* more fragments flag */
|
---|
104 | #define IP_OFFMASK 0x1fff /* mask for fragmenting bits */
|
---|
105 | uint8_t ip_ttl; /* time to live */
|
---|
106 | uint8_t ip_p; /* protocol */
|
---|
107 | uint16_t ip_sum; /* checksum */
|
---|
108 | struct in_addr ip_src; /* source address */
|
---|
109 | struct in_addr ip_dst; /* destination address */
|
---|
110 | };
|
---|
111 | AssertCompileSize(struct ip, 20);
|
---|
112 |
|
---|
113 | #define IP_MAXPACKET 65535 /* maximum packet size */
|
---|
114 |
|
---|
115 | /*
|
---|
116 | * Definitions for IP type of service (ip_tos)
|
---|
117 | */
|
---|
118 | #define IPTOS_LOWDELAY 0x10
|
---|
119 | #define IPTOS_THROUGHPUT 0x08
|
---|
120 | #define IPTOS_RELIABILITY 0x04
|
---|
121 |
|
---|
122 |
|
---|
123 | /*
|
---|
124 | * Time stamp option structure.
|
---|
125 | */
|
---|
126 | struct ip_timestamp
|
---|
127 | {
|
---|
128 | uint8_t ipt_code; /* IPOPT_TS */
|
---|
129 | uint8_t ipt_len; /* size of structure (variable) */
|
---|
130 | uint8_t ipt_ptr; /* index of current entry */
|
---|
131 | #ifdef WORDS_BIGENDIAN
|
---|
132 | # ifdef _MSC_VER
|
---|
133 | uint8_t ipt_oflw:4; /* overflow counter */
|
---|
134 | uint8_t ipt_flg:4; /* flags, see below */
|
---|
135 | # else
|
---|
136 | unsigned ipt_oflw:4; /* overflow counter */
|
---|
137 | unsigned ipt_flg:4; /* flags, see below */
|
---|
138 | # endif
|
---|
139 | #else
|
---|
140 | # ifdef _MSC_VER
|
---|
141 | uint8_t ipt_flg:4; /* flags, see below */
|
---|
142 | uint8_t ipt_oflw:4; /* overflow counter */
|
---|
143 | # else
|
---|
144 | unsigned ipt_flg:4; /* flags, see below */
|
---|
145 | unsigned ipt_oflw:4; /* overflow counter */
|
---|
146 | # endif
|
---|
147 | #endif
|
---|
148 | union ipt_timestamp
|
---|
149 | {
|
---|
150 | uint32_t ipt_time[1];
|
---|
151 | struct ipt_ta
|
---|
152 | {
|
---|
153 | struct in_addr ipt_addr;
|
---|
154 | uint32_t ipt_time;
|
---|
155 | } ipt_ta[1];
|
---|
156 | } ipt_timestamp;
|
---|
157 | };
|
---|
158 | AssertCompileSize(struct ip_timestamp, 12);
|
---|
159 |
|
---|
160 | /*
|
---|
161 | * Internet implementation parameters.
|
---|
162 | */
|
---|
163 | #define MAXTTL 255 /* maximum time to live (seconds) */
|
---|
164 | #define IPDEFTTL 64 /* default ttl, from RFC 1340 */
|
---|
165 | #define IPFRAGTTL 60 /* time to live for frags, slowhz */
|
---|
166 | #define IPTTLDEC 1 /* subtracted when forwarding */
|
---|
167 |
|
---|
168 | #define IP_MSS 576 /* default maximum segment size */
|
---|
169 |
|
---|
170 | #ifdef HAVE_SYS_TYPES32_H /* Overcome some Solaris 2.x junk */
|
---|
171 | # include <sys/types32.h>
|
---|
172 | #else
|
---|
173 | typedef caddr_t caddr32_t;
|
---|
174 | #endif
|
---|
175 |
|
---|
176 | #if SIZEOF_CHAR_P == 4
|
---|
177 | typedef struct ipq_t *ipqp_32;
|
---|
178 | typedef struct ipasfrag *ipasfragp_32;
|
---|
179 | #else
|
---|
180 | typedef caddr32_t ipqp_32;
|
---|
181 | typedef caddr32_t ipasfragp_32;
|
---|
182 | #endif
|
---|
183 |
|
---|
184 | /*
|
---|
185 | * Overlay for ip header used by other protocols (tcp, udp).
|
---|
186 | */
|
---|
187 | struct ipovly
|
---|
188 | {
|
---|
189 | u_int8_t ih_x1[9]; /* (unused) */
|
---|
190 | u_int8_t ih_pr; /* protocol */
|
---|
191 | u_int16_t ih_len; /* protocol length */
|
---|
192 | struct in_addr ih_src; /* source internet address */
|
---|
193 | struct in_addr ih_dst; /* destination internet address */
|
---|
194 | };
|
---|
195 | AssertCompileSize(struct ipovly, 20);
|
---|
196 |
|
---|
197 | /*
|
---|
198 | * Ip reassembly queue structure. Each fragment being reassembled is
|
---|
199 | * attached to one of these structures. They are timed out after ipq_ttl
|
---|
200 | * drops to 0, and may also be reclaimed if memory becomes tight.
|
---|
201 | * size 28 bytes
|
---|
202 | */
|
---|
203 | struct ipq_t
|
---|
204 | {
|
---|
205 | TAILQ_ENTRY(ipq_t) ipq_list;
|
---|
206 | u_int8_t ipq_ttl; /* time for reass q to live */
|
---|
207 | u_int8_t ipq_p; /* protocol of this fragment */
|
---|
208 | u_int16_t ipq_id; /* sequence id for reassembly */
|
---|
209 | struct mbuf *ipq_frags; /* to ip headers of fragments */
|
---|
210 | uint8_t ipq_nfrags; /* # of fragments in this packet */
|
---|
211 | struct in_addr ipq_src;
|
---|
212 | struct in_addr ipq_dst;
|
---|
213 | };
|
---|
214 |
|
---|
215 |
|
---|
216 | /*
|
---|
217 | * IP datagram reassembly.
|
---|
218 | */
|
---|
219 | #define IPREASS_NHASH_LOG2 6
|
---|
220 | #define IPREASS_NHASH (1 << IPREASS_NHASH_LOG2)
|
---|
221 | #define IPREASS_HMASK (IPREASS_NHASH - 1)
|
---|
222 | #define IPREASS_HASH(x,y) \
|
---|
223 | (((((x) & 0xF) | ((((x) >> 8) & 0xF) << 4)) ^ (y)) & IPREASS_HMASK)
|
---|
224 | TAILQ_HEAD(ipqhead,ipq_t);
|
---|
225 |
|
---|
226 | /*
|
---|
227 | * Structure attached to inpcb.ip_moptions and
|
---|
228 | * passed to ip_output when IP multicast options are in use.
|
---|
229 | */
|
---|
230 |
|
---|
231 | struct ipstat_t
|
---|
232 | {
|
---|
233 | u_long ips_total; /* total packets received */
|
---|
234 | u_long ips_badsum; /* checksum bad */
|
---|
235 | u_long ips_tooshort; /* packet too short */
|
---|
236 | u_long ips_toosmall; /* not enough data */
|
---|
237 | u_long ips_badhlen; /* ip header length < data size */
|
---|
238 | u_long ips_badlen; /* ip length < ip header length */
|
---|
239 | u_long ips_fragments; /* fragments received */
|
---|
240 | u_long ips_fragdropped; /* frags dropped (dups, out of space) */
|
---|
241 | u_long ips_fragtimeout; /* fragments timed out */
|
---|
242 | u_long ips_forward; /* packets forwarded */
|
---|
243 | u_long ips_cantforward; /* packets rcvd for unreachable dest */
|
---|
244 | u_long ips_redirectsent; /* packets forwarded on same net */
|
---|
245 | u_long ips_noproto; /* unknown or unsupported protocol */
|
---|
246 | u_long ips_delivered; /* datagrams delivered to upper level*/
|
---|
247 | u_long ips_localout; /* total ip packets generated here */
|
---|
248 | u_long ips_odropped; /* lost packets due to nobufs, etc. */
|
---|
249 | u_long ips_reassembled; /* total packets reassembled ok */
|
---|
250 | u_long ips_fragmented; /* datagrams successfully fragmented */
|
---|
251 | u_long ips_ofragments; /* output fragments created */
|
---|
252 | u_long ips_cantfrag; /* don't fragment flag was set, etc. */
|
---|
253 | u_long ips_badoptions; /* error in option processing */
|
---|
254 | u_long ips_noroute; /* packets discarded due to no route */
|
---|
255 | u_long ips_badvers; /* ip version != 4 */
|
---|
256 | u_long ips_rawout; /* total raw ip packets generated */
|
---|
257 | u_long ips_unaligned; /* times the ip packet was not aligned */
|
---|
258 | };
|
---|
259 |
|
---|
260 | #endif
|
---|