1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
7 #include "sd-netlink.h"
8 #include "sd-network.h"
10 #include "common-signal.h"
13 #include "ordered-set.h"
14 #include "resolve-util.h"
17 typedef struct Manager Manager
;
19 #include "resolved-dns-query.h"
20 #include "resolved-dns-search-domain.h"
21 #include "resolved-dns-stream.h"
22 #include "resolved-dns-stub.h"
23 #include "resolved-dns-trust-anchor.h"
24 #include "resolved-link.h"
25 #include "resolved-socket-graveyard.h"
27 #define MANAGER_SEARCH_DOMAINS_MAX 256
28 #define MANAGER_DNS_SERVERS_MAX 256
30 typedef struct EtcHosts
{
39 ResolveSupport llmnr_support
;
40 ResolveSupport mdns_support
;
41 DnssecMode dnssec_mode
;
42 DnsOverTlsMode dns_over_tls_mode
;
43 DnsCacheMode enable_cache
;
44 bool cache_from_localhost
;
45 DnsStubListenerMode dns_stub_listener_mode
;
46 usec_t stale_retention_usec
;
48 #if ENABLE_DNS_OVER_TLS
49 DnsTlsManagerData dnstls_data
;
56 sd_event_source
*rtnl_event_source
;
58 sd_network_monitor
*network_monitor
;
59 sd_event_source
*network_event_source
;
61 /* DNS query management */
62 Hashmap
*dns_transactions
;
63 LIST_HEAD(DnsQuery
, dns_queries
);
64 unsigned n_dns_queries
;
65 Hashmap
*stub_queries_by_packet
;
67 LIST_HEAD(DnsStream
, dns_streams
);
68 unsigned n_dns_streams
[_DNS_STREAM_TYPE_MAX
];
71 LIST_HEAD(DnsServer
, dns_servers
);
72 LIST_HEAD(DnsServer
, fallback_dns_servers
);
73 unsigned n_dns_servers
; /* counts both main and fallback */
74 DnsServer
*current_dns_server
;
76 LIST_HEAD(DnsSearchDomain
, search_domains
);
77 unsigned n_search_domains
;
79 bool need_builtin_fallbacks
;
80 bool read_resolv_conf
;
81 bool resolve_unicast_single_label
;
83 struct stat resolv_conf_stat
;
85 DnsTrustAnchor trust_anchor
;
87 LIST_HEAD(DnsScope
, dns_scopes
);
88 DnsScope
*unicast_scope
;
91 int llmnr_ipv4_udp_fd
;
92 int llmnr_ipv6_udp_fd
;
93 int llmnr_ipv4_tcp_fd
;
94 int llmnr_ipv6_tcp_fd
;
96 sd_event_source
*llmnr_ipv4_udp_event_source
;
97 sd_event_source
*llmnr_ipv6_udp_event_source
;
98 sd_event_source
*llmnr_ipv4_tcp_event_source
;
99 sd_event_source
*llmnr_ipv6_tcp_event_source
;
104 sd_event_source
*mdns_ipv4_event_source
;
105 sd_event_source
*mdns_ipv6_event_source
;
108 Hashmap
*dnssd_services
;
113 /* The hostname we publish on LLMNR and mDNS */
115 char *llmnr_hostname
;
117 DnsResourceKey
*llmnr_host_ipv4_key
;
118 DnsResourceKey
*llmnr_host_ipv6_key
;
119 DnsResourceKey
*mdns_host_ipv4_key
;
120 DnsResourceKey
*mdns_host_ipv6_key
;
122 /* Watch the system hostname */
124 sd_event_source
*hostname_event_source
;
126 sd_event_source
*sigusr1_event_source
;
127 sd_event_source
*sigusr2_event_source
;
128 sd_event_source
*sigrtmin1_event_source
;
130 unsigned n_transactions_total
;
131 unsigned n_timeouts_total
;
132 unsigned n_timeouts_served_stale_total
;
133 unsigned n_failure_responses_total
;
134 unsigned n_failure_responses_served_stale_total
;
136 unsigned n_dnssec_verdict
[_DNSSEC_VERDICT_MAX
];
138 /* Data from /etc/hosts */
140 usec_t etc_hosts_last
;
141 struct stat etc_hosts_stat
;
144 OrderedSet
*dns_extra_stub_listeners
;
146 /* Local DNS stub on 127.0.0.53:53 */
147 sd_event_source
*dns_stub_udp_event_source
;
148 sd_event_source
*dns_stub_tcp_event_source
;
150 /* Local DNS proxy stub on 127.0.0.54:53 */
151 sd_event_source
*dns_proxy_stub_udp_event_source
;
152 sd_event_source
*dns_proxy_stub_tcp_event_source
;
154 Hashmap
*polkit_registry
;
156 VarlinkServer
*varlink_server
;
157 VarlinkServer
*varlink_monitor_server
;
159 Set
*varlink_subscription
;
161 sd_event_source
*clock_change_event_source
;
163 LIST_HEAD(SocketGraveyard
, socket_graveyard
);
164 SocketGraveyard
*socket_graveyard_oldest
;
165 size_t n_socket_graveyard
;
167 struct sigrtmin18_info sigrtmin18_info
;
172 int manager_new(Manager
**ret
);
173 Manager
* manager_free(Manager
*m
);
175 int manager_start(Manager
*m
);
177 uint32_t manager_find_mtu(Manager
*m
);
179 int manager_monitor_send(Manager
*m
, int state
, int rcode
, int error
, DnsQuestion
*question_idna
, DnsQuestion
*question_utf8
, DnsPacket
*question_bypass
, DnsQuestion
*collected_questions
, DnsAnswer
*answer
);
181 int manager_write(Manager
*m
, int fd
, DnsPacket
*p
);
182 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
);
183 int manager_recv(Manager
*m
, int fd
, DnsProtocol protocol
, DnsPacket
**ret
);
185 int manager_find_ifindex(Manager
*m
, int family
, const union in_addr_union
*in_addr
);
186 LinkAddress
* manager_find_link_address(Manager
*m
, int family
, const union in_addr_union
*in_addr
);
188 void manager_refresh_rrs(Manager
*m
);
189 int manager_next_hostname(Manager
*m
);
191 bool manager_packet_from_local_address(Manager
*m
, DnsPacket
*p
);
192 bool manager_packet_from_our_transaction(Manager
*m
, DnsPacket
*p
);
194 DnsScope
* manager_find_scope(Manager
*m
, DnsPacket
*p
);
196 void manager_verify_all(Manager
*m
);
198 DEFINE_TRIVIAL_CLEANUP_FUNC(Manager
*, manager_free
);
200 /* For some reason we need some extra cmsg space on some kernels/archs. One of those days we need to figure out why */
201 #define EXTRA_CMSG_SPACE 1024
203 int manager_is_own_hostname(Manager
*m
, const char *name
);
205 int manager_compile_dns_servers(Manager
*m
, OrderedSet
**servers
);
206 int manager_compile_search_domains(Manager
*m
, OrderedSet
**domains
, int filter_route
);
208 DnssecMode
manager_get_dnssec_mode(Manager
*m
);
209 bool manager_dnssec_supported(Manager
*m
);
211 DnsOverTlsMode
manager_get_dns_over_tls_mode(Manager
*m
);
213 void manager_dnssec_verdict(Manager
*m
, DnssecVerdict verdict
, const DnsResourceKey
*key
);
215 bool manager_routable(Manager
*m
);
217 void manager_flush_caches(Manager
*m
, int log_level
);
218 void manager_reset_server_features(Manager
*m
);
220 void manager_cleanup_saved_user(Manager
*m
);
222 bool manager_next_dnssd_names(Manager
*m
);
224 bool manager_server_is_stub(Manager
*m
, DnsServer
*s
);
226 int socket_disable_pmtud(int fd
, int af
);
228 int dns_manager_dump_statistics_json(Manager
*m
, JsonVariant
**ret
);
230 void dns_manager_reset_statistics(Manager
*m
);