Changeset 84c20da in mainline


Ignore:
Timestamp:
2010-10-17T22:07:45Z (14 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
1b11576d
Parents:
25171e5
Message:

Cleanup transport layer common functions.

Location:
uspace/lib/net
Files:
2 edited

Legend:

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

    r25171e5 r84c20da  
    2727 */
    2828
    29 /** @addtogroup net_tl
    30  *  @{
     29/** @addtogroup libnet
     30 * @{
    3131 */
    3232
    3333/** @file
    34  *  Transport layer common functions.
     34 * Transport layer common functions.
    3535 */
    3636
    37 #ifndef __NET_TL_COMMON_H__
    38 #define __NET_TL_COMMON_H__
     37#ifndef LIBNET_TL_COMMON_H_
     38#define LIBNET_TL_COMMON_H_
     39
     40#include <ipc/services.h>
    3941
    4042#include <net/socket_codes.h>
     
    4446
    4547/** Device packet dimensions.
    46  *  Maps devices to the packet dimensions.
    47  *  @see device.h
     48 * Maps devices to the packet dimensions.
     49 * @see device.h
    4850 */
    4951DEVICE_MAP_DECLARE(packet_dimensions, packet_dimension_t);
     
    5153extern int tl_get_ip_packet_dimension(int, packet_dimensions_ref,
    5254    device_id_t, packet_dimension_ref *);
    53 
    54 /** Gets the address port.
    55  *  Supports AF_INET and AF_INET6 address families.
    56  *  @param[in,out] addr The address to be updated.
    57  *  @param[in] addrlen The address length.
    58  *  @param[out] port The set port.
    59  *  @returns EOK on success.
    60  *  @returns EINVAL if the address length does not match the address family.
    61  *  @returns EAFNOSUPPORT if the address family is not supported.
    62  */
    63 extern int tl_get_address_port(const struct sockaddr * addr, int addrlen, uint16_t * port);
    64 
    65 /** Updates IP device packet dimensions cache.
    66  *  @param[in,out] packet_dimensions The packet dimensions cache.
    67  *  @param[in] device_id The device identifier.
    68  *  @param[in] content The new maximum content size.
    69  *  @returns EOK on success.
    70  *  @returns ENOENT if the packet dimension is not cached.
    71  */
    72 extern int tl_update_ip_packet_dimension(packet_dimensions_ref packet_dimensions, device_id_t device_id, size_t content);
    73 
    74 /** Sets the address port.
    75  *  Supports AF_INET and AF_INET6 address families.
    76  *  @param[in,out] addr The address to be updated.
    77  *  @param[in] addrlen The address length.
    78  *  @param[in] port The port to be set.
    79  *  @returns EOK on success.
    80  *  @returns EINVAL if the address length does not match the address family.
    81  *  @returns EAFNOSUPPORT if the address family is not supported.
    82  */
    83 extern int tl_set_address_port(struct sockaddr * addr, int addrlen, uint16_t port);
    84 
    85 /** Prepares the packet for ICMP error notification.
    86  *  Keeps the first packet and releases all the others.
    87  *  Releases all the packets on error.
    88  *  @param[in] packet_phone The packet server module phone.
    89  *  @param[in] icmp_phone The ICMP module phone.
    90  *  @param[in] packet The packet to be send.
    91  *  @param[in] error The packet error reporting service. Prefixes the received packet.
    92  *  @returns EOK on success.
    93  *  @returns ENOENT if no packet may be sent.
    94  */
    95 extern int tl_prepare_icmp_packet(int packet_phone, int icmp_phone, packet_t packet, services_t error);
    96 
    97 /** Receives data from the socket into a packet.
    98  *  @param[in] packet_phone The packet server module phone.
    99  *  @param[out] packet The new created packet.
    100  *  @param[in] prefix Reserved packet data prefix length.
    101  *  @param[in] dimension The packet dimension.
    102  *  @param[in] addr The destination address.
    103  *  @param[in] addrlen The address length.
    104  *  @returns Number of bytes received.
    105  *  @returns EINVAL if the client does not send data.
    106  *  @returns ENOMEM if there is not enough memory left.
    107  *  @returns Other error codes as defined for the async_data_read_finalize() function.
    108  */
    109 extern int tl_socket_read_packet_data(int packet_phone, packet_ref packet, size_t prefix, const packet_dimension_ref dimension, const struct sockaddr * addr, socklen_t addrlen);
     55extern int tl_get_address_port(const struct sockaddr *, int, uint16_t *);
     56extern int tl_update_ip_packet_dimension(packet_dimensions_ref, device_id_t,
     57    size_t);
     58extern int tl_set_address_port(struct sockaddr *, int, uint16_t);
     59extern int tl_prepare_icmp_packet(int, int, packet_t, services_t);
     60extern int tl_socket_read_packet_data(int, packet_ref, size_t,
     61    const packet_dimension_ref, const struct sockaddr *, socklen_t);
    11062
    11163#endif
  • uspace/lib/net/tl/tl_common.c

    r25171e5 r84c20da  
    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>
     
    4556#include <err.h>
    4657
    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>
    56 
    5758DEVICE_MAP_IMPLEMENT(packet_dimensions, packet_dimension_t);
    5859
     60/** Gets the address port.
     61 *
     62 * Supports AF_INET and AF_INET6 address families.
     63 *
     64 * @param[in,out] addr  The address to be updated.
     65 * @param[in] addrlen   The address length.
     66 * @param[out] port     The set port.
     67 * @returns             EOK on success.
     68 * @returns             EINVAL if the address length does not match the address
     69 *                      family.
     70 * @returns             EAFNOSUPPORT if the address family is not supported.
     71 */
    5972int
    6073tl_get_address_port(const struct sockaddr *addr, int addrlen, uint16_t *port)
     
    7487                *port = ntohs(address_in->sin_port);
    7588                break;
     89       
    7690        case AF_INET6:
    7791                if (addrlen != sizeof(struct sockaddr_in6))
    78                                 return EINVAL;
     92                        return EINVAL;
    7993
    8094                address_in6 = (struct sockaddr_in6 *) addr;
    8195                *port = ntohs(address_in6->sin6_port);
    8296                break;
     97       
    8398        default:
    8499                return EAFNOSUPPORT;
     
    93108 * The reply is cached then.
    94109 *
    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,
     110 * @param[in] ip_phone  The IP moduel phone for (semi)remote calls.
     111 * @param[in] packet_dimensions The packet dimensions cache.
     112 * @param[in] device_id The device identifier.
     113 * @param[out] packet_dimension The IP packet dimensions.
     114 * @return              EOK on success.
     115 * @return              EBADMEM if the packet_dimension parameter is NULL.
     116 * @return              ENOMEM if there is not enough memory left.
     117 * @return              EINVAL if the packet_dimensions cache is not valid.
     118 * @return              Other codes as defined for the ip_packet_size_req()
     119 *                      function.
     120 */
     121int
     122tl_get_ip_packet_dimension(int ip_phone,
    108123    packet_dimensions_ref packet_dimensions, device_id_t device_id,
    109124    packet_dimension_ref *packet_dimension)
     
    139154}
    140155
     156/** Updates IP device packet dimensions cache.
     157 *
     158 * @param[in,out] packet_dimensions The packet dimensions cache.
     159 * @param[in] device_id The device identifier.
     160 * @param[in] content   The new maximum content size.
     161 * @returns             EOK on success.
     162 * @return              ENOENT if the packet dimension is not cached.
     163 */
    141164int
    142165tl_update_ip_packet_dimension(packet_dimensions_ref packet_dimensions,
     
    148171        if (!packet_dimension)
    149172                return ENOENT;
     173
    150174        packet_dimension->content = content;
    151175
     
    160184                                packet_dimensions_exclude(packet_dimensions,
    161185                                    DEVICE_INVALID_ID);
    162 
    163186                }
    164187        }
     
    167190}
    168191
     192/** Sets the address port.
     193 *
     194 * Supports AF_INET and AF_INET6 address families.
     195 *
     196 * @param[in,out] addr  The address to be updated.
     197 * @param[in] addrlen   The address length.
     198 * @param[in] port      The port to be set.
     199 * @returns             EOK on success.
     200 * @returns             EINVAL if the address length does not match the address
     201 *                      family.
     202 * @returns             EAFNOSUPPORT if the address family is not supported.
     203 */
    169204int tl_set_address_port(struct sockaddr * addr, int addrlen, uint16_t port)
    170205{
     
    187222                address_in->sin_port = htons(port);
    188223                return EOK;
     224       
    189225        case AF_INET6:
    190226                if (length != sizeof(struct sockaddr_in6))
     
    193229                address_in6->sin6_port = htons(port);
    194230                return EOK;
     231       
    195232        default:
    196233                return EAFNOSUPPORT;
     
    198235}
    199236
     237/** Prepares the packet for ICMP error notification.
     238 *
     239 * Keeps the first packet and releases all the others.
     240 * Releases all the packets on error.
     241 *
     242 * @param[in] packet_phone The packet server module phone.
     243 * @param[in] icmp_phone The ICMP module phone.
     244 * @param[in] packet    The packet to be send.
     245 * @param[in] error     The packet error reporting service. Prefixes the
     246 *                      received packet.
     247 * @returns             EOK on success.
     248 * @returns             ENOENT if no packet may be sent.
     249 */
    200250int
    201251tl_prepare_icmp_packet(int packet_phone, int icmp_phone, packet_t packet,
     
    223273}
    224274
     275/** Receives data from the socket into a packet.
     276 *
     277 * @param[in] packet_phone The packet server module phone.
     278 * @param[out] packet   The new created packet.
     279 * @param[in] prefix    Reserved packet data prefix length.
     280 * @param[in] dimension The packet dimension.
     281 * @param[in] addr      The destination address.
     282 * @param[in] addrlen   The address length.
     283 * @returns             Number of bytes received.
     284 * @returns             EINVAL if the client does not send data.
     285 * @returns             ENOMEM if there is not enough memory left.
     286 * @returns             Other error codes as defined for the
     287 *                      async_data_read_finalize() function.
     288 */
    225289int
    226290tl_socket_read_packet_data(int packet_phone, packet_ref packet, size_t prefix,
Note: See TracChangeset for help on using the changeset viewer.