1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 14:57:34 +00:00

LookupServer: Retry with 0x20 randomization turned off on EREFUSED

Apparently some authoritative servers don't handle 0x20 randomization
well and may send EREFUSED. Retry with randomization turned off then.

Reference: https://github.com/dns-violations/dns-violations/blob/master/2017/DVE-2017-0006.md

More work towards #10.
This commit is contained in:
Andreas Kling 2020-01-26 13:45:15 +01:00
parent 00be9b33b1
commit a9ec2225a5
6 changed files with 48 additions and 11 deletions

View file

@ -161,7 +161,7 @@ void LookupServer::service_client(RefPtr<CLocalSocket> socket)
}
}
Vector<String> LookupServer::lookup(const String& hostname, bool& did_timeout, unsigned short record_type)
Vector<String> LookupServer::lookup(const String& hostname, bool& did_timeout, unsigned short record_type, ShouldRandomizeCase should_randomize_case)
{
if (auto it = m_lookup_cache.find(hostname); it != m_lookup_cache.end()) {
auto& cached_lookup = it->value;
@ -172,7 +172,7 @@ Vector<String> LookupServer::lookup(const String& hostname, bool& did_timeout, u
}
DNSRequest request;
request.add_question(hostname, record_type);
request.add_question(hostname, record_type, should_randomize_case);
auto buffer = request.to_byte_buffer();
@ -216,6 +216,15 @@ Vector<String> LookupServer::lookup(const String& hostname, bool& did_timeout, u
dbgprintf("LookupServer: ID mismatch (%u vs %u) :(\n", response.id(), request.id());
return {};
}
if (response.code() == DNSResponse::Code::REFUSED) {
if (should_randomize_case == ShouldRandomizeCase::Yes) {
// Retry with 0x20 case randomization turned off.
return lookup(hostname, did_timeout, record_type, ShouldRandomizeCase::No);
}
return {};
}
if (response.question_count() != request.question_count()) {
dbgprintf("LookupServer: Question count (%u vs %u) :(\n", response.question_count(), request.question_count());
return {};