]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/resolve/resolved-dns-transaction.h
tree-wide: drop license boilerplate
[thirdparty/systemd.git] / src / resolve / resolved-dns-transaction.h
CommitLineData
53e1b683 1/* SPDX-License-Identifier: LGPL-2.1+ */
ec2c5e43
LP
2#pragma once
3
4/***
5 This file is part of systemd.
6
7 Copyright 2014 Lennart Poettering
ec2c5e43
LP
8***/
9
10typedef struct DnsTransaction DnsTransaction;
11typedef enum DnsTransactionState DnsTransactionState;
c3bc53e6 12typedef enum DnsTransactionSource DnsTransactionSource;
ec2c5e43
LP
13
14enum DnsTransactionState {
15 DNS_TRANSACTION_NULL,
16 DNS_TRANSACTION_PENDING,
547973de 17 DNS_TRANSACTION_VALIDATING,
3bbdc31d 18 DNS_TRANSACTION_RCODE_FAILURE,
ec2c5e43
LP
19 DNS_TRANSACTION_SUCCESS,
20 DNS_TRANSACTION_NO_SERVERS,
21 DNS_TRANSACTION_TIMEOUT,
22 DNS_TRANSACTION_ATTEMPTS_MAX_REACHED,
23 DNS_TRANSACTION_INVALID_REPLY,
7cc6ed7b 24 DNS_TRANSACTION_ERRNO,
ec2c5e43 25 DNS_TRANSACTION_ABORTED,
547973de 26 DNS_TRANSACTION_DNSSEC_FAILED,
b2b796b8 27 DNS_TRANSACTION_NO_TRUST_ANCHOR,
91adc4db 28 DNS_TRANSACTION_RR_TYPE_UNSUPPORTED,
edbcc1fd 29 DNS_TRANSACTION_NETWORK_DOWN,
0791110f 30 DNS_TRANSACTION_NOT_FOUND, /* like NXDOMAIN, but when LLMNR/TCP connections fail */
ec2c5e43
LP
31 _DNS_TRANSACTION_STATE_MAX,
32 _DNS_TRANSACTION_STATE_INVALID = -1
33};
34
547973de
LP
35#define DNS_TRANSACTION_IS_LIVE(state) IN_SET((state), DNS_TRANSACTION_NULL, DNS_TRANSACTION_PENDING, DNS_TRANSACTION_VALIDATING)
36
c3bc53e6
LP
37enum DnsTransactionSource {
38 DNS_TRANSACTION_NETWORK,
39 DNS_TRANSACTION_CACHE,
40 DNS_TRANSACTION_ZONE,
0d2cd476 41 DNS_TRANSACTION_TRUST_ANCHOR,
c3bc53e6
LP
42 _DNS_TRANSACTION_SOURCE_MAX,
43 _DNS_TRANSACTION_SOURCE_INVALID = -1
44};
45
71d35b6b 46#include "resolved-dns-answer.h"
ec2c5e43
LP
47#include "resolved-dns-packet.h"
48#include "resolved-dns-question.h"
71d35b6b 49#include "resolved-dns-scope.h"
07f264e4
DM
50#include "resolved-dns-server.h"
51#include "resolved-dns-stream.h"
ec2c5e43
LP
52
53struct DnsTransaction {
54 DnsScope *scope;
55
f52e61da 56 DnsResourceKey *key;
ec2c5e43
LP
57
58 DnsTransactionState state;
547973de 59
ec2c5e43
LP
60 uint16_t id;
61
cbe4216d
LP
62 bool tried_stream:1;
63
a0c888c7
LP
64 bool initial_jitter_scheduled:1;
65 bool initial_jitter_elapsed:1;
6e068472 66
17c8de63
LP
67 bool clamp_ttl:1;
68
53fda2bb
DR
69 bool probing:1;
70
ec2c5e43 71 DnsPacket *sent, *received;
ae6a4bbf
LP
72
73 DnsAnswer *answer;
74 int answer_rcode;
019036a4 75 DnssecResult answer_dnssec_result;
c3bc53e6 76 DnsTransactionSource answer_source;
d3760be0 77 uint32_t answer_nsec_ttl;
7cc6ed7b 78 int answer_errno; /* if state is DNS_TRANSACTION_ERRNO */
105e1512
LP
79
80 /* Indicates whether the primary answer is authenticated,
81 * i.e. whether the RRs from answer which directly match the
82 * question are authenticated, or, if there are none, whether
83 * the NODATA or NXDOMAIN case is. It says nothing about
84 * additional RRs listed in the answer, however they have
85 * their own DNS_ANSWER_AUTHORIZED FLAGS. Note that this bit
86 * is defined different than the AD bit in DNS packets, as
87 * that covers more than just the actual primary answer. */
931851e8 88 bool answer_authenticated;
ec2c5e43 89
105e1512
LP
90 /* Contains DNSKEY, DS, SOA RRs we already verified and need
91 * to authenticate this reply */
547973de
LP
92 DnsAnswer *validated_keys;
93
9df3ba6c 94 usec_t start_usec;
a9da14e1 95 usec_t next_attempt_after;
ec2c5e43
LP
96 sd_event_source *timeout_event_source;
97 unsigned n_attempts;
98
44db02d0
LP
99 unsigned n_picked_servers;
100
f32f0e57 101 /* UDP connection logic, if we need it */
4667e00a
LP
102 int dns_udp_fd;
103 sd_event_source *dns_udp_event_source;
d20b1667 104
f32f0e57
LP
105 /* TCP connection logic, if we need it */
106 DnsStream *stream;
107
4667e00a 108 /* The active server */
8300ba21
TG
109 DnsServer *server;
110
547973de 111 /* The features of the DNS server at time of transaction start */
274b8748 112 DnsServerFeatureLevel current_feature_level;
be808ea0 113
d001e0a3
LP
114 /* If we got SERVFAIL back, we retry the lookup, using a lower feature level than we used before. */
115 DnsServerFeatureLevel clamp_feature_level;
116
801ad6a6
LP
117 /* Query candidates this transaction is referenced by and that
118 * shall be notified about this specific transaction
119 * completing. */
35aa04e9 120 Set *notify_query_candidates, *notify_query_candidates_done;
ec2c5e43
LP
121
122 /* Zone items this transaction is referenced by and that shall
123 * be notified about completion. */
35aa04e9 124 Set *notify_zone_items, *notify_zone_items_done;
547973de
LP
125
126 /* Other transactions that this transactions is referenced by
127 * and that shall be notified about completion. This is used
128 * when transactions want to validate their RRsets, but need
129 * another DNSKEY or DS RR to do so. */
35aa04e9 130 Set *notify_transactions, *notify_transactions_done;
547973de
LP
131
132 /* The opposite direction: the transactions this transaction
133 * created in order to request DNSKEY or DS RRs. */
134 Set *dnssec_transactions;
ec2c5e43
LP
135
136 unsigned block_gc;
137
138 LIST_FIELDS(DnsTransaction, transactions_by_scope);
139};
140
f52e61da 141int dns_transaction_new(DnsTransaction **ret, DnsScope *s, DnsResourceKey *key);
ec2c5e43
LP
142DnsTransaction* dns_transaction_free(DnsTransaction *t);
143
51e399bc 144bool dns_transaction_gc(DnsTransaction *t);
ec2c5e43
LP
145int dns_transaction_go(DnsTransaction *t);
146
147void dns_transaction_process_reply(DnsTransaction *t, DnsPacket *p);
148void dns_transaction_complete(DnsTransaction *t, DnsTransactionState state);
149
547973de
LP
150void dns_transaction_notify(DnsTransaction *t, DnsTransaction *source);
151int dns_transaction_validate_dnssec(DnsTransaction *t);
152int dns_transaction_request_dnssec_keys(DnsTransaction *t);
153
ec2c5e43
LP
154const char* dns_transaction_state_to_string(DnsTransactionState p) _const_;
155DnsTransactionState dns_transaction_state_from_string(const char *s) _pure_;
156
c3bc53e6
LP
157const char* dns_transaction_source_to_string(DnsTransactionSource p) _const_;
158DnsTransactionSource dns_transaction_source_from_string(const char *s) _pure_;
159
ec2c5e43 160/* LLMNR Jitter interval, see RFC 4795 Section 7 */
6e068472 161#define LLMNR_JITTER_INTERVAL_USEC (100 * USEC_PER_MSEC)
ec2c5e43 162
ea12bcc7
DM
163/* mDNS Jitter interval, see RFC 6762 Section 5.2 */
164#define MDNS_JITTER_MIN_USEC (20 * USEC_PER_MSEC)
165#define MDNS_JITTER_RANGE_USEC (100 * USEC_PER_MSEC)
166
53fda2bb
DR
167/* mDNS probing interval, see RFC 6762 Section 8.1 */
168#define MDNS_PROBING_INTERVAL_USEC (250 * USEC_PER_MSEC)
169
ec2c5e43 170/* Maximum attempts to send DNS requests, across all DNS servers */
74a3ed74 171#define DNS_TRANSACTION_ATTEMPTS_MAX 24
ec2c5e43
LP
172
173/* Maximum attempts to send LLMNR requests, see RFC 4795 Section 2.7 */
174#define LLMNR_TRANSACTION_ATTEMPTS_MAX 3
175
53fda2bb
DR
176/* Maximum attempts to send MDNS requests, see RFC 6762 Section 8.1 */
177#define MDNS_TRANSACTION_ATTEMPTS_MAX 3
178
179#define TRANSACTION_ATTEMPTS_MAX(p) (((p) == DNS_PROTOCOL_LLMNR) ? \
180 LLMNR_TRANSACTION_ATTEMPTS_MAX : \
181 (((p) == DNS_PROTOCOL_MDNS) ? \
182 MDNS_TRANSACTION_ATTEMPTS_MAX : \
183 DNS_TRANSACTION_ATTEMPTS_MAX))