-/* $OpenBSD: dhclient.c,v 1.422 2017/06/14 16:09:42 krw Exp $ */
+/* $OpenBSD: dhclient.c,v 1.423 2017/06/14 16:29:58 krw Exp $ */
/*
* Copyright 2004 Henning Brauer <henning@openbsd.org>
#endif /* DEBUG */
ifi->linkstat = linkstat;
if (ifi->linkstat) {
- if (client->state == S_PREBOOT) {
+ if (ifi->state == S_PREBOOT) {
state_preboot(ifi);
get_hw_address(ifi);
} else {
- client->state = S_REBOOTING;
+ ifi->state = S_REBOOTING;
state_reboot(ifi);
}
} else {
time(&ifi->startup_time);
if (ifi->linkstat) {
- ifi->client->state = S_REBOOTING;
+ ifi->state = S_REBOOTING;
state_reboot(ifi);
} else {
- ifi->client->state = S_PREBOOT;
+ ifi->state = S_PREBOOT;
state_preboot(ifi);
}
state_preboot(void *xifi)
{
struct interface_info *ifi = xifi;
- struct client_state *client = ifi->client;
static int preamble;
time_t cur_time;
int interval;
}
if (ifi->linkstat) {
- client->state = S_REBOOTING;
+ ifi->state = S_REBOOTING;
set_timeout_interval(1, state_reboot, ifi);
} else {
if (interval > config->link_timeout)
go_daemon();
- client->state = S_PREBOOT;
+ ifi->state = S_PREBOOT;
set_timeout_interval(1, state_preboot, ifi);
}
}
/* If we don't remember an active lease, go straight to INIT. */
if (!client->active || client->active->is_bootp) {
- client->state = S_INIT;
+ ifi->state = S_INIT;
state_init(ifi);
return;
}
ifi->xid = arc4random();
make_request(ifi, client->active);
- client->destination.s_addr = INADDR_BROADCAST;
+ ifi->destination.s_addr = INADDR_BROADCAST;
ifi->first_sending = time(NULL);
- client->interval = 0;
+ ifi->interval = 0;
send_request(ifi);
}
ifi->xid = arc4random();
make_discover(ifi, client->active);
- client->destination.s_addr = INADDR_BROADCAST;
- client->state = S_SELECTING;
+ ifi->destination.s_addr = INADDR_BROADCAST;
+ ifi->state = S_SELECTING;
ifi->first_sending = time(NULL);
- client->interval = 0;
+ ifi->interval = 0;
send_discover(ifi);
}
memcpy(option->data, "\x00\x00\x27\x10", 4);
}
- client->state = S_REQUESTING;
+ ifi->state = S_REQUESTING;
bind_lease(ifi);
return;
}
- client->destination.s_addr = INADDR_BROADCAST;
- client->state = S_REQUESTING;
+ ifi->destination.s_addr = INADDR_BROADCAST;
+ ifi->state = S_REQUESTING;
ifi->first_sending = time(NULL);
- client->interval = 0;
+ ifi->interval = 0;
/*
* Make a DHCPREQUEST packet from the lease we picked. Keep
struct client_state *client = ifi->client;
struct client_lease *lease;
- if (client->state != S_REBOOTING &&
- client->state != S_REQUESTING &&
- client->state != S_RENEWING &&
- client->state != S_REBINDING) {
+ if (ifi->state != S_REBOOTING &&
+ ifi->state != S_REQUESTING &&
+ ifi->state != S_RENEWING &&
+ ifi->state != S_REBINDING) {
#ifdef DEBUG
log_debug("Unexpected %s. State #%d", info, client->state);
#endif /* DEBUG */
make_decline(ifi, lease);
send_decline(ifi);
free_client_lease(lease);
- client->state = S_INIT;
+ ifi->state = S_INIT;
state_init(ifi);
return;
}
* A duplicate lease once we are responsible & S_RENEWING means we
* don't need to change the interface, routing table or resolv.conf.
*/
- if ((ifi->flags & IFI_IS_RESPONSIBLE) && client->state == S_RENEWING &&
+ if ((ifi->flags & IFI_IS_RESPONSIBLE) && ifi->state == S_RENEWING &&
compare_lease(client->active, client->new) == 0) {
client->new->resolv_conf = client->active->resolv_conf;
client->active->resolv_conf = NULL;
/* Write out new leases file. */
rewrite_client_leases(ifi);
- client->state = S_BOUND;
+ ifi->state = S_BOUND;
/* Set timeout to start the renewal process. */
set_timeout(client->active->renewal, state_bound, ifi);
ifi->xid = arc4random();
make_request(ifi, client->active);
- dest = &client->destination;
+ dest = &ifi->destination;
opt = &client->active->options[DHO_DHCP_SERVER_IDENTIFIER];
if (opt->len == sizeof(*dest))
dest->s_addr = INADDR_BROADCAST;
ifi->first_sending = time(NULL);
- client->interval = 0;
- client->state = S_RENEWING;
+ ifi->interval = 0;
+ ifi->state = S_RENEWING;
send_request(ifi);
}
struct client_lease *lease, *lp;
time_t stop_selecting;
- if (client->state != S_SELECTING) {
+ if (ifi->state != S_SELECTING) {
#ifdef DEBUG
log_debug("Unexpected %s. State #%d.", info, client->state);
#endif /* DEBUG */
if (TAILQ_EMPTY(&client->offered_leases)) {
TAILQ_INSERT_HEAD(&client->offered_leases, lease, next);
- } else if (lease->address.s_addr == client->requested_address.s_addr) {
+ } else if (lease->address.s_addr == ifi->requested_address.s_addr) {
/* The expected lease - put it at the head of the list. */
TAILQ_INSERT_HEAD(&client->offered_leases, lease, next);
} else {
{
struct client_state *client = ifi->client;
- if (client->state != S_REBOOTING &&
- client->state != S_REQUESTING &&
- client->state != S_RENEWING &&
- client->state != S_REBINDING) {
+ if (ifi->state != S_REBOOTING &&
+ ifi->state != S_REQUESTING &&
+ ifi->state != S_RENEWING &&
+ ifi->state != S_REBINDING) {
#ifdef DEBUG
log_debug("Unexpected %s. State #%d", info, client->state);
#endif /* DEBUG */
/* Stop sending DHCPREQUEST packets. */
cancel_timeout();
- client->state = S_INIT;
+ ifi->state = S_INIT;
state_init(ifi);
}
send_discover(void *xifi)
{
struct interface_info *ifi = xifi;
- struct client_state *client = ifi->client;
struct dhcp_packet *packet = &ifi->sent_packet;
time_t cur_time;
ssize_t rslt;
* number between zero and two times itself. On average, this
* means that it will double with every transmission.
*/
- if (!client->interval)
- client->interval = config->initial_interval;
+ if (!ifi->interval)
+ ifi->interval = config->initial_interval;
else {
- client->interval += arc4random_uniform(2 * client->interval);
+ ifi->interval += arc4random_uniform(2 * ifi->interval);
}
/* Don't backoff past cutoff. */
- if (client->interval > config->backoff_cutoff)
- client->interval = config->backoff_cutoff;
+ if (ifi->interval > config->backoff_cutoff)
+ ifi->interval = config->backoff_cutoff;
/* If the backoff would take us to the panic timeout, just use that
as the interval. */
- if (cur_time + client->interval >
+ if (cur_time + ifi->interval >
ifi->first_sending + config->timeout)
- client->interval = (ifi->first_sending +
+ ifi->interval = (ifi->first_sending +
config->timeout) - cur_time + 1;
/* Record the number of seconds since we started sending. */
ifi->secs = packet->secs;
log_info("DHCPDISCOVER on %s - interval %lld", ifi->name,
- (long long)client->interval);
+ (long long)ifi->interval);
rslt = send_packet(ifi, inaddr_any, inaddr_broadcast);
if (rslt == -1 && errno == EAFNOSUPPORT) {
log_warnx("dhclient cannot be used on %s", ifi->name);
quit = INTERNALSIG;
} else
- set_timeout_interval(client->interval, send_discover, ifi);
+ set_timeout_interval(ifi->interval, send_discover, ifi);
}
/*
lp = get_recorded_lease(ifi);
if (lp) {
client->new = lp;
- client->state = S_REQUESTING;
+ ifi->state = S_REQUESTING;
bind_lease(ifi);
return;
}
* No leases were available, or what was available didn't work
*/
log_info("No working leases in persistent database - sleeping.");
- client->state = S_INIT;
+ ifi->state = S_INIT;
set_timeout_interval(config->retry_interval, state_init, ifi);
go_daemon();
}
* reused our old address. In the former case, we're hosed
* anyway. This is not a win-prone situation.
*/
- if (client->state == S_REBOOTING && interval >
+ if (ifi->state == S_REBOOTING && interval >
config->reboot_timeout) {
- client->state = S_INIT;
+ ifi->state = S_INIT;
cancel_timeout();
state_init(ifi);
return;
* If the lease has expired, relinquish the address and go back to the
* INIT state.
*/
- if (client->state != S_REQUESTING &&
+ if (ifi->state != S_REQUESTING &&
cur_time > client->active->expiry) {
if (client->active)
delete_address(client->active->address);
- client->state = S_INIT;
+ ifi->state = S_INIT;
state_init(ifi);
return;
}
/* Do the exponential backoff. */
- if (!client->interval) {
- if (client->state == S_REBOOTING)
- client->interval = config->reboot_timeout;
+ if (!ifi->interval) {
+ if (ifi->state == S_REBOOTING)
+ ifi->interval = config->reboot_timeout;
else
- client->interval = config->initial_interval;
+ ifi->interval = config->initial_interval;
} else
- client->interval += arc4random_uniform(2 * client->interval);
+ ifi->interval += arc4random_uniform(2 * ifi->interval);
/* Don't backoff past cutoff. */
- if (client->interval > config->backoff_cutoff)
- client->interval = config->backoff_cutoff;
+ if (ifi->interval > config->backoff_cutoff)
+ ifi->interval = config->backoff_cutoff;
/*
* If the backoff would take us to the expiry time, just set the
* timeout to the expiry time.
*/
- if (client->state != S_REQUESTING && cur_time + client->interval >
+ if (ifi->state != S_REQUESTING && cur_time + ifi->interval >
client->active->expiry)
- client->interval = client->active->expiry - cur_time + 1;
+ ifi->interval = client->active->expiry - cur_time + 1;
/*
* If the reboot timeout has expired, or the lease rebind time has
* than unicasting.
*/
memset(&destination, 0, sizeof(destination));
- if (client->state == S_REQUESTING ||
- client->state == S_REBOOTING ||
+ if (ifi->state == S_REQUESTING ||
+ ifi->state == S_REBOOTING ||
cur_time > client->active->rebind ||
interval > config->reboot_timeout)
destination.sin_addr.s_addr = INADDR_BROADCAST;
else
- destination.sin_addr.s_addr = client->destination.s_addr;
+ destination.sin_addr.s_addr = ifi->destination.s_addr;
- if (client->state != S_REQUESTING)
+ if (ifi->state != S_REQUESTING)
from.s_addr = client->active->address.s_addr;
else
from.s_addr = INADDR_ANY;
/* Record the number of seconds since we started sending. */
- if (client->state == S_REQUESTING)
+ if (ifi->state == S_REQUESTING)
packet->secs = ifi->secs;
else {
if (interval < UINT16_MAX)
send_packet(ifi, from, destination.sin_addr);
- set_timeout_interval(client->interval, send_request, ifi);
+ set_timeout_interval(ifi->interval, send_request, ifi);
}
void
void
make_discover(struct interface_info *ifi, struct client_lease *lease)
{
- struct client_state *client = ifi->client;
struct option_data options[256];
struct dhcp_packet *packet = &ifi->sent_packet;
unsigned char discover = DHCPDISCOVER;
/* If we had an address, try to get it again. */
if (lease) {
- client->requested_address = lease->address;
+ ifi->requested_address = lease->address;
i = DHO_DHCP_REQUESTED_ADDRESS;
options[i].data = (char *)&lease->address;
options[i].len = sizeof(lease->address);
} else
- client->requested_address.s_addr = INADDR_ANY;
+ ifi->requested_address.s_addr = INADDR_ANY;
/* Send any options requested in the config file. */
for (i = 0; i < 256; i++)
void
make_request(struct interface_info *ifi, struct client_lease * lease)
{
- struct client_state *client = ifi->client;
struct option_data options[256];
struct dhcp_packet *packet = &ifi->sent_packet;
unsigned char request = DHCPREQUEST;
* If we are requesting an address that hasn't yet been assigned
* to us, use the DHCP Requested Address option.
*/
- if (client->state == S_REQUESTING) {
+ if (ifi->state == S_REQUESTING) {
/* Send back the server identifier. */
i = DHO_DHCP_SERVER_IDENTIFIER;
options[i].data = lease->options[i].data;
options[i].len = lease->options[i].len;
}
- if (client->state == S_REQUESTING ||
- client->state == S_REBOOTING) {
- client->requested_address = lease->address;
+ if (ifi->state == S_REQUESTING ||
+ ifi->state == S_REBOOTING) {
+ ifi->requested_address = lease->address;
i = DHO_DHCP_REQUESTED_ADDRESS;
options[i].data = (char *)&lease->address.s_addr;
options[i].len = sizeof(in_addr_t);
* If we own the address we're requesting, put it in ciaddr. Otherwise
* set ciaddr to zero.
*/
- if (client->state == S_BOUND ||
- client->state == S_RENEWING ||
- client->state == S_REBINDING)
+ if (ifi->state == S_BOUND ||
+ ifi->state == S_RENEWING ||
+ ifi->state == S_REBINDING)
packet->ciaddr.s_addr = lease->address.s_addr;
else
packet->ciaddr.s_addr = INADDR_ANY;