BOOST_AUTO_TEST_CASE(test_getEDNSZ) {
+ uint16_t z;
+ uint16_t udpPayloadSize;
DNSName qname("www.powerdns.com.");
uint16_t qtype = QType::A;
uint16_t qclass = QClass::IN;
pw.commit();
BOOST_CHECK_EQUAL(getZ(qname, qtype, qclass, query), 0);
- BOOST_CHECK_EQUAL(getEDNSUDPPayloadSize(reinterpret_cast<const char*>(query.data()), query.size()), 0);
+ BOOST_CHECK_EQUAL(getEDNSUDPPayloadSizeAndZ(reinterpret_cast<const char*>(query.data()), query.size(), &udpPayloadSize, &z), false);
+ BOOST_CHECK_EQUAL(z, 0);
+ BOOST_CHECK_EQUAL(udpPayloadSize, 0);
}
{
query.resize(query.size() - (/* RDLEN */ sizeof(uint16_t) + /* last byte of TTL / Z */ 1));
BOOST_CHECK_EQUAL(getZ(qname, qtype, qclass, query), 0);
- BOOST_CHECK_EQUAL(getEDNSUDPPayloadSize(reinterpret_cast<const char*>(query.data()), query.size()), 512);
+ BOOST_CHECK_EQUAL(getEDNSUDPPayloadSizeAndZ(reinterpret_cast<const char*>(query.data()), query.size(), &udpPayloadSize, &z), false);
+ BOOST_CHECK_EQUAL(z, 0);
+ BOOST_CHECK_EQUAL(udpPayloadSize, 0);
}
{
pw.commit();
BOOST_CHECK_EQUAL(getZ(qname, qtype, qclass, query), 0);
- BOOST_CHECK_EQUAL(getEDNSUDPPayloadSize(reinterpret_cast<const char*>(query.data()), query.size()), 512);
+ BOOST_CHECK_EQUAL(getEDNSUDPPayloadSizeAndZ(reinterpret_cast<const char*>(query.data()), query.size(), &udpPayloadSize, &z), true);
+ BOOST_CHECK_EQUAL(z, 0);
+ BOOST_CHECK_EQUAL(udpPayloadSize, 512);
}
{
pw.commit();
BOOST_CHECK_EQUAL(getZ(qname, qtype, qclass, query), EDNS_HEADER_FLAG_DO);
- BOOST_CHECK_EQUAL(getEDNSUDPPayloadSize(reinterpret_cast<const char*>(query.data()), query.size()), 512);
+ BOOST_CHECK_EQUAL(getEDNSUDPPayloadSizeAndZ(reinterpret_cast<const char*>(query.data()), query.size(), &udpPayloadSize, &z), true);
+ BOOST_CHECK_EQUAL(z, EDNS_HEADER_FLAG_DO);
+ BOOST_CHECK_EQUAL(udpPayloadSize, 512);
}
{
pw.commit();
BOOST_CHECK_EQUAL(getZ(qname, qtype, qclass, query), 0);
- BOOST_CHECK_EQUAL(getEDNSUDPPayloadSize(reinterpret_cast<const char*>(query.data()), query.size()), 512);
+ BOOST_CHECK_EQUAL(getEDNSUDPPayloadSizeAndZ(reinterpret_cast<const char*>(query.data()), query.size(), &udpPayloadSize, &z), true);
+ BOOST_CHECK_EQUAL(z, 0);
+ BOOST_CHECK_EQUAL(udpPayloadSize, 512);
}
{
pw.commit();
BOOST_CHECK_EQUAL(getZ(qname, qtype, qclass, query), EDNS_HEADER_FLAG_DO);
- BOOST_CHECK_EQUAL(getEDNSUDPPayloadSize(reinterpret_cast<const char*>(query.data()), query.size()), 512);
+ BOOST_CHECK_EQUAL(getEDNSUDPPayloadSizeAndZ(reinterpret_cast<const char*>(query.data()), query.size(), &udpPayloadSize, &z), true);
+ BOOST_CHECK_EQUAL(z, EDNS_HEADER_FLAG_DO);
+ BOOST_CHECK_EQUAL(udpPayloadSize, 512);
}
}
BOOST_AUTO_TEST_CASE(test_addEDNSToQueryTurnedResponse) {
+ uint16_t z;
+ uint16_t udpPayloadSize;
DNSName qname("www.powerdns.com.");
uint16_t qtype = QType::A;
uint16_t qclass = QClass::IN;
auto dq = turnIntoResponse(qname, qtype, qclass, lc, rem, queryRealTime, query);
BOOST_CHECK_EQUAL(getEDNSZ(dq), 0);
- BOOST_CHECK_EQUAL(getEDNSUDPPayloadSize(reinterpret_cast<const char*>(dq.dh), dq.len), 0);
+ BOOST_CHECK_EQUAL(getEDNSUDPPayloadSizeAndZ(reinterpret_cast<const char*>(dq.dh), dq.len, &udpPayloadSize, &z), false);
+ BOOST_CHECK_EQUAL(z, 0);
+ BOOST_CHECK_EQUAL(udpPayloadSize, 0);
}
{
query.resize(query.size() - (/* RDLEN */ sizeof(uint16_t) + /* last byte of TTL / Z */ 1));
auto dq = turnIntoResponse(qname, qtype, qclass, lc, rem, queryRealTime, query);
BOOST_CHECK_EQUAL(getEDNSZ(dq), 0);
- /* 512, because we don't touch a broken OPT record */
- BOOST_CHECK_EQUAL(getEDNSUDPPayloadSize(reinterpret_cast<const char*>(dq.dh), dq.len), 512);
+ BOOST_CHECK_EQUAL(getEDNSUDPPayloadSizeAndZ(reinterpret_cast<const char*>(dq.dh), dq.len, &udpPayloadSize, &z), false);
+ BOOST_CHECK_EQUAL(z, 0);
+ BOOST_CHECK_EQUAL(udpPayloadSize, 0);
}
{
auto dq = turnIntoResponse(qname, qtype, qclass, lc, rem, queryRealTime, query);
BOOST_CHECK_EQUAL(getEDNSZ(dq), 0);
- BOOST_CHECK_EQUAL(getEDNSUDPPayloadSize(reinterpret_cast<const char*>(dq.dh), dq.len), g_PayloadSizeSelfGenAnswers);
+ BOOST_CHECK_EQUAL(getEDNSUDPPayloadSizeAndZ(reinterpret_cast<const char*>(dq.dh), dq.len, &udpPayloadSize, &z), true);
+ BOOST_CHECK_EQUAL(z, 0);
+ BOOST_CHECK_EQUAL(udpPayloadSize, g_PayloadSizeSelfGenAnswers);
}
{
auto dq = turnIntoResponse(qname, qtype, qclass, lc, rem, queryRealTime, query);
BOOST_CHECK_EQUAL(getEDNSZ(dq), EDNS_HEADER_FLAG_DO);
- BOOST_CHECK_EQUAL(getEDNSUDPPayloadSize(reinterpret_cast<const char*>(dq.dh), dq.len), g_PayloadSizeSelfGenAnswers);
+ BOOST_CHECK_EQUAL(getEDNSUDPPayloadSizeAndZ(reinterpret_cast<const char*>(dq.dh), dq.len, &udpPayloadSize, &z), true);
+ BOOST_CHECK_EQUAL(z, EDNS_HEADER_FLAG_DO);
+ BOOST_CHECK_EQUAL(udpPayloadSize, g_PayloadSizeSelfGenAnswers);
}
{
auto dq = turnIntoResponse(qname, qtype, qclass, lc, rem, queryRealTime, query);
BOOST_CHECK_EQUAL(getEDNSZ(dq), 0);
- BOOST_CHECK_EQUAL(getEDNSUDPPayloadSize(reinterpret_cast<const char*>(dq.dh), dq.len), g_PayloadSizeSelfGenAnswers);
+ BOOST_CHECK_EQUAL(getEDNSUDPPayloadSizeAndZ(reinterpret_cast<const char*>(dq.dh), dq.len, &udpPayloadSize, &z), true);
+ BOOST_CHECK_EQUAL(z, 0);
+ BOOST_CHECK_EQUAL(udpPayloadSize, g_PayloadSizeSelfGenAnswers);
}
{
auto dq = turnIntoResponse(qname, qtype, qclass, lc, rem, queryRealTime, query);
BOOST_CHECK_EQUAL(getEDNSZ(dq), EDNS_HEADER_FLAG_DO);
- BOOST_CHECK_EQUAL(getEDNSUDPPayloadSize(reinterpret_cast<const char*>(dq.dh), dq.len), g_PayloadSizeSelfGenAnswers);
+ BOOST_CHECK_EQUAL(getEDNSUDPPayloadSizeAndZ(reinterpret_cast<const char*>(dq.dh), dq.len, &udpPayloadSize, &z), true);
+ BOOST_CHECK_EQUAL(z, EDNS_HEADER_FLAG_DO);
+ BOOST_CHECK_EQUAL(udpPayloadSize, g_PayloadSizeSelfGenAnswers);
}
}
response.answer.append(rrset)
response.flags |= dns.flags.TC
+ expectedResponse = dns.message.make_response(query)
+ expectedResponse.flags |= dns.flags.TC
+
+ (receivedQuery, receivedResponse) = self.sendUDPQuery(query, response)
+ receivedQuery.id = query.id
+ self.assertEquals(query, receivedQuery)
+ self.assertEquals(expectedResponse.flags, receivedResponse.flags)
+ self.assertEquals(expectedResponse.question, receivedResponse.question)
+ self.assertFalse(response.answer == receivedResponse.answer)
+ self.assertEquals(len(receivedResponse.answer), 0)
+ self.assertEquals(len(receivedResponse.authority), 0)
+ self.assertEquals(len(receivedResponse.additional), 0)
+ self.checkMessageNoEDNS(expectedResponse, receivedResponse)
+
+ def testTruncateTCEDNS(self):
+ """
+ Basics: Truncate TC with EDNS
+
+ dnsdist is configured to truncate TC (default),
+ we make the backend send responses
+ with TC set and additional content,
+ and check that the received response has been fixed.
+ Note that the query and initial response had EDNS,
+ so the final response should have it too.
+ """
+ name = 'atruncatetc.tests.powerdns.com.'
+ query = dns.message.make_query(name, 'A', 'IN', use_edns=True, payload=4096, want_dnssec=True)
+ response = dns.message.make_response(query)
+ # force a different responder payload than the one in the query,
+ # so we check that we don't just mirror it
+ response.payload = 4242
+ rrset = dns.rrset.from_text(name,
+ 3600,
+ dns.rdataclass.IN,
+ dns.rdatatype.A,
+ '127.0.0.1')
+
+ response.answer.append(rrset)
+ response.flags |= dns.flags.TC
+ expectedResponse = dns.message.make_response(query)
+ expectedResponse.payload = 4242
+ expectedResponse.flags |= dns.flags.TC
(receivedQuery, receivedResponse) = self.sendUDPQuery(query, response)
receivedQuery.id = query.id
self.assertEquals(len(receivedResponse.answer), 0)
self.assertEquals(len(receivedResponse.authority), 0)
self.assertEquals(len(receivedResponse.additional), 0)
+ print(expectedResponse)
+ print(receivedResponse)
+ self.checkMessageEDNSWithoutOptions(expectedResponse, receivedResponse)
+ self.assertFalse(receivedResponse.ednsflags & dns.flags.DO)
+ self.assertEquals(receivedResponse.payload, 4242)
def testRegexReturnsRefused(self):
"""