Changeset 4a3b501 in mainline


Ignore:
Timestamp:
2010-10-17T19:19:27Z (14 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
42a9f27
Parents:
e037e20e
Message:

Cleanup ip_header.h.

Remove all comments that did not seem to have been written by the author of
ip_header.h himself, but rather taken from the RFC document.

Location:
uspace
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/net/include/ip_header.h

    re037e20e r4a3b501  
    2727 */
    2828
    29 /** @addtogroup ip
    30  *  @{
     29/** @addtogroup libnet
     30 * @{
    3131 */
    3232
    3333/** @file
    34  *  IP header and options definitions.
    35  *  Based on the RFC~791.
    36  */
    37 
    38 #ifndef __NET_IP_HEADER_H__
    39 #define __NET_IP_HEADER_H__
     34 * IP header and options definitions.
     35 * Based on the RFC 791.
     36 */
     37
     38#ifndef LIBNET_IP_HEADER_H_
     39#define LIBNET_IP_HEADER_H_
    4040
    4141#include <byteorder.h>
     
    4343
    4444/** 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)
     45 * @param[in] length The prefixed data total length.
     46 */
     47#define IP_COMPUTE_FRAGMENT_OFFSET_HIGH(length) \
     48        ((((length) / 8U) & 0x1f00) >> 8)
    4849
    4950/** 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)
     51 * @param[in] length The prefixed data total length.
     52 */
     53#define IP_COMPUTE_FRAGMENT_OFFSET_LOW(length) \
     54        (((length) / 8U) & 0xff)
    5355
    5456/** 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))
     57 * @param[in] length The IP header length in bytes.
     58 */
     59#define IP_COMPUTE_HEADER_LENGTH(length) \
     60        ((uint8_t) ((length) / 4U))
    5861
    5962/** 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 * @param[in] header The IP packet header.
     64 */
     65#define IP_FRAGMENT_OFFSET(header) \
     66        ((((header)->fragment_offset_high << 8) + \
     67            (header)->fragment_offset_low) * 8U)
    6368
    6469/** Returns the IP packet header checksum.
    6570 *  @param[in] header The IP packet header.
    6671 */
    67 #define IP_HEADER_CHECKSUM(header)      (htons(ip_checksum((uint8_t *)(header), IP_HEADER_LENGTH(header))))
     72#define IP_HEADER_CHECKSUM(header) \
     73        (htons(ip_checksum((uint8_t *) (header), IP_HEADER_LENGTH(header))))
    6874
    6975/** 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))
     76 * @param[in] header The IP packet header.
     77 */
     78#define IP_HEADER_DATA_LENGTH(header) \
     79        (IP_TOTAL_LENGTH(header) - IP_HEADER_LENGTH(header))
    7380
    7481/** 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)
     82 * @param[in] header The IP packet header.
     83 */
     84#define IP_HEADER_LENGTH(header) \
     85        ((header)->header_length * 4U)
    7886
    7987/** 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  */
     88 * @param[in] header The IP packet header.
     89 */
     90#define IP_TOTAL_LENGTH(header) \
     91        ntohs((header)->total_length)
     92
     93/** @name IP flags definitions */
    8694/*@{*/
    8795
    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
     96/** Fragment flag field shift. */
     97#define IPFLAG_FRAGMENT_SHIFT   1
     98
     99/** Fragmented flag field shift. */
     100#define IPFLAG_FRAGMENTED_SHIFT 0
    95101
    96102/** Don't fragment flag value.
    97  *  Permits the packet fragmentation.
    98  */
    99 #define IPFLAG_DONT_FRAGMENT            (0x1 << IPFLAG_FRAGMENT_SHIFT)
     103 * Permits the packet fragmentation.
     104 */
     105#define IPFLAG_DONT_FRAGMENT    (0x1 << IPFLAG_FRAGMENT_SHIFT)
    100106
    101107/** Last fragment flag value.
    102  *  Indicates the last packet fragment.
    103  */
    104 #define IPFLAG_LAST_FRAGMENT            (0x0 << IPFLAG_FRAGMENTED_SHIFT)
     108 * Indicates the last packet fragment.
     109 */
     110#define IPFLAG_LAST_FRAGMENT    (0x0 << IPFLAG_FRAGMENTED_SHIFT)
    105111
    106112/** May fragment flag value.
    107  *  Allows the packet fragmentation.
    108  */
    109 #define IPFLAG_MAY_FRAGMENT                     (0x0 << IPFLAG_FRAGMENT_SHIFT)
     113 * Allows the packet fragmentation.
     114 */
     115#define IPFLAG_MAY_FRAGMENT     (0x0 << IPFLAG_FRAGMENT_SHIFT)
    110116
    111117/** More fragments flag value.
    112  *  Indicates that more packet fragments follow.
    113  */
    114 #define IPFLAG_MORE_FRAGMENTS           (0x1 << IPFLAG_FRAGMENTED_SHIFT)
     118 * Indicates that more packet fragments follow.
     119 */
     120#define IPFLAG_MORE_FRAGMENTS   (0x1 << IPFLAG_FRAGMENTED_SHIFT)
    115121
    116122/*@}*/
    117123
    118124/** Type definition of the internet header.
    119  *  @see ip_header
    120  */
    121 typedef struct ip_header        ip_header_t;
     125 * @see ip_header
     126 */
     127typedef struct ip_header ip_header_t;
    122128
    123129/** Type definition of the internet header pointer.
    124  *  @see ip_header
    125  */
    126 typedef ip_header_t *           ip_header_ref;
     130 * @see ip_header
     131 */
     132typedef ip_header_t *ip_header_ref;
    127133
    128134/** Type definition of the internet option header.
    129  *  @see ip_header
    130  */
    131 typedef struct ip_option        ip_option_t;
     135 * @see ip_header
     136 */
     137typedef struct ip_option ip_option_t;
    132138
    133139/** Type definition of the internet option header pointer.
    134  *  @see ip_header
    135  */
    136 typedef ip_option_t *           ip_option_ref;
     140 * @see ip_header
     141 */
     142typedef ip_option_t *ip_option_ref;
    137143
    138144/** 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;
     145 * @see ipv4_pseudo_header
     146 */
     147typedef struct ipv4_pseudo_header ipv4_pseudo_header_t;
    142148
    143149/** 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;
     150 * @see ipv4_pseudo_header
     151 */
     152typedef ipv4_pseudo_header_t *ipv4_pseudo_header_ref;
    147153
    148154/** Internet header.
    149  *  The variable options should be included after the header itself and indicated by the increased header length value.
    150  */
    151 struct ip_header{
     155 *
     156 * The variable options should be included after the header itself and
     157 * indicated by the increased header length value.
     158 */
     159struct ip_header {
    152160#ifdef ARCH_IS_BIG_ENDIAN
    153         /** The Version field indicates the format of the internet header.
    154          */
    155         uint8_t version:4;
    156         /** Internet Header Length is the length of the internet header in 32~bit words, and thus points to the beginning of the data.
    157          *  Note that the minimum value for a~correct header is~5.
    158          */
    159         uint8_t header_length:4;
     161        uint8_t version : 4;
     162        uint8_t header_length : 4;
    160163#else
    161         /** Internet Header Length is the length of the internet header in 32~bit words, and thus points to the beginning of the data.
    162          *  Note that the minimum value for a~correct header is~5.
    163          */
    164         uint8_t header_length:4;
    165         /** The Version field indicates the format of the internet header.
    166          */
    167         uint8_t version:4;
    168 #endif
    169         /** The Type of Service provides an indication of the abstract parameters of the quality of service desired.
    170          *  These parameters are to be used to guide the selection of the actual service parameters when transmitting a~datagram through a~particular network.
    171          *  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).
    172          *  The major choice is a~three way tradeoff between low-delay, high-reliability, and high-throughput.
    173          */
     164        uint8_t header_length : 4;
     165        uint8_t version : 4;
     166#endif
     167
    174168        uint8_t tos;
    175         /** Total Length is the length of the datagram, measured in octets, including internet header and data.
    176          *  This field allows the length of a~datagram to be up to 65,535~octets.
    177          */
    178169        uint16_t total_length;
    179         /** An identifying value assigned by the sender to aid in assembling the fragments of a~datagram.
    180          */
    181170        uint16_t identification;
     171
    182172#ifdef ARCH_IS_BIG_ENDIAN
    183         /** Various control flags.
    184          */
    185         uint8_t flags:3;
    186         /** This field indicates where in the datagram this fragment belongs.
    187          *  High bits.
    188          */
    189         uint8_t fragment_offset_high:5;
     173        uint8_t flags : 3;
     174        uint8_t fragment_offset_high : 5;
    190175#else
    191         /** This field indicates where in the datagram this fragment belongs.
    192          *  High bits.
    193          */
    194         uint8_t fragment_offset_high:5;
    195         /** Various control flags.
    196          */
    197         uint8_t flags:3;
    198 #endif
    199         /** This field indicates where in the datagram this fragment belongs.
    200          *  Low bits.
    201          */
     176        uint8_t fragment_offset_high : 5;
     177        uint8_t flags : 3;
     178#endif
     179
    202180        uint8_t fragment_offset_low;
    203         /** This field indicates the maximum time the datagram is allowed to remain in the internet system.
    204          *  If this field contains the value zero, then the datagram must be destroyed.
    205          *  This field is modified in internet header processing.
    206          *  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.
    207          *  The intention is to cause undeliverable datagrams to be discarded, and to bound the maximum datagram lifetime.
    208          */
    209181        uint8_t ttl;
    210         /** This field indicates the next level protocol used in the data portion of the internet datagram.
    211          */
    212182        uint8_t protocol;
    213         /** A checksum of the header only.
    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.
    215          *  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.
    216          *  For purposes of computing the checksum, the value of the checksum field is zero.
    217          */
    218183        uint16_t header_checksum;
    219         /** The source address.
    220          */
    221184        uint32_t source_address;
    222         /** The destination address.
    223          */
    224185        uint32_t destination_address;
    225186} __attribute__ ((packed));
    226187
    227188/** Internet option header.
    228  *  Only type field is always valid.
    229  *  Other fields' validity depends on the option type.
    230  */
    231 struct ip_option{
    232         /** A single octet of option-type.
    233          */
     189 *
     190 * Only type field is always valid.
     191 * Other fields' validity depends on the option type.
     192 */
     193struct ip_option {
    234194        uint8_t type;
    235         /** An option length octet.
    236          */
    237195        uint8_t length;
    238         /** A~pointer.
    239          */
    240196        uint8_t pointer;
     197
    241198#ifdef ARCH_IS_BIG_ENDIAN
    242         /** The number of IP modules that cannot register timestamps due to lack of space.
    243          */
    244         uint8_t overflow:4;
    245         /** Various internet timestamp control flags.
    246          */
    247         uint8_t flags:4;
     199        uint8_t overflow : 4;
     200        uint8_t flags : 4;
    248201#else
    249         /** Various internet timestamp control flags.
    250          */
    251         uint8_t flags:4;
    252         /** The number of IP modules that cannot register timestamps due to lack of space.
    253          */
    254         uint8_t overflow:4;
     202        uint8_t flags : 4;
     203        uint8_t overflow : 4;
    255204#endif
    256205} __attribute__ ((packed));
    257206
    258 /** Internet version 4 pseudo header.
    259  */
    260 struct ipv4_pseudo_header{
    261         /** The source address.
    262          */
     207/** Internet version 4 pseudo header. */
     208struct ipv4_pseudo_header {
    263209        uint32_t source_address;
    264         /** The destination address.
    265          */
    266210        uint32_t destination_address;
    267         /** Reserved byte.
    268          *  Must be zero.
    269          */
    270211        uint8_t reserved;
    271         /** This field indicates the next level protocol used in the data portion of the internet datagram.
    272          */
    273212        uint8_t protocol;
    274         /** Data length is the length of the datagram, measured in octets.
    275          */
    276213        uint16_t data_length;
    277214} __attribute__ ((packed));
  • uspace/srv/net/il/ip/ip.c

    re037e20e r4a3b501  
    6767#include <ip_client.h>
    6868#include <ip_interface.h>
     69#include <ip_header.h>
    6970#include <net_interface.h>
    7071#include <nil_interface.h>
     
    7778
    7879#include "ip.h"
    79 #include "ip_header.h"
    8080#include "ip_module.h"
    8181#include "ip_local.h"
Note: See TracChangeset for help on using the changeset viewer.