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