1 /* SPDX-License-Identifier: LGPL-2.1+ */
5 #include "sd-netlink.h"
6 #include "sd-network.h"
10 #include "ordered-set.h"
11 #include "resolve-util.h"
13 typedef struct Manager Manager
;
15 #include "resolved-conf.h"
16 #include "resolved-dns-query.h"
17 #include "resolved-dns-search-domain.h"
18 #include "resolved-dns-server.h"
19 #include "resolved-dns-stream.h"
20 #include "resolved-dns-trust-anchor.h"
21 #include "resolved-link.h"
23 #define MANAGER_SEARCH_DOMAINS_MAX 32
24 #define MANAGER_DNS_SERVERS_MAX 32
26 typedef struct EtcHosts
{
35 ResolveSupport llmnr_support
;
36 ResolveSupport mdns_support
;
37 DnssecMode dnssec_mode
;
38 DnsOverTlsMode dns_over_tls_mode
;
40 DnsStubListenerMode dns_stub_listener_mode
;
46 sd_event_source
*rtnl_event_source
;
48 sd_network_monitor
*network_monitor
;
49 sd_event_source
*network_event_source
;
51 /* DNS query management */
52 Hashmap
*dns_transactions
;
53 LIST_HEAD(DnsQuery
, dns_queries
);
54 unsigned n_dns_queries
;
56 LIST_HEAD(DnsStream
, dns_streams
);
57 unsigned n_dns_streams
;
60 LIST_HEAD(DnsServer
, dns_servers
);
61 LIST_HEAD(DnsServer
, fallback_dns_servers
);
62 unsigned n_dns_servers
; /* counts both main and fallback */
63 DnsServer
*current_dns_server
;
65 LIST_HEAD(DnsSearchDomain
, search_domains
);
66 unsigned n_search_domains
;
68 bool need_builtin_fallbacks
:1;
70 bool read_resolv_conf
:1;
71 usec_t resolv_conf_mtime
;
73 DnsTrustAnchor trust_anchor
;
75 LIST_HEAD(DnsScope
, dns_scopes
);
76 DnsScope
*unicast_scope
;
79 int llmnr_ipv4_udp_fd
;
80 int llmnr_ipv6_udp_fd
;
81 int llmnr_ipv4_tcp_fd
;
82 int llmnr_ipv6_tcp_fd
;
84 sd_event_source
*llmnr_ipv4_udp_event_source
;
85 sd_event_source
*llmnr_ipv6_udp_event_source
;
86 sd_event_source
*llmnr_ipv4_tcp_event_source
;
87 sd_event_source
*llmnr_ipv6_tcp_event_source
;
94 Hashmap
*dnssd_services
;
96 sd_event_source
*mdns_ipv4_event_source
;
97 sd_event_source
*mdns_ipv6_event_source
;
102 /* The hostname we publish on LLMNR and mDNS */
104 char *llmnr_hostname
;
106 DnsResourceKey
*llmnr_host_ipv4_key
;
107 DnsResourceKey
*llmnr_host_ipv6_key
;
108 DnsResourceKey
*mdns_host_ipv4_key
;
109 DnsResourceKey
*mdns_host_ipv6_key
;
111 /* Watch the system hostname */
113 sd_event_source
*hostname_event_source
;
115 sd_event_source
*sigusr1_event_source
;
116 sd_event_source
*sigusr2_event_source
;
117 sd_event_source
*sigrtmin1_event_source
;
119 unsigned n_transactions_total
;
120 unsigned n_dnssec_verdict
[_DNSSEC_VERDICT_MAX
];
122 /* Data from /etc/hosts */
124 usec_t etc_hosts_last
, etc_hosts_mtime
;
127 /* Local DNS stub on 127.0.0.53:53 */
131 sd_event_source
*dns_stub_udp_event_source
;
132 sd_event_source
*dns_stub_tcp_event_source
;
134 Hashmap
*polkit_registry
;
139 int manager_new(Manager
**ret
);
140 Manager
* manager_free(Manager
*m
);
142 int manager_start(Manager
*m
);
144 uint32_t manager_find_mtu(Manager
*m
);
146 int manager_write(Manager
*m
, int fd
, DnsPacket
*p
);
147 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
);
148 int manager_recv(Manager
*m
, int fd
, DnsProtocol protocol
, DnsPacket
**ret
);
150 int manager_find_ifindex(Manager
*m
, int family
, const union in_addr_union
*in_addr
);
151 LinkAddress
* manager_find_link_address(Manager
*m
, int family
, const union in_addr_union
*in_addr
);
153 void manager_refresh_rrs(Manager
*m
);
154 int manager_next_hostname(Manager
*m
);
156 bool manager_our_packet(Manager
*m
, DnsPacket
*p
);
157 DnsScope
* manager_find_scope(Manager
*m
, DnsPacket
*p
);
159 void manager_verify_all(Manager
*m
);
161 DEFINE_TRIVIAL_CLEANUP_FUNC(Manager
*, manager_free
);
163 #define EXTRA_CMSG_SPACE 1024
165 int manager_is_own_hostname(Manager
*m
, const char *name
);
167 int manager_compile_dns_servers(Manager
*m
, OrderedSet
**servers
);
168 int manager_compile_search_domains(Manager
*m
, OrderedSet
**domains
, int filter_route
);
170 DnssecMode
manager_get_dnssec_mode(Manager
*m
);
171 bool manager_dnssec_supported(Manager
*m
);
173 DnsOverTlsMode
manager_get_dns_over_tls_mode(Manager
*m
);
175 void manager_dnssec_verdict(Manager
*m
, DnssecVerdict verdict
, const DnsResourceKey
*key
);
177 bool manager_routable(Manager
*m
, int family
);
179 void manager_flush_caches(Manager
*m
);
180 void manager_reset_server_features(Manager
*m
);
182 void manager_cleanup_saved_user(Manager
*m
);
184 bool manager_next_dnssd_names(Manager
*m
);