summary refs log tree commit diff
path: root/src/core/dns
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/dns')
-rw-r--r--src/core/dns/nm-dns-manager.c32
-rw-r--r--src/core/dns/nm-dns-manager.h5
-rw-r--r--src/core/dns/nm-dns-systemd-resolved.c103
3 files changed, 82 insertions, 58 deletions
diff --git a/src/core/dns/nm-dns-manager.c b/src/core/dns/nm-dns-manager.c
index 4c498c82..f0ec0c89 100644
--- a/src/core/dns/nm-dns-manager.c
+++ b/src/core/dns/nm-dns-manager.c
@@ -19,7 +19,7 @@
 #include <linux/fs.h>
 
 #if WITH_LIBPSL
-    #include <libpsl.h>
+#include <libpsl.h>
 #endif
 
 #include "libnm-glib-aux/nm-str-buf.h"
@@ -42,17 +42,17 @@
 #define HASH_LEN NM_UTILS_CHECKSUM_LENGTH_SHA1
 
 #ifndef RESOLVCONF_PATH
-    #define RESOLVCONF_PATH "/sbin/resolvconf"
-    #define HAS_RESOLVCONF  0
+#define RESOLVCONF_PATH "/sbin/resolvconf"
+#define HAS_RESOLVCONF  0
 #else
-    #define HAS_RESOLVCONF 1
+#define HAS_RESOLVCONF 1
 #endif
 
 #ifndef NETCONFIG_PATH
-    #define NETCONFIG_PATH "/sbin/netconfig"
-    #define HAS_NETCONFIG  0
+#define NETCONFIG_PATH "/sbin/netconfig"
+#define HAS_NETCONFIG  0
 #else
-    #define HAS_NETCONFIG 1
+#define HAS_NETCONFIG 1
 #endif
 
 /*****************************************************************************/
@@ -272,7 +272,7 @@ _dns_config_ip_data_new(NMDnsConfigData * data,
     g_signal_connect(ip_config,
                      NM_IS_IP4_CONFIG(ip_config) ? "notify::" NM_IP4_CONFIG_DNS_PRIORITY
                                                  : "notify::" NM_IP6_CONFIG_DNS_PRIORITY,
-                     (GCallback) _ip_config_dns_priority_changed,
+                     G_CALLBACK(_ip_config_dns_priority_changed),
                      ip_data);
 
     _ASSERT_dns_config_ip_data(ip_data);
@@ -1327,7 +1327,7 @@ get_ip_rdns_domains(NMIPConfig *ip_config)
     /* Free the array and return NULL if the only element was the ending NULL */
     strv = (char **) g_ptr_array_free(domains, (domains->len == 1));
 
-    return _nm_utils_strv_cleanup(strv, FALSE, FALSE, TRUE);
+    return nm_strv_cleanup(strv, FALSE, FALSE, TRUE);
 }
 
 static gboolean
@@ -1744,8 +1744,8 @@ plugin_skip:;
         nameservers    = g_new0(char *, 2);
         nameservers[0] = g_strdup(lladdr);
 
-        need_edns0 = nm_utils_strv_find_first(options, -1, NM_SETTING_DNS_OPTION_EDNS0) < 0;
-        need_trust = nm_utils_strv_find_first(options, -1, NM_SETTING_DNS_OPTION_TRUST_AD) < 0;
+        need_edns0 = nm_strv_find_first(options, -1, NM_SETTING_DNS_OPTION_EDNS0) < 0;
+        need_trust = nm_strv_find_first(options, -1, NM_SETTING_DNS_OPTION_TRUST_AD) < 0;
 
         if (need_edns0 || need_trust) {
             gsize len;
@@ -2128,10 +2128,7 @@ _resolvconf_resolved_managed(void)
          * We want to handle that, because systemd-resolved might not
          * have started yet. */
         full_path = g_file_read_link(_PATH_RESCONF, NULL);
-        if (nm_utils_strv_find_first((char **) RESOLVED_PATHS,
-                                     G_N_ELEMENTS(RESOLVED_PATHS),
-                                     full_path)
-            >= 0)
+        if (nm_strv_find_first(RESOLVED_PATHS, G_N_ELEMENTS(RESOLVED_PATHS), full_path) >= 0)
             return TRUE;
 
         /* see if resolv.conf is a symlink that resolves exactly one
@@ -2143,10 +2140,7 @@ _resolvconf_resolved_managed(void)
          * We want to handle that, because systemd-resolved might not
          * have started yet. */
         real_path = realpath(_PATH_RESCONF, NULL);
-        if (nm_utils_strv_find_first((char **) RESOLVED_PATHS,
-                                     G_N_ELEMENTS(RESOLVED_PATHS),
-                                     real_path)
-            >= 0)
+        if (nm_strv_find_first(RESOLVED_PATHS, G_N_ELEMENTS(RESOLVED_PATHS), real_path) >= 0)
             return TRUE;
 
         /* fall-through and resolve the symlink, to check the file
diff --git a/src/core/dns/nm-dns-manager.h b/src/core/dns/nm-dns-manager.h
index 501085f7..1972a5dd 100644
--- a/src/core/dns/nm-dns-manager.h
+++ b/src/core/dns/nm-dns-manager.h
@@ -21,11 +21,6 @@ typedef enum {
     NM_DNS_IP_CONFIG_TYPE_VPN,
 } NMDnsIPConfigType;
 
-enum {
-    NM_DNS_PRIORITY_DEFAULT_NORMAL = 100,
-    NM_DNS_PRIORITY_DEFAULT_VPN    = 50,
-};
-
 /*****************************************************************************/
 
 struct _NMDnsConfigData;
diff --git a/src/core/dns/nm-dns-systemd-resolved.c b/src/core/dns/nm-dns-systemd-resolved.c
index 4b8c4f94..445f8498 100644
--- a/src/core/dns/nm-dns-systemd-resolved.c
+++ b/src/core/dns/nm-dns-systemd-resolved.c
@@ -36,6 +36,7 @@
 
 /* define a variable, so that we can compare the operation with pointer equality. */
 static const char *const DBUS_OP_SET_LINK_DEFAULT_ROUTE = "SetLinkDefaultRoute";
+static const char *const DBUS_OP_SET_LINK_DNS_OVER_TLS  = "SetLinkDNSOverTLS";
 
 /*****************************************************************************/
 
@@ -86,7 +87,12 @@ typedef struct {
     bool             try_start_blocked : 1;
     bool             dbus_initied : 1;
     bool             send_updates_waiting : 1;
-    NMTernary        has_link_default_route : 3;
+    /* These two variables ensure that the log is not spammed with
+     * API (not) supported messages.
+     * They can be removed when no distro uses systemd-resolved < v240 anymore
+     */
+    NMTernary has_link_default_route : 3;
+    NMTernary has_link_dns_over_tls : 3;
 } NMDnsSystemdResolvedPrivate;
 
 struct _NMDnsSystemdResolved {
@@ -201,16 +207,26 @@ call_done(GObject *source, GAsyncResult *r, gpointer user_data)
             priv->has_link_default_route = NM_TERNARY_TRUE;
             _LOGD("systemd-resolved support for SetLinkDefaultRoute(): API supported");
         }
+        if (request_item->operation == DBUS_OP_SET_LINK_DNS_OVER_TLS
+            && priv->has_link_dns_over_tls == NM_TERNARY_DEFAULT) {
+            priv->has_link_dns_over_tls = NM_TERNARY_TRUE;
+            _LOGD("systemd-resolved support for SetLinkDNSOverTLS(): API supported");
+        }
         priv->send_updates_warn_ratelimited = FALSE;
         return;
     }
 
-    if (request_item->operation == DBUS_OP_SET_LINK_DEFAULT_ROUTE
-        && nm_g_error_matches(error, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD)) {
-        if (priv->has_link_default_route == NM_TERNARY_DEFAULT) {
+    if (nm_g_error_matches(error, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD)) {
+        if (priv->has_link_default_route == NM_TERNARY_DEFAULT
+            && request_item->operation == DBUS_OP_SET_LINK_DEFAULT_ROUTE) {
             priv->has_link_default_route = NM_TERNARY_FALSE;
             _LOGD("systemd-resolved support for SetLinkDefaultRoute(): API not supported");
         }
+        if (priv->has_link_dns_over_tls == NM_TERNARY_DEFAULT
+            && request_item->operation == DBUS_OP_SET_LINK_DNS_OVER_TLS) {
+            priv->has_link_dns_over_tls = NM_TERNARY_FALSE;
+            _LOGD("systemd-resolved support for SetLinkDNSOverTLS(): API not supported");
+        }
         return;
     }
 
@@ -286,14 +302,15 @@ free_pending_updates(NMDnsSystemdResolved *self)
 static gboolean
 prepare_one_interface(NMDnsSystemdResolved *self, InterfaceConfig *ic)
 {
-    GVariantBuilder          dns;
-    GVariantBuilder          domains;
-    NMCListElem *            elem;
-    NMSettingConnectionMdns  mdns     = NM_SETTING_CONNECTION_MDNS_DEFAULT;
-    NMSettingConnectionLlmnr llmnr    = NM_SETTING_CONNECTION_LLMNR_DEFAULT;
-    const char *             mdns_arg = NULL, *llmnr_arg = NULL;
-    gboolean                 has_config        = FALSE;
-    gboolean                 has_default_route = FALSE;
+    GVariantBuilder               dns;
+    GVariantBuilder               domains;
+    NMCListElem *                 elem;
+    NMSettingConnectionMdns       mdns         = NM_SETTING_CONNECTION_MDNS_DEFAULT;
+    NMSettingConnectionLlmnr      llmnr        = NM_SETTING_CONNECTION_LLMNR_DEFAULT;
+    NMSettingConnectionDnsOverTls dns_over_tls = NM_SETTING_CONNECTION_DNS_OVER_TLS_DEFAULT;
+    const char *                  mdns_arg = NULL, *llmnr_arg = NULL, *dns_over_tls_arg = NULL;
+    gboolean                      has_config        = FALSE;
+    gboolean                      has_default_route = FALSE;
 
     g_variant_builder_init(&dns, G_VARIANT_TYPE("(ia(iay))"));
     g_variant_builder_add(&dns, "i", ic->ifindex);
@@ -315,6 +332,8 @@ prepare_one_interface(NMDnsSystemdResolved *self, InterfaceConfig *ic)
         if (NM_IS_IP4_CONFIG(ip_config)) {
             mdns  = NM_MAX(mdns, nm_ip4_config_mdns_get(NM_IP4_CONFIG(ip_config)));
             llmnr = NM_MAX(llmnr, nm_ip4_config_llmnr_get(NM_IP4_CONFIG(ip_config)));
+            dns_over_tls =
+                NM_MAX(dns_over_tls, nm_ip4_config_dns_over_tls_get(NM_IP4_CONFIG(ip_config)));
         }
     }
 
@@ -353,7 +372,24 @@ prepare_one_interface(NMDnsSystemdResolved *self, InterfaceConfig *ic)
     }
     nm_assert(llmnr_arg);
 
-    if (!nm_str_is_empty(mdns_arg) || !nm_str_is_empty(llmnr_arg))
+    switch (dns_over_tls) {
+    case NM_SETTING_CONNECTION_DNS_OVER_TLS_NO:
+        dns_over_tls_arg = "no";
+        break;
+    case NM_SETTING_CONNECTION_DNS_OVER_TLS_OPPORTUNISTIC:
+        dns_over_tls_arg = "opportunistic";
+        break;
+    case NM_SETTING_CONNECTION_DNS_OVER_TLS_YES:
+        dns_over_tls_arg = "yes";
+        break;
+    case NM_SETTING_CONNECTION_DNS_OVER_TLS_DEFAULT:
+        dns_over_tls_arg = "";
+        break;
+    }
+    nm_assert(dns_over_tls_arg);
+
+    if (!nm_str_is_empty(mdns_arg) || !nm_str_is_empty(llmnr_arg)
+        || !nm_str_is_empty(dns_over_tls_arg))
         has_config = TRUE;
 
     _request_item_append(self, "SetLinkDomains", ic->ifindex, g_variant_builder_end(&domains));
@@ -370,6 +406,10 @@ prepare_one_interface(NMDnsSystemdResolved *self, InterfaceConfig *ic)
                          ic->ifindex,
                          g_variant_new("(is)", ic->ifindex, llmnr_arg ?: ""));
     _request_item_append(self, "SetLinkDNS", ic->ifindex, g_variant_builder_end(&dns));
+    _request_item_append(self,
+                         DBUS_OP_SET_LINK_DNS_OVER_TLS,
+                         ic->ifindex,
+                         g_variant_new("(is)", ic->ifindex, dns_over_tls_arg ?: ""));
 
     return has_config;
 }
@@ -422,12 +462,7 @@ ensure_resolved_running(NMDnsSystemdResolved *self)
         priv->try_start_blocked = TRUE;
 
         priv->try_start_timeout_source =
-            nm_g_source_attach(nm_g_timeout_source_new(4000,
-                                                       G_PRIORITY_DEFAULT,
-                                                       _ensure_resolved_running_timeout,
-                                                       self,
-                                                       NULL),
-                               NULL);
+            nm_g_timeout_add_source(4000, _ensure_resolved_running_timeout, self);
 
         nm_dbus_connection_call_start_service_by_name(priv->dbus_connection,
                                                       SYSTEMD_RESOLVED_DBUS_SERVICE,
@@ -468,15 +503,18 @@ send_updates(NMDnsSystemdResolved *self)
 
     priv->send_updates_waiting = FALSE;
 
-    _LOGT("send-updates: start %lu requests", c_list_length(&priv->request_queue_lst_head));
+    _LOGT("send-updates: start %zu requests", c_list_length(&priv->request_queue_lst_head));
 
     c_list_for_each_entry (request_item, &priv->request_queue_lst_head, request_queue_lst) {
         gs_free char *ss = NULL;
 
-        if (request_item->operation == DBUS_OP_SET_LINK_DEFAULT_ROUTE
-            && priv->has_link_default_route == NM_TERNARY_FALSE) {
+        if ((request_item->operation == DBUS_OP_SET_LINK_DEFAULT_ROUTE
+             && priv->has_link_default_route == NM_TERNARY_FALSE)
+            || (request_item->operation == DBUS_OP_SET_LINK_DNS_OVER_TLS
+                && priv->has_link_dns_over_tls == NM_TERNARY_FALSE)) {
             /* The "SetLinkDefaultRoute" API is only supported since v240.
-             * We detected that it is not supported, and skip the call. There
+             * The "SetLinkDNSOverTLS" API is only supported since v239.
+             * We detected whether they are supported, and skip the calls. There
              * is no special workaround, because in this case we rely on systemd-resolved
              * to do the right thing automatically. */
             continue;
@@ -601,13 +639,15 @@ name_owner_changed(NMDnsSystemdResolved *self, const char *owner)
 
     nm_clear_g_source_inst(&priv->try_start_timeout_source);
 
-    nm_utils_strdup_reset(&priv->dbus_owner, owner);
+    nm_strdup_reset(&priv->dbus_owner, owner);
 
     if (owner) {
         priv->try_start_blocked    = FALSE;
         priv->send_updates_waiting = TRUE;
-    } else
+    } else {
         priv->has_link_default_route = NM_TERNARY_DEFAULT;
+        priv->has_link_dns_over_tls  = NM_TERNARY_DEFAULT;
+    }
 
     send_updates(self);
 }
@@ -821,19 +861,13 @@ _resolve_start(NMDnsSystemdResolved *self, NMDnsSystemdResolvedResolveHandle *ha
         _LOG2T(handle, "systemd-resolved not running. Failing on idle...");
         nm_assert(!handle->timeout_source);
         handle->is_failing_on_idle = TRUE;
-        handle->timeout_source     = nm_g_source_attach(
-            nm_g_idle_source_new(G_PRIORITY_DEFAULT, _resolve_failing_on_idle, handle, NULL),
-            NULL);
+        handle->timeout_source     = nm_g_idle_add_source(_resolve_failing_on_idle, handle);
         return;
     }
 
     if (!handle->timeout_source) {
-        handle->timeout_source = nm_g_source_attach(nm_g_timeout_source_new(handle->timeout_msec,
-                                                                            G_PRIORITY_DEFAULT,
-                                                                            _resolve_handle_timeout,
-                                                                            handle,
-                                                                            NULL),
-                                                    NULL);
+        handle->timeout_source =
+            nm_g_timeout_add_source(handle->timeout_msec, _resolve_handle_timeout, handle);
     }
 
     if (is_running == NM_TERNARY_DEFAULT) {
@@ -929,6 +963,7 @@ nm_dns_systemd_resolved_init(NMDnsSystemdResolved *self)
     NMDnsSystemdResolvedPrivate *priv = NM_DNS_SYSTEMD_RESOLVED_GET_PRIVATE(self);
 
     priv->has_link_default_route = NM_TERNARY_DEFAULT;
+    priv->has_link_dns_over_tls  = NM_TERNARY_DEFAULT;
 
     c_list_init(&priv->request_queue_lst_head);
     c_list_init(&priv->handle_lst_head);