Skip to content

Commit

Permalink
[posix] allow OT process to run when infra netif gets lost (#9583)
Browse files Browse the repository at this point in the history
In `ot::Posix::InfraNetif::GetFlags()`, the OT process would die if
the infra network interface is removed on the POSIX platform. On
Android platform, this is not the desired behavior because the system
server may tell the OT process to switch another infra network
interface. It's fine for OT process to keep running when the previous
infra network interface disappears because later system server will
call `otSysSetInfraNetif()` to specify the new infra network
interface.
  • Loading branch information
superwhd authored Nov 9, 2023
1 parent a05954b commit 6edb06e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/posix/platform/infra_if.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ uint32_t InfraNetif::GetFlags(void) const
{
int sock;
struct ifreq ifReq;
uint32_t flags = 0;

OT_ASSERT(mInfraIfIndex != 0);

Expand All @@ -299,11 +300,20 @@ uint32_t InfraNetif::GetFlags(void) const
static_assert(sizeof(ifReq.ifr_name) >= sizeof(mInfraIfName), "mInfraIfName is not of appropriate size.");
strcpy(ifReq.ifr_name, mInfraIfName);

VerifyOrDie(ioctl(sock, SIOCGIFFLAGS, &ifReq) != -1, OT_EXIT_ERROR_ERRNO);
if (ioctl(sock, SIOCGIFFLAGS, &ifReq) == -1)
{
#if OPENTHREAD_POSIX_CONFIG_EXIT_ON_INFRA_NETIF_LOST_ENABLE
otLogCritPlat("The infra link %s may be lost. Exiting.", mInfraIfName);
DieNow(OT_EXIT_ERROR_ERRNO);
#endif
ExitNow();
}
flags = static_cast<uint32_t>(ifReq.ifr_flags);

exit:
close(sock);

return static_cast<uint32_t>(ifReq.ifr_flags);
return flags;
}

void InfraNetif::CountAddresses(otSysInfraNetIfAddressCounters &aAddressCounters) const
Expand Down
11 changes: 11 additions & 0 deletions src/posix/platform/openthread-posix-config.h
Original file line number Diff line number Diff line change
Expand Up @@ -441,4 +441,15 @@
#ifdef OPENTHREAD_POSIX_CONFIG_RCP_TIME_SYNC_INTERVAL
#error "OPENTHREAD_POSIX_CONFIG_RCP_TIME_SYNC_INTERVAL was replaced by OPENTHREAD_SPINEL_CONFIG_RCP_TIME_SYNC_INTERVAL"
#endif

/**
* @def OPENTHREAD_POSIX_CONFIG_EXIT_ON_INFRA_NETIF_LOST_ENABLE
*
* Define as 1 to let the process exit when the infra network interface is lost on the POSIX platform.
*
*/
#ifndef OPENTHREAD_POSIX_CONFIG_EXIT_ON_INFRA_NETIF_LOST_ENABLE
#define OPENTHREAD_POSIX_CONFIG_EXIT_ON_INFRA_NETIF_LOST_ENABLE 1
#endif

#endif // OPENTHREAD_PLATFORM_CONFIG_H_

0 comments on commit 6edb06e

Please sign in to comment.