about summary refs log tree commit diff
path: root/src/core/dns/nm-dns-systemd-resolved.c
diff options
context:
space:
mode:
authorMichael Biebl <biebl@debian.org>2022-02-14 19:23:28 +0100
committerMichael Biebl <biebl@debian.org>2022-02-14 19:23:28 +0100
commit2f94dba7385fd0e0ef19a06eb4a2fcf6c43d7946 (patch)
treee2222f5577115985dd52044d2991253403cdd952 /src/core/dns/nm-dns-systemd-resolved.c
parent88c227d90a6b7b388c5c85d72802a0ca8f05ed5c (diff)
New upstream version 1.35.91 upstream/1.35.91
Diffstat (limited to 'src/core/dns/nm-dns-systemd-resolved.c')
-rw-r--r--src/core/dns/nm-dns-systemd-resolved.c193
1 files changed, 96 insertions, 97 deletions
diff --git a/src/core/dns/nm-dns-systemd-resolved.c b/src/core/dns/nm-dns-systemd-resolved.c
index 445f8498..a043e855 100644
--- a/src/core/dns/nm-dns-systemd-resolved.c
+++ b/src/core/dns/nm-dns-systemd-resolved.c
@@ -21,10 +21,9 @@
 #include "libnm-core-intern/nm-core-internal.h"
 #include "libnm-platform/nm-platform.h"
 #include "nm-utils.h"
-#include "nm-ip4-config.h"
-#include "nm-ip6-config.h"
 #include "nm-dbus-manager.h"
 #include "nm-manager.h"
+#include "nm-l3-config-data.h"
 #include "nm-setting-connection.h"
 #include "devices/nm-device.h"
 #include "NetworkManagerUtils.h"
@@ -47,8 +46,8 @@ typedef struct {
 
 typedef struct {
     CList                 request_queue_lst;
-    const char *          operation;
-    GVariant *            argument;
+    const char           *operation;
+    GVariant             *argument;
     NMDnsSystemdResolved *self;
     int                   ifindex;
 } RequestItem;
@@ -56,8 +55,8 @@ typedef struct {
 struct _NMDnsSystemdResolvedResolveHandle {
     CList                 handle_lst;
     NMDnsSystemdResolved *self;
-    GSource *             timeout_source;
-    GCancellable *        handle_cancellable;
+    GSource              *timeout_source;
+    GCancellable         *handle_cancellable;
     gpointer              callback_user_data;
     guint                 timeout_msec;
     bool                  is_failing_on_idle;
@@ -76,11 +75,11 @@ struct _NMDnsSystemdResolvedResolveHandle {
 
 typedef struct {
     GDBusConnection *dbus_connection;
-    GHashTable *     dirty_interfaces;
-    GCancellable *   cancellable;
-    GSource *        try_start_timeout_source;
+    GHashTable      *dirty_interfaces;
+    GCancellable    *cancellable;
+    GSource         *try_start_timeout_source;
     CList            request_queue_lst_head;
-    char *           dbus_owner;
+    char            *dbus_owner;
     CList            handle_lst_head;
     guint            name_owner_changed_id;
     bool             send_updates_warn_ratelimited : 1;
@@ -157,12 +156,12 @@ _request_item_free(RequestItem *request_item)
 
 static void
 _request_item_append(NMDnsSystemdResolved *self,
-                     const char *          operation,
+                     const char           *operation,
                      int                   ifindex,
-                     GVariant *            argument)
+                     GVariant             *argument)
 {
     NMDnsSystemdResolvedPrivate *priv = NM_DNS_SYSTEMD_RESOLVED_GET_PRIVATE(self);
-    RequestItem *                request_item;
+    RequestItem                 *request_item;
 
     request_item  = g_slice_new(RequestItem);
     *request_item = (RequestItem){
@@ -186,11 +185,11 @@ _interface_config_free(InterfaceConfig *config)
 static void
 call_done(GObject *source, GAsyncResult *r, gpointer user_data)
 {
-    gs_unref_variant GVariant *v       = NULL;
-    gs_free_error GError *       error = NULL;
-    NMDnsSystemdResolved *       self;
+    gs_unref_variant GVariant   *v     = NULL;
+    gs_free_error GError        *error = NULL;
+    NMDnsSystemdResolved        *self;
     NMDnsSystemdResolvedPrivate *priv;
-    RequestItem *                request_item;
+    RequestItem                 *request_item;
     NMLogLevel                   log_level;
 
     v = g_dbus_connection_call_finish(G_DBUS_CONNECTION(source), r, &error);
@@ -244,42 +243,44 @@ call_done(GObject *source, GAsyncResult *r, gpointer user_data)
 
 static gboolean
 update_add_ip_config(NMDnsSystemdResolved *self,
-                     GVariantBuilder *     dns,
-                     GVariantBuilder *     domains,
-                     NMDnsConfigIPData *   data)
+                     GVariantBuilder      *dns,
+                     GVariantBuilder      *domains,
+                     NMDnsConfigIPData    *ip_data)
 {
-    int         addr_family;
-    gsize       addr_size;
-    guint       i, n;
-    gboolean    is_routing;
-    const char *domain;
-    gboolean    has_config = FALSE;
-
-    addr_family = nm_ip_config_get_addr_family(data->ip_config);
-    addr_size   = nm_utils_addr_family_to_size(addr_family);
-
-    if ((!data->domains.search || !data->domains.search[0])
-        && !data->domains.has_default_route_exclusive && !data->domains.has_default_route)
+    gsize         addr_size;
+    guint         n;
+    guint         i;
+    gboolean      is_routing;
+    const char   *domain;
+    gboolean      has_config = FALSE;
+    gconstpointer nameservers;
+
+    addr_size = nm_utils_addr_family_to_size(ip_data->addr_family);
+
+    if ((!ip_data->domains.search || !ip_data->domains.search[0])
+        && !ip_data->domains.has_default_route_exclusive && !ip_data->domains.has_default_route)
         return FALSE;
 
-    n = nm_ip_config_get_num_nameservers(data->ip_config);
+    nameservers = nm_l3_config_data_get_nameservers(ip_data->l3cd, ip_data->addr_family, &n);
     for (i = 0; i < n; i++) {
         g_variant_builder_open(dns, G_VARIANT_TYPE("(iay)"));
-        g_variant_builder_add(dns, "i", addr_family);
+        g_variant_builder_add(dns, "i", ip_data->addr_family);
         g_variant_builder_add_value(
             dns,
-            nm_g_variant_new_ay(nm_ip_config_get_nameserver(data->ip_config, i), addr_size));
+            nm_g_variant_new_ay(nm_ip_addr_from_packed_array(ip_data->addr_family, nameservers, i),
+                                addr_size));
         g_variant_builder_close(dns);
         has_config = TRUE;
     }
 
-    if (!data->domains.has_default_route_explicit && data->domains.has_default_route_exclusive) {
+    if (!ip_data->domains.has_default_route_explicit
+        && ip_data->domains.has_default_route_exclusive) {
         g_variant_builder_add(domains, "(sb)", ".", TRUE);
         has_config = TRUE;
     }
-    if (data->domains.search) {
-        for (i = 0; data->domains.search[i]; i++) {
-            domain = nm_utils_parse_dns_domain(data->domains.search[i], &is_routing);
+    if (ip_data->domains.search) {
+        for (i = 0; ip_data->domains.search[i]; i++) {
+            domain = nm_utils_parse_dns_domain(ip_data->domains.search[i], &is_routing);
             g_variant_builder_add(domains, "(sb)", domain[0] ? domain : ".", is_routing);
             has_config = TRUE;
         }
@@ -292,7 +293,7 @@ static void
 free_pending_updates(NMDnsSystemdResolved *self)
 {
     NMDnsSystemdResolvedPrivate *priv = NM_DNS_SYSTEMD_RESOLVED_GET_PRIVATE(self);
-    RequestItem *                request_item;
+    RequestItem                 *request_item;
 
     while ((request_item =
                 c_list_first_entry(&priv->request_queue_lst_head, RequestItem, request_queue_lst)))
@@ -304,11 +305,11 @@ prepare_one_interface(NMDnsSystemdResolved *self, InterfaceConfig *ic)
 {
     GVariantBuilder               dns;
     GVariantBuilder               domains;
-    NMCListElem *                 elem;
+    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;
+    const char                   *mdns_arg = NULL, *llmnr_arg = NULL, *dns_over_tls_arg = NULL;
     gboolean                      has_config        = FALSE;
     gboolean                      has_default_route = FALSE;
 
@@ -321,19 +322,17 @@ prepare_one_interface(NMDnsSystemdResolved *self, InterfaceConfig *ic)
     g_variant_builder_open(&domains, G_VARIANT_TYPE("a(sb)"));
 
     c_list_for_each_entry (elem, &ic->configs_lst_head, lst) {
-        NMDnsConfigIPData *data      = elem->data;
-        NMIPConfig *       ip_config = data->ip_config;
+        NMDnsConfigIPData *ip_data = elem->data;
 
-        has_config |= update_add_ip_config(self, &dns, &domains, data);
+        has_config |= update_add_ip_config(self, &dns, &domains, ip_data);
 
-        if (data->domains.has_default_route)
+        if (ip_data->domains.has_default_route)
             has_default_route = TRUE;
 
-        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)));
+        if (NM_IS_IPv4(ip_data->addr_family)) {
+            mdns         = NM_MAX(mdns, nm_l3_config_data_get_mdns(ip_data->l3cd));
+            llmnr        = NM_MAX(llmnr, nm_l3_config_data_get_llmnr(ip_data->l3cd));
+            dns_over_tls = NM_MAX(dns_over_tls, nm_l3_config_data_get_dns_over_tls(ip_data->l3cd));
         }
     }
 
@@ -417,8 +416,8 @@ prepare_one_interface(NMDnsSystemdResolved *self, InterfaceConfig *ic)
 static gboolean
 _ensure_resolved_running_timeout(gpointer user_data)
 {
-    NMDnsSystemdResolved *             self = user_data;
-    NMDnsSystemdResolvedPrivate *      priv = NM_DNS_SYSTEMD_RESOLVED_GET_PRIVATE(self);
+    NMDnsSystemdResolved              *self = user_data;
+    NMDnsSystemdResolvedPrivate       *priv = NM_DNS_SYSTEMD_RESOLVED_GET_PRIVATE(self);
     NMDnsSystemdResolvedResolveHandle *handle;
 
     nm_clear_g_source_inst(&priv->try_start_timeout_source);
@@ -479,8 +478,8 @@ ensure_resolved_running(NMDnsSystemdResolved *self)
 static void
 send_updates(NMDnsSystemdResolved *self)
 {
-    NMDnsSystemdResolvedPrivate *      priv = NM_DNS_SYSTEMD_RESOLVED_GET_PRIVATE(self);
-    RequestItem *                      request_item;
+    NMDnsSystemdResolvedPrivate       *priv = NM_DNS_SYSTEMD_RESOLVED_GET_PRIVATE(self);
+    RequestItem                       *request_item;
     NMDnsSystemdResolvedResolveHandle *handle;
 
     if (!priv->send_updates_waiting) {
@@ -549,31 +548,31 @@ start_resolve:
 }
 
 static gboolean
-update(NMDnsPlugin *            plugin,
+update(NMDnsPlugin             *plugin,
        const NMGlobalDnsConfig *global_config,
-       const CList *            ip_config_lst_head,
-       const char *             hostname,
-       GError **                error)
+       const CList             *ip_data_lst_head,
+       const char              *hostname,
+       GError                 **error)
 {
-    NMDnsSystemdResolved *       self         = NM_DNS_SYSTEMD_RESOLVED(plugin);
-    NMDnsSystemdResolvedPrivate *priv         = NM_DNS_SYSTEMD_RESOLVED_GET_PRIVATE(self);
-    gs_unref_hashtable GHashTable *interfaces = NULL;
-    gs_free gpointer * interfaces_keys        = NULL;
-    guint              interfaces_len;
-    int                ifindex;
-    gpointer           pointer;
-    NMDnsConfigIPData *ip_data;
-    GHashTableIter     iter;
-    guint              i;
+    NMDnsSystemdResolved          *self            = NM_DNS_SYSTEMD_RESOLVED(plugin);
+    NMDnsSystemdResolvedPrivate   *priv            = NM_DNS_SYSTEMD_RESOLVED_GET_PRIVATE(self);
+    gs_unref_hashtable GHashTable *interfaces      = NULL;
+    gs_free gpointer              *interfaces_keys = NULL;
+    guint                          interfaces_len;
+    int                            ifindex;
+    gpointer                       pointer;
+    NMDnsConfigIPData             *ip_data;
+    GHashTableIter                 iter;
+    guint                          i;
 
     interfaces =
         g_hash_table_new_full(nm_direct_hash, NULL, NULL, (GDestroyNotify) _interface_config_free);
 
-    c_list_for_each_entry (ip_data, ip_config_lst_head, ip_config_lst) {
+    c_list_for_each_entry (ip_data, ip_data_lst_head, ip_data_lst) {
         InterfaceConfig *ic = NULL;
 
         ifindex = ip_data->data->ifindex;
-        nm_assert(ifindex == nm_ip_config_get_ifindex(ip_data->ip_config));
+        nm_assert(ifindex == nm_l3_config_data_get_ifindex(ip_data->l3cd));
 
         ic = g_hash_table_lookup(interfaces, GINT_TO_POINTER(ifindex));
         if (!ic) {
@@ -654,16 +653,16 @@ name_owner_changed(NMDnsSystemdResolved *self, const char *owner)
 
 static void
 name_owner_changed_cb(GDBusConnection *connection,
-                      const char *     sender_name,
-                      const char *     object_path,
-                      const char *     interface_name,
-                      const char *     signal_name,
-                      GVariant *       parameters,
+                      const char      *sender_name,
+                      const char      *object_path,
+                      const char      *interface_name,
+                      const char      *signal_name,
+                      GVariant        *parameters,
                       gpointer         user_data)
 {
-    NMDnsSystemdResolved *       self = user_data;
+    NMDnsSystemdResolved        *self = user_data;
     NMDnsSystemdResolvedPrivate *priv = NM_DNS_SYSTEMD_RESOLVED_GET_PRIVATE(self);
-    const char *                 new_owner;
+    const char                  *new_owner;
 
     if (!g_variant_is_of_type(parameters, G_VARIANT_TYPE("(sss)")))
         return;
@@ -684,7 +683,7 @@ name_owner_changed_cb(GDBusConnection *connection,
 static void
 get_name_owner_cb(const char *name_owner, GError *error, gpointer user_data)
 {
-    NMDnsSystemdResolved *       self;
+    NMDnsSystemdResolved        *self;
     NMDnsSystemdResolvedPrivate *priv;
 
     if (!name_owner && g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
@@ -718,13 +717,13 @@ nm_dns_systemd_resolved_is_running(NMDnsSystemdResolved *self)
 /*****************************************************************************/
 
 static void
-_resolve_complete(NMDnsSystemdResolvedResolveHandle *      handle,
+_resolve_complete(NMDnsSystemdResolvedResolveHandle       *handle,
                   const NMDnsSystemdResolvedAddressResult *names,
                   guint                                    names_len,
                   guint64                                  flags,
-                  GError *                                 error)
+                  GError                                  *error)
 {
-    NMDnsSystemdResolved *       self;
+    NMDnsSystemdResolved        *self;
     NMDnsSystemdResolvedPrivate *priv;
 
     g_return_if_fail(handle && NM_IS_DNS_SYSTEMD_RESOLVED(handle->self));
@@ -760,16 +759,16 @@ _resolve_complete_error(NMDnsSystemdResolvedResolveHandle *handle, GError *error
 static void
 _resolve_handle_call_cb(GObject *source, GAsyncResult *result, gpointer user_data)
 {
-    gs_unref_variant GVariant *v             = NULL;
-    gs_free_error GError *             error = NULL;
+    gs_unref_variant GVariant         *v     = NULL;
+    gs_free_error GError              *error = NULL;
     NMDnsSystemdResolvedResolveHandle *handle;
-    NMDnsSystemdResolved *             self;
-    GVariantIter *                     v_names_iter;
+    NMDnsSystemdResolved              *self;
+    GVariantIter                      *v_names_iter;
     guint64                            v_flags;
     int                                v_ifindex;
-    char *                             v_name;
-    gs_unref_array GArray *v_names = NULL;
-    gs_free char *         ss      = NULL;
+    char                              *v_name;
+    gs_unref_array GArray             *v_names = NULL;
+    gs_free char                      *ss      = NULL;
 
     v = g_dbus_connection_call_finish(G_DBUS_CONNECTION(source), result, &error);
     if (nm_utils_error_is_cancelled(error))
@@ -824,7 +823,7 @@ static gboolean
 _resolve_failing_on_idle(gpointer user_data)
 {
     NMDnsSystemdResolvedResolveHandle *handle = user_data;
-    gs_free_error GError *error               = NULL;
+    gs_free_error GError              *error  = NULL;
 
     nm_utils_error_set_literal(&error,
                                NM_UTILS_ERROR_NOT_READY,
@@ -837,7 +836,7 @@ static gboolean
 _resolve_handle_timeout(gpointer user_data)
 {
     NMDnsSystemdResolvedResolveHandle *handle = user_data;
-    gs_free_error GError *error               = NULL;
+    gs_free_error GError              *error  = NULL;
 
     nm_utils_error_set_literal(&error, NM_UTILS_ERROR_UNKNOWN, "timeout for request");
     _resolve_complete_error(handle, error);
@@ -901,16 +900,16 @@ _resolve_start(NMDnsSystemdResolved *self, NMDnsSystemdResolvedResolveHandle *ha
 }
 
 NMDnsSystemdResolvedResolveHandle *
-nm_dns_systemd_resolved_resolve_address(NMDnsSystemdResolved *                     self,
+nm_dns_systemd_resolved_resolve_address(NMDnsSystemdResolved                      *self,
                                         int                                        ifindex,
                                         int                                        addr_family,
-                                        const NMIPAddr *                           addr,
+                                        const NMIPAddr                            *addr,
                                         guint64                                    flags,
                                         guint                                      timeout_msec,
                                         NMDnsSystemdResolvedResolveAddressCallback callback,
                                         gpointer                                   user_data)
 {
-    NMDnsSystemdResolvedPrivate *      priv = NM_DNS_SYSTEMD_RESOLVED_GET_PRIVATE(self);
+    NMDnsSystemdResolvedPrivate       *priv = NM_DNS_SYSTEMD_RESOLVED_GET_PRIVATE(self);
     NMDnsSystemdResolvedResolveHandle *handle;
     char                               addr_str[NM_UTILS_INET_ADDRSTRLEN];
 
@@ -999,8 +998,8 @@ nm_dns_systemd_resolved_new(void)
 static void
 dispose(GObject *object)
 {
-    NMDnsSystemdResolved *             self = NM_DNS_SYSTEMD_RESOLVED(object);
-    NMDnsSystemdResolvedPrivate *      priv = NM_DNS_SYSTEMD_RESOLVED_GET_PRIVATE(self);
+    NMDnsSystemdResolved              *self = NM_DNS_SYSTEMD_RESOLVED(object);
+    NMDnsSystemdResolvedPrivate       *priv = NM_DNS_SYSTEMD_RESOLVED_GET_PRIVATE(self);
     NMDnsSystemdResolvedResolveHandle *handle;
 
     while ((handle = c_list_first_entry(&priv->handle_lst_head,
@@ -1032,7 +1031,7 @@ static void
 nm_dns_systemd_resolved_class_init(NMDnsSystemdResolvedClass *dns_class)
 {
     NMDnsPluginClass *plugin_class = NM_DNS_PLUGIN_CLASS(dns_class);
-    GObjectClass *    object_class = G_OBJECT_CLASS(dns_class);
+    GObjectClass     *object_class = G_OBJECT_CLASS(dns_class);
 
     object_class->dispose = dispose;