Add defines for toggling packet send count before timeout and timeout length.

This commit is contained in:
Nicholas J. Kain 2010-11-12 18:19:19 -05:00
parent c0703fc8c9
commit e781322b4d

View File

@ -53,6 +53,8 @@
#include "malloc.h" #include "malloc.h"
#define VERSION "1.0" #define VERSION "1.0"
#define NUMPACKETS 3 /* number of packets to send before delay */
#define RETRY_DELAY 30 /* time in seconds to delay after sending NUMPACKETS */
static unsigned long requested_ip, server_addr, timeout; static unsigned long requested_ip, server_addr, timeout;
static unsigned long lease, t1, t2, xid, start; static unsigned long lease, t1, t2, xid, start;
@ -197,14 +199,14 @@ static void handle_timeout(void)
/* timeout dropped to zero */ /* timeout dropped to zero */
switch (state) { switch (state) {
case INIT_SELECTING: case INIT_SELECTING:
if (packet_num < 3) { if (packet_num < NUMPACKETS) {
if (packet_num == 0) if (packet_num == 0)
xid = random_xid(); xid = random_xid();
/* send discover packet */ /* send discover packet */
send_discover(xid, requested_ip); /* broadcast */ send_discover(xid, requested_ip); /* broadcast */
timeout = now + ((packet_num == 2) ? 4 : 2); timeout = now + ((packet_num == NUMPACKETS - 1) ? 4 : 2);
packet_num++; packet_num++;
} else { } else {
if (client_config.background_if_no_lease) { if (client_config.background_if_no_lease) {
@ -216,12 +218,12 @@ static void handle_timeout(void)
} }
/* wait to try again */ /* wait to try again */
packet_num = 0; packet_num = 0;
timeout = now + 60; timeout = now + RETRY_DELAY;
} }
break; break;
case RENEW_REQUESTED: case RENEW_REQUESTED:
case REQUESTING: case REQUESTING:
if (packet_num < 3) { if (packet_num < NUMPACKETS) {
/* send request packet */ /* send request packet */
if (state == RENEW_REQUESTED) if (state == RENEW_REQUESTED)
/* unicast */ /* unicast */
@ -229,7 +231,7 @@ static void handle_timeout(void)
else else
/* broadcast */ /* broadcast */
send_selecting(xid, server_addr, requested_ip); send_selecting(xid, server_addr, requested_ip);
timeout = now + ((packet_num == 2) ? 10 : 2); timeout = now + ((packet_num == NUMPACKETS - 1) ? 10 : 2);
packet_num++; packet_num++;
} else { } else {
/* timed out, go back to init state */ /* timed out, go back to init state */