xref: /illumos-gate/usr/src/uts/common/netinet/ip.h (revision 2d6eb4a5e0a47d30189497241345dc5466bb68ab)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
3*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
4*7c478bd9Sstevel@tonic-gate  */
5*7c478bd9Sstevel@tonic-gate 
6*7c478bd9Sstevel@tonic-gate /*
7*7c478bd9Sstevel@tonic-gate  * Copyright (c) 1982, 1986 Regents of the University of California.
8*7c478bd9Sstevel@tonic-gate  * All rights reserved.
9*7c478bd9Sstevel@tonic-gate  *
10*7c478bd9Sstevel@tonic-gate  * Redistribution and use in source and binary forms are permitted
11*7c478bd9Sstevel@tonic-gate  * provided that this notice is preserved and that due credit is given
12*7c478bd9Sstevel@tonic-gate  * to the University of California at Berkeley. The name of the University
13*7c478bd9Sstevel@tonic-gate  * may not be used to endorse or promote products derived from this
14*7c478bd9Sstevel@tonic-gate  * software without specific prior written permission. This software
15*7c478bd9Sstevel@tonic-gate  * is provided ``as is'' without express or implied warranty.
16*7c478bd9Sstevel@tonic-gate  */
17*7c478bd9Sstevel@tonic-gate 
18*7c478bd9Sstevel@tonic-gate /*
19*7c478bd9Sstevel@tonic-gate  * Definitions for internet protocol version 4.
20*7c478bd9Sstevel@tonic-gate  * Per RFC 791, September 1981.
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate 
23*7c478bd9Sstevel@tonic-gate #ifndef	_NETINET_IP_H
24*7c478bd9Sstevel@tonic-gate #define	_NETINET_IP_H
25*7c478bd9Sstevel@tonic-gate 
26*7c478bd9Sstevel@tonic-gate /* ip.h 1.13 88/08/19 SMI; from UCB 7.6.1.1 3/15/88	*/
27*7c478bd9Sstevel@tonic-gate 
28*7c478bd9Sstevel@tonic-gate #include <sys/isa_defs.h>
29*7c478bd9Sstevel@tonic-gate 
30*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
31*7c478bd9Sstevel@tonic-gate extern "C" {
32*7c478bd9Sstevel@tonic-gate #endif
33*7c478bd9Sstevel@tonic-gate 
34*7c478bd9Sstevel@tonic-gate #define	IPVERSION	4
35*7c478bd9Sstevel@tonic-gate 
36*7c478bd9Sstevel@tonic-gate /*
37*7c478bd9Sstevel@tonic-gate  * Structure of an internet header, naked of options.
38*7c478bd9Sstevel@tonic-gate  */
39*7c478bd9Sstevel@tonic-gate struct ip {
40*7c478bd9Sstevel@tonic-gate #ifdef _BIT_FIELDS_LTOH
41*7c478bd9Sstevel@tonic-gate 	uchar_t	ip_hl:4,		/* header length */
42*7c478bd9Sstevel@tonic-gate 		ip_v:4;			/* version */
43*7c478bd9Sstevel@tonic-gate #else
44*7c478bd9Sstevel@tonic-gate 	uchar_t	ip_v:4,			/* version */
45*7c478bd9Sstevel@tonic-gate 		ip_hl:4;		/* header length */
46*7c478bd9Sstevel@tonic-gate #endif
47*7c478bd9Sstevel@tonic-gate 	uchar_t	ip_tos;			/* type of service */
48*7c478bd9Sstevel@tonic-gate 	ushort_t ip_len;		/* total length */
49*7c478bd9Sstevel@tonic-gate 	ushort_t ip_id;			/* identification */
50*7c478bd9Sstevel@tonic-gate 	ushort_t ip_off;		/* fragment offset field */
51*7c478bd9Sstevel@tonic-gate #define	IP_DF 0x4000			/* dont fragment flag */
52*7c478bd9Sstevel@tonic-gate #define	IP_MF 0x2000			/* more fragments flag */
53*7c478bd9Sstevel@tonic-gate 	uchar_t	ip_ttl;			/* time to live */
54*7c478bd9Sstevel@tonic-gate 	uchar_t	ip_p;			/* protocol */
55*7c478bd9Sstevel@tonic-gate 	ushort_t ip_sum;		/* checksum */
56*7c478bd9Sstevel@tonic-gate 	struct	in_addr ip_src, ip_dst;	/* source and dest address */
57*7c478bd9Sstevel@tonic-gate };
58*7c478bd9Sstevel@tonic-gate 
59*7c478bd9Sstevel@tonic-gate #define	IP_MAXPACKET	65535		/* maximum packet size */
60*7c478bd9Sstevel@tonic-gate 
61*7c478bd9Sstevel@tonic-gate /*
62*7c478bd9Sstevel@tonic-gate  * Definitions for IP type of service (ip_tos)
63*7c478bd9Sstevel@tonic-gate  */
64*7c478bd9Sstevel@tonic-gate #define	IPTOS_LOWDELAY		0x10
65*7c478bd9Sstevel@tonic-gate #define	IPTOS_THROUGHPUT	0x08
66*7c478bd9Sstevel@tonic-gate #define	IPTOS_RELIABILITY	0x04
67*7c478bd9Sstevel@tonic-gate #define	IPTOS_ECT		0x02	/* ECN-Capable Transport flag */
68*7c478bd9Sstevel@tonic-gate #define	IPTOS_CE		0x01	/* ECN-Congestion Experienced flag */
69*7c478bd9Sstevel@tonic-gate 
70*7c478bd9Sstevel@tonic-gate /*
71*7c478bd9Sstevel@tonic-gate  * Definitions for IP precedence (also in ip_tos) (hopefully unused)
72*7c478bd9Sstevel@tonic-gate  */
73*7c478bd9Sstevel@tonic-gate #define	IPTOS_PREC_NETCONTROL		0xe0
74*7c478bd9Sstevel@tonic-gate #define	IPTOS_PREC_INTERNETCONTROL	0xc0
75*7c478bd9Sstevel@tonic-gate #define	IPTOS_PREC_CRITIC_ECP		0xa0
76*7c478bd9Sstevel@tonic-gate #define	IPTOS_PREC_FLASHOVERRIDE	0x80
77*7c478bd9Sstevel@tonic-gate #define	IPTOS_PREC_FLASH		0x60
78*7c478bd9Sstevel@tonic-gate #define	IPTOS_PREC_IMMEDIATE		0x40
79*7c478bd9Sstevel@tonic-gate #define	IPTOS_PREC_PRIORITY		0x20
80*7c478bd9Sstevel@tonic-gate #define	IPTOS_PREC_ROUTINE		0x00
81*7c478bd9Sstevel@tonic-gate 
82*7c478bd9Sstevel@tonic-gate /*
83*7c478bd9Sstevel@tonic-gate  * Definitions for options.
84*7c478bd9Sstevel@tonic-gate  */
85*7c478bd9Sstevel@tonic-gate 
86*7c478bd9Sstevel@tonic-gate /* Bits in the option value */
87*7c478bd9Sstevel@tonic-gate #define	IPOPT_COPY		0x80
88*7c478bd9Sstevel@tonic-gate 
89*7c478bd9Sstevel@tonic-gate #define	IPOPT_COPIED(o)		((o)&0x80)
90*7c478bd9Sstevel@tonic-gate #define	IPOPT_CLASS(o)		((o)&0x60)
91*7c478bd9Sstevel@tonic-gate #define	IPOPT_NUMBER(o)		((o)&0x1f)
92*7c478bd9Sstevel@tonic-gate 
93*7c478bd9Sstevel@tonic-gate #define	IPOPT_CONTROL		0x00
94*7c478bd9Sstevel@tonic-gate #define	IPOPT_RESERVED1		0x20
95*7c478bd9Sstevel@tonic-gate #define	IPOPT_DEBMEAS		0x40
96*7c478bd9Sstevel@tonic-gate #define	IPOPT_RESERVED2		0x60
97*7c478bd9Sstevel@tonic-gate 
98*7c478bd9Sstevel@tonic-gate #define	IPOPT_EOL		0x00		/* end of option list */
99*7c478bd9Sstevel@tonic-gate #define	IPOPT_NOP		0x01		/* no operation */
100*7c478bd9Sstevel@tonic-gate 
101*7c478bd9Sstevel@tonic-gate #define	IPOPT_RR		0x07		/* record packet route */
102*7c478bd9Sstevel@tonic-gate #define	IPOPT_RTRALERT		0x14		/* router alert */
103*7c478bd9Sstevel@tonic-gate #define	IPOPT_TS		0x44		/* timestamp */
104*7c478bd9Sstevel@tonic-gate #define	IPOPT_SECURITY		0x82		/* provide s,c,h,tcc */
105*7c478bd9Sstevel@tonic-gate #define	IPOPT_LSRR		0x83		/* loose source route */
106*7c478bd9Sstevel@tonic-gate #define	IPOPT_EXTSEC		0x85
107*7c478bd9Sstevel@tonic-gate #define	IPOPT_COMSEC		0x86
108*7c478bd9Sstevel@tonic-gate #define	IPOPT_SATID		0x88		/* satnet id */
109*7c478bd9Sstevel@tonic-gate #define	IPOPT_SSRR		0x89		/* strict source route */
110*7c478bd9Sstevel@tonic-gate #define	IPOPT_RA		0x94
111*7c478bd9Sstevel@tonic-gate #define	IPOPT_SDMDD		0x95
112*7c478bd9Sstevel@tonic-gate 
113*7c478bd9Sstevel@tonic-gate /*
114*7c478bd9Sstevel@tonic-gate  * Offsets to fields in options other than EOL and NOP.
115*7c478bd9Sstevel@tonic-gate  */
116*7c478bd9Sstevel@tonic-gate #define	IPOPT_OPTVAL		0		/* option ID */
117*7c478bd9Sstevel@tonic-gate #define	IPOPT_OLEN		1		/* option length */
118*7c478bd9Sstevel@tonic-gate #define	IPOPT_OFFSET		2		/* offset within option */
119*7c478bd9Sstevel@tonic-gate #define	IPOPT_POS_OV_FLG	3
120*7c478bd9Sstevel@tonic-gate #define	IPOPT_MINOFF		4		/* min value of IPOPT_OFFSET */
121*7c478bd9Sstevel@tonic-gate 
122*7c478bd9Sstevel@tonic-gate 
123*7c478bd9Sstevel@tonic-gate /* Minimum for src and record route options */
124*7c478bd9Sstevel@tonic-gate #define	IPOPT_MINOFF_SR		IPOPT_MINOFF
125*7c478bd9Sstevel@tonic-gate 
126*7c478bd9Sstevel@tonic-gate /*
127*7c478bd9Sstevel@tonic-gate  * Time stamp option structure.
128*7c478bd9Sstevel@tonic-gate  */
129*7c478bd9Sstevel@tonic-gate struct	ip_timestamp {
130*7c478bd9Sstevel@tonic-gate 	uchar_t	ipt_code;		/* IPOPT_TS */
131*7c478bd9Sstevel@tonic-gate 	uchar_t	ipt_len;		/* size of structure (variable) */
132*7c478bd9Sstevel@tonic-gate 	uchar_t	ipt_ptr;		/* index of current entry */
133*7c478bd9Sstevel@tonic-gate #ifdef _BIT_FIELDS_LTOH
134*7c478bd9Sstevel@tonic-gate 	uchar_t	ipt_flg:4,		/* flags, see below */
135*7c478bd9Sstevel@tonic-gate 		ipt_oflw:4;		/* overflow counter */
136*7c478bd9Sstevel@tonic-gate #else
137*7c478bd9Sstevel@tonic-gate 	uchar_t	ipt_oflw:4,		/* overflow counter */
138*7c478bd9Sstevel@tonic-gate 		ipt_flg:4;		/* flags, see below */
139*7c478bd9Sstevel@tonic-gate #endif
140*7c478bd9Sstevel@tonic-gate 	union ipt_timestamp {
141*7c478bd9Sstevel@tonic-gate 		uint32_t	ipt_time[1];
142*7c478bd9Sstevel@tonic-gate 		struct	ipt_ta {
143*7c478bd9Sstevel@tonic-gate 			struct in_addr	ipt_addr;
144*7c478bd9Sstevel@tonic-gate 			uint32_t	ipt_time;
145*7c478bd9Sstevel@tonic-gate 		} ipt_ta[1];
146*7c478bd9Sstevel@tonic-gate 	} ipt_timestamp;
147*7c478bd9Sstevel@tonic-gate };
148*7c478bd9Sstevel@tonic-gate 
149*7c478bd9Sstevel@tonic-gate /* flag bits for ipt_flg */
150*7c478bd9Sstevel@tonic-gate #define	IPOPT_TS_TSONLY		0		/* timestamps only */
151*7c478bd9Sstevel@tonic-gate #define	IPOPT_TS_TSANDADDR	1		/* timestamps and addresses */
152*7c478bd9Sstevel@tonic-gate #define	IPOPT_TS_PRESPEC	2		/* specified modules only */
153*7c478bd9Sstevel@tonic-gate #define	IPOPT_TS_PRESPEC_RFC791	3
154*7c478bd9Sstevel@tonic-gate 
155*7c478bd9Sstevel@tonic-gate /* Minimum for timestamp option */
156*7c478bd9Sstevel@tonic-gate #define	IPOPT_MINOFF_IT		5
157*7c478bd9Sstevel@tonic-gate #define	IPOPT_MINLEN_IT		5
158*7c478bd9Sstevel@tonic-gate 
159*7c478bd9Sstevel@tonic-gate #define	IPOPT_TS_TIMELEN	4	/* Timestamp size */
160*7c478bd9Sstevel@tonic-gate 
161*7c478bd9Sstevel@tonic-gate /* bits for security (not byte swapped) */
162*7c478bd9Sstevel@tonic-gate #define	IPOPT_SECUR_UNCLASS	0x0000
163*7c478bd9Sstevel@tonic-gate #define	IPOPT_SECUR_CONFID	0xf135
164*7c478bd9Sstevel@tonic-gate #define	IPOPT_SECUR_EFTO	0x789a
165*7c478bd9Sstevel@tonic-gate #define	IPOPT_SECUR_MMMM	0xbc4d
166*7c478bd9Sstevel@tonic-gate #define	IPOPT_SECUR_RESTR	0xaf13
167*7c478bd9Sstevel@tonic-gate #define	IPOPT_SECUR_SECRET	0xd788
168*7c478bd9Sstevel@tonic-gate #define	IPOPT_SECUR_TOPSECRET	0x6bc5
169*7c478bd9Sstevel@tonic-gate 
170*7c478bd9Sstevel@tonic-gate /*
171*7c478bd9Sstevel@tonic-gate  * Internet implementation parameters.
172*7c478bd9Sstevel@tonic-gate  */
173*7c478bd9Sstevel@tonic-gate #define	MAXTTL		255		/* maximum time to live (seconds) */
174*7c478bd9Sstevel@tonic-gate #define	IPFRAGTTL	60		/* time to live for frags, slowhz */
175*7c478bd9Sstevel@tonic-gate #define	IPTTLDEC	1		/* subtracted when forwarding */
176*7c478bd9Sstevel@tonic-gate 
177*7c478bd9Sstevel@tonic-gate #define	IP_MSS		576		/* default maximum segment size */
178*7c478bd9Sstevel@tonic-gate 
179*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
180*7c478bd9Sstevel@tonic-gate }
181*7c478bd9Sstevel@tonic-gate #endif
182*7c478bd9Sstevel@tonic-gate 
183*7c478bd9Sstevel@tonic-gate #endif	/* _NETINET_IP_H */
184