]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Merge pull request #8901 from rgacogne/ddist-docs-8683
authorRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 5 Mar 2020 22:04:50 +0000 (23:04 +0100)
committerGitHub <noreply@github.com>
Thu, 5 Mar 2020 22:04:50 +0000 (23:04 +0100)
dnsdist: Fix documentation for functions removed in 1.3.0

40 files changed:
modules/bindbackend/bindbackend2.cc
modules/gmysqlbackend/smysql.cc
modules/gpgsqlbackend/spgsql.cc
pdns/auth-packetcache.cc
pdns/auth-querycache.cc
pdns/auth-querycache.hh
pdns/backends/gsql/gsqlbackend.cc
pdns/backends/gsql/gsqlbackend.hh
pdns/dbdnsseckeeper.cc
pdns/dnsbackend.cc
pdns/dnsdist-lua.cc
pdns/dnsdistdist/docs/reference/config.rst
pdns/dnsdistdist/docs/reference/index.rst
pdns/dnsdistdist/docs/reference/netmask.rst
pdns/dnsdistdist/docs/rules-actions.rst
pdns/dnsdistdist/docs/upgrade_guide.rst
pdns/dnsname.cc
pdns/dnsname.hh
pdns/dnspacket.cc
pdns/dnspacket.hh
pdns/dnsproxy.cc
pdns/dnsrecords.cc
pdns/dnswriter.cc
pdns/ixfrutils.cc
pdns/lua-auth4.cc
pdns/nameserver.cc
pdns/packethandler.cc
pdns/sdig.cc
pdns/serialtweaker.cc
pdns/slavecommunicator.cc
pdns/ssqlite3.cc
pdns/tcpreceiver.cc
pdns/test-packetcache_cc.cc
pdns/tkey.cc
pdns/ueberbackend.cc
pdns/ueberbackend.hh
pdns/ws-auth.cc
pdns/zoneparser-tng.cc
pdns/zoneparser-tng.hh
regression-tests.dnsdist/test_DOH.py

index fe383aa8b956aa36debeae73663c295c417dcf06..9e6c33c38dc867f9a9d9883fd91719f864c4de0a 100644 (file)
@@ -34,6 +34,8 @@
 #include <sstream>
 #include <boost/algorithm/string.hpp>
 #include <system_error>
+#include <unordered_map>
+#include <unordered_set>
 
 #include "pdns/dnsseckeeper.hh"
 #include "pdns/dnssecinfra.hh"
@@ -325,7 +327,7 @@ void Bind2Backend::getUpdatedMasters(vector<DomainInfo> *changedDomains)
       di.notified_serial=i->d_lastnotified;
       di.backend=this;
       di.kind=DomainInfo::Master;
-      consider.push_back(di);
+      consider.push_back(std::move(di));
     }
   }
 
@@ -346,7 +348,7 @@ void Bind2Backend::getUpdatedMasters(vector<DomainInfo> *changedDomains)
       }
       if(di.notified_serial)  { // don't do notification storm on startup
         di.serial=soadata.serial;
-        changedDomains->push_back(di);
+        changedDomains->push_back(std::move(di));
       }
     }
   }
@@ -359,6 +361,7 @@ void Bind2Backend::getAllDomains(vector<DomainInfo> *domains, bool include_disab
   // prevent deadlock by using getSOA() later on
   {
     ReadLock rl(&s_state_lock);
+    domains->reserve(s_state.size());
 
     for(state_t::const_iterator i = s_state.begin(); i != s_state.end() ; ++i) {
       DomainInfo di;
@@ -368,7 +371,7 @@ void Bind2Backend::getAllDomains(vector<DomainInfo> *domains, bool include_disab
       di.kind=i->d_kind;
       di.masters=i->d_masters;
       di.backend=this;
-      domains->push_back(di);
+      domains->push_back(std::move(di));
     };
   }
 
@@ -390,6 +393,7 @@ void Bind2Backend::getUnfreshSlaveInfos(vector<DomainInfo> *unfreshDomains)
   vector<DomainInfo> domains;
   {
     ReadLock rl(&s_state_lock);
+    domains.reserve(s_state.size());
     for(state_t::const_iterator i = s_state.begin(); i != s_state.end() ; ++i) {
       if(i->d_kind != DomainInfo::Slave)
         continue;
@@ -400,9 +404,10 @@ void Bind2Backend::getUnfreshSlaveInfos(vector<DomainInfo> *unfreshDomains)
       sd.last_check=i->d_lastcheck;
       sd.backend=this;
       sd.kind=DomainInfo::Slave;
-      domains.push_back(sd);
+      domains.push_back(std::move(sd));
     }
   }
+  unfreshDomains->reserve(domains.size());
 
   for(DomainInfo &sd :  domains) {
     SOAData soadata;
@@ -414,7 +419,7 @@ void Bind2Backend::getUnfreshSlaveInfos(vector<DomainInfo> *unfreshDomains)
     catch(...){}
     sd.serial=soadata.serial;
     if(sd.last_check+soadata.refresh < (unsigned int)time(0))
-      unfreshDomains->push_back(sd);    
+      unfreshDomains->push_back(std::move(sd));
   }
 }
 
@@ -510,7 +515,7 @@ void Bind2Backend::insertRecord(std::shared_ptr<recordstorage_t>& records, const
   if(zoneName.empty())
     ;
   else if(bdr.qname.isPartOf(zoneName))
-    bdr.qname = bdr.qname.makeRelative(zoneName);
+    bdr.qname.makeUsRelative(zoneName);
   else {
     string msg = "Trying to insert non-zone data, name='"+bdr.qname.toLogString()+"', qtype="+qtype.getName()+", zone='"+zoneName.toLogString()+"'";
     if(s_ignore_broken_records) {
@@ -537,7 +542,7 @@ void Bind2Backend::insertRecord(std::shared_ptr<recordstorage_t>& records, const
     bdr.auth=true;
 
   bdr.ttl=ttl;
-  records->insert(bdr);
+  records->insert(std::move(bdr));
 }
 
 string Bind2Backend::DLReloadNowHandler(const vector<string>&parts, Utility::pid_t ppid)
@@ -803,8 +808,8 @@ void Bind2Backend::doEmptyNonTerminals(std::shared_ptr<recordstorage_t>& records
 {
   bool auth;
   DNSName shorter;
-  set<DNSName> qnames;
-  map<DNSName, bool> nonterm;
+  std::unordered_set<DNSName> qnames;
+  std::unordered_map<DNSName, bool> nonterm;
 
   uint32_t maxent = ::arg().asNum("max-ent-entries");
 
@@ -830,7 +835,7 @@ void Bind2Backend::doEmptyNonTerminals(std::shared_ptr<recordstorage_t>& records
         }
 
         if (!nonterm.count(shorter)) {
-          nonterm.insert(pair<DNSName, bool>(shorter, auth));
+          nonterm.emplace(shorter, auth);
           --maxent;
         } else if (auth)
           nonterm[shorter] = true;
@@ -899,7 +904,7 @@ void Bind2Backend::loadConfig(string* status)
     sort(domains.begin(), domains.end()); // put stuff in inode order
     for(vector<BindDomainInfo>::const_iterator i=domains.begin();
         i!=domains.end();
-        ++i) 
+        ++i)
       {
         if (!(i->hadFileDirective)) {
           g_log<<Logger::Warning<<d_logprefix<<" Zone '"<<i->name<<"' has no 'file' directive set in "<<getArg("config")<<endl;
@@ -1134,7 +1139,7 @@ void Bind2Backend::lookup(const QType &qtype, const DNSName &qname, int zoneId,
 
   if (zoneId >= 0) {
     if ((found = (safeGetBBDomainInfo(zoneId, &bbd) && qname.isPartOf(bbd.d_name)))) {
-      domain = bbd.d_name;
+      domain = std::move(bbd.d_name);
     }
   } else {
     domain = qname;
@@ -1156,17 +1161,17 @@ void Bind2Backend::lookup(const QType &qtype, const DNSName &qname, int zoneId,
   d_handle.id=bbd.d_id;
   d_handle.qname=qname.makeRelative(domain); // strip domain name
   d_handle.qtype=qtype;
-  d_handle.domain=domain;
+  d_handle.domain=std::move(domain);
 
   if(!bbd.d_loaded) {
     d_handle.reset();
-    throw DBException("Zone for '"+bbd.d_name.toLogString()+"' in '"+bbd.d_filename+"' temporarily not available (file missing, or master dead)"); // fsck
+    throw DBException("Zone for '"+d_handle.domain.toLogString()+"' in '"+bbd.d_filename+"' temporarily not available (file missing, or master dead)"); // fsck
   }
     
   if(!bbd.current()) {
-    g_log<<Logger::Warning<<"Zone '"<<bbd.d_name<<"' ("<<bbd.d_filename<<") needs reloading"<<endl;
+    g_log<<Logger::Warning<<"Zone '"<<d_handle.domain<<"' ("<<bbd.d_filename<<") needs reloading"<<endl;
     queueReloadAndStore(bbd.d_id);
-    if (!safeGetBBDomainInfo(domain, &bbd))
+    if (!safeGetBBDomainInfo(d_handle.domain, &bbd))
       throw DBException("Zone '"+bbd.d_name.toLogString()+"' ("+bbd.d_filename+") gone after reload"); // if we don't throw here, we crash for some reason
   }
 
@@ -1424,7 +1429,7 @@ bool Bind2Backend::searchRecords(const string &pattern, int maxResults, vector<D
           r.qtype=ri->qtype;
           r.ttl=ri->ttl;
           r.auth = ri->auth;
-          result.push_back(r);
+          result.push_back(std::move(r));
         }
       }
     }
index 9de744c5aa6f4ba4ff90d79ec4f3eb7af4cf0199..74087425e262d9462638628033df0ff56c18e238 100644 (file)
@@ -283,10 +283,10 @@ public:
         g_log<<Logger::Warning<<"Result field at row " << d_residx << " column " << i << " has been truncated, we allocated " << d_res_bind[i].buffer_length << " bytes but at least " << *d_res_bind[i].length << " was needed" << endl;
       }
       if (*d_res_bind[i].is_null) {
-        row.push_back("");
+        row.emplace_back("");
         continue;
       } else {
-        row.push_back(string((char*)d_res_bind[i].buffer, std::min(d_res_bind[i].buffer_length, *d_res_bind[i].length)));
+        row.emplace_back((char*)d_res_bind[i].buffer, std::min(d_res_bind[i].buffer_length, *d_res_bind[i].length));
       }
     }
 
@@ -326,7 +326,7 @@ public:
 
     while(hasNextRow()) {
       nextRow(row);
-      result.push_back(row); 
+      result.push_back(std::move(row));
     }
 
     return this; 
index 7ca9d42230b8017cd2fe7a4d2290b09a93c3f793..68e5be885fc7cf88d576a52ed39185d3481c27c0 100644 (file)
@@ -149,12 +149,12 @@ public:
     row.reserve(PQnfields(d_res));
     for(i=0;i<PQnfields(d_res);i++) {
       if (PQgetisnull(d_res, d_residx, i)) {
-        row.push_back("");
+        row.emplace_back("");
       } else if (PQftype(d_res, i) == 16) { // BOOLEAN
         char *val = PQgetvalue(d_res, d_residx, i);
-        row.push_back(val[0] == 't' ? "1" : "0");
+        row.emplace_back(val[0] == 't' ? "1" : "0");
       } else {
-        row.push_back(string(PQgetvalue(d_res, d_residx, i)));
+        row.emplace_back(PQgetvalue(d_res, d_residx, i));
       }
     }
     d_residx++;
@@ -171,7 +171,7 @@ public:
     if (d_res == NULL) return this;
     result.reserve(d_resnum);
     row_t row;
-    while(hasNextRow()) { nextRow(row); result.push_back(row); }
+    while(hasNextRow()) { nextRow(row); result.push_back(std::move(row)); }
     return this;
   }
 
index 7759c8c07156ecbcd110496de81da0feb7d0aa3b..fd96a16257336a5436ce4011cffc0f3e2579439a 100644 (file)
@@ -170,7 +170,7 @@ void AuthPacketCache::insert(DNSPacket& q, DNSPacket& r, unsigned int maxTTL)
     }
 
     /* no existing entry found to refresh */
-    mc.d_map.insert(entry);
+    mc.d_map.insert(std::move(entry));
 
     if (*d_statnumentries >= d_maxEntries) {
       /* remove the least recently inserted or replaced entry */
@@ -178,7 +178,7 @@ void AuthPacketCache::insert(DNSPacket& q, DNSPacket& r, unsigned int maxTTL)
       sidx.pop_front();
     }
     else {
-      (*d_statnumentries)++;
+      ++(*d_statnumentries);
     }
   }
 }
index b9b13602c15a7159bafa6c62dd91c853c15875d8..1baa52109229ed0ede439640f419c1f6350bd87b 100644 (file)
@@ -86,7 +86,7 @@ bool AuthQueryCache::getEntry(const DNSName &qname, const QType& qtype, vector<D
   }
 }
 
-void AuthQueryCache::insert(const DNSName &qname, const QType& qtype, const vector<DNSZoneRecord>& value, uint32_t ttl, int zoneID)
+void AuthQueryCache::insert(const DNSName &qname, const QType& qtype, vector<DNSZoneRecord>&& value, uint32_t ttl, int zoneID)
 {
   cleanupIfNeeded();
 
@@ -99,7 +99,7 @@ void AuthQueryCache::insert(const DNSName &qname, const QType& qtype, const vect
   val.ttd = now + ttl;
   val.qname = qname;
   val.qtype = qtype.getCode();
-  val.drs = value;
+  val.drs = std::move(value);
   val.zoneID = zoneID;
 
   auto& mc = getMap(val.qname);
@@ -116,7 +116,7 @@ void AuthQueryCache::insert(const DNSName &qname, const QType& qtype, const vect
     tie(place, inserted) = mc.d_map.insert(val);
 
     if (!inserted) {
-      mc.d_map.replace(place, val);
+      mc.d_map.replace(place, std::move(val));
       moveCacheItemToBack<SequencedTag>(mc.d_map, place);
     }
     else {
index 889634bb60dd88dc8a7abc469ca9404df53bed02..c62230b2280f73f2984f0e9fd5e7d5e09bd7ffd9 100644 (file)
@@ -39,7 +39,7 @@ public:
   AuthQueryCache(size_t mapsCount=1024);
   ~AuthQueryCache();
 
-  void insert(const DNSName &qname, const QType& qtype, const vector<DNSZoneRecord>& content, uint32_t ttl, int zoneID);
+  void insert(const DNSName &qname, const QType& qtype, vector<DNSZoneRecord>&& content, uint32_t ttl, int zoneID);
 
   bool getEntry(const DNSName &qname, const QType& qtype, vector<DNSZoneRecord>& entry, int zoneID);
 
index d223a0618bb28684830496d50321c916b9d9ece6..3687c61a5a04223ad846f32b98280b0c626a30e5 100644 (file)
@@ -1796,12 +1796,15 @@ bool GSQLBackend::searchComments(const string &pattern, int maxResults, vector<C
   return false;
 }
 
-void GSQLBackend::extractRecord(const SSqlStatement::row_t& row, DNSResourceRecord& r)
+void GSQLBackend::extractRecord(SSqlStatement::row_t& row, DNSResourceRecord& r)
 {
+  static const int defaultTTL = ::arg().asNum( "default-ttl" );
+
   if (row[1].empty())
-      r.ttl = ::arg().asNum( "default-ttl" );
+      r.ttl = defaultTTL;
   else
       r.ttl=pdns_stou(row[1]);
+
   if(!d_qname.empty())
     r.qname=d_qname;
   else
@@ -1809,10 +1812,13 @@ void GSQLBackend::extractRecord(const SSqlStatement::row_t& row, DNSResourceReco
 
   r.qtype=row[3];
 
-  if (r.qtype==QType::MX || r.qtype==QType::SRV)
+  if (r.qtype==QType::MX || r.qtype==QType::SRV) {
+    r.content.reserve(row[2].size() + row[0].size() + 1);
     r.content=row[2]+" "+row[0];
-  else
-    r.content=row[0];
+  }
+  else {
+    r.content=std::move(row[0]);
+  }
 
   r.last_modified=0;
 
@@ -1826,14 +1832,14 @@ void GSQLBackend::extractRecord(const SSqlStatement::row_t& row, DNSResourceReco
   r.domain_id=pdns_stou(row[4]);
 }
 
-void GSQLBackend::extractComment(const SSqlStatement::row_t& row, Comment& comment)
+void GSQLBackend::extractComment(SSqlStatement::row_t& row, Comment& comment)
 {
   comment.domain_id = pdns_stou(row[0]);
   comment.qname = DNSName(row[1]);
   comment.qtype = row[2];
   comment.modified_at = pdns_stou(row[3]);
-  comment.account = row[4];
-  comment.content = row[5];
+  comment.account = std::move(row[4]);
+  comment.content = std::move(row[5]);
 }
 
 SSqlStatement::~SSqlStatement() { 
index e13290c723db1fc95c88b98e21cce90354062ffe..a98b3a83805841dfb91ffc3a42004a3299c9b3f3 100644 (file)
@@ -241,8 +241,8 @@ public:
 protected:
   bool createDomain(const DNSName &domain, const string &type, const string &masters, const string &account);
   string pattern2SQLPattern(const string& pattern);
-  void extractRecord(const SSqlStatement::row_t& row, DNSResourceRecord& rr);
-  void extractComment(const SSqlStatement::row_t& row, Comment& c);
+  void extractRecord(SSqlStatement::row_t& row, DNSResourceRecord& rr);
+  void extractComment(SSqlStatement::row_t& row, Comment& c);
   bool isConnectionUsable() {
     if (d_db) {
       return d_db->isConnectionUsable();
index e7f42a14770258378e8dddde6e52c60955b971dc..c2485628249d932353db032a9c54a126cd3dd490 100644 (file)
@@ -221,8 +221,8 @@ bool DNSSECKeeper::getFromMeta(const DNSName& zname, const std::string& key, std
   }
 
   if (ttl > 0) {
-    ReadLock l(&s_metacachelock); 
-    
+    ReadLock l(&s_metacachelock);
+
     metacache_t::const_iterator iter = s_metacache.find(tie(zname, key));
     if(iter != s_metacache.end() && iter->d_ttd > now) {
       value = iter->d_value;
@@ -232,7 +232,7 @@ bool DNSSECKeeper::getFromMeta(const DNSName& zname, const std::string& key, std
   vector<string> meta;
   d_keymetadb->getDomainMetadata(zname, key, meta);
   if(!meta.empty()) {
-    value=*meta.begin();
+    value=std::move(*meta.begin());
     isset = true;
   }
 
@@ -479,6 +479,7 @@ DNSSECKeeper::keyset_t DNSSECKeeper::getKeys(const DNSName& zone, bool useCache)
 
     if(iter != s_keycache.end() && iter->d_ttd > now) {
       keyset_t ret;
+      ret.reserve(iter->d_keys.size());
       for(const keyset_t::value_type& value :  iter->d_keys)
         ret.push_back(value);
       return ret;
@@ -507,6 +508,7 @@ DNSSECKeeper::keyset_t DNSSECKeeper::getKeys(const DNSName& zone, bool useCache)
     }
   }
   set_intersection(algoSEP.begin(), algoSEP.end(), algoNoSEP.begin(), algoNoSEP.end(), std::back_inserter(algoHasSeparateKSK));
+  retkeyset.reserve(dbkeyset.size());
 
   for(DNSBackend::KeyData& kd : dbkeyset)
   {
index 6b15ffd8ab7f4fdd683283a0e017b074fd04347f..07fe9c6d42f4f443486437957658856395374334 100644 (file)
@@ -347,6 +347,7 @@ void fillSOAData(const string &content, SOAData &data)
   // fill out data with some plausible defaults:
   // 10800 3600 604800 3600
   vector<string>parts;
+  parts.reserve(7);
   stringtok(parts,content);
   int pleft=parts.size();
 
index 9e104868d5aa1f8cc14e50956c310c5f022359d8..431b2e533ed461dd87e5b1c2ece009372a3c2d13 100644 (file)
@@ -208,7 +208,12 @@ static void parseTLSConfig(TLSConfig& config, const std::string& context, boost:
   }
 
   if (vars->count("keyLogFile")) {
+#ifdef HAVE_SSL_CTX_SET_KEYLOG_CALLBACK
     config.d_keyLogFile = boost::get<const string>((*vars)["keyLogFile"]);
+#else
+    errlog("TLS Key logging has been enabled using the 'keyLogFile' parameter to %s(), but this version of OpenSSL does not support it", context);
+    g_outputBuffer = "TLS Key logging has been enabled using the 'keyLogFile' parameter to " + context + "(), but this version of OpenSSL does not support it";
+#endif
   }
 }
 
@@ -1827,10 +1832,10 @@ static void setupLuaConfig(bool client, bool configCheck)
   });
 
   g_lua.writeFunction("addDOHLocal", [client](const std::string& addr, boost::optional<boost::variant<std::string, std::vector<std::pair<int,std::string>>>> certFiles, boost::optional<boost::variant<std::string, std::vector<std::pair<int,std::string>>>> keyFiles, boost::optional<boost::variant<std::string, vector<pair<int, std::string> > > > urls, boost::optional<localbind_t> vars) {
-#ifdef HAVE_DNS_OVER_HTTPS
     if (client) {
       return;
     }
+#ifdef HAVE_DNS_OVER_HTTPS
     setLuaSideEffect();
     if (g_configurationDone) {
       g_outputBuffer="addDOHLocal cannot be used at runtime!\n";
@@ -1862,7 +1867,7 @@ static void setupLuaConfig(bool client, bool configCheck)
       }
     }
     else {
-      frontend->d_urls = {"/"};
+      frontend->d_urls = {"/dns-query"};
     }
 
     bool reusePort = false;
@@ -2023,9 +2028,10 @@ static void setupLuaConfig(bool client, bool configCheck)
       });
 
   g_lua.writeFunction("addTLSLocal", [client](const std::string& addr, boost::variant<std::string, std::vector<std::pair<int,std::string>>> certFiles, boost::variant<std::string, std::vector<std::pair<int,std::string>>> keyFiles, boost::optional<localbind_t> vars) {
-#ifdef HAVE_DNS_OVER_TLS
-        if (client)
+        if (client) {
           return;
+        }
+#ifdef HAVE_DNS_OVER_TLS
         setLuaSideEffect();
         if (g_configurationDone) {
           g_outputBuffer="addTLSLocal cannot be used at runtime!\n";
index 7b2d484171a45d1ffaffab874266ee8496be0454..cb51d14bc6557c9f5ce8e169780398b23857d31b 100644 (file)
@@ -110,6 +110,7 @@ Listen Sockets
 
   .. versionchanged:: 1.5.0
     ``sendCacheControlHeaders``, ``sessionTimeout`` options added.
+    ``url`` now defaults to ``/dns-query`` instead of ``/``
 
   Listen on the specified address and TCP port for incoming DNS over HTTPS connections, presenting the specified X.509 certificate.
   If no certificate (or key) files are specified, listen for incoming DNS over HTTP connections instead.
@@ -118,7 +119,7 @@ Listen Sockets
                       The default port is 443.
   :param str certFile(s): The path to a X.509 certificate file in PEM format, or a list of paths to such files.
   :param str keyFile(s): The path to the private key file corresponding to the certificate, or a list of paths to such files, whose order should match the certFile(s) ones.
-  :param str-or-list urls: A base URL, or a list of base URLs, to accept queries on. Any query with a path under one of these will be treated as a DoH query. The default is /.
+  :param str-or-list urls: A base URL, or a list of base URLs, to accept queries on. Any query with a path under one of these will be treated as a DoH query. The default is /dns-query.
   :param table options: A table with key: value pairs with listen options.
 
   Options:
@@ -141,7 +142,7 @@ Listen Sockets
   * ``sessionTickets``: bool - Whether session resumption via session tickets is enabled. Default is true, meaning tickets are enabled.
   * ``numberOfStoredSessions``: int - The maximum number of sessions kept in memory at the same time. Default is 20480. Setting this value to 0 disables stored session entirely.
   * ``preferServerCiphers``: bool - Whether to prefer the order of ciphers set by the server instead of the one set by the client. Default is true, meaning that the order of the server is used.
-  * ``keyLogFile``: str - Write the TLS keys in the specified file so that an external program can decrypt TLS exchanges, in the format described in https://developer.mozilla.org/en-US/docs/Mozilla/Projects/NSS/Key_Log_Format.
+  * ``keyLogFile``: str - Write the TLS keys in the specified file so that an external program can decrypt TLS exchanges, in the format described in https://developer.mozilla.org/en-US/docs/Mozilla/Projects/NSS/Key_Log_Format. Note that this feature requires OpenSSL >= 1.1.1.
   * ``sendCacheControlHeaders``: bool - Whether to parse the response to find the lowest TTL and set a HTTP Cache-Control header accordingly. Default is true.
 
 .. function:: addTLSLocal(address, certFile(s), keyFile(s) [, options])
@@ -183,7 +184,7 @@ Listen Sockets
   * ``ocspResponses``: list - List of files containing OCSP responses, in the same order than the certificates and keys, that will be used to provide OCSP stapling responses.
   * ``minTLSVersion``: str - Minimum version of the TLS protocol to support. Possible values are 'tls1.0', 'tls1.1', 'tls1.2' and 'tls1.3'. Default is to require at least TLS 1.0. Note that this value is ignored when the GnuTLS provider is in use, and the ``ciphers`` option should be set accordingly instead. For example, 'NORMAL:!VERS-TLS1.0:!VERS-TLS1.1' will disable TLS 1.0 and 1.1.
   * ``preferServerCiphers``: bool - Whether to prefer the order of ciphers set by the server instead of the one set by the client. Default is true, meaning that the order of the server is used.
-  * ``keyLogFile``: str - Write the TLS keys in the specified file so that an external program can decrypt TLS exchanges, in the format described in https://developer.mozilla.org/en-US/docs/Mozilla/Projects/NSS/Key_Log_Format.
+  * ``keyLogFile``: str - Write the TLS keys in the specified file so that an external program can decrypt TLS exchanges, in the format described in https://developer.mozilla.org/en-US/docs/Mozilla/Projects/NSS/Key_Log_Format. Note that this feature requires OpenSSL >= 1.1.1.
 
 .. function:: setLocal(address[, options])
 
index b541b3ae463279f32bf1b86e453486b3ea21cc05..08c64c2db5b3699bcfdef013c36b61eafc595576 100644 (file)
@@ -9,6 +9,7 @@ These chapters contain extensive information on all functions and object availab
   config
   constants
   comboaddress
+  netmask
   netmaskgroup
   dnsname
   dnsnameset
index 89a66307d6c03b2267b0ef959db3f4156f36c597..102fea0b4830ea3be8b2994b2fa172e44a239831 100644 (file)
@@ -24,7 +24,7 @@ Netmask
 
   .. method:: Netmask:getMaskedNetwork() -> ComboAddress
 
-    Return a :class:`ComboAddress` object representing the base network of this netmask object after masking any additional bits if necessary (for example ``192.0.2.0`` if the netmask was constructed with ``newNetmask('192.0.2.1/24')).
+    Return a :class:`ComboAddress` object representing the base network of this netmask object after masking any additional bits if necessary (for example ``192.0.2.0`` if the netmask was constructed with ``newNetmask('192.0.2.1/24')``).
 
   .. method:: Netmask:empty() -> bool
 
index bba9781c55d39bad37b95c4cf3f320ed942e392c..c534787af791e4dccbd8e9fb42cf987d46546151 100644 (file)
@@ -1311,7 +1311,15 @@ The following actions exist.
   .. versionadded:: 1.5.0
 
   Forge a response with the specified raw bytes as record data.
-  For example, for a TXT record of "aaa" "bbbb": SpoofRawAction("\003aaa\004bbbb")
+
+  .. code-block:: Lua
+
+    -- select queries for the 'raw.powerdns.com.' name and TXT type, and answer with a "aaa" "bbb" TXT record:
+    addAction(AndRule({QNameRule('raw.powerdns.com.'), QTypeRule(DNSQType.TXT)}), SpoofRawAction("\003aaa\004bbbb"))
+    -- select queries for the 'raw-srv.powerdns.com.' name and SRV type, and answer with a '0 0 65535 srv.powerdns.com.' SRV record, setting the AA bit to 1 and the TTL to 3600s
+    addAction(AndRule({QNameRule('raw-srv.powerdns.com.'), QTypeRule(DNSQType.SRV)}), SpoofRawAction("\000\000\000\000\255\255\003srv\008powerdns\003com\000", { aa=true, ttl=3600 }))
+    -- select reverse queries for '127.0.0.1' and answer with 'localhost'
+    addAction(AndRule({QNameRule('1.0.0.127.in-addr.arpa.'), QTypeRule(DNSQType.PTR)}), SpoofRawAction("\009localhost\000"))
 
   :param string rawAnswer: The raw record data
   :param table options: A table with key: value pairs with options.
index d7349f724974506bf37044792df8b89a8179cc81..b5e62f02ab91e2c33cae001f9d4ce5fad977f0ea 100644 (file)
@@ -4,7 +4,7 @@ Upgrade Guide
 1.4.0 to 1.5.x
 --------------
 
-DOH endpoints specified in the fourth parameter of :func:`addDOHLocal` are now specified as exact URLs instead of path prefixes```
+DOH endpoints specified in the fourth parameter of :func:`addDOHLocal` are now specified as exact URLs instead of path prefixes. The default endpoint also switched from ``/`` to ``/dns-query``.
 For example, ``addDOHLocal('2001:db8:1:f00::1', '/etc/ssl/certs/example.com.pem', '/etc/ssl/private/example.com.key', { "/dns-query" })`` will now only accept queries for ``/dns-query`` and no longer for ``/dns-query/foo/bar``.
 
 The systemd service-file that is installed no longer uses the ``root`` user to start. It uses the user and group set with the ``--with-service-user`` and ``--with-service-group`` switches during
index c262d282023b6362f19bc86f8bcfe517b38ee1b7..7ebc2c4f5be07adebedb714261e2f9cdb6db4c77 100644 (file)
@@ -456,3 +456,25 @@ void DNSName::appendEscapedLabel(std::string& appendTo, const char* orig, size_t
     ++pos;
   }
 }
+
+bool DNSName::has8bitBytes() const
+{
+  const auto& s = d_storage;
+  string::size_type pos = 0;
+  uint8_t length = s.at(pos);
+  while (length > 0) {
+    for (size_t idx = 0; idx < length; idx++) {
+      ++pos;
+      char c = s.at(pos);
+      if(!((c >= 'a' && c <= 'z') ||
+           (c >= 'A' && c <= 'Z') ||
+           (c >= '0' && c <= '9') ||
+           c =='-' || c == '_' || c=='*' || c=='.' || c=='/' || c=='@' || c==' ' || c=='\\' || c==':'))
+        return true;
+    }
+    ++pos;
+    length = s.at(pos);
+  }
+
+  return false;
+}
index 1f8ddf49a107f066060d4afa005b045c11496f25..f933a62252c1c44281498414c187534248ee982c 100644 (file)
@@ -148,6 +148,9 @@ public:
   const string_t& getStorage() const {
     return d_storage;
   }
+
+  bool has8bitBytes() const; /* returns true if at least one byte of the labels forming the name is not included in [A-Za-z0-9_*./@ \\:-] */
+
 private:
   string_t d_storage;
 
index e87d0a1991896b58eecca05bdb0f80173d0ac28f..97a372be32f141afd642aab116528b22490457f7 100644 (file)
@@ -123,7 +123,7 @@ void DNSPacket::clearRecords()
   d_dedup.clear();
 }
 
-void DNSPacket::addRecord(const DNSZoneRecord &rr)
+void DNSPacket::addRecord(DNSZoneRecord&& rr)
 {
   // this removes duplicates from the packet.
   // in case we are not compressing for AXFR, no such checking is performed!
@@ -140,7 +140,7 @@ void DNSPacket::addRecord(const DNSZoneRecord &rr)
     d_dedup.insert(hash);
   }
 
-  d_rrs.push_back(rr);
+  d_rrs.push_back(std::move(rr));
 }
 
 vector<DNSZoneRecord*> DNSPacket::getAPRecords()
index 90dd156d9e68fa15a5f90be82da58d4ff1d04221..86ef68b7315af4441bb15a0261dad0b2024ae23d 100644 (file)
@@ -97,7 +97,7 @@ public:
   /** Add a DNSZoneRecord to this packet. A DNSPacket (as does a DNS Packet) has 4 kinds of resource records. Questions, 
       Answers, Authority and Additional. See RFC 1034 and 1035 for details. You can specify where a record needs to go in the
       DNSZoneRecord d_place field */
-  void addRecord(const DNSZoneRecord &);  // adds to 'rrs'
+  void addRecord(DNSZoneRecord&&);  // adds to 'rrs'
 
   void setQuestion(int op, const DNSName &qdomain, int qtype);  // wipes 'd', sets a random id, creates start of packet (domain, type, class etc)
 
index 05fd4bed19fa4c11a096ace7a19a53cd17640b81..decd631e4f5fa63d22909e53d5450d68cecc94d4 100644 (file)
@@ -114,7 +114,7 @@ bool DNSProxy::completePacket(std::unique_ptr<DNSPacket>& r, const DNSName& targ
       for (auto &ip : ips)
       {
         ip.dr.d_name = aname;
-        r->addRecord(ip);
+        r->addRecord(std::move(ip));
       }
     }
 
@@ -262,7 +262,7 @@ void DNSProxy::mainloop(void)
                 dzr.dr.d_ttl=j->first.d_ttl;
                 dzr.dr.d_place= j->first.d_place;
                 dzr.dr.d_content=j->first.d_content;
-                i->second.complete->addRecord(dzr);
+                i->second.complete->addRecord(std::move(dzr));
               }
             }
           }
index aa5ae30cec90c4d0af3aba270e2a634e155ceec2..2f2268bf544c342e8d2a102cd316cfa94a7666cb 100644 (file)
@@ -191,7 +191,7 @@ void OPTRecordContent::getData(vector<pair<uint16_t, string> >& options)
 
     string field(d_data.c_str() + pos, len);
     pos+=len;
-    options.push_back(make_pair(code, field));
+    options.push_back(make_pair(code, std::move(field)));
   }
 }
 
index 82ddce707367178b49dac2d05531515996fdce61..1cbd2b219c4f40598b5526dd950a46ad191bfcc1 100644 (file)
@@ -53,9 +53,9 @@ DNSPacketWriter::DNSPacketWriter(vector<uint8_t>& content, const DNSName& qname,
   dnsheader.opcode=opcode;
 
   const uint8_t* ptr=(const uint8_t*)&dnsheader;
-  uint32_t len=d_content.size();
-  d_content.resize(len + sizeof(dnsheader));
-  uint8_t* dptr=(&*d_content.begin()) + len;
+  d_content.reserve(sizeof(dnsheader) + qname.wirelength() + sizeof(qtype) + sizeof(qclass));
+  d_content.resize(sizeof(dnsheader));
+  uint8_t* dptr=(&*d_content.begin());
 
   memcpy(dptr, ptr, sizeof(dnsheader));
   d_namepositions.reserve(16);
index cf38c1c1f2ed48a0a7d7c9a57c409ba61f5557d7..feec7c33927eb86f217b07502a184c46f3bbb3a5 100644 (file)
@@ -92,10 +92,9 @@ uint32_t getSerialFromDir(const std::string& dir)
 
 uint32_t getSerialFromRecords(const records_t& records, DNSRecord& soaret)
 {
-  DNSName root(".");
   uint16_t t=QType::SOA;
 
-  auto found = records.equal_range(tie(root, t));
+  auto found = records.equal_range(tie(g_rootdnsname, t));
 
   for(auto iter = found.first; iter != found.second; ++iter) {
     auto soa = std::dynamic_pointer_cast<SOARecordContent>(iter->d_content);
index f990f18b488177c54eee06bd75a133662739ea13..ede5d1b038e5b55ab9c4cbe5132c35879e6b3d0e 100644 (file)
@@ -54,8 +54,8 @@ void AuthLua4::postPrepareContext() {
   d_lw->registerFunction<DNSPacket, void(unsigned int)>("setOpCode", [](DNSPacket &p, unsigned int opcode) { return p.setOpcode(static_cast<uint16_t>(opcode)); });
   d_lw->registerFunction<DNSPacket, void(int)>("setRcode", [](DNSPacket &p, int rcode) { return p.setRcode(rcode); });
   d_lw->registerFunction<DNSPacket, void()>("clearRecords",[](DNSPacket &p){p.clearRecords();});
-  d_lw->registerFunction<DNSPacket, void(DNSRecord&, bool)>("addRecord", [](DNSPacket &p, DNSRecord &dr, bool auth) { DNSZoneRecord dzr; dzr.dr = dr; dzr.auth = auth; p.addRecord(dzr); });
-  d_lw->registerFunction<DNSPacket, void(const vector<pair<unsigned int, DNSRecord> >&)>("addRecords", [](DNSPacket &p, const vector<pair<unsigned int, DNSRecord> >& records){ for(const auto &dr: records){ DNSZoneRecord dzr; dzr.dr = std::get<1>(dr); dzr.auth = true; p.addRecord(dzr); }});
+  d_lw->registerFunction<DNSPacket, void(DNSRecord&, bool)>("addRecord", [](DNSPacket &p, DNSRecord &dr, bool auth) { DNSZoneRecord dzr; dzr.dr = dr; dzr.auth = auth; p.addRecord(std::move(dzr)); });
+  d_lw->registerFunction<DNSPacket, void(const vector<pair<unsigned int, DNSRecord> >&)>("addRecords", [](DNSPacket &p, const vector<pair<unsigned int, DNSRecord> >& records){ for(const auto &dr: records){ DNSZoneRecord dzr; dzr.dr = std::get<1>(dr); dzr.auth = true; p.addRecord(std::move(dzr)); }});
   d_lw->registerFunction<DNSPacket, void(unsigned int, const DNSName&, const std::string&)>("setQuestion", [](DNSPacket &p, unsigned int opcode, const DNSName &name, const string &type){ QType qtype; qtype = type; p.setQuestion(static_cast<int>(opcode), name, static_cast<int>(qtype.getCode())); });
   d_lw->registerFunction<DNSPacket, bool()>("isEmpty", [](DNSPacket &p){return p.isEmpty();});
   d_lw->registerFunction<DNSPacket, std::shared_ptr<DNSPacket>()>("replyPacket",[](DNSPacket& p){ return p.replyPacket();});
index 2a8b3a5bfbc3c62d335f6ed48db7dbbca2fc005f..bac4ede45fccae5778034c538158641ef07b4e2e 100644 (file)
@@ -222,7 +222,7 @@ UDPNameserver::UDPNameserver( bool additional_socket )
 
 void UDPNameserver::send(DNSPacket& p)
 {
-  string buffer=p.getString();
+  const string& buffer=p.getString();
   g_rs.submitResponse(p, true);
 
   struct msghdr msgh;
index 580039217b07a391e9381b218fb0e6284526152e..197bab40a55d99a5c124b01353a6240938753978 100644 (file)
@@ -125,7 +125,7 @@ bool PacketHandler::addCDNSKEY(DNSPacket& p, std::unique_ptr<DNSPacket>& r, cons
     rr.dr.d_name=p.qdomain;
     rr.dr.d_content=std::make_shared<DNSKEYRecordContent>(value.first.getDNSKEY());
     rr.auth=true;
-    r->addRecord(rr);
+    r->addRecord(std::move(rr));
     haveOne=true;
   }
 
@@ -134,7 +134,7 @@ bool PacketHandler::addCDNSKEY(DNSPacket& p, std::unique_ptr<DNSPacket>& r, cons
 
     while(B.get(rr)) {
       rr.dr.d_ttl=sd.minimum;
-      r->addRecord(rr);
+      r->addRecord(std::move(rr));
       haveOne=true;
     }
   }
@@ -164,7 +164,7 @@ bool PacketHandler::addDNSKEY(DNSPacket& p, std::unique_ptr<DNSPacket>& r, const
     rr.dr.d_name=p.qdomain;
     rr.dr.d_content=std::make_shared<DNSKEYRecordContent>(value.first.getDNSKEY());
     rr.auth=true;
-    r->addRecord(rr);
+    r->addRecord(std::move(rr));
     haveOne=true;
   }
 
@@ -173,7 +173,7 @@ bool PacketHandler::addDNSKEY(DNSPacket& p, std::unique_ptr<DNSPacket>& r, const
 
     while(B.get(rr)) {
       rr.dr.d_ttl=sd.minimum;
-      r->addRecord(rr);
+      r->addRecord(std::move(rr));
       haveOne=true;
     }
   }
@@ -216,7 +216,7 @@ bool PacketHandler::addCDS(DNSPacket& p, std::unique_ptr<DNSPacket>& r, const SO
     }
     for(auto const &digestAlgo : digestAlgos){
       rr.dr.d_content=std::make_shared<DSRecordContent>(makeDSFromDNSKey(p.qdomain, value.first.getDNSKEY(), pdns_stou(digestAlgo)));
-      r->addRecord(rr);
+      r->addRecord(DNSZoneRecord(rr));
       haveOne=true;
     }
   }
@@ -226,7 +226,7 @@ bool PacketHandler::addCDS(DNSPacket& p, std::unique_ptr<DNSPacket>& r, const SO
 
     while(B.get(rr)) {
       rr.dr.d_ttl=sd.minimum;
-      r->addRecord(rr);
+      r->addRecord(std::move(rr));
       haveOne=true;
     }
   }
@@ -247,7 +247,7 @@ bool PacketHandler::addNSEC3PARAM(const DNSPacket& p, std::unique_ptr<DNSPacket>
     ns3prc.d_flags = 0; // the NSEC3PARAM 'flag' is defined to always be zero in RFC5155.
     rr.dr.d_content=std::make_shared<NSEC3PARAMRecordContent>(ns3prc);
     rr.auth = true;
-    r->addRecord(rr);
+    r->addRecord(std::move(rr));
     return true;
   }
   return false;
@@ -300,7 +300,7 @@ int PacketHandler::doChaosRequest(const DNSPacket& p, std::unique_ptr<DNSPacket>
     rr.dr.d_name=target;
     rr.dr.d_type=QType::TXT;
     rr.dr.d_class=QClass::CHAOS;
-    r->addRecord(rr);
+    r->addRecord(std::move(rr));
     return 1;
   }
 
@@ -486,8 +486,10 @@ int PacketHandler::doAdditionalProcessingAndDropAA(DNSPacket& p, std::unique_ptr
         toAdd.push_back(rr);
       }
     }
-    for(const auto& rec : toAdd)
-      r->addRecord(rec);
+
+    for(auto& rec : toAdd) {
+      r->addRecord(std::move(rec));
+    }
     
     //records.insert(records.end(), toAdd.cbegin(), toAdd.cend()); // would be faster, but no dedup
   }
@@ -535,7 +537,7 @@ void PacketHandler::emitNSEC(std::unique_ptr<DNSPacket>& r, const SOAData& sd, c
   rr.dr.d_place = (mode == 5 ) ? DNSResourceRecord::ANSWER: DNSResourceRecord::AUTHORITY;
   rr.auth = true;
 
-  r->addRecord(rr);
+  r->addRecord(std::move(rr));
 }
 
 void PacketHandler::emitNSEC3(std::unique_ptr<DNSPacket>& r, const SOAData& sd, const NSEC3PARAMRecordContent& ns3prc, const DNSName& name, const string& namehash, const string& nexthash, int mode)
@@ -588,7 +590,7 @@ void PacketHandler::emitNSEC3(std::unique_ptr<DNSPacket>& r, const SOAData& sd,
   rr.dr.d_place = (mode == 5 ) ? DNSResourceRecord::ANSWER: DNSResourceRecord::AUTHORITY;
   rr.auth = true;
 
-  r->addRecord(rr);
+  r->addRecord(std::move(rr));
 }
 
 /*
@@ -940,22 +942,10 @@ int PacketHandler::processNotify(const DNSPacket& p)
   return 0;
 }
 
-static bool validDNSName(const DNSName &name)
+static bool validDNSName(const DNSNamename)
 {
   if (!g_8bitDNS) {
-    string::size_type pos, length;
-    char c;
-    for(const auto& s : name.getRawLabels()) {
-      length=s.length();
-      for(pos=0; pos < length; ++pos) {
-        c=s[pos];
-        if(!((c >= 'a' && c <= 'z') ||
-             (c >= 'A' && c <= 'Z') ||
-             (c >= '0' && c <= '9') ||
-             c =='-' || c == '_' || c=='*' || c=='.' || c=='/' || c=='@' || c==' ' || c=='\\' || c==':'))
-          return false;
-      }
-    }
+    return name.has8bitBytes() == false;
   }
   return true;
 }
@@ -985,7 +975,7 @@ void PacketHandler::makeNXDomain(DNSPacket& p, std::unique_ptr<DNSPacket>& r, co
   DNSZoneRecord rr;
   rr=makeEditedDNSZRFromSOAData(d_dk, sd, DNSResourceRecord::AUTHORITY);
   rr.dr.d_ttl=sd.getNegativeTTL();
-  r->addRecord(rr);
+  r->addRecord(std::move(rr));
 
   if(d_dnssec) {
     addNSECX(p, r, target, wildcard, sd.qname, 4);
@@ -999,7 +989,7 @@ void PacketHandler::makeNOError(DNSPacket& p, std::unique_ptr<DNSPacket>& r, con
   DNSZoneRecord rr;
   rr=makeEditedDNSZRFromSOAData(d_dk, sd, DNSResourceRecord::AUTHORITY);
   rr.dr.d_ttl=sd.getNegativeTTL();
-  r->addRecord(rr);
+  r->addRecord(std::move(rr));
 
   if(d_dnssec) {
     addNSECX(p, r, target, wildcard, sd.qname, mode);
@@ -1018,7 +1008,7 @@ bool PacketHandler::addDSforNS(DNSPacket& p, std::unique_ptr<DNSPacket>& r, cons
   while(B.get(rr)) {
     gotOne=true;
     rr.dr.d_place = DNSResourceRecord::AUTHORITY;
-    r->addRecord(rr);
+    r->addRecord(std::move(rr));
   }
   return gotOne;
 }
@@ -1028,16 +1018,17 @@ bool PacketHandler::tryReferral(DNSPacket& p, std::unique_ptr<DNSPacket>& r, con
   vector<DNSZoneRecord> rrset = getBestReferralNS(p, sd, target);
   if(rrset.empty())
     return false;
-  
+
+  DNSName name = rrset.begin()->dr.d_name;
   for(auto& rr: rrset) {
     rr.dr.d_place=DNSResourceRecord::AUTHORITY;
-    r->addRecord(rr);
+    r->addRecord(std::move(rr));
   }
   if(!retargeted)
     r->setA(false);
 
-  if(d_dk.isSecuredZone(sd.qname) && !addDSforNS(p, r, sd, rrset.begin()->dr.d_name) && d_dnssec) {
-    addNSECX(p, r, rrset.begin()->dr.d_name, DNSName(), sd.qname, 1);
+  if(d_dk.isSecuredZone(sd.qname) && !addDSforNS(p, r, sd, name) && d_dnssec) {
+    addNSECX(p, r, name, DNSName(), sd.qname, 1);
   }
 
   return true;
@@ -1063,7 +1054,7 @@ bool PacketHandler::tryDNAME(DNSPacket& p, std::unique_ptr<DNSPacket>& r, const
   if(!rrset.empty()) {
     for(auto& rr: rrset) {
       rr.dr.d_place = DNSResourceRecord::ANSWER;
-      r->addRecord(rr);
+      r->addRecord(std::move(rr));
     }
     return true;
   }
@@ -1093,7 +1084,7 @@ bool PacketHandler::tryWildcard(DNSPacket& p, std::unique_ptr<DNSPacket>& r, con
       }
   
       rr.dr.d_place=DNSResourceRecord::ANSWER;
-      r->addRecord(rr);
+      r->addRecord(std::move(rr));
     }
   }
   if(d_dnssec && !nodata) {
@@ -1308,7 +1299,7 @@ std::unique_ptr<DNSPacket> PacketHandler::doQuestion(DNSPacket& p)
 
     if(p.qtype.getCode() == QType::SOA && sd.qname==p.qdomain) {
       rr=makeEditedDNSZRFromSOAData(d_dk, sd);
-      r->addRecord(rr);
+      r->addRecord(std::move(rr));
       goto sendit;
     }
 
@@ -1503,7 +1494,7 @@ std::unique_ptr<DNSPacket> PacketHandler::doQuestion(DNSPacket& p)
     if(weRedirected) {
       for(auto& loopRR: rrset) {
         if(loopRR.dr.d_type == QType::CNAME) {
-          r->addRecord(loopRR);
+          r->addRecord(DNSZoneRecord(loopRR));
           target = getRR<CNAMERecordContent>(loopRR.dr)->getTarget();
           retargetcount++;
           goto retargeted;
@@ -1518,7 +1509,7 @@ std::unique_ptr<DNSPacket> PacketHandler::doQuestion(DNSPacket& p)
             continue;
 #endif
         if((p.qtype.getCode() == QType::ANY || loopRR.dr.d_type == p.qtype.getCode()) && loopRR.dr.d_type && loopRR.dr.d_type != QType::ALIAS && loopRR.auth) {
-          r->addRecord(loopRR);
+          r->addRecord(DNSZoneRecord(loopRR));
           haveRecords = true;
         }
       }
index 83a921e9df521fc846db31afff4fe9870c4de11f..1279d91ffe599674ddbac8f143fca127204d9823 100644 (file)
@@ -84,7 +84,7 @@ void fillPacket(vector<uint8_t>& packet, const string& q, const string& t,
 
   if (xpfcode) {
     ComboAddress src(xpfsrc), dst(xpfdst);
-    pw.startRecord(DNSName("."), xpfcode, 0, QClass::IN, DNSResourceRecord::ADDITIONAL);
+    pw.startRecord(g_rootdnsname, xpfcode, 0, QClass::IN, DNSResourceRecord::ADDITIONAL);
     // xpf->toPacket(pw);
     pw.xfr8BitInt(xpfversion);
     pw.xfr8BitInt(xpfproto);
index 3ec6fe7494c3f6aad979a31e087ff0edcc1fc581..b4573b9c275ebe341d0e7d0d4af5e1f834a88d3e 100644 (file)
@@ -176,7 +176,7 @@ DNSZoneRecord makeEditedDNSZRFromSOAData(DNSSECKeeper& dk, const SOAData& sd, DN
   dzr.domain_id = sd.domain_id;
   dzr.signttl = sd.ttl;
   dzr.auth = true;
-  dzr.dr = soa;
+  dzr.dr = std::move(soa);
 
   return dzr;
 }
index 6ca612850406fa09f6a8b8b6b8680be8785fe244..8a55e4125ba34e8ebe082c634b982cbfc7b835f7 100644 (file)
@@ -768,6 +768,7 @@ void CommunicatorClass::slaveRefresh(PacketHandler *P)
   {
     Lock l(&d_lock);
     set<DomainInfo> requeue;
+    rdomains.reserve(d_tocheck.size());
     for(const auto& di: d_tocheck) {
       if(d_inprogress.count(di.zone)) {
         g_log<<Logger::Debug<<"Got NOTIFY for "<<di.zone<<" while AXFR in progress, requeueing SOA check"<<endl;
@@ -802,6 +803,7 @@ void CommunicatorClass::slaveRefresh(PacketHandler *P)
   if(rdomains.empty()) { // if we have priority domains, check them first
     B->getUnfreshSlaveInfos(&rdomains);
   }
+  sdomains.reserve(rdomains.size());
   DNSSECKeeper dk(B); // NOW HEAR THIS! This DK uses our B backend, so no interleaved access!
   {
     Lock l(&d_lock);
@@ -859,7 +861,7 @@ void CommunicatorClass::slaveRefresh(PacketHandler *P)
         dni.localaddr.sin4.sin_family = 0;
       }
 
-      sdomains.push_back(dni);
+      sdomains.push_back(std::move(dni));
     }
   }
   if(sdomains.empty())
index 507f2cd2353973e40bbe7250bae9c12870570bc3..0c0eb207aa0901f21fc73d99b9516f5ac258d2ca 100644 (file)
@@ -113,10 +113,10 @@ public:
     for ( int i=0; i<numCols; i++)
     {
       if (sqlite3_column_type(d_stmt,i) == SQLITE_NULL) {
-        row.push_back("");
+        row.emplace_back("");
       } else {
         const char *pData = (const char*) sqlite3_column_text(d_stmt, i);
-        row.push_back(string(pData, sqlite3_column_bytes(d_stmt, i)));
+        row.emplace_back(pData, sqlite3_column_bytes(d_stmt, i));
       }
     }
     d_rc = sqlite3_step(d_stmt);
@@ -128,7 +128,7 @@ public:
     while(hasNextRow()) {
       row_t row;
       nextRow(row);
-      result.push_back(row);
+      result.push_back(std::move(row));
     }
     return this;
   }
index 8de12d61f5ed7f980107e5effc6ccc83a6cc20d0..80cf3f9f4ca9ad0f9c7db036cf3042a38a71b449 100644 (file)
@@ -648,7 +648,7 @@ int TCPNameserver::doAXFR(const DNSName &target, std::unique_ptr<DNSPacket>& q,
   // SOA *must* go out first, our signing pipe might reorder
   DLOG(g_log<<"Sending out SOA"<<endl);
   DNSZoneRecord soa = makeEditedDNSZRFromSOAData(dk, sd);
-  outpacket->addRecord(soa);
+  outpacket->addRecord(DNSZoneRecord(soa));
   if(securedZone && !presignedZone) {
     set<DNSName> authSet;
     authSet.insert(target);
@@ -1043,7 +1043,7 @@ int TCPNameserver::doAXFR(const DNSName &target, std::unique_ptr<DNSPacket>& q,
   DLOG(g_log<<"Done writing out records"<<endl);
   /* and terminate with yet again the SOA record */
   outpacket=getFreshAXFRPacket(q);
-  outpacket->addRecord(soa);
+  outpacket->addRecord(std::move(soa));
   if(haveTSIGDetails && !tsigkeyname.empty())
     outpacket->setTSIGDetails(trc, tsigkeyname, tsigsecret, trc.d_mac, true); 
   
@@ -1167,7 +1167,7 @@ int TCPNameserver::doIXFR(std::unique_ptr<DNSPacket>& q, int outsock)
     // SOA *must* go out first, our signing pipe might reorder
     DLOG(g_log<<"Sending out SOA"<<endl);
     DNSZoneRecord soa = makeEditedDNSZRFromSOAData(dk, sd);
-    outpacket->addRecord(soa);
+    outpacket->addRecord(std::move(soa));
     if(securedZone && outpacket->d_dnssecOk) {
       set<DNSName> authSet;
       authSet.insert(target);
index 1655abe42a67b3fdef1c90890864464e4219c700..39f5911998ff5d868320b4183132fb5ce0a60366 100644 (file)
@@ -23,7 +23,7 @@ BOOST_AUTO_TEST_CASE(test_AuthQueryCacheSimple) {
   vector<DNSZoneRecord> records;
 
   BOOST_CHECK_EQUAL(QC.size(), 0U);
-  QC.insert(DNSName("hello"), QType(QType::A), records, 3600, 1);
+  QC.insert(DNSName("hello"), QType(QType::A), vector<DNSZoneRecord>(records), 3600, 1);
   BOOST_CHECK_EQUAL(QC.size(), 1U);
   BOOST_CHECK_EQUAL(QC.purge(), 1U);
   BOOST_CHECK_EQUAL(QC.size(), 0U);
@@ -34,10 +34,10 @@ BOOST_AUTO_TEST_CASE(test_AuthQueryCacheSimple) {
       DNSName a=DNSName("hello ")+DNSName(std::to_string(counter));
       BOOST_CHECK_EQUAL(DNSName(a.toString()), a);
 
-      QC.insert(a, QType(QType::A), records, 3600, 1);
+      QC.insert(a, QType(QType::A), vector<DNSZoneRecord>(records), 3600, 1);
       if(!QC.purge(a.toString()))
        BOOST_FAIL("Could not remove entry we just added to the query cache!");
-      QC.insert(a, QType(QType::A), records, 3600, 1);
+      QC.insert(a, QType(QType::A), vector<DNSZoneRecord>(records), 3600, 1);
     }
 
     BOOST_CHECK_EQUAL(QC.size(), counter);
@@ -77,7 +77,7 @@ try
   vector<DNSZoneRecord> records;
   unsigned int offset=(unsigned int)(unsigned long)a;
   for(unsigned int counter=0; counter < 100000; ++counter)
-    g_QC->insert(DNSName("hello ")+DNSName(std::to_string(counter+offset)), QType(QType::A), records, 3600, 1);
+    g_QC->insert(DNSName("hello ")+DNSName(std::to_string(counter+offset)), QType(QType::A), vector<DNSZoneRecord>(records), 3600, 1);
   return 0;
 }
  catch(PDNSException& e) {
@@ -264,7 +264,7 @@ BOOST_AUTO_TEST_CASE(test_QueryCacheClean) {
     vector<DNSZoneRecord> records;
 
     for(unsigned int counter = 0; counter < 1000000; ++counter) {
-      QC.insert(DNSName("hello ")+DNSName(std::to_string(counter)), QType(QType::A), records, 1, 1);
+      QC.insert(DNSName("hello ")+DNSName(std::to_string(counter)), QType(QType::A), vector<DNSZoneRecord>(records), 1, 1);
     }
 
     sleep(1);
index d1dc180ba08fbde3ef527e8c3b104a1e8fd35e48..7f7e5da313e35667d2f739223caa245e69b385f2 100644 (file)
@@ -79,7 +79,7 @@ void PacketHandler::tkeyHandler(const DNSPacket& p, std::unique_ptr<DNSPacket>&
   zrr.dr.d_class = QClass::ANY;
   zrr.dr.d_content = tkey_out;
   zrr.dr.d_place = DNSResourceRecord::ANSWER;
-  r->addRecord(zrr);
+  r->addRecord(std::move(zrr));
 
   if (sign)
   {
index 266b25be13f452c05d2abbe1665743ddd90e2900..5fd0a3936e08b3b95d9d11c44f4011e76766265a 100644 (file)
@@ -528,7 +528,7 @@ void UeberBackend::addNegCache(const Question &q)
   QC.insert(q.qname, q.qtype, vector<DNSZoneRecord>(), d_negcache_ttl, q.zoneId);
 }
 
-void UeberBackend::addCache(const Question &q, const vector<DNSZoneRecord> &rrs)
+void UeberBackend::addCache(const Question &q, vector<DNSZoneRecord> &&rrs)
 {
   extern AuthQueryCache QC;
 
@@ -543,7 +543,7 @@ void UeberBackend::addCache(const Question &q, const vector<DNSZoneRecord> &rrs)
      return;
   }
 
-  QC.insert(q.qname, q.qtype, rrs, store_ttl, q.zoneId);
+  QC.insert(q.qname, q.qtype, std::move(rrs), store_ttl, q.zoneId);
 }
 
 void UeberBackend::alsoNotifies(const DNSName &domain, set<string> *ips)
@@ -647,7 +647,7 @@ bool UeberBackend::get(DNSZoneRecord &rr)
     }
     else {
       // cout<<"adding query cache"<<endl;
-      addCache(d_question, d_answers);
+      addCache(d_question, std::move(d_answers));
     }
     d_answers.clear();
     return false;
index 131cf1d184e33d2e3266f274a5d1950683ea4975..09c3b451b15b585c1e1ed07dca095d11431f5c0a 100644 (file)
@@ -160,6 +160,6 @@ private:
 
   int cacheHas(const Question &q, vector<DNSZoneRecord> &rrs);
   void addNegCache(const Question &q);
-  void addCache(const Question &q, const vector<DNSZoneRecord> &rrs);
+  void addCache(const Question &q, vector<DNSZoneRecord>&& rrs);
   
 };
index 6fb3637fa4ab39eb86cb75d1b8e4de3548b8534b..8a8c4336e9a325744d287f63c649e58558814b9a 100644 (file)
@@ -325,8 +325,10 @@ static inline string makeBackendRecordContent(const QType& qtype, const string&
 static Json::object getZoneInfo(const DomainInfo& di, DNSSECKeeper* dk) {
   string zoneId = apiZoneNameToId(di.zone);
   vector<string> masters;
-  for(const auto& m : di.masters)
+  masters.reserve(di.masters.size());
+  for(const auto& m : di.masters) {
     masters.push_back(m.toStringWithPortExcept(53));
+  }
 
   auto obj = Json::object {
     // id is the canonical lookup key, which doesn't actually match the name (in some cases)
@@ -335,7 +337,7 @@ static Json::object getZoneInfo(const DomainInfo& di, DNSSECKeeper* dk) {
     { "name", di.zone.toString() },
     { "kind", di.getKindString() },
     { "account", di.account },
-    { "masters", masters },
+    { "masters", std::move(masters) },
     { "serial", (double)di.serial },
     { "notified_serial", (double)di.notified_serial },
     { "last_check", (double)di.last_check }
@@ -1727,6 +1729,7 @@ static void apiServerZones(HttpRequest* req, HttpResponse* resp) {
   }
 
   Json::array doc;
+  doc.reserve(domains.size());
   for(const DomainInfo& di : domains) {
     doc.push_back(getZoneInfo(di, with_dnssec ? &dk : nullptr));
   }
index 3a1bc444d35302467d765ed158d915def74cc749..0dc2b646701900218566b8921b7d3d670e35223e 100644 (file)
@@ -294,36 +294,37 @@ bool ZoneParserTNG::get(DNSResourceRecord& rr, std::string* comment)
     comment->clear();
   if(comment && d_line.find(';') != string::npos)
     *comment = d_line.substr(d_line.find(';'));
-  parts_t parts;
-  vstringtok(parts, d_line);
 
-  if(parts.empty())
+  d_parts.clear();
+  vstringtok(d_parts, d_line);
+
+  if(d_parts.empty())
     goto retry;
 
-  if(parts[0].first != parts[0].second && d_line[parts[0].first]==';') // line consisting of nothing but comments
+  if(d_parts[0].first != d_parts[0].second && d_line[d_parts[0].first]==';') // line consisting of nothing but comments
     goto retry;
 
   if(d_line[0]=='$') { 
-    string command=makeString(d_line, parts[0]);
-    if(pdns_iequals(command,"$TTL") && parts.size() > 1) {
-      d_defaultttl=makeTTLFromZone(trim_right_copy_if(makeString(d_line, parts[1]), is_any_of(";")));
+    string command=makeString(d_line, d_parts[0]);
+    if(pdns_iequals(command,"$TTL") && d_parts.size() > 1) {
+      d_defaultttl=makeTTLFromZone(trim_right_copy_if(makeString(d_line, d_parts[1]), is_any_of(";")));
       d_havedollarttl=true;
     }
-    else if(pdns_iequals(command,"$INCLUDE") && parts.size() > 1 && d_fromfile) {
-      string fname=unquotify(makeString(d_line, parts[1]));
+    else if(pdns_iequals(command,"$INCLUDE") && d_parts.size() > 1 && d_fromfile) {
+      string fname=unquotify(makeString(d_line, d_parts[1]));
       if(!fname.empty() && fname[0]!='/' && !d_reldir.empty())
         fname=d_reldir+"/"+fname;
       stackFile(fname);
     }
-    else if(pdns_iequals(command, "$ORIGIN") && parts.size() > 1) {
-      d_zonename = DNSName(makeString(d_line, parts[1]));
+    else if(pdns_iequals(command, "$ORIGIN") && d_parts.size() > 1) {
+      d_zonename = DNSName(makeString(d_line, d_parts[1]));
     }
-    else if(pdns_iequals(command, "$GENERATE") && parts.size() > 2) {
+    else if(pdns_iequals(command, "$GENERATE") && d_parts.size() > 2) {
       if (!d_generateEnabled) {
         throw exception("$GENERATE is not allowed in this zone");
       }
       // $GENERATE 1-127 $ CNAME $.0
-      string range=makeString(d_line, parts[1]);
+      string range=makeString(d_line, d_parts[1]);
       d_templatestep=1;
       d_templatestop=0;
       sscanf(range.c_str(),"%u-%u/%u", &d_templatecounter, &d_templatestop, &d_templatestep);
@@ -338,10 +339,10 @@ bool ZoneParserTNG::get(DNSResourceRecord& rr, std::string* comment)
         }
       }
       d_templateline=d_line;
-      parts.pop_front();
-      parts.pop_front();
+      d_parts.pop_front();
+      d_parts.pop_front();
 
-      d_templateparts=parts;
+      d_templateparts=d_parts;
       goto retry;
     }
     else
@@ -350,13 +351,13 @@ bool ZoneParserTNG::get(DNSResourceRecord& rr, std::string* comment)
   }
 
   bool prevqname=false;
-  string qname = makeString(d_line, parts[0]); // Don't use DNSName here!
+  string qname = makeString(d_line, d_parts[0]); // Don't use DNSName here!
   if(dns_isspace(d_line[0])) {
     rr.qname=d_prevqname;
     prevqname=true;
   }else {
     rr.qname=DNSName(qname); 
-    parts.pop_front();
+    d_parts.pop_front();
     if(qname.empty() || qname[0]==';')
       goto retry;
   }
@@ -366,7 +367,7 @@ bool ZoneParserTNG::get(DNSResourceRecord& rr, std::string* comment)
     rr.qname += d_zonename;
   d_prevqname=rr.qname;
 
-  if(parts.empty()) 
+  if(d_parts.empty())
     throw exception("Line with too little parts "+getLineOfFile());
 
   string nextpart;
@@ -375,9 +376,9 @@ bool ZoneParserTNG::get(DNSResourceRecord& rr, std::string* comment)
   bool haveTTL=0, haveQTYPE=0;
   pair<string::size_type, string::size_type> range;
 
-  while(!parts.empty()) {
-    range=parts.front();
-    parts.pop_front();
+  while(!d_parts.empty()) {
+    range=d_parts.front();
+    d_parts.pop_front();
     nextpart=makeString(d_line, range);
     if(nextpart.empty())
       break;
index 8cb2788a22532b7884efe08c7fb5528f28173c35..4b16a465656a236ff9fa2c8043ca509dcee0db9e 100644 (file)
@@ -30,7 +30,7 @@
 class ZoneParserTNG
 {
 public:
-  ZoneParserTNG(const string& fname, const DNSName& zname=DNSName("."), const string& reldir="");
+  ZoneParserTNG(const string& fname, const DNSName& zname=g_rootdnsname, const string& reldir="");
   ZoneParserTNG(const vector<string> zonedata, const DNSName& zname);
 
   ~ZoneParserTNG();
@@ -61,6 +61,7 @@ private:
     int d_lineno;
   };
 
+  parts_t d_parts;
   string d_reldir;
   string d_line;
   DNSName d_prevqname;
index ec60470bdaeccf4f33bec16561de30b48a2602e2..f7d2f4f3c8fa3e7cdce4f2dda88b4816c9aa9a55 100644 (file)
@@ -720,7 +720,7 @@ class TestDOHOverHTTP(DNSDistDOHTest):
 
     _dohServerPort = 8480
     _serverName = 'tls.tests.dnsdist.org'
-    _dohBaseURL = ("http://%s:%d/" % (_serverName, _dohServerPort))
+    _dohBaseURL = ("http://%s:%d/dns-query" % (_serverName, _dohServerPort))
     _config_template = """
     newServer{address="127.0.0.1:%s"}
     addDOHLocal("127.0.0.1:%s")
@@ -788,7 +788,7 @@ class TestDOHWithCache(DNSDistDOHTest):
     _serverName = 'tls.tests.dnsdist.org'
     _caCert = 'ca.pem'
     _dohServerPort = 8443
-    _dohBaseURL = ("https://%s:%d/" % (_serverName, _dohServerPort))
+    _dohBaseURL = ("https://%s:%d/dns-query" % (_serverName, _dohServerPort))
     _config_template = """
     newServer{address="127.0.0.1:%s"}