diff options
author | Thomas Haller <thaller@redhat.com> | 2020-11-25 17:27:04 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2020-11-26 14:43:58 +0100 |
commit | ef4f06e734e3c020da595e045e31a1f383028e5f (patch) | |
tree | f3753ed7cd6ed6451c4dfb1ccb215188ee4c6c0e | |
parent | c914024141f178f7480a38bfbf5bcd858b634d73 (diff) | |
download | NetworkManager-th/dns-resolved-default-route.tar.gz |
dns: detect support of systemd-resolved's SetLinkDefaultRoute() and avoid itth/dns-resolved-default-route
We now always use SetLinkDefaultRoute(), but that API was only added in
systemd v240 ([1]).
We could just always call the non-existing method, and ignore the
error. However, that feels ugly. Would systemd-resolved log warnings
about that? Should we suppress all messages about that failure (not
good for debugging).
Instead, make an effort to detect support of the function, and avoid
calling it. That is significantly more complicated than just always
calling the method and not care.
Note that even if systemd-resolved does not support SetLinkDefaultRoute(),
we cannot do anything smart about that. We would simply rely on
systemd-resolved (hopefully) doing the right thing automatically.
That's better and simpler than explicitly adding a "~." domain in
the fallback case.
Also, detecting support is straight forward in the common case, where
there is either success or a clear "org.freedesktop.DBus.Error.UnknownMethod"
error. In cases where there is any other failure, we don't really know.
In that case, we keep trying to use the API under the assumption that
it should work.
[1] https://github.com/systemd/systemd/commit/7 ## 7673795dcf5797491e7f785cbf5077d29a15db4
-rw-r--r-- | src/dns/nm-dns-systemd-resolved.c | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/src/dns/nm-dns-systemd-resolved.c b/src/dns/nm-dns-systemd-resolved.c index 3ae50ba719..e99e13b665 100644 --- a/src/dns/nm-dns-systemd-resolved.c +++ b/src/dns/nm-dns-systemd-resolved.c @@ -65,6 +65,7 @@ typedef struct { bool dbus_has_owner : 1; bool dbus_initied : 1; bool request_queue_to_send : 1; + NMTernary has_link_default_route : 3; } NMDnsSystemdResolvedPrivate; struct _NMDnsSystemdResolved { @@ -143,17 +144,29 @@ call_done(GObject *source, GAsyncResult *r, gpointer user_data) priv = NM_DNS_SYSTEMD_RESOLVED_GET_PRIVATE(self); if (v) { + if (request_item->operation == DBUS_OP_SET_LINK_DEFAULT_ROUTE + && priv->has_link_default_route == NM_TERNARY_DEFAULT) { + priv->has_link_default_route = NM_TERNARY_TRUE; + _LOGD("systemd-resolved support for SetLinkDefaultRoute(): API supported"); + } priv->send_updates_warn_ratelimited = FALSE; return; } - log_level = LOGL_DEBUG; + 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) { + priv->has_link_default_route = NM_TERNARY_FALSE; + _LOGD("systemd-resolved support for SetLinkDefaultRoute(): API not supported"); + } + return; + } + log_level = LOGL_DEBUG; if (!priv->send_updates_warn_ratelimited) { priv->send_updates_warn_ratelimited = TRUE; log_level = LOGL_WARN; } - _NMLOG(log_level, "send-updates %s@%d failed: %s", request_item->operation, @@ -363,6 +376,15 @@ send_updates(NMDnsSystemdResolved *self) priv->request_queue_to_send = FALSE; c_list_for_each_entry (request_item, &priv->request_queue_lst_head, request_queue_lst) { + if (request_item->operation == DBUS_OP_SET_LINK_DEFAULT_ROUTE + && priv->has_link_default_route == NM_TERNARY_FALSE) { + /* The "SetLinkDefaultRoute" API is only supported since v240. + * We detected that it is not supported, and skip the call. There + * is no special workaround, because in this case we rely on systemd-resolved + * to do the right thing automatically. */ + continue; + } + /* 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 @@ -477,7 +499,8 @@ name_owner_changed(NMDnsSystemdResolved *self, const char *owner) if (owner) { priv->try_start_blocked = FALSE; priv->request_queue_to_send = TRUE; - } + } else + priv->has_link_default_route = NM_TERNARY_DEFAULT; send_updates(self); } @@ -550,6 +573,8 @@ nm_dns_systemd_resolved_init(NMDnsSystemdResolved *self) { NMDnsSystemdResolvedPrivate *priv = NM_DNS_SYSTEMD_RESOLVED_GET_PRIVATE(self); + priv->has_link_default_route = NM_TERNARY_DEFAULT; + c_list_init(&priv->request_queue_lst_head); priv->dirty_interfaces = g_hash_table_new(nm_direct_hash, NULL); |