Changeset 98abd40 in mainline for uspace/srv/net/inetsrv/inetsrv.c


Ignore:
Timestamp:
2013-07-06T21:57:22Z (12 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
c8bb1633, cdc8a391
Parents:
b8e72fd1 (diff), 507c6f3 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes

File:
1 edited

Legend:

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

    rb8e72fd1 r98abd40  
    4646#include <stdlib.h>
    4747#include <sys/types.h>
    48 
     48#include <net/socket_codes.h>
    4949#include "addrobj.h"
    5050#include "icmp.h"
    5151#include "icmp_std.h"
     52#include "icmpv6.h"
     53#include "icmpv6_std.h"
    5254#include "inetsrv.h"
    5355#include "inetcfg.h"
    5456#include "inetping.h"
     57#include "inetping6.h"
    5558#include "inet_link.h"
    5659#include "reass.h"
     
    9396        rc = loc_service_register_with_iface(SERVICE_NAME_INETPING, &sid,
    9497            INET_PORT_PING);
     98        if (rc != EOK) {
     99                log_msg(LOG_DEFAULT, LVL_ERROR, "Failed registering service (%d).", rc);
     100                return EEXIST;
     101        }
     102       
     103        rc = loc_service_register_with_iface(SERVICE_NAME_INETPING6, &sid,
     104            INET_PORT_PING6);
    95105        if (rc != EOK) {
    96106                log_msg(LOG_DEFAULT, LVL_ERROR, "Failed registering service (%d).", rc);
     
    104114        }
    105115
    106         sroute->dest.ipv4 = 0;
    107         sroute->dest.bits = 0;
    108         sroute->router.ipv4 = (10 << 24) | (0 << 16) | (2 << 8) | 2;
     116        inet_naddr(&sroute->dest, 0, 0, 0, 0, 0);
     117        inet_addr(&sroute->router, 10, 0, 2, 2);
    109118        sroute->name = str_dup("default");
    110119        inet_sroute_add(sroute);
    111120
    112         rc = inet_link_discovery_start();
     121        rc = inet_link_discovery_start();
    113122        if (rc != EOK)
    114123                return EEXIST;
     
    194203
    195204        /* Take source address from the address object */
    196         local->ipv4 = dir.aobj->naddr.ipv4;
     205        inet_naddr_addr(&dir.aobj->naddr, local);
    197206        return EOK;
    198207}
    199208
    200 static void inet_get_srcaddr_srv(inet_client_t *client, ipc_callid_t callid,
    201     ipc_call_t *call)
    202 {
     209static void inet_get_srcaddr_srv(inet_client_t *client, ipc_callid_t iid,
     210    ipc_call_t *icall)
     211{
     212        log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_get_srcaddr_srv()");
     213       
     214        uint8_t tos = IPC_GET_ARG1(*icall);
     215       
     216        ipc_callid_t callid;
     217        size_t size;
     218        if (!async_data_write_receive(&callid, &size)) {
     219                async_answer_0(callid, EREFUSED);
     220                async_answer_0(iid, EREFUSED);
     221                return;
     222        }
     223       
     224        if (size != sizeof(inet_addr_t)) {
     225                async_answer_0(callid, EINVAL);
     226                async_answer_0(iid, EINVAL);
     227                return;
     228        }
     229       
    203230        inet_addr_t remote;
    204         uint8_t tos;
     231        int rc = async_data_write_finalize(callid, &remote, size);
     232        if (rc != EOK) {
     233                async_answer_0(callid, rc);
     234                async_answer_0(iid, rc);
     235        }
     236       
    205237        inet_addr_t local;
    206         int rc;
    207 
    208         log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_get_srcaddr_srv()");
    209 
    210         remote.ipv4 = IPC_GET_ARG1(*call);
    211         tos = IPC_GET_ARG2(*call);
    212         local.ipv4 = 0;
    213 
    214238        rc = inet_get_srcaddr(&remote, tos, &local);
    215         async_answer_1(callid, rc, local.ipv4);
    216 }
    217 
    218 static void inet_send_srv(inet_client_t *client, ipc_callid_t callid,
    219     ipc_call_t *call)
    220 {
     239        if (rc != EOK) {
     240                async_answer_0(iid, rc);
     241                return;
     242        }
     243       
     244        if (!async_data_read_receive(&callid, &size)) {
     245                async_answer_0(callid, EREFUSED);
     246                async_answer_0(iid, EREFUSED);
     247                return;
     248        }
     249       
     250        if (size != sizeof(inet_addr_t)) {
     251                async_answer_0(callid, EINVAL);
     252                async_answer_0(iid, EINVAL);
     253                return;
     254        }
     255       
     256        rc = async_data_read_finalize(callid, &local, size);
     257        if (rc != EOK) {
     258                async_answer_0(callid, rc);
     259                async_answer_0(iid, rc);
     260                return;
     261        }
     262       
     263        async_answer_0(iid, rc);
     264}
     265
     266static void inet_send_srv(inet_client_t *client, ipc_callid_t iid,
     267    ipc_call_t *icall)
     268{
     269        log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_send_srv()");
     270       
    221271        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);
     272       
     273        dgram.tos = IPC_GET_ARG1(*icall);
     274       
     275        uint8_t ttl = IPC_GET_ARG2(*icall);
     276        int df = IPC_GET_ARG3(*icall);
     277       
     278        ipc_callid_t callid;
     279        size_t size;
     280        if (!async_data_write_receive(&callid, &size)) {
     281                async_answer_0(callid, EREFUSED);
     282                async_answer_0(iid, EREFUSED);
     283                return;
     284        }
     285       
     286        if (size != sizeof(inet_addr_t)) {
     287                async_answer_0(callid, EINVAL);
     288                async_answer_0(iid, EINVAL);
     289                return;
     290        }
     291       
     292        int rc = async_data_write_finalize(callid, &dgram.src, size);
    235293        if (rc != EOK) {
    236294                async_answer_0(callid, rc);
    237                 return;
    238         }
    239 
     295                async_answer_0(iid, rc);
     296        }
     297       
     298        if (!async_data_write_receive(&callid, &size)) {
     299                async_answer_0(callid, EREFUSED);
     300                async_answer_0(iid, EREFUSED);
     301                return;
     302        }
     303       
     304        if (size != sizeof(inet_addr_t)) {
     305                async_answer_0(callid, EINVAL);
     306                async_answer_0(iid, EINVAL);
     307                return;
     308        }
     309       
     310        rc = async_data_write_finalize(callid, &dgram.dest, size);
     311        if (rc != EOK) {
     312                async_answer_0(callid, rc);
     313                async_answer_0(iid, rc);
     314        }
     315       
     316        rc = async_data_write_accept(&dgram.data, false, 0, 0, 0,
     317            &dgram.size);
     318        if (rc != EOK) {
     319                async_answer_0(iid, rc);
     320                return;
     321        }
     322       
    240323        rc = inet_send(client, &dgram, client->protocol, ttl, df);
    241 
     324       
    242325        free(dgram.data);
    243         async_answer_0(callid, rc);
     326        async_answer_0(iid, rc);
    244327}
    245328
     
    339422                inetping_conn(iid, icall, arg);
    340423                break;
     424        case INET_PORT_PING6:
     425                inetping6_conn(iid, icall, arg);
     426                break;
    341427        default:
    342428                async_answer_0(iid, ENOTSUP);
     
    366452{
    367453        async_exch_t *exch = async_exchange_begin(client->sess);
    368 
     454       
    369455        ipc_call_t answer;
    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) {
     456        aid_t req = async_send_1(exch, INET_EV_RECV, dgram->tos, &answer);
     457       
     458        int rc = async_data_write_start(exch, &dgram->src, sizeof(inet_addr_t));
     459        if (rc != EOK) {
     460                async_exchange_end(exch);
    376461                async_forget(req);
    377462                return rc;
    378463        }
    379 
     464       
     465        rc = async_data_write_start(exch, &dgram->dest, sizeof(inet_addr_t));
     466        if (rc != EOK) {
     467                async_exchange_end(exch);
     468                async_forget(req);
     469                return rc;
     470        }
     471       
     472        rc = async_data_write_start(exch, dgram->data, dgram->size);
     473       
     474        async_exchange_end(exch);
     475       
     476        if (rc != EOK) {
     477                async_forget(req);
     478                return rc;
     479        }
     480       
    380481        sysarg_t retval;
    381482        async_wait_for(req, &retval);
    382         if (retval != EOK)
    383                 return retval;
    384 
    385         return EOK;
     483       
     484        return (int) retval;
    386485}
    387486
     
    392491        log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_recv_dgram_local()");
    393492
    394         /* ICMP messages are handled internally */
     493        /* ICMP and ICMPv6 messages are handled internally */
    395494        if (proto == IP_PROTO_ICMP)
    396495                return icmp_recv(dgram);
     496       
     497        if (proto == IP_PROTO_ICMPV6)
     498                return icmpv6_recv(dgram);
    397499
    398500        client = inet_client_find(proto);
Note: See TracChangeset for help on using the changeset viewer.