Changeset 9e2e715 in mainline for uspace/srv/net/tl/udp/udp.c


Ignore:
Timestamp:
2010-11-14T14:08:29Z (13 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
a9db9b8, d52b0044, eb522e8
Parents:
71e3289 (diff), fb04cba8 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge networking cstyle cleanup.

File:
1 edited

Legend:

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

    r71e3289 r9e2e715  
    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{
Note: See TracChangeset for help on using the changeset viewer.