diff options
author | Beniamino Galvani <bgalvani@redhat.com> | 2023-06-29 09:21:23 +0200 |
---|---|---|
committer | Beniamino Galvani <bgalvani@redhat.com> | 2023-06-29 15:12:51 +0200 |
commit | 646e041523668a7bc19dc18e84e07e2aada89c2d (patch) | |
tree | 1fbce8c784dbbc9013814e9f67864e18bbe39b31 | |
parent | c961ec1f990aa00ebc7da0979962318eb5c5a369 (diff) |
dns: fix tracking of best ip configbg/dns-fix-best
When a IP configuration has type "best", it is the configuration with
the best (lowest) metric default route for the specific address
family. Therefore, there can be only one best configuration for
address family.
When a new configuration is added as best, make sure it is the only
one for the address family.
This reverts commit 0abc14b3a0d9259b2a17f2fe3c56444752f49215.
Fixes: 0abc14b3a0d9 ('core: remove unused best_ip_config_[46] field in NMDnsManager')
https://lists.freedesktop.org/archives/networkmanager/2023-June/000123.html
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/1331
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1683
-rw-r--r-- | src/core/dns/nm-dns-manager.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/core/dns/nm-dns-manager.c b/src/core/dns/nm-dns-manager.c index 2eeb48f21a..535646930c 100644 --- a/src/core/dns/nm-dns-manager.c +++ b/src/core/dns/nm-dns-manager.c @@ -125,6 +125,9 @@ typedef struct { NMConfig *config; + NMDnsConfigIPData *best_ip_config_4; + NMDnsConfigIPData *best_ip_config_6; + struct { guint64 ts; guint num_restarts; @@ -1978,6 +1981,7 @@ nm_dns_manager_set_ip_config(NMDnsManager *self, NMDnsConfigIPData *ip_data = NULL; int dns_priority; gboolean any_removed = FALSE; + NMDnsConfigIPData **p_best; g_return_val_if_fail(NM_IS_DNS_MANAGER(self), FALSE); g_return_val_if_fail(!l3cd || NM_IS_L3_CONFIG_DATA(l3cd), FALSE); @@ -2045,6 +2049,12 @@ nm_dns_manager_set_ip_config(NMDnsManager *self, } any_removed = TRUE; + + if (priv->best_ip_config_4 == ip_data_iter) + priv->best_ip_config_4 = NULL; + if (priv->best_ip_config_6 == ip_data_iter) + priv->best_ip_config_6 = NULL; + _dns_config_ip_data_free(ip_data_iter); } } @@ -2095,6 +2105,19 @@ nm_dns_manager_set_ip_config(NMDnsManager *self, changed = TRUE; } + p_best = NM_IS_IPv4(addr_family) ? &priv->best_ip_config_4 : &priv->best_ip_config_6; + if (ip_config_type == NM_DNS_IP_CONFIG_TYPE_BEST_DEVICE) { + /* Only one best-device per IP version is allowed */ + if (*p_best != ip_data) { + if (*p_best) + (*p_best)->ip_config_type = NM_DNS_IP_CONFIG_TYPE_DEFAULT; + *p_best = ip_data; + } + } else { + if (*p_best == ip_data) + *p_best = NULL; + } + if (changed) priv->ip_data_lst_need_sort = TRUE; @@ -2819,6 +2842,9 @@ dispose(GObject *object) nm_clear_g_source_inst(&priv->update_pending_unblock); + priv->best_ip_config_4 = NULL; + priv->best_ip_config_6 = NULL; + c_list_for_each_entry_safe (ip_data, ip_data_safe, &priv->ip_data_lst_head, ip_data_lst) _dns_config_ip_data_free(ip_data); |