]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
resolve: do not dump cache entries when not necessary
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 6 Nov 2025 17:56:13 +0000 (02:56 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 10 Nov 2025 02:02:51 +0000 (11:02 +0900)
Follow-up for 306375c36804c5c85cd9b77b353f40edf116521d.

src/resolve/resolved-dns-scope.c
src/resolve/resolved-dns-scope.h
src/resolve/resolved-manager.c
src/resolve/resolved-varlink.c

index 6f8d0fdcfe213880e3cb7d283a36e4795f63c320..c6c6bdc86695002398a9d618ab6850aba9221d7d 100644 (file)
@@ -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))),
index 16c28eb9a304420f54f8e09d2dac2cc148fdb676..b492d7d4bd32c9a10a40a486387d37f59855d4b0 100644 (file)
@@ -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);
index 64c3a3a3e785aff0e765d5d63783c0c07ce213db..fe4807685a59f233a7e50d9de9588ba4e06037ad 100644 (file)
@@ -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;
 
index e4ea55b173465a525a5c70f320f36363b75557ec..a4723176a8833fbab5983e2e3fdc477e09a6913e 100644 (file)
@@ -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;