/src/systemd/src/resolve/resolved-manager.h
Line | Count | Source |
1 | | /* SPDX-License-Identifier: LGPL-2.1-or-later */ |
2 | | #pragma once |
3 | | |
4 | | #include <sys/stat.h> |
5 | | |
6 | | #include "common-signal.h" |
7 | | #include "list.h" |
8 | | #include "resolve-util.h" |
9 | | #include "resolved-dns-browse-services.h" |
10 | | #include "resolved-dns-dnssec.h" |
11 | | #include "resolved-dns-stream.h" |
12 | | #include "resolved-dns-stub.h" |
13 | | #include "resolved-dns-trust-anchor.h" |
14 | | #include "resolved-etc-hosts.h" |
15 | | #include "resolved-forward.h" |
16 | | |
17 | 0 | #define MANAGER_SEARCH_DOMAINS_MAX 1024 |
18 | 0 | #define MANAGER_DNS_SERVERS_MAX 256 |
19 | | |
20 | | typedef struct Manager { |
21 | | sd_event *event; |
22 | | |
23 | | ResolveSupport llmnr_support; |
24 | | ResolveSupport mdns_support; |
25 | | DnssecMode dnssec_mode; |
26 | | DnsOverTlsMode dns_over_tls_mode; |
27 | | DnsCacheMode enable_cache; |
28 | | bool cache_from_localhost; |
29 | | DnsStubListenerMode dns_stub_listener_mode; |
30 | | usec_t stale_retention_usec; |
31 | | |
32 | | #if ENABLE_DNS_OVER_TLS |
33 | | DnsTlsManagerData dnstls_data; |
34 | | #endif |
35 | | |
36 | | /* Network */ |
37 | | Hashmap *links; |
38 | | |
39 | | sd_netlink *rtnl; |
40 | | sd_event_source *rtnl_event_source; |
41 | | |
42 | | sd_network_monitor *network_monitor; |
43 | | sd_event_source *network_event_source; |
44 | | |
45 | | /* DNS query management */ |
46 | | Hashmap *dns_transactions; |
47 | | LIST_HEAD(DnsQuery, dns_queries); |
48 | | unsigned n_dns_queries; |
49 | | Hashmap *stub_queries_by_packet; |
50 | | |
51 | | LIST_HEAD(DnsStream, dns_streams); |
52 | | unsigned n_dns_streams[_DNS_STREAM_TYPE_MAX]; |
53 | | |
54 | | /* Unicast dns */ |
55 | | LIST_HEAD(DnsServer, dns_servers); |
56 | | LIST_HEAD(DnsServer, fallback_dns_servers); |
57 | | unsigned n_dns_servers; /* counts both main and fallback */ |
58 | | DnsServer *current_dns_server; |
59 | | |
60 | | LIST_HEAD(DnsSearchDomain, search_domains); |
61 | | unsigned n_search_domains; |
62 | | |
63 | | bool need_builtin_fallbacks; |
64 | | bool read_resolv_conf; |
65 | | bool resolve_unicast_single_label; |
66 | | |
67 | | struct stat resolv_conf_stat; |
68 | | |
69 | | DnsTrustAnchor trust_anchor; |
70 | | |
71 | | LIST_HEAD(DnsScope, dns_scopes); |
72 | | DnsScope *unicast_scope; |
73 | | |
74 | | Hashmap *delegates; /* id string → DnsDelegate objects */ |
75 | | |
76 | | /* LLMNR */ |
77 | | int llmnr_ipv4_udp_fd; |
78 | | int llmnr_ipv6_udp_fd; |
79 | | int llmnr_ipv4_tcp_fd; |
80 | | int llmnr_ipv6_tcp_fd; |
81 | | |
82 | | sd_event_source *llmnr_ipv4_udp_event_source; |
83 | | sd_event_source *llmnr_ipv6_udp_event_source; |
84 | | sd_event_source *llmnr_ipv4_tcp_event_source; |
85 | | sd_event_source *llmnr_ipv6_tcp_event_source; |
86 | | |
87 | | /* mDNS */ |
88 | | int mdns_ipv4_fd; |
89 | | int mdns_ipv6_fd; |
90 | | sd_event_source *mdns_ipv4_event_source; |
91 | | sd_event_source *mdns_ipv6_event_source; |
92 | | |
93 | | /* DNS-SD */ |
94 | | Hashmap *dnssd_registered_services; |
95 | | |
96 | | /* dbus */ |
97 | | sd_bus *bus; |
98 | | |
99 | | /* The hostname we publish on LLMNR and mDNS */ |
100 | | char *full_hostname; |
101 | | char *llmnr_hostname; |
102 | | char *mdns_hostname; |
103 | | DnsResourceKey *llmnr_host_ipv4_key; |
104 | | DnsResourceKey *llmnr_host_ipv6_key; |
105 | | DnsResourceKey *mdns_host_ipv4_key; |
106 | | DnsResourceKey *mdns_host_ipv6_key; |
107 | | |
108 | | /* Watch the system hostname */ |
109 | | int hostname_fd; |
110 | | sd_event_source *hostname_event_source; |
111 | | |
112 | | unsigned n_transactions_total; |
113 | | unsigned n_timeouts_total; |
114 | | unsigned n_timeouts_served_stale_total; |
115 | | unsigned n_failure_responses_total; |
116 | | unsigned n_failure_responses_served_stale_total; |
117 | | |
118 | | unsigned n_dnssec_verdict[_DNSSEC_VERDICT_MAX]; |
119 | | |
120 | | /* Data from /etc/hosts */ |
121 | | EtcHosts etc_hosts; |
122 | | usec_t etc_hosts_last; |
123 | | struct stat etc_hosts_stat; |
124 | | bool read_etc_hosts; |
125 | | |
126 | | /* Data from {/etc,/run,/usr/local/lib,/usr/lib}/systemd/resolve/static.d/ */ |
127 | | Hashmap *static_records; |
128 | | usec_t static_records_last; |
129 | | Set *static_records_stat; |
130 | | bool read_static_records; |
131 | | |
132 | | /* List of refused DNS Record Types */ |
133 | | Set *refuse_record_types; |
134 | | |
135 | | OrderedSet *dns_extra_stub_listeners; |
136 | | |
137 | | /* Local DNS stub on 127.0.0.53:53 */ |
138 | | sd_event_source *dns_stub_udp_event_source; |
139 | | sd_event_source *dns_stub_tcp_event_source; |
140 | | |
141 | | /* Local DNS proxy stub on 127.0.0.54:53 */ |
142 | | sd_event_source *dns_proxy_stub_udp_event_source; |
143 | | sd_event_source *dns_proxy_stub_tcp_event_source; |
144 | | |
145 | | Hashmap *polkit_registry; |
146 | | |
147 | | sd_varlink_server *varlink_server; |
148 | | sd_varlink_server *varlink_monitor_server; |
149 | | |
150 | | Set *varlink_query_results_subscription; |
151 | | Set *varlink_dns_configuration_subscription; |
152 | | |
153 | | sd_json_variant *dns_configuration_json; |
154 | | |
155 | | sd_netlink_slot *netlink_new_route_slot; |
156 | | sd_netlink_slot *netlink_del_route_slot; |
157 | | |
158 | | sd_event_source *clock_change_event_source; |
159 | | |
160 | | LIST_HEAD(SocketGraveyard, socket_graveyard); |
161 | | SocketGraveyard *socket_graveyard_oldest; |
162 | | size_t n_socket_graveyard; |
163 | | |
164 | | struct sigrtmin18_info sigrtmin18_info; |
165 | | |
166 | | /* Map varlink links to DnsServiceBrowser instances. */ |
167 | | Hashmap *dns_service_browsers; |
168 | | |
169 | | Hashmap *hooks; |
170 | | struct stat hook_stat; |
171 | | } Manager; |
172 | | |
173 | | /* Manager */ |
174 | | |
175 | | int manager_new(Manager **ret); |
176 | | Manager* manager_free(Manager *m); |
177 | | |
178 | | int manager_start(Manager *m); |
179 | | |
180 | | uint32_t manager_find_mtu(Manager *m); |
181 | | |
182 | | int manager_monitor_send(Manager *m, DnsQuery *q); |
183 | | |
184 | | int sendmsg_loop(int fd, struct msghdr *mh, int flags); |
185 | | int manager_write(Manager *m, int fd, DnsPacket *p); |
186 | | int manager_send(Manager *m, int fd, int ifindex, int family, const union in_addr_union *destination, uint16_t port, const union in_addr_union *source, DnsPacket *p); |
187 | | int manager_recv(Manager *m, int fd, DnsProtocol protocol, DnsPacket **ret); |
188 | | |
189 | | int manager_find_ifindex(Manager *m, int family, const union in_addr_union *in_addr); |
190 | | LinkAddress* manager_find_link_address(Manager *m, int family, const union in_addr_union *in_addr); |
191 | | |
192 | | void manager_refresh_rrs(Manager *m); |
193 | | int manager_next_hostname(Manager *m); |
194 | | |
195 | | bool manager_packet_from_local_address(Manager *m, DnsPacket *p); |
196 | | bool manager_packet_from_our_transaction(Manager *m, DnsPacket *p); |
197 | | |
198 | | DnsScope* manager_find_scope_from_protocol(Manager *m, int ifindex, DnsProtocol protocol, int family); |
199 | | |
200 | 0 | static inline DnsScope* manager_find_scope(Manager *m, DnsPacket *p) { |
201 | 0 | assert(m); |
202 | | assert(p); |
203 | 0 | return manager_find_scope_from_protocol(m, p->ifindex, p->protocol, p->family); |
204 | 0 | } Unexecuted instantiation: resolved-bus.c:manager_find_scope Unexecuted instantiation: resolved-conf.c:manager_find_scope Unexecuted instantiation: resolved-dns-browse-services.c:manager_find_scope Unexecuted instantiation: resolved-dns-delegate.c:manager_find_scope Unexecuted instantiation: resolved-dns-delegate-bus.c:manager_find_scope Unexecuted instantiation: resolved-dns-query.c:manager_find_scope Unexecuted instantiation: resolved-dns-scope.c:manager_find_scope Unexecuted instantiation: resolved-dns-search-domain.c:manager_find_scope Unexecuted instantiation: resolved-dns-server.c:manager_find_scope Unexecuted instantiation: resolved-dns-stream.c:manager_find_scope Unexecuted instantiation: resolved-dns-stub.c:manager_find_scope Unexecuted instantiation: resolved-dns-synthesize.c:manager_find_scope Unexecuted instantiation: resolved-dns-transaction.c:manager_find_scope Unexecuted instantiation: resolved-dns-zone.c:manager_find_scope Unexecuted instantiation: resolved-dnssd-bus.c:manager_find_scope Unexecuted instantiation: resolved-dnssd.c:manager_find_scope Unexecuted instantiation: resolved-etc-hosts.c:manager_find_scope Unexecuted instantiation: resolved-hook.c:manager_find_scope Unexecuted instantiation: resolved-link-bus.c:manager_find_scope Unexecuted instantiation: resolved-link.c:manager_find_scope Unexecuted instantiation: resolved-llmnr.c:manager_find_scope Unexecuted instantiation: resolved-manager.c:manager_find_scope Unexecuted instantiation: resolved-mdns.c:manager_find_scope Unexecuted instantiation: resolved-resolv-conf.c:manager_find_scope Unexecuted instantiation: resolved-socket-graveyard.c:manager_find_scope Unexecuted instantiation: resolved-static-records.c:manager_find_scope Unexecuted instantiation: resolved-varlink.c:manager_find_scope Unexecuted instantiation: resolved-gperf.c:manager_find_scope |
205 | | |
206 | | void manager_verify_all(Manager *m); |
207 | | |
208 | | DEFINE_TRIVIAL_CLEANUP_FUNC(Manager*, manager_free); |
209 | | |
210 | | /* For some reason we need some extra cmsg space on some kernels/archs. One of those days we need to figure out why */ |
211 | | #define EXTRA_CMSG_SPACE 1024 |
212 | | |
213 | | int manager_is_own_hostname(Manager *m, const char *name); |
214 | | |
215 | | int manager_compile_dns_servers(Manager *m, OrderedSet **servers); |
216 | | int manager_compile_search_domains(Manager *m, OrderedSet **domains, int filter_route); |
217 | | |
218 | | DnssecMode manager_get_dnssec_mode(Manager *m); |
219 | | bool manager_dnssec_supported(Manager *m); |
220 | | |
221 | | DnsOverTlsMode manager_get_dns_over_tls_mode(Manager *m); |
222 | | |
223 | | void manager_dnssec_verdict(Manager *m, DnssecVerdict verdict, const DnsResourceKey *key); |
224 | | |
225 | | bool manager_routable(Manager *m); |
226 | | |
227 | | void manager_flush_caches(Manager *m, int log_level); |
228 | | void manager_reset_server_features(Manager *m); |
229 | | |
230 | | void manager_cleanup_saved_user(Manager *m); |
231 | | |
232 | | bool manager_next_dnssd_names(Manager *m); |
233 | | |
234 | | bool manager_server_is_stub(Manager *m, DnsServer *s); |
235 | | |
236 | | int socket_disable_pmtud(int fd, int af); |
237 | | |
238 | | int dns_manager_dump_statistics_json(Manager *m, sd_json_variant **ret); |
239 | | |
240 | | void dns_manager_reset_statistics(Manager *m); |
241 | | |
242 | | int manager_dump_dns_configuration_json(Manager *m, sd_json_variant **ret); |
243 | | int manager_send_dns_configuration_changed(Manager *m, Link *l, bool reset); |
244 | | |
245 | | int manager_start_dns_configuration_monitor(Manager *m); |
246 | | void manager_stop_dns_configuration_monitor(Manager *m); |