]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
rec: Remove a useless copy in arecvfrom(), reserve whenever possible
authorRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 2 Aug 2018 14:52:28 +0000 (16:52 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 6 Aug 2018 08:00:22 +0000 (10:00 +0200)
pdns/lwres.cc
pdns/lwres.hh
pdns/pdns_recursor.cc
pdns/syncres.cc

index 4739ae10a3abb34a8b36f6fbf7912503ade07667..ba0c3322a6d3a4f3796c4f08d1d0c18d71104737 100644 (file)
@@ -170,7 +170,7 @@ int asyncresolve(const ComboAddress& ip, const DNSName& domain, int type, bool d
 
     // sleep until we see an answer to this, interface to mtasker
     
-    ret=arecvfrom(const_cast<char *>(buf.data()), buf.size(), 0, ip, &len, qid,
+    ret=arecvfrom(buf, 0, ip, &len, qid,
                   domain, type, queryfd, now);
   }
   else {
@@ -248,7 +248,8 @@ int asyncresolve(const ComboAddress& ip, const DNSName& domain, int type, bool d
       // unexpected count has already been done @ pdns_recursor.cc
       goto out;
     }
-    
+
+    lwr->d_records.reserve(mdp.d_answers.size());
     for(const auto& a : mdp.d_answers)
       lwr->d_records.push_back(a.first);
 
index 98c3f0845d3d33e112a1523e22dad36b1edd65a5..1397812627fadeb44d2fea7e944ee7822e19604a 100644 (file)
@@ -45,7 +45,7 @@
 
 int asendto(const char *data, size_t len, int flags, const ComboAddress& ip, uint16_t id,
             const DNSName& domain, uint16_t qtype,  int* fd);
-int arecvfrom(char *data, size_t len, int flags, const ComboAddress& ip, size_t *d_len, uint16_t id,
+int arecvfrom(std::string& packet, int flags, const ComboAddress& ip, size_t *d_len, uint16_t id,
               const DNSName& domain, uint16_t qtype, int fd, struct timeval* now);
 
 class LWResException : public PDNSException
index 4901ca45b80c578d185328242ca9a63528a45e1d..d854a7f0ee5958f665560e1498e6dbed31bf4bfa 100644 (file)
@@ -659,7 +659,7 @@ int asendto(const char *data, size_t len, int flags,
 }
 
 // -1 is error, 0 is timeout, 1 is success
-int arecvfrom(char *data, size_t len, int flags, const ComboAddress& fromaddr, size_t *d_len,
+int arecvfrom(std::string& packet, int flags, const ComboAddress& fromaddr, size_t *d_len,
               uint16_t id, const DNSName& domain, uint16_t qtype, int fd, struct timeval* now)
 {
   static optional<unsigned int> nearMissLimit;
@@ -673,7 +673,6 @@ int arecvfrom(char *data, size_t len, int flags, const ComboAddress& fromaddr, s
   pident.type = qtype;
   pident.remote=fromaddr;
 
-  string packet;
   int ret=MT->waitEvent(pident, &packet, g_networkTimeoutMsec, now);
 
   if(ret > 0) {
@@ -681,7 +680,7 @@ int arecvfrom(char *data, size_t len, int flags, const ComboAddress& fromaddr, s
       return -1;
 
     *d_len=packet.size();
-    memcpy(data,packet.c_str(),min(len,*d_len));
+
     if(*nearMissLimit && pident.nearMisses > *nearMissLimit) {
       g_log<<Logger::Error<<"Too many ("<<pident.nearMisses<<" > "<<*nearMissLimit<<") bogus answers for '"<<domain<<"' from "<<fromaddr.toString()<<", assuming spoof attempt."<<endl;
       g_stats.spoofCount++;
index 0de239d7090494a61451389750219b41cd9369e2..fd2d0dfab2c0ad7380e1e99f1d1c47a1e6f76ae3 100644 (file)
@@ -940,6 +940,7 @@ bool SyncRes::doCNAMECacheCheck(const DNSName &qname, const QType &qtype, vector
 
         DNSRecord dr=*j;
         dr.d_ttl-=d_now.tv_sec;
+        ret.reserve(ret.size() + 1 + signatures.size() + authorityRecs.size());
         ret.push_back(dr);
 
         for(const auto& signature : signatures) {
@@ -1211,6 +1212,8 @@ bool SyncRes::doCacheCheck(const DNSName &qname, const DNSName& authname, bool w
       }
     }
 
+    ret.reserve(ret.size() + signatures.size() + authorityRecs.size());
+
     for(const auto& signature : signatures) {
       DNSRecord dr;
       dr.d_type=QType::RRSIG;