[netdata] update Service::DnsSrpUnicast to include Origin (#7498)

This commit updates `NetworkData::Service::DnsSrpUnicast` to indicate
`Origin` of the entry, whether the server IPv6 address and port
number is included as part of service data or server data. This will
be used by clients to prefer entries with the info in service data
(which coveys the infra-structure provided (authoritative) server)
over the ones in server data (which are used by Thread BRs).

This commit also updates the unit test `test_network_data` to validate
the new behavior.
This commit is contained in:
Abtin Keshavarzian
2022-03-23 13:17:53 -07:00
committed by GitHub
parent a53893a334
commit 119df62cbd
3 changed files with 30 additions and 7 deletions
+3
View File
@@ -239,6 +239,7 @@ Error Manager::GetNextDnsSrpUnicastInfo(Iterator &aIterator, DnsSrpUnicast::Info
aInfo.mSockAddr.SetAddress(serverData->GetAddress());
aInfo.mSockAddr.SetPort(serverData->GetPort());
aInfo.mOrigin = DnsSrpUnicast::kFromServerData;
ExitNow();
}
@@ -250,6 +251,7 @@ Error Manager::GetNextDnsSrpUnicastInfo(Iterator &aIterator, DnsSrpUnicast::Info
aInfo.mSockAddr.GetAddress().SetToRoutingLocator(Get<Mle::Mle>().GetMeshLocalPrefix(),
aIterator.mServerSubTlv->GetServer16());
aInfo.mSockAddr.SetPort(Encoding::BigEndian::ReadUint16(data.GetBytes()));
aInfo.mOrigin = DnsSrpUnicast::kFromServerData;
ExitNow();
}
}
@@ -271,6 +273,7 @@ Error Manager::GetNextDnsSrpUnicastInfo(Iterator &aIterator, DnsSrpUnicast::Info
dnsServiceData = reinterpret_cast<const DnsSrpUnicast::ServiceData *>(serviceData.GetBytes());
aInfo.mSockAddr.SetAddress(dnsServiceData->GetAddress());
aInfo.mSockAddr.SetPort(dnsServiceData->GetPort());
aInfo.mOrigin = DnsSrpUnicast::kFromServiceData;
ExitNow();
}
+11
View File
@@ -259,6 +259,16 @@ public:
*/
static const uint8_t kServiceData = kServiceNumber;
/**
* This enumeration represents the origin a `DnsSrpUnicast` entry.
*
*/
enum Origin : uint8_t
{
kFromServiceData, ///< Socket address is from service data.
kFromServerData, ///< Socket address is from server data.
};
/**
* This structure represents information about an DNS/SRP server parsed from related Network Data service entries.
*
@@ -266,6 +276,7 @@ public:
struct Info
{
Ip6::SockAddr mSockAddr; ///< The socket address (IPv6 address and port) of the DNS/SRP server.
Origin mOrigin; ///< The origin of the socket address (whether from service or server data).
};
/**
+16 -7
View File
@@ -318,6 +318,11 @@ void TestNetworkDataFindNextService(void)
void TestNetworkDataDsnSrpServices(void)
{
static const char *kOriginStrings[] = {
"service-data", // (0) Service::DnsSrpUnicast::kFromServiceData
"server-data", // (1) Service::DnsSrpUnicast::kFromServerData
};
class TestLeader : public Leader
{
public:
@@ -353,8 +358,9 @@ void TestNetworkDataDsnSrpServices(void)
struct UnicastEntry
{
const char *mAddress;
uint16_t mPort;
const char * mAddress;
uint16_t mPort;
Service::DnsSrpUnicast::Origin mOrigin;
bool Matches(Service::DnsSrpUnicast::Info aInfo) const
{
@@ -363,7 +369,7 @@ void TestNetworkDataDsnSrpServices(void)
SuccessOrQuit(sockAddr.GetAddress().FromString(mAddress));
sockAddr.SetPort(mPort);
return (aInfo.mSockAddr == sockAddr);
return (aInfo.mSockAddr == sockAddr) && (aInfo.mOrigin == mOrigin);
}
};
@@ -384,9 +390,11 @@ void TestNetworkDataDsnSrpServices(void)
};
const UnicastEntry kUnicastEntries[] = {
{"fdde:ad00:beef:0:2d0e:c627:5556:18d9", 0x1234}, {"fd00:aabb:ccdd:eeff:11:2233:4455:6677", 0xabcd},
{"fdde:ad00:beef:0:0:ff:fe00:2800", 0x5678}, {"fd00:1234:5678:9abc:def0:123:4567:89ab", 0x0e},
{"fdde:ad00:beef:0:0:ff:fe00:6c00", 0xcd12},
{"fdde:ad00:beef:0:2d0e:c627:5556:18d9", 0x1234, Service::DnsSrpUnicast::kFromServiceData},
{"fd00:aabb:ccdd:eeff:11:2233:4455:6677", 0xabcd, Service::DnsSrpUnicast::kFromServerData},
{"fdde:ad00:beef:0:0:ff:fe00:2800", 0x5678, Service::DnsSrpUnicast::kFromServerData},
{"fd00:1234:5678:9abc:def0:123:4567:89ab", 0x0e, Service::DnsSrpUnicast::kFromServerData},
{"fdde:ad00:beef:0:0:ff:fe00:6c00", 0xcd12, Service::DnsSrpUnicast::kFromServerData},
};
const uint8_t kPreferredAnycastEntryIndex = 2;
@@ -436,7 +444,8 @@ void TestNetworkDataDsnSrpServices(void)
for (const UnicastEntry &entry : kUnicastEntries)
{
SuccessOrQuit(manager.GetNextDnsSrpUnicastInfo(iterator, unicastInfo));
printf("\nunicastInfo %s", unicastInfo.mSockAddr.ToString().AsCString());
printf("\nunicastInfo { %s, origin:%s }", unicastInfo.mSockAddr.ToString().AsCString(),
kOriginStrings[unicastInfo.mOrigin]);
VerifyOrQuit(entry.Matches(unicastInfo), "GetNextDnsSrpUnicastInfo() returned incorrect info");
}