]>
Commit | Line | Data |
---|---|---|
091a364c TG |
1 | /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ |
2 | ||
74b2466e LP |
3 | #pragma once |
4 | ||
091a364c TG |
5 | /*** |
6 | This file is part of systemd. | |
7 | ||
4e945a6f | 8 | Copyright 2014 Tom Gundersen <teg@jklm.no> |
091a364c TG |
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 | ||
091a364c | 24 | #include "sd-event.h" |
1c4baffc | 25 | #include "sd-netlink.h" |
71d35b6b TA |
26 | #include "sd-network.h" |
27 | ||
74b2466e | 28 | #include "hashmap.h" |
71d35b6b | 29 | #include "list.h" |
9176a57c | 30 | #include "ordered-set.h" |
091a364c | 31 | |
091a364c | 32 | typedef struct Manager Manager; |
19b50b5b | 33 | typedef enum Support Support; |
091a364c | 34 | |
19b50b5b | 35 | enum Support { |
4e945a6f LP |
36 | SUPPORT_NO, |
37 | SUPPORT_YES, | |
38 | SUPPORT_RESOLVE, | |
39 | _SUPPORT_MAX, | |
40 | _SUPPORT_INVALID = -1 | |
19b50b5b LP |
41 | }; |
42 | ||
43 | #include "resolved-dns-query.h" | |
a51c1048 LP |
44 | #include "resolved-dns-search-domain.h" |
45 | #include "resolved-dns-server.h" | |
19b50b5b | 46 | #include "resolved-dns-stream.h" |
0d2cd476 | 47 | #include "resolved-dns-trust-anchor.h" |
19b50b5b | 48 | #include "resolved-link.h" |
4e945a6f | 49 | |
eed857b7 LP |
50 | #define MANAGER_SEARCH_DOMAINS_MAX 32 |
51 | #define MANAGER_DNS_SERVERS_MAX 32 | |
52 | ||
091a364c TG |
53 | struct Manager { |
54 | sd_event *event; | |
55 | ||
4e945a6f | 56 | Support llmnr_support; |
bc7702b0 | 57 | Support mdns_support; |
1716f6dc LP |
58 | |
59 | /* Network */ | |
74b2466e LP |
60 | Hashmap *links; |
61 | ||
1c4baffc | 62 | sd_netlink *rtnl; |
74b2466e LP |
63 | sd_event_source *rtnl_event_source; |
64 | ||
091a364c | 65 | sd_network_monitor *network_monitor; |
74b2466e LP |
66 | sd_event_source *network_event_source; |
67 | ||
1716f6dc | 68 | /* DNS query management */ |
ec2c5e43 | 69 | Hashmap *dns_transactions; |
1716f6dc LP |
70 | LIST_HEAD(DnsQuery, dns_queries); |
71 | unsigned n_dns_queries; | |
72 | ||
623a4c97 LP |
73 | LIST_HEAD(DnsStream, dns_streams); |
74 | unsigned n_dns_streams; | |
75 | ||
1716f6dc | 76 | /* Unicast dns */ |
74b2466e | 77 | LIST_HEAD(DnsServer, dns_servers); |
4e945a6f | 78 | LIST_HEAD(DnsServer, fallback_dns_servers); |
eed857b7 | 79 | unsigned n_dns_servers; /* counts both main and fallback */ |
74b2466e LP |
80 | DnsServer *current_dns_server; |
81 | ||
a51c1048 | 82 | LIST_HEAD(DnsSearchDomain, search_domains); |
eed857b7 | 83 | unsigned n_search_domains; |
a51c1048 | 84 | |
00fa60ae | 85 | bool need_builtin_fallbacks:1; |
a51c1048 | 86 | |
00fa60ae | 87 | bool read_resolv_conf:1; |
5cb36f41 LP |
88 | usec_t resolv_conf_mtime; |
89 | ||
0d2cd476 LP |
90 | DnsTrustAnchor trust_anchor; |
91 | ||
74b2466e LP |
92 | LIST_HEAD(DnsScope, dns_scopes); |
93 | DnsScope *unicast_scope; | |
94 | ||
1716f6dc LP |
95 | /* LLMNR */ |
96 | int llmnr_ipv4_udp_fd; | |
97 | int llmnr_ipv6_udp_fd; | |
623a4c97 LP |
98 | int llmnr_ipv4_tcp_fd; |
99 | int llmnr_ipv6_tcp_fd; | |
1716f6dc LP |
100 | |
101 | sd_event_source *llmnr_ipv4_udp_event_source; | |
102 | sd_event_source *llmnr_ipv6_udp_event_source; | |
623a4c97 LP |
103 | sd_event_source *llmnr_ipv4_tcp_event_source; |
104 | sd_event_source *llmnr_ipv6_tcp_event_source; | |
1716f6dc | 105 | |
bc7702b0 DM |
106 | /* mDNS */ |
107 | int mdns_ipv4_fd; | |
108 | int mdns_ipv6_fd; | |
109 | ||
110 | sd_event_source *mdns_ipv4_event_source; | |
111 | sd_event_source *mdns_ipv6_event_source; | |
112 | ||
74b2466e LP |
113 | /* dbus */ |
114 | sd_bus *bus; | |
115 | sd_event_source *bus_retry_event_source; | |
623a4c97 LP |
116 | |
117 | /* The hostname we publish on LLMNR and mDNS */ | |
78c6a153 LP |
118 | char *llmnr_hostname; |
119 | char *mdns_hostname; | |
120 | DnsResourceKey *llmnr_host_ipv4_key; | |
121 | DnsResourceKey *llmnr_host_ipv6_key; | |
eb60f9cd LP |
122 | |
123 | /* Watch the system hostname */ | |
124 | int hostname_fd; | |
125 | sd_event_source *hostname_event_source; | |
902bb5d8 LP |
126 | |
127 | /* Watch for system suspends */ | |
128 | sd_bus_slot *prepare_for_sleep_slot; | |
4d506d6b LP |
129 | |
130 | sd_event_source *sigusr1_event_source; | |
091a364c TG |
131 | }; |
132 | ||
133 | /* Manager */ | |
134 | ||
135 | int manager_new(Manager **ret); | |
74b2466e LP |
136 | Manager* manager_free(Manager *m); |
137 | ||
edc501d4 | 138 | int manager_start(Manager *m); |
74b2466e | 139 | |
e1c95994 | 140 | uint32_t manager_find_mtu(Manager *m); |
091a364c | 141 | |
72290734 | 142 | int manager_write(Manager *m, int fd, DnsPacket *p); |
623a4c97 | 143 | int manager_send(Manager *m, int fd, int ifindex, int family, const union in_addr_union *addr, uint16_t port, DnsPacket *p); |
1716f6dc | 144 | int manager_recv(Manager *m, int fd, DnsProtocol protocol, DnsPacket **ret); |
74b2466e | 145 | |
623a4c97 | 146 | int manager_find_ifindex(Manager *m, int family, const union in_addr_union *in_addr); |
4e945a6f | 147 | LinkAddress* manager_find_link_address(Manager *m, int family, const union in_addr_union *in_addr); |
ec2c5e43 | 148 | |
eb60f9cd | 149 | void manager_refresh_rrs(Manager *m); |
ec2c5e43 | 150 | int manager_next_hostname(Manager *m); |
74b2466e | 151 | |
a4076574 LP |
152 | bool manager_our_packet(Manager *m, DnsPacket *p); |
153 | DnsScope* manager_find_scope(Manager *m, DnsPacket *p); | |
091a364c | 154 | |
902bb5d8 LP |
155 | void manager_verify_all(Manager *m); |
156 | ||
091a364c | 157 | DEFINE_TRIVIAL_CLEANUP_FUNC(Manager*, manager_free); |
091a364c | 158 | |
623a4c97 | 159 | #define EXTRA_CMSG_SPACE 1024 |
4e945a6f | 160 | |
78c6a153 LP |
161 | int manager_is_own_hostname(Manager *m, const char *name); |
162 | ||
9176a57c LP |
163 | int manager_compile_dns_servers(Manager *m, OrderedSet **servers); |
164 | int manager_compile_search_domains(Manager *m, OrderedSet **domains); | |
165 | ||
4e945a6f LP |
166 | const char* support_to_string(Support p) _const_; |
167 | int support_from_string(const char *s) _pure_; |