dhcp: derive the grace period duration from the timeout property

Currently the duration of the DHCP grace period (in which we try to
acquire a new lease after expiration) is hardcoded to 480
seconds. That value seems arbitrary and too long for the default
configuration. Since we already have a property that allows the user
to configure how long NM should try to get the lease initially, it
makes sense to use it also for retries after lease expirations.

In particular, setting the ipvx.dhcp-timeout to a high value extends
also the grace period to a very long time, potentially forever.

(cherry picked from commit aee78ca788)
This commit is contained in:
Beniamino Galvani 2020-01-27 17:38:33 +01:00
parent 4b32506f5e
commit 4505c25270

View file

@ -76,7 +76,7 @@ _LOG_DECLARE_SELF (NMDevice);
/*****************************************************************************/
#define DEFAULT_AUTOCONNECT TRUE
#define DHCP_GRACE_PERIOD_SEC 480
#define DHCP_GRACE_PERIOD_MULTIPLIER 2U
#define CARRIER_WAIT_TIME_MS 6000
#define CARRIER_WAIT_TIME_AFTER_MTU_MS 10000
@ -7834,12 +7834,24 @@ dhcp4_fail (NMDevice *self, NMDhcpState dhcp_state)
* wait for some time before failing the IP method.
*/
if (!priv->dhcp4.grace_id) {
priv->dhcp4.grace_id = g_timeout_add_seconds (DHCP_GRACE_PERIOD_SEC,
guint32 timeout;
/* Start a grace period equal to the DHCP timeout multiplied
* by a constant factor. */
timeout = get_dhcp_timeout (self, AF_INET);
if (timeout < G_MAXUINT32 / DHCP_GRACE_PERIOD_MULTIPLIER) {
timeout *= DHCP_GRACE_PERIOD_MULTIPLIER;
_LOGI (LOGD_DHCP4,
"DHCPv4: trying to acquire a new lease within %u seconds",
timeout);
} else {
timeout = G_MAXUINT32;
_LOGI (LOGD_DHCP4, "DHCPv4: trying to acquire a new lease");
}
priv->dhcp4.grace_id = g_timeout_add_seconds (timeout,
dhcp4_grace_period_expired,
self);
_LOGI (LOGD_DHCP4,
"DHCPv4: %u seconds grace period started",
DHCP_GRACE_PERIOD_SEC);
goto clear_config;
}
return;
@ -8627,12 +8639,24 @@ dhcp6_fail (NMDevice *self, NMDhcpState dhcp_state)
* wait for some time before failing the IP method.
*/
if (!priv->dhcp6.grace_id) {
priv->dhcp6.grace_id = g_timeout_add_seconds (DHCP_GRACE_PERIOD_SEC,
guint32 timeout;
/* Start a grace period equal to the DHCP timeout multiplied
* by a constant factor. */
timeout = get_dhcp_timeout (self, AF_INET6);
if (timeout < G_MAXUINT32 / DHCP_GRACE_PERIOD_MULTIPLIER) {
timeout *= DHCP_GRACE_PERIOD_MULTIPLIER;
_LOGI (LOGD_DHCP6,
"DHCPv6: trying to acquire a new lease within %u seconds",
timeout);
} else {
timeout = G_MAXUINT32;
_LOGI (LOGD_DHCP6, "DHCPv6: trying to acquire a new lease");
}
priv->dhcp6.grace_id = g_timeout_add_seconds (timeout,
dhcp6_grace_period_expired,
self);
_LOGI (LOGD_DHCP6,
"DHCPv6: %u seconds grace period started",
DHCP_GRACE_PERIOD_SEC);
goto clear_config;
}
} else {