summaryrefslogtreecommitdiff
path: root/sbin/dhclient
diff options
context:
space:
mode:
authorKenneth R Westerback <krw@cvs.openbsd.org>2012-07-09 16:21:22 +0000
committerKenneth R Westerback <krw@cvs.openbsd.org>2012-07-09 16:21:22 +0000
commitb13a2b7df2e123e0eac1d3b424d16ff102f4d36d (patch)
tree785527ca59c2d29d8d02aaedbd3a2ccc8d30fd24 /sbin/dhclient
parentde5d303a9cb010306e55db34e84d5551a1654095 (diff)
Terminate with extreme prejudice the multiple timeout queuing
mechanism that was a holdover from when dhclient handled multiple interfaces at once. There is only one timeout possible at a time. Also move calculation of current time to just before check to see if the timeout has expired. ok beck@ guenther@
Diffstat (limited to 'sbin/dhclient')
-rw-r--r--sbin/dhclient/dhclient.c32
-rw-r--r--sbin/dhclient/dhcpd.h6
-rw-r--r--sbin/dhclient/dispatch.c110
3 files changed, 33 insertions, 115 deletions
diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c
index 3c667bc9315..90308927d28 100644
--- a/sbin/dhclient/dhclient.c
+++ b/sbin/dhclient/dhclient.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dhclient.c,v 1.145 2012/06/24 16:01:18 krw Exp $ */
+/* $OpenBSD: dhclient.c,v 1.146 2012/07/09 16:21:21 krw Exp $ */
/*
* Copyright 2004 Henning Brauer <henning@openbsd.org>
@@ -470,11 +470,7 @@ state_reboot(void)
{
/* Cancel all timeouts, since a link state change gets us here
and can happen anytime. */
- cancel_timeout(state_init);
- cancel_timeout(state_selecting);
- cancel_timeout(state_bound);
- cancel_timeout(send_discover);
- cancel_timeout(send_request);
+ cancel_timeout();
/* If we don't remember an active lease, go straight to INIT. */
if (!client->active || client->active->is_bootp) {
@@ -531,8 +527,7 @@ state_selecting(void)
/* Cancel state_selecting and send_discover timeouts, since either
one could have got us here. */
- cancel_timeout(state_selecting);
- cancel_timeout(send_discover);
+ cancel_timeout();
/* We have received one or more DHCPOFFER packets. Currently,
the only criterion by which we judge leases is whether or
@@ -614,7 +609,7 @@ dhcpack(struct iaddr client_addr, struct option_data *options)
client->new = lease;
/* Stop resending DHCPREQUEST. */
- cancel_timeout(send_request);
+ cancel_timeout();
/* Figure out the lease time. */
if (client->new->options[DHO_DHCP_LEASE_TIME].data)
@@ -681,8 +676,8 @@ bind_lease(void)
/* Write out new leases file. */
rewrite_client_leases();
- /* Set up a timeout to start the renewal process. */
- add_timeout(client->active->renewal, state_bound);
+ /* Set timeout to start the renewal process. */
+ set_timeout(client->active->renewal, state_bound);
note("bound to %s -- renewal in %d seconds.",
piaddr(client->active->address),
@@ -793,8 +788,7 @@ dhcpoffer(struct iaddr client_addr, struct option_data *options)
if (stop_selecting <= cur_time)
state_selecting();
else {
- add_timeout(stop_selecting, state_selecting);
- cancel_timeout(send_discover);
+ set_timeout(stop_selecting, state_selecting);
}
}
@@ -890,7 +884,7 @@ dhcpnak(struct iaddr client_addr, struct option_data *options)
client->active = NULL;
/* Stop sending DHCPREQUEST packets... */
- cancel_timeout(send_request);
+ cancel_timeout();
client->state = S_INIT;
state_init();
@@ -960,7 +954,7 @@ send_discover(void)
/* Send out a packet. */
send_packet(inaddr_any, &sockaddr_broadcast, NULL);
- add_timeout(cur_time + client->interval, send_discover);
+ set_timeout(cur_time + client->interval, send_discover);
}
/*
@@ -1002,7 +996,7 @@ state_panic(void)
note("bound: renewal in %d seconds.",
client->active->renewal -
cur_time);
- add_timeout(client->active->renewal,
+ set_timeout(client->active->renewal,
state_bound);
} else {
client->state = S_BOUND;
@@ -1049,7 +1043,7 @@ activate_next:
script_init("FAIL");
script_go();
client->state = S_INIT;
- add_timeout(cur_time + config->retry_interval, state_init);
+ set_timeout(cur_time + config->retry_interval, state_init);
go_daemon();
}
@@ -1077,7 +1071,7 @@ send_request(void)
client->state == S_REQUESTING) &&
interval > config->reboot_timeout) {
client->state = S_INIT;
- cancel_timeout(send_request);
+ cancel_timeout();
state_init();
return;
}
@@ -1149,7 +1143,7 @@ send_request(void)
/* Send out a packet. */
send_packet(from, &destination, NULL);
- add_timeout(cur_time + client->interval, send_request);
+ set_timeout(cur_time + client->interval, send_request);
}
void
diff --git a/sbin/dhclient/dhcpd.h b/sbin/dhclient/dhcpd.h
index f2cc00b27d7..13968245cbd 100644
--- a/sbin/dhclient/dhcpd.h
+++ b/sbin/dhclient/dhcpd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: dhcpd.h,v 1.75 2012/06/24 16:01:18 krw Exp $ */
+/* $OpenBSD: dhcpd.h,v 1.76 2012/07/09 16:21:21 krw Exp $ */
/*
* Copyright (c) 2004 Henning Brauer <henning@openbsd.org>
@@ -251,8 +251,8 @@ void discover_interface(void);
void reinitialize_interface(void);
void dispatch(void);
void got_one(void);
-void add_timeout(time_t, void (*)(void));
-void cancel_timeout(void (*)(void));
+void set_timeout(time_t, void (*)(void));
+void cancel_timeout(void);
int interface_status(char *);
int interface_link_forceup(char *);
int get_rdomain(char *);
diff --git a/sbin/dhclient/dispatch.c b/sbin/dhclient/dispatch.c
index 6bc23353711..399da2f249f 100644
--- a/sbin/dhclient/dispatch.c
+++ b/sbin/dhclient/dispatch.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dispatch.c,v 1.51 2012/06/24 16:01:18 krw Exp $ */
+/* $OpenBSD: dispatch.c,v 1.52 2012/07/09 16:21:21 krw Exp $ */
/*
* Copyright 2004 Henning Brauer <henning@openbsd.org>
@@ -47,8 +47,7 @@
#include <ifaddrs.h>
#include <poll.h>
-struct timeout *timeouts;
-static struct timeout *free_timeouts;
+struct timeout timeout;
static int interfaces_invalidated;
/*
@@ -124,10 +123,11 @@ dispatch(void)
int count, to_msec;
struct pollfd fds[2];
time_t howlong;
+ void (*func)(void);
do {
/*
- * Call any expired timeouts, and then if there's still
+ * Call expired timeout, and then if there's still
* a timeout registered, time out the select call then.
*/
another:
@@ -142,25 +142,21 @@ another:
" rdomain changed out from under us",
ifi->name);
- if (timeouts) {
- struct timeout *t;
-
- if (timeouts->when <= cur_time) {
- t = timeouts;
- timeouts = timeouts->next;
- (*(t->func))();
- t->next = free_timeouts;
- free_timeouts = t;
+ if (timeout.func) {
+ time(&cur_time);
+ if (timeout.when <= cur_time) {
+ func = timeout.func;
+ cancel_timeout();
+ (*(func))();
goto another;
}
-
/*
* Figure timeout in milliseconds, and check for
* potential overflow, so we can cram into an
* int for poll, while not polling with a
* negative timeout and blocking indefinitely.
*/
- howlong = timeouts->when - cur_time;
+ howlong = timeout.when - cur_time;
if (howlong > INT_MAX / 1000)
howlong = INT_MAX / 1000;
to_msec = howlong * 1000;
@@ -178,9 +174,6 @@ another:
/* Wait for a packet or a timeout... XXX */
count = poll(fds, 2, to_msec);
- /* Get the current time... */
- time(&cur_time);
-
/* Not likely to be transitory... */
if (count == -1) {
if (errno == EAGAIN || errno == EINTR) {
@@ -317,86 +310,17 @@ active:
}
void
-add_timeout(time_t when, void (*where)(void))
+set_timeout(time_t when, void (*where)(void))
{
- struct timeout *t, *q;
-
- /* See if this timeout supersedes an existing timeout. */
- t = NULL;
- for (q = timeouts; q; q = q->next) {
- if (q->func == where) {
- if (t)
- t->next = q->next;
- else
- timeouts = q->next;
- break;
- }
- t = q;
- }
-
- /* If we didn't supersede a timeout, allocate a timeout
- structure now. */
- if (!q) {
- if (free_timeouts) {
- q = free_timeouts;
- free_timeouts = q->next;
- q->func = where;
- } else {
- q = malloc(sizeof(struct timeout));
- if (!q)
- error("Can't allocate timeout structure!");
- q->func = where;
- }
- }
-
- q->when = when;
-
- /* Now sort this timeout into the timeout list. */
-
- /* Beginning of list? */
- if (!timeouts || timeouts->when > q->when) {
- q->next = timeouts;
- timeouts = q;
- return;
- }
-
- /* Middle of list? */
- for (t = timeouts; t->next; t = t->next) {
- if (t->next->when > q->when) {
- q->next = t->next;
- t->next = q;
- return;
- }
- }
-
- /* End of list. */
- t->next = q;
- q->next = NULL;
+ timeout.when = when;
+ timeout.func = where;
}
void
-cancel_timeout(void (*where)(void))
+cancel_timeout(void)
{
- struct timeout *t, *q;
-
- /* Look for this timeout on the list, and unlink it if we find it. */
- t = NULL;
- for (q = timeouts; q; q = q->next) {
- if (q->func == where) {
- if (t)
- t->next = q->next;
- else
- timeouts = q->next;
- break;
- }
- t = q;
- }
-
- /* If we found the timeout, put it on the free list. */
- if (q) {
- q->next = free_timeouts;
- free_timeouts = q;
- }
+ timeout.when = 0;
+ timeout.func = NULL;
}
int