[dns] support new resource records (PTR, SRV, TXT, KEY, SIG, OPT) (#6048)

This commit is contained in:
Abtin Keshavarzian
2021-01-10 08:31:14 -08:00
committed by Jonathan Hui
parent b179cf21be
commit 418c9afbe2
3 changed files with 939 additions and 53 deletions
+6 -6
View File
@@ -346,12 +346,12 @@ void Client::HandleUdpReceive(Message &aMessage, const Ip6::MessageInfo &aMessag
// which it sent the corresponding query to.
OT_UNUSED_VARIABLE(aMessageInfo);
otError error = OT_ERROR_NOT_FOUND;
Header responseHeader;
QueryMetadata queryMetadata;
ResourceRecordAaaa record;
Message * message = nullptr;
uint16_t offset;
otError error = OT_ERROR_NOT_FOUND;
Header responseHeader;
QueryMetadata queryMetadata;
AaaaRecord record;
Message * message = nullptr;
uint16_t offset;
SuccessOrExit(aMessage.Read(aMessage.GetOffset(), responseHeader));
VerifyOrExit(responseHeader.GetType() == Header::kTypeResponse && responseHeader.GetQuestionCount() == 1 &&
+57 -15
View File
@@ -35,6 +35,7 @@
#include "common/code_utils.hpp"
#include "common/debug.hpp"
#include "common/random.hpp"
#include "common/string.hpp"
namespace ot {
@@ -42,6 +43,62 @@ namespace Dns {
using ot::Encoding::BigEndian::HostSwap16;
otError Header::SetRandomMessageId(void)
{
return Random::Crypto::FillBuffer(reinterpret_cast<uint8_t *>(&mMessageId), sizeof(mMessageId));
}
otError Header::ResponseCodeToError(Response aResponse)
{
otError error = OT_ERROR_FAILED;
switch (aResponse)
{
case kResponseSuccess:
error = OT_ERROR_NONE;
break;
case kResponseFormatError: // Server unable to interpret request due to format error.
case kResponseBadName: // Bad name.
case kResponseBadTruncation: // Bad truncation.
case kResponseNotZone: // A name is not in the zone.
error = OT_ERROR_PARSE;
break;
case kResponseServerFailure: // Server encountered an internal failure.
error = OT_ERROR_FAILED;
break;
case kResponseNameError: // Name that ought to exist, does not exists.
case kResponseRecordNotExists: // Some RRset that out to exist, does not exist.
error = OT_ERROR_NOT_FOUND;
break;
case kResponseNotImplemented: // Server does not support the query type (OpCode).
error = OT_ERROR_NOT_IMPLEMENTED;
break;
case kResponseBadAlg: // Bad algorithm.
error = OT_ERROR_NOT_CAPABLE;
break;
case kResponseNameExists: // Some name that ought not to exist, does exist.
case kResponseRecordExists: // Some RRset that ought not to exits, does exist.
error = OT_ERROR_DUPLICATED;
break;
case kResponseRefused: // Server refused to perform operation for policy or security reasons.
case kResponseNotAuth: // Service is not authoritative for zone.
error = OT_ERROR_SECURITY;
break;
default:
break;
}
return error;
}
otError Name::AppendLabel(const char *aLabel, Message &aMessage)
{
return AppendLabel(aLabel, static_cast<uint8_t>(StringLength(aLabel, kMaxLabelLength + 1)), aMessage);
@@ -316,20 +373,5 @@ exit:
return error;
}
void ResourceRecord::Init(uint16_t aType, uint16_t aClass, uint32_t aTtl)
{
SetType(aType);
SetClass(aClass);
SetTtl(aTtl);
SetLength(0);
}
void ResourceRecordAaaa::Init(void)
{
ResourceRecord::Init(kTypeAaaa);
SetLength(sizeof(mAddress));
mAddress.Clear();
}
} // namespace Dns
} // namespace ot
File diff suppressed because it is too large Load Diff