Skip to content

Commit

Permalink
[nat64] enhancements for Translator::UpdateState (openthread#10564)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
superwhd authored Aug 1, 2024
1 parent fba922e commit 03113e8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
17 changes: 6 additions & 11 deletions src/core/net/nat64_translator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/core/net/nat64_translator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ class Translator : public InstanceLocator, private NonCopyable

using MappingTimer = TimerMilliIn<Translator, &Translator::HandleMappingExpirerTimer>;

void UpdateState(bool aAlwaysNotify = false);
void UpdateState(void);

bool mEnabled;
State mState;
Expand Down

0 comments on commit 03113e8

Please sign in to comment.