[nat64] enhancements for Translator::UpdateState (#10564)

This commit applies following enhancements to the
`Translator::UpdateState`:
- Remove the `aAlwaysNotify` parameter to simplify its logic.
- Fix an issue that `mState` may not be updated when setting a CIDR.
This commit is contained in:
Handa Wang
2024-08-01 08:33:19 -07:00
committed by GitHub
parent fba922ebe2
commit 03113e8502
2 changed files with 7 additions and 12 deletions
+6 -11
View File
@@ -509,8 +509,10 @@ Error Translator::SetIp4Cidr(const Ip4::Cidr &aCidr)
ToUlong(numberOfHosts));
mIp4Cidr = aCidr;
// Always notify the platform when the CIDR is changed.
UpdateState(true /* aAlwaysNotify */);
UpdateState();
// Notify the platform when the CIDR is changed.
Get<Notifier>().Signal(kEventNat64TranslatorStateChanged);
exit:
return err;
@@ -634,7 +636,7 @@ void Translator::ProtocolCounters::Count4To6Packet(uint8_t aProtocol, uint64_t a
mTotal.m4To6Bytes += aPacketSize;
}
void Translator::UpdateState(bool aAlwaysNotify)
void Translator::UpdateState(void)
{
State newState;
@@ -654,14 +656,7 @@ void Translator::UpdateState(bool aAlwaysNotify)
newState = kStateDisabled;
}
if (aAlwaysNotify)
{
Get<Notifier>().Signal(kEventNat64TranslatorStateChanged);
}
else
{
SuccessOrExit(Get<Notifier>().Update(mState, newState, kEventNat64TranslatorStateChanged));
}
SuccessOrExit(Get<Notifier>().Update(mState, newState, kEventNat64TranslatorStateChanged));
LogInfo("NAT64 translator is now %s", StateToString(mState));
exit:
+1 -1
View File
@@ -380,7 +380,7 @@ private:
using MappingTimer = TimerMilliIn<Translator, &Translator::HandleMappingExpirerTimer>;
void UpdateState(bool aAlwaysNotify = false);
void UpdateState(void);
bool mEnabled;
State mState;