Changeset d8f95529 in mainline
- Timestamp:
- 2010-11-04T17:21:36Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 46ae62c
- Parents:
- 08e3ca4
- Location:
- uspace/srv/net/tl/icmp
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/tl/icmp/icmp.c
r08e3ca4 rd8f95529 54 54 #include <byteorder.h> 55 55 #include <errno.h> 56 #include <err.h>57 56 58 57 #include <net/socket_codes.h> … … 161 160 int dont_fragment) 162 161 { 163 ERROR_DECLARE;162 int rc; 164 163 165 164 // do not send an error if disabled … … 172 171 header->checksum = ICMP_CHECKSUM(header, 173 172 packet_get_data_length(packet)); 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 } 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); 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 253 251 icmp_header_ref header; 254 252 packet_t packet; … … 257 255 icmp_reply_ref reply; 258 256 int reply_key; 259 int result;260 257 int index; 258 int rc; 261 259 262 260 if (addrlen <= 0) … … 265 263 length = (size_t) addrlen; 266 264 // TODO do not ask all the time 267 ERROR_PROPAGATE(ip_packet_size_req(icmp_globals.ip_phone, -1, 268 &icmp_globals.packet_dimension)); 265 rc = ip_packet_size_req(icmp_globals.ip_phone, -1, 266 &icmp_globals.packet_dimension); 267 if (rc != EOK) 268 return rc; 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 if (ERROR_OCCURRED(packet_set_addr(packet, NULL, (const uint8_t *) addr, 280 length))) { 281 return icmp_release_and_return(packet, ERROR_CODE); 282 } 279 rc = packet_set_addr(packet, NULL, (const uint8_t *) addr, length); 280 if (rc != EOK) 281 return icmp_release_and_return(packet, rc); 283 282 284 283 // allocate space in the packet … … 329 328 // wait for the reply 330 329 // timeout in microseconds 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 } 330 rc = fibril_condvar_wait_timeout(&reply->condvar, &reply->mutex, 331 timeout * 1000); 332 if (rc == EOK) 333 rc = reply->result; 338 334 339 335 // drop the reply mutex before locking the globals again … … 344 340 icmp_replies_exclude_index(&icmp_globals.replies, index); 345 341 346 return r esult;342 return rc; 347 343 } 348 344 … … 413 409 int icmp_initialize(async_client_conn_t client_connection) 414 410 { 415 ERROR_DECLARE;416 417 411 measured_string_t names[] = { 418 412 { … … 428 422 size_t count = sizeof(names) / sizeof(measured_string_t); 429 423 char *data; 424 int rc; 430 425 431 426 fibril_rwlock_initialize(&icmp_globals.lock); … … 433 428 icmp_replies_initialize(&icmp_globals.replies); 434 429 icmp_echo_data_initialize(&icmp_globals.echo_data); 430 435 431 icmp_globals.ip_phone = ip_bind_service(SERVICE_IP, IPPROTO_ICMP, 436 432 SERVICE_ICMP, client_connection); 437 if (icmp_globals.ip_phone < 0) 433 if (icmp_globals.ip_phone < 0) { 434 fibril_rwlock_write_unlock(&icmp_globals.lock); 438 435 return icmp_globals.ip_phone; 439 440 ERROR_PROPAGATE(ip_packet_size_req(icmp_globals.ip_phone, -1, 441 &icmp_globals.packet_dimension)); 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 442 445 icmp_globals.packet_dimension.prefix += ICMP_HEADER_SIZE; 443 446 icmp_globals.packet_dimension.content -= ICMP_HEADER_SIZE; … … 448 451 // get configuration 449 452 configuration = &names[0]; 450 ERROR_PROPAGATE(net_get_conf_req(icmp_globals.net_phone, &configuration, 451 count, &data)); 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 452 460 if (configuration) { 453 461 if (configuration[0].value) { … … 519 527 static int icmp_process_packet(packet_t packet, services_t error) 520 528 { 521 ERROR_DECLARE;522 523 529 size_t length; 524 530 uint8_t *src; … … 529 535 icmp_type_t type; 530 536 icmp_code_t code; 537 int rc; 531 538 532 539 switch (error) { … … 541 548 length = (size_t) result; 542 549 // remove the error header 543 ERROR_PROPAGATE(packet_trim(packet, length, 0)); 550 rc = packet_trim(packet, length, 0); 551 if (rc != EOK) 552 return rc; 544 553 break; 545 554 default: … … 549 558 // get rid of the ip header 550 559 length = ip_client_header_length(packet); 551 ERROR_PROPAGATE(packet_trim(packet, length, 0)); 560 rc = packet_trim(packet, length, 0); 561 if (rc != EOK) 562 return rc; 552 563 553 564 length = packet_get_data_length(packet); … … 582 593 switch (header->type) { 583 594 case ICMP_ECHOREPLY: 584 if (error) 595 if (error) 585 596 icmp_process_echo_reply(packet, header, type, code); 586 597 else … … 654 665 services_t receiver, services_t error) 655 666 { 656 ERROR_DECLARE; 657 658 if (ERROR_OCCURRED(icmp_process_packet(packet, error))) 659 return icmp_release_and_return(packet, ERROR_CODE); 667 int rc; 668 669 rc = icmp_process_packet(packet, error); 670 if (rc != EOK) 671 return icmp_release_and_return(packet, rc); 660 672 661 673 return EOK; … … 682 694 static int icmp_process_message(ipc_call_t *call) 683 695 { 684 ERROR_DECLARE;685 686 696 packet_t packet; 697 int rc; 687 698 688 699 switch (IPC_GET_METHOD(*call)) { 689 700 case NET_ICMP_DEST_UNREACH: 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;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); 696 707 case NET_ICMP_SOURCE_QUENCH: 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;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); 702 713 case NET_ICMP_TIME_EXCEEDED: 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;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); 709 720 case NET_ICMP_PARAMETERPROB: 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; 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); 717 727 default: 718 728 return ENOTSUP; … … 757 767 break; 758 768 } 759 } while (icmp_echo_data_find(&icmp_globals.echo_data, index) != NULL);769 } while (icmp_echo_data_find(&icmp_globals.echo_data, index) != NULL); 760 770 761 771 echo_data->identifier = index; … … 779 789 static int icmp_process_client_messages(ipc_callid_t callid, ipc_call_t call) 780 790 { 781 ERROR_DECLARE;782 783 791 bool keep_on_going = true; 784 792 ipc_call_t answer; … … 788 796 ipc_callid_t data_callid; 789 797 icmp_echo_ref echo_data; 790 int r es;798 int rc = EOK; 791 799 792 800 /* … … 794 802 * - Answer the first NET_ICMP_INIT call. 795 803 */ 796 res = EOK;797 804 answer_count = 0; 798 805 … … 803 810 // assign a new identifier 804 811 fibril_rwlock_write_lock(&icmp_globals.lock); 805 r es= icmp_bind_free_id(echo_data);812 rc = icmp_bind_free_id(echo_data); 806 813 fibril_rwlock_write_unlock(&icmp_globals.lock); 807 if (r es< 0) {814 if (rc < 0) { 808 815 free(echo_data); 809 return r es;816 return rc; 810 817 } 811 818 812 819 while (keep_on_going) { 813 820 // answer the call 814 answer_call(callid, r es, &answer, answer_count);821 answer_call(callid, rc, &answer, answer_count); 815 822 816 823 // refresh data … … 824 831 case IPC_M_PHONE_HUNGUP: 825 832 keep_on_going = false; 826 r es= EHANGUP;833 rc = EHANGUP; 827 834 break; 828 835 829 836 case NET_ICMP_ECHO: 830 837 if (!async_data_write_receive(&data_callid, &length)) { 831 r es= EINVAL;838 rc = EINVAL; 832 839 break; 833 840 } … … 835 842 addr = malloc(length); 836 843 if (!addr) { 837 r es= ENOMEM;844 rc = ENOMEM; 838 845 break; 839 846 } 840 847 841 if (ERROR_OCCURRED(async_data_write_finalize( 842 data_callid, addr, length))) { 848 rc = async_data_write_finalize(data_callid, addr, 849 length); 850 if (rc != EOK) { 843 851 free(addr); 844 res = ERROR_CODE;845 852 break; 846 853 } 847 854 848 855 fibril_rwlock_write_lock(&icmp_globals.lock); 849 r es= icmp_echo(echo_data->identifier,856 rc = icmp_echo(echo_data->identifier, 850 857 echo_data->sequence_number, ICMP_GET_SIZE(call), 851 858 ICMP_GET_TIMEOUT(call), ICMP_GET_TTL(call), … … 864 871 865 872 default: 866 r es= icmp_process_message(&call);873 rc = icmp_process_message(&call); 867 874 } 868 875 … … 874 881 fibril_rwlock_write_unlock(&icmp_globals.lock); 875 882 876 return r es;883 return rc; 877 884 } 878 885 … … 894 901 ipc_call_t *answer, int *answer_count) 895 902 { 896 ERROR_DECLARE;897 898 903 packet_t packet; 904 int rc; 899 905 900 906 *answer_count = 0; 901 907 switch (IPC_GET_METHOD(*call)) { 902 908 case NET_TL_RECEIVED: 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; 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)); 910 915 911 916 case NET_ICMP_INIT: … … 970 975 int main(int argc, char *argv[]) 971 976 { 972 ERROR_DECLARE;977 int rc; 973 978 974 979 /* Start the module */ 975 ERROR_PROPAGATE(tl_module_start_standalone(tl_client_connection));976 return EOK;980 rc = tl_module_start_standalone(tl_client_connection); 981 return rc; 977 982 } 978 983 -
uspace/srv/net/tl/icmp/icmp_module.c
r08e3ca4 rd8f95529 43 43 #include <async.h> 44 44 #include <stdio.h> 45 #include <err .h>45 #include <errno.h> 46 46 #include <ipc/ipc.h> 47 47 #include <ipc/services.h> … … 58 58 int tl_module_start_standalone(async_client_conn_t client_connection) 59 59 { 60 ERROR_DECLARE;61 62 60 ipcarg_t phonehash; 61 int rc; 63 62 64 63 async_set_client_connection(client_connection); … … 67 66 return icmp_globals.net_phone; 68 67 69 ERROR_PROPAGATE(pm_init()); 70 if (ERROR_OCCURRED(icmp_initialize(client_connection)) || 71 ERROR_OCCURRED(REGISTER_ME(SERVICE_ICMP, &phonehash))) { 72 pm_destroy(); 73 return ERROR_CODE; 74 } 68 rc = pm_init(); 69 if (rc != EOK) 70 return rc; 71 72 rc = icmp_initialize(client_connection); 73 if (rc != EOK) 74 goto out; 75 76 rc = REGISTER_ME(SERVICE_ICMP, &phonehash); 77 if (rc != EOK) 78 goto out; 75 79 76 80 async_manager(); 77 81 82 out: 78 83 pm_destroy(); 79 return EOK;84 return rc; 80 85 } 81 86 … … 89 94 /** @} 90 95 */ 91
Note:
See TracChangeset
for help on using the changeset viewer.