2 * This file is part of PowerDNS or dnsdist.
3 * Copyright -- PowerDNS.COM B.V. and its contributors
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.
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.
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.
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.
22 #ifndef PDNS_RESOLVER_HH
23 #define PDNS_RESOLVER_HH
27 #include <sys/types.h>
34 #include <sys/socket.h>
35 #include <netinet/in.h>
36 #include <arpa/inet.h>
39 #include "pdnsexception.hh"
41 #include "namespaces.hh"
42 #include "dnsrecords.hh"
43 #include "dnssecinfra.hh"
44 #include "tsigverifier.hh"
46 class ResolverException : public PDNSException
49 ResolverException(const string &reason) : PDNSException(reason){}
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
61 typedef vector<DNSResourceRecord> res_t;
62 //! synchronously resolve domain|type at IP, store result in result, rcode in ret
63 int resolve(const string &ip, const DNSName &domain, int type, res_t* result, const ComboAddress& local);
65 int resolve(const string &ip, const DNSName &domain, int type, res_t* result);
67 //! only send out a resolution request
68 uint16_t sendResolve(const ComboAddress& remote, const ComboAddress& local, const DNSName &domain, int type, bool dnssecOk=false,
69 const DNSName& tsigkeyname=DNSName(), const DNSName& tsigalgorithm=DNSName(), const string& tsigsecret="");
71 uint16_t sendResolve(const ComboAddress& remote, const DNSName &domain, int type, bool dnssecOk=false,
72 const DNSName& tsigkeyname=DNSName(), const DNSName& tsigalgorithm=DNSName(), const string& tsigsecret="");
74 //! see if we got a SOA response from our sendResolve
75 bool tryGetSOASerial(DNSName *theirDomain, uint32_t* theirSerial, uint32_t* theirInception, uint32_t* theirExpire, uint16_t* id);
77 //! convenience function that calls resolve above
78 void getSoaSerial(const string &, const DNSName &, uint32_t *);
81 std::map<std::string, int> locals;
84 class AXFRRetriever : public boost::noncopyable
87 AXFRRetriever(const ComboAddress& remote,
89 const TSIGTriplet& tt = TSIGTriplet(),
90 const ComboAddress* laddr = NULL,
91 size_t maxReceivedBytes=0);
93 int getChunk(Resolver::res_t &res, vector<DNSRecord>* records=0);
98 void timeoutReadn(uint16_t bytes);
100 shared_array<char> d_buf;
104 ComboAddress d_remote;
105 TSIGTCPVerifier d_tsigVerifier;
107 size_t d_receivedBytes;
108 size_t d_maxReceivedBytes;
109 TSIGRecordContent d_trc;
113 #endif /* PDNS_RESOLVER_HH */