diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2019-05-15 13:08:48 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2019-05-15 13:08:48 +0200 |
commit | 8402969d4892891ddfde524fbb9ee73e076f3771 (patch) | |
tree | 67a83b2c0ca94141dc865bc34b75cbe1631f6eab /networking | |
parent | 63d765e666a8b23e3923acecdc41be71d5679439 (diff) | |
download | busybox-w32-8402969d4892891ddfde524fbb9ee73e076f3771.tar.gz busybox-w32-8402969d4892891ddfde524fbb9ee73e076f3771.tar.bz2 busybox-w32-8402969d4892891ddfde524fbb9ee73e076f3771.zip |
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>
Diffstat (limited to 'networking')
-rw-r--r-- | networking/udhcp/dhcpd.c | 20 |
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) | |||
662 | static NOINLINE void send_offer(struct dhcp_packet *oldpacket, | 662 | static NOINLINE void send_offer(struct dhcp_packet *oldpacket, |
663 | uint32_t static_lease_nip, | 663 | uint32_t static_lease_nip, |
664 | struct dyn_lease *lease, | 664 | struct dyn_lease *lease, |
665 | uint8_t *requested_ip_opt, | 665 | uint32_t requested_nip, |
666 | unsigned arpping_ms) | 666 | unsigned arpping_ms) |
667 | { | 667 | { |
668 | struct dhcp_packet packet; | 668 | struct dhcp_packet packet; |
@@ -676,7 +676,6 @@ static NOINLINE void send_offer(struct dhcp_packet *oldpacket, | |||
676 | /* Else: */ | 676 | /* Else: */ |
677 | if (!static_lease_nip) { | 677 | if (!static_lease_nip) { |
678 | /* We have no static lease for client's chaddr */ | 678 | /* We have no static lease for client's chaddr */ |
679 | uint32_t req_nip; | ||
680 | const char *p_host_name; | 679 | const char *p_host_name; |
681 | 680 | ||
682 | if (lease) { | 681 | if (lease) { |
@@ -687,18 +686,16 @@ static NOINLINE void send_offer(struct dhcp_packet *oldpacket, | |||
687 | packet.yiaddr = lease->lease_nip; | 686 | packet.yiaddr = lease->lease_nip; |
688 | } | 687 | } |
689 | /* Or: if client has requested an IP */ | 688 | /* Or: if client has requested an IP */ |
690 | else if (requested_ip_opt != NULL | 689 | else if (requested_nip != 0 |
691 | /* (read IP) */ | ||
692 | && (move_from_unaligned32(req_nip, requested_ip_opt), 1) | ||
693 | /* and the IP is in the lease range */ | 690 | /* and the IP is in the lease range */ |
694 | && ntohl(req_nip) >= server_config.start_ip | 691 | && ntohl(requested_nip) >= server_config.start_ip |
695 | && ntohl(req_nip) <= server_config.end_ip | 692 | && ntohl(requested_nip) <= server_config.end_ip |
696 | /* and */ | 693 | /* and */ |
697 | && ( !(lease = find_lease_by_nip(req_nip)) /* is not already taken */ | 694 | && ( !(lease = find_lease_by_nip(requested_nip)) /* is not already taken */ |
698 | || is_expired_lease(lease) /* or is taken, but expired */ | 695 | || is_expired_lease(lease) /* or is taken, but expired */ |
699 | ) | 696 | ) |
700 | ) { | 697 | ) { |
701 | packet.yiaddr = req_nip; | 698 | packet.yiaddr = requested_nip; |
702 | } | 699 | } |
703 | else { | 700 | else { |
704 | /* Otherwise, find a free IP */ | 701 | /* Otherwise, find a free IP */ |
@@ -913,7 +910,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv) | |||
913 | int tv; | 910 | int tv; |
914 | uint8_t *server_id_opt; | 911 | uint8_t *server_id_opt; |
915 | uint8_t *requested_ip_opt; | 912 | uint8_t *requested_ip_opt; |
916 | uint32_t requested_nip = requested_nip; /* for compiler */ | 913 | uint32_t requested_nip; |
917 | uint32_t static_lease_nip; | 914 | uint32_t static_lease_nip; |
918 | struct dyn_lease *lease, fake_lease; | 915 | struct dyn_lease *lease, fake_lease; |
919 | 916 | ||
@@ -1016,6 +1013,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv) | |||
1016 | } | 1013 | } |
1017 | 1014 | ||
1018 | /* Get REQUESTED_IP if present */ | 1015 | /* Get REQUESTED_IP if present */ |
1016 | requested_nip = 0; | ||
1019 | requested_ip_opt = udhcp_get_option32(&packet, DHCP_REQUESTED_IP); | 1017 | requested_ip_opt = udhcp_get_option32(&packet, DHCP_REQUESTED_IP); |
1020 | if (requested_ip_opt) { | 1018 | if (requested_ip_opt) { |
1021 | move_from_unaligned32(requested_nip, requested_ip_opt); | 1019 | move_from_unaligned32(requested_nip, requested_ip_opt); |
@@ -1026,7 +1024,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv) | |||
1026 | case DHCPDISCOVER: | 1024 | case DHCPDISCOVER: |
1027 | log1("received %s", "DISCOVER"); | 1025 | log1("received %s", "DISCOVER"); |
1028 | 1026 | ||
1029 | send_offer(&packet, static_lease_nip, lease, requested_ip_opt, arpping_ms); | 1027 | send_offer(&packet, static_lease_nip, lease, requested_nip, arpping_ms); |
1030 | break; | 1028 | break; |
1031 | 1029 | ||
1032 | case DHCPREQUEST: | 1030 | case DHCPREQUEST: |