Changeset 3f0a7971 in mainline for uspace/srv/net/tl/icmp/icmp.c


Ignore:
Timestamp:
2010-11-18T22:34:23Z (13 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
63b4f90
Parents:
c7137738 (diff), 45f04f8 (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

Updated srv/hw/bus/usb/hcd/virtual to use new type names (devmap_handle_t).

File:
1 edited

Legend:

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

    rc7137738 r3f0a7971  
    155155 * @returns             EPERM if the error message is not allowed.
    156156 */
    157 static int
    158 icmp_send_packet(icmp_type_t type, icmp_code_t code, packet_t packet,
     157static int icmp_send_packet(icmp_type_t type, icmp_code_t code, packet_t packet,
    159158    icmp_header_ref header, services_t error, ip_ttl_t ttl, ip_tos_t tos,
    160159    int dont_fragment)
     
    162161        int rc;
    163162
    164         // do not send an error if disabled
     163        /* Do not send an error if disabled */
    165164        if (error && !icmp_globals.error_reporting)
    166165                return icmp_release_and_return(packet, EPERM);
     
    204203                return NULL;
    205204
    206         // truncate if longer than 64 bits (without the IP header)
     205        /* Truncate if longer than 64 bits (without the IP header) */
    207206        if ((total_length > header_length + ICMP_KEEP_LENGTH) &&
    208207            (packet_trim(packet, 0,
     
    244243 * @returns             EPARTY if there was an internal error.
    245244 */
    246 static int
    247 icmp_echo(icmp_param_t id, icmp_param_t sequence, size_t size,
     245static int icmp_echo(icmp_param_t id, icmp_param_t sequence, size_t size,
    248246    mseconds_t timeout, ip_ttl_t ttl, ip_tos_t tos, int dont_fragment,
    249247    const struct sockaddr * addr, socklen_t addrlen)
     
    262260
    263261        length = (size_t) addrlen;
    264         // TODO do not ask all the time
     262        /* TODO do not ask all the time */
    265263        rc = ip_packet_size_req(icmp_globals.ip_phone, -1,
    266264            &icmp_globals.packet_dimension);
     
    275273                return ENOMEM;
    276274
    277         // prepare the requesting packet
    278         // set the destination address
     275        /* Prepare the requesting packet, set the destination address. */
    279276        rc = packet_set_addr(packet, NULL, (const uint8_t *) addr, length);
    280277        if (rc != EOK)
    281278                return icmp_release_and_return(packet, rc);
    282279
    283         // allocate space in the packet
     280        /* Allocate space in the packet */
    284281        data = (uint8_t *) packet_suffix(packet, size);
    285282        if (!data)
    286283                return icmp_release_and_return(packet, ENOMEM);
    287284
    288         // fill the data
     285        /* Fill the data */
    289286        length = 0;
    290287        while (size > length + sizeof(ICMP_ECHO_TEXT)) {
     
    294291        memcpy(data + length, ICMP_ECHO_TEXT, size - length);
    295292
    296         // prefix the header
     293        /* Prefix the header */
    297294        header = PACKET_PREFIX(packet, icmp_header_t);
    298295        if (!header)
     
    303300        header->un.echo.sequence_number = sequence;
    304301
    305         // prepare the reply structure
     302        /* Prepare the reply structure */
    306303        reply = malloc(sizeof(*reply));
    307304        if (!reply)
     
    319316        }
    320317
    321         // unlock the globals so that we can wait for the reply
     318        /* Unlock the globals so that we can wait for the reply */
    322319        fibril_rwlock_write_unlock(&icmp_globals.lock);
    323320
    324         // send the request
     321        /* Send the request */
    325322        icmp_send_packet(ICMP_ECHO, 0, packet, header, 0, ttl, tos,
    326323            dont_fragment);
    327324
    328         // wait for the reply
    329         // timeout in microseconds
     325        /* Wait for the reply. Timeout in microseconds. */
    330326        rc = fibril_condvar_wait_timeout(&reply->condvar, &reply->mutex,
    331327            timeout * 1000);
     
    333329                rc = reply->result;
    334330
    335         // drop the reply mutex before locking the globals again
     331        /* Drop the reply mutex before locking the globals again */
    336332        fibril_mutex_unlock(&reply->mutex);
    337333        fibril_rwlock_write_lock(&icmp_globals.lock);
    338334
    339         // destroy the reply structure
     335        /* Destroy the reply structure */
    340336        icmp_replies_exclude_index(&icmp_globals.replies, index);
    341337
     
    343339}
    344340
    345 static int
    346 icmp_destination_unreachable_msg_local(int icmp_phone, icmp_code_t code,
    347     icmp_param_t mtu, packet_t packet)
     341static int icmp_destination_unreachable_msg_local(int icmp_phone,
     342    icmp_code_t code, icmp_param_t mtu, packet_t packet)
    348343{
    349344        icmp_header_ref header;
     
    372367}
    373368
    374 static int
    375 icmp_time_exceeded_msg_local(int icmp_phone, icmp_code_t code, packet_t packet)
     369static int icmp_time_exceeded_msg_local(int icmp_phone, icmp_code_t code,
     370    packet_t packet)
    376371{
    377372        icmp_header_ref header;
     
    385380}
    386381
    387 static int
    388 icmp_parameter_problem_msg_local(int icmp_phone, icmp_code_t code,
     382static int icmp_parameter_problem_msg_local(int icmp_phone, icmp_code_t code,
    389383    icmp_param_t pointer, packet_t packet)
    390384{
     
    449443        icmp_globals.echo_replying = NET_DEFAULT_ICMP_ECHO_REPLYING;
    450444
    451         // get configuration
     445        /* Get configuration */
    452446        configuration = &names[0];
    453447        rc = net_get_conf_req(icmp_globals.net_phone, &configuration, count,
     
    485479 * @param[in] code      The received reply message code.
    486480 */
    487 static void
    488 icmp_process_echo_reply(packet_t packet, icmp_header_ref header,
     481static void  icmp_process_echo_reply(packet_t packet, icmp_header_ref header,
    489482    icmp_type_t type, icmp_code_t code)
    490483{
     
    492485        icmp_reply_ref reply;
    493486
    494         // compute the reply key
     487        /* Compute the reply key */
    495488        reply_key = ICMP_GET_REPLY_KEY(header->un.echo.identifier,
    496489            header->un.echo.sequence_number);
    497490        pq_release_remote(icmp_globals.net_phone, packet_get_id(packet));
    498491
     492        /* Find the pending reply */
    499493        fibril_rwlock_write_lock(&icmp_globals.lock);
    500         // find the pending reply
    501494        reply = icmp_replies_find(&icmp_globals.replies, reply_key);
    502495        if (reply) {
     
    541534                break;
    542535        case SERVICE_ICMP:
    543                 // process error
     536                /* Process error */
    544537                result = icmp_client_process_packet(packet, &type, &code, NULL,
    545538                    NULL);
     
    547540                        return result;
    548541                length = (size_t) result;
    549                 // remove the error header
     542                /* Remove the error header */
    550543                rc = packet_trim(packet, length, 0);
    551544                if (rc != EOK)
     
    556549        }
    557550
    558         // get rid of the ip header
     551        /* Get rid of the IP header */
    559552        length = ip_client_header_length(packet);
    560553        rc = packet_trim(packet, length, 0);
     
    573566                return EINVAL;
    574567
    575         // get icmp header
     568        /* Get ICMP header */
    576569        header = (icmp_header_ref) data;
    577570
    578571        if (header->checksum) {
    579572                while (ICMP_CHECKSUM(header, length) != IP_CHECKSUM_ZERO) {
    580                         // set the original message type on error notification
    581                         // type swap observed in Qemu
     573                        /*
     574                         * Set the original message type on error notification.
     575                         * Type swap observed in Qemu.
     576                         */
    582577                        if (error) {
    583578                                switch (header->type) {
     
    606601                }
    607602               
    608                 // do not send a reply if disabled
     603                /* Do not send a reply if disabled */
    609604                if (icmp_globals.echo_replying) {
    610605                        addrlen = packet_get_addr(packet, &src, NULL);
    611606
    612                         // set both addresses to the source one (avoids the
    613                         // source address deletion before setting the
    614                         // destination one)
     607                        /*
     608                         * Set both addresses to the source one (avoids the
     609                         * source address deletion before setting the
     610                         * destination one).
     611                         */
    615612                        if ((addrlen > 0) && (packet_set_addr(packet, src, src,
    616613                            (size_t) addrlen) == EOK)) {
    617                                 // send the reply
     614                                /* Send the reply */
    618615                                icmp_send_packet(ICMP_ECHOREPLY, 0, packet,
    619616                                    header, 0, 0, 0, 0);
     
    661658 *                      icmp_process_packet() function.
    662659 */
    663 static int
    664 icmp_received_msg_local(device_id_t device_id, packet_t packet,
     660static int icmp_received_msg_local(device_id_t device_id, packet_t packet,
    665661    services_t receiver, services_t error)
    666662{
     
    746742                return EBADMEM;
    747743
    748         // from the last used one
     744        /* From the last used one */
    749745        index = icmp_globals.last_used_id;
    750746        do {
    751747                index++;
    752                 // til the range end
     748                /* til the range end */
    753749                if (index >= ICMP_FREE_IDS_END) {
    754                         // start from the range beginning
     750                        /* start from the range beginning */
    755751                        index = ICMP_FREE_IDS_START - 1;
    756752                        do {
    757753                                index++;
    758                                 // til the last used one
     754                                /* til the last used one */
    759755                                if (index >= icmp_globals.last_used_id) {
    760                                         // none found
     756                                        /* none found */
    761757                                        return ENOTCONN;
    762758                                }
     
    764760                            index) != NULL);
    765761
    766                         // found, break immediately
     762                        /* Found, break immediately */
    767763                        break;
    768764                }
     
    808804                return ENOMEM;
    809805
    810         // assign a new identifier
     806        /* Assign a new identifier */
    811807        fibril_rwlock_write_lock(&icmp_globals.lock);
    812808        rc = icmp_bind_free_id(echo_data);
     
    818814
    819815        while (keep_on_going) {
    820                 // answer the call
     816                /* Answer the call */
    821817                answer_call(callid, rc, &answer, answer_count);
    822818
    823                 // refresh data
     819                /* Refresh data */
    824820                refresh_answer(&answer, &answer_count);
    825821
    826                 // get the next call
     822                /* Get the next call */
    827823                callid = async_get_call(&call);
    828824
    829                 // process the call
     825                /* Process the call */
    830826                switch (IPC_GET_METHOD(call)) {
    831827                case IPC_M_PHONE_HUNGUP:
     
    876872        }
    877873
    878         // release the identifier
     874        /* Release the identifier */
    879875        fibril_rwlock_write_lock(&icmp_globals.lock);
    880876        icmp_echo_data_exclude(&icmp_globals.echo_data, echo_data->identifier);
     
    897893 * @see IS_NET_ICMP_MESSAGE()
    898894 */
    899 int
    900 icmp_message_standalone(ipc_callid_t callid, ipc_call_t *call,
     895int icmp_message_standalone(ipc_callid_t callid, ipc_call_t *call,
    901896    ipc_call_t *answer, int *answer_count)
    902897{
Note: See TracChangeset for help on using the changeset viewer.