From 75f6df57ccb47787d1e8398665266bf3567547d2 Mon Sep 17 00:00:00 2001 From: krw Date: Tue, 6 Feb 2018 00:25:09 +0000 Subject: [PATCH] Flip -q (be quiet) into -v (be noisy), making terseness the default behaviour. Always go daemon after link_timeout seconds and complete lease negotiations in the background if necessary. No hanging around in the foreground for the full 64 seconds waiting for a server to appear. Log a more relevant message when a default route can't be obtained via RTM_GET. i.e. "no default route" rather than "No such process". -q -> -v ok mpi@ --- sbin/dhclient/clparse.c | 4 +-- sbin/dhclient/dhclient.8 | 18 ++++++------ sbin/dhclient/dhclient.c | 53 +++++++++++++++++++++++++---------- sbin/dhclient/dhclient.conf.5 | 6 ++-- sbin/dhclient/dhcpd.h | 4 +-- sbin/dhclient/kroute.c | 8 ++++-- 6 files changed, 60 insertions(+), 33 deletions(-) diff --git a/sbin/dhclient/clparse.c b/sbin/dhclient/clparse.c index 657a828f125..f20c2c354b3 100644 --- a/sbin/dhclient/clparse.c +++ b/sbin/dhclient/clparse.c @@ -1,4 +1,4 @@ -/* $OpenBSD: clparse.c,v 1.166 2018/01/05 15:03:09 krw Exp $ */ +/* $OpenBSD: clparse.c,v 1.167 2018/02/06 00:25:09 krw Exp $ */ /* Parser for dhclient config and lease files. */ @@ -92,7 +92,7 @@ read_conf(char *name) TAILQ_INIT(&config->reject_list); /* Set some defaults. */ - config->link_timeout = 10; /* secs before going daemon w/o link */ + config->link_timeout = 10; /* secs before going daemon w/o lease */ config->timeout = 30; /* secs to wait for an OFFER */ config->select_interval = 0; /* secs to wait for other OFFERs */ config->reboot_timeout = 1; /* secs before giving up on reboot */ diff --git a/sbin/dhclient/dhclient.8 b/sbin/dhclient/dhclient.8 index 539ca5005b2..3a0ae603b49 100644 --- a/sbin/dhclient/dhclient.8 +++ b/sbin/dhclient/dhclient.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: dhclient.8,v 1.35 2017/10/27 15:10:16 krw Exp $ +.\" $OpenBSD: dhclient.8,v 1.36 2018/02/06 00:25:09 krw Exp $ .\" .\" Copyright (c) 1997 The Internet Software Consortium. .\" All rights reserved. @@ -35,7 +35,7 @@ .\" Enterprises. To learn more about the Internet Software Consortium, .\" see ``http://www.isc.org/isc''. To learn more about Vixie .\" Enterprises, see ``http://www.vix.com''. -.Dd $Mdocdate: October 27 2017 $ +.Dd $Mdocdate: February 6 2018 $ .Dt DHCLIENT 8 .Os .Sh NAME @@ -43,7 +43,7 @@ .Nd Dynamic Host Configuration Protocol (DHCP) client .Sh SYNOPSIS .Nm -.Op Fl dnq +.Op Fl dnv .Op Fl c Ar file .Op Fl i Ar options .Op Fl L Ar file @@ -123,16 +123,16 @@ for the leases file. .It Fl n Configtest mode. Only check the configuration file for validity. -.It Fl q -Forces +.It Fl v +Causes .Nm -to be less verbose on startup. -.Fl q -has no effect if either +to log more information. +.Fl v +is implied if either .Fl d or .Fl n -is also present. +is present. .El .Pp The DHCP protocol allows a host to contact a central server which diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c index bfb2ce126f0..16f3e1cc85b 100644 --- a/sbin/dhclient/dhclient.c +++ b/sbin/dhclient/dhclient.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dhclient.c,v 1.554 2018/02/05 09:33:50 krw Exp $ */ +/* $OpenBSD: dhclient.c,v 1.555 2018/02/06 00:25:09 krw Exp $ */ /* * Copyright 2004 Henning Brauer @@ -433,9 +433,9 @@ main(int argc, char *argv[]) else log_init(0, LOG_DEBUG); /* can't log to stderr */ - log_setverbose(1); /* Show log_debug() messages. */ + log_setverbose(0); /* Don't show log_debug() messages. */ - while ((ch = getopt(argc, argv, "c:di:l:L:nq")) != -1) + while ((ch = getopt(argc, argv, "c:di:l:L:nv")) != -1) switch (ch) { case 'c': path_dhclient_conf = optarg; @@ -465,8 +465,8 @@ main(int argc, char *argv[]) case 'n': cmd_opts |= OPT_NOACTION; break; - case 'q': - cmd_opts |= OPT_QUIET; + case 'v': + cmd_opts |= OPT_VERBOSE; break; default: usage(); @@ -479,10 +479,10 @@ main(int argc, char *argv[]) usage(); if ((cmd_opts & (OPT_FOREGROUND | OPT_NOACTION)) != 0) - cmd_opts &= ~OPT_QUIET; + cmd_opts |= OPT_VERBOSE; - if ((cmd_opts & OPT_QUIET) != 0) - log_setverbose(0); /* Don't show log_debug() */ + if ((cmd_opts & OPT_VERBOSE) != 0) + log_setverbose(1); /* Show log_debug() messages. */ ifi = calloc(1, sizeof(*ifi)); if (ifi == NULL) @@ -681,7 +681,7 @@ usage(void) extern char *__progname; fprintf(stderr, - "usage: %s [-dnq] [-c file] [-i options] [-L file] " + "usage: %s [-dnv] [-c file] [-i options] [-L file] " "[-l file] interface\n", __progname); exit(1); } @@ -1323,11 +1323,23 @@ send_discover(struct interface_info *ifi) * If the backoff would take us to the panic timeout, just use that * as the interval. */ - if (cur_time + ifi->interval > - ifi->first_sending + config->timeout) + if (cur_time + ifi->interval > ifi->first_sending + config->timeout) ifi->interval = (ifi->first_sending + config->timeout) - cur_time + 1; + /* + * If we are still starting up, backoff 1 second. If we are past + * link_timeout we just go daemon and finish things up in the + * background. + */ + if (cur_time - ifi->startup_time < config->link_timeout) + ifi->interval = 1; + else { + if (isatty(STDERR_FILENO) != 0) + fprintf(stderr, "no lease .... sleeping\n"); + go_daemon(); + } + /* Record the number of seconds since we started sending. */ if (interval < UINT16_MAX) packet->secs = htons(interval); @@ -1335,7 +1347,6 @@ send_discover(struct interface_info *ifi) packet->secs = htons(UINT16_MAX); ifi->secs = packet->secs; - rslt = send_packet(ifi, inaddr_any, inaddr_broadcast, "DHCPDISCOVER"); if (rslt != -1) log_debug("%s: DHCPDISCOVER - interval %lld", log_procname, @@ -1437,6 +1448,19 @@ send_request(struct interface_info *ifi) ifi->expiry) ifi->interval = ifi->expiry - cur_time + 1; + /* + * If we are still starting up, backoff 1 second. If we are past + * link_timeout we just go daemon and finish things up in the + * background. + */ + if (cur_time - ifi->startup_time < config->link_timeout) + ifi->interval = 1; + else { + if (isatty(STDERR_FILENO) != 0) + fprintf(stderr, "no lease .... sleeping"); + go_daemon(); + } + /* * If the reboot timeout has expired, or the lease rebind time has * elapsed, or if we're not yet bound, broadcast the DHCPREQUEST rather @@ -1466,7 +1490,6 @@ send_request(struct interface_info *ifi) packet->secs = htons(UINT16_MAX); } - rslt = send_packet(ifi, from, destination.sin_addr, "DHCPREQUEST"); if (rslt != -1) log_debug("%s: DHCPREQUEST to %s", log_procname, @@ -1998,8 +2021,8 @@ go_daemon(void) /* Stop logging to stderr. */ log_init(0, LOG_DAEMON); - if ((cmd_opts & OPT_QUIET) == 0) - log_setverbose(1); /* show log_debug() messages. */ + if ((cmd_opts & OPT_VERBOSE) != 0) + log_setverbose(1); /* Show log_debug() messages. */ log_procinit(log_procname); setproctitle("%s", log_procname); diff --git a/sbin/dhclient/dhclient.conf.5 b/sbin/dhclient/dhclient.conf.5 index 703a873c134..c6666f8f3fa 100644 --- a/sbin/dhclient/dhclient.conf.5 +++ b/sbin/dhclient/dhclient.conf.5 @@ -1,4 +1,4 @@ -.\" $OpenBSD: dhclient.conf.5,v 1.39 2017/12/13 18:45:08 krw Exp $ +.\" $OpenBSD: dhclient.conf.5,v 1.40 2018/02/06 00:25:09 krw Exp $ .\" .\" Copyright (c) 1997 The Internet Software Consortium. .\" All rights reserved. @@ -36,7 +36,7 @@ .\" see ``http://www.isc.org/isc''. To learn more about Vixie .\" Enterprises, see ``http://www.vix.com''. .\" -.Dd $Mdocdate: December 13 2017 $ +.Dd $Mdocdate: February 6 2018 $ .Dt DHCLIENT.CONF 5 .Os .Sh NAME @@ -64,7 +64,7 @@ and the first retransmission of the packet. The default is 1 second. .It Ic link-timeout Ar seconds ; Sets the number of seconds -to wait for interface link before going into the background as a daemon. +to wait for a lease before going into the background as a daemon. The default is 10 seconds. .It Ic reboot Ar seconds ; Sets the number of seconds to wait diff --git a/sbin/dhclient/dhcpd.h b/sbin/dhclient/dhcpd.h index 106aa975de6..b78727e5543 100644 --- a/sbin/dhclient/dhcpd.h +++ b/sbin/dhclient/dhcpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: dhcpd.h,v 1.249 2018/01/30 13:22:42 krw Exp $ */ +/* $OpenBSD: dhcpd.h,v 1.250 2018/02/06 00:25:09 krw Exp $ */ /* * Copyright (c) 2004 Henning Brauer @@ -216,7 +216,7 @@ extern struct imsgbuf *unpriv_ibuf; extern volatile sig_atomic_t quit; extern int cmd_opts; #define OPT_NOACTION 1 -#define OPT_QUIET 2 +#define OPT_VERBOSE 2 #define OPT_FOREGROUND 4 void dhcpoffer(struct interface_info *, struct option_data *, diff --git a/sbin/dhclient/kroute.c b/sbin/dhclient/kroute.c index 1af13cddc50..7e90270ee7a 100644 --- a/sbin/dhclient/kroute.c +++ b/sbin/dhclient/kroute.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kroute.c,v 1.154 2017/10/23 13:31:35 krw Exp $ */ +/* $OpenBSD: kroute.c,v 1.155 2018/02/06 00:25:09 krw Exp $ */ /* * Copyright 2012 Kenneth R Westerback @@ -655,7 +655,11 @@ default_route_index(int rdomain, int routefd) fatal("start time"); if (writev(routefd, iov, 3) == -1) { - log_warn("%s: writev(RTM_GET)", log_procname); + if (errno == ESRCH) + log_debug("%s: writev(RTM_GET) - no default route", + log_procname); + else + log_warn("%s: writev(RTM_GET)", log_procname); return 0; } -- 2.20.1