xref: /dflybsd-src/contrib/tcpdump/ip.h (revision 59c07fbdf8168fa08c76c515186d561b5a92690c)
141c99275SPeter Avalos /*
241c99275SPeter Avalos  * Copyright (c) 1982, 1986, 1993
341c99275SPeter Avalos  *	The Regents of the University of California.  All rights reserved.
441c99275SPeter Avalos  *
541c99275SPeter Avalos  * Redistribution and use in source and binary forms, with or without
641c99275SPeter Avalos  * modification, are permitted provided that the following conditions
741c99275SPeter Avalos  * are met:
841c99275SPeter Avalos  * 1. Redistributions of source code must retain the above copyright
941c99275SPeter Avalos  *    notice, this list of conditions and the following disclaimer.
1041c99275SPeter Avalos  * 2. Redistributions in binary form must reproduce the above copyright
1141c99275SPeter Avalos  *    notice, this list of conditions and the following disclaimer in the
1241c99275SPeter Avalos  *    documentation and/or other materials provided with the distribution.
1341c99275SPeter Avalos  * 3. All advertising materials mentioning features or use of this software
1441c99275SPeter Avalos  *    must display the following acknowledgement:
1541c99275SPeter Avalos  *	This product includes software developed by the University of
1641c99275SPeter Avalos  *	California, Berkeley and its contributors.
1741c99275SPeter Avalos  * 4. Neither the name of the University nor the names of its contributors
1841c99275SPeter Avalos  *    may be used to endorse or promote products derived from this software
1941c99275SPeter Avalos  *    without specific prior written permission.
2041c99275SPeter Avalos  *
2141c99275SPeter Avalos  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2241c99275SPeter Avalos  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2341c99275SPeter Avalos  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2441c99275SPeter Avalos  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2541c99275SPeter Avalos  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2641c99275SPeter Avalos  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2741c99275SPeter Avalos  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2841c99275SPeter Avalos  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2941c99275SPeter Avalos  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3041c99275SPeter Avalos  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3141c99275SPeter Avalos  * SUCH DAMAGE.
3241c99275SPeter Avalos  *
3341c99275SPeter Avalos  *	@(#)ip.h	8.2 (Berkeley) 6/1/94
3441c99275SPeter Avalos  */
3541c99275SPeter Avalos 
36411677aeSAaron LI #ifndef netdissect_ip_h
37411677aeSAaron LI #define netdissect_ip_h
38411677aeSAaron LI 
3941c99275SPeter Avalos /*
4041c99275SPeter Avalos  * Definitions for internet protocol version 4.
4141c99275SPeter Avalos  * Per RFC 791, September 1981.
4241c99275SPeter Avalos  */
4341c99275SPeter Avalos #define	IPVERSION	4
4441c99275SPeter Avalos 
4541c99275SPeter Avalos /*
4641c99275SPeter Avalos  * Structure of an internet header, naked of options.
4741c99275SPeter Avalos  *
4841c99275SPeter Avalos  * We declare ip_len and ip_off to be short, rather than u_short
4941c99275SPeter Avalos  * pragmatically since otherwise unsigned comparisons can result
5041c99275SPeter Avalos  * against negative integers quite easily, and fail in subtle ways.
5141c99275SPeter Avalos  */
5241c99275SPeter Avalos struct ip {
53411677aeSAaron LI 	nd_uint8_t	ip_vhl;		/* header length, version */
54*ed775ee7SAntonio Huete Jimenez #define IP_V(ip)	((GET_U_1((ip)->ip_vhl) & 0xf0) >> 4)
55*ed775ee7SAntonio Huete Jimenez #define IP_HL(ip)	(GET_U_1((ip)->ip_vhl) & 0x0f)
56411677aeSAaron LI 	nd_uint8_t	ip_tos;		/* type of service */
57411677aeSAaron LI 	nd_uint16_t	ip_len;		/* total length */
58411677aeSAaron LI 	nd_uint16_t	ip_id;		/* identification */
59411677aeSAaron LI 	nd_uint16_t	ip_off;		/* fragment offset field */
60*ed775ee7SAntonio Huete Jimenez #define	IP_DF 0x4000			/* don't fragment flag */
6141c99275SPeter Avalos #define	IP_MF 0x2000			/* more fragments flag */
6241c99275SPeter Avalos #define	IP_OFFMASK 0x1fff		/* mask for fragmenting bits */
63411677aeSAaron LI 	nd_uint8_t	ip_ttl;		/* time to live */
64411677aeSAaron LI 	nd_uint8_t	ip_p;		/* protocol */
65411677aeSAaron LI 	nd_uint16_t	ip_sum;		/* checksum */
66411677aeSAaron LI 	nd_ipv4		ip_src,ip_dst;	/* source and dest address */
67411677aeSAaron LI };
6841c99275SPeter Avalos 
6941c99275SPeter Avalos #define	IP_MAXPACKET	65535		/* maximum packet size */
7041c99275SPeter Avalos 
7141c99275SPeter Avalos /*
7241c99275SPeter Avalos  * Definitions for IP type of service (ip_tos)
7341c99275SPeter Avalos  */
7441c99275SPeter Avalos #define	IPTOS_LOWDELAY		0x10
7541c99275SPeter Avalos #define	IPTOS_THROUGHPUT	0x08
7641c99275SPeter Avalos #define	IPTOS_RELIABILITY	0x04
7741c99275SPeter Avalos 
7841c99275SPeter Avalos /*
7941c99275SPeter Avalos  * Definitions for IP precedence (also in ip_tos) (hopefully unused)
8041c99275SPeter Avalos  */
8141c99275SPeter Avalos #define	IPTOS_PREC_NETCONTROL		0xe0
8241c99275SPeter Avalos #define	IPTOS_PREC_INTERNETCONTROL	0xc0
8341c99275SPeter Avalos #define	IPTOS_PREC_CRITIC_ECP		0xa0
8441c99275SPeter Avalos #define	IPTOS_PREC_FLASHOVERRIDE	0x80
8541c99275SPeter Avalos #define	IPTOS_PREC_FLASH		0x60
8641c99275SPeter Avalos #define	IPTOS_PREC_IMMEDIATE		0x40
8741c99275SPeter Avalos #define	IPTOS_PREC_PRIORITY		0x20
8841c99275SPeter Avalos #define	IPTOS_PREC_ROUTINE		0x00
8941c99275SPeter Avalos 
9041c99275SPeter Avalos /*
9141c99275SPeter Avalos  * Definitions for options.
9241c99275SPeter Avalos  */
9341c99275SPeter Avalos #define	IPOPT_COPIED(o)		((o)&0x80)
9441c99275SPeter Avalos #define	IPOPT_CLASS(o)		((o)&0x60)
9541c99275SPeter Avalos #define	IPOPT_NUMBER(o)		((o)&0x1f)
9641c99275SPeter Avalos 
9741c99275SPeter Avalos #define	IPOPT_CONTROL		0x00
9841c99275SPeter Avalos #define	IPOPT_RESERVED1		0x20
9941c99275SPeter Avalos #define	IPOPT_DEBMEAS		0x40
10041c99275SPeter Avalos #define	IPOPT_RESERVED2		0x60
10141c99275SPeter Avalos 
10241c99275SPeter Avalos #define	IPOPT_EOL		0		/* end of option list */
10341c99275SPeter Avalos #define	IPOPT_NOP		1		/* no operation */
10441c99275SPeter Avalos 
10541c99275SPeter Avalos #define	IPOPT_RR		7		/* record packet route */
10641c99275SPeter Avalos #define	IPOPT_TS		68		/* timestamp */
10741c99275SPeter Avalos #define	IPOPT_RFC1393           82              /* traceroute RFC 1393 */
10841c99275SPeter Avalos #define	IPOPT_SECURITY		130		/* provide s,c,h,tcc */
10941c99275SPeter Avalos #define	IPOPT_LSRR		131		/* loose source route */
11041c99275SPeter Avalos #define	IPOPT_SATID		136		/* satnet id */
11141c99275SPeter Avalos #define	IPOPT_SSRR		137		/* strict source route */
11241c99275SPeter Avalos #define IPOPT_RA                148             /* router-alert, rfc2113 */
11341c99275SPeter Avalos 
11441c99275SPeter Avalos /*
11541c99275SPeter Avalos  * Offsets to fields in options other than EOL and NOP.
11641c99275SPeter Avalos  */
11741c99275SPeter Avalos #define	IPOPT_OPTVAL		0		/* option ID */
11841c99275SPeter Avalos #define	IPOPT_OLEN		1		/* option length */
11941c99275SPeter Avalos #define IPOPT_OFFSET		2		/* offset within option */
12041c99275SPeter Avalos #define	IPOPT_MINOFF		4		/* min value of above */
12141c99275SPeter Avalos 
12241c99275SPeter Avalos /*
12341c99275SPeter Avalos  * Time stamp option structure.
12441c99275SPeter Avalos  */
12541c99275SPeter Avalos struct	ip_timestamp {
126411677aeSAaron LI 	nd_uint8_t	ipt_code;	/* IPOPT_TS */
127411677aeSAaron LI 	nd_uint8_t	ipt_len;	/* size of structure (variable) */
128411677aeSAaron LI 	nd_uint8_t	ipt_ptr;	/* index of current entry */
129411677aeSAaron LI 	nd_uint8_t	ipt_oflwflg;	/* flags, overflow counter */
13041c99275SPeter Avalos #define IPTS_OFLW(ip)	(((ipt)->ipt_oflwflg & 0xf0) >> 4)
13141c99275SPeter Avalos #define IPTS_FLG(ip)	((ipt)->ipt_oflwflg & 0x0f)
13241c99275SPeter Avalos 	union ipt_timestamp {
133411677aeSAaron LI 		nd_uint32_t ipt_time[1];
13441c99275SPeter Avalos 		struct	ipt_ta {
135411677aeSAaron LI 			nd_ipv4 ipt_addr;
136411677aeSAaron LI 			nd_uint32_t ipt_time;
13741c99275SPeter Avalos 		} ipt_ta[1];
13841c99275SPeter Avalos 	} ipt_timestamp;
139411677aeSAaron LI };
14041c99275SPeter Avalos 
14141c99275SPeter Avalos /* flag bits for ipt_flg */
14241c99275SPeter Avalos #define	IPOPT_TS_TSONLY		0		/* timestamps only */
14341c99275SPeter Avalos #define	IPOPT_TS_TSANDADDR	1		/* timestamps and addresses */
14441c99275SPeter Avalos #define	IPOPT_TS_PRESPEC	3		/* specified modules only */
14541c99275SPeter Avalos 
14641c99275SPeter Avalos /* bits for security (not byte swapped) */
14741c99275SPeter Avalos #define	IPOPT_SECUR_UNCLASS	0x0000
14841c99275SPeter Avalos #define	IPOPT_SECUR_CONFID	0xf135
14941c99275SPeter Avalos #define	IPOPT_SECUR_EFTO	0x789a
15041c99275SPeter Avalos #define	IPOPT_SECUR_MMMM	0xbc4d
15141c99275SPeter Avalos #define	IPOPT_SECUR_RESTR	0xaf13
15241c99275SPeter Avalos #define	IPOPT_SECUR_SECRET	0xd788
15341c99275SPeter Avalos #define	IPOPT_SECUR_TOPSECRET	0x6bc5
15441c99275SPeter Avalos 
15541c99275SPeter Avalos /*
15641c99275SPeter Avalos  * Internet implementation parameters.
15741c99275SPeter Avalos  */
15841c99275SPeter Avalos #define	MAXTTL		255		/* maximum time to live (seconds) */
15941c99275SPeter Avalos #define	IPDEFTTL	64		/* default ttl, from RFC 1340 */
16041c99275SPeter Avalos #define	IPFRAGTTL	60		/* time to live for frags, slowhz */
16141c99275SPeter Avalos #define	IPTTLDEC	1		/* subtracted when forwarding */
16241c99275SPeter Avalos 
16341c99275SPeter Avalos #define	IP_MSS		576		/* default maximum segment size */
164411677aeSAaron LI #endif /* netdissect_ip_h */
165