From 5d54dc2c5bda1998936a5d041f75ae3d7ced1216 Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Mon, 12 Jul 2021 12:45:56 -0700 Subject: [PATCH] [dns-client] use NAT64 prefix from network data (#6783) This commit updates `AddressResponse::GetNat64Prefix()` to search in Network Data to find NAT64 prefixes added by BRs. Prefixes with higher preference are selected first. --- src/core/net/dns_client.cpp | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/core/net/dns_client.cpp b/src/core/net/dns_client.cpp index bd4f18f27..c7d68808b 100644 --- a/src/core/net/dns_client.cpp +++ b/src/core/net/dns_client.cpp @@ -350,13 +350,29 @@ exit: Error Client::AddressResponse::GetNat64Prefix(Ip6::Prefix &aPrefix) const { - // Use well-known prefix "64:ff9b::/96" (temporary solution). - static const uint8_t kWellknownPrefix[] = {0x00, 0x64, 0xff, 0x9b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + Error error = kErrorNotFound; + NetworkData::Iterator iterator = NetworkData::kIteratorInit; + signed int preference = OT_ROUTE_PREFERENCE_LOW; + NetworkData::ExternalRouteConfig config; aPrefix.Clear(); - aPrefix.Set(kWellknownPrefix, 96); - return kErrorNone; + while (mInstance->Get().GetNextExternalRoute(iterator, config) == kErrorNone) + { + if (!config.mNat64 || !config.GetPrefix().IsValidNat64()) + { + continue; + } + + if ((aPrefix.GetLength() == 0) || (config.mPreference > preference)) + { + aPrefix = config.GetPrefix(); + preference = config.mPreference; + error = kErrorNone; + } + } + + return error; } #endif // OPENTHREAD_CONFIG_DNS_CLIENT_NAT64_ENABLE