Changeset 4c53333 in mainline for uspace/srv/net/inetsrv/inetsrv.c


Ignore:
Timestamp:
2013-07-11T08:21:10Z (12 years ago)
Author:
Maurizio Lombardi <m.lombardi85@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
64e63ce1
Parents:
80445cf (diff), c8bb1633 (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 moved

Legend:

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

    r80445cf r4c53333  
    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 "inet.h"
     52#include "icmpv6.h"
     53#include "icmpv6_std.h"
     54#include "inetsrv.h"
    5355#include "inetcfg.h"
    5456#include "inetping.h"
     57#include "inetping6.h"
    5558#include "inet_link.h"
    5659#include "reass.h"
    5760#include "sroute.h"
    5861
    59 #define NAME "inet"
     62#define NAME "inetsrv"
    6063
    6164static void inet_client_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg);
     
    6669static int inet_init(void)
    6770{
     71        log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_init()");
     72       
     73        async_set_client_connection(inet_client_conn);
     74       
     75        int rc = loc_server_register(NAME);
     76        if (rc != EOK) {
     77                log_msg(LOG_DEFAULT, LVL_ERROR, "Failed registering server (%d).", rc);
     78                return EEXIST;
     79        }
     80       
    6881        service_id_t sid;
    69         int rc;
    70 
    71         log_msg(LVL_DEBUG, "inet_init()");
    72 
    73         async_set_client_connection(inet_client_conn);
    74 
    75         rc = loc_server_register(NAME);
    76         if (rc != EOK) {
    77                 log_msg(LVL_ERROR, "Failed registering server (%d).", rc);
    78                 return EEXIST;
    79         }
    80 
    8182        rc = loc_service_register_with_iface(SERVICE_NAME_INET, &sid,
    8283            INET_PORT_DEFAULT);
    8384        if (rc != EOK) {
    84                 log_msg(LVL_ERROR, "Failed registering service (%d).", rc);
     85                log_msg(LOG_DEFAULT, LVL_ERROR, "Failed registering service (%d).", rc);
    8586                return EEXIST;
    8687        }
    87 
     88       
    8889        rc = loc_service_register_with_iface(SERVICE_NAME_INETCFG, &sid,
    8990            INET_PORT_CFG);
    9091        if (rc != EOK) {
    91                 log_msg(LVL_ERROR, "Failed registering service (%d).", rc);
     92                log_msg(LOG_DEFAULT, LVL_ERROR, "Failed registering service (%d).", rc);
    9293                return EEXIST;
    9394        }
    94 
     95       
    9596        rc = loc_service_register_with_iface(SERVICE_NAME_INETPING, &sid,
    9697            INET_PORT_PING);
    9798        if (rc != EOK) {
    98                 log_msg(LVL_ERROR, "Failed registering service (%d).", rc);
     99                log_msg(LOG_DEFAULT, LVL_ERROR, "Failed registering service (%d).", rc);
    99100                return EEXIST;
    100101        }
     102       
     103        rc = loc_service_register_with_iface(SERVICE_NAME_INETPING6, &sid,
     104            INET_PORT_PING6);
     105        if (rc != EOK) {
     106                log_msg(LOG_DEFAULT, LVL_ERROR, "Failed registering service (%d).", rc);
     107                return EEXIST;
     108        }
     109       
     110        inet_sroute_t *sroute = inet_sroute_new();
     111        if (sroute == NULL) {
     112                log_msg(LOG_DEFAULT, LVL_ERROR, "Failed creating default route (%d).", rc);
     113                return ENOMEM;
     114        }
     115
     116        inet_naddr(&sroute->dest, 0, 0, 0, 0, 0);
     117        inet_addr(&sroute->router, 10, 0, 2, 2);
     118        sroute->name = str_dup("default");
     119        inet_sroute_add(sroute);
    101120
    102121        rc = inet_link_discovery_start();
    103122        if (rc != EOK)
    104123                return EEXIST;
    105 
     124       
    106125        return EOK;
    107126}
     
    110129    ipc_call_t *call)
    111130{
    112         log_msg(LVL_DEBUG, "inet_callback_create_srv()");
     131        log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_callback_create_srv()");
    113132
    114133        async_sess_t *sess = async_callback_receive(EXCHANGE_SERIALIZE);
     
    145164
    146165        if (dir->aobj == NULL) {
    147                 log_msg(LVL_DEBUG, "inet_send: No route to destination.");
     166                log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_send: No route to destination.");
    148167                return ENOENT;
    149168        }
     
    184203
    185204        /* Take source address from the address object */
    186         local->ipv4 = dir.aobj->naddr.ipv4;
     205        inet_naddr_addr(&dir.aobj->naddr, local);
    187206        return EOK;
    188207}
    189208
    190 static void inet_get_srcaddr_srv(inet_client_t *client, ipc_callid_t callid,
    191     ipc_call_t *call)
    192 {
     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       
    193230        inet_addr_t remote;
    194         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       
    195237        inet_addr_t local;
    196         int rc;
    197 
    198         log_msg(LVL_DEBUG, "inet_get_srcaddr_srv()");
    199 
    200         remote.ipv4 = IPC_GET_ARG1(*call);
    201         tos = IPC_GET_ARG2(*call);
    202         local.ipv4 = 0;
    203 
    204238        rc = inet_get_srcaddr(&remote, tos, &local);
    205         async_answer_1(callid, rc, local.ipv4);
    206 }
    207 
    208 static void inet_send_srv(inet_client_t *client, ipc_callid_t callid,
    209     ipc_call_t *call)
    210 {
     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       
    211271        inet_dgram_t dgram;
    212         uint8_t ttl;
    213         int df;
    214         int rc;
    215 
    216         log_msg(LVL_DEBUG, "inet_send_srv()");
    217 
    218         dgram.src.ipv4 = IPC_GET_ARG1(*call);
    219         dgram.dest.ipv4 = IPC_GET_ARG2(*call);
    220         dgram.tos = IPC_GET_ARG3(*call);
    221         ttl = IPC_GET_ARG4(*call);
    222         df = IPC_GET_ARG5(*call);
    223 
    224         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);
    225293        if (rc != EOK) {
    226294                async_answer_0(callid, rc);
    227                 return;
    228         }
    229 
     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       
    230323        rc = inet_send(client, &dgram, client->protocol, ttl, df);
    231 
     324       
    232325        free(dgram.data);
    233         async_answer_0(callid, rc);
     326        async_answer_0(iid, rc);
    234327}
    235328
     
    240333
    241334        proto = IPC_GET_ARG1(*call);
    242         log_msg(LVL_DEBUG, "inet_set_proto_srv(%lu)", (unsigned long) proto);
     335        log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_set_proto_srv(%lu)", (unsigned long) proto);
    243336
    244337        if (proto > UINT8_MAX) {
     
    274367        inet_client_t client;
    275368
    276         log_msg(LVL_DEBUG, "inet_default_conn()");
     369        log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_default_conn()");
    277370
    278371        /* Accept the connection */
     
    329422                inetping_conn(iid, icall, arg);
    330423                break;
     424        case INET_PORT_PING6:
     425                inetping6_conn(iid, icall, arg);
     426                break;
    331427        default:
    332428                async_answer_0(iid, ENOTSUP);
     
    356452{
    357453        async_exch_t *exch = async_exchange_begin(client->sess);
    358 
     454       
    359455        ipc_call_t answer;
    360         aid_t req = async_send_3(exch, INET_EV_RECV, dgram->src.ipv4,
    361             dgram->dest.ipv4, dgram->tos, &answer);
    362         int rc = async_data_write_start(exch, dgram->data, dgram->size);
     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);
     461                async_forget(req);
     462                return rc;
     463        }
     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       
    363474        async_exchange_end(exch);
    364 
    365         if (rc != EOK) {
    366                 async_wait_for(req, NULL);
     475       
     476        if (rc != EOK) {
     477                async_forget(req);
    367478                return rc;
    368479        }
    369 
     480       
    370481        sysarg_t retval;
    371482        async_wait_for(req, &retval);
    372         if (retval != EOK)
    373                 return retval;
    374 
    375         return EOK;
     483       
     484        return (int) retval;
    376485}
    377486
     
    380489        inet_client_t *client;
    381490
    382         log_msg(LVL_DEBUG, "inet_recv_dgram_local()");
    383 
    384         /* ICMP messages are handled internally */
     491        log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_recv_dgram_local()");
     492
     493        /* ICMP and ICMPv6 messages are handled internally */
    385494        if (proto == IP_PROTO_ICMP)
    386495                return icmp_recv(dgram);
     496       
     497        if (proto == IP_PROTO_ICMPV6)
     498                return icmpv6_recv(dgram);
    387499
    388500        client = inet_client_find(proto);
    389501        if (client == NULL) {
    390                 log_msg(LVL_DEBUG, "No client found for protocol 0x%" PRIx8,
     502                log_msg(LOG_DEFAULT, LVL_DEBUG, "No client found for protocol 0x%" PRIx8,
    391503                    proto);
    392504                return ENOENT;
     
    430542        printf(NAME ": HelenOS Internet Protocol service\n");
    431543
    432         if (log_init(NAME, LVL_WARN) != EOK) {
     544        if (log_init(NAME) != EOK) {
    433545                printf(NAME ": Failed to initialize logging.\n");
    434546                return 1;
Note: See TracChangeset for help on using the changeset viewer.