From: bert hubert Date: Fri, 26 Aug 2016 13:26:10 +0000 (+0200) Subject: save a ton of DNSName(".") and DNSName("*") instantiations. Even though these live... X-Git-Tag: dnsdist-1.1.0-beta2~166^2~9 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=12c062114657b63d05779940582f8840590543ef;p=pdns save a ton of DNSName(".") and DNSName("*") instantiations. Even though these live on the stack, we were going through needless motions. --- diff --git a/pdns/dnsrecords.cc b/pdns/dnsrecords.cc index c29323dda..ed0fa7586 100644 --- a/pdns/dnsrecords.cc +++ b/pdns/dnsrecords.cc @@ -557,7 +557,7 @@ DNSRecord makeOpt(int udpsize, int extRCode, int Z) static_assert(sizeof(EDNS0Record) == sizeof(dr.d_ttl), "sizeof(EDNS0Record) must match sizeof(DNSRecord.d_ttl)"); memcpy(&dr.d_ttl, &stuff, sizeof(stuff)); dr.d_ttl=ntohl(dr.d_ttl); - dr.d_name=DNSName("."); + dr.d_name=g_rootdnsname; dr.d_type = QType::OPT; dr.d_class=udpsize; dr.d_place=DNSResourceRecord::ADDITIONAL; diff --git a/pdns/dnssecinfra.cc b/pdns/dnssecinfra.cc index 31174acd4..6edc8297d 100644 --- a/pdns/dnssecinfra.cc +++ b/pdns/dnssecinfra.cc @@ -338,7 +338,7 @@ DNSCryptoKeyEngine* DNSCryptoKeyEngine::makeFromPEMString(DNSKEYRecordContent& d bool sharedDNSSECCompare(const shared_ptr& a, const shared_ptr& b) { - return a->serialize(DNSName("."), true, true) < b->serialize(DNSName("."), true, true); + return a->serialize(g_rootdnsname, true, true) < b->serialize(g_rootdnsname, true, true); } /** @@ -359,7 +359,7 @@ string getMessageForRRSET(const DNSName& qname, const RRSIGRecordContent& rrc, v sort(signRecords.begin(), signRecords.end(), sharedDNSSECCompare); string toHash; - toHash.append(const_cast(rrc).serialize(DNSName("."), true, true)); + toHash.append(const_cast(rrc).serialize(g_rootdnsname, true, true)); toHash.resize(toHash.size() - rrc.d_signature.length()); // chop off the end, don't sign the signature! string nameToHash(qname.toDNSStringLC()); @@ -389,7 +389,7 @@ string getMessageForRRSET(const DNSName& qname, const RRSIGRecordContent& rrc, v uint32_t ttl=htonl(rrc.d_originalttl); toHash.append((char*)&ttl, 4); // for NSEC signatures, we should not lowercase the rdata section - string rdata=add->serialize(DNSName("."), true, (add->getType() == QType::NSEC) ? false : true); // RFC 6840, 5.1 + string rdata=add->serialize(g_rootdnsname, true, (add->getType() == QType::NSEC) ? false : true); // RFC 6840, 5.1 tmp=htons(rdata.length()); toHash.append((char*)&tmp, 2); toHash.append(rdata); diff --git a/pdns/dnswriter.cc b/pdns/dnswriter.cc index 3e07a7289..475ca41ba 100644 --- a/pdns/dnswriter.cc +++ b/pdns/dnswriter.cc @@ -127,7 +127,7 @@ void DNSPacketWriter::addOpt(uint16_t udpsize, int extRCode, int Z, const vector ttl=ntohl(ttl); // will be reversed later on - startRecord(DNSName("."), QType::OPT, ttl, udpsize, DNSResourceRecord::ADDITIONAL, false); + startRecord(g_rootdnsname, QType::OPT, ttl, udpsize, DNSResourceRecord::ADDITIONAL, false); for(optvect_t::const_iterator iter = options.begin(); iter != options.end(); ++iter) { xfr16BitInt(iter->first); xfr16BitInt(iter->second.length()); diff --git a/pdns/filterpo.cc b/pdns/filterpo.cc index 7e3f08266..e17d20d41 100644 --- a/pdns/filterpo.cc +++ b/pdns/filterpo.cc @@ -48,7 +48,7 @@ bool findNamedPolicy(const map& polmap, const } while(s.chopOff()){ - iter = polmap.find(DNSName("*")+s); + iter = polmap.find(g_wildcarddnsname+s); if(iter != polmap.end()) { pol=iter->second; return true; diff --git a/pdns/nsec3dig.cc b/pdns/nsec3dig.cc index facec3ce1..fc372dcff 100644 --- a/pdns/nsec3dig.cc +++ b/pdns/nsec3dig.cc @@ -222,7 +222,7 @@ try for(const auto &n: namestocheck) { proveOrDeny(nsec3s, n, nsec3salt, nsec3iters, proven, denied); - proveOrDeny(nsec3s, DNSName("*")+n, nsec3salt, nsec3iters, proven, denied); + proveOrDeny(nsec3s, g_wildcarddnsname+n, nsec3salt, nsec3iters, proven, denied); } if(names.count(qname)) @@ -262,7 +262,7 @@ try { cout<<"next closer ("<qtype || rr.qtype.getCode() == QType::CNAME || (p->qtype.getCode() == QType::ANY && rr.qtype.getCode() != QType::RRSIG)) ret->push_back(rr); - wildcard=DNSName("*")+subdomain; + wildcard=g_wildcarddnsname+subdomain; haveSomething=true; } @@ -676,7 +676,7 @@ void PacketHandler::addNSEC3(DNSPacket *p, DNSPacket *r, const DNSName& target, // wildcard denial if (mode == 2 || mode == 4) { - unhashed=DNSName("*")+closest; + unhashed=g_wildcarddnsname+closest; hashed=hashQNameWithSalt(ns3rc, unhashed); DLOG(L<<"3 hash: "<, vector > grouped; while(zpt.get(rr)) { try { diff --git a/pdns/rec-lua-conf.cc b/pdns/rec-lua-conf.cc index f8001bf9f..2f7e055d0 100644 --- a/pdns/rec-lua-conf.cc +++ b/pdns/rec-lua-conf.cc @@ -36,7 +36,7 @@ LuaConfigItems::LuaConfigItems() { for (const auto &dsRecord : rootDSs) { auto ds=unique_ptr(dynamic_cast(DSRecordContent::make(dsRecord))); - dsAnchors[DNSName(".")].insert(*ds); + dsAnchors[g_rootdnsname].insert(*ds); } } diff --git a/pdns/reczones.cc b/pdns/reczones.cc index 63ccb27e3..790118514 100644 --- a/pdns/reczones.cc +++ b/pdns/reczones.cc @@ -46,7 +46,7 @@ void primeHints(void) if(::arg()["hint-file"].empty()) { DNSRecord arr, aaaarr, nsrr; - nsrr.d_name=DNSName("."); + nsrr.d_name=g_rootdnsname; arr.d_type=QType::A; aaaarr.d_type=QType::AAAA; nsrr.d_type=QType::NS; @@ -94,7 +94,7 @@ void primeHints(void) } } } - t_RC->replace(time(0), DNSName("."), QType(QType::NS), nsset, vector>(), true); // and stuff in the cache (auth) + t_RC->replace(time(0), g_rootdnsname, QType(QType::NS), nsset, vector>(), true); // and stuff in the cache (auth) } static void makeNameToIPZone(SyncRes::domainmap_t* newMap, const DNSName& hostname, const string& ip) diff --git a/pdns/rpzloader.cc b/pdns/rpzloader.cc index 8e4b3cb9b..3d78b2a13 100644 --- a/pdns/rpzloader.cc +++ b/pdns/rpzloader.cc @@ -82,7 +82,7 @@ void RPZRecordToPolicy(const DNSRecord& dr, DNSFilterEngine& target, bool addOrR else if(target.isRoot()) { // cerr<<"Wants NXDOMAIN for "<(DNSName("."), DNSName("."), st); + dr.d_content = std::make_shared(g_rootdnsname, g_rootdnsname, st); auto deltas = getIXFRDeltas(remote, domain, dr, tt, laddr.sin4.sin_family ? &laddr : 0, ((size_t) ::arg().asNum("xfr-max-received-mbytes")) * 1024 * 1024); zs.numDeltas=deltas.size(); // cout<<"Got "<first && wcarddomain.chopOff()) { LOG(prefix<second.d_records.equal_range(boost::make_tuple(DNSName("*")+wcarddomain)); + range=iter->second.d_records.equal_range(boost::make_tuple(g_wildcarddnsname+wcarddomain)); if(range.first==range.second) continue; @@ -1133,7 +1133,7 @@ int SyncRes::doResolveAt(NsSet &nameservers, DNSName auth, bool flawedNSSet, con t_sstorage->nsSpeeds[*tns].submit(*remoteIP, 1000000, &d_now); // 1 sec // code below makes sure we don't filter COM or the root - if (s_serverdownmaxfails > 0 && (auth != DNSName(".")) && t_sstorage->fails.incr(*remoteIP) >= s_serverdownmaxfails) { + if (s_serverdownmaxfails > 0 && (auth != g_rootdnsname) && t_sstorage->fails.incr(*remoteIP) >= s_serverdownmaxfails) { LOG(prefix<toString() <<". Going full throttle for "<< s_serverdownthrottletime <<" seconds" <throttle.throttle(d_now.tv_sec, boost::make_tuple(*remoteIP, "", 0), s_serverdownthrottletime, 10000); // mark server as down } else if(resolveret==-1) diff --git a/pdns/test-dnsname_cc.cc b/pdns/test-dnsname_cc.cc index 26f232ea8..dd7388cc6 100644 --- a/pdns/test-dnsname_cc.cc +++ b/pdns/test-dnsname_cc.cc @@ -286,7 +286,7 @@ BOOST_AUTO_TEST_CASE(test_PacketParse) { vector packet; reportBasicTypes(); DNSName root("."); - DNSPacketWriter dpw1(packet, DNSName("."), QType::AAAA); + DNSPacketWriter dpw1(packet, g_rootdnsname, QType::AAAA); DNSName p((char*)&packet[0], packet.size(), 12, false); BOOST_CHECK_EQUAL(p, root); unsigned char* buffer=&packet[0]; @@ -458,7 +458,7 @@ BOOST_AUTO_TEST_CASE(test_suffixmatch) { BOOST_CHECK(!smn.check(DNSName("www.news.gov.uk."))); - smn.add(DNSName(".")); // block the root + smn.add(g_rootdnsname); // block the root BOOST_CHECK(smn.check(DNSName("a.root-servers.net."))); } @@ -503,9 +503,9 @@ BOOST_AUTO_TEST_CASE(test_compare_canonical) { BOOST_CHECK(!DNSName("www.BeRt.com").canonCompare(DNSName("WWW.berT.com"))); CanonDNSNameCompare a; - BOOST_CHECK(a(DNSName("."), DNSName("www.powerdns.com"))); - BOOST_CHECK(a(DNSName("."), DNSName("www.powerdns.net"))); - BOOST_CHECK(!a(DNSName("www.powerdns.net"), DNSName("."))); + BOOST_CHECK(a(g_rootdnsname, DNSName("www.powerdns.com"))); + BOOST_CHECK(a(g_rootdnsname, DNSName("www.powerdns.net"))); + BOOST_CHECK(!a(DNSName("www.powerdns.net"), g_rootdnsname)); vector vec; for(const std::string& a : {"bert.com.", "alpha.nl.", "articles.xxx.", diff --git a/pdns/toysdig.cc b/pdns/toysdig.cc index 4992b0574..1900183b4 100644 --- a/pdns/toysdig.cc +++ b/pdns/toysdig.cc @@ -103,7 +103,7 @@ LuaConfigItems::LuaConfigItems() { for (const auto &dsRecord : rootDSs) { auto ds=unique_ptr(dynamic_cast(DSRecordContent::make(dsRecord))); - dsAnchors[DNSName(".")].insert(*ds); + dsAnchors[g_rootdnsname].insert(*ds); } } diff --git a/pdns/validate.cc b/pdns/validate.cc index 83f7b973a..9281118f3 100644 --- a/pdns/validate.cc +++ b/pdns/validate.cc @@ -283,7 +283,7 @@ vState getKeysFor(DNSRecordOracle& dro, const DNSName& zone, keyset_t &keyset) LOG("DNSKEY did not match the DS, parent DS: "< "<(dsrc.d_digesttype)<<"\" ]; label = \"zone: "<(drc.d_algorithm)).str()); } } @@ -486,13 +486,13 @@ void dotEdge(DNSName zone, string type1, DNSName name1, string tag1, string type { #ifdef GRAPHVIZ cout<<" "; - if(zone != DNSName(".")) cout<<"subgraph "< " <name != DNSName(".") && i->name != DNSName("localhost") && i->name != DNSName("0.0.127.in-addr.arpa") ) + if( i->name != g_rootdnsname && i->name != DNSName("localhost") && i->name != DNSName("0.0.127.in-addr.arpa") ) { cerr << "Parsing file: " << i->filename << ", domain: " << i->name << endl; g_zonename = i->name;