From 9f41271f3ce82e0f7196c2442614ef4e9d360928 Mon Sep 17 00:00:00 2001 From: Michel Stam Date: Thu, 30 Oct 2014 11:59:04 +0100 Subject: 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 Signed-off-by: Denys Vlasenko --- networking/udhcp/leases.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'networking/udhcp/leases.c') diff --git a/networking/udhcp/leases.c b/networking/udhcp/leases.c index c5b60b108..745340ad3 100644 --- a/networking/udhcp/leases.c +++ b/networking/udhcp/leases.c @@ -112,7 +112,7 @@ struct dyn_lease* FAST_FUNC find_lease_by_nip(uint32_t nip) } /* Check if the IP is taken; if it is, add it to the lease table */ -static int nobody_responds_to_arp(uint32_t nip, const uint8_t *safe_mac) +static int nobody_responds_to_arp(uint32_t nip, const uint8_t *safe_mac, unsigned arpping_ms) { struct in_addr temp; int r; @@ -120,7 +120,8 @@ static int nobody_responds_to_arp(uint32_t nip, const uint8_t *safe_mac) r = arpping(nip, safe_mac, server_config.server_nip, server_config.server_mac, - server_config.interface); + server_config.interface, + arpping_ms); if (r) return r; @@ -132,7 +133,7 @@ static int nobody_responds_to_arp(uint32_t nip, const uint8_t *safe_mac) } /* Find a new usable (we think) address */ -uint32_t FAST_FUNC find_free_or_expired_nip(const uint8_t *safe_mac) +uint32_t FAST_FUNC find_free_or_expired_nip(const uint8_t *safe_mac, unsigned arpping_ms) { uint32_t addr; struct dyn_lease *oldest_lease = NULL; @@ -177,7 +178,7 @@ uint32_t FAST_FUNC find_free_or_expired_nip(const uint8_t *safe_mac) lease = find_lease_by_nip(nip); if (!lease) { //TODO: DHCP servers do not always sit on the same subnet as clients: should *ping*, not arp-ping! - if (nobody_responds_to_arp(nip, safe_mac)) + if (nobody_responds_to_arp(nip, safe_mac, arpping_ms)) return nip; } else { if (!oldest_lease || lease->expires < oldest_lease->expires) @@ -194,7 +195,7 @@ uint32_t FAST_FUNC find_free_or_expired_nip(const uint8_t *safe_mac) if (oldest_lease && is_expired_lease(oldest_lease) - && nobody_responds_to_arp(oldest_lease->lease_nip, safe_mac) + && nobody_responds_to_arp(oldest_lease->lease_nip, safe_mac, arpping_ms) ) { return oldest_lease->lease_nip; } -- cgit v1.2.3