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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since b623b68 was b8b1adb1, checked in by Jiri Svoboda <jiri@…>, 12 years ago

Add link listing to inet utility, showing MAC address.

  • Property mode set to 100644
File size: 16.9 KB
RevLine 
[0e25780]1/*
2 * Copyright (c) 2012 Jiri Svoboda
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>
[0e25780]45#include <sys/types.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
[0e94b979]162static int inetcfg_link_get(sysarg_t link_id, inet_link_info_t *linfo)
[0e25780]163{
[0e94b979]164 inet_link_t *ilink;
165
166 ilink = inet_link_get_by_id(link_id);
167 if (ilink == NULL) {
168 return ENOENT;
169 }
170
171 linfo->name = str_dup(ilink->svc_name);
[347768d]172 linfo->def_mtu = ilink->def_mtu;
[b8b1adb1]173 if (ilink->mac_valid) {
174 addr48(ilink->mac, linfo->mac_addr);
175 } else {
176 memset(linfo->mac_addr, 0, sizeof(linfo->mac_addr));
177 }
178
[0e94b979]179 return EOK;
[0e25780]180}
181
[8bf672d]182static int inetcfg_sroute_create(char *name, inet_naddr_t *dest,
183 inet_addr_t *router, sysarg_t *sroute_id)
184{
185 inet_sroute_t *sroute;
186
187 sroute = inet_sroute_new();
188 if (sroute == NULL) {
189 *sroute_id = 0;
190 return ENOMEM;
191 }
192
193 sroute->dest = *dest;
194 sroute->router = *router;
195 sroute->name = str_dup(name);
196 inet_sroute_add(sroute);
197
198 *sroute_id = sroute->id;
199 return EOK;
200}
201
202static int inetcfg_sroute_delete(sysarg_t sroute_id)
203{
204 inet_sroute_t *sroute;
205
206 sroute = inet_sroute_get_by_id(sroute_id);
207 if (sroute == NULL)
208 return ENOENT;
209
210 inet_sroute_remove(sroute);
211 inet_sroute_delete(sroute);
212
213 return EOK;
214}
215
216static int inetcfg_sroute_get(sysarg_t sroute_id, inet_sroute_info_t *srinfo)
217{
218 inet_sroute_t *sroute;
219
220 sroute = inet_sroute_get_by_id(sroute_id);
221 if (sroute == NULL)
222 return ENOENT;
223
224 srinfo->dest = sroute->dest;
225 srinfo->router = sroute->router;
226 srinfo->name = str_dup(sroute->name);
227
228 return EOK;
229}
230
231static int inetcfg_sroute_get_id(char *name, sysarg_t *sroute_id)
232{
233 inet_sroute_t *sroute;
234
235 sroute = inet_sroute_find_by_name(name);
236 if (sroute == NULL) {
[a1a101d]237 log_msg(LOG_DEFAULT, LVL_DEBUG, "Static route '%s' not found.", name);
[8bf672d]238 return ENOENT;
239 }
240
241 *sroute_id = sroute->id;
242 return EOK;
243}
244
[02a09ed]245static void inetcfg_addr_create_static_srv(ipc_callid_t iid,
246 ipc_call_t *icall)
[0e25780]247{
[a1a101d]248 log_msg(LOG_DEFAULT, LVL_DEBUG, "inetcfg_addr_create_static_srv()");
[02a09ed]249
250 sysarg_t link_id = IPC_GET_ARG1(*icall);
251
252 ipc_callid_t callid;
253 size_t size;
254 if (!async_data_write_receive(&callid, &size)) {
255 async_answer_0(callid, EINVAL);
256 async_answer_0(iid, EINVAL);
257 return;
258 }
259
260 if (size != sizeof(inet_naddr_t)) {
261 async_answer_0(callid, EINVAL);
262 async_answer_0(iid, EINVAL);
263 return;
264 }
265
266 inet_naddr_t naddr;
267 int rc = async_data_write_finalize(callid, &naddr, size);
268 if (rc != EOK) {
269 async_answer_0(callid, rc);
270 async_answer_0(iid, rc);
271 return;
272 }
273
274 char *name;
[291c792]275 rc = async_data_write_accept((void **) &name, true, 0, LOC_NAME_MAXLEN,
276 0, NULL);
277 if (rc != EOK) {
[02a09ed]278 async_answer_0(iid, rc);
[291c792]279 return;
280 }
[02a09ed]281
282 sysarg_t addr_id = 0;
[291c792]283 rc = inetcfg_addr_create_static(name, &naddr, link_id, &addr_id);
284 free(name);
[02a09ed]285 async_answer_1(iid, rc, addr_id);
[0e25780]286}
287
288static void inetcfg_addr_delete_srv(ipc_callid_t callid, ipc_call_t *call)
289{
290 sysarg_t addr_id;
291 int rc;
292
[a1a101d]293 log_msg(LOG_DEFAULT, LVL_DEBUG, "inetcfg_addr_delete_srv()");
[0e25780]294
295 addr_id = IPC_GET_ARG1(*call);
296
297 rc = inetcfg_addr_delete(addr_id);
298 async_answer_0(callid, rc);
299}
300
[02a09ed]301static void inetcfg_addr_get_srv(ipc_callid_t iid, ipc_call_t *icall)
[0e25780]302{
[a1a101d]303 log_msg(LOG_DEFAULT, LVL_DEBUG, "inetcfg_addr_get_srv()");
[a2e3ee6]304
[02a09ed]305 sysarg_t addr_id = IPC_GET_ARG1(*icall);
[a2e3ee6]306
307 inet_addr_info_t ainfo;
308
309 inet_naddr_any(&ainfo.naddr);
[0e94b979]310 ainfo.ilink = 0;
311 ainfo.name = NULL;
[a2e3ee6]312
[02a09ed]313 int rc = inetcfg_addr_get(addr_id, &ainfo);
314 if (rc != EOK) {
315 async_answer_0(iid, rc);
316 return;
317 }
[a2e3ee6]318
[02a09ed]319 ipc_callid_t callid;
320 size_t size;
321 if (!async_data_read_receive(&callid, &size)) {
[0e94b979]322 async_answer_0(callid, EREFUSED);
[02a09ed]323 async_answer_0(iid, EREFUSED);
[0e94b979]324 return;
325 }
[a2e3ee6]326
[02a09ed]327 if (size != sizeof(inet_naddr_t)) {
328 async_answer_0(callid, EINVAL);
329 async_answer_0(iid, EINVAL);
[0e94b979]330 return;
331 }
[a2e3ee6]332
[02a09ed]333 rc = async_data_read_finalize(callid, &ainfo.naddr, size);
[a2e3ee6]334 if (rc != EOK) {
335 async_answer_0(callid, rc);
[02a09ed]336 async_answer_0(iid, rc);
337 return;
338 }
339
340 if (!async_data_read_receive(&callid, &size)) {
341 async_answer_0(callid, EREFUSED);
342 async_answer_0(iid, EREFUSED);
[a2e3ee6]343 return;
344 }
345
[02a09ed]346 rc = async_data_read_finalize(callid, ainfo.name,
347 min(size, str_size(ainfo.name)));
[0e94b979]348 free(ainfo.name);
[a2e3ee6]349
[02a09ed]350 if (rc != EOK) {
351 async_answer_0(callid, rc);
352 async_answer_0(iid, rc);
353 return;
354 }
355
356 async_answer_1(iid, (sysarg_t) rc, ainfo.ilink);
[0e25780]357}
358
[fa101c4]359static void inetcfg_addr_get_id_srv(ipc_callid_t callid, ipc_call_t *call)
360{
361 char *name;
362 sysarg_t link_id;
363 sysarg_t addr_id;
364 int rc;
365
[a1a101d]366 log_msg(LOG_DEFAULT, LVL_DEBUG, "inetcfg_addr_get_id_srv()");
[fa101c4]367
368 link_id = IPC_GET_ARG1(*call);
369
370 rc = async_data_write_accept((void **) &name, true, 0, LOC_NAME_MAXLEN,
371 0, NULL);
372 if (rc != EOK) {
373 async_answer_0(callid, rc);
374 return;
375 }
376
377 addr_id = 0;
378 rc = inetcfg_addr_get_id(name, link_id, &addr_id);
379 free(name);
380 async_answer_1(callid, rc, addr_id);
381}
382
[0e25780]383static void inetcfg_get_addr_list_srv(ipc_callid_t callid, ipc_call_t *call)
384{
385 ipc_callid_t rcallid;
[0e94b979]386 size_t count;
[0e25780]387 size_t max_size;
388 size_t act_size;
389 size_t size;
390 sysarg_t *id_buf;
391 int rc;
392
[a1a101d]393 log_msg(LOG_DEFAULT, LVL_DEBUG, "inetcfg_get_addr_list_srv()");
[0e25780]394
395 if (!async_data_read_receive(&rcallid, &max_size)) {
396 async_answer_0(rcallid, EREFUSED);
397 async_answer_0(callid, EREFUSED);
398 return;
399 }
400
[0e94b979]401 rc = inetcfg_get_addr_list(&id_buf, &count);
[0e25780]402 if (rc != EOK) {
403 async_answer_0(rcallid, rc);
404 async_answer_0(callid, rc);
405 return;
406 }
407
[0e94b979]408 act_size = count * sizeof(sysarg_t);
[0e25780]409 size = min(act_size, max_size);
410
411 sysarg_t retval = async_data_read_finalize(rcallid, id_buf, size);
412 free(id_buf);
413
414 async_answer_1(callid, retval, act_size);
415}
416
[8bf672d]417static void inetcfg_get_link_list_srv(ipc_callid_t callid, ipc_call_t *call)
418{
419 ipc_callid_t rcallid;
[b8b1adb1]420 size_t count;
[8bf672d]421 size_t max_size;
422 size_t act_size;
423 size_t size;
424 sysarg_t *id_buf;
425 int rc;
426
[b8b1adb1]427 log_msg(LOG_DEFAULT, LVL_DEBUG, "inetcfg_get_addr_list_srv()");
[8bf672d]428
429 if (!async_data_read_receive(&rcallid, &max_size)) {
430 async_answer_0(rcallid, EREFUSED);
431 async_answer_0(callid, EREFUSED);
432 return;
433 }
434
[b8b1adb1]435 rc = inetcfg_get_link_list(&id_buf, &count);
[8bf672d]436 if (rc != EOK) {
437 async_answer_0(rcallid, rc);
438 async_answer_0(callid, rc);
439 return;
440 }
441
[b8b1adb1]442 act_size = count * sizeof(sysarg_t);
[8bf672d]443 size = min(act_size, max_size);
444
445 sysarg_t retval = async_data_read_finalize(rcallid, id_buf, size);
446 free(id_buf);
447
448 async_answer_1(callid, retval, act_size);
449}
450
451static void inetcfg_get_sroute_list_srv(ipc_callid_t callid, ipc_call_t *call)
452{
453 ipc_callid_t rcallid;
454 size_t count;
455 size_t max_size;
456 size_t act_size;
457 size_t size;
458 sysarg_t *id_buf;
459 int rc;
460
[a1a101d]461 log_msg(LOG_DEFAULT, LVL_DEBUG, "inetcfg_get_sroute_list_srv()");
[8bf672d]462
463 if (!async_data_read_receive(&rcallid, &max_size)) {
464 async_answer_0(rcallid, EREFUSED);
465 async_answer_0(callid, EREFUSED);
466 return;
467 }
468
469 rc = inetcfg_get_sroute_list(&id_buf, &count);
470 if (rc != EOK) {
471 async_answer_0(rcallid, rc);
472 async_answer_0(callid, rc);
473 return;
474 }
475
476 act_size = count * sizeof(sysarg_t);
477 size = min(act_size, max_size);
478
479 sysarg_t retval = async_data_read_finalize(rcallid, id_buf, size);
480 free(id_buf);
481
482 async_answer_1(callid, retval, act_size);
483}
484
[0e25780]485static void inetcfg_link_get_srv(ipc_callid_t callid, ipc_call_t *call)
486{
[b8b1adb1]487 ipc_callid_t name_callid;
488 ipc_callid_t laddr_callid;
489 size_t name_max_size;
490 size_t laddr_max_size;
[0e94b979]491
[0e25780]492 sysarg_t link_id;
493 inet_link_info_t linfo;
494 int rc;
495
496 link_id = IPC_GET_ARG1(*call);
[a1a101d]497 log_msg(LOG_DEFAULT, LVL_DEBUG, "inetcfg_link_get_srv()");
[0e25780]498
[0e94b979]499 linfo.name = NULL;
500
[b8b1adb1]501 if (!async_data_read_receive(&name_callid, &name_max_size)) {
502 async_answer_0(name_callid, EREFUSED);
503 async_answer_0(callid, EREFUSED);
504 return;
505 }
506
507 if (!async_data_read_receive(&laddr_callid, &laddr_max_size)) {
508 async_answer_0(name_callid, EREFUSED);
[0e94b979]509 async_answer_0(callid, EREFUSED);
510 return;
511 }
512
[0e25780]513 rc = inetcfg_link_get(link_id, &linfo);
[0e94b979]514 if (rc != EOK) {
[b8b1adb1]515 async_answer_0(laddr_callid, rc);
516 async_answer_0(name_callid, rc);
[0e94b979]517 async_answer_0(callid, rc);
518 return;
519 }
520
[b8b1adb1]521 sysarg_t retval = async_data_read_finalize(name_callid, linfo.name,
522 min(name_max_size, str_size(linfo.name)));
523 if (retval != EOK) {
524 free(linfo.name);
525 async_answer_0(laddr_callid, retval);
526 async_answer_0(callid, retval);
527 return;
528 }
529
530 retval = async_data_read_finalize(laddr_callid, &linfo.mac_addr,
531 min(laddr_max_size, sizeof(linfo.mac_addr)));
532
[0e94b979]533 free(linfo.name);
534
[347768d]535 async_answer_1(callid, retval, linfo.def_mtu);
[0e25780]536}
537
[02a09ed]538static void inetcfg_sroute_create_srv(ipc_callid_t iid,
539 ipc_call_t *icall)
[8bf672d]540{
[a1a101d]541 log_msg(LOG_DEFAULT, LVL_DEBUG, "inetcfg_sroute_create_srv()");
[02a09ed]542
543 ipc_callid_t callid;
544 size_t size;
545 if (!async_data_write_receive(&callid, &size)) {
546 async_answer_0(callid, EINVAL);
547 async_answer_0(iid, EINVAL);
548 return;
549 }
[a2e3ee6]550
[02a09ed]551 if (size != sizeof(inet_naddr_t)) {
552 async_answer_0(callid, EINVAL);
553 async_answer_0(iid, EINVAL);
554 return;
555 }
556
557 inet_naddr_t dest;
558 int rc = async_data_write_finalize(callid, &dest, size);
[8bf672d]559 if (rc != EOK) {
560 async_answer_0(callid, rc);
[02a09ed]561 async_answer_0(iid, rc);
562 return;
563 }
564
565 if (!async_data_write_receive(&callid, &size)) {
566 async_answer_0(callid, EINVAL);
567 async_answer_0(iid, EINVAL);
568 return;
569 }
570
571 if (size != sizeof(inet_addr_t)) {
572 async_answer_0(callid, EINVAL);
573 async_answer_0(iid, EINVAL);
[8bf672d]574 return;
575 }
[a2e3ee6]576
577 inet_addr_t router;
[02a09ed]578 rc = async_data_write_finalize(callid, &router, size);
579 if (rc != EOK) {
580 async_answer_0(callid, rc);
581 async_answer_0(iid, rc);
582 return;
583 }
[a2e3ee6]584
[02a09ed]585 char *name;
586 rc = async_data_write_accept((void **) &name, true, 0, LOC_NAME_MAXLEN,
587 0, NULL);
588 if (rc != EOK) {
589 async_answer_0(iid, rc);
590 return;
591 }
[a2e3ee6]592
593 sysarg_t sroute_id = 0;
[8bf672d]594 rc = inetcfg_sroute_create(name, &dest, &router, &sroute_id);
595 free(name);
[02a09ed]596 async_answer_1(iid, rc, sroute_id);
[8bf672d]597}
598
599static void inetcfg_sroute_delete_srv(ipc_callid_t callid, ipc_call_t *call)
600{
601 sysarg_t sroute_id;
602 int rc;
603
[a1a101d]604 log_msg(LOG_DEFAULT, LVL_DEBUG, "inetcfg_sroute_delete_srv()");
[8bf672d]605
606 sroute_id = IPC_GET_ARG1(*call);
607
608 rc = inetcfg_sroute_delete(sroute_id);
609 async_answer_0(callid, rc);
610}
611
[02a09ed]612static void inetcfg_sroute_get_srv(ipc_callid_t iid, ipc_call_t *icall)
[0e25780]613{
[a1a101d]614 log_msg(LOG_DEFAULT, LVL_DEBUG, "inetcfg_sroute_get_srv()");
[a2e3ee6]615
[02a09ed]616 sysarg_t sroute_id = IPC_GET_ARG1(*icall);
[a2e3ee6]617
618 inet_sroute_info_t srinfo;
619
620 inet_naddr_any(&srinfo.dest);
621 inet_addr_any(&srinfo.router);
[8bf672d]622 srinfo.name = NULL;
[a2e3ee6]623
[02a09ed]624 int rc = inetcfg_sroute_get(sroute_id, &srinfo);
625 if (rc != EOK) {
626 async_answer_0(iid, rc);
627 return;
628 }
629
630 ipc_callid_t callid;
631 size_t size;
632 if (!async_data_read_receive(&callid, &size)) {
[0e25780]633 async_answer_0(callid, EREFUSED);
[02a09ed]634 async_answer_0(iid, EREFUSED);
[0e25780]635 return;
636 }
[a2e3ee6]637
[02a09ed]638 if (size != sizeof(inet_naddr_t)) {
639 async_answer_0(callid, EINVAL);
640 async_answer_0(iid, EINVAL);
[0e25780]641 return;
642 }
[a2e3ee6]643
[02a09ed]644 rc = async_data_read_finalize(callid, &srinfo.dest, size);
[a2e3ee6]645 if (rc != EOK) {
646 async_answer_0(callid, rc);
[02a09ed]647 async_answer_0(iid, rc);
648 return;
649 }
650
651 if (!async_data_read_receive(&callid, &size)) {
652 async_answer_0(callid, EREFUSED);
653 async_answer_0(iid, EREFUSED);
654 return;
655 }
656
657 if (size != sizeof(inet_addr_t)) {
658 async_answer_0(callid, EINVAL);
659 async_answer_0(iid, EINVAL);
[a2e3ee6]660 return;
661 }
662
[02a09ed]663 rc = async_data_read_finalize(callid, &srinfo.router, size);
[a2e3ee6]664 if (rc != EOK) {
665 async_answer_0(callid, rc);
[02a09ed]666 async_answer_0(iid, rc);
667 return;
668 }
669
670 if (!async_data_read_receive(&callid, &size)) {
671 async_answer_0(callid, EREFUSED);
672 async_answer_0(iid, EREFUSED);
[a2e3ee6]673 return;
674 }
675
[02a09ed]676 rc = async_data_read_finalize(callid, srinfo.name,
677 min(size, str_size(srinfo.name)));
[8bf672d]678 free(srinfo.name);
[a2e3ee6]679
[02a09ed]680 async_answer_0(iid, (sysarg_t) rc);
[8bf672d]681}
[0e25780]682
[8bf672d]683static void inetcfg_sroute_get_id_srv(ipc_callid_t callid, ipc_call_t *call)
684{
685 char *name;
686 sysarg_t sroute_id;
687 int rc;
688
[a1a101d]689 log_msg(LOG_DEFAULT, LVL_DEBUG, "inetcfg_sroute_get_id_srv()");
[8bf672d]690
691 rc = async_data_write_accept((void **) &name, true, 0, LOC_NAME_MAXLEN,
692 0, NULL);
693 if (rc != EOK) {
694 async_answer_0(callid, rc);
695 return;
696 }
697
698 sroute_id = 0;
699 rc = inetcfg_sroute_get_id(name, &sroute_id);
700 free(name);
701 async_answer_1(callid, rc, sroute_id);
[0e25780]702}
703
704void inet_cfg_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg)
705{
[a1a101d]706 log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_cfg_conn()");
[0e25780]707
708 /* Accept the connection */
709 async_answer_0(iid, EOK);
710
711 while (true) {
712 ipc_call_t call;
713 ipc_callid_t callid = async_get_call(&call);
714 sysarg_t method = IPC_GET_IMETHOD(call);
715
716 if (!method) {
717 /* The other side has hung up */
718 async_answer_0(callid, EOK);
719 return;
720 }
721
722 switch (method) {
723 case INETCFG_ADDR_CREATE_STATIC:
724 inetcfg_addr_create_static_srv(callid, &call);
725 break;
726 case INETCFG_ADDR_DELETE:
727 inetcfg_addr_delete_srv(callid, &call);
728 break;
729 case INETCFG_ADDR_GET:
730 inetcfg_addr_get_srv(callid, &call);
731 break;
[fa101c4]732 case INETCFG_ADDR_GET_ID:
733 inetcfg_addr_get_id_srv(callid, &call);
734 break;
[0e25780]735 case INETCFG_GET_ADDR_LIST:
736 inetcfg_get_addr_list_srv(callid, &call);
737 break;
738 case INETCFG_GET_LINK_LIST:
739 inetcfg_get_link_list_srv(callid, &call);
740 break;
[8bf672d]741 case INETCFG_GET_SROUTE_LIST:
742 inetcfg_get_sroute_list_srv(callid, &call);
743 break;
[0e25780]744 case INETCFG_LINK_GET:
745 inetcfg_link_get_srv(callid, &call);
746 break;
[8bf672d]747 case INETCFG_SROUTE_CREATE:
748 inetcfg_sroute_create_srv(callid, &call);
749 break;
750 case INETCFG_SROUTE_DELETE:
751 inetcfg_sroute_delete_srv(callid, &call);
752 break;
753 case INETCFG_SROUTE_GET:
754 inetcfg_sroute_get_srv(callid, &call);
755 break;
756 case INETCFG_SROUTE_GET_ID:
757 inetcfg_sroute_get_id_srv(callid, &call);
758 break;
[0e25780]759 default:
760 async_answer_0(callid, EINVAL);
761 }
762 }
763}
764
765/** @}
766 */
Note: See TracBrowser for help on using the repository browser.