diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-09-26 23:45:20 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-09-26 23:45:20 +0000 |
commit | 739e30fbc3363756e574b5761ff63ea97ffd61c1 (patch) | |
tree | e2a42d90dcc984d6ad6dc1736d75095991a1ab09 /networking/udhcp/dhcpc.c | |
parent | 7d9399e8dcfb9853f435c2936f449377d92f6e47 (diff) | |
download | busybox-w32-739e30fbc3363756e574b5761ff63ea97ffd61c1.tar.gz busybox-w32-739e30fbc3363756e574b5761ff63ea97ffd61c1.tar.bz2 busybox-w32-739e30fbc3363756e574b5761ff63ea97ffd61c1.zip |
udhcp: add inline docs; small code shrink
function old new delta
send_packet 103 87 -16
udhcpc_main 2359 2323 -36
Diffstat (limited to 'networking/udhcp/dhcpc.c')
-rw-r--r-- | networking/udhcp/dhcpc.c | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c index 8985cc705..2d48980d9 100644 --- a/networking/udhcp/dhcpc.c +++ b/networking/udhcp/dhcpc.c | |||
@@ -452,7 +452,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
452 | } | 452 | } |
453 | 453 | ||
454 | /* select() didn't timeout, something did happen. */ | 454 | /* select() didn't timeout, something did happen. */ |
455 | /* Is is a packet? */ | 455 | /* Is it a packet? */ |
456 | if (listen_mode != LISTEN_NONE && FD_ISSET(sockfd, &rfds)) { | 456 | if (listen_mode != LISTEN_NONE && FD_ISSET(sockfd, &rfds)) { |
457 | int len; | 457 | int len; |
458 | /* A packet is ready, read it */ | 458 | /* A packet is ready, read it */ |
@@ -474,7 +474,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
474 | continue; | 474 | continue; |
475 | 475 | ||
476 | if (packet.xid != xid) { | 476 | if (packet.xid != xid) { |
477 | DEBUG("Ignoring XID %x (our xid is %x)", | 477 | DEBUG("Ignoring xid %x (our xid is %x)", |
478 | (unsigned)packet.xid, (unsigned)xid); | 478 | (unsigned)packet.xid, (unsigned)xid); |
479 | continue; | 479 | continue; |
480 | } | 480 | } |
@@ -524,17 +524,24 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
524 | bb_error_msg("no lease time with ACK, using 1 hour lease"); | 524 | bb_error_msg("no lease time with ACK, using 1 hour lease"); |
525 | lease_seconds = 60 * 60; | 525 | lease_seconds = 60 * 60; |
526 | } else { | 526 | } else { |
527 | /* can be misaligned, thus memcpy */ | 527 | /* it IS unaligned sometimes, don't "optimize" */ |
528 | memcpy(&lease_seconds, temp, 4); | 528 | lease_seconds = get_unaligned_u32p((uint32_t*)temp); |
529 | lease_seconds = ntohl(lease_seconds); | 529 | lease_seconds = ntohl(lease_seconds); |
530 | lease_seconds &= 0x0fffffff; /* paranoia: must not be prone to overflows */ | 530 | lease_seconds &= 0x0fffffff; /* paranoia: must not be prone to overflows */ |
531 | if (lease_seconds < 10) /* and not too small */ | 531 | if (lease_seconds < 10) /* and not too small */ |
532 | lease_seconds = 10; | 532 | lease_seconds = 10; |
533 | } | 533 | } |
534 | //FIXME: why do we check ARP only after we've got DHCPACK? | ||
535 | //Shouldn't we do it immediately after DHCPOFFER? | ||
536 | #if ENABLE_FEATURE_UDHCPC_ARPING | 534 | #if ENABLE_FEATURE_UDHCPC_ARPING |
537 | if (opt & OPT_a) { | 535 | if (opt & OPT_a) { |
536 | /* RFC 2131 3.1 paragraph 5: | ||
537 | * "The client receives the DHCPACK message with configuration | ||
538 | * parameters. The client SHOULD perform a final check on the | ||
539 | * parameters (e.g., ARP for allocated network address), and notes | ||
540 | * the duration of the lease specified in the DHCPACK message. At this | ||
541 | * point, the client is configured. If the client detects that the | ||
542 | * address is already in use (e.g., through the use of ARP), | ||
543 | * the client MUST send a DHCPDECLINE message to the server and restarts | ||
544 | * the configuration process..." */ | ||
538 | if (!arpping(packet.yiaddr, | 545 | if (!arpping(packet.yiaddr, |
539 | (uint32_t) 0, | 546 | (uint32_t) 0, |
540 | client_config.arp, | 547 | client_config.arp, |
@@ -542,8 +549,6 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
542 | ) { | 549 | ) { |
543 | bb_info_msg("offered address is in use " | 550 | bb_info_msg("offered address is in use " |
544 | "(got ARP reply), declining"); | 551 | "(got ARP reply), declining"); |
545 | //NB: not clear whether it should be unicast or bcast. | ||
546 | //Currently it is a bcast. Why? | ||
547 | send_decline(xid, server_addr, packet.yiaddr); | 552 | send_decline(xid, server_addr, packet.yiaddr); |
548 | 553 | ||
549 | if (state != REQUESTING) | 554 | if (state != REQUESTING) |
@@ -568,7 +573,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
568 | } | 573 | } |
569 | requested_ip = packet.yiaddr; | 574 | requested_ip = packet.yiaddr; |
570 | udhcp_run_script(&packet, | 575 | udhcp_run_script(&packet, |
571 | ((state == RENEWING || state == REBINDING) ? "renew" : "bound")); | 576 | ((state == RENEWING || state == REBINDING) ? "renew" : "bound")); |
572 | 577 | ||
573 | state = BOUND; | 578 | state = BOUND; |
574 | change_listen_mode(LISTEN_NONE); | 579 | change_listen_mode(LISTEN_NONE); |