summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBeniamino Galvani <bgalvani@redhat.com>2018-09-28 15:58:02 +0200
committerBeniamino Galvani <bgalvani@redhat.com>2018-10-08 10:18:43 +0200
commit33c5274267aab5d13936774a28dc7076b38d0fda (patch)
treeadf0aafd37af1af36603fcc46e10c42c61669151
parente9334810eaf113f8afc2bfc54d50784d31bc1846 (diff)
downloadNetworkManager-bg/dhcp-failed-rh1625901.tar.gz
dhcp: don't start grace period if the client is not runningbg/dhcp-failed-rh1625901
We shouldn't start a grace period when the client is not running.
-rw-r--r--src/devices/nm-device.c64
1 files changed, 31 insertions, 33 deletions
diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c
index bacbe6c4f2..cbc0b75052 100644
--- a/src/devices/nm-device.c
+++ b/src/devices/nm-device.c
@@ -7306,7 +7306,7 @@ dhcp4_grace_period_expired (gpointer user_data)
}
static void
-dhcp4_fail (NMDevice *self)
+dhcp4_fail (NMDevice *self, NMDhcpState dhcp_state)
{
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
@@ -7322,11 +7322,14 @@ dhcp4_fail (NMDevice *self)
&& nm_ip4_config_get_num_addresses (priv->con_ip_config_4) > 0)
goto clear_config;
- /* Fail the method in case of timeout or failure during initial
- * configuration.
+ /* Fail the method when one of the following is true:
+ * 1) the DHCP client terminated: it does not make sense to start a grace
+ * period without a client running;
+ * 2) we failed to get an initial lease AND the client was
+ * not active before.
*/
- if ( !priv->dhcp4.was_active
- && priv->ip4_state == IP_CONF) {
+ if ( dhcp_state == NM_DHCP_STATE_TERMINATED
+ || (!priv->dhcp4.was_active && priv->ip4_state == IP_CONF)) {
dhcp4_cleanup (self, CLEANUP_TYPE_DECONFIGURE, FALSE);
nm_device_activate_schedule_ip4_config_timeout (self);
return;
@@ -7389,7 +7392,7 @@ dhcp4_state_changed (NMDhcpClient *client,
case NM_DHCP_STATE_BOUND:
if (!ip4_config) {
_LOGW (LOGD_DHCP4, "failed to get IPv4 config in response to DHCP event.");
- dhcp4_fail (self);
+ dhcp4_fail (self, state);
break;
}
@@ -7432,11 +7435,11 @@ dhcp4_state_changed (NMDhcpClient *client,
if (dhcp4_lease_change (self, ip4_config))
nm_device_update_metered (self);
else
- dhcp4_fail (self);
+ dhcp4_fail (self, state);
}
break;
case NM_DHCP_STATE_TIMEOUT:
- dhcp4_fail (self);
+ dhcp4_fail (self, state);
break;
case NM_DHCP_STATE_EXPIRE:
/* Ignore expiry before we even have a lease (NAK, old lease, etc) */
@@ -7446,7 +7449,7 @@ dhcp4_state_changed (NMDhcpClient *client,
case NM_DHCP_STATE_DONE:
case NM_DHCP_STATE_FAIL:
case NM_DHCP_STATE_TERMINATED:
- dhcp4_fail (self);
+ dhcp4_fail (self, state);
break;
default:
break;
@@ -8061,7 +8064,7 @@ dhcp6_grace_period_expired (gpointer user_data)
}
static void
-dhcp6_fail (NMDevice *self)
+dhcp6_fail (NMDevice *self, NMDhcpState dhcp_state)
{
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
gboolean is_dhcp_managed;
@@ -8081,11 +8084,14 @@ dhcp6_fail (NMDevice *self)
&& nm_ip6_config_get_num_addresses (priv->con_ip_config_6))
goto clear_config;
- /* Fail the method in case of timeout or failure during initial
- * configuration.
+ /* Fail the method when one of the following is true:
+ * 1) the DHCP client terminated: it does not make sense to start a grace
+ * period without a client running;
+ * 2) we failed to get an initial lease AND the client was
+ * not active before.
*/
- if ( !priv->dhcp6.was_active
- && priv->ip6_state == IP_CONF) {
+ if ( dhcp_state == NM_DHCP_STATE_TERMINATED
+ || (!priv->dhcp6.was_active && priv->ip6_state == IP_CONF)) {
dhcp6_cleanup (self, CLEANUP_TYPE_DECONFIGURE, FALSE);
nm_device_activate_schedule_ip6_config_timeout (self);
return;
@@ -8122,21 +8128,6 @@ clear_config:
}
static void
-dhcp6_timeout (NMDevice *self, NMDhcpClient *client)
-{
- NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
-
- if (priv->dhcp6.mode == NM_NDISC_DHCP_LEVEL_MANAGED)
- dhcp6_fail (self);
- else {
- /* not a hard failure; just live with the RA info */
- dhcp6_cleanup (self, CLEANUP_TYPE_DECONFIGURE, FALSE);
- if (priv->ip6_state == IP_CONF)
- nm_device_activate_schedule_ip6_config_result (self);
- }
-}
-
-static void
dhcp6_state_changed (NMDhcpClient *client,
NMDhcpState state,
NMIP6Config *ip6_config,
@@ -8193,15 +8184,22 @@ dhcp6_state_changed (NMDhcpClient *client,
nm_device_activate_schedule_ip6_config_result (self);
} else if (priv->ip6_state == IP_DONE)
if (!dhcp6_lease_change (self))
- dhcp6_fail (self);
+ dhcp6_fail (self, state);
break;
case NM_DHCP_STATE_TIMEOUT:
- dhcp6_timeout (self, client);
+ if (priv->dhcp6.mode == NM_NDISC_DHCP_LEVEL_MANAGED)
+ dhcp6_fail (self, state);
+ else {
+ /* not a hard failure; just live with the RA info */
+ dhcp6_cleanup (self, CLEANUP_TYPE_DECONFIGURE, FALSE);
+ if (priv->ip6_state == IP_CONF)
+ nm_device_activate_schedule_ip6_config_result (self);
+ }
break;
case NM_DHCP_STATE_EXPIRE:
/* Ignore expiry before we even have a lease (NAK, old lease, etc) */
if (priv->ip6_state != IP_CONF)
- dhcp6_fail (self);
+ dhcp6_fail (self, state);
break;
case NM_DHCP_STATE_TERMINATED:
/* In IPv6 info-only mode, the client doesn't handle leases so it
@@ -8213,7 +8211,7 @@ dhcp6_state_changed (NMDhcpClient *client,
/* fall through */
case NM_DHCP_STATE_DONE:
case NM_DHCP_STATE_FAIL:
- dhcp6_fail (self);
+ dhcp6_fail (self, state);
break;
default:
break;