]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/resolve/resolved-dns-scope.h
Merge pull request #31621 from poettering/resolved-proxy-do
[thirdparty/systemd.git] / src / resolve / resolved-dns-scope.h
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 #pragma once
3
4 #include "list.h"
5 #include "ratelimit.h"
6
7 typedef struct DnsQueryCandidate DnsQueryCandidate;
8 typedef struct DnsScope DnsScope;
9
10 #include "resolved-dns-cache.h"
11 #include "resolved-dns-dnssec.h"
12 #include "resolved-dns-packet.h"
13 #include "resolved-dns-query.h"
14 #include "resolved-dns-search-domain.h"
15 #include "resolved-dns-server.h"
16 #include "resolved-dns-stream.h"
17 #include "resolved-dns-zone.h"
18
19 typedef enum DnsScopeMatch {
20 DNS_SCOPE_NO,
21 DNS_SCOPE_MAYBE,
22 DNS_SCOPE_YES_BASE, /* Add the number of matching labels to this */
23 DNS_SCOPE_YES_END = DNS_SCOPE_YES_BASE + DNS_N_LABELS_MAX,
24 _DNS_SCOPE_MATCH_MAX,
25 _DNS_SCOPE_MATCH_INVALID = -EINVAL,
26 } DnsScopeMatch;
27
28 struct DnsScope {
29 Manager *manager;
30
31 DnsProtocol protocol;
32 int family;
33
34 /* Copied at scope creation time from the link/manager */
35 DnssecMode dnssec_mode;
36 DnsOverTlsMode dns_over_tls_mode;
37
38 Link *link;
39
40 DnsCache cache;
41 DnsZone zone;
42
43 OrderedHashmap *conflict_queue;
44 sd_event_source *conflict_event_source;
45
46 sd_event_source *announce_event_source;
47
48 sd_event_source *mdns_goodbye_event_source;
49
50 RateLimit ratelimit;
51
52 usec_t resend_timeout;
53 usec_t max_rtt;
54
55 LIST_HEAD(DnsQueryCandidate, query_candidates);
56
57 /* Note that we keep track of ongoing transactions in two ways: once in a hashmap, indexed by the rr
58 * key, and once in a linked list. We use the hashmap to quickly find transactions we can reuse for a
59 * key. But note that there might be multiple transactions for the same key (because the associated
60 * query flags might differ in incompatible ways: e.g. we may not reuse a non-validating transaction
61 * as validating. Hence we maintain a per-key list of transactions, which we iterate through to find
62 * one we can reuse with matching flags. */
63 Hashmap *transactions_by_key;
64 LIST_HEAD(DnsTransaction, transactions);
65
66 LIST_FIELDS(DnsScope, scopes);
67
68 bool announced;
69 };
70
71 int dns_scope_new(Manager *m, DnsScope **ret, Link *l, DnsProtocol p, int family);
72 DnsScope* dns_scope_free(DnsScope *s);
73
74 void dns_scope_packet_received(DnsScope *s, usec_t rtt);
75 void dns_scope_packet_lost(DnsScope *s, usec_t usec);
76
77 int dns_scope_emit_udp(DnsScope *s, int fd, int af, DnsPacket *p);
78 int dns_scope_socket_tcp(DnsScope *s, int family, const union in_addr_union *address, DnsServer *server, uint16_t port, union sockaddr_union *ret_socket_address);
79 int dns_scope_socket_udp(DnsScope *s, DnsServer *server);
80
81 DnsScopeMatch dns_scope_good_domain(DnsScope *s, DnsQuery *q, uint64_t query_flags);
82 bool dns_scope_good_key(DnsScope *s, const DnsResourceKey *key);
83
84 DnsServer *dns_scope_get_dns_server(DnsScope *s);
85 unsigned dns_scope_get_n_dns_servers(DnsScope *s);
86 void dns_scope_next_dns_server(DnsScope *s, DnsServer *if_current);
87
88 int dns_scope_llmnr_membership(DnsScope *s, bool b);
89 int dns_scope_mdns_membership(DnsScope *s, bool b);
90
91 int dns_scope_make_reply_packet(DnsScope *s, uint16_t id, int rcode, DnsQuestion *q, DnsAnswer *answer, DnsAnswer *soa, bool tentative, DnsPacket **ret);
92 void dns_scope_process_query(DnsScope *s, DnsStream *stream, DnsPacket *p);
93
94 DnsTransaction *dns_scope_find_transaction(DnsScope *scope, DnsResourceKey *key, uint64_t query_flags);
95
96 int dns_scope_notify_conflict(DnsScope *scope, DnsResourceRecord *rr);
97 void dns_scope_check_conflicts(DnsScope *scope, DnsPacket *p);
98
99 void dns_scope_dump(DnsScope *s, FILE *f);
100
101 DnsSearchDomain *dns_scope_get_search_domains(DnsScope *s);
102
103 bool dns_scope_name_wants_search_domain(DnsScope *s, const char *name);
104
105 bool dns_scope_network_good(DnsScope *s);
106
107 int dns_scope_ifindex(DnsScope *s);
108
109 int dns_scope_announce(DnsScope *scope, bool goodbye);
110
111 int dns_scope_add_dnssd_services(DnsScope *scope);
112 int dns_scope_remove_dnssd_services(DnsScope *scope);
113
114 bool dns_scope_is_default_route(DnsScope *scope);
115
116 int dns_scope_dump_cache_to_json(DnsScope *scope, JsonVariant **ret);
117
118 int dns_type_suitable_for_protocol(uint16_t type, DnsProtocol protocol);
119 int dns_question_types_suitable_for_protocol(DnsQuestion *q, DnsProtocol protocol);