2020-11-09 05:23:58 +01:00
|
|
|
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
2014-07-16 00:26:02 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "list.h"
|
2020-05-06 19:10:59 +02:00
|
|
|
#include "ratelimit.h"
|
2014-07-16 00:26:02 +02:00
|
|
|
|
2020-05-06 19:10:59 +02:00
|
|
|
typedef struct DnsQueryCandidate DnsQueryCandidate;
|
2014-07-16 00:26:02 +02:00
|
|
|
typedef struct DnsScope DnsScope;
|
|
|
|
|
2014-07-17 19:38:37 +02:00
|
|
|
#include "resolved-dns-cache.h"
|
2015-12-03 19:51:04 +01:00
|
|
|
#include "resolved-dns-dnssec.h"
|
2015-11-18 22:46:33 +01:00
|
|
|
#include "resolved-dns-packet.h"
|
2020-05-06 19:10:59 +02:00
|
|
|
|
2016-09-01 00:33:21 +02:00
|
|
|
#include "resolved-dns-search-domain.h"
|
2015-11-18 22:46:33 +01:00
|
|
|
#include "resolved-dns-server.h"
|
2016-09-01 00:33:21 +02:00
|
|
|
#include "resolved-dns-stream.h"
|
2014-07-29 14:24:02 +02:00
|
|
|
#include "resolved-dns-zone.h"
|
2014-07-16 00:26:02 +02:00
|
|
|
|
|
|
|
typedef enum DnsScopeMatch {
|
|
|
|
DNS_SCOPE_NO,
|
|
|
|
DNS_SCOPE_MAYBE,
|
2018-12-03 16:25:00 +01:00
|
|
|
DNS_SCOPE_YES_BASE, /* Add the number of matching labels to this */
|
|
|
|
DNS_SCOPE_YES_END = DNS_SCOPE_YES_BASE + DNS_N_LABELS_MAX,
|
2014-07-16 00:26:02 +02:00
|
|
|
_DNS_SCOPE_MATCH_MAX,
|
2018-12-03 22:26:46 +01:00
|
|
|
_DNS_SCOPE_MATCH_INVALID = -1
|
2014-07-16 00:26:02 +02:00
|
|
|
} DnsScopeMatch;
|
|
|
|
|
|
|
|
struct DnsScope {
|
|
|
|
Manager *manager;
|
|
|
|
|
2014-07-18 12:34:02 +02:00
|
|
|
DnsProtocol protocol;
|
2014-07-18 16:09:30 +02:00
|
|
|
int family;
|
2018-12-04 13:00:19 +01:00
|
|
|
|
|
|
|
/* Copied at scope creation time from the link/manager */
|
2015-12-03 19:51:04 +01:00
|
|
|
DnssecMode dnssec_mode;
|
2018-06-13 20:26:24 +02:00
|
|
|
DnsOverTlsMode dns_over_tls_mode;
|
2014-07-16 00:26:02 +02:00
|
|
|
|
|
|
|
Link *link;
|
|
|
|
|
2014-07-17 19:38:37 +02:00
|
|
|
DnsCache cache;
|
2014-07-29 14:24:02 +02:00
|
|
|
DnsZone zone;
|
2014-07-17 19:38:37 +02:00
|
|
|
|
2014-08-22 13:56:51 +02:00
|
|
|
OrderedHashmap *conflict_queue;
|
2014-08-06 16:15:35 +02:00
|
|
|
sd_event_source *conflict_event_source;
|
|
|
|
|
2016-12-02 14:01:56 +01:00
|
|
|
bool announced:1;
|
|
|
|
sd_event_source *announce_event_source;
|
|
|
|
|
2014-08-05 16:34:45 +02:00
|
|
|
RateLimit ratelimit;
|
|
|
|
|
2015-07-28 02:32:24 +02:00
|
|
|
usec_t resend_timeout;
|
|
|
|
usec_t max_rtt;
|
|
|
|
|
2015-11-25 20:47:27 +01:00
|
|
|
LIST_HEAD(DnsQueryCandidate, query_candidates);
|
2014-07-16 00:26:02 +02:00
|
|
|
|
2015-11-26 23:51:59 +01:00
|
|
|
/* Note that we keep track of ongoing transactions in two
|
|
|
|
* ways: once in a hashmap, indexed by the rr key, and once in
|
|
|
|
* a linked list. We use the hashmap to quickly find
|
|
|
|
* transactions we can reuse for a key. But note that there
|
|
|
|
* might be multiple transactions for the same key (because
|
|
|
|
* the zone probing can't reuse a transaction answered from
|
|
|
|
* the zone or the cache), and the hashmap only tracks the
|
|
|
|
* most recent entry. */
|
|
|
|
Hashmap *transactions_by_key;
|
|
|
|
LIST_HEAD(DnsTransaction, transactions);
|
|
|
|
|
2014-07-16 00:26:02 +02:00
|
|
|
LIST_FIELDS(DnsScope, scopes);
|
|
|
|
};
|
|
|
|
|
2014-07-18 16:09:30 +02:00
|
|
|
int dns_scope_new(Manager *m, DnsScope **ret, Link *l, DnsProtocol p, int family);
|
2014-07-16 00:26:02 +02:00
|
|
|
DnsScope* dns_scope_free(DnsScope *s);
|
|
|
|
|
2015-07-28 02:32:24 +02:00
|
|
|
void dns_scope_packet_received(DnsScope *s, usec_t rtt);
|
|
|
|
void dns_scope_packet_lost(DnsScope *s, usec_t usec);
|
|
|
|
|
2015-12-26 18:49:32 +01:00
|
|
|
int dns_scope_emit_udp(DnsScope *s, int fd, DnsPacket *p);
|
2018-04-27 13:20:31 +02:00
|
|
|
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);
|
2020-07-13 01:58:02 +02:00
|
|
|
int dns_scope_socket_udp(DnsScope *s, DnsServer *server);
|
2014-07-16 20:15:47 +02:00
|
|
|
|
2014-08-14 01:00:15 +02:00
|
|
|
DnsScopeMatch dns_scope_good_domain(DnsScope *s, int ifindex, uint64_t flags, const char *domain);
|
2016-02-01 00:00:01 +01:00
|
|
|
bool dns_scope_good_key(DnsScope *s, const DnsResourceKey *key);
|
2014-07-16 00:26:02 +02:00
|
|
|
|
2014-08-01 18:09:07 +02:00
|
|
|
DnsServer *dns_scope_get_dns_server(DnsScope *s);
|
2017-12-08 19:48:15 +01:00
|
|
|
unsigned dns_scope_get_n_dns_servers(DnsScope *s);
|
2014-07-16 00:26:02 +02:00
|
|
|
void dns_scope_next_dns_server(DnsScope *s);
|
2014-07-18 12:34:02 +02:00
|
|
|
|
|
|
|
int dns_scope_llmnr_membership(DnsScope *s, bool b);
|
2015-07-11 20:33:58 +02:00
|
|
|
int dns_scope_mdns_membership(DnsScope *s, bool b);
|
2014-07-29 14:24:02 +02:00
|
|
|
|
2016-12-05 16:12:15 +01:00
|
|
|
int dns_scope_make_reply_packet(DnsScope *s, uint16_t id, int rcode, DnsQuestion *q, DnsAnswer *answer, DnsAnswer *soa, bool tentative, DnsPacket **ret);
|
2014-07-29 14:24:02 +02:00
|
|
|
void dns_scope_process_query(DnsScope *s, DnsStream *stream, DnsPacket *p);
|
2014-07-31 17:46:40 +02:00
|
|
|
|
2015-08-21 22:55:01 +02:00
|
|
|
DnsTransaction *dns_scope_find_transaction(DnsScope *scope, DnsResourceKey *key, bool cache_ok);
|
2014-08-06 16:15:35 +02:00
|
|
|
|
|
|
|
int dns_scope_notify_conflict(DnsScope *scope, DnsResourceRecord *rr);
|
|
|
|
void dns_scope_check_conflicts(DnsScope *scope, DnsPacket *p);
|
2015-08-26 09:41:45 +02:00
|
|
|
|
|
|
|
void dns_scope_dump(DnsScope *s, FILE *f);
|
2015-11-24 21:12:51 +01:00
|
|
|
|
|
|
|
DnsSearchDomain *dns_scope_get_search_domains(DnsScope *s);
|
2015-11-25 20:47:27 +01:00
|
|
|
|
2020-06-03 13:10:23 +02:00
|
|
|
bool dns_scope_name_wants_search_domain(DnsScope *s, const char *name);
|
2016-01-20 21:28:22 +01:00
|
|
|
|
|
|
|
bool dns_scope_network_good(DnsScope *s);
|
2016-06-14 23:28:54 +02:00
|
|
|
|
|
|
|
int dns_scope_ifindex(DnsScope *s);
|
2016-12-02 14:01:56 +01:00
|
|
|
|
2017-02-13 20:44:11 +01:00
|
|
|
int dns_scope_announce(DnsScope *scope, bool goodbye);
|
2017-10-04 10:34:39 +02:00
|
|
|
|
|
|
|
int dns_scope_add_dnssd_services(DnsScope *scope);
|
|
|
|
int dns_scope_remove_dnssd_services(DnsScope *scope);
|
2018-12-04 12:08:18 +01:00
|
|
|
|
2018-12-04 12:40:07 +01:00
|
|
|
bool dns_scope_is_default_route(DnsScope *scope);
|