diff options
author | Denys Vlasenko | 2010-03-21 00:43:11 +0100 |
---|---|---|
committer | Denys Vlasenko | 2010-03-21 00:43:11 +0100 |
commit | e5ce91b41b657a0dbd1db442ebc47f4c935e7d1f (patch) | |
tree | ca7537fff5a9026bdfe5c5c5104b65d6c2a5ebd0 /networking/udhcp/leases.c | |
parent | 87fa216e1e388c537cda2cff126eea816a4135ac (diff) | |
download | busybox-e5ce91b41b657a0dbd1db442ebc47f4c935e7d1f.zip busybox-e5ce91b41b657a0dbd1db442ebc47f4c935e7d1f.tar.gz |
udhcp: code shrink; disable time and log server options
function old new delta
add_server_options - 100 +100
udhcp_add_simple_option 92 90 -2
nobody_responds_to_arp 88 85 -3
dhcp_options 66 62 -4
udhcp_add_option_string 104 94 -10
udhcp_run_script 665 654 -11
dhcp_option_strings 203 188 -15
static.blank_chaddr 16 - -16
send_ACK 211 180 -31
add_bootp_options 61 - -61
udhcpd_main 1925 1846 -79
------------------------------------------------------------------------------
(add/remove: 1/2 grow/shrink: 0/8 up/down: 100/-232) Total: -132 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'networking/udhcp/leases.c')
-rw-r--r-- | networking/udhcp/leases.c | 33 |
1 files changed, 16 insertions, 17 deletions
diff --git a/networking/udhcp/leases.c b/networking/udhcp/leases.c index 78b0d0a..efe67cf 100644 --- a/networking/udhcp/leases.c +++ b/networking/udhcp/leases.c @@ -29,16 +29,15 @@ static struct dyn_lease *oldest_expired_lease(void) } -/* Clear every lease out that chaddr OR yiaddr matches and is nonzero */ -static void clear_lease(const uint8_t *chaddr, uint32_t yiaddr) +/* Clear out all leases with matching nonzero chaddr OR yiaddr. + * If chaddr == NULL, this is a conflict lease. + */ +static void clear_leases(const uint8_t *chaddr, uint32_t yiaddr) { - unsigned i, j; - - for (j = 0; j < 16 && !chaddr[j]; j++) - continue; + unsigned i; for (i = 0; i < server_config.max_leases; i++) { - if ((j != 16 && memcmp(g_leases[i].lease_mac, chaddr, 6) == 0) + if ((chaddr && memcmp(g_leases[i].lease_mac, chaddr, 6) == 0) || (yiaddr && g_leases[i].lease_nip == yiaddr) ) { memset(&g_leases[i], 0, sizeof(g_leases[i])); @@ -47,7 +46,9 @@ static void clear_lease(const uint8_t *chaddr, uint32_t yiaddr) } -/* Add a lease into the table, clearing out any old ones */ +/* Add a lease into the table, clearing out any old ones + * If chaddr == NULL, this is a conflict lease. + */ struct dyn_lease* FAST_FUNC add_lease( const uint8_t *chaddr, uint32_t yiaddr, leasetime_t leasetime, @@ -56,12 +57,12 @@ struct dyn_lease* FAST_FUNC add_lease( struct dyn_lease *oldest; /* clean out any old ones */ - clear_lease(chaddr, yiaddr); + clear_leases(chaddr, yiaddr); oldest = oldest_expired_lease(); if (oldest) { - oldest->hostname[0] = '\0'; + memset(oldest, 0, sizeof(*oldest)); if (hostname) { char *p; if (hostname_len > sizeof(oldest->hostname)) @@ -74,7 +75,8 @@ struct dyn_lease* FAST_FUNC add_lease( p++; } } - memcpy(oldest->lease_mac, chaddr, 6); + if (chaddr) + memcpy(oldest->lease_mac, chaddr, 6); oldest->lease_nip = yiaddr; oldest->expires = time(NULL) + leasetime; } @@ -119,10 +121,6 @@ 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) { - /* 16 zero bytes */ - static const uint8_t blank_chaddr[16] = { 0 }; - /* = { 0 } helps gcc to put it in rodata, not bss */ - struct in_addr temp; int r; @@ -136,7 +134,7 @@ static int nobody_responds_to_arp(uint32_t nip, const uint8_t *safe_mac) temp.s_addr = nip; bb_info_msg("%s belongs to someone, reserving it for %u seconds", inet_ntoa(temp), (unsigned)server_config.conflict_time); - add_lease(blank_chaddr, nip, server_config.conflict_time, NULL, 0); + add_lease(NULL, nip, server_config.conflict_time, NULL, 0); return 0; } @@ -173,7 +171,8 @@ uint32_t FAST_FUNC find_free_or_expired_nip(const uint8_t *safe_mac) } } - if (oldest_lease && is_expired_lease(oldest_lease) + if (oldest_lease + && is_expired_lease(oldest_lease) && nobody_responds_to_arp(oldest_lease->lease_nip, safe_mac) ) { return oldest_lease->lease_nip; |