2 * Copyright (c) 1982, 1986, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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
33 * @(#)ip.h 8.1 (Berkeley) 6/10/93
34 * ip.h,v 1.3 1994/08/21 05:27:30 paul Exp
41 #if defined(VDE_DARWIN) || defined(VDE_FREEBSD)
42 #include <machine/endian.h>
43 #define __BYTE_ORDER _BYTE_ORDER
44 #define __BIG_ENDIAN __BIG_ENDIAN
45 #define __LITTLE_ENDIAN _LITTLE_ENDIAN
49 #if __BYTE_ORDER == __BIG_ENDIAN
64 # define NTOHL(d) ((d) = ntohl((d)))
67 # define NTOHS(d) ((d) = ntohs((u_int16_t)(d)))
70 # define HTONL(d) ((d) = htonl((d)))
73 # define HTONS(d) ((d) = htons((u_int16_t)(d)))
77 typedef u_int32_t n_long
; /* long as received from the net */
80 * Definitions for internet protocol version 4.
81 * Per RFC 791, September 1981.
86 * Structure of an internet header, naked of options.
88 * We declare ip_len and ip_off to be short, rather than u_short
89 * pragmatically since otherwise unsigned comparisons can result
90 * against negative integers quite easily, and fail in subtle ways.
93 #if __BYTE_ORDER == __BIG_ENDIAN
94 u_int ip_v
:4, /* version */
95 ip_hl
:4; /* header length */
97 u_int ip_hl
:4, /* header length */
100 u_int8_t ip_tos
; /* type of service */
101 int16_t ip_len
; /* total length */
102 u_int16_t ip_id
; /* identification */
103 int16_t ip_off
; /* fragment offset field */
104 #define IP_DF 0x4000 /* don't fragment flag */
105 #define IP_MF 0x2000 /* more fragments flag */
106 #define IP_OFFMASK 0x1fff /* mask for fragmenting bits */
107 u_int8_t ip_ttl
; /* time to live */
108 u_int8_t ip_p
; /* protocol */
109 u_int16_t ip_sum
; /* checksum */
110 struct in_addr ip_src
,ip_dst
; /* source and dest address */
113 #define IP_MAXPACKET 65535 /* maximum packet size */
116 * Definitions for IP type of service (ip_tos)
118 #define IPTOS_LOWDELAY 0x10
119 #define IPTOS_THROUGHPUT 0x08
120 #define IPTOS_RELIABILITY 0x04
123 * Definitions for options.
125 #define IPOPT_COPIED(o) ((o)&0x80)
126 #define IPOPT_CLASS(o) ((o)&0x60)
127 #define IPOPT_NUMBER(o) ((o)&0x1f)
129 #define IPOPT_CONTROL 0x00
130 #define IPOPT_RESERVED1 0x20
131 #define IPOPT_DEBMEAS 0x40
132 #define IPOPT_RESERVED2 0x60
134 #define IPOPT_EOL 0 /* end of option list */
135 #define IPOPT_NOP 1 /* no operation */
137 #define IPOPT_RR 7 /* record packet route */
138 #define IPOPT_TS 68 /* timestamp */
139 #define IPOPT_SECURITY 130 /* provide s,c,h,tcc */
140 #define IPOPT_LSRR 131 /* loose source route */
141 #define IPOPT_SATID 136 /* satnet id */
142 #define IPOPT_SSRR 137 /* strict source route */
145 * Offsets to fields in options other than EOL and NOP.
147 #define IPOPT_OPTVAL 0 /* option ID */
148 #define IPOPT_OLEN 1 /* option length */
149 #define IPOPT_OFFSET 2 /* offset within option */
150 #define IPOPT_MINOFF 4 /* min value of above */
153 * Time stamp option structure.
155 struct ip_timestamp
{
156 u_int8_t ipt_code
; /* IPOPT_TS */
157 u_int8_t ipt_len
; /* size of structure (variable) */
158 u_int8_t ipt_ptr
; /* index of current entry */
159 #if __BYTE_ORDER == __BIG_ENDIAN
160 u_int ipt_oflw
:4, /* overflow counter */
161 ipt_flg
:4; /* flags, see below */
163 u_int ipt_flg
:4, /* flags, see below */
164 ipt_oflw
:4; /* overflow counter */
166 union ipt_timestamp
{
169 struct in_addr ipt_addr
;
175 /* flag bits for ipt_flg */
176 #define IPOPT_TS_TSONLY 0 /* timestamps only */
177 #define IPOPT_TS_TSANDADDR 1 /* timestamps and addresses */
178 #define IPOPT_TS_PRESPEC 3 /* specified modules only */
180 /* bits for security (not byte swapped) */
181 #define IPOPT_SECUR_UNCLASS 0x0000
182 #define IPOPT_SECUR_CONFID 0xf135
183 #define IPOPT_SECUR_EFTO 0x789a
184 #define IPOPT_SECUR_MMMM 0xbc4d
185 #define IPOPT_SECUR_RESTR 0xaf13
186 #define IPOPT_SECUR_SECRET 0xd788
187 #define IPOPT_SECUR_TOPSECRET 0x6bc5
190 * Internet implementation parameters.
192 #define MAXTTL 255 /* maximum time to live (seconds) */
193 #define IPDEFTTL 64 /* default ttl, from RFC 1340 */
194 #define IPFRAGTTL 60 /* time to live for frags, slowhz */
195 #define IPTTLDEC 1 /* subtracted when forwarding */
197 #define IP_MSS 576 /* default maximum segment size */
199 #ifdef HAVE_SYS_TYPES32_H /* Overcome some Solaris 2.x junk */
200 #include <sys/types32.h>
202 #if SIZEOF_CHAR_P == 4
203 typedef caddr_t caddr32_t
;
205 typedef u_int32_t caddr32_t
;
209 #if SIZEOF_CHAR_P == 4
210 typedef struct ipq
*ipqp_32
;
211 typedef struct ipasfrag
*ipasfragp_32
;
213 typedef caddr32_t ipqp_32
;
214 typedef caddr32_t ipasfragp_32
;
218 * Overlay for ip header used by other protocols (tcp, udp).
221 caddr32_t ih_next
, ih_prev
; /* for protocol sequence q's */
222 u_int8_t ih_x1
; /* (unused) */
223 u_int8_t ih_pr
; /* protocol */
224 int16_t ih_len
; /* protocol length */
225 struct in_addr ih_src
; /* source internet address */
226 struct in_addr ih_dst
; /* destination internet address */
230 * Ip reassembly queue structure. Each fragment
231 * being reassembled is attached to one of these structures.
232 * They are timed out after ipq_ttl drops to 0, and may also
233 * be reclaimed if memory becomes tight.
237 ipqp_32 next
,prev
; /* to other reass headers */
238 u_int8_t ipq_ttl
; /* time for reass q to live */
239 u_int8_t ipq_p
; /* protocol of this fragment */
240 u_int16_t ipq_id
; /* sequence id for reassembly */
241 ipasfragp_32 ipq_next
,ipq_prev
;
242 /* to ip headers of fragments */
243 struct in_addr ipq_src
,ipq_dst
;
247 * Ip header, when holding a fragment.
249 * Note: ipf_next must be at same offset as ipq_next above
252 #if __BYTE_ORDER == __BIG_ENDIAN
259 /* BUG : u_int changed to u_int8_t.
260 * sizeof(u_int)==4 on linux 2.0
262 u_int8_t ipf_mff
; /* XXX overlays ip_tos: use low bit
263 * to avoid destroying tos (PPPDTRuu);
264 * copied from (ip_off&IP_MF) */
271 ipasfragp_32 ipf_next
; /* next fragment */
272 ipasfragp_32 ipf_prev
; /* previous fragment */
276 * Structure stored in mbuf in inpcb.ip_options
277 * and passed to ip_output when ip options are in use.
278 * The actual length of the options (including ipopt_dst)
281 #define MAX_IPOPTLEN 40
284 struct in_addr ipopt_dst
; /* first-hop dst if source routed */
285 int8_t ipopt_list
[MAX_IPOPTLEN
]; /* options proper */
289 * Structure attached to inpcb.ip_moptions and
290 * passed to ip_output when IP multicast options are in use.
294 u_long ips_total
; /* total packets received */
295 u_long ips_badsum
; /* checksum bad */
296 u_long ips_tooshort
; /* packet too short */
297 u_long ips_toosmall
; /* not enough data */
298 u_long ips_badhlen
; /* ip header length < data size */
299 u_long ips_badlen
; /* ip length < ip header length */
300 u_long ips_fragments
; /* fragments received */
301 u_long ips_fragdropped
; /* frags dropped (dups, out of space) */
302 u_long ips_fragtimeout
; /* fragments timed out */
303 u_long ips_forward
; /* packets forwarded */
304 u_long ips_cantforward
; /* packets rcvd for unreachable dest */
305 u_long ips_redirectsent
; /* packets forwarded on same net */
306 u_long ips_noproto
; /* unknown or unsupported protocol */
307 u_long ips_delivered
; /* datagrams delivered to upper level*/
308 u_long ips_localout
; /* total ip packets generated here */
309 u_long ips_odropped
; /* lost packets due to nobufs, etc. */
310 u_long ips_reassembled
; /* total packets reassembled ok */
311 u_long ips_fragmented
; /* datagrams successfully fragmented */
312 u_long ips_ofragments
; /* output fragments created */
313 u_long ips_cantfrag
; /* don't fragment flag was set, etc. */
314 u_long ips_badoptions
; /* error in option processing */
315 u_long ips_noroute
; /* packets discarded due to no route */
316 u_long ips_badvers
; /* ip version != 4 */
317 u_long ips_rawout
; /* total raw ip packets generated */
318 u_long ips_unaligned
; /* times the ip packet was not aligned */
321 extern struct ipstat ipstat
;
322 extern struct ipq ipq
; /* ip reass. queue */
323 extern u_int16_t ip_id
; /* ip packet ctr, for ids */
324 extern int ip_defttl
; /* default IP ttl */