From b86388bef3758b46f9c4239230c57ee9b2787fd8 Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Mon, 25 Oct 2021 15:58:25 +0200 Subject: [PATCH] core: avoid stale entries in the DNS manager When a virtual interface is removed externally, the device is unrealized and the ifindex is cleared; this also detaches the existing l3cfg from the device. At this point the l3cd entry for the device lingers forever in the DNS manager. Emit a last L3CD_CHANGED so that the old entry gets removed. Fixes-test: @disconnect_from_pppoe --- src/core/devices/nm-device.c | 12 ++++++++++++ src/core/nm-policy.c | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/core/devices/nm-device.c b/src/core/devices/nm-device.c index 4435b550e..896b0dc63 100644 --- a/src/core/devices/nm-device.c +++ b/src/core/devices/nm-device.c @@ -3980,6 +3980,18 @@ _set_ifindex(NMDevice *self, int ifindex, gboolean is_ip_ifindex) if (priv->l3cfg) { if (ip_ifindex_new <= 0 || ip_ifindex_new != nm_l3cfg_get_ifindex(priv->l3cfg)) { + const NML3ConfigData *l3cd_old; + + if (ip_ifindex_new <= 0) { + /* The ifindex was reset. Send a last L3CD_CHANGED + * signal with a NULL l3cd so that the old one can + * be removed from the DNS manager. + */ + l3cd_old = nm_l3cfg_get_combined_l3cd(priv->l3cfg, TRUE); + if (l3cd_old) + g_signal_emit(self, signals[L3CD_CHANGED], 0, l3cd_old, NULL); + } + g_signal_handlers_disconnect_by_func(priv->l3cfg, G_CALLBACK(_dev_l3_cfg_notify_cb), self); diff --git a/src/core/nm-policy.c b/src/core/nm-policy.c index 2c3e80a32..329d14d16 100644 --- a/src/core/nm-policy.c +++ b/src/core/nm-policy.c @@ -2120,7 +2120,7 @@ device_l3cd_changed(NMDevice * device, * now. */ state = nm_device_get_state(device); - if (state > NM_DEVICE_STATE_DISCONNECTED && state < NM_DEVICE_STATE_DEACTIVATING) { + if (l3cd_new && state > NM_DEVICE_STATE_DISCONNECTED && state < NM_DEVICE_STATE_DEACTIVATING) { nm_dns_manager_set_ip_config(priv->dns_manager, AF_UNSPEC, device,