Ignore:
File:
1 edited

Legend:

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

    rfb04cba8 r08042bd  
    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 udp_process_packet(device_id_t device_id, packet_t packet,
    220     services_t error)
     219static int
     220udp_process_packet(device_id_t device_id, packet_t packet, 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 
    247                 /* Process error */
     246                // process error
    248247                result = icmp_client_process_packet(packet, &type,
    249248                    &code, NULL, NULL);
     
    259258        }
    260259
    261         /* TODO process received ipopts? */
     260        // TODO process received ipopts?
    262261        result = ip_client_process_packet(packet, NULL, NULL, NULL, NULL, NULL);
    263262        if (result < 0)
     
    271270                return udp_release_and_return(packet, NO_DATA);
    272271
    273         /* Trim all but UDP header */
     272        // trim all but UDP header
    274273        rc = packet_trim(packet, offset, 0);
    275274        if (rc != EOK)
    276275                return udp_release_and_return(packet, rc);
    277276
    278         /* Get UDP header */
     277        // get udp header
    279278        header = (udp_header_ref) packet_get_data(packet);
    280279        if (!header)
    281280                return udp_release_and_return(packet, NO_DATA);
    282281
    283         /* Find the destination socket */
     282        // find the destination socket
    284283        socket = socket_port_find(&udp_globals.sockets,
    285284        ntohs(header->destination_port), SOCKET_MAP_KEY_LISTENING, 0);
     
    293292        }
    294293
    295         /* Count the received packet fragments */
     294        // count the received packet fragments
    296295        next_packet = packet;
    297296        fragments = 0;
    298297        total_length = ntohs(header->total_length);
    299298
    300         /* Compute header checksum if set */
     299        // compute header checksum if set
    301300        if (header->checksum && !error) {
    302301                result = packet_get_addr(packet, (uint8_t **) &src,
     
    311310                } else {
    312311                        checksum = compute_checksum(0, ip_header, length);
    313                         /*
    314                          * The udp header checksum will be added with the first
    315                          * fragment later.
    316                          */
     312                        // the udp header checksum will be added with the first
     313                        // fragment later
    317314                        free(ip_header);
    318315                }
     
    333330                                return udp_release_and_return(packet, rc);
    334331
    335                         /* Add partial checksum if set */
     332                        // add partial checksum if set
    336333                        if (header->checksum) {
    337334                                checksum = compute_checksum(checksum,
     
    340337                        }
    341338
    342                         /* Relese the rest of the packet fragments */
     339                        // relese the rest of the packet fragments
    343340                        tmp_packet = pq_next(next_packet);
    344341                        while (tmp_packet) {
     
    349346                        }
    350347
    351                         /* Exit the loop */
     348                        // exit the loop
    352349                        break;
    353350                }
    354351                total_length -= length;
    355352
    356                 /* Add partial checksum if set */
     353                // add partial checksum if set
    357354                if (header->checksum) {
    358355                        checksum = compute_checksum(checksum,
     
    363360        } while ((next_packet = pq_next(next_packet)) && (total_length > 0));
    364361
    365         /* Verify checksum */
     362        // check checksum
    366363        if (header->checksum) {
    367364                if (flip_checksum(compact_checksum(checksum)) !=
     
    369366                        if (tl_prepare_icmp_packet(udp_globals.net_phone,
    370367                            udp_globals.icmp_phone, packet, error) == EOK) {
    371                                 /* Checksum error ICMP */
     368                                // checksum error ICMP
    372369                                icmp_parameter_problem_msg(
    373370                                    udp_globals.icmp_phone, ICMP_PARAM_POINTER,
     
    379376        }
    380377
    381         /* Queue the received packet */
     378        // queue the received packet
    382379        rc = dyn_fifo_push(&socket->received, packet_get_id(packet),
    383380            SOCKET_MAX_RECEIVED_SIZE);
     
    390387                return udp_release_and_return(packet, rc);
    391388
    392         /* Notify the destination socket */
     389        // notify the destination socket
    393390        fibril_rwlock_write_unlock(&udp_globals.lock);
    394391        async_msg_5(socket->phone, NET_SOCKET_RECEIVED,
     
    413410 *                      udp_process_packet() function.
    414411 */
    415 static int udp_received_msg(device_id_t device_id, packet_t packet,
    416     services_t receiver, services_t error)
     412static int
     413udp_received_msg(device_id_t device_id, packet_t packet, services_t receiver,
     414    services_t error)
    417415{
    418416        int result;
     
    453451 *                      function.
    454452 */
    455 static int udp_sendto_message(socket_cores_ref local_sockets, int socket_id,
     453static int
     454udp_sendto_message(socket_cores_ref local_sockets, int socket_id,
    456455    const struct sockaddr *addr, socklen_t addrlen, int fragments,
    457456    size_t *data_fragment_size, int flags)
     
    481480
    482481        if ((socket->port <= 0) && udp_globals.autobinding) {
    483                 /* Bind the socket to a random free port if not bound */
     482                // bind the socket to a random free port if not bound
    484483                rc = socket_bind_free_port(&udp_globals.sockets, socket,
    485484                    UDP_FREE_PORTS_START, UDP_FREE_PORTS_END,
     
    487486                if (rc != EOK)
    488487                        return rc;
    489                 /* Set the next port as the search starting port number */
     488                // set the next port as the search starting port number
    490489                udp_globals.last_used_port = socket->port;
    491490        }
     
    496495                if (rc != EOK)
    497496                        return rc;
    498                 /* Get the device packet dimension */
     497                // get the device packet dimension
    499498//              rc = tl_get_ip_packet_dimension(udp_globals.ip_phone,
    500499//                  &udp_globals.dimensions, device_id, &packet_dimension);
     
    503502        }
    504503//      } else {
    505                 /* Do not ask all the time */
     504                // do not ask all the time
    506505                rc = ip_packet_size_req(udp_globals.ip_phone, -1,
    507506                    &udp_globals.packet_dimension);
     
    511510//      }
    512511
    513         /* Read the first packet fragment */
     512        // read the first packet fragment
    514513        result = tl_socket_read_packet_data(udp_globals.net_phone, &packet,
    515514            UDP_HEADER_SIZE, packet_dimension, addr, addrlen);
     
    524523                checksum = 0;
    525524
    526         /* Prefix the UDP header */
     525        // prefix the udp header
    527526        header = PACKET_PREFIX(packet, udp_header_t);
    528527        if (!header)
     
    530529
    531530        bzero(header, sizeof(*header));
    532 
    533         /* Read the rest of the packet fragments */
     531        // read the rest of the packet fragments
    534532        for (index = 1; index < fragments; index++) {
    535533                result = tl_socket_read_packet_data(udp_globals.net_phone,
     
    550548        }
    551549
    552         /* Set the UDP header */
     550        // set the udp header
    553551        header->source_port = htons((socket->port > 0) ? socket->port : 0);
    554552        header->destination_port = htons(dest_port);
    555553        header->total_length = htons(total_length + sizeof(*header));
    556554        header->checksum = 0;
    557 
    558555        if (udp_globals.checksum_computing) {
    559                 /* Update the pseudo header */
     556                // update the pseudo header
    560557                rc = ip_client_set_pseudo_header_data_length(ip_header,
    561558                    headerlen, total_length + UDP_HEADER_SIZE);
     
    565562                }
    566563
    567                 /* Finish the checksum computation */
     564                // finish the checksum computation
    568565                checksum = compute_checksum(checksum, ip_header, headerlen);
    569566                checksum = compute_checksum(checksum, (uint8_t *) header,
     
    576573        }
    577574
    578         /* Prepare the first packet fragment */
     575        // prepare the first packet fragment
    579576        rc = ip_client_prepare_packet(packet, IPPROTO_UDP, 0, 0, 0, 0);
    580577        if (rc != EOK)
     
    584581        fibril_rwlock_write_unlock(&udp_globals.lock);
    585582
    586         /* Send the packet */
     583        // send the packet
    587584        ip_send_msg(udp_globals.ip_phone, device_id, packet, SERVICE_UDP, 0);
    588585
     
    609606 *                      function.
    610607 */
    611 static int udp_recvfrom_message(socket_cores_ref local_sockets, int socket_id,
    612     int flags, size_t *addrlen)
     608static int
     609udp_recvfrom_message(socket_cores_ref local_sockets, int socket_id, int flags,
     610    size_t *addrlen)
    613611{
    614612        socket_core_ref socket;
     
    622620        int rc;
    623621
    624         /* Find the socket */
     622        // find the socket
    625623        socket = socket_cores_find(local_sockets, socket_id);
    626624        if (!socket)
    627625                return ENOTSOCK;
    628626
    629         /* Get the next received packet */
     627        // get the next received packet
    630628        packet_id = dyn_fifo_value(&socket->received);
    631629        if (packet_id < 0)
     
    638636        }
    639637
    640         /* Get UDP header */
     638        // get udp header
    641639        data = packet_get_data(packet);
    642640        if (!data) {
     
    646644        header = (udp_header_ref) data;
    647645
    648         /* Set the source address port */
     646        // set the source address port
    649647        result = packet_get_addr(packet, (uint8_t **) &addr, NULL);
    650648        rc = tl_set_address_port(addr, result, ntohs(header->source_port));
     
    655653        *addrlen = (size_t) result;
    656654
    657         /* Send the source address */
     655        // send the source address
    658656        rc = data_reply(addr, *addrlen);
    659657        switch (rc) {
     
    667665        }
    668666
    669         /* Trim the header */
     667        // trim the header
    670668        rc = packet_trim(packet, UDP_HEADER_SIZE, 0);
    671669        if (rc != EOK) {
     
    674672        }
    675673
    676         /* Reply the packets */
     674        // reply the packets
    677675        rc = socket_reply_packets(packet, &length);
    678676        switch (rc) {
     
    688686        (void) dyn_fifo_pop(&socket->received);
    689687
    690         /* Release the packet and return the total length */
     688        // release the packet and return the total length
    691689        return udp_release_and_return(packet, (int) length);
    692690}
     
    723721        answer_count = 0;
    724722
    725         /*
    726          * The client connection is only in one fibril and therefore no
    727          * additional locks are needed.
    728          */
     723        // The client connection is only in one fibril and therefore no
     724        // additional locks are needed.
    729725
    730726        socket_cores_initialize(&local_sockets);
     
    732728        while (keep_on_going) {
    733729
    734                 /* Answer the call */
     730                // answer the call
    735731                answer_call(callid, res, &answer, answer_count);
    736732
    737                 /* Refresh data */
     733                // refresh data
    738734                refresh_answer(&answer, &answer_count);
    739735
    740                 /* Get the next call */
     736                // get the next call
    741737                callid = async_get_call(&call);
    742738
    743                 /* Process the call */
     739                // process the call
    744740                switch (IPC_GET_METHOD(call)) {
    745741                case IPC_M_PHONE_HUNGUP:
     
    835831        }
    836832
    837         /* Release the application phone */
     833        // release the application phone
    838834        ipc_hangup(app_phone);
    839835
    840         /* Release all local sockets */
     836        // release all local sockets
    841837        socket_cores_release(udp_globals.net_phone, &local_sockets,
    842838            &udp_globals.sockets, NULL);
     
    858854 * @see IS_NET_UDP_MESSAGE()
    859855 */
    860 int udp_message_standalone(ipc_callid_t callid, ipc_call_t *call,
     856int
     857udp_message_standalone(ipc_callid_t callid, ipc_call_t *call,
    861858    ipc_call_t *answer, int *answer_count)
    862859{
Note: See TracChangeset for help on using the changeset viewer.