diff options
| author | Michael Biebl <biebl@debian.org> | 2022-01-13 22:30:39 +0100 |
|---|---|---|
| committer | Michael Biebl <biebl@debian.org> | 2022-01-13 22:30:39 +0100 |
| commit | 88c227d90a6b7b388c5c85d72802a0ca8f05ed5c (patch) | |
| tree | 71f32df6617802270e8a78574bd8e1637dc532f4 /src/core/dns/nm-dns-systemd-resolved.c | |
| parent | e74c568b07b50b97873fb4ee1d776dedefbd54d6 (diff) | |
New upstream version 1.34.0 upstream/1.34.0
Diffstat (limited to 'src/core/dns/nm-dns-systemd-resolved.c')
| -rw-r--r-- | src/core/dns/nm-dns-systemd-resolved.c | 103 |
1 files changed, 69 insertions, 34 deletions
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); |