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

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

Reduce the number of files that include <sys/types.h>

  • Property mode set to 100644
File size: 17.8 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
[291c792]54static int inetcfg_addr_create_static(char *name, inet_naddr_t *naddr,
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;
[45aa22c]60 int rc;
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
97static int inetcfg_addr_delete(sysarg_t addr_id)
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
111static int inetcfg_addr_get(sysarg_t addr_id, inet_addr_info_t *ainfo)
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
[fa101c4]126static int inetcfg_addr_get_id(char *name, sysarg_t link_id, sysarg_t *addr_id)
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
[0e25780]147static int inetcfg_get_addr_list(sysarg_t **addrs, size_t *count)
148{
[0e94b979]149 return inet_addrobj_get_id_list(addrs, count);
[0e25780]150}
151
152static int inetcfg_get_link_list(sysarg_t **addrs, size_t *count)
153{
[b8b1adb1]154 return inet_link_get_id_list(addrs, count);
[0e25780]155}
156
[8bf672d]157static int inetcfg_get_sroute_list(sysarg_t **sroutes, size_t *count)
158{
159 return inet_sroute_get_id_list(sroutes, count);
160}
161
[7af0cc5]162static int inetcfg_link_add(sysarg_t link_id)
163{
164 return inet_link_open(link_id);
165}
166
[0e94b979]167static int 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
[7af0cc5]187static int inetcfg_link_remove(sysarg_t link_id)
188{
189 return ENOTSUP;
190}
191
[8bf672d]192static int inetcfg_sroute_create(char *name, inet_naddr_t *dest,
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
212static int inetcfg_sroute_delete(sysarg_t sroute_id)
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
226static int inetcfg_sroute_get(sysarg_t sroute_id, inet_sroute_info_t *srinfo)
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
241static int inetcfg_sroute_get_id(char *name, sysarg_t *sroute_id)
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
[02a09ed]255static void inetcfg_addr_create_static_srv(ipc_callid_t iid,
256 ipc_call_t *icall)
[0e25780]257{
[a1a101d]258 log_msg(LOG_DEFAULT, LVL_DEBUG, "inetcfg_addr_create_static_srv()");
[02a09ed]259
260 sysarg_t link_id = IPC_GET_ARG1(*icall);
261
262 ipc_callid_t callid;
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 }
269
270 if (size != sizeof(inet_naddr_t)) {
271 async_answer_0(callid, EINVAL);
272 async_answer_0(iid, EINVAL);
273 return;
274 }
275
276 inet_naddr_t naddr;
277 int rc = async_data_write_finalize(callid, &naddr, size);
278 if (rc != EOK) {
279 async_answer_0(callid, rc);
280 async_answer_0(iid, rc);
281 return;
282 }
283
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 }
[02a09ed]291
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
298static void inetcfg_addr_delete_srv(ipc_callid_t callid, ipc_call_t *call)
299{
300 sysarg_t addr_id;
301 int rc;
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
[02a09ed]311static void inetcfg_addr_get_srv(ipc_callid_t iid, ipc_call_t *icall)
[0e25780]312{
[a1a101d]313 log_msg(LOG_DEFAULT, LVL_DEBUG, "inetcfg_addr_get_srv()");
[a2e3ee6]314
[02a09ed]315 sysarg_t addr_id = IPC_GET_ARG1(*icall);
[a2e3ee6]316
317 inet_addr_info_t ainfo;
318
319 inet_naddr_any(&ainfo.naddr);
[0e94b979]320 ainfo.ilink = 0;
321 ainfo.name = NULL;
[a2e3ee6]322
[02a09ed]323 int rc = inetcfg_addr_get(addr_id, &ainfo);
324 if (rc != EOK) {
325 async_answer_0(iid, rc);
326 return;
327 }
[a2e3ee6]328
[02a09ed]329 ipc_callid_t callid;
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 }
[a2e3ee6]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 }
[a2e3ee6]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 }
349
350 if (!async_data_read_receive(&callid, &size)) {
351 async_answer_0(callid, EREFUSED);
352 async_answer_0(iid, EREFUSED);
[a2e3ee6]353 return;
354 }
355
[02a09ed]356 rc = async_data_read_finalize(callid, ainfo.name,
357 min(size, str_size(ainfo.name)));
[0e94b979]358 free(ainfo.name);
[a2e3ee6]359
[02a09ed]360 if (rc != EOK) {
361 async_answer_0(callid, rc);
362 async_answer_0(iid, rc);
363 return;
364 }
365
366 async_answer_1(iid, (sysarg_t) rc, ainfo.ilink);
[0e25780]367}
368
[fa101c4]369static void inetcfg_addr_get_id_srv(ipc_callid_t callid, ipc_call_t *call)
370{
371 char *name;
372 sysarg_t link_id;
373 sysarg_t addr_id;
374 int rc;
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
[0e25780]393static void inetcfg_get_addr_list_srv(ipc_callid_t callid, ipc_call_t *call)
394{
395 ipc_callid_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;
401 int rc;
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
421 sysarg_t retval = async_data_read_finalize(rcallid, id_buf, size);
422 free(id_buf);
423
424 async_answer_1(callid, retval, act_size);
425}
426
[8bf672d]427static void inetcfg_get_link_list_srv(ipc_callid_t callid, ipc_call_t *call)
428{
429 ipc_callid_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;
435 int rc;
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
455 sysarg_t retval = async_data_read_finalize(rcallid, id_buf, size);
456 free(id_buf);
457
458 async_answer_1(callid, retval, act_size);
459}
460
461static void inetcfg_get_sroute_list_srv(ipc_callid_t callid, ipc_call_t *call)
462{
463 ipc_callid_t rcallid;
464 size_t count;
465 size_t max_size;
466 size_t act_size;
467 size_t size;
468 sysarg_t *id_buf;
469 int rc;
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
489 sysarg_t retval = async_data_read_finalize(rcallid, id_buf, size);
490 free(id_buf);
491
492 async_answer_1(callid, retval, act_size);
493}
494
[7af0cc5]495static void inetcfg_link_add_srv(ipc_callid_t callid, ipc_call_t *call)
496{
497 sysarg_t link_id;
498 int rc;
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
[0e25780]508static void inetcfg_link_get_srv(ipc_callid_t callid, ipc_call_t *call)
509{
[b8b1adb1]510 ipc_callid_t name_callid;
511 ipc_callid_t laddr_callid;
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;
517 int rc;
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
[b8b1adb1]544 sysarg_t retval = async_data_read_finalize(name_callid, linfo.name,
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
[7af0cc5]561static void inetcfg_link_remove_srv(ipc_callid_t callid, ipc_call_t *call)
562{
563 sysarg_t link_id;
564 int rc;
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
[02a09ed]574static void inetcfg_sroute_create_srv(ipc_callid_t iid,
575 ipc_call_t *icall)
[8bf672d]576{
[a1a101d]577 log_msg(LOG_DEFAULT, LVL_DEBUG, "inetcfg_sroute_create_srv()");
[02a09ed]578
579 ipc_callid_t callid;
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 }
[a2e3ee6]586
[02a09ed]587 if (size != sizeof(inet_naddr_t)) {
588 async_answer_0(callid, EINVAL);
589 async_answer_0(iid, EINVAL);
590 return;
591 }
592
593 inet_naddr_t dest;
594 int 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 }
600
601 if (!async_data_write_receive(&callid, &size)) {
602 async_answer_0(callid, EINVAL);
603 async_answer_0(iid, EINVAL);
604 return;
605 }
606
607 if (size != sizeof(inet_addr_t)) {
608 async_answer_0(callid, EINVAL);
609 async_answer_0(iid, EINVAL);
[8bf672d]610 return;
611 }
[a2e3ee6]612
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 }
[a2e3ee6]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 }
[a2e3ee6]628
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
635static void inetcfg_sroute_delete_srv(ipc_callid_t callid, ipc_call_t *call)
636{
637 sysarg_t sroute_id;
638 int rc;
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
[02a09ed]648static void inetcfg_sroute_get_srv(ipc_callid_t iid, ipc_call_t *icall)
[0e25780]649{
[a1a101d]650 log_msg(LOG_DEFAULT, LVL_DEBUG, "inetcfg_sroute_get_srv()");
[a2e3ee6]651
[02a09ed]652 sysarg_t sroute_id = IPC_GET_ARG1(*icall);
[a2e3ee6]653
654 inet_sroute_info_t srinfo;
655
656 inet_naddr_any(&srinfo.dest);
657 inet_addr_any(&srinfo.router);
[8bf672d]658 srinfo.name = NULL;
[a2e3ee6]659
[02a09ed]660 int rc = inetcfg_sroute_get(sroute_id, &srinfo);
661 if (rc != EOK) {
662 async_answer_0(iid, rc);
663 return;
664 }
665
666 ipc_callid_t callid;
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 }
[a2e3ee6]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 }
[a2e3ee6]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 }
686
687 if (!async_data_read_receive(&callid, &size)) {
688 async_answer_0(callid, EREFUSED);
689 async_answer_0(iid, EREFUSED);
690 return;
691 }
692
693 if (size != sizeof(inet_addr_t)) {
694 async_answer_0(callid, EINVAL);
695 async_answer_0(iid, EINVAL);
[a2e3ee6]696 return;
697 }
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 }
705
706 if (!async_data_read_receive(&callid, &size)) {
707 async_answer_0(callid, EREFUSED);
708 async_answer_0(iid, EREFUSED);
[a2e3ee6]709 return;
710 }
711
[02a09ed]712 rc = async_data_read_finalize(callid, srinfo.name,
713 min(size, str_size(srinfo.name)));
[8bf672d]714 free(srinfo.name);
[a2e3ee6]715
[02a09ed]716 async_answer_0(iid, (sysarg_t) rc);
[8bf672d]717}
[0e25780]718
[8bf672d]719static void inetcfg_sroute_get_id_srv(ipc_callid_t callid, ipc_call_t *call)
720{
721 char *name;
722 sysarg_t sroute_id;
723 int rc;
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
740void inet_cfg_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg)
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;
749 ipc_callid_t callid = async_get_call(&call);
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.