File nm-fix-dhcp-client-timeout.patch of Package NetworkManager.19171

Index: NetworkManager-1.22.10/src/dhcp/nm-dhcp-client.c
===================================================================
--- NetworkManager-1.22.10.orig/src/dhcp/nm-dhcp-client.c
+++ NetworkManager-1.22.10/src/dhcp/nm-dhcp-client.c
@@ -420,9 +420,6 @@ nm_dhcp_client_set_state (NMDhcpClient *
 	if (NM_IN_SET (new_state, NM_DHCP_STATE_BOUND, NM_DHCP_STATE_EXTENDED)) {
 		g_return_if_fail (NM_IS_IP_CONFIG (ip_config, priv->addr_family));
 		g_return_if_fail (options);
-	} else {
-		g_return_if_fail (!ip_config);
-		g_return_if_fail (!options);
 	}
 
 	if (new_state >= NM_DHCP_STATE_BOUND)
@@ -436,7 +433,7 @@ nm_dhcp_client_set_state (NMDhcpClient *
 	 * events since the lease won't have changed and the state was already handled.
 	 */
 	if (   (priv->state == new_state)
-	    && !NM_IN_SET (new_state, NM_DHCP_STATE_BOUND, NM_DHCP_STATE_EXTENDED))
+	    && !NM_IN_SET (new_state, NM_DHCP_STATE_BOUND, NM_DHCP_STATE_EXTENDED, NM_DHCP_STATE_TIMEOUT))
 		return;
 
 	if (_LOGI_ENABLED ()) {
@@ -524,8 +521,8 @@ nm_dhcp_client_start_timeout (NMDhcpClie
 		return;
 
 	priv->timeout_id = g_timeout_add_seconds (priv->timeout,
-	                                          transaction_timeout,
-	                                          self);
+                                              transaction_timeout,
+                                              self);
 }
 
 void
@@ -536,8 +533,6 @@ nm_dhcp_client_watch_child (NMDhcpClient
 	g_return_if_fail (priv->pid == -1);
 	priv->pid = pid;
 
-	nm_dhcp_client_start_timeout (self);
-
 	g_return_if_fail (priv->watch_id == 0);
 	priv->watch_id = g_child_watch_add (pid, daemon_watch_cb, self);
 }
@@ -880,7 +875,7 @@ nm_dhcp_client_handle_event (gpointer un
 	_LOGD ("DHCP state '%s' -> '%s' (reason: '%s')",
 	       state_to_string (old_state), state_to_string (new_state), reason);
 
-	if (NM_IN_SET (new_state, NM_DHCP_STATE_BOUND, NM_DHCP_STATE_EXTENDED)) {
+	if (NM_IN_SET (new_state, NM_DHCP_STATE_BOUND, NM_DHCP_STATE_EXTENDED, NM_DHCP_STATE_TIMEOUT)) {
 		GVariantIter iter;
 		const char *name;
 		GVariant *value;
Index: NetworkManager-1.22.10/src/devices/nm-device.c
===================================================================
--- NetworkManager-1.22.10.orig/src/devices/nm-device.c
+++ NetworkManager-1.22.10/src/devices/nm-device.c
@@ -8000,7 +8000,39 @@ dhcp4_state_changed (NMDhcpClient *clien
 		}
 		break;
 	case NM_DHCP_STATE_TIMEOUT:
-		dhcp4_fail (self, state);
+		/* If got valid ip config from recorded lease file */
+		if (!ip4_config) {
+			_LOGI (LOGD_DHCP4, "DHCP timed out and no valid lease file is available.");
+			dhcp4_fail (self, TRUE);
+		} else {
+			nm_dhcp4_config_set_options (priv->dhcp4.config, options);
+			_notify (self, PROP_DHCP4_CONFIG);
+
+			if (priv->ip_state_4 == NM_DEVICE_IP_STATE_CONF) {
+				connection = nm_device_get_applied_connection (self);
+				g_assert (connection);
+
+				manual = nm_device_ip4_config_new (self);
+				nm_ip4_config_merge_setting (manual,
+				                             nm_connection_get_setting_ip4_config (connection),
+				                             NM_SETTING_CONNECTION_MDNS_DEFAULT,
+				                             NM_SETTING_CONNECTION_LLMNR_DEFAULT,
+				                             nm_device_get_route_table (self, AF_INET),
+				                             nm_device_get_route_metric (self, AF_INET));
+
+				configs = g_new0 (NMIP4Config *, 3);
+				configs[0] = manual;
+				configs[1] = g_object_ref (ip4_config);
+
+				ipv4_dad_start (self, configs, dhcp4_dad_cb);
+			} else if (priv->ip_state_4 == NM_DEVICE_IP_STATE_DONE) {
+				if (dhcp4_lease_change (self, ip4_config,
+				                        state == NM_DHCP_STATE_BOUND))
+					nm_device_update_metered (self);
+				else
+					dhcp4_fail (self, state);
+			}
+        	}
 		break;
 	case NM_DHCP_STATE_EXPIRE:
 		/* Ignore expiry before we even have a lease (NAK, old lease, etc) */
openSUSE Build Service is sponsored by