]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/resolve/resolved-dns-transaction.h
resolved: cache stringified transaction key once per transaction
[thirdparty/systemd.git] / src / resolve / resolved-dns-transaction.h
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3 #pragma once
4
5 /***
6 This file is part of systemd.
7
8 Copyright 2014 Lennart Poettering
9
10 systemd is free software; you can redistribute it and/or modify it
11 under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14
15 systemd is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Lesser General Public License for more details.
19
20 You should have received a copy of the GNU Lesser General Public License
21 along with systemd; If not, see <http://www.gnu.org/licenses/>.
22 ***/
23
24 typedef struct DnsTransaction DnsTransaction;
25 typedef enum DnsTransactionState DnsTransactionState;
26 typedef enum DnsTransactionSource DnsTransactionSource;
27
28 enum DnsTransactionState {
29 DNS_TRANSACTION_NULL,
30 DNS_TRANSACTION_PENDING,
31 DNS_TRANSACTION_VALIDATING,
32 DNS_TRANSACTION_FAILURE,
33 DNS_TRANSACTION_SUCCESS,
34 DNS_TRANSACTION_NO_SERVERS,
35 DNS_TRANSACTION_TIMEOUT,
36 DNS_TRANSACTION_ATTEMPTS_MAX_REACHED,
37 DNS_TRANSACTION_INVALID_REPLY,
38 DNS_TRANSACTION_RESOURCES,
39 DNS_TRANSACTION_ABORTED,
40 DNS_TRANSACTION_DNSSEC_FAILED,
41 _DNS_TRANSACTION_STATE_MAX,
42 _DNS_TRANSACTION_STATE_INVALID = -1
43 };
44
45 #define DNS_TRANSACTION_IS_LIVE(state) IN_SET((state), DNS_TRANSACTION_NULL, DNS_TRANSACTION_PENDING, DNS_TRANSACTION_VALIDATING)
46
47 enum DnsTransactionSource {
48 DNS_TRANSACTION_NETWORK,
49 DNS_TRANSACTION_CACHE,
50 DNS_TRANSACTION_ZONE,
51 DNS_TRANSACTION_TRUST_ANCHOR,
52 _DNS_TRANSACTION_SOURCE_MAX,
53 _DNS_TRANSACTION_SOURCE_INVALID = -1
54 };
55
56 #include "resolved-dns-answer.h"
57 #include "resolved-dns-packet.h"
58 #include "resolved-dns-question.h"
59 #include "resolved-dns-scope.h"
60
61 struct DnsTransaction {
62 DnsScope *scope;
63
64 DnsResourceKey *key;
65 char *key_string;
66
67 DnsTransactionState state;
68 DnssecResult dnssec_result;
69
70 uint16_t id;
71
72 bool initial_jitter_scheduled;
73 bool initial_jitter_elapsed;
74
75 DnsPacket *sent, *received;
76
77 DnsAnswer *answer;
78 unsigned n_answer_cacheable; /* Specifies how many RRs of the answer shall be cached, from the beginning */
79 int answer_rcode;
80 DnsTransactionSource answer_source;
81 bool answer_authenticated;
82
83 /* Contains DS and DNSKEY RRs we already verified and need to authenticate this reply */
84 DnsAnswer *validated_keys;
85
86 usec_t start_usec;
87 usec_t next_attempt_after;
88 sd_event_source *timeout_event_source;
89 unsigned n_attempts;
90
91 int dns_udp_fd;
92 sd_event_source *dns_udp_event_source;
93
94 /* The active server */
95 DnsServer *server;
96
97 /* The features of the DNS server at time of transaction start */
98 DnsServerFeatureLevel current_features;
99
100 /* TCP connection logic, if we need it */
101 DnsStream *stream;
102
103 /* Query candidates this transaction is referenced by and that
104 * shall be notified about this specific transaction
105 * completing. */
106 Set *notify_query_candidates;
107
108 /* Zone items this transaction is referenced by and that shall
109 * be notified about completion. */
110 Set *notify_zone_items;
111
112 /* Other transactions that this transactions is referenced by
113 * and that shall be notified about completion. This is used
114 * when transactions want to validate their RRsets, but need
115 * another DNSKEY or DS RR to do so. */
116 Set *notify_transactions;
117
118 /* The opposite direction: the transactions this transaction
119 * created in order to request DNSKEY or DS RRs. */
120 Set *dnssec_transactions;
121
122 unsigned block_gc;
123
124 LIST_FIELDS(DnsTransaction, transactions_by_scope);
125 };
126
127 int dns_transaction_new(DnsTransaction **ret, DnsScope *s, DnsResourceKey *key);
128 DnsTransaction* dns_transaction_free(DnsTransaction *t);
129
130 void dns_transaction_gc(DnsTransaction *t);
131 int dns_transaction_go(DnsTransaction *t);
132
133 void dns_transaction_process_reply(DnsTransaction *t, DnsPacket *p);
134 void dns_transaction_complete(DnsTransaction *t, DnsTransactionState state);
135
136 void dns_transaction_notify(DnsTransaction *t, DnsTransaction *source);
137 int dns_transaction_validate_dnssec(DnsTransaction *t);
138 int dns_transaction_request_dnssec_keys(DnsTransaction *t);
139
140 const char *dns_transaction_key_string(DnsTransaction *t);
141
142 const char* dns_transaction_state_to_string(DnsTransactionState p) _const_;
143 DnsTransactionState dns_transaction_state_from_string(const char *s) _pure_;
144
145 const char* dns_transaction_source_to_string(DnsTransactionSource p) _const_;
146 DnsTransactionSource dns_transaction_source_from_string(const char *s) _pure_;
147
148 /* LLMNR Jitter interval, see RFC 4795 Section 7 */
149 #define LLMNR_JITTER_INTERVAL_USEC (100 * USEC_PER_MSEC)
150
151 /* mDNS Jitter interval, see RFC 6762 Section 5.2 */
152 #define MDNS_JITTER_MIN_USEC (20 * USEC_PER_MSEC)
153 #define MDNS_JITTER_RANGE_USEC (100 * USEC_PER_MSEC)
154
155 /* Maximum attempts to send DNS requests, across all DNS servers */
156 #define DNS_TRANSACTION_ATTEMPTS_MAX 16
157
158 /* Maximum attempts to send LLMNR requests, see RFC 4795 Section 2.7 */
159 #define LLMNR_TRANSACTION_ATTEMPTS_MAX 3
160
161 #define TRANSACTION_ATTEMPTS_MAX(p) ((p) == DNS_PROTOCOL_LLMNR ? LLMNR_TRANSACTION_ATTEMPTS_MAX : DNS_TRANSACTION_ATTEMPTS_MAX)