aboutsummaryrefslogtreecommitdiff
path: root/networking/udhcp/dhcpc.c
diff options
context:
space:
mode:
Diffstat (limited to 'networking/udhcp/dhcpc.c')
-rw-r--r--networking/udhcp/dhcpc.c30
1 files changed, 8 insertions, 22 deletions
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c
index 3c4e8dee1..945600c6b 100644
--- a/networking/udhcp/dhcpc.c
+++ b/networking/udhcp/dhcpc.c
@@ -123,24 +123,6 @@ static int sprint_nip(char *dest, const char *pre, const uint8_t *ip)
123 return sprintf(dest, "%s%u.%u.%u.%u", pre, ip[0], ip[1], ip[2], ip[3]); 123 return sprintf(dest, "%s%u.%u.%u.%u", pre, ip[0], ip[1], ip[2], ip[3]);
124} 124}
125 125
126static int sprint_nip6(char *dest, /*const char *pre,*/ const uint8_t *ip)
127{
128 char hexstrbuf[16 * 2];
129 bin2hex(hexstrbuf, (void*)ip, 16);
130 return sprintf(dest, /* "%s" */
131 "%.4s:%.4s:%.4s:%.4s:%.4s:%.4s:%.4s:%.4s",
132 /* pre, */
133 hexstrbuf + 0 * 4,
134 hexstrbuf + 1 * 4,
135 hexstrbuf + 2 * 4,
136 hexstrbuf + 3 * 4,
137 hexstrbuf + 4 * 4,
138 hexstrbuf + 5 * 4,
139 hexstrbuf + 6 * 4,
140 hexstrbuf + 7 * 4
141 );
142}
143
144/* really simple implementation, just count the bits */ 126/* really simple implementation, just count the bits */
145static int mton(uint32_t mask) 127static int mton(uint32_t mask)
146{ 128{
@@ -744,7 +726,7 @@ static NOINLINE int send_renew(uint32_t xid, uint32_t server, uint32_t ciaddr)
744#if ENABLE_FEATURE_UDHCPC_ARPING 726#if ENABLE_FEATURE_UDHCPC_ARPING
745/* Broadcast a DHCP decline message */ 727/* Broadcast a DHCP decline message */
746/* NOINLINE: limit stack usage in caller */ 728/* NOINLINE: limit stack usage in caller */
747static NOINLINE int send_decline(uint32_t xid, uint32_t server, uint32_t requested) 729static NOINLINE int send_decline(/*uint32_t xid,*/ uint32_t server, uint32_t requested)
748{ 730{
749 struct dhcp_packet packet; 731 struct dhcp_packet packet;
750 732
@@ -753,12 +735,14 @@ static NOINLINE int send_decline(uint32_t xid, uint32_t server, uint32_t request
753 */ 735 */
754 init_packet(&packet, DHCPDECLINE); 736 init_packet(&packet, DHCPDECLINE);
755 737
738#if 0
756 /* RFC 2131 says DHCPDECLINE's xid is randomly selected by client, 739 /* RFC 2131 says DHCPDECLINE's xid is randomly selected by client,
757 * but in case the server is buggy and wants DHCPDECLINE's xid 740 * but in case the server is buggy and wants DHCPDECLINE's xid
758 * to match the xid which started entire handshake, 741 * to match the xid which started entire handshake,
759 * we use the same xid we used in initial DHCPDISCOVER: 742 * we use the same xid we used in initial DHCPDISCOVER:
760 */ 743 */
761 packet.xid = xid; 744 packet.xid = xid;
745#endif
762 /* DHCPDECLINE uses "requested ip", not ciaddr, to store offered IP */ 746 /* DHCPDECLINE uses "requested ip", not ciaddr, to store offered IP */
763 udhcp_add_simple_option(&packet, DHCP_REQUESTED_IP, requested); 747 udhcp_add_simple_option(&packet, DHCP_REQUESTED_IP, requested);
764 748
@@ -1149,7 +1133,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
1149 int discover_retries = 3; 1133 int discover_retries = 3;
1150 uint32_t server_addr = server_addr; /* for compiler */ 1134 uint32_t server_addr = server_addr; /* for compiler */
1151 uint32_t requested_ip = 0; 1135 uint32_t requested_ip = 0;
1152 uint32_t xid = 0; 1136 uint32_t xid = xid; /* for compiler */
1153 int packet_num; 1137 int packet_num;
1154 int timeout; /* must be signed */ 1138 int timeout; /* must be signed */
1155 unsigned already_waited_sec; 1139 unsigned already_waited_sec;
@@ -1538,7 +1522,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
1538 1522
1539 switch (state) { 1523 switch (state) {
1540 case INIT_SELECTING: 1524 case INIT_SELECTING:
1541 /* Must be a DHCPOFFER to one of our xid's */ 1525 /* Must be a DHCPOFFER */
1542 if (*message == DHCPOFFER) { 1526 if (*message == DHCPOFFER) {
1543/* What exactly is server's IP? There are several values. 1527/* What exactly is server's IP? There are several values.
1544 * Example DHCP offer captured with tchdump: 1528 * Example DHCP offer captured with tchdump:
@@ -1618,7 +1602,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
1618 ) { 1602 ) {
1619 bb_info_msg("Offered address is in use " 1603 bb_info_msg("Offered address is in use "
1620 "(got ARP reply), declining"); 1604 "(got ARP reply), declining");
1621 send_decline(xid, server_addr, packet.yiaddr); 1605 send_decline(/*xid,*/ server_addr, packet.yiaddr);
1622 1606
1623 if (state != REQUESTING) 1607 if (state != REQUESTING)
1624 udhcp_run_script(NULL, "deconfig"); 1608 udhcp_run_script(NULL, "deconfig");
@@ -1655,6 +1639,8 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
1655 opt = ((opt & ~OPT_b) | OPT_f); 1639 opt = ((opt & ~OPT_b) | OPT_f);
1656 } 1640 }
1657#endif 1641#endif
1642 /* make future renew packets use different xid */
1643 /* xid = random_xid(); ...but why bother? */
1658 already_waited_sec = 0; 1644 already_waited_sec = 0;
1659 continue; /* back to main loop */ 1645 continue; /* back to main loop */
1660 } 1646 }