Changeset 46ae62c in mainline


Ignore:
Timestamp:
2010-11-04T18:26:43Z (13 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
a873201
Parents:
d8f95529
Message:

Get rid of the ERROR_CODE madness in udp.

Location:
uspace/srv/net/tl/udp
Files:
2 edited

Legend:

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

    rd8f95529 r46ae62c  
    5151#include <adt/dynamic_fifo.h>
    5252#include <errno.h>
    53 #include <err.h>
    5453
    5554#include <net/socket_codes.h>
     
    103102int udp_initialize(async_client_conn_t client_connection)
    104103{
    105         ERROR_DECLARE;
    106 
    107104        measured_string_t names[] = {
    108105                {
     
    118115        size_t count = sizeof(names) / sizeof(measured_string_t);
    119116        char *data;
     117        int rc;
    120118
    121119        fibril_rwlock_initialize(&udp_globals.lock);
     
    124122        udp_globals.icmp_phone = icmp_connect_module(SERVICE_ICMP,
    125123            ICMP_CONNECT_TIMEOUT);
     124       
    126125        udp_globals.ip_phone = ip_bind_service(SERVICE_IP, IPPROTO_UDP,
    127126            SERVICE_UDP, client_connection);
    128         if (udp_globals.ip_phone < 0)
     127        if (udp_globals.ip_phone < 0) {
     128                fibril_rwlock_write_unlock(&udp_globals.lock);
    129129                return udp_globals.ip_phone;
     130        }
    130131
    131132        // read default packet dimensions
    132         ERROR_PROPAGATE(ip_packet_size_req(udp_globals.ip_phone, -1,
    133             &udp_globals.packet_dimension));
    134         ERROR_PROPAGATE(socket_ports_initialize(&udp_globals.sockets));
    135         if (ERROR_OCCURRED(packet_dimensions_initialize(
    136             &udp_globals.dimensions))) {
     133        rc = ip_packet_size_req(udp_globals.ip_phone, -1,
     134            &udp_globals.packet_dimension);
     135        if (rc != EOK) {
     136                fibril_rwlock_write_unlock(&udp_globals.lock);
     137                return rc;
     138        }
     139       
     140        rc = socket_ports_initialize(&udp_globals.sockets);
     141        if (rc != EOK) {
     142                fibril_rwlock_write_unlock(&udp_globals.lock);
     143                return rc;
     144        }
     145       
     146        rc = packet_dimensions_initialize(&udp_globals.dimensions);
     147        if (rc != EOK) {
    137148                socket_ports_destroy(&udp_globals.sockets);
    138                 return ERROR_CODE;
    139         }
     149                fibril_rwlock_write_unlock(&udp_globals.lock);
     150                return rc;
     151        }
     152       
    140153        udp_globals.packet_dimension.prefix += sizeof(udp_header_t);
    141154        udp_globals.packet_dimension.content -= sizeof(udp_header_t);
     
    147160        // get configuration
    148161        configuration = &names[0];
    149         ERROR_PROPAGATE(net_get_conf_req(udp_globals.net_phone, &configuration,
    150             count, &data));
     162        rc = net_get_conf_req(udp_globals.net_phone, &configuration, count,
     163            &data);
     164        if (rc != EOK) {
     165                socket_ports_destroy(&udp_globals.sockets);
     166                fibril_rwlock_write_unlock(&udp_globals.lock);
     167                return rc;
     168        }
     169       
    151170        if (configuration) {
    152171                if (configuration[0].value)
     
    201220udp_process_packet(device_id_t device_id, packet_t packet, services_t error)
    202221{
    203         ERROR_DECLARE;
    204 
    205222        size_t length;
    206223        size_t offset;
     
    219236        struct sockaddr *dest;
    220237        packet_dimension_ref packet_dimension;
     238        int rc;
    221239
    222240        switch (error) {
     
    232250                        return udp_release_and_return(packet, result);
    233251                length = (size_t) result;
    234                 if (ERROR_OCCURRED(packet_trim(packet, length, 0)))
    235                         return udp_release_and_return(packet,
    236                             ERROR_CODE);
     252                rc = packet_trim(packet, length, 0);
     253                if (rc != EOK)
     254                        return udp_release_and_return(packet, rc);
    237255                break;
    238256        default:
     
    253271
    254272        // trim all but UDP header
    255         if (ERROR_OCCURRED(packet_trim(packet, offset, 0)))
    256                 return udp_release_and_return(packet, ERROR_CODE);
     273        rc = packet_trim(packet, offset, 0);
     274        if (rc != EOK)
     275                return udp_release_and_return(packet, rc);
    257276
    258277        // get udp header
     
    284303                if (result <= 0)
    285304                        return udp_release_and_return(packet, result);
    286 
    287                 if (ERROR_OCCURRED(ip_client_get_pseudo_header(IPPROTO_UDP,
    288                     src, result, dest, result, total_length, &ip_header,
    289                     &length))) {
    290                         return udp_release_and_return(packet, ERROR_CODE);
     305               
     306                rc = ip_client_get_pseudo_header(IPPROTO_UDP, src, result, dest,
     307                    result, total_length, &ip_header, &length);
     308                if (rc != EOK) {
     309                        return udp_release_and_return(packet, rc);
    291310                } else {
    292311                        checksum = compute_checksum(0, ip_header, length);
     
    307326
    308327                if (total_length < length) {
    309                         if (ERROR_OCCURRED(packet_trim(next_packet, 0,
    310                             length - total_length))) {
    311                                 return udp_release_and_return(packet,
    312                                     ERROR_CODE);
    313                         }
     328                        rc = packet_trim(next_packet, 0, length - total_length);
     329                        if (rc != EOK)
     330                                return udp_release_and_return(packet, rc);
    314331
    315332                        // add partial checksum if set
     
    360377
    361378        // queue the received packet
    362         if (ERROR_OCCURRED(dyn_fifo_push(&socket->received,
    363             packet_get_id(packet), SOCKET_MAX_RECEIVED_SIZE)) ||
    364             ERROR_OCCURRED(tl_get_ip_packet_dimension(udp_globals.ip_phone,
    365             &udp_globals.dimensions, device_id, &packet_dimension))) {
    366                 return udp_release_and_return(packet, ERROR_CODE);
    367         }
     379        rc = dyn_fifo_push(&socket->received, packet_get_id(packet),
     380            SOCKET_MAX_RECEIVED_SIZE);
     381        if (rc != EOK)
     382                return udp_release_and_return(packet, rc);
     383               
     384        rc = tl_get_ip_packet_dimension(udp_globals.ip_phone,
     385            &udp_globals.dimensions, device_id, &packet_dimension);
     386        if (rc != EOK)
     387                return udp_release_and_return(packet, rc);
    368388
    369389        // notify the destination socket
     
    436456    size_t *data_fragment_size, int flags)
    437457{
    438         ERROR_DECLARE;
    439 
    440458        socket_core_ref socket;
    441459        packet_t packet;
     
    451469        device_id_t device_id;
    452470        packet_dimension_ref packet_dimension;
    453 
    454         ERROR_PROPAGATE(tl_get_address_port(addr, addrlen, &dest_port));
     471        int rc;
     472       
     473        rc = tl_get_address_port(addr, addrlen, &dest_port);
     474        if (rc != EOK)
     475                return rc;
    455476
    456477        socket = socket_cores_find(local_sockets, socket_id);
     
    466487                        // might be changed in the meantime
    467488//                      if (socket->port <= 0) {
    468                                 if (ERROR_OCCURRED(socket_bind_free_port(
    469                                     &udp_globals.sockets, socket,
    470                                     UDP_FREE_PORTS_START, UDP_FREE_PORTS_END,
    471                                     udp_globals.last_used_port))) {
     489                                rc = socket_bind_free_port(&udp_globals.sockets,
     490                                    socket, UDP_FREE_PORTS_START,
     491                                    UDP_FREE_PORTS_END,
     492                                    udp_globals.last_used_port);
     493                                if (rc != EOK) {
    472494//                                      fibril_rwlock_write_unlock(
    473495//                                          &udp_globals.lock);
    474496//                                      fibril_rwlock_read_lock(
    475497//                                          &udp_globals.lock);
    476                                         return ERROR_CODE;
     498                                        return rc;
    477499                                }
    478500                                // set the next port as the search starting port
     
    487509
    488510        if (udp_globals.checksum_computing) {
    489                 if (ERROR_OCCURRED(ip_get_route_req(udp_globals.ip_phone,
    490                     IPPROTO_UDP, addr, addrlen, &device_id, &ip_header,
    491                     &headerlen))) {
    492                         return udp_release_and_return(packet, ERROR_CODE);
    493                 }
     511                rc = ip_get_route_req(udp_globals.ip_phone, IPPROTO_UDP, addr,
     512                    addrlen, &device_id, &ip_header, &headerlen);
     513                if (rc != EOK)
     514                        return udp_release_and_return(packet, rc);
    494515                // get the device packet dimension
    495 //              ERROR_PROPAGATE(tl_get_ip_packet_dimension(udp_globals.ip_phone,
    496 //                  &udp_globals.dimensions, device_id, &packet_dimension));
     516//              rc = tl_get_ip_packet_dimension(udp_globals.ip_phone,
     517//                  &udp_globals.dimensions, device_id, &packet_dimension);
     518//              if (rc != EOK)
     519//                      return rc;
    497520        }
    498521//      } else {
    499522                // do not ask all the time
    500                 ERROR_PROPAGATE(ip_packet_size_req(udp_globals.ip_phone, -1,
    501                     &udp_globals.packet_dimension));
     523                rc = ip_packet_size_req(udp_globals.ip_phone, -1,
     524                    &udp_globals.packet_dimension);
     525                if (rc != EOK)
     526                        return rc;
    502527                packet_dimension = &udp_globals.packet_dimension;
    503528//      }
     
    529554                        return udp_release_and_return(packet, result);
    530555
    531                 if (ERROR_OCCURRED(pq_add(&packet, next_packet, index, 0)))
    532                         return udp_release_and_return(packet, ERROR_CODE);
     556                rc = pq_add(&packet, next_packet, index, 0);
     557                if (rc != EOK)
     558                        return udp_release_and_return(packet, rc);
    533559
    534560                total_length += (size_t) result;
     
    547573        if (udp_globals.checksum_computing) {
    548574                // update the pseudo header
    549                 if (ERROR_OCCURRED(ip_client_set_pseudo_header_data_length(
    550                     ip_header, headerlen, total_length + UDP_HEADER_SIZE))) {
     575                rc = ip_client_set_pseudo_header_data_length(ip_header,
     576                    headerlen, total_length + UDP_HEADER_SIZE);
     577                if (rc != EOK) {
    551578                        free(ip_header);
    552                         return udp_release_and_return(packet, ERROR_CODE);
     579                        return udp_release_and_return(packet, rc);
    553580                }
    554581
     
    565592
    566593        // prepare the first packet fragment
    567         if (ERROR_OCCURRED(ip_client_prepare_packet(packet, IPPROTO_UDP, 0, 0,
    568             0, 0))) {
    569                 return udp_release_and_return(packet, ERROR_CODE);
    570         }
     594        rc = ip_client_prepare_packet(packet, IPPROTO_UDP, 0, 0, 0, 0);
     595        if (rc != EOK)
     596                return udp_release_and_return(packet, rc);
    571597
    572598        // send the packet
     
    600626    size_t *addrlen)
    601627{
    602         ERROR_DECLARE;
    603 
    604628        socket_core_ref socket;
    605629        int packet_id;
     
    610634        uint8_t *data;
    611635        int result;
     636        int rc;
    612637
    613638        // find the socket
     
    620645        if (packet_id < 0)
    621646                return NO_DATA;
    622 
    623         ERROR_PROPAGATE(packet_translate_remote(udp_globals.net_phone, &packet,
    624             packet_id));
     647       
     648        rc = packet_translate_remote(udp_globals.net_phone, &packet, packet_id);
     649        if (rc != EOK)
     650                return rc;
    625651
    626652        // get udp header
     
    634660        // set the source address port
    635661        result = packet_get_addr(packet, (uint8_t **) &addr, NULL);
    636         if (ERROR_OCCURRED(tl_set_address_port(addr, result,
    637             ntohs(header->source_port)))) {
     662        rc = tl_set_address_port(addr, result, ntohs(header->source_port));
     663        if (rc != EOK) {
    638664                pq_release_remote(udp_globals.net_phone, packet_id);
    639                 return ERROR_CODE;
     665                return rc;
    640666        }
    641667        *addrlen = (size_t) result;
    642668
    643669        // send the source address
    644         ERROR_PROPAGATE(data_reply(addr, *addrlen));
     670        rc = data_reply(addr, *addrlen);
     671        if (rc != EOK)
     672                return rc;
    645673
    646674        // trim the header
    647         ERROR_PROPAGATE(packet_trim(packet, UDP_HEADER_SIZE, 0));
     675        rc = packet_trim(packet, UDP_HEADER_SIZE, 0);
     676        if (rc != EOK)
     677                return rc;
    648678
    649679        // reply the packets
    650         ERROR_PROPAGATE(socket_reply_packets(packet, &length));
     680        rc = socket_reply_packets(packet, &length);
     681        if (rc != EOK)
     682                return rc;
    651683
    652684        // release the packet
     
    826858    ipc_call_t *answer, int *answer_count)
    827859{
    828         ERROR_DECLARE;
    829 
    830860        packet_t packet;
     861        int rc;
    831862
    832863        *answer_count = 0;
     
    834865        switch (IPC_GET_METHOD(*call)) {
    835866        case NET_TL_RECEIVED:
    836                 if (ERROR_NONE(packet_translate_remote(udp_globals.net_phone,
    837                     &packet, IPC_GET_PACKET(call)))) {
    838                         ERROR_CODE = udp_received_msg(IPC_GET_DEVICE(call),
    839                             packet, SERVICE_UDP, IPC_GET_ERROR(call));
    840                 }
    841                 return ERROR_CODE;
    842        
     867                rc = packet_translate_remote(udp_globals.net_phone, &packet,
     868                    IPC_GET_PACKET(call));
     869                if (rc != EOK)
     870                        return rc;
     871                return udp_received_msg(IPC_GET_DEVICE(call), packet,
     872                    SERVICE_UDP, IPC_GET_ERROR(call));
    843873        case IPC_M_CONNECT_TO_ME:
    844874                return udp_process_client_messages(callid, * call);
     
    850880/** Default thread for new connections.
    851881 *
    852  *  @param[in] iid      The initial message identifier.
    853  *  @param[in] icall    The initial message call structure.
    854  *
     882 * @param[in] iid       The initial message identifier.
     883 * @param[in] icall     The initial message call structure.
    855884 */
    856885static void tl_client_connection(ipc_callid_t iid, ipc_call_t * icall)
     
    898927int main(int argc, char *argv[])
    899928{
    900         ERROR_DECLARE;
     929        int rc;
    901930       
    902931        /* Start the module */
    903         if (ERROR_OCCURRED(tl_module_start_standalone(tl_client_connection)))
    904                 return ERROR_CODE;
    905        
    906         return EOK;
     932        rc = tl_module_start_standalone(tl_client_connection);
     933        return rc;
    907934}
    908935
  • uspace/srv/net/tl/udp/udp_module.c

    rd8f95529 r46ae62c  
    4444#include <async.h>
    4545#include <stdio.h>
    46 #include <err.h>
     46#include <errno.h>
    4747#include <ipc/ipc.h>
    4848#include <ipc/services.h>
     
    5959int tl_module_start_standalone(async_client_conn_t client_connection)
    6060{
    61         ERROR_DECLARE;
    62 
    6361        ipcarg_t phonehash;
     62        int rc;
    6463
    6564        async_set_client_connection(client_connection);
     
    6766        if (udp_globals.net_phone < 0)
    6867                return udp_globals.net_phone;
    69 
    70         ERROR_PROPAGATE(pm_init());
    71         if (ERROR_OCCURRED(udp_initialize(client_connection)) ||
    72             ERROR_OCCURRED(REGISTER_ME(SERVICE_UDP, &phonehash))) {
    73                 pm_destroy();
    74                 return ERROR_CODE;
    75         }
     68       
     69        rc = pm_init();
     70        if (rc != EOK)
     71                return EOK;
     72               
     73        rc = udp_initialize(client_connection);
     74        if (rc != EOK)
     75                goto out;
     76       
     77        rc = REGISTER_ME(SERVICE_UDP, &phonehash);
     78        if (rc != EOK)
     79                goto out;
    7680
    7781        async_manager();
    7882
     83out:
    7984        pm_destroy();
    80         return EOK;
     85        return rc;
    8186}
    8287
Note: See TracChangeset for help on using the changeset viewer.