Changeset bd88bee in mainline
- Timestamp:
- 2013-09-21T22:51:06Z (11 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 66ec63a
- Parents:
- 7af0cc5
- Location:
- uspace
- Files:
-
- 5 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/init/init.c
r7af0cc5 rbd88bee 360 360 srv_start("/srv/udp"); 361 361 srv_start("/srv/dnsrsrv"); 362 srv_start("/srv/dhcp"); 363 srv_start("/srv/nconfsrv"); 362 364 363 365 srv_start("/srv/clipboard"); -
uspace/lib/c/Makefile
r7af0cc5 rbd88bee 77 77 generic/device/pci.c \ 78 78 generic/device/ahci.c \ 79 generic/dhcp.c \ 79 80 generic/dnsr.c \ 80 81 generic/dlfcn.c \ -
uspace/lib/c/include/ipc/services.h
r7af0cc5 rbd88bee 54 54 55 55 #define SERVICE_NAME_CORECFG "corecfg" 56 #define SERVICE_NAME_DHCP "net/dhcp" 56 57 #define SERVICE_NAME_DNSR "net/dnsr" 57 58 #define SERVICE_NAME_INET "net/inet" -
uspace/srv/net/dhcp/Makefile
r7af0cc5 rbd88bee 31 31 32 32 SOURCES = \ 33 dhcp.c 33 dhcp.c \ 34 main.c 34 35 35 36 include $(USPACE_PREFIX)/Makefile.common -
uspace/srv/net/dhcp/dhcp.c
r7af0cc5 rbd88bee 39 39 #include <inet/dnsr.h> 40 40 #include <inet/inetcfg.h> 41 #include <io/log.h> 41 42 #include <loc.h> 42 43 #include <net/in.h> … … 46 47 #include <stdlib.h> 47 48 49 #include "dhcp.h" 48 50 #include "dhcp_std.h" 49 51 … … 113 115 (struct sockaddr *)&addr, sizeof(addr)); 114 116 if (rc != EOK) { 115 printf("Sending failed\n");117 log_msg(LOG_DEFAULT, LVL_ERROR, "Sending failed"); 116 118 return rc; 117 119 } … … 154 156 (struct sockaddr *)&src_addr, &src_addr_size); 155 157 if (rc < 0) { 156 printf("recvfrom failed (%d)\n", rc);158 log_msg(LOG_DEFAULT, LVL_ERROR, "recvfrom failed (%d)", rc); 157 159 return rc; 158 160 } … … 222 224 size_t i; 223 225 224 printf("Receive reply\n");226 log_msg(LOG_DEFAULT, LVL_DEBUG, "Receive reply"); 225 227 memset(offer, 0, sizeof(*offer)); 226 228 … … 231 233 return rc; 232 234 233 printf("Your IP address: %s\n", saddr);235 log_msg(LOG_DEFAULT, LVL_DEBUG, "Your IP address: %s", saddr); 234 236 free(saddr); 235 237 … … 240 242 return rc; 241 243 242 printf("Next server IP address: %s\n", saddr);244 log_msg(LOG_DEFAULT, LVL_DEBUG, "Next server IP address: %s", saddr); 243 245 free(saddr); 244 246 … … 249 251 return rc; 250 252 251 printf("Relay agent IP address: %s\n", saddr);253 log_msg(LOG_DEFAULT, LVL_DEBUG, "Relay agent IP address: %s", saddr); 252 254 free(saddr); 253 255 … … 320 322 321 323 if (!have_server_id) { 322 printf("Missing server ID option.\n");324 log_msg(LOG_DEFAULT, LVL_ERROR, "Missing server ID option."); 323 325 return rc; 324 326 } 325 327 326 328 if (!have_subnet_mask) { 327 printf("Missing subnet mask option.\n");329 log_msg(LOG_DEFAULT, LVL_ERROR, "Missing subnet mask option."); 328 330 return rc; 329 331 } … … 333 335 return rc; 334 336 335 printf("Offered network address: %s\n", saddr);337 log_msg(LOG_DEFAULT, LVL_DEBUG, "Offered network address: %s", saddr); 336 338 free(saddr); 337 339 … … 341 343 return rc; 342 344 343 printf("Router address: %s\n", saddr);345 log_msg(LOG_DEFAULT, LVL_DEBUG, "Router address: %s", saddr); 344 346 free(saddr); 345 347 } … … 350 352 return rc; 351 353 352 printf("DNS server: %s\n", saddr);354 log_msg(LOG_DEFAULT, LVL_DEBUG, "DNS server: %s", saddr); 353 355 free(saddr); 354 356 } … … 367 369 &addr_id); 368 370 if (rc != EOK) { 369 printf("Error creating IP address %s (%d)\n", "dhcp4a", rc); 371 log_msg(LOG_DEFAULT, LVL_ERROR, 372 "Error creating IP address %s (%d)", "dhcp4a", rc); 370 373 return rc; 371 374 } … … 378 381 rc = inetcfg_sroute_create("dhcpdef", &defr, &offer->router, &sroute_id); 379 382 if (rc != EOK) { 380 printf("Error creating default route %s (%d).\n", "dhcpdef",381 rc);383 log_msg(LOG_DEFAULT, LVL_ERROR, "Error creating " 384 "default route %s (%d).", "dhcpdef", rc); 382 385 return rc; 383 386 } … … 387 390 rc = dnsr_set_srvaddr(&offer->dns_server); 388 391 if (rc != EOK) { 389 printf("%s: Error setting nameserver address (%d))\n",390 NAME, rc);392 log_msg(LOG_DEFAULT, LVL_ERROR, "%s: Error setting " 393 "nameserver address (%d))", NAME, rc); 391 394 return rc; 392 395 } … … 396 399 } 397 400 398 int main(int argc, char *argv[])401 int dhcpsrv_link_add(service_id_t link_id) 399 402 { 400 403 int fd; 401 404 struct sockaddr_in laddr; 402 405 void *msg; 403 service_id_t iplink;404 406 size_t msg_size; 405 407 dhcp_offer_t offer; 406 408 int rc; 407 409 408 if (argc < 2) { 409 printf("syntax: %s <ip-link>\n", NAME); 410 return 1; 411 } 412 413 rc = inetcfg_init(); 410 log_msg(LOG_DEFAULT, LVL_DEBUG, "dhcpsrv_link_add(%zu)", link_id); 411 412 /* Get link hardware address */ 413 rc = inetcfg_link_get(link_id, &link_info); 414 414 if (rc != EOK) { 415 printf("Error contacting inet configuration service.\n"); 416 return 1; 417 } 418 419 rc = loc_service_get_id(argv[1], &iplink, 0); 420 if (rc != EOK) { 421 printf("Error resolving service '%s'.\n", argv[1]); 422 return 1; 423 } 424 425 /* Get link hardware address */ 426 rc = inetcfg_link_get(iplink, &link_info); 427 if (rc != EOK) { 428 printf("Error getting properties for link '%s'.\n", argv[1]); 429 return 1; 415 log_msg(LOG_DEFAULT, LVL_ERROR, "Error getting properties " 416 "for link %zu.", link_id); 417 return EIO; 430 418 } 431 419 … … 436 424 fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP); 437 425 if (fd < 0) 438 return 1;439 440 printf("Bind socket.\n");426 return EIO; 427 428 log_msg(LOG_DEFAULT, LVL_DEBUG, "Bind socket."); 441 429 rc = bind(fd, (struct sockaddr *)&laddr, sizeof(laddr)); 442 430 if (rc != EOK) 443 return 1;444 445 printf("Set socket options\n");446 rc = setsockopt(fd, SOL_SOCKET, SO_IPLINK, & iplink, sizeof(iplink));447 if (rc != EOK) 448 return 1;431 return EIO; 432 433 log_msg(LOG_DEFAULT, LVL_DEBUG, "Set socket options"); 434 rc = setsockopt(fd, SOL_SOCKET, SO_IPLINK, &link_id, sizeof(link_id)); 435 if (rc != EOK) 436 return EIO; 449 437 450 438 transport_fd = fd; 451 439 452 printf("Send DHCPDISCOVER\n");440 log_msg(LOG_DEFAULT, LVL_DEBUG, "Send DHCPDISCOVER"); 453 441 rc = dhcp_send_discover(); 454 442 if (rc != EOK) 455 return 1;443 return EIO; 456 444 457 445 rc = dhcp_recv_msg(&msg, &msg_size); 458 446 if (rc != EOK) 459 return 1;460 461 printf("Received %zu bytes\n", msg_size);447 return EIO; 448 449 log_msg(LOG_DEFAULT, LVL_DEBUG, "Received %zu bytes", msg_size); 462 450 463 451 rc = dhcp_recv_reply(msg, msg_size, &offer); 464 452 if (rc != EOK) 465 return 1;453 return EIO; 466 454 467 455 rc = dhcp_send_request(&offer); 468 456 if (rc != EOK) 469 return 1;457 return EIO; 470 458 471 459 rc = dhcp_recv_msg(&msg, &msg_size); 472 460 if (rc != EOK) 473 return 1;474 475 printf("Received %zu bytes\n", msg_size);461 return EIO; 462 463 log_msg(LOG_DEFAULT, LVL_DEBUG, "Received %zu bytes", msg_size); 476 464 477 465 rc = dhcp_recv_reply(msg, msg_size, &offer); 478 466 if (rc != EOK) 479 return 1;480 481 rc = dhcp_cfg_create( iplink, &offer);482 if (rc != EOK) 483 return 1;467 return EIO; 468 469 rc = dhcp_cfg_create(link_id, &offer); 470 if (rc != EOK) 471 return EIO; 484 472 485 473 closesocket(fd); 486 return 0; 487 } 474 return EOK; 475 } 476 477 int dhcpsrv_link_remove(service_id_t link_id) 478 { 479 return ENOTSUP; 480 } 481 488 482 489 483 /** @} -
uspace/srv/net/inetsrv/inet_link.c
r7af0cc5 rbd88bee 251 251 } 252 252 253 log_msg(LOG_DEFAULT, LVL_DEBUG, "Configured link '%s'.", ilink->svc_name); 253 254 return EOK; 254 255 -
uspace/srv/net/inetsrv/inetcfg.c
r7af0cc5 rbd88bee 750 750 sysarg_t method = IPC_GET_IMETHOD(call); 751 751 752 log_msg(LOG_DEFAULT, LVL_DEBUG, "method %d", (int)method); 752 753 if (!method) { 753 754 /* The other side has hung up */ -
uspace/srv/net/nconfsrv/iplink.c
r7af0cc5 rbd88bee 38 38 #include <errno.h> 39 39 #include <fibril_synch.h> 40 #include <inet/dhcp.h> 40 41 #include <inet/inetcfg.h> 41 42 #include <io/log.h> 42 43 #include <loc.h> 43 44 #include <stdlib.h> 45 #include <str.h> 44 46 45 47 #include "iplink.h" … … 139 141 } 140 142 143 log_msg(LOG_DEFAULT, LVL_NOTE, "Configure link %s", nlink->svc_name); 141 144 rc = inetcfg_link_add(sid); 142 145 if (rc != EOK) { … … 144 147 "'%s'.\n", nlink->svc_name); 145 148 goto error; 149 } 150 151 if (str_lcmp(nlink->svc_name, "net/eth", str_length("net/eth")) == 0) { 152 rc = dhcp_link_add(sid); 153 if (rc != EOK) { 154 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed configuring DHCP on " 155 " link '%s'.\n", nlink->svc_name); 156 goto error; 157 } 146 158 } 147 159 -
uspace/srv/net/nconfsrv/nconfsrv.c
r7af0cc5 rbd88bee 39 39 #include <errno.h> 40 40 #include <fibril_synch.h> 41 #include <inet/dhcp.h> 41 42 #include <inet/inetcfg.h> 42 43 #include <io/log.h> … … 65 66 if (rc != EOK) { 66 67 log_msg(LOG_DEFAULT, LVL_ERROR, "Error contacting inet " 68 "configuration service."); 69 return EIO; 70 } 71 72 rc = dhcp_init(); 73 if (rc != EOK) { 74 log_msg(LOG_DEFAULT, LVL_ERROR, "Error contacting dhcp " 67 75 "configuration service."); 68 76 return EIO;
Note:
See TracChangeset
for help on using the changeset viewer.