Enforce upper and lower sanity bounds on lease times.
Add some comments.
This commit is contained in:
parent
aaca1ab6ef
commit
987ba12982
13
ndhc/ndhc.c
13
ndhc/ndhc.c
@ -211,19 +211,18 @@ static void background(void)
|
|||||||
write_pid(pidfile);
|
write_pid(pidfile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Handle select timeout dropping to zero */
|
||||||
static void handle_timeout(void)
|
static void handle_timeout(void)
|
||||||
{
|
{
|
||||||
time_t now = time(0);
|
time_t now = time(0);
|
||||||
|
|
||||||
/* timeout dropped to zero */
|
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case INIT_SELECTING:
|
case INIT_SELECTING:
|
||||||
if (packet_num < NUMPACKETS) {
|
if (packet_num < NUMPACKETS) {
|
||||||
if (packet_num == 0)
|
if (packet_num == 0)
|
||||||
xid = random_xid();
|
xid = random_xid();
|
||||||
|
/* broadcast */
|
||||||
/* send discover packet */
|
send_discover(xid, requested_ip);
|
||||||
send_discover(xid, requested_ip); /* broadcast */
|
|
||||||
|
|
||||||
timeout = now + ((packet_num == NUMPACKETS - 1) ? 4 : 2);
|
timeout = now + ((packet_num == NUMPACKETS - 1) ? 4 : 2);
|
||||||
packet_num++;
|
packet_num++;
|
||||||
@ -347,6 +346,7 @@ static void handle_packet(void)
|
|||||||
/* Must be a DHCPOFFER to one of our xid's */
|
/* Must be a DHCPOFFER to one of our xid's */
|
||||||
if (*message == DHCPOFFER) {
|
if (*message == DHCPOFFER) {
|
||||||
if ((temp = get_option(&packet, DHCP_SERVER_ID))) {
|
if ((temp = get_option(&packet, DHCP_SERVER_ID))) {
|
||||||
|
/* Memcpy to a temp buffer to force alignment */
|
||||||
memcpy(&server_addr, temp, 4);
|
memcpy(&server_addr, temp, 4);
|
||||||
xid = packet.xid;
|
xid = packet.xid;
|
||||||
requested_ip = packet.yiaddr;
|
requested_ip = packet.yiaddr;
|
||||||
@ -369,8 +369,13 @@ static void handle_packet(void)
|
|||||||
log_line("No lease time received, assuming 1h.");
|
log_line("No lease time received, assuming 1h.");
|
||||||
lease = 60 * 60;
|
lease = 60 * 60;
|
||||||
} else {
|
} else {
|
||||||
|
/* Memcpy to a temp buffer to force alignment */
|
||||||
memcpy(&lease, temp, 4);
|
memcpy(&lease, temp, 4);
|
||||||
lease = ntohl(lease);
|
lease = ntohl(lease);
|
||||||
|
/* Enforce upper and lower bounds on lease. */
|
||||||
|
lease &= 0x0fffffff;
|
||||||
|
if (lease < RETRY_DELAY)
|
||||||
|
lease = RETRY_DELAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* enter bound state */
|
/* enter bound state */
|
||||||
|
Loading…
Reference in New Issue
Block a user