]> git.ipfire.org Git - thirdparty/pdns.git/blob - pdns/resolver.hh
Merge pull request #14021 from Habbie/auth-lua-join-whitespace
[thirdparty/pdns.git] / pdns / resolver.hh
1 /*
2 * This file is part of PowerDNS or dnsdist.
3 * Copyright -- PowerDNS.COM B.V. and its contributors
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * In addition, for the avoidance of any doubt, permission is granted to
10 * link this program with OpenSSL and to (re)distribute the binaries
11 * produced as the result of such linking.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 */
22 #ifndef PDNS_RESOLVER_HH
23 #define PDNS_RESOLVER_HH
24
25 #include <string>
26 #include <vector>
27 #include <sys/types.h>
28 #include "iputils.hh"
29 #include <netdb.h>
30 #include <unistd.h>
31 #include <sys/time.h>
32 #include <sys/uio.h>
33 #include <fcntl.h>
34 #include <sys/socket.h>
35 #include <netinet/in.h>
36 #include <arpa/inet.h>
37 #undef res_mkquery
38
39 #include "pdnsexception.hh"
40 #include "dns.hh"
41 #include "namespaces.hh"
42 #include "dnsrecords.hh"
43 #include "dnssecinfra.hh"
44 #include "tsigverifier.hh"
45
46 class ResolverException : public PDNSException
47 {
48 public:
49 ResolverException(const string &reason_) : PDNSException(reason_){}
50 };
51
52 // make an IPv4 or IPv6 query socket
53 int makeQuerySocket(const ComboAddress& local, bool udpOrTCP, bool nonLocalBind=false);
54 //! Resolver class. Can be used synchronously and asynchronously, over IPv4 and over IPv6 (simultaneously)
55 class Resolver : public boost::noncopyable
56 {
57 public:
58 Resolver();
59 ~Resolver();
60
61 typedef vector<DNSResourceRecord> res_t;
62 //! synchronously resolve domain|type at IP, store result in result, rcode in ret
63 int resolve(const ComboAddress &ip, const DNSName &domain, int type, res_t* result, const ComboAddress& local);
64
65 int resolve(const ComboAddress &ip, const DNSName &domain, int type, res_t* result);
66
67 //! only send out a resolution request
68 uint16_t sendResolve(const ComboAddress& remote, const ComboAddress& local, const DNSName &domain, int type, int *localsock, bool dnssecOk=false,
69 const DNSName& tsigkeyname=DNSName(), const DNSName& tsigalgorithm=DNSName(), const string& tsigsecret="");
70
71 //! see if we got a SOA response from our sendResolve
72 bool tryGetSOASerial(DNSName *theirDomain, ComboAddress* remote, uint32_t* theirSerial, uint32_t* theirInception, uint32_t* theirExpire, uint16_t* id);
73
74 //! convenience function that calls resolve above
75 void getSoaSerial(const ComboAddress&, const DNSName &, uint32_t *);
76
77 private:
78 std::map<std::string, int> locals;
79 };
80
81 class AXFRRetriever : public boost::noncopyable
82 {
83 public:
84 AXFRRetriever(const ComboAddress& remote,
85 const DNSName& zone,
86 const TSIGTriplet& tt = TSIGTriplet(),
87 const ComboAddress* laddr = NULL,
88 size_t maxReceivedBytes=0,
89 uint16_t timeout=10);
90 ~AXFRRetriever();
91 int getChunk(Resolver::res_t &res, vector<DNSRecord>* records=0, uint16_t timeout=10);
92
93 private:
94 void connect(uint16_t timeout);
95 int getLength(uint16_t timeout);
96 void timeoutReadn(uint16_t bytes, uint16_t timeoutsec=10);
97
98 shared_array<char> d_buf;
99 string d_domain;
100 int d_sock;
101 int d_soacount;
102 ComboAddress d_remote;
103 TSIGTCPVerifier d_tsigVerifier;
104
105 size_t d_receivedBytes;
106 size_t d_maxReceivedBytes;
107 TSIGRecordContent d_trc;
108 };
109
110
111 #endif /* PDNS_RESOLVER_HH */