mirror of
https://github.com/espressif/openthread.git
synced 2026-08-29 21:39:54 +00:00
[posix] enable building infra_if.cpp on macOS (#9891)
This change makes it possible to build the `posix/platform/infra_if` module on macOS (and other non-Linux systems). It adds guard checks `#ifdef __linux__` around the use of `mNetLinkSocket`(used for network interface state change detection). This allows compilation to proceed on macOS, though equivalent functionality for detecting netif change is not yet implemented. This commit also adds a new `toranj-macos` workflow job to validate that the code builds successfully with the `posix` platform.
This commit is contained in:
@@ -159,6 +159,28 @@ jobs:
|
||||
git clean -dfx
|
||||
./tests/toranj/build.sh --enable-plat-key-ref all
|
||||
|
||||
toranj-macos:
|
||||
name: toranj-macos
|
||||
runs-on: macos-14
|
||||
steps:
|
||||
- name: Harden Runner
|
||||
uses: step-security/harden-runner@63c24ba6bd7ba022e95695ff85de572c04a18142 # v2.7.0
|
||||
with:
|
||||
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs
|
||||
|
||||
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
|
||||
with:
|
||||
submodules: true
|
||||
- name: Bootstrap
|
||||
env:
|
||||
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
|
||||
run: |
|
||||
brew update
|
||||
brew install ninja
|
||||
- name: Build & Run
|
||||
run: |
|
||||
./tests/toranj/build.sh posix-15.4
|
||||
|
||||
upload-coverage:
|
||||
needs:
|
||||
- toranj-cli
|
||||
|
||||
@@ -190,6 +190,7 @@ bool IsAddressUniqueLocal(const in6_addr &aAddress) { return (aAddress.s6_addr[0
|
||||
|
||||
bool IsAddressGlobalUnicast(const in6_addr &aAddress) { return (aAddress.s6_addr[0] & 0xe0) == 0x20; }
|
||||
|
||||
#ifdef __linux__
|
||||
// Create a net-link socket that subscribes to link & addresses events.
|
||||
int CreateNetLinkSocket(void)
|
||||
{
|
||||
@@ -209,6 +210,7 @@ int CreateNetLinkSocket(void)
|
||||
|
||||
return sock;
|
||||
}
|
||||
#endif // #ifdef __linux__
|
||||
|
||||
#if OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE
|
||||
otError InfraNetif::SendIcmp6Nd(uint32_t aInfraIfIndex,
|
||||
@@ -405,7 +407,12 @@ bool InfraNetif::HasLinkLocalAddress(void) const
|
||||
return hasLla;
|
||||
}
|
||||
|
||||
void InfraNetif::Init(void) { mNetLinkSocket = CreateNetLinkSocket(); }
|
||||
void InfraNetif::Init(void)
|
||||
{
|
||||
#ifdef __linux__
|
||||
mNetLinkSocket = CreateNetLinkSocket();
|
||||
#endif
|
||||
}
|
||||
|
||||
void InfraNetif::SetInfraNetif(const char *aIfName, int aIcmp6Socket)
|
||||
{
|
||||
@@ -414,7 +421,9 @@ void InfraNetif::SetInfraNetif(const char *aIfName, int aIcmp6Socket)
|
||||
OT_UNUSED_VARIABLE(aIcmp6Socket);
|
||||
|
||||
OT_ASSERT(gInstance != nullptr);
|
||||
#ifdef __linux__
|
||||
VerifyOrDie(mNetLinkSocket != -1, OT_EXIT_INVALID_STATE);
|
||||
#endif
|
||||
|
||||
#if OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE
|
||||
SetInfraNetifIcmp6SocketForBorderRouting(aIcmp6Socket);
|
||||
@@ -449,7 +458,9 @@ exit:
|
||||
void InfraNetif::SetUp(void)
|
||||
{
|
||||
OT_ASSERT(gInstance != nullptr);
|
||||
#ifdef __linux__
|
||||
VerifyOrExit(mNetLinkSocket != -1);
|
||||
#endif
|
||||
|
||||
#if OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE
|
||||
SuccessOrDie(otBorderRoutingInit(gInstance, mInfraIfIndex, otSysInfraIfIsRunning()));
|
||||
@@ -461,6 +472,9 @@ void InfraNetif::SetUp(void)
|
||||
#endif
|
||||
|
||||
Mainloop::Manager::Get().Add(*this);
|
||||
|
||||
ExitNow(); // To silence unused `exit` label warning.
|
||||
|
||||
exit:
|
||||
return;
|
||||
}
|
||||
@@ -488,11 +502,13 @@ void InfraNetif::Deinit(void)
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef __linux__
|
||||
if (mNetLinkSocket != -1)
|
||||
{
|
||||
close(mNetLinkSocket);
|
||||
mNetLinkSocket = -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
mInfraIfName[0] = '\0';
|
||||
mInfraIfIndex = 0;
|
||||
@@ -500,7 +516,9 @@ void InfraNetif::Deinit(void)
|
||||
|
||||
void InfraNetif::Update(otSysMainloopContext &aContext)
|
||||
{
|
||||
#ifdef __linux__
|
||||
VerifyOrExit(mNetLinkSocket != -1);
|
||||
#endif
|
||||
|
||||
#if OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE
|
||||
VerifyOrExit(mInfraIfIcmp6Socket != -1);
|
||||
@@ -509,13 +527,17 @@ void InfraNetif::Update(otSysMainloopContext &aContext)
|
||||
aContext.mMaxFd = OT_MAX(aContext.mMaxFd, mInfraIfIcmp6Socket);
|
||||
#endif
|
||||
|
||||
#ifdef __linux__
|
||||
FD_SET(mNetLinkSocket, &aContext.mReadFdSet);
|
||||
aContext.mMaxFd = OT_MAX(aContext.mMaxFd, mNetLinkSocket);
|
||||
#endif
|
||||
|
||||
exit:
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef __linux__
|
||||
|
||||
void InfraNetif::ReceiveNetLinkMessage(void)
|
||||
{
|
||||
const size_t kMaxNetLinkBufSize = 8192;
|
||||
@@ -566,6 +588,8 @@ exit:
|
||||
return;
|
||||
}
|
||||
|
||||
#endif // #ifdef __linux__
|
||||
|
||||
#if OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE
|
||||
void InfraNetif::ReceiveIcmp6Message(void)
|
||||
{
|
||||
@@ -792,7 +816,10 @@ void InfraNetif::Process(const otSysMainloopContext &aContext)
|
||||
#if OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE
|
||||
VerifyOrExit(mInfraIfIcmp6Socket != -1);
|
||||
#endif
|
||||
|
||||
#ifdef __linux__
|
||||
VerifyOrExit(mNetLinkSocket != -1);
|
||||
#endif
|
||||
|
||||
#if OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE
|
||||
if (FD_ISSET(mInfraIfIcmp6Socket, &aContext.mReadFdSet))
|
||||
@@ -801,10 +828,12 @@ void InfraNetif::Process(const otSysMainloopContext &aContext)
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef __linux__
|
||||
if (FD_ISSET(mNetLinkSocket, &aContext.mReadFdSet))
|
||||
{
|
||||
ReceiveNetLinkMessage();
|
||||
}
|
||||
#endif
|
||||
|
||||
exit:
|
||||
return;
|
||||
|
||||
@@ -220,8 +220,12 @@ private:
|
||||
static const uint8_t kValidNat64PrefixLength[];
|
||||
|
||||
char mInfraIfName[IFNAMSIZ];
|
||||
uint32_t mInfraIfIndex = 0;
|
||||
int mNetLinkSocket = -1;
|
||||
uint32_t mInfraIfIndex = 0;
|
||||
|
||||
#ifdef __linux__
|
||||
int mNetLinkSocket = -1;
|
||||
#endif
|
||||
|
||||
#if OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE
|
||||
int mInfraIfIcmp6Socket = -1;
|
||||
#endif
|
||||
@@ -229,7 +233,10 @@ private:
|
||||
MulticastRoutingManager mMulticastRoutingManager;
|
||||
#endif
|
||||
|
||||
void ReceiveNetLinkMessage(void);
|
||||
#ifdef __linux__
|
||||
void ReceiveNetLinkMessage(void);
|
||||
#endif
|
||||
|
||||
bool HasLinkLocalAddress(void) const;
|
||||
static void DiscoverNat64PrefixDone(union sigval sv);
|
||||
#if OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE
|
||||
|
||||
@@ -39,6 +39,10 @@
|
||||
|
||||
#define OPENTHREAD_CONFIG_PLATFORM_INFO "POSIX-toranj"
|
||||
|
||||
#ifdef __linux__
|
||||
#define OPENTHREAD_CONFIG_BACKBONE_ROUTER_ENABLE 1
|
||||
#endif
|
||||
|
||||
#define OPENTHREAD_CONFIG_LOG_OUTPUT OPENTHREAD_CONFIG_LOG_OUTPUT_PLATFORM_DEFINED
|
||||
|
||||
#define OPENTHREAD_CONFIG_BORDER_ROUTER_ENABLE 1
|
||||
|
||||
@@ -69,6 +69,8 @@
|
||||
|
||||
#define OPENTHREAD_CONFIG_BORDER_ROUTING_USE_HEAP_ENABLE 1
|
||||
|
||||
#define OPENTHREAD_CONFIG_BACKBONE_ROUTER_ENABLE 1
|
||||
|
||||
#define OPENTHREAD_CONFIG_RADIO_STATS_ENABLE 0
|
||||
|
||||
#endif /* OPENTHREAD_CORE_TORANJ_CONFIG_SIMULATION_H_ */
|
||||
|
||||
@@ -170,8 +170,6 @@
|
||||
|
||||
#define OPENTHREAD_CONFIG_DELAY_AWARE_QUEUE_MANAGEMENT_ENABLE 1
|
||||
|
||||
#define OPENTHREAD_CONFIG_BACKBONE_ROUTER_ENABLE 1
|
||||
|
||||
#define OPENTHREAD_CONFIG_CLI_REGISTER_IP6_RECV_CALLBACK 1
|
||||
|
||||
#define OPENTHREAD_CONFIG_MLE_PARENT_RESPONSE_CALLBACK_API_ENABLE 1
|
||||
|
||||
Reference in New Issue
Block a user