Changeset 8bf672d in mainline


Ignore:
Timestamp:
2012-03-30T17:42:11Z (12 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
66a272f8
Parents:
3b3c689
Message:

Static route configuration.

Location:
uspace
Files:
4 added
10 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/inetcfg/inetcfg.c

    r3b3c689 r8bf672d  
    5151        printf("\t" NAME " create <addr>/<width> <link-name> <addr-name>\n");
    5252        printf("\t" NAME " delete <link-name> <addr-name>\n");
     53        printf("\t" NAME " add-sr <dest-addr>/<width> <router-addr> <route-name>\n");
     54        printf("\t" NAME " del-sr <route-name>\n");
    5355}
    5456
     
    8284        }
    8385
    84         if (bits < 1 || bits > 31)
     86        if (bits > 31)
    8587                return EINVAL;
    8688
    8789        naddr->bits = bits;
     90        return EOK;
     91}
     92
     93static int addr_parse(const char *text, inet_addr_t *addr)
     94{
     95        unsigned long a[4];
     96        char *cp = (char *)text;
     97        int i;
     98
     99        for (i = 0; i < 3; i++) {
     100                a[i] = strtoul(cp, &cp, 10);
     101                if (*cp != '.')
     102                        return EINVAL;
     103                ++cp;
     104        }
     105
     106        a[3] = strtoul(cp, &cp, 10);
     107        if (*cp != '\0')
     108                return EINVAL;
     109
     110        addr->ipv4 = 0;
     111        for (i = 0; i < 4; i++) {
     112                if (a[i] > 255)
     113                        return EINVAL;
     114                addr->ipv4 = (addr->ipv4 << 8) | a[i];
     115        }
     116
    88117        return EOK;
    89118}
     
    103132}
    104133
     134static int addr_format(inet_addr_t *addr, char **bufp)
     135{
     136        int rc;
     137
     138        rc = asprintf(bufp, "%d.%d.%d.%d", addr->ipv4 >> 24,
     139            (addr->ipv4 >> 16) & 0xff, (addr->ipv4 >> 8) & 0xff,
     140            addr->ipv4 & 0xff);
     141
     142        if (rc < 0)
     143                return ENOMEM;
     144
     145        return EOK;
     146}
     147
    105148static int addr_create_static(int argc, char *argv[])
    106149{
     
    138181        rc = naddr_parse(addr_spec, &naddr);
    139182        if (rc != EOK) {
    140                 printf(NAME ": Invalid address format '%s'.\n", addr_spec);
     183                printf(NAME ": Invalid network address format '%s'.\n",
     184                    addr_spec);
    141185                return EINVAL;
    142186        }
     
    197241}
    198242
     243static int sroute_create(int argc, char *argv[])
     244{
     245        char *dest_str;
     246        char *router_str;
     247        char *route_name;
     248
     249        inet_naddr_t dest;
     250        inet_addr_t router;
     251        sysarg_t sroute_id;
     252        int rc;
     253
     254        if (argc < 3) {
     255                printf(NAME ": Missing arguments.\n");
     256                print_syntax();
     257                return EINVAL;
     258        }
     259
     260        if (argc > 3) {
     261                printf(NAME ": Too many arguments.\n");
     262                print_syntax();
     263                return EINVAL;
     264        }
     265
     266        dest_str   = argv[0];
     267        router_str = argv[1];
     268        route_name = argv[2];
     269
     270        rc = naddr_parse(dest_str, &dest);
     271        if (rc != EOK) {
     272                printf(NAME ": Invalid network address format '%s'.\n",
     273                    dest_str);
     274                return EINVAL;
     275        }
     276
     277        rc = addr_parse(router_str, &router);
     278        if (rc != EOK) {
     279                printf(NAME ": Invalid address format '%s'.\n", router_str);
     280                return EINVAL;
     281        }
     282
     283        rc = inetcfg_sroute_create(route_name, &dest, &router, &sroute_id);
     284        if (rc != EOK) {
     285                printf(NAME ": Failed creating static route '%s' (%d)\n",
     286                    route_name, rc);
     287                return EIO;
     288        }
     289
     290        return EOK;
     291}
     292
     293static int sroute_delete(int argc, char *argv[])
     294{
     295        char *route_name;
     296        sysarg_t sroute_id;
     297        int rc;
     298
     299        if (argc < 1) {
     300                printf(NAME ": Missing arguments.\n");
     301                print_syntax();
     302                return EINVAL;
     303        }
     304
     305        if (argc > 1) {
     306                printf(NAME ": Too many arguments.\n");
     307                print_syntax();
     308                return EINVAL;
     309        }
     310
     311        route_name = argv[0];
     312
     313        rc = inetcfg_sroute_get_id(route_name, &sroute_id);
     314        if (rc != EOK) {
     315                printf(NAME ": Static route '%s' not found (%d).\n",
     316                    route_name, rc);
     317                return ENOENT;
     318        }
     319
     320        rc = inetcfg_sroute_delete(sroute_id);
     321        if (rc != EOK) {
     322                printf(NAME ": Failed deleting static route '%s' (%d)\n",
     323                    route_name, rc);
     324                return EIO;
     325        }
     326
     327        return EOK;
     328}
     329
    199330static int addr_list(void)
    200331{
     
    213344                return rc;
    214345        }
     346
     347        printf("Configured addresses:\n");
     348
     349        ainfo.name = linfo.name = astr = NULL;
    215350
    216351        for (i = 0; i < count; i++) {
     
    219354                        printf("Failed getting properties of address %zu.\n",
    220355                            (size_t)addr_list[i]);
     356                        ainfo.name = NULL;
    221357                        continue;
    222358                }
     
    226362                        printf("Failed getting properties of link %zu.\n",
    227363                            (size_t)ainfo.ilink);
     364                        linfo.name = NULL;
    228365                        continue;
    229366                }
     
    232369                if (rc != EOK) {
    233370                        printf("Memory allocation failed.\n");
     371                        astr = NULL;
    234372                        goto out;
    235373                }
    236374
    237                 printf("%s %s %s\n", astr, linfo.name,
     375                printf("    %s %s %s\n", astr, linfo.name,
    238376                    ainfo.name);
    239377
    240                 free(astr);
    241378                free(ainfo.name);
    242379                free(linfo.name);
    243         }
     380                free(astr);
     381
     382                ainfo.name = linfo.name = astr = NULL;
     383        }
     384
     385        if (count == 0)
     386                printf("    None\n");
    244387out:
     388        if (ainfo.name != NULL)
     389                free(ainfo.name);
     390        if (linfo.name != NULL)
     391                free(linfo.name);
     392        if (astr != NULL)
     393                free(astr);
     394
    245395        free(addr_list);
     396
     397        return EOK;
     398}
     399
     400static int sroute_list(void)
     401{
     402        sysarg_t *sroute_list;
     403        inet_sroute_info_t srinfo;
     404
     405        size_t count;
     406        size_t i;
     407        int rc;
     408        char *dest_str;
     409        char *router_str;
     410
     411        rc = inetcfg_get_sroute_list(&sroute_list, &count);
     412        if (rc != EOK) {
     413                printf(NAME ": Failed getting address list.\n");
     414                return rc;
     415        }
     416
     417        printf("Static routes:\n");
     418
     419        srinfo.name = dest_str = router_str = NULL;
     420
     421        for (i = 0; i < count; i++) {
     422                rc = inetcfg_sroute_get(sroute_list[i], &srinfo);
     423                if (rc != EOK) {
     424                        printf("Failed getting properties of static route %zu.\n",
     425                            (size_t)sroute_list[i]);
     426                        srinfo.name = NULL;
     427                        continue;
     428                }
     429
     430                rc = naddr_format(&srinfo.dest, &dest_str);
     431                if (rc != EOK) {
     432                        printf("Memory allocation failed.\n");
     433                        dest_str = NULL;
     434                        goto out;
     435                }
     436
     437                rc = addr_format(&srinfo.router, &router_str);
     438                if (rc != EOK) {
     439                        printf("Memory allocation failed.\n");
     440                        router_str = NULL;
     441                        goto out;
     442                }
     443
     444                printf("    %s %s %s\n", dest_str, router_str, srinfo.name);
     445
     446                free(srinfo.name);
     447                free(dest_str);
     448                free(router_str);
     449
     450                router_str = srinfo.name = dest_str = NULL;
     451        }
     452
     453        if (count == 0)
     454                printf("    None\n");
     455out:
     456        if (srinfo.name != NULL)
     457                free(srinfo.name);
     458        if (dest_str != NULL)
     459                free(dest_str);
     460        if (router_str != NULL)
     461                free(router_str);
     462
     463        free(sroute_list);
    246464
    247465        return EOK;
     
    261479        if (argc < 2) {
    262480                rc = addr_list();
     481                if (rc != EOK)
     482                        return 1;
     483                rc = sroute_list();
    263484                if (rc != EOK)
    264485                        return 1;
     
    274495                if (rc != EOK)
    275496                        return 1;
     497        } else if (str_cmp(argv[1], "add-sr") == 0) {
     498                rc = sroute_create(argc - 2, argv + 2);
     499                if (rc != EOK)
     500                        return 1;
     501        } else if (str_cmp(argv[1], "del-sr") == 0) {
     502                rc = sroute_delete(argc - 2, argv + 2);
     503                if (rc != EOK)
     504                        return 1;
    276505        } else {
    277506                printf(NAME ": Unknown command '%s'.\n", argv[1]);
  • uspace/lib/c/generic/inetcfg.c

    r3b3c689 r8bf672d  
    238238}
    239239
     240int inetcfg_get_sroute_list(sysarg_t **sroutes, size_t *count)
     241{
     242        return inetcfg_get_ids_internal(INETCFG_GET_SROUTE_LIST,
     243            0, sroutes, count);
     244}
     245
    240246int inetcfg_link_get(sysarg_t link_id, inet_link_info_t *linfo)
    241247{
     
    274280}
    275281
     282int inetcfg_sroute_create(const char *name, inet_naddr_t *dest,
     283    inet_addr_t *router, sysarg_t *sroute_id)
     284{
     285        async_exch_t *exch = async_exchange_begin(inetcfg_sess);
     286
     287        ipc_call_t answer;
     288        aid_t req = async_send_3(exch, INETCFG_SROUTE_CREATE,
     289            dest->ipv4, dest->bits, router->ipv4, &answer);
     290        sysarg_t retval = async_data_write_start(exch, name, str_size(name));
     291
     292        async_exchange_end(exch);
     293
     294        if (retval != EOK) {
     295                async_wait_for(req, NULL);
     296                return retval;
     297        }
     298
     299        async_wait_for(req, &retval);
     300        *sroute_id = IPC_GET_ARG1(answer);
     301
     302        return retval;
     303}
     304
     305int inetcfg_sroute_delete(sysarg_t sroute_id)
     306{
     307        async_exch_t *exch = async_exchange_begin(inetcfg_sess);
     308
     309        int rc = async_req_1_0(exch, INETCFG_SROUTE_DELETE, sroute_id);
     310        async_exchange_end(exch);
     311
     312        return rc;
     313}
     314
     315int inetcfg_sroute_get(sysarg_t sroute_id, inet_sroute_info_t *srinfo)
     316{
     317        ipc_call_t dreply;
     318        sysarg_t dretval;
     319        size_t act_size;
     320        char name_buf[LOC_NAME_MAXLEN + 1];
     321
     322        async_exch_t *exch = async_exchange_begin(inetcfg_sess);
     323
     324        ipc_call_t answer;
     325        aid_t req = async_send_1(exch, INETCFG_SROUTE_GET, sroute_id, &answer);
     326        aid_t dreq = async_data_read(exch, name_buf, LOC_NAME_MAXLEN, &dreply);
     327        async_wait_for(dreq, &dretval);
     328
     329        async_exchange_end(exch);
     330
     331        if (dretval != EOK) {
     332                async_wait_for(req, NULL);
     333                return dretval;
     334        }
     335
     336        sysarg_t retval;
     337        async_wait_for(req, &retval);
     338
     339        if (retval != EOK)
     340                return retval;
     341
     342        act_size = IPC_GET_ARG2(dreply);
     343        assert(act_size <= LOC_NAME_MAXLEN);
     344        name_buf[act_size] = '\0';
     345
     346        srinfo->dest.ipv4 = IPC_GET_ARG1(answer);
     347        srinfo->dest.bits = IPC_GET_ARG2(answer);
     348        srinfo->router.ipv4 = IPC_GET_ARG3(answer);
     349        srinfo->name = str_dup(name_buf);
     350
     351        return EOK;
     352}
     353
     354int inetcfg_sroute_get_id(const char *name, sysarg_t *sroute_id)
     355{
     356        async_exch_t *exch = async_exchange_begin(inetcfg_sess);
     357
     358        ipc_call_t answer;
     359        aid_t req = async_send_0(exch, INETCFG_SROUTE_GET_ID, &answer);
     360        sysarg_t retval = async_data_write_start(exch, name, str_size(name));
     361
     362        async_exchange_end(exch);
     363
     364        if (retval != EOK) {
     365                async_wait_for(req, NULL);
     366                return retval;
     367        }
     368
     369        async_wait_for(req, &retval);
     370        *sroute_id = IPC_GET_ARG1(answer);
     371
     372        return retval;
     373}
     374
    276375/** @}
    277376 */
  • uspace/lib/c/include/inet/inetcfg.h

    r3b3c689 r8bf672d  
    6363} inet_link_info_t;
    6464
     65/** Static route info */
     66typedef struct {
     67        /** Destination network address */
     68        inet_naddr_t dest;
     69        /** Router address */
     70        inet_addr_t router;
     71        /** Static route name */
     72        char *name;
     73} inet_sroute_info_t;
     74
    6575extern int inetcfg_init(void);
    6676extern int inetcfg_addr_create_static(const char *, inet_naddr_t *, sysarg_t, sysarg_t *);
     
    7080extern int inetcfg_get_addr_list(sysarg_t **, size_t *);
    7181extern int inetcfg_get_link_list(sysarg_t **, size_t *);
     82extern int inetcfg_get_sroute_list(sysarg_t **, size_t *);
    7283extern int inetcfg_link_get(sysarg_t, inet_link_info_t *);
     84extern int inetcfg_sroute_get(sysarg_t, inet_sroute_info_t *);
     85extern int inetcfg_sroute_get_id(const char *, sysarg_t *);
     86extern int inetcfg_sroute_create(const char *, inet_naddr_t *, inet_addr_t *,
     87    sysarg_t *);
     88extern int inetcfg_sroute_delete(sysarg_t);
    7389
    7490#endif
  • uspace/lib/c/include/ipc/inet.h

    r3b3c689 r8bf672d  
    6969        INETCFG_GET_ADDR_LIST,
    7070        INETCFG_GET_LINK_LIST,
     71        INETCFG_GET_SROUTE_LIST,
    7172        INETCFG_LINK_GET,
     73        INETCFG_SROUTE_CREATE,
     74        INETCFG_SROUTE_DELETE,
     75        INETCFG_SROUTE_GET,
     76        INETCFG_SROUTE_GET_ID
    7277} inetcfg_request_t;
    7378
  • uspace/srv/inet/Makefile

    r3b3c689 r8bf672d  
    3535        inet.c \
    3636        inet_link.c \
     37        inet_util.c \
    3738        inetcfg.c \
    3839        inetping.c \
    39         pdu.c
     40        pdu.c \
     41        sroute.c
    4042
    4143include $(USPACE_PREFIX)/Makefile.common
  • uspace/srv/inet/addrobj.c

    r3b3c689 r8bf672d  
    4646#include "inet.h"
    4747#include "inet_link.h"
     48#include "inet_util.h"
    4849
    4950static FIBRIL_MUTEX_INITIALIZE(addr_list_lock);
    5051static LIST_INITIALIZE(addr_list);
    5152static sysarg_t addr_id = 0;
    52 
    53 static uint32_t inet_netmask(int bits)
    54 {
    55         assert(bits >= 1);
    56         assert(bits < 32);
    57 
    58         return BIT_RANGE(uint32_t, 31, 31 - (bits - 1));
    59 }
    6053
    6154inet_addrobj_t *inet_addrobj_new(void)
     
    162155}
    163156
    164 /** Find address object matching address @a addr.
     157/** Find address object with the given ID.
    165158 *
    166159 * @param id    Address object ID
     
    188181}
    189182
    190 /** Send datagram to directly reachable destination */
    191 int inet_addrobj_send_dgram(inet_addrobj_t *addr, inet_dgram_t *dgram,
    192     uint8_t proto, uint8_t ttl, int df)
     183/** Send datagram from address object */
     184int inet_addrobj_send_dgram(inet_addrobj_t *addr, inet_addr_t *ldest,
     185    inet_dgram_t *dgram, uint8_t proto, uint8_t ttl, int df)
    193186{
    194187        inet_addr_t lsrc_addr;
  • uspace/srv/inet/addrobj.h

    r3b3c689 r8bf672d  
    5555extern inet_addrobj_t *inet_addrobj_find_by_name(const char *, inet_link_t *);
    5656extern inet_addrobj_t *inet_addrobj_get_by_id(sysarg_t);
    57 extern int inet_addrobj_send_dgram(inet_addrobj_t *, inet_dgram_t *,
    58     uint8_t, uint8_t, int);
     57extern int inet_addrobj_send_dgram(inet_addrobj_t *, inet_addr_t *,
     58    inet_dgram_t *, uint8_t, uint8_t, int);
    5959extern int inet_addrobj_get_id_list(sysarg_t **, size_t *);
    6060
  • uspace/srv/inet/inet.c

    r3b3c689 r8bf672d  
    5454#include "inetping.h"
    5555#include "inet_link.h"
     56#include "sroute.h"
    5657
    5758#define NAME "inet"
     
    120121}
    121122
     123static int inet_find_dir(inet_addr_t *src, inet_addr_t *dest, uint8_t tos,
     124    inet_dir_t *dir)
     125{
     126        inet_sroute_t *sr;
     127
     128        /* XXX Handle case where source address is specified */
     129        (void) src;
     130
     131        dir->aobj = inet_addrobj_find(dest, iaf_net);
     132        if (dir->aobj != NULL) {
     133                dir->ldest = *dest;
     134                dir->dtype = dt_direct;
     135        } else {
     136                /* No direct path, try using a static route */
     137                sr = inet_sroute_find(dest);
     138                if (sr != NULL) {
     139                        dir->aobj = inet_addrobj_find(&sr->router, iaf_net);
     140                        dir->ldest = sr->router;
     141                        dir->dtype = dt_router;
     142                }
     143        }
     144
     145        if (dir->aobj == NULL) {
     146                log_msg(LVL_DEBUG, "inet_send: No route to destination.");
     147                return ENOENT;
     148        }
     149
     150        return EOK;
     151}
     152
    122153int inet_route_packet(inet_dgram_t *dgram, uint8_t proto, uint8_t ttl,
    123154    int df)
    124155{
    125         inet_addrobj_t *addr;
    126 
    127         addr = inet_addrobj_find(&dgram->dest, iaf_net);
    128         if (addr != NULL) {
    129                 /* Destination is directly accessible */
    130                 return inet_addrobj_send_dgram(addr, dgram, proto, ttl, df);
    131         }
    132 
    133         /* TODO: Gateways */
    134         log_msg(LVL_DEBUG, "inet_send: No route to destination.");
    135         return ENOENT;
     156        inet_dir_t dir;
     157        int rc;
     158
     159        rc = inet_find_dir(&dgram->src, &dgram->dest, dgram->tos, &dir);
     160        if (rc != EOK)
     161                return rc;
     162
     163        return inet_addrobj_send_dgram(dir.aobj, &dir.ldest, dgram,
     164            proto, ttl, df);
    136165}
    137166
     
    144173int inet_get_srcaddr(inet_addr_t *remote, uint8_t tos, inet_addr_t *local)
    145174{
    146         inet_addrobj_t *addr;
    147 
    148         addr = inet_addrobj_find(remote, iaf_net);
    149         if (addr != NULL) {
    150                 /* Destination is directly accessible */
    151                 local->ipv4 = addr->naddr.ipv4;
    152                 return EOK;
    153         }
    154 
    155         return ENOENT;
     175        inet_dir_t dir;
     176        int rc;
     177
     178        rc = inet_find_dir(NULL, remote, tos, &dir);
     179        if (rc != EOK)
     180                return rc;
     181
     182        /* XXX dt_local? */
     183
     184        /* Take source address from the address object */
     185        local->ipv4 = dir.aobj->naddr.ipv4;
     186        return EOK;
    156187}
    157188
  • uspace/srv/inet/inet.h

    r3b3c689 r8bf672d  
    9090} inet_link_info_t;
    9191
     92/** Static route info */
     93typedef struct {
     94        /** Destination network address */
     95        inet_naddr_t dest;
     96        /** Router address */
     97        inet_addr_t router;
     98        /** Static route name */
     99        char *name;
     100} inet_sroute_info_t;
     101
    92102typedef struct {
    93103        inet_addr_t src;
     
    125135} inet_addrobj_t;
    126136
     137/** Static route configuration */
     138typedef struct {
     139        link_t sroute_list;
     140        sysarg_t id;
     141        /** Destination network */
     142        inet_naddr_t dest;
     143        /** Router via which to route packets */
     144        inet_addr_t router;
     145        char *name;
     146} inet_sroute_t;
     147
     148typedef enum {
     149        /** Destination is on this network node */
     150        dt_local,
     151        /** Destination is directly reachable */
     152        dt_direct,
     153        /** Destination is behind a router */
     154        dt_router
     155} inet_dir_type_t;
     156
     157/** Direction (next hop) to a destination */
     158typedef struct {
     159        /** Route type */
     160        inet_dir_type_t dtype;
     161        /** Address object (direction) */
     162        inet_addrobj_t *aobj;
     163        /** Local destination address */
     164        inet_addr_t ldest;
     165} inet_dir_t;
     166
    127167typedef struct {
    128168        inet_addr_t src;
  • uspace/srv/inet/inetcfg.c

    r3b3c689 r8bf672d  
    4949#include "inet_link.h"
    5050#include "inetcfg.h"
     51#include "sroute.h"
    5152
    5253static int inetcfg_addr_create_static(char *name, inet_naddr_t *naddr,
     
    6667
    6768        addr = inet_addrobj_new();
     69        if (addr == NULL) {
     70                *addr_id = 0;
     71                return ENOMEM;
     72        }
     73
    6874        addr->naddr = *naddr;
    6975        addr->ilink = ilink;
     
    143149}
    144150
     151static int inetcfg_get_sroute_list(sysarg_t **sroutes, size_t *count)
     152{
     153        return inet_sroute_get_id_list(sroutes, count);
     154}
     155
    145156static int inetcfg_link_get(sysarg_t link_id, inet_link_info_t *linfo)
    146157{
     
    153164
    154165        linfo->name = str_dup(ilink->svc_name);
     166        return EOK;
     167}
     168
     169static int inetcfg_sroute_create(char *name, inet_naddr_t *dest,
     170    inet_addr_t *router, sysarg_t *sroute_id)
     171{
     172        inet_sroute_t *sroute;
     173
     174        sroute = inet_sroute_new();
     175        if (sroute == NULL) {
     176                *sroute_id = 0;
     177                return ENOMEM;
     178        }
     179
     180        sroute->dest = *dest;
     181        sroute->router = *router;
     182        sroute->name = str_dup(name);
     183        inet_sroute_add(sroute);
     184
     185        *sroute_id = sroute->id;
     186        return EOK;
     187}
     188
     189static int inetcfg_sroute_delete(sysarg_t sroute_id)
     190{
     191        inet_sroute_t *sroute;
     192
     193        sroute = inet_sroute_get_by_id(sroute_id);
     194        if (sroute == NULL)
     195                return ENOENT;
     196
     197        inet_sroute_remove(sroute);
     198        inet_sroute_delete(sroute);
     199
     200        return EOK;
     201}
     202
     203static int inetcfg_sroute_get(sysarg_t sroute_id, inet_sroute_info_t *srinfo)
     204{
     205        inet_sroute_t *sroute;
     206
     207        sroute = inet_sroute_get_by_id(sroute_id);
     208        if (sroute == NULL)
     209                return ENOENT;
     210
     211        srinfo->dest = sroute->dest;
     212        srinfo->router = sroute->router;
     213        srinfo->name = str_dup(sroute->name);
     214
     215        return EOK;
     216}
     217
     218static int inetcfg_sroute_get_id(char *name, sysarg_t *sroute_id)
     219{
     220        inet_sroute_t *sroute;
     221
     222        sroute = inet_sroute_find_by_name(name);
     223        if (sroute == NULL) {
     224                log_msg(LVL_DEBUG, "Static route '%s' not found.", name);
     225                return ENOENT;
     226        }
     227
     228        *sroute_id = sroute->id;
    155229        return EOK;
    156230}
     
    257331        async_answer_1(callid, rc, addr_id);
    258332}
    259 
    260333
    261334static void inetcfg_get_addr_list_srv(ipc_callid_t callid, ipc_call_t *call)
     
    293366}
    294367
    295 static void inetcfg_link_get_srv(ipc_callid_t callid, ipc_call_t *call)
    296 {
    297         ipc_callid_t rcallid;
    298         size_t max_size;
    299 
    300         sysarg_t link_id;
    301         inet_link_info_t linfo;
    302         int rc;
    303 
    304         link_id = IPC_GET_ARG1(*call);
    305         log_msg(LVL_DEBUG, "inetcfg_link_get_srv()");
    306 
    307         linfo.name = NULL;
    308 
    309         if (!async_data_read_receive(&rcallid, &max_size)) {
    310                 async_answer_0(rcallid, EREFUSED);
    311                 async_answer_0(callid, EREFUSED);
    312                 return;
    313         }
    314 
    315         rc = inetcfg_link_get(link_id, &linfo);
    316         if (rc != EOK) {
    317                 async_answer_0(rcallid, rc);
    318                 async_answer_0(callid, rc);
    319                 return;
    320         }
    321 
    322         sysarg_t retval = async_data_read_finalize(rcallid, linfo.name,
    323             min(max_size, str_size(linfo.name)));
    324         free(linfo.name);
    325 
    326         async_answer_0(callid, retval);
    327 }
    328368
    329369static void inetcfg_get_link_list_srv(ipc_callid_t callid, ipc_call_t *call)
     
    359399}
    360400
     401static void inetcfg_get_sroute_list_srv(ipc_callid_t callid, ipc_call_t *call)
     402{
     403        ipc_callid_t rcallid;
     404        size_t count;
     405        size_t max_size;
     406        size_t act_size;
     407        size_t size;
     408        sysarg_t *id_buf;
     409        int rc;
     410
     411        log_msg(LVL_DEBUG, "inetcfg_get_sroute_list_srv()");
     412
     413        if (!async_data_read_receive(&rcallid, &max_size)) {
     414                async_answer_0(rcallid, EREFUSED);
     415                async_answer_0(callid, EREFUSED);
     416                return;
     417        }
     418
     419        rc = inetcfg_get_sroute_list(&id_buf, &count);
     420        if (rc != EOK) {
     421                async_answer_0(rcallid, rc);
     422                async_answer_0(callid, rc);
     423                return;
     424        }
     425
     426        act_size = count * sizeof(sysarg_t);
     427        size = min(act_size, max_size);
     428
     429        sysarg_t retval = async_data_read_finalize(rcallid, id_buf, size);
     430        free(id_buf);
     431
     432        async_answer_1(callid, retval, act_size);
     433}
     434
     435static void inetcfg_link_get_srv(ipc_callid_t callid, ipc_call_t *call)
     436{
     437        ipc_callid_t rcallid;
     438        size_t max_size;
     439
     440        sysarg_t link_id;
     441        inet_link_info_t linfo;
     442        int rc;
     443
     444        link_id = IPC_GET_ARG1(*call);
     445        log_msg(LVL_DEBUG, "inetcfg_link_get_srv()");
     446
     447        linfo.name = NULL;
     448
     449        if (!async_data_read_receive(&rcallid, &max_size)) {
     450                async_answer_0(rcallid, EREFUSED);
     451                async_answer_0(callid, EREFUSED);
     452                return;
     453        }
     454
     455        rc = inetcfg_link_get(link_id, &linfo);
     456        if (rc != EOK) {
     457                async_answer_0(rcallid, rc);
     458                async_answer_0(callid, rc);
     459                return;
     460        }
     461
     462        sysarg_t retval = async_data_read_finalize(rcallid, linfo.name,
     463            min(max_size, str_size(linfo.name)));
     464        free(linfo.name);
     465
     466        async_answer_0(callid, retval);
     467}
     468
     469static void inetcfg_sroute_create_srv(ipc_callid_t callid,
     470    ipc_call_t *call)
     471{
     472        char *name;
     473        inet_naddr_t dest;
     474        inet_addr_t router;
     475        sysarg_t sroute_id;
     476        int rc;
     477
     478        log_msg(LVL_DEBUG, "inetcfg_sroute_create_srv()");
     479
     480        rc = async_data_write_accept((void **) &name, true, 0, LOC_NAME_MAXLEN,
     481            0, NULL);
     482        if (rc != EOK) {
     483                async_answer_0(callid, rc);
     484                return;
     485        }
     486
     487        dest.ipv4   = IPC_GET_ARG1(*call);
     488        dest.bits   = IPC_GET_ARG2(*call);
     489        router.ipv4 = IPC_GET_ARG3(*call);
     490
     491        sroute_id = 0;
     492        rc = inetcfg_sroute_create(name, &dest, &router, &sroute_id);
     493        free(name);
     494        async_answer_1(callid, rc, sroute_id);
     495}
     496
     497static void inetcfg_sroute_delete_srv(ipc_callid_t callid, ipc_call_t *call)
     498{
     499        sysarg_t sroute_id;
     500        int rc;
     501
     502        log_msg(LVL_DEBUG, "inetcfg_sroute_delete_srv()");
     503
     504        sroute_id = IPC_GET_ARG1(*call);
     505
     506        rc = inetcfg_sroute_delete(sroute_id);
     507        async_answer_0(callid, rc);
     508}
     509
     510static void inetcfg_sroute_get_srv(ipc_callid_t callid, ipc_call_t *call)
     511{
     512        ipc_callid_t rcallid;
     513        size_t max_size;
     514
     515        sysarg_t sroute_id;
     516        inet_sroute_info_t srinfo;
     517        int rc;
     518
     519        sroute_id = IPC_GET_ARG1(*call);
     520        log_msg(LVL_DEBUG, "inetcfg_sroute_get_srv()");
     521
     522        srinfo.dest.ipv4 = 0;
     523        srinfo.dest.bits = 0;
     524        srinfo.router.ipv4 = 0;
     525        srinfo.name = NULL;
     526
     527        if (!async_data_read_receive(&rcallid, &max_size)) {
     528                async_answer_0(rcallid, EREFUSED);
     529                async_answer_0(callid, EREFUSED);
     530                return;
     531        }
     532
     533        rc = inetcfg_sroute_get(sroute_id, &srinfo);
     534        if (rc != EOK) {
     535                async_answer_0(callid, rc);
     536                return;
     537        }
     538
     539        sysarg_t retval = async_data_read_finalize(rcallid, srinfo.name,
     540            min(max_size, str_size(srinfo.name)));
     541        free(srinfo.name);
     542
     543        async_answer_3(callid, retval, srinfo.dest.ipv4, srinfo.dest.bits,
     544            srinfo.router.ipv4);
     545}
     546
     547static void inetcfg_sroute_get_id_srv(ipc_callid_t callid, ipc_call_t *call)
     548{
     549        char *name;
     550        sysarg_t sroute_id;
     551        int rc;
     552
     553        log_msg(LVL_DEBUG, "inetcfg_sroute_get_id_srv()");
     554
     555        rc = async_data_write_accept((void **) &name, true, 0, LOC_NAME_MAXLEN,
     556            0, NULL);
     557        if (rc != EOK) {
     558                async_answer_0(callid, rc);
     559                return;
     560        }
     561
     562        sroute_id = 0;
     563        rc = inetcfg_sroute_get_id(name, &sroute_id);
     564        free(name);
     565        async_answer_1(callid, rc, sroute_id);
     566}
     567
    361568void inet_cfg_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg)
    362569{
     
    396603                        inetcfg_get_link_list_srv(callid, &call);
    397604                        break;
     605                case INETCFG_GET_SROUTE_LIST:
     606                        inetcfg_get_sroute_list_srv(callid, &call);
     607                        break;
    398608                case INETCFG_LINK_GET:
    399609                        inetcfg_link_get_srv(callid, &call);
     610                        break;
     611                case INETCFG_SROUTE_CREATE:
     612                        inetcfg_sroute_create_srv(callid, &call);
     613                        break;
     614                case INETCFG_SROUTE_DELETE:
     615                        inetcfg_sroute_delete_srv(callid, &call);
     616                        break;
     617                case INETCFG_SROUTE_GET:
     618                        inetcfg_sroute_get_srv(callid, &call);
     619                        break;
     620                case INETCFG_SROUTE_GET_ID:
     621                        inetcfg_sroute_get_id_srv(callid, &call);
    400622                        break;
    401623                default:
Note: See TracChangeset for help on using the changeset viewer.