Changeset f51f193 in mainline for uspace/srv/net/tl/udp/udp.c


Ignore:
Timestamp:
2011-07-12T03:00:14Z (13 years ago)
Author:
Petr Koupy <petr.koupy@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
6817eba
Parents:
eca52a8 (diff), 026793d (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 mainline changes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/net/tl/udp/udp.c

    reca52a8 rf51f193  
    3737
    3838#include <async.h>
    39 #include <async_obsolete.h>
    4039#include <fibril_synch.h>
    4140#include <malloc.h>
     
    7170#include "udp_header.h"
    7271
    73 // FIXME: remove this header
    74 #include <kernel/ipc/ipc_methods.h>
    75 
    7672/** UDP module name. */
    7773#define NAME  "udp"
     
    10399static int udp_release_and_return(packet_t *packet, int result)
    104100{
    105         pq_release_remote(udp_globals.net_phone, packet_get_id(packet));
     101        pq_release_remote(udp_globals.net_sess, packet_get_id(packet));
    106102        return result;
    107103}
     
    196192            ntohs(header->destination_port), (uint8_t *) SOCKET_MAP_KEY_LISTENING, 0);
    197193        if (!socket) {
    198                 if (tl_prepare_icmp_packet(udp_globals.net_phone,
    199                     udp_globals.icmp_phone, packet, error) == EOK) {
    200                         icmp_destination_unreachable_msg(udp_globals.icmp_phone,
     194                if (tl_prepare_icmp_packet(udp_globals.net_sess,
     195                    udp_globals.icmp_sess, packet, error) == EOK) {
     196                        icmp_destination_unreachable_msg(udp_globals.icmp_sess,
    201197                            ICMP_PORT_UNREACH, 0, packet);
    202198                }
     
    255251                        while (tmp_packet) {
    256252                                next_packet = pq_detach(tmp_packet);
    257                                 pq_release_remote(udp_globals.net_phone,
     253                                pq_release_remote(udp_globals.net_sess,
    258254                                    packet_get_id(tmp_packet));
    259255                                tmp_packet = next_packet;
     
    278274                if (flip_checksum(compact_checksum(checksum)) !=
    279275                    IP_CHECKSUM_ZERO) {
    280                         if (tl_prepare_icmp_packet(udp_globals.net_phone,
    281                             udp_globals.icmp_phone, packet, error) == EOK) {
     276                        if (tl_prepare_icmp_packet(udp_globals.net_sess,
     277                            udp_globals.icmp_sess, packet, error) == EOK) {
    282278                                /* Checksum error ICMP */
    283279                                icmp_parameter_problem_msg(
    284                                     udp_globals.icmp_phone, ICMP_PARAM_POINTER,
     280                                    udp_globals.icmp_sess, ICMP_PARAM_POINTER,
    285281                                    ((size_t) ((void *) &header->checksum)) -
    286282                                    ((size_t) ((void *) header)), packet);
     
    296292                return udp_release_and_return(packet, rc);
    297293               
    298         rc = tl_get_ip_packet_dimension(udp_globals.ip_phone,
     294        rc = tl_get_ip_packet_dimension(udp_globals.ip_sess,
    299295            &udp_globals.dimensions, device_id, &packet_dimension);
    300296        if (rc != EOK)
     
    303299        /* Notify the destination socket */
    304300        fibril_rwlock_write_unlock(&udp_globals.lock);
    305         async_obsolete_msg_5(socket->phone, NET_SOCKET_RECEIVED,
    306             (sysarg_t) socket->socket_id, packet_dimension->content, 0, 0,
    307             (sysarg_t) fragments);
     301       
     302        async_exch_t *exch = async_exchange_begin(socket->sess);
     303        async_msg_5(exch, NET_SOCKET_RECEIVED, (sysarg_t) socket->socket_id,
     304            packet_dimension->content, 0, 0, (sysarg_t) fragments);
     305        async_exchange_end(exch);
    308306
    309307        return EOK;
     
    342340 * @param[in,out] icall Message parameters.
    343341 * @param[in]     arg   Local argument.
     342 *
    344343 */
    345344static void udp_receiver(ipc_callid_t iid, ipc_call_t *icall, void *arg)
     
    351350                switch (IPC_GET_IMETHOD(*icall)) {
    352351                case NET_TL_RECEIVED:
    353                         rc = packet_translate_remote(udp_globals.net_phone, &packet,
     352                        rc = packet_translate_remote(udp_globals.net_sess, &packet,
    354353                            IPC_GET_PACKET(*icall));
    355354                        if (rc == EOK)
     
    369368/** Initialize the UDP module.
    370369 *
    371  * @param[in] net_phone Network module phone.
     370 * @param[in] sess Network module session.
    372371 *
    373372 * @return EOK on success.
     
    375374 *
    376375 */
    377 int tl_initialize(int net_phone)
     376int tl_initialize(async_sess_t *sess)
    378377{
    379378        measured_string_t names[] = {
     
    394393        fibril_rwlock_write_lock(&udp_globals.lock);
    395394       
    396         udp_globals.net_phone = net_phone;
    397        
    398         udp_globals.icmp_phone = icmp_connect_module();
    399        
    400         udp_globals.ip_phone = ip_bind_service(SERVICE_IP, IPPROTO_UDP,
    401             SERVICE_UDP, udp_receiver);
    402         if (udp_globals.ip_phone < 0) {
    403                 fibril_rwlock_write_unlock(&udp_globals.lock);
    404                 return udp_globals.ip_phone;
     395        udp_globals.net_sess = sess;
     396        udp_globals.icmp_sess = icmp_connect_module();
     397       
     398        udp_globals.ip_sess = ip_bind_service(SERVICE_IP, IPPROTO_UDP,
     399             SERVICE_UDP, udp_receiver);
     400        if (udp_globals.ip_sess == NULL) {
     401            fibril_rwlock_write_unlock(&udp_globals.lock);
     402            return ENOENT;
    405403        }
    406404       
    407405        /* Read default packet dimensions */
    408         int rc = ip_packet_size_req(udp_globals.ip_phone, -1,
     406        int rc = ip_packet_size_req(udp_globals.ip_sess, -1,
    409407            &udp_globals.packet_dimension);
    410408        if (rc != EOK) {
     
    435433        /* Get configuration */
    436434        configuration = &names[0];
    437         rc = net_get_conf_req(udp_globals.net_phone, &configuration, count,
     435        rc = net_get_conf_req(udp_globals.net_sess, &configuration, count,
    438436            &data);
    439437        if (rc != EOK) {
     
    529527
    530528        if (udp_globals.checksum_computing) {
    531                 rc = ip_get_route_req(udp_globals.ip_phone, IPPROTO_UDP, addr,
     529                rc = ip_get_route_req(udp_globals.ip_sess, IPPROTO_UDP, addr,
    532530                    addrlen, &device_id, &ip_header, &headerlen);
    533531                if (rc != EOK)
    534532                        return rc;
    535533                /* Get the device packet dimension */
    536 //              rc = tl_get_ip_packet_dimension(udp_globals.ip_phone,
     534//              rc = tl_get_ip_packet_dimension(udp_globals.ip_sess,
    537535//                  &udp_globals.dimensions, device_id, &packet_dimension);
    538536//              if (rc != EOK)
     
    541539//      } else {
    542540                /* Do not ask all the time */
    543                 rc = ip_packet_size_req(udp_globals.ip_phone, -1,
     541                rc = ip_packet_size_req(udp_globals.ip_sess, -1,
    544542                    &udp_globals.packet_dimension);
    545543                if (rc != EOK)
     
    559557
    560558        /* Read the first packet fragment */
    561         result = tl_socket_read_packet_data(udp_globals.net_phone, &packet,
     559        result = tl_socket_read_packet_data(udp_globals.net_sess, &packet,
    562560            UDP_HEADER_SIZE, packet_dimension, addr, addrlen);
    563561        if (result < 0)
     
    580578        /* Read the rest of the packet fragments */
    581579        for (index = 1; index < fragments; index++) {
    582                 result = tl_socket_read_packet_data(udp_globals.net_phone,
     580                result = tl_socket_read_packet_data(udp_globals.net_sess,
    583581                    &next_packet, 0, packet_dimension, addr, addrlen);
    584582                if (result < 0)
     
    632630
    633631        /* Send the packet */
    634         ip_send_msg(udp_globals.ip_phone, device_id, packet, SERVICE_UDP, 0);
     632        ip_send_msg(udp_globals.ip_sess, device_id, packet, SERVICE_UDP, 0);
    635633
    636634        return EOK;
     
    679677                return NO_DATA;
    680678       
    681         rc = packet_translate_remote(udp_globals.net_phone, &packet, packet_id);
     679        rc = packet_translate_remote(udp_globals.net_sess, &packet, packet_id);
    682680        if (rc != EOK) {
    683681                (void) dyn_fifo_pop(&socket->received);
     
    739737}
    740738
    741 /** Processes the socket client messages.
    742  *
    743  * Runs until the client module disconnects.
    744  *
    745  * @param[in] callid    The message identifier.
    746  * @param[in] call      The message parameters.
    747  * @return              EOK on success.
    748  *
    749  * @see socket.h
    750  */
    751 static int udp_process_client_messages(ipc_callid_t callid, ipc_call_t call)
     739/** Process the socket client messages.
     740 *
     741 * Run until the client module disconnects.
     742 *
     743 * @see socket.h
     744 *
     745 * @param[in] sess   Callback session.
     746 * @param[in] callid Message identifier.
     747 * @param[in] call   Message parameters.
     748 *
     749 * @return EOK on success.
     750 *
     751 */
     752static int udp_process_client_messages(async_sess_t *sess, ipc_callid_t callid,
     753    ipc_call_t call)
    752754{
    753755        int res;
    754756        socket_cores_t local_sockets;
    755         int app_phone = IPC_GET_PHONE(call);
    756757        struct sockaddr *addr;
    757758        int socket_id;
     
    786787                /* Get the next call */
    787788                callid = async_get_call(&call);
    788                
     789
     790                /* Process the call */
    789791                if (!IPC_GET_IMETHOD(call)) {
    790792                        res = EHANGUP;
    791793                        break;
    792794                }
    793 
    794                 /* Process the call */
     795               
    795796                switch (IPC_GET_IMETHOD(call)) {
    796797                case NET_SOCKET:
    797798                        socket_id = SOCKET_GET_SOCKET_ID(call);
    798                         res = socket_create(&local_sockets, app_phone, NULL,
     799                        res = socket_create(&local_sockets, sess, NULL,
    799800                            &socket_id);
    800801                        SOCKET_SET_SOCKET_ID(answer, socket_id);
     
    804805                       
    805806                        size = MAX_UDP_FRAGMENT_SIZE;
    806                         if (tl_get_ip_packet_dimension(udp_globals.ip_phone,
     807                        if (tl_get_ip_packet_dimension(udp_globals.ip_sess,
    807808                            &udp_globals.dimensions, DEVICE_INVALID_ID,
    808809                            &packet_dimension) == EOK) {
     
    868869                case NET_SOCKET_CLOSE:
    869870                        fibril_rwlock_write_lock(&udp_globals.lock);
    870                         res = socket_destroy(udp_globals.net_phone,
     871                        res = socket_destroy(udp_globals.net_sess,
    871872                            SOCKET_GET_SOCKET_ID(call), &local_sockets,
    872873                            &udp_globals.sockets, NULL);
     
    882883        }
    883884
    884         /* Release the application phone */
    885         async_obsolete_hangup(app_phone);
     885        /* Release the application session */
     886        async_hangup(sess);
    886887
    887888        /* Release all local sockets */
    888         socket_cores_release(udp_globals.net_phone, &local_sockets,
     889        socket_cores_release(udp_globals.net_sess, &local_sockets,
    889890            &udp_globals.sockets, NULL);
    890891
     
    916917{
    917918        *answer_count = 0;
    918 
    919         switch (IPC_GET_IMETHOD(*call)) {
    920         case IPC_M_CONNECT_TO_ME:
    921                 return udp_process_client_messages(callid, *call);
    922         }
    923 
     919       
     920        async_sess_t *callback =
     921            async_callback_receive_start(EXCHANGE_SERIALIZE, call);
     922        if (callback)
     923                return udp_process_client_messages(callback, callid, *call);
     924       
    924925        return ENOTSUP;
    925926}
Note: See TracChangeset for help on using the changeset viewer.