]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/resolve/resolved-manager.h
23ee1f6bc551fe9b720d9c7255358eff6607c511
[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-stream.h"
44 #include "resolved-link.h"
45
46 struct Manager {
47 sd_event *event;
48
49 Support llmnr_support;
50
51 /* Network */
52 Hashmap *links;
53
54 sd_netlink *rtnl;
55 sd_event_source *rtnl_event_source;
56
57 sd_network_monitor *network_monitor;
58 sd_event_source *network_event_source;
59
60 /* DNS query management */
61 Hashmap *dns_transactions;
62 LIST_HEAD(DnsQuery, dns_queries);
63 unsigned n_dns_queries;
64
65 LIST_HEAD(DnsStream, dns_streams);
66 unsigned n_dns_streams;
67
68 /* Unicast dns */
69 LIST_HEAD(DnsServer, dns_servers);
70 LIST_HEAD(DnsServer, fallback_dns_servers);
71 DnsServer *current_dns_server;
72
73 bool read_resolv_conf;
74 usec_t resolv_conf_mtime;
75
76 LIST_HEAD(DnsScope, dns_scopes);
77 DnsScope *unicast_scope;
78
79 /* LLMNR */
80 int llmnr_ipv4_udp_fd;
81 int llmnr_ipv6_udp_fd;
82 int llmnr_ipv4_tcp_fd;
83 int llmnr_ipv6_tcp_fd;
84
85 sd_event_source *llmnr_ipv4_udp_event_source;
86 sd_event_source *llmnr_ipv6_udp_event_source;
87 sd_event_source *llmnr_ipv4_tcp_event_source;
88 sd_event_source *llmnr_ipv6_tcp_event_source;
89
90 /* dbus */
91 sd_bus *bus;
92 sd_event_source *bus_retry_event_source;
93
94 /* The hostname we publish on LLMNR and mDNS */
95 char *llmnr_hostname;
96 char *mdns_hostname;
97 DnsResourceKey *llmnr_host_ipv4_key;
98 DnsResourceKey *llmnr_host_ipv6_key;
99
100 /* Watch the system hostname */
101 int hostname_fd;
102 sd_event_source *hostname_event_source;
103
104 /* Watch for system suspends */
105 sd_bus_slot *prepare_for_sleep_slot;
106
107 sd_event_source *sigusr1_event_source;
108 };
109
110 /* Manager */
111
112 int manager_new(Manager **ret);
113 Manager* manager_free(Manager *m);
114
115 int manager_start(Manager *m);
116
117 DnsServer *manager_set_dns_server(Manager *m, DnsServer *s);
118 DnsServer *manager_find_dns_server(Manager *m, int family, const union in_addr_union *in_addr);
119 DnsServer *manager_get_dns_server(Manager *m);
120 void manager_next_dns_server(Manager *m);
121
122 uint32_t manager_find_mtu(Manager *m);
123
124 int manager_write(Manager *m, int fd, DnsPacket *p);
125 int manager_send(Manager *m, int fd, int ifindex, int family, const union in_addr_union *addr, uint16_t port, DnsPacket *p);
126 int manager_recv(Manager *m, int fd, DnsProtocol protocol, DnsPacket **ret);
127
128 int manager_find_ifindex(Manager *m, int family, const union in_addr_union *in_addr);
129 LinkAddress* manager_find_link_address(Manager *m, int family, const union in_addr_union *in_addr);
130
131 void manager_refresh_rrs(Manager *m);
132 int manager_next_hostname(Manager *m);
133
134 bool manager_our_packet(Manager *m, DnsPacket *p);
135 DnsScope* manager_find_scope(Manager *m, DnsPacket *p);
136
137 void manager_verify_all(Manager *m);
138
139 DEFINE_TRIVIAL_CLEANUP_FUNC(Manager*, manager_free);
140
141 #define EXTRA_CMSG_SPACE 1024
142
143 int manager_is_own_hostname(Manager *m, const char *name);
144
145 const char* support_to_string(Support p) _const_;
146 int support_from_string(const char *s) _pure_;