]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/resolve/resolved-dns-query.h
resolved: set LLMNR TCP and UDP TTLs to the values suggested by the RFC
[thirdparty/systemd.git] / src / resolve / resolved-dns-query.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 #include <inttypes.h>
25
26 #include "sd-bus.h"
27 #include "util.h"
28 #include "set.h"
29
30 typedef struct DnsQuery DnsQuery;
31 typedef struct DnsQueryTransaction DnsQueryTransaction;
32
33 #include "resolved.h"
34 #include "resolved-dns-scope.h"
35 #include "resolved-dns-rr.h"
36 #include "resolved-dns-packet.h"
37 #include "resolved-dns-question.h"
38 #include "resolved-dns-answer.h"
39 #include "resolved-dns-stream.h"
40
41 typedef enum DnsQueryState {
42 DNS_QUERY_NULL,
43 DNS_QUERY_PENDING,
44 DNS_QUERY_FAILURE,
45 DNS_QUERY_SUCCESS,
46 DNS_QUERY_NO_SERVERS,
47 DNS_QUERY_TIMEOUT,
48 DNS_QUERY_ATTEMPTS_MAX,
49 DNS_QUERY_INVALID_REPLY,
50 DNS_QUERY_RESOURCES,
51 DNS_QUERY_ABORTED,
52 } DnsQueryState;
53
54 struct DnsQueryTransaction {
55 DnsScope *scope;
56
57 DnsQuestion *question;
58
59 DnsQueryState state;
60 uint16_t id;
61
62 DnsPacket *sent, *received;
63 DnsAnswer *cached;
64 int cached_rcode;
65
66 sd_event_source *timeout_event_source;
67 unsigned n_attempts;
68
69 /* TCP connection logic, if we need it */
70 DnsStream *stream;
71
72 /* Queries this transaction is referenced by and that shall by
73 * notified about this specific transaction completing. */
74 Set *queries;
75
76 unsigned block_gc;
77
78 LIST_FIELDS(DnsQueryTransaction, transactions_by_scope);
79 };
80
81 struct DnsQuery {
82 Manager *manager;
83 DnsQuestion *question;
84
85 DnsQueryState state;
86 unsigned n_cname_redirects;
87
88 sd_event_source *timeout_event_source;
89
90 /* Discovered data */
91 DnsAnswer *answer;
92 int answer_ifindex;
93 int answer_rcode;
94
95 /* Bus client information */
96 sd_bus_message *request;
97 int request_family;
98 const char *request_hostname;
99 union in_addr_union request_address;
100
101 /* Completion callback */
102 void (*complete)(DnsQuery* q);
103 unsigned block_ready;
104
105 Set *transactions;
106
107 LIST_FIELDS(DnsQuery, queries);
108 };
109
110 DnsQueryTransaction* dns_query_transaction_free(DnsQueryTransaction *t);
111 void dns_query_transaction_complete(DnsQueryTransaction *t, DnsQueryState state);
112
113 void dns_query_transaction_process_reply(DnsQueryTransaction *t, DnsPacket *p);
114
115 int dns_query_new(Manager *m, DnsQuery **q, DnsQuestion *question);
116 DnsQuery *dns_query_free(DnsQuery *q);
117
118 int dns_query_go(DnsQuery *q);
119 void dns_query_ready(DnsQuery *q);
120
121 int dns_query_cname_redirect(DnsQuery *q, const char *name);
122
123 DEFINE_TRIVIAL_CLEANUP_FUNC(DnsQuery*, dns_query_free);