Changes in uspace/srv/net/inetsrv/inetcfg.c [bd88bee:a1a101d] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/inetsrv/inetcfg.c
rbd88bee ra1a101d 1 1 /* 2 * Copyright (c) 201 3Jiri Svoboda2 * Copyright (c) 2012 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 44 44 #include <str.h> 45 45 #include <sys/types.h> 46 #include <types/inetcfg.h>47 46 48 47 #include "addrobj.h" … … 57 56 inet_link_t *ilink; 58 57 inet_addrobj_t *addr; 59 i net_addr_t iaddr;58 iplink_addr_t iaddr; 60 59 int rc; 61 60 … … 83 82 } 84 83 85 i net_naddr_addr(&addr->naddr, &iaddr);84 iaddr.ipv4 = addr->naddr.ipv4; 86 85 rc = iplink_addr_add(ilink->iplink, &iaddr); 87 86 if (rc != EOK) { … … 152 151 static int inetcfg_get_link_list(sysarg_t **addrs, size_t *count) 153 152 { 154 return inet_link_get_id_list(addrs, count);153 return ENOTSUP; 155 154 } 156 155 … … 158 157 { 159 158 return inet_sroute_get_id_list(sroutes, count); 160 }161 162 static int inetcfg_link_add(sysarg_t link_id)163 {164 return inet_link_open(link_id);165 159 } 166 160 … … 176 170 linfo->name = str_dup(ilink->svc_name); 177 171 linfo->def_mtu = ilink->def_mtu; 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 184 return EOK; 185 } 186 187 static int inetcfg_link_remove(sysarg_t link_id) 188 { 189 return ENOTSUP; 172 return EOK; 190 173 } 191 174 … … 253 236 } 254 237 255 static void inetcfg_addr_create_static_srv(ipc_callid_t iid, 256 ipc_call_t *icall) 257 { 238 static void inetcfg_addr_create_static_srv(ipc_callid_t callid, 239 ipc_call_t *call) 240 { 241 char *name; 242 inet_naddr_t naddr; 243 sysarg_t link_id; 244 sysarg_t addr_id; 245 int rc; 246 258 247 log_msg(LOG_DEFAULT, LVL_DEBUG, "inetcfg_addr_create_static_srv()"); 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; 248 285 249 rc = async_data_write_accept((void **) &name, true, 0, LOC_NAME_MAXLEN, 286 250 0, NULL); 287 251 if (rc != EOK) { 288 async_answer_0(iid, rc); 289 return; 290 } 291 292 sysarg_t addr_id = 0; 252 async_answer_0(callid, rc); 253 return; 254 } 255 256 naddr.ipv4 = IPC_GET_ARG1(*call); 257 naddr.bits = IPC_GET_ARG2(*call); 258 link_id = IPC_GET_ARG3(*call); 259 260 addr_id = 0; 293 261 rc = inetcfg_addr_create_static(name, &naddr, link_id, &addr_id); 294 262 free(name); 295 async_answer_1( iid, rc, addr_id);263 async_answer_1(callid, rc, addr_id); 296 264 } 297 265 … … 309 277 } 310 278 311 static void inetcfg_addr_get_srv(ipc_callid_t iid, ipc_call_t *icall) 312 { 279 static void inetcfg_addr_get_srv(ipc_callid_t callid, ipc_call_t *call) 280 { 281 ipc_callid_t rcallid; 282 size_t max_size; 283 284 sysarg_t addr_id; 285 inet_addr_info_t ainfo; 286 int rc; 287 288 addr_id = IPC_GET_ARG1(*call); 313 289 log_msg(LOG_DEFAULT, LVL_DEBUG, "inetcfg_addr_get_srv()"); 314 315 sysarg_t addr_id = IPC_GET_ARG1(*icall); 316 317 inet_addr_info_t ainfo; 318 319 inet_naddr_any(&ainfo.naddr); 290 291 ainfo.naddr.ipv4 = 0; 292 ainfo.naddr.bits = 0; 320 293 ainfo.ilink = 0; 321 294 ainfo.name = NULL; 322 323 int rc = inetcfg_addr_get(addr_id, &ainfo); 324 if (rc != EOK) { 325 async_answer_0(iid, rc); 326 return; 327 } 328 329 ipc_callid_t callid; 330 size_t size; 331 if (!async_data_read_receive(&callid, &size)) { 295 296 if (!async_data_read_receive(&rcallid, &max_size)) { 297 async_answer_0(rcallid, EREFUSED); 332 298 async_answer_0(callid, EREFUSED); 333 async_answer_0(iid, EREFUSED); 334 return; 335 } 336 337 if (size != sizeof(inet_naddr_t)) { 338 async_answer_0(callid, EINVAL); 339 async_answer_0(iid, EINVAL); 340 return; 341 } 342 343 rc = async_data_read_finalize(callid, &ainfo.naddr, size); 344 if (rc != EOK) { 345 async_answer_0(callid, rc); 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); 353 return; 354 } 355 356 rc = async_data_read_finalize(callid, ainfo.name, 357 min(size, str_size(ainfo.name))); 299 return; 300 } 301 302 rc = inetcfg_addr_get(addr_id, &ainfo); 303 if (rc != EOK) { 304 async_answer_0(callid, rc); 305 return; 306 } 307 308 sysarg_t retval = async_data_read_finalize(rcallid, ainfo.name, 309 min(max_size, str_size(ainfo.name))); 358 310 free(ainfo.name); 359 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); 311 312 async_answer_3(callid, retval, ainfo.naddr.ipv4, ainfo.naddr.bits, 313 ainfo.ilink); 367 314 } 368 315 … … 425 372 } 426 373 374 427 375 static void inetcfg_get_link_list_srv(ipc_callid_t callid, ipc_call_t *call) 376 { 377 ipc_callid_t rcallid; 378 size_t max_size; 379 size_t act_size; 380 size_t size; 381 sysarg_t *id_buf; 382 int rc; 383 384 log_msg(LOG_DEFAULT, LVL_DEBUG, "inetcfg_get_link_list_srv()"); 385 386 if (!async_data_read_receive(&rcallid, &max_size)) { 387 async_answer_0(rcallid, EREFUSED); 388 async_answer_0(callid, EREFUSED); 389 return; 390 } 391 392 rc = inetcfg_get_link_list(&id_buf, &act_size); 393 if (rc != EOK) { 394 async_answer_0(rcallid, rc); 395 async_answer_0(callid, rc); 396 return; 397 } 398 399 size = min(act_size, max_size); 400 401 sysarg_t retval = async_data_read_finalize(rcallid, id_buf, size); 402 free(id_buf); 403 404 async_answer_1(callid, retval, act_size); 405 } 406 407 static void inetcfg_get_sroute_list_srv(ipc_callid_t callid, ipc_call_t *call) 428 408 { 429 409 ipc_callid_t rcallid; … … 435 415 int rc; 436 416 437 log_msg(LOG_DEFAULT, LVL_DEBUG, "inetcfg_get_ addr_list_srv()");417 log_msg(LOG_DEFAULT, LVL_DEBUG, "inetcfg_get_sroute_list_srv()"); 438 418 439 419 if (!async_data_read_receive(&rcallid, &max_size)) { … … 443 423 } 444 424 445 rc = inetcfg_get_ link_list(&id_buf, &count);425 rc = inetcfg_get_sroute_list(&id_buf, &count); 446 426 if (rc != EOK) { 447 427 async_answer_0(rcallid, rc); … … 459 439 } 460 440 461 static void inetcfg_ get_sroute_list_srv(ipc_callid_t callid, ipc_call_t *call)441 static void inetcfg_link_get_srv(ipc_callid_t callid, ipc_call_t *call) 462 442 { 463 443 ipc_callid_t rcallid; 464 size_t count;465 444 size_t max_size; 466 size_t act_size; 467 size_t size; 468 sysarg_t *id_buf; 469 int rc; 470 471 log_msg(LOG_DEFAULT, LVL_DEBUG, "inetcfg_get_sroute_list_srv()"); 445 446 sysarg_t link_id; 447 inet_link_info_t linfo; 448 int rc; 449 450 link_id = IPC_GET_ARG1(*call); 451 log_msg(LOG_DEFAULT, LVL_DEBUG, "inetcfg_link_get_srv()"); 452 453 linfo.name = NULL; 472 454 473 455 if (!async_data_read_receive(&rcallid, &max_size)) { … … 477 459 } 478 460 479 rc = inetcfg_ get_sroute_list(&id_buf, &count);461 rc = inetcfg_link_get(link_id, &linfo); 480 462 if (rc != EOK) { 481 463 async_answer_0(rcallid, rc); … … 484 466 } 485 467 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 495 static 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 508 static void inetcfg_link_get_srv(ipc_callid_t callid, ipc_call_t *call) 509 { 510 ipc_callid_t name_callid; 511 ipc_callid_t laddr_callid; 512 size_t name_max_size; 513 size_t laddr_max_size; 514 515 sysarg_t link_id; 516 inet_link_info_t linfo; 517 int rc; 518 519 link_id = IPC_GET_ARG1(*call); 520 log_msg(LOG_DEFAULT, LVL_DEBUG, "inetcfg_link_get_srv()"); 521 522 linfo.name = NULL; 523 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); 532 async_answer_0(callid, EREFUSED); 533 return; 534 } 535 536 rc = inetcfg_link_get(link_id, &linfo); 537 if (rc != EOK) { 538 async_answer_0(laddr_callid, rc); 539 async_answer_0(name_callid, rc); 540 async_answer_0(callid, rc); 541 return; 542 } 543 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 468 sysarg_t retval = async_data_read_finalize(rcallid, linfo.name, 469 min(max_size, str_size(linfo.name))); 556 470 free(linfo.name); 557 471 … … 559 473 } 560 474 561 static 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 574 static void inetcfg_sroute_create_srv(ipc_callid_t iid, 575 ipc_call_t *icall) 576 { 475 static void inetcfg_sroute_create_srv(ipc_callid_t callid, 476 ipc_call_t *call) 477 { 478 char *name; 479 inet_naddr_t dest; 480 inet_addr_t router; 481 sysarg_t sroute_id; 482 int rc; 483 577 484 log_msg(LOG_DEFAULT, LVL_DEBUG, "inetcfg_sroute_create_srv()"); 578 485 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 }586 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);595 if (rc != EOK) {596 async_answer_0(callid, rc);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);610 return;611 }612 613 inet_addr_t router;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 }620 621 char *name;622 486 rc = async_data_write_accept((void **) &name, true, 0, LOC_NAME_MAXLEN, 623 487 0, NULL); 624 488 if (rc != EOK) { 625 async_answer_0(iid, rc); 626 return; 627 } 628 629 sysarg_t sroute_id = 0; 489 async_answer_0(callid, rc); 490 return; 491 } 492 493 dest.ipv4 = IPC_GET_ARG1(*call); 494 dest.bits = IPC_GET_ARG2(*call); 495 router.ipv4 = IPC_GET_ARG3(*call); 496 497 sroute_id = 0; 630 498 rc = inetcfg_sroute_create(name, &dest, &router, &sroute_id); 631 499 free(name); 632 async_answer_1( iid, rc, sroute_id);500 async_answer_1(callid, rc, sroute_id); 633 501 } 634 502 … … 646 514 } 647 515 648 static void inetcfg_sroute_get_srv(ipc_callid_t iid, ipc_call_t *icall) 649 { 516 static void inetcfg_sroute_get_srv(ipc_callid_t callid, ipc_call_t *call) 517 { 518 ipc_callid_t rcallid; 519 size_t max_size; 520 521 sysarg_t sroute_id; 522 inet_sroute_info_t srinfo; 523 int rc; 524 525 sroute_id = IPC_GET_ARG1(*call); 650 526 log_msg(LOG_DEFAULT, LVL_DEBUG, "inetcfg_sroute_get_srv()"); 651 652 sysarg_t sroute_id = IPC_GET_ARG1(*icall); 653 654 inet_sroute_info_t srinfo; 655 656 inet_naddr_any(&srinfo.dest); 657 inet_addr_any(&srinfo.router); 527 528 srinfo.dest.ipv4 = 0; 529 srinfo.dest.bits = 0; 530 srinfo.router.ipv4 = 0; 658 531 srinfo.name = NULL; 659 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)) { 532 533 if (!async_data_read_receive(&rcallid, &max_size)) { 534 async_answer_0(rcallid, EREFUSED); 669 535 async_answer_0(callid, EREFUSED); 670 async_answer_0(iid, EREFUSED); 671 return; 672 } 673 674 if (size != sizeof(inet_naddr_t)) { 675 async_answer_0(callid, EINVAL); 676 async_answer_0(iid, EINVAL); 677 return; 678 } 679 680 rc = async_data_read_finalize(callid, &srinfo.dest, size); 681 if (rc != EOK) { 682 async_answer_0(callid, rc); 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); 696 return; 697 } 698 699 rc = async_data_read_finalize(callid, &srinfo.router, size); 700 if (rc != EOK) { 701 async_answer_0(callid, rc); 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); 709 return; 710 } 711 712 rc = async_data_read_finalize(callid, srinfo.name, 713 min(size, str_size(srinfo.name))); 536 return; 537 } 538 539 rc = inetcfg_sroute_get(sroute_id, &srinfo); 540 if (rc != EOK) { 541 async_answer_0(callid, rc); 542 return; 543 } 544 545 sysarg_t retval = async_data_read_finalize(rcallid, srinfo.name, 546 min(max_size, str_size(srinfo.name))); 714 547 free(srinfo.name); 715 716 async_answer_0(iid, (sysarg_t) rc); 548 549 async_answer_3(callid, retval, srinfo.dest.ipv4, srinfo.dest.bits, 550 srinfo.router.ipv4); 717 551 } 718 552 … … 750 584 sysarg_t method = IPC_GET_IMETHOD(call); 751 585 752 log_msg(LOG_DEFAULT, LVL_DEBUG, "method %d", (int)method);753 586 if (!method) { 754 587 /* The other side has hung up */ … … 779 612 inetcfg_get_sroute_list_srv(callid, &call); 780 613 break; 781 case INETCFG_LINK_ADD:782 inetcfg_link_add_srv(callid, &call);783 break;784 614 case INETCFG_LINK_GET: 785 615 inetcfg_link_get_srv(callid, &call); 786 break;787 case INETCFG_LINK_REMOVE:788 inetcfg_link_remove_srv(callid, &call);789 616 break; 790 617 case INETCFG_SROUTE_CREATE:
Note:
See TracChangeset
for help on using the changeset viewer.