Changeset dfda6a1 in mainline for uspace/lib/net/tl/tl_common.c


Ignore:
Timestamp:
2010-10-23T20:28:55Z (13 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
cc8d91a
Parents:
33dbbd2 (diff), 018d79b8 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge from lp:~jakub/helenos/net.

File:
1 edited

Legend:

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

    r33dbbd2 rdfda6a1  
    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.