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