Changeset 7715994 in mainline for uspace/srv/net/il/ip/ip_header.h
- Timestamp:
- 2010-03-13T12:17:02Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 6ba20a6b
- Parents:
- d0febca (diff), 2070570 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/il/ip/ip_header.h
rd0febca r7715994 42 42 #include <sys/types.h> 43 43 44 /** Returns the actual IP header length in bytes. 45 * @param[in] header The IP packet header. 46 */ 47 #define IP_HEADER_LENGTH( header ) (( header )->header_length * 4u ) 44 /** Returns the fragment offest high bits. 45 * @param[in] length The prefixed data total length. 46 */ 47 #define IP_COMPUTE_FRAGMENT_OFFSET_HIGH(length) ((((length) / 8u) &0x1F00) >> 8) 48 49 /** Returns the fragment offest low bits. 50 * @param[in] length The prefixed data total length. 51 */ 52 #define IP_COMPUTE_FRAGMENT_OFFSET_LOW(length) (((length) / 8u) &0xFF) 48 53 49 54 /** Returns the IP header length. 50 55 * @param[in] length The IP header length in bytes. 51 56 */ 52 #define IP_COMPUTE_HEADER_LENGTH( length ) (( uint8_t ) (( length ) / 4u )) 57 #define IP_COMPUTE_HEADER_LENGTH(length) ((uint8_t) ((length) / 4u)) 58 59 /** Returns the fragment offest. 60 * @param[in] header The IP packet header. 61 */ 62 #define IP_FRAGMENT_OFFSET(header) ((((header)->fragment_offset_high << 8) + (header)->fragment_offset_low) * 8u) 63 64 /** Returns the IP packet header checksum. 65 * @param[in] header The IP packet header. 66 */ 67 #define IP_HEADER_CHECKSUM(header) (htons(ip_checksum((uint8_t *)(header), IP_HEADER_LENGTH(header)))) 68 69 /** Returns the actual IP packet data length. 70 * @param[in] header The IP packet header. 71 */ 72 #define IP_HEADER_DATA_LENGTH(header) (IP_TOTAL_LENGTH(header) - IP_HEADER_LENGTH(header)) 73 74 /** Returns the actual IP header length in bytes. 75 * @param[in] header The IP packet header. 76 */ 77 #define IP_HEADER_LENGTH(header) ((header)->header_length * 4u) 53 78 54 79 /** Returns the actual IP packet total length. 55 80 * @param[in] header The IP packet header. 56 81 */ 57 #define IP_TOTAL_LENGTH( header ) ntohs(( header )->total_length ) 58 59 /** Returns the actual IP packet data length. 60 * @param[in] header The IP packet header. 61 */ 62 #define IP_HEADER_DATA_LENGTH( header ) ( IP_TOTAL_LENGTH( header ) - IP_HEADER_LENGTH( header )) 63 64 /** Returns the IP packet header checksum. 65 * @param[in] header The IP packet header. 66 */ 67 #define IP_HEADER_CHECKSUM( header ) ( htons( ip_checksum(( uint8_t * )( header ), IP_HEADER_LENGTH( header )))) 68 69 /** Returns the fragment offest. 70 * @param[in] header The IP packet header. 71 */ 72 #define IP_FRAGMENT_OFFSET( header ) (((( header )->fragment_offset_high << 8 ) + ( header )->fragment_offset_low ) * 8u ) 73 74 /** Returns the fragment offest high bits. 75 * @param[in] length The prefixed data total length. 76 */ 77 #define IP_COMPUTE_FRAGMENT_OFFSET_HIGH( length ) (((( length ) / 8u ) & 0x1F00 ) >> 8 ) 78 79 /** Returns the fragment offest low bits. 80 * @param[in] length The prefixed data total length. 81 */ 82 #define IP_COMPUTE_FRAGMENT_OFFSET_LOW( length ) ((( length ) / 8u ) & 0xFF ) 82 #define IP_TOTAL_LENGTH(header) ntohs((header)->total_length) 83 84 /** @name IP flags definitions 85 */ 86 /*@{*/ 87 88 /** Fragment flag field shift. 89 */ 90 #define IPFLAG_FRAGMENT_SHIFT 1 91 92 /** Fragmented flag field shift. 93 */ 94 #define IPFLAG_FRAGMENTED_SHIFT 0 95 96 /** Don't fragment flag value. 97 * Permits the packet fragmentation. 98 */ 99 #define IPFLAG_DONT_FRAGMENT (0x1 << IPFLAG_FRAGMENT_SHIFT) 100 101 /** Last fragment flag value. 102 * Indicates the last packet fragment. 103 */ 104 #define IPFLAG_LAST_FRAGMENT (0x0 << IPFLAG_FRAGMENTED_SHIFT) 105 106 /** May fragment flag value. 107 * Allows the packet fragmentation. 108 */ 109 #define IPFLAG_MAY_FRAGMENT (0x0 << IPFLAG_FRAGMENT_SHIFT) 110 111 /** More fragments flag value. 112 * Indicates that more packet fragments follow. 113 */ 114 #define IPFLAG_MORE_FRAGMENTS (0x1 << IPFLAG_FRAGMENTED_SHIFT) 115 116 /*@}*/ 83 117 84 118 /** Type definition of the internet header. … … 91 125 */ 92 126 typedef ip_header_t * ip_header_ref; 127 128 /** Type definition of the internet option header. 129 * @see ip_header 130 */ 131 typedef struct ip_option ip_option_t; 132 133 /** Type definition of the internet option header pointer. 134 * @see ip_header 135 */ 136 typedef ip_option_t * ip_option_ref; 137 138 /** Type definition of the internet version 4 pseudo header. 139 * @see ipv4_pseudo_header 140 */ 141 typedef struct ipv4_pseudo_header ipv4_pseudo_header_t; 142 143 /** Type definition of the internet version 4 pseudo header pointer. 144 * @see ipv4_pseudo_header 145 */ 146 typedef ipv4_pseudo_header_t * ipv4_pseudo_header_ref; 93 147 94 148 /** Internet header. … … 99 153 /** The Version field indicates the format of the internet header. 100 154 */ 101 uint8_t 155 uint8_t version:4; 102 156 /** Internet Header Length is the length of the internet header in 32~bit words, and thus points to the beginning of the data. 103 157 * Note that the minimum value for a~correct header is~5. 104 158 */ 105 uint8_t 159 uint8_t header_length:4; 106 160 #else 107 161 /** Internet Header Length is the length of the internet header in 32~bit words, and thus points to the beginning of the data. 108 162 * Note that the minimum value for a~correct header is~5. 109 163 */ 110 uint8_t 164 uint8_t header_length:4; 111 165 /** The Version field indicates the format of the internet header. 112 166 */ 113 uint8_t 167 uint8_t version:4; 114 168 #endif 115 169 /** The Type of Service provides an indication of the abstract parameters of the quality of service desired. … … 118 172 * The major choice is a~three way tradeoff between low-delay, high-reliability, and high-throughput. 119 173 */ 120 uint8_t 174 uint8_t tos; 121 175 /** Total Length is the length of the datagram, measured in octets, including internet header and data. 122 176 * This field allows the length of a~datagram to be up to 65,535~octets. 123 177 */ 124 uint16_t 178 uint16_t total_length; 125 179 /** An identifying value assigned by the sender to aid in assembling the fragments of a~datagram. 126 180 */ 127 uint16_t 181 uint16_t identification; 128 182 #ifdef ARCH_IS_BIG_ENDIAN 129 183 /** Various control flags. 130 184 */ 131 uint8_t 185 uint8_t flags:3; 132 186 /** This field indicates where in the datagram this fragment belongs. 133 187 * High bits. 134 188 */ 135 uint8_t 189 uint8_t fragment_offset_high:5; 136 190 #else 137 191 /** This field indicates where in the datagram this fragment belongs. 138 192 * High bits. 139 193 */ 140 uint8_t 194 uint8_t fragment_offset_high:5; 141 195 /** Various control flags. 142 196 */ 143 uint8_t 197 uint8_t flags:3; 144 198 #endif 145 199 /** This field indicates where in the datagram this fragment belongs. 146 200 * Low bits. 147 201 */ 148 uint8_t 202 uint8_t fragment_offset_low; 149 203 /** This field indicates the maximum time the datagram is allowed to remain in the internet system. 150 204 * If this field contains the value zero, then the datagram must be destroyed. … … 153 207 * The intention is to cause undeliverable datagrams to be discarded, and to bound the maximum datagram lifetime. 154 208 */ 155 uint8_t 209 uint8_t ttl; 156 210 /** This field indicates the next level protocol used in the data portion of the internet datagram. 157 211 */ 158 uint8_t 212 uint8_t protocol; 159 213 /** A checksum of the header only. 160 214 * Since some header fields change (e.g., time to live), this is recomputed and verified at each point that the internet header is processed. … … 162 216 * For purposes of computing the checksum, the value of the checksum field is zero. 163 217 */ 164 uint16_t 218 uint16_t header_checksum; 165 219 /** The source address. 166 220 */ 167 uint32_t 221 uint32_t source_address; 168 222 /** The destination address. 169 223 */ 170 uint32_t 224 uint32_t destination_address; 171 225 } __attribute__ ((packed)); 172 173 /** Type definition of the internet option header.174 * @see ip_header175 */176 typedef struct ip_option ip_option_t;177 178 /** Type definition of the internet option header pointer.179 * @see ip_header180 */181 typedef ip_option_t * ip_option_ref;182 226 183 227 /** Internet option header. … … 188 232 /** A single octet of option-type. 189 233 */ 190 uint8_t 234 uint8_t type; 191 235 /** An option length octet. 192 236 */ 193 uint8_t 237 uint8_t length; 194 238 /** A~pointer. 195 239 */ 196 uint8_t 240 uint8_t pointer; 197 241 #ifdef ARCH_IS_BIG_ENDIAN 198 242 /** The number of IP modules that cannot register timestamps due to lack of space. 199 243 */ 200 uint8_t 244 uint8_t overflow:4; 201 245 /** Various internet timestamp control flags. 202 246 */ 203 uint8_t 247 uint8_t flags:4; 204 248 #else 205 249 /** Various internet timestamp control flags. 206 250 */ 207 uint8_t 251 uint8_t flags:4; 208 252 /** The number of IP modules that cannot register timestamps due to lack of space. 209 253 */ 210 uint8_t 254 uint8_t overflow:4; 211 255 #endif 212 256 } __attribute__ ((packed)); 213 214 /** @name IP flags definitions215 */216 /*@{*/217 218 /** Fragment flag field shift.219 */220 #define IPFLAG_FRAGMENT_SHIFT 1221 222 /** Fragmented flag field shift.223 */224 #define IPFLAG_FRAGMENTED_SHIFT 0225 226 /** May fragment flag value.227 * Allows the packet fragmentation.228 */229 #define IPFLAG_MAY_FRAGMENT ( 0x0 << IPFLAG_FRAGMENT_SHIFT )230 231 /** Don't fragment flag value.232 * Permits the packet fragmentation.233 */234 #define IPFLAG_DONT_FRAGMENT ( 0x1 << IPFLAG_FRAGMENT_SHIFT )235 236 /** Last fragment flag value.237 * Indicates the last packet fragment.238 */239 #define IPFLAG_LAST_FRAGMENT ( 0x0 << IPFLAG_FRAGMENTED_SHIFT )240 241 /** More fragments flag value.242 * Indicates that more packet fragments follow.243 */244 #define IPFLAG_MORE_FRAGMENTS ( 0x1 << IPFLAG_FRAGMENTED_SHIFT )245 246 /*@}*/247 248 /** Type definition of the internet version 4 pseudo header.249 * @see ipv4_pseudo_header250 */251 typedef struct ipv4_pseudo_header ipv4_pseudo_header_t;252 253 /** Type definition of the internet version 4 pseudo header pointer.254 * @see ipv4_pseudo_header255 */256 typedef ipv4_pseudo_header_t * ipv4_pseudo_header_ref;257 257 258 258 /** Internet version 4 pseudo header. … … 261 261 /** The source address. 262 262 */ 263 uint32_t 263 uint32_t source_address; 264 264 /** The destination address. 265 265 */ 266 uint32_t 266 uint32_t destination_address; 267 267 /** Reserved byte. 268 268 * Must be zero. 269 269 */ 270 uint8_t 270 uint8_t reserved; 271 271 /** This field indicates the next level protocol used in the data portion of the internet datagram. 272 272 */ 273 uint8_t 273 uint8_t protocol; 274 274 /** Data length is the length of the datagram, measured in octets. 275 275 */ 276 uint16_t 276 uint16_t data_length; 277 277 } __attribute__ ((packed)); 278 278
Note:
See TracChangeset
for help on using the changeset viewer.