xref: /csrg-svn/sys/netinet/ip.h (revision 44369)
123181Smckusick /*
229140Smckusick  * Copyright (c) 1982, 1986 Regents of the University of California.
332787Sbostic  * All rights reserved.
423181Smckusick  *
532787Sbostic  * Redistribution and use in source and binary forms are permitted
634854Sbostic  * provided that the above copyright notice and this paragraph are
734854Sbostic  * duplicated in all such forms and that any documentation,
834854Sbostic  * advertising materials, and other materials related to such
934854Sbostic  * distribution and use acknowledge that the software was developed
1034854Sbostic  * by the University of California, Berkeley.  The name of the
1134854Sbostic  * University may not be used to endorse or promote products derived
1234854Sbostic  * from this software without specific prior written permission.
1334854Sbostic  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
1434854Sbostic  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
1534854Sbostic  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
1632787Sbostic  *
17*44369Skarels  *	@(#)ip.h	7.9 (Berkeley) 06/28/90
1823181Smckusick  */
194571Swnj 
204662Swnj /*
214662Swnj  * Definitions for internet protocol version 4.
224662Swnj  * Per RFC 791, September 1981.
234662Swnj  */
244662Swnj #define	IPVERSION	4
254662Swnj 
264662Swnj /*
274662Swnj  * Structure of an internet header, naked of options.
284662Swnj  *
294884Swnj  * We declare ip_len and ip_off to be short, rather than u_short
304884Swnj  * pragmatically since otherwise unsigned comparisons can result
314884Swnj  * against negative integers quite easily, and fail in subtle ways.
324662Swnj  */
334571Swnj struct ip {
3433283Skarels #if BYTE_ORDER == LITTLE_ENDIAN
354571Swnj 	u_char	ip_hl:4,		/* header length */
364571Swnj 		ip_v:4;			/* version */
379991Ssam #endif
3833283Skarels #if BYTE_ORDER == BIG_ENDIAN
3929923Skarels 	u_char	ip_v:4,			/* version */
4029923Skarels 		ip_hl:4;		/* header length */
4129923Skarels #endif
424571Swnj 	u_char	ip_tos;			/* type of service */
434647Swnj 	short	ip_len;			/* total length */
444571Swnj 	u_short	ip_id;			/* identification */
454647Swnj 	short	ip_off;			/* fragment offset field */
464662Swnj #define	IP_DF 0x4000			/* dont fragment flag */
474662Swnj #define	IP_MF 0x2000			/* more fragments flag */
484571Swnj 	u_char	ip_ttl;			/* time to live */
494571Swnj 	u_char	ip_p;			/* protocol */
504571Swnj 	u_short	ip_sum;			/* checksum */
514923Swnj 	struct	in_addr ip_src,ip_dst;	/* source and dest address */
524498Swnj };
534498Swnj 
5433518Skarels #define	IP_MAXPACKET	65535		/* maximum packet size */
5533518Skarels 
564571Swnj /*
57*44369Skarels  * Definitions for IP type of service (ip_tos)
58*44369Skarels  */
59*44369Skarels #define	IPTOS_LOWDELAY		0x10
60*44369Skarels #define	IPTOS_THROUGHPUT	0x08
61*44369Skarels #define	IPTOS_RELIABILITY	0x04
62*44369Skarels 
63*44369Skarels /*
64*44369Skarels  * Definitions for IP precedence (also in ip_tos) (hopefully unused)
65*44369Skarels  */
66*44369Skarels #define	IPTOS_PREC_NETCONTROL		0xe0
67*44369Skarels #define	IPTOS_PREC_INTERNETCONTROL	0xc0
68*44369Skarels #define	IPTOS_PREC_CRITIC_ECP		0xa0
69*44369Skarels #define	IPTOS_PREC_FLASHOVERRIDE	0x80
70*44369Skarels #define	IPTOS_PREC_FLASH		0x60
71*44369Skarels #define	IPTOS_PREC_IMMEDIATE		0x40
72*44369Skarels #define	IPTOS_PREC_PRIORITY		0x20
73*44369Skarels #define	IPTOS_PREC_ROUTINE		0x10
74*44369Skarels 
75*44369Skarels /*
764662Swnj  * Definitions for options.
774571Swnj  */
784662Swnj #define	IPOPT_COPIED(o)		((o)&0x80)
7916051Skarels #define	IPOPT_CLASS(o)		((o)&0x60)
8016051Skarels #define	IPOPT_NUMBER(o)		((o)&0x1f)
814662Swnj 
824662Swnj #define	IPOPT_CONTROL		0x00
8316051Skarels #define	IPOPT_RESERVED1		0x20
8416051Skarels #define	IPOPT_DEBMEAS		0x40
8516051Skarels #define	IPOPT_RESERVED2		0x60
864662Swnj 
874662Swnj #define	IPOPT_EOL		0		/* end of option list */
884662Swnj #define	IPOPT_NOP		1		/* no operation */
894662Swnj 
904662Swnj #define	IPOPT_RR		7		/* record packet route */
914662Swnj #define	IPOPT_TS		68		/* timestamp */
924662Swnj #define	IPOPT_SECURITY		130		/* provide s,c,h,tcc */
934662Swnj #define	IPOPT_LSRR		131		/* loose source route */
944662Swnj #define	IPOPT_SATID		136		/* satnet id */
954662Swnj #define	IPOPT_SSRR		137		/* strict source route */
964662Swnj 
974662Swnj /*
9824810Skarels  * Offsets to fields in options other than EOL and NOP.
9924810Skarels  */
10024810Skarels #define	IPOPT_OPTVAL		0		/* option ID */
10124810Skarels #define	IPOPT_OLEN		1		/* option length */
10224810Skarels #define IPOPT_OFFSET		2		/* offset within option */
10324810Skarels #define	IPOPT_MINOFF		4		/* min value of above */
10424810Skarels 
10524810Skarels /*
1064662Swnj  * Time stamp option structure.
1074662Swnj  */
1084662Swnj struct	ip_timestamp {
1094662Swnj 	u_char	ipt_code;		/* IPOPT_TS */
1104662Swnj 	u_char	ipt_len;		/* size of structure (variable) */
1114662Swnj 	u_char	ipt_ptr;		/* index of current entry */
11233283Skarels #if BYTE_ORDER == LITTLE_ENDIAN
1134662Swnj 	u_char	ipt_flg:4,		/* flags, see below */
1144662Swnj 		ipt_oflw:4;		/* overflow counter */
11529923Skarels #endif
11633283Skarels #if BYTE_ORDER == BIG_ENDIAN
11729923Skarels 	u_char	ipt_oflw:4,		/* overflow counter */
11829923Skarels 		ipt_flg:4;		/* flags, see below */
11929923Skarels #endif
12033283Skarels 	union ipt_timestamp {
1214662Swnj 		n_long	ipt_time[1];
1224662Swnj 		struct	ipt_ta {
1234923Swnj 			struct in_addr ipt_addr;
1244662Swnj 			n_long ipt_time;
1254662Swnj 		} ipt_ta[1];
12633283Skarels 	} ipt_timestamp;
1274662Swnj };
1284662Swnj 
1294662Swnj /* flag bits for ipt_flg */
1304662Swnj #define	IPOPT_TS_TSONLY		0		/* timestamps only */
1314662Swnj #define	IPOPT_TS_TSANDADDR	1		/* timestamps and addresses */
13236842Skarels #define	IPOPT_TS_PRESPEC	3		/* specified modules only */
1334662Swnj 
1344662Swnj /* bits for security (not byte swapped) */
1354662Swnj #define	IPOPT_SECUR_UNCLASS	0x0000
1364662Swnj #define	IPOPT_SECUR_CONFID	0xf135
1374662Swnj #define	IPOPT_SECUR_EFTO	0x789a
1384662Swnj #define	IPOPT_SECUR_MMMM	0xbc4d
1394662Swnj #define	IPOPT_SECUR_RESTR	0xaf13
1404662Swnj #define	IPOPT_SECUR_SECRET	0xd788
1414662Swnj #define	IPOPT_SECUR_TOPSECRET	0x6bc5
1424662Swnj 
1434662Swnj /*
1444662Swnj  * Internet implementation parameters.
1454662Swnj  */
1464571Swnj #define	MAXTTL		255		/* maximum time to live (seconds) */
14730291Skarels #define	IPFRAGTTL	60		/* time to live for frags, slowhz */
14816523Skarels #define	IPTTLDEC	1		/* subtracted when forwarding */
14917272Skarels 
15017272Skarels #define	IP_MSS		576		/* default maximum segment size */
151