Changeset a64c64d in mainline for uspace/srv/net/il/ip/ip_client.c


Ignore:
Timestamp:
2010-03-09T22:24:31Z (14 years ago)
Author:
Lukas Mejdrech <lukasmejdrech@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
74520daf
Parents:
9f2ea28
Message:
  • code reorganization (no functional change)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/net/il/ip/ip_client.c

    r9f2ea28 ra64c64d  
    4848#include "ip_header.h"
    4949
    50 int ip_client_prepare_packet(packet_t packet, ip_protocol_t protocol, ip_ttl_t ttl, ip_tos_t tos, int dont_fragment, size_t ipopt_length){
    51         ip_header_ref header;
    52         uint8_t * data;
    53         size_t padding;
    54 
    55         padding =  ipopt_length % 4;
    56         if(padding){
    57                 padding = 4 - padding;
    58                 ipopt_length += padding;
    59         }
    60         data = (uint8_t *) packet_prefix(packet, sizeof(ip_header_t) + padding);
    61         if(! data){
    62                 return ENOMEM;
    63         }
    64         while(padding --){
    65                 data[sizeof(ip_header_t) + padding] = IPOPT_NOOP;
    66         }
    67         header = (ip_header_ref) data;
    68         header->header_length = IP_COMPUTE_HEADER_LENGTH(sizeof(ip_header_t) + ipopt_length);
    69         header->ttl = (ttl ? ttl : IPDEFTTL); //(((ttl) <= MAXTTL) ? ttl : MAXTTL) : IPDEFTTL;
    70         header->tos = tos;
    71         header->protocol = protocol;
    72         if(dont_fragment){
    73                 header->flags = IPFLAG_DONT_FRAGMENT;
    74         }
    75         return EOK;
    76 }
    77 
    78 int ip_client_process_packet(packet_t packet, ip_protocol_t * protocol, ip_ttl_t * ttl, ip_tos_t * tos, int * dont_fragment, size_t * ipopt_length){
    79         ip_header_ref header;
    80 
    81         header = (ip_header_ref) packet_get_data(packet);
    82         if((! header)
    83                 || (packet_get_data_length(packet) < sizeof(ip_header_t))){
    84                 return ENOMEM;
    85         }
    86         if(protocol){
    87                 *protocol = header->protocol;
    88         }
    89         if(ttl){
    90                 *ttl = header->ttl;
    91         }
    92         if(tos){
    93                 *tos = header->tos;
    94         }
    95         if(dont_fragment){
    96                 *dont_fragment = header->flags &IPFLAG_DONT_FRAGMENT;
    97         }
    98         if(ipopt_length){
    99                 *ipopt_length = IP_HEADER_LENGTH(header) - sizeof(ip_header_t);
    100                 return sizeof(ip_header_t);
    101         }else{
    102                 return IP_HEADER_LENGTH(header);
    103         }
    104 }
    105 
    10650size_t ip_client_header_length(packet_t packet){
    10751        ip_header_ref header;
     
    11357        }
    11458        return IP_HEADER_LENGTH(header);
    115 }
    116 
    117 int ip_client_set_pseudo_header_data_length(ip_pseudo_header_ref header, size_t headerlen, size_t data_length){
    118         ipv4_pseudo_header_ref header_in;
    119 
    120         if(! header){
    121                 return EBADMEM;
    122         }
    123         if(headerlen == sizeof(ipv4_pseudo_header_t)){
    124                 header_in = (ipv4_pseudo_header_ref) header;
    125                 header_in->data_length = htons(data_length);
    126                 return EOK;
    127         }else{
    128                 return EINVAL;
    129         }
    13059}
    13160
     
    14069                return EINVAL;
    14170        }
     71
    14272        switch(src->sa_family){
    14373                case AF_INET:
     
    171101}
    172102
     103int ip_client_prepare_packet(packet_t packet, ip_protocol_t protocol, ip_ttl_t ttl, ip_tos_t tos, int dont_fragment, size_t ipopt_length){
     104        ip_header_ref header;
     105        uint8_t * data;
     106        size_t padding;
     107
     108        // compute the padding if IP options are set
     109        // multiple of 4 bytes
     110        padding =  ipopt_length % 4;
     111        if(padding){
     112                padding = 4 - padding;
     113                ipopt_length += padding;
     114        }
     115
     116        // prefix the header
     117        data = (uint8_t *) packet_prefix(packet, sizeof(ip_header_t) + padding);
     118        if(! data){
     119                return ENOMEM;
     120        }
     121
     122        // add the padding
     123        while(padding --){
     124                data[sizeof(ip_header_t) + padding] = IPOPT_NOOP;
     125        }
     126
     127        // set the header
     128        header = (ip_header_ref) data;
     129        header->header_length = IP_COMPUTE_HEADER_LENGTH(sizeof(ip_header_t) + ipopt_length);
     130        header->ttl = (ttl ? ttl : IPDEFTTL); //(((ttl) <= MAXTTL) ? ttl : MAXTTL) : IPDEFTTL;
     131        header->tos = tos;
     132        header->protocol = protocol;
     133
     134        if(dont_fragment){
     135                header->flags = IPFLAG_DONT_FRAGMENT;
     136        }
     137        return EOK;
     138}
     139
     140int ip_client_process_packet(packet_t packet, ip_protocol_t * protocol, ip_ttl_t * ttl, ip_tos_t * tos, int * dont_fragment, size_t * ipopt_length){
     141        ip_header_ref header;
     142
     143        header = (ip_header_ref) packet_get_data(packet);
     144        if((! header)
     145                || (packet_get_data_length(packet) < sizeof(ip_header_t))){
     146                return ENOMEM;
     147        }
     148
     149        if(protocol){
     150                *protocol = header->protocol;
     151        }
     152        if(ttl){
     153                *ttl = header->ttl;
     154        }
     155        if(tos){
     156                *tos = header->tos;
     157        }
     158        if(dont_fragment){
     159                *dont_fragment = header->flags &IPFLAG_DONT_FRAGMENT;
     160        }
     161        if(ipopt_length){
     162                *ipopt_length = IP_HEADER_LENGTH(header) - sizeof(ip_header_t);
     163                return sizeof(ip_header_t);
     164        }else{
     165                return IP_HEADER_LENGTH(header);
     166        }
     167}
     168
     169int ip_client_set_pseudo_header_data_length(ip_pseudo_header_ref header, size_t headerlen, size_t data_length){
     170        ipv4_pseudo_header_ref header_in;
     171
     172        if(! header){
     173                return EBADMEM;
     174        }
     175
     176        if(headerlen == sizeof(ipv4_pseudo_header_t)){
     177                header_in = (ipv4_pseudo_header_ref) header;
     178                header_in->data_length = htons(data_length);
     179                return EOK;
     180        // TODO IPv6
     181        }else{
     182                return EINVAL;
     183        }
     184}
     185
    173186/** @}
    174187 */
Note: See TracChangeset for help on using the changeset viewer.