Subversion Repositories HelenOS

Rev

Rev 3886 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
3846 mejdrech 1
/*
2
 * Copyright (c) 2008 Lukas Mejdrech
3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
7
 * are met:
8
 *
9
 * - Redistributions of source code must retain the above copyright
10
 *   notice, this list of conditions and the following disclaimer.
11
 * - Redistributions in binary form must reproduce the above copyright
12
 *   notice, this list of conditions and the following disclaimer in the
13
 *   documentation and/or other materials provided with the distribution.
14
 * - The name of the author may not be used to endorse or promote products
15
 *   derived from this software without specific prior written permission.
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 */
28
 
29
/** @addtogroup net
30
 * @{
31
 */
32
 
33
/**
34
 * @file
35
 * Interent protocol header and options definitions.
36
 * Names according to the linux src/include/linux/ip.h header file.
37
 */
38
 
39
#ifndef __NET_IP_HEADER_H__
40
#define __NET_IP_HEADER_H__
41
 
42
#include <byteorder.h>
43
#include <types.h>
44
 
45
typedef struct ip_header	ip_header_t;
46
typedef ip_header_t *		ip_header_ref;
47
 
48
/** Internet header.
49
 *  The variable options should be included after the header itself and indicated by the increased header length value.
50
 */
51
struct ip_header{
52
#ifdef ARCH_IS_BIG_ENDIAN
53
	/** The Version field indicates the format of the internet header.
54
	 */
55
	uint8_t:4	version;
56
	/** Internet Header Length is the length of the internet header in 32~bit words, and thus points to the beginning of the data.
57
	 *  Note that the minimum value for a~correct header is~5.
58
	 */
59
	uint8_t:4	ihl;
60
#else
61
	/** Internet Header Length is the length of the internet header in 32~bit words, and thus points to the beginning of the data.
62
	 *  Note that the minimum value for a~correct header is~5.
63
	 */
64
	uint8_t:4	ihl;
65
	/** The Version field indicates the format of the internet header.
66
	 */
67
	uint8_t:4	version;
68
#endif
69
	/** The Type of Service provides an indication of the abstract parameters of the quality of service desired.
70
	 *  These parameters are to be used to guide the selection of the actual service parameters when transmitting a~datagram through a~particular network.
71
	 *  Several networks offer service precedence, which somehow treats high precedence traffic as more important than other traffic (generally by accepting only traffic above a~certain precedence at time of high load).
72
	 *  The major choice is a~three way tradeoff between low-delay, high-reliability, and high-throughput.
73
	 */
74
	uint8_t		tos;
75
	/** Total Length is the length of the datagram, measured in octets, including internet header and data.
76
	 *  This field allows the length of a~datagram to be up to 65,535~octets.
77
	 */
78
	uint16_t	total_length;
79
	/** An identifying value assigned by the sender to aid in assembling the fragments of a~datagram.
80
	 */
81
	unit16_t	identification;
82
#ifdef ARCH_IS_BIG_ENDIAN
83
	/** Various control flags.
84
	 */
85
	uint_16:3	flags;
86
	/** This field indicates where in the datagram this fragment belongs.
87
	 */
88
	uint_16:13	fragment_offset;
89
#else
90
	/** This field indicates where in the datagram this fragment belongs.
91
	 */
92
	uint_16:13	fragment_offset;
93
	/** Various control flags.
94
	 */
95
	uint_16:3	flags;
96
#endif
97
	/** This field indicates the maximum time the datagram is allowed to remain in the internet system.
98
	 *  If this field contains the value zero, then the datagram must be destroyed.
99
	 *  This field is modified in internet header processing.
100
	 *  The time is measured in units of seconds, but since every module that processes a~datagram must decrease the TTL by at least one even if it process the datagram in less than a~second, the TTL must be thought of only as an upper bound on the time a~datagram may exist.
101
	 *  The intention is to cause undeliverable datagrams to be discarded, and to bound the maximum datagram lifetime.
102
	 */
103
	uint8_t		ttl;
104
	/** This field indicates the next level protocol used in the data portion of the internet datagram.
105
	 */
106
	uint8_t		protocol;
107
	/** A checksum on the header only.
108
	 *  Since some header fields change (e.g., time to live), this is recomputed and verified at each point that the internet header is processed.
109
	 *  The checksum algorithm is: The checksum field is the 16~bit one's complement of the one's complement sum of all 16~bit words in the header.
110
	 *  For purposes of computing the checksum, the value of the checksum field is zero.
111
	 */
112
	uint16_t	header_checksum;
113
	/** The source address.
114
	 */
115
	uint32_t	source_address;
116
	/** The destination address.
117
	 */
118
	uint32_t	destination_address;
119
};
120
 
121
typedef struct ip_option	ip_option_t;
122
typedef ip_option *		ip_option_ref;
123
 
124
/** Internet option header.
125
 *  Only type field is always valid.
126
 *  Other fields' validity depends on the option type.
127
 */
128
struct ip_option{
129
	/** A single octet of option-type.
130
	 */
131
	uint8_t		type;
132
	/** An option length octet.
133
	 */
134
	uint8_t		length;
135
	/** A~pointer.
136
	 */
137
	uint8_t		pointer;
138
#ifdef ARCH_IS_BIG_ENDIAN
139
	/** The number of IP modules that cannot register timestamps due to lack of space.
140
	 */
141
	uint8_t:4	overflow;
142
	/** Various internet timestamp control flags.
143
	 */
144
	uint8_t:4	flags;
145
#else
146
	/** Various internet timestamp control flags.
147
	 */
148
	uint8_t:4	flags;
149
	/** The number of IP modules that cannot register timestamps due to lack of space.
150
	 */
151
	uint8_t:4	overflow;
152
#endif
153
};
154
 
155
#define IPTOS_TOS_MASK				0x1E
156
#define IPTOS_PRECEDENCE_SHIFT		5
157
#define IPTOS_DELAY_SHIFT			4
158
#define IPTOS_TROUGHPUT_SHIFT		3
159
#define IPTOS_RELIABILITY_SHIFT		2
160
#define IPTOS_COST_SHIFT			1
161
 
162
#define IPTOS_NORMALDELAY			( 0x0 << IPTOS_DELAY_SHIFT )
163
#define IPTOS_LOWDELAY				( 0x1 << IPTOS_DELAY_SHIFT )
164
 
165
#define IPTOS_NORMALTHROUGHPUT		( 0x0 << IPTOS_THROUGHPUT_SHIFT )
166
#define IPTOS_THROUGHPUT			( 0x1 << IPTOS_THROUGHPUT_SHIFT )
167
 
168
#define IPTOS_NORMALRELIABILITY		( 0x0 << IPTOS_RELIABILITY_SHIFT )
169
#define IPTOS_RELIABILITY			( 0x1 << IPTOS_RELIABILITY_SHIFT )
170
 
171
#define IPTOS_NORMALCOST			( 0x0 << IPTOS_COST_SHIFT )
172
#define IPTOS_MICNCOST				( 0x1 << IPTOS_COST_SHIFT )
173
 
174
#define IPTOS_PREC_MASK				0xE0
175
#define IPTOS_PREC_ROUTINE			( 0x0 << IPTOS_PRECEDENCE_SHIFT )
176
#define IPTOS_PREC_PRIORITY			( 0x1 << IPTOS_PRECEDENCE_SHIFT )
177
#define IPTOS_PREC_IMMEDIATE		( 0x2 << IPTOS_PRECEDENCE_SHIFT )
178
#define IPTOS_PREC_FLASH			( 0x3 << IPTOS_PRECEDENCE_SHIFT )
179
#define IPTOS_PREC_FLASHOVERRIDE	( 0x4 << IPTOS_PRECEDENCE_SHIFT )
180
#define IPTOS_PREC_CRITIC_ECP		( 0x5 << IPTOS_PRECEDENCE_SHIFT )
181
#define IPTOS_PREC_INTERNETCONTROL	( 0x6 << IPTOS_PRECEDENCE_SHIFT )
182
#define IPTOS_PREC_NETCONTROL		( 0x7 << IPTOS_PRECEDENCE_SHIFT )
183
 
184
#define IPFLAG_FRAGMENT_SHIFT		1
185
#define IPFLAG_FRAGMENTED_SHIFT		0
186
 
187
#define IPFLAG_MAY_FRAGMENT			( 0x0 << IPFLAG_FRAGMENT_SHIFT )
188
#define IPFLAG_DONT_FRAGMENT		( 0x1 << IPFLAG_FRAGMENT_SHIFT )
189
 
190
#define IPFLAG_LAST_FRAGMENT		( 0x0 << IPFLAG_FRAGMENTED_SHIFT )
191
#define IPFLAG_MORE_FRAGMENTS		( 0x1 << IPFLAG_FRAGMENTED_SHIFT )
192
 
193
#define IPOPT_COPY_SHIFT			7
194
#define IPOPT_CLASS_SHIFT			5
195
#define IPOPT_NUMBER_SHIFT			0
196
#define IPOPT_CLASS_MASK			0x60
197
#define IPOPT_NUMBER_MASK			0x1F
198
 
199
#define IPOPT_COPY					( 1 << IPOPT_COPY_SHIFT )
200
 
201
#define IPOPT_TYPE( copy, class, number )	((( copy ) & IPOPT_COPY ) | (( class ) & IPOPT_CLASS_MASK ) | (( number << IPOPT_NUMBER_SHIFT ) & IPOPT_NUMBER_MASK ))
202
 
203
#define	IPOPT_COPIED( o )			(( o ) & IPOPT_COPY )
204
#define	IPOPT_CLASS( o )			(( o ) & IPOPT_CLASS_MASK )
205
#define	IPOPT_NUMBER( o )			(( o ) & IPOPT_NUMBER_MASK )
206
 
207
#define	IPOPT_CONTROL				( 1 << IPOPT_CLASS_SHIFT )
208
#define	IPOPT_RESERVED1				( 2 << IPOPT_CLASS_SHIFT )
209
#define	IPOPT_MEASUREMENT			( 3 << IPOPT_CLASS_SHIFT )
210
#define	IPOPT_RESERVED2				( 4 << IPOPT_CLASS_SHIFT )
211
 
212
//#define IPOPT_END_OF_LIST		0x0
213
#define IPOPT_END					IPOPT_TYPE( 0, IPOPT_CONTROL, 0 )
214
//#define IPOPT_NO_OPERATION		0x1
215
#define IPOPT_NOOP					IPOPT_TYPE( 0, IPOPT_CONTROL, 1 )
216
//#define IPOPT_SECURITY			0x82
217
#define IPOPT_SEC					IPOPT_TYPE( IPOPT_COPY, IPOPT_CONTROL, 2 )
218
#define IPOPT_SEC_LENGTH			11
219
#define IPOPT_SEC_UNCLASIFIED		0x0
220
#define IPOPT_SEC_CONFIDENTIAL		0xF035
221
#define IPOPT_SEC_EFTO				0x789A
222
#define IPOPT_SEC_MMMM				0xBC4D
223
#define IPOPT_SEC_PROG				0x5E26
224
#define IPOPT_SEC_RESTRICTED		0xAF13
225
#define IPOPT_SEC_SECRET			0xD788
226
#define IPOPT_SEC_TOP_SECRET		0x6BC5
227
//#define IPOPT_LOOSE_SOURCE		0x83
228
#define IPOPT_LSRR					IPOPT_TYPE( IPOPT_COPY, IPOPT_CONTROL, 3 )
229
//#define IPOPT_STRICT_SOURCE		0x89
230
#define IPOPT_SSRR					IPOPT_TYPE( IPOPT_COPY, IPOPT_CONTROL, 9 )
231
//#define IPOPT_RECORD_ROUTE		0x07
232
#define IPOPT_RR					IPOPT_TYPE( IPOPT_COPY, IPOPT_CONTROL, 7 )
233
//#define IPOPT_STREAM_IDENTIFIER	0x88
234
#define IPOPT_SID					IPOPT_TYPE( IPOPT_COPY, IPOPT_CONTROL, 8 )
235
#define IPOPT_SID_LENGTH			4
236
//#define IPOPT_INTERNET_TIMESTAMP	0x44
237
#define IPOPT_TIMESTAMP				IPOPT_TYPE( IPOPT_COPY, IPOPT_MEASUREMENT, 4 )
238
#define IPOPT_CIPSO					IPOPT_TYPE( IPOPT_COPY, IPOPT_CONTROL, 5 )
239
 
240
#define IPVERSION	4
241
#define MAXTTL		255
242
#define IPDEFTTL	64
243
 
244
#define IPOPT_OPTVAL 0
245
#define IPOPT_OLEN   1
246
#define IPOPT_OFFSET 2
247
#define IPOPT_MINOFF 4
248
#define MAX_IPOPTLEN 40
249
#define IPOPT_NOP IPOPT_NOOP
250
#define IPOPT_EOL IPOPT_END
251
#define IPOPT_TS  IPOPT_TIMESTAMP
252
 
253
#define	IPOPT_TS_TSONLY		0		/* timestamps only */
254
#define	IPOPT_TS_TSANDADDR	1		/* timestamps and addresses */
255
#define	IPOPT_TS_PRESPEC	3		/* specified modules only */
256
 
257
#endif
258
 
259
/** @}
260
 */