Changeset 06295a9 in mainline


Ignore:
Timestamp:
2012-02-06T12:43:31Z (12 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
bc38578
Parents:
e2e56e67
Message:

NIC discovery in ethip. Create one IP link for each NIC.

Location:
uspace/srv/ethip
Files:
3 added
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/ethip/Makefile

    re2e56e67 r06295a9  
    3131
    3232SOURCES = \
    33         ethip.c
     33        ethip.c \
     34        ethip_nic.c
    3435
    3536include $(USPACE_PREFIX)/Makefile.common
  • uspace/srv/ethip/ethip.c

    re2e56e67 r06295a9  
    4141#include <loc.h>
    4242#include <stdio.h>
     43#include <stdlib.h>
     44
     45#include "ethip.h"
     46#include "ethip_nic.h"
    4347
    4448#define NAME "eth"
     
    5862};
    5963
    60 static iplink_srv_t test_srv;
    61 
    6264static int ethip_init(void)
    6365{
    6466        int rc;
    65         service_id_t sid;
    66         category_id_t iplink_cat;
    67 
    68         test_srv.ops = &ethip_iplink_ops;
    69         test_srv.arg = NULL;
    7067
    7168        async_set_client_connection(ethip_client_conn);
     
    7774        }
    7875
    79         rc = loc_service_register("net/eth0", &sid);
     76        rc = ethip_nic_discovery_start();
     77        if (rc != EOK)
     78                return rc;
     79
     80        return EOK;
     81}
     82
     83int ethip_iplink_init(ethip_nic_t *nic)
     84{
     85        int rc;
     86        service_id_t sid;
     87        category_id_t iplink_cat;
     88        static unsigned link_num = 0;
     89        char *svc_name = NULL;
     90
     91        log_msg(LVL_DEBUG, "ethip_iplink_init()");
     92
     93        nic->iplink.ops = &ethip_iplink_ops;
     94        nic->iplink.arg = nic;
     95
     96        rc = asprintf(&svc_name, "net/eth%u", ++link_num);
     97        if (rc < 0) {
     98                log_msg(LVL_ERROR, "Out of memory.");
     99                goto error;
     100        }
     101
     102        rc = loc_service_register(svc_name, &sid);
    80103        if (rc != EOK) {
    81                 log_msg(LVL_ERROR, "Failed registering service net/eth0.");
    82                 return rc;
     104                log_msg(LVL_ERROR, "Failed registering service %s.", svc_name);
     105                goto error;
    83106        }
    84107
     
    86109        if (rc != EOK) {
    87110                log_msg(LVL_ERROR, "Failed resolving category 'iplink'.");
    88                 return rc;
     111                goto error;
    89112        }
    90113
    91114        rc = loc_service_add_to_cat(sid, iplink_cat);
    92115        if (rc != EOK) {
    93                 log_msg(LVL_ERROR, "Failed adding net/eth0 to category.");
    94                 return rc;
     116                log_msg(LVL_ERROR, "Failed adding %s to category.", svc_name);
     117                goto error;
    95118        }
    96119
    97120        return EOK;
     121
     122error:
     123        if (svc_name != NULL)
     124                free(svc_name);
     125        return rc;
    98126}
    99127
    100128static void ethip_client_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg)
    101129{
    102         log_msg(LVL_DEBUG, "ethip_client_conn()");
    103         iplink_conn(iid, icall, &test_srv);
     130        log_msg(LVL_DEBUG, "ethip_client_conn(%u)", (unsigned) IPC_GET_ARG1(*icall));
     131        if (0) iplink_conn(iid, icall, NULL);
    104132}
    105133
Note: See TracChangeset for help on using the changeset viewer.