]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/resolve/resolved-manager.h
Merge pull request #7411 from joergsteffens/tapechanger
[thirdparty/systemd.git] / src / resolve / resolved-manager.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 #pragma once
3
4 #include "sd-event.h"
5 #include "sd-netlink.h"
6 #include "sd-network.h"
7
8 #include "hashmap.h"
9 #include "list.h"
10 #include "ordered-set.h"
11 #include "resolve-util.h"
12
13 typedef struct Manager Manager;
14
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"
22
23 #define MANAGER_SEARCH_DOMAINS_MAX 32
24 #define MANAGER_DNS_SERVERS_MAX 32
25
26 typedef struct EtcHosts {
27 Hashmap *by_address;
28 Hashmap *by_name;
29 Set *no_address;
30 } EtcHosts;
31
32 struct Manager {
33 sd_event *event;
34
35 ResolveSupport llmnr_support;
36 ResolveSupport mdns_support;
37 DnssecMode dnssec_mode;
38 DnsOverTlsMode dns_over_tls_mode;
39 bool enable_cache;
40 DnsStubListenerMode dns_stub_listener_mode;
41
42 /* Network */
43 Hashmap *links;
44
45 sd_netlink *rtnl;
46 sd_event_source *rtnl_event_source;
47
48 sd_network_monitor *network_monitor;
49 sd_event_source *network_event_source;
50
51 /* DNS query management */
52 Hashmap *dns_transactions;
53 LIST_HEAD(DnsQuery, dns_queries);
54 unsigned n_dns_queries;
55
56 LIST_HEAD(DnsStream, dns_streams);
57 unsigned n_dns_streams;
58
59 /* Unicast dns */
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;
64
65 LIST_HEAD(DnsSearchDomain, search_domains);
66 unsigned n_search_domains;
67
68 bool need_builtin_fallbacks:1;
69
70 bool read_resolv_conf:1;
71 usec_t resolv_conf_mtime;
72
73 DnsTrustAnchor trust_anchor;
74
75 LIST_HEAD(DnsScope, dns_scopes);
76 DnsScope *unicast_scope;
77
78 /* LLMNR */
79 int llmnr_ipv4_udp_fd;
80 int llmnr_ipv6_udp_fd;
81 int llmnr_ipv4_tcp_fd;
82 int llmnr_ipv6_tcp_fd;
83
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;
88
89 /* mDNS */
90 int mdns_ipv4_fd;
91 int mdns_ipv6_fd;
92
93 /* DNS-SD */
94 Hashmap *dnssd_services;
95
96 sd_event_source *mdns_ipv4_event_source;
97 sd_event_source *mdns_ipv6_event_source;
98
99 /* dbus */
100 sd_bus *bus;
101
102 /* The hostname we publish on LLMNR and mDNS */
103 char *full_hostname;
104 char *llmnr_hostname;
105 char *mdns_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;
110
111 /* Watch the system hostname */
112 int hostname_fd;
113 sd_event_source *hostname_event_source;
114
115 sd_event_source *sigusr1_event_source;
116 sd_event_source *sigusr2_event_source;
117 sd_event_source *sigrtmin1_event_source;
118
119 unsigned n_transactions_total;
120 unsigned n_dnssec_verdict[_DNSSEC_VERDICT_MAX];
121
122 /* Data from /etc/hosts */
123 EtcHosts etc_hosts;
124 usec_t etc_hosts_last, etc_hosts_mtime;
125 bool read_etc_hosts;
126
127 /* Local DNS stub on 127.0.0.53:53 */
128 int dns_stub_udp_fd;
129 int dns_stub_tcp_fd;
130
131 sd_event_source *dns_stub_udp_event_source;
132 sd_event_source *dns_stub_tcp_event_source;
133
134 Hashmap *polkit_registry;
135 };
136
137 /* Manager */
138
139 int manager_new(Manager **ret);
140 Manager* manager_free(Manager *m);
141
142 int manager_start(Manager *m);
143
144 uint32_t manager_find_mtu(Manager *m);
145
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);
149
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);
152
153 void manager_refresh_rrs(Manager *m);
154 int manager_next_hostname(Manager *m);
155
156 bool manager_our_packet(Manager *m, DnsPacket *p);
157 DnsScope* manager_find_scope(Manager *m, DnsPacket *p);
158
159 void manager_verify_all(Manager *m);
160
161 DEFINE_TRIVIAL_CLEANUP_FUNC(Manager*, manager_free);
162
163 #define EXTRA_CMSG_SPACE 1024
164
165 int manager_is_own_hostname(Manager *m, const char *name);
166
167 int manager_compile_dns_servers(Manager *m, OrderedSet **servers);
168 int manager_compile_search_domains(Manager *m, OrderedSet **domains, int filter_route);
169
170 DnssecMode manager_get_dnssec_mode(Manager *m);
171 bool manager_dnssec_supported(Manager *m);
172
173 DnsOverTlsMode manager_get_dns_over_tls_mode(Manager *m);
174
175 void manager_dnssec_verdict(Manager *m, DnssecVerdict verdict, const DnsResourceKey *key);
176
177 bool manager_routable(Manager *m, int family);
178
179 void manager_flush_caches(Manager *m);
180 void manager_reset_server_features(Manager *m);
181
182 void manager_cleanup_saved_user(Manager *m);
183
184 bool manager_next_dnssd_names(Manager *m);