Improve timeout backoff. It's a capped linear backoff. RFC specifies

capped randomized exponential, but I don't feel like incurring the cost
when the cap is so low.
Add comments for the dhcpMessage structure members.
This commit is contained in:
Nicholas J. Kain 2011-03-30 18:58:09 -04:00
parent 18e6f8d2c6
commit de23d2241d
3 changed files with 22 additions and 16 deletions

View File

@ -1,5 +1,5 @@
/* options.c - DHCP options handling
* Time-stamp: <2011-03-30 16:41:03 nk>
* Time-stamp: <2011-03-30 18:29:18 nk>
*
* (c) 2004-2011 Nicholas J. Kain <njkain at gmail dot com>
*

View File

@ -7,20 +7,23 @@
#include "config.h"
struct dhcpMessage {
uint8_t op;
uint8_t htype;
uint8_t hlen;
uint8_t hops;
uint32_t xid;
uint16_t secs;
uint16_t flags;
uint32_t ciaddr;
uint32_t yiaddr;
uint32_t siaddr;
uint32_t giaddr;
uint8_t chaddr[16];
uint8_t sname[64];
uint8_t file[128];
uint8_t op; // Message type: 1 = BOOTREQUEST for clients.
uint8_t htype; // ARP HW address type: always '1' for 10MB ethernet.
uint8_t hlen; // Hardware address length: always '6' for 10MB ethernet.
uint8_t hops; // Client sets to zero.
uint32_t xid; // Transaction ID: random number identifying session
uint16_t secs; // Filled by client: seconds since client began address
// aquisition or renewal process.
uint16_t flags; // DHCP flags
uint32_t ciaddr; // Client IP: only filled in if client is inBOUND, RENEW,
// or REBINDING and can reply to ARP requests
uint32_t yiaddr; // 'your' (client) IP address
uint32_t siaddr; // IP address of next server to use in bootstrap; returned
// in DHCPOFFER or DHCPACK by server
uint32_t giaddr; // relay agent IP: used when booting via relay agent
uint8_t chaddr[16]; // Client MAC address
uint8_t sname[64]; // Server host name (optional); null-terminated string
uint8_t file[128]; // boot file name, null-terminated string
uint32_t cookie;
uint8_t options[308]; /* 312 - cookie */
};

View File

@ -9,6 +9,8 @@
#include "arp.h"
#include "log.h"
#define DELAY_SEC (((RETRY_DELAY - (RETRY_DELAY / NUMPACKETS)) / NUMPACKETS) + 1)
static void init_selecting_timeout(struct client_state_t *cs)
{
if (cs->packetNum < NUMPACKETS) {
@ -17,7 +19,7 @@ static void init_selecting_timeout(struct client_state_t *cs)
/* broadcast */
send_discover(cs->xid, cs->requestedIP);
cs->timeout = ((cs->packetNum == NUMPACKETS - 1) ? 4 : 2) * 1000;
cs->timeout = DELAY_SEC * (cs->packetNum + 1);
cs->packetNum++;
} else {
if (client_config.background_if_no_lease) {
@ -32,6 +34,7 @@ static void init_selecting_timeout(struct client_state_t *cs)
cs->timeout = RETRY_DELAY * 1000;
}
}
#undef DELAY_SEC
static void renew_requested_timeout(struct client_state_t *cs)
{