Changes in uspace/srv/net/tl/icmp/icmp.c [014dd57b:774e6d1a] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/tl/icmp/icmp.c
r014dd57b r774e6d1a 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. */ … … 391 392 return icmp_send_packet(ICMP_PARAMETERPROB, code, packet, header, 392 393 SERVICE_ICMP, 0, 0, 0); 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 (uint8_t *) "ICMP_ERROR_REPORTING", 408 20 409 }, 410 { 411 (uint8_t *) "ICMP_ECHO_REPLYING", 412 18 413 } 414 }; 415 measured_string_t *configuration; 416 size_t count = sizeof(names) / sizeof(measured_string_t); 417 uint8_t *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; 393 468 } 394 469 … … 592 667 return icmp_release_and_return(packet, rc); 593 668 594 return EOK;595 }596 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 669 return EOK; 701 670 } … … 924 893 * @see IS_NET_ICMP_MESSAGE() 925 894 */ 926 int tl_module_message(ipc_callid_t callid, ipc_call_t *call,895 int icmp_message_standalone(ipc_callid_t callid, ipc_call_t *call, 927 896 ipc_call_t *answer, size_t *answer_count) 928 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 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 size_t 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.