-/* $OpenBSD: dhclient.c,v 1.703 2021/02/24 16:53:18 krw Exp $ */
+/* $OpenBSD: dhclient.c,v 1.704 2021/02/27 13:59:00 krw Exp $ */
/*
* Copyright 2004 Henning Brauer <henning@openbsd.org>
#define TICK_WAIT 0
#define TICK_SUCCESS 1
-#define TICK_SLEEP 2
-#define TICK_NEWLINE 3
+#define TICK_DAEMON 2
static FILE *leaseFile;
newlinkup = LINK_STATE_IS_UP(ifi->link_state);
if (newlinkup != oldlinkup) {
tick_msg("link", newlinkup ? TICK_SUCCESS : TICK_WAIT);
- if (log_getverbose()) {
- tick_msg("", TICK_NEWLINE);
- log_debug("%s: link %s -> %s", log_procname,
- (oldlinkup != 0) ? "up" : "down",
- (newlinkup != 0) ? "up" : "down");
- }
+ log_debug("%s: link %s -> %s", log_procname,
+ (oldlinkup != 0) ? "up" : "down",
+ (newlinkup != 0) ? "up" : "down");
}
if (newlinkup != 0) {
memcpy(ifi->hw_address.ether_addr_octet, LLADDR(sdl),
ETHER_ADDR_LEN);
if (memcmp(&hw, &ifi->hw_address, sizeof(hw))) {
- if (log_getverbose()) {
- tick_msg("", TICK_NEWLINE);
- log_debug("%s: LLADDR changed", log_procname);
- }
+ log_debug("%s: LLADDR changed", log_procname);
quit = RESTART;
}
}
ifie = &((struct if_ieee80211_msghdr *)rtm)->ifim_ifie;
if (ifi->ssid_len != ifie->ifie_nwid_len || memcmp(ifi->ssid,
ifie->ifie_nwid, ifie->ifie_nwid_len) != 0) {
- if (log_getverbose()) {
- tick_msg("", TICK_NEWLINE);
- log_debug("%s: SSID changed", log_procname);
- }
+ log_debug("%s: SSID changed", log_procname);
quit = RESTART;
return;
}
int rslt, seen;
time(&cur_time);
- if (log_getverbose())
- tick_msg("lease", TICK_SUCCESS);
+ tick_msg("lease", TICK_SUCCESS);
lease = apply_defaults(ifi->offer);
ifi->offer_src = NULL;
if (msg != NULL) {
- tick_msg("", TICK_NEWLINE);
if ((cmd_opts & OPT_FOREGROUND) != 0) {
/* log msg on console only. */
;
time(&cur_time);
- if (log_getverbose())
- tick_msg("lease", TICK_WAIT);
-
if (cur_time > ifi->first_sending + config->offer_interval) {
state_panic(ifi);
return;
}
+ tick_msg("lease", TICK_WAIT);
+
set_interval(ifi, cur_time);
set_secs(ifi, cur_time);
log_procname);
ifi->state = S_INIT;
set_timeout(ifi, config->retry_interval, state_init);
- go_daemon();
+ tick_msg("lease", TICK_DAEMON);
}
void
cancel_timeout(ifi);
clock_gettime(CLOCK_REALTIME, &now);
cur_time = now.tv_sec;
- if (log_getverbose())
- tick_msg("lease", TICK_WAIT);
+ tick_msg("lease", TICK_WAIT);
/* Figure out how long it's been since we started transmitting. */
interval = cur_time - ifi->first_sending;
const struct timespec link_intvl = {config->link_interval, 0};
static struct timespec grace, stop;
struct timespec now;
- static int preamble_sent, sleeping;
+ static int linkup, preamble_sent, sleeping;
+ int printmsg;
if (isatty(STDERR_FILENO) == 0 || sleeping == 1)
return;
return;
}
if (timespeccmp(&now, &grace, <))
- return;
- if (timespeccmp(&now, &stop, >=))
- action = TICK_SLEEP;
+ printmsg = 0; /* Wait a bit before speaking. */
+ else if (linkup && strcmp("link", preamble) == 0)
+ printmsg = 0; /* One 'got link' is enough for anyone. */
+ else if (log_getverbose())
+ printmsg = 0; /* Verbose has sufficent verbiage. */
+ else
+ printmsg = 1;
+
+ if (timespeccmp(&now, &stop, >=)) {
+ if (action == TICK_WAIT)
+ action = TICK_DAEMON;
+ log_debug("%s: link timeout (%lld seconds) expired",
+ log_procname, (long long)link_intvl.tv_sec);
+ linkup = 1;
+ }
- if (preamble_sent == 0) {
+ if (printmsg && preamble_sent == 0) {
fprintf(stderr, "%s: no %s...", log_procname, preamble);
preamble_sent = 1;
}
switch (action) {
case TICK_SUCCESS:
- fprintf(stderr, "got %s\n", preamble);
- timespecclear(&stop);
+ if (printmsg)
+ fprintf(stderr, "got %s\n", preamble);
+ preamble_sent = 0;
+ if (strcmp("link", preamble) == 0)
+ linkup = 1;
break;
case TICK_WAIT:
- fprintf(stderr, ".");
+ if (printmsg)
+ fprintf(stderr, ".");
break;
- case TICK_SLEEP:
- fprintf(stderr, "sleeping\n");
+ case TICK_DAEMON:
+ if (printmsg)
+ fprintf(stderr, "sleeping\n");
go_daemon();
sleeping = 1; /* OPT_FOREGROUND means isatty() == 1! */
- timespecclear(&stop);
- break;
- case TICK_NEWLINE:
- if (preamble_sent == 1) {
- fprintf(stderr, "\n");
- preamble_sent = 0;
- }
break;
default:
break;
}
- fflush(stderr);
+ if (printmsg)
+ fflush(stderr);
}
/*