From: Remi Gacogne Date: Fri, 18 Jul 2025 10:07:12 +0000 (+0200) Subject: dnsdist: Small speedup for getEDNSUDPPayloadSizeAndZ() X-Git-Tag: rec-5.4.0-alpha0~8^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4e7c4d06db5f6421bc33ccf7d7e72b36fe4e68db;p=thirdparty%2Fpdns.git dnsdist: Small speedup for getEDNSUDPPayloadSizeAndZ() Signed-off-by: Remi Gacogne --- diff --git a/pdns/dnsparser.cc b/pdns/dnsparser.cc index 9419ddb429..93ff63dd11 100644 --- a/pdns/dnsparser.cc +++ b/pdns/dnsparser.cc @@ -1161,6 +1161,10 @@ bool getEDNSUDPPayloadSizeAndZ(const char* packet, size_t length, uint16_t* payl try { const dnsheader_aligned dh(packet); + if (dh->arcount == 0) { + return false; + } + DNSPacketMangler dpm(const_cast(packet), length); const uint16_t qdcount = ntohs(dh->qdcount); @@ -1172,17 +1176,18 @@ bool getEDNSUDPPayloadSizeAndZ(const char* packet, size_t length, uint16_t* payl const size_t numrecords = ntohs(dh->ancount) + ntohs(dh->nscount) + ntohs(dh->arcount); for(size_t n = 0; n < numrecords; ++n) { dpm.skipDomainName(); - const uint16_t dnstype = dpm.get16BitInt(); - const uint16_t dnsclass = dpm.get16BitInt(); + const auto dnstype = dpm.get16BitInt(); - if(dnstype == QType::OPT) { + if (dnstype == QType::OPT) { + const auto dnsclass = dpm.get16BitInt(); /* skip extended rcode and version */ dpm.skipBytes(2); *z = dpm.get16BitInt(); *payloadSize = dnsclass; return true; } - + /* skip class */ + dpm.skipBytes(2); /* TTL */ dpm.skipBytes(4); dpm.skipRData(); diff --git a/pdns/dnsparser.hh b/pdns/dnsparser.hh index 7a728afc25..7bd667dee3 100644 --- a/pdns/dnsparser.hh +++ b/pdns/dnsparser.hh @@ -610,7 +610,7 @@ public: void skipRData() { - int toskip = get16BitInt(); + auto toskip = get16BitInt(); moveOffset(toskip); }