Changeset ca2d142 in mainline for uspace/srv/net/tl
- Timestamp:
- 2010-02-18T10:00:30Z (16 years ago)
- 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. - Location:
- uspace/srv/net/tl
- Files:
-
- 6 edited
-
icmp/icmp.c (modified) (8 diffs)
-
icmp/icmp.h (modified) (1 diff)
-
tcp/tcp.c (modified) (5 diffs)
-
tl_common.c (modified) (1 diff)
-
tl_common.h (modified) (1 diff)
-
udp/udp.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/tl/icmp/icmp.c
rb8da2a3 rca2d142 115 115 #define ICMP_GET_REPLY_KEY( id, sequence ) ((( id ) << 16 ) | ( sequence & 0xFFFF )) 116 116 117 /** Type definition of the ICMP reply timeout.118 * @see icmp_reply_timeout119 */120 typedef struct icmp_reply_timeout icmp_reply_timeout_t;121 122 /** Type definition of the ICMP reply timeout pointer.123 * @see icmp_reply_timeout124 */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 140 117 /** Processes the received ICMP packet. 141 118 * Is used as an entry point from the underlying IP module. … … 255 232 int icmp_process_echo_reply( packet_t packet, icmp_header_ref header, icmp_type_t type, icmp_code_t code ); 256 233 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 268 234 /** Assigns a new identifier for the connection. 269 235 * Fills the echo data parameter with the assigned values. … … 304 270 } 305 271 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 timeout314 async_usleep( timeout->timeout );315 // lock the globals316 fibril_rwlock_write_lock( & icmp_globals.lock );317 // find the pending reply318 reply = icmp_replies_find( & icmp_globals.replies, timeout->reply_key );319 if( reply ){320 // set the timeout result321 reply->result = ETIMEOUT;322 // notify the main fibril323 fibril_condvar_signal( & reply->condvar );324 }else{325 // unlock only if no reply326 fibril_rwlock_write_unlock( & icmp_globals.lock );327 }328 // release the timeout structure329 free( timeout );330 return EOK;331 }332 333 272 int 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 ){ 334 273 ERROR_DECLARE; … … 339 278 uint8_t * data; 340 279 icmp_reply_ref reply; 341 i cmp_reply_timeout_ref reply_timeout;280 int reply_key; 342 281 int result; 343 282 int index; 344 fid_t fibril;345 283 346 284 if( addrlen <= 0 ){ … … 349 287 length = ( size_t ) addrlen; 350 288 // 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 ); 353 291 if( ! packet ) return ENOMEM; 354 292 … … 379 317 header->un.echo.sequence_number = sequence; 380 318 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 386 320 reply = malloc( sizeof( * reply )); 387 321 if( ! reply ){ 388 free( reply_timeout );389 322 return icmp_release_and_return( packet, ENOMEM ); 390 323 } 391 // prepare the timeouting thread392 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 microseconds400 reply_timeout->timeout = timeout * 1000;401 324 fibril_mutex_initialize( & reply->mutex ); 402 325 fibril_mutex_lock( & reply->mutex ); 403 326 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 ); 407 329 if( index < 0 ){ 408 330 free( reply ); … … 417 339 418 340 // 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 } 423 354 424 355 // destroy the reply structure 425 fibril_mutex_unlock( & reply->mutex );426 356 icmp_replies_exclude_index( & icmp_globals.replies, index ); 427 357 return result; … … 547 477 return icmp_globals.ip_phone; 548 478 } 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.p refix += 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; 552 482 // get configuration 553 483 icmp_globals.error_reporting = NET_DEFAULT_ICMP_ERROR_REPORTING; -
uspace/srv/net/tl/icmp/icmp.h
rb8da2a3 rca2d142 94 94 */ 95 95 int ip_phone; 96 /** Reserved packet prefix length.96 /** Packet dimension. 97 97 */ 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; 108 99 /** Networking module phone. 109 100 */ -
uspace/srv/net/tl/tcp/tcp.c
rb8da2a3 rca2d142 613 613 next_packet = pq_detach( packet ); 614 614 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 ))){ 617 616 // remove the corrupted packets 618 617 pq_release( tcp_globals.net_phone, packet_get_id( packet )); 619 618 pq_release( tcp_globals.net_phone, packet_get_id( next_packet )); 620 619 }else{ 621 socket_data->incoming = tmp_packet;622 620 while( next_packet ){ 623 621 new_sequence_number += length; … … 939 937 packet_t next; 940 938 packet_t acknowledged = NULL; 941 packet_t first;942 939 uint32_t old; 943 940 … … 981 978 } 982 979 // 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 ){ 987 981 pq_release( tcp_globals.net_phone, packet_get_id( packet )); 988 982 } … … 1508 1502 int tcp_queue_packet( socket_core_ref socket, tcp_socket_data_ref socket_data, packet_t packet, size_t data_length ){ 1509 1503 ERROR_DECLARE; 1510 packet_t first;1511 1504 1512 1505 assert( socket ); … … 1516 1509 ERROR_PROPAGATE( tcp_queue_prepare_packet( socket, socket_data, packet, data_length )); 1517 1510 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 } 1523 1514 socket_data->next_outgoing += data_length; 1524 1515 return EOK; -
uspace/srv/net/tl/tl_common.c
rb8da2a3 rca2d142 89 89 * packet_dimension = malloc( sizeof( ** packet_dimension )); 90 90 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 ))){ 92 92 free( * packet_dimension ); 93 93 return ERROR_CODE; -
uspace/srv/net/tl/tl_common.h
rb8da2a3 rca2d142 43 43 #include "../include/inet.h" 44 44 #include "../include/socket_codes.h" 45 46 /** Type definition of the packet dimension.47 * @see packet_dimension48 */49 typedef struct packet_dimension packet_dimension_t;50 51 /** Type definition of the packet dimension pointer.52 * @see packet_dimension53 */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 };72 45 73 46 /** Device packet dimensions. -
uspace/srv/net/tl/udp/udp.c
rb8da2a3 rca2d142 205 205 } 206 206 // 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 )); 208 208 ERROR_PROPAGATE( socket_ports_initialize( & udp_globals.sockets )); 209 209 if( ERROR_OCCURRED( packet_dimensions_initialize( & udp_globals.dimensions ))){ … … 579 579 // }else{ 580 580 // 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 )); 582 582 packet_dimension = & udp_globals.packet_dimension; 583 583 // } … … 604 604 return udp_release_and_return( packet, result ); 605 605 } 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 } 607 609 total_length += ( size_t ) result; 608 610 if( udp_globals.checksum_computing ){
Note:
See TracChangeset
for help on using the changeset viewer.
