Rev 4722 | Rev 4730 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 4722 | Rev 4728 | ||
|---|---|---|---|
| Line 281... | Line 281... | ||
| 281 | // use the phone as the echo data index |
281 | // use the phone as the echo data index |
| 282 | echo_data = icmp_echo_data_find( & icmp_globals.echo_data, icmp_phone ); |
282 | echo_data = icmp_echo_data_find( & icmp_globals.echo_data, icmp_phone ); |
| 283 | if( ! echo_data ){ |
283 | if( ! echo_data ){ |
| 284 | res = ENOENT; |
284 | res = ENOENT; |
| 285 | }else{ |
285 | }else{ |
| 286 | res = icmp_echo( echo_data->id, echo_data->sequence, size, timeout, ttl, tos, dont_fragment, addr, addrlen ); |
286 | res = icmp_echo( echo_data->identifier, echo_data->sequence_number, size, timeout, ttl, tos, dont_fragment, addr, addrlen ); |
| 287 | if( echo_data->sequence < MAX_UINT16 ){ |
287 | if( echo_data->sequence_number < MAX_UINT16 ){ |
| 288 | ++ echo_data->sequence; |
288 | ++ echo_data->sequence_number; |
| 289 | }else{ |
289 | }else{ |
| 290 | echo_data->sequence = 0; |
290 | echo_data->sequence_number = 0; |
| 291 | } |
291 | } |
| 292 | } |
292 | } |
| 293 | fibril_rwlock_write_unlock( & icmp_globals.lock ); |
293 | fibril_rwlock_write_unlock( & icmp_globals.lock ); |
| 294 | return res; |
294 | return res; |
| 295 | } |
295 | } |
| Line 364... | Line 364... | ||
| 364 | header = PACKET_PREFIX( packet, icmp_header_t ); |
364 | header = PACKET_PREFIX( packet, icmp_header_t ); |
| 365 | if( ! header ){ |
365 | if( ! header ){ |
| 366 | return icmp_release_and_return( packet, ENOMEM ); |
366 | return icmp_release_and_return( packet, ENOMEM ); |
| 367 | } |
367 | } |
| 368 | bzero( header, sizeof( * header )); |
368 | bzero( header, sizeof( * header )); |
| 369 | header->un.echo.id = id; |
369 | header->un.echo.identifier = id; |
| 370 | header->un.echo.sequence = sequence; |
370 | header->un.echo.sequence_number = sequence; |
| 371 | 371 | ||
| 372 | // prepare the reply and the reply timeout structures |
372 | // prepare the reply and the reply timeout structures |
| 373 | reply_timeout = malloc( sizeof( * reply_timeout )); |
373 | reply_timeout = malloc( sizeof( * reply_timeout )); |
| 374 | if( ! reply_timeout ){ |
374 | if( ! reply_timeout ){ |
| 375 | return icmp_release_and_return( packet, ENOMEM ); |
375 | return icmp_release_and_return( packet, ENOMEM ); |
| Line 377... | Line 377... | ||
| 377 | reply = malloc( sizeof( * reply )); |
377 | reply = malloc( sizeof( * reply )); |
| 378 | if( ! reply ){ |
378 | if( ! reply ){ |
| 379 | free( reply_timeout ); |
379 | free( reply_timeout ); |
| 380 | return icmp_release_and_return( packet, ENOMEM ); |
380 | return icmp_release_and_return( packet, ENOMEM ); |
| 381 | } |
381 | } |
| 382 | reply_timeout->reply_key = ICMP_GET_REPLY_KEY( header->un.echo.id, header->un.echo.sequence ); |
382 | reply_timeout->reply_key = ICMP_GET_REPLY_KEY( header->un.echo.identifier, header->un.echo.sequence_number ); |
| 383 | // timeout in microseconds |
383 | // timeout in microseconds |
| 384 | reply_timeout->timeout = timeout * 1000; |
384 | reply_timeout->timeout = timeout * 1000; |
| 385 | fibril_mutex_initialize( & reply->mutex ); |
385 | fibril_mutex_initialize( & reply->mutex ); |
| 386 | fibril_mutex_lock( & reply->mutex ); |
386 | fibril_mutex_lock( & reply->mutex ); |
| 387 | fibril_condvar_initialize( & reply->condvar ); |
387 | fibril_condvar_initialize( & reply->condvar ); |
| Line 509... | Line 509... | ||
| 509 | if( index < 0 ){ |
509 | if( index < 0 ){ |
| 510 | free( echo_data ); |
510 | free( echo_data ); |
| 511 | fibril_rwlock_write_unlock( & icmp_globals.lock ); |
511 | fibril_rwlock_write_unlock( & icmp_globals.lock ); |
| 512 | return index; |
512 | return index; |
| 513 | }else{ |
513 | }else{ |
| 514 | id = echo_data->id; |
514 | id = echo_data->identifier; |
| 515 | fibril_rwlock_write_unlock( & icmp_globals.lock ); |
515 | fibril_rwlock_write_unlock( & icmp_globals.lock ); |
| 516 | // return the echo data identifier as the ICMP phone |
516 | // return the echo data identifier as the ICMP phone |
| 517 | return id; |
517 | return id; |
| 518 | } |
518 | } |
| 519 | } |
519 | } |
| Line 666... | Line 666... | ||
| 666 | int icmp_process_echo_reply( packet_t packet, icmp_header_ref header, icmp_type_t type, icmp_code_t code ){ |
666 | int icmp_process_echo_reply( packet_t packet, icmp_header_ref header, icmp_type_t type, icmp_code_t code ){ |
| 667 | int reply_key; |
667 | int reply_key; |
| 668 | icmp_reply_ref reply; |
668 | icmp_reply_ref reply; |
| 669 | 669 | ||
| 670 | // compute the reply key |
670 | // compute the reply key |
| 671 | reply_key = ICMP_GET_REPLY_KEY( header->un.echo.id, header->un.echo.sequence ); |
671 | reply_key = ICMP_GET_REPLY_KEY( header->un.echo.identifier, header->un.echo.sequence_number ); |
| 672 | pq_release( icmp_globals.net_phone, packet_get_id( packet )); |
672 | pq_release( icmp_globals.net_phone, packet_get_id( packet )); |
| 673 | // lock the globals |
673 | // lock the globals |
| 674 | fibril_rwlock_write_lock( & icmp_globals.lock ); |
674 | fibril_rwlock_write_lock( & icmp_globals.lock ); |
| 675 | // find the pending reply |
675 | // find the pending reply |
| 676 | reply = icmp_replies_find( & icmp_globals.replies, reply_key ); |
676 | reply = icmp_replies_find( & icmp_globals.replies, reply_key ); |
| Line 708... | Line 708... | ||
| 708 | 708 | ||
| 709 | int icmp_process_client_messages( ipc_callid_t callid, ipc_call_t call ){ |
709 | int icmp_process_client_messages( ipc_callid_t callid, ipc_call_t call ){ |
| 710 | ERROR_DECLARE; |
710 | ERROR_DECLARE; |
| 711 | 711 | ||
| 712 | bool keep_on_going = true; |
712 | bool keep_on_going = true; |
| 713 | fibril_rwlock_t lock; |
713 | // fibril_rwlock_t lock; |
| 714 | ipc_call_t answer; |
714 | ipc_call_t answer; |
| 715 | int answer_count; |
715 | int answer_count; |
| 716 | size_t length; |
716 | size_t length; |
| 717 | struct sockaddr * addr; |
717 | struct sockaddr * addr; |
| 718 | ipc_callid_t data_callid; |
718 | ipc_callid_t data_callid; |
| Line 722... | Line 722... | ||
| 722 | * Accept the connection |
722 | * Accept the connection |
| 723 | * - Answer the first NET_ICMP_INIT call. |
723 | * - Answer the first NET_ICMP_INIT call. |
| 724 | */ |
724 | */ |
| 725 | ipc_answer_0( callid, EOK ); |
725 | ipc_answer_0( callid, EOK ); |
| 726 | 726 | ||
| 727 | fibril_rwlock_initialize( & lock ); |
727 | // fibril_rwlock_initialize( & lock ); |
| 728 | 728 | ||
| 729 | echo_data = ( icmp_echo_ref ) malloc( sizeof( * echo_data )); |
729 | echo_data = ( icmp_echo_ref ) malloc( sizeof( * echo_data )); |
| 730 | if( ! echo_data ) return ENOMEM; |
730 | if( ! echo_data ) return ENOMEM; |
| 731 | // assign a new identifier |
731 | // assign a new identifier |
| 732 | fibril_rwlock_write_lock( & icmp_globals.lock ); |
732 | fibril_rwlock_write_lock( & icmp_globals.lock ); |
| Line 746... | Line 746... | ||
| 746 | case IPC_M_PHONE_HUNGUP: |
746 | case IPC_M_PHONE_HUNGUP: |
| 747 | keep_on_going = false; |
747 | keep_on_going = false; |
| 748 | ERROR_CODE = EOK; |
748 | ERROR_CODE = EOK; |
| 749 | break; |
749 | break; |
| 750 | case NET_ICMP_ECHO: |
750 | case NET_ICMP_ECHO: |
| 751 | fibril_rwlock_write_lock( & lock ); |
751 | // fibril_rwlock_write_lock( & lock ); |
| 752 | if( ! ipc_data_write_receive( & data_callid, & length )){ |
752 | if( ! ipc_data_write_receive( & data_callid, & length )){ |
| 753 | ERROR_CODE = EINVAL; |
753 | ERROR_CODE = EINVAL; |
| 754 | }else{ |
754 | }else{ |
| 755 | addr = malloc( length ); |
755 | addr = malloc( length ); |
| 756 | if( ! addr ){ |
756 | if( ! addr ){ |
| 757 | ERROR_CODE = ENOMEM; |
757 | ERROR_CODE = ENOMEM; |
| 758 | }else{ |
758 | }else{ |
| 759 | if( ! ERROR_OCCURRED( ipc_data_write_finalize( data_callid, addr, length ))){ |
759 | if( ! ERROR_OCCURRED( ipc_data_write_finalize( data_callid, addr, length ))){ |
| 760 | fibril_rwlock_write_lock( & icmp_globals.lock ); |
760 | fibril_rwlock_write_lock( & icmp_globals.lock ); |
| 761 | ERROR_CODE = icmp_echo( echo_data->id, echo_data->sequence, ICMP_GET_SIZE( call ), ICMP_GET_TIMEOUT( call ), ICMP_GET_TTL( call ), ICMP_GET_TOS( call ), ICMP_GET_DONT_FRAGMENT( call ), addr, ( socklen_t ) length ); |
761 | ERROR_CODE = icmp_echo( echo_data->identifier, echo_data->sequence_number, ICMP_GET_SIZE( call ), ICMP_GET_TIMEOUT( call ), ICMP_GET_TTL( call ), ICMP_GET_TOS( call ), ICMP_GET_DONT_FRAGMENT( call ), addr, ( socklen_t ) length ); |
| 762 | fibril_rwlock_write_unlock( & icmp_globals.lock ); |
762 | fibril_rwlock_write_unlock( & icmp_globals.lock ); |
| 763 | free( addr ); |
763 | free( addr ); |
| 764 | if( echo_data->sequence < MAX_UINT16 ){ |
764 | if( echo_data->sequence_number < MAX_UINT16 ){ |
| 765 | ++ echo_data->sequence; |
765 | ++ echo_data->sequence_number; |
| 766 | }else{ |
766 | }else{ |
| 767 | echo_data->sequence = 0; |
767 | echo_data->sequence_number = 0; |
| 768 | } |
768 | } |
| 769 | } |
769 | } |
| 770 | } |
770 | } |
| 771 | } |
771 | } |
| 772 | fibril_rwlock_write_unlock( & lock ); |
772 | // fibril_rwlock_write_unlock( & lock ); |
| 773 | break; |
773 | break; |
| 774 | default: |
774 | default: |
| 775 | ERROR_CODE = icmp_process_message( & call ); |
775 | ERROR_CODE = icmp_process_message( & call ); |
| 776 | } |
776 | } |
| 777 | 777 | ||
| 778 | answer_call( callid, ERROR_CODE, & answer, answer_count ); |
778 | answer_call( callid, ERROR_CODE, & answer, answer_count ); |
| 779 | } |
779 | } |
| 780 | 780 | ||
| 781 | // release the identifier |
781 | // release the identifier |
| 782 | fibril_rwlock_write_lock( & icmp_globals.lock ); |
782 | fibril_rwlock_write_lock( & icmp_globals.lock ); |
| 783 | icmp_echo_data_exclude( & icmp_globals.echo_data, echo_data->id ); |
783 | icmp_echo_data_exclude( & icmp_globals.echo_data, echo_data->identifier ); |
| 784 | fibril_rwlock_write_unlock( & icmp_globals.lock ); |
784 | fibril_rwlock_write_unlock( & icmp_globals.lock ); |
| 785 | return EOK; |
785 | return EOK; |
| 786 | } |
786 | } |
| 787 | 787 | ||
| 788 | int icmp_process_message( ipc_call_t * call ){ |
788 | int icmp_process_message( ipc_call_t * call ){ |
| Line 843... | Line 843... | ||
| 843 | }while( icmp_echo_data_find( & icmp_globals.echo_data, index ) != NULL ); |
843 | }while( icmp_echo_data_find( & icmp_globals.echo_data, index ) != NULL ); |
| 844 | // found, break immediately |
844 | // found, break immediately |
| 845 | break; |
845 | break; |
| 846 | } |
846 | } |
| 847 | }while( icmp_echo_data_find( & icmp_globals.echo_data, index ) != NULL ); |
847 | }while( icmp_echo_data_find( & icmp_globals.echo_data, index ) != NULL ); |
| 848 | echo_data->id = index; |
848 | echo_data->identifier = index; |
| 849 | echo_data->sequence = 0; |
849 | echo_data->sequence_number = 0; |
| 850 | return icmp_echo_data_add( & icmp_globals.echo_data, index, echo_data ); |
850 | return icmp_echo_data_add( & icmp_globals.echo_data, index, echo_data ); |
| 851 | } |
851 | } |
| 852 | 852 | ||
| 853 | /** @} |
853 | /** @} |
| 854 | */ |
854 | */ |