Changeset 7715994 in mainline for uspace/srv/net/il/ip/ip_header.h


Ignore:
Timestamp:
2010-03-13T12:17:02Z (15 years ago)
Author:
Jiri Svoboda <jiri@…>
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.
Message:

Merge mainline changes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/net/il/ip/ip_header.h

    rd0febca r7715994  
    4242#include <sys/types.h>
    4343
    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)
    4853
    4954/** Returns the IP header length.
    5055 *  @param[in] length The IP header length in bytes.
    5156 */
    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)
    5378
    5479/** Returns the actual IP packet total length.
    5580 *  @param[in] header The IP packet header.
    5681 */
    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/*@}*/
    83117
    84118/** Type definition of the internet header.
     
    91125 */
    92126typedef ip_header_t *           ip_header_ref;
     127
     128/** Type definition of the internet option header.
     129 *  @see ip_header
     130 */
     131typedef struct ip_option        ip_option_t;
     132
     133/** Type definition of the internet option header pointer.
     134 *  @see ip_header
     135 */
     136typedef ip_option_t *           ip_option_ref;
     137
     138/** Type definition of the internet version 4 pseudo header.
     139 *  @see ipv4_pseudo_header
     140 */
     141typedef 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 */
     146typedef ipv4_pseudo_header_t *          ipv4_pseudo_header_ref;
    93147
    94148/** Internet header.
     
    99153        /** The Version field indicates the format of the internet header.
    100154         */
    101         uint8_t         version:4;
     155        uint8_t version:4;
    102156        /** Internet Header Length is the length of the internet header in 32~bit words, and thus points to the beginning of the data.
    103157         *  Note that the minimum value for a~correct header is~5.
    104158         */
    105         uint8_t         header_length:4;
     159        uint8_t header_length:4;
    106160#else
    107161        /** Internet Header Length is the length of the internet header in 32~bit words, and thus points to the beginning of the data.
    108162         *  Note that the minimum value for a~correct header is~5.
    109163         */
    110         uint8_t         header_length:4;
     164        uint8_t header_length:4;
    111165        /** The Version field indicates the format of the internet header.
    112166         */
    113         uint8_t         version:4;
     167        uint8_t version:4;
    114168#endif
    115169        /** The Type of Service provides an indication of the abstract parameters of the quality of service desired.
     
    118172         *  The major choice is a~three way tradeoff between low-delay, high-reliability, and high-throughput.
    119173         */
    120         uint8_t         tos;
     174        uint8_t tos;
    121175        /** Total Length is the length of the datagram, measured in octets, including internet header and data.
    122176         *  This field allows the length of a~datagram to be up to 65,535~octets.
    123177         */
    124         uint16_t        total_length;
     178        uint16_t total_length;
    125179        /** An identifying value assigned by the sender to aid in assembling the fragments of a~datagram.
    126180         */
    127         uint16_t        identification;
     181        uint16_t identification;
    128182#ifdef ARCH_IS_BIG_ENDIAN
    129183        /** Various control flags.
    130184         */
    131         uint8_t flags:3;
     185        uint8_t flags:3;
    132186        /** This field indicates where in the datagram this fragment belongs.
    133187         *  High bits.
    134188         */
    135         uint8_t fragment_offset_high:5;
     189        uint8_t fragment_offset_high:5;
    136190#else
    137191        /** This field indicates where in the datagram this fragment belongs.
    138192         *  High bits.
    139193         */
    140         uint8_t fragment_offset_high:5;
     194        uint8_t fragment_offset_high:5;
    141195        /** Various control flags.
    142196         */
    143         uint8_t flags:3;
     197        uint8_t flags:3;
    144198#endif
    145199        /** This field indicates where in the datagram this fragment belongs.
    146200         *  Low bits.
    147201         */
    148         uint8_t fragment_offset_low;
     202        uint8_t fragment_offset_low;
    149203        /** This field indicates the maximum time the datagram is allowed to remain in the internet system.
    150204         *  If this field contains the value zero, then the datagram must be destroyed.
     
    153207         *  The intention is to cause undeliverable datagrams to be discarded, and to bound the maximum datagram lifetime.
    154208         */
    155         uint8_t         ttl;
     209        uint8_t ttl;
    156210        /** This field indicates the next level protocol used in the data portion of the internet datagram.
    157211         */
    158         uint8_t         protocol;
     212        uint8_t protocol;
    159213        /** A checksum of the header only.
    160214         *  Since some header fields change (e.g., time to live), this is recomputed and verified at each point that the internet header is processed.
     
    162216         *  For purposes of computing the checksum, the value of the checksum field is zero.
    163217         */
    164         uint16_t        header_checksum;
     218        uint16_t header_checksum;
    165219        /** The source address.
    166220         */
    167         uint32_t        source_address;
     221        uint32_t source_address;
    168222        /** The destination address.
    169223         */
    170         uint32_t        destination_address;
     224        uint32_t destination_address;
    171225} __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;
    182226
    183227/** Internet option header.
     
    188232        /** A single octet of option-type.
    189233         */
    190         uint8_t         type;
     234        uint8_t type;
    191235        /** An option length octet.
    192236         */
    193         uint8_t         length;
     237        uint8_t length;
    194238        /** A~pointer.
    195239         */
    196         uint8_t         pointer;
     240        uint8_t pointer;
    197241#ifdef ARCH_IS_BIG_ENDIAN
    198242        /** The number of IP modules that cannot register timestamps due to lack of space.
    199243         */
    200         uint8_t overflow:4;
     244        uint8_t overflow:4;
    201245        /** Various internet timestamp control flags.
    202246         */
    203         uint8_t flags:4;
     247        uint8_t flags:4;
    204248#else
    205249        /** Various internet timestamp control flags.
    206250         */
    207         uint8_t flags:4;
     251        uint8_t flags:4;
    208252        /** The number of IP modules that cannot register timestamps due to lack of space.
    209253         */
    210         uint8_t overflow:4;
     254        uint8_t overflow:4;
    211255#endif
    212256} __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;
    257257
    258258/** Internet version 4 pseudo header.
     
    261261        /** The source address.
    262262         */
    263         uint32_t        source_address;
     263        uint32_t source_address;
    264264        /** The destination address.
    265265         */
    266         uint32_t        destination_address;
     266        uint32_t destination_address;
    267267        /** Reserved byte.
    268268         *  Must be zero.
    269269         */
    270         uint8_t         reserved;
     270        uint8_t reserved;
    271271        /** This field indicates the next level protocol used in the data portion of the internet datagram.
    272272         */
    273         uint8_t         protocol;
     273        uint8_t protocol;
    274274        /** Data length is the length of the datagram, measured in octets.
    275275         */
    276         uint16_t        data_length;
     276        uint16_t data_length;
    277277} __attribute__ ((packed));
    278278
Note: See TracChangeset for help on using the changeset viewer.