Changeset 8bf672d in mainline for uspace/srv/inet/inetcfg.c
- Timestamp:
- 2012-03-30T17:42:11Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 66a272f8
- Parents:
- 3b3c689
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/inet/inetcfg.c
r3b3c689 r8bf672d 49 49 #include "inet_link.h" 50 50 #include "inetcfg.h" 51 #include "sroute.h" 51 52 52 53 static int inetcfg_addr_create_static(char *name, inet_naddr_t *naddr, … … 66 67 67 68 addr = inet_addrobj_new(); 69 if (addr == NULL) { 70 *addr_id = 0; 71 return ENOMEM; 72 } 73 68 74 addr->naddr = *naddr; 69 75 addr->ilink = ilink; … … 143 149 } 144 150 151 static int inetcfg_get_sroute_list(sysarg_t **sroutes, size_t *count) 152 { 153 return inet_sroute_get_id_list(sroutes, count); 154 } 155 145 156 static int inetcfg_link_get(sysarg_t link_id, inet_link_info_t *linfo) 146 157 { … … 153 164 154 165 linfo->name = str_dup(ilink->svc_name); 166 return EOK; 167 } 168 169 static 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 189 static 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 203 static 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 218 static 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; 155 229 return EOK; 156 230 } … … 257 331 async_answer_1(callid, rc, addr_id); 258 332 } 259 260 333 261 334 static void inetcfg_get_addr_list_srv(ipc_callid_t callid, ipc_call_t *call) … … 293 366 } 294 367 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 }328 368 329 369 static void inetcfg_get_link_list_srv(ipc_callid_t callid, ipc_call_t *call) … … 359 399 } 360 400 401 static 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 435 static 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 469 static 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 497 static 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 510 static 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 547 static 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 361 568 void inet_cfg_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg) 362 569 { … … 396 603 inetcfg_get_link_list_srv(callid, &call); 397 604 break; 605 case INETCFG_GET_SROUTE_LIST: 606 inetcfg_get_sroute_list_srv(callid, &call); 607 break; 398 608 case INETCFG_LINK_GET: 399 609 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); 400 622 break; 401 623 default:
Note:
See TracChangeset
for help on using the changeset viewer.