Skip to content

Commit cb90930

Browse files
authored
[mdns] improve local host address logging (openthread#11651)
This commit refines the logging of local host address events in the `Mdns` module. Address update events signaled from the platform layer are now logged at the `Debug` level instead of `Info`. This avoids excessive logging from platform implementations that use periodic polling for address monitoring. Instead, after the events are processed, an `Info` level log is now generated only if the address list has changed. This new log specifies which addresses were added or removed. Additionally, the format for IPv4 addresses (tracked as IPv4-mapped IPv6 addresses) is updated to use the standard dotted-decimal notation, making the logs easier to read.
1 parent 6f434ce commit cb90930

2 files changed

Lines changed: 26 additions & 2 deletions

File tree

src/core/net/mdns.cpp

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1566,7 +1566,7 @@ void Core::LocalHost::HandleAddressEvent(const Ip6::Address &aAddress, bool aAdd
15661566
VerifyOrExit(Get<Core>().mIsEnabled);
15671567
VerifyOrExit(aInfraIfIndex == Get<Core>().mInfraIfIndex);
15681568

1569-
LogInfo("Host address %s event: %s", aAddress.ToString().AsCString(), aAdded ? "added" : "removed");
1569+
LogDebg("Host address %s event: %s", aAddress.ToString().AsCString(), aAdded ? "add" : "remove");
15701570

15711571
addrEvent = AddrEvent::Allocate(aAddress, aAdded);
15721572
OT_ASSERT(addrEvent != nullptr);
@@ -1601,7 +1601,7 @@ void Core::LocalHost::HandleAddressRemoveAll(uint32_t aInfraIfIndex)
16011601
mAddrEvents.Clear();
16021602
mEventTimer.Stop();
16031603

1604-
LogInfo("Host address event: remove all");
1604+
LogDebg("Host address event: remove all");
16051605

16061606
for (const Ip6::Address &address : mIp4Addresses)
16071607
{
@@ -1645,6 +1645,10 @@ void Core::LocalHost::HandleEventTimer(void)
16451645
{
16461646
SuccessOrAssert(addresses.PushBack(address));
16471647
}
1648+
else
1649+
{
1650+
LogAddressChange(/* aAdded */ false, addrType, address);
1651+
}
16481652
}
16491653

16501654
// Next, add any new addresses for which we got an "added"
@@ -1660,6 +1664,7 @@ void Core::LocalHost::HandleEventTimer(void)
16601664
if (addrEvent.mAdded && !addresses.Contains(addrEvent.mAddress))
16611665
{
16621666
SuccessOrAssert(addresses.PushBack(addrEvent.mAddress));
1667+
LogAddressChange(/* aAdded */ true, addrType, addrEvent.mAddress);
16631668
}
16641669
}
16651670
}
@@ -1670,6 +1675,23 @@ void Core::LocalHost::HandleEventTimer(void)
16701675
mAddrEvents.Clear();
16711676
}
16721677

1678+
#if OT_SHOULD_LOG_AT(OT_LOG_LEVEL_INFO)
1679+
void Core::LocalHost::LogAddressChange(bool aAdded, AddrType aAddrType, const Ip6::Address &aAddress) const
1680+
{
1681+
Ip4::Address ip4Address;
1682+
1683+
if (aAddrType == kIp4AddrType)
1684+
{
1685+
SuccessOrAssert(ip4Address.ExtractFromIp4MappedIp6Address(aAddress));
1686+
}
1687+
1688+
LogInfo("%s host address %s", aAdded ? "Adding" : "Removing",
1689+
aAddrType == kIp4AddrType ? ip4Address.ToString().AsCString() : aAddress.ToString().AsCString());
1690+
}
1691+
#else
1692+
void Core::LocalHost::LogAddressChange(bool, AddrType, const Ip6::Address &) const {}
1693+
#endif
1694+
16731695
//----------------------------------------------------------------------------------------------------------------------
16741696
// Core::LocalHost::AddrEvent
16751697

src/core/net/mdns.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,6 +1182,8 @@ class Core : public InstanceLocator, private NonCopyable
11821182
bool mAdded;
11831183
};
11841184

1185+
void LogAddressChange(bool aAdded, AddrType aAddrType, const Ip6::Address &aAddress) const;
1186+
11851187
using EventTimer = TimerMilliIn<Core, &Core::HandleLocalHostEventTimer>;
11861188

11871189
Heap::String mName;

0 commit comments

Comments
 (0)