232 lines
8.7 KiB
Diff
232 lines
8.7 KiB
Diff
From 4d75c43f1a12840b940bf0a327d5664db84b9c1c Mon Sep 17 00:00:00 2001
|
|
From: Lubomir Rintel <lkundrak@v3.sk>
|
|
Date: Mon, 12 Sep 2022 13:21:51 +0200
|
|
Subject: [PATCH 3/3] dns-manager: always apply options from [global-dns]
|
|
|
|
Currently, the use of [global-dns] section for setting DNS options is
|
|
conditioned on presence of a nameserver in a [global-dns-domain-*] section.
|
|
Attempt to use the section for options alone results in an error:
|
|
|
|
[global-dns]
|
|
options=timeout:1
|
|
|
|
Or via D-Bus API:
|
|
|
|
# busctl set-property org.freedesktop.NetworkManager \
|
|
/org/freedesktop/NetworkManager org.freedesktop.NetworkManager \
|
|
GlobalDnsConfiguration 'a{sv}' 2 \
|
|
"options" as 1 "timeout:1" \
|
|
"domains" a{sv} 0
|
|
...
|
|
Nov 24 13:15:21 zmok.local NetworkManager[501184]: <debug> [1669292121.3904]
|
|
manager: set global DNS failed with error: Global
|
|
DNS configuration is missing the default domain
|
|
|
|
The insistence on existence of [global-dns-domain-*] would make sense if
|
|
other [global-dns-domain-...] sections were present.
|
|
|
|
However, the user might only want to set the options in resolv.conf and
|
|
still use connection-provide nameservers for the actual resolving.
|
|
|
|
Lift the limitation by allowing the [global-dns] to be used alone, while
|
|
still insist on [global-dns-domain-*] being there in presence of other
|
|
domain-specific options.
|
|
|
|
https://bugzilla.redhat.com/show_bug.cgi?id=2019306
|
|
(cherry picked from commit 1f0d1d78d2a28ef82764a801c344e22816b06f67)
|
|
---
|
|
Makefile.am | 2 +
|
|
src/core/dns/nm-dns-manager.c | 41 +++++++++----------
|
|
src/core/nm-config-data.c | 2 +-
|
|
src/core/tests/config/global-dns-good.conf | 13 ++++++
|
|
src/core/tests/config/global-dns-options.conf | 5 +++
|
|
src/core/tests/config/test-config.c | 16 +++++++-
|
|
6 files changed, 55 insertions(+), 24 deletions(-)
|
|
create mode 100644 src/core/tests/config/global-dns-good.conf
|
|
create mode 100644 src/core/tests/config/global-dns-options.conf
|
|
|
|
diff --git a/Makefile.am b/Makefile.am
|
|
index aa79967e1b..3d43c010a7 100644
|
|
--- a/Makefile.am
|
|
+++ b/Makefile.am
|
|
@@ -4497,7 +4497,9 @@ EXTRA_DIST += \
|
|
src/core/tests/config/NetworkManager-warn.conf \
|
|
src/core/tests/config/NetworkManager.state \
|
|
src/core/tests/config/bad.conf \
|
|
+ src/core/tests/config/global-dns-good.conf \
|
|
src/core/tests/config/global-dns-invalid.conf \
|
|
+ src/core/tests/config/global-dns-options.conf \
|
|
src/core/tests/config/conf.d/00-overrides.conf \
|
|
src/core/tests/config/conf.d/10-more.conf \
|
|
src/core/tests/config/conf.d/20-config-enable-1.conf \
|
|
diff --git a/src/core/dns/nm-dns-manager.c b/src/core/dns/nm-dns-manager.c
|
|
index 457b82a098..42519e64fe 100644
|
|
--- a/src/core/dns/nm-dns-manager.c
|
|
+++ b/src/core/dns/nm-dns-manager.c
|
|
@@ -1201,7 +1201,8 @@ compute_hash(NMDnsManager *self, const NMGlobalDnsConfig *global, guint8 buffer[
|
|
|
|
if (global)
|
|
nm_global_dns_config_update_checksum(global, sum);
|
|
- else {
|
|
+
|
|
+ if (!global || !nm_global_dns_config_lookup_domain(global, "*")) {
|
|
const CList *head;
|
|
|
|
/* FIXME(ip-config-checksum): this relies on the fact that an IP
|
|
@@ -1244,13 +1245,15 @@ merge_global_dns_config(NMResolvConfData *rc, NMGlobalDnsConfig *global_conf)
|
|
}
|
|
|
|
default_domain = nm_global_dns_config_lookup_domain(global_conf, "*");
|
|
- nm_assert(default_domain);
|
|
+ if (!default_domain)
|
|
+ return TRUE;
|
|
|
|
servers = nm_global_dns_domain_get_servers(default_domain);
|
|
- if (servers) {
|
|
- for (i = 0; servers[i]; i++)
|
|
- add_string_item(rc->nameservers, servers[i], TRUE);
|
|
- }
|
|
+ if (!servers)
|
|
+ return TRUE;
|
|
+
|
|
+ for (i = 0; servers[i]; i++)
|
|
+ add_string_item(rc->nameservers, servers[i], TRUE);
|
|
|
|
return TRUE;
|
|
}
|
|
@@ -1311,9 +1314,10 @@ _collect_resolv_conf_data(NMDnsManager *self,
|
|
|
|
priv = NM_DNS_MANAGER_GET_PRIVATE(self);
|
|
|
|
- if (global_config) {
|
|
+ if (global_config)
|
|
merge_global_dns_config(&rc, global_config);
|
|
- } else {
|
|
+
|
|
+ if (!global_config || !nm_global_dns_config_lookup_domain(global_config, "*")) {
|
|
nm_auto_str_buf NMStrBuf tmp_strbuf = NM_STR_BUF_INIT(0, FALSE);
|
|
int first_prio = 0;
|
|
const NMDnsConfigIPData *ip_data;
|
|
@@ -2556,14 +2560,12 @@ config_changed_cb(NMConfig *config,
|
|
}
|
|
}
|
|
|
|
-static GVariant *
|
|
-_get_global_config_variant(NMGlobalDnsConfig *global)
|
|
+static void
|
|
+_get_global_config_variant(GVariantBuilder *builder, NMGlobalDnsConfig *global)
|
|
{
|
|
NMGlobalDnsDomain *domain;
|
|
- GVariantBuilder builder;
|
|
guint i, num;
|
|
|
|
- g_variant_builder_init(&builder, G_VARIANT_TYPE("aa{sv}"));
|
|
num = nm_global_dns_config_get_num_domains(global);
|
|
for (i = 0; i < num; i++) {
|
|
GVariantBuilder conf_builder;
|
|
@@ -2599,10 +2601,8 @@ _get_global_config_variant(NMGlobalDnsConfig *global)
|
|
"priority",
|
|
g_variant_new_int32(NM_DNS_PRIORITY_DEFAULT_NORMAL));
|
|
|
|
- g_variant_builder_add(&builder, "a{sv}", &conf_builder);
|
|
+ g_variant_builder_add(builder, "a{sv}", &conf_builder);
|
|
}
|
|
-
|
|
- return g_variant_ref_sink(g_variant_builder_end(&builder));
|
|
}
|
|
|
|
static GVariant *
|
|
@@ -2619,15 +2619,12 @@ _get_config_variant(NMDnsManager *self)
|
|
if (priv->config_variant)
|
|
return priv->config_variant;
|
|
|
|
- global_config = nm_config_data_get_global_dns_config(nm_config_get_data(priv->config));
|
|
- if (global_config) {
|
|
- priv->config_variant = _get_global_config_variant(global_config);
|
|
- _LOGT("current configuration: %s", (str = g_variant_print(priv->config_variant, TRUE)));
|
|
- return priv->config_variant;
|
|
- }
|
|
-
|
|
g_variant_builder_init(&builder, G_VARIANT_TYPE("aa{sv}"));
|
|
|
|
+ global_config = nm_config_data_get_global_dns_config(nm_config_get_data(priv->config));
|
|
+ if (global_config)
|
|
+ _get_global_config_variant(&builder, global_config);
|
|
+
|
|
head = _mgr_get_ip_data_lst_head(self);
|
|
c_list_for_each_entry (ip_data, head, ip_data_lst) {
|
|
GVariantBuilder entry_builder;
|
|
diff --git a/src/core/nm-config-data.c b/src/core/nm-config-data.c
|
|
index 1504b15659..c6ab998f94 100644
|
|
--- a/src/core/nm-config-data.c
|
|
+++ b/src/core/nm-config-data.c
|
|
@@ -1233,7 +1233,7 @@ load_global_dns(GKeyFile *keyfile, gboolean internal)
|
|
default_found = TRUE;
|
|
}
|
|
|
|
- if (!default_found) {
|
|
+ if (!default_found && g_hash_table_size(dns_config->domains)) {
|
|
nm_log_dbg(LOGD_CORE,
|
|
"%s global DNS configuration is missing default domain, ignore it",
|
|
internal ? "internal" : "user");
|
|
diff --git a/src/core/tests/config/global-dns-good.conf b/src/core/tests/config/global-dns-good.conf
|
|
new file mode 100644
|
|
index 0000000000..6265a611cf
|
|
--- /dev/null
|
|
+++ b/src/core/tests/config/global-dns-good.conf
|
|
@@ -0,0 +1,13 @@
|
|
+# Good configuration, since there is a default domain section
|
|
+
|
|
+[global-dns]
|
|
+searches=foo.com
|
|
+options=timeout:5
|
|
+
|
|
+[global-dns-domain-*]
|
|
+servers=4.5.6.7
|
|
+options=myoption1
|
|
+
|
|
+[global-dns-domain-test.com]
|
|
+servers=1.2.3.4
|
|
+options=myoption2
|
|
diff --git a/src/core/tests/config/global-dns-options.conf b/src/core/tests/config/global-dns-options.conf
|
|
new file mode 100644
|
|
index 0000000000..0be1773525
|
|
--- /dev/null
|
|
+++ b/src/core/tests/config/global-dns-options.conf
|
|
@@ -0,0 +1,5 @@
|
|
+# Good configuration, since there is no domain section
|
|
+
|
|
+[global-dns]
|
|
+searches=foo.com
|
|
+options=timeout:5
|
|
diff --git a/src/core/tests/config/test-config.c b/src/core/tests/config/test-config.c
|
|
index fa7fae0757..054b9003f4 100644
|
|
--- a/src/core/tests/config/test-config.c
|
|
+++ b/src/core/tests/config/test-config.c
|
|
@@ -370,7 +370,21 @@ test_config_global_dns(void)
|
|
|
|
g_object_unref(config);
|
|
|
|
- /* Check that a file without a default domain section gives a NULL configuration */
|
|
+ /* Check that a file with a default domain section gives a good configuration */
|
|
+ config =
|
|
+ setup_config(NULL, TEST_DIR "/global-dns-good.conf", "", NULL, "/no/such/dir", "", NULL);
|
|
+ dns = nm_config_data_get_global_dns_config(nm_config_get_data_orig(config));
|
|
+ g_assert(dns);
|
|
+ g_object_unref(config);
|
|
+
|
|
+ /* Check that a file with options but no domains gives a good configuration */
|
|
+ config =
|
|
+ setup_config(NULL, TEST_DIR "/global-dns-options.conf", "", NULL, "/no/such/dir", "", NULL);
|
|
+ dns = nm_config_data_get_global_dns_config(nm_config_get_data_orig(config));
|
|
+ g_assert(dns);
|
|
+ g_object_unref(config);
|
|
+
|
|
+ /* Check that a file with a domain domain, but without a default one gives a NULL configuration */
|
|
config =
|
|
setup_config(NULL, TEST_DIR "/global-dns-invalid.conf", "", NULL, "/no/such/dir", "", NULL);
|
|
dns = nm_config_data_get_global_dns_config(nm_config_get_data_orig(config));
|
|
--
|
|
2.39.1
|
|
|