]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/resolve/resolved-manager.h
resolved: automatically forget all learnt DNS server information when the network...
[thirdparty/systemd.git] / src / resolve / resolved-manager.h
CommitLineData
74b2466e
LP
1#pragma once
2
091a364c
TG
3/***
4 This file is part of systemd.
5
4e945a6f 6 Copyright 2014 Tom Gundersen <teg@jklm.no>
091a364c
TG
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
091a364c 22#include "sd-event.h"
1c4baffc 23#include "sd-netlink.h"
71d35b6b
TA
24#include "sd-network.h"
25
74b2466e 26#include "hashmap.h"
71d35b6b 27#include "list.h"
9176a57c 28#include "ordered-set.h"
af49ca27 29#include "resolve-util.h"
091a364c 30
091a364c 31typedef struct Manager Manager;
19b50b5b 32
1ae43295 33#include "resolved-conf.h"
19b50b5b 34#include "resolved-dns-query.h"
a51c1048
LP
35#include "resolved-dns-search-domain.h"
36#include "resolved-dns-server.h"
19b50b5b 37#include "resolved-dns-stream.h"
0d2cd476 38#include "resolved-dns-trust-anchor.h"
19b50b5b 39#include "resolved-link.h"
4e945a6f 40
eed857b7
LP
41#define MANAGER_SEARCH_DOMAINS_MAX 32
42#define MANAGER_DNS_SERVERS_MAX 32
43
091a364c
TG
44struct Manager {
45 sd_event *event;
46
af49ca27
LP
47 ResolveSupport llmnr_support;
48 ResolveSupport mdns_support;
ad6c0475 49 DnssecMode dnssec_mode;
ceeddf79 50 bool enable_cache;
1ae43295 51 DnsStubListenerMode dns_stub_listener_mode;
1716f6dc
LP
52
53 /* Network */
74b2466e
LP
54 Hashmap *links;
55
1c4baffc 56 sd_netlink *rtnl;
74b2466e
LP
57 sd_event_source *rtnl_event_source;
58
091a364c 59 sd_network_monitor *network_monitor;
74b2466e
LP
60 sd_event_source *network_event_source;
61
1716f6dc 62 /* DNS query management */
ec2c5e43 63 Hashmap *dns_transactions;
1716f6dc
LP
64 LIST_HEAD(DnsQuery, dns_queries);
65 unsigned n_dns_queries;
66
623a4c97
LP
67 LIST_HEAD(DnsStream, dns_streams);
68 unsigned n_dns_streams;
69
1716f6dc 70 /* Unicast dns */
74b2466e 71 LIST_HEAD(DnsServer, dns_servers);
4e945a6f 72 LIST_HEAD(DnsServer, fallback_dns_servers);
eed857b7 73 unsigned n_dns_servers; /* counts both main and fallback */
74b2466e
LP
74 DnsServer *current_dns_server;
75
a51c1048 76 LIST_HEAD(DnsSearchDomain, search_domains);
eed857b7 77 unsigned n_search_domains;
a51c1048 78
00fa60ae 79 bool need_builtin_fallbacks:1;
a51c1048 80
00fa60ae 81 bool read_resolv_conf:1;
5cb36f41
LP
82 usec_t resolv_conf_mtime;
83
0d2cd476
LP
84 DnsTrustAnchor trust_anchor;
85
74b2466e
LP
86 LIST_HEAD(DnsScope, dns_scopes);
87 DnsScope *unicast_scope;
88
1716f6dc
LP
89 /* LLMNR */
90 int llmnr_ipv4_udp_fd;
91 int llmnr_ipv6_udp_fd;
623a4c97
LP
92 int llmnr_ipv4_tcp_fd;
93 int llmnr_ipv6_tcp_fd;
1716f6dc
LP
94
95 sd_event_source *llmnr_ipv4_udp_event_source;
96 sd_event_source *llmnr_ipv6_udp_event_source;
623a4c97
LP
97 sd_event_source *llmnr_ipv4_tcp_event_source;
98 sd_event_source *llmnr_ipv6_tcp_event_source;
1716f6dc 99
bc7702b0
DM
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
74b2466e
LP
107 /* dbus */
108 sd_bus *bus;
109 sd_event_source *bus_retry_event_source;
623a4c97
LP
110
111 /* The hostname we publish on LLMNR and mDNS */
e96de0ce 112 char *full_hostname;
78c6a153
LP
113 char *llmnr_hostname;
114 char *mdns_hostname;
115 DnsResourceKey *llmnr_host_ipv4_key;
116 DnsResourceKey *llmnr_host_ipv6_key;
400cb36e
DR
117 DnsResourceKey *mdns_host_ipv4_key;
118 DnsResourceKey *mdns_host_ipv6_key;
eb60f9cd
LP
119
120 /* Watch the system hostname */
121 int hostname_fd;
122 sd_event_source *hostname_event_source;
902bb5d8
LP
123
124 /* Watch for system suspends */
125 sd_bus_slot *prepare_for_sleep_slot;
4d506d6b
LP
126
127 sd_event_source *sigusr1_event_source;
bc81447e 128 sd_event_source *sigusr2_event_source;
a150ff5e
LP
129
130 unsigned n_transactions_total;
59c5b597 131 unsigned n_dnssec_verdict[_DNSSEC_VERDICT_MAX];
dd0bc0f1
LP
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;
b30bf55d
LP
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;
091a364c
TG
144};
145
146/* Manager */
147
148int manager_new(Manager **ret);
74b2466e
LP
149Manager* manager_free(Manager *m);
150
edc501d4 151int manager_start(Manager *m);
74b2466e 152
e1c95994 153uint32_t manager_find_mtu(Manager *m);
091a364c 154
72290734 155int manager_write(Manager *m, int fd, DnsPacket *p);
b30bf55d 156int 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);
1716f6dc 157int manager_recv(Manager *m, int fd, DnsProtocol protocol, DnsPacket **ret);
74b2466e 158
623a4c97 159int manager_find_ifindex(Manager *m, int family, const union in_addr_union *in_addr);
4e945a6f 160LinkAddress* manager_find_link_address(Manager *m, int family, const union in_addr_union *in_addr);
ec2c5e43 161
eb60f9cd 162void manager_refresh_rrs(Manager *m);
ec2c5e43 163int manager_next_hostname(Manager *m);
74b2466e 164
a4076574
LP
165bool manager_our_packet(Manager *m, DnsPacket *p);
166DnsScope* manager_find_scope(Manager *m, DnsPacket *p);
091a364c 167
902bb5d8
LP
168void manager_verify_all(Manager *m);
169
091a364c 170DEFINE_TRIVIAL_CLEANUP_FUNC(Manager*, manager_free);
091a364c 171
623a4c97 172#define EXTRA_CMSG_SPACE 1024
4e945a6f 173
78c6a153
LP
174int manager_is_own_hostname(Manager *m, const char *name);
175
9176a57c 176int manager_compile_dns_servers(Manager *m, OrderedSet **servers);
6f7da49d 177int manager_compile_search_domains(Manager *m, OrderedSet **domains, int filter_route);
c69fa7e3
LP
178
179DnssecMode manager_get_dnssec_mode(Manager *m);
180bool manager_dnssec_supported(Manager *m);
59c5b597
LP
181
182void manager_dnssec_verdict(Manager *m, DnssecVerdict verdict, const DnsResourceKey *key);
011696f7
LP
183
184bool manager_routable(Manager *m, int family);
ba35662f
LP
185
186void manager_flush_caches(Manager *m);
59c0fd0e 187void manager_reset_server_features(Manager *m);
943ef07c
LP
188
189void manager_cleanup_saved_user(Manager *m);