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>
This commit is contained in:
parent
63d765e666
commit
8402969d48
@ -662,7 +662,7 @@ static uint32_t select_lease_time(struct dhcp_packet *packet)
|
|||||||
static NOINLINE void send_offer(struct dhcp_packet *oldpacket,
|
static NOINLINE void send_offer(struct dhcp_packet *oldpacket,
|
||||||
uint32_t static_lease_nip,
|
uint32_t static_lease_nip,
|
||||||
struct dyn_lease *lease,
|
struct dyn_lease *lease,
|
||||||
uint8_t *requested_ip_opt,
|
uint32_t requested_nip,
|
||||||
unsigned arpping_ms)
|
unsigned arpping_ms)
|
||||||
{
|
{
|
||||||
struct dhcp_packet packet;
|
struct dhcp_packet packet;
|
||||||
@ -676,7 +676,6 @@ static NOINLINE void send_offer(struct dhcp_packet *oldpacket,
|
|||||||
/* Else: */
|
/* Else: */
|
||||||
if (!static_lease_nip) {
|
if (!static_lease_nip) {
|
||||||
/* We have no static lease for client's chaddr */
|
/* We have no static lease for client's chaddr */
|
||||||
uint32_t req_nip;
|
|
||||||
const char *p_host_name;
|
const char *p_host_name;
|
||||||
|
|
||||||
if (lease) {
|
if (lease) {
|
||||||
@ -687,18 +686,16 @@ static NOINLINE void send_offer(struct dhcp_packet *oldpacket,
|
|||||||
packet.yiaddr = lease->lease_nip;
|
packet.yiaddr = lease->lease_nip;
|
||||||
}
|
}
|
||||||
/* Or: if client has requested an IP */
|
/* Or: if client has requested an IP */
|
||||||
else if (requested_ip_opt != NULL
|
else if (requested_nip != 0
|
||||||
/* (read IP) */
|
|
||||||
&& (move_from_unaligned32(req_nip, requested_ip_opt), 1)
|
|
||||||
/* and the IP is in the lease range */
|
/* and the IP is in the lease range */
|
||||||
&& ntohl(req_nip) >= server_config.start_ip
|
&& ntohl(requested_nip) >= server_config.start_ip
|
||||||
&& ntohl(req_nip) <= server_config.end_ip
|
&& ntohl(requested_nip) <= server_config.end_ip
|
||||||
/* and */
|
/* 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 */
|
|| is_expired_lease(lease) /* or is taken, but expired */
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
packet.yiaddr = req_nip;
|
packet.yiaddr = requested_nip;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/* Otherwise, find a free IP */
|
/* Otherwise, find a free IP */
|
||||||
@ -913,7 +910,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
int tv;
|
int tv;
|
||||||
uint8_t *server_id_opt;
|
uint8_t *server_id_opt;
|
||||||
uint8_t *requested_ip_opt;
|
uint8_t *requested_ip_opt;
|
||||||
uint32_t requested_nip = requested_nip; /* for compiler */
|
uint32_t requested_nip;
|
||||||
uint32_t static_lease_nip;
|
uint32_t static_lease_nip;
|
||||||
struct dyn_lease *lease, fake_lease;
|
struct dyn_lease *lease, fake_lease;
|
||||||
|
|
||||||
@ -1016,6 +1013,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Get REQUESTED_IP if present */
|
/* Get REQUESTED_IP if present */
|
||||||
|
requested_nip = 0;
|
||||||
requested_ip_opt = udhcp_get_option32(&packet, DHCP_REQUESTED_IP);
|
requested_ip_opt = udhcp_get_option32(&packet, DHCP_REQUESTED_IP);
|
||||||
if (requested_ip_opt) {
|
if (requested_ip_opt) {
|
||||||
move_from_unaligned32(requested_nip, 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:
|
case DHCPDISCOVER:
|
||||||
log1("received %s", "DISCOVER");
|
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;
|
break;
|
||||||
|
|
||||||
case DHCPREQUEST:
|
case DHCPREQUEST:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user