diff --git a/include/openthread/border_routing.h b/include/openthread/border_routing.h index be56351d3..4b957f5cd 100644 --- a/include/openthread/border_routing.h +++ b/include/openthread/border_routing.h @@ -663,6 +663,24 @@ otError otBorderRoutingGetNextRdnssAddrEntry(otInstance otBorderRoutingPrefixTableIterator *aIterator, otBorderRoutingRdnssAddrEntry *aEntry); +/** + * Iterates through the RA-discovered NAT64 prefix table. + * + * Requires `OPENTHREAD_CONFIG_NAT64_BORDER_ROUTING_ENABLE`. + * + * @param[in] aInstance The OpenThread instance. + * @param[in,out] aIterator A pointer to the iterator. + * @param[out] aEntry A pointer to the entry to populate. + * + * @retval OT_ERROR_NONE Iterated to the next NAT64 prefix entry, @p aEntry and @p aIterator are updated. + * @retval OT_ERROR_NOT_FOUND No more entries in the table. + * @retval OT_ERROR_INVALID_ARGS The iterator is invalid (used to iterate over other entry types). + * + */ +otError otBorderRoutingGetNextNat64PrefixEntry(otInstance *aInstance, + otBorderRoutingPrefixTableIterator *aIterator, + otBorderRoutingNat64PrefixEntry *aEntry); + /** * Callback function pointer to notify of changes to discovered Recursive DNS Server (RDNSS) address entries. * diff --git a/include/openthread/instance.h b/include/openthread/instance.h index 3df8a9c71..7780e21c1 100644 --- a/include/openthread/instance.h +++ b/include/openthread/instance.h @@ -52,7 +52,7 @@ extern "C" { * * @note This number versions both OpenThread platform and user APIs. */ -#define OPENTHREAD_API_VERSION (550) +#define OPENTHREAD_API_VERSION (551) /** * @addtogroup api-instance diff --git a/src/cli/README_BR.md b/src/cli/README_BR.md index b3214a5d1..752d24513 100644 --- a/src/cli/README_BR.md +++ b/src/cli/README_BR.md @@ -13,6 +13,7 @@ Usage : `br [command] ...` - [init](#init) - [multiail](#multiail) - [nat64prefix](#nat64prefix) +- [nat64prefixtable](#nat64prefixtable) - [omrconfig](#omrconfig) - [omrprefix](#omrprefix) - [onlinkprefix](#onlinkprefix) @@ -44,6 +45,7 @@ infraif init multiail nat64prefix +nat64prefixtable omrconfig omrprefix onlinkprefix @@ -348,6 +350,32 @@ fd14:1078:b3d5:b0b0:0:0::/96 Done ``` +### nat64prefixtable + +Usage: `br nat64prefixtable` + +Get the discovered NAT64 prefixes by Border Routing Manager on the infrastructure link. + +`OPENTHREAD_CONFIG_NAT64_BORDER_ROUTING_ENABLE` is required. + +Info per prefix entry: + +- The prefix +- Milliseconds since last received Router Advertisement containing this prefix +- Prefix lifetime in seconds +- The router IPv6 address which advertises this prefix +- Flags in received Router Advertisement header: + - M: Managed Address Config flag + - O: Other Config flag + - S: SNAC Router flag + +```bash +> br nat64prefixtable +prefix:fd00:1234:5678:0:0:0::/96, ms-since-rx:29526, lifetime:1800, router:fe80:0:0:0:0:0:0:1 (M:0 O:0 S:1) +prefix:fd11:2233:4455:0:0:0::/96, ms-since-rx:29527, lifetime:1800, router:fe80:0:0:0:0:0:0:1 (M:0 O:0 S:1) +Done +``` + ### pd Usage: `br pd [enable|disable]` @@ -446,7 +474,7 @@ Info per prefix entry: - Prefix lifetime in seconds - Preferred lifetime in seconds only if prefix is on-link - Route preference (low, med, high) only if prefix is route (not on-link) -- The router IPv6 address which advertising this prefix +- The router IPv6 address which advertises this prefix - Flags in received Router Advertisement header: - M: Managed Address Config flag - O: Other Config flag diff --git a/src/cli/cli_br.cpp b/src/cli/cli_br.cpp index e20982085..61332387c 100644 --- a/src/cli/cli_br.cpp +++ b/src/cli/cli_br.cpp @@ -602,6 +602,50 @@ exit: return error; } +/** + * @cli br nat64prefixtable + * @code + * br nat64prefixtable + * prefix:fd00:1234:5678:0:0:0::/96, ms-since-rx:29526, lifetime:1800, router:fe80:0:0:0:0:0:0:1 (M:0 O:0 S:1) + * prefix:fd11:2233:4455:0:0:0::/96, ms-since-rx:29527, lifetime:1800, router:fe80:0:0:0:0:0:0:1 (M:0 O:0 S:1) + * Done + * @endcode + * @par + * Get the RA-discovered NAT64 prefixes by Border Routing Manager on the infrastructure link. + * Info per prefix entry: + * - The prefix + * - Milliseconds since last received Router Advertisement containing this prefix + * - Prefix lifetime in seconds + * - The router IPv6 address which advertises this prefix + * - Flags in received Router Advertisement header: + * - M: Managed Address Config flag + * - O: Other Config flag + * - S: SNAC Router flag + * @sa otBorderRoutingGetNextNat64PrefixEntry + */ +template <> otError Br::Process(Arg aArgs[]) +{ + otError error = OT_ERROR_NONE; + otBorderRoutingPrefixTableIterator iterator; + otBorderRoutingNat64PrefixEntry entry; + + VerifyOrExit(aArgs[0].IsEmpty(), error = OT_ERROR_INVALID_ARGS); + + otBorderRoutingPrefixTableInitIterator(GetInstancePtr(), &iterator); + + while (otBorderRoutingGetNextNat64PrefixEntry(GetInstancePtr(), &iterator, &entry) == OT_ERROR_NONE) + { + char string[OT_IP6_PREFIX_STRING_SIZE]; + + otIp6PrefixToString(&entry.mPrefix, string, sizeof(string)); + OutputFormat("prefix:%s, ms-since-rx:%lu, lifetime:%lu, router:", string, ToUlong(entry.mMsecSinceLastUpdate), + ToUlong(entry.mLifetime)); + OutputRouterInfo(entry.mRouter, kShortVersion); + } + +exit: + return error; +} #endif // OPENTHREAD_CONFIG_NAT64_BORDER_ROUTING_ENABLE #if OPENTHREAD_CONFIG_BORDER_ROUTING_TRACK_PEER_BR_INFO_ENABLE @@ -701,7 +745,7 @@ exit: * - Prefix lifetime in seconds * - Preferred lifetime in seconds only if prefix is on-link * - Route preference (low, med, high) only if prefix is route (not on-link) - * - The router IPv6 address which advertising this prefix + * - The router IPv6 address which advertises this prefix * - Flags in received Router Advertisement header: * - M: Managed Address Config flag * - O: Other Config flag @@ -1172,23 +1216,23 @@ otError Br::Process(Arg aArgs[]) #if OPENTHREAD_CONFIG_IP6_BR_COUNTERS_ENABLE CmdEntry("counters"), #endif - CmdEntry("disable"), CmdEntry("enable"), CmdEntry("ifaddrs"), CmdEntry("infraif"), + CmdEntry("disable"), CmdEntry("enable"), CmdEntry("ifaddrs"), CmdEntry("infraif"), CmdEntry("init"), #if OPENTHREAD_CONFIG_BORDER_ROUTING_MULTI_AIL_DETECTION_ENABLE CmdEntry("multiail"), #endif #if OPENTHREAD_CONFIG_NAT64_BORDER_ROUTING_ENABLE - CmdEntry("nat64prefix"), + CmdEntry("nat64prefix"), CmdEntry("nat64prefixtable"), #endif - CmdEntry("omrconfig"), CmdEntry("omrprefix"), CmdEntry("onlinkprefix"), + CmdEntry("omrconfig"), CmdEntry("omrprefix"), CmdEntry("onlinkprefix"), #if OPENTHREAD_CONFIG_BORDER_ROUTING_DHCP6_PD_ENABLE CmdEntry("pd"), #endif #if OPENTHREAD_CONFIG_BORDER_ROUTING_TRACK_PEER_BR_INFO_ENABLE CmdEntry("peers"), #endif - CmdEntry("prefixtable"), CmdEntry("raoptions"), CmdEntry("rdnsstable"), CmdEntry("rioprf"), - CmdEntry("routeprf"), CmdEntry("routers"), CmdEntry("state"), + CmdEntry("prefixtable"), CmdEntry("raoptions"), CmdEntry("rdnsstable"), CmdEntry("rioprf"), + CmdEntry("routeprf"), CmdEntry("routers"), CmdEntry("state"), }; #undef CmdEntry diff --git a/src/core/api/border_routing_api.cpp b/src/core/api/border_routing_api.cpp index c8726b998..66f7edd0e 100644 --- a/src/core/api/border_routing_api.cpp +++ b/src/core/api/border_routing_api.cpp @@ -238,6 +238,18 @@ otError otBorderRoutingGetNextRouterEntry(otInstance *aI return AsCoreType(aInstance).Get().GetNextRouterEntry(*aIterator, *aEntry); } +#if OPENTHREAD_CONFIG_NAT64_BORDER_ROUTING_ENABLE +otError otBorderRoutingGetNextNat64PrefixEntry(otInstance *aInstance, + otBorderRoutingPrefixTableIterator *aIterator, + otBorderRoutingNat64PrefixEntry *aEntry) +{ + AssertPointerIsNotNull(aIterator); + AssertPointerIsNotNull(aEntry); + + return AsCoreType(aInstance).Get().GetNextNat64PrefixEntry(*aIterator, *aEntry); +} +#endif + otError otBorderRoutingGetNextRdnssAddrEntry(otInstance *aInstance, otBorderRoutingPrefixTableIterator *aIterator, otBorderRoutingRdnssAddrEntry *aEntry)