]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/resolve/resolved-manager.h
resolved: automatically forget all learnt DNS server information when the network...
[thirdparty/systemd.git] / src / resolve / resolved-manager.h
1 #pragma once
2
3 /***
4 This file is part of systemd.
5
6 Copyright 2014 Tom Gundersen <teg@jklm.no>
7
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
12
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
20 ***/
21
22 #include "sd-event.h"
23 #include "sd-netlink.h"
24 #include "sd-network.h"
25
26 #include "hashmap.h"
27 #include "list.h"
28 #include "ordered-set.h"
29 #include "resolve-util.h"
30
31 typedef struct Manager Manager;
32
33 #include "resolved-conf.h"
34 #include "resolved-dns-query.h"
35 #include "resolved-dns-search-domain.h"
36 #include "resolved-dns-server.h"
37 #include "resolved-dns-stream.h"
38 #include "resolved-dns-trust-anchor.h"
39 #include "resolved-link.h"
40
41 #define MANAGER_SEARCH_DOMAINS_MAX 32
42 #define MANAGER_DNS_SERVERS_MAX 32
43
44 struct Manager {
45 sd_event *event;
46
47 ResolveSupport llmnr_support;
48 ResolveSupport mdns_support;
49 DnssecMode dnssec_mode;
50 bool enable_cache;
51 DnsStubListenerMode dns_stub_listener_mode;
52
53 /* Network */
54 Hashmap *links;
55
56 sd_netlink *rtnl;
57 sd_event_source *rtnl_event_source;
58
59 sd_network_monitor *network_monitor;
60 sd_event_source *network_event_source;
61
62 /* DNS query management */
63 Hashmap *dns_transactions;
64 LIST_HEAD(DnsQuery, dns_queries);
65 unsigned n_dns_queries;
66
67 LIST_HEAD(DnsStream, dns_streams);
68 unsigned n_dns_streams;
69
70 /* Unicast dns */
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;
75
76 LIST_HEAD(DnsSearchDomain, search_domains);
77 unsigned n_search_domains;
78
79 bool need_builtin_fallbacks:1;
80
81 bool read_resolv_conf:1;
82 usec_t resolv_conf_mtime;
83
84 DnsTrustAnchor trust_anchor;
85
86 LIST_HEAD(DnsScope, dns_scopes);
87 DnsScope *unicast_scope;
88
89 /* LLMNR */
90 int llmnr_ipv4_udp_fd;
91 int llmnr_ipv6_udp_fd;
92 int llmnr_ipv4_tcp_fd;
93 int llmnr_ipv6_tcp_fd;
94
95 sd_event_source *llmnr_ipv4_udp_event_source;
96 sd_event_source *llmnr_ipv6_udp_event_source;
97 sd_event_source *llmnr_ipv4_tcp_event_source;
98 sd_event_source *llmnr_ipv6_tcp_event_source;
99
100 /* mDNS */
101 int mdns_ipv4_fd;
102 int mdns_ipv6_fd;
103
104 sd_event_source *mdns_ipv4_event_source;
105 sd_event_source *mdns_ipv6_event_source;
106
107 /* dbus */
108 sd_bus *bus;
109 sd_event_source *bus_retry_event_source;
110
111 /* The hostname we publish on LLMNR and mDNS */
112 char *full_hostname;
113 char *llmnr_hostname;
114 char *mdns_hostname;
115 DnsResourceKey *llmnr_host_ipv4_key;
116 DnsResourceKey *llmnr_host_ipv6_key;
117 DnsResourceKey *mdns_host_ipv4_key;
118 DnsResourceKey *mdns_host_ipv6_key;
119
120 /* Watch the system hostname */
121 int hostname_fd;
122 sd_event_source *hostname_event_source;
123
124 /* Watch for system suspends */
125 sd_bus_slot *prepare_for_sleep_slot;
126
127 sd_event_source *sigusr1_event_source;
128 sd_event_source *sigusr2_event_source;
129
130 unsigned n_transactions_total;
131 unsigned n_dnssec_verdict[_DNSSEC_VERDICT_MAX];
132
133 /* Data from /etc/hosts */
134 Set* etc_hosts_by_address;
135 Hashmap* etc_hosts_by_name;
136 usec_t etc_hosts_last, etc_hosts_mtime;
137
138 /* Local DNS stub on 127.0.0.53:53 */
139 int dns_stub_udp_fd;
140 int dns_stub_tcp_fd;
141
142 sd_event_source *dns_stub_udp_event_source;
143 sd_event_source *dns_stub_tcp_event_source;
144 };
145
146 /* Manager */
147
148 int manager_new(Manager **ret);
149 Manager* manager_free(Manager *m);
150
151 int manager_start(Manager *m);
152
153 uint32_t manager_find_mtu(Manager *m);
154
155 int manager_write(Manager *m, int fd, DnsPacket *p);
156 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);
157 int manager_recv(Manager *m, int fd, DnsProtocol protocol, DnsPacket **ret);
158
159 int manager_find_ifindex(Manager *m, int family, const union in_addr_union *in_addr);
160 LinkAddress* manager_find_link_address(Manager *m, int family, const union in_addr_union *in_addr);
161
162 void manager_refresh_rrs(Manager *m);
163 int manager_next_hostname(Manager *m);
164
165 bool manager_our_packet(Manager *m, DnsPacket *p);
166 DnsScope* manager_find_scope(Manager *m, DnsPacket *p);
167
168 void manager_verify_all(Manager *m);
169
170 DEFINE_TRIVIAL_CLEANUP_FUNC(Manager*, manager_free);
171
172 #define EXTRA_CMSG_SPACE 1024
173
174 int manager_is_own_hostname(Manager *m, const char *name);
175
176 int manager_compile_dns_servers(Manager *m, OrderedSet **servers);
177 int manager_compile_search_domains(Manager *m, OrderedSet **domains, int filter_route);
178
179 DnssecMode manager_get_dnssec_mode(Manager *m);
180 bool manager_dnssec_supported(Manager *m);
181
182 void manager_dnssec_verdict(Manager *m, DnssecVerdict verdict, const DnsResourceKey *key);
183
184 bool manager_routable(Manager *m, int family);
185
186 void manager_flush_caches(Manager *m);
187 void manager_reset_server_features(Manager *m);
188
189 void manager_cleanup_saved_user(Manager *m);