Changeset fb04cba8 in mainline for uspace/srv/net/tl


Ignore:
Timestamp:
2010-11-14T14:07:05Z (15 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
9e2e715
Parents:
c9ebbe71
Message:

Fix style of function headers and comments.

Location:
uspace/srv/net/tl
Files:
6 edited

Legend:

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

    rc9ebbe71 rfb04cba8  
    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{
  • uspace/srv/net/tl/icmp/icmp_module.c

    rc9ebbe71 rfb04cba8  
    8585}
    8686
    87 int
    88 tl_module_message_standalone(ipc_callid_t callid, ipc_call_t *call,
     87int tl_module_message_standalone(ipc_callid_t callid, ipc_call_t *call,
    8988    ipc_call_t *answer, int *answer_count)
    9089{
  • uspace/srv/net/tl/tcp/tcp.c

    rc9ebbe71 rfb04cba8  
    4444#include <fibril_synch.h>
    4545#include <malloc.h>
    46 //TODO remove stdio
     46/* TODO remove stdio */
    4747#include <stdio.h>
    4848#include <errno.h>
     
    267267}
    268268
    269 int
    270 tcp_received_msg(device_id_t device_id, packet_t packet, services_t receiver,
    271     services_t error)
     269int tcp_received_msg(device_id_t device_id, packet_t packet,
     270    services_t receiver, services_t error)
    272271{
    273272        int rc;
     
    309308                break;
    310309        case SERVICE_ICMP:
    311                 // process error
     310                /* Process error */
    312311                result = icmp_client_process_packet(packet, &type, &code, NULL,
    313312                    NULL);
     
    324323        }
    325324
    326         // TODO process received ipopts?
     325        /* TODO process received ipopts? */
    327326        result = ip_client_process_packet(packet, NULL, NULL, NULL, NULL, NULL);
    328327        if (result < 0)
     
    338337                return tcp_release_and_return(packet, NO_DATA);
    339338
    340         // trim all but TCP header
     339        /* Trim all but TCP header */
    341340        rc = packet_trim(packet, offset, 0);
    342341        if (rc != EOK)
    343342                return tcp_release_and_return(packet, rc);
    344343
    345         // get tcp header
     344        /* Get tcp header */
    346345        header = (tcp_header_ref) packet_get_data(packet);
    347346        if (!header)
     
    361360                return tcp_release_and_return(packet, rc);
    362361       
    363         // find the destination socket
     362        /* Find the destination socket */
    364363        socket = socket_port_find(&tcp_globals.sockets,
    365364            ntohs(header->destination_port), (const char *) src, addrlen);
    366365        if (!socket) {
    367                 // find the listening destination socket
     366                /* Find the listening destination socket */
    368367                socket = socket_port_find(&tcp_globals.sockets,
    369368                    ntohs(header->destination_port), SOCKET_MAP_KEY_LISTENING,
    370369                    0);
    371370        }
     371
    372372        if (!socket) {
    373373                if (tl_prepare_icmp_packet(tcp_globals.net_phone,
     
    383383        assert(socket_data);
    384384
    385         // some data received, clear the timeout counter
     385        /* Some data received, clear the timeout counter */
    386386        socket_data->timeout_count = 0;
    387387
    388         // count the received packet fragments
     388        /* Count the received packet fragments */
    389389        next_packet = packet;
    390390        fragments = 0;
     
    399399                total_length += length;
    400400
    401                 // add partial checksum if set
     401                /* Add partial checksum if set */
    402402                if (!error) {
    403403                        checksum = compute_checksum(checksum,
     
    447447                    tcp_globals.icmp_phone, packet, error);
    448448                if (rc == EOK) {
    449                         // checksum error ICMP
     449                        /* Checksum error ICMP */
    450450                        icmp_parameter_problem_msg(tcp_globals.icmp_phone,
    451451                            ICMP_PARAM_POINTER,
     
    460460        fibril_rwlock_read_unlock(&tcp_globals.lock);
    461461
    462         // TODO error reporting/handling
     462        /* TODO error reporting/handling */
    463463        switch (socket_data->state) {
    464464        case TCP_SOCKET_LISTEN:
     
    474474                break;
    475475        case TCP_SOCKET_FIN_WAIT_1:
    476                 // ack changing the state to FIN_WAIT_2 gets processed later
     476                /* ack changing the state to FIN_WAIT_2 gets processed later */
    477477        case TCP_SOCKET_FIN_WAIT_2:
    478                 // fin changing state to LAST_ACK gets processed later
     478                /* fin changing state to LAST_ACK gets processed later */
    479479        case TCP_SOCKET_LAST_ACK:
    480                 // ack releasing the socket get processed later
     480                /* ack releasing the socket get processed later */
    481481        case TCP_SOCKET_CLOSING:
    482                 // ack releasing the socket gets processed later
     482                /* ack releasing the socket gets processed later */
    483483        case TCP_SOCKET_ESTABLISHED:
    484484                rc = tcp_process_established(socket, socket_data, header,
     
    497497}
    498498
    499 int
    500 tcp_process_established(socket_core_ref socket, tcp_socket_data_ref socket_data,
    501     tcp_header_ref header, packet_t packet, int fragments, size_t total_length)
     499int tcp_process_established(socket_core_ref socket, tcp_socket_data_ref
     500    socket_data, tcp_header_ref header, packet_t packet, int fragments,
     501    size_t total_length)
    502502{
    503503        packet_t next_packet;
     
    523523                socket_data->fin_incoming = new_sequence_number;
    524524
    525         // trim begining if containing expected data
     525        /* Trim begining if containing expected data */
    526526        if (IS_IN_INTERVAL_OVERFLOW(new_sequence_number,
    527527            socket_data->next_incoming, new_sequence_number + total_length)) {
    528528
    529                 // get the acknowledged offset
     529                /* Get the acknowledged offset */
    530530                if (socket_data->next_incoming < new_sequence_number) {
    531531                        offset = new_sequence_number -
     
    539539                total_length -= offset;
    540540                length = packet_get_data_length(packet);
    541                 // trim the acknowledged data
     541
     542                /* Trim the acknowledged data */
    542543                while (length <= offset) {
    543                         // release the acknowledged packets
     544                        /* Release the acknowledged packets */
    544545                        next_packet = pq_next(packet);
    545546                        pq_release_remote(tcp_globals.net_phone,
     
    559560        }
    560561
    561         // release if overflowing the window
     562        /* Release if overflowing the window */
    562563/*
    563564        if (IS_IN_INTERVAL_OVERFLOW(socket_data->next_incoming +
     
    609610        }
    610611*/
    611         // the expected one arrived?
     612        /* The expected one arrived? */
    612613        if (new_sequence_number == socket_data->next_incoming) {
    613614                printf("expected\n");
    614                 // process acknowledgement
     615                /* Process acknowledgement */
    615616                tcp_process_acknowledgement(socket, socket_data, header);
    616617
    617                 // remove the header
     618                /* Remove the header */
    618619                total_length -= TCP_HEADER_LENGTH(header);
    619620                rc = packet_trim(packet, TCP_HEADER_LENGTH(header), 0);
     
    635636                        rc = pq_get_order(socket_data->incoming, &order, NULL);
    636637                        if (rc != EOK) {
    637                                 // remove the corrupted packet
     638                                /* Remove the corrupted packet */
    638639                                next_packet = pq_detach(packet);
    639640                                if (packet == socket_data->incoming)
     
    648649                        if (IS_IN_INTERVAL_OVERFLOW(sequence_number,
    649650                            old_incoming, socket_data->next_incoming)) {
    650                                 // move to the next
     651                                /* Move to the next */
    651652                                packet = pq_next(packet);
    652                                 // coninual data?
     653                                /* Coninual data? */
    653654                        } else if (IS_IN_INTERVAL_OVERFLOW(old_incoming,
    654655                            sequence_number, socket_data->next_incoming)) {
    655                                 // detach the packet
     656                                /* Detach the packet */
    656657                                next_packet = pq_detach(packet);
    657658                                if (packet == socket_data->incoming)
    658659                                        socket_data->incoming = next_packet;
    659                                 // get data length
     660                                /* Get data length */
    660661                                length = packet_get_data_length(packet);
    661662                                new_sequence_number = sequence_number + length;
    662663                                if (length <= 0) {
    663                                         // remove the empty packet
     664                                        /* Remove the empty packet */
    664665                                        pq_release_remote(tcp_globals.net_phone,
    665666                                            packet_get_id(packet));
     
    667668                                        continue;
    668669                                }
    669                                 // exactly following
     670                                /* Exactly following */
    670671                                if (sequence_number ==
    671672                                    socket_data->next_incoming) {
    672                                         // queue received data
     673                                        /* Queue received data */
    673674                                        rc = tcp_queue_received_packet(socket,
    674675                                            socket_data, packet, 1,
     
    680681                                        packet = next_packet;
    681682                                        continue;
    682                                         // at least partly following data?
     683                                        /* At least partly following data? */
    683684                                }
    684685                                if (IS_IN_INTERVAL_OVERFLOW(sequence_number,
     
    695696                                        rc = packet_trim(packet,length, 0);
    696697                                        if (rc == EOK) {
    697                                                 // queue received data
     698                                                /* Queue received data */
    698699                                                rc = tcp_queue_received_packet(
    699700                                                    socket, socket_data, packet,
     
    708709                                        }
    709710                                }
    710                                 // remove the duplicit or corrupted packet
     711                                /* Remove the duplicit or corrupted packet */
    711712                                pq_release_remote(tcp_globals.net_phone,
    712713                                    packet_get_id(packet));
     
    721722            socket_data->next_incoming + socket_data->window)) {
    722723                printf("in window\n");
    723                 // process acknowledgement
     724                /* Process acknowledgement */
    724725                tcp_process_acknowledgement(socket, socket_data, header);
    725726
    726                 // remove the header
     727                /* Remove the header */
    727728                total_length -= TCP_HEADER_LENGTH(header);
    728729                rc = packet_trim(packet, TCP_HEADER_LENGTH(header), 0);
     
    735736                    length);
    736737                if (rc != EOK) {
    737                         // remove the corrupted packets
     738                        /* Remove the corrupted packets */
    738739                        pq_release_remote(tcp_globals.net_phone,
    739740                            packet_get_id(packet));
     
    762763        } else {
    763764                printf("unexpected\n");
    764                 // release duplicite or restricted
     765                /* Release duplicite or restricted */
    765766                pq_release_remote(tcp_globals.net_phone, packet_get_id(packet));
    766767        }
    767768
    768         // change state according to the acknowledging incoming fin
     769        /* Change state according to the acknowledging incoming fin */
    769770        if (IS_IN_INTERVAL_OVERFLOW(old_incoming, socket_data->fin_incoming,
    770771            socket_data->next_incoming)) {
     
    775776                        socket_data->state = TCP_SOCKET_CLOSING;
    776777                        break;
    777                         //case TCP_ESTABLISHED:
     778                /*case TCP_ESTABLISHED:*/
    778779                default:
    779780                        socket_data->state = TCP_SOCKET_CLOSE_WAIT;
     
    784785        packet = tcp_get_packets_to_send(socket, socket_data);
    785786        if (!packet) {
    786                 // create the notification packet
     787                /* Create the notification packet */
    787788                rc = tcp_create_notification_packet(&packet, socket,
    788789                    socket_data, 0, 0);
     
    798799        fibril_rwlock_write_unlock(socket_data->local_lock);
    799800
    800         // send the packet
     801        /* Send the packet */
    801802        tcp_send_packets(socket_data->device_id, packet);
    802803
     
    804805}
    805806
    806 int
    807 tcp_queue_received_packet(socket_core_ref socket,
     807int tcp_queue_received_packet(socket_core_ref socket,
    808808    tcp_socket_data_ref socket_data, packet_t packet, int fragments,
    809809    size_t total_length)
     
    819819        assert(socket_data->window > total_length);
    820820
    821         // queue the received packet
     821        /* Queue the received packet */
    822822        rc = dyn_fifo_push(&socket->received, packet_get_id(packet),
    823823            SOCKET_MAX_RECEIVED_SIZE);
     
    829829                return tcp_release_and_return(packet, rc);
    830830
    831         // decrease the window size
     831        /* Decrease the window size */
    832832        socket_data->window -= total_length;
    833833
    834         // notify the destination socket
     834        /* Notify the destination socket */
    835835        async_msg_5(socket->phone, NET_SOCKET_RECEIVED,
    836836            (ipcarg_t) socket->socket_id,
     
    842842}
    843843
    844 int
    845 tcp_process_syn_sent(socket_core_ref socket, tcp_socket_data_ref socket_data,
    846     tcp_header_ref header, packet_t packet)
     844int tcp_process_syn_sent(socket_core_ref socket, tcp_socket_data_ref
     845    socket_data, tcp_header_ref header, packet_t packet)
    847846{
    848847        packet_t next_packet;
     
    858857                return tcp_release_and_return(packet, EINVAL);
    859858       
    860         // process acknowledgement
     859        /* Process acknowledgement */
    861860        tcp_process_acknowledgement(socket, socket_data, header);
    862861
    863862        socket_data->next_incoming = ntohl(header->sequence_number) + 1;
    864         // release additional packets
     863
     864        /* Release additional packets */
    865865        next_packet = pq_detach(packet);
    866866        if (next_packet) {
     
    868868                    packet_get_id(next_packet));
    869869        }
    870         // trim if longer than the header
     870
     871        /* Trim if longer than the header */
    871872        if (packet_get_data_length(packet) > sizeof(*header)) {
    872873                rc = packet_trim(packet, 0,
     
    875876                        return tcp_release_and_return(packet, rc);
    876877        }
     878
    877879        tcp_prepare_operation_header(socket, socket_data, header, 0, 0);
    878880        fibril_mutex_lock(&socket_data->operation.mutex);
    879881        socket_data->operation.result = tcp_queue_packet(socket, socket_data,
    880882            packet, 1);
     883
    881884        if (socket_data->operation.result == EOK) {
    882885                socket_data->state = TCP_SOCKET_ESTABLISHED;
     
    884887                if (packet) {
    885888                        fibril_rwlock_write_unlock( socket_data->local_lock);
    886                         // send the packet
     889                        /* Send the packet */
    887890                        tcp_send_packets(socket_data->device_id, packet);
    888                         // signal the result
     891                        /* Signal the result */
    889892                        fibril_condvar_signal( &socket_data->operation.condvar);
    890893                        fibril_mutex_unlock( &socket_data->operation.mutex);
     
    892895                }
    893896        }
     897
    894898        fibril_mutex_unlock(&socket_data->operation.mutex);
    895899        return tcp_release_and_return(packet, EINVAL);
    896900}
    897901
    898 int
    899 tcp_process_listen(socket_core_ref listening_socket,
     902int tcp_process_listen(socket_core_ref listening_socket,
    900903    tcp_socket_data_ref listening_socket_data, tcp_header_ref header,
    901904    packet_t packet, struct sockaddr *src, struct sockaddr *dest,
     
    936939                return tcp_release_and_return(packet, ENOMEM);
    937940        }
     941
    938942        memcpy(socket_data->addr, src, socket_data->addrlen);
    939943        socket_data->dest_port = ntohs(header->source_port);
     
    946950        }
    947951
    948         // create a socket
     952        /* Create a socket */
    949953        socket_id = -1;
    950954        rc = socket_create(socket_data->local_sockets, listening_socket->phone,
     
    965969        fibril_rwlock_write_lock(&tcp_globals.lock);
    966970
    967         // find the destination socket
     971        /* Find the destination socket */
    968972        listening_socket = socket_port_find(&tcp_globals.sockets,
    969973            listening_port, SOCKET_MAP_KEY_LISTENING, 0);
     
    971975            (listening_socket->socket_id != listening_socket_id)) {
    972976                fibril_rwlock_write_unlock(&tcp_globals.lock);
    973                 // a shadow may remain until app hangs up
     977                /* A shadow may remain until app hangs up */
    974978                return tcp_release_and_return(packet, EOK /*ENOTSOCK*/);
    975979        }
     
    983987            socket_id);
    984988        if (!socket) {
    985                 // where is the socket?!?
     989                /* Where is the socket?!? */
    986990                fibril_rwlock_write_unlock(&tcp_globals.lock);
    987991                return ENOTSOCK;
     
    10101014        socket_data->next_incoming = ntohl(header->sequence_number) + 1;
    10111015
    1012         // release additional packets
     1016        /* Release additional packets */
    10131017        next_packet = pq_detach(packet);
    10141018        if (next_packet) {
     
    10171021        }
    10181022
    1019         // trim if longer than the header
     1023        /* Trim if longer than the header */
    10201024        if (packet_get_data_length(packet) > sizeof(*header)) {
    10211025                rc = packet_trim(packet, 0,
     
    10501054        fibril_rwlock_write_unlock(socket_data->local_lock);
    10511055
    1052         // send the packet
     1056        /* Send the packet */
    10531057        tcp_send_packets(socket_data->device_id, packet);
    10541058
     
    10561060}
    10571061
    1058 int
    1059 tcp_process_syn_received(socket_core_ref socket,
     1062int tcp_process_syn_received(socket_core_ref socket,
    10601063    tcp_socket_data_ref socket_data, tcp_header_ref header, packet_t packet)
    10611064{
     
    10731076                return tcp_release_and_return(packet, EINVAL);
    10741077
    1075         // process acknowledgement
     1078        /* Process acknowledgement */
    10761079        tcp_process_acknowledgement(socket, socket_data, header);
    10771080
     
    10861089                assert(listening_socket_data);
    10871090
    1088                 // queue the received packet
     1091                /* Queue the received packet */
    10891092                rc = dyn_fifo_push(&listening_socket->accepted,
    10901093                    (-1 * socket->socket_id), listening_socket_data->backlog);
    10911094                if (rc == EOK) {
    1092                         // notify the destination socket
     1095                        /* Notify the destination socket */
    10931096                        async_msg_5(socket->phone, NET_SOCKET_ACCEPTED,
    10941097                            (ipcarg_t) listening_socket->socket_id,
     
    11001103                }
    11011104        }
    1102         // send FIN
     1105        /* Send FIN */
    11031106        socket_data->state = TCP_SOCKET_FIN_WAIT_1;
    11041107
    1105         // create the notification packet
     1108        /* Create the notification packet */
    11061109        rc = tcp_create_notification_packet(&packet, socket, socket_data, 0, 1);
    11071110        if (rc != EOK)
    11081111                return rc;
    11091112
    1110         // send the packet
     1113        /* Send the packet */
    11111114        rc = tcp_queue_packet(socket, socket_data, packet, 1);
    11121115        if (rc != EOK)
    11131116                return rc;
    11141117
    1115         // flush packets
     1118        /* Flush packets */
    11161119        packet = tcp_get_packets_to_send(socket, socket_data);
    11171120        fibril_rwlock_write_unlock(socket_data->local_lock);
    11181121        if (packet) {
    1119                 // send the packet
     1122                /* Send the packet */
    11201123                tcp_send_packets(socket_data->device_id, packet);
    11211124        }
     
    11241127}
    11251128
    1126 void
    1127 tcp_process_acknowledgement(socket_core_ref socket,
     1129void tcp_process_acknowledgement(socket_core_ref socket,
    11281130    tcp_socket_data_ref socket_data, tcp_header_ref header)
    11291131{
     
    11441146
    11451147        number = ntohl(header->acknowledgement_number);
    1146         // if more data acknowledged
     1148
     1149        /* If more data acknowledged */
    11471150        if (number != socket_data->expected) {
    11481151                old = socket_data->expected;
     
    11551158                        case TCP_SOCKET_LAST_ACK:
    11561159                        case TCP_SOCKET_CLOSING:
    1157                                 // fin acknowledged - release the socket in
    1158                                 // another fibril
     1160                                /*
     1161                                 * FIN acknowledged - release the socket in
     1162                                 * another fibril.
     1163                                 */
    11591164                                tcp_prepare_timeout(tcp_release_after_timeout,
    11601165                                    socket, socket_data, 0,
     
    11661171                        }
    11671172                }
    1168                 // update the treshold if higher than set
     1173
     1174                /* Update the treshold if higher than set */
    11691175                if (number + ntohs(header->window) >
    11701176                    socket_data->expected + socket_data->treshold) {
     
    11721178                            socket_data->expected;
    11731179                }
    1174                 // set new expected sequence number
     1180
     1181                /* Set new expected sequence number */
    11751182                socket_data->expected = number;
    11761183                socket_data->expected_count = 1;
     
    11841191                                        socket_data->outgoing = next;
    11851192
    1186                                 // add to acknowledged or release
     1193                                /* Add to acknowledged or release */
    11871194                                if (pq_add(&acknowledged, packet, 0, 0) != EOK)
    11881195                                        pq_release_remote(tcp_globals.net_phone,
     
    11921199                                break;
    11931200                }
    1194                 // release acknowledged
     1201
     1202                /* Release acknowledged */
    11951203                if (acknowledged) {
    11961204                        pq_release_remote(tcp_globals.net_phone,
     
    11981206                }
    11991207                return;
    1200                 // if the same as the previous time
    1201         }
     1208                /* If the same as the previous time */
     1209        }
     1210
    12021211        if (number == socket_data->expected) {
    1203                 // increase the counter
     1212                /* Increase the counter */
    12041213                socket_data->expected_count++;
    12051214                if (socket_data->expected_count == TCP_FAST_RETRANSMIT_COUNT) {
    12061215                        socket_data->expected_count = 1;
    1207                         // TODO retransmit lock
     1216                        /* TODO retransmit lock */
    12081217                        //tcp_retransmit_packet(socket, socket_data, number);
    12091218                }
     
    13111320        while (keep_on_going) {
    13121321
    1313                 // answer the call
     1322                /* Answer the call */
    13141323                answer_call(callid, res, &answer, answer_count);
    1315                 // refresh data
     1324                /* Refresh data */
    13161325                refresh_answer(&answer, &answer_count);
    1317                 // get the next call
     1326                /* Get the next call */
    13181327                callid = async_get_call(&call);
    13191328
    1320                 // process the call
     1329                /* Process the call */
    13211330                switch (IPC_GET_METHOD(call)) {
    13221331                case IPC_M_PHONE_HUNGUP:
     
    14011410                        if (res != EOK)
    14021411                                break;
    1403                         // the global lock may be released in the
    1404                         // tcp_connect_message() function
     1412                        /*
     1413                         * The global lock may be released in the
     1414                         * tcp_connect_message() function.
     1415                         */
    14051416                        fibril_rwlock_write_lock(&tcp_globals.lock);
    14061417                        fibril_rwlock_write_lock(&lock);
     
    15161527        }
    15171528
    1518         // release the application phone
     1529        /* Release the application phone */
    15191530        ipc_hangup(app_phone);
    15201531
    15211532        printf("release\n");
    1522         // release all local sockets
     1533        /* Release all local sockets */
    15231534        socket_cores_release(tcp_globals.net_phone, &local_sockets,
    15241535            &tcp_globals.sockets, tcp_free_socket_data);
     
    15361547        assert(timeout);
    15371548
    1538         // sleep the given timeout
     1549        /* Sleep the given timeout */
    15391550        async_usleep(timeout->timeout);
    1540         // lock the globals
     1551        /* Lock the globals */
    15411552        if (timeout->globals_read_only)
    15421553                fibril_rwlock_read_lock(&tcp_globals.lock);
     
    15441555                fibril_rwlock_write_lock(&tcp_globals.lock);
    15451556
    1546         // find the pending operation socket
     1557        /* Find the pending operation socket */
    15471558        socket = socket_port_find(&tcp_globals.sockets, timeout->port,
    15481559            timeout->key, timeout->key_length);
     
    15571568        fibril_rwlock_write_lock(socket_data->local_lock);
    15581569        if (timeout->sequence_number) {
    1559                 // increase the timeout counter;
     1570                /* Increase the timeout counter */
    15601571                socket_data->timeout_count++;
    15611572                if (socket_data->timeout_count == TCP_MAX_TIMEOUTS) {
    1562                         // TODO release as connection lost
     1573                        /* TODO release as connection lost */
    15631574                        //tcp_refresh_socket_data(socket_data);
    15641575                        fibril_rwlock_write_unlock(socket_data->local_lock);
    15651576                } else {
    1566                         // retransmit
     1577                        /* Retransmit */
    15671578//                      tcp_retransmit_packet(socket,
    15681579//                          socket_data, timeout->sequence_number);
     
    15711582        } else {
    15721583                fibril_mutex_lock(&socket_data->operation.mutex);
    1573                 // set the timeout operation result if state not
    1574                 // changed
     1584                /* Set the timeout operation result if state not changed */
    15751585                if (socket_data->state == timeout->state) {
    15761586                        socket_data->operation.result = ETIMEOUT;
    1577                         // notify the main fibril
     1587
     1588                        /* Notify the main fibril */
    15781589                        fibril_condvar_signal(&socket_data->operation.condvar);
    1579                         // keep the global write lock
     1590
     1591                        /* Keep the global write lock */
    15801592                        keep_write_lock = true;
    15811593                } else {
    1582                         // operation is ok, do nothing
    1583                         // unlocking from now on, so the unlocki
    1584                         // order does not matter...
     1594                        /*
     1595                         * Operation is ok, do nothing.
     1596                         * Unlocking from now on, so the unlocking
     1597                         * order does not matter.
     1598                         */
    15851599                        fibril_rwlock_write_unlock(socket_data->local_lock);
    15861600                }
     
    15891603
    15901604out:
    1591         // unlock only if no socket
     1605        /* Unlock only if no socket */
    15921606        if (timeout->globals_read_only)
    15931607                fibril_rwlock_read_unlock(&tcp_globals.lock);
    15941608        else if (!keep_write_lock)
    1595                 // release if not desired
     1609                /* Release if not desired */
    15961610                fibril_rwlock_write_unlock(&tcp_globals.lock);
    15971611       
    1598         // release the timeout structure
     1612        /* Release the timeout structure */
    15991613        free(timeout);
    16001614        return EOK;
     
    16101624        assert(timeout);
    16111625
    1612         // sleep the given timeout
     1626        /* Sleep the given timeout */
    16131627        async_usleep(timeout->timeout);
    1614         // lock the globals
     1628
     1629        /* Lock the globals */
    16151630        fibril_rwlock_write_lock(&tcp_globals.lock);
    1616         // find the pending operation socket
     1631
     1632        /* Find the pending operation socket */
    16171633        socket = socket_port_find(&tcp_globals.sockets, timeout->port,
    16181634            timeout->key, timeout->key_length);
     1635
    16191636        if (socket && (socket->socket_id == timeout->socket_id)) {
    16201637                socket_data = (tcp_socket_data_ref) socket->specific_data;
     
    16291646                }
    16301647        }
    1631         // unlock the globals
     1648
     1649        /* Unlock the globals */
    16321650        fibril_rwlock_write_unlock(&tcp_globals.lock);
    1633         // release the timeout structure
     1651
     1652        /* Release the timeout structure */
    16341653        free(timeout);
     1654
    16351655        return EOK;
    16361656}
    16371657
    1638 void
    1639 tcp_retransmit_packet(socket_core_ref socket, tcp_socket_data_ref socket_data,
    1640     size_t sequence_number)
     1658void tcp_retransmit_packet(socket_core_ref socket, tcp_socket_data_ref
     1659    socket_data, size_t sequence_number)
    16411660{
    16421661        packet_t packet;
     
    16481667        assert(socket->specific_data == socket_data);
    16491668
    1650         // sent packet?
     1669        /* Sent packet? */
    16511670        packet = pq_find(socket_data->outgoing, sequence_number);
    16521671        printf("retransmit %d\n", packet_get_id(packet));
     
    16641683}
    16651684
    1666 int
    1667 tcp_listen_message(socket_cores_ref local_sockets, int socket_id, int backlog)
     1685int tcp_listen_message(socket_cores_ref local_sockets, int socket_id,
     1686    int backlog)
    16681687{
    16691688        socket_core_ref socket;
     
    16751694                return EINVAL;
    16761695
    1677         // find the socket
     1696        /* Find the socket */
    16781697        socket = socket_cores_find(local_sockets, socket_id);
    16791698        if (!socket)
    16801699                return ENOTSOCK;
    16811700       
    1682         // get the socket specific data
     1701        /* Get the socket specific data */
    16831702        socket_data = (tcp_socket_data_ref) socket->specific_data;
    16841703        assert(socket_data);
    1685         // set the backlog
     1704
     1705        /* Set the backlog */
    16861706        socket_data->backlog = backlog;
    16871707
     
    16891709}
    16901710
    1691 int
    1692 tcp_connect_message(socket_cores_ref local_sockets, int socket_id,
     1711int tcp_connect_message(socket_cores_ref local_sockets, int socket_id,
    16931712    struct sockaddr *addr, socklen_t addrlen)
    16941713{
     
    17001719        assert(addrlen > 0);
    17011720
    1702         // find the socket
     1721        /* Find the socket */
    17031722        socket = socket_cores_find(local_sockets, socket_id);
    17041723        if (!socket)
     
    17081727        if (rc != EOK) {
    17091728                tcp_free_socket_data(socket);
    1710                 // unbind if bound
     1729                /* Unbind if bound */
    17111730                if (socket->port > 0) {
    17121731                        socket_ports_exclude(&tcp_globals.sockets,
     
    17181737}
    17191738
    1720 int
    1721 tcp_connect_core(socket_core_ref socket, socket_cores_ref local_sockets,
     1739int tcp_connect_core(socket_core_ref socket, socket_cores_ref local_sockets,
    17221740    struct sockaddr *addr, socklen_t addrlen)
    17231741{
     
    17301748        assert(addrlen > 0);
    17311749
    1732         // get the socket specific data
     1750        /* Get the socket specific data */
    17331751        socket_data = (tcp_socket_data_ref) socket->specific_data;
    17341752        assert(socket_data);
     
    17391757                return EINVAL;
    17401758
    1741         // get the destination port
     1759        /* Get the destination port */
    17421760        rc = tl_get_address_port(addr, addrlen, &socket_data->dest_port);
    17431761        if (rc != EOK)
     
    17451763       
    17461764        if (socket->port <= 0) {
    1747                 // try to find a free port
     1765                /* Try to find a free port */
    17481766                rc = socket_bind_free_port(&tcp_globals.sockets, socket,
    17491767                    TCP_FREE_PORTS_START, TCP_FREE_PORTS_END,
     
    17511769                if (rc != EOK)
    17521770                        return rc;
    1753                 // set the next port as the search starting port number
     1771                /* Set the next port as the search starting port number */
    17541772                tcp_globals.last_used_port = socket->port;
    17551773        }
     
    17611779                return rc;
    17621780
    1763         // create the notification packet
     1781        /* Create the notification packet */
    17641782        rc = tcp_create_notification_packet(&packet, socket, socket_data, 1, 0);
    17651783        if (rc != EOK)
    17661784                return rc;
    17671785
    1768         // unlock the globals and wait for an operation
     1786        /* Unlock the globals and wait for an operation */
    17691787        fibril_rwlock_write_unlock(&tcp_globals.lock);
    17701788
    17711789        socket_data->addr = addr;
    17721790        socket_data->addrlen = addrlen;
    1773         // send the packet
     1791
     1792        /* Send the packet */
    17741793
    17751794        if (((rc = tcp_queue_packet(socket, socket_data, packet, 1)) != EOK) ||
     
    17851804                        fibril_mutex_lock(&socket_data->operation.mutex);
    17861805                        fibril_rwlock_write_unlock(socket_data->local_lock);
    1787                         // send the packet
     1806
     1807                        /* Send the packet */
    17881808                        printf("connecting %d\n", packet_get_id(packet));
    17891809                        tcp_send_packets(socket_data->device_id, packet);
    17901810
    1791                         // wait for a reply
     1811                        /* Wait for a reply */
    17921812                        fibril_condvar_wait(&socket_data->operation.condvar,
    17931813                            &socket_data->operation.mutex);
     
    18051825
    18061826        fibril_mutex_unlock(&socket_data->operation.mutex);
    1807 
    1808         // return the result
    18091827        return rc;
    18101828}
    18111829
    1812 int
    1813 tcp_queue_prepare_packet(socket_core_ref socket,
     1830int tcp_queue_prepare_packet(socket_core_ref socket,
    18141831    tcp_socket_data_ref socket_data, packet_t packet, size_t data_length)
    18151832{
     
    18211838        assert(socket->specific_data == socket_data);
    18221839
    1823         // get tcp header
     1840        /* Get TCP header */
    18241841        header = (tcp_header_ref) packet_get_data(packet);
    18251842        if (!header)
     
    18351852                return tcp_release_and_return(packet, EINVAL);
    18361853
    1837         // remember the outgoing FIN
     1854        /* Remember the outgoing FIN */
    18381855        if (header->finalize)
    18391856                socket_data->fin_outgoing = socket_data->next_outgoing;
     
    18421859}
    18431860
    1844 int
    1845 tcp_queue_packet(socket_core_ref socket, tcp_socket_data_ref socket_data,
     1861int tcp_queue_packet(socket_core_ref socket, tcp_socket_data_ref socket_data,
    18461862    packet_t packet, size_t data_length)
    18471863{
     
    18651881}
    18661882
    1867 packet_t
    1868 tcp_get_packets_to_send(socket_core_ref socket, tcp_socket_data_ref socket_data)
     1883packet_t tcp_get_packets_to_send(socket_core_ref socket, tcp_socket_data_ref
     1884    socket_data)
    18691885{
    18701886        packet_t packet;
     
    18831899                pq_get_order(packet, NULL, &data_length);
    18841900
    1885                 // send only if fits into the window
    1886                 // respecting the possible overflow
     1901                /*
     1902                 * Send only if fits into the window, respecting the possible
     1903                 * overflow.
     1904                 */
    18871905                if (!IS_IN_INTERVAL_OVERFLOW(
    18881906                    (uint32_t) socket_data->last_outgoing,
     
    19091927                previous = copy;
    19101928                packet = pq_next(packet);
    1911                 // overflow occurred ?
     1929
     1930                /* Overflow occurred? */
    19121931                if (!packet &&
    19131932                    (socket_data->last_outgoing > socket_data->next_outgoing)) {
    19141933                        printf("gpts overflow\n");
    1915                         // continue from the beginning
     1934                        /* Continue from the beginning */
    19161935                        packet = socket_data->outgoing;
    19171936                }
     
    19221941}
    19231942
    1924 packet_t
    1925 tcp_send_prepare_packet(socket_core_ref socket, tcp_socket_data_ref socket_data,
    1926     packet_t packet, size_t data_length, size_t sequence_number)
     1943packet_t tcp_send_prepare_packet(socket_core_ref socket, tcp_socket_data_ref
     1944    socket_data, packet_t packet, size_t data_length, size_t sequence_number)
    19271945{
    19281946        tcp_header_ref header;
     
    19341952        assert(socket->specific_data == socket_data);
    19351953
    1936         // adjust the pseudo header
     1954        /* Adjust the pseudo header */
    19371955        rc = ip_client_set_pseudo_header_data_length(socket_data->pseudo_header,
    19381956            socket_data->headerlen, packet_get_data_length(packet));
     
    19421960        }
    19431961
    1944         // get the header
     1962        /* Get the header */
    19451963        header = (tcp_header_ref) packet_get_data(packet);
    19461964        if (!header) {
     
    19501968        assert(ntohl(header->sequence_number) == sequence_number);
    19511969
    1952         // adjust the header
     1970        /* Adjust the header */
    19531971        if (socket_data->next_incoming) {
    19541972                header->acknowledgement_number =
     
    19581976        header->window = htons(socket_data->window);
    19591977
    1960         // checksum
     1978        /* Checksum */
    19611979        header->checksum = 0;
    19621980        checksum = compute_checksum(0, socket_data->pseudo_header,
     
    19671985        header->checksum = htons(flip_checksum(compact_checksum(checksum)));
    19681986
    1969         // prepare the packet
     1987        /* Prepare the packet */
    19701988        rc = ip_client_prepare_packet(packet, IPPROTO_TCP, 0, 0, 0, 0);
    19711989        if (rc != EOK) {
     
    19731991                return NULL;
    19741992        }
     1993
    19751994        rc = tcp_prepare_timeout(tcp_timeout, socket, socket_data,
    19761995            sequence_number, socket_data->state, socket_data->timeout, true);
     
    19832002}
    19842003
    1985 packet_t
    1986 tcp_prepare_copy(socket_core_ref socket, tcp_socket_data_ref socket_data,
    1987     packet_t packet, size_t data_length, size_t sequence_number)
     2004packet_t tcp_prepare_copy(socket_core_ref socket, tcp_socket_data_ref
     2005    socket_data, packet_t packet, size_t data_length, size_t sequence_number)
    19882006{
    19892007        packet_t copy;
     
    19932011        assert(socket->specific_data == socket_data);
    19942012
    1995         // make a copy of the packet
     2013        /* Make a copy of the packet */
    19962014        copy = packet_get_copy(tcp_globals.net_phone, packet);
    19972015        if (!copy)
     
    20142032}
    20152033
    2016 void
    2017 tcp_prepare_operation_header(socket_core_ref socket,
     2034void tcp_prepare_operation_header(socket_core_ref socket,
    20182035    tcp_socket_data_ref socket_data, tcp_header_ref header, int synchronize,
    20192036    int finalize)
     
    20322049}
    20332050
    2034 int
    2035 tcp_prepare_timeout(int (*timeout_function)(void *tcp_timeout_t),
     2051int tcp_prepare_timeout(int (*timeout_function)(void *tcp_timeout_t),
    20362052    socket_core_ref socket, tcp_socket_data_ref socket_data,
    20372053    size_t sequence_number, tcp_socket_state_t state, suseconds_t timeout,
     
    20452061        assert(socket->specific_data == socket_data);
    20462062
    2047         // prepare the timeout with key bundle structure
     2063        /* Prepare the timeout with key bundle structure */
    20482064        operation_timeout = malloc(sizeof(*operation_timeout) +
    20492065            socket->key_length + 1);
     
    20602076        operation_timeout->state = state;
    20612077
    2062         // copy the key
     2078        /* Copy the key */
    20632079        operation_timeout->key = ((char *) operation_timeout) +
    20642080            sizeof(*operation_timeout);
     
    20672083        operation_timeout->key[operation_timeout->key_length] = '\0';
    20682084
    2069         // prepare the timeouting thread
     2085        /* Prepare the timeouting thread */
    20702086        fibril = fibril_create(timeout_function, operation_timeout);
    20712087        if (!fibril) {
     
    20742090        }
    20752091//      fibril_mutex_lock(&socket_data->operation.mutex);
    2076         // start the timeouting fibril
     2092        /* Start the timeout fibril */
    20772093        fibril_add_ready(fibril);
    20782094        //socket_data->state = state;
     
    20802096}
    20812097
    2082 int
    2083 tcp_recvfrom_message(socket_cores_ref local_sockets, int socket_id, int flags,
    2084     size_t *addrlen)
     2098int tcp_recvfrom_message(socket_cores_ref local_sockets, int socket_id,
     2099    int flags, size_t *addrlen)
    20852100{
    20862101        socket_core_ref socket;
     
    20932108        assert(local_sockets);
    20942109
    2095         // find the socket
     2110        /* Find the socket */
    20962111        socket = socket_cores_find(local_sockets, socket_id);
    20972112        if (!socket)
    20982113                return ENOTSOCK;
    20992114
    2100         // get the socket specific data
     2115        /* Get the socket specific data */
    21012116        if (!socket->specific_data)
    21022117                return NO_DATA;
     
    21042119        socket_data = (tcp_socket_data_ref) socket->specific_data;
    21052120
    2106         // check state
     2121        /* Check state */
    21072122        if ((socket_data->state != TCP_SOCKET_ESTABLISHED) &&
    21082123            (socket_data->state != TCP_SOCKET_CLOSE_WAIT))
    21092124                return ENOTCONN;
    21102125
    2111         // send the source address if desired
     2126        /* Send the source address if desired */
    21122127        if (addrlen) {
    21132128                rc = data_reply(socket_data->addr, socket_data->addrlen);
     
    21172132        }
    21182133
    2119         // get the next received packet
     2134        /* Get the next received packet */
    21202135        packet_id = dyn_fifo_value(&socket->received);
    21212136        if (packet_id < 0)
     
    21262141                return rc;
    21272142
    2128         // reply the packets
     2143        /* Reply the packets */
    21292144        rc = socket_reply_packets(packet, &length);
    21302145        if (rc != EOK)
    21312146                return rc;
    21322147
    2133         // release the packet
     2148        /* Release the packet */
    21342149        dyn_fifo_pop(&socket->received);
    21352150        pq_release_remote(tcp_globals.net_phone, packet_get_id(packet));
    2136         // return the total length
     2151
     2152        /* Return the total length */
    21372153        return (int) length;
    21382154}
    21392155
    2140 int
    2141 tcp_send_message(socket_cores_ref local_sockets, int socket_id, int fragments,
    2142     size_t *data_fragment_size, int flags)
     2156int tcp_send_message(socket_cores_ref local_sockets, int socket_id,
     2157    int fragments, size_t *data_fragment_size, int flags)
    21432158{
    21442159        socket_core_ref socket;
     
    21552170        assert(data_fragment_size);
    21562171
    2157         // find the socket
     2172        /* Find the socket */
    21582173        socket = socket_cores_find(local_sockets, socket_id);
    21592174        if (!socket)
    21602175                return ENOTSOCK;
    21612176
    2162         // get the socket specific data
     2177        /* Get the socket specific data */
    21632178        if (!socket->specific_data)
    21642179                return NO_DATA;
     
    21662181        socket_data = (tcp_socket_data_ref) socket->specific_data;
    21672182
    2168         // check state
     2183        /* Check state */
    21692184        if ((socket_data->state != TCP_SOCKET_ESTABLISHED) &&
    21702185            (socket_data->state != TCP_SOCKET_CLOSE_WAIT))
     
    21812196
    21822197        for (index = 0; index < fragments; index++) {
    2183                 // read the data fragment
     2198                /* Read the data fragment */
    21842199                result = tl_socket_read_packet_data(tcp_globals.net_phone,
    21852200                    &packet, TCP_HEADER_SIZE, packet_dimension,
     
    21892204
    21902205                total_length = (size_t) result;
    2191                 // prefix the tcp header
     2206
     2207                /* Prefix the TCP header */
    21922208                header = PACKET_PREFIX(packet, tcp_header_t);
    21932209                if (!header)
     
    22002216        }
    22012217
    2202         // flush packets
     2218        /* Flush packets */
    22032219        packet = tcp_get_packets_to_send(socket, socket_data);
    22042220        fibril_rwlock_write_unlock(socket_data->local_lock);
     
    22062222
    22072223        if (packet) {
    2208                 // send the packet
     2224                /* Send the packet */
    22092225                tcp_send_packets(socket_data->device_id, packet);
    22102226        }
     
    22212237        int rc;
    22222238
    2223         // find the socket
     2239        /* Find the socket */
    22242240        socket = socket_cores_find(local_sockets, socket_id);
    22252241        if (!socket)
    22262242                return ENOTSOCK;
    22272243
    2228         // get the socket specific data
     2244        /* Get the socket specific data */
    22292245        socket_data = (tcp_socket_data_ref) socket->specific_data;
    22302246        assert(socket_data);
    22312247
    2232         // check state
     2248        /* Check state */
    22332249        switch (socket_data->state) {
    22342250        case TCP_SOCKET_ESTABLISHED:
     
    22432259
    22442260        default:
    2245                 // just destroy
     2261                /* Just destroy */
    22462262                rc = socket_destroy(tcp_globals.net_phone, socket_id,
    22472263                    local_sockets, &tcp_globals.sockets,
     
    22542270        }
    22552271
    2256         // send FIN
    2257         // TODO should I wait to complete?
    2258 
    2259         // create the notification packet
     2272        /*
     2273         * Send FIN.
     2274         * TODO should I wait to complete?
     2275         */
     2276
     2277        /* Create the notification packet */
    22602278        rc = tcp_create_notification_packet(&packet, socket, socket_data, 0, 1);
    22612279        if (rc != EOK)
    22622280                return rc;
    22632281
    2264         // send the packet
     2282        /* Send the packet */
    22652283        rc = tcp_queue_packet(socket, socket_data, packet, 1);
    22662284        if (rc != EOK)
    22672285                return rc;
    22682286
    2269         // flush packets
     2287        /* Flush packets */
    22702288        packet = tcp_get_packets_to_send(socket, socket_data);
    22712289        fibril_rwlock_write_unlock(socket_data->local_lock);
     
    22732291
    22742292        if (packet) {
    2275                 // send the packet
     2293                /* Send the packet */
    22762294                tcp_send_packets(socket_data->device_id, packet);
    22772295        }
     
    22802298}
    22812299
    2282 int
    2283 tcp_create_notification_packet(packet_t *packet, socket_core_ref socket,
     2300int tcp_create_notification_packet(packet_t *packet, socket_core_ref socket,
    22842301    tcp_socket_data_ref socket_data, int synchronize, int finalize)
    22852302{
     
    22902307        assert(packet);
    22912308
    2292         // get the device packet dimension
     2309        /* Get the device packet dimension */
    22932310        rc = tl_get_ip_packet_dimension(tcp_globals.ip_phone,
    22942311            &tcp_globals.dimensions, socket_data->device_id, &packet_dimension);
     
    22962313                return rc;
    22972314
    2298         // get a new packet
     2315        /* Get a new packet */
    22992316        *packet = packet_get_4_remote(tcp_globals.net_phone, TCP_HEADER_SIZE,
    23002317            packet_dimension->addr_len, packet_dimension->prefix,
     
    23042321                return ENOMEM;
    23052322
    2306         // allocate space in the packet
     2323        /* Allocate space in the packet */
    23072324        header = PACKET_SUFFIX(*packet, tcp_header_t);
    23082325        if (!header)
     
    23152332}
    23162333
    2317 int
    2318 tcp_accept_message(socket_cores_ref local_sockets, int socket_id,
     2334int tcp_accept_message(socket_cores_ref local_sockets, int socket_id,
    23192335    int new_socket_id, size_t *data_fragment_size, size_t *addrlen)
    23202336{
     
    23292345        assert(addrlen);
    23302346
    2331         // find the socket
     2347        /* Find the socket */
    23322348        socket = socket_cores_find(local_sockets, socket_id);
    23332349        if (!socket)
    23342350                return ENOTSOCK;
    23352351
    2336         // get the socket specific data
     2352        /* Get the socket specific data */
    23372353        socket_data = (tcp_socket_data_ref) socket->specific_data;
    23382354        assert(socket_data);
    23392355
    2340         // check state
     2356        /* Check state */
    23412357        if (socket_data->state != TCP_SOCKET_LISTEN)
    23422358                return EINVAL;
     
    23522368                        return ENOTSOCK;
    23532369
    2354                 // get the socket specific data
     2370                /* Get the socket specific data */
    23552371                socket_data = (tcp_socket_data_ref) accepted->specific_data;
    23562372                assert(socket_data);
    2357                 // TODO can it be in another state?
     2373                /* TODO can it be in another state? */
    23582374                if (socket_data->state == TCP_SOCKET_ESTABLISHED) {
    23592375                        rc = data_reply(socket_data->addr,
     
    23892405}
    23902406
    2391 void
    2392 tcp_free_socket_data(socket_core_ref socket)
     2407void tcp_free_socket_data(socket_core_ref socket)
    23932408{
    23942409        tcp_socket_data_ref socket_data;
     
    23982413        printf("destroy_socket %d\n", socket->socket_id);
    23992414
    2400         // get the socket specific data
     2415        /* Get the socket specific data */
    24012416        socket_data = (tcp_socket_data_ref) socket->specific_data;
    24022417        assert(socket_data);
    2403         //free the pseudo header
     2418
     2419        /* Free the pseudo header */
    24042420        if (socket_data->pseudo_header) {
    24052421                if (socket_data->headerlen) {
     
    24102426                socket_data->pseudo_header = NULL;
    24112427        }
     2428
    24122429        socket_data->headerlen = 0;
    2413         // free the address
     2430
     2431        /* Free the address */
    24142432        if (socket_data->addr) {
    24152433                if (socket_data->addrlen) {
     
    24732491
    24742492                /*
    2475                    Answer the message
     2493                 * Answer the message
    24762494                 */
    24772495                answer_call(callid, res, &answer, answer_count);
  • uspace/srv/net/tl/tcp/tcp_module.c

    rc9ebbe71 rfb04cba8  
    8686}
    8787
    88 int
    89 tl_module_message_standalone(ipc_callid_t callid, ipc_call_t *call,
     88int tl_module_message_standalone(ipc_callid_t callid, ipc_call_t *call,
    9089    ipc_call_t *answer, int *answer_count)
    9190{
  • uspace/srv/net/tl/udp/udp.c

    rc9ebbe71 rfb04cba8  
    130130        }
    131131
    132         // read default packet dimensions
     132        /* Read default packet dimensions */
    133133        rc = ip_packet_size_req(udp_globals.ip_phone, -1,
    134134            &udp_globals.packet_dimension);
     
    158158        udp_globals.autobinding = NET_DEFAULT_UDP_AUTOBINDING;
    159159
    160         // get configuration
     160        /* Get configuration */
    161161        configuration = &names[0];
    162162        rc = net_get_conf_req(udp_globals.net_phone, &configuration, count,
     
    217217 *                      ip_client_process_packet() function.
    218218 */
    219 static int
    220 udp_process_packet(device_id_t device_id, packet_t packet, services_t error)
     219static int udp_process_packet(device_id_t device_id, packet_t packet,
     220    services_t error)
    221221{
    222222        size_t length;
     
    242242                break;
    243243        case SERVICE_ICMP:
    244                 // ignore error
     244                /* Ignore error */
    245245                // length = icmp_client_header_length(packet);
    246                 // process error
     246
     247                /* Process error */
    247248                result = icmp_client_process_packet(packet, &type,
    248249                    &code, NULL, NULL);
     
    258259        }
    259260
    260         // TODO process received ipopts?
     261        /* TODO process received ipopts? */
    261262        result = ip_client_process_packet(packet, NULL, NULL, NULL, NULL, NULL);
    262263        if (result < 0)
     
    270271                return udp_release_and_return(packet, NO_DATA);
    271272
    272         // trim all but UDP header
     273        /* Trim all but UDP header */
    273274        rc = packet_trim(packet, offset, 0);
    274275        if (rc != EOK)
    275276                return udp_release_and_return(packet, rc);
    276277
    277         // get udp header
     278        /* Get UDP header */
    278279        header = (udp_header_ref) packet_get_data(packet);
    279280        if (!header)
    280281                return udp_release_and_return(packet, NO_DATA);
    281282
    282         // find the destination socket
     283        /* Find the destination socket */
    283284        socket = socket_port_find(&udp_globals.sockets,
    284285        ntohs(header->destination_port), SOCKET_MAP_KEY_LISTENING, 0);
     
    292293        }
    293294
    294         // count the received packet fragments
     295        /* Count the received packet fragments */
    295296        next_packet = packet;
    296297        fragments = 0;
    297298        total_length = ntohs(header->total_length);
    298299
    299         // compute header checksum if set
     300        /* Compute header checksum if set */
    300301        if (header->checksum && !error) {
    301302                result = packet_get_addr(packet, (uint8_t **) &src,
     
    310311                } else {
    311312                        checksum = compute_checksum(0, ip_header, length);
    312                         // the udp header checksum will be added with the first
    313                         // fragment later
     313                        /*
     314                         * The udp header checksum will be added with the first
     315                         * fragment later.
     316                         */
    314317                        free(ip_header);
    315318                }
     
    330333                                return udp_release_and_return(packet, rc);
    331334
    332                         // add partial checksum if set
     335                        /* Add partial checksum if set */
    333336                        if (header->checksum) {
    334337                                checksum = compute_checksum(checksum,
     
    337340                        }
    338341
    339                         // relese the rest of the packet fragments
     342                        /* Relese the rest of the packet fragments */
    340343                        tmp_packet = pq_next(next_packet);
    341344                        while (tmp_packet) {
     
    346349                        }
    347350
    348                         // exit the loop
     351                        /* Exit the loop */
    349352                        break;
    350353                }
    351354                total_length -= length;
    352355
    353                 // add partial checksum if set
     356                /* Add partial checksum if set */
    354357                if (header->checksum) {
    355358                        checksum = compute_checksum(checksum,
     
    360363        } while ((next_packet = pq_next(next_packet)) && (total_length > 0));
    361364
    362         // check checksum
     365        /* Verify checksum */
    363366        if (header->checksum) {
    364367                if (flip_checksum(compact_checksum(checksum)) !=
     
    366369                        if (tl_prepare_icmp_packet(udp_globals.net_phone,
    367370                            udp_globals.icmp_phone, packet, error) == EOK) {
    368                                 // checksum error ICMP
     371                                /* Checksum error ICMP */
    369372                                icmp_parameter_problem_msg(
    370373                                    udp_globals.icmp_phone, ICMP_PARAM_POINTER,
     
    376379        }
    377380
    378         // queue the received packet
     381        /* Queue the received packet */
    379382        rc = dyn_fifo_push(&socket->received, packet_get_id(packet),
    380383            SOCKET_MAX_RECEIVED_SIZE);
     
    387390                return udp_release_and_return(packet, rc);
    388391
    389         // notify the destination socket
     392        /* Notify the destination socket */
    390393        fibril_rwlock_write_unlock(&udp_globals.lock);
    391394        async_msg_5(socket->phone, NET_SOCKET_RECEIVED,
     
    410413 *                      udp_process_packet() function.
    411414 */
    412 static int
    413 udp_received_msg(device_id_t device_id, packet_t packet, services_t receiver,
    414     services_t error)
     415static int udp_received_msg(device_id_t device_id, packet_t packet,
     416    services_t receiver, services_t error)
    415417{
    416418        int result;
     
    451453 *                      function.
    452454 */
    453 static int
    454 udp_sendto_message(socket_cores_ref local_sockets, int socket_id,
     455static int udp_sendto_message(socket_cores_ref local_sockets, int socket_id,
    455456    const struct sockaddr *addr, socklen_t addrlen, int fragments,
    456457    size_t *data_fragment_size, int flags)
     
    480481
    481482        if ((socket->port <= 0) && udp_globals.autobinding) {
    482                 // bind the socket to a random free port if not bound
     483                /* Bind the socket to a random free port if not bound */
    483484                rc = socket_bind_free_port(&udp_globals.sockets, socket,
    484485                    UDP_FREE_PORTS_START, UDP_FREE_PORTS_END,
     
    486487                if (rc != EOK)
    487488                        return rc;
    488                 // set the next port as the search starting port number
     489                /* Set the next port as the search starting port number */
    489490                udp_globals.last_used_port = socket->port;
    490491        }
     
    495496                if (rc != EOK)
    496497                        return rc;
    497                 // get the device packet dimension
     498                /* Get the device packet dimension */
    498499//              rc = tl_get_ip_packet_dimension(udp_globals.ip_phone,
    499500//                  &udp_globals.dimensions, device_id, &packet_dimension);
     
    502503        }
    503504//      } else {
    504                 // do not ask all the time
     505                /* Do not ask all the time */
    505506                rc = ip_packet_size_req(udp_globals.ip_phone, -1,
    506507                    &udp_globals.packet_dimension);
     
    510511//      }
    511512
    512         // read the first packet fragment
     513        /* Read the first packet fragment */
    513514        result = tl_socket_read_packet_data(udp_globals.net_phone, &packet,
    514515            UDP_HEADER_SIZE, packet_dimension, addr, addrlen);
     
    523524                checksum = 0;
    524525
    525         // prefix the udp header
     526        /* Prefix the UDP header */
    526527        header = PACKET_PREFIX(packet, udp_header_t);
    527528        if (!header)
     
    529530
    530531        bzero(header, sizeof(*header));
    531         // read the rest of the packet fragments
     532
     533        /* Read the rest of the packet fragments */
    532534        for (index = 1; index < fragments; index++) {
    533535                result = tl_socket_read_packet_data(udp_globals.net_phone,
     
    548550        }
    549551
    550         // set the udp header
     552        /* Set the UDP header */
    551553        header->source_port = htons((socket->port > 0) ? socket->port : 0);
    552554        header->destination_port = htons(dest_port);
    553555        header->total_length = htons(total_length + sizeof(*header));
    554556        header->checksum = 0;
     557
    555558        if (udp_globals.checksum_computing) {
    556                 // update the pseudo header
     559                /* Update the pseudo header */
    557560                rc = ip_client_set_pseudo_header_data_length(ip_header,
    558561                    headerlen, total_length + UDP_HEADER_SIZE);
     
    562565                }
    563566
    564                 // finish the checksum computation
     567                /* Finish the checksum computation */
    565568                checksum = compute_checksum(checksum, ip_header, headerlen);
    566569                checksum = compute_checksum(checksum, (uint8_t *) header,
     
    573576        }
    574577
    575         // prepare the first packet fragment
     578        /* Prepare the first packet fragment */
    576579        rc = ip_client_prepare_packet(packet, IPPROTO_UDP, 0, 0, 0, 0);
    577580        if (rc != EOK)
     
    581584        fibril_rwlock_write_unlock(&udp_globals.lock);
    582585
    583         // send the packet
     586        /* Send the packet */
    584587        ip_send_msg(udp_globals.ip_phone, device_id, packet, SERVICE_UDP, 0);
    585588
     
    606609 *                      function.
    607610 */
    608 static int
    609 udp_recvfrom_message(socket_cores_ref local_sockets, int socket_id, int flags,
    610     size_t *addrlen)
     611static int udp_recvfrom_message(socket_cores_ref local_sockets, int socket_id,
     612    int flags, size_t *addrlen)
    611613{
    612614        socket_core_ref socket;
     
    620622        int rc;
    621623
    622         // find the socket
     624        /* Find the socket */
    623625        socket = socket_cores_find(local_sockets, socket_id);
    624626        if (!socket)
    625627                return ENOTSOCK;
    626628
    627         // get the next received packet
     629        /* Get the next received packet */
    628630        packet_id = dyn_fifo_value(&socket->received);
    629631        if (packet_id < 0)
     
    636638        }
    637639
    638         // get udp header
     640        /* Get UDP header */
    639641        data = packet_get_data(packet);
    640642        if (!data) {
     
    644646        header = (udp_header_ref) data;
    645647
    646         // set the source address port
     648        /* Set the source address port */
    647649        result = packet_get_addr(packet, (uint8_t **) &addr, NULL);
    648650        rc = tl_set_address_port(addr, result, ntohs(header->source_port));
     
    653655        *addrlen = (size_t) result;
    654656
    655         // send the source address
     657        /* Send the source address */
    656658        rc = data_reply(addr, *addrlen);
    657659        switch (rc) {
     
    665667        }
    666668
    667         // trim the header
     669        /* Trim the header */
    668670        rc = packet_trim(packet, UDP_HEADER_SIZE, 0);
    669671        if (rc != EOK) {
     
    672674        }
    673675
    674         // reply the packets
     676        /* Reply the packets */
    675677        rc = socket_reply_packets(packet, &length);
    676678        switch (rc) {
     
    686688        (void) dyn_fifo_pop(&socket->received);
    687689
    688         // release the packet and return the total length
     690        /* Release the packet and return the total length */
    689691        return udp_release_and_return(packet, (int) length);
    690692}
     
    721723        answer_count = 0;
    722724
    723         // The client connection is only in one fibril and therefore no
    724         // additional locks are needed.
     725        /*
     726         * The client connection is only in one fibril and therefore no
     727         * additional locks are needed.
     728         */
    725729
    726730        socket_cores_initialize(&local_sockets);
     
    728732        while (keep_on_going) {
    729733
    730                 // answer the call
     734                /* Answer the call */
    731735                answer_call(callid, res, &answer, answer_count);
    732736
    733                 // refresh data
     737                /* Refresh data */
    734738                refresh_answer(&answer, &answer_count);
    735739
    736                 // get the next call
     740                /* Get the next call */
    737741                callid = async_get_call(&call);
    738742
    739                 // process the call
     743                /* Process the call */
    740744                switch (IPC_GET_METHOD(call)) {
    741745                case IPC_M_PHONE_HUNGUP:
     
    831835        }
    832836
    833         // release the application phone
     837        /* Release the application phone */
    834838        ipc_hangup(app_phone);
    835839
    836         // release all local sockets
     840        /* Release all local sockets */
    837841        socket_cores_release(udp_globals.net_phone, &local_sockets,
    838842            &udp_globals.sockets, NULL);
     
    854858 * @see IS_NET_UDP_MESSAGE()
    855859 */
    856 int
    857 udp_message_standalone(ipc_callid_t callid, ipc_call_t *call,
     860int udp_message_standalone(ipc_callid_t callid, ipc_call_t *call,
    858861    ipc_call_t *answer, int *answer_count)
    859862{
  • uspace/srv/net/tl/udp/udp_module.c

    rc9ebbe71 rfb04cba8  
    8686}
    8787
    88 int
    89 tl_module_message_standalone(ipc_callid_t callid, ipc_call_t *call,
     88int tl_module_message_standalone(ipc_callid_t callid, ipc_call_t *call,
    9089    ipc_call_t *answer, int *answer_count)
    9190{
Note: See TracChangeset for help on using the changeset viewer.