resolved: implement D-Bus API for DNS-SD
This commit is contained in:
@@ -83,6 +83,8 @@
|
|||||||
#define BUS_ERROR_NO_SUCH_LINK "org.freedesktop.resolve1.NoSuchLink"
|
#define BUS_ERROR_NO_SUCH_LINK "org.freedesktop.resolve1.NoSuchLink"
|
||||||
#define BUS_ERROR_LINK_BUSY "org.freedesktop.resolve1.LinkBusy"
|
#define BUS_ERROR_LINK_BUSY "org.freedesktop.resolve1.LinkBusy"
|
||||||
#define BUS_ERROR_NETWORK_DOWN "org.freedesktop.resolve1.NetworkDown"
|
#define BUS_ERROR_NETWORK_DOWN "org.freedesktop.resolve1.NetworkDown"
|
||||||
|
#define BUS_ERROR_NO_SUCH_DNSSD_SERVICE "org.freedesktop.resolve1.NoSuchDnssdService"
|
||||||
|
#define BUS_ERROR_DNSSD_SERVICE_EXISTS "org.freedesktop.resolve1.DnssdServiceExists"
|
||||||
#define _BUS_ERROR_DNS "org.freedesktop.resolve1.DnsError."
|
#define _BUS_ERROR_DNS "org.freedesktop.resolve1.DnsError."
|
||||||
|
|
||||||
#define BUS_ERROR_NO_SUCH_TRANSFER "org.freedesktop.import1.NoSuchTransfer"
|
#define BUS_ERROR_NO_SUCH_TRANSFER "org.freedesktop.import1.NoSuchTransfer"
|
||||||
|
|||||||
@@ -37,6 +37,8 @@ systemd_resolved_only_sources = files('''
|
|||||||
resolved-manager.h
|
resolved-manager.h
|
||||||
resolved-dnssd.c
|
resolved-dnssd.c
|
||||||
resolved-dnssd.h
|
resolved-dnssd.h
|
||||||
|
resolved-dnssd-bus.c
|
||||||
|
resolved-dnssd-bus.h
|
||||||
resolved-conf.c
|
resolved-conf.c
|
||||||
resolved-conf.h
|
resolved-conf.h
|
||||||
resolved-resolv-conf.c
|
resolved-resolv-conf.c
|
||||||
|
|||||||
@@ -25,7 +25,10 @@
|
|||||||
#include "resolved-bus.h"
|
#include "resolved-bus.h"
|
||||||
#include "resolved-def.h"
|
#include "resolved-def.h"
|
||||||
#include "resolved-dns-synthesize.h"
|
#include "resolved-dns-synthesize.h"
|
||||||
|
#include "resolved-dnssd.h"
|
||||||
|
#include "resolved-dnssd-bus.h"
|
||||||
#include "resolved-link-bus.h"
|
#include "resolved-link-bus.h"
|
||||||
|
#include "utf8.h"
|
||||||
|
|
||||||
static int reply_query_state(DnsQuery *q) {
|
static int reply_query_state(DnsQuery *q) {
|
||||||
|
|
||||||
@@ -1581,6 +1584,177 @@ static int bus_method_reset_server_features(sd_bus_message *message, void *userd
|
|||||||
return sd_bus_reply_method_return(message, NULL);
|
return sd_bus_reply_method_return(message, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int on_bus_track(sd_bus_track *t, void *userdata) {
|
||||||
|
DnssdService *s = userdata;
|
||||||
|
|
||||||
|
assert(t);
|
||||||
|
assert(s);
|
||||||
|
|
||||||
|
log_debug("Client of active request vanished, destroying DNS-SD service.");
|
||||||
|
dnssd_service_free(s);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int bus_method_register_service(sd_bus_message *message, void *userdata, sd_bus_error *error) {
|
||||||
|
_cleanup_(dnssd_service_freep) DnssdService *service = NULL;
|
||||||
|
_cleanup_(sd_bus_track_unrefp) sd_bus_track *bus_track = NULL;
|
||||||
|
_cleanup_free_ char *path = NULL;
|
||||||
|
_cleanup_free_ char *instance_name = NULL;
|
||||||
|
Manager *m = userdata;
|
||||||
|
DnssdService *s = NULL;
|
||||||
|
DnsTxtItem *last = NULL;
|
||||||
|
const char *name;
|
||||||
|
const char *name_template;
|
||||||
|
const char *type;
|
||||||
|
int r;
|
||||||
|
|
||||||
|
assert(message);
|
||||||
|
assert(m);
|
||||||
|
|
||||||
|
if (m->mdns_support != RESOLVE_SUPPORT_YES)
|
||||||
|
return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, "Support for MulticastDNS is disabled");
|
||||||
|
|
||||||
|
service = new0(DnssdService, 1);
|
||||||
|
if (!service)
|
||||||
|
return log_oom();
|
||||||
|
|
||||||
|
r = sd_bus_message_read(message, "sssqqq", &name, &name_template, &type,
|
||||||
|
&service->port, &service->priority,
|
||||||
|
&service->weight);
|
||||||
|
if (r < 0)
|
||||||
|
return r;
|
||||||
|
|
||||||
|
s = hashmap_get(m->dnssd_services, name);
|
||||||
|
if (s)
|
||||||
|
return sd_bus_error_setf(error, BUS_ERROR_DNSSD_SERVICE_EXISTS, "DNS-SD service '%s' exists already", name);
|
||||||
|
|
||||||
|
if (!dnssd_srv_type_is_valid(type))
|
||||||
|
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "DNS-SD service type '%s' is invalid", type);
|
||||||
|
|
||||||
|
service->name = strdup(name);
|
||||||
|
if (!service->name)
|
||||||
|
return log_oom();
|
||||||
|
|
||||||
|
service->name_template = strdup(name_template);
|
||||||
|
if (!service->name_template)
|
||||||
|
return log_oom();
|
||||||
|
|
||||||
|
service->type = strdup(type);
|
||||||
|
if (!service->type)
|
||||||
|
return log_oom();
|
||||||
|
|
||||||
|
r = dnssd_render_instance_name(service, &instance_name);
|
||||||
|
if (r < 0)
|
||||||
|
return r;
|
||||||
|
|
||||||
|
r = sd_bus_message_enter_container(message, SD_BUS_TYPE_ARRAY, "{say}");
|
||||||
|
if (r < 0)
|
||||||
|
return sd_bus_error_set_errno(error, r);
|
||||||
|
|
||||||
|
while ((r = sd_bus_message_enter_container(message, SD_BUS_TYPE_DICT_ENTRY, "say")) > 0) {
|
||||||
|
const char *key;
|
||||||
|
const void *value;
|
||||||
|
size_t size;
|
||||||
|
DnsTxtItem *i;
|
||||||
|
|
||||||
|
r = sd_bus_message_read(message, "s", &key);
|
||||||
|
if (r < 0)
|
||||||
|
return sd_bus_error_set_errno(error, r);
|
||||||
|
|
||||||
|
if (strlen_ptr(key) == 0)
|
||||||
|
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Keys in DNS-SD TXT RRs can't be empty");
|
||||||
|
|
||||||
|
if (!ascii_is_valid(key))
|
||||||
|
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "TXT key '%s' contains non-ASCII symbols", key);
|
||||||
|
|
||||||
|
r = sd_bus_message_read_array(message, 'y', &value, &size);
|
||||||
|
if (r < 0)
|
||||||
|
return sd_bus_error_set_errno(error, r);
|
||||||
|
|
||||||
|
r = dnssd_txt_item_new_from_data(key, value, size, &i);
|
||||||
|
if (r < 0)
|
||||||
|
return sd_bus_error_set_errno(error, r);
|
||||||
|
|
||||||
|
LIST_INSERT_AFTER(items, service->txt, last, i);
|
||||||
|
last = i;
|
||||||
|
}
|
||||||
|
|
||||||
|
r = sd_bus_message_exit_container(message);
|
||||||
|
if (r < 0)
|
||||||
|
return sd_bus_error_set_errno(error, r);
|
||||||
|
|
||||||
|
if (!service->txt) {
|
||||||
|
r = dns_txt_item_new_empty(&service->txt);
|
||||||
|
if (r < 0)
|
||||||
|
return sd_bus_error_set_errno(error, r);
|
||||||
|
}
|
||||||
|
|
||||||
|
r = sd_bus_path_encode("/org/freedesktop/resolve1/dnssd", service->name, &path);
|
||||||
|
if (r < 0)
|
||||||
|
return r;
|
||||||
|
|
||||||
|
r = hashmap_ensure_allocated(&m->dnssd_services, &string_hash_ops);
|
||||||
|
if (r < 0)
|
||||||
|
return r;
|
||||||
|
|
||||||
|
r = hashmap_put(m->dnssd_services, service->name, service);
|
||||||
|
if (r < 0)
|
||||||
|
return r;
|
||||||
|
|
||||||
|
r = sd_bus_track_new(sd_bus_message_get_bus(message), &bus_track, on_bus_track, service);
|
||||||
|
if (r < 0)
|
||||||
|
return r;
|
||||||
|
|
||||||
|
r = sd_bus_track_add_sender(bus_track, message);
|
||||||
|
if (r < 0)
|
||||||
|
return r;
|
||||||
|
|
||||||
|
service->manager = m;
|
||||||
|
|
||||||
|
service = NULL;
|
||||||
|
|
||||||
|
manager_refresh_rrs(m);
|
||||||
|
|
||||||
|
return sd_bus_reply_method_return(message, "o", path);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int call_dnssd_method(Manager *m, sd_bus_message *message, sd_bus_message_handler_t handler, sd_bus_error *error) {
|
||||||
|
_cleanup_free_ char *name = NULL;
|
||||||
|
DnssdService *s = NULL;
|
||||||
|
const char *path;
|
||||||
|
int r;
|
||||||
|
|
||||||
|
assert(m);
|
||||||
|
assert(message);
|
||||||
|
assert(handler);
|
||||||
|
|
||||||
|
r = sd_bus_message_read(message, "o", &path);
|
||||||
|
if (r < 0)
|
||||||
|
return r;
|
||||||
|
|
||||||
|
r = sd_bus_path_decode(path, "/org/freedesktop/resolve1/dnssd", &name);
|
||||||
|
if (r == 0)
|
||||||
|
return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_DNSSD_SERVICE, "DNS-SD service with object path '%s' does not exist", path);
|
||||||
|
if (r < 0)
|
||||||
|
return r;
|
||||||
|
|
||||||
|
s = hashmap_get(m->dnssd_services, name);
|
||||||
|
if (!s)
|
||||||
|
return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_DNSSD_SERVICE, "DNS-SD service '%s' not known", name);
|
||||||
|
|
||||||
|
return handler(message, s, error);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int bus_method_unregister_service(sd_bus_message *message, void *userdata, sd_bus_error *error) {
|
||||||
|
Manager *m = userdata;
|
||||||
|
|
||||||
|
assert(message);
|
||||||
|
assert(m);
|
||||||
|
|
||||||
|
return call_dnssd_method(m, message, bus_dnssd_method_unregister, error);
|
||||||
|
}
|
||||||
|
|
||||||
static const sd_bus_vtable resolve_vtable[] = {
|
static const sd_bus_vtable resolve_vtable[] = {
|
||||||
SD_BUS_VTABLE_START(0),
|
SD_BUS_VTABLE_START(0),
|
||||||
SD_BUS_PROPERTY("LLMNRHostname", "s", NULL, offsetof(Manager, llmnr_hostname), 0),
|
SD_BUS_PROPERTY("LLMNRHostname", "s", NULL, offsetof(Manager, llmnr_hostname), 0),
|
||||||
@@ -1609,6 +1783,8 @@ static const sd_bus_vtable resolve_vtable[] = {
|
|||||||
SD_BUS_METHOD("SetLinkDNSSECNegativeTrustAnchors", "ias", NULL, bus_method_set_link_dnssec_negative_trust_anchors, 0),
|
SD_BUS_METHOD("SetLinkDNSSECNegativeTrustAnchors", "ias", NULL, bus_method_set_link_dnssec_negative_trust_anchors, 0),
|
||||||
SD_BUS_METHOD("RevertLink", "i", NULL, bus_method_revert_link, 0),
|
SD_BUS_METHOD("RevertLink", "i", NULL, bus_method_revert_link, 0),
|
||||||
|
|
||||||
|
SD_BUS_METHOD("RegisterService", "sssqqqa{say}", "o", bus_method_register_service, 0),
|
||||||
|
SD_BUS_METHOD("UnregisterService", "o", NULL, bus_method_unregister_service, 0),
|
||||||
SD_BUS_VTABLE_END,
|
SD_BUS_VTABLE_END,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1681,6 +1857,14 @@ int manager_connect_bus(Manager *m) {
|
|||||||
if (r < 0)
|
if (r < 0)
|
||||||
return log_error_errno(r, "Failed to register link enumerator: %m");
|
return log_error_errno(r, "Failed to register link enumerator: %m");
|
||||||
|
|
||||||
|
r = sd_bus_add_fallback_vtable(m->bus, NULL, "/org/freedesktop/resolve1/dnssd", "org.freedesktop.resolve1.DnssdService", dnssd_vtable, dnssd_object_find, m);
|
||||||
|
if (r < 0)
|
||||||
|
return log_error_errno(r, "Failed to register dnssd objects: %m");
|
||||||
|
|
||||||
|
r = sd_bus_add_node_enumerator(m->bus, NULL, "/org/freedesktop/resolve1/dnssd", dnssd_node_enumerator, m);
|
||||||
|
if (r < 0)
|
||||||
|
return log_error_errno(r, "Failed to register dnssd enumerator: %m");
|
||||||
|
|
||||||
r = sd_bus_request_name(m->bus, "org.freedesktop.resolve1", 0);
|
r = sd_bus_request_name(m->bus, "org.freedesktop.resolve1", 0);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return log_error_errno(r, "Failed to register name: %m");
|
return log_error_errno(r, "Failed to register name: %m");
|
||||||
|
|||||||
@@ -1205,6 +1205,8 @@ int dns_scope_add_dnssd_services(DnsScope *scope) {
|
|||||||
scope->announced = false;
|
scope->announced = false;
|
||||||
|
|
||||||
HASHMAP_FOREACH(service, scope->manager->dnssd_services, i) {
|
HASHMAP_FOREACH(service, scope->manager->dnssd_services, i) {
|
||||||
|
service->withdrawn = false;
|
||||||
|
|
||||||
r = dns_zone_put(&scope->zone, scope, service->ptr_rr, false);
|
r = dns_zone_put(&scope->zone, scope, service->ptr_rr, false);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
log_warning_errno(r, "Failed to add PTR record to MDNS zone: %m");
|
log_warning_errno(r, "Failed to add PTR record to MDNS zone: %m");
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
#include "list.h"
|
#include "list.h"
|
||||||
#include "resolved-dns-packet.h"
|
#include "resolved-dns-packet.h"
|
||||||
#include "resolved-dns-zone.h"
|
#include "resolved-dns-zone.h"
|
||||||
|
#include "resolved-dnssd.h"
|
||||||
#include "string-util.h"
|
#include "string-util.h"
|
||||||
|
|
||||||
/* Never allow more than 1K entries */
|
/* Never allow more than 1K entries */
|
||||||
@@ -525,6 +526,8 @@ void dns_zone_item_conflict(DnsZoneItem *i) {
|
|||||||
/* Withdraw the conflict item */
|
/* Withdraw the conflict item */
|
||||||
i->state = DNS_ZONE_ITEM_WITHDRAWN;
|
i->state = DNS_ZONE_ITEM_WITHDRAWN;
|
||||||
|
|
||||||
|
dnssd_signal_conflict(i->scope->manager, dns_resource_key_name(i->rr->key));
|
||||||
|
|
||||||
/* Maybe change the hostname */
|
/* Maybe change the hostname */
|
||||||
if (manager_is_own_hostname(i->scope->manager, dns_resource_key_name(i->rr->key)) > 0)
|
if (manager_is_own_hostname(i->scope->manager, dns_resource_key_name(i->rr->key)) > 0)
|
||||||
manager_next_hostname(i->scope->manager);
|
manager_next_hostname(i->scope->manager);
|
||||||
|
|||||||
@@ -0,0 +1,132 @@
|
|||||||
|
/***
|
||||||
|
This file is part of systemd.
|
||||||
|
|
||||||
|
Copyright 2017 Dmitry Rozhkov
|
||||||
|
|
||||||
|
systemd is free software; you can redistribute it and/or modify it
|
||||||
|
under the terms of the GNU Lesser General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2.1 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
systemd is distributed in the hope that it will be useful, but
|
||||||
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
***/
|
||||||
|
|
||||||
|
#include "alloc-util.h"
|
||||||
|
#include "resolved-dnssd.h"
|
||||||
|
#include "resolved-dnssd-bus.h"
|
||||||
|
#include "resolved-link.h"
|
||||||
|
#include "strv.h"
|
||||||
|
|
||||||
|
int bus_dnssd_method_unregister(sd_bus_message *message, void *userdata, sd_bus_error *error) {
|
||||||
|
DnssdService *s = userdata;
|
||||||
|
Manager *m;
|
||||||
|
Iterator i;
|
||||||
|
Link *l;
|
||||||
|
int r;
|
||||||
|
|
||||||
|
assert(message);
|
||||||
|
assert(s);
|
||||||
|
|
||||||
|
m = s->manager;
|
||||||
|
|
||||||
|
HASHMAP_FOREACH(l, m->links, i) {
|
||||||
|
if (l->mdns_ipv4_scope) {
|
||||||
|
r = dns_scope_announce(l->mdns_ipv4_scope, true);
|
||||||
|
if (r < 0)
|
||||||
|
log_warning_errno(r, "Failed to send goodbye messages in IPv4 scope: %m");
|
||||||
|
|
||||||
|
dns_zone_remove_rr(&l->mdns_ipv4_scope->zone, s->ptr_rr);
|
||||||
|
dns_zone_remove_rr(&l->mdns_ipv4_scope->zone, s->srv_rr);
|
||||||
|
dns_zone_remove_rr(&l->mdns_ipv4_scope->zone, s->txt_rr);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (l->mdns_ipv6_scope) {
|
||||||
|
r = dns_scope_announce(l->mdns_ipv6_scope, true);
|
||||||
|
if (r < 0)
|
||||||
|
log_warning_errno(r, "Failed to send goodbye messages in IPv6 scope: %m");
|
||||||
|
|
||||||
|
dns_zone_remove_rr(&l->mdns_ipv6_scope->zone, s->ptr_rr);
|
||||||
|
dns_zone_remove_rr(&l->mdns_ipv6_scope->zone, s->srv_rr);
|
||||||
|
dns_zone_remove_rr(&l->mdns_ipv6_scope->zone, s->txt_rr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dnssd_service_free(s);
|
||||||
|
|
||||||
|
manager_refresh_rrs(m);
|
||||||
|
|
||||||
|
return sd_bus_reply_method_return(message, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
const sd_bus_vtable dnssd_vtable[] = {
|
||||||
|
SD_BUS_VTABLE_START(0),
|
||||||
|
|
||||||
|
SD_BUS_METHOD("Unregister", NULL, NULL, bus_dnssd_method_unregister, 0),
|
||||||
|
SD_BUS_SIGNAL("Conflicted", NULL, 0),
|
||||||
|
|
||||||
|
SD_BUS_VTABLE_END
|
||||||
|
};
|
||||||
|
|
||||||
|
int dnssd_object_find(sd_bus *bus, const char *path, const char *interface, void *userdata, void **found, sd_bus_error *error) {
|
||||||
|
_cleanup_free_ char *name = NULL;
|
||||||
|
Manager *m = userdata;
|
||||||
|
DnssdService *service;
|
||||||
|
int r;
|
||||||
|
|
||||||
|
assert(bus);
|
||||||
|
assert(path);
|
||||||
|
assert(interface);
|
||||||
|
assert(found);
|
||||||
|
assert(m);
|
||||||
|
|
||||||
|
r = sd_bus_path_decode(path, "/org/freedesktop/resolve1/dnssd", &name);
|
||||||
|
if (r <= 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
service = hashmap_get(m->dnssd_services, name);
|
||||||
|
if (!service)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
*found = service;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int dnssd_node_enumerator(sd_bus *bus, const char *path, void *userdata, char ***nodes, sd_bus_error *error) {
|
||||||
|
_cleanup_strv_free_ char **l = NULL;
|
||||||
|
Manager *m = userdata;
|
||||||
|
DnssdService *service;
|
||||||
|
Iterator i;
|
||||||
|
unsigned c = 0;
|
||||||
|
int r;
|
||||||
|
|
||||||
|
assert(bus);
|
||||||
|
assert(path);
|
||||||
|
assert(m);
|
||||||
|
assert(nodes);
|
||||||
|
|
||||||
|
l = new0(char*, hashmap_size(m->dnssd_services) + 1);
|
||||||
|
if (!l)
|
||||||
|
return -ENOMEM;
|
||||||
|
|
||||||
|
HASHMAP_FOREACH(service, m->dnssd_services, i) {
|
||||||
|
char *p;
|
||||||
|
|
||||||
|
r = sd_bus_path_encode("/org/freedesktop/resolve1/dnssd", service->name, &p);
|
||||||
|
if (r < 0)
|
||||||
|
return r;
|
||||||
|
|
||||||
|
l[c++] = p;
|
||||||
|
}
|
||||||
|
|
||||||
|
l[c] = NULL;
|
||||||
|
*nodes = l;
|
||||||
|
l = NULL;
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
/***
|
||||||
|
This file is part of systemd.
|
||||||
|
|
||||||
|
Copyright 2017 Dmitry Rozhkov
|
||||||
|
|
||||||
|
systemd is free software; you can redistribute it and/or modify it
|
||||||
|
under the terms of the GNU Lesser General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2.1 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
systemd is distributed in the hope that it will be useful, but
|
||||||
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
***/
|
||||||
|
|
||||||
|
#include "sd-bus.h"
|
||||||
|
|
||||||
|
extern const sd_bus_vtable dnssd_vtable[];
|
||||||
|
|
||||||
|
int dnssd_object_find(sd_bus *bus, const char *path, const char *interface, void *userdata, void **found, sd_bus_error *error);
|
||||||
|
int dnssd_node_enumerator(sd_bus *bus, const char *path, void *userdata, char ***nodes, sd_bus_error *error);
|
||||||
|
|
||||||
|
int bus_dnssd_method_unregister(sd_bus_message *message, void *userdata, sd_bus_error *error);
|
||||||
@@ -314,3 +314,38 @@ int dnssd_txt_item_new_from_data(const char *key, const void *data, const size_t
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void dnssd_signal_conflict(Manager *manager, const char *name) {
|
||||||
|
Iterator i;
|
||||||
|
DnssdService *s;
|
||||||
|
int r;
|
||||||
|
|
||||||
|
HASHMAP_FOREACH(s, manager->dnssd_services, i) {
|
||||||
|
if (s->withdrawn)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (dns_name_equal(dns_resource_key_name(s->srv_rr->key), name)) {
|
||||||
|
_cleanup_free_ char *path = NULL;
|
||||||
|
|
||||||
|
s->withdrawn = true;
|
||||||
|
|
||||||
|
r = sd_bus_path_encode("/org/freedesktop/resolve1/dnssd", s->name, &path);
|
||||||
|
if (r < 0) {
|
||||||
|
log_error_errno(r, "Can't get D-BUS object path: %m");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
r = sd_bus_emit_signal(manager->bus,
|
||||||
|
path,
|
||||||
|
"org.freedesktop.resolve1.DnssdService",
|
||||||
|
"Conflicted",
|
||||||
|
NULL);
|
||||||
|
if (r < 0) {
|
||||||
|
log_error_errno(r, "Cannot emit signal: %m");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -45,6 +45,8 @@ struct DnssdService {
|
|||||||
DnsResourceRecord *txt_rr;
|
DnsResourceRecord *txt_rr;
|
||||||
|
|
||||||
Manager *manager;
|
Manager *manager;
|
||||||
|
|
||||||
|
bool withdrawn:1;
|
||||||
};
|
};
|
||||||
|
|
||||||
DnssdService *dnssd_service_free(DnssdService *service);
|
DnssdService *dnssd_service_free(DnssdService *service);
|
||||||
@@ -56,3 +58,4 @@ int dnssd_load(Manager *manager);
|
|||||||
int dnssd_txt_item_new_from_string(const char *key, const char *value, DnsTxtItem **ret_item);
|
int dnssd_txt_item_new_from_string(const char *key, const char *value, DnsTxtItem **ret_item);
|
||||||
int dnssd_txt_item_new_from_data(const char *key, const void *value, const size_t size, DnsTxtItem **ret_item);
|
int dnssd_txt_item_new_from_data(const char *key, const void *value, const size_t size, DnsTxtItem **ret_item);
|
||||||
int dnssd_update_rrs(DnssdService *s);
|
int dnssd_update_rrs(DnssdService *s);
|
||||||
|
void dnssd_signal_conflict(Manager *manager, const char *name);
|
||||||
|
|||||||
Reference in New Issue
Block a user