chiark / gitweb /
resolved: simplify detection of packets from the loopback device
[elogind.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-rtnl.h"
27 #include "util.h"
28 #include "list.h"
29 #include "in-addr-util.h"
30 #include "hashmap.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-server.h"
45 #include "resolved-dns-scope.h"
46 #include "resolved-dns-stream.h"
47 #include "resolved-link.h"
48
49 struct Manager {
50         sd_event *event;
51
52         Support llmnr_support;
53
54         /* Network */
55         Hashmap *links;
56
57         sd_rtnl *rtnl;
58         sd_event_source *rtnl_event_source;
59
60         sd_network_monitor *network_monitor;
61         sd_event_source *network_event_source;
62
63         /* DNS query management */
64         Hashmap *dns_transactions;
65         LIST_HEAD(DnsQuery, dns_queries);
66         unsigned n_dns_queries;
67
68         LIST_HEAD(DnsStream, dns_streams);
69         unsigned n_dns_streams;
70
71         /* Unicast dns */
72         int dns_ipv4_fd;
73         int dns_ipv6_fd;
74
75         sd_event_source *dns_ipv4_event_source;
76         sd_event_source *dns_ipv6_event_source;
77
78         LIST_HEAD(DnsServer, dns_servers);
79         LIST_HEAD(DnsServer, fallback_dns_servers);
80         DnsServer *current_dns_server;
81
82         bool read_resolv_conf;
83         usec_t resolv_conf_mtime;
84
85         LIST_HEAD(DnsScope, dns_scopes);
86         DnsScope *unicast_scope;
87
88         /* LLMNR */
89         int llmnr_ipv4_udp_fd;
90         int llmnr_ipv6_udp_fd;
91         int llmnr_ipv4_tcp_fd;
92         int llmnr_ipv6_tcp_fd;
93
94         sd_event_source *llmnr_ipv4_udp_event_source;
95         sd_event_source *llmnr_ipv6_udp_event_source;
96         sd_event_source *llmnr_ipv4_tcp_event_source;
97         sd_event_source *llmnr_ipv6_tcp_event_source;
98
99         /* dbus */
100         sd_bus *bus;
101         sd_event_source *bus_retry_event_source;
102
103         /* The hostname we publish on LLMNR and mDNS */
104         char *hostname;
105         DnsResourceKey *host_ipv4_key;
106         DnsResourceKey *host_ipv6_key;
107
108         /* Watch the system hostname */
109         int hostname_fd;
110         sd_event_source *hostname_event_source;
111
112         /* Watch for system suspends */
113         sd_bus_slot *prepare_for_sleep_slot;
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 int manager_read_resolv_conf(Manager *m);
123 int manager_write_resolv_conf(Manager *m);
124
125 DnsServer *manager_set_dns_server(Manager *m, DnsServer *s);
126 DnsServer *manager_find_dns_server(Manager *m, int family, const union in_addr_union *in_addr);
127 DnsServer *manager_get_dns_server(Manager *m);
128 void manager_next_dns_server(Manager *m);
129
130 uint32_t manager_find_mtu(Manager *m);
131
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_dns_ipv4_fd(Manager *m);
136 int manager_dns_ipv6_fd(Manager *m);
137 int manager_llmnr_ipv4_udp_fd(Manager *m);
138 int manager_llmnr_ipv6_udp_fd(Manager *m);
139 int manager_llmnr_ipv4_tcp_fd(Manager *m);
140 int manager_llmnr_ipv6_tcp_fd(Manager *m);
141
142 int manager_find_ifindex(Manager *m, int family, const union in_addr_union *in_addr);
143 LinkAddress* manager_find_link_address(Manager *m, int family, const union in_addr_union *in_addr);
144
145 void manager_refresh_rrs(Manager *m);
146 int manager_next_hostname(Manager *m);
147
148 bool manager_our_packet(Manager *m, DnsPacket *p);
149 DnsScope* manager_find_scope(Manager *m, DnsPacket *p);
150
151 void manager_verify_all(Manager *m);
152
153 void manager_flush_dns_servers(Manager *m, DnsServerType t);
154
155 DEFINE_TRIVIAL_CLEANUP_FUNC(Manager*, manager_free);
156
157 #define EXTRA_CMSG_SPACE 1024
158
159 const char* support_to_string(Support p) _const_;
160 int support_from_string(const char *s) _pure_;