From a092a89d8f052072e562861f2968573d89e10dd5 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 16 Nov 2011 20:17:12 +0100 Subject: udhcpc6: rudimentary code to export data to script; fix IAADDR parsing Signed-off-by: Denys Vlasenko --- networking/udhcp/dhcpc.c | 18 ------------------ 1 file changed, 18 deletions(-) (limited to 'networking/udhcp/dhcpc.c') diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c index 3c4e8dee1..43d682341 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) return sprintf(dest, "%s%u.%u.%u.%u", pre, ip[0], ip[1], ip[2], ip[3]); } -static int sprint_nip6(char *dest, /*const char *pre,*/ const uint8_t *ip) -{ - char hexstrbuf[16 * 2]; - bin2hex(hexstrbuf, (void*)ip, 16); - return sprintf(dest, /* "%s" */ - "%.4s:%.4s:%.4s:%.4s:%.4s:%.4s:%.4s:%.4s", - /* pre, */ - hexstrbuf + 0 * 4, - hexstrbuf + 1 * 4, - hexstrbuf + 2 * 4, - hexstrbuf + 3 * 4, - hexstrbuf + 4 * 4, - hexstrbuf + 5 * 4, - hexstrbuf + 6 * 4, - hexstrbuf + 7 * 4 - ); -} - /* really simple implementation, just count the bits */ static int mton(uint32_t mask) { -- cgit v1.2.3 From 860491c5251886c40d6dfb89723f392db3a397a9 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 18 Nov 2011 02:09:13 +0100 Subject: udhcpc: shrink code by setting xid more economically function old new delta send_decline 90 82 -8 udhcpc_main 2649 2640 -9 Signed-off-by: Denys Vlasenko --- networking/udhcp/dhcpc.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'networking/udhcp/dhcpc.c') diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c index 43d682341..945600c6b 100644 --- a/networking/udhcp/dhcpc.c +++ b/networking/udhcp/dhcpc.c @@ -726,7 +726,7 @@ static NOINLINE int send_renew(uint32_t xid, uint32_t server, uint32_t ciaddr) #if ENABLE_FEATURE_UDHCPC_ARPING /* Broadcast a DHCP decline message */ /* NOINLINE: limit stack usage in caller */ -static NOINLINE int send_decline(uint32_t xid, uint32_t server, uint32_t requested) +static NOINLINE int send_decline(/*uint32_t xid,*/ uint32_t server, uint32_t requested) { struct dhcp_packet packet; @@ -735,12 +735,14 @@ static NOINLINE int send_decline(uint32_t xid, uint32_t server, uint32_t request */ init_packet(&packet, DHCPDECLINE); +#if 0 /* RFC 2131 says DHCPDECLINE's xid is randomly selected by client, * but in case the server is buggy and wants DHCPDECLINE's xid * to match the xid which started entire handshake, * we use the same xid we used in initial DHCPDISCOVER: */ packet.xid = xid; +#endif /* DHCPDECLINE uses "requested ip", not ciaddr, to store offered IP */ udhcp_add_simple_option(&packet, DHCP_REQUESTED_IP, requested); @@ -1131,7 +1133,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) int discover_retries = 3; uint32_t server_addr = server_addr; /* for compiler */ uint32_t requested_ip = 0; - uint32_t xid = 0; + uint32_t xid = xid; /* for compiler */ int packet_num; int timeout; /* must be signed */ unsigned already_waited_sec; @@ -1520,7 +1522,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) switch (state) { case INIT_SELECTING: - /* Must be a DHCPOFFER to one of our xid's */ + /* Must be a DHCPOFFER */ if (*message == DHCPOFFER) { /* What exactly is server's IP? There are several values. * Example DHCP offer captured with tchdump: @@ -1600,7 +1602,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) ) { bb_info_msg("Offered address is in use " "(got ARP reply), declining"); - send_decline(xid, server_addr, packet.yiaddr); + send_decline(/*xid,*/ server_addr, packet.yiaddr); if (state != REQUESTING) udhcp_run_script(NULL, "deconfig"); @@ -1637,6 +1639,8 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) opt = ((opt & ~OPT_b) | OPT_f); } #endif + /* make future renew packets use different xid */ + /* xid = random_xid(); ...but why bother? */ already_waited_sec = 0; continue; /* back to main loop */ } -- cgit v1.2.3