From: Remi Gacogne Date: Wed, 11 Apr 2018 09:33:10 +0000 (+0200) Subject: rec: Respect the AXFR timeout while connecting to the server X-Git-Tag: dnsdist-1.3.1~161^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e07c3801fa248c5976799e5ed3bf40479173d0e6;p=thirdparty%2Fpdns.git rec: Respect the AXFR timeout while connecting to the server --- diff --git a/pdns/misc.cc b/pdns/misc.cc index bd58036ce5..219d0e0034 100644 --- a/pdns/misc.cc +++ b/pdns/misc.cc @@ -338,10 +338,7 @@ int waitForRWData(int fd, bool waitForRead, int seconds, int useconds, bool* err pfd.events=POLLOUT; ret = poll(&pfd, 1, seconds * 1000 + useconds/1000); - if ( ret == -1 ) { - errno = ETIMEDOUT; // ??? - } - else if (ret > 0) { + if (ret > 0) { if (error && (pfd.revents & POLLERR)) { *error = true; } diff --git a/pdns/resolver.cc b/pdns/resolver.cc index 24e9cc9792..c96d7edb5d 100644 --- a/pdns/resolver.cc +++ b/pdns/resolver.cc @@ -362,7 +362,8 @@ AXFRRetriever::AXFRRetriever(const ComboAddress& remote, const DNSName& domain, const TSIGTriplet& tt, const ComboAddress* laddr, - size_t maxReceivedBytes) + size_t maxReceivedBytes, + uint16_t timeout) : d_tsigVerifier(tt, remote, d_trc), d_receivedBytes(0), d_maxReceivedBytes(maxReceivedBytes) { ComboAddress local; @@ -382,7 +383,7 @@ AXFRRetriever::AXFRRetriever(const ComboAddress& remote, throw ResolverException("Error creating socket for AXFR request to "+d_remote.toStringWithPort()); d_buf = shared_array(new char[65536]); d_remote = remote; // mostly for error reporting - this->connect(); + this->connect(timeout); d_soacount = 0; vector packet; @@ -415,7 +416,7 @@ AXFRRetriever::AXFRRetriever(const ComboAddress& remote, throw ResolverException("Partial write on AXFR request to "+d_remote.toStringWithPort()); } - int res = waitForData(d_sock, 10, 0); + int res = waitForData(d_sock, timeout, 0); if(!res) throw ResolverException("Timeout waiting for answer from "+d_remote.toStringWithPort()+" during AXFR"); @@ -504,7 +505,7 @@ void AXFRRetriever::timeoutReadn(uint16_t bytes, uint16_t timeoutsec) } } -void AXFRRetriever::connect() +void AXFRRetriever::connect(uint16_t timeout) { setNonBlocking( d_sock ); @@ -525,7 +526,7 @@ void AXFRRetriever::connect() if(!err) goto done; - err=waitForRWData(d_sock, false, 10, 0); // wait for writeability + err=waitForRWData(d_sock, false, timeout, 0); // wait for writeability if(!err) { try { @@ -542,7 +543,7 @@ void AXFRRetriever::connect() throw ResolverException("Timeout connecting to server"); } else if(err < 0) { - throw ResolverException("Error connecting: "+string(strerror(err))); + throw ResolverException("Error connecting: "+string(strerror(errno))); } else { Utility::socklen_t len=sizeof(err); diff --git a/pdns/resolver.hh b/pdns/resolver.hh index 419aa032ea..38ef39f067 100644 --- a/pdns/resolver.hh +++ b/pdns/resolver.hh @@ -85,12 +85,13 @@ class AXFRRetriever : public boost::noncopyable const DNSName& zone, const TSIGTriplet& tt = TSIGTriplet(), const ComboAddress* laddr = NULL, - size_t maxReceivedBytes=0); + size_t maxReceivedBytes=0, + uint16_t timeout=10); ~AXFRRetriever(); int getChunk(Resolver::res_t &res, vector* records=0, uint16_t timeout=10); private: - void connect(); + void connect(uint16_t timeout); int getLength(uint16_t timeout); void timeoutReadn(uint16_t bytes, uint16_t timeoutsec=10); diff --git a/pdns/rpzloader.cc b/pdns/rpzloader.cc index a135608f0e..bb077e8108 100644 --- a/pdns/rpzloader.cc +++ b/pdns/rpzloader.cc @@ -185,7 +185,7 @@ shared_ptr loadRPZFromServer(const ComboAddress& master, const if (local == ComboAddress()) local = getQueryLocalAddress(master.sin4.sin_family, 0); - AXFRRetriever axfr(master, zoneName, tt, &local, maxReceivedBytes); + AXFRRetriever axfr(master, zoneName, tt, &local, maxReceivedBytes, axfrTimeout); unsigned int nrecords=0; Resolver::res_t nop; vector chunk;