]> git.ipfire.org Git - thirdparty/pdns.git/blob - pdns/resolver.hh
Meson: Separate test files from common files
[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 #pragma once
23 #include <string>
24 #include <vector>
25 #include <sys/types.h>
26 #include "iputils.hh"
27 #include <netdb.h>
28 #include <unistd.h>
29 #include <sys/time.h>
30 #include <sys/uio.h>
31 #include <fcntl.h>
32 #include <sys/socket.h>
33 #include <netinet/in.h>
34 #include <arpa/inet.h>
35 #undef res_mkquery
36
37 #include "pdnsexception.hh"
38 #include "dns.hh"
39 #include "namespaces.hh"
40 #include "dnsrecords.hh"
41 #include "dnssecinfra.hh"
42 #include "tsigverifier.hh"
43
44 class ResolverException : public PDNSException
45 {
46 public:
47 ResolverException(const string &reason_) : PDNSException(reason_){}
48 };
49
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
54 {
55 public:
56 Resolver();
57 ~Resolver();
58
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);
62
63 int resolve(const ComboAddress &ip, const DNSName &domain, int type, res_t* result);
64
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="");
68
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);
71
72 //! convenience function that calls resolve above
73 void getSoaSerial(const ComboAddress&, const DNSName &, uint32_t *);
74
75 private:
76 std::map<std::string, int> locals;
77 };
78
79 namespace pdns {
80 namespace resolver {
81 int parseResult(MOADNSParser& mdp, const DNSName& origQname, uint16_t origQtype, uint16_t id, Resolver::res_t* result);
82 } // namespace resolver
83 } // namespace pdns