]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/resolve/resolved-dns-query.h
Merge pull request #8817 from yuwata/cleanup-nsflags
[thirdparty/systemd.git] / src / resolve / resolved-dns-query.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 #pragma once
3
4 /***
5 This file is part of systemd.
6
7 Copyright 2014 Lennart Poettering
8 ***/
9
10 #include "sd-bus.h"
11
12 #include "set.h"
13
14 typedef struct DnsQueryCandidate DnsQueryCandidate;
15 typedef struct DnsQuery DnsQuery;
16
17 #include "resolved-dns-answer.h"
18 #include "resolved-dns-question.h"
19 #include "resolved-dns-stream.h"
20 #include "resolved-dns-search-domain.h"
21
22 struct DnsQueryCandidate {
23 DnsQuery *query;
24 DnsScope *scope;
25
26 DnsSearchDomain *search_domain;
27
28 int error_code;
29 Set *transactions;
30
31 LIST_FIELDS(DnsQueryCandidate, candidates_by_query);
32 LIST_FIELDS(DnsQueryCandidate, candidates_by_scope);
33 };
34
35 struct DnsQuery {
36 Manager *manager;
37
38 /* When resolving a service, we first create a TXT+SRV query,
39 * and then for the hostnames we discover auxiliary A+AAAA
40 * queries. This pointer always points from the auxiliary
41 * queries back to the TXT+SRV query. */
42 DnsQuery *auxiliary_for;
43 LIST_HEAD(DnsQuery, auxiliary_queries);
44 unsigned n_auxiliary_queries;
45 int auxiliary_result;
46
47 /* The question, formatted in IDNA for use on classic DNS, and as UTF8 for use in LLMNR or mDNS. Note that even
48 * on classic DNS some labels might use UTF8 encoding. Specifically, DNS-SD service names (in contrast to their
49 * domain suffixes) use UTF-8 encoding even on DNS. Thus, the difference between these two fields is mostly
50 * relevant only for explicit *hostname* lookups as well as the domain suffixes of service lookups. */
51 DnsQuestion *question_idna;
52 DnsQuestion *question_utf8;
53
54 uint64_t flags;
55 int ifindex;
56
57 /* If true, A or AAAA RR lookups will be suppressed on links with no routable address of the matching address
58 * family */
59 bool suppress_unroutable_family;
60
61 /* If true, the RR TTLs of the answer will be clamped by their current left validity in the cache */
62 bool clamp_ttl;
63
64 DnsTransactionState state;
65 unsigned n_cname_redirects;
66
67 LIST_HEAD(DnsQueryCandidate, candidates);
68 sd_event_source *timeout_event_source;
69
70 /* Discovered data */
71 DnsAnswer *answer;
72 int answer_rcode;
73 DnssecResult answer_dnssec_result;
74 bool answer_authenticated;
75 DnsProtocol answer_protocol;
76 int answer_family;
77 DnsSearchDomain *answer_search_domain;
78 int answer_errno; /* if state is DNS_TRANSACTION_ERRNO */
79 bool previous_redirect_unauthenticated;
80
81 /* Bus client information */
82 sd_bus_message *request;
83 int request_family;
84 bool request_address_valid;
85 union in_addr_union request_address;
86 unsigned block_all_complete;
87 char *request_address_string;
88
89 /* DNS stub information */
90 DnsPacket *request_dns_packet;
91 DnsStream *request_dns_stream;
92 DnsPacket *reply_dns_packet;
93
94 /* Completion callback */
95 void (*complete)(DnsQuery* q);
96 unsigned block_ready;
97
98 sd_bus_track *bus_track;
99
100 LIST_FIELDS(DnsQuery, queries);
101 LIST_FIELDS(DnsQuery, auxiliary_queries);
102 };
103
104 enum {
105 DNS_QUERY_MATCH,
106 DNS_QUERY_NOMATCH,
107 DNS_QUERY_RESTARTED,
108 };
109
110 DnsQueryCandidate* dns_query_candidate_free(DnsQueryCandidate *c);
111 void dns_query_candidate_notify(DnsQueryCandidate *c);
112
113 int dns_query_new(Manager *m, DnsQuery **q, DnsQuestion *question_utf8, DnsQuestion *question_idna, int family, uint64_t flags);
114 DnsQuery *dns_query_free(DnsQuery *q);
115
116 int dns_query_make_auxiliary(DnsQuery *q, DnsQuery *auxiliary_for);
117
118 int dns_query_go(DnsQuery *q);
119 void dns_query_ready(DnsQuery *q);
120
121 int dns_query_process_cname(DnsQuery *q);
122
123 int dns_query_bus_track(DnsQuery *q, sd_bus_message *m);
124
125 DnsQuestion* dns_query_question_for_protocol(DnsQuery *q, DnsProtocol protocol);
126
127 const char *dns_query_string(DnsQuery *q);
128
129 DEFINE_TRIVIAL_CLEANUP_FUNC(DnsQuery*, dns_query_free);
130
131 bool dns_query_fully_authenticated(DnsQuery *q);