xref: /original-bsd/sys/netinet/ip.h (revision bb2d502b)
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.6.1.3 (Berkeley) 02/20/89
18  */
19 #ifndef BYTE_ORDER
20 /*
21  * Definitions for byte order,
22  * according to byte significance from low address to high.
23  */
24 #define	LITTLE_ENDIAN	1234	/* least-significant byte first (vax) */
25 #define	BIG_ENDIAN	4321	/* most-significant byte first (IBM, net) */
26 #define	PDP_ENDIAN	3412	/* LSB first in word, MSW first in long (pdp) */
27 
28 #ifdef vax
29 #define	BYTE_ORDER	LITTLE_ENDIAN
30 #else
31 #define	BYTE_ORDER	BIG_ENDIAN	/* mc68000, tahoe, most others */
32 #endif
33 #endif BYTE_ORDER
34 
35 /*
36  * Definitions for internet protocol version 4.
37  * Per RFC 791, September 1981.
38  */
39 #define	IPVERSION	4
40 
41 /*
42  * Structure of an internet header, naked of options.
43  *
44  * We declare ip_len and ip_off to be short, rather than u_short
45  * pragmatically since otherwise unsigned comparisons can result
46  * against negative integers quite easily, and fail in subtle ways.
47  */
48 struct ip {
49 #if BYTE_ORDER == LITTLE_ENDIAN
50 	u_char	ip_hl:4,		/* header length */
51 		ip_v:4;			/* version */
52 #endif
53 #if BYTE_ORDER == BIG_ENDIAN
54 	u_char	ip_v:4,			/* version */
55 		ip_hl:4;		/* header length */
56 #endif
57 	u_char	ip_tos;			/* type of service */
58 	short	ip_len;			/* total length */
59 	u_short	ip_id;			/* identification */
60 	short	ip_off;			/* fragment offset field */
61 #define	IP_DF 0x4000			/* dont fragment flag */
62 #define	IP_MF 0x2000			/* more fragments flag */
63 	u_char	ip_ttl;			/* time to live */
64 	u_char	ip_p;			/* protocol */
65 	u_short	ip_sum;			/* checksum */
66 	struct	in_addr ip_src,ip_dst;	/* source and dest address */
67 };
68 
69 #define	IP_MAXPACKET	65535		/* maximum packet size */
70 
71 /*
72  * Definitions for options.
73  */
74 #define	IPOPT_COPIED(o)		((o)&0x80)
75 #define	IPOPT_CLASS(o)		((o)&0x60)
76 #define	IPOPT_NUMBER(o)		((o)&0x1f)
77 
78 #define	IPOPT_CONTROL		0x00
79 #define	IPOPT_RESERVED1		0x20
80 #define	IPOPT_DEBMEAS		0x40
81 #define	IPOPT_RESERVED2		0x60
82 
83 #define	IPOPT_EOL		0		/* end of option list */
84 #define	IPOPT_NOP		1		/* no operation */
85 
86 #define	IPOPT_RR		7		/* record packet route */
87 #define	IPOPT_TS		68		/* timestamp */
88 #define	IPOPT_SECURITY		130		/* provide s,c,h,tcc */
89 #define	IPOPT_LSRR		131		/* loose source route */
90 #define	IPOPT_SATID		136		/* satnet id */
91 #define	IPOPT_SSRR		137		/* strict source route */
92 
93 /*
94  * Offsets to fields in options other than EOL and NOP.
95  */
96 #define	IPOPT_OPTVAL		0		/* option ID */
97 #define	IPOPT_OLEN		1		/* option length */
98 #define IPOPT_OFFSET		2		/* offset within option */
99 #define	IPOPT_MINOFF		4		/* min value of above */
100 
101 /*
102  * Time stamp option structure.
103  */
104 struct	ip_timestamp {
105 	u_char	ipt_code;		/* IPOPT_TS */
106 	u_char	ipt_len;		/* size of structure (variable) */
107 	u_char	ipt_ptr;		/* index of current entry */
108 #if BYTE_ORDER == LITTLE_ENDIAN
109 	u_char	ipt_flg:4,		/* flags, see below */
110 		ipt_oflw:4;		/* overflow counter */
111 #endif
112 #if BYTE_ORDER == BIG_ENDIAN
113 	u_char	ipt_oflw:4,		/* overflow counter */
114 		ipt_flg:4;		/* flags, see below */
115 #endif
116 	union ipt_timestamp {
117 		n_long	ipt_time[1];
118 		struct	ipt_ta {
119 			struct in_addr ipt_addr;
120 			n_long ipt_time;
121 		} ipt_ta[1];
122 	} ipt_timestamp;
123 };
124 
125 /* flag bits for ipt_flg */
126 #define	IPOPT_TS_TSONLY		0		/* timestamps only */
127 #define	IPOPT_TS_TSANDADDR	1		/* timestamps and addresses */
128 #define	IPOPT_TS_PRESPEC	3		/* specified modules only */
129 
130 /* bits for security (not byte swapped) */
131 #define	IPOPT_SECUR_UNCLASS	0x0000
132 #define	IPOPT_SECUR_CONFID	0xf135
133 #define	IPOPT_SECUR_EFTO	0x789a
134 #define	IPOPT_SECUR_MMMM	0xbc4d
135 #define	IPOPT_SECUR_RESTR	0xaf13
136 #define	IPOPT_SECUR_SECRET	0xd788
137 #define	IPOPT_SECUR_TOPSECRET	0x6bc5
138 
139 /*
140  * Internet implementation parameters.
141  */
142 #define	MAXTTL		255		/* maximum time to live (seconds) */
143 #define	IPFRAGTTL	60		/* time to live for frags, slowhz */
144 #define	IPTTLDEC	1		/* subtracted when forwarding */
145 
146 #define	IP_MSS		576		/* default maximum segment size */
147