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