]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
DHCP: use request_time, fallback_time and ipv4ll_time
authorRoy Marples <roy@marples.name>
Fri, 24 May 2024 10:30:29 +0000 (10:30 +0000)
committerRoy Marples <roy@marples.name>
Fri, 24 May 2024 10:30:29 +0000 (10:30 +0000)
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.

src/dhcp.c
src/dhcpcd.conf.5.in
src/if-options.c
src/if-options.h

index 275c0c4b8c0a24f34a9e5825f786f480e1f05e72..6e6b49a2ff012c7204ba294dabecfe579ee9ef22 100644 (file)
@@ -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)
index d6f73eacc8f92790170d9d9253cbdeb5bae88653..3af2cc3e7f4a11792c8a2727a27a61105659e26c 100644 (file)
@@ -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 .
index f4f55204b13afcdefdc42533d1e234fb469dec7e..ee8644d20c132c3414a7b089d6166e7234328b1a 100644 (file)
@@ -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);
index d317d370fb70b497f0388492798b19e2a21439b3..14c698fe1754f3b0b17371bc66ed0450ff359e03 100644 (file)
@@ -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) */
 #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;