From eb0803de60d0bf4aa4faa53e20a2820c4c1c5568 Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Wed, 24 Aug 2022 16:50:14 +0200 Subject: [PATCH 1/2] core: log when dynamic IP configuration is restarted and why (cherry picked from commit 6cd69fde339cc69717671226e06156339de71314) (cherry picked from commit 2f8e4e2b0615a82225a1d63b5bd767a85ceee754) (cherry picked from commit 8011d0b32bedf8096a67d68d7f94eaac927fcd44) (cherry picked from commit 3d02df8061faae2e91eab88f773e2f2164c07ae6) (cherry picked from commit 2c358b89a299d3b5e7113fe4cf03b3d53e8722d0) --- src/core/devices/nm-device-ethernet.c | 2 +- src/core/devices/nm-device.c | 12 +++++++----- src/core/devices/nm-device.h | 2 +- src/core/devices/wifi/nm-device-wifi.c | 2 +- src/core/nm-manager.c | 2 +- 5 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/core/devices/nm-device-ethernet.c b/src/core/devices/nm-device-ethernet.c index 95336c7a52..cd559d286f 100644 --- a/src/core/devices/nm-device-ethernet.c +++ b/src/core/devices/nm-device-ethernet.c @@ -447,7 +447,7 @@ supplicant_auth_state_changed(NMSupplicantInterface *iface, if (state == NM_SUPPLICANT_AUTH_STATE_SUCCESS) { nm_clear_g_signal_handler(priv->supplicant.iface, &priv->supplicant.iface_state_id); - nm_device_update_dynamic_ip_setup(NM_DEVICE(self)); + nm_device_update_dynamic_ip_setup(NM_DEVICE(self), "supplicant auth state changed"); } } diff --git a/src/core/devices/nm-device.c b/src/core/devices/nm-device.c index ae4bcdbafc..66a2f44753 100644 --- a/src/core/devices/nm-device.c +++ b/src/core/devices/nm-device.c @@ -4934,7 +4934,7 @@ set_unmanaged_external_down(NMDevice *self, gboolean only_if_unmanaged) } void -nm_device_update_dynamic_ip_setup(NMDevice *self) +nm_device_update_dynamic_ip_setup(NMDevice *self, const char *reason) { NMDevicePrivate *priv; @@ -4945,6 +4945,8 @@ nm_device_update_dynamic_ip_setup(NMDevice *self) if (priv->state < NM_DEVICE_STATE_IP_CONFIG || priv->state > NM_DEVICE_STATE_ACTIVATED) return; + _LOGD(LOGD_DEVICE, "restarting dynamic IP configuration (%s)", reason); + g_hash_table_remove_all(priv->ip6_saved_properties); if (priv->dhcp_data_4.client) { @@ -4998,7 +5000,7 @@ carrier_changed(NMDevice *self, gboolean carrier) /* Force master to retry getting ip addresses when carrier * is restored. */ if (priv->state == NM_DEVICE_STATE_ACTIVATED) - nm_device_update_dynamic_ip_setup(self); + nm_device_update_dynamic_ip_setup(self, "interface got carrier"); /* If needed, also resume IP configuration that is * waiting for carrier. */ if (nm_device_activate_ip4_state_in_wait(self)) @@ -5033,7 +5035,7 @@ carrier_changed(NMDevice *self, gboolean carrier) * tagged for carrier ignore) ensure that when the carrier appears we * renew DHCP leases and such. */ - nm_device_update_dynamic_ip_setup(self); + nm_device_update_dynamic_ip_setup(self, "interface got carrier"); } } else { if (priv->state == NM_DEVICE_STATE_UNAVAILABLE) { @@ -5448,7 +5450,7 @@ device_link_changed(NMDevice *self) /* Update DHCP, etc, if needed */ if (ip_ifname_changed) - nm_device_update_dynamic_ip_setup(self); + nm_device_update_dynamic_ip_setup(self, "IP interface changed"); was_up = priv->up; priv->up = NM_FLAGS_HAS(pllink->n_ifi_flags, IFF_UP); @@ -5556,7 +5558,7 @@ device_ip_link_changed(NMDevice *self) priv->ip_iface_ = g_strdup(ip_iface); _notify(self, PROP_IP_IFACE); - nm_device_update_dynamic_ip_setup(self); + nm_device_update_dynamic_ip_setup(self, "interface renamed"); } return G_SOURCE_REMOVE; diff --git a/src/core/devices/nm-device.h b/src/core/devices/nm-device.h index f59b6fa845..9db9e257da 100644 --- a/src/core/devices/nm-device.h +++ b/src/core/devices/nm-device.h @@ -768,7 +768,7 @@ void nm_device_reactivate_ip_config(NMDevice * device, gboolean nm_device_update_hw_address(NMDevice *self); void nm_device_update_initial_hw_address(NMDevice *self); void nm_device_update_permanent_hw_address(NMDevice *self, gboolean force_freeze); -void nm_device_update_dynamic_ip_setup(NMDevice *self); +void nm_device_update_dynamic_ip_setup(NMDevice *self, const char *reason); guint nm_device_get_supplicant_timeout(NMDevice *self); gboolean nm_device_auth_retries_try_next(NMDevice *self); diff --git a/src/core/devices/wifi/nm-device-wifi.c b/src/core/devices/wifi/nm-device-wifi.c index fca2fde515..c27eddb77e 100644 --- a/src/core/devices/wifi/nm-device-wifi.c +++ b/src/core/devices/wifi/nm-device-wifi.c @@ -2610,7 +2610,7 @@ supplicant_iface_notify_current_bss(NMSupplicantInterface *iface, * Also, some APs (e.g. Cisco) can be configured to drop * all traffic until DHCP completes. To support such * cases, renew the lease when roaming to a new AP. */ - nm_device_update_dynamic_ip_setup(NM_DEVICE(self)); + nm_device_update_dynamic_ip_setup(NM_DEVICE(self), "roamed to a different AP"); } set_current_ap(self, new_ap, TRUE); diff --git a/src/core/nm-manager.c b/src/core/nm-manager.c index e20d5515e2..8805048c41 100644 --- a/src/core/nm-manager.c +++ b/src/core/nm-manager.c @@ -6329,7 +6329,7 @@ do_sleep_wake(NMManager *self, gboolean sleeping_changed) && !nm_device_get_unmanaged_flags(device, NM_UNMANAGED_SLEEPING)) { /* DHCP leases of software devices could have gone stale * so we need to renew them. */ - nm_device_update_dynamic_ip_setup(device); + nm_device_update_dynamic_ip_setup(device, "wake up"); continue; } From 25abc22ac9929b84613454086be74320c1ba778d Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Wed, 24 Aug 2022 16:52:52 +0200 Subject: [PATCH 2/2] device: restart DHCP when the MAC changes If the MAC changes there is the possibility that the DHCP client will not be able to renew the address because it uses the old MAC as CHADDR. Depending on the implementation, the DHCP server might use CHADDR (so, the old address) as the destination MAC for DHCP replies, and those packets will be lost. To avoid this problem, restart the DHCP client when the MAC changes. https://bugzilla.redhat.com/show_bug.cgi?id=2110000 (cherry picked from commit 905adabdba033bbfc33013d0ad203bd444131dc5) (cherry picked from commit 5a49a2f6b20e6d124ac705e79ab7d5df3837b8c1) (cherry picked from commit d0fb3fbf8e68c8452840adeb2ee818596b4b54af) (cherry picked from commit 59a52510f3002be099c6894b952eefffb12f9b62) (cherry picked from commit 0766d08db925bf5fd4adc00c4f8ff883b72c3d96) --- src/core/devices/nm-device.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/core/devices/nm-device.c b/src/core/devices/nm-device.c index 66a2f44753..6fc39c858a 100644 --- a/src/core/devices/nm-device.c +++ b/src/core/devices/nm-device.c @@ -5350,9 +5350,10 @@ device_update_interface_flags(NMDevice *self, const NMPlatformLink *plink) static gboolean device_link_changed(NMDevice *self) { - NMDeviceClass * klass = NM_DEVICE_GET_CLASS(self); - NMDevicePrivate * priv = NM_DEVICE_GET_PRIVATE(self); - gboolean ip_ifname_changed = FALSE; + NMDeviceClass * klass = NM_DEVICE_GET_CLASS(self); + NMDevicePrivate * priv = NM_DEVICE_GET_PRIVATE(self); + gboolean ip_ifname_changed = FALSE; + gboolean hw_addr_changed; nm_auto_nmpobj const NMPObject *pllink_keep_alive = NULL; const NMPlatformLink * pllink; const char * str; @@ -5399,9 +5400,9 @@ device_link_changed(NMDevice *self) if (ifindex == nm_device_get_ip_ifindex(self)) _stats_update_counters_from_pllink(self, pllink); - had_hw_addr = (priv->hw_addr != NULL); - nm_device_update_hw_address(self); - got_hw_addr = (!had_hw_addr && priv->hw_addr); + had_hw_addr = (priv->hw_addr != NULL); + hw_addr_changed = nm_device_update_hw_address(self); + got_hw_addr = (!had_hw_addr && priv->hw_addr); nm_device_update_permanent_hw_address(self, FALSE); if (pllink->name[0] && !nm_streq(priv->iface, pllink->name)) { @@ -5451,6 +5452,8 @@ device_link_changed(NMDevice *self) /* Update DHCP, etc, if needed */ if (ip_ifname_changed) nm_device_update_dynamic_ip_setup(self, "IP interface changed"); + else if (hw_addr_changed) + nm_device_update_dynamic_ip_setup(self, "hw-address changed"); was_up = priv->up; priv->up = NM_FLAGS_HAS(pllink->n_ifi_flags, IFF_UP);