]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/resolve/resolved-manager.h
resolved: add an option to control the DNS stub listener
[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 *llmnr_hostname;
113 char *mdns_hostname;
114 DnsResourceKey *llmnr_host_ipv4_key;
115 DnsResourceKey *llmnr_host_ipv6_key;
116
117 /* Watch the system hostname */
118 int hostname_fd;
119 sd_event_source *hostname_event_source;
120
121 /* Watch for system suspends */
122 sd_bus_slot *prepare_for_sleep_slot;
123
124 sd_event_source *sigusr1_event_source;
125 sd_event_source *sigusr2_event_source;
126
127 unsigned n_transactions_total;
128 unsigned n_dnssec_verdict[_DNSSEC_VERDICT_MAX];
129
130 /* Data from /etc/hosts */
131 Set* etc_hosts_by_address;
132 Hashmap* etc_hosts_by_name;
133 usec_t etc_hosts_last, etc_hosts_mtime;
134
135 /* Local DNS stub on 127.0.0.53:53 */
136 int dns_stub_udp_fd;
137 int dns_stub_tcp_fd;
138
139 sd_event_source *dns_stub_udp_event_source;
140 sd_event_source *dns_stub_tcp_event_source;
141 };
142
143 /* Manager */
144
145 int manager_new(Manager **ret);
146 Manager* manager_free(Manager *m);
147
148 int manager_start(Manager *m);
149
150 uint32_t manager_find_mtu(Manager *m);
151
152 int manager_write(Manager *m, int fd, DnsPacket *p);
153 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);
154 int manager_recv(Manager *m, int fd, DnsProtocol protocol, DnsPacket **ret);
155
156 int manager_find_ifindex(Manager *m, int family, const union in_addr_union *in_addr);
157 LinkAddress* manager_find_link_address(Manager *m, int family, const union in_addr_union *in_addr);
158
159 void manager_refresh_rrs(Manager *m);
160 int manager_next_hostname(Manager *m);
161
162 bool manager_our_packet(Manager *m, DnsPacket *p);
163 DnsScope* manager_find_scope(Manager *m, DnsPacket *p);
164
165 void manager_verify_all(Manager *m);
166
167 DEFINE_TRIVIAL_CLEANUP_FUNC(Manager*, manager_free);
168
169 #define EXTRA_CMSG_SPACE 1024
170
171 int manager_is_own_hostname(Manager *m, const char *name);
172
173 int manager_compile_dns_servers(Manager *m, OrderedSet **servers);
174 int manager_compile_search_domains(Manager *m, OrderedSet **domains, int filter_route);
175
176 DnssecMode manager_get_dnssec_mode(Manager *m);
177 bool manager_dnssec_supported(Manager *m);
178
179 void manager_dnssec_verdict(Manager *m, DnssecVerdict verdict, const DnsResourceKey *key);
180
181 bool manager_routable(Manager *m, int family);
182
183 void manager_flush_caches(Manager *m);
184
185 void manager_cleanup_saved_user(Manager *m);