]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
rec: Respect the AXFR timeout while connecting to the server
authorRemi Gacogne <remi.gacogne@powerdns.com>
Wed, 11 Apr 2018 09:33:10 +0000 (11:33 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Wed, 16 May 2018 12:16:06 +0000 (14:16 +0200)
(cherry picked from commit e07c3801fa248c5976799e5ed3bf40479173d0e6)

pdns/misc.cc
pdns/resolver.cc
pdns/resolver.hh
pdns/rpzloader.cc

index 46434506950421c2192f6e99471887331cfdab7a..b32eff9bfee5a3a03aa1dbb4740cf3480ee2c0ed 100644 (file)
@@ -334,10 +334,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;
     }
index 6ab89c87be21620af0168285a512fc5fcc55172b..1669791ecf7f297d07dc40865f43015afc1f7444 100644 (file)
@@ -370,7 +370,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;
@@ -391,7 +392,7 @@ AXFRRetriever::AXFRRetriever(const ComboAddress& remote,
       throw ResolverException("Error creating socket for AXFR request to "+d_remote.toStringWithPort());
     d_buf = shared_array<char>(new char[65536]);
     d_remote = remote; // mostly for error reporting
-    this->connect();
+    this->connect(timeout);
     d_soacount = 0;
   
     vector<uint8_t> packet;
@@ -424,7 +425,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");
@@ -513,7 +514,7 @@ void AXFRRetriever::timeoutReadn(uint16_t bytes, uint16_t timeoutsec)
   }
 }
 
-void AXFRRetriever::connect()
+void AXFRRetriever::connect(uint16_t timeout)
 {
   setNonBlocking( d_sock );
 
@@ -534,7 +535,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 {
@@ -551,7 +552,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);
index 59dec932705469dfcdf5984ef9ec98189b7cf69a..8b8b023d9cd3fe4769ac617615eba51c3d0a7e53 100644 (file)
@@ -88,12 +88,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<DNSRecord>* 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);
 
index 7db92cb8458877536cc15ff6ea1c0ebd5b41b683..f549cf28cd13e1c3181acf0ff7d38a0806969010 100644 (file)
@@ -185,7 +185,7 @@ shared_ptr<SOARecordContent> 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<DNSRecord> chunk;