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