Skip to content

Commit

Permalink
actually honour the startRecord compress parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
Habbie committed Jul 9, 2019
1 parent d26fa31 commit 02e7763
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
3 changes: 2 additions & 1 deletion pdns/dnswriter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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 "<<matchlen<<" bytes from the back, offset: "<<li<<", dnslen: "<<dns.size()<<endl;
Expand Down
2 changes: 1 addition & 1 deletion pdns/dnswriter.hh
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ private:

uint16_t d_truncatemarker; // end of header, for truncate
DNSResourceRecord::Place d_recordplace;
bool d_canonic, d_lowerCase;
bool d_canonic, d_lowerCase, d_compress{false};
};

typedef vector<pair<string::size_type, string::size_type> > labelparts_t;
Expand Down
30 changes: 30 additions & 0 deletions pdns/test-dnswriter_cc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint8_t> 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.");

Expand Down

0 comments on commit 02e7763

Please sign in to comment.