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,
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))),
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);
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;
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;