Changeset 0b81cad0 in mainline for uspace/srv/net/tl/icmp/icmp.c


Ignore:
Timestamp:
2010-11-06T00:19:13Z (13 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
1712f87
Parents:
0485135 (diff), 0578271 (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/srv/net/tl/icmp/icmp.c

    r0485135 r0b81cad0  
    5454#include <byteorder.h>
    5555#include <errno.h>
    56 #include <err.h>
    5756
    5857#include <net/socket_codes.h>
     
    161160    int dont_fragment)
    162161{
    163         ERROR_DECLARE;
     162        int rc;
    164163
    165164        // do not send an error if disabled
     
    172171        header->checksum = ICMP_CHECKSUM(header,
    173172            packet_get_data_length(packet));
    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         }
     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);
    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 
    253251        icmp_header_ref header;
    254252        packet_t packet;
     
    257255        icmp_reply_ref reply;
    258256        int reply_key;
    259         int result;
    260257        int index;
     258        int rc;
    261259
    262260        if (addrlen <= 0)
     
    265263        length = (size_t) addrlen;
    266264        // TODO do not ask all the time
    267         ERROR_PROPAGATE(ip_packet_size_req(icmp_globals.ip_phone, -1,
    268             &icmp_globals.packet_dimension));
     265        rc = ip_packet_size_req(icmp_globals.ip_phone, -1,
     266            &icmp_globals.packet_dimension);
     267        if (rc != EOK)
     268                return rc;
    269269
    270270        packet = packet_get_4_remote(icmp_globals.net_phone, size,
     
    277277        // prepare the requesting packet
    278278        // set the destination address
    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         }
     279        rc = packet_set_addr(packet, NULL, (const uint8_t *) addr, length);
     280        if (rc != EOK)
     281                return icmp_release_and_return(packet, rc);
    283282
    284283        // allocate space in the packet
     
    329328        // wait for the reply
    330329        // timeout in microseconds
    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         }
     330        rc = fibril_condvar_wait_timeout(&reply->condvar, &reply->mutex,
     331            timeout * 1000);
     332        if (rc == EOK)
     333                rc = reply->result;
    338334
    339335        // drop the reply mutex before locking the globals again
     
    344340        icmp_replies_exclude_index(&icmp_globals.replies, index);
    345341
    346         return result;
     342        return rc;
    347343}
    348344
     
    413409int icmp_initialize(async_client_conn_t client_connection)
    414410{
    415         ERROR_DECLARE;
    416 
    417411        measured_string_t names[] = {
    418412                {
     
    428422        size_t count = sizeof(names) / sizeof(measured_string_t);
    429423        char *data;
     424        int rc;
    430425
    431426        fibril_rwlock_initialize(&icmp_globals.lock);
     
    433428        icmp_replies_initialize(&icmp_globals.replies);
    434429        icmp_echo_data_initialize(&icmp_globals.echo_data);
     430       
    435431        icmp_globals.ip_phone = ip_bind_service(SERVICE_IP, IPPROTO_ICMP,
    436432            SERVICE_ICMP, client_connection);
    437         if (icmp_globals.ip_phone < 0)
     433        if (icmp_globals.ip_phone < 0) {
     434                fibril_rwlock_write_unlock(&icmp_globals.lock);
    438435                return icmp_globals.ip_phone;
    439 
    440         ERROR_PROPAGATE(ip_packet_size_req(icmp_globals.ip_phone, -1,
    441             &icmp_globals.packet_dimension));
     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
    442445        icmp_globals.packet_dimension.prefix += ICMP_HEADER_SIZE;
    443446        icmp_globals.packet_dimension.content -= ICMP_HEADER_SIZE;
     
    448451        // get configuration
    449452        configuration = &names[0];
    450         ERROR_PROPAGATE(net_get_conf_req(icmp_globals.net_phone, &configuration,
    451             count, &data));
     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       
    452460        if (configuration) {
    453461                if (configuration[0].value) {
     
    519527static int icmp_process_packet(packet_t packet, services_t error)
    520528{
    521         ERROR_DECLARE;
    522 
    523529        size_t length;
    524530        uint8_t *src;
     
    529535        icmp_type_t type;
    530536        icmp_code_t code;
     537        int rc;
    531538
    532539        switch (error) {
     
    541548                length = (size_t) result;
    542549                // remove the error header
    543                 ERROR_PROPAGATE(packet_trim(packet, length, 0));
     550                rc = packet_trim(packet, length, 0);
     551                if (rc != EOK)
     552                        return rc;
    544553                break;
    545554        default:
     
    549558        // get rid of the ip header
    550559        length = ip_client_header_length(packet);
    551         ERROR_PROPAGATE(packet_trim(packet, length, 0));
     560        rc = packet_trim(packet, length, 0);
     561        if (rc != EOK)
     562                return rc;
    552563
    553564        length = packet_get_data_length(packet);
     
    582593        switch (header->type) {
    583594        case ICMP_ECHOREPLY:
    584                 if (error) 
     595                if (error)
    585596                        icmp_process_echo_reply(packet, header, type, code);
    586597                else
     
    654665    services_t receiver, services_t error)
    655666{
    656         ERROR_DECLARE;
    657 
    658         if (ERROR_OCCURRED(icmp_process_packet(packet, error)))
    659                 return icmp_release_and_return(packet, ERROR_CODE);
     667        int rc;
     668
     669        rc = icmp_process_packet(packet, error);
     670        if (rc != EOK)
     671                return icmp_release_and_return(packet, rc);
    660672
    661673        return EOK;
     
    682694static int icmp_process_message(ipc_call_t *call)
    683695{
    684         ERROR_DECLARE;
    685 
    686696        packet_t packet;
     697        int rc;
    687698
    688699        switch (IPC_GET_METHOD(*call)) {
    689700        case NET_ICMP_DEST_UNREACH:
    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;
     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);
    696707        case NET_ICMP_SOURCE_QUENCH:
    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;
     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);
    702713        case NET_ICMP_TIME_EXCEEDED:
    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;
     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);
    709720        case NET_ICMP_PARAMETERPROB:
    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;
     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);
    717727        default:
    718728                return ENOTSUP;
     
    757767                        break;
    758768                }
    759         } while(icmp_echo_data_find(&icmp_globals.echo_data, index) != NULL);
     769        } while (icmp_echo_data_find(&icmp_globals.echo_data, index) != NULL);
    760770
    761771        echo_data->identifier = index;
     
    779789static int icmp_process_client_messages(ipc_callid_t callid, ipc_call_t call)
    780790{
    781         ERROR_DECLARE;
    782 
    783791        bool keep_on_going = true;
    784792        ipc_call_t answer;
     
    788796        ipc_callid_t data_callid;
    789797        icmp_echo_ref echo_data;
    790         int res;
     798        int rc = EOK;
    791799
    792800        /*
     
    794802         *  - Answer the first NET_ICMP_INIT call.
    795803         */
    796         res = EOK;
    797804        answer_count = 0;
    798805
     
    803810        // assign a new identifier
    804811        fibril_rwlock_write_lock(&icmp_globals.lock);
    805         res = icmp_bind_free_id(echo_data);
     812        rc = icmp_bind_free_id(echo_data);
    806813        fibril_rwlock_write_unlock(&icmp_globals.lock);
    807         if (res < 0) {
     814        if (rc < 0) {
    808815                free(echo_data);
    809                 return res;
     816                return rc;
    810817        }
    811818
    812819        while (keep_on_going) {
    813820                // answer the call
    814                 answer_call(callid, res, &answer, answer_count);
     821                answer_call(callid, rc, &answer, answer_count);
    815822
    816823                // refresh data
     
    824831                case IPC_M_PHONE_HUNGUP:
    825832                        keep_on_going = false;
    826                         res = EHANGUP;
     833                        rc = EHANGUP;
    827834                        break;
    828835               
    829836                case NET_ICMP_ECHO:
    830837                        if (!async_data_write_receive(&data_callid, &length)) {
    831                                 res = EINVAL;
     838                                rc = EINVAL;
    832839                                break;
    833840                        }
     
    835842                        addr = malloc(length);
    836843                        if (!addr) {
    837                                 res = ENOMEM;
     844                                rc = ENOMEM;
    838845                                break;
    839846                        }
    840847                       
    841                         if (ERROR_OCCURRED(async_data_write_finalize(
    842                             data_callid, addr, length))) {
     848                        rc = async_data_write_finalize(data_callid, addr,
     849                            length);
     850                        if (rc != EOK) {
    843851                                free(addr);
    844                                 res = ERROR_CODE;
    845852                                break;
    846853                        }
    847854
    848855                        fibril_rwlock_write_lock(&icmp_globals.lock);
    849                         res = icmp_echo(echo_data->identifier,
     856                        rc = icmp_echo(echo_data->identifier,
    850857                            echo_data->sequence_number, ICMP_GET_SIZE(call),
    851858                            ICMP_GET_TIMEOUT(call), ICMP_GET_TTL(call),
     
    864871
    865872                default:
    866                         res = icmp_process_message(&call);
     873                        rc = icmp_process_message(&call);
    867874                }
    868875
     
    874881        fibril_rwlock_write_unlock(&icmp_globals.lock);
    875882
    876         return res;
     883        return rc;
    877884}
    878885
     
    894901    ipc_call_t *answer, int *answer_count)
    895902{
    896         ERROR_DECLARE;
    897 
    898903        packet_t packet;
     904        int rc;
    899905
    900906        *answer_count = 0;
    901907        switch (IPC_GET_METHOD(*call)) {
    902908        case NET_TL_RECEIVED:
    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;
     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));
    910915       
    911916        case NET_ICMP_INIT:
     
    970975int main(int argc, char *argv[])
    971976{
    972         ERROR_DECLARE;
     977        int rc;
    973978       
    974979        /* Start the module */
    975         ERROR_PROPAGATE(tl_module_start_standalone(tl_client_connection));
    976         return EOK;
     980        rc = tl_module_start_standalone(tl_client_connection);
     981        return rc;
    977982}
    978983
Note: See TracChangeset for help on using the changeset viewer.