From b85a9cd9df540e9ee7adc40fcdef56a8bf314d1f Mon Sep 17 00:00:00 2001 From: Fernando Fernandez Mancera Date: Tue, 9 Nov 2021 12:07:45 +0100 Subject: [PATCH] device: set ip_state to PENDING when cleaning up from reapply When doing a reapply the ip_state must be set as PENDING, if not the ipdhcp_state won't be extended to ip_state. In addition, if one of the IP configuration is ready and the other may fail, then we should consider it ready. The other ip state does not matter at all, it can be none too. Fixes-test: @nmcli_device_reapply_routes --- src/core/devices/nm-device.c | 37 +++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/src/core/devices/nm-device.c b/src/core/devices/nm-device.c index 371145982..078dc16a5 100644 --- a/src/core/devices/nm-device.c +++ b/src/core/devices/nm-device.c @@ -833,7 +833,8 @@ static void _dev_ipshared4_spawn_dnsmasq(NMDevice *self); static void _dev_ipshared6_start(NMDevice *self); -static void _cleanup_ip_pre(NMDevice *self, int addr_family, CleanupType cleanup_type); +static void +_cleanup_ip_pre(NMDevice *self, int addr_family, CleanupType cleanup_type, gboolean from_reapply); static void concheck_update_state(NMDevice * self, int addr_family, @@ -3246,10 +3247,6 @@ got_ip_state: &may_fail_other))) combinedip_state = NM_DEVICE_IP_STATE_PENDING; else if (ip_state == NM_DEVICE_IP_STATE_READY - && NM_IN_SET(ip_state_other, - NM_DEVICE_IP_STATE_PENDING, - NM_DEVICE_IP_STATE_READY, - NM_DEVICE_IP_STATE_FAILED) && _prop_get_ipvx_may_fail_cached(self, nm_utils_addr_family_other(addr_family), &may_fail_other)) @@ -3350,13 +3347,16 @@ _dev_ip_state_check_async(NMDevice *self, int addr_family) } static void -_dev_ip_state_cleanup(NMDevice *self, int addr_family) +_dev_ip_state_cleanup(NMDevice *self, int addr_family, gboolean from_reapply) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); int IS_IPv4; if (addr_family == AF_UNSPEC) { - _dev_ip_state_set_state(self, addr_family, NM_DEVICE_IP_STATE_NONE, "ip-state-clear"); + _dev_ip_state_set_state(self, + addr_family, + from_reapply ? NM_DEVICE_IP_STATE_PENDING : NM_DEVICE_IP_STATE_NONE, + "ip-state-clear"); return; } @@ -3364,7 +3364,10 @@ _dev_ip_state_cleanup(NMDevice *self, int addr_family) nm_clear_g_source_inst(&priv->ip_data_x[IS_IPv4].check_async_source); nm_clear_g_source_inst(&priv->ip_data_x[IS_IPv4].req_timeout_source); - _dev_ip_state_set_state(self, addr_family, NM_DEVICE_IP_STATE_NONE, "ip-state-clear"); + _dev_ip_state_set_state(self, + addr_family, + from_reapply ? NM_DEVICE_IP_STATE_PENDING : NM_DEVICE_IP_STATE_NONE, + "ip-state-clear"); priv->ip_data_x[IS_IPv4].wait_for_carrier = FALSE; priv->ip_data_x[IS_IPv4].wait_for_ports = FALSE; priv->ip_data_x[IS_IPv4].is_disabled = FALSE; @@ -11744,11 +11747,11 @@ activate_stage3_ip_config(NMDevice *self) if (priv->ip_data_4.do_reapply) { _LOGD_ip(AF_INET, "reapply..."); - _cleanup_ip_pre(self, AF_INET, CLEANUP_TYPE_DECONFIGURE); + _cleanup_ip_pre(self, AF_INET, CLEANUP_TYPE_DECONFIGURE, TRUE); } if (priv->ip_data_6.do_reapply) { _LOGD_ip(AF_INET6, "reapply..."); - _cleanup_ip_pre(self, AF_INET6, CLEANUP_TYPE_DECONFIGURE); + _cleanup_ip_pre(self, AF_INET6, CLEANUP_TYPE_DECONFIGURE, TRUE); } /* Add the interface to the specified firewall zone */ @@ -12247,7 +12250,7 @@ delete_on_deactivate_check_and_schedule(NMDevice *self) } static void -_cleanup_ip_pre(NMDevice *self, int addr_family, CleanupType cleanup_type) +_cleanup_ip_pre(NMDevice *self, int addr_family, CleanupType cleanup_type, gboolean from_reapply) { const int IS_IPv4 = NM_IS_IPv4(addr_family); @@ -12265,8 +12268,8 @@ _cleanup_ip_pre(NMDevice *self, int addr_family, CleanupType cleanup_type) _dev_ipmanual_cleanup(self); - _dev_ip_state_cleanup(self, AF_UNSPEC); - _dev_ip_state_cleanup(self, addr_family); + _dev_ip_state_cleanup(self, AF_UNSPEC, from_reapply); + _dev_ip_state_cleanup(self, addr_family, from_reapply); } gboolean @@ -14923,8 +14926,8 @@ _cleanup_generic_pre(NMDevice *self, CleanupType cleanup_type) for (i = 0; i < 2; i++) nm_clear_pointer(&priv->hostname_resolver_x[i], _hostname_resolver_free); - _cleanup_ip_pre(self, AF_INET, cleanup_type); - _cleanup_ip_pre(self, AF_INET6, cleanup_type); + _cleanup_ip_pre(self, AF_INET, cleanup_type, FALSE); + _cleanup_ip_pre(self, AF_INET6, cleanup_type, FALSE); _dev_ip_state_req_timeout_cancel(self, AF_UNSPEC); } @@ -15424,8 +15427,8 @@ _set_state_full(NMDevice *self, NMDeviceState state, NMDeviceStateReason reason, /* Clean up any half-done IP operations if the device's layer2 * finds out it needs authentication during IP config. */ - _cleanup_ip_pre(self, AF_INET, CLEANUP_TYPE_DECONFIGURE); - _cleanup_ip_pre(self, AF_INET6, CLEANUP_TYPE_DECONFIGURE); + _cleanup_ip_pre(self, AF_INET, CLEANUP_TYPE_DECONFIGURE, FALSE); + _cleanup_ip_pre(self, AF_INET6, CLEANUP_TYPE_DECONFIGURE, FALSE); } break; default: