]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/resolve/resolved-manager.h
resolved: split out calls to compile full list of dns servers and search domains
[thirdparty/systemd.git] / src / resolve / resolved-manager.h
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3 #pragma once
4
5 /***
6 This file is part of systemd.
7
8 Copyright 2014 Tom Gundersen <teg@jklm.no>
9
10 systemd is free software; you can redistribute it and/or modify it
11 under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14
15 systemd is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Lesser General Public License for more details.
19
20 You should have received a copy of the GNU Lesser General Public License
21 along with systemd; If not, see <http://www.gnu.org/licenses/>.
22 ***/
23
24 #include "sd-event.h"
25 #include "sd-netlink.h"
26 #include "sd-network.h"
27
28 #include "hashmap.h"
29 #include "list.h"
30 #include "ordered-set.h"
31
32 typedef struct Manager Manager;
33 typedef enum Support Support;
34
35 enum Support {
36 SUPPORT_NO,
37 SUPPORT_YES,
38 SUPPORT_RESOLVE,
39 _SUPPORT_MAX,
40 _SUPPORT_INVALID = -1
41 };
42
43 #include "resolved-dns-query.h"
44 #include "resolved-dns-search-domain.h"
45 #include "resolved-dns-server.h"
46 #include "resolved-dns-stream.h"
47 #include "resolved-link.h"
48
49 #define MANAGER_SEARCH_DOMAINS_MAX 32
50 #define MANAGER_DNS_SERVERS_MAX 32
51
52 struct Manager {
53 sd_event *event;
54
55 Support llmnr_support;
56
57 /* Network */
58 Hashmap *links;
59
60 sd_netlink *rtnl;
61 sd_event_source *rtnl_event_source;
62
63 sd_network_monitor *network_monitor;
64 sd_event_source *network_event_source;
65
66 /* DNS query management */
67 Hashmap *dns_transactions;
68 LIST_HEAD(DnsQuery, dns_queries);
69 unsigned n_dns_queries;
70
71 LIST_HEAD(DnsStream, dns_streams);
72 unsigned n_dns_streams;
73
74 /* Unicast dns */
75 LIST_HEAD(DnsServer, dns_servers);
76 LIST_HEAD(DnsServer, fallback_dns_servers);
77 unsigned n_dns_servers; /* counts both main and fallback */
78 DnsServer *current_dns_server;
79
80 LIST_HEAD(DnsSearchDomain, search_domains);
81 unsigned n_search_domains;
82
83 bool need_builtin_fallbacks:1;
84
85 bool read_resolv_conf:1;
86 usec_t resolv_conf_mtime;
87
88 LIST_HEAD(DnsScope, dns_scopes);
89 DnsScope *unicast_scope;
90
91 /* LLMNR */
92 int llmnr_ipv4_udp_fd;
93 int llmnr_ipv6_udp_fd;
94 int llmnr_ipv4_tcp_fd;
95 int llmnr_ipv6_tcp_fd;
96
97 sd_event_source *llmnr_ipv4_udp_event_source;
98 sd_event_source *llmnr_ipv6_udp_event_source;
99 sd_event_source *llmnr_ipv4_tcp_event_source;
100 sd_event_source *llmnr_ipv6_tcp_event_source;
101
102 /* dbus */
103 sd_bus *bus;
104 sd_event_source *bus_retry_event_source;
105
106 /* The hostname we publish on LLMNR and mDNS */
107 char *llmnr_hostname;
108 char *mdns_hostname;
109 DnsResourceKey *llmnr_host_ipv4_key;
110 DnsResourceKey *llmnr_host_ipv6_key;
111
112 /* Watch the system hostname */
113 int hostname_fd;
114 sd_event_source *hostname_event_source;
115
116 /* Watch for system suspends */
117 sd_bus_slot *prepare_for_sleep_slot;
118
119 sd_event_source *sigusr1_event_source;
120 };
121
122 /* Manager */
123
124 int manager_new(Manager **ret);
125 Manager* manager_free(Manager *m);
126
127 int manager_start(Manager *m);
128
129 uint32_t manager_find_mtu(Manager *m);
130
131 int manager_write(Manager *m, int fd, DnsPacket *p);
132 int manager_send(Manager *m, int fd, int ifindex, int family, const union in_addr_union *addr, uint16_t port, DnsPacket *p);
133 int manager_recv(Manager *m, int fd, DnsProtocol protocol, DnsPacket **ret);
134
135 int manager_find_ifindex(Manager *m, int family, const union in_addr_union *in_addr);
136 LinkAddress* manager_find_link_address(Manager *m, int family, const union in_addr_union *in_addr);
137
138 void manager_refresh_rrs(Manager *m);
139 int manager_next_hostname(Manager *m);
140
141 bool manager_our_packet(Manager *m, DnsPacket *p);
142 DnsScope* manager_find_scope(Manager *m, DnsPacket *p);
143
144 void manager_verify_all(Manager *m);
145
146 DEFINE_TRIVIAL_CLEANUP_FUNC(Manager*, manager_free);
147
148 #define EXTRA_CMSG_SPACE 1024
149
150 int manager_is_own_hostname(Manager *m, const char *name);
151
152 int manager_compile_dns_servers(Manager *m, OrderedSet **servers);
153 int manager_compile_search_domains(Manager *m, OrderedSet **domains);
154
155 const char* support_to_string(Support p) _const_;
156 int support_from_string(const char *s) _pure_;