mirror of
https://github.com/espressif/openthread.git
synced 2026-10-01 05:17:40 +00:00
[posix] improve infra interface state detection (#12194)
This commit enhances the robustness of interface management with two improvements: 1. The `SendIcmp6Nd` function now explicitly handles `EADDRNOTAVAIL` and `ENODEV` errors from the `sendmsg()` system call. These errors often indicate that the interface is down or has lost its addresses. Upon that, we trigger an immediate re-evaluation of the interface's state by calling `otPlatInfraIfStateChanged()`. 2. The `GetFlags` function has been updated to also verify mInfraIndex and mInfraName not changed.
This commit is contained in:
@@ -275,7 +275,19 @@ otError InfraNetif::SendIcmp6Nd(uint32_t aInfraIfIndex,
|
|||||||
|
|
||||||
if (rval < 0)
|
if (rval < 0)
|
||||||
{
|
{
|
||||||
LogWarn("failed to send ICMPv6 message: %s", strerror(errno));
|
switch (errno)
|
||||||
|
{
|
||||||
|
case EADDRNOTAVAIL:
|
||||||
|
case ENODEV:
|
||||||
|
LogWarn("failed to send ICMPv6 message: %s, suggests infra link might be down, checking status.",
|
||||||
|
strerror(errno));
|
||||||
|
SuccessOrDie(otPlatInfraIfStateChanged(gInstance, mInfraIfIndex, IsRunning()));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
LogWarn("failed to send ICMPv6 message: %s", strerror(errno));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
ExitNow(error = OT_ERROR_FAILED);
|
ExitNow(error = OT_ERROR_FAILED);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -292,7 +304,9 @@ exit:
|
|||||||
|
|
||||||
bool InfraNetif::IsRunning(void) const
|
bool InfraNetif::IsRunning(void) const
|
||||||
{
|
{
|
||||||
return mInfraIfIndex ? ((GetFlags() & IFF_RUNNING) && HasLinkLocalAddress()) : false;
|
return mInfraIfIndex
|
||||||
|
? (if_nametoindex(mInfraIfName) == mInfraIfIndex && (GetFlags() & IFF_RUNNING) && HasLinkLocalAddress())
|
||||||
|
: false;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t InfraNetif::GetFlags(void) const
|
uint32_t InfraNetif::GetFlags(void) const
|
||||||
@@ -469,7 +483,7 @@ void InfraNetif::SetUp(void)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE
|
#if OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE
|
||||||
SuccessOrDie(otBorderRoutingInit(gInstance, mInfraIfIndex, otSysInfraIfIsRunning()));
|
SuccessOrDie(otBorderRoutingInit(gInstance, mInfraIfIndex, IsRunning()));
|
||||||
SuccessOrDie(otBorderRoutingSetEnabled(gInstance, /* aEnabled */ true));
|
SuccessOrDie(otBorderRoutingSetEnabled(gInstance, /* aEnabled */ true));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user