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.
25 #include <sys/types.h>
32 #include <sys/socket.h>
33 #include <netinet/in.h>
34 #include <arpa/inet.h>
37 #include "pdnsexception.hh"
39 #include "namespaces.hh"
40 #include "dnsrecords.hh"
41 #include "dnssecinfra.hh"
42 #include "tsigverifier.hh"
44 class ResolverException : public PDNSException
47 ResolverException(const string &reason_) : PDNSException(reason_){}
50 // make an IPv4 or IPv6 query socket
51 int makeQuerySocket(const ComboAddress& local, bool udpOrTCP, bool nonLocalBind=false);
52 //! Resolver class. Can be used synchronously and asynchronously, over IPv4 and over IPv6 (simultaneously)
53 class Resolver : public boost::noncopyable
59 typedef vector<DNSResourceRecord> res_t;
60 //! synchronously resolve domain|type at IP, store result in result, rcode in ret
61 int resolve(const ComboAddress &ip, const DNSName &domain, int type, res_t* result, const ComboAddress& local);
63 int resolve(const ComboAddress &ip, const DNSName &domain, int type, res_t* result);
65 //! only send out a resolution request
66 uint16_t sendResolve(const ComboAddress& remote, const ComboAddress& local, const DNSName &domain, int type, int *localsock, bool dnssecOk=false,
67 const DNSName& tsigkeyname=DNSName(), const DNSName& tsigalgorithm=DNSName(), const string& tsigsecret="");
69 //! see if we got a SOA response from our sendResolve
70 bool tryGetSOASerial(DNSName *theirDomain, ComboAddress* remote, uint32_t* theirSerial, uint32_t* theirInception, uint32_t* theirExpire, uint16_t* id);
72 //! convenience function that calls resolve above
73 void getSoaSerial(const ComboAddress&, const DNSName &, uint32_t *);
76 std::map<std::string, int> locals;
81 int parseResult(MOADNSParser& mdp, const DNSName& origQname, uint16_t origQtype, uint16_t id, Resolver::res_t* result);
82 } // namespace resolver