]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/resolve/resolved-dns-query.h
67fe7f6e8f5b033a1b1d3aff676b42689c557e47
[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 _DNS_QUERY_STATE_MAX,
53 _DNS_QUERY_STATE_INVALID = -1
54 } DnsQueryState;
55
56 struct DnsQueryTransaction {
57 DnsScope *scope;
58
59 DnsQuestion *question;
60
61 DnsQueryState state;
62 uint16_t id;
63
64 DnsPacket *sent, *received;
65 DnsAnswer *cached;
66 int cached_rcode;
67
68 sd_event_source *timeout_event_source;
69 unsigned n_attempts;
70
71 /* TCP connection logic, if we need it */
72 DnsStream *stream;
73
74 /* Queries this transaction is referenced by and that shall by
75 * notified about this specific transaction completing. */
76 Set *queries;
77
78 unsigned block_gc;
79
80 LIST_FIELDS(DnsQueryTransaction, transactions_by_scope);
81 };
82
83 struct DnsQuery {
84 Manager *manager;
85 DnsQuestion *question;
86
87 DnsQueryState state;
88 unsigned n_cname_redirects;
89
90 sd_event_source *timeout_event_source;
91
92 /* Discovered data */
93 DnsAnswer *answer;
94 int answer_ifindex;
95 int answer_rcode;
96
97 /* Bus client information */
98 sd_bus_message *request;
99 int request_family;
100 const char *request_hostname;
101 union in_addr_union request_address;
102
103 /* Completion callback */
104 void (*complete)(DnsQuery* q);
105 unsigned block_ready;
106
107 Set *transactions;
108
109 LIST_FIELDS(DnsQuery, queries);
110 };
111
112 DnsQueryTransaction* dns_query_transaction_free(DnsQueryTransaction *t);
113 void dns_query_transaction_complete(DnsQueryTransaction *t, DnsQueryState state);
114
115 void dns_query_transaction_process_reply(DnsQueryTransaction *t, DnsPacket *p);
116
117 int dns_query_new(Manager *m, DnsQuery **q, DnsQuestion *question);
118 DnsQuery *dns_query_free(DnsQuery *q);
119
120 int dns_query_go(DnsQuery *q);
121 void dns_query_ready(DnsQuery *q);
122
123 int dns_query_cname_redirect(DnsQuery *q, const char *name);
124
125 const char* dns_query_state_to_string(DnsQueryState p) _const_;
126 DnsQueryState dns_query_state_from_string(const char *s) _pure_;
127
128 DEFINE_TRIVIAL_CLEANUP_FUNC(DnsQuery*, dns_query_free);