Changeset ede63e4 in mainline for uspace/srv/net/tl/udp/udp.c
- Timestamp:
- 2010-01-04T23:25:48Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- eac9722
- Parents:
- 1a0fb3f8
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/tl/udp/udp.c
r1a0fb3f8 rede63e4 97 97 * Is used as an entry point from the underlying IP module. 98 98 * 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. 100 100 * @param[in,out] packet The received packet queue. 101 101 * @param receiver The target service. Ignored parameter. … … 109 109 * Notifies the destination socket application. 110 110 * Releases the packet on error or sends an ICMP error notification.. 111 * @param[in] device_id The receiving device identifier. 111 112 * @param[in,out] packet The received packet queue. 112 113 * @param[in] error The packet error reporting service. Prefixes the received packet. … … 120 121 * @returns Other error codes as defined for the ip_client_process_packet() function. 121 122 */ 122 int udp_process_packet( packet_t packet, services_t error );123 int udp_process_packet( device_id_t device_id, packet_t packet, services_t error ); 123 124 124 125 /** Releases the packet and returns the result. … … 151 152 * @param[in] addrlen The address length. 152 153 * @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. 154 155 * @param[in] flags Various send flags. 155 156 * @returns EOK on success. … … 163 164 * @returns Other error codes as defined for the ip_send_msg() function. 164 165 */ 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 );166 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 ); 166 167 167 168 /** Receives data to the socket. … … 235 236 236 237 fibril_rwlock_write_lock( & udp_globals.lock ); 237 result = udp_process_packet( packet, error );238 result = udp_process_packet( device_id, packet, error ); 238 239 if( result != EOK ){ 239 240 fibril_rwlock_write_unlock( & udp_globals.lock ); … … 243 244 } 244 245 245 int udp_process_packet( packet_t packet, services_t error ){246 int udp_process_packet( device_id_t device_id, packet_t packet, services_t error ){ 246 247 ERROR_DECLARE; 247 248 … … 261 262 struct sockaddr * src; 262 263 struct sockaddr * dest; 264 packet_dimension_ref packet_dimension; 263 265 264 266 if( error ){ … … 292 294 return udp_release_and_return( packet, EINVAL ); 293 295 } 294 if( length < sizeof( udp_header_t )+ offset ){296 if( length < UDP_HEADER_SIZE + offset ){ 295 297 return udp_release_and_return( packet, NO_DATA ); 296 298 } … … 380 382 381 383 // 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 ))){ 383 386 return udp_release_and_return( packet, ERROR_CODE ); 384 387 } … … 386 389 // notify the destination socket 387 390 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 ); 388 393 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; 390 395 } 391 396 … … 418 423 ipc_call_t answer; 419 424 int answer_count; 425 packet_dimension_ref packet_dimension; 420 426 421 427 /* … … 444 450 case NET_SOCKET: 445 451 fibril_rwlock_write_lock( & lock ); 452 * SOCKET_SET_SOCKET_ID( answer ) = SOCKET_GET_SOCKET_ID( call ); 446 453 res = socket_create( & local_sockets, app_phone, NULL, SOCKET_SET_SOCKET_ID( answer )); 447 454 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 } 452 463 break; 453 464 case NET_SOCKET_BIND: … … 467 478 fibril_rwlock_read_lock( & lock ); 468 479 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 )); 470 481 if( res != EOK ){ 471 482 fibril_rwlock_write_unlock( & udp_globals.lock ); 483 }else{ 484 answer_count = 2; 472 485 } 473 486 fibril_rwlock_read_unlock( & lock ); … … 484 497 * SOCKET_SET_READ_DATA_LENGTH( answer ) = res; 485 498 * SOCKET_SET_ADDRESS_LENGTH( answer ) = addrlen; 486 answer_count = 2;499 answer_count = 3; 487 500 res = EOK; 488 501 } … … 513 526 } 514 527 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 ){528 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 ){ 516 529 ERROR_DECLARE; 517 530 … … 571 584 572 585 // 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 ); 574 587 if( result < 0 ) return result; 575 588 total_length = ( size_t ) result; … … 606 619 // return udp_release_and_return( packet, ERROR_CODE ); 607 620 // } 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))){ 609 622 free( ip_header ); 610 623 return udp_release_and_return( packet, ERROR_CODE ); … … 615 628 free( ip_header ); 616 629 }else{ 617 device_id = -1;630 device_id = DEVICE_INVALID_ID; 618 631 } 619 632 // prepare the first packet fragment … … 665 678 666 679 // trim the header 667 ERROR_PROPAGATE( packet_trim( packet, sizeof( udp_header_t ), 0 ));680 ERROR_PROPAGATE( packet_trim( packet, UDP_HEADER_SIZE, 0 )); 668 681 669 682 // reply the packets
Note:
See TracChangeset
for help on using the changeset viewer.