}
}
-static int append_address(sd_bus_message *reply, DnsResourceRecord *rr, int ifindex) {
+static int append_address(sd_bus_message *reply, DnsResourceRecord *rr, int ifindex, bool is_container) {
int r;
assert(reply);
assert(rr);
- r = sd_bus_message_open_container(reply, 'r', "iiay");
- if (r < 0)
- return r;
+ if (is_container) {
+ r = sd_bus_message_open_container(reply, 'r', "iiay");
+ if (r < 0)
+ return r;
+ }
r = sd_bus_message_append(reply, "i", ifindex);
if (r < 0)
if (r < 0)
return r;
- r = sd_bus_message_close_container(reply);
- if (r < 0)
- return r;
+ if (is_container) {
+ r = sd_bus_message_close_container(reply);
+ if (r < 0)
+ return r;
+ }
return 0;
}
if (r == 0)
continue;
- r = append_address(reply, rr, ifindex);
+ r = append_address(reply, rr, ifindex, true);
if (r < 0)
goto finish;
if (r == 0)
continue;
- r = append_address(reply, zz, ifindex);
+ r = append_address(reply, zz, ifindex, true);
if (r < 0)
return r;
}
return call_dnssd_method(m, message, bus_dnssd_method_unregister, error);
}
+static int bus_method_get_multicast_hosts(sd_bus_message *message, void *userdata, sd_bus_error *error) {
+ _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
+ DnsScope *s;
+ Manager *m = userdata;
+ int r;
+
+ assert(message);
+ assert(m);
+
+ r = sd_bus_message_new_method_return(message, &reply);
+ if (r < 0)
+ return r;
+
+ r = sd_bus_message_open_container(reply, 'a', "(stiiay)");
+ if (r < 0)
+ return r;
+
+ LIST_FOREACH(scopes, s, m->dns_scopes) {
+ _cleanup_(dns_answer_unrefp) DnsAnswer *answer = NULL;
+ DnsResourceRecord *rr;
+ DnsAnswerFlags flags;
+ int ifindex;
+
+ if (s->protocol == DNS_PROTOCOL_DNS)
+ continue;
+
+ r = dns_cache_dump_to_answer(&s->cache, &answer);
+ if (r < 0)
+ return r;
+ if (r == 0)
+ continue;
+
+ DNS_ANSWER_FOREACH_FULL(rr, ifindex, flags, answer) {
+ _cleanup_free_ char *normalized = NULL;
+ bool authenticated = FLAGS_SET(flags, DNS_ANSWER_AUTHENTICATED);
+
+ r = dns_name_normalize(dns_resource_key_name(rr->key), 0, &normalized);
+ if (r < 0)
+ return r;
+
+ r = sd_bus_message_open_container(reply, 'r', "stiiay");
+ if (r < 0)
+ return r;
+
+ r = sd_bus_message_append(
+ reply,
+ "st",
+ normalized,
+ SD_RESOLVED_FLAGS_MAKE(s->protocol, s->family, authenticated));
+ if (r < 0)
+ return r;
+
+ r = append_address(reply, rr, ifindex, false);
+ if (r < 0)
+ return r;
+
+ r = sd_bus_message_close_container(reply);
+ if (r < 0)
+ return r;
+ }
+ }
+
+ r = sd_bus_message_close_container(reply);
+ if (r < 0)
+ return r;
+
+ return sd_bus_reply(message, reply);
+}
+
+/* clang-format off */
static const sd_bus_vtable resolve_vtable[] = {
SD_BUS_VTABLE_START(0),
SD_BUS_PROPERTY("LLMNRHostname", "s", NULL, offsetof(Manager, llmnr_hostname), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
SD_BUS_NO_RESULT,
bus_method_reset_server_features,
SD_BUS_VTABLE_UNPRIVILEGED),
-
+ SD_BUS_METHOD_WITH_ARGS("GetMulticastHosts",
+ SD_BUS_NO_ARGS,
+ SD_BUS_RESULT("a(stiiay)", addresses),
+ bus_method_get_multicast_hosts,
+ SD_BUS_VTABLE_UNPRIVILEGED),
SD_BUS_VTABLE_END,
};
+/* clang-format on */
const BusObjectImplementation manager_object = {
"/org/freedesktop/resolve1",
return 0;
}
-void dns_cache_dump(DnsCache *cache, FILE *f) {
+int dns_cache_dump_to_answer(DnsCache *cache, DnsAnswer **ret) {
+ _cleanup_(dns_answer_unrefp) DnsAnswer *answer = NULL;
+ DnsCacheItem *i;
+ size_t n = 0;
+ int r;
+
+ assert(cache);
+ assert(ret);
+
+ HASHMAP_FOREACH(i, cache->by_key) {
+ DnsCacheItem *j;
+
+ LIST_FOREACH(by_key, j, i) {
+ if (!j->rr)
+ continue;
+
+ n++;
+ }
+ }
+
+ if (n == 0) {
+ *ret = NULL;
+ return 0;
+ }
+
+ answer = dns_answer_new(n);
+ if (!answer)
+ return -ENOMEM;
+
+ HASHMAP_FOREACH(i, cache->by_key) {
+ DnsCacheItem *j;
+
+ LIST_FOREACH(by_key, j, i) {
+ if (!j->rr)
+ continue;
+
+ r = dns_answer_add(
+ answer, j->rr, j->ifindex, j->authenticated ? DNS_ANSWER_AUTHENTICATED : 0);
+ if (r < 0)
+ return r;
+ }
+ }
+
+ *ret = TAKE_PTR(answer);
+
+ return n;
+}
+
+void dns_cache_dump_to_file(DnsCache *cache, FILE *f) {
DnsCacheItem *i;
if (!cache)