From 75bb4d018f1209eb3f58c0c4dbfb9d06e4190066 Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Thu, 28 Aug 2025 10:43:04 -0700 Subject: [PATCH] [nat64] ensure to extend mapping lifetime on reuse (#11866) Previously, a NAT64 mapping's lifetime was only extended upon its initial allocation. This meant that if an existing mapping was found and reused, its expiration timer would not be refreshed, potentially leading to its premature removal. This change moves the `mapping->Touch()` call from `AllocateMapping()` to `TranslateFromIp6()`. This ensures that a mapping's lifetime is extended every time it is used for translation, whether it is newly allocated or an existing one being reused. --- src/core/net/nat64_translator.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/core/net/nat64_translator.cpp b/src/core/net/nat64_translator.cpp index 25859f8b1..d5b94082c 100644 --- a/src/core/net/nat64_translator.cpp +++ b/src/core/net/nat64_translator.cpp @@ -163,6 +163,8 @@ Translator::Result Translator::TranslateFromIp6(Message &aMessage) ExitNow(result = kDrop); } + mapping->Touch(ip6Headers.GetIpProto()); + #if OPENTHREAD_CONFIG_NAT64_PORT_TRANSLATION_ENABLE srcPortOrId = mapping->mTranslatedPortOrId; #else @@ -502,7 +504,6 @@ Translator::Mapping *Translator::AllocateMapping(const Ip6::Headers &aIp6Headers mapping->mSrcPortOrId = GetSourcePortOrIcmp6Id(aIp6Headers); mapping->mTranslatedPortOrId = AllocateSourcePort(mapping->mSrcPortOrId); #endif - mapping->Touch(aIp6Headers.GetIpProto()); LogInfo("Mapping created: %s", mapping->ToString().AsCString());