Changes in uspace/srv/net/il/ip/ip_header.h [a64c64d:21580dd] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/il/ip/ip_header.h
ra64c64d r21580dd 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 ) 48 49 /** Returns the IP header length. 50 * @param[in] length The IP header length in bytes. 51 */ 52 #define IP_COMPUTE_HEADER_LENGTH( length ) (( uint8_t ) (( length ) / 4u )) 53 54 /** Returns the actual IP packet total length. 55 * @param[in] header The IP packet header. 56 */ 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 44 74 /** Returns the fragment offest high bits. 45 75 * @param[in] length The prefixed data total length. 46 76 */ 47 #define IP_COMPUTE_FRAGMENT_OFFSET_HIGH( length) ((((length) / 8u) &0x1F00) >> 8)77 #define IP_COMPUTE_FRAGMENT_OFFSET_HIGH( length ) (((( length ) / 8u ) & 0x1F00 ) >> 8 ) 48 78 49 79 /** Returns the fragment offest low bits. 50 80 * @param[in] length The prefixed data total length. 51 81 */ 52 #define IP_COMPUTE_FRAGMENT_OFFSET_LOW(length) (((length) / 8u) &0xFF) 53 54 /** Returns the IP header length. 55 * @param[in] length The IP header length in bytes. 56 */ 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) 78 79 /** Returns the actual IP packet total length. 80 * @param[in] header The IP packet header. 81 */ 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 /*@}*/ 82 #define IP_COMPUTE_FRAGMENT_OFFSET_LOW( length ) ((( length ) / 8u ) & 0xFF ) 117 83 118 84 /** Type definition of the internet header. … … 125 91 */ 126 92 typedef ip_header_t * ip_header_ref; 127 128 /** Type definition of the internet option header.129 * @see ip_header130 */131 typedef struct ip_option ip_option_t;132 133 /** Type definition of the internet option header pointer.134 * @see ip_header135 */136 typedef ip_option_t * ip_option_ref;137 138 /** Type definition of the internet version 4 pseudo header.139 * @see ipv4_pseudo_header140 */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_header145 */146 typedef ipv4_pseudo_header_t * ipv4_pseudo_header_ref;147 93 148 94 /** Internet header. … … 153 99 /** The Version field indicates the format of the internet header. 154 100 */ 155 uint8_t 101 uint8_t version:4; 156 102 /** Internet Header Length is the length of the internet header in 32~bit words, and thus points to the beginning of the data. 157 103 * Note that the minimum value for a~correct header is~5. 158 104 */ 159 uint8_t 105 uint8_t header_length:4; 160 106 #else 161 107 /** Internet Header Length is the length of the internet header in 32~bit words, and thus points to the beginning of the data. 162 108 * Note that the minimum value for a~correct header is~5. 163 109 */ 164 uint8_t 110 uint8_t header_length:4; 165 111 /** The Version field indicates the format of the internet header. 166 112 */ 167 uint8_t 113 uint8_t version:4; 168 114 #endif 169 115 /** The Type of Service provides an indication of the abstract parameters of the quality of service desired. … … 172 118 * The major choice is a~three way tradeoff between low-delay, high-reliability, and high-throughput. 173 119 */ 174 uint8_t 120 uint8_t tos; 175 121 /** Total Length is the length of the datagram, measured in octets, including internet header and data. 176 122 * This field allows the length of a~datagram to be up to 65,535~octets. 177 123 */ 178 uint16_t 124 uint16_t total_length; 179 125 /** An identifying value assigned by the sender to aid in assembling the fragments of a~datagram. 180 126 */ 181 uint16_t 127 uint16_t identification; 182 128 #ifdef ARCH_IS_BIG_ENDIAN 183 129 /** Various control flags. 184 130 */ 185 uint8_t 131 uint8_t flags:3; 186 132 /** This field indicates where in the datagram this fragment belongs. 187 133 * High bits. 188 134 */ 189 uint8_t 135 uint8_t fragment_offset_high:5; 190 136 #else 191 137 /** This field indicates where in the datagram this fragment belongs. 192 138 * High bits. 193 139 */ 194 uint8_t 140 uint8_t fragment_offset_high:5; 195 141 /** Various control flags. 196 142 */ 197 uint8_t 143 uint8_t flags:3; 198 144 #endif 199 145 /** This field indicates where in the datagram this fragment belongs. 200 146 * Low bits. 201 147 */ 202 uint8_t 148 uint8_t fragment_offset_low; 203 149 /** This field indicates the maximum time the datagram is allowed to remain in the internet system. 204 150 * If this field contains the value zero, then the datagram must be destroyed. … … 207 153 * The intention is to cause undeliverable datagrams to be discarded, and to bound the maximum datagram lifetime. 208 154 */ 209 uint8_t 155 uint8_t ttl; 210 156 /** This field indicates the next level protocol used in the data portion of the internet datagram. 211 157 */ 212 uint8_t 158 uint8_t protocol; 213 159 /** A checksum of the header only. 214 160 * Since some header fields change (e.g., time to live), this is recomputed and verified at each point that the internet header is processed. … … 216 162 * For purposes of computing the checksum, the value of the checksum field is zero. 217 163 */ 218 uint16_t 164 uint16_t header_checksum; 219 165 /** The source address. 220 166 */ 221 uint32_t 167 uint32_t source_address; 222 168 /** The destination address. 223 169 */ 224 uint32_t 170 uint32_t destination_address; 225 171 } __attribute__ ((packed)); 172 173 /** Type definition of the internet option header. 174 * @see ip_header 175 */ 176 typedef struct ip_option ip_option_t; 177 178 /** Type definition of the internet option header pointer. 179 * @see ip_header 180 */ 181 typedef ip_option_t * ip_option_ref; 226 182 227 183 /** Internet option header. … … 232 188 /** A single octet of option-type. 233 189 */ 234 uint8_t 190 uint8_t type; 235 191 /** An option length octet. 236 192 */ 237 uint8_t 193 uint8_t length; 238 194 /** A~pointer. 239 195 */ 240 uint8_t 196 uint8_t pointer; 241 197 #ifdef ARCH_IS_BIG_ENDIAN 242 198 /** The number of IP modules that cannot register timestamps due to lack of space. 243 199 */ 244 uint8_t 200 uint8_t overflow:4; 245 201 /** Various internet timestamp control flags. 246 202 */ 247 uint8_t 203 uint8_t flags:4; 248 204 #else 249 205 /** Various internet timestamp control flags. 250 206 */ 251 uint8_t 207 uint8_t flags:4; 252 208 /** The number of IP modules that cannot register timestamps due to lack of space. 253 209 */ 254 uint8_t 210 uint8_t overflow:4; 255 211 #endif 256 212 } __attribute__ ((packed)); 213 214 /** @name IP flags definitions 215 */ 216 /*@{*/ 217 218 /** Fragment flag field shift. 219 */ 220 #define IPFLAG_FRAGMENT_SHIFT 1 221 222 /** Fragmented flag field shift. 223 */ 224 #define IPFLAG_FRAGMENTED_SHIFT 0 225 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_header 250 */ 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_header 255 */ 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.