From 3f1069e1109df5e3d87b4b15c747f8ba89a8676b Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Fri, 22 Aug 2025 11:17:48 -0700 Subject: [PATCH] [test] enable NAT64 translator unit tests (#11845) This commit makes several updates to enable and fix NAT64 unit test - Enables the NAT64 translator in `toranj` test configs, ensuring that the `test_nat64` unit test is now covered by the GitHub Actions CI (under the `toranj` workflow). - Enable `OPENTHREAD_CONFIG_NAT64_PORT_TRANSLATION_ENABLE` for the POSIX `toranj` build while disabling it for the simulation build, ensuring both configurations are built and covered by CI. - Fixes the `test_nat64` unit test by removing an incorrect "mapping pool exhausted" step. This step is now invalid as the pool size is configured to a much larger value (254) via `OPENTHREAD_CONFIG_NAT64_MAX_MAPPINGS`. --- src/posix/platform/netif.cpp | 12 +++++------- tests/toranj/openthread-core-toranj-config-posix.h | 2 ++ .../openthread-core-toranj-config-simulation.h | 2 ++ tests/toranj/openthread-core-toranj-config.h | 2 ++ tests/unit/test_nat64.cpp | 11 ----------- 5 files changed, 11 insertions(+), 18 deletions(-) diff --git a/src/posix/platform/netif.cpp b/src/posix/platform/netif.cpp index eb9bf2772..de8bed0e6 100644 --- a/src/posix/platform/netif.cpp +++ b/src/posix/platform/netif.cpp @@ -161,9 +161,6 @@ extern int unsigned int gNetifIndex = 0; char gNetifName[IFNAMSIZ]; -#if OPENTHREAD_CONFIG_NAT64_TRANSLATOR_ENABLE -static otIp4Cidr sActiveNat64Cidr; -#endif const char *otSysGetThreadNetifName(void) { return gNetifName; } @@ -214,10 +211,6 @@ static uint8_t sAddedExternalRoutesNum = 0; static otIp6Prefix sAddedExternalRoutes[kMaxExternalRoutesNum]; #endif -#if OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE && OPENTHREAD_CONFIG_NAT64_TRANSLATOR_ENABLE -static constexpr uint32_t kNat64RoutePriority = 100; ///< Priority for route to NAT64 CIDR, 100 means a high priority. -#endif - #if defined(RTM_NEWMADDR) || defined(__NetBSD__) // on some BSDs (mac OS, FreeBSD), we get RTM_NEWMADDR/RTM_DELMADDR messages, so we don't need to monitor using MLD // on NetBSD, MLD monitoring simply doesn't work @@ -976,6 +969,11 @@ static void processAddressChange(const otIp6AddressInfo *aAddressInfo, bool aIsA } #if defined(__linux__) && OPENTHREAD_CONFIG_NAT64_TRANSLATOR_ENABLE + +static otIp4Cidr sActiveNat64Cidr; + +static constexpr uint32_t kNat64RoutePriority = 100; // Priority for route to NAT64 CIDR, 100 means a high priority. + static bool isSameIp4Cidr(const otIp4Cidr &aCidr1, const otIp4Cidr &aCidr2) { bool res = true; diff --git a/tests/toranj/openthread-core-toranj-config-posix.h b/tests/toranj/openthread-core-toranj-config-posix.h index e9ed1bdff..774911166 100644 --- a/tests/toranj/openthread-core-toranj-config-posix.h +++ b/tests/toranj/openthread-core-toranj-config-posix.h @@ -70,6 +70,8 @@ #define OPENTHREAD_POSIX_CONFIG_NAT64_AIL_PREFIX_ENABLE 1 +#define OPENTHREAD_CONFIG_NAT64_PORT_TRANSLATION_ENABLE 1 + // The following two features (`USE_HEAP`) are set explicitly on posix `toranj` // to validate the build with these config. The `toranj` build under simulation // platform covers the opposite configs (allows `USE_HEAP`). diff --git a/tests/toranj/openthread-core-toranj-config-simulation.h b/tests/toranj/openthread-core-toranj-config-simulation.h index fdac31723..94dbbfd79 100644 --- a/tests/toranj/openthread-core-toranj-config-simulation.h +++ b/tests/toranj/openthread-core-toranj-config-simulation.h @@ -93,6 +93,8 @@ #define OPENTHREAD_CONFIG_DHCP6_CLIENT_ENABLE 1 +#define OPENTHREAD_CONFIG_NAT64_PORT_TRANSLATION_ENABLE 0 + #define OPENTHREAD_CONFIG_RADIO_STATS_ENABLE 0 #define OPENTHREAD_CONFIG_TREL_MANAGE_DNSSD_ENABLE 0 diff --git a/tests/toranj/openthread-core-toranj-config.h b/tests/toranj/openthread-core-toranj-config.h index 8bc539ed5..9b9bb99fd 100644 --- a/tests/toranj/openthread-core-toranj-config.h +++ b/tests/toranj/openthread-core-toranj-config.h @@ -54,6 +54,8 @@ #define OPENTHREAD_CONFIG_NAT64_BORDER_ROUTING_ENABLE OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE +#define OPENTHREAD_CONFIG_NAT64_TRANSLATOR_ENABLE OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE + #define OPENTHREAD_CONFIG_BORDER_ROUTING_DHCP6_PD_ENABLE 1 #define OPENTHREAD_CONFIG_BORDER_ROUTING_DHCP6_PD_CLIENT_ENABLE 1 diff --git a/tests/unit/test_nat64.cpp b/tests/unit/test_nat64.cpp index 3a474e854..e2d5c6355 100644 --- a/tests/unit/test_nat64.cpp +++ b/tests/unit/test_nat64.cpp @@ -314,17 +314,6 @@ void TestNat64(void) TestCase4To6("no v4 mapping", kIp4Packet, Nat64::Translator::kDrop, nullptr, 0); } - { - // fd02::2 fd01::ac10:f3c5 UDP 52 43981 → 4660 Len=4 - const uint8_t kIp6Packet[] = { - 0x60, 0x08, 0x6e, 0x38, 0x00, 0x0c, 0x11, 0x40, 0xfd, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xfd, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 172, 16, 243, 197, 0xab, 0xcd, 0x12, 0x34, 0x00, 0x0c, 0xe3, 0x30, 0x61, 0x62, 0x63, 0x64, - }; - - TestCase6To4("mapping pool exhausted", kIp6Packet, Nat64::Translator::kDrop, nullptr, 0); - } - testFreeInstance(sInstance); }