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.
This commit is contained in:
Thomas Haller 2018-12-01 15:48:19 +01:00
parent df734a03bc
commit c7d8864511
4 changed files with 74 additions and 36 deletions

View file

@ -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>

View file

@ -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)
{

View file

@ -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,

View file

@ -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