summary refs log tree commit diff
path: root/src/core/devices
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/devices')
-rw-r--r--src/core/devices/nm-device-utils.c49
1 files changed, 36 insertions, 13 deletions
diff --git a/src/core/devices/nm-device-utils.c b/src/core/devices/nm-device-utils.c
index 80909805..4597ba85 100644
--- a/src/core/devices/nm-device-utils.c
+++ b/src/core/devices/nm-device-utils.c
@@ -245,14 +245,36 @@ resolve_addr_helper_cb(GObject *source, GAsyncResult *result, gpointer user_data
     resolve_addr_complete(info, g_steal_pointer(&output), g_steal_pointer(&error));
 }
 
+typedef enum {
+    RESOLVE_ADDR_SERVICE_NONE  = 0x0,
+    RESOLVE_ADDR_SERVICE_DNS   = 0x1,
+    RESOLVE_ADDR_SERVICE_FILES = 0x2,
+} ResolveAddrService;
+
 static void
-resolve_addr_spawn_helper(ResolveAddrInfo *info)
+resolve_addr_spawn_helper(ResolveAddrInfo *info, ResolveAddrService services)
 {
-    char addr_str[NM_INET_ADDRSTRLEN];
+    char     addr_str[NM_INET_ADDRSTRLEN];
+    char     str[256];
+    char    *s     = str;
+    gsize    len   = sizeof(str);
+    gboolean comma = FALSE;
+
+    nm_assert(services != RESOLVE_ADDR_SERVICE_NONE);
+    nm_assert((services & ~(RESOLVE_ADDR_SERVICE_DNS | RESOLVE_ADDR_SERVICE_FILES)) == 0);
+
+    if (services & RESOLVE_ADDR_SERVICE_DNS) {
+        nm_strbuf_append(&s, &len, "%sdns", comma ? "," : "");
+        comma = TRUE;
+    }
+    if (services & RESOLVE_ADDR_SERVICE_FILES) {
+        nm_strbuf_append(&s, &len, "%sfiles", comma ? "," : "");
+        comma = TRUE;
+    }
 
     nm_inet_ntop(info->addr_family, &info->address, addr_str);
-    _LOG2D(info, "start lookup via nm-daemon-helper");
-    nm_utils_spawn_helper(NM_MAKE_STRV("resolve-address", addr_str),
+    _LOG2D(info, "start lookup via nm-daemon-helper using services: %s", str);
+    nm_utils_spawn_helper(NM_MAKE_STRV("resolve-address", addr_str, str),
                           g_task_get_cancellable(info->task),
                           resolve_addr_helper_cb,
                           info);
@@ -282,27 +304,28 @@ resolve_addr_resolved_cb(NMDnsSystemdResolved                    *resolved,
         dbus_error = g_dbus_error_get_remote_error(error);
         if (NM_STR_HAS_PREFIX(dbus_error, "org.freedesktop.resolve1.")) {
             /* systemd-resolved is enabled but it couldn't resolve the
-             * address via DNS.  Don't fall back to spawning the helper,
-             * because the helper will possibly ask again to
+             * address via DNS. Spawn again the helper to check if we
+             * can find a result in /etc/hosts. Don't enable the 'dns'
+             * service otherwise the helper will possibly ask again to
              * systemd-resolved (via /etc/resolv.conf), potentially using
              * other protocols than DNS or returning synthetic results.
              *
-             * Consider the error as the final indication that the address
-             * can't be resolved.
-             *
              * See: https://www.freedesktop.org/wiki/Software/systemd/resolved/#commonerrors
              */
-            resolve_addr_complete(info, NULL, g_error_copy(error));
+            resolve_addr_spawn_helper(info, RESOLVE_ADDR_SERVICE_FILES);
             return;
         }
 
-        resolve_addr_spawn_helper(info);
+        /* systemd-resolved couldn't be contacted, use the helper */
+        resolve_addr_spawn_helper(info, RESOLVE_ADDR_SERVICE_DNS | RESOLVE_ADDR_SERVICE_FILES);
         return;
     }
 
     if (names_len == 0) {
         _LOG2D(info, "systemd-resolved returned no result");
-        resolve_addr_complete(info, g_strdup(""), NULL);
+        /* We passed the NO_SYNTHESIZE flag and so systemd-resolved
+         * didn't look into /etc/hosts. Spawn the helper for that. */
+        resolve_addr_spawn_helper(info, RESOLVE_ADDR_SERVICE_FILES);
         return;
     }
 
@@ -366,7 +389,7 @@ nm_device_resolve_address(int                 addr_family,
         return;
     }
 
-    resolve_addr_spawn_helper(info);
+    resolve_addr_spawn_helper(info, RESOLVE_ADDR_SERVICE_DNS | RESOLVE_ADDR_SERVICE_FILES);
 }
 
 char *