Permalink
Browse files

actually truncate packet when setting TC, closes #1092

  • Loading branch information...
1 parent c6f9468 commit add935a230b8ad0029f7f88ee8f13569b85db896 @Habbie Habbie committed Nov 4, 2013
View
@@ -46,6 +46,7 @@ DNSPacketWriter::DNSPacketWriter(vector<uint8_t>& 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<dnsheader*>( &*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()))
View
@@ -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;
};
@@ -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
}
}
@@ -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
@@ -0,0 +1,2 @@
+#!/bin/sh
+cleandig big.arthur.example.net txt | sed 's/\(.*\tIN\t[A-Z0-9]\+\t\)\([0-9]\+\)/\13600/'
@@ -0,0 +1 @@
+Verify that truncated messages are empty.
@@ -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

0 comments on commit add935a

Please sign in to comment.