15c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu/* @(#) $Header: /tcpdump/master/tcpdump/ip.h,v 1.12 2007-09-14 01:29:28 guy Exp $ (LBL) */
25c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu/*
35c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu * Copyright (c) 1982, 1986, 1993
45c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu *	The Regents of the University of California.  All rights reserved.
55c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu *
65c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu * Redistribution and use in source and binary forms, with or without
75c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu * modification, are permitted provided that the following conditions
85c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu * are met:
95c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu * 1. Redistributions of source code must retain the above copyright
105c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu *    notice, this list of conditions and the following disclaimer.
115c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu * 2. Redistributions in binary form must reproduce the above copyright
125c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu *    notice, this list of conditions and the following disclaimer in the
135c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu *    documentation and/or other materials provided with the distribution.
145c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu * 3. All advertising materials mentioning features or use of this software
155c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu *    must display the following acknowledgement:
165c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu *	This product includes software developed by the University of
175c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu *	California, Berkeley and its contributors.
185c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu * 4. Neither the name of the University nor the names of its contributors
195c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu *    may be used to endorse or promote products derived from this software
205c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu *    without specific prior written permission.
215c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu *
225c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
235c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
245c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
255c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
265c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
275c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
285c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
295c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
305c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
315c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
325c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu * SUCH DAMAGE.
335c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu *
345c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu *	@(#)ip.h	8.2 (Berkeley) 6/1/94
355c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu */
365c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
375c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu/*
385c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu * Definitions for internet protocol version 4.
395c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu * Per RFC 791, September 1981.
405c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu */
415c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu#define	IPVERSION	4
425c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
435c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu/*
445c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu * Structure of an internet header, naked of options.
455c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu *
465c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu * We declare ip_len and ip_off to be short, rather than u_short
475c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu * pragmatically since otherwise unsigned comparisons can result
485c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu * against negative integers quite easily, and fail in subtle ways.
495c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu */
505c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liustruct ip {
515c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu	u_int8_t	ip_vhl;		/* header length, version */
525c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu#define IP_V(ip)	(((ip)->ip_vhl & 0xf0) >> 4)
535c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu#define IP_HL(ip)	((ip)->ip_vhl & 0x0f)
545c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu	u_int8_t	ip_tos;		/* type of service */
555c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu	u_int16_t	ip_len;		/* total length */
565c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu	u_int16_t	ip_id;		/* identification */
575c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu	u_int16_t	ip_off;		/* fragment offset field */
585c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu#define	IP_DF 0x4000			/* dont fragment flag */
595c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu#define	IP_MF 0x2000			/* more fragments flag */
605c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu#define	IP_OFFMASK 0x1fff		/* mask for fragmenting bits */
615c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu	u_int8_t	ip_ttl;		/* time to live */
625c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu	u_int8_t	ip_p;		/* protocol */
635c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu	u_int16_t	ip_sum;		/* checksum */
645c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu	struct	in_addr ip_src,ip_dst;	/* source and dest address */
655c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu} UNALIGNED;
665c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
675c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu#define	IP_MAXPACKET	65535		/* maximum packet size */
685c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
695c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu/*
705c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu * Definitions for IP type of service (ip_tos)
715c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu */
725c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu#define	IPTOS_LOWDELAY		0x10
735c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu#define	IPTOS_THROUGHPUT	0x08
745c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu#define	IPTOS_RELIABILITY	0x04
755c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
765c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu/*
775c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu * Definitions for IP precedence (also in ip_tos) (hopefully unused)
785c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu */
795c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu#define	IPTOS_PREC_NETCONTROL		0xe0
805c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu#define	IPTOS_PREC_INTERNETCONTROL	0xc0
815c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu#define	IPTOS_PREC_CRITIC_ECP		0xa0
825c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu#define	IPTOS_PREC_FLASHOVERRIDE	0x80
835c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu#define	IPTOS_PREC_FLASH		0x60
845c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu#define	IPTOS_PREC_IMMEDIATE		0x40
855c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu#define	IPTOS_PREC_PRIORITY		0x20
865c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu#define	IPTOS_PREC_ROUTINE		0x00
875c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
885c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu/*
895c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu * Definitions for options.
905c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu */
915c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu#define	IPOPT_COPIED(o)		((o)&0x80)
925c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu#define	IPOPT_CLASS(o)		((o)&0x60)
93#define	IPOPT_NUMBER(o)		((o)&0x1f)
94
95#define	IPOPT_CONTROL		0x00
96#define	IPOPT_RESERVED1		0x20
97#define	IPOPT_DEBMEAS		0x40
98#define	IPOPT_RESERVED2		0x60
99
100#define	IPOPT_EOL		0		/* end of option list */
101#define	IPOPT_NOP		1		/* no operation */
102
103#define	IPOPT_RR		7		/* record packet route */
104#define	IPOPT_TS		68		/* timestamp */
105#define	IPOPT_RFC1393           82              /* traceroute RFC 1393 */
106#define	IPOPT_SECURITY		130		/* provide s,c,h,tcc */
107#define	IPOPT_LSRR		131		/* loose source route */
108#define	IPOPT_SATID		136		/* satnet id */
109#define	IPOPT_SSRR		137		/* strict source route */
110#define IPOPT_RA                148             /* router-alert, rfc2113 */
111
112/*
113 * Offsets to fields in options other than EOL and NOP.
114 */
115#define	IPOPT_OPTVAL		0		/* option ID */
116#define	IPOPT_OLEN		1		/* option length */
117#define IPOPT_OFFSET		2		/* offset within option */
118#define	IPOPT_MINOFF		4		/* min value of above */
119
120/*
121 * Time stamp option structure.
122 */
123struct	ip_timestamp {
124	u_int8_t	ipt_code;	/* IPOPT_TS */
125	u_int8_t	ipt_len;	/* size of structure (variable) */
126	u_int8_t	ipt_ptr;	/* index of current entry */
127	u_int8_t	ipt_oflwflg;	/* flags, overflow counter */
128#define IPTS_OFLW(ip)	(((ipt)->ipt_oflwflg & 0xf0) >> 4)
129#define IPTS_FLG(ip)	((ipt)->ipt_oflwflg & 0x0f)
130	union ipt_timestamp {
131		u_int32_t ipt_time[1];
132		struct	ipt_ta {
133			struct in_addr ipt_addr;
134			u_int32_t ipt_time;
135		} ipt_ta[1];
136	} ipt_timestamp;
137} UNALIGNED;
138
139/* flag bits for ipt_flg */
140#define	IPOPT_TS_TSONLY		0		/* timestamps only */
141#define	IPOPT_TS_TSANDADDR	1		/* timestamps and addresses */
142#define	IPOPT_TS_PRESPEC	3		/* specified modules only */
143
144/* bits for security (not byte swapped) */
145#define	IPOPT_SECUR_UNCLASS	0x0000
146#define	IPOPT_SECUR_CONFID	0xf135
147#define	IPOPT_SECUR_EFTO	0x789a
148#define	IPOPT_SECUR_MMMM	0xbc4d
149#define	IPOPT_SECUR_RESTR	0xaf13
150#define	IPOPT_SECUR_SECRET	0xd788
151#define	IPOPT_SECUR_TOPSECRET	0x6bc5
152
153/*
154 * Internet implementation parameters.
155 */
156#define	MAXTTL		255		/* maximum time to live (seconds) */
157#define	IPDEFTTL	64		/* default ttl, from RFC 1340 */
158#define	IPFRAGTTL	60		/* time to live for frags, slowhz */
159#define	IPTTLDEC	1		/* subtracted when forwarding */
160
161#define	IP_MSS		576		/* default maximum segment size */
162
163/* in print-ip.c */
164extern int nextproto4_cksum(const struct ip *, const u_int8_t *, u_int, u_int);
165