]>
Commit | Line | Data |
---|---|---|
db9ecf05 | 1 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ |
74b2466e LP |
2 | #pragma once |
3 | ||
68527d30 | 4 | #include "dns-def.h" |
284d7641 | 5 | #include "forward.h" |
74b2466e | 6 | #include "list.h" |
be28f72d | 7 | #include "ratelimit.h" |
68527d30 | 8 | #include "resolve-util.h" |
322345fd | 9 | #include "resolved-dns-cache.h" |
71d35b6b | 10 | #include "resolved-dns-packet.h" |
623a4c97 | 11 | #include "resolved-dns-zone.h" |
284d7641 | 12 | #include "resolved-forward.h" |
74b2466e | 13 | |
74b2466e LP |
14 | typedef enum DnsScopeMatch { |
15 | DNS_SCOPE_NO, | |
da920fe1 | 16 | DNS_SCOPE_LAST_RESORT, |
74b2466e | 17 | DNS_SCOPE_MAYBE, |
a97a3b25 LP |
18 | DNS_SCOPE_YES_BASE, /* Add the number of matching labels to this */ |
19 | DNS_SCOPE_YES_END = DNS_SCOPE_YES_BASE + DNS_N_LABELS_MAX, | |
74b2466e | 20 | _DNS_SCOPE_MATCH_MAX, |
2d93c20e | 21 | _DNS_SCOPE_MATCH_INVALID = -EINVAL, |
74b2466e LP |
22 | } DnsScopeMatch; |
23 | ||
6a198b43 LP |
24 | typedef enum DnsScopeOrigin { |
25 | DNS_SCOPE_GLOBAL, | |
26 | DNS_SCOPE_LINK, | |
7928c0e0 | 27 | DNS_SCOPE_DELEGATE, |
6a198b43 LP |
28 | _DNS_SCOPE_ORIGIN_MAX, |
29 | _DNS_SCOPE_ORIGIN_INVALID = -EINVAL, | |
30 | } DnsScopeOrigin; | |
31 | ||
284d7641 | 32 | typedef struct DnsScope { |
74b2466e LP |
33 | Manager *manager; |
34 | ||
6a198b43 LP |
35 | DnsScopeOrigin origin; |
36 | ||
1716f6dc | 37 | DnsProtocol protocol; |
0dd25fb9 | 38 | int family; |
89307df3 LP |
39 | |
40 | /* Copied at scope creation time from the link/manager */ | |
24710c48 | 41 | DnssecMode dnssec_mode; |
c9299be2 | 42 | DnsOverTlsMode dns_over_tls_mode; |
74b2466e LP |
43 | |
44 | Link *link; | |
7928c0e0 | 45 | DnsDelegate *delegate; |
74b2466e | 46 | |
322345fd | 47 | DnsCache cache; |
623a4c97 | 48 | DnsZone zone; |
322345fd | 49 | |
1e43061b | 50 | OrderedHashmap *conflict_queue; |
a4076574 LP |
51 | sd_event_source *conflict_event_source; |
52 | ||
53fda2bb DR |
53 | sd_event_source *announce_event_source; |
54 | ||
d08566fa VCS |
55 | sd_event_source *mdns_goodbye_event_source; |
56 | ||
aea2429d LP |
57 | RateLimit ratelimit; |
58 | ||
9df3ba6c TG |
59 | usec_t resend_timeout; |
60 | usec_t max_rtt; | |
61 | ||
801ad6a6 | 62 | LIST_HEAD(DnsQueryCandidate, query_candidates); |
74b2466e | 63 | |
775ae354 LP |
64 | /* Note that we keep track of ongoing transactions in two ways: once in a hashmap, indexed by the rr |
65 | * key, and once in a linked list. We use the hashmap to quickly find transactions we can reuse for a | |
66 | * key. But note that there might be multiple transactions for the same key (because the associated | |
67 | * query flags might differ in incompatible ways: e.g. we may not reuse a non-validating transaction | |
68 | * as validating. Hence we maintain a per-key list of transactions, which we iterate through to find | |
69 | * one we can reuse with matching flags. */ | |
f9ebb22a LP |
70 | Hashmap *transactions_by_key; |
71 | LIST_HEAD(DnsTransaction, transactions); | |
72 | ||
74b2466e | 73 | LIST_FIELDS(DnsScope, scopes); |
ebfdf45a ZJS |
74 | |
75 | bool announced; | |
284d7641 | 76 | } DnsScope; |
74b2466e | 77 | |
7928c0e0 | 78 | int dns_scope_new(Manager *m, DnsScope **ret, DnsScopeOrigin origin, Link *link, DnsDelegate *delegate, DnsProtocol protocol, int family); |
74b2466e LP |
79 | DnsScope* dns_scope_free(DnsScope *s); |
80 | ||
9df3ba6c TG |
81 | void dns_scope_packet_received(DnsScope *s, usec_t rtt); |
82 | void dns_scope_packet_lost(DnsScope *s, usec_t usec); | |
83 | ||
d79677ab | 84 | int dns_scope_emit_udp(DnsScope *s, int fd, int af, DnsPacket *p); |
91ccab1e | 85 | 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); |
da9de738 | 86 | int dns_scope_socket_udp(DnsScope *s, DnsServer *server); |
ad867662 | 87 | |
d0eae64c | 88 | DnsScopeMatch dns_scope_good_domain(DnsScope *s, DnsQuery *q, uint64_t query_flags); |
011696f7 | 89 | bool dns_scope_good_key(DnsScope *s, const DnsResourceKey *key); |
74b2466e | 90 | |
2c27fbca | 91 | DnsServer *dns_scope_get_dns_server(DnsScope *s); |
44db02d0 | 92 | unsigned dns_scope_get_n_dns_servers(DnsScope *s); |
5e8bc852 | 93 | void dns_scope_next_dns_server(DnsScope *s, DnsServer *if_current); |
1716f6dc LP |
94 | |
95 | int dns_scope_llmnr_membership(DnsScope *s, bool b); | |
0db4c90a | 96 | int dns_scope_mdns_membership(DnsScope *s, bool b); |
623a4c97 | 97 | |
3b991089 | 98 | int dns_scope_make_reply_packet(DnsScope *s, uint16_t id, int rcode, DnsQuestion *q, DnsAnswer *answer, DnsAnswer *soa, bool tentative, DnsPacket **ret); |
623a4c97 | 99 | void dns_scope_process_query(DnsScope *s, DnsStream *stream, DnsPacket *p); |
ec2c5e43 | 100 | |
775ae354 | 101 | DnsTransaction *dns_scope_find_transaction(DnsScope *scope, DnsResourceKey *key, uint64_t query_flags); |
a4076574 LP |
102 | |
103 | int dns_scope_notify_conflict(DnsScope *scope, DnsResourceRecord *rr); | |
104 | void dns_scope_check_conflicts(DnsScope *scope, DnsPacket *p); | |
4d506d6b LP |
105 | |
106 | void dns_scope_dump(DnsScope *s, FILE *f); | |
a51c1048 LP |
107 | |
108 | DnsSearchDomain *dns_scope_get_search_domains(DnsScope *s); | |
801ad6a6 | 109 | |
3b5bd7d6 | 110 | bool dns_scope_name_wants_search_domain(DnsScope *s, const char *name); |
edbcc1fd LP |
111 | |
112 | bool dns_scope_network_good(DnsScope *s); | |
97ebebbc LP |
113 | |
114 | int dns_scope_ifindex(DnsScope *s); | |
6e1fa751 | 115 | const char* dns_scope_ifname(DnsScope *s); |
53fda2bb | 116 | |
1a63fc54 | 117 | int dns_scope_announce(DnsScope *scope, bool goodbye); |
6db6a464 DR |
118 | |
119 | int dns_scope_add_dnssd_services(DnsScope *scope); | |
6db6a464 | 120 | int dns_scope_remove_dnssd_services(DnsScope *scope); |
f76fa088 | 121 | |
ca5394d2 | 122 | bool dns_scope_is_default_route(DnsScope *scope); |
e0930aa6 | 123 | |
309a747f | 124 | int dns_scope_dump_cache_to_json(DnsScope *scope, sd_json_variant **ret); |
8841d1ce LP |
125 | |
126 | int dns_type_suitable_for_protocol(uint16_t type, DnsProtocol protocol); | |
127 | int dns_question_types_suitable_for_protocol(DnsQuestion *q, DnsProtocol protocol); | |
6a198b43 LP |
128 | |
129 | const char* dns_scope_origin_to_string(DnsScopeOrigin origin) _const_; | |
130 | DnsScopeOrigin dns_scope_origin_from_string(const char *s) _pure_; |