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


Ignore:
Timestamp:
2010-02-18T10:00:30Z (16 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
e326edc
Parents:
b8da2a3 (diff), 91478aa (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 from the networking branch.

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

Legend:

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

    rb8da2a3 rca2d142  
    115115#define ICMP_GET_REPLY_KEY( id, sequence )      ((( id ) << 16 ) | ( sequence & 0xFFFF ))
    116116
    117 /** Type definition of the ICMP reply timeout.
    118  *  @see icmp_reply_timeout
    119  */
    120 typedef struct icmp_reply_timeout       icmp_reply_timeout_t;
    121 
    122 /** Type definition of the ICMP reply timeout pointer.
    123  *  @see icmp_reply_timeout
    124  */
    125 typedef icmp_reply_timeout_t *  icmp_reply_timeout_ref;
    126 
    127 /** ICMP reply timeout data.
    128  *  Used as a timeouting fibril argument.
    129  *  @see icmp_timeout_for_reply()
    130  */
    131 struct icmp_reply_timeout{
    132         /** Reply data key.
    133          */
    134         int                     reply_key;
    135         /** Timeout in microseconds.
    136          */
    137         suseconds_t     timeout;
    138 };
    139 
    140117/** Processes the received ICMP packet.
    141118 *  Is used as an entry point from the underlying IP module.
     
    255232int     icmp_process_echo_reply( packet_t packet, icmp_header_ref header, icmp_type_t type, icmp_code_t code );
    256233
    257 /** Tries to set the pending reply result as timeouted.
    258  *  Sleeps the timeout period of time and then tries to obtain and set the pending reply result as timeouted and signals the reply result.
    259  *  If the reply data are still present, the reply timeouted and the parent fibril is awaken.
    260  *  The global lock is not released in this case to be reused by the parent fibril.
    261  *  Should run in a searate fibril.
    262  *  @param[in] data The icmp_reply_timeout structure.
    263  *  @returns EOK on success.
    264  *  @returns EINVAL if the data parameter is NULL.
    265  */
    266 int     icmp_timeout_for_reply( void * data );
    267 
    268234/** Assigns a new identifier for the connection.
    269235 *  Fills the echo data parameter with the assigned values.
     
    304270}
    305271
    306 int icmp_timeout_for_reply( void * data ){
    307         icmp_reply_ref                  reply;
    308         icmp_reply_timeout_ref  timeout = data;
    309 
    310         if( ! timeout ){
    311                 return EINVAL;
    312         }
    313         // sleep the given timeout
    314         async_usleep( timeout->timeout );
    315         // lock the globals
    316         fibril_rwlock_write_lock( & icmp_globals.lock );
    317         // find the pending reply
    318         reply = icmp_replies_find( & icmp_globals.replies, timeout->reply_key );
    319         if( reply ){
    320                 // set the timeout result
    321                 reply->result = ETIMEOUT;
    322                 // notify the main fibril
    323                 fibril_condvar_signal( & reply->condvar );
    324         }else{
    325                 // unlock only if no reply
    326                 fibril_rwlock_write_unlock( & icmp_globals.lock );
    327         }
    328         // release the timeout structure
    329         free( timeout );
    330         return EOK;
    331 }
    332 
    333272int icmp_echo( icmp_param_t id, icmp_param_t sequence, size_t size, mseconds_t timeout, ip_ttl_t ttl, ip_tos_t tos, int dont_fragment, const struct sockaddr * addr, socklen_t addrlen ){
    334273        ERROR_DECLARE;
     
    339278        uint8_t *               data;
    340279        icmp_reply_ref                  reply;
    341         icmp_reply_timeout_ref  reply_timeout;
     280        int                             reply_key;
    342281        int                             result;
    343282        int                             index;
    344         fid_t                   fibril;
    345283
    346284        if( addrlen <= 0 ){
     
    349287        length = ( size_t ) addrlen;
    350288        // TODO do not ask all the time
    351         ERROR_PROPAGATE( ip_packet_size_req( icmp_globals.ip_phone, -1, & icmp_globals.addr_len, & icmp_globals.prefix, & icmp_globals.content, & icmp_globals.suffix ));
    352         packet = packet_get_4( icmp_globals.net_phone, size, icmp_globals.addr_len, ICMP_HEADER_SIZE + icmp_globals.prefix, icmp_globals.suffix );
     289        ERROR_PROPAGATE( ip_packet_size_req( icmp_globals.ip_phone, -1, & icmp_globals.packet_dimension ));
     290        packet = packet_get_4( icmp_globals.net_phone, size, icmp_globals.packet_dimension.addr_len, ICMP_HEADER_SIZE + icmp_globals.packet_dimension.prefix, icmp_globals.packet_dimension.suffix );
    353291        if( ! packet ) return ENOMEM;
    354292
     
    379317        header->un.echo.sequence_number = sequence;
    380318
    381         // prepare the reply and the reply timeout structures
    382         reply_timeout = malloc( sizeof( * reply_timeout ));
    383         if( ! reply_timeout ){
    384                 return icmp_release_and_return( packet, ENOMEM );
    385         }
     319        // prepare the reply structure
    386320        reply = malloc( sizeof( * reply ));
    387321        if( ! reply ){
    388                 free( reply_timeout );
    389322                return icmp_release_and_return( packet, ENOMEM );
    390323        }
    391         // prepare the timeouting thread
    392         fibril = fibril_create( icmp_timeout_for_reply, reply_timeout );
    393         if( ! fibril ){
    394                 free( reply );
    395                 free( reply_timeout );
    396                 return icmp_release_and_return( packet, EPARTY );
    397         }
    398         reply_timeout->reply_key = ICMP_GET_REPLY_KEY( header->un.echo.identifier, header->un.echo.sequence_number );
    399         // timeout in microseconds
    400         reply_timeout->timeout = timeout * 1000;
    401324        fibril_mutex_initialize( & reply->mutex );
    402325        fibril_mutex_lock( & reply->mutex );
    403326        fibril_condvar_initialize( & reply->condvar );
    404         // start the timeouting fibril
    405         fibril_add_ready( fibril );
    406         index = icmp_replies_add( & icmp_globals.replies, reply_timeout->reply_key, reply );
     327        reply_key = ICMP_GET_REPLY_KEY( header->un.echo.identifier, header->un.echo.sequence_number );
     328        index = icmp_replies_add( & icmp_globals.replies, reply_key, reply );
    407329        if( index < 0 ){
    408330                free( reply );
     
    417339
    418340        // wait for a reply
    419         fibril_condvar_wait( & reply->condvar, & reply->mutex );
    420 
    421         // read the result
    422         result = reply->result;
     341        // timeout in microseconds
     342        if( ERROR_OCCURRED( fibril_condvar_wait_timeout( & reply->condvar, & reply->mutex, timeout * 1000 ))){
     343                result = ERROR_CODE;
     344
     345                // lock the globals again and clean up
     346                fibril_rwlock_write_lock( & icmp_globals.lock );
     347        }else{
     348                // read the result
     349                result = reply->result;
     350
     351                // release the reply structure
     352                fibril_mutex_unlock( & reply->mutex );
     353        }
    423354
    424355        // destroy the reply structure
    425         fibril_mutex_unlock( & reply->mutex );
    426356        icmp_replies_exclude_index( & icmp_globals.replies, index );
    427357        return result;
     
    547477                return icmp_globals.ip_phone;
    548478        }
    549         ERROR_PROPAGATE( ip_packet_size_req( icmp_globals.ip_phone, -1, & icmp_globals.addr_len, & icmp_globals.prefix, & icmp_globals.content, & icmp_globals.suffix ));
    550         icmp_globals.prefix += ICMP_HEADER_SIZE;
    551         icmp_globals.content -= ICMP_HEADER_SIZE;
     479        ERROR_PROPAGATE( ip_packet_size_req( icmp_globals.ip_phone, -1, & icmp_globals.packet_dimension ));
     480        icmp_globals.packet_dimension.prefix += ICMP_HEADER_SIZE;
     481        icmp_globals.packet_dimension.content -= ICMP_HEADER_SIZE;
    552482        // get configuration
    553483        icmp_globals.error_reporting = NET_DEFAULT_ICMP_ERROR_REPORTING;
  • uspace/srv/net/tl/icmp/icmp.h

    rb8da2a3 rca2d142  
    9494         */
    9595        int                             ip_phone;
    96         /** Reserved packet prefix length.
     96        /** Packet dimension.
    9797         */
    98         size_t                  prefix;
    99         /** Maximal packet content length.
    100          */
    101         size_t                  content;
    102         /** Reserved packet suffix length.
    103          */
    104         size_t                  suffix;
    105         /** Packet address length.
    106          */
    107         size_t                  addr_len;
     98        packet_dimension_t      packet_dimension;
    10899        /** Networking module phone.
    109100         */
  • uspace/srv/net/tl/tcp/tcp.c

    rb8da2a3 rca2d142  
    613613                next_packet = pq_detach( packet );
    614614                length = packet_get_data_length( packet );
    615                 tmp_packet = pq_add( socket_data->incoming, packet, new_sequence_number, length );
    616                 if( ! tmp_packet ){
     615                if( ERROR_OCCURRED( pq_add( & socket_data->incoming, packet, new_sequence_number, length ))){
    617616                        // remove the corrupted packets
    618617                        pq_release( tcp_globals.net_phone, packet_get_id( packet ));
    619618                        pq_release( tcp_globals.net_phone, packet_get_id( next_packet ));
    620619                }else{
    621                         socket_data->incoming = tmp_packet;
    622620                        while( next_packet ){
    623621                                new_sequence_number += length;
     
    939937        packet_t        next;
    940938        packet_t        acknowledged = NULL;
    941         packet_t        first;
    942939        uint32_t        old;
    943940
     
    981978                                        }
    982979                                        // add to acknowledged or release
    983                                         first = pq_add( acknowledged, packet, 0, 0 );
    984                                         if( first ){
    985                                                 acknowledged = first;
    986                                         }else{
     980                                        if( pq_add( & acknowledged, packet, 0, 0 ) != EOK ){
    987981                                                pq_release( tcp_globals.net_phone, packet_get_id( packet ));
    988982                                        }
     
    15081502int     tcp_queue_packet( socket_core_ref socket, tcp_socket_data_ref socket_data, packet_t packet, size_t data_length ){
    15091503        ERROR_DECLARE;
    1510         packet_t                first;
    15111504
    15121505        assert( socket );
     
    15161509        ERROR_PROPAGATE( tcp_queue_prepare_packet( socket, socket_data, packet, data_length ));
    15171510
    1518         first = pq_add( socket_data->outgoing, packet, socket_data->next_outgoing, data_length );
    1519         if( ! first ){
    1520                 return tcp_release_and_return( packet, EINVAL );
    1521         }
    1522         socket_data->outgoing = first;
     1511        if( ERROR_OCCURRED( pq_add( & socket_data->outgoing, packet, socket_data->next_outgoing, data_length ))){
     1512                return tcp_release_and_return( packet, ERROR_CODE );
     1513        }
    15231514        socket_data->next_outgoing += data_length;
    15241515        return EOK;
  • uspace/srv/net/tl/tl_common.c

    rb8da2a3 rca2d142  
    8989                * packet_dimension = malloc( sizeof( ** packet_dimension ));
    9090                if( ! * packet_dimension ) return ENOMEM;
    91                 if( ERROR_OCCURRED( ip_packet_size_req( ip_phone, device_id, & ( ** packet_dimension ).addr_len, & ( ** packet_dimension ).prefix, & ( ** packet_dimension ).content, & ( ** packet_dimension ).suffix ))){
     91                if( ERROR_OCCURRED( ip_packet_size_req( ip_phone, device_id, * packet_dimension ))){
    9292                        free( * packet_dimension );
    9393                        return ERROR_CODE;
  • uspace/srv/net/tl/tl_common.h

    rb8da2a3 rca2d142  
    4343#include "../include/inet.h"
    4444#include "../include/socket_codes.h"
    45 
    46 /** Type definition of the packet dimension.
    47  *  @see packet_dimension
    48  */
    49 typedef struct packet_dimension packet_dimension_t;
    50 
    51 /** Type definition of the packet dimension pointer.
    52  *  @see packet_dimension
    53  */
    54 typedef packet_dimension_t *    packet_dimension_ref;
    55 
    56 /** Packet dimension.
    57  */
    58 struct packet_dimension{
    59         /** Reserved packet prefix length.
    60          */
    61         size_t                  prefix;
    62         /** Maximal packet content length.
    63          */
    64         size_t                  content;
    65         /** Reserved packet suffix length.
    66          */
    67         size_t                  suffix;
    68         /** Maximal packet address length.
    69          */
    70         size_t                  addr_len;
    71 };
    7245
    7346/** Device packet dimensions.
  • uspace/srv/net/tl/udp/udp.c

    rb8da2a3 rca2d142  
    205205        }
    206206        // read default packet dimensions
    207         ERROR_PROPAGATE( ip_packet_size_req( udp_globals.ip_phone, -1, & udp_globals.packet_dimension.addr_len, & udp_globals.packet_dimension.prefix, & udp_globals.packet_dimension.content, & udp_globals.packet_dimension.suffix ));
     207        ERROR_PROPAGATE( ip_packet_size_req( udp_globals.ip_phone, -1, & udp_globals.packet_dimension ));
    208208        ERROR_PROPAGATE( socket_ports_initialize( & udp_globals.sockets ));
    209209        if( ERROR_OCCURRED( packet_dimensions_initialize( & udp_globals.dimensions ))){
     
    579579//      }else{
    580580                // do not ask all the time
    581                 ERROR_PROPAGATE( ip_packet_size_req( udp_globals.ip_phone, -1, & udp_globals.packet_dimension.addr_len, & udp_globals.packet_dimension.prefix, & udp_globals.packet_dimension.content, & udp_globals.packet_dimension.suffix ));
     581                ERROR_PROPAGATE( ip_packet_size_req( udp_globals.ip_phone, -1, & udp_globals.packet_dimension ));
    582582                packet_dimension = & udp_globals.packet_dimension;
    583583//      }
     
    604604                        return udp_release_and_return( packet, result );
    605605                }
    606                 packet = pq_add( packet, next_packet, index, 0 );
     606                if( ERROR_OCCURRED( pq_add( & packet, next_packet, index, 0 ))){
     607                        return udp_release_and_return( packet, ERROR_CODE );
     608                }
    607609                total_length += ( size_t ) result;
    608610                if( udp_globals.checksum_computing ){
Note: See TracChangeset for help on using the changeset viewer.