xref: /netbsd-src/external/bsd/tcpdump/dist/ip.h (revision 26ba0b503b498a5194a71ac319838b7f5497f3fe)
10f74e101Schristos /*
20f74e101Schristos  * Copyright (c) 1982, 1986, 1993
30f74e101Schristos  *	The Regents of the University of California.  All rights reserved.
40f74e101Schristos  *
50f74e101Schristos  * Redistribution and use in source and binary forms, with or without
60f74e101Schristos  * modification, are permitted provided that the following conditions
70f74e101Schristos  * are met:
80f74e101Schristos  * 1. Redistributions of source code must retain the above copyright
90f74e101Schristos  *    notice, this list of conditions and the following disclaimer.
100f74e101Schristos  * 2. Redistributions in binary form must reproduce the above copyright
110f74e101Schristos  *    notice, this list of conditions and the following disclaimer in the
120f74e101Schristos  *    documentation and/or other materials provided with the distribution.
1311b3aaa1Schristos  * 3. Neither the name of the University nor the names of its contributors
140f74e101Schristos  *    may be used to endorse or promote products derived from this software
150f74e101Schristos  *    without specific prior written permission.
160f74e101Schristos  *
170f74e101Schristos  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
180f74e101Schristos  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
190f74e101Schristos  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
200f74e101Schristos  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
210f74e101Schristos  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
220f74e101Schristos  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
230f74e101Schristos  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
240f74e101Schristos  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
250f74e101Schristos  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
260f74e101Schristos  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
270f74e101Schristos  * SUCH DAMAGE.
280f74e101Schristos  *
290f74e101Schristos  *	@(#)ip.h	8.2 (Berkeley) 6/1/94
300f74e101Schristos  */
310f74e101Schristos 
32fdccd7e4Schristos #ifndef netdissect_ip_h
33fdccd7e4Schristos #define netdissect_ip_h
34ba2ff121Schristos 
350f74e101Schristos /*
360f74e101Schristos  * Definitions for internet protocol version 4.
370f74e101Schristos  * Per RFC 791, September 1981.
380f74e101Schristos  */
390f74e101Schristos #define	IPVERSION	4
400f74e101Schristos 
410f74e101Schristos /*
420f74e101Schristos  * Structure of an internet header, naked of options.
430f74e101Schristos  *
440f74e101Schristos  * We declare ip_len and ip_off to be short, rather than u_short
450f74e101Schristos  * pragmatically since otherwise unsigned comparisons can result
460f74e101Schristos  * against negative integers quite easily, and fail in subtle ways.
470f74e101Schristos  */
480f74e101Schristos struct ip {
49fdccd7e4Schristos 	nd_uint8_t	ip_vhl;		/* header length, version */
50*c74ad251Schristos #define IP_V(ip)	((GET_U_1((ip)->ip_vhl) & 0xf0) >> 4)
51*c74ad251Schristos #define IP_HL(ip)	(GET_U_1((ip)->ip_vhl) & 0x0f)
52fdccd7e4Schristos 	nd_uint8_t	ip_tos;		/* type of service */
53fdccd7e4Schristos 	nd_uint16_t	ip_len;		/* total length */
54fdccd7e4Schristos 	nd_uint16_t	ip_id;		/* identification */
55fdccd7e4Schristos 	nd_uint16_t	ip_off;		/* fragment offset field */
56*c74ad251Schristos #define	IP_DF 0x4000			/* don't fragment flag */
570f74e101Schristos #define	IP_MF 0x2000			/* more fragments flag */
580f74e101Schristos #define	IP_OFFMASK 0x1fff		/* mask for fragmenting bits */
59fdccd7e4Schristos 	nd_uint8_t	ip_ttl;		/* time to live */
60fdccd7e4Schristos 	nd_uint8_t	ip_p;		/* protocol */
61fdccd7e4Schristos 	nd_uint16_t	ip_sum;		/* checksum */
62fdccd7e4Schristos 	nd_ipv4		ip_src,ip_dst;	/* source and dest address */
63fdccd7e4Schristos };
640f74e101Schristos 
650f74e101Schristos #define	IP_MAXPACKET	65535		/* maximum packet size */
660f74e101Schristos 
670f74e101Schristos /*
680f74e101Schristos  * Definitions for IP type of service (ip_tos)
690f74e101Schristos  */
700f74e101Schristos #define	IPTOS_LOWDELAY		0x10
710f74e101Schristos #define	IPTOS_THROUGHPUT	0x08
720f74e101Schristos #define	IPTOS_RELIABILITY	0x04
730f74e101Schristos 
740f74e101Schristos /*
750f74e101Schristos  * Definitions for IP precedence (also in ip_tos) (hopefully unused)
760f74e101Schristos  */
770f74e101Schristos #define	IPTOS_PREC_NETCONTROL		0xe0
780f74e101Schristos #define	IPTOS_PREC_INTERNETCONTROL	0xc0
790f74e101Schristos #define	IPTOS_PREC_CRITIC_ECP		0xa0
800f74e101Schristos #define	IPTOS_PREC_FLASHOVERRIDE	0x80
810f74e101Schristos #define	IPTOS_PREC_FLASH		0x60
820f74e101Schristos #define	IPTOS_PREC_IMMEDIATE		0x40
830f74e101Schristos #define	IPTOS_PREC_PRIORITY		0x20
840f74e101Schristos #define	IPTOS_PREC_ROUTINE		0x00
850f74e101Schristos 
860f74e101Schristos /*
870f74e101Schristos  * Definitions for options.
880f74e101Schristos  */
890f74e101Schristos #define	IPOPT_COPIED(o)		((o)&0x80)
900f74e101Schristos #define	IPOPT_CLASS(o)		((o)&0x60)
910f74e101Schristos #define	IPOPT_NUMBER(o)		((o)&0x1f)
920f74e101Schristos 
930f74e101Schristos #define	IPOPT_CONTROL		0x00
940f74e101Schristos #define	IPOPT_RESERVED1		0x20
950f74e101Schristos #define	IPOPT_DEBMEAS		0x40
960f74e101Schristos #define	IPOPT_RESERVED2		0x60
970f74e101Schristos 
980f74e101Schristos #define	IPOPT_EOL		0		/* end of option list */
990f74e101Schristos #define	IPOPT_NOP		1		/* no operation */
1000f74e101Schristos 
1010f74e101Schristos #define	IPOPT_RR		7		/* record packet route */
1020f74e101Schristos #define	IPOPT_TS		68		/* timestamp */
1030f74e101Schristos #define	IPOPT_RFC1393           82              /* traceroute RFC 1393 */
1040f74e101Schristos #define	IPOPT_SECURITY		130		/* provide s,c,h,tcc */
1050f74e101Schristos #define	IPOPT_LSRR		131		/* loose source route */
1060f74e101Schristos #define	IPOPT_SSRR		137		/* strict source route */
1070f74e101Schristos #define IPOPT_RA                148             /* router-alert, rfc2113 */
1080f74e101Schristos 
1090f74e101Schristos /*
1100f74e101Schristos  * Offsets to fields in options other than EOL and NOP.
1110f74e101Schristos  */
1120f74e101Schristos #define	IPOPT_OPTVAL		0		/* option ID */
1130f74e101Schristos #define	IPOPT_OLEN		1		/* option length */
1140f74e101Schristos #define IPOPT_OFFSET		2		/* offset within option */
1150f74e101Schristos #define	IPOPT_MINOFF		4		/* min value of above */
1160f74e101Schristos 
1170f74e101Schristos /*
1180f74e101Schristos  * Time stamp option structure.
1190f74e101Schristos  */
1200f74e101Schristos struct	ip_timestamp {
121fdccd7e4Schristos 	nd_uint8_t	ipt_code;	/* IPOPT_TS */
122fdccd7e4Schristos 	nd_uint8_t	ipt_len;	/* size of structure (variable) */
123fdccd7e4Schristos 	nd_uint8_t	ipt_ptr;	/* index of current entry */
124fdccd7e4Schristos 	nd_uint8_t	ipt_oflwflg;	/* flags, overflow counter */
1250f74e101Schristos #define IPTS_OFLW(ip)	(((ipt)->ipt_oflwflg & 0xf0) >> 4)
1260f74e101Schristos #define IPTS_FLG(ip)	((ipt)->ipt_oflwflg & 0x0f)
1270f74e101Schristos 	union ipt_timestamp {
128fdccd7e4Schristos 		nd_uint32_t ipt_time[1];
1290f74e101Schristos 		struct	ipt_ta {
130fdccd7e4Schristos 			nd_ipv4 ipt_addr;
131fdccd7e4Schristos 			nd_uint32_t ipt_time;
1320f74e101Schristos 		} ipt_ta[1];
1330f74e101Schristos 	} ipt_timestamp;
134fdccd7e4Schristos };
1350f74e101Schristos 
1360f74e101Schristos /* flag bits for ipt_flg */
1370f74e101Schristos #define	IPOPT_TS_TSONLY		0		/* timestamps only */
1380f74e101Schristos #define	IPOPT_TS_TSANDADDR	1		/* timestamps and addresses */
1390f74e101Schristos #define	IPOPT_TS_PRESPEC	3		/* specified modules only */
1400f74e101Schristos 
1410f74e101Schristos /* bits for security (not byte swapped) */
1420f74e101Schristos #define	IPOPT_SECUR_UNCLASS	0x0000
1430f74e101Schristos #define	IPOPT_SECUR_CONFID	0xf135
1440f74e101Schristos #define	IPOPT_SECUR_EFTO	0x789a
1450f74e101Schristos #define	IPOPT_SECUR_MMMM	0xbc4d
1460f74e101Schristos #define	IPOPT_SECUR_RESTR	0xaf13
1470f74e101Schristos #define	IPOPT_SECUR_SECRET	0xd788
1480f74e101Schristos #define	IPOPT_SECUR_TOPSECRET	0x6bc5
1490f74e101Schristos 
1500f74e101Schristos /*
1510f74e101Schristos  * Internet implementation parameters.
1520f74e101Schristos  */
1530f74e101Schristos #define	MAXTTL		255		/* maximum time to live (seconds) */
1540f74e101Schristos #define	IPDEFTTL	64		/* default ttl, from RFC 1340 */
1550f74e101Schristos #define	IPFRAGTTL	60		/* time to live for frags, slowhz */
1560f74e101Schristos #define	IPTTLDEC	1		/* subtracted when forwarding */
1570f74e101Schristos 
1580f74e101Schristos #define	IP_MSS		576		/* default maximum segment size */
159fdccd7e4Schristos #endif /* netdissect_ip_h */
160