Ignore:
File:
1 edited

Legend:

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

    rd8f95529 rba1a2fd  
    5454#include <byteorder.h>
    5555#include <errno.h>
     56#include <err.h>
    5657
    5758#include <net/socket_codes.h>
     
    160161    int dont_fragment)
    161162{
    162         int rc;
     163        ERROR_DECLARE;
    163164
    164165        // do not send an error if disabled
     
    171172        header->checksum = ICMP_CHECKSUM(header,
    172173            packet_get_data_length(packet));
    173        
    174         rc = ip_client_prepare_packet(packet, IPPROTO_ICMP, ttl, tos,
    175             dont_fragment, 0);
    176         if (rc != EOK)
    177                 return icmp_release_and_return(packet, rc);
     174        if (ERROR_OCCURRED(ip_client_prepare_packet(packet, IPPROTO_ICMP, ttl,
     175            tos, dont_fragment, 0))) {
     176                return icmp_release_and_return(packet, ERROR_CODE);
     177        }
    178178
    179179        return ip_send_msg(icmp_globals.ip_phone, -1, packet, SERVICE_ICMP,
     
    249249    const struct sockaddr * addr, socklen_t addrlen)
    250250{
     251        ERROR_DECLARE;
     252
    251253        icmp_header_ref header;
    252254        packet_t packet;
     
    255257        icmp_reply_ref reply;
    256258        int reply_key;
     259        int result;
    257260        int index;
    258         int rc;
    259261
    260262        if (addrlen <= 0)
     
    263265        length = (size_t) addrlen;
    264266        // TODO do not ask all the time
    265         rc = ip_packet_size_req(icmp_globals.ip_phone, -1,
    266             &icmp_globals.packet_dimension);
    267         if (rc != EOK)
    268                 return rc;
     267        ERROR_PROPAGATE(ip_packet_size_req(icmp_globals.ip_phone, -1,
     268            &icmp_globals.packet_dimension));
    269269
    270270        packet = packet_get_4_remote(icmp_globals.net_phone, size,
     
    277277        // prepare the requesting packet
    278278        // set the destination address
    279         rc = packet_set_addr(packet, NULL, (const uint8_t *) addr, length);
    280         if (rc != EOK)
    281                 return icmp_release_and_return(packet, rc);
     279        if (ERROR_OCCURRED(packet_set_addr(packet, NULL, (const uint8_t *) addr,
     280            length))) {
     281                return icmp_release_and_return(packet, ERROR_CODE);
     282        }
    282283
    283284        // allocate space in the packet
     
    328329        // wait for the reply
    329330        // timeout in microseconds
    330         rc = fibril_condvar_wait_timeout(&reply->condvar, &reply->mutex,
    331             timeout * 1000);
    332         if (rc == EOK)
    333                 rc = reply->result;
     331        if (ERROR_OCCURRED(fibril_condvar_wait_timeout(&reply->condvar,
     332            &reply->mutex, timeout * 1000))) {
     333                result = ERROR_CODE;
     334        } else {
     335                // read the result
     336                result = reply->result;
     337        }
    334338
    335339        // drop the reply mutex before locking the globals again
     
    340344        icmp_replies_exclude_index(&icmp_globals.replies, index);
    341345
    342         return rc;
     346        return result;
    343347}
    344348
     
    409413int icmp_initialize(async_client_conn_t client_connection)
    410414{
     415        ERROR_DECLARE;
     416
    411417        measured_string_t names[] = {
    412418                {
     
    422428        size_t count = sizeof(names) / sizeof(measured_string_t);
    423429        char *data;
    424         int rc;
    425430
    426431        fibril_rwlock_initialize(&icmp_globals.lock);
     
    428433        icmp_replies_initialize(&icmp_globals.replies);
    429434        icmp_echo_data_initialize(&icmp_globals.echo_data);
    430        
    431435        icmp_globals.ip_phone = ip_bind_service(SERVICE_IP, IPPROTO_ICMP,
    432436            SERVICE_ICMP, client_connection);
    433         if (icmp_globals.ip_phone < 0) {
    434                 fibril_rwlock_write_unlock(&icmp_globals.lock);
     437        if (icmp_globals.ip_phone < 0)
    435438                return icmp_globals.ip_phone;
    436         }
    437        
    438         rc = ip_packet_size_req(icmp_globals.ip_phone, -1,
    439             &icmp_globals.packet_dimension);
    440         if (rc != EOK) {
    441                 fibril_rwlock_write_unlock(&icmp_globals.lock);
    442                 return rc;
    443         }
    444 
     439
     440        ERROR_PROPAGATE(ip_packet_size_req(icmp_globals.ip_phone, -1,
     441            &icmp_globals.packet_dimension));
    445442        icmp_globals.packet_dimension.prefix += ICMP_HEADER_SIZE;
    446443        icmp_globals.packet_dimension.content -= ICMP_HEADER_SIZE;
     
    451448        // get configuration
    452449        configuration = &names[0];
    453         rc = net_get_conf_req(icmp_globals.net_phone, &configuration, count,
    454             &data);
    455         if (rc != EOK) {
    456                 fibril_rwlock_write_unlock(&icmp_globals.lock);
    457                 return rc;
    458         }
    459        
     450        ERROR_PROPAGATE(net_get_conf_req(icmp_globals.net_phone, &configuration,
     451            count, &data));
    460452        if (configuration) {
    461453                if (configuration[0].value) {
     
    527519static int icmp_process_packet(packet_t packet, services_t error)
    528520{
     521        ERROR_DECLARE;
     522
    529523        size_t length;
    530524        uint8_t *src;
     
    535529        icmp_type_t type;
    536530        icmp_code_t code;
    537         int rc;
    538531
    539532        switch (error) {
     
    548541                length = (size_t) result;
    549542                // remove the error header
    550                 rc = packet_trim(packet, length, 0);
    551                 if (rc != EOK)
    552                         return rc;
     543                ERROR_PROPAGATE(packet_trim(packet, length, 0));
    553544                break;
    554545        default:
     
    558549        // get rid of the ip header
    559550        length = ip_client_header_length(packet);
    560         rc = packet_trim(packet, length, 0);
    561         if (rc != EOK)
    562                 return rc;
     551        ERROR_PROPAGATE(packet_trim(packet, length, 0));
    563552
    564553        length = packet_get_data_length(packet);
     
    593582        switch (header->type) {
    594583        case ICMP_ECHOREPLY:
    595                 if (error)
     584                if (error) 
    596585                        icmp_process_echo_reply(packet, header, type, code);
    597586                else
     
    665654    services_t receiver, services_t error)
    666655{
    667         int rc;
    668 
    669         rc = icmp_process_packet(packet, error);
    670         if (rc != EOK)
    671                 return icmp_release_and_return(packet, rc);
     656        ERROR_DECLARE;
     657
     658        if (ERROR_OCCURRED(icmp_process_packet(packet, error)))
     659                return icmp_release_and_return(packet, ERROR_CODE);
    672660
    673661        return EOK;
     
    694682static int icmp_process_message(ipc_call_t *call)
    695683{
     684        ERROR_DECLARE;
     685
    696686        packet_t packet;
    697         int rc;
    698687
    699688        switch (IPC_GET_METHOD(*call)) {
    700689        case NET_ICMP_DEST_UNREACH:
    701                 rc = packet_translate_remote(icmp_globals.net_phone, &packet,
    702                     IPC_GET_PACKET(call));
    703                 if (rc != EOK)
    704                         return rc;
    705                 return icmp_destination_unreachable_msg_local(0,
    706                     ICMP_GET_CODE(call), ICMP_GET_MTU(call), packet);
     690                if (ERROR_NONE(packet_translate_remote(icmp_globals.net_phone,
     691                    &packet, IPC_GET_PACKET(call)))) {
     692                        ERROR_CODE = icmp_destination_unreachable_msg_local(0,
     693                            ICMP_GET_CODE(call), ICMP_GET_MTU(call), packet);
     694                }
     695                return ERROR_CODE;
    707696        case NET_ICMP_SOURCE_QUENCH:
    708                 rc = packet_translate_remote(icmp_globals.net_phone, &packet,
    709                     IPC_GET_PACKET(call));
    710                 if (rc != EOK)
    711                         return rc;
    712                 return icmp_source_quench_msg_local(0, packet);
     697                if (ERROR_NONE(packet_translate_remote(icmp_globals.net_phone,
     698                    &packet, IPC_GET_PACKET(call)))) {
     699                        ERROR_CODE = icmp_source_quench_msg_local(0, packet);
     700                }
     701                return ERROR_CODE;
    713702        case NET_ICMP_TIME_EXCEEDED:
    714                 rc = packet_translate_remote(icmp_globals.net_phone, &packet,
    715                     IPC_GET_PACKET(call));
    716                 if (rc != EOK)
    717                         return rc;
    718                 return icmp_time_exceeded_msg_local(0, ICMP_GET_CODE(call),
    719                     packet);
     703                if (ERROR_NONE(packet_translate_remote(icmp_globals.net_phone,
     704                    &packet, IPC_GET_PACKET(call)))) {
     705                        ERROR_CODE = icmp_time_exceeded_msg_local(0,
     706                            ICMP_GET_CODE(call), packet);
     707                }
     708                return ERROR_CODE;
    720709        case NET_ICMP_PARAMETERPROB:
    721                 rc = packet_translate_remote(icmp_globals.net_phone, &packet,
    722                     IPC_GET_PACKET(call));
    723                 if (rc != EOK)
    724                         return rc;
    725                 return icmp_parameter_problem_msg_local(0, ICMP_GET_CODE(call),
    726                     ICMP_GET_POINTER(call), packet);
     710                if (ERROR_NONE(packet_translate_remote(icmp_globals.net_phone,
     711                    &packet, IPC_GET_PACKET(call)))) {
     712                        ERROR_CODE = icmp_parameter_problem_msg_local(0,
     713                            ICMP_GET_CODE(call), ICMP_GET_POINTER(call),
     714                            packet);
     715                }
     716                return ERROR_CODE;
    727717        default:
    728718                return ENOTSUP;
     
    767757                        break;
    768758                }
    769         } while (icmp_echo_data_find(&icmp_globals.echo_data, index) != NULL);
     759        } while(icmp_echo_data_find(&icmp_globals.echo_data, index) != NULL);
    770760
    771761        echo_data->identifier = index;
     
    789779static int icmp_process_client_messages(ipc_callid_t callid, ipc_call_t call)
    790780{
     781        ERROR_DECLARE;
     782
    791783        bool keep_on_going = true;
    792784        ipc_call_t answer;
     
    796788        ipc_callid_t data_callid;
    797789        icmp_echo_ref echo_data;
    798         int rc = EOK;
     790        int res;
    799791
    800792        /*
     
    802794         *  - Answer the first NET_ICMP_INIT call.
    803795         */
     796        res = EOK;
    804797        answer_count = 0;
    805798
     
    810803        // assign a new identifier
    811804        fibril_rwlock_write_lock(&icmp_globals.lock);
    812         rc = icmp_bind_free_id(echo_data);
     805        res = icmp_bind_free_id(echo_data);
    813806        fibril_rwlock_write_unlock(&icmp_globals.lock);
    814         if (rc < 0) {
     807        if (res < 0) {
    815808                free(echo_data);
    816                 return rc;
     809                return res;
    817810        }
    818811
    819812        while (keep_on_going) {
    820813                // answer the call
    821                 answer_call(callid, rc, &answer, answer_count);
     814                answer_call(callid, res, &answer, answer_count);
    822815
    823816                // refresh data
     
    831824                case IPC_M_PHONE_HUNGUP:
    832825                        keep_on_going = false;
    833                         rc = EHANGUP;
     826                        res = EHANGUP;
    834827                        break;
    835828               
    836829                case NET_ICMP_ECHO:
    837830                        if (!async_data_write_receive(&data_callid, &length)) {
    838                                 rc = EINVAL;
     831                                res = EINVAL;
    839832                                break;
    840833                        }
     
    842835                        addr = malloc(length);
    843836                        if (!addr) {
    844                                 rc = ENOMEM;
     837                                res = ENOMEM;
    845838                                break;
    846839                        }
    847840                       
    848                         rc = async_data_write_finalize(data_callid, addr,
    849                             length);
    850                         if (rc != EOK) {
     841                        if (ERROR_OCCURRED(async_data_write_finalize(
     842                            data_callid, addr, length))) {
    851843                                free(addr);
     844                                res = ERROR_CODE;
    852845                                break;
    853846                        }
    854847
    855848                        fibril_rwlock_write_lock(&icmp_globals.lock);
    856                         rc = icmp_echo(echo_data->identifier,
     849                        res = icmp_echo(echo_data->identifier,
    857850                            echo_data->sequence_number, ICMP_GET_SIZE(call),
    858851                            ICMP_GET_TIMEOUT(call), ICMP_GET_TTL(call),
     
    871864
    872865                default:
    873                         rc = icmp_process_message(&call);
     866                        res = icmp_process_message(&call);
    874867                }
    875868
     
    881874        fibril_rwlock_write_unlock(&icmp_globals.lock);
    882875
    883         return rc;
     876        return res;
    884877}
    885878
     
    901894    ipc_call_t *answer, int *answer_count)
    902895{
     896        ERROR_DECLARE;
     897
    903898        packet_t packet;
    904         int rc;
    905899
    906900        *answer_count = 0;
    907901        switch (IPC_GET_METHOD(*call)) {
    908902        case NET_TL_RECEIVED:
    909                 rc = packet_translate_remote(icmp_globals.net_phone, &packet,
    910                     IPC_GET_PACKET(call));
    911                 if (rc != EOK)
    912                         return rc;
    913                 return icmp_received_msg_local(IPC_GET_DEVICE(call), packet,
    914                     SERVICE_ICMP, IPC_GET_ERROR(call));
     903                if (ERROR_NONE(packet_translate_remote(icmp_globals.net_phone,
     904                    &packet, IPC_GET_PACKET(call)))) {
     905                        ERROR_CODE =
     906                            icmp_received_msg_local(IPC_GET_DEVICE(call),
     907                            packet, SERVICE_ICMP, IPC_GET_ERROR(call));
     908                }
     909                return ERROR_CODE;
    915910       
    916911        case NET_ICMP_INIT:
     
    975970int main(int argc, char *argv[])
    976971{
    977         int rc;
     972        ERROR_DECLARE;
    978973       
    979974        /* Start the module */
    980         rc = tl_module_start_standalone(tl_client_connection);
    981         return rc;
     975        ERROR_PROPAGATE(tl_module_start_standalone(tl_client_connection));
     976        return EOK;
    982977}
    983978
Note: See TracChangeset for help on using the changeset viewer.