Ignore:
File:
1 edited

Legend:

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

    rf9b2cb4c r9ae6fc7  
    4646#include <stdlib.h>
    4747#include <sys/types.h>
    48 #include <task.h>
     48#include <net/socket_codes.h>
    4949#include "addrobj.h"
    5050#include "icmp.h"
     
    5555#include "inetcfg.h"
    5656#include "inetping.h"
     57#include "inetping6.h"
    5758#include "inet_link.h"
    5859#include "reass.h"
     
    6263
    6364static inet_naddr_t solicited_node_mask = {
    64         .version = ip_v6,
     65        .family = AF_INET6,
    6566        .addr6 = {0xff, 0x02, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x01, 0xff, 0, 0, 0},
    6667        .prefix = 104
    6768};
    6869
    69 static inet_addr_t broadcast4_all_hosts = {
    70         .version = ip_v4,
    71         .addr = 0xffffffff
    72 };
    73 
    7470static inet_addr_t multicast_all_nodes = {
    75         .version = ip_v6,
     71        .family = AF_INET,
    7672        .addr6 = {0xff, 0x02, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x01}
    7773};
    7874
     75static void inet_client_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg);
     76
    7977static FIBRIL_MUTEX_INITIALIZE(client_list_lock);
    8078static LIST_INITIALIZE(client_list);
    8179
    82 static void inet_default_conn(ipc_callid_t, ipc_call_t *, void *);
    83 
    8480static int inet_init(void)
    8581{
    8682        log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_init()");
    8783       
    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);
     84        async_set_client_connection(inet_client_conn);
     85       
     86        int rc = loc_server_register(NAME);
    10587        if (rc != EOK) {
    10688                log_msg(LOG_DEFAULT, LVL_ERROR, "Failed registering server (%d).", rc);
     
    10991       
    11092        service_id_t sid;
    111         rc = loc_service_register(SERVICE_NAME_INET, &sid);
     93        rc = loc_service_register_with_iface(SERVICE_NAME_INET, &sid,
     94            INET_PORT_DEFAULT);
    11295        if (rc != EOK) {
    11396                log_msg(LOG_DEFAULT, LVL_ERROR, "Failed registering service (%d).", rc);
    11497                return EEXIST;
    11598        }
     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;
    116135       
    117136        return EOK;
     
    167186{
    168187        inet_dir_t dir;
    169         inet_link_t *ilink;
    170188        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 */
    192189
    193190        rc = inet_find_dir(&dgram->src, &dgram->dest, dgram->tos, &dir);
     
    217214
    218215        /* 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 
    226216        inet_naddr_addr(&dir.aobj->naddr, local);
    227217        return EOK;
     
    292282        inet_dgram_t dgram;
    293283       
    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);
     284        dgram.tos = IPC_GET_ARG1(*icall);
     285       
     286        uint8_t ttl = IPC_GET_ARG2(*icall);
     287        int df = IPC_GET_ARG3(*icall);
    299288       
    300289        ipc_callid_t callid;
     
    428417}
    429418
     419static 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
    430444static inet_client_t *inet_client_find(uint8_t proto)
    431445{
    432446        fibril_mutex_lock(&client_list_lock);
    433447
    434         list_foreach(client_list, client_list, inet_client_t, client) {
     448        list_foreach(client_list, link) {
     449                inet_client_t *client = list_get_instance(link, inet_client_t,
     450                    client_list);
     451
    435452                if (client->protocol == proto) {
    436453                        fibril_mutex_unlock(&client_list_lock);
     
    446463{
    447464        async_exch_t *exch = async_exchange_begin(client->sess);
    448 
     465       
    449466        ipc_call_t answer;
    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 
     467        aid_t req = async_send_1(exch, INET_EV_RECV, dgram->tos, &answer);
     468       
    457469        int rc = async_data_write_start(exch, &dgram->src, sizeof(inet_addr_t));
    458470        if (rc != EOK) {
     
    461473                return rc;
    462474        }
    463 
     475       
    464476        rc = async_data_write_start(exch, &dgram->dest, sizeof(inet_addr_t));
    465477        if (rc != EOK) {
     
    468480                return rc;
    469481        }
    470 
     482       
    471483        rc = async_data_write_start(exch, dgram->data, dgram->size);
    472 
     484       
    473485        async_exchange_end(exch);
    474 
     486       
    475487        if (rc != EOK) {
    476488                async_forget(req);
    477489                return rc;
    478490        }
    479 
     491       
    480492        sysarg_t retval;
    481493        async_wait_for(req, &retval);
    482 
     494       
    483495        return (int) retval;
    484496}
     
    493505        if (proto == IP_PROTO_ICMP)
    494506                return icmp_recv(dgram);
    495 
     507       
    496508        if (proto == IP_PROTO_ICMPV6)
    497509                return icmpv6_recv(dgram);
     
    515527        if ((addr != NULL) ||
    516528            (inet_naddr_compare_mask(&solicited_node_mask, &packet->dest)) ||
    517             (inet_addr_compare(&multicast_all_nodes, &packet->dest)) ||
    518             (inet_addr_compare(&broadcast4_all_hosts, &packet->dest))) {
     529            (inet_addr_compare(&multicast_all_nodes, &packet->dest))) {
    519530                /* Destined for one of the local addresses */
    520531
     
    522533                if (packet->offs == 0 && !packet->mf) {
    523534                        /* It is complete deliver it immediately */
    524                         dgram.iplink = packet->link_id;
    525535                        dgram.src = packet->src;
    526536                        dgram.dest = packet->dest;
Note: See TracChangeset for help on using the changeset viewer.