]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/resolve/resolved-dns-query.h
systemd-detect-virt: detect s390 virtualization
[thirdparty/systemd.git] / src / resolve / resolved-dns-query.h
CommitLineData
74b2466e
LP
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
29typedef struct DnsQuery DnsQuery;
30typedef struct DnsQueryTransaction DnsQueryTransaction;
31
32#include "resolved.h"
33#include "resolved-dns-scope.h"
34#include "resolved-dns-rr.h"
35#include "resolved-dns-packet.h"
36
37typedef enum DnsQueryState {
38 DNS_QUERY_NULL,
8ba9fd9c 39 DNS_QUERY_PENDING,
74b2466e
LP
40 DNS_QUERY_FAILURE,
41 DNS_QUERY_SUCCESS,
ad867662 42 DNS_QUERY_NO_SERVERS,
74b2466e
LP
43 DNS_QUERY_TIMEOUT,
44 DNS_QUERY_ATTEMPTS_MAX,
45 DNS_QUERY_INVALID_REPLY,
8ba9fd9c 46 DNS_QUERY_RESOURCES
74b2466e
LP
47} DnsQueryState;
48
49struct DnsQueryTransaction {
50 DnsQuery *query;
51 DnsScope *scope;
52
53 DnsQueryState state;
54 uint16_t id;
55
56 sd_event_source *timeout_event_source;
57 unsigned n_attempts;
58
ad867662
LP
59 DnsPacket *sent, *received;
60
61 /* TCP connection logic */
62 int tcp_fd;
63 sd_event_source *tcp_event_source;
64 size_t tcp_written, tcp_read;
65 be16_t tcp_read_size;
74b2466e 66
322345fd
LP
67 /* Data from cache */
68 DnsResourceRecord **cached_rrs;
69 unsigned n_cached_rrs;
70
74b2466e
LP
71 LIST_FIELDS(DnsQueryTransaction, transactions_by_query);
72 LIST_FIELDS(DnsQueryTransaction, transactions_by_scope);
73};
74
75struct DnsQuery {
76 Manager *manager;
77
78 DnsResourceKey *keys;
79 unsigned n_keys;
80
81 DnsQueryState state;
8ba9fd9c 82 unsigned n_cname;
74b2466e
LP
83
84 sd_event_source *timeout_event_source;
85
322345fd 86 /* Discovered data */
ad867662 87 DnsPacket *received;
322345fd
LP
88 DnsResourceRecord **cached_rrs;
89 unsigned n_cached_rrs;
74b2466e 90
8ba9fd9c 91 /* Bus client information */
74b2466e
LP
92 sd_bus_message *request;
93 unsigned char request_family;
94 const char *request_hostname;
95 union in_addr_union request_address;
96
322345fd 97 /* Completion callback */
74b2466e 98 void (*complete)(DnsQuery* q);
322345fd 99 unsigned block_finish;
74b2466e
LP
100
101 LIST_HEAD(DnsQueryTransaction, transactions);
102 LIST_FIELDS(DnsQuery, queries);
103};
104
322345fd
LP
105DnsQueryTransaction* dns_query_transaction_free(DnsQueryTransaction *t);
106void dns_query_transaction_reply(DnsQueryTransaction *t, DnsPacket *p);
107
74b2466e
LP
108int dns_query_new(Manager *m, DnsQuery **q, DnsResourceKey *keys, unsigned n_keys);
109DnsQuery *dns_query_free(DnsQuery *q);
322345fd
LP
110
111int dns_query_go(DnsQuery *q);
112int dns_query_cname_redirect(DnsQuery *q, const char *name);
113void dns_query_finish(DnsQuery *q);
114
8ba9fd9c
LP
115int dns_query_matches_rr(DnsQuery *q, DnsResourceRecord *rr);
116int dns_query_matches_cname(DnsQuery *q, DnsResourceRecord *rr);
74b2466e 117
322345fd
LP
118/* What we found */
119int dns_query_get_rrs(DnsQuery *q, DnsResourceRecord *** rrs);
120int dns_query_get_rcode(DnsQuery *q);
121int dns_query_get_ifindex(DnsQuery *q);
74b2466e
LP
122
123DEFINE_TRIVIAL_CLEANUP_FUNC(DnsQuery*, dns_query_free);