udhcpd: fix a bug in add_lease where it was reading at [-1]
It is not correct when we read lease file! Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
@@ -130,7 +130,8 @@ int FAST_FUNC send_offer(struct dhcp_packet *oldpacket)
|
||||
uint32_t req_nip;
|
||||
uint32_t lease_time_sec = server_config.max_lease_sec;
|
||||
uint32_t static_lease_ip;
|
||||
uint8_t *req_ip_opt, *p_host_name;
|
||||
uint8_t *req_ip_opt;
|
||||
const char *p_host_name;
|
||||
struct option_set *curr;
|
||||
struct in_addr addr;
|
||||
|
||||
@@ -173,8 +174,13 @@ int FAST_FUNC send_offer(struct dhcp_packet *oldpacket)
|
||||
bb_error_msg("no IP addresses to give - OFFER abandoned");
|
||||
return -1;
|
||||
}
|
||||
p_host_name = get_option(oldpacket, DHCP_HOST_NAME);
|
||||
if (!add_lease(packet.chaddr, packet.yiaddr, server_config.offer_time, p_host_name)) {
|
||||
p_host_name = (const char*) get_option(oldpacket, DHCP_HOST_NAME);
|
||||
if (add_lease(packet.chaddr, packet.yiaddr,
|
||||
server_config.offer_time,
|
||||
p_host_name,
|
||||
p_host_name ? (unsigned char)p_host_name[OPT_LEN - OPT_DATA] : 0
|
||||
) == 0
|
||||
) {
|
||||
bb_error_msg("lease pool is full - OFFER abandoned");
|
||||
return -1;
|
||||
}
|
||||
@@ -218,7 +224,7 @@ int FAST_FUNC send_ACK(struct dhcp_packet *oldpacket, uint32_t yiaddr)
|
||||
struct option_set *curr;
|
||||
uint32_t lease_time_sec;
|
||||
struct in_addr addr;
|
||||
uint8_t *p_host_name;
|
||||
const char *p_host_name;
|
||||
|
||||
init_packet(&packet, oldpacket, DHCPACK);
|
||||
packet.yiaddr = yiaddr;
|
||||
@@ -242,8 +248,12 @@ int FAST_FUNC send_ACK(struct dhcp_packet *oldpacket, uint32_t yiaddr)
|
||||
if (send_packet(&packet, 0) < 0)
|
||||
return -1;
|
||||
|
||||
p_host_name = get_option(oldpacket, DHCP_HOST_NAME);
|
||||
add_lease(packet.chaddr, packet.yiaddr, lease_time_sec, p_host_name);
|
||||
p_host_name = (const char*) get_option(oldpacket, DHCP_HOST_NAME);
|
||||
add_lease(packet.chaddr, packet.yiaddr,
|
||||
lease_time_sec,
|
||||
p_host_name,
|
||||
p_host_name ? (unsigned char)p_host_name[OPT_LEN - OPT_DATA] : 0
|
||||
);
|
||||
if (ENABLE_FEATURE_UDHCPD_WRITE_LEASES_EARLY) {
|
||||
/* rewrite the file with leases at every new acceptance */
|
||||
write_leases();
|
||||
|
||||
Reference in New Issue
Block a user