Ignore:
File:
1 edited

Legend:

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

    rfb04cba8 rd8f95529  
    155155 * @returns             EPERM if the error message is not allowed.
    156156 */
    157 static int icmp_send_packet(icmp_type_t type, icmp_code_t code, packet_t packet,
     157static int
     158icmp_send_packet(icmp_type_t type, icmp_code_t code, packet_t packet,
    158159    icmp_header_ref header, services_t error, ip_ttl_t ttl, ip_tos_t tos,
    159160    int dont_fragment)
     
    161162        int rc;
    162163
    163         /* Do not send an error if disabled */
     164        // do not send an error if disabled
    164165        if (error && !icmp_globals.error_reporting)
    165166                return icmp_release_and_return(packet, EPERM);
     
    203204                return NULL;
    204205
    205         /* Truncate if longer than 64 bits (without the IP header) */
     206        // truncate if longer than 64 bits (without the IP header)
    206207        if ((total_length > header_length + ICMP_KEEP_LENGTH) &&
    207208            (packet_trim(packet, 0,
     
    243244 * @returns             EPARTY if there was an internal error.
    244245 */
    245 static int icmp_echo(icmp_param_t id, icmp_param_t sequence, size_t size,
     246static int
     247icmp_echo(icmp_param_t id, icmp_param_t sequence, size_t size,
    246248    mseconds_t timeout, ip_ttl_t ttl, ip_tos_t tos, int dont_fragment,
    247249    const struct sockaddr * addr, socklen_t addrlen)
     
    260262
    261263        length = (size_t) addrlen;
    262         /* TODO do not ask all the time */
     264        // TODO do not ask all the time
    263265        rc = ip_packet_size_req(icmp_globals.ip_phone, -1,
    264266            &icmp_globals.packet_dimension);
     
    273275                return ENOMEM;
    274276
    275         /* Prepare the requesting packet, set the destination address. */
     277        // prepare the requesting packet
     278        // set the destination address
    276279        rc = packet_set_addr(packet, NULL, (const uint8_t *) addr, length);
    277280        if (rc != EOK)
    278281                return icmp_release_and_return(packet, rc);
    279282
    280         /* Allocate space in the packet */
     283        // allocate space in the packet
    281284        data = (uint8_t *) packet_suffix(packet, size);
    282285        if (!data)
    283286                return icmp_release_and_return(packet, ENOMEM);
    284287
    285         /* Fill the data */
     288        // fill the data
    286289        length = 0;
    287290        while (size > length + sizeof(ICMP_ECHO_TEXT)) {
     
    291294        memcpy(data + length, ICMP_ECHO_TEXT, size - length);
    292295
    293         /* Prefix the header */
     296        // prefix the header
    294297        header = PACKET_PREFIX(packet, icmp_header_t);
    295298        if (!header)
     
    300303        header->un.echo.sequence_number = sequence;
    301304
    302         /* Prepare the reply structure */
     305        // prepare the reply structure
    303306        reply = malloc(sizeof(*reply));
    304307        if (!reply)
     
    316319        }
    317320
    318         /* Unlock the globals so that we can wait for the reply */
     321        // unlock the globals so that we can wait for the reply
    319322        fibril_rwlock_write_unlock(&icmp_globals.lock);
    320323
    321         /* Send the request */
     324        // send the request
    322325        icmp_send_packet(ICMP_ECHO, 0, packet, header, 0, ttl, tos,
    323326            dont_fragment);
    324327
    325         /* Wait for the reply. Timeout in microseconds. */
     328        // wait for the reply
     329        // timeout in microseconds
    326330        rc = fibril_condvar_wait_timeout(&reply->condvar, &reply->mutex,
    327331            timeout * 1000);
     
    329333                rc = reply->result;
    330334
    331         /* Drop the reply mutex before locking the globals again */
     335        // drop the reply mutex before locking the globals again
    332336        fibril_mutex_unlock(&reply->mutex);
    333337        fibril_rwlock_write_lock(&icmp_globals.lock);
    334338
    335         /* Destroy the reply structure */
     339        // destroy the reply structure
    336340        icmp_replies_exclude_index(&icmp_globals.replies, index);
    337341
     
    339343}
    340344
    341 static int icmp_destination_unreachable_msg_local(int icmp_phone,
    342     icmp_code_t code, icmp_param_t mtu, packet_t packet)
     345static int
     346icmp_destination_unreachable_msg_local(int icmp_phone, icmp_code_t code,
     347    icmp_param_t mtu, packet_t packet)
    343348{
    344349        icmp_header_ref header;
     
    367372}
    368373
    369 static int icmp_time_exceeded_msg_local(int icmp_phone, icmp_code_t code,
    370     packet_t packet)
     374static int
     375icmp_time_exceeded_msg_local(int icmp_phone, icmp_code_t code, packet_t packet)
    371376{
    372377        icmp_header_ref header;
     
    380385}
    381386
    382 static int icmp_parameter_problem_msg_local(int icmp_phone, icmp_code_t code,
     387static int
     388icmp_parameter_problem_msg_local(int icmp_phone, icmp_code_t code,
    383389    icmp_param_t pointer, packet_t packet)
    384390{
     
    443449        icmp_globals.echo_replying = NET_DEFAULT_ICMP_ECHO_REPLYING;
    444450
    445         /* Get configuration */
     451        // get configuration
    446452        configuration = &names[0];
    447453        rc = net_get_conf_req(icmp_globals.net_phone, &configuration, count,
     
    479485 * @param[in] code      The received reply message code.
    480486 */
    481 static void  icmp_process_echo_reply(packet_t packet, icmp_header_ref header,
     487static void
     488icmp_process_echo_reply(packet_t packet, icmp_header_ref header,
    482489    icmp_type_t type, icmp_code_t code)
    483490{
     
    485492        icmp_reply_ref reply;
    486493
    487         /* Compute the reply key */
     494        // compute the reply key
    488495        reply_key = ICMP_GET_REPLY_KEY(header->un.echo.identifier,
    489496            header->un.echo.sequence_number);
    490497        pq_release_remote(icmp_globals.net_phone, packet_get_id(packet));
    491498
    492         /* Find the pending reply */
    493499        fibril_rwlock_write_lock(&icmp_globals.lock);
     500        // find the pending reply
    494501        reply = icmp_replies_find(&icmp_globals.replies, reply_key);
    495502        if (reply) {
     
    534541                break;
    535542        case SERVICE_ICMP:
    536                 /* Process error */
     543                // process error
    537544                result = icmp_client_process_packet(packet, &type, &code, NULL,
    538545                    NULL);
     
    540547                        return result;
    541548                length = (size_t) result;
    542                 /* Remove the error header */
     549                // remove the error header
    543550                rc = packet_trim(packet, length, 0);
    544551                if (rc != EOK)
     
    549556        }
    550557
    551         /* Get rid of the IP header */
     558        // get rid of the ip header
    552559        length = ip_client_header_length(packet);
    553560        rc = packet_trim(packet, length, 0);
     
    566573                return EINVAL;
    567574
    568         /* Get ICMP header */
     575        // get icmp header
    569576        header = (icmp_header_ref) data;
    570577
    571578        if (header->checksum) {
    572579                while (ICMP_CHECKSUM(header, length) != IP_CHECKSUM_ZERO) {
    573                         /*
    574                          * Set the original message type on error notification.
    575                          * Type swap observed in Qemu.
    576                          */
     580                        // set the original message type on error notification
     581                        // type swap observed in Qemu
    577582                        if (error) {
    578583                                switch (header->type) {
     
    601606                }
    602607               
    603                 /* Do not send a reply if disabled */
     608                // do not send a reply if disabled
    604609                if (icmp_globals.echo_replying) {
    605610                        addrlen = packet_get_addr(packet, &src, NULL);
    606611
    607                         /*
    608                          * Set both addresses to the source one (avoids the
    609                          * source address deletion before setting the
    610                          * destination one).
    611                          */
     612                        // set both addresses to the source one (avoids the
     613                        // source address deletion before setting the
     614                        // destination one)
    612615                        if ((addrlen > 0) && (packet_set_addr(packet, src, src,
    613616                            (size_t) addrlen) == EOK)) {
    614                                 /* Send the reply */
     617                                // send the reply
    615618                                icmp_send_packet(ICMP_ECHOREPLY, 0, packet,
    616619                                    header, 0, 0, 0, 0);
     
    658661 *                      icmp_process_packet() function.
    659662 */
    660 static int icmp_received_msg_local(device_id_t device_id, packet_t packet,
     663static int
     664icmp_received_msg_local(device_id_t device_id, packet_t packet,
    661665    services_t receiver, services_t error)
    662666{
     
    742746                return EBADMEM;
    743747
    744         /* From the last used one */
     748        // from the last used one
    745749        index = icmp_globals.last_used_id;
    746750        do {
    747751                index++;
    748                 /* til the range end */
     752                // til the range end
    749753                if (index >= ICMP_FREE_IDS_END) {
    750                         /* start from the range beginning */
     754                        // start from the range beginning
    751755                        index = ICMP_FREE_IDS_START - 1;
    752756                        do {
    753757                                index++;
    754                                 /* til the last used one */
     758                                // til the last used one
    755759                                if (index >= icmp_globals.last_used_id) {
    756                                         /* none found */
     760                                        // none found
    757761                                        return ENOTCONN;
    758762                                }
     
    760764                            index) != NULL);
    761765
    762                         /* Found, break immediately */
     766                        // found, break immediately
    763767                        break;
    764768                }
     
    804808                return ENOMEM;
    805809
    806         /* Assign a new identifier */
     810        // assign a new identifier
    807811        fibril_rwlock_write_lock(&icmp_globals.lock);
    808812        rc = icmp_bind_free_id(echo_data);
     
    814818
    815819        while (keep_on_going) {
    816                 /* Answer the call */
     820                // answer the call
    817821                answer_call(callid, rc, &answer, answer_count);
    818822
    819                 /* Refresh data */
     823                // refresh data
    820824                refresh_answer(&answer, &answer_count);
    821825
    822                 /* Get the next call */
     826                // get the next call
    823827                callid = async_get_call(&call);
    824828
    825                 /* Process the call */
     829                // process the call
    826830                switch (IPC_GET_METHOD(call)) {
    827831                case IPC_M_PHONE_HUNGUP:
     
    872876        }
    873877
    874         /* Release the identifier */
     878        // release the identifier
    875879        fibril_rwlock_write_lock(&icmp_globals.lock);
    876880        icmp_echo_data_exclude(&icmp_globals.echo_data, echo_data->identifier);
     
    893897 * @see IS_NET_ICMP_MESSAGE()
    894898 */
    895 int icmp_message_standalone(ipc_callid_t callid, ipc_call_t *call,
     899int
     900icmp_message_standalone(ipc_callid_t callid, ipc_call_t *call,
    896901    ipc_call_t *answer, int *answer_count)
    897902{
Note: See TracChangeset for help on using the changeset viewer.