]> git.ipfire.org Git - thirdparty/pdns.git/blame - pdns/resolver.hh
Merge pull request #7628 from tcely/patch-3
[thirdparty/pdns.git] / pdns / resolver.hh
CommitLineData
12c86877 1/*
12471842
PL
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 */
680f25f8
RK
22#ifndef PDNS_RESOLVER_HH
23#define PDNS_RESOLVER_HH
092f210a 24
12c86877
BH
25#include <string>
26#include <vector>
092f210a 27#include <sys/types.h>
809fe23f 28#include "iputils.hh"
76473b92
KM
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
12c86877 38
5c409fa2 39#include "pdnsexception.hh"
12c86877 40#include "dns.hh"
10f4eea8 41#include "namespaces.hh"
ef03cc09 42#include "dnsrecords.hh"
43#include "dnssecinfra.hh"
60a1c204 44#include "tsigverifier.hh"
12c86877 45
3f81d239 46class ResolverException : public PDNSException
12c86877
BH
47{
48public:
dd079764 49 ResolverException(const string &reason_) : PDNSException(reason_){}
12c86877
BH
50};
51
0c01dd7c 52// make an IPv4 or IPv6 query socket
f688119e 53int makeQuerySocket(const ComboAddress& local, bool udpOrTCP, bool nonLocalBind=false);
0c01dd7c
BH
54//! Resolver class. Can be used synchronously and asynchronously, over IPv4 and over IPv6 (simultaneously)
55class Resolver : public boost::noncopyable
12c86877
BH
56{
57public:
58 Resolver();
59 ~Resolver();
12c86877
BH
60
61 typedef vector<DNSResourceRecord> res_t;
0c01dd7c 62 //! synchronously resolve domain|type at IP, store result in result, rcode in ret
d622042f 63 int resolve(const ComboAddress &ip, const DNSName &domain, int type, res_t* result, const ComboAddress& local);
95302209 64
d622042f 65 int resolve(const ComboAddress &ip, const DNSName &domain, int type, res_t* result);
95302209 66
0c01dd7c 67 //! only send out a resolution request
7f24b6c6 68 uint16_t sendResolve(const ComboAddress& remote, const ComboAddress& local, const DNSName &domain, int type, int *localsock, bool dnssecOk=false,
561434a6 69 const DNSName& tsigkeyname=DNSName(), const DNSName& tsigalgorithm=DNSName(), const string& tsigsecret="");
95302209 70
0c01dd7c 71 //! see if we got a SOA response from our sendResolve
40c9a111 72 bool tryGetSOASerial(DNSName *theirDomain, ComboAddress* remote, uint32_t* theirSerial, uint32_t* theirInception, uint32_t* theirExpire, uint16_t* id);
3696224d 73
0c01dd7c 74 //! convenience function that calls resolve above
d622042f 75 void getSoaSerial(const ComboAddress&, const DNSName &, uint32_t *);
12c86877
BH
76
77private:
95302209 78 std::map<std::string, int> locals;
0c01dd7c
BH
79};
80
81class AXFRRetriever : public boost::noncopyable
82{
83 public:
fc396d56 84 AXFRRetriever(const ComboAddress& remote,
98c9ec39 85 const DNSName& zone,
86 const TSIGTriplet& tt = TSIGTriplet(),
db8f9152 87 const ComboAddress* laddr = NULL,
e07c3801
RG
88 size_t maxReceivedBytes=0,
89 uint16_t timeout=10);
db8f9152 90 ~AXFRRetriever();
99bea744 91 int getChunk(Resolver::res_t &res, vector<DNSRecord>* records=0, uint16_t timeout=10);
0c01dd7c
BH
92
93 private:
e07c3801 94 void connect(uint16_t timeout);
b726c127 95 int getLength(uint16_t timeout);
99bea744 96 void timeoutReadn(uint16_t bytes, uint16_t timeoutsec=10);
0c01dd7c
BH
97
98 shared_array<char> d_buf;
99 string d_domain;
100 int d_sock;
101 int d_soacount;
102 ComboAddress d_remote;
60a1c204
RG
103 TSIGTCPVerifier d_tsigVerifier;
104
db8f9152
RG
105 size_t d_receivedBytes;
106 size_t d_maxReceivedBytes;
ab4994df 107 TSIGRecordContent d_trc;
12c86877
BH
108};
109
93afc0a3 110
680f25f8 111#endif /* PDNS_RESOLVER_HH */