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


Ignore:
Timestamp:
2010-01-04T23:25:48Z (14 years ago)
Author:
Lukas Mejdrech <lukasmejdrech@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
eac9722
Parents:
1a0fb3f8
Message:
  • socket identifier generation moved to libsocket, + data fragment size fix and enhancement, + [ICMP|TCP|UDP]_HEADER_SIZE definition, + int_map_update() function to alter item key
File:
1 edited

Legend:

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

    r1a0fb3f8 rede63e4  
    9797 *  Is used as an entry point from the underlying IP module.
    9898 *  Locks the global lock and calls udp_process_packet() function.
    99  *  @param device_id The device identifier. Ignored parameter.
     99 *  @param[in] device_id The receiving device identifier.
    100100 *  @param[in,out] packet The received packet queue.
    101101 *  @param receiver The target service. Ignored parameter.
     
    109109 *  Notifies the destination socket application.
    110110 *  Releases the packet on error or sends an ICMP error notification..
     111 *  @param[in] device_id The receiving device identifier.
    111112 *  @param[in,out] packet The received packet queue.
    112113 *  @param[in] error The packet error reporting service. Prefixes the received packet.
     
    120121 *  @returns Other error codes as defined for the ip_client_process_packet() function.
    121122 */
    122 int udp_process_packet( packet_t packet, services_t error );
     123int udp_process_packet( device_id_t device_id, packet_t packet, services_t error );
    123124
    124125/** Releases the packet and returns the result.
     
    151152 *  @param[in] addrlen The address length.
    152153 *  @param[in] fragments The number of data fragments.
    153  *  @param[in] data_fragment_size The data fragment size in bytes.
     154 *  @param[out] data_fragment_size The data fragment size in bytes.
    154155 *  @param[in] flags Various send flags.
    155156 *  @returns EOK on success.
     
    163164 *  @returns Other error codes as defined for the ip_send_msg() function.
    164165 */
    165 int udp_sendto_message( socket_cores_ref local_sockets, int socket_id, const struct sockaddr * addr, socklen_t addrlen, int fragments, size_t data_fragment_size, int flags );
     166int udp_sendto_message( socket_cores_ref local_sockets, int socket_id, const struct sockaddr * addr, socklen_t addrlen, int fragments, size_t * data_fragment_size, int flags );
    166167
    167168/** Receives data to the socket.
     
    235236
    236237        fibril_rwlock_write_lock( & udp_globals.lock );
    237         result = udp_process_packet( packet, error );
     238        result = udp_process_packet( device_id, packet, error );
    238239        if( result != EOK ){
    239240                fibril_rwlock_write_unlock( & udp_globals.lock );
     
    243244}
    244245
    245 int udp_process_packet( packet_t packet, services_t error ){
     246int udp_process_packet( device_id_t device_id, packet_t packet, services_t error ){
    246247        ERROR_DECLARE;
    247248
     
    261262        struct sockaddr *               src;
    262263        struct sockaddr *               dest;
     264        packet_dimension_ref    packet_dimension;
    263265
    264266        if( error ){
     
    292294                return udp_release_and_return( packet, EINVAL );
    293295        }
    294         if( length < sizeof( udp_header_t ) + offset ){
     296        if( length < UDP_HEADER_SIZE + offset ){
    295297                return udp_release_and_return( packet, NO_DATA );
    296298        }
     
    380382
    381383        // queue the received packet
    382         if( ERROR_OCCURRED( dyn_fifo_push( & socket->received, packet_get_id( packet ), SOCKET_MAX_RECEIVED_SIZE ))){
     384        if( ERROR_OCCURRED( dyn_fifo_push( & socket->received, packet_get_id( packet ), SOCKET_MAX_RECEIVED_SIZE ))
     385        || ERROR_OCCURRED( tl_get_ip_packet_dimension( udp_globals.ip_phone, & udp_globals.dimensions, device_id, & packet_dimension ))){
    383386                return udp_release_and_return( packet, ERROR_CODE );
    384387        }
     
    386389        // notify the destination socket
    387390        fibril_rwlock_write_unlock( & udp_globals.lock );
     391        async_msg_5( socket->phone, NET_SOCKET_RECEIVED, ( ipcarg_t ) socket->socket_id, packet_dimension->content, 0, 0, ( ipcarg_t ) fragments );
     392/*      fibril_rwlock_write_unlock( & udp_globals.lock );
    388393        async_msg_5( socket->phone, NET_SOCKET_RECEIVED, ( ipcarg_t ) socket->socket_id, 0, 0, 0, ( ipcarg_t ) fragments );
    389         return EOK;
     394*/      return EOK;
    390395}
    391396
     
    418423        ipc_call_t                              answer;
    419424        int                                             answer_count;
     425        packet_dimension_ref    packet_dimension;
    420426
    421427        /*
     
    444450                        case NET_SOCKET:
    445451                                fibril_rwlock_write_lock( & lock );
     452                                * SOCKET_SET_SOCKET_ID( answer ) = SOCKET_GET_SOCKET_ID( call );
    446453                                res = socket_create( & local_sockets, app_phone, NULL, SOCKET_SET_SOCKET_ID( answer ));
    447454                                fibril_rwlock_write_unlock( & lock );
    448                                 // TODO max fragment size
    449                                 * SOCKET_SET_DATA_FRAGMENT_SIZE( answer ) = MAX_UDP_FRAGMENT_SIZE;
    450                                 * SOCKET_SET_HEADER_SIZE( answer ) = sizeof( udp_header_t );
    451                                 answer_count = 3;
     455                                if( res == EOK ){
     456                                        if( tl_get_ip_packet_dimension( udp_globals.ip_phone, & udp_globals.dimensions, DEVICE_INVALID_ID, & packet_dimension ) == EOK ){
     457                                                * SOCKET_SET_DATA_FRAGMENT_SIZE( answer ) = packet_dimension->content;
     458                                        }
     459//                                      * SOCKET_SET_DATA_FRAGMENT_SIZE( answer ) = MAX_UDP_FRAGMENT_SIZE;
     460                                        * SOCKET_SET_HEADER_SIZE( answer ) = UDP_HEADER_SIZE;
     461                                        answer_count = 3;
     462                                }
    452463                                break;
    453464                        case NET_SOCKET_BIND:
     
    467478                                        fibril_rwlock_read_lock( & lock );
    468479                                        fibril_rwlock_write_lock( & udp_globals.lock );
    469                                         res = udp_sendto_message( & local_sockets, SOCKET_GET_SOCKET_ID( call ), addr, addrlen, SOCKET_GET_DATA_FRAGMENTS( call ), SOCKET_GET_DATA_FRAGMENT_SIZE( call ), SOCKET_GET_FLAGS( call ));
     480                                        res = udp_sendto_message( & local_sockets, SOCKET_GET_SOCKET_ID( call ), addr, addrlen, SOCKET_GET_DATA_FRAGMENTS( call ), SOCKET_SET_DATA_FRAGMENT_SIZE( answer ), SOCKET_GET_FLAGS( call ));
    470481                                        if( res != EOK ){
    471482                                                fibril_rwlock_write_unlock( & udp_globals.lock );
     483                                        }else{
     484                                                answer_count = 2;
    472485                                        }
    473486                                        fibril_rwlock_read_unlock( & lock );
     
    484497                                        * SOCKET_SET_READ_DATA_LENGTH( answer ) = res;
    485498                                        * SOCKET_SET_ADDRESS_LENGTH( answer ) = addrlen;
    486                                         answer_count = 2;
     499                                        answer_count = 3;
    487500                                        res = EOK;
    488501                                }
     
    513526}
    514527
    515 int udp_sendto_message( socket_cores_ref local_sockets, int socket_id, const struct sockaddr * addr, socklen_t addrlen, int fragments, size_t data_fragment_size, int flags ){
     528int udp_sendto_message( socket_cores_ref local_sockets, int socket_id, const struct sockaddr * addr, socklen_t addrlen, int fragments, size_t * data_fragment_size, int flags ){
    516529        ERROR_DECLARE;
    517530
     
    571584
    572585        // read the first packet fragment
    573         result = tl_socket_read_packet_data( udp_globals.net_phone, & packet, sizeof( udp_header_t ), packet_dimension, addr, addrlen );
     586        result = tl_socket_read_packet_data( udp_globals.net_phone, & packet, UDP_HEADER_SIZE, packet_dimension, addr, addrlen );
    574587        if( result < 0 ) return result;
    575588        total_length = ( size_t ) result;
     
    606619//                      return udp_release_and_return( packet, ERROR_CODE );
    607620//              }
    608                 if( ERROR_OCCURRED( ip_client_set_pseudo_header_data_length( ip_header, headerlen, total_length + sizeof( udp_header_t )))){
     621                if( ERROR_OCCURRED( ip_client_set_pseudo_header_data_length( ip_header, headerlen, total_length + UDP_HEADER_SIZE))){
    609622                        free( ip_header );
    610623                        return udp_release_and_return( packet, ERROR_CODE );
     
    615628                free( ip_header );
    616629        }else{
    617                 device_id = -1;
     630                device_id = DEVICE_INVALID_ID;
    618631        }
    619632        // prepare the first packet fragment
     
    665678
    666679        // trim the header
    667         ERROR_PROPAGATE( packet_trim( packet, sizeof( udp_header_t ), 0 ));
     680        ERROR_PROPAGATE( packet_trim( packet, UDP_HEADER_SIZE, 0 ));
    668681
    669682        // reply the packets
Note: See TracChangeset for help on using the changeset viewer.