dhclient - Have only one timeout at once.
[dragonfly.git] / sbin / dhclient / dhclient.c
index 3df23ea..159e956 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: src/sbin/dhclient/dhclient.c,v 1.144 2012/06/22 00:08:43 krw Exp $    */
+/*     $OpenBSD: src/sbin/dhclient/dhclient.c,v 1.146 2012/07/09 16:21:21 krw Exp $    */
 
 /*
  * Copyright 2004 Henning Brauer <henning@openbsd.org>
@@ -240,7 +240,7 @@ routehandler(void)
                            ifi->linkstat ? "up" : "down",
                            linkstat ? "up" : "down");
 #endif
-                       ifi->linkstat = interface_link_status(ifi->name);
+                       ifi->linkstat = interface_status(ifi->name);
                        if (ifi->linkstat) {
                                client->state = S_REBOOTING;
                                state_reboot();
@@ -340,7 +340,7 @@ main(int argc, char *argv[])
        } else
                i = 0;
 
-       while (!(ifi->linkstat = interface_link_status(ifi->name))) {
+       while (!(ifi->linkstat = interface_status(ifi->name))) {
                if (i == 0)
                        fprintf(stderr, "%s: no link ...", ifi->name);
                else if (i > 0)
@@ -454,11 +454,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) {
@@ -515,8 +511,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
@@ -600,7 +595,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)
@@ -667,8 +662,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 %ld seconds.",
            piaddr(client->active->address),
@@ -781,8 +776,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);
        }
 }
 
@@ -880,7 +874,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();
@@ -950,7 +944,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);
 }
 
 /*
@@ -992,7 +986,7 @@ state_panic(void)
                                        note("bound: renewal in %ld seconds.",
                                            client->active->renewal -
                                            cur_time);
-                                       add_timeout(client->active->renewal,
+                                       set_timeout(client->active->renewal,
                                            state_bound);
                                } else {
                                        client->state = S_BOUND;
@@ -1039,7 +1033,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();
 }
 
@@ -1067,7 +1061,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;
        }
@@ -1139,7 +1133,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