xref: /csrg-svn/sys/netinet/ip.h (revision 36842)
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*36842Skarels  *	@(#)ip.h	7.8 (Berkeley) 02/20/89
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 /*
574662Swnj  * Definitions for options.
584571Swnj  */
594662Swnj #define	IPOPT_COPIED(o)		((o)&0x80)
6016051Skarels #define	IPOPT_CLASS(o)		((o)&0x60)
6116051Skarels #define	IPOPT_NUMBER(o)		((o)&0x1f)
624662Swnj 
634662Swnj #define	IPOPT_CONTROL		0x00
6416051Skarels #define	IPOPT_RESERVED1		0x20
6516051Skarels #define	IPOPT_DEBMEAS		0x40
6616051Skarels #define	IPOPT_RESERVED2		0x60
674662Swnj 
684662Swnj #define	IPOPT_EOL		0		/* end of option list */
694662Swnj #define	IPOPT_NOP		1		/* no operation */
704662Swnj 
714662Swnj #define	IPOPT_RR		7		/* record packet route */
724662Swnj #define	IPOPT_TS		68		/* timestamp */
734662Swnj #define	IPOPT_SECURITY		130		/* provide s,c,h,tcc */
744662Swnj #define	IPOPT_LSRR		131		/* loose source route */
754662Swnj #define	IPOPT_SATID		136		/* satnet id */
764662Swnj #define	IPOPT_SSRR		137		/* strict source route */
774662Swnj 
784662Swnj /*
7924810Skarels  * Offsets to fields in options other than EOL and NOP.
8024810Skarels  */
8124810Skarels #define	IPOPT_OPTVAL		0		/* option ID */
8224810Skarels #define	IPOPT_OLEN		1		/* option length */
8324810Skarels #define IPOPT_OFFSET		2		/* offset within option */
8424810Skarels #define	IPOPT_MINOFF		4		/* min value of above */
8524810Skarels 
8624810Skarels /*
874662Swnj  * Time stamp option structure.
884662Swnj  */
894662Swnj struct	ip_timestamp {
904662Swnj 	u_char	ipt_code;		/* IPOPT_TS */
914662Swnj 	u_char	ipt_len;		/* size of structure (variable) */
924662Swnj 	u_char	ipt_ptr;		/* index of current entry */
9333283Skarels #if BYTE_ORDER == LITTLE_ENDIAN
944662Swnj 	u_char	ipt_flg:4,		/* flags, see below */
954662Swnj 		ipt_oflw:4;		/* overflow counter */
9629923Skarels #endif
9733283Skarels #if BYTE_ORDER == BIG_ENDIAN
9829923Skarels 	u_char	ipt_oflw:4,		/* overflow counter */
9929923Skarels 		ipt_flg:4;		/* flags, see below */
10029923Skarels #endif
10133283Skarels 	union ipt_timestamp {
1024662Swnj 		n_long	ipt_time[1];
1034662Swnj 		struct	ipt_ta {
1044923Swnj 			struct in_addr ipt_addr;
1054662Swnj 			n_long ipt_time;
1064662Swnj 		} ipt_ta[1];
10733283Skarels 	} ipt_timestamp;
1084662Swnj };
1094662Swnj 
1104662Swnj /* flag bits for ipt_flg */
1114662Swnj #define	IPOPT_TS_TSONLY		0		/* timestamps only */
1124662Swnj #define	IPOPT_TS_TSANDADDR	1		/* timestamps and addresses */
113*36842Skarels #define	IPOPT_TS_PRESPEC	3		/* specified modules only */
1144662Swnj 
1154662Swnj /* bits for security (not byte swapped) */
1164662Swnj #define	IPOPT_SECUR_UNCLASS	0x0000
1174662Swnj #define	IPOPT_SECUR_CONFID	0xf135
1184662Swnj #define	IPOPT_SECUR_EFTO	0x789a
1194662Swnj #define	IPOPT_SECUR_MMMM	0xbc4d
1204662Swnj #define	IPOPT_SECUR_RESTR	0xaf13
1214662Swnj #define	IPOPT_SECUR_SECRET	0xd788
1224662Swnj #define	IPOPT_SECUR_TOPSECRET	0x6bc5
1234662Swnj 
1244662Swnj /*
1254662Swnj  * Internet implementation parameters.
1264662Swnj  */
1274571Swnj #define	MAXTTL		255		/* maximum time to live (seconds) */
12830291Skarels #define	IPFRAGTTL	60		/* time to live for frags, slowhz */
12916523Skarels #define	IPTTLDEC	1		/* subtracted when forwarding */
13017272Skarels 
13117272Skarels #define	IP_MSS		576		/* default maximum segment size */
132