]>
Commit | Line | Data |
---|---|---|
c3036641 DR |
1 | /*** |
2 | This file is part of systemd. | |
3 | ||
4 | Copyright 2017 Dmitry Rozhkov | |
5 | ||
6 | systemd is free software; you can redistribute it and/or modify it | |
7 | under the terms of the GNU Lesser General Public License as published by | |
8 | the Free Software Foundation; either version 2.1 of the License, or | |
9 | (at your option) any later version. | |
10 | ||
11 | systemd is distributed in the hope that it will be useful, but | |
12 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | Lesser General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU Lesser General Public License | |
17 | along with systemd; If not, see <http://www.gnu.org/licenses/>. | |
18 | ***/ | |
19 | ||
20 | #include "alloc-util.h" | |
21 | #include "resolved-dnssd.h" | |
22 | #include "resolved-dnssd-bus.h" | |
23 | #include "resolved-link.h" | |
24 | #include "strv.h" | |
25 | ||
26 | int bus_dnssd_method_unregister(sd_bus_message *message, void *userdata, sd_bus_error *error) { | |
27 | DnssdService *s = userdata; | |
28 | Manager *m; | |
29 | Iterator i; | |
30 | Link *l; | |
31 | int r; | |
32 | ||
33 | assert(message); | |
34 | assert(s); | |
35 | ||
36 | m = s->manager; | |
37 | ||
38 | HASHMAP_FOREACH(l, m->links, i) { | |
39 | if (l->mdns_ipv4_scope) { | |
40 | r = dns_scope_announce(l->mdns_ipv4_scope, true); | |
41 | if (r < 0) | |
42 | log_warning_errno(r, "Failed to send goodbye messages in IPv4 scope: %m"); | |
43 | ||
44 | dns_zone_remove_rr(&l->mdns_ipv4_scope->zone, s->ptr_rr); | |
45 | dns_zone_remove_rr(&l->mdns_ipv4_scope->zone, s->srv_rr); | |
46 | dns_zone_remove_rr(&l->mdns_ipv4_scope->zone, s->txt_rr); | |
47 | } | |
48 | ||
49 | if (l->mdns_ipv6_scope) { | |
50 | r = dns_scope_announce(l->mdns_ipv6_scope, true); | |
51 | if (r < 0) | |
52 | log_warning_errno(r, "Failed to send goodbye messages in IPv6 scope: %m"); | |
53 | ||
54 | dns_zone_remove_rr(&l->mdns_ipv6_scope->zone, s->ptr_rr); | |
55 | dns_zone_remove_rr(&l->mdns_ipv6_scope->zone, s->srv_rr); | |
56 | dns_zone_remove_rr(&l->mdns_ipv6_scope->zone, s->txt_rr); | |
57 | } | |
58 | } | |
59 | ||
60 | dnssd_service_free(s); | |
61 | ||
62 | manager_refresh_rrs(m); | |
63 | ||
64 | return sd_bus_reply_method_return(message, NULL); | |
65 | } | |
66 | ||
67 | const sd_bus_vtable dnssd_vtable[] = { | |
68 | SD_BUS_VTABLE_START(0), | |
69 | ||
70 | SD_BUS_METHOD("Unregister", NULL, NULL, bus_dnssd_method_unregister, 0), | |
71 | SD_BUS_SIGNAL("Conflicted", NULL, 0), | |
72 | ||
73 | SD_BUS_VTABLE_END | |
74 | }; | |
75 | ||
76 | int dnssd_object_find(sd_bus *bus, const char *path, const char *interface, void *userdata, void **found, sd_bus_error *error) { | |
77 | _cleanup_free_ char *name = NULL; | |
78 | Manager *m = userdata; | |
79 | DnssdService *service; | |
80 | int r; | |
81 | ||
82 | assert(bus); | |
83 | assert(path); | |
84 | assert(interface); | |
85 | assert(found); | |
86 | assert(m); | |
87 | ||
88 | r = sd_bus_path_decode(path, "/org/freedesktop/resolve1/dnssd", &name); | |
89 | if (r <= 0) | |
90 | return 0; | |
91 | ||
92 | service = hashmap_get(m->dnssd_services, name); | |
93 | if (!service) | |
94 | return 0; | |
95 | ||
96 | *found = service; | |
97 | return 1; | |
98 | } | |
99 | ||
100 | int dnssd_node_enumerator(sd_bus *bus, const char *path, void *userdata, char ***nodes, sd_bus_error *error) { | |
101 | _cleanup_strv_free_ char **l = NULL; | |
102 | Manager *m = userdata; | |
103 | DnssdService *service; | |
104 | Iterator i; | |
105 | unsigned c = 0; | |
106 | int r; | |
107 | ||
108 | assert(bus); | |
109 | assert(path); | |
110 | assert(m); | |
111 | assert(nodes); | |
112 | ||
113 | l = new0(char*, hashmap_size(m->dnssd_services) + 1); | |
114 | if (!l) | |
115 | return -ENOMEM; | |
116 | ||
117 | HASHMAP_FOREACH(service, m->dnssd_services, i) { | |
118 | char *p; | |
119 | ||
120 | r = sd_bus_path_encode("/org/freedesktop/resolve1/dnssd", service->name, &p); | |
121 | if (r < 0) | |
122 | return r; | |
123 | ||
124 | l[c++] = p; | |
125 | } | |
126 | ||
127 | l[c] = NULL; | |
128 | *nodes = l; | |
129 | l = NULL; | |
130 | ||
131 | return 1; | |
132 | } |