if (s->protocol != DNS_PROTOCOL_DNS)
return false;
- return dns_name_is_single_label(name);
+ if (!dns_name_is_single_label(name))
+ return false;
+
+ /* If we allow single-label domain lookups on unicast DNS, and this scope has a search domain that matches
+ * _exactly_ this name, then do not use search domains. */
+ if (s->manager->resolve_unicast_single_label)
+ LIST_FOREACH(domains, d, dns_scope_get_search_domains(s))
+ if (dns_name_equal(name, d->name) > 0)
+ return false;
+
+ return true;
}
bool dns_scope_network_good(DnsScope *s) {
if (scope->protocol != DNS_PROTOCOL_MDNS)
return 0;
+ r = sd_event_get_state(scope->manager->event);
+ if (r < 0)
+ return log_debug_errno(r, "Failed to get event loop state: %m");
+
+ /* If this is called on exit, through manager_free() -> link_free(), then we cannot announce. */
+ if (r == SD_EVENT_FINISHED)
+ return 0;
+
/* Check if we're done with probing. */
LIST_FOREACH(transactions_by_scope, t, scope->transactions)
- if (DNS_TRANSACTION_IS_LIVE(t->state))
+ if (t->probing && DNS_TRANSACTION_IS_LIVE(t->state))
return 0;
/* Check if there're services pending conflict resolution. */
assert(scope);
- if (hashmap_size(scope->manager->dnssd_services) == 0)
+ if (hashmap_isempty(scope->manager->dnssd_services))
return 0;
scope->announced = false;
* volunteer as default route. */
return !dns_scope_has_route_only_domains(scope);
}
+
+int dns_scope_dump_cache_to_json(DnsScope *scope, JsonVariant **ret) {
+ _cleanup_(json_variant_unrefp) JsonVariant *cache = NULL;
+ int r;
+
+ assert(scope);
+ assert(ret);
+
+ r = dns_cache_dump_to_json(&scope->cache, &cache);
+ if (r < 0)
+ return r;
+
+ return json_build(ret,
+ JSON_BUILD_OBJECT(
+ JSON_BUILD_PAIR_STRING("protocol", dns_protocol_to_string(scope->protocol)),
+ JSON_BUILD_PAIR_CONDITION(scope->family != AF_UNSPEC, "family", JSON_BUILD_INTEGER(scope->family)),
+ JSON_BUILD_PAIR_CONDITION(scope->link, "ifindex", JSON_BUILD_INTEGER(scope->link ? scope->link->ifindex : 0)),
+ JSON_BUILD_PAIR_CONDITION(scope->link, "ifname", JSON_BUILD_STRING(scope->link ? scope->link->ifname : NULL)),
+ JSON_BUILD_PAIR_VARIANT("cache", cache)));
+}