From 37f9d171c086429adee54951709b10c8d18372f3 Mon Sep 17 00:00:00 2001 From: Yi Date: Wed, 19 Jan 2022 16:35:10 +0800 Subject: [PATCH] [routing-manager] generate random nat64 prefix and add it to netdata (#7232) This commit generates a random NAT64 prefix and adds the prefix to NetworkData if none exits. The prefix will be saved in Settings for recovery. It also adds a new CLI command `br nat64prefix` to show the local nat64 prefix. A new config OPENTHREAD_CONFIG_BORDER_ROUTING_NAT64_ENABLE is defined and used to guard the change. This initial implementation only supports a single BR. --- etc/cmake/options.cmake | 5 + examples/README.md | 2 + examples/common-switches.mk | 5 + include/openthread/border_router.h | 17 ++++ include/openthread/instance.h | 2 +- include/openthread/platform/settings.h | 3 +- script/check-scan-build | 1 + script/make-pretty | 1 + src/cli/README.md | 12 +++ src/cli/cli.cpp | 9 ++ src/core/api/border_router_api.cpp | 8 +- src/core/border_router/routing_manager.cpp | 104 ++++++++++++++++++++- src/core/border_router/routing_manager.hpp | 30 +++++- src/core/common/settings.cpp | 5 +- src/core/common/settings.hpp | 24 ++++- src/core/config/border_router.h | 10 ++ 16 files changed, 225 insertions(+), 13 deletions(-) diff --git a/etc/cmake/options.cmake b/etc/cmake/options.cmake index 117dded48..e8c921262 100644 --- a/etc/cmake/options.cmake +++ b/etc/cmake/options.cmake @@ -82,6 +82,11 @@ if(OT_BORDER_ROUTING) target_compile_definitions(ot-config INTERFACE "OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE=1") endif() +option(OT_BORDER_ROUTING_NAT64 "enable border routing NAT64 support") +if(OT_BORDER_ROUTING_NAT64) + target_compile_definitions(ot-config INTERFACE "OPENTHREAD_CONFIG_BORDER_ROUTING_NAT64_ENABLE=1") +endif() + if(NOT OT_EXTERNAL_MBEDTLS) set(OT_MBEDTLS mbedtls) target_compile_definitions(ot-config INTERFACE "OPENTHREAD_CONFIG_ENABLE_BUILTIN_MBEDTLS=1") diff --git a/examples/README.md b/examples/README.md index bfd730482..2d0f5d5ef 100644 --- a/examples/README.md +++ b/examples/README.md @@ -11,6 +11,8 @@ This page lists the available common switches with description. Unless stated ot | BIG_ENDIAN | OT_BIG_ENDIAN | Allows the host platform to use big-endian byte order. | | BORDER_AGENT | OT_BORDER_AGENT | Enables support for border agent. In most cases, enable this switch if you are building On-mesh Commissioner or Border Router with External Commissioning support. | | BORDER_ROUTER | OT_BORDER_ROUTER | Enables support for Border Router. This switch is usually combined with the BORDER_AGENT and UDP_FORWARD (or PLATFORM_UDP in case of RCP design) switches to build Border Router device. | +| BORDER_ROUTING | OT_BORDER_ROUTING | Enables bi-directional border routing between Thread and Infrastructure networks for Border Router. | +| BORDER_ROUTING_NAT64 | OT_BORDER_ROUTING_NAT64 | Enables NAT64 border routing support for Border Router. | | BUILTIN_MBEDTLS_MANAGEMENT | OT_BUILTIN_MBEDTLS_MANAGEMENT | Enables the built-in mbedTLS management. Enable this switch if the external mbedTLS is used, but mbedTLS memory allocation and debug config should be managed internally by OpenThread. | | CHANNEL_MANAGER | OT_CHANNEL_MANAGER | Enables support for channel manager. Enable this switch on devices that are supposed to request a Thread network channel change. This switch should be used only with an FTD build. | | CHANNEL_MONITOR | OT_CHANNEL_MONITOR | Enables support for channel monitor. Enable this switch on devices that are supposed to determine the cleaner channels. | diff --git a/examples/common-switches.mk b/examples/common-switches.mk index f63fcbc7c..1795f88db 100644 --- a/examples/common-switches.mk +++ b/examples/common-switches.mk @@ -34,6 +34,7 @@ BIG_ENDIAN ?= 0 BORDER_AGENT ?= 0 BORDER_ROUTER ?= 0 BORDER_ROUTING ?= 0 +BORDER_ROUTING_NAT64 ?= 0 COAP ?= 0 COAP_BLOCK ?= 0 COAP_OBSERVE ?= 0 @@ -116,6 +117,10 @@ ifeq ($(BORDER_ROUTING),1) COMMONCFLAGS += -DOPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE=1 endif +ifeq ($(BORDER_ROUTING_NAT64),1) +COMMONCFLAGS += -DOPENTHREAD_CONFIG_BORDER_ROUTING_NAT64_ENABLE=1 +endif + ifeq ($(COAP),1) COMMONCFLAGS += -DOPENTHREAD_CONFIG_COAP_API_ENABLE=1 endif diff --git a/include/openthread/border_router.h b/include/openthread/border_router.h index 7774727b4..4161e1925 100644 --- a/include/openthread/border_router.h +++ b/include/openthread/border_router.h @@ -117,6 +117,23 @@ otError otBorderRoutingGetOmrPrefix(otInstance *aInstance, otIp6Prefix *aPrefix) */ otError otBorderRoutingGetOnLinkPrefix(otInstance *aInstance, otIp6Prefix *aPrefix); +/** + * This function returns the local NAT64 prefix. + * + * This prefix might not be advertised in the Thread network. + * + * This function is only available when `OPENTHREAD_CONFIG_BORDER_ROUTING_NAT64_ENABLE` + * is enabled. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * @param[out] aPrefix A pointer to where the prefix will be output to. + * + * @retval OT_ERROR_INVALID_STATE The Border Routing Manager is not initialized yet. + * @retval OT_ERROR_NONE Successfully retrieved the NAT64 prefix. + * + */ +otError otBorderRoutingGetNat64Prefix(otInstance *aInstance, otIp6Prefix *aPrefix); + /** * This method provides a full or stable copy of the local Thread Network Data. * diff --git a/include/openthread/instance.h b/include/openthread/instance.h index c908508b1..7739ff7db 100644 --- a/include/openthread/instance.h +++ b/include/openthread/instance.h @@ -53,7 +53,7 @@ extern "C" { * @note This number versions both OpenThread platform and user APIs. * */ -#define OPENTHREAD_API_VERSION (184) +#define OPENTHREAD_API_VERSION (185) /** * @addtogroup api-instance diff --git a/include/openthread/platform/settings.h b/include/openthread/platform/settings.h index 17a68a022..39e0613bb 100644 --- a/include/openthread/platform/settings.h +++ b/include/openthread/platform/settings.h @@ -54,7 +54,7 @@ extern "C" { /** * This enumeration defines the keys of settings. * - * Note: When adding a new setings key, if the settings corresponding to the key contains security sensitive + * Note: When adding a new settings key, if the settings corresponding to the key contains security sensitive * information, the developer MUST add the key to the array `kCriticalKeys`. * */ @@ -73,6 +73,7 @@ enum OT_SETTINGS_KEY_SRP_ECDSA_KEY = 0x000b, ///< SRP client ECDSA public/private key pair. OT_SETTINGS_KEY_SRP_CLIENT_INFO = 0x000c, ///< The SRP client info (selected SRP server address). OT_SETTINGS_KEY_SRP_SERVER_INFO = 0x000d, ///< The SRP server info (UDP port). + OT_SETTINGS_KEY_NAT64_PREFIX = 0x000e, ///< NAT64 prefix. }; /** diff --git a/script/check-scan-build b/script/check-scan-build index de68aeefc..06329d9ca 100755 --- a/script/check-scan-build +++ b/script/check-scan-build @@ -37,6 +37,7 @@ readonly OT_BUILD_OPTIONS=( "-DOT_BORDER_AGENT=ON" "-DOT_BORDER_ROUTER=ON" "-DOT_BORDER_ROUTING=ON" + "-DOT_BORDER_ROUTING_NAT64=ON" "-DOT_COAP=ON" "-DOT_COAP_BLOCK=ON" "-DOT_COAP_OBSERVE=ON" diff --git a/script/make-pretty b/script/make-pretty index da10a2420..70984de7c 100755 --- a/script/make-pretty +++ b/script/make-pretty @@ -83,6 +83,7 @@ readonly OT_CLANG_TIDY_BUILD_OPTS=( '-DOT_BORDER_AGENT=ON' '-DOT_BORDER_ROUTER=ON' '-DOT_BORDER_ROUTING=ON' + '-DOT_BORDER_ROUTING_NAT64=ON' '-DOT_CHANNEL_MANAGER=ON' '-DOT_CHANNEL_MONITOR=ON' '-DOT_CHILD_SUPERVISION=ON' diff --git a/src/cli/README.md b/src/cli/README.md index d86506f8c..e7b3e7566 100644 --- a/src/cli/README.md +++ b/src/cli/README.md @@ -393,6 +393,18 @@ fd41:2650:a6f5:0::/64 Done ``` +### br nat64prefix + +Get the local NAT64 prefix of the Border Router. + +`OPENTHREAD_CONFIG_BORDER_ROUTING_NAT64_ENABLE` is required. + +```bash +> br nat64prefix +fd14:1078:b3d5:b0b0:0:0::/96 +Done +``` + ### bufferinfo Show the current message buffer information. diff --git a/src/cli/cli.cpp b/src/cli/cli.cpp index f0934919c..4825fca92 100644 --- a/src/cli/cli.cpp +++ b/src/cli/cli.cpp @@ -494,6 +494,15 @@ otError Interpreter::ProcessBorderRouting(Arg aArgs[]) SuccessOrExit(error = otBorderRoutingGetOnLinkPrefix(GetInstancePtr(), &onLinkPrefix)); OutputIp6PrefixLine(onLinkPrefix); } +#if OPENTHREAD_CONFIG_BORDER_ROUTING_NAT64_ENABLE + else if (aArgs[0] == "nat64prefix") + { + otIp6Prefix nat64Prefix; + + SuccessOrExit(error = otBorderRoutingGetNat64Prefix(GetInstancePtr(), &nat64Prefix)); + OutputIp6PrefixLine(nat64Prefix); + } +#endif // OPENTHREAD_CONFIG_BORDER_ROUTING_NAT64_ENABLE else { error = OT_ERROR_INVALID_COMMAND; diff --git a/src/core/api/border_router_api.cpp b/src/core/api/border_router_api.cpp index 7900dadde..12d463116 100644 --- a/src/core/api/border_router_api.cpp +++ b/src/core/api/border_router_api.cpp @@ -64,7 +64,13 @@ otError otBorderRoutingGetOnLinkPrefix(otInstance *aInstance, otIp6Prefix *aPref return AsCoreType(aInstance).Get().GetOnLinkPrefix(AsCoreType(aPrefix)); } -#endif +#if OPENTHREAD_CONFIG_BORDER_ROUTING_NAT64_ENABLE +otError otBorderRoutingGetNat64Prefix(otInstance *aInstance, otIp6Prefix *aPrefix) +{ + return AsCoreType(aInstance).Get().GetNat64Prefix(AsCoreType(aPrefix)); +} +#endif // OPENTHREAD_CONFIG_BORDER_ROUTING_NAT64_ENABLE +#endif // OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE otError otBorderRouterGetNetData(otInstance *aInstance, bool aStable, uint8_t *aData, uint8_t *aDataLength) { diff --git a/src/core/border_router/routing_manager.cpp b/src/core/border_router/routing_manager.cpp index 3f625eb9b..0ea712cca 100644 --- a/src/core/border_router/routing_manager.cpp +++ b/src/core/border_router/routing_manager.cpp @@ -64,6 +64,7 @@ RoutingManager::RoutingManager(Instance &aInstance) , mInfraIfIndex(0) , mIsAdvertisingLocalOnLinkPrefix(false) , mOnLinkPrefixDeprecateTimer(aInstance, HandleOnLinkPrefixDeprecateTimer) + , mIsAdvertisingLocalNat64Prefix(false) , mTimeRouterAdvMessageLastUpdate(TimerMilli::GetNow()) , mLearntRouterAdvMessageFromHost(false) , mDiscoveredPrefixInvalidTimer(aInstance, HandleDiscoveredPrefixInvalidTimer) @@ -79,6 +80,8 @@ RoutingManager::RoutingManager(Instance &aInstance) mLocalOmrPrefix.Clear(); mLocalOnLinkPrefix.Clear(); + + mLocalNat64Prefix.Clear(); } Error RoutingManager::Init(uint32_t aInfraIfIndex, bool aInfraIfIsRunning) @@ -90,6 +93,9 @@ Error RoutingManager::Init(uint32_t aInfraIfIndex, bool aInfraIfIsRunning) SuccessOrExit(error = LoadOrGenerateRandomOmrPrefix()); SuccessOrExit(error = LoadOrGenerateRandomOnLinkPrefix()); +#if OPENTHREAD_CONFIG_BORDER_ROUTING_NAT64_ENABLE + SuccessOrExit(error = LoadOrGenerateRandomNat64Prefix()); +#endif mInfraIfIndex = aInfraIfIndex; @@ -141,6 +147,19 @@ exit: return error; } +#if OPENTHREAD_CONFIG_BORDER_ROUTING_NAT64_ENABLE +Error RoutingManager::GetNat64Prefix(Ip6::Prefix &aPrefix) +{ + Error error = kErrorNone; + + VerifyOrExit(IsInitialized(), error = kErrorInvalidState); + aPrefix = mLocalNat64Prefix; + +exit: + return error; +} +#endif + Error RoutingManager::LoadOrGenerateRandomOmrPrefix(void) { Error error = kErrorNone; @@ -151,6 +170,7 @@ Error RoutingManager::LoadOrGenerateRandomOmrPrefix(void) otLogNoteBr("No valid OMR prefix found in settings, generating new one"); + // TODO: generate OMR prefix from the /48 BR ULA prefix error = randomOmrPrefix.GenerateRandomUla(); if (error != kErrorNone) { @@ -195,6 +215,39 @@ exit: return error; } +#if OPENTHREAD_CONFIG_BORDER_ROUTING_NAT64_ENABLE +Error RoutingManager::LoadOrGenerateRandomNat64Prefix(void) +{ + Error error = kErrorNone; + + if (Get().Read(mLocalNat64Prefix) != kErrorNone || + !mLocalNat64Prefix.IsValidNat64()) + { + Ip6::NetworkPrefix randomNat64Prefix; + constexpr uint8_t nat64PrefixLength = 96; + + otLogNoteBr("No valid NAT64 prefix found in settings, generating new one"); + + // TODO: generate NAT64 prefix from the /48 BR ULA prefix + error = randomNat64Prefix.GenerateRandomUla(); + if (error != kErrorNone) + { + otLogCritBr("Failed to generate random NAT64 prefix"); + ExitNow(); + } + + mLocalNat64Prefix.Clear(); + mLocalNat64Prefix.Set(randomNat64Prefix); + mLocalNat64Prefix.SetLength(nat64PrefixLength); + + IgnoreError(Get().Save(mLocalNat64Prefix)); + } + +exit: + return error; +} +#endif + void RoutingManager::EvaluateState(void) { if (mIsEnabled && Get().IsAttached() && mInfraIfIsRunning) @@ -233,6 +286,13 @@ void RoutingManager::Stop(void) DeprecateOnLinkPrefix(); } +#if OPENTHREAD_CONFIG_BORDER_ROUTING_NAT64_ENABLE + if (mIsAdvertisingLocalNat64Prefix) + { + RemoveExternalRoute(mLocalNat64Prefix); + mIsAdvertisingLocalNat64Prefix = false; + } +#endif // Use empty OMR & on-link prefixes to invalidate possible advertised prefixes. SendRouterAdvertisement(OmrPrefixArray(), nullptr); @@ -429,7 +489,7 @@ Error RoutingManager::PublishLocalOmrPrefix(void) else { Get().HandleServerDataUpdated(); - otLogInfoBr("Published local OMR prefix %s in Thread network", mLocalOmrPrefix.ToString().AsCString()); + otLogInfoBr("Publishing local OMR prefix %s in Thread network", mLocalOmrPrefix.ToString().AsCString()); } return error; @@ -444,7 +504,7 @@ void RoutingManager::UnpublishLocalOmrPrefix(void) SuccessOrExit(error = Get().RemoveOnMeshPrefix(mLocalOmrPrefix)); Get().HandleServerDataUpdated(); - otLogInfoBr("Unpublished local OMR prefix %s from Thread network", mLocalOmrPrefix.ToString().AsCString()); + otLogInfoBr("Unpublishing local OMR prefix %s from Thread network", mLocalOmrPrefix.ToString().AsCString()); exit: if (error != kErrorNone) @@ -454,7 +514,7 @@ exit: } } -Error RoutingManager::AddExternalRoute(const Ip6::Prefix &aPrefix, RoutePreference aRoutePreference) +Error RoutingManager::AddExternalRoute(const Ip6::Prefix &aPrefix, RoutePreference aRoutePreference, bool aNat64) { Error error; NetworkData::ExternalRouteConfig routeConfig; @@ -464,6 +524,7 @@ Error RoutingManager::AddExternalRoute(const Ip6::Prefix &aPrefix, RoutePreferen routeConfig.Clear(); routeConfig.SetPrefix(aPrefix); routeConfig.mStable = true; + routeConfig.mNat64 = aNat64; routeConfig.mPreference = aRoutePreference; error = Get().AddHasRoutePrefix(routeConfig); @@ -474,7 +535,7 @@ Error RoutingManager::AddExternalRoute(const Ip6::Prefix &aPrefix, RoutePreferen else { Get().HandleServerDataUpdated(); - otLogInfoBr("Added external route %s", aPrefix.ToString().AsCString()); + otLogInfoBr("Adding external route %s", aPrefix.ToString().AsCString()); } return error; @@ -489,7 +550,7 @@ void RoutingManager::RemoveExternalRoute(const Ip6::Prefix &aPrefix) SuccessOrExit(error = Get().RemoveHasRoutePrefix(aPrefix)); Get().HandleServerDataUpdated(); - otLogInfoBr("Removed external route %s", aPrefix.ToString().AsCString()); + otLogInfoBr("Removing external route %s", aPrefix.ToString().AsCString()); exit: if (error != kErrorNone) @@ -573,6 +634,36 @@ void RoutingManager::DeprecateOnLinkPrefix(void) TimeMilli::SecToMsec(kDefaultOnLinkPrefixLifetime)); } +#if OPENTHREAD_CONFIG_BORDER_ROUTING_NAT64_ENABLE +void RoutingManager::EvaluateNat64Prefix(void) +{ + OT_ASSERT(mIsRunning); + + NetworkData::Iterator iterator = NetworkData::kIteratorInit; + NetworkData::ExternalRouteConfig config; + bool hasAdvertisedNat64Prefix = false; + + otLogInfoBr("Evaluating NAT64 prefix"); + + while (Get().GetNextExternalRoute(iterator, config) == kErrorNone) + { + if (config.mNat64 && config.GetPrefix().IsValidNat64()) + { + hasAdvertisedNat64Prefix = true; + } + } + + if (!hasAdvertisedNat64Prefix && !mIsAdvertisingLocalNat64Prefix) + { + // TODO: when multiple prefixes exits, remove the ones with lower preference or numerically larger. + if (AddExternalRoute(mLocalNat64Prefix, NetworkData::kRoutePreferenceLow, /* aNat64= */ true) == kErrorNone) + { + mIsAdvertisingLocalNat64Prefix = true; + } + } +} +#endif + // This method evaluate the routing policy depends on prefix and route // information on Thread Network and infra link. As a result, this // method May send RA messages on infra link and publish/unpublish @@ -589,6 +680,9 @@ void RoutingManager::EvaluateRoutingPolicy(void) // 0. Evaluate on-link & OMR prefixes. newOnLinkPrefix = EvaluateOnLinkPrefix(); EvaluateOmrPrefix(newOmrPrefixes); +#if OPENTHREAD_CONFIG_BORDER_ROUTING_NAT64_ENABLE + EvaluateNat64Prefix(); +#endif // 1. Send Router Advertisement message if necessary. SendRouterAdvertisement(newOmrPrefixes, newOnLinkPrefix); diff --git a/src/core/border_router/routing_manager.hpp b/src/core/border_router/routing_manager.hpp index 01e011c2c..01325f8f8 100644 --- a/src/core/border_router/routing_manager.hpp +++ b/src/core/border_router/routing_manager.hpp @@ -138,6 +138,22 @@ public: */ Error GetOnLinkPrefix(Ip6::Prefix &aPrefix); +#if OPENTHREAD_CONFIG_BORDER_ROUTING_NAT64_ENABLE + /** + * This method returns the local NAT64 prefix. + * + * The local NAT64 prefix will be published in the Thread network + * if none exists. + * + * @param[out] aPrefix A reference to where the prefix will be output to. + * + * @retval kErrorInvalidState The Border Routing Manager is not initialized yet. + * @retval kErrorNone Successfully retrieved the NAT64 prefix. + * + */ + Error GetNat64Prefix(Ip6::Prefix &aPrefix); +#endif // OPENTHREAD_CONFIG_BORDER_ROUTING_NAT64_ENABLE + /** * This method receives an ICMPv6 message on the infrastructure interface. * @@ -278,13 +294,18 @@ private: const Ip6::Prefix *EvaluateOnLinkPrefix(void); +#if OPENTHREAD_CONFIG_BORDER_ROUTING_NAT64_ENABLE + Error LoadOrGenerateRandomNat64Prefix(void); + void EvaluateNat64Prefix(void); +#endif + void EvaluateRoutingPolicy(void); void StartRoutingPolicyEvaluationJitter(uint32_t aJitterMilli); void StartRoutingPolicyEvaluationDelay(uint32_t aDelayMilli); void EvaluateOmrPrefix(OmrPrefixArray &aNewOmrPrefixes); Error PublishLocalOmrPrefix(void); void UnpublishLocalOmrPrefix(void); - Error AddExternalRoute(const Ip6::Prefix &aPrefix, RoutePreference aRoutePreference); + Error AddExternalRoute(const Ip6::Prefix &aPrefix, RoutePreference aRoutePreference, bool aNat64 = false); void RemoveExternalRoute(const Ip6::Prefix &aPrefix); void StartRouterSolicitationDelay(void); Error SendRouterSolicitation(void); @@ -359,6 +380,13 @@ private: TimeMilli mTimeAdvertisedOnLinkPrefix; TimerMilli mOnLinkPrefixDeprecateTimer; + // The NAT64 prefix loaded from local persistent storage or + // randomly generated if none is found in persistent storage. + Ip6::Prefix mLocalNat64Prefix; + + // True if the local NAT64 prefix is advertised in Thread network. + bool mIsAdvertisingLocalNat64Prefix; + // The array of prefixes discovered on the infra link. Those // prefixes consist of on-link prefix(es) and OMR prefixes // advertised by BRs in another Thread Network which is connected to diff --git a/src/core/common/settings.cpp b/src/core/common/settings.cpp index d120f3740..424db0f15 100644 --- a/src/core/common/settings.cpp +++ b/src/core/common/settings.cpp @@ -154,6 +154,7 @@ const char *SettingsBase::KeyToString(Key aKey) "SrpEcdsaKey", // (11) kKeySrpEcdsaKey "SrpClientInfo", // (12) kKeySrpClientInfo "SrpServerInfo", // (13) kKeySrpServerInfo + "Nat64Prefix", // (14) kKeyNat64Prefix }; static_assert(1 == kKeyActiveDataset, "kKeyActiveDataset value is incorrect"); @@ -169,8 +170,9 @@ const char *SettingsBase::KeyToString(Key aKey) static_assert(11 == kKeySrpEcdsaKey, "kKeySrpEcdsaKey value is incorrect"); static_assert(12 == kKeySrpClientInfo, "kKeySrpClientInfo value is incorrect"); static_assert(13 == kKeySrpServerInfo, "kKeySrpServerInfo value is incorrect"); + static_assert(14 == kKeyNat64Prefix, "kKeyNat64Prefix value is incorrect"); - static_assert(kLastKey == kKeySrpServerInfo, "kLastKey is not valid"); + static_assert(kLastKey == kKeyNat64Prefix, "kLastKey is not valid"); OT_ASSERT(aKey <= kLastKey); @@ -431,6 +433,7 @@ void Settings::Log(Action aAction, Error aError, Key aKey, const void *aValue) #if OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE case kKeyOmrPrefix: case kKeyOnLinkPrefix: + case kKeyNat64Prefix: LogPrefix(aAction, aKey, *reinterpret_cast(aValue)); break; #endif diff --git a/src/core/common/settings.hpp b/src/core/common/settings.hpp index 70bee9041..c394bb02b 100644 --- a/src/core/common/settings.hpp +++ b/src/core/common/settings.hpp @@ -122,9 +122,10 @@ public: kKeySrpEcdsaKey = OT_SETTINGS_KEY_SRP_ECDSA_KEY, kKeySrpClientInfo = OT_SETTINGS_KEY_SRP_CLIENT_INFO, kKeySrpServerInfo = OT_SETTINGS_KEY_SRP_SERVER_INFO, + kKeyNat64Prefix = OT_SETTINGS_KEY_NAT64_PREFIX, }; - static constexpr Key kLastKey = kKeySrpServerInfo; ///< The last (numerically) enumerator value in `Key`. + static constexpr Key kLastKey = kKeyNat64Prefix; ///< The last (numerically) enumerator value in `Key`. /** * This structure represents the device's own network information for settings storage. @@ -596,6 +597,23 @@ public: private: OnLinkPrefix(void) = default; }; + +#if OPENTHREAD_CONFIG_BORDER_ROUTING_NAT64_ENABLE + /** + * This class defines constants and types for NAT64 prefix settings. + * + */ + class Nat64Prefix + { + public: + static constexpr Key kKey = kKeyNat64Prefix; ///< The associated key. + + typedef Ip6::Prefix ValueType; ///< The associated value type. + + private: + Nat64Prefix(void) = default; + }; +#endif // OPENTHREAD_CONFIG_BORDER_ROUTING_NAT64_ENABLE #endif // OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE #if OPENTHREAD_CONFIG_SRP_CLIENT_ENABLE @@ -848,7 +866,7 @@ public: * - It must provide a nested type `EntryType::ValueType` to specify the associated entry value type. * * This version of `Read` is intended for use with entries that have a simple entry value type (which can - * be represented by an existing type), e.g., `OmrPrefx` (using `Ip6::Prefix` as the value type). + * be represented by an existing type), e.g., `OmrPrefix` (using `Ip6::Prefix` as the value type). * * @tparam EntryType The settings entry type. * @@ -898,7 +916,7 @@ public: * - It must provide a nested type `EntryType::ValueType` to specify the associated entry value type. * * This version of `Save` is intended for use with entries that have a simple entry value type (which can - * be represented by an existing type), e.g., `OmrPrefx` (using `Ip6::Prefix` as the value type). + * be represented by an existing type), e.g., `OmrPrefix` (using `Ip6::Prefix` as the value type). * * @tparam EntryType The settings entry type. * diff --git a/src/core/config/border_router.h b/src/core/config/border_router.h index 9e01b0425..18b4d3336 100644 --- a/src/core/config/border_router.h +++ b/src/core/config/border_router.h @@ -75,6 +75,16 @@ #define OPENTHREAD_CONFIG_BORDER_ROUTING_VICARIOUS_RS_ENABLE 1 #endif +/** + * @def OPENTHREAD_CONFIG_BORDER_ROUTING_NAT64_ENABLE + * + * Define to 1 to enable Border Routing NAT64 support. + * + */ +#ifndef OPENTHREAD_CONFIG_BORDER_ROUTING_NAT64_ENABLE +#define OPENTHREAD_CONFIG_BORDER_ROUTING_NAT64_ENABLE 0 +#endif + /** * @def OPENTHREAD_CONFIG_BORDER_AGENT_UDP_PORT *