aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2013-11-03 19:20:54 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2013-11-03 19:20:54 +0100
commit8d3efaf35eb9d138114563bba4173c39c1231198 (patch)
tree69b514394ecf1b1f63afbda195359d596c34e7f5
parentb21bc80c7651bfb5a9e001cc220a598cf89b7cfd (diff)
downloadbusybox-w32-8d3efaf35eb9d138114563bba4173c39c1231198.tar.gz
busybox-w32-8d3efaf35eb9d138114563bba4173c39c1231198.tar.bz2
busybox-w32-8d3efaf35eb9d138114563bba4173c39c1231198.zip
udhcpc: allow zero server-id. Closes 6614.
function old new delta bcast_or_ucast - 47 +47 udhcp_send_kernel_packet 271 295 +24 udhcpc_main 2696 2705 +9 udhcp_send_raw_packet 456 459 +3 send_release 90 76 -14 send_renew 105 77 -28 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 3/2 up/down: 83/-42) Total: 41 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--networking/udhcp/dhcpc.c36
1 files changed, 25 insertions, 11 deletions
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c
index 53d8a5e08..8dee916d9 100644
--- a/networking/udhcp/dhcpc.c
+++ b/networking/udhcp/dhcpc.c
@@ -667,6 +667,15 @@ static int raw_bcast_from_client_config_ifindex(struct dhcp_packet *packet)
667 client_config.ifindex); 667 client_config.ifindex);
668} 668}
669 669
670static int bcast_or_ucast(struct dhcp_packet *packet, uint32_t ciaddr, uint32_t server)
671{
672 if (server)
673 return udhcp_send_kernel_packet(packet,
674 ciaddr, CLIENT_PORT,
675 server, SERVER_PORT);
676 return raw_bcast_from_client_config_ifindex(packet);
677}
678
670/* Broadcast a DHCP discover packet to the network, with an optionally requested IP */ 679/* Broadcast a DHCP discover packet to the network, with an optionally requested IP */
671/* NOINLINE: limit stack usage in caller */ 680/* NOINLINE: limit stack usage in caller */
672static NOINLINE int send_discover(uint32_t xid, uint32_t requested) 681static NOINLINE int send_discover(uint32_t xid, uint32_t requested)
@@ -773,11 +782,7 @@ static NOINLINE int send_renew(uint32_t xid, uint32_t server, uint32_t ciaddr)
773 add_client_options(&packet); 782 add_client_options(&packet);
774 783
775 bb_info_msg("Sending renew..."); 784 bb_info_msg("Sending renew...");
776 if (server) 785 return bcast_or_ucast(&packet, ciaddr, server);
777 return udhcp_send_kernel_packet(&packet,
778 ciaddr, CLIENT_PORT,
779 server, SERVER_PORT);
780 return raw_bcast_from_client_config_ifindex(&packet);
781} 786}
782 787
783#if ENABLE_FEATURE_UDHCPC_ARPING 788#if ENABLE_FEATURE_UDHCPC_ARPING
@@ -826,7 +831,11 @@ static int send_release(uint32_t server, uint32_t ciaddr)
826 udhcp_add_simple_option(&packet, DHCP_SERVER_ID, server); 831 udhcp_add_simple_option(&packet, DHCP_SERVER_ID, server);
827 832
828 bb_info_msg("Sending release..."); 833 bb_info_msg("Sending release...");
829 return udhcp_send_kernel_packet(&packet, ciaddr, CLIENT_PORT, server, SERVER_PORT); 834 /* Note: normally we unicast here since "server" is not zero.
835 * However, there _are_ people who run "address-less" DHCP servers,
836 * and reportedly ISC dhcp client and Windows allow that.
837 */
838 return bcast_or_ucast(&packet, ciaddr, server);
830} 839}
831 840
832/* Returns -1 on errors that are fatal for the socket, -2 for those that aren't */ 841/* Returns -1 on errors that are fatal for the socket, -2 for those that aren't */
@@ -1648,14 +1657,19 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
1648 * might work too. 1657 * might work too.
1649 * "Next server" and router are definitely wrong ones to use, though... 1658 * "Next server" and router are definitely wrong ones to use, though...
1650 */ 1659 */
1660/* We used to ignore pcakets without DHCP_SERVER_ID.
1661 * I've got user reports from people who run "address-less" servers.
1662 * They either supply DHCP_SERVER_ID of 0.0.0.0 or don't supply it at all.
1663 * They say ISC DHCP client supports this case.
1664 */
1665 server_addr = 0;
1651 temp = udhcp_get_option(&packet, DHCP_SERVER_ID); 1666 temp = udhcp_get_option(&packet, DHCP_SERVER_ID);
1652 if (!temp) { 1667 if (!temp) {
1653 bb_error_msg("no server ID, ignoring packet"); 1668 bb_error_msg("no server ID, using 0.0.0.0");
1654 continue; 1669 } else {
1655 /* still selecting - this server looks bad */ 1670 /* it IS unaligned sometimes, don't "optimize" */
1671 move_from_unaligned32(server_addr, temp);
1656 } 1672 }
1657 /* it IS unaligned sometimes, don't "optimize" */
1658 move_from_unaligned32(server_addr, temp);
1659 /*xid = packet.xid; - already is */ 1673 /*xid = packet.xid; - already is */
1660 requested_ip = packet.yiaddr; 1674 requested_ip = packet.yiaddr;
1661 1675