Changeset 8426912a in mainline for uspace/srv/net/tl/icmp/icmp.c


Ignore:
Timestamp:
2011-01-14T12:35:19Z (13 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
d450964
Parents:
6610565b (diff), 08abd81 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/net/tl/icmp/icmp.c

    r6610565b r8426912a  
    3535 * @see icmp.h
    3636 */
    37 
    38 #include "icmp.h"
    39 #include "icmp_module.h"
    4037
    4138#include <async.h>
     
    6865#include <icmp_client.h>
    6966#include <icmp_interface.h>
    70 #include <il_interface.h>
     67#include <il_remote.h>
    7168#include <ip_client.h>
    7269#include <ip_interface.h>
    7370#include <net_interface.h>
    74 #include <tl_interface.h>
    75 #include <tl_local.h>
     71#include <tl_remote.h>
     72#include <tl_skel.h>
    7673#include <icmp_header.h>
    7774
     75#include "icmp.h"
     76
    7877/** ICMP module name. */
    79 #define NAME    "ICMP protocol"
     78#define NAME  "icmp"
    8079
    8180/** Default ICMP error reporting. */
     
    394393}
    395394
    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;
    468 }
    469 
    470395/** Tries to set the pending reply result as the received message type.
    471396 *
     
    667592                return icmp_release_and_return(packet, rc);
    668593
     594        return EOK;
     595}
     596
     597/** Process IPC messages from the IP module
     598 *
     599 * @param[in]     iid   Message identifier.
     600 * @param[in,out] icall Message parameters.
     601 *
     602 */
     603static 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 */
     635int tl_initialize(int net_phone)
     636{
     637        measured_string_t names[] = {
     638                {
     639                        (uint8_t *) "ICMP_ERROR_REPORTING",
     640                        20
     641                },
     642                {
     643                        (uint8_t *) "ICMP_ECHO_REPLYING",
     644                        18
     645                }
     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);
    669700        return EOK;
    670701}
     
    893924 * @see IS_NET_ICMP_MESSAGE()
    894925 */
    895 int icmp_message_standalone(ipc_callid_t callid, ipc_call_t *call,
     926int tl_module_message   (ipc_callid_t callid, ipc_call_t *call,
    896927    ipc_call_t *answer, size_t *answer_count)
    897928{
    898         packet_t *packet;
    899         int rc;
    900 
    901929        *answer_count = 0;
    902930        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        
    911931        case NET_ICMP_INIT:
    912932                return icmp_process_client_messages(callid, *call);
    913        
    914933        default:
    915934                return icmp_process_message(call);
    916935        }
    917 
     936       
    918937        return ENOTSUP;
    919938}
    920939
    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);
    935        
    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  */
    970940int main(int argc, char *argv[])
    971941{
    972         int rc;
    973        
    974942        /* Start the module */
    975         rc = tl_module_start_standalone(tl_client_connection);
    976         return rc;
     943        return tl_module_start(SERVICE_ICMP);
    977944}
    978945
    979946/** @}
    980947 */
    981 
Note: See TracChangeset for help on using the changeset viewer.