[dns] allow partial read of TXT data and add config for max size in CLI (#8232)

This commit updates `Dns::Client` so that when reading service info
`otDnsServiceInfo` if the received TXT data does not fit in the given
buffer, it is read partially. A new field `mTxtDataTruncated` is added
in `otDnsServiceInfo` to indicate that TXT data was not fully read.

This commit also updates `dns` related commands in CLI so to output
the partially read TXT data and add a new config specifying the max
TXT data size used by CLI.
This commit is contained in:
Abtin Keshavarzian
2022-10-05 15:10:28 -07:00
committed by GitHub
parent c5b4cd7bbc
commit d3e00fbd28
9 changed files with 72 additions and 18 deletions
+12 -1
View File
@@ -1021,6 +1021,8 @@ void TestHeaderAndResourceRecords(void)
for (const char *instanceName : kInstanceNames)
{
uint16_t savedOffset;
// SRV record
SuccessOrQuit(Dns::Name::CompareName(*message, offset, instanceName));
SuccessOrQuit(Dns::ResourceRecord::ReadRecord(*message, offset, srvRecord));
@@ -1037,12 +1039,21 @@ void TestHeaderAndResourceRecords(void)
SuccessOrQuit(Dns::Name::CompareName(*message, offset, instanceName));
SuccessOrQuit(Dns::ResourceRecord::ReadRecord(*message, offset, txtRecord));
VerifyOrQuit(txtRecord.GetTtl() == kTxtTtl);
len = sizeof(buffer);
savedOffset = offset;
len = sizeof(buffer);
SuccessOrQuit(txtRecord.ReadTxtData(*message, offset, buffer, len));
VerifyOrQuit(len == sizeof(kTxtData));
VerifyOrQuit(memcmp(buffer, kTxtData, len) == 0);
printf(" \"%s\" TXT %u %d \"%s\"\n", instanceName, txtRecord.GetTtl(), txtRecord.GetLength(),
reinterpret_cast<const char *>(buffer));
// Partial read of TXT data
len = sizeof(kTxtData) - 1;
memset(buffer, 0, sizeof(buffer));
VerifyOrQuit(txtRecord.ReadTxtData(*message, savedOffset, buffer, len) == kErrorNoBufs);
VerifyOrQuit(len == sizeof(kTxtData) - 1);
VerifyOrQuit(memcmp(buffer, kTxtData, len) == 0);
VerifyOrQuit(savedOffset == offset);
}
SuccessOrQuit(Dns::Name::CompareName(*message, offset, kHostName));