Ignore:
File:
1 edited

Legend:

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

    ra64c64d r21580dd  
    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 )
     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
    4474/** Returns the fragment offest high bits.
    4575 *  @param[in] length The prefixed data total length.
    4676 */
    47 #define IP_COMPUTE_FRAGMENT_OFFSET_HIGH(length) ((((length) / 8u) &0x1F00) >> 8)
     77#define IP_COMPUTE_FRAGMENT_OFFSET_HIGH( length ) (((( length ) / 8u ) & 0x1F00 ) >> 8 )
    4878
    4979/** Returns the fragment offest low bits.
    5080 *  @param[in] length The prefixed data total length.
    5181 */
    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 )
    11783
    11884/** Type definition of the internet header.
     
    12591 */
    12692typedef 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;
    14793
    14894/** Internet header.
     
    15399        /** The Version field indicates the format of the internet header.
    154100         */
    155         uint8_t version:4;
     101        uint8_t         version:4;
    156102        /** Internet Header Length is the length of the internet header in 32~bit words, and thus points to the beginning of the data.
    157103         *  Note that the minimum value for a~correct header is~5.
    158104         */
    159         uint8_t header_length:4;
     105        uint8_t         header_length:4;
    160106#else
    161107        /** Internet Header Length is the length of the internet header in 32~bit words, and thus points to the beginning of the data.
    162108         *  Note that the minimum value for a~correct header is~5.
    163109         */
    164         uint8_t header_length:4;
     110        uint8_t         header_length:4;
    165111        /** The Version field indicates the format of the internet header.
    166112         */
    167         uint8_t version:4;
     113        uint8_t         version:4;
    168114#endif
    169115        /** The Type of Service provides an indication of the abstract parameters of the quality of service desired.
     
    172118         *  The major choice is a~three way tradeoff between low-delay, high-reliability, and high-throughput.
    173119         */
    174         uint8_t tos;
     120        uint8_t         tos;
    175121        /** Total Length is the length of the datagram, measured in octets, including internet header and data.
    176122         *  This field allows the length of a~datagram to be up to 65,535~octets.
    177123         */
    178         uint16_t total_length;
     124        uint16_t        total_length;
    179125        /** An identifying value assigned by the sender to aid in assembling the fragments of a~datagram.
    180126         */
    181         uint16_t identification;
     127        uint16_t        identification;
    182128#ifdef ARCH_IS_BIG_ENDIAN
    183129        /** Various control flags.
    184130         */
    185         uint8_t flags:3;
     131        uint8_t flags:3;
    186132        /** This field indicates where in the datagram this fragment belongs.
    187133         *  High bits.
    188134         */
    189         uint8_t fragment_offset_high:5;
     135        uint8_t fragment_offset_high:5;
    190136#else
    191137        /** This field indicates where in the datagram this fragment belongs.
    192138         *  High bits.
    193139         */
    194         uint8_t fragment_offset_high:5;
     140        uint8_t fragment_offset_high:5;
    195141        /** Various control flags.
    196142         */
    197         uint8_t flags:3;
     143        uint8_t flags:3;
    198144#endif
    199145        /** This field indicates where in the datagram this fragment belongs.
    200146         *  Low bits.
    201147         */
    202         uint8_t fragment_offset_low;
     148        uint8_t fragment_offset_low;
    203149        /** This field indicates the maximum time the datagram is allowed to remain in the internet system.
    204150         *  If this field contains the value zero, then the datagram must be destroyed.
     
    207153         *  The intention is to cause undeliverable datagrams to be discarded, and to bound the maximum datagram lifetime.
    208154         */
    209         uint8_t ttl;
     155        uint8_t         ttl;
    210156        /** This field indicates the next level protocol used in the data portion of the internet datagram.
    211157         */
    212         uint8_t protocol;
     158        uint8_t         protocol;
    213159        /** A checksum of the header only.
    214160         *  Since some header fields change (e.g., time to live), this is recomputed and verified at each point that the internet header is processed.
     
    216162         *  For purposes of computing the checksum, the value of the checksum field is zero.
    217163         */
    218         uint16_t header_checksum;
     164        uint16_t        header_checksum;
    219165        /** The source address.
    220166         */
    221         uint32_t source_address;
     167        uint32_t        source_address;
    222168        /** The destination address.
    223169         */
    224         uint32_t destination_address;
     170        uint32_t        destination_address;
    225171} __attribute__ ((packed));
     172
     173/** Type definition of the internet option header.
     174 *  @see ip_header
     175 */
     176typedef struct ip_option        ip_option_t;
     177
     178/** Type definition of the internet option header pointer.
     179 *  @see ip_header
     180 */
     181typedef ip_option_t *           ip_option_ref;
    226182
    227183/** Internet option header.
     
    232188        /** A single octet of option-type.
    233189         */
    234         uint8_t type;
     190        uint8_t         type;
    235191        /** An option length octet.
    236192         */
    237         uint8_t length;
     193        uint8_t         length;
    238194        /** A~pointer.
    239195         */
    240         uint8_t pointer;
     196        uint8_t         pointer;
    241197#ifdef ARCH_IS_BIG_ENDIAN
    242198        /** The number of IP modules that cannot register timestamps due to lack of space.
    243199         */
    244         uint8_t overflow:4;
     200        uint8_t overflow:4;
    245201        /** Various internet timestamp control flags.
    246202         */
    247         uint8_t flags:4;
     203        uint8_t flags:4;
    248204#else
    249205        /** Various internet timestamp control flags.
    250206         */
    251         uint8_t flags:4;
     207        uint8_t flags:4;
    252208        /** The number of IP modules that cannot register timestamps due to lack of space.
    253209         */
    254         uint8_t overflow:4;
     210        uint8_t overflow:4;
    255211#endif
    256212} __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 */
     251typedef 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 */
     256typedef 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.