From: Peter van Dijk Date: Mon, 8 Jul 2019 15:39:35 +0000 (+0200) Subject: actually honour the startRecord compress parameter X-Git-Tag: dnsdist-1.4.0-rc1~59^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=02e7763f2c7f4d2c9d7bab3a3319df1724065ef2;p=thirdparty%2Fpdns.git actually honour the startRecord compress parameter --- diff --git a/pdns/dnswriter.cc b/pdns/dnswriter.cc index 24dad7c0b6..ca95cc2435 100644 --- a/pdns/dnswriter.cc +++ b/pdns/dnswriter.cc @@ -76,6 +76,7 @@ dnsheader* DNSPacketWriter::getHeader() void DNSPacketWriter::startRecord(const DNSName& name, uint16_t qtype, uint32_t ttl, uint16_t qclass, DNSResourceRecord::Place place, bool compress) { + d_compress = compress; commit(); d_rollbackmarker=d_content.size(); @@ -327,7 +328,7 @@ void DNSPacketWriter::xfrName(const DNSName& name, bool compress, bool) uint16_t li=0; uint16_t matchlen=0; - if(compress && (li=lookupName(name, &matchlen)) && li < 16384) { + if(d_compress && compress && (li=lookupName(name, &matchlen)) && li < 16384) { const auto& dns=name.getStorage(); if(l_verbose) cout<<"Found a substring of "< > labelparts_t; diff --git a/pdns/test-dnswriter_cc.cc b/pdns/test-dnswriter_cc.cc index b9baa0593e..d4158b824e 100644 --- a/pdns/test-dnswriter_cc.cc +++ b/pdns/test-dnswriter_cc.cc @@ -13,6 +13,36 @@ BOOST_AUTO_TEST_SUITE(test_dnswriter_cc) +BOOST_AUTO_TEST_CASE(test_compressionBool) { + auto testCompressionBool = [](bool compress, size_t size1, size_t size2) { + DNSName name("powerdns.com."); + + vector packet; + DNSPacketWriter pwR(packet, name, QType::A, QClass::IN, 0); + pwR.getHeader()->qr = 1; + + pwR.startRecord(DNSName("mediumsizedlabel.example.net"), QType::A, 3600, QClass::IN, DNSResourceRecord::ANSWER, compress); + pwR.xfrIP('P'<<24 | + 'Q'<<16 | + 'R'<<8 | + 'S'); + pwR.commit(); + BOOST_CHECK_EQUAL(pwR.size(), size1); + + pwR.startRecord(DNSName("adifferentlabel.example.net"), QType::NS, 3600, QClass::IN, DNSResourceRecord::ANSWER, compress); + pwR.xfrName(DNSName("target.example.net"), true); + pwR.commit(); + BOOST_CHECK_EQUAL(pwR.size(), size2); + + string spacket(packet.begin(), packet.end()); + + BOOST_CHECK_NO_THROW(MOADNSParser mdp(false, spacket)); + }; + + testCompressionBool(true, 74, 111); + testCompressionBool(false, 74, 133); +} + BOOST_AUTO_TEST_CASE(test_compressionBoundary) { DNSName name("powerdns.com.");