summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2020-11-26 13:35:13 +0100
committerThomas Haller <thaller@redhat.com>2020-11-27 10:26:11 +0100
commit8af6647cdaac067cbe37f84bc7d47351f343fa34 (patch)
tree2e838c7b663d6792e119a890cc7864ccfd6adadc
parentd80eee99913c4e68f9558f9ec53ff1e43b60f0c8 (diff)
downloadNetworkManager-8af6647cdaac067cbe37f84bc7d47351f343fa34.tar.gz
dns: cleanup RequestItem and track ifindex and self parameter
We will need these changes next: - add "self" and "ifindex" fields to RequestItem struct. We will pass on these structs are user-data for the callbacks, so that we afterwards know which request completed. - add DBUS_OP_SET_LINK_DEFAULT_ROUTE global variable. We don't clone the "operation" string but use string literals. However, string literals are not guaranteed to be deduplicated, so we should only compare them with strcmp(). The static variable avoids this: we can use pointer equality to compare it. This will be used next.
-rw-r--r--src/dns/nm-dns-systemd-resolved.c71
1 files changed, 43 insertions, 28 deletions
diff --git a/src/dns/nm-dns-systemd-resolved.c b/src/dns/nm-dns-systemd-resolved.c
index d1756a573b..b4aab861ef 100644
--- a/src/dns/nm-dns-systemd-resolved.c
+++ b/src/dns/nm-dns-systemd-resolved.c
@@ -34,6 +34,9 @@
#define SYSTEMD_RESOLVED_MANAGER_IFACE "org.freedesktop.resolve1.Manager"
#define SYSTEMD_RESOLVED_DBUS_PATH "/org/freedesktop/resolve1"
+/* define a variable, so that we can compare the operation with pointer equality. */
+static const char *const DBUS_OP_SET_LINK_DEFAULT_ROUTE = "SetLinkDefaultRoute";
+
/*****************************************************************************/
typedef struct {
@@ -42,9 +45,11 @@ typedef struct {
} InterfaceConfig;
typedef struct {
- CList request_queue_lst;
- const char *operation;
- GVariant * argument;
+ CList request_queue_lst;
+ const char * operation;
+ GVariant * argument;
+ NMDnsSystemdResolved *self;
+ int ifindex;
} RequestItem;
/*****************************************************************************/
@@ -88,18 +93,26 @@ _request_item_free(RequestItem *request_item)
{
c_list_unlink_stale(&request_item->request_queue_lst);
g_variant_unref(request_item->argument);
- g_slice_free(RequestItem, request_item);
+ nm_g_slice_free(request_item);
}
static void
-_request_item_append(CList *request_queue_lst_head, const char *operation, GVariant *argument)
+_request_item_append(NMDnsSystemdResolved *self,
+ const char * operation,
+ int ifindex,
+ GVariant * argument)
{
- RequestItem *request_item;
+ NMDnsSystemdResolvedPrivate *priv = NM_DNS_SYSTEMD_RESOLVED_GET_PRIVATE(self);
+ RequestItem * request_item;
- request_item = g_slice_new(RequestItem);
- request_item->operation = operation;
- request_item->argument = g_variant_ref_sink(argument);
- c_list_link_tail(request_queue_lst_head, &request_item->request_queue_lst);
+ request_item = g_slice_new(RequestItem);
+ *request_item = (RequestItem){
+ .operation = operation,
+ .argument = g_variant_ref_sink(argument),
+ .self = self,
+ .ifindex = ifindex,
+ };
+ c_list_link_tail(&priv->request_queue_lst_head, &request_item->request_queue_lst);
}
/*****************************************************************************/
@@ -116,13 +129,14 @@ call_done(GObject *source, GAsyncResult *r, gpointer user_data)
{
gs_unref_variant GVariant *v = NULL;
gs_free_error GError * error = NULL;
- NMDnsSystemdResolved * self = (NMDnsSystemdResolved *) user_data;
+ NMDnsSystemdResolved * self;
NMDnsSystemdResolvedPrivate *priv;
v = g_dbus_connection_call_finish(G_DBUS_CONNECTION(source), r, &error);
- if (!v && g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
+ if (nm_utils_error_is_cancelled(error))
return;
+ self = user_data;
priv = NM_DNS_SYSTEMD_RESOLVED_GET_PRIVATE(self);
if (!v) {
@@ -198,14 +212,14 @@ free_pending_updates(NMDnsSystemdResolved *self)
static gboolean
prepare_one_interface(NMDnsSystemdResolved *self, InterfaceConfig *ic)
{
- NMDnsSystemdResolvedPrivate *priv = NM_DNS_SYSTEMD_RESOLVED_GET_PRIVATE(self);
- GVariantBuilder dns, 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;
+ const char * mdns_arg = NULL, *llmnr_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);
@@ -268,19 +282,20 @@ prepare_one_interface(NMDnsSystemdResolved *self, InterfaceConfig *ic)
if (!nm_str_is_empty(mdns_arg) || !nm_str_is_empty(llmnr_arg))
has_config = TRUE;
- _request_item_append(&priv->request_queue_lst_head,
- "SetLinkDomains",
- g_variant_builder_end(&domains));
- _request_item_append(&priv->request_queue_lst_head,
- "SetLinkDefaultRoute",
+ _request_item_append(self, "SetLinkDomains", ic->ifindex, g_variant_builder_end(&domains));
+ _request_item_append(self,
+ DBUS_OP_SET_LINK_DEFAULT_ROUTE,
+ ic->ifindex,
g_variant_new("(ib)", ic->ifindex, has_default_route));
- _request_item_append(&priv->request_queue_lst_head,
+ _request_item_append(self,
"SetLinkMulticastDNS",
+ ic->ifindex,
g_variant_new("(is)", ic->ifindex, mdns_arg ?: ""));
- _request_item_append(&priv->request_queue_lst_head,
+ _request_item_append(self,
"SetLinkLLMNR",
+ ic->ifindex,
g_variant_new("(is)", ic->ifindex, llmnr_arg ?: ""));
- _request_item_append(&priv->request_queue_lst_head, "SetLinkDNS", g_variant_builder_end(&dns));
+ _request_item_append(self, "SetLinkDNS", ic->ifindex, g_variant_builder_end(&dns));
return has_config;
}