Rev 4704 | Rev 4728 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4704 | Rev 4722 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (c) 2009 Lukas Mejdrech |
2 | * Copyright (c) 2009 Lukas Mejdrech |
3 | * All rights reserved. |
3 | * All rights reserved. |
4 | * |
4 | * |
5 | * Redistribution and use in source and binary forms, with or without |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
6 | * modification, are permitted provided that the following conditions |
7 | * are met: |
7 | * are met: |
8 | * |
8 | * |
9 | * - Redistributions of source code must retain the above copyright |
9 | * - Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. |
10 | * notice, this list of conditions and the following disclaimer. |
11 | * - Redistributions in binary form must reproduce the above copyright |
11 | * - Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in the |
12 | * notice, this list of conditions and the following disclaimer in the |
13 | * documentation and/or other materials provided with the distribution. |
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 |
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. |
15 | * derived from this software without specific prior written permission. |
16 | * |
16 | * |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
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 |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
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 |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
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 |
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. |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | */ |
27 | */ |
28 | 28 | ||
29 | /** @addtogroup ip |
29 | /** @addtogroup ip |
30 | * @{ |
30 | * @{ |
31 | */ |
31 | */ |
32 | 32 | ||
33 | /** @file |
33 | /** @file |
34 | * IP header and options definitions. |
34 | * IP header and options definitions. |
35 | * Names according to the linux src/include/linux/ip.h header file. |
35 | * Names according to the linux src/include/linux/ip.h header file. |
36 | */ |
36 | */ |
37 | 37 | ||
38 | #ifndef __NET_IP_HEADER_H__ |
38 | #ifndef __NET_IP_HEADER_H__ |
39 | #define __NET_IP_HEADER_H__ |
39 | #define __NET_IP_HEADER_H__ |
40 | 40 | ||
41 | #include <byteorder.h> |
41 | #include <byteorder.h> |
42 | #include <sys/types.h> |
42 | #include <sys/types.h> |
43 | 43 | ||
44 | /** Type definition of the internet header. |
44 | /** Type definition of the internet header. |
45 | * @see ip_header |
45 | * @see ip_header |
46 | */ |
46 | */ |
47 | typedef struct ip_header ip_header_t; |
47 | typedef struct ip_header ip_header_t; |
48 | 48 | ||
49 | /** Type definition of the internet header pointer. |
49 | /** Type definition of the internet header pointer. |
50 | * @see ip_header |
50 | * @see ip_header |
51 | */ |
51 | */ |
52 | typedef ip_header_t * ip_header_ref; |
52 | typedef ip_header_t * ip_header_ref; |
53 | 53 | ||
54 | /** Internet header. |
54 | /** Internet header. |
55 | * The variable options should be included after the header itself and indicated by the increased header length value. |
55 | * The variable options should be included after the header itself and indicated by the increased header length value. |
56 | */ |
56 | */ |
57 | struct ip_header{ |
57 | struct ip_header{ |
58 | #ifdef ARCH_IS_BIG_ENDIAN |
58 | #ifdef ARCH_IS_BIG_ENDIAN |
59 | /** The Version field indicates the format of the internet header. |
59 | /** The Version field indicates the format of the internet header. |
60 | */ |
60 | */ |
61 | uint8_t version:4; |
61 | uint8_t version:4; |
62 | /** Internet Header Length is the length of the internet header in 32~bit words, and thus points to the beginning of the data. |
62 | /** Internet Header Length is the length of the internet header in 32~bit words, and thus points to the beginning of the data. |
63 | * Note that the minimum value for a~correct header is~5. |
63 | * Note that the minimum value for a~correct header is~5. |
64 | */ |
64 | */ |
65 | uint8_t ihl:4; |
65 | uint8_t ihl:4; |
66 | #else |
66 | #else |
67 | /** Internet Header Length is the length of the internet header in 32~bit words, and thus points to the beginning of the data. |
67 | /** Internet Header Length is the length of the internet header in 32~bit words, and thus points to the beginning of the data. |
68 | * Note that the minimum value for a~correct header is~5. |
68 | * Note that the minimum value for a~correct header is~5. |
69 | */ |
69 | */ |
70 | uint8_t ihl:4; |
70 | uint8_t ihl:4; |
71 | /** The Version field indicates the format of the internet header. |
71 | /** The Version field indicates the format of the internet header. |
72 | */ |
72 | */ |
73 | uint8_t version:4; |
73 | uint8_t version:4; |
74 | #endif |
74 | #endif |
75 | /** The Type of Service provides an indication of the abstract parameters of the quality of service desired. |
75 | /** The Type of Service provides an indication of the abstract parameters of the quality of service desired. |
76 | * These parameters are to be used to guide the selection of the actual service parameters when transmitting a~datagram through a~particular network. |
76 | * These parameters are to be used to guide the selection of the actual service parameters when transmitting a~datagram through a~particular network. |
77 | * 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). |
77 | * 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). |
78 | * The major choice is a~three way tradeoff between low-delay, high-reliability, and high-throughput. |
78 | * The major choice is a~three way tradeoff between low-delay, high-reliability, and high-throughput. |
79 | */ |
79 | */ |
80 | uint8_t tos; |
80 | uint8_t tos; |
81 | /** Total Length is the length of the datagram, measured in octets, including internet header and data. |
81 | /** Total Length is the length of the datagram, measured in octets, including internet header and data. |
82 | * This field allows the length of a~datagram to be up to 65,535~octets. |
82 | * This field allows the length of a~datagram to be up to 65,535~octets. |
83 | */ |
83 | */ |
84 | uint16_t total_length; |
84 | uint16_t total_length; |
85 | /** An identifying value assigned by the sender to aid in assembling the fragments of a~datagram. |
85 | /** An identifying value assigned by the sender to aid in assembling the fragments of a~datagram. |
86 | */ |
86 | */ |
87 | uint16_t identification; |
87 | uint16_t identification; |
88 | #ifdef ARCH_IS_BIG_ENDIAN |
88 | #ifdef ARCH_IS_BIG_ENDIAN |
89 | /** Various control flags. |
89 | /** Various control flags. |
90 | * @see |
90 | * @see |
91 | */ |
91 | */ |
92 | uint16_t flags:3; |
92 | uint16_t flags:3; |
93 | /** This field indicates where in the datagram this fragment belongs. |
93 | /** This field indicates where in the datagram this fragment belongs. |
94 | */ |
94 | */ |
95 | uint16_t fragment_offset:3; |
95 | uint16_t fragment_offset:3; |
96 | #else |
96 | #else |
97 | /** This field indicates where in the datagram this fragment belongs. |
97 | /** This field indicates where in the datagram this fragment belongs. |
98 | */ |
98 | */ |
99 | uint16_t fragment_offset:13; |
99 | uint16_t fragment_offset:13; |
100 | /** Various control flags. |
100 | /** Various control flags. |
101 | */ |
101 | */ |
102 | uint16_t flags:3; |
102 | uint16_t flags:3; |
103 | #endif |
103 | #endif |
104 | /** This field indicates the maximum time the datagram is allowed to remain in the internet system. |
104 | /** This field indicates the maximum time the datagram is allowed to remain in the internet system. |
105 | * If this field contains the value zero, then the datagram must be destroyed. |
105 | * If this field contains the value zero, then the datagram must be destroyed. |
106 | * This field is modified in internet header processing. |
106 | * This field is modified in internet header processing. |
107 | * 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. |
107 | * 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. |
108 | * The intention is to cause undeliverable datagrams to be discarded, and to bound the maximum datagram lifetime. |
108 | * The intention is to cause undeliverable datagrams to be discarded, and to bound the maximum datagram lifetime. |
109 | */ |
109 | */ |
110 | uint8_t ttl; |
110 | uint8_t ttl; |
111 | /** This field indicates the next level protocol used in the data portion of the internet datagram. |
111 | /** This field indicates the next level protocol used in the data portion of the internet datagram. |
112 | */ |
112 | */ |
113 | uint8_t protocol; |
113 | uint8_t protocol; |
114 | /** A checksum of the header only. |
114 | /** A checksum of the header only. |
115 | * Since some header fields change (e.g., time to live), this is recomputed and verified at each point that the internet header is processed. |
115 | * Since some header fields change (e.g., time to live), this is recomputed and verified at each point that the internet header is processed. |
116 | * 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. |
116 | * 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. |
117 | * For purposes of computing the checksum, the value of the checksum field is zero. |
117 | * For purposes of computing the checksum, the value of the checksum field is zero. |
118 | */ |
118 | */ |
119 | uint16_t header_checksum; |
119 | uint16_t header_checksum; |
120 | /** The source address. |
120 | /** The source address. |
121 | */ |
121 | */ |
122 | uint32_t source_address; |
122 | uint32_t source_address; |
123 | /** The destination address. |
123 | /** The destination address. |
124 | */ |
124 | */ |
125 | uint32_t destination_address; |
125 | uint32_t destination_address; |
126 | } __attribute__ ((packed)); |
126 | } __attribute__ ((packed)); |
127 | 127 | ||
128 | /** Type definition of the internet option header. |
128 | /** Type definition of the internet option header. |
129 | * @see ip_header |
129 | * @see ip_header |
130 | */ |
130 | */ |
131 | typedef struct ip_option ip_option_t; |
131 | typedef struct ip_option ip_option_t; |
132 | 132 | ||
133 | /** Type definition of the internet option header pointer. |
133 | /** Type definition of the internet option header pointer. |
134 | * @see ip_header |
134 | * @see ip_header |
135 | */ |
135 | */ |
136 | typedef ip_option_t * ip_option_ref; |
136 | typedef ip_option_t * ip_option_ref; |
137 | 137 | ||
138 | /** Internet option header. |
138 | /** Internet option header. |
139 | * Only type field is always valid. |
139 | * Only type field is always valid. |
140 | * Other fields' validity depends on the option type. |
140 | * Other fields' validity depends on the option type. |
141 | */ |
141 | */ |
142 | struct ip_option{ |
142 | struct ip_option{ |
143 | /** A single octet of option-type. |
143 | /** A single octet of option-type. |
144 | */ |
144 | */ |
145 | uint8_t type; |
145 | uint8_t type; |
146 | /** An option length octet. |
146 | /** An option length octet. |
147 | */ |
147 | */ |
148 | uint8_t length; |
148 | uint8_t length; |
149 | /** A~pointer. |
149 | /** A~pointer. |
150 | */ |
150 | */ |
151 | uint8_t pointer; |
151 | uint8_t pointer; |
152 | #ifdef ARCH_IS_BIG_ENDIAN |
152 | #ifdef ARCH_IS_BIG_ENDIAN |
153 | /** The number of IP modules that cannot register timestamps due to lack of space. |
153 | /** The number of IP modules that cannot register timestamps due to lack of space. |
154 | */ |
154 | */ |
155 | uint8_t overflow:4; |
155 | uint8_t overflow:4; |
156 | /** Various internet timestamp control flags. |
156 | /** Various internet timestamp control flags. |
157 | */ |
157 | */ |
158 | uint8_t flags:4; |
158 | uint8_t flags:4; |
159 | #else |
159 | #else |
160 | /** Various internet timestamp control flags. |
160 | /** Various internet timestamp control flags. |
161 | */ |
161 | */ |
162 | uint8_t flags:4; |
162 | uint8_t flags:4; |
163 | /** The number of IP modules that cannot register timestamps due to lack of space. |
163 | /** The number of IP modules that cannot register timestamps due to lack of space. |
164 | */ |
164 | */ |
165 | uint8_t overflow:4; |
165 | uint8_t overflow:4; |
166 | #endif |
166 | #endif |
167 | } __attribute__ ((packed)); |
167 | } __attribute__ ((packed)); |
168 | 168 | ||
169 | /** @name IP flags definitions |
169 | /** @name IP flags definitions |
170 | */ |
170 | */ |
171 | /*@{*/ |
171 | /*@{*/ |
172 | 172 | ||
173 | /** Fragment flag field shift. |
173 | /** Fragment flag field shift. |
174 | */ |
174 | */ |
175 | #define IPFLAG_FRAGMENT_SHIFT 1 |
175 | #define IPFLAG_FRAGMENT_SHIFT 1 |
176 | 176 | ||
177 | /** Fragmented flag field shift. |
177 | /** Fragmented flag field shift. |
178 | */ |
178 | */ |
179 | #define IPFLAG_FRAGMENTED_SHIFT 0 |
179 | #define IPFLAG_FRAGMENTED_SHIFT 0 |
180 | 180 | ||
181 | /** May fragment flag value. |
181 | /** May fragment flag value. |
182 | * Allows the packet fragmentation. |
182 | * Allows the packet fragmentation. |
183 | */ |
183 | */ |
184 | #define IPFLAG_MAY_FRAGMENT ( 0x0 << IPFLAG_FRAGMENT_SHIFT ) |
184 | #define IPFLAG_MAY_FRAGMENT ( 0x0 << IPFLAG_FRAGMENT_SHIFT ) |
185 | 185 | ||
186 | /** Don't fragment flag value. |
186 | /** Don't fragment flag value. |
187 | * Permits the packet fragmentation. |
187 | * Permits the packet fragmentation. |
188 | */ |
188 | */ |
189 | #define IPFLAG_DONT_FRAGMENT ( 0x1 << IPFLAG_FRAGMENT_SHIFT ) |
189 | #define IPFLAG_DONT_FRAGMENT ( 0x1 << IPFLAG_FRAGMENT_SHIFT ) |
190 | 190 | ||
191 | /** Last fragment flag value. |
191 | /** Last fragment flag value. |
192 | * Indicates the last packet fragment. |
192 | * Indicates the last packet fragment. |
193 | */ |
193 | */ |
194 | #define IPFLAG_LAST_FRAGMENT ( 0x0 << IPFLAG_FRAGMENTED_SHIFT ) |
194 | #define IPFLAG_LAST_FRAGMENT ( 0x0 << IPFLAG_FRAGMENTED_SHIFT ) |
195 | 195 | ||
196 | /** More fragments flag value. |
196 | /** More fragments flag value. |
197 | * Indicates that more packet fragments follow. |
197 | * Indicates that more packet fragments follow. |
198 | */ |
198 | */ |
199 | #define IPFLAG_MORE_FRAGMENTS ( 0x1 << IPFLAG_FRAGMENTED_SHIFT ) |
199 | #define IPFLAG_MORE_FRAGMENTS ( 0x1 << IPFLAG_FRAGMENTED_SHIFT ) |
200 | 200 | ||
201 | /*@}*/ |
201 | /*@}*/ |
202 | 202 | ||
203 | /* |
203 | /* |
204 | #define IPOPT_OPTVAL 0 |
204 | #define IPOPT_OPTVAL 0 |
205 | #define IPOPT_OLEN 1 |
205 | #define IPOPT_OLEN 1 |
206 | #define IPOPT_OFFSET 2 |
206 | #define IPOPT_OFFSET 2 |
207 | #define IPOPT_MINOFF 4 |
207 | #define IPOPT_MINOFF 4 |
208 | #define MAX_IPOPTLEN 40 |
208 | #define MAX_IPOPTLEN 40 |
209 | */ |
209 | */ |
210 | 210 | ||
- | 211 | /** Type definition of the internet version 4 pseudo header. |
|
- | 212 | * @see ipv4_pseudo_header |
|
- | 213 | */ |
|
- | 214 | typedef struct ipv4_pseudo_header ipv4_pseudo_header_t; |
|
- | 215 | ||
- | 216 | /** Type definition of the internet version 4 pseudo header pointer. |
|
- | 217 | * @see ipv4_pseudo_header |
|
- | 218 | */ |
|
- | 219 | typedef ipv4_pseudo_header_t * ipv4_pseudo_header_ref; |
|
- | 220 | ||
- | 221 | /** Internet version 4 pseudo header. |
|
- | 222 | */ |
|
- | 223 | struct ipv4_pseudo_header{ |
|
- | 224 | /** The source address. |
|
- | 225 | */ |
|
- | 226 | uint32_t source_address; |
|
- | 227 | /** The destination address. |
|
- | 228 | */ |
|
- | 229 | uint32_t destination_address; |
|
- | 230 | /** Zero byte. |
|
- | 231 | */ |
|
- | 232 | uint8_t zero; |
|
- | 233 | /** This field indicates the next level protocol used in the data portion of the internet datagram. |
|
- | 234 | */ |
|
- | 235 | uint8_t protocol; |
|
- | 236 | /** Data length is the length of the datagram, measured in octets. |
|
- | 237 | */ |
|
- | 238 | uint16_t data_length; |
|
- | 239 | } __attribute__ ((packed)); |
|
- | 240 | ||
211 | #endif |
241 | #endif |
212 | 242 | ||
213 | /** @} |
243 | /** @} |
214 | */ |
244 | */ |
215 | 245 |