Ignore:
File:
1 edited

Legend:

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

    rb323a3a r4a5a18be  
    4646#include <stdlib.h>
    4747#include <sys/types.h>
    48 #include <net/socket_codes.h>
     48
    4949#include "addrobj.h"
    5050#include "icmp.h"
    5151#include "icmp_std.h"
    52 #include "icmpv6.h"
    53 #include "icmpv6_std.h"
    5452#include "inetsrv.h"
    5553#include "inetcfg.h"
    5654#include "inetping.h"
    57 #include "inetping6.h"
    5855#include "inet_link.h"
    5956#include "reass.h"
     
    6259#define NAME "inetsrv"
    6360
    64 static inet_naddr_t solicited_node_mask = {
    65         .family = AF_INET6,
    66         .addr6 = {0xff, 0x02, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x01, 0xff, 0, 0, 0},
    67         .prefix = 104
    68 };
    69 
    70 static inet_addr_t multicast_all_nodes = {
    71         .family = AF_INET6,
    72         .addr6 = {0xff, 0x02, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x01}
    73 };
    74 
    7561static void inet_client_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg);
    7662
     
    10793        rc = loc_service_register_with_iface(SERVICE_NAME_INETPING, &sid,
    10894            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);
    11695        if (rc != EOK) {
    11796                log_msg(LOG_DEFAULT, LVL_ERROR, "Failed registering service (%d).", rc);
     
    125104        }
    126105
    127         inet_naddr(&sroute->dest, 0, 0, 0, 0, 0);
    128         inet_addr(&sroute->router, 10, 0, 2, 2);
     106        sroute->dest.ipv4 = 0;
     107        sroute->dest.bits = 0;
     108        sroute->router.ipv4 = (10 << 24) | (0 << 16) | (2 << 8) | 2;
    129109        sroute->name = str_dup("default");
    130110        inet_sroute_add(sroute);
    131111
    132         rc = inet_link_discovery_start();
     112        rc = inet_link_discovery_start();
    133113        if (rc != EOK)
    134114                return EEXIST;
     
    214194
    215195        /* Take source address from the address object */
    216         inet_naddr_addr(&dir.aobj->naddr, local);
     196        local->ipv4 = dir.aobj->naddr.ipv4;
    217197        return EOK;
    218198}
    219199
    220 static void inet_get_srcaddr_srv(inet_client_t *client, ipc_callid_t iid,
    221     ipc_call_t *icall)
    222 {
     200static void inet_get_srcaddr_srv(inet_client_t *client, ipc_callid_t callid,
     201    ipc_call_t *call)
     202{
     203        inet_addr_t remote;
     204        uint8_t tos;
     205        inet_addr_t local;
     206        int rc;
     207
    223208        log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_get_srcaddr_srv()");
    224        
    225         uint8_t tos = IPC_GET_ARG1(*icall);
    226        
    227         ipc_callid_t callid;
    228         size_t size;
    229         if (!async_data_write_receive(&callid, &size)) {
    230                 async_answer_0(callid, EREFUSED);
    231                 async_answer_0(iid, EREFUSED);
     209
     210        remote.ipv4 = IPC_GET_ARG1(*call);
     211        tos = IPC_GET_ARG2(*call);
     212        local.ipv4 = 0;
     213
     214        rc = inet_get_srcaddr(&remote, tos, &local);
     215        async_answer_1(callid, rc, local.ipv4);
     216}
     217
     218static void inet_send_srv(inet_client_t *client, ipc_callid_t callid,
     219    ipc_call_t *call)
     220{
     221        inet_dgram_t dgram;
     222        uint8_t ttl;
     223        int df;
     224        int rc;
     225
     226        log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_send_srv()");
     227
     228        dgram.src.ipv4 = IPC_GET_ARG1(*call);
     229        dgram.dest.ipv4 = IPC_GET_ARG2(*call);
     230        dgram.tos = IPC_GET_ARG3(*call);
     231        ttl = IPC_GET_ARG4(*call);
     232        df = IPC_GET_ARG5(*call);
     233
     234        rc = async_data_write_accept(&dgram.data, false, 0, 0, 0, &dgram.size);
     235        if (rc != EOK) {
     236                async_answer_0(callid, rc);
    232237                return;
    233238        }
    234        
    235         if (size != sizeof(inet_addr_t)) {
    236                 async_answer_0(callid, EINVAL);
    237                 async_answer_0(iid, EINVAL);
    238                 return;
    239         }
    240        
    241         inet_addr_t remote;
    242         int rc = async_data_write_finalize(callid, &remote, size);
    243         if (rc != EOK) {
    244                 async_answer_0(callid, rc);
    245                 async_answer_0(iid, rc);
    246         }
    247        
    248         inet_addr_t local;
    249         rc = inet_get_srcaddr(&remote, tos, &local);
    250         if (rc != EOK) {
    251                 async_answer_0(iid, rc);
    252                 return;
    253         }
    254        
    255         if (!async_data_read_receive(&callid, &size)) {
    256                 async_answer_0(callid, EREFUSED);
    257                 async_answer_0(iid, EREFUSED);
    258                 return;
    259         }
    260        
    261         if (size != sizeof(inet_addr_t)) {
    262                 async_answer_0(callid, EINVAL);
    263                 async_answer_0(iid, EINVAL);
    264                 return;
    265         }
    266        
    267         rc = async_data_read_finalize(callid, &local, size);
    268         if (rc != EOK) {
    269                 async_answer_0(callid, rc);
    270                 async_answer_0(iid, rc);
    271                 return;
    272         }
    273        
    274         async_answer_0(iid, rc);
    275 }
    276 
    277 static void inet_send_srv(inet_client_t *client, ipc_callid_t iid,
    278     ipc_call_t *icall)
    279 {
    280         log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_send_srv()");
    281        
    282         inet_dgram_t dgram;
    283        
    284         dgram.tos = IPC_GET_ARG1(*icall);
    285        
    286         uint8_t ttl = IPC_GET_ARG2(*icall);
    287         int df = IPC_GET_ARG3(*icall);
    288        
    289         ipc_callid_t callid;
    290         size_t size;
    291         if (!async_data_write_receive(&callid, &size)) {
    292                 async_answer_0(callid, EREFUSED);
    293                 async_answer_0(iid, EREFUSED);
    294                 return;
    295         }
    296        
    297         if (size != sizeof(inet_addr_t)) {
    298                 async_answer_0(callid, EINVAL);
    299                 async_answer_0(iid, EINVAL);
    300                 return;
    301         }
    302        
    303         int rc = async_data_write_finalize(callid, &dgram.src, size);
    304         if (rc != EOK) {
    305                 async_answer_0(callid, rc);
    306                 async_answer_0(iid, rc);
    307         }
    308        
    309         if (!async_data_write_receive(&callid, &size)) {
    310                 async_answer_0(callid, EREFUSED);
    311                 async_answer_0(iid, EREFUSED);
    312                 return;
    313         }
    314        
    315         if (size != sizeof(inet_addr_t)) {
    316                 async_answer_0(callid, EINVAL);
    317                 async_answer_0(iid, EINVAL);
    318                 return;
    319         }
    320        
    321         rc = async_data_write_finalize(callid, &dgram.dest, size);
    322         if (rc != EOK) {
    323                 async_answer_0(callid, rc);
    324                 async_answer_0(iid, rc);
    325         }
    326        
    327         rc = async_data_write_accept(&dgram.data, false, 0, 0, 0,
    328             &dgram.size);
    329         if (rc != EOK) {
    330                 async_answer_0(iid, rc);
    331                 return;
    332         }
    333        
     239
    334240        rc = inet_send(client, &dgram, client->protocol, ttl, df);
    335        
     241
    336242        free(dgram.data);
    337         async_answer_0(iid, rc);
     243        async_answer_0(callid, rc);
    338244}
    339245
     
    433339                inetping_conn(iid, icall, arg);
    434340                break;
    435         case INET_PORT_PING6:
    436                 inetping6_conn(iid, icall, arg);
    437                 break;
    438341        default:
    439342                async_answer_0(iid, ENOTSUP);
     
    463366{
    464367        async_exch_t *exch = async_exchange_begin(client->sess);
    465        
     368
    466369        ipc_call_t answer;
    467         aid_t req = async_send_1(exch, INET_EV_RECV, dgram->tos, &answer);
    468        
    469         int rc = async_data_write_start(exch, &dgram->src, sizeof(inet_addr_t));
    470         if (rc != EOK) {
    471                 async_exchange_end(exch);
     370        aid_t req = async_send_3(exch, INET_EV_RECV, dgram->src.ipv4,
     371            dgram->dest.ipv4, dgram->tos, &answer);
     372        int rc = async_data_write_start(exch, dgram->data, dgram->size);
     373        async_exchange_end(exch);
     374
     375        if (rc != EOK) {
    472376                async_forget(req);
    473377                return rc;
    474378        }
    475        
    476         rc = async_data_write_start(exch, &dgram->dest, sizeof(inet_addr_t));
    477         if (rc != EOK) {
    478                 async_exchange_end(exch);
    479                 async_forget(req);
    480                 return rc;
    481         }
    482        
    483         rc = async_data_write_start(exch, dgram->data, dgram->size);
    484        
    485         async_exchange_end(exch);
    486        
    487         if (rc != EOK) {
    488                 async_forget(req);
    489                 return rc;
    490         }
    491        
     379
    492380        sysarg_t retval;
    493381        async_wait_for(req, &retval);
    494        
    495         return (int) retval;
     382        if (retval != EOK)
     383                return retval;
     384
     385        return EOK;
    496386}
    497387
     
    502392        log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_recv_dgram_local()");
    503393
    504         /* ICMP and ICMPv6 messages are handled internally */
     394        /* ICMP messages are handled internally */
    505395        if (proto == IP_PROTO_ICMP)
    506396                return icmp_recv(dgram);
    507        
    508         if (proto == IP_PROTO_ICMPV6)
    509                 return icmpv6_recv(dgram);
    510397
    511398        client = inet_client_find(proto);
     
    525412
    526413        addr = inet_addrobj_find(&packet->dest, iaf_addr);
    527         if ((addr != NULL) ||
    528             (inet_naddr_compare_mask(&solicited_node_mask, &packet->dest)) ||
    529             (inet_addr_compare(&multicast_all_nodes, &packet->dest))) {
     414        if (addr != NULL) {
    530415                /* Destined for one of the local addresses */
    531416
Note: See TracChangeset for help on using the changeset viewer.