Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/net/inetsrv/inetsrv.c

    r9ae6fc7 rf9b2cb4c  
    4646#include <stdlib.h>
    4747#include <sys/types.h>
    48 #include <net/socket_codes.h>
     48#include <task.h>
    4949#include "addrobj.h"
    5050#include "icmp.h"
     
    5555#include "inetcfg.h"
    5656#include "inetping.h"
    57 #include "inetping6.h"
    5857#include "inet_link.h"
    5958#include "reass.h"
     
    6362
    6463static inet_naddr_t solicited_node_mask = {
    65         .family = AF_INET6,
     64        .version = ip_v6,
    6665        .addr6 = {0xff, 0x02, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x01, 0xff, 0, 0, 0},
    6766        .prefix = 104
    6867};
    6968
     69static inet_addr_t broadcast4_all_hosts = {
     70        .version = ip_v4,
     71        .addr = 0xffffffff
     72};
     73
    7074static inet_addr_t multicast_all_nodes = {
    71         .family = AF_INET,
     75        .version = ip_v6,
    7276        .addr6 = {0xff, 0x02, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x01}
    7377};
    7478
    75 static void inet_client_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg);
    76 
    7779static FIBRIL_MUTEX_INITIALIZE(client_list_lock);
    7880static LIST_INITIALIZE(client_list);
    7981
     82static void inet_default_conn(ipc_callid_t, ipc_call_t *, void *);
     83
    8084static int inet_init(void)
    8185{
    8286        log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_init()");
    8387       
    84         async_set_client_connection(inet_client_conn);
    85        
    86         int rc = loc_server_register(NAME);
     88        port_id_t port;
     89        int rc = async_create_port(INTERFACE_INET,
     90            inet_default_conn, NULL, &port);
     91        if (rc != EOK)
     92                return rc;
     93       
     94        rc = async_create_port(INTERFACE_INETCFG,
     95            inet_cfg_conn, NULL, &port);
     96        if (rc != EOK)
     97                return rc;
     98       
     99        rc = async_create_port(INTERFACE_INETPING,
     100            inetping_conn, NULL, &port);
     101        if (rc != EOK)
     102                return rc;
     103       
     104        rc = loc_server_register(NAME);
    87105        if (rc != EOK) {
    88106                log_msg(LOG_DEFAULT, LVL_ERROR, "Failed registering server (%d).", rc);
     
    91109       
    92110        service_id_t sid;
    93         rc = loc_service_register_with_iface(SERVICE_NAME_INET, &sid,
    94             INET_PORT_DEFAULT);
     111        rc = loc_service_register(SERVICE_NAME_INET, &sid);
    95112        if (rc != EOK) {
    96113                log_msg(LOG_DEFAULT, LVL_ERROR, "Failed registering service (%d).", rc);
    97114                return EEXIST;
    98115        }
    99        
    100         rc = loc_service_register_with_iface(SERVICE_NAME_INETCFG, &sid,
    101             INET_PORT_CFG);
    102         if (rc != EOK) {
    103                 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed registering service (%d).", rc);
    104                 return EEXIST;
    105         }
    106        
    107         rc = loc_service_register_with_iface(SERVICE_NAME_INETPING, &sid,
    108             INET_PORT_PING);
    109         if (rc != EOK) {
    110                 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed registering service (%d).", rc);
    111                 return EEXIST;
    112         }
    113        
    114         rc = loc_service_register_with_iface(SERVICE_NAME_INETPING6, &sid,
    115             INET_PORT_PING6);
    116         if (rc != EOK) {
    117                 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed registering service (%d).", rc);
    118                 return EEXIST;
    119         }
    120        
    121         inet_sroute_t *sroute = inet_sroute_new();
    122         if (sroute == NULL) {
    123                 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed creating default route (%d).", rc);
    124                 return ENOMEM;
    125         }
    126 
    127         inet_naddr(&sroute->dest, 0, 0, 0, 0, 0);
    128         inet_addr(&sroute->router, 10, 0, 2, 2);
    129         sroute->name = str_dup("default");
    130         inet_sroute_add(sroute);
    131 
    132         rc = inet_link_discovery_start();
    133         if (rc != EOK)
    134                 return EEXIST;
    135116       
    136117        return EOK;
     
    186167{
    187168        inet_dir_t dir;
     169        inet_link_t *ilink;
    188170        int rc;
     171
     172        if (dgram->iplink != 0) {
     173                /* XXX TODO - IPv6 */
     174                log_msg(LOG_DEFAULT, LVL_DEBUG, "dgram directly to iplink %zu",
     175                    dgram->iplink);
     176                /* Send packet directly to the specified IP link */
     177                ilink = inet_link_get_by_id(dgram->iplink);
     178                if (ilink == 0)
     179                        return ENOENT;
     180
     181                if (dgram->src.version != ip_v4 ||
     182                        dgram->dest.version != ip_v4)
     183                        return EINVAL;
     184
     185                return inet_link_send_dgram(ilink, dgram->src.addr,
     186                    dgram->dest.addr, dgram, proto, ttl, df);
     187        }
     188
     189        log_msg(LOG_DEFAULT, LVL_DEBUG, "dgram to be routed");
     190
     191        /* Route packet using source/destination addresses */
    189192
    190193        rc = inet_find_dir(&dgram->src, &dgram->dest, dgram->tos, &dir);
     
    214217
    215218        /* Take source address from the address object */
     219        if (remote->version == ip_v4 && remote->addr == 0xffffffff) {
     220                /* XXX TODO - IPv6 */
     221                local->version = ip_v4;
     222                local->addr = 0;
     223                return EOK;
     224        }
     225
    216226        inet_naddr_addr(&dir.aobj->naddr, local);
    217227        return EOK;
     
    282292        inet_dgram_t dgram;
    283293       
    284         dgram.tos = IPC_GET_ARG1(*icall);
    285        
    286         uint8_t ttl = IPC_GET_ARG2(*icall);
    287         int df = IPC_GET_ARG3(*icall);
     294        dgram.iplink = IPC_GET_ARG1(*icall);
     295        dgram.tos = IPC_GET_ARG2(*icall);
     296       
     297        uint8_t ttl = IPC_GET_ARG3(*icall);
     298        int df = IPC_GET_ARG4(*icall);
    288299       
    289300        ipc_callid_t callid;
     
    417428}
    418429
    419 static void inet_client_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg)
    420 {
    421         sysarg_t port;
    422 
    423         port = IPC_GET_ARG1(*icall);
    424 
    425         switch (port) {
    426         case INET_PORT_DEFAULT:
    427                 inet_default_conn(iid, icall, arg);
    428                 break;
    429         case INET_PORT_CFG:
    430                 inet_cfg_conn(iid, icall, arg);
    431                 break;
    432         case INET_PORT_PING:
    433                 inetping_conn(iid, icall, arg);
    434                 break;
    435         case INET_PORT_PING6:
    436                 inetping6_conn(iid, icall, arg);
    437                 break;
    438         default:
    439                 async_answer_0(iid, ENOTSUP);
    440                 break;
    441         }
    442 }
    443 
    444430static inet_client_t *inet_client_find(uint8_t proto)
    445431{
    446432        fibril_mutex_lock(&client_list_lock);
    447433
    448         list_foreach(client_list, link) {
    449                 inet_client_t *client = list_get_instance(link, inet_client_t,
    450                     client_list);
    451 
     434        list_foreach(client_list, client_list, inet_client_t, client) {
    452435                if (client->protocol == proto) {
    453436                        fibril_mutex_unlock(&client_list_lock);
     
    463446{
    464447        async_exch_t *exch = async_exchange_begin(client->sess);
    465        
     448
    466449        ipc_call_t answer;
    467         aid_t req = async_send_1(exch, INET_EV_RECV, dgram->tos, &answer);
    468        
     450
     451        log_msg(LOG_DEFAULT, LVL_NOTE, "inet_ev_recv: iplink=%zu",
     452            dgram->iplink);
     453
     454        aid_t req = async_send_2(exch, INET_EV_RECV, dgram->tos,
     455            dgram->iplink, &answer);
     456
    469457        int rc = async_data_write_start(exch, &dgram->src, sizeof(inet_addr_t));
    470458        if (rc != EOK) {
     
    473461                return rc;
    474462        }
    475        
     463
    476464        rc = async_data_write_start(exch, &dgram->dest, sizeof(inet_addr_t));
    477465        if (rc != EOK) {
     
    480468                return rc;
    481469        }
    482        
     470
    483471        rc = async_data_write_start(exch, dgram->data, dgram->size);
    484        
     472
    485473        async_exchange_end(exch);
    486        
     474
    487475        if (rc != EOK) {
    488476                async_forget(req);
    489477                return rc;
    490478        }
    491        
     479
    492480        sysarg_t retval;
    493481        async_wait_for(req, &retval);
    494        
     482
    495483        return (int) retval;
    496484}
     
    505493        if (proto == IP_PROTO_ICMP)
    506494                return icmp_recv(dgram);
    507        
     495
    508496        if (proto == IP_PROTO_ICMPV6)
    509497                return icmpv6_recv(dgram);
     
    527515        if ((addr != NULL) ||
    528516            (inet_naddr_compare_mask(&solicited_node_mask, &packet->dest)) ||
    529             (inet_addr_compare(&multicast_all_nodes, &packet->dest))) {
     517            (inet_addr_compare(&multicast_all_nodes, &packet->dest)) ||
     518            (inet_addr_compare(&broadcast4_all_hosts, &packet->dest))) {
    530519                /* Destined for one of the local addresses */
    531520
     
    533522                if (packet->offs == 0 && !packet->mf) {
    534523                        /* It is complete deliver it immediately */
     524                        dgram.iplink = packet->link_id;
    535525                        dgram.src = packet->src;
    536526                        dgram.dest = packet->dest;
Note: See TracChangeset for help on using the changeset viewer.