-/* $OpenBSD: dhclient.c,v 1.558 2018/02/06 21:09:10 krw Exp $ */
+/* $OpenBSD: dhclient.c,v 1.559 2018/02/06 23:45:15 krw Exp $ */
/*
* Copyright 2004 Henning Brauer <henning@openbsd.org>
void interface_link_forceup(char *, int);
int interface_status(char *);
void get_hw_address(struct interface_info *);
+void tick_msg(const char *, int, time_t, time_t);
struct client_lease *apply_defaults(struct client_lease *);
struct client_lease *clone_lease(struct client_lease *);
void
state_preboot(struct interface_info *ifi)
{
- static int preamble;
- time_t cur_time;
- int interval;
+ time_t cur_time, tickstart, tickstop;
time(&cur_time);
- interval = cur_time - ifi->startup_time;
+ tickstart = ifi->startup_time + 3;
+ tickstop = ifi->startup_time + config->link_timeout;
ifi->linkstat = interface_status(ifi->name);
- if (isatty(STDERR_FILENO) != 0 && interval > 3) {
- if (preamble == 0 && ifi->linkstat == 0) {
- fprintf(stderr, "%s: no link ....", ifi->name);
- preamble = 1;
- }
- if (preamble != 0) {
- if (ifi->linkstat != 0)
- fprintf(stderr, " got link\n");
- else if (interval > config->link_timeout)
- fprintf(stderr, " sleeping\n");
- else
- fprintf(stderr, ".");
- fflush(stderr);
- }
- }
-
if (ifi->linkstat != 0) {
+ tick_msg("link", 1, tickstart, tickstop);
if ((ifi->flags & IFI_VALID_LLADDR) == 0)
get_hw_address(ifi);
ifi->state = S_REBOOTING;
state_reboot(ifi);
- } else if (interval > config->link_timeout) {
- go_daemon();
- cancel_timeout(ifi); /* Wait for RTM_IFINFO. */
} else {
- set_timeout(ifi, 1, state_preboot);
+ tick_msg("link", 0, tickstart, tickstop);
+ if (cur_time > tickstop)
+ cancel_timeout(ifi); /* Wait for RTM_IFINFO. */
+ else
+ set_timeout(ifi, 1, state_preboot);
}
}
struct proposal *offered_proposal = NULL;
struct proposal *effective_proposal = NULL;
char *msg;
- time_t cur_time, renewal;
+ time_t cur_time, renewal, tickstart, tickstop;
int rslt, seen;
time(&cur_time);
+ tickstart = ifi->first_sending + 3;
+ tickstop = ifi->startup_time + config->link_timeout;
+ if ((cmd_opts & OPT_VERBOSE) == 0)
+ tick_msg("lease", 1, tickstart, tickstop);
+
lease = apply_defaults(ifi->offer);
/*
send_discover(struct interface_info *ifi)
{
struct dhcp_packet *packet = &ifi->sent_packet;
- time_t cur_time;
+ time_t cur_time, interval, tickstart, tickstop;
ssize_t rslt;
- int interval;
time(&cur_time);
/* Figure out how long it's been since we started transmitting. */
interval = cur_time - ifi->first_sending;
+ tickstart = ifi->first_sending + 3;
+ tickstop = ifi->startup_time + config->link_timeout;
+
if (interval > config->timeout) {
state_panic(ifi);
return;
* link_timeout we just go daemon and finish things up in the
* background.
*/
- if (cur_time - ifi->startup_time < config->link_timeout)
+ if (cur_time < tickstop) {
+ if ((cmd_opts & OPT_VERBOSE) == 0)
+ tick_msg("lease", 0, tickstart, tickstop);
ifi->interval = 1;
- else {
- if (isatty(STDERR_FILENO) != 0)
- fprintf(stderr, "%s: no lease .... sleeping\n",
- log_procname);
- go_daemon();
+ } else {
+ tick_msg("lease", 0, tickstart, tickstop);
}
/* Record the number of seconds since we started sending. */
struct in_addr from;
struct dhcp_packet *packet = &ifi->sent_packet;
ssize_t rslt;
- time_t cur_time;
- int interval;
+ time_t cur_time, interval, tickstart, tickstop;
time(&cur_time);
/* Figure out how long it's been since we started transmitting. */
interval = cur_time - ifi->first_sending;
+ tickstart = ifi->first_sending + 3;
+ tickstop = ifi->startup_time + config->link_timeout;
+
/*
* If we're in the INIT-REBOOT state and we've been trying longer
* than reboot_timeout, go to INIT state and DISCOVER an address.
* link_timeout we just go daemon and finish things up in the
* background.
*/
- if (cur_time - ifi->startup_time < config->link_timeout)
+ if (cur_time < tickstop) {
+ if ((cmd_opts & OPT_VERBOSE) == 0)
+ tick_msg("lease", 0, tickstart, tickstop);
ifi->interval = 1;
- else {
- if (isatty(STDERR_FILENO) != 0)
- fprintf(stderr, "%s: no lease .... sleeping\n",
- log_procname);
- go_daemon();
+ } else {
+ tick_msg("lease", 0, tickstart, tickstop);
}
/*
return lease->epoch + rebind;
}
+
+void
+tick_msg(const char *preamble, int success, time_t start, time_t stop)
+{
+ static int preamble_sent;
+ time_t cur_time;
+
+ time(&cur_time);
+
+ if (isatty(STDERR_FILENO) == 0 || cur_time < start)
+ return;
+
+ if (preamble_sent == 0) {
+ fprintf(stderr, "%s: no %s ...", log_procname, preamble);
+ fflush(stderr);
+ preamble_sent = 1;
+ }
+
+ if (success == 1) {
+ fprintf(stderr, " got %s\n", preamble);
+ fflush(stderr);
+ preamble_sent = 0;
+ } else if (cur_time < stop) {
+ fprintf(stderr, ".");
+ fflush(stderr);
+ } else {
+ fprintf(stderr, " sleeping\n");
+ fflush(stderr);
+ go_daemon();
+ preamble_sent = 0;
+ }
+}