xref: /csrg-svn/sys/netinet/ip.h (revision 44369)
1 /*
2  * Copyright (c) 1982, 1986 Regents of the University of California.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms are permitted
6  * provided that the above copyright notice and this paragraph are
7  * duplicated in all such forms and that any documentation,
8  * advertising materials, and other materials related to such
9  * distribution and use acknowledge that the software was developed
10  * by the University of California, Berkeley.  The name of the
11  * University may not be used to endorse or promote products derived
12  * from this software without specific prior written permission.
13  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
16  *
17  *	@(#)ip.h	7.9 (Berkeley) 06/28/90
18  */
19 
20 /*
21  * Definitions for internet protocol version 4.
22  * Per RFC 791, September 1981.
23  */
24 #define	IPVERSION	4
25 
26 /*
27  * Structure of an internet header, naked of options.
28  *
29  * We declare ip_len and ip_off to be short, rather than u_short
30  * pragmatically since otherwise unsigned comparisons can result
31  * against negative integers quite easily, and fail in subtle ways.
32  */
33 struct ip {
34 #if BYTE_ORDER == LITTLE_ENDIAN
35 	u_char	ip_hl:4,		/* header length */
36 		ip_v:4;			/* version */
37 #endif
38 #if BYTE_ORDER == BIG_ENDIAN
39 	u_char	ip_v:4,			/* version */
40 		ip_hl:4;		/* header length */
41 #endif
42 	u_char	ip_tos;			/* type of service */
43 	short	ip_len;			/* total length */
44 	u_short	ip_id;			/* identification */
45 	short	ip_off;			/* fragment offset field */
46 #define	IP_DF 0x4000			/* dont fragment flag */
47 #define	IP_MF 0x2000			/* more fragments flag */
48 	u_char	ip_ttl;			/* time to live */
49 	u_char	ip_p;			/* protocol */
50 	u_short	ip_sum;			/* checksum */
51 	struct	in_addr ip_src,ip_dst;	/* source and dest address */
52 };
53 
54 #define	IP_MAXPACKET	65535		/* maximum packet size */
55 
56 /*
57  * Definitions for IP type of service (ip_tos)
58  */
59 #define	IPTOS_LOWDELAY		0x10
60 #define	IPTOS_THROUGHPUT	0x08
61 #define	IPTOS_RELIABILITY	0x04
62 
63 /*
64  * Definitions for IP precedence (also in ip_tos) (hopefully unused)
65  */
66 #define	IPTOS_PREC_NETCONTROL		0xe0
67 #define	IPTOS_PREC_INTERNETCONTROL	0xc0
68 #define	IPTOS_PREC_CRITIC_ECP		0xa0
69 #define	IPTOS_PREC_FLASHOVERRIDE	0x80
70 #define	IPTOS_PREC_FLASH		0x60
71 #define	IPTOS_PREC_IMMEDIATE		0x40
72 #define	IPTOS_PREC_PRIORITY		0x20
73 #define	IPTOS_PREC_ROUTINE		0x10
74 
75 /*
76  * Definitions for options.
77  */
78 #define	IPOPT_COPIED(o)		((o)&0x80)
79 #define	IPOPT_CLASS(o)		((o)&0x60)
80 #define	IPOPT_NUMBER(o)		((o)&0x1f)
81 
82 #define	IPOPT_CONTROL		0x00
83 #define	IPOPT_RESERVED1		0x20
84 #define	IPOPT_DEBMEAS		0x40
85 #define	IPOPT_RESERVED2		0x60
86 
87 #define	IPOPT_EOL		0		/* end of option list */
88 #define	IPOPT_NOP		1		/* no operation */
89 
90 #define	IPOPT_RR		7		/* record packet route */
91 #define	IPOPT_TS		68		/* timestamp */
92 #define	IPOPT_SECURITY		130		/* provide s,c,h,tcc */
93 #define	IPOPT_LSRR		131		/* loose source route */
94 #define	IPOPT_SATID		136		/* satnet id */
95 #define	IPOPT_SSRR		137		/* strict source route */
96 
97 /*
98  * Offsets to fields in options other than EOL and NOP.
99  */
100 #define	IPOPT_OPTVAL		0		/* option ID */
101 #define	IPOPT_OLEN		1		/* option length */
102 #define IPOPT_OFFSET		2		/* offset within option */
103 #define	IPOPT_MINOFF		4		/* min value of above */
104 
105 /*
106  * Time stamp option structure.
107  */
108 struct	ip_timestamp {
109 	u_char	ipt_code;		/* IPOPT_TS */
110 	u_char	ipt_len;		/* size of structure (variable) */
111 	u_char	ipt_ptr;		/* index of current entry */
112 #if BYTE_ORDER == LITTLE_ENDIAN
113 	u_char	ipt_flg:4,		/* flags, see below */
114 		ipt_oflw:4;		/* overflow counter */
115 #endif
116 #if BYTE_ORDER == BIG_ENDIAN
117 	u_char	ipt_oflw:4,		/* overflow counter */
118 		ipt_flg:4;		/* flags, see below */
119 #endif
120 	union ipt_timestamp {
121 		n_long	ipt_time[1];
122 		struct	ipt_ta {
123 			struct in_addr ipt_addr;
124 			n_long ipt_time;
125 		} ipt_ta[1];
126 	} ipt_timestamp;
127 };
128 
129 /* flag bits for ipt_flg */
130 #define	IPOPT_TS_TSONLY		0		/* timestamps only */
131 #define	IPOPT_TS_TSANDADDR	1		/* timestamps and addresses */
132 #define	IPOPT_TS_PRESPEC	3		/* specified modules only */
133 
134 /* bits for security (not byte swapped) */
135 #define	IPOPT_SECUR_UNCLASS	0x0000
136 #define	IPOPT_SECUR_CONFID	0xf135
137 #define	IPOPT_SECUR_EFTO	0x789a
138 #define	IPOPT_SECUR_MMMM	0xbc4d
139 #define	IPOPT_SECUR_RESTR	0xaf13
140 #define	IPOPT_SECUR_SECRET	0xd788
141 #define	IPOPT_SECUR_TOPSECRET	0x6bc5
142 
143 /*
144  * Internet implementation parameters.
145  */
146 #define	MAXTTL		255		/* maximum time to live (seconds) */
147 #define	IPFRAGTTL	60		/* time to live for frags, slowhz */
148 #define	IPTTLDEC	1		/* subtracted when forwarding */
149 
150 #define	IP_MSS		576		/* default maximum segment size */
151