Changes in uspace/srv/net/tl/icmp/icmp.c [d8f95529:ba1a2fd] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/tl/icmp/icmp.c
rd8f95529 rba1a2fd 54 54 #include <byteorder.h> 55 55 #include <errno.h> 56 #include <err.h> 56 57 57 58 #include <net/socket_codes.h> … … 160 161 int dont_fragment) 161 162 { 162 int rc;163 ERROR_DECLARE; 163 164 164 165 // do not send an error if disabled … … 171 172 header->checksum = ICMP_CHECKSUM(header, 172 173 packet_get_data_length(packet)); 173 174 rc = ip_client_prepare_packet(packet, IPPROTO_ICMP, ttl, tos, 175 dont_fragment, 0); 176 if (rc != EOK) 177 return icmp_release_and_return(packet, rc); 174 if (ERROR_OCCURRED(ip_client_prepare_packet(packet, IPPROTO_ICMP, ttl, 175 tos, dont_fragment, 0))) { 176 return icmp_release_and_return(packet, ERROR_CODE); 177 } 178 178 179 179 return ip_send_msg(icmp_globals.ip_phone, -1, packet, SERVICE_ICMP, … … 249 249 const struct sockaddr * addr, socklen_t addrlen) 250 250 { 251 ERROR_DECLARE; 252 251 253 icmp_header_ref header; 252 254 packet_t packet; … … 255 257 icmp_reply_ref reply; 256 258 int reply_key; 259 int result; 257 260 int index; 258 int rc;259 261 260 262 if (addrlen <= 0) … … 263 265 length = (size_t) addrlen; 264 266 // TODO do not ask all the time 265 rc = ip_packet_size_req(icmp_globals.ip_phone, -1, 266 &icmp_globals.packet_dimension); 267 if (rc != EOK) 268 return rc; 267 ERROR_PROPAGATE(ip_packet_size_req(icmp_globals.ip_phone, -1, 268 &icmp_globals.packet_dimension)); 269 269 270 270 packet = packet_get_4_remote(icmp_globals.net_phone, size, … … 277 277 // prepare the requesting packet 278 278 // set the destination address 279 rc = packet_set_addr(packet, NULL, (const uint8_t *) addr, length); 280 if (rc != EOK) 281 return icmp_release_and_return(packet, rc); 279 if (ERROR_OCCURRED(packet_set_addr(packet, NULL, (const uint8_t *) addr, 280 length))) { 281 return icmp_release_and_return(packet, ERROR_CODE); 282 } 282 283 283 284 // allocate space in the packet … … 328 329 // wait for the reply 329 330 // timeout in microseconds 330 rc = fibril_condvar_wait_timeout(&reply->condvar, &reply->mutex, 331 timeout * 1000); 332 if (rc == EOK) 333 rc = reply->result; 331 if (ERROR_OCCURRED(fibril_condvar_wait_timeout(&reply->condvar, 332 &reply->mutex, timeout * 1000))) { 333 result = ERROR_CODE; 334 } else { 335 // read the result 336 result = reply->result; 337 } 334 338 335 339 // drop the reply mutex before locking the globals again … … 340 344 icmp_replies_exclude_index(&icmp_globals.replies, index); 341 345 342 return r c;346 return result; 343 347 } 344 348 … … 409 413 int icmp_initialize(async_client_conn_t client_connection) 410 414 { 415 ERROR_DECLARE; 416 411 417 measured_string_t names[] = { 412 418 { … … 422 428 size_t count = sizeof(names) / sizeof(measured_string_t); 423 429 char *data; 424 int rc;425 430 426 431 fibril_rwlock_initialize(&icmp_globals.lock); … … 428 433 icmp_replies_initialize(&icmp_globals.replies); 429 434 icmp_echo_data_initialize(&icmp_globals.echo_data); 430 431 435 icmp_globals.ip_phone = ip_bind_service(SERVICE_IP, IPPROTO_ICMP, 432 436 SERVICE_ICMP, client_connection); 433 if (icmp_globals.ip_phone < 0) { 434 fibril_rwlock_write_unlock(&icmp_globals.lock); 437 if (icmp_globals.ip_phone < 0) 435 438 return icmp_globals.ip_phone; 436 } 437 438 rc = ip_packet_size_req(icmp_globals.ip_phone, -1, 439 &icmp_globals.packet_dimension); 440 if (rc != EOK) { 441 fibril_rwlock_write_unlock(&icmp_globals.lock); 442 return rc; 443 } 444 439 440 ERROR_PROPAGATE(ip_packet_size_req(icmp_globals.ip_phone, -1, 441 &icmp_globals.packet_dimension)); 445 442 icmp_globals.packet_dimension.prefix += ICMP_HEADER_SIZE; 446 443 icmp_globals.packet_dimension.content -= ICMP_HEADER_SIZE; … … 451 448 // get configuration 452 449 configuration = &names[0]; 453 rc = net_get_conf_req(icmp_globals.net_phone, &configuration, count, 454 &data); 455 if (rc != EOK) { 456 fibril_rwlock_write_unlock(&icmp_globals.lock); 457 return rc; 458 } 459 450 ERROR_PROPAGATE(net_get_conf_req(icmp_globals.net_phone, &configuration, 451 count, &data)); 460 452 if (configuration) { 461 453 if (configuration[0].value) { … … 527 519 static int icmp_process_packet(packet_t packet, services_t error) 528 520 { 521 ERROR_DECLARE; 522 529 523 size_t length; 530 524 uint8_t *src; … … 535 529 icmp_type_t type; 536 530 icmp_code_t code; 537 int rc;538 531 539 532 switch (error) { … … 548 541 length = (size_t) result; 549 542 // remove the error header 550 rc = packet_trim(packet, length, 0); 551 if (rc != EOK) 552 return rc; 543 ERROR_PROPAGATE(packet_trim(packet, length, 0)); 553 544 break; 554 545 default: … … 558 549 // get rid of the ip header 559 550 length = ip_client_header_length(packet); 560 rc = packet_trim(packet, length, 0); 561 if (rc != EOK) 562 return rc; 551 ERROR_PROPAGATE(packet_trim(packet, length, 0)); 563 552 564 553 length = packet_get_data_length(packet); … … 593 582 switch (header->type) { 594 583 case ICMP_ECHOREPLY: 595 if (error) 584 if (error) 596 585 icmp_process_echo_reply(packet, header, type, code); 597 586 else … … 665 654 services_t receiver, services_t error) 666 655 { 667 int rc; 668 669 rc = icmp_process_packet(packet, error); 670 if (rc != EOK) 671 return icmp_release_and_return(packet, rc); 656 ERROR_DECLARE; 657 658 if (ERROR_OCCURRED(icmp_process_packet(packet, error))) 659 return icmp_release_and_return(packet, ERROR_CODE); 672 660 673 661 return EOK; … … 694 682 static int icmp_process_message(ipc_call_t *call) 695 683 { 684 ERROR_DECLARE; 685 696 686 packet_t packet; 697 int rc;698 687 699 688 switch (IPC_GET_METHOD(*call)) { 700 689 case NET_ICMP_DEST_UNREACH: 701 rc = packet_translate_remote(icmp_globals.net_phone, &packet,702 IPC_GET_PACKET(call));703 if (rc != EOK)704 return rc;705 return icmp_destination_unreachable_msg_local(0,706 ICMP_GET_CODE(call), ICMP_GET_MTU(call), packet);690 if (ERROR_NONE(packet_translate_remote(icmp_globals.net_phone, 691 &packet, IPC_GET_PACKET(call)))) { 692 ERROR_CODE = icmp_destination_unreachable_msg_local(0, 693 ICMP_GET_CODE(call), ICMP_GET_MTU(call), packet); 694 } 695 return ERROR_CODE; 707 696 case NET_ICMP_SOURCE_QUENCH: 708 rc = packet_translate_remote(icmp_globals.net_phone, &packet,709 IPC_GET_PACKET(call));710 if (rc != EOK)711 return rc;712 return icmp_source_quench_msg_local(0, packet);697 if (ERROR_NONE(packet_translate_remote(icmp_globals.net_phone, 698 &packet, IPC_GET_PACKET(call)))) { 699 ERROR_CODE = icmp_source_quench_msg_local(0, packet); 700 } 701 return ERROR_CODE; 713 702 case NET_ICMP_TIME_EXCEEDED: 714 rc = packet_translate_remote(icmp_globals.net_phone, &packet,715 IPC_GET_PACKET(call));716 if (rc != EOK)717 return rc;718 return icmp_time_exceeded_msg_local(0, ICMP_GET_CODE(call),719 packet);703 if (ERROR_NONE(packet_translate_remote(icmp_globals.net_phone, 704 &packet, IPC_GET_PACKET(call)))) { 705 ERROR_CODE = icmp_time_exceeded_msg_local(0, 706 ICMP_GET_CODE(call), packet); 707 } 708 return ERROR_CODE; 720 709 case NET_ICMP_PARAMETERPROB: 721 rc = packet_translate_remote(icmp_globals.net_phone, &packet, 722 IPC_GET_PACKET(call)); 723 if (rc != EOK) 724 return rc; 725 return icmp_parameter_problem_msg_local(0, ICMP_GET_CODE(call), 726 ICMP_GET_POINTER(call), packet); 710 if (ERROR_NONE(packet_translate_remote(icmp_globals.net_phone, 711 &packet, IPC_GET_PACKET(call)))) { 712 ERROR_CODE = icmp_parameter_problem_msg_local(0, 713 ICMP_GET_CODE(call), ICMP_GET_POINTER(call), 714 packet); 715 } 716 return ERROR_CODE; 727 717 default: 728 718 return ENOTSUP; … … 767 757 break; 768 758 } 769 } while 759 } while(icmp_echo_data_find(&icmp_globals.echo_data, index) != NULL); 770 760 771 761 echo_data->identifier = index; … … 789 779 static int icmp_process_client_messages(ipc_callid_t callid, ipc_call_t call) 790 780 { 781 ERROR_DECLARE; 782 791 783 bool keep_on_going = true; 792 784 ipc_call_t answer; … … 796 788 ipc_callid_t data_callid; 797 789 icmp_echo_ref echo_data; 798 int r c = EOK;790 int res; 799 791 800 792 /* … … 802 794 * - Answer the first NET_ICMP_INIT call. 803 795 */ 796 res = EOK; 804 797 answer_count = 0; 805 798 … … 810 803 // assign a new identifier 811 804 fibril_rwlock_write_lock(&icmp_globals.lock); 812 r c= icmp_bind_free_id(echo_data);805 res = icmp_bind_free_id(echo_data); 813 806 fibril_rwlock_write_unlock(&icmp_globals.lock); 814 if (r c< 0) {807 if (res < 0) { 815 808 free(echo_data); 816 return r c;809 return res; 817 810 } 818 811 819 812 while (keep_on_going) { 820 813 // answer the call 821 answer_call(callid, r c, &answer, answer_count);814 answer_call(callid, res, &answer, answer_count); 822 815 823 816 // refresh data … … 831 824 case IPC_M_PHONE_HUNGUP: 832 825 keep_on_going = false; 833 r c= EHANGUP;826 res = EHANGUP; 834 827 break; 835 828 836 829 case NET_ICMP_ECHO: 837 830 if (!async_data_write_receive(&data_callid, &length)) { 838 r c= EINVAL;831 res = EINVAL; 839 832 break; 840 833 } … … 842 835 addr = malloc(length); 843 836 if (!addr) { 844 r c= ENOMEM;837 res = ENOMEM; 845 838 break; 846 839 } 847 840 848 rc = async_data_write_finalize(data_callid, addr, 849 length); 850 if (rc != EOK) { 841 if (ERROR_OCCURRED(async_data_write_finalize( 842 data_callid, addr, length))) { 851 843 free(addr); 844 res = ERROR_CODE; 852 845 break; 853 846 } 854 847 855 848 fibril_rwlock_write_lock(&icmp_globals.lock); 856 r c= icmp_echo(echo_data->identifier,849 res = icmp_echo(echo_data->identifier, 857 850 echo_data->sequence_number, ICMP_GET_SIZE(call), 858 851 ICMP_GET_TIMEOUT(call), ICMP_GET_TTL(call), … … 871 864 872 865 default: 873 r c= icmp_process_message(&call);866 res = icmp_process_message(&call); 874 867 } 875 868 … … 881 874 fibril_rwlock_write_unlock(&icmp_globals.lock); 882 875 883 return r c;876 return res; 884 877 } 885 878 … … 901 894 ipc_call_t *answer, int *answer_count) 902 895 { 896 ERROR_DECLARE; 897 903 898 packet_t packet; 904 int rc;905 899 906 900 *answer_count = 0; 907 901 switch (IPC_GET_METHOD(*call)) { 908 902 case NET_TL_RECEIVED: 909 rc = packet_translate_remote(icmp_globals.net_phone, &packet, 910 IPC_GET_PACKET(call)); 911 if (rc != EOK) 912 return rc; 913 return icmp_received_msg_local(IPC_GET_DEVICE(call), packet, 914 SERVICE_ICMP, IPC_GET_ERROR(call)); 903 if (ERROR_NONE(packet_translate_remote(icmp_globals.net_phone, 904 &packet, IPC_GET_PACKET(call)))) { 905 ERROR_CODE = 906 icmp_received_msg_local(IPC_GET_DEVICE(call), 907 packet, SERVICE_ICMP, IPC_GET_ERROR(call)); 908 } 909 return ERROR_CODE; 915 910 916 911 case NET_ICMP_INIT: … … 975 970 int main(int argc, char *argv[]) 976 971 { 977 int rc;972 ERROR_DECLARE; 978 973 979 974 /* Start the module */ 980 rc = tl_module_start_standalone(tl_client_connection);981 return rc;975 ERROR_PROPAGATE(tl_module_start_standalone(tl_client_connection)); 976 return EOK; 982 977 } 983 978
Note:
See TracChangeset
for help on using the changeset viewer.