Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/net/tl/tl_common.c

    r46d4d9f re526f08  
    2727 */
    2828
    29 /** @addtogroup libnet
    30  * @{
     29/** @addtogroup net_tl
     30 *  @{
    3131 */
    3232
    3333/** @file
    34  * Transport layer common functions implementation.
    35  * @see tl_common.h
    36  */
    37 
    38 #include <tl_common.h>
     34 *  Transport layer common functions implementation.
     35 *  @see tl_common.h
     36 */
     37
     38#include <net/socket_codes.h>
     39#include <net/in.h>
     40#include <net/in6.h>
     41#include <net/inet.h>
     42#include <async.h>
     43#include <ipc/services.h>
     44#include <errno.h>
     45#include <err.h>
     46
     47#include <net/packet.h>
    3948#include <packet_client.h>
    4049#include <packet_remote.h>
     50#include <net/device.h>
    4151#include <icmp_interface.h>
    4252#include <ip_remote.h>
    4353#include <ip_interface.h>
    4454#include <tl_interface.h>
    45 
    46 #include <net/socket_codes.h>
    47 #include <net/in.h>
    48 #include <net/in6.h>
    49 #include <net/inet.h>
    50 #include <net/device.h>
    51 #include <net/packet.h>
    52 
    53 #include <async.h>
    54 #include <ipc/services.h>
    55 #include <errno.h>
     55#include <tl_common.h>
    5656
    5757DEVICE_MAP_IMPLEMENT(packet_dimensions, packet_dimension_t);
    5858
    59 /** Gets the address port.
    60  *
    61  * Supports AF_INET and AF_INET6 address families.
    62  *
    63  * @param[in,out] addr  The address to be updated.
    64  * @param[in] addrlen   The address length.
    65  * @param[out] port     The set port.
    66  * @return              EOK on success.
    67  * @return              EINVAL if the address length does not match the address
    68  *                      family.
    69  * @return              EAFNOSUPPORT if the address family is not supported.
    70  */
    7159int
    7260tl_get_address_port(const struct sockaddr *addr, int addrlen, uint16_t *port)
     
    8674                *port = ntohs(address_in->sin_port);
    8775                break;
    88        
    8976        case AF_INET6:
    9077                if (addrlen != sizeof(struct sockaddr_in6))
    91                         return EINVAL;
     78                                return EINVAL;
    9279
    9380                address_in6 = (struct sockaddr_in6 *) addr;
    9481                *port = ntohs(address_in6->sin6_port);
    9582                break;
    96        
    9783        default:
    9884                return EAFNOSUPPORT;
     
    10793 * The reply is cached then.
    10894 *
    109  * @param[in] ip_phone  The IP moduel phone for (semi)remote calls.
    110  * @param[in] packet_dimensions The packet dimensions cache.
    111  * @param[in] device_id The device identifier.
    112  * @param[out] packet_dimension The IP packet dimensions.
    113  * @return              EOK on success.
    114  * @return              EBADMEM if the packet_dimension parameter is NULL.
    115  * @return              ENOMEM if there is not enough memory left.
    116  * @return              EINVAL if the packet_dimensions cache is not valid.
    117  * @return              Other codes as defined for the ip_packet_size_req()
    118  *                      function.
    119  */
    120 int
    121 tl_get_ip_packet_dimension(int ip_phone,
    122     packet_dimensions_t *packet_dimensions, device_id_t device_id,
    123     packet_dimension_t **packet_dimension)
    124 {
    125         int rc;
     95 * @param[in]  ip_phone          The IP moduel phone for (semi)remote calls.
     96 * @param[in]  packet_dimensions The packet dimensions cache.
     97 * @param[in]  device_id         The device identifier.
     98 * @param[out] packet_dimension  The IP packet dimensions.
     99 *
     100 * @return EOK on success.
     101 * @return EBADMEM if the packet_dimension parameter is NULL.
     102 * @return ENOMEM if there is not enough memory left.
     103 * @return EINVAL if the packet_dimensions cache is not valid.
     104 * @return Other codes as defined for the ip_packet_size_req() function.
     105 *
     106 */
     107int tl_get_ip_packet_dimension(int ip_phone,
     108    packet_dimensions_ref packet_dimensions, device_id_t device_id,
     109    packet_dimension_ref *packet_dimension)
     110{
     111        ERROR_DECLARE;
    126112       
    127113        if (!packet_dimension)
     
    136122                        return ENOMEM;
    137123               
    138                 rc = ip_packet_size_req(ip_phone, device_id, *packet_dimension);
    139                 if (rc != EOK) {
     124                if (ERROR_OCCURRED(ip_packet_size_req(ip_phone, device_id,
     125                    *packet_dimension))) {
    140126                        free(*packet_dimension);
    141                         return rc;
     127                        return ERROR_CODE;
    142128                }
    143129               
    144                 rc = packet_dimensions_add(packet_dimensions, device_id,
     130                ERROR_CODE = packet_dimensions_add(packet_dimensions, device_id,
    145131                    *packet_dimension);
    146                 if (rc < 0) {
     132                if (ERROR_CODE < 0) {
    147133                        free(*packet_dimension);
    148                         return rc;
     134                        return ERROR_CODE;
    149135                }
    150136        }
     
    153139}
    154140
    155 /** Updates IP device packet dimensions cache.
    156  *
    157  * @param[in,out] packet_dimensions The packet dimensions cache.
    158  * @param[in] device_id The device identifier.
    159  * @param[in] content   The new maximum content size.
    160  * @return              EOK on success.
    161  * @return              ENOENT if the packet dimension is not cached.
    162  */
    163 int
    164 tl_update_ip_packet_dimension(packet_dimensions_t *packet_dimensions,
     141int
     142tl_update_ip_packet_dimension(packet_dimensions_ref packet_dimensions,
    165143    device_id_t device_id, size_t content)
    166144{
    167         packet_dimension_t *packet_dimension;
     145        packet_dimension_ref packet_dimension;
    168146
    169147        packet_dimension = packet_dimensions_find(packet_dimensions, device_id);
    170148        if (!packet_dimension)
    171149                return ENOENT;
    172 
    173150        packet_dimension->content = content;
    174151
     
    183160                                packet_dimensions_exclude(packet_dimensions,
    184161                                    DEVICE_INVALID_ID);
     162
    185163                }
    186164        }
     
    189167}
    190168
    191 /** Sets the address port.
    192  *
    193  * Supports AF_INET and AF_INET6 address families.
    194  *
    195  * @param[in,out] addr  The address to be updated.
    196  * @param[in] addrlen   The address length.
    197  * @param[in] port      The port to be set.
    198  * @return              EOK on success.
    199  * @return              EINVAL if the address length does not match the address
    200  *                      family.
    201  * @return              EAFNOSUPPORT if the address family is not supported.
    202  */
    203169int tl_set_address_port(struct sockaddr * addr, int addrlen, uint16_t port)
    204170{
     
    221187                address_in->sin_port = htons(port);
    222188                return EOK;
    223        
    224189        case AF_INET6:
    225190                if (length != sizeof(struct sockaddr_in6))
     
    228193                address_in6->sin6_port = htons(port);
    229194                return EOK;
    230        
    231195        default:
    232196                return EAFNOSUPPORT;
     
    234198}
    235199
    236 /** Prepares the packet for ICMP error notification.
    237  *
    238  * Keeps the first packet and releases all the others.
    239  * Releases all the packets on error.
    240  *
    241  * @param[in] packet_phone The packet server module phone.
    242  * @param[in] icmp_phone The ICMP module phone.
    243  * @param[in] packet    The packet to be send.
    244  * @param[in] error     The packet error reporting service. Prefixes the
    245  *                      received packet.
    246  * @return              EOK on success.
    247  * @return              ENOENT if no packet may be sent.
    248  */
    249 int
    250 tl_prepare_icmp_packet(int packet_phone, int icmp_phone, packet_t *packet,
     200int
     201tl_prepare_icmp_packet(int packet_phone, int icmp_phone, packet_t packet,
    251202    services_t error)
    252203{
    253         packet_t *next;
     204        packet_t next;
    254205        uint8_t *src;
    255206        int length;
     
    272223}
    273224
    274 /** Receives data from the socket into a packet.
    275  *
    276  * @param[in] packet_phone The packet server module phone.
    277  * @param[out] packet   The new created packet.
    278  * @param[in] prefix    Reserved packet data prefix length.
    279  * @param[in] dimension The packet dimension.
    280  * @param[in] addr      The destination address.
    281  * @param[in] addrlen   The address length.
    282  * @return              Number of bytes received.
    283  * @return              EINVAL if the client does not send data.
    284  * @return              ENOMEM if there is not enough memory left.
    285  * @return              Other error codes as defined for the
    286  *                      async_data_read_finalize() function.
    287  */
    288 int
    289 tl_socket_read_packet_data(int packet_phone, packet_t **packet, size_t prefix,
    290     const packet_dimension_t *dimension, const struct sockaddr *addr,
     225int
     226tl_socket_read_packet_data(int packet_phone, packet_ref packet, size_t prefix,
     227    const packet_dimension_ref dimension, const struct sockaddr *addr,
    291228    socklen_t addrlen)
    292229{
     230        ERROR_DECLARE;
     231
    293232        ipc_callid_t callid;
    294233        size_t length;
    295         void *data;
    296         int rc;
     234        void * data;
    297235
    298236        if (!dimension)
     
    317255
    318256        // read the data into the packet
    319         rc = async_data_write_finalize(callid, data, length);
    320         if (rc != EOK) {
     257        if (ERROR_OCCURRED(async_data_write_finalize(callid, data, length)) ||
     258            // set the packet destination address
     259            ERROR_OCCURRED(packet_set_addr(*packet, NULL, (uint8_t *) addr,
     260            addrlen))) {
    321261                pq_release_remote(packet_phone, packet_get_id(*packet));
    322                 return rc;
    323         }
    324        
    325         // set the packet destination address
    326         rc = packet_set_addr(*packet, NULL, (uint8_t *) addr, addrlen);
    327         if (rc != EOK) {
    328                 pq_release_remote(packet_phone, packet_get_id(*packet));
    329                 return rc;
     262                return ERROR_CODE;
    330263        }
    331264
Note: See TracChangeset for help on using the changeset viewer.