source: mainline/uspace/srv/net/inetsrv/inetcfg.c@ 3e242d2

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 3e242d2 was 3be9d10, checked in by Jakub Jermar <jakub@…>, 8 years ago

Get rid of ipc_callid_t

  • Property mode set to 100644
File size: 18.0 KB
RevLine 
[0e25780]1/*
[7af0cc5]2 * Copyright (c) 2013 Jiri Svoboda
[0e25780]3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup inet
30 * @{
31 */
32/**
33 * @file
34 * @brief
35 */
36
37#include <async.h>
38#include <errno.h>
39#include <macros.h>
40#include <io/log.h>
41#include <ipc/inet.h>
42#include <loc.h>
43#include <stdlib.h>
[0e94b979]44#include <str.h>
[8d2dd7f2]45#include <stddef.h>
[b8b1adb1]46#include <types/inetcfg.h>
[0e25780]47
[45aa22c]48#include "addrobj.h"
[b4ec1ea]49#include "inetsrv.h"
[45aa22c]50#include "inet_link.h"
[0e25780]51#include "inetcfg.h"
[8bf672d]52#include "sroute.h"
[0e25780]53
[b7fd2a0]54static errno_t inetcfg_addr_create_static(char *name, inet_naddr_t *naddr,
[291c792]55 sysarg_t link_id, sysarg_t *addr_id)
[0e25780]56{
[45aa22c]57 inet_link_t *ilink;
58 inet_addrobj_t *addr;
[a2e3ee6]59 inet_addr_t iaddr;
[b7fd2a0]60 errno_t rc;
[45aa22c]61
62 ilink = inet_link_get_by_id(link_id);
63 if (ilink == NULL) {
[a1a101d]64 log_msg(LOG_DEFAULT, LVL_DEBUG, "Link %lu not found.",
[45aa22c]65 (unsigned long) link_id);
66 return ENOENT;
67 }
68
69 addr = inet_addrobj_new();
[8bf672d]70 if (addr == NULL) {
71 *addr_id = 0;
72 return ENOMEM;
73 }
74
[45aa22c]75 addr->naddr = *naddr;
76 addr->ilink = ilink;
[291c792]77 addr->name = str_dup(name);
[bf9e6fc]78 rc = inet_addrobj_add(addr);
79 if (rc != EOK) {
[a1a101d]80 log_msg(LOG_DEFAULT, LVL_DEBUG, "Duplicate address name '%s'.", addr->name);
[bf9e6fc]81 inet_addrobj_delete(addr);
82 return rc;
83 }
[45aa22c]84
[a2e3ee6]85 inet_naddr_addr(&addr->naddr, &iaddr);
[45aa22c]86 rc = iplink_addr_add(ilink->iplink, &iaddr);
87 if (rc != EOK) {
[a1a101d]88 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed setting IP address on internet link.");
[45aa22c]89 inet_addrobj_remove(addr);
90 inet_addrobj_delete(addr);
91 return rc;
92 }
93
94 return EOK;
[0e25780]95}
96
[b7fd2a0]97static errno_t inetcfg_addr_delete(sysarg_t addr_id)
[0e25780]98{
[fa101c4]99 inet_addrobj_t *addr;
100
101 addr = inet_addrobj_get_by_id(addr_id);
102 if (addr == NULL)
103 return ENOENT;
104
105 inet_addrobj_remove(addr);
106 inet_addrobj_delete(addr);
107
108 return EOK;
[0e25780]109}
110
[b7fd2a0]111static errno_t inetcfg_addr_get(sysarg_t addr_id, inet_addr_info_t *ainfo)
[0e25780]112{
[0e94b979]113 inet_addrobj_t *addr;
114
115 addr = inet_addrobj_get_by_id(addr_id);
116 if (addr == NULL)
117 return ENOENT;
118
119 ainfo->naddr = addr->naddr;
120 ainfo->ilink = addr->ilink->svc_id;
121 ainfo->name = str_dup(addr->name);
122
123 return EOK;
[0e25780]124}
125
[b7fd2a0]126static errno_t inetcfg_addr_get_id(char *name, sysarg_t link_id, sysarg_t *addr_id)
[fa101c4]127{
128 inet_link_t *ilink;
129 inet_addrobj_t *addr;
130
131 ilink = inet_link_get_by_id(link_id);
132 if (ilink == NULL) {
[a1a101d]133 log_msg(LOG_DEFAULT, LVL_DEBUG, "Link %zu not found.", (size_t) link_id);
[fa101c4]134 return ENOENT;
135 }
136
137 addr = inet_addrobj_find_by_name(name, ilink);
138 if (addr == NULL) {
[a1a101d]139 log_msg(LOG_DEFAULT, LVL_DEBUG, "Address '%s' not found.", name);
[fa101c4]140 return ENOENT;
141 }
142
143 *addr_id = addr->id;
144 return EOK;
145}
146
[b7fd2a0]147static errno_t inetcfg_get_addr_list(sysarg_t **addrs, size_t *count)
[0e25780]148{
[0e94b979]149 return inet_addrobj_get_id_list(addrs, count);
[0e25780]150}
151
[b7fd2a0]152static errno_t inetcfg_get_link_list(sysarg_t **addrs, size_t *count)
[0e25780]153{
[b8b1adb1]154 return inet_link_get_id_list(addrs, count);
[0e25780]155}
156
[b7fd2a0]157static errno_t inetcfg_get_sroute_list(sysarg_t **sroutes, size_t *count)
[8bf672d]158{
159 return inet_sroute_get_id_list(sroutes, count);
160}
161
[b7fd2a0]162static errno_t inetcfg_link_add(sysarg_t link_id)
[7af0cc5]163{
164 return inet_link_open(link_id);
165}
166
[b7fd2a0]167static errno_t inetcfg_link_get(sysarg_t link_id, inet_link_info_t *linfo)
[0e25780]168{
[0e94b979]169 inet_link_t *ilink;
170
171 ilink = inet_link_get_by_id(link_id);
172 if (ilink == NULL) {
173 return ENOENT;
174 }
175
176 linfo->name = str_dup(ilink->svc_name);
[347768d]177 linfo->def_mtu = ilink->def_mtu;
[b8b1adb1]178 if (ilink->mac_valid) {
179 addr48(ilink->mac, linfo->mac_addr);
180 } else {
181 memset(linfo->mac_addr, 0, sizeof(linfo->mac_addr));
182 }
183
[0e94b979]184 return EOK;
[0e25780]185}
186
[b7fd2a0]187static errno_t inetcfg_link_remove(sysarg_t link_id)
[7af0cc5]188{
189 return ENOTSUP;
190}
191
[b7fd2a0]192static errno_t inetcfg_sroute_create(char *name, inet_naddr_t *dest,
[8bf672d]193 inet_addr_t *router, sysarg_t *sroute_id)
194{
195 inet_sroute_t *sroute;
196
197 sroute = inet_sroute_new();
198 if (sroute == NULL) {
199 *sroute_id = 0;
200 return ENOMEM;
201 }
202
203 sroute->dest = *dest;
204 sroute->router = *router;
205 sroute->name = str_dup(name);
206 inet_sroute_add(sroute);
207
208 *sroute_id = sroute->id;
209 return EOK;
210}
211
[b7fd2a0]212static errno_t inetcfg_sroute_delete(sysarg_t sroute_id)
[8bf672d]213{
214 inet_sroute_t *sroute;
215
216 sroute = inet_sroute_get_by_id(sroute_id);
217 if (sroute == NULL)
218 return ENOENT;
219
220 inet_sroute_remove(sroute);
221 inet_sroute_delete(sroute);
222
223 return EOK;
224}
225
[b7fd2a0]226static errno_t inetcfg_sroute_get(sysarg_t sroute_id, inet_sroute_info_t *srinfo)
[8bf672d]227{
228 inet_sroute_t *sroute;
229
230 sroute = inet_sroute_get_by_id(sroute_id);
231 if (sroute == NULL)
232 return ENOENT;
233
234 srinfo->dest = sroute->dest;
235 srinfo->router = sroute->router;
236 srinfo->name = str_dup(sroute->name);
237
238 return EOK;
239}
240
[b7fd2a0]241static errno_t inetcfg_sroute_get_id(char *name, sysarg_t *sroute_id)
[8bf672d]242{
243 inet_sroute_t *sroute;
244
245 sroute = inet_sroute_find_by_name(name);
246 if (sroute == NULL) {
[a1a101d]247 log_msg(LOG_DEFAULT, LVL_DEBUG, "Static route '%s' not found.", name);
[8bf672d]248 return ENOENT;
249 }
250
251 *sroute_id = sroute->id;
252 return EOK;
253}
254
[3be9d10]255static void inetcfg_addr_create_static_srv(cap_call_handle_t iid,
[02a09ed]256 ipc_call_t *icall)
[0e25780]257{
[a1a101d]258 log_msg(LOG_DEFAULT, LVL_DEBUG, "inetcfg_addr_create_static_srv()");
[a35b458]259
[02a09ed]260 sysarg_t link_id = IPC_GET_ARG1(*icall);
[a35b458]261
[3be9d10]262 cap_call_handle_t callid;
[02a09ed]263 size_t size;
264 if (!async_data_write_receive(&callid, &size)) {
265 async_answer_0(callid, EINVAL);
266 async_answer_0(iid, EINVAL);
267 return;
268 }
[a35b458]269
[02a09ed]270 if (size != sizeof(inet_naddr_t)) {
271 async_answer_0(callid, EINVAL);
272 async_answer_0(iid, EINVAL);
273 return;
274 }
[a35b458]275
[02a09ed]276 inet_naddr_t naddr;
[b7fd2a0]277 errno_t rc = async_data_write_finalize(callid, &naddr, size);
[02a09ed]278 if (rc != EOK) {
279 async_answer_0(callid, rc);
280 async_answer_0(iid, rc);
281 return;
282 }
[a35b458]283
[02a09ed]284 char *name;
[291c792]285 rc = async_data_write_accept((void **) &name, true, 0, LOC_NAME_MAXLEN,
286 0, NULL);
287 if (rc != EOK) {
[02a09ed]288 async_answer_0(iid, rc);
[291c792]289 return;
290 }
[a35b458]291
[02a09ed]292 sysarg_t addr_id = 0;
[291c792]293 rc = inetcfg_addr_create_static(name, &naddr, link_id, &addr_id);
294 free(name);
[02a09ed]295 async_answer_1(iid, rc, addr_id);
[0e25780]296}
297
[3be9d10]298static void inetcfg_addr_delete_srv(cap_call_handle_t callid, ipc_call_t *call)
[0e25780]299{
300 sysarg_t addr_id;
[b7fd2a0]301 errno_t rc;
[0e25780]302
[a1a101d]303 log_msg(LOG_DEFAULT, LVL_DEBUG, "inetcfg_addr_delete_srv()");
[0e25780]304
305 addr_id = IPC_GET_ARG1(*call);
306
307 rc = inetcfg_addr_delete(addr_id);
308 async_answer_0(callid, rc);
309}
310
[3be9d10]311static void inetcfg_addr_get_srv(cap_call_handle_t iid, ipc_call_t *icall)
[0e25780]312{
[a1a101d]313 log_msg(LOG_DEFAULT, LVL_DEBUG, "inetcfg_addr_get_srv()");
[a35b458]314
[02a09ed]315 sysarg_t addr_id = IPC_GET_ARG1(*icall);
[a35b458]316
[a2e3ee6]317 inet_addr_info_t ainfo;
[a35b458]318
[a2e3ee6]319 inet_naddr_any(&ainfo.naddr);
[0e94b979]320 ainfo.ilink = 0;
321 ainfo.name = NULL;
[a35b458]322
[b7fd2a0]323 errno_t rc = inetcfg_addr_get(addr_id, &ainfo);
[02a09ed]324 if (rc != EOK) {
325 async_answer_0(iid, rc);
326 return;
327 }
[a35b458]328
[3be9d10]329 cap_call_handle_t callid;
[02a09ed]330 size_t size;
331 if (!async_data_read_receive(&callid, &size)) {
[0e94b979]332 async_answer_0(callid, EREFUSED);
[02a09ed]333 async_answer_0(iid, EREFUSED);
[0e94b979]334 return;
335 }
[a35b458]336
[02a09ed]337 if (size != sizeof(inet_naddr_t)) {
338 async_answer_0(callid, EINVAL);
339 async_answer_0(iid, EINVAL);
[0e94b979]340 return;
341 }
[a35b458]342
[02a09ed]343 rc = async_data_read_finalize(callid, &ainfo.naddr, size);
[a2e3ee6]344 if (rc != EOK) {
345 async_answer_0(callid, rc);
[02a09ed]346 async_answer_0(iid, rc);
347 return;
348 }
[a35b458]349
[02a09ed]350 if (!async_data_read_receive(&callid, &size)) {
351 async_answer_0(callid, EREFUSED);
352 async_answer_0(iid, EREFUSED);
[a2e3ee6]353 return;
354 }
[a35b458]355
[02a09ed]356 rc = async_data_read_finalize(callid, ainfo.name,
357 min(size, str_size(ainfo.name)));
[0e94b979]358 free(ainfo.name);
[a35b458]359
[02a09ed]360 if (rc != EOK) {
361 async_answer_0(callid, rc);
362 async_answer_0(iid, rc);
363 return;
364 }
[a35b458]365
[25a179e]366 async_answer_1(iid, rc, ainfo.ilink);
[0e25780]367}
368
[3be9d10]369static void inetcfg_addr_get_id_srv(cap_call_handle_t callid, ipc_call_t *call)
[fa101c4]370{
371 char *name;
372 sysarg_t link_id;
373 sysarg_t addr_id;
[b7fd2a0]374 errno_t rc;
[fa101c4]375
[a1a101d]376 log_msg(LOG_DEFAULT, LVL_DEBUG, "inetcfg_addr_get_id_srv()");
[fa101c4]377
378 link_id = IPC_GET_ARG1(*call);
379
380 rc = async_data_write_accept((void **) &name, true, 0, LOC_NAME_MAXLEN,
381 0, NULL);
382 if (rc != EOK) {
383 async_answer_0(callid, rc);
384 return;
385 }
386
387 addr_id = 0;
388 rc = inetcfg_addr_get_id(name, link_id, &addr_id);
389 free(name);
390 async_answer_1(callid, rc, addr_id);
391}
392
[3be9d10]393static void inetcfg_get_addr_list_srv(cap_call_handle_t callid, ipc_call_t *call)
[0e25780]394{
[3be9d10]395 cap_call_handle_t rcallid;
[0e94b979]396 size_t count;
[0e25780]397 size_t max_size;
398 size_t act_size;
399 size_t size;
400 sysarg_t *id_buf;
[b7fd2a0]401 errno_t rc;
[0e25780]402
[a1a101d]403 log_msg(LOG_DEFAULT, LVL_DEBUG, "inetcfg_get_addr_list_srv()");
[0e25780]404
405 if (!async_data_read_receive(&rcallid, &max_size)) {
406 async_answer_0(rcallid, EREFUSED);
407 async_answer_0(callid, EREFUSED);
408 return;
409 }
410
[0e94b979]411 rc = inetcfg_get_addr_list(&id_buf, &count);
[0e25780]412 if (rc != EOK) {
413 async_answer_0(rcallid, rc);
414 async_answer_0(callid, rc);
415 return;
416 }
417
[0e94b979]418 act_size = count * sizeof(sysarg_t);
[0e25780]419 size = min(act_size, max_size);
420
[b7fd2a0]421 errno_t retval = async_data_read_finalize(rcallid, id_buf, size);
[0e25780]422 free(id_buf);
423
424 async_answer_1(callid, retval, act_size);
425}
426
[3be9d10]427static void inetcfg_get_link_list_srv(cap_call_handle_t callid, ipc_call_t *call)
[8bf672d]428{
[3be9d10]429 cap_call_handle_t rcallid;
[b8b1adb1]430 size_t count;
[8bf672d]431 size_t max_size;
432 size_t act_size;
433 size_t size;
434 sysarg_t *id_buf;
[b7fd2a0]435 errno_t rc;
[8bf672d]436
[b8b1adb1]437 log_msg(LOG_DEFAULT, LVL_DEBUG, "inetcfg_get_addr_list_srv()");
[8bf672d]438
439 if (!async_data_read_receive(&rcallid, &max_size)) {
440 async_answer_0(rcallid, EREFUSED);
441 async_answer_0(callid, EREFUSED);
442 return;
443 }
444
[b8b1adb1]445 rc = inetcfg_get_link_list(&id_buf, &count);
[8bf672d]446 if (rc != EOK) {
447 async_answer_0(rcallid, rc);
448 async_answer_0(callid, rc);
449 return;
450 }
451
[b8b1adb1]452 act_size = count * sizeof(sysarg_t);
[8bf672d]453 size = min(act_size, max_size);
454
[b7fd2a0]455 errno_t retval = async_data_read_finalize(rcallid, id_buf, size);
[8bf672d]456 free(id_buf);
457
458 async_answer_1(callid, retval, act_size);
459}
460
[3be9d10]461static void inetcfg_get_sroute_list_srv(cap_call_handle_t callid, ipc_call_t *call)
[8bf672d]462{
[3be9d10]463 cap_call_handle_t rcallid;
[8bf672d]464 size_t count;
465 size_t max_size;
466 size_t act_size;
467 size_t size;
468 sysarg_t *id_buf;
[b7fd2a0]469 errno_t rc;
[8bf672d]470
[a1a101d]471 log_msg(LOG_DEFAULT, LVL_DEBUG, "inetcfg_get_sroute_list_srv()");
[8bf672d]472
473 if (!async_data_read_receive(&rcallid, &max_size)) {
474 async_answer_0(rcallid, EREFUSED);
475 async_answer_0(callid, EREFUSED);
476 return;
477 }
478
479 rc = inetcfg_get_sroute_list(&id_buf, &count);
480 if (rc != EOK) {
481 async_answer_0(rcallid, rc);
482 async_answer_0(callid, rc);
483 return;
484 }
485
486 act_size = count * sizeof(sysarg_t);
487 size = min(act_size, max_size);
488
[b7fd2a0]489 errno_t retval = async_data_read_finalize(rcallid, id_buf, size);
[8bf672d]490 free(id_buf);
491
492 async_answer_1(callid, retval, act_size);
493}
494
[3be9d10]495static void inetcfg_link_add_srv(cap_call_handle_t callid, ipc_call_t *call)
[7af0cc5]496{
497 sysarg_t link_id;
[b7fd2a0]498 errno_t rc;
[7af0cc5]499
500 log_msg(LOG_DEFAULT, LVL_DEBUG, "inetcfg_link_add_srv()");
501
502 link_id = IPC_GET_ARG1(*call);
503
504 rc = inetcfg_link_add(link_id);
505 async_answer_0(callid, rc);
506}
507
[3be9d10]508static void inetcfg_link_get_srv(cap_call_handle_t callid, ipc_call_t *call)
[0e25780]509{
[3be9d10]510 cap_call_handle_t name_callid;
511 cap_call_handle_t laddr_callid;
[b8b1adb1]512 size_t name_max_size;
513 size_t laddr_max_size;
[0e94b979]514
[0e25780]515 sysarg_t link_id;
516 inet_link_info_t linfo;
[b7fd2a0]517 errno_t rc;
[0e25780]518
519 link_id = IPC_GET_ARG1(*call);
[a1a101d]520 log_msg(LOG_DEFAULT, LVL_DEBUG, "inetcfg_link_get_srv()");
[0e25780]521
[0e94b979]522 linfo.name = NULL;
523
[b8b1adb1]524 if (!async_data_read_receive(&name_callid, &name_max_size)) {
525 async_answer_0(name_callid, EREFUSED);
526 async_answer_0(callid, EREFUSED);
527 return;
528 }
529
530 if (!async_data_read_receive(&laddr_callid, &laddr_max_size)) {
531 async_answer_0(name_callid, EREFUSED);
[0e94b979]532 async_answer_0(callid, EREFUSED);
533 return;
534 }
535
[0e25780]536 rc = inetcfg_link_get(link_id, &linfo);
[0e94b979]537 if (rc != EOK) {
[b8b1adb1]538 async_answer_0(laddr_callid, rc);
539 async_answer_0(name_callid, rc);
[0e94b979]540 async_answer_0(callid, rc);
541 return;
542 }
543
[b7fd2a0]544 errno_t retval = async_data_read_finalize(name_callid, linfo.name,
[b8b1adb1]545 min(name_max_size, str_size(linfo.name)));
546 if (retval != EOK) {
547 free(linfo.name);
548 async_answer_0(laddr_callid, retval);
549 async_answer_0(callid, retval);
550 return;
551 }
552
553 retval = async_data_read_finalize(laddr_callid, &linfo.mac_addr,
554 min(laddr_max_size, sizeof(linfo.mac_addr)));
555
[0e94b979]556 free(linfo.name);
557
[347768d]558 async_answer_1(callid, retval, linfo.def_mtu);
[0e25780]559}
560
[3be9d10]561static void inetcfg_link_remove_srv(cap_call_handle_t callid, ipc_call_t *call)
[7af0cc5]562{
563 sysarg_t link_id;
[b7fd2a0]564 errno_t rc;
[7af0cc5]565
566 log_msg(LOG_DEFAULT, LVL_DEBUG, "inetcfg_link_remove_srv()");
567
568 link_id = IPC_GET_ARG1(*call);
569
570 rc = inetcfg_link_remove(link_id);
571 async_answer_0(callid, rc);
572}
573
[3be9d10]574static void inetcfg_sroute_create_srv(cap_call_handle_t iid,
[02a09ed]575 ipc_call_t *icall)
[8bf672d]576{
[a1a101d]577 log_msg(LOG_DEFAULT, LVL_DEBUG, "inetcfg_sroute_create_srv()");
[02a09ed]578
[3be9d10]579 cap_call_handle_t callid;
[02a09ed]580 size_t size;
581 if (!async_data_write_receive(&callid, &size)) {
582 async_answer_0(callid, EINVAL);
583 async_answer_0(iid, EINVAL);
584 return;
585 }
[a35b458]586
[02a09ed]587 if (size != sizeof(inet_naddr_t)) {
588 async_answer_0(callid, EINVAL);
589 async_answer_0(iid, EINVAL);
590 return;
591 }
[a35b458]592
[02a09ed]593 inet_naddr_t dest;
[b7fd2a0]594 errno_t rc = async_data_write_finalize(callid, &dest, size);
[8bf672d]595 if (rc != EOK) {
596 async_answer_0(callid, rc);
[02a09ed]597 async_answer_0(iid, rc);
598 return;
599 }
[a35b458]600
[02a09ed]601 if (!async_data_write_receive(&callid, &size)) {
602 async_answer_0(callid, EINVAL);
603 async_answer_0(iid, EINVAL);
604 return;
605 }
[a35b458]606
[02a09ed]607 if (size != sizeof(inet_addr_t)) {
608 async_answer_0(callid, EINVAL);
609 async_answer_0(iid, EINVAL);
[8bf672d]610 return;
611 }
[a35b458]612
[a2e3ee6]613 inet_addr_t router;
[02a09ed]614 rc = async_data_write_finalize(callid, &router, size);
615 if (rc != EOK) {
616 async_answer_0(callid, rc);
617 async_answer_0(iid, rc);
618 return;
619 }
[a35b458]620
[02a09ed]621 char *name;
622 rc = async_data_write_accept((void **) &name, true, 0, LOC_NAME_MAXLEN,
623 0, NULL);
624 if (rc != EOK) {
625 async_answer_0(iid, rc);
626 return;
627 }
[a35b458]628
[a2e3ee6]629 sysarg_t sroute_id = 0;
[8bf672d]630 rc = inetcfg_sroute_create(name, &dest, &router, &sroute_id);
631 free(name);
[02a09ed]632 async_answer_1(iid, rc, sroute_id);
[8bf672d]633}
634
[3be9d10]635static void inetcfg_sroute_delete_srv(cap_call_handle_t callid, ipc_call_t *call)
[8bf672d]636{
637 sysarg_t sroute_id;
[b7fd2a0]638 errno_t rc;
[8bf672d]639
[a1a101d]640 log_msg(LOG_DEFAULT, LVL_DEBUG, "inetcfg_sroute_delete_srv()");
[8bf672d]641
642 sroute_id = IPC_GET_ARG1(*call);
643
644 rc = inetcfg_sroute_delete(sroute_id);
645 async_answer_0(callid, rc);
646}
647
[3be9d10]648static void inetcfg_sroute_get_srv(cap_call_handle_t iid, ipc_call_t *icall)
[0e25780]649{
[a1a101d]650 log_msg(LOG_DEFAULT, LVL_DEBUG, "inetcfg_sroute_get_srv()");
[a35b458]651
[02a09ed]652 sysarg_t sroute_id = IPC_GET_ARG1(*icall);
[a35b458]653
[a2e3ee6]654 inet_sroute_info_t srinfo;
[a35b458]655
[a2e3ee6]656 inet_naddr_any(&srinfo.dest);
657 inet_addr_any(&srinfo.router);
[8bf672d]658 srinfo.name = NULL;
[a35b458]659
[b7fd2a0]660 errno_t rc = inetcfg_sroute_get(sroute_id, &srinfo);
[02a09ed]661 if (rc != EOK) {
662 async_answer_0(iid, rc);
663 return;
664 }
[a35b458]665
[3be9d10]666 cap_call_handle_t callid;
[02a09ed]667 size_t size;
668 if (!async_data_read_receive(&callid, &size)) {
[0e25780]669 async_answer_0(callid, EREFUSED);
[02a09ed]670 async_answer_0(iid, EREFUSED);
[0e25780]671 return;
672 }
[a35b458]673
[02a09ed]674 if (size != sizeof(inet_naddr_t)) {
675 async_answer_0(callid, EINVAL);
676 async_answer_0(iid, EINVAL);
[0e25780]677 return;
678 }
[a35b458]679
[02a09ed]680 rc = async_data_read_finalize(callid, &srinfo.dest, size);
[a2e3ee6]681 if (rc != EOK) {
682 async_answer_0(callid, rc);
[02a09ed]683 async_answer_0(iid, rc);
684 return;
685 }
[a35b458]686
[02a09ed]687 if (!async_data_read_receive(&callid, &size)) {
688 async_answer_0(callid, EREFUSED);
689 async_answer_0(iid, EREFUSED);
690 return;
691 }
[a35b458]692
[02a09ed]693 if (size != sizeof(inet_addr_t)) {
694 async_answer_0(callid, EINVAL);
695 async_answer_0(iid, EINVAL);
[a2e3ee6]696 return;
697 }
[a35b458]698
[02a09ed]699 rc = async_data_read_finalize(callid, &srinfo.router, size);
[a2e3ee6]700 if (rc != EOK) {
701 async_answer_0(callid, rc);
[02a09ed]702 async_answer_0(iid, rc);
703 return;
704 }
[a35b458]705
[02a09ed]706 if (!async_data_read_receive(&callid, &size)) {
707 async_answer_0(callid, EREFUSED);
708 async_answer_0(iid, EREFUSED);
[a2e3ee6]709 return;
710 }
[a35b458]711
[02a09ed]712 rc = async_data_read_finalize(callid, srinfo.name,
713 min(size, str_size(srinfo.name)));
[8bf672d]714 free(srinfo.name);
[a35b458]715
[25a179e]716 async_answer_0(iid, rc);
[8bf672d]717}
[0e25780]718
[3be9d10]719static void inetcfg_sroute_get_id_srv(cap_call_handle_t callid, ipc_call_t *call)
[8bf672d]720{
721 char *name;
722 sysarg_t sroute_id;
[b7fd2a0]723 errno_t rc;
[8bf672d]724
[a1a101d]725 log_msg(LOG_DEFAULT, LVL_DEBUG, "inetcfg_sroute_get_id_srv()");
[8bf672d]726
727 rc = async_data_write_accept((void **) &name, true, 0, LOC_NAME_MAXLEN,
728 0, NULL);
729 if (rc != EOK) {
730 async_answer_0(callid, rc);
731 return;
732 }
733
734 sroute_id = 0;
735 rc = inetcfg_sroute_get_id(name, &sroute_id);
736 free(name);
737 async_answer_1(callid, rc, sroute_id);
[0e25780]738}
739
[3be9d10]740void inet_cfg_conn(cap_call_handle_t iid, ipc_call_t *icall, void *arg)
[0e25780]741{
[a1a101d]742 log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_cfg_conn()");
[0e25780]743
744 /* Accept the connection */
745 async_answer_0(iid, EOK);
746
747 while (true) {
748 ipc_call_t call;
[3be9d10]749 cap_call_handle_t callid = async_get_call(&call);
[0e25780]750 sysarg_t method = IPC_GET_IMETHOD(call);
751
[bd88bee]752 log_msg(LOG_DEFAULT, LVL_DEBUG, "method %d", (int)method);
[0e25780]753 if (!method) {
754 /* The other side has hung up */
755 async_answer_0(callid, EOK);
756 return;
757 }
758
759 switch (method) {
760 case INETCFG_ADDR_CREATE_STATIC:
761 inetcfg_addr_create_static_srv(callid, &call);
762 break;
763 case INETCFG_ADDR_DELETE:
764 inetcfg_addr_delete_srv(callid, &call);
765 break;
766 case INETCFG_ADDR_GET:
767 inetcfg_addr_get_srv(callid, &call);
768 break;
[fa101c4]769 case INETCFG_ADDR_GET_ID:
770 inetcfg_addr_get_id_srv(callid, &call);
771 break;
[0e25780]772 case INETCFG_GET_ADDR_LIST:
773 inetcfg_get_addr_list_srv(callid, &call);
774 break;
775 case INETCFG_GET_LINK_LIST:
776 inetcfg_get_link_list_srv(callid, &call);
777 break;
[8bf672d]778 case INETCFG_GET_SROUTE_LIST:
779 inetcfg_get_sroute_list_srv(callid, &call);
780 break;
[7af0cc5]781 case INETCFG_LINK_ADD:
782 inetcfg_link_add_srv(callid, &call);
783 break;
[0e25780]784 case INETCFG_LINK_GET:
785 inetcfg_link_get_srv(callid, &call);
786 break;
[7af0cc5]787 case INETCFG_LINK_REMOVE:
788 inetcfg_link_remove_srv(callid, &call);
789 break;
[8bf672d]790 case INETCFG_SROUTE_CREATE:
791 inetcfg_sroute_create_srv(callid, &call);
792 break;
793 case INETCFG_SROUTE_DELETE:
794 inetcfg_sroute_delete_srv(callid, &call);
795 break;
796 case INETCFG_SROUTE_GET:
797 inetcfg_sroute_get_srv(callid, &call);
798 break;
799 case INETCFG_SROUTE_GET_ID:
800 inetcfg_sroute_get_id_srv(callid, &call);
801 break;
[0e25780]802 default:
803 async_answer_0(callid, EINVAL);
804 }
805 }
806}
807
808/** @}
809 */
Note: See TracBrowser for help on using the repository browser.