aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2019-05-15 13:08:48 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2019-05-15 13:08:48 +0200
commit8402969d4892891ddfde524fbb9ee73e076f3771 (patch)
tree67a83b2c0ca94141dc865bc34b75cbe1631f6eab
parent63d765e666a8b23e3923acecdc41be71d5679439 (diff)
downloadbusybox-8402969d4892891ddfde524fbb9ee73e076f3771.tar.gz
udhcpd: code shrink - do not fetch requested IP twice
function old new delta send_offer 444 443 -1 udhcpd_main 1454 1442 -12 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-13) Total: -13 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--networking/udhcp/dhcpd.c20
1 files changed, 9 insertions, 11 deletions
diff --git a/networking/udhcp/dhcpd.c b/networking/udhcp/dhcpd.c
index 0642fc826..bf44320a1 100644
--- a/networking/udhcp/dhcpd.c
+++ b/networking/udhcp/dhcpd.c
@@ -662,7 +662,7 @@ static uint32_t select_lease_time(struct dhcp_packet *packet)
static NOINLINE void send_offer(struct dhcp_packet *oldpacket,
uint32_t static_lease_nip,
struct dyn_lease *lease,
- uint8_t *requested_ip_opt,
+ uint32_t requested_nip,
unsigned arpping_ms)
{
struct dhcp_packet packet;
@@ -676,7 +676,6 @@ static NOINLINE void send_offer(struct dhcp_packet *oldpacket,
/* Else: */
if (!static_lease_nip) {
/* We have no static lease for client's chaddr */
- uint32_t req_nip;
const char *p_host_name;
if (lease) {
@@ -687,18 +686,16 @@ static NOINLINE void send_offer(struct dhcp_packet *oldpacket,
packet.yiaddr = lease->lease_nip;
}
/* Or: if client has requested an IP */
- else if (requested_ip_opt != NULL
- /* (read IP) */
- && (move_from_unaligned32(req_nip, requested_ip_opt), 1)
+ else if (requested_nip != 0
/* and the IP is in the lease range */
- && ntohl(req_nip) >= server_config.start_ip
- && ntohl(req_nip) <= server_config.end_ip
+ && ntohl(requested_nip) >= server_config.start_ip
+ && ntohl(requested_nip) <= server_config.end_ip
/* and */
- && ( !(lease = find_lease_by_nip(req_nip)) /* is not already taken */
+ && ( !(lease = find_lease_by_nip(requested_nip)) /* is not already taken */
|| is_expired_lease(lease) /* or is taken, but expired */
)
) {
- packet.yiaddr = req_nip;
+ packet.yiaddr = requested_nip;
}
else {
/* Otherwise, find a free IP */
@@ -913,7 +910,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
int tv;
uint8_t *server_id_opt;
uint8_t *requested_ip_opt;
- uint32_t requested_nip = requested_nip; /* for compiler */
+ uint32_t requested_nip;
uint32_t static_lease_nip;
struct dyn_lease *lease, fake_lease;
@@ -1016,6 +1013,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
}
/* Get REQUESTED_IP if present */
+ requested_nip = 0;
requested_ip_opt = udhcp_get_option32(&packet, DHCP_REQUESTED_IP);
if (requested_ip_opt) {
move_from_unaligned32(requested_nip, requested_ip_opt);
@@ -1026,7 +1024,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
case DHCPDISCOVER:
log1("received %s", "DISCOVER");
- send_offer(&packet, static_lease_nip, lease, requested_ip_opt, arpping_ms);
+ send_offer(&packet, static_lease_nip, lease, requested_nip, arpping_ms);
break;
case DHCPREQUEST: