]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/resolve/resolved-manager.h
resolved: add a generic DnsSearchDomain concept
[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
31 typedef struct Manager Manager;
32 typedef enum Support Support;
33
34 enum Support {
35 SUPPORT_NO,
36 SUPPORT_YES,
37 SUPPORT_RESOLVE,
38 _SUPPORT_MAX,
39 _SUPPORT_INVALID = -1
40 };
41
42 #include "resolved-dns-query.h"
43 #include "resolved-dns-search-domain.h"
44 #include "resolved-dns-server.h"
45 #include "resolved-dns-stream.h"
46 #include "resolved-link.h"
47
48 struct Manager {
49 sd_event *event;
50
51 Support llmnr_support;
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 DnsServer *current_dns_server;
74
75 LIST_HEAD(DnsSearchDomain, search_domains);
76
77 bool need_builtin_fallbacks:1;
78
79 bool read_resolv_conf:1;
80 usec_t resolv_conf_mtime;
81
82 LIST_HEAD(DnsScope, dns_scopes);
83 DnsScope *unicast_scope;
84
85 /* LLMNR */
86 int llmnr_ipv4_udp_fd;
87 int llmnr_ipv6_udp_fd;
88 int llmnr_ipv4_tcp_fd;
89 int llmnr_ipv6_tcp_fd;
90
91 sd_event_source *llmnr_ipv4_udp_event_source;
92 sd_event_source *llmnr_ipv6_udp_event_source;
93 sd_event_source *llmnr_ipv4_tcp_event_source;
94 sd_event_source *llmnr_ipv6_tcp_event_source;
95
96 /* dbus */
97 sd_bus *bus;
98 sd_event_source *bus_retry_event_source;
99
100 /* The hostname we publish on LLMNR and mDNS */
101 char *llmnr_hostname;
102 char *mdns_hostname;
103 DnsResourceKey *llmnr_host_ipv4_key;
104 DnsResourceKey *llmnr_host_ipv6_key;
105
106 /* Watch the system hostname */
107 int hostname_fd;
108 sd_event_source *hostname_event_source;
109
110 /* Watch for system suspends */
111 sd_bus_slot *prepare_for_sleep_slot;
112
113 sd_event_source *sigusr1_event_source;
114 };
115
116 /* Manager */
117
118 int manager_new(Manager **ret);
119 Manager* manager_free(Manager *m);
120
121 int manager_start(Manager *m);
122
123 uint32_t manager_find_mtu(Manager *m);
124
125 int manager_write(Manager *m, int fd, DnsPacket *p);
126 int manager_send(Manager *m, int fd, int ifindex, int family, const union in_addr_union *addr, uint16_t port, DnsPacket *p);
127 int manager_recv(Manager *m, int fd, DnsProtocol protocol, DnsPacket **ret);
128
129 int manager_find_ifindex(Manager *m, int family, const union in_addr_union *in_addr);
130 LinkAddress* manager_find_link_address(Manager *m, int family, const union in_addr_union *in_addr);
131
132 void manager_refresh_rrs(Manager *m);
133 int manager_next_hostname(Manager *m);
134
135 bool manager_our_packet(Manager *m, DnsPacket *p);
136 DnsScope* manager_find_scope(Manager *m, DnsPacket *p);
137
138 void manager_verify_all(Manager *m);
139
140 DEFINE_TRIVIAL_CLEANUP_FUNC(Manager*, manager_free);
141
142 #define EXTRA_CMSG_SPACE 1024
143
144 int manager_is_own_hostname(Manager *m, const char *name);
145
146 const char* support_to_string(Support p) _const_;
147 int support_from_string(const char *s) _pure_;