summaryrefslogtreecommitdiff
path: root/networking/udhcp/dhcpc.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-05-21 07:05:06 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-05-21 07:05:06 +0000
commit6de8994440165e2f30c50d2d7c1f332d9cd649bd (patch)
treed1e2794c09b2b73e93e64c84444cb52806498494 /networking/udhcp/dhcpc.c
parent19903f0d447116baef455eddc14458b1dfd1c834 (diff)
downloadbusybox-w32-6de8994440165e2f30c50d2d7c1f332d9cd649bd.tar.gz
busybox-w32-6de8994440165e2f30c50d2d7c1f332d9cd649bd.tar.bz2
busybox-w32-6de8994440165e2f30c50d2d7c1f332d9cd649bd.zip
udhcpc: regularize the names of receiving functions,
pause on "serious failure to receive". Some misc fixes are also folded in here.
Diffstat (limited to 'networking/udhcp/dhcpc.c')
-rw-r--r--networking/udhcp/dhcpc.c44
1 files changed, 23 insertions, 21 deletions
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c
index 7138389b8..fef8632f6 100644
--- a/networking/udhcp/dhcpc.c
+++ b/networking/udhcp/dhcpc.c
@@ -147,9 +147,7 @@ int udhcpc_main(int argc ATTRIBUTE_UNUSED, char **argv)
147 unsigned opt; 147 unsigned opt;
148 int max_fd; 148 int max_fd;
149 int retval; 149 int retval;
150 int len;
151 struct timeval tv; 150 struct timeval tv;
152 struct in_addr temp_addr;
153 struct dhcpMessage packet; 151 struct dhcpMessage packet;
154 fd_set rfds; 152 fd_set rfds;
155 153
@@ -380,7 +378,6 @@ int udhcpc_main(int argc ATTRIBUTE_UNUSED, char **argv)
380 if (packet_num == 0) 378 if (packet_num == 0)
381 xid = random_xid(); 379 xid = random_xid();
382 380
383 /* send discover packet */
384 send_discover(xid, requested_ip); /* broadcast */ 381 send_discover(xid, requested_ip); /* broadcast */
385 382
386 timeout = discover_timeout; 383 timeout = discover_timeout;
@@ -396,7 +393,7 @@ int udhcpc_main(int argc ATTRIBUTE_UNUSED, char **argv)
396 retval = 1; 393 retval = 1;
397 goto ret; 394 goto ret;
398 } 395 }
399 /* wait to try again */ 396 /* wait before trying again */
400 timeout = tryagain_timeout; 397 timeout = tryagain_timeout;
401 packet_num = 0; 398 packet_num = 0;
402 continue; 399 continue;
@@ -404,11 +401,12 @@ int udhcpc_main(int argc ATTRIBUTE_UNUSED, char **argv)
404 case REQUESTING: 401 case REQUESTING:
405 if (packet_num < discover_retries) { 402 if (packet_num < discover_retries) {
406 /* send request packet */ 403 /* send request packet */
407 if (state == RENEW_REQUESTED) 404 if (state == RENEW_REQUESTED) /* unicast */
408 send_renew(xid, server_addr, requested_ip); /* unicast */ 405 send_renew(xid, server_addr, requested_ip);
409 else send_selecting(xid, server_addr, requested_ip); /* broadcast */ 406 else /* broadcast */
407 send_selecting(xid, server_addr, requested_ip);
410 408
411 timeout = ((packet_num == 2) ? 10 : 2); 409 timeout = discover_timeout;
412 packet_num++; 410 packet_num++;
413 continue; 411 continue;
414 } 412 }
@@ -436,7 +434,7 @@ int udhcpc_main(int argc ATTRIBUTE_UNUSED, char **argv)
436 /* Timed out, enter rebinding state */ 434 /* Timed out, enter rebinding state */
437 DEBUG("Entering rebinding state"); 435 DEBUG("Entering rebinding state");
438 state = REBINDING; 436 state = REBINDING;
439 continue; 437 /* fall right through */
440 case REBINDING: 438 case REBINDING:
441 /* Lease is *really* about to run out, 439 /* Lease is *really* about to run out,
442 * try to find DHCP server using broadcast */ 440 * try to find DHCP server using broadcast */
@@ -464,23 +462,24 @@ int udhcpc_main(int argc ATTRIBUTE_UNUSED, char **argv)
464 /* select() didn't timeout, something did happen. */ 462 /* select() didn't timeout, something did happen. */
465 /* Is is a packet? */ 463 /* Is is a packet? */
466 if (listen_mode != LISTEN_NONE && FD_ISSET(sockfd, &rfds)) { 464 if (listen_mode != LISTEN_NONE && FD_ISSET(sockfd, &rfds)) {
465 int len;
467 /* A packet is ready, read it */ 466 /* A packet is ready, read it */
468 467
469 if (listen_mode == LISTEN_KERNEL) 468 if (listen_mode == LISTEN_KERNEL)
470 len = udhcp_recv_packet(&packet, sockfd); 469 len = udhcp_recv_kernel_packet(&packet, sockfd);
471 else 470 else
472 len = get_raw_packet(&packet, sockfd); 471 len = udhcp_recv_raw_packet(&packet, sockfd);
473
474 /* If this packet will turn out to be unrelated/bogus,
475 * we will go back and wait for next one.
476 * Be sure timeout is properly decreased. */
477 already_waited_sec += (unsigned)monotonic_sec() - timestamp_before_wait;
478
479 if (len == -1) { /* error is severe, reopen socket */ 472 if (len == -1) { /* error is severe, reopen socket */
480 DEBUG("error on read, %s, reopening socket", strerror(errno)); 473 DEBUG("error on read, %s, reopening socket", strerror(errno));
474 sleep(discover_timeout); /* 3 seconds by default */
481 change_listen_mode(listen_mode); /* just close and reopen */ 475 change_listen_mode(listen_mode); /* just close and reopen */
482 } 476 }
483 if (len < 0) continue; 477 /* If this packet will turn out to be unrelated/bogus,
478 * we will go back and wait for next one.
479 * Be sure timeout is properly decreased. */
480 already_waited_sec += (unsigned)monotonic_sec() - timestamp_before_wait;
481 if (len < 0)
482 continue;
484 483
485 if (packet.xid != xid) { 484 if (packet.xid != xid) {
486 DEBUG("Ignoring XID %x (our xid is %x)", 485 DEBUG("Ignoring XID %x (our xid is %x)",
@@ -563,9 +562,12 @@ int udhcpc_main(int argc ATTRIBUTE_UNUSED, char **argv)
563#endif 562#endif
564 /* enter bound state */ 563 /* enter bound state */
565 timeout = lease_seconds / 2; 564 timeout = lease_seconds / 2;
566 temp_addr.s_addr = packet.yiaddr; 565 {
567 bb_info_msg("Lease of %s obtained, lease time %u", 566 struct in_addr temp_addr;
568 inet_ntoa(temp_addr), (unsigned)lease_seconds); 567 temp_addr.s_addr = packet.yiaddr;
568 bb_info_msg("Lease of %s obtained, lease time %u",
569 inet_ntoa(temp_addr), (unsigned)lease_seconds);
570 }
569 requested_ip = packet.yiaddr; 571 requested_ip = packet.yiaddr;
570 udhcp_run_script(&packet, 572 udhcp_run_script(&packet,
571 ((state == RENEWING || state == REBINDING) ? "renew" : "bound")); 573 ((state == RENEWING || state == REBINDING) ? "renew" : "bound"));