]> granicus.if.org Git - pdns/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, 11 Apr 2018 09:33:10 +0000 (11:33 +0200)
pdns/misc.cc
pdns/resolver.cc
pdns/resolver.hh
pdns/rpzloader.cc

index bd58036ce51eff538e5434edbf840ad4b90d201f..219d0e003431bc85bee79c543b2a7f7a4d04cf36 100644 (file)
@@ -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;
     }
index 24e9cc97924c9a08a89bec760b1aac66a8873356..c96d7edb5de58a1e8447f5938e5213f7d89c4fbe 100644 (file)
@@ -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<char>(new char[65536]);
     d_remote = remote; // mostly for error reporting
-    this->connect();
+    this->connect(timeout);
     d_soacount = 0;
   
     vector<uint8_t> 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);
index 419aa032eaf3fb94d724a457be4bf4e12af5b808..38ef39f0671fe2e5cdfd487c9cf0cf37cd7c9f75 100644 (file)
@@ -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<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 a135608f0ec9ca6bb69d723126fc4333c3ed77d2..bb077e8108b20916b9cae1d8c0ea917f36060546 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;