Ignore:
File:
1 edited

Legend:

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

    re526f08 r46d4d9f  
    2727 */
    2828
    29 /** @addtogroup net_tl
    30  *  @{
     29/** @addtogroup libnet
     30 * @{
    3131 */
    3232
    3333/** @file
    34  *  Transport layer common functions implementation.
    35  *  @see tl_common.h
    36  */
     34 * Transport layer common functions implementation.
     35 * @see tl_common.h
     36 */
     37
     38#include <tl_common.h>
     39#include <packet_client.h>
     40#include <packet_remote.h>
     41#include <icmp_interface.h>
     42#include <ip_remote.h>
     43#include <ip_interface.h>
     44#include <tl_interface.h>
    3745
    3846#include <net/socket_codes.h>
     
    4048#include <net/in6.h>
    4149#include <net/inet.h>
     50#include <net/device.h>
     51#include <net/packet.h>
     52
    4253#include <async.h>
    4354#include <ipc/services.h>
    4455#include <errno.h>
    45 #include <err.h>
    46 
    47 #include <net/packet.h>
    48 #include <packet_client.h>
    49 #include <packet_remote.h>
    50 #include <net/device.h>
    51 #include <icmp_interface.h>
    52 #include <ip_remote.h>
    53 #include <ip_interface.h>
    54 #include <tl_interface.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 */
    5971int
    6072tl_get_address_port(const struct sockaddr *addr, int addrlen, uint16_t *port)
     
    7486                *port = ntohs(address_in->sin_port);
    7587                break;
     88       
    7689        case AF_INET6:
    7790                if (addrlen != sizeof(struct sockaddr_in6))
    78                                 return EINVAL;
     91                        return EINVAL;
    7992
    8093                address_in6 = (struct sockaddr_in6 *) addr;
    8194                *port = ntohs(address_in6->sin6_port);
    8295                break;
     96       
    8397        default:
    8498                return EAFNOSUPPORT;
     
    93107 * The reply is cached then.
    94108 *
    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  */
    107 int 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;
     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 */
     120int
     121tl_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;
    112126       
    113127        if (!packet_dimension)
     
    122136                        return ENOMEM;
    123137               
    124                 if (ERROR_OCCURRED(ip_packet_size_req(ip_phone, device_id,
    125                     *packet_dimension))) {
     138                rc = ip_packet_size_req(ip_phone, device_id, *packet_dimension);
     139                if (rc != EOK) {
    126140                        free(*packet_dimension);
    127                         return ERROR_CODE;
     141                        return rc;
    128142                }
    129143               
    130                 ERROR_CODE = packet_dimensions_add(packet_dimensions, device_id,
     144                rc = packet_dimensions_add(packet_dimensions, device_id,
    131145                    *packet_dimension);
    132                 if (ERROR_CODE < 0) {
     146                if (rc < 0) {
    133147                        free(*packet_dimension);
    134                         return ERROR_CODE;
     148                        return rc;
    135149                }
    136150        }
     
    139153}
    140154
    141 int
    142 tl_update_ip_packet_dimension(packet_dimensions_ref packet_dimensions,
     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 */
     163int
     164tl_update_ip_packet_dimension(packet_dimensions_t *packet_dimensions,
    143165    device_id_t device_id, size_t content)
    144166{
    145         packet_dimension_ref packet_dimension;
     167        packet_dimension_t *packet_dimension;
    146168
    147169        packet_dimension = packet_dimensions_find(packet_dimensions, device_id);
    148170        if (!packet_dimension)
    149171                return ENOENT;
     172
    150173        packet_dimension->content = content;
    151174
     
    160183                                packet_dimensions_exclude(packet_dimensions,
    161184                                    DEVICE_INVALID_ID);
    162 
    163185                }
    164186        }
     
    167189}
    168190
     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 */
    169203int tl_set_address_port(struct sockaddr * addr, int addrlen, uint16_t port)
    170204{
     
    187221                address_in->sin_port = htons(port);
    188222                return EOK;
     223       
    189224        case AF_INET6:
    190225                if (length != sizeof(struct sockaddr_in6))
     
    193228                address_in6->sin6_port = htons(port);
    194229                return EOK;
     230       
    195231        default:
    196232                return EAFNOSUPPORT;
     
    198234}
    199235
    200 int
    201 tl_prepare_icmp_packet(int packet_phone, int icmp_phone, packet_t packet,
     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 */
     249int
     250tl_prepare_icmp_packet(int packet_phone, int icmp_phone, packet_t *packet,
    202251    services_t error)
    203252{
    204         packet_t next;
     253        packet_t *next;
    205254        uint8_t *src;
    206255        int length;
     
    223272}
    224273
    225 int
    226 tl_socket_read_packet_data(int packet_phone, packet_ref packet, size_t prefix,
    227     const packet_dimension_ref dimension, const struct sockaddr *addr,
     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 */
     288int
     289tl_socket_read_packet_data(int packet_phone, packet_t **packet, size_t prefix,
     290    const packet_dimension_t *dimension, const struct sockaddr *addr,
    228291    socklen_t addrlen)
    229292{
    230         ERROR_DECLARE;
    231 
    232293        ipc_callid_t callid;
    233294        size_t length;
    234         void * data;
     295        void *data;
     296        int rc;
    235297
    236298        if (!dimension)
     
    255317
    256318        // read the data into the packet
    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))) {
     319        rc = async_data_write_finalize(callid, data, length);
     320        if (rc != EOK) {
    261321                pq_release_remote(packet_phone, packet_get_id(*packet));
    262                 return ERROR_CODE;
     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;
    263330        }
    264331
Note: See TracChangeset for help on using the changeset viewer.