From: Roy Marples Date: Fri, 24 May 2024 10:30:29 +0000 (+0000) Subject: DHCP: use request_time, fallback_time and ipv4ll_time X-Git-Tag: v10.0.7~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6149af646b610d0b36826fdfbec7157ce03ca166;p=thirdparty%2Fdhcpcd.git DHCP: use request_time, fallback_time and ipv4ll_time Rather than reboot time. This allows reboot time of zero to skip the using old leases while still allowing REQUESTs to gracefully fallback to DISCOVER. request_time has a default of 180 seconds to mirror the DHCPv6 equivalent. fallback_time and ipv4_ll time have a default of 5 seconds to mirror the default reboot time. Fixes #325 and affects #255. --- diff --git a/src/dhcp.c b/src/dhcp.c index 275c0c4b..6e6b49a2 100644 --- a/src/dhcp.c +++ b/src/dhcp.c @@ -1877,13 +1877,13 @@ dhcp_discover(void *arg) dhcp_new_xid(ifp); eloop_timeout_delete(ifp->ctx->eloop, NULL, ifp); if (!(state->added & STATE_EXPIRED)) { - if (ifo->fallback) + if (ifo->fallback && ifo->fallback_time) eloop_timeout_add_sec(ifp->ctx->eloop, - ifo->reboot, dhcp_fallback, ifp); + ifo->fallback_time, dhcp_fallback, ifp); #ifdef IPV4LL else if (ifo->options & DHCPCD_IPV4LL) eloop_timeout_add_sec(ifp->ctx->eloop, - ifo->reboot, ipv4ll_start, ifp); + ifo->ipv4ll_time, ipv4ll_start, ifp); #endif } if (ifo->options & DHCPCD_REQUEST) @@ -1914,11 +1914,13 @@ dhcp_request(void *arg) { struct interface *ifp = arg; struct dhcp_state *state = D_STATE(ifp); + struct if_options *ifo = ifp->options; state->state = DHS_REQUEST; // Handle the server being silent to our request. - eloop_timeout_add_sec(ifp->ctx->eloop, ifp->options->reboot, - dhcp_requestfailed, ifp); + if (ifo->request_time != 0) + eloop_timeout_add_sec(ifp->ctx->eloop, ifo->request_time, + dhcp_requestfailed, ifp); send_request(ifp); } @@ -2748,7 +2750,7 @@ dhcp_reboot(struct interface *ifp) /* Need to add this before dhcp_expire and friends. */ if (!ifo->fallback && ifo->options & DHCPCD_IPV4LL) eloop_timeout_add_sec(ifp->ctx->eloop, - ifo->reboot, ipv4ll_start, ifp); + ifo->ipv4ll_time, ipv4ll_start, ifp); #endif if (ifo->options & DHCPCD_LASTLEASE && state->lease.frominfo) diff --git a/src/dhcpcd.conf.5.in b/src/dhcpcd.conf.5.in index d6f73eac..3af2cc3e 100644 --- a/src/dhcpcd.conf.5.in +++ b/src/dhcpcd.conf.5.in @@ -24,7 +24,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd December 21, 2023 +.Dd May 24, 2024 .Dt DHCPCD.CONF 5 .Os .Sh NAME @@ -305,6 +305,10 @@ You can use this option to stop this from happening. .It Ic fallback Ar profile Fall back to using this profile if DHCP fails. This allows you to configure a static profile instead of using ZeroConf. +.It Ic fallback_time Ar seconds +Start fallback after +.Ar seconds . +The default is 5 seconds. .It Ic hostname Ar name Sends the hostname .Ar name @@ -442,6 +446,11 @@ encodes the FQDN hostname as specified in .It Ic interface Ar interface Subsequent options are only parsed for this .Ar interface . +.It Ic ipv4ll_time Ar seconds +Wait for +.Ar seconds +before starting IPv4LL. +The default is 5 seconds. .It Ic ipv6ra_autoconf Generate SLAAC addresses for each Prefix advertised by an IPv6 Router Advertisement message with the Auto flag set. @@ -649,6 +658,11 @@ Use .Ar script instead of the default .Pa @SCRIPT@ . +.It Ic request_time Ar seconds +Request the lease for +.Ar seconds +before going back to DISCOVER. +The default is 180 seconds. .It Ic ssid Ar ssid Subsequent options are only parsed for this wireless .Ar ssid . diff --git a/src/if-options.c b/src/if-options.c index f4f55204..ee8644d2 100644 --- a/src/if-options.c +++ b/src/if-options.c @@ -169,6 +169,9 @@ const struct option cf_options[] = { {"configure", no_argument, NULL, O_CONFIGURE}, {"noconfigure", no_argument, NULL, O_NOCONFIGURE}, {"arp_persistdefence", no_argument, NULL, O_ARP_PERSISTDEFENCE}, + {"request_time", required_argument, NULL, O_REQUEST_TIME}, + {"fallback_time", required_argument, NULL, O_FALLBACK_TIME}, + {"ipv4ll_time", required_argument, NULL, O_IPV4LL_TIME}, {NULL, 0, NULL, '\0'} }; @@ -2341,6 +2344,35 @@ invalid_token: case O_ARP_PERSISTDEFENCE: ifo->options |= DHCPCD_ARP_PERSISTDEFENCE; break; + case O_REQUEST_TIME: + ARG_REQUIRED; + ifo->request_time = + (uint32_t)strtou(arg, NULL, 0, 0, UINT32_MAX, &e); + if (e) { + logerrx("invalid request time: %s", arg); + return -1; + } + break; +#ifdef INET + case O_FALLBACK_TIME: + ARG_REQUIRED; + ifo->request_time = + (uint32_t)strtou(arg, NULL, 0, 0, UINT32_MAX, &e); + if (e) { + logerrx("invalid fallback time: %s", arg); + return -1; + } + break; + case O_IPV4LL_TIME: + ARG_REQUIRED; + ifo->ipv4ll_time = + (uint32_t)strtou(arg, NULL, 0, 0, UINT32_MAX, &e); + if (e) { + logerrx("invalid ipv4ll time: %s", arg); + return -1; + } + break; +#endif default: return 0; } @@ -2424,6 +2456,11 @@ default_config(struct dhcpcd_ctx *ctx) ifo->options |= DHCPCD_IF_UP | DHCPCD_LINK | DHCPCD_INITIAL_DELAY; ifo->timeout = DEFAULT_TIMEOUT; ifo->reboot = DEFAULT_REBOOT; + ifo->request_time = DEFAULT_REQUEST; +#ifdef INET + ifo->fallback_time = DEFAULT_FALLBACK; + ifo->ipv4ll_time = DEFAULT_IPV4LL; +#endif ifo->metric = -1; ifo->auth.options |= DHCPCD_AUTH_REQUIRE; rb_tree_init(&ifo->routes, &rt_compare_list_ops); diff --git a/src/if-options.h b/src/if-options.h index d317d370..14c698fe 100644 --- a/src/if-options.h +++ b/src/if-options.h @@ -49,6 +49,9 @@ #define DEFAULT_TIMEOUT 30 #define DEFAULT_REBOOT 5 +#define DEFAULT_REQUEST 180 /* secs to request, mirror DHCP6 */ +#define DEFAULT_FALLBACK 5 /* secs until fallback */ +#define DEFAULT_IPV4LL 5 /* secs until ipv4ll */ #ifndef HOSTNAME_MAX_LEN #define HOSTNAME_MAX_LEN 250 /* 255 - 3 (FQDN) - 2 (DNS enc) */ @@ -185,6 +188,9 @@ #define O_NOCONFIGURE O_BASE + 51 #define O_RANDOMISE_HWADDR O_BASE + 52 #define O_ARP_PERSISTDEFENCE O_BASE + 53 +#define O_REQUEST_TIME O_BASE + 54 +#define O_FALLBACK_TIME O_BASE + 55 +#define O_IPV4LL_TIME O_BASE + 56 extern const struct option cf_options[]; @@ -236,6 +242,9 @@ struct if_options { uint32_t leasetime; uint32_t timeout; uint32_t reboot; + uint32_t request_time; + uint32_t fallback_time; + uint32_t ipv4ll_time; unsigned long long options; bool randomise_hwaddr;