From: Yu Watanabe Date: Thu, 6 Nov 2025 17:56:13 +0000 (+0900) Subject: resolve: do not dump cache entries when not necessary X-Git-Tag: v259-rc1~105^2~3 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=6f841e58b1b14029ad79e754b3abfd5afbbf0511;p=thirdparty%2Fsystemd.git resolve: do not dump cache entries when not necessary Follow-up for 306375c36804c5c85cd9b77b353f40edf116521d. --- diff --git a/src/resolve/resolved-dns-scope.c b/src/resolve/resolved-dns-scope.c index 6f8d0fdcfe2..c6c6bdc8669 100644 --- a/src/resolve/resolved-dns-scope.c +++ b/src/resolve/resolved-dns-scope.c @@ -1793,16 +1793,18 @@ bool dns_scope_is_default_route(DnsScope *scope) { return true; } -int dns_scope_dump_cache_to_json(DnsScope *scope, sd_json_variant **ret) { +int dns_scope_to_json(DnsScope *scope, bool with_cache, sd_json_variant **ret) { _cleanup_(sd_json_variant_unrefp) sd_json_variant *cache = NULL; int r; assert(scope); assert(ret); - r = dns_cache_dump_to_json(&scope->cache, &cache); - if (r < 0) - return r; + if (with_cache) { + r = dns_cache_dump_to_json(&scope->cache, &cache); + if (r < 0) + return r; + } return sd_json_buildo( ret, @@ -1810,7 +1812,7 @@ int dns_scope_dump_cache_to_json(DnsScope *scope, sd_json_variant **ret) { SD_JSON_BUILD_PAIR_CONDITION(scope->family != AF_UNSPEC, "family", SD_JSON_BUILD_INTEGER(scope->family)), SD_JSON_BUILD_PAIR_CONDITION(!!scope->link, "ifindex", SD_JSON_BUILD_INTEGER(dns_scope_ifindex(scope))), SD_JSON_BUILD_PAIR_CONDITION(!!scope->link, "ifname", SD_JSON_BUILD_STRING(dns_scope_ifname(scope))), - SD_JSON_BUILD_PAIR_VARIANT("cache", cache), + SD_JSON_BUILD_PAIR_CONDITION(with_cache, "cache", SD_JSON_BUILD_VARIANT(cache)), SD_JSON_BUILD_PAIR_CONDITION(scope->protocol == DNS_PROTOCOL_DNS, "dnssec", SD_JSON_BUILD_STRING(dnssec_mode_to_string(scope->dnssec_mode))), diff --git a/src/resolve/resolved-dns-scope.h b/src/resolve/resolved-dns-scope.h index 16c28eb9a30..b492d7d4bd3 100644 --- a/src/resolve/resolved-dns-scope.h +++ b/src/resolve/resolved-dns-scope.h @@ -120,7 +120,7 @@ int dns_scope_remove_dnssd_registered_services(DnsScope *scope); bool dns_scope_is_default_route(DnsScope *scope); -int dns_scope_dump_cache_to_json(DnsScope *scope, sd_json_variant **ret); +int dns_scope_to_json(DnsScope *scope, bool with_cache, sd_json_variant **ret); int dns_type_suitable_for_protocol(uint16_t type, DnsProtocol protocol); int dns_question_types_suitable_for_protocol(DnsQuestion *q, DnsProtocol protocol); diff --git a/src/resolve/resolved-manager.c b/src/resolve/resolved-manager.c index 64c3a3a3e78..fe4807685a5 100644 --- a/src/resolve/resolved-manager.c +++ b/src/resolve/resolved-manager.c @@ -2071,12 +2071,7 @@ static int dns_configuration_json_append( SET_FOREACH(scope, dns_scopes) { _cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL; - r = dns_scope_dump_cache_to_json(scope, &v); - if (r < 0) - return r; - - /* The cache is not relevant to the configuration of the scope. */ - r = sd_json_variant_filter(&v, STRV_MAKE("cache")); + r = dns_scope_to_json(scope, /* with_cache= */ false, &v); if (r < 0) return r; diff --git a/src/resolve/resolved-varlink.c b/src/resolve/resolved-varlink.c index e4ea55b1734..a4723176a88 100644 --- a/src/resolve/resolved-varlink.c +++ b/src/resolve/resolved-varlink.c @@ -1270,7 +1270,7 @@ static int vl_method_dump_cache(sd_varlink *link, sd_json_variant *parameters, s LIST_FOREACH(scopes, s, m->dns_scopes) { _cleanup_(sd_json_variant_unrefp) sd_json_variant *j = NULL; - r = dns_scope_dump_cache_to_json(s, &j); + r = dns_scope_to_json(s, /* with_cache= */ true, &j); if (r < 0) return r;