summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2020-11-26 13:49:35 +0100
committerThomas Haller <thaller@redhat.com>2020-11-27 10:46:42 +0100
commit4fc44952f7fd44771a1c006529cea6db937290ec (patch)
tree5061d7c9c3d5392ff1ae6a06aeaa469ef82f9cd3
parent42d47d1cd762b6d2b6d8b92b66647bd9308ad09e (diff)
downloadNetworkManager-4fc44952f7fd44771a1c006529cea6db937290ec.tar.gz
dns: preserve DNS settings for systemd-resolved to resend
When the DNS settings change, we update the request_queue_lst_head list, with all the requests we want to send. Then, send_updates() will try to send it. It might not do it right away, if resolved is not on the bus or the D-Bus connection is not fully inialized (meaning, we don't know the name owner yet). In those cases, we would keep the list of requests, and send them later. However, when sending them, we would also forget about the configuration. That means, if you restart systemd-resolved, then the daemon drops off the bus and reappears. I think that systemd-resolved in fact persists the configuration during restart. So, usually the settings are still the same after restart. However, we should do better here: if the service appears, we should send the settings again. This means to not forget the requests after we send them once -- at least, until a new update replaces them.
-rw-r--r--src/dns/nm-dns-systemd-resolved.c35
1 files changed, 20 insertions, 15 deletions
diff --git a/src/dns/nm-dns-systemd-resolved.c b/src/dns/nm-dns-systemd-resolved.c
index 8651c8c212..a26db6eba3 100644
--- a/src/dns/nm-dns-systemd-resolved.c
+++ b/src/dns/nm-dns-systemd-resolved.c
@@ -64,6 +64,7 @@ typedef struct {
bool try_start_blocked : 1;
bool dbus_has_owner : 1;
bool dbus_initied : 1;
+ bool request_queue_to_send : 1;
} NMDnsSystemdResolvedPrivate;
struct _NMDnsSystemdResolved {
@@ -136,7 +137,7 @@ call_done(GObject *source, GAsyncResult *r, gpointer user_data)
v = g_dbus_connection_call_finish(G_DBUS_CONNECTION(source), r, &error);
if (nm_utils_error_is_cancelled(error))
- goto out;
+ return;
request_item = user_data;
self = request_item->self;
@@ -144,7 +145,7 @@ call_done(GObject *source, GAsyncResult *r, gpointer user_data)
if (v) {
priv->send_updates_warn_ratelimited = FALSE;
- goto out;
+ return;
}
log_level = LOGL_DEBUG;
@@ -159,9 +160,6 @@ call_done(GObject *source, GAsyncResult *r, gpointer user_data)
request_item->operation,
request_item->ifindex,
error->message);
-
-out:
- _request_item_free(request_item);
}
static gboolean
@@ -321,7 +319,7 @@ send_updates(NMDnsSystemdResolved *self)
NMDnsSystemdResolvedPrivate *priv = NM_DNS_SYSTEMD_RESOLVED_GET_PRIVATE(self);
RequestItem * request_item;
- if (c_list_is_empty(&priv->request_queue_lst_head)) {
+ if (!priv->request_queue_to_send) {
/* nothing to do. */
return;
}
@@ -351,15 +349,21 @@ send_updates(NMDnsSystemdResolved *self)
return;
}
- _LOGT("send-updates: start %lu requests", c_list_length(&priv->request_queue_lst_head));
-
nm_clear_g_cancellable(&priv->cancellable);
+ if (c_list_is_empty(&priv->request_queue_lst_head)) {
+ _LOGT("send-updates: no requests to send");
+ priv->request_queue_to_send = FALSE;
+ return;
+ }
+
+ _LOGT("send-updates: start %lu requests", c_list_length(&priv->request_queue_lst_head));
+
priv->cancellable = g_cancellable_new();
- while (
- (request_item =
- c_list_first_entry(&priv->request_queue_lst_head, RequestItem, request_queue_lst))) {
+ priv->request_queue_to_send = FALSE;
+
+ c_list_for_each_entry (request_item, &priv->request_queue_lst_head, request_queue_lst) {
/* Above we explicitly call "StartServiceByName" trying to avoid D-Bus activating systmd-resolved
* multiple times. There is still a race, were we might hit this line although actually
* the service just quit this very moment. In that case, we would try to D-Bus activate the
@@ -380,7 +384,6 @@ send_updates(NMDnsSystemdResolved *self)
priv->cancellable,
call_done,
request_item);
- c_list_unlink(&request_item->request_queue_lst);
}
}
@@ -452,8 +455,8 @@ update(NMDnsPlugin * plugin,
}
}
+ priv->request_queue_to_send = TRUE;
send_updates(self);
-
return TRUE;
}
@@ -472,8 +475,10 @@ name_owner_changed(NMDnsSystemdResolved *self, const char *owner)
_LOGT("D-Bus name for systemd-resolved has owner %s", owner);
priv->dbus_has_owner = !!owner;
- if (owner)
- priv->try_start_blocked = FALSE;
+ if (owner) {
+ priv->try_start_blocked = FALSE;
+ priv->request_queue_to_send = TRUE;
+ }
send_updates(self);
}