Changes in uspace/srv/net/tl/icmp/icmp.c [014dd57b:228e490] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/tl/icmp/icmp.c
r014dd57b r228e490 35 35 * @see icmp.h 36 36 */ 37 38 #include "icmp.h" 39 #include "icmp_module.h" 37 40 38 41 #include <async.h> … … 65 68 #include <icmp_client.h> 66 69 #include <icmp_interface.h> 67 #include <il_ remote.h>70 #include <il_interface.h> 68 71 #include <ip_client.h> 69 72 #include <ip_interface.h> 70 73 #include <net_interface.h> 71 #include <tl_ remote.h>72 #include <tl_ skel.h>74 #include <tl_interface.h> 75 #include <tl_local.h> 73 76 #include <icmp_header.h> 74 77 75 #include "icmp.h"76 77 78 /** ICMP module name. */ 78 #define NAME "icmp"79 #define NAME "ICMP protocol" 79 80 80 81 /** Default ICMP error reporting. */ … … 393 394 } 394 395 396 /** Initializes the ICMP module. 397 * 398 * @param[in] client_connection The client connection processing function. The 399 * module skeleton propagates its own one. 400 * @return EOK on success. 401 * @return ENOMEM if there is not enough memory left. 402 */ 403 int icmp_initialize(async_client_conn_t client_connection) 404 { 405 measured_string_t names[] = { 406 { 407 (char *) "ICMP_ERROR_REPORTING", 408 20 409 }, 410 { 411 (char *) "ICMP_ECHO_REPLYING", 412 18 413 } 414 }; 415 measured_string_t *configuration; 416 size_t count = sizeof(names) / sizeof(measured_string_t); 417 char *data; 418 int rc; 419 420 fibril_rwlock_initialize(&icmp_globals.lock); 421 fibril_rwlock_write_lock(&icmp_globals.lock); 422 icmp_replies_initialize(&icmp_globals.replies); 423 icmp_echo_data_initialize(&icmp_globals.echo_data); 424 425 icmp_globals.ip_phone = ip_bind_service(SERVICE_IP, IPPROTO_ICMP, 426 SERVICE_ICMP, client_connection); 427 if (icmp_globals.ip_phone < 0) { 428 fibril_rwlock_write_unlock(&icmp_globals.lock); 429 return icmp_globals.ip_phone; 430 } 431 432 rc = ip_packet_size_req(icmp_globals.ip_phone, -1, 433 &icmp_globals.packet_dimension); 434 if (rc != EOK) { 435 fibril_rwlock_write_unlock(&icmp_globals.lock); 436 return rc; 437 } 438 439 icmp_globals.packet_dimension.prefix += ICMP_HEADER_SIZE; 440 icmp_globals.packet_dimension.content -= ICMP_HEADER_SIZE; 441 442 icmp_globals.error_reporting = NET_DEFAULT_ICMP_ERROR_REPORTING; 443 icmp_globals.echo_replying = NET_DEFAULT_ICMP_ECHO_REPLYING; 444 445 /* Get configuration */ 446 configuration = &names[0]; 447 rc = net_get_conf_req(icmp_globals.net_phone, &configuration, count, 448 &data); 449 if (rc != EOK) { 450 fibril_rwlock_write_unlock(&icmp_globals.lock); 451 return rc; 452 } 453 454 if (configuration) { 455 if (configuration[0].value) { 456 icmp_globals.error_reporting = 457 (configuration[0].value[0] == 'y'); 458 } 459 if (configuration[1].value) { 460 icmp_globals.echo_replying = 461 (configuration[1].value[0] == 'y'); 462 } 463 net_free_settings(configuration, data); 464 } 465 466 fibril_rwlock_write_unlock(&icmp_globals.lock); 467 return EOK; 468 } 469 395 470 /** Tries to set the pending reply result as the received message type. 396 471 * … … 454 529 icmp_code_t code; 455 530 int rc; 456 531 457 532 switch (error) { 458 533 case SERVICE_NONE: … … 595 670 } 596 671 597 /** Process IPC messages from the IP module598 *599 * @param[in] iid Message identifier.600 * @param[in,out] icall Message parameters.601 *602 */603 static void icmp_receiver(ipc_callid_t iid, ipc_call_t *icall)604 {605 packet_t *packet;606 int rc;607 608 while (true) {609 switch (IPC_GET_IMETHOD(*icall)) {610 case NET_TL_RECEIVED:611 rc = packet_translate_remote(icmp_globals.net_phone, &packet,612 IPC_GET_PACKET(*icall));613 if (rc == EOK)614 rc = icmp_received_msg_local(IPC_GET_DEVICE(*icall), packet,615 SERVICE_ICMP, IPC_GET_ERROR(*icall));616 617 ipc_answer_0(iid, (sysarg_t) rc);618 break;619 default:620 ipc_answer_0(iid, (sysarg_t) ENOTSUP);621 }622 623 iid = async_get_call(icall);624 }625 }626 627 /** Initialize the ICMP module.628 *629 * @param[in] net_phone Network module phone.630 *631 * @return EOK on success.632 * @return ENOMEM if there is not enough memory left.633 *634 */635 int tl_initialize(int net_phone)636 {637 measured_string_t names[] = {638 {639 (uint8_t *) "ICMP_ERROR_REPORTING",640 20641 },642 {643 (uint8_t *) "ICMP_ECHO_REPLYING",644 18645 }646 };647 measured_string_t *configuration;648 size_t count = sizeof(names) / sizeof(measured_string_t);649 uint8_t *data;650 651 fibril_rwlock_initialize(&icmp_globals.lock);652 fibril_rwlock_write_lock(&icmp_globals.lock);653 icmp_replies_initialize(&icmp_globals.replies);654 icmp_echo_data_initialize(&icmp_globals.echo_data);655 656 icmp_globals.net_phone = net_phone;657 658 icmp_globals.ip_phone = ip_bind_service(SERVICE_IP, IPPROTO_ICMP,659 SERVICE_ICMP, icmp_receiver);660 if (icmp_globals.ip_phone < 0) {661 fibril_rwlock_write_unlock(&icmp_globals.lock);662 return icmp_globals.ip_phone;663 }664 665 int rc = ip_packet_size_req(icmp_globals.ip_phone, -1,666 &icmp_globals.packet_dimension);667 if (rc != EOK) {668 fibril_rwlock_write_unlock(&icmp_globals.lock);669 return rc;670 }671 672 icmp_globals.packet_dimension.prefix += ICMP_HEADER_SIZE;673 icmp_globals.packet_dimension.content -= ICMP_HEADER_SIZE;674 675 icmp_globals.error_reporting = NET_DEFAULT_ICMP_ERROR_REPORTING;676 icmp_globals.echo_replying = NET_DEFAULT_ICMP_ECHO_REPLYING;677 678 /* Get configuration */679 configuration = &names[0];680 rc = net_get_conf_req(icmp_globals.net_phone, &configuration, count,681 &data);682 if (rc != EOK) {683 fibril_rwlock_write_unlock(&icmp_globals.lock);684 return rc;685 }686 687 if (configuration) {688 if (configuration[0].value) {689 icmp_globals.error_reporting =690 (configuration[0].value[0] == 'y');691 }692 if (configuration[1].value) {693 icmp_globals.echo_replying =694 (configuration[1].value[0] == 'y');695 }696 net_free_settings(configuration, data);697 }698 699 fibril_rwlock_write_unlock(&icmp_globals.lock);700 return EOK;701 }702 703 672 /** Processes the generic client messages. 704 673 * … … 727 696 case NET_ICMP_DEST_UNREACH: 728 697 rc = packet_translate_remote(icmp_globals.net_phone, &packet, 729 IPC_GET_PACKET( *call));698 IPC_GET_PACKET(call)); 730 699 if (rc != EOK) 731 700 return rc; 732 701 return icmp_destination_unreachable_msg_local(0, 733 ICMP_GET_CODE( *call), ICMP_GET_MTU(*call), packet);702 ICMP_GET_CODE(call), ICMP_GET_MTU(call), packet); 734 703 case NET_ICMP_SOURCE_QUENCH: 735 704 rc = packet_translate_remote(icmp_globals.net_phone, &packet, 736 IPC_GET_PACKET( *call));705 IPC_GET_PACKET(call)); 737 706 if (rc != EOK) 738 707 return rc; … … 740 709 case NET_ICMP_TIME_EXCEEDED: 741 710 rc = packet_translate_remote(icmp_globals.net_phone, &packet, 742 IPC_GET_PACKET( *call));711 IPC_GET_PACKET(call)); 743 712 if (rc != EOK) 744 713 return rc; 745 return icmp_time_exceeded_msg_local(0, ICMP_GET_CODE( *call),714 return icmp_time_exceeded_msg_local(0, ICMP_GET_CODE(call), 746 715 packet); 747 716 case NET_ICMP_PARAMETERPROB: 748 717 rc = packet_translate_remote(icmp_globals.net_phone, &packet, 749 IPC_GET_PACKET( *call));718 IPC_GET_PACKET(call)); 750 719 if (rc != EOK) 751 720 return rc; 752 return icmp_parameter_problem_msg_local(0, ICMP_GET_CODE( *call),753 ICMP_GET_POINTER( *call), packet);721 return icmp_parameter_problem_msg_local(0, ICMP_GET_CODE(call), 722 ICMP_GET_POINTER(call), packet); 754 723 default: 755 724 return ENOTSUP; … … 818 787 bool keep_on_going = true; 819 788 ipc_call_t answer; 820 size_t answer_count;789 int answer_count; 821 790 size_t length; 822 791 struct sockaddr *addr; … … 924 893 * @see IS_NET_ICMP_MESSAGE() 925 894 */ 926 int tl_module_message (ipc_callid_t callid, ipc_call_t *call, 927 ipc_call_t *answer, size_t *answer_count) 928 { 895 int icmp_message_standalone(ipc_callid_t callid, ipc_call_t *call, 896 ipc_call_t *answer, int *answer_count) 897 { 898 packet_t *packet; 899 int rc; 900 929 901 *answer_count = 0; 930 902 switch (IPC_GET_IMETHOD(*call)) { 903 case NET_TL_RECEIVED: 904 rc = packet_translate_remote(icmp_globals.net_phone, &packet, 905 IPC_GET_PACKET(call)); 906 if (rc != EOK) 907 return rc; 908 return icmp_received_msg_local(IPC_GET_DEVICE(call), packet, 909 SERVICE_ICMP, IPC_GET_ERROR(call)); 910 931 911 case NET_ICMP_INIT: 932 return icmp_process_client_messages(callid, *call); 912 return icmp_process_client_messages(callid, * call); 913 933 914 default: 934 915 return icmp_process_message(call); 935 916 } 917 918 return ENOTSUP; 919 } 920 921 922 /** Default thread for new connections. 923 * 924 * @param[in] iid The initial message identifier. 925 * @param[in] icall The initial message call structure. 926 * 927 */ 928 static void tl_client_connection(ipc_callid_t iid, ipc_call_t *icall) 929 { 930 /* 931 * Accept the connection 932 * - Answer the first IPC_M_CONNECT_ME_TO call. 933 */ 934 ipc_answer_0(iid, EOK); 936 935 937 return ENOTSUP; 938 } 939 936 while (true) { 937 ipc_call_t answer; 938 int answer_count; 939 940 /* Clear the answer structure */ 941 refresh_answer(&answer, &answer_count); 942 943 /* Fetch the next message */ 944 ipc_call_t call; 945 ipc_callid_t callid = async_get_call(&call); 946 947 /* Process the message */ 948 int res = tl_module_message_standalone(callid, &call, &answer, 949 &answer_count); 950 951 /* 952 * End if told to either by the message or the processing 953 * result. 954 */ 955 if ((IPC_GET_IMETHOD(call) == IPC_M_PHONE_HUNGUP) || 956 (res == EHANGUP)) 957 return; 958 959 /* Answer the message */ 960 answer_call(callid, res, &answer, answer_count); 961 } 962 } 963 964 /** Starts the module. 965 * 966 * @return EOK on success. 967 * @return Other error codes as defined for each specific module 968 * start function. 969 */ 940 970 int main(int argc, char *argv[]) 941 971 { 972 int rc; 973 942 974 /* Start the module */ 943 return tl_module_start(SERVICE_ICMP); 975 rc = tl_module_start_standalone(tl_client_connection); 976 return rc; 944 977 } 945 978 946 979 /** @} 947 980 */ 981
Note:
See TracChangeset
for help on using the changeset viewer.