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