Changeset 14f1db0 in mainline for uspace/srv/net/il/ip/ip.c


Ignore:
Timestamp:
2010-04-09T12:54:57Z (15 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
a1caa3c2
Parents:
24ab58b3
Message:

networking overhaul:

  • separation of conserns
  • removal of (almost all) overlaping symbols, libnetif is not needed anymore
  • again, it is possible to build the networking in multiple architecture configurations (however, currently only the bundling netif and nil layers is supported, more to come)
  • code style updates and fixes (still a huge amount of work to do)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/net/il/ip/ip.c

    r24ab58b3 r14f1db0  
    6969#include <adt/module_map.h>
    7070#include <packet/packet_client.h>
     71#include <packet_remote.h>
    7172#include <nil_messages.h>
    7273#include <il_messages.h>
     74#include <il_local.h>
     75#include <ip_local.h>
    7376
    7477#include "ip.h"
     
    424427}
    425428
    426 int ip_device_req(int il_phone, device_id_t device_id, services_t netif){
     429int ip_device_req_local(int il_phone, device_id_t device_id, services_t netif){
    427430        ERROR_DECLARE;
    428431
     
    656659}
    657660
    658 int ip_send_msg(int il_phone, device_id_t device_id, packet_t packet, services_t sender, services_t error){
     661int ip_send_msg_local(int il_phone, device_id_t device_id, packet_t packet, services_t sender, services_t error){
    659662        ERROR_DECLARE;
    660663
     
    782785//                      sleep(1);
    783786//                      ERROR_PROPAGATE(arp_translate_req(netif->arp->phone, netif->device_id, SERVICE_IP, &destination, &translation, &data));
    784                         pq_release(ip_globals.net_phone, packet_get_id(packet));
     787                        pq_release_remote(ip_globals.net_phone, packet_get_id(packet));
    785788                        return ERROR_CODE;
    786789                }
     
    799802        }else translation = NULL;
    800803        if(ERROR_OCCURRED(ip_prepare_packet(src, dest, packet, translation))){
    801                 pq_release(ip_globals.net_phone, packet_get_id(packet));
     804                pq_release_remote(ip_globals.net_phone, packet_get_id(packet));
    802805        }else{
    803806                packet = ip_split_packet(packet, netif->packet_dimension.prefix, netif->packet_dimension.content, netif->packet_dimension.suffix, netif->packet_dimension.addr_len, error);
     
    891894}
    892895
    893 int ip_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){
     896int ip_message_standalone(ipc_callid_t callid, ipc_call_t *call,
     897    ipc_call_t *answer, int * answer_count)
     898{
    894899        ERROR_DECLARE;
    895 
     900       
    896901        packet_t packet;
    897         struct sockaddr * addr;
     902        struct sockaddr *addr;
    898903        size_t addrlen;
    899904        size_t prefix;
    900905        size_t suffix;
    901906        size_t content;
    902         ip_pseudo_header_ref header;
     907        void *header;
    903908        size_t headerlen;
    904909        device_id_t device_id;
    905 
     910       
    906911        *answer_count = 0;
    907         switch(IPC_GET_METHOD(*call)){
     912        switch (IPC_GET_METHOD(*call)) {
    908913                case IPC_M_PHONE_HUNGUP:
    909914                        return EOK;
    910915                case NET_IL_DEVICE:
    911                         return ip_device_req(0, IPC_GET_DEVICE(call), IPC_GET_SERVICE(call));
     916                        return ip_device_req_local(0, IPC_GET_DEVICE(call),
     917                            IPC_GET_SERVICE(call));
    912918                case IPC_M_CONNECT_TO_ME:
    913                         return ip_register(IL_GET_PROTO(call), IL_GET_SERVICE(call), IPC_GET_PHONE(call), NULL);
     919                        return ip_register(IL_GET_PROTO(call), IL_GET_SERVICE(call),
     920                            IPC_GET_PHONE(call), NULL);
    914921                case NET_IL_SEND:
    915                         ERROR_PROPAGATE(packet_translate(ip_globals.net_phone, &packet, IPC_GET_PACKET(call)));
    916                         return ip_send_msg(0, IPC_GET_DEVICE(call), packet, 0, IPC_GET_ERROR(call));
     922                        ERROR_PROPAGATE(packet_translate_remote(ip_globals.net_phone, &packet,
     923                            IPC_GET_PACKET(call)));
     924                        return ip_send_msg_local(0, IPC_GET_DEVICE(call), packet, 0,
     925                            IPC_GET_ERROR(call));
    917926                case NET_IL_DEVICE_STATE:
    918                         return ip_device_state_message(IPC_GET_DEVICE(call), IPC_GET_STATE(call));
     927                        return ip_device_state_message(IPC_GET_DEVICE(call),
     928                            IPC_GET_STATE(call));
    919929                case NET_IL_RECEIVED:
    920                         ERROR_PROPAGATE(packet_translate(ip_globals.net_phone, &packet, IPC_GET_PACKET(call)));
     930                        ERROR_PROPAGATE(packet_translate_remote(ip_globals.net_phone, &packet,
     931                            IPC_GET_PACKET(call)));
    921932                        return ip_receive_message(IPC_GET_DEVICE(call), packet);
    922933                case NET_IP_RECEIVED_ERROR:
    923                         ERROR_PROPAGATE(packet_translate(ip_globals.net_phone, &packet, IPC_GET_PACKET(call)));
    924                         return ip_received_error_msg(0, IPC_GET_DEVICE(call), packet, IPC_GET_TARGET(call), IPC_GET_ERROR(call));
     934                        ERROR_PROPAGATE(packet_translate_remote(ip_globals.net_phone, &packet,
     935                            IPC_GET_PACKET(call)));
     936                        return ip_received_error_msg_local(0, IPC_GET_DEVICE(call), packet,
     937                            IPC_GET_TARGET(call), IPC_GET_ERROR(call));
    925938                case NET_IP_ADD_ROUTE:
    926                         return ip_add_route_req(0, IPC_GET_DEVICE(call), IP_GET_ADDRESS(call), IP_GET_NETMASK(call), IP_GET_GATEWAY(call));
     939                        return ip_add_route_req_local(0, IPC_GET_DEVICE(call),
     940                            IP_GET_ADDRESS(call), IP_GET_NETMASK(call), IP_GET_GATEWAY(call));
    927941                case NET_IP_SET_GATEWAY:
    928                         return ip_set_gateway_req(0, IPC_GET_DEVICE(call), IP_GET_GATEWAY(call));
     942                        return ip_set_gateway_req_local(0, IPC_GET_DEVICE(call),
     943                            IP_GET_GATEWAY(call));
    929944                case NET_IP_GET_ROUTE:
    930945                        ERROR_PROPAGATE(data_receive((void **) &addr, &addrlen));
    931                         ERROR_PROPAGATE(ip_get_route_req(0, IP_GET_PROTOCOL(call), addr, (socklen_t) addrlen,
    932                             &device_id, &header, &headerlen));
     946                        ERROR_PROPAGATE(ip_get_route_req_local(0, IP_GET_PROTOCOL(call),
     947                            addr, (socklen_t) addrlen, &device_id, &header, &headerlen));
    933948                        IPC_SET_DEVICE(answer, device_id);
    934949                        IP_SET_HEADERLEN(answer, headerlen);
     950                       
    935951                        *answer_count = 2;
    936                         if(! ERROR_OCCURRED(data_reply(&headerlen, sizeof(headerlen)))){
     952                       
     953                        if (!ERROR_OCCURRED(data_reply(&headerlen, sizeof(headerlen))))
    937954                                ERROR_CODE = data_reply(header, headerlen);
    938                         }
     955                       
    939956                        free(header);
    940957                        return ERROR_CODE;
    941958                case NET_IL_PACKET_SPACE:
    942                         ERROR_PROPAGATE(ip_packet_size_message(IPC_GET_DEVICE(call), &addrlen, &prefix, &content, &suffix));
     959                        ERROR_PROPAGATE(ip_packet_size_message(IPC_GET_DEVICE(call),
     960                            &addrlen, &prefix, &content, &suffix));
    943961                        IPC_SET_ADDR(answer, addrlen);
    944962                        IPC_SET_PREFIX(answer, prefix);
     
    948966                        return EOK;
    949967                case NET_IL_MTU_CHANGED:
    950                         return ip_mtu_changed_message(IPC_GET_DEVICE(call), IPC_GET_MTU(call));
    951         }
     968                        return ip_mtu_changed_message(IPC_GET_DEVICE(call),
     969                            IPC_GET_MTU(call));
     970        }
     971       
    952972        return ENOTSUP;
    953973}
    954974
    955 int ip_packet_size_req(int ip_phone, device_id_t device_id, packet_dimension_ref packet_dimension){
    956         if(! packet_dimension){
     975int ip_packet_size_req_local(int ip_phone, device_id_t device_id,
     976    packet_dimension_ref packet_dimension)
     977{
     978        if (!packet_dimension)
    957979                return EBADMEM;
    958         }
    959         return ip_packet_size_message(device_id, &packet_dimension->addr_len, &packet_dimension->prefix, &packet_dimension->content, &packet_dimension->suffix);
     980       
     981        return ip_packet_size_message(device_id, &packet_dimension->addr_len,
     982            &packet_dimension->prefix, &packet_dimension->content,
     983            &packet_dimension->suffix);
    960984}
    961985
     
    10031027}
    10041028
    1005 int ip_add_route_req(int ip_phone, device_id_t device_id, in_addr_t address, in_addr_t netmask, in_addr_t gateway){
     1029int ip_add_route_req_local(int ip_phone, device_id_t device_id, in_addr_t address, in_addr_t netmask, in_addr_t gateway){
    10061030        ip_route_ref route;
    10071031        ip_netif_ref netif;
     
    10671091}
    10681092
    1069 int ip_set_gateway_req(int ip_phone, device_id_t device_id, in_addr_t gateway){
     1093int ip_set_gateway_req_local(int ip_phone, device_id_t device_id, in_addr_t gateway)
     1094{
    10701095        ip_netif_ref netif;
    10711096
     
    11121137                                        }
    11131138                                }else{
    1114                                         pq_release(ip_globals.net_phone, packet_get_id(next));
     1139                                        pq_release_remote(ip_globals.net_phone, packet_get_id(next));
    11151140                                }
    11161141                                next = new_packet;
     
    11531178        }
    11541179        // create the last fragment
    1155         new_packet = packet_get_4(ip_globals.net_phone, prefix, length, suffix, ((addrlen > addr_len) ? addrlen : addr_len));
     1180        new_packet = packet_get_4_remote(ip_globals.net_phone, prefix, length, suffix, ((addrlen > addr_len) ? addrlen : addr_len));
    11561181        if(! new_packet){
    11571182                return ENOMEM;
     
    11771202        // create middle framgents
    11781203        while(IP_TOTAL_LENGTH(header) > length){
    1179                 new_packet = packet_get_4(ip_globals.net_phone, prefix, length, suffix, ((addrlen >= addr_len) ? addrlen : addr_len));
     1204                new_packet = packet_get_4_remote(ip_globals.net_phone, prefix, length, suffix, ((addrlen >= addr_len) ? addrlen : addr_len));
    11801205                if(! new_packet){
    11811206                        return ENOMEM;
     
    13571382}
    13581383
    1359 int ip_received_error_msg(int ip_phone, device_id_t device_id, packet_t packet, services_t target, services_t error){
     1384/** Notify the IP module about the received error notification packet.
     1385 *
     1386 * @param[in] ip_phone  The IP module phone used for (semi)remote calls.
     1387 * @param[in] device_id The device identifier.
     1388 * @param[in] packet    The received packet or the received packet queue.
     1389 * @param[in] target    The target internetwork module service to be
     1390 *                      delivered to.
     1391 * @param[in] error     The packet error reporting service. Prefixes the
     1392 *                      received packet.
     1393 *
     1394 * @return EOK on success.
     1395 *
     1396 */
     1397int ip_received_error_msg_local(int ip_phone, device_id_t device_id, packet_t packet, services_t target, services_t error){
    13601398        uint8_t * data;
    13611399        int offset;
     
    14921530        next = pq_detach(packet);
    14931531        if(next){
    1494                 pq_release(ip_globals.net_phone, packet_get_id(next));
     1532                pq_release_remote(ip_globals.net_phone, packet_get_id(next));
    14951533        }
    14961534        if(! header){
     
    15561594
    15571595int ip_release_and_return(packet_t packet, int result){
    1558         pq_release(ip_globals.net_phone, packet_get_id(packet));
     1596        pq_release_remote(ip_globals.net_phone, packet_get_id(packet));
    15591597        return result;
    15601598}
    15611599
    1562 int ip_get_route_req(int ip_phone, ip_protocol_t protocol, const struct sockaddr * destination, socklen_t addrlen, device_id_t * device_id, ip_pseudo_header_ref * header, size_t * headerlen){
     1600int ip_get_route_req_local(int ip_phone, ip_protocol_t protocol, const struct sockaddr * destination, socklen_t addrlen, device_id_t * device_id, void **header, size_t * headerlen){
    15631601        struct sockaddr_in * address_in;
    15641602//      struct sockaddr_in6 *   address_in6;
     
    16241662        header_in->protocol = protocol;
    16251663        header_in->data_length = 0;
    1626         *header = (ip_pseudo_header_ref) header_in;
     1664        *header = header_in;
    16271665        return EOK;
    16281666}
    1629 
    1630 #ifdef CONFIG_NETWORKING_modular
    1631 
    1632 #include <il_standalone.h>
    16331667
    16341668/** Default thread for new connections.
     
    16581692               
    16591693                /* Process the message */
    1660                 int res = il_module_message(callid, &call, &answer, &answer_count);
     1694                int res = il_module_message_standalone(callid, &call, &answer,
     1695                    &answer_count);
    16611696               
    16621697                /* End if said to either by the message or the processing result */
     
    16831718       
    16841719        /* Start the module */
    1685         if (ERROR_OCCURRED(il_module_start(il_client_connection)))
     1720        if (ERROR_OCCURRED(il_module_start_standalone(il_client_connection)))
    16861721                return ERROR_CODE;
    16871722       
     
    16891724}
    16901725
    1691 #endif /* CONFIG_NETWORKING_modular */
    1692 
    16931726/** @}
    16941727 */
Note: See TracChangeset for help on using the changeset viewer.