From: Peter van Dijk Date: Mon, 4 Nov 2013 12:44:05 +0000 (+0100) Subject: actually truncate packet when setting TC, closes #1092 X-Git-Tag: rec-3.6.0-rc1~359 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=add935a230b8ad0029f7f88ee8f13569b85db896;p=pdns actually truncate packet when setting TC, closes #1092 --- diff --git a/pdns/dnswriter.cc b/pdns/dnswriter.cc index cd30f37f2..3bd862fa6 100644 --- a/pdns/dnswriter.cc +++ b/pdns/dnswriter.cc @@ -46,6 +46,7 @@ DNSPacketWriter::DNSPacketWriter(vector& content, const string& qname, d_stuff=0xffff; d_labelmap.reserve(16); + d_truncatemarker=d_content.size(); } dnsheader* DNSPacketWriter::getHeader() @@ -294,6 +295,15 @@ void DNSPacketWriter::rollback() d_stuff=0; } +void DNSPacketWriter::truncate() +{ + d_content.resize(d_truncatemarker); + d_record.clear(); + d_stuff=0; + dnsheader* dh=reinterpret_cast( &*d_content.begin()); + dh->ancount = dh->nscount = dh->arcount = 0; +} + void DNSPacketWriter::commit() { if(d_stuff==0xffff && (d_content.size()!=d_sor || !d_record.empty())) diff --git a/pdns/dnswriter.hh b/pdns/dnswriter.hh index 7d42d0543..a3c36c232 100644 --- a/pdns/dnswriter.hh +++ b/pdns/dnswriter.hh @@ -61,6 +61,9 @@ public: /** Should the packet have grown too big for the writer's liking, rollback removes the record currently being written */ void rollback(); + /** Discard all content except the question section */ + void truncate(); + void xfr48BitInt(uint64_t val); void xfr32BitInt(uint32_t val); void xfr16BitInt(uint16_t val); @@ -120,6 +123,7 @@ private: uint16_t d_stuff; uint16_t d_sor; uint16_t d_rollbackmarker; // start of last complete packet, for rollback + uint16_t d_truncatemarker; // end of header, for truncate Place d_recordplace; bool d_canonic, d_lowerCase; }; diff --git a/pdns/pdns_recursor.cc b/pdns/pdns_recursor.cc index ce56b76f2..355bbaf0b 100644 --- a/pdns/pdns_recursor.cc +++ b/pdns/pdns_recursor.cc @@ -591,7 +591,10 @@ void startDoResolve(void *p) if(pw.size() > maxanswersize) { pw.rollback(); if(i->d_place==DNSResourceRecord::ANSWER) // only truncate if we actually omitted parts of the answer + { pw.getHeader()->tc=1; + pw.truncate(); + } goto sendit; // need to jump over pw.commit } } diff --git a/regression-tests.recursor/config.sh b/regression-tests.recursor/config.sh index d880bc542..decaa7194 100755 --- a/regression-tests.recursor/config.sh +++ b/regression-tests.recursor/config.sh @@ -95,6 +95,50 @@ ns2.arthur.example.net. 3600 IN A $PREFIX.13 www.arthur.example.net. 3600 IN A 192.0.2.2 www2.arthur.example.net. 3600 IN A 192.0.2.6 mail.arthur.example.net. 3600 IN A 192.0.2.3 +big.arthur.example.net. 3600 IN TXT "the quick brown fox jumps over the lazy dog" +big.arthur.example.net. 3600 IN TXT "The quick brown fox jumps over the lazy dog" +big.arthur.example.net. 3600 IN TXT "THe quick brown fox jumps over the lazy dog" +big.arthur.example.net. 3600 IN TXT "THE quick brown fox jumps over the lazy dog" +big.arthur.example.net. 3600 IN TXT "THE quick brown fox jumps over the lazy dog" +big.arthur.example.net. 3600 IN TXT "THE Quick brown fox jumps over the lazy dog" +big.arthur.example.net. 3600 IN TXT "THE QUick brown fox jumps over the lazy dog" +big.arthur.example.net. 3600 IN TXT "THE QUIck brown fox jumps over the lazy dog" +big.arthur.example.net. 3600 IN TXT "THE QUICk brown fox jumps over the lazy dog" +big.arthur.example.net. 3600 IN TXT "THE QUICK brown fox jumps over the lazy dog" +big.arthur.example.net. 3600 IN TXT "THE QUICK brown fox jumps over the lazy dog" +big.arthur.example.net. 3600 IN TXT "THE QUICK Brown fox jumps over the lazy dog" +big.arthur.example.net. 3600 IN TXT "THE QUICK BRown fox jumps over the lazy dog" +big.arthur.example.net. 3600 IN TXT "THE QUICK BROwn fox jumps over the lazy dog" +big.arthur.example.net. 3600 IN TXT "THE QUICK BROWn fox jumps over the lazy dog" +big.arthur.example.net. 3600 IN TXT "THE QUICK BROWN fox jumps over the lazy dog" +big.arthur.example.net. 3600 IN TXT "THE QUICK BROWN fox jumps over the lazy dog" +big.arthur.example.net. 3600 IN TXT "THE QUICK BROWN Fox jumps over the lazy dog" +big.arthur.example.net. 3600 IN TXT "THE QUICK BROWN FOx jumps over the lazy dog" +big.arthur.example.net. 3600 IN TXT "THE QUICK BROWN FOX jumps over the lazy dog" +big.arthur.example.net. 3600 IN TXT "THE QUICK BROWN FOX jumps over the lazy dog" +big.arthur.example.net. 3600 IN TXT "THE QUICK BROWN FOX Jumps over the lazy dog" +big.arthur.example.net. 3600 IN TXT "THE QUICK BROWN FOX JUmps over the lazy dog" +big.arthur.example.net. 3600 IN TXT "THE QUICK BROWN FOX JUMps over the lazy dog" +big.arthur.example.net. 3600 IN TXT "THE QUICK BROWN FOX JUMPs over the lazy dog" +big.arthur.example.net. 3600 IN TXT "THE QUICK BROWN FOX JUMPS over the lazy dog" +big.arthur.example.net. 3600 IN TXT "THE QUICK BROWN FOX JUMPS over the lazy dog" +big.arthur.example.net. 3600 IN TXT "THE QUICK BROWN FOX JUMPS Over the lazy dog" +big.arthur.example.net. 3600 IN TXT "THE QUICK BROWN FOX JUMPS OVer the lazy dog" +big.arthur.example.net. 3600 IN TXT "THE QUICK BROWN FOX JUMPS OVEr the lazy dog" +big.arthur.example.net. 3600 IN TXT "THE QUICK BROWN FOX JUMPS OVER the lazy dog" +big.arthur.example.net. 3600 IN TXT "THE QUICK BROWN FOX JUMPS OVER the lazy dog" +big.arthur.example.net. 3600 IN TXT "THE QUICK BROWN FOX JUMPS OVER The lazy dog" +big.arthur.example.net. 3600 IN TXT "THE QUICK BROWN FOX JUMPS OVER THe lazy dog" +big.arthur.example.net. 3600 IN TXT "THE QUICK BROWN FOX JUMPS OVER THE lazy dog" +big.arthur.example.net. 3600 IN TXT "THE QUICK BROWN FOX JUMPS OVER THE lazy dog" +big.arthur.example.net. 3600 IN TXT "THE QUICK BROWN FOX JUMPS OVER THE Lazy dog" +big.arthur.example.net. 3600 IN TXT "THE QUICK BROWN FOX JUMPS OVER THE LAzy dog" +big.arthur.example.net. 3600 IN TXT "THE QUICK BROWN FOX JUMPS OVER THE LAZy dog" +big.arthur.example.net. 3600 IN TXT "THE QUICK BROWN FOX JUMPS OVER THE LAZY dog" +big.arthur.example.net. 3600 IN TXT "THE QUICK BROWN FOX JUMPS OVER THE LAZY dog" +big.arthur.example.net. 3600 IN TXT "THE QUICK BROWN FOX JUMPS OVER THE LAZY Dog" +big.arthur.example.net. 3600 IN TXT "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOg" +big.arthur.example.net. 3600 IN TXT "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG" EOF mkdir $PREFIX.13 diff --git a/regression-tests.recursor/truncate-empty/command b/regression-tests.recursor/truncate-empty/command new file mode 100755 index 000000000..5898ab45d --- /dev/null +++ b/regression-tests.recursor/truncate-empty/command @@ -0,0 +1,2 @@ +#!/bin/sh +cleandig big.arthur.example.net txt | sed 's/\(.*\tIN\t[A-Z0-9]\+\t\)\([0-9]\+\)/\13600/' diff --git a/regression-tests.recursor/truncate-empty/description b/regression-tests.recursor/truncate-empty/description new file mode 100644 index 000000000..884b31246 --- /dev/null +++ b/regression-tests.recursor/truncate-empty/description @@ -0,0 +1 @@ +Verify that truncated messages are empty. diff --git a/regression-tests.recursor/truncate-empty/expected_result b/regression-tests.recursor/truncate-empty/expected_result new file mode 100644 index 000000000..11ac812a7 --- /dev/null +++ b/regression-tests.recursor/truncate-empty/expected_result @@ -0,0 +1,2 @@ +Rcode: 0, RD: 1, QR: 1, TC: 1, AA: 0, opcode: 0 +Reply to question for qname='big.arthur.example.net.', qtype=TXT