diff --git a/src/core/thread/network_data_service.cpp b/src/core/thread/network_data_service.cpp index 878c027c2..f4d7f5813 100644 --- a/src/core/thread/network_data_service.cpp +++ b/src/core/thread/network_data_service.cpp @@ -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().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(serviceData.GetBytes()); aInfo.mSockAddr.SetAddress(dnsServiceData->GetAddress()); aInfo.mSockAddr.SetPort(dnsServiceData->GetPort()); + aInfo.mOrigin = DnsSrpUnicast::kFromServiceData; ExitNow(); } diff --git a/src/core/thread/network_data_service.hpp b/src/core/thread/network_data_service.hpp index b7f16f97c..25cf77094 100644 --- a/src/core/thread/network_data_service.hpp +++ b/src/core/thread/network_data_service.hpp @@ -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). }; /** diff --git a/tests/unit/test_network_data.cpp b/tests/unit/test_network_data.cpp index 31438a1d1..93d607e8a 100644 --- a/tests/unit/test_network_data.cpp +++ b/tests/unit/test_network_data.cpp @@ -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"); }