Ignore:
File:
1 edited

Legend:

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

    r19f857a r14f1db0  
    4242#include <stdint.h>
    4343#include <str.h>
    44 
    4544#include <ipc/ipc.h>
    4645#include <ipc/services.h>
    47 
    4846#include <sys/time.h>
    4947#include <sys/types.h>
    5048
    51 #include "../../err.h"
    52 #include "../../messages.h"
    53 #include "../../modules.h"
    54 
    55 #include "../../structures/packet/packet_client.h"
    56 
    57 #include "../../include/byteorder.h"
    58 #include "../../include/checksum.h"
    59 #include "../../include/icmp_api.h"
    60 #include "../../include/icmp_client.h"
    61 #include "../../include/icmp_codes.h"
    62 #include "../../include/icmp_common.h"
    63 #include "../../include/icmp_interface.h"
    64 #include "../../include/il_interface.h"
    65 #include "../../include/inet.h"
    66 #include "../../include/ip_client.h"
    67 #include "../../include/ip_interface.h"
    68 #include "../../include/ip_protocols.h"
    69 #include "../../include/net_interface.h"
    70 #include "../../include/socket_codes.h"
    71 #include "../../include/socket_errno.h"
    72 
    73 #include "../../tl/tl_messages.h"
     49#include <net_err.h>
     50#include <net_messages.h>
     51#include <net_modules.h>
     52#include <packet/packet_client.h>
     53#include <packet_remote.h>
     54#include <net_byteorder.h>
     55#include <net_checksum.h>
     56#include <icmp_api.h>
     57#include <icmp_client.h>
     58#include <icmp_codes.h>
     59#include <icmp_common.h>
     60#include <icmp_interface.h>
     61#include <il_interface.h>
     62#include <inet.h>
     63#include <ip_client.h>
     64#include <ip_interface.h>
     65#include <ip_protocols.h>
     66#include <net_interface.h>
     67#include <socket_codes.h>
     68#include <socket_errno.h>
     69#include <tl_messages.h>
     70#include <tl_interface.h>
     71#include <tl_local.h>
     72#include <icmp_messages.h>
     73#include <icmp_header.h>
    7474
    7575#include "icmp.h"
    76 #include "icmp_header.h"
    77 #include "icmp_messages.h"
    7876#include "icmp_module.h"
     77
     78/** ICMP module name.
     79 */
     80#define NAME    "ICMP protocol"
    7981
    8082/** Default ICMP error reporting.
     
    289291        // TODO do not ask all the time
    290292        ERROR_PROPAGATE(ip_packet_size_req(icmp_globals.ip_phone, -1, &icmp_globals.packet_dimension));
    291         packet = packet_get_4(icmp_globals.net_phone, size, icmp_globals.packet_dimension.addr_len, ICMP_HEADER_SIZE + icmp_globals.packet_dimension.prefix, icmp_globals.packet_dimension.suffix);
     293        packet = packet_get_4_remote(icmp_globals.net_phone, size, icmp_globals.packet_dimension.addr_len, ICMP_HEADER_SIZE + icmp_globals.packet_dimension.prefix, icmp_globals.packet_dimension.suffix);
    292294        if(! packet){
    293295                return ENOMEM;
     
    627629        // compute the reply key
    628630        reply_key = ICMP_GET_REPLY_KEY(header->un.echo.identifier, header->un.echo.sequence_number);
    629         pq_release(icmp_globals.net_phone, packet_get_id(packet));
     631        pq_release_remote(icmp_globals.net_phone, packet_get_id(packet));
    630632        // lock the globals
    631633        fibril_rwlock_write_lock(&icmp_globals.lock);
     
    642644}
    643645
    644 int icmp_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){
     646int icmp_message_standalone(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){
    645647        ERROR_DECLARE;
    646648
     
    650652        switch(IPC_GET_METHOD(*call)){
    651653                case NET_TL_RECEIVED:
    652                         if(! ERROR_OCCURRED(packet_translate(icmp_globals.net_phone, &packet, IPC_GET_PACKET(call)))){
     654                        if(! ERROR_OCCURRED(packet_translate_remote(icmp_globals.net_phone, &packet, IPC_GET_PACKET(call)))){
    653655                                ERROR_CODE = icmp_received_msg(IPC_GET_DEVICE(call), packet, SERVICE_ICMP, IPC_GET_ERROR(call));
    654656                        }
     
    760762        switch(IPC_GET_METHOD(*call)){
    761763                case NET_ICMP_DEST_UNREACH:
    762                         if(! ERROR_OCCURRED(packet_translate(icmp_globals.net_phone, &packet, IPC_GET_PACKET(call)))){
     764                        if(! ERROR_OCCURRED(packet_translate_remote(icmp_globals.net_phone, &packet, IPC_GET_PACKET(call)))){
    763765                                ERROR_CODE = icmp_destination_unreachable_msg(0, ICMP_GET_CODE(call), ICMP_GET_MTU(call), packet);
    764766                        }
    765767                        return ERROR_CODE;
    766768                case NET_ICMP_SOURCE_QUENCH:
    767                         if(! ERROR_OCCURRED(packet_translate(icmp_globals.net_phone, &packet, IPC_GET_PACKET(call)))){
     769                        if(! ERROR_OCCURRED(packet_translate_remote(icmp_globals.net_phone, &packet, IPC_GET_PACKET(call)))){
    768770                                ERROR_CODE = icmp_source_quench_msg(0, packet);
    769771                        }
    770772                        return ERROR_CODE;
    771773                case NET_ICMP_TIME_EXCEEDED:
    772                         if(! ERROR_OCCURRED(packet_translate(icmp_globals.net_phone, &packet, IPC_GET_PACKET(call)))){
     774                        if(! ERROR_OCCURRED(packet_translate_remote(icmp_globals.net_phone, &packet, IPC_GET_PACKET(call)))){
    773775                                ERROR_CODE = icmp_time_exceeded_msg(0, ICMP_GET_CODE(call), packet);
    774776                        }
    775777                        return ERROR_CODE;
    776778                case NET_ICMP_PARAMETERPROB:
    777                         if(! ERROR_OCCURRED(packet_translate(icmp_globals.net_phone, &packet, IPC_GET_PACKET(call)))){
     779                        if(! ERROR_OCCURRED(packet_translate_remote(icmp_globals.net_phone, &packet, IPC_GET_PACKET(call)))){
    778780                                ERROR_CODE = icmp_parameter_problem_msg(0, ICMP_GET_CODE(call), ICMP_GET_POINTER(call), packet);
    779781                        }
     
    785787
    786788int icmp_release_and_return(packet_t packet, int result){
    787         pq_release(icmp_globals.net_phone, packet_get_id(packet));
     789        pq_release_remote(icmp_globals.net_phone, packet_get_id(packet));
    788790        return result;
    789791}
     
    820822}
    821823
     824/** Default thread for new connections.
     825 *
     826 *  @param[in] iid The initial message identifier.
     827 *  @param[in] icall The initial message call structure.
     828 *
     829 */
     830static void tl_client_connection(ipc_callid_t iid, ipc_call_t * icall)
     831{
     832        /*
     833         * Accept the connection
     834         *  - Answer the first IPC_M_CONNECT_ME_TO call.
     835         */
     836        ipc_answer_0(iid, EOK);
     837       
     838        while(true) {
     839                ipc_call_t answer;
     840                int answer_count;
     841               
     842                /* Clear the answer structure */
     843                refresh_answer(&answer, &answer_count);
     844               
     845                /* Fetch the next message */
     846                ipc_call_t call;
     847                ipc_callid_t callid = async_get_call(&call);
     848               
     849                /* Process the message */
     850                int res = tl_module_message_standalone(callid, &call, &answer,
     851                    &answer_count);
     852               
     853                /* End if said to either by the message or the processing result */
     854                if ((IPC_GET_METHOD(call) == IPC_M_PHONE_HUNGUP) || (res == EHANGUP))
     855                        return;
     856               
     857                /* Answer the message */
     858                answer_call(callid, res, &answer, answer_count);
     859        }
     860}
     861
     862/** Starts the module.
     863 *
     864 *  @param argc The count of the command line arguments. Ignored parameter.
     865 *  @param argv The command line parameters. Ignored parameter.
     866 *
     867 *  @returns EOK on success.
     868 *  @returns Other error codes as defined for each specific module start function.
     869 *
     870 */
     871int main(int argc, char *argv[])
     872{
     873        ERROR_DECLARE;
     874       
     875        /* Start the module */
     876        if (ERROR_OCCURRED(tl_module_start_standalone(tl_client_connection)))
     877                return ERROR_CODE;
     878       
     879        return EOK;
     880}
     881
    822882/** @}
    823883 */
Note: See TracChangeset for help on using the changeset viewer.