diff options
author | Thomas Haller <thaller@redhat.com> | 2018-12-01 15:48:19 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2018-12-11 09:23:47 +0100 |
commit | c7d88645111c90aaea418aad3f3c94398db59ed8 (patch) | |
tree | 7cf329fe5b1558b4b1a572afda56a108c3b1a3c8 | |
parent | df734a03bcb860344b5f25a24255617bb856af29 (diff) | |
download | NetworkManager-c7d88645111c90aaea418aad3f3c94398db59ed8.tar.gz |
connectivity: honor "main.systemd-resolved" setting to not resolve names first
If the user disabled systemd-resolved, two things seem apparent:
- the user does not want us to use systemd-resolved
- NetworkManager is not pushing the DNS configuration to
systemd-resoved.
It seems to me, we should not consult systemd-resolved in that case.
-rw-r--r-- | man/NetworkManager.conf.xml | 4 | ||||
-rw-r--r-- | src/dns/nm-dns-manager.c | 15 | ||||
-rw-r--r-- | src/dns/nm-dns-manager.h | 2 | ||||
-rw-r--r-- | src/nm-connectivity.c | 89 |
4 files changed, 74 insertions, 36 deletions
diff --git a/man/NetworkManager.conf.xml b/man/NetworkManager.conf.xml index 26de6f275a..65ebe013ad 100644 --- a/man/NetworkManager.conf.xml +++ b/man/NetworkManager.conf.xml @@ -402,11 +402,13 @@ no-auto-default=* <literal>systemd-resolved</literal>. Defaults to "<literal>true</literal>". </para> <para>Note that this setting is complementary to the - <varname>dns</varname> setting. You can keep this enable while using + <varname>dns</varname> setting. You can keep this enabled while using <varname>dns</varname> set to another DNS plugin alongside <literal>systemd-resolved</literal>, or <varname>dns</varname> set to <literal>systemd-resolved</literal> to configure the system resolver to use <literal>systemd-resolved</literal>.</para> + <para>If systemd-resolved is enabled, the connectivity check resolves the + hostname per-device.</para> </listitem> </varlistentry> diff --git a/src/dns/nm-dns-manager.c b/src/dns/nm-dns-manager.c index 5b02edb92d..1f1fe21317 100644 --- a/src/dns/nm-dns-manager.c +++ b/src/dns/nm-dns-manager.c @@ -344,6 +344,21 @@ _ip_config_lst_head (NMDnsManager *self) /*****************************************************************************/ +gboolean +nm_dns_manager_has_systemd_resolved (NMDnsManager *self) +{ + NMDnsManagerPrivate *priv; + + g_return_val_if_fail (NM_IS_DNS_MANAGER (self), FALSE); + + priv = NM_DNS_MANAGER_GET_PRIVATE (self); + + return priv->sd_resolve_plugin + || NM_IS_DNS_SYSTEMD_RESOLVED (priv->plugin); +} + +/*****************************************************************************/ + static void add_string_item (GPtrArray *array, const char *str, gboolean dup) { diff --git a/src/dns/nm-dns-manager.h b/src/dns/nm-dns-manager.h index a3e9472e5f..7f6ed3edc6 100644 --- a/src/dns/nm-dns-manager.h +++ b/src/dns/nm-dns-manager.h @@ -129,6 +129,8 @@ typedef enum { void nm_dns_manager_stop (NMDnsManager *self); +gboolean nm_dns_manager_has_systemd_resolved (NMDnsManager *self); + /*****************************************************************************/ char *nmtst_dns_create_resolv_conf (const char *const*searches, diff --git a/src/nm-connectivity.c b/src/nm-connectivity.c index ea4ea7189e..3703f7f269 100644 --- a/src/nm-connectivity.c +++ b/src/nm-connectivity.c @@ -23,7 +23,6 @@ #include "nm-default.h" #include "nm-connectivity.h" -#include "nm-dbus-manager.h" #include <string.h> @@ -34,6 +33,8 @@ #include "c-list/src/c-list.h" #include "nm-config.h" #include "NetworkManagerUtils.h" +#include "nm-dbus-manager.h" +#include "dns/nm-dns-manager.h" #define HEADER_STATUS_ONLINE "X-NetworkManager-Status: online\r\n" @@ -114,9 +115,10 @@ typedef struct { char *host; char *port; char *response; - gboolean enabled; - guint interval; NMConfig *config; + guint interval; + + bool enabled:1; } NMConnectivityPrivate; struct _NMConnectivity { @@ -728,43 +730,60 @@ nm_connectivity_check_start (NMConnectivity *self, #if WITH_CONCHECK if (iface && ifindex > 0 && priv->enabled && priv->host) { - GDBusConnection *dbus_connection; + gboolean has_systemd_resolved; cb_data->concheck.ifindex = ifindex; - dbus_connection = nm_dbus_manager_get_dbus_connection (nm_dbus_manager_get ()); - if (!dbus_connection) { - /* we have no D-Bus connection? That might happen in configure and quit mode. - * - * Anyway, something is very odd, just fail connectivity check. */ - _LOG2D ("start fake request (fail due to no D-Bus connection)"); - cb_data->fail_reason_no_dbus_connection = TRUE; - cb_data->timeout_id = g_idle_add (_idle_cb, cb_data); - return cb_data; + /* note that we pick up support for systemd-resolved right away when we need it. + * We don't need to remember the setting, because we can (cheaply) check anew + * on each request. + * + * Yes, this makes NMConnectivity singleton dependent on NMDnsManager singleton. + * Well, not really: it makes connectivity-check-start dependent on NMDnsManager + * which merely means, not to start a connectivity check, late during shutdown. */ + has_systemd_resolved = nm_dns_manager_has_systemd_resolved (nm_dns_manager_get ()); + + if (has_systemd_resolved) { + GDBusConnection *dbus_connection; + + dbus_connection = nm_dbus_manager_get_dbus_connection (nm_dbus_manager_get ()); + if (!dbus_connection) { + /* we have no D-Bus connection? That might happen in configure and quit mode. + * + * Anyway, something is very odd, just fail connectivity check. */ + _LOG2D ("start fake request (fail due to no D-Bus connection)"); + cb_data->fail_reason_no_dbus_connection = TRUE; + cb_data->timeout_id = g_idle_add (_idle_cb, cb_data); + return cb_data; + } + + cb_data->concheck.resolve_cancellable = g_cancellable_new (); + + g_dbus_connection_call (nm_dbus_manager_get_dbus_connection (nm_dbus_manager_get ()), + "org.freedesktop.resolve1", + "/org/freedesktop/resolve1", + "org.freedesktop.resolve1.Manager", + "ResolveHostname", + g_variant_new ("(isit)", + (gint32) cb_data->concheck.ifindex, + priv->host, + (gint32) cb_data->addr_family, + SD_RESOLVED_DNS), + G_VARIANT_TYPE ("(a(iiay)st)"), + G_DBUS_CALL_FLAGS_NONE, + -1, + cb_data->concheck.resolve_cancellable, + resolve_cb, + cb_data); + _LOG2D ("start request to '%s' (try resolving '%s' using systemd-resolved)", + priv->uri, + priv->host); + } else { + _LOG2D ("start request to '%s' (systemd-resolved not available)", + priv->uri); + do_curl_request (cb_data); } - cb_data->concheck.resolve_cancellable = g_cancellable_new (); - - g_dbus_connection_call (nm_dbus_manager_get_dbus_connection (nm_dbus_manager_get ()), - "org.freedesktop.resolve1", - "/org/freedesktop/resolve1", - "org.freedesktop.resolve1.Manager", - "ResolveHostname", - g_variant_new ("(isit)", - (gint32) cb_data->concheck.ifindex, - priv->host, - (gint32) cb_data->addr_family, - SD_RESOLVED_DNS), - G_VARIANT_TYPE ("(a(iiay)st)"), - G_DBUS_CALL_FLAGS_NONE, - -1, - cb_data->concheck.resolve_cancellable, - resolve_cb, - cb_data); - - _LOG2D ("start request to '%s' (try resolving '%s' using systemd-resolved)", - priv->uri, - priv->host); return cb_data; } #endif |