udhcpd: add option for tweaking arpping

Some clients have a very short timeout for sending the DHCP
DISCOVER, shorter than the arpping timeout of 2000 milliseconds
that udhcpd uses by default.

This patch allows tweaking the timeout, or disabling of arpping
altogether, at the risk of handing out addresses which are
already in use.

function                                             old     new   delta
udhcpd_main                                         1460    1501     +41
udhcpc_main                                         2814    2851     +37
packed_usage                                       29957   29974     +17
arpping                                              477     493     +16
find_free_or_expired_nip                             161     174     +13
send_offer                                           285     292      +7
nobody_responds_to_arp                                85      89      +4
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 7/0 up/down: 135/0)             Total: 135 bytes

Signed-off-by: Michel Stam <m.stam@fugro.nl>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Michel Stam
2014-10-30 11:59:04 +01:00
committed by Denys Vlasenko
parent 760d035699
commit 9f41271f3c
6 changed files with 39 additions and 21 deletions

View File

@@ -39,7 +39,8 @@ int FAST_FUNC arpping(uint32_t test_nip,
const uint8_t *safe_mac,
uint32_t from_ip,
uint8_t *from_mac,
const char *interface)
const char *interface,
unsigned timeo)
{
int timeout_ms;
struct pollfd pfd[1];
@@ -48,6 +49,9 @@ int FAST_FUNC arpping(uint32_t test_nip,
struct sockaddr addr; /* for interface name */
struct arpMsg arp;
if (!timeo)
return 1;
s = socket(PF_PACKET, SOCK_PACKET, htons(ETH_P_ARP));
if (s == -1) {
bb_perror_msg(bb_msg_can_not_create_raw_socket);
@@ -83,7 +87,7 @@ int FAST_FUNC arpping(uint32_t test_nip,
}
/* wait for arp reply, and check it */
timeout_ms = 2000;
timeout_ms = (int)timeo;
do {
typedef uint32_t aliased_uint32_t FIX_ALIASING;
int r;
@@ -124,7 +128,7 @@ int FAST_FUNC arpping(uint32_t test_nip,
* this is more under/overflow-resistant
* (people did see overflows here when system time jumps):
*/
} while ((unsigned)timeout_ms <= 2000);
} while ((unsigned)timeout_ms <= timeo);
ret:
close(s);