[infra-if] add missing otInstance parameter to otPlatInfraIf APIs (#12662)

This commit updates the following `otPlatInfraIf` platform APIs to
include an `otInstance *` as their first parameter:

- `otPlatInfraIfHasAddress()`
- `otPlatInfraIfSendIcmp6Nd()`
- `otPlatInfraIfDiscoverNat64Prefix()`

Other APIs under `otPlatInfraIf` already follow this pattern. Passing
the `otInstance` pointer is the required standard for all platform
and public APIs; however, it was missed during the initial design of
these specific APIs.

While missing this parameter is often not a blocker on platforms using
a single OpenThread instance, it has become a blocker for simulations,
especially when multiple Border Routers are emulated in the same
simulation setup.

This change introduces a compatibility break for existing platform
implementations, however, it is necessary to support new use cases
(simulation of BRs). It also helps ensure consistent API design
across the stack.
This commit is contained in:
Abtin Keshavarzian
2026-03-12 08:10:08 -07:00
committed by GitHub
parent a03011cf73
commit cf733a331e
11 changed files with 72 additions and 41 deletions
+8 -3
View File
@@ -172,18 +172,22 @@ exit:
//---------------------------------------------------------------------------------------------------------------------
// otPlatInfraIf
bool otPlatInfraIfHasAddress(uint32_t aInfraIfIndex, const otIp6Address *aAddress)
bool otPlatInfraIfHasAddress(otInstance *aInstance, uint32_t aInfraIfIndex, const otIp6Address *aAddress)
{
OT_UNUSED_VARIABLE(aInstance);
OT_UNUSED_VARIABLE(aInfraIfIndex);
return addressesMatch(aAddress, &sIp6Address);
}
otError otPlatInfraIfSendIcmp6Nd(uint32_t aInfraIfIndex,
otError otPlatInfraIfSendIcmp6Nd(otInstance *aInstance,
uint32_t aInfraIfIndex,
const otIp6Address *aDestAddress,
const uint8_t *aBuffer,
uint16_t aBufferLength)
{
OT_UNUSED_VARIABLE(aInstance);
otError error = OT_ERROR_FAILED;
Message *message;
@@ -207,8 +211,9 @@ exit:
return error;
}
otError otPlatInfraIfDiscoverNat64Prefix(uint32_t aInfraIfIndex)
otError otPlatInfraIfDiscoverNat64Prefix(otInstance *aInstance, uint32_t aInfraIfIndex)
{
OT_UNUSED_VARIABLE(aInstance);
OT_UNUSED_VARIABLE(aInfraIfIndex);
return OT_ERROR_NONE;
+1 -1
View File
@@ -52,7 +52,7 @@ extern "C" {
*
* @note This number versions both OpenThread platform and user APIs.
*/
#define OPENTHREAD_API_VERSION (580)
#define OPENTHREAD_API_VERSION (581)
/**
* @addtogroup api-instance
+7 -3
View File
@@ -70,18 +70,20 @@ typedef struct otPlatInfraIfLinkLayerAddress
/**
* Tells whether an infra interface has the given IPv6 address assigned.
*
* @param[in] aInstance The OpenThread instance.
* @param[in] aInfraIfIndex The index of the infra interface.
* @param[in] aAddress The IPv6 address.
*
* @returns TRUE if the infra interface has given IPv6 address assigned, FALSE otherwise.
*/
bool otPlatInfraIfHasAddress(uint32_t aInfraIfIndex, const otIp6Address *aAddress);
bool otPlatInfraIfHasAddress(otInstance *aInstance, uint32_t aInfraIfIndex, const otIp6Address *aAddress);
/**
* Sends an ICMPv6 Neighbor Discovery message on given infrastructure interface.
*
* See RFC 4861: https://tools.ietf.org/html/rfc4861.
*
* @param[in] aInstance The OpenThread instance.
* @param[in] aInfraIfIndex The index of the infrastructure interface this message is sent to.
* @param[in] aDestAddress The destination address this message is sent to.
* @param[in] aBuffer The ICMPv6 message buffer. The ICMPv6 checksum is left zero and the
@@ -94,7 +96,8 @@ bool otPlatInfraIfHasAddress(uint32_t aInfraIfIndex, const otIp6Address *aAddres
* @retval OT_ERROR_NONE Successfully sent the ICMPv6 message.
* @retval OT_ERROR_FAILED Failed to send the ICMPv6 message.
*/
otError otPlatInfraIfSendIcmp6Nd(uint32_t aInfraIfIndex,
otError otPlatInfraIfSendIcmp6Nd(otInstance *aInstance,
uint32_t aInfraIfIndex,
const otIp6Address *aDestAddress,
const uint8_t *aBuffer,
uint16_t aBufferLength);
@@ -145,6 +148,7 @@ extern otError otPlatInfraIfStateChanged(otInstance *aInstance, uint32_t aInfraI
*
* OpenThread will call this method periodically to monitor the presence or change of NAT64 prefix.
*
* @param[in] aInstance The OpenThread instance.
* @param[in] aInfraIfIndex The index of the infrastructure interface to discover the NAT64 prefix.
*
* @retval OT_ERROR_NONE Successfully requested NAT64 prefix discovery.
@@ -155,7 +159,7 @@ extern otError otPlatInfraIfStateChanged(otInstance *aInstance, uint32_t aInfraI
* discovery). The priority of the discovered prefix is lower than that of the prefix discovered via Router
* Advertisements PREF64 option (RFC 8781).
*/
otError otPlatInfraIfDiscoverNat64Prefix(uint32_t aInfraIfIndex);
otError otPlatInfraIfDiscoverNat64Prefix(otInstance *aInstance, uint32_t aInfraIfIndex);
/**
* The infra interface driver calls this method to notify OpenThread that
+6 -6
View File
@@ -95,14 +95,14 @@ bool InfraIf::HasAddress(const Ip6::Address &aAddress) const
{
OT_ASSERT(mInitialized);
return otPlatInfraIfHasAddress(mIfIndex, &aAddress);
return otPlatInfraIfHasAddress(&GetInstance(), mIfIndex, &aAddress);
}
Error InfraIf::Send(const Icmp6Packet &aPacket, const Ip6::Address &aDestination) const
{
OT_ASSERT(mInitialized);
return otPlatInfraIfSendIcmp6Nd(mIfIndex, &aDestination, aPacket.GetBytes(), aPacket.GetLength());
return otPlatInfraIfSendIcmp6Nd(&GetInstance(), mIfIndex, &aDestination, aPacket.GetBytes(), aPacket.GetLength());
}
void InfraIf::HandledReceived(uint32_t aIfIndex, const Ip6::Address &aSource, const Icmp6Packet &aPacket)
@@ -142,7 +142,7 @@ Error InfraIf::DiscoverNat64Prefix(void) const
{
OT_ASSERT(mInitialized);
return otPlatInfraIfDiscoverNat64Prefix(mIfIndex);
return otPlatInfraIfDiscoverNat64Prefix(&GetInstance(), mIfIndex);
}
void InfraIf::DiscoverNat64PrefixDone(uint32_t aIfIndex, const Ip6::Prefix &aPrefix)
@@ -283,14 +283,14 @@ extern "C" void otPlatInfraIfDhcp6PdClientHandleReceived(otInstance *aInstance,
//---------------------------------------------------------------------------------------------------------------------
#if OPENTHREAD_CONFIG_BORDER_ROUTING_MOCK_PLAT_APIS_ENABLE
OT_TOOL_WEAK bool otPlatInfraIfHasAddress(uint32_t, const otIp6Address *) { return false; }
OT_TOOL_WEAK bool otPlatInfraIfHasAddress(otInstance *, uint32_t, const otIp6Address *) { return false; }
OT_TOOL_WEAK otError otPlatInfraIfSendIcmp6Nd(uint32_t, const otIp6Address *, const uint8_t *, uint16_t)
OT_TOOL_WEAK otError otPlatInfraIfSendIcmp6Nd(otInstance *, uint32_t, const otIp6Address *, const uint8_t *, uint16_t)
{
return OT_ERROR_FAILED;
}
OT_TOOL_WEAK otError otPlatInfraIfDiscoverNat64Prefix(uint32_t) { return OT_ERROR_FAILED; }
OT_TOOL_WEAK otError otPlatInfraIfDiscoverNat64Prefix(otInstance *, uint32_t) { return OT_ERROR_FAILED; }
#endif
extern "C" OT_TOOL_WEAK otError otPlatGetInfraIfLinkLayerAddress(otInstance *,
+9 -3
View File
@@ -31,23 +31,29 @@
#include "ncp/ncp_base.hpp"
#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_NCP_INFRA_IF_ENABLE && OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE
bool otPlatInfraIfHasAddress(uint32_t aInfraIfIndex, const otIp6Address *aAddress)
bool otPlatInfraIfHasAddress(otInstance *aInstance, uint32_t aInfraIfIndex, const otIp6Address *aAddress)
{
OT_UNUSED_VARIABLE(aInstance);
return ot::Ncp::NcpBase::GetNcpInstance()->InfraIfHasAddress(aInfraIfIndex, aAddress);
}
otError otPlatInfraIfSendIcmp6Nd(uint32_t aInfraIfIndex,
otError otPlatInfraIfSendIcmp6Nd(otInstance *aInstance,
uint32_t aInfraIfIndex,
const otIp6Address *aDestAddress,
const uint8_t *aBuffer,
uint16_t aBufferLength)
{
OT_UNUSED_VARIABLE(aInstance);
ot::Ncp::NcpBase *ncp = ot::Ncp::NcpBase::GetNcpInstance();
return ncp->InfraIfSendIcmp6Nd(aInfraIfIndex, aDestAddress, aBuffer, aBufferLength);
}
otError otPlatInfraIfDiscoverNat64Prefix(uint32_t aInfraIfIndex)
otError otPlatInfraIfDiscoverNat64Prefix(otInstance *aInstance, uint32_t aInfraIfIndex)
{
OT_UNUSED_VARIABLE(aInstance);
OT_UNUSED_VARIABLE(aInfraIfIndex);
return OT_ERROR_NOT_IMPLEMENTED;
+10 -3
View File
@@ -64,8 +64,10 @@
#include "common/debug.hpp"
#include "lib/platform/exit_code.h"
bool otPlatInfraIfHasAddress(uint32_t aInfraIfIndex, const otIp6Address *aAddress)
bool otPlatInfraIfHasAddress(otInstance *aInstance, uint32_t aInfraIfIndex, const otIp6Address *aAddress)
{
OT_UNUSED_VARIABLE(aInstance);
bool ret = false;
struct ifaddrs *ifAddrs = nullptr;
@@ -94,19 +96,24 @@ exit:
}
#if OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE
otError otPlatInfraIfSendIcmp6Nd(uint32_t aInfraIfIndex,
otError otPlatInfraIfSendIcmp6Nd(otInstance *aInstance,
uint32_t aInfraIfIndex,
const otIp6Address *aDestAddress,
const uint8_t *aBuffer,
uint16_t aBufferLength)
{
OT_UNUSED_VARIABLE(aInstance);
return ot::Posix::InfraNetif::Get().SendIcmp6Nd(aInfraIfIndex, *aDestAddress, aBuffer, aBufferLength);
}
#endif
#if OPENTHREAD_CONFIG_NAT64_BORDER_ROUTING_ENABLE
otError otPlatInfraIfDiscoverNat64Prefix(uint32_t aInfraIfIndex)
otError otPlatInfraIfDiscoverNat64Prefix(otInstance *aInstance, uint32_t aInfraIfIndex)
{
OT_UNUSED_VARIABLE(aInstance);
OT_UNUSED_VARIABLE(aInfraIfIndex);
return OT_ERROR_NOT_IMPLEMENTED;
}
#endif
+6 -3
View File
@@ -502,11 +502,14 @@ void *otPlatCAlloc(size_t aNum, size_t aSize) { return calloc(aNum, aSize); }
void otPlatFree(void *aPtr) { free(aPtr); }
bool otPlatInfraIfHasAddress(uint32_t, const otIp6Address *) { return false; }
bool otPlatInfraIfHasAddress(otInstance *, uint32_t, const otIp6Address *) { return false; }
otError otPlatInfraIfSendIcmp6Nd(uint32_t, const otIp6Address *, const uint8_t *, uint16_t) { return OT_ERROR_FAILED; }
otError otPlatInfraIfSendIcmp6Nd(otInstance *, uint32_t, const otIp6Address *, const uint8_t *, uint16_t)
{
return OT_ERROR_FAILED;
}
otError otPlatInfraIfDiscoverNat64Prefix(uint32_t) { return OT_ERROR_FAILED; }
otError otPlatInfraIfDiscoverNat64Prefix(otInstance *, uint32_t) { return OT_ERROR_FAILED; }
void otPlatDsoEnableListening(otInstance *, bool) {}
+6 -3
View File
@@ -33,11 +33,14 @@ namespace Nexus {
extern "C" {
bool otPlatInfraIfHasAddress(uint32_t, const otIp6Address *) { return false; }
bool otPlatInfraIfHasAddress(otInstance *, uint32_t, const otIp6Address *) { return false; }
otError otPlatInfraIfSendIcmp6Nd(uint32_t, const otIp6Address *, const uint8_t *, uint16_t) { return OT_ERROR_NONE; }
otError otPlatInfraIfSendIcmp6Nd(otInstance *, uint32_t, const otIp6Address *, const uint8_t *, uint16_t)
{
return OT_ERROR_NONE;
}
otError otPlatInfraIfDiscoverNat64Prefix(uint32_t) { return OT_ERROR_NOT_IMPLEMENTED; }
otError otPlatInfraIfDiscoverNat64Prefix(otInstance *, uint32_t) { return OT_ERROR_NOT_IMPLEMENTED; }
} // extern "C"
+11 -11
View File
@@ -94,14 +94,14 @@ void TestNcpInfraIfSetUp(void)
recvLen));
ncpBase.HandleReceive(recvBuf, recvLen);
VerifyOrQuit(otBorderRoutingGetState(instance) == OT_BORDER_ROUTING_STATE_STOPPED);
VerifyOrQuit(otPlatInfraIfHasAddress(kInfraIfIndex, &infraIfAddresses[0]));
VerifyOrQuit(!otPlatInfraIfHasAddress(kInfraIfIndex + 100, &infraIfAddresses[0]));
VerifyOrQuit(otPlatInfraIfHasAddress(instance, kInfraIfIndex, &infraIfAddresses[0]));
VerifyOrQuit(!otPlatInfraIfHasAddress(instance, kInfraIfIndex + 100, &infraIfAddresses[0]));
SuccessOrQuit(
GenerateSpinelInfraIfStateFrame(kInfraIfIndex, true /* IsRunning */, infraIfAddresses, 0, recvBuf, recvLen));
ncpBase.HandleReceive(recvBuf, recvLen);
VerifyOrQuit(otBorderRoutingGetState(instance) == OT_BORDER_ROUTING_STATE_STOPPED);
VerifyOrQuit(!otPlatInfraIfHasAddress(kInfraIfIndex, &infraIfAddresses[0]));
VerifyOrQuit(!otPlatInfraIfHasAddress(instance, kInfraIfIndex, &infraIfAddresses[0]));
printf("Test Ncp Infra If SetUp passed.\n");
}
@@ -124,22 +124,22 @@ void TestNcpInfraIfUpdate(void)
SuccessOrQuit(
GenerateSpinelInfraIfStateFrame(kInfraIfIndex1, true /* IsRunning */, infraIfAddresses, 1, recvBuf, recvLen));
ncpBase.HandleReceive(recvBuf, recvLen);
VerifyOrQuit(otPlatInfraIfHasAddress(kInfraIfIndex1, &infraIfAddresses[0]));
VerifyOrQuit(!otPlatInfraIfHasAddress(kInfraIfIndex1, &infraIfAddresses[1]));
VerifyOrQuit(otPlatInfraIfHasAddress(instance, kInfraIfIndex1, &infraIfAddresses[0]));
VerifyOrQuit(!otPlatInfraIfHasAddress(instance, kInfraIfIndex1, &infraIfAddresses[1]));
SuccessOrQuit(
GenerateSpinelInfraIfStateFrame(kInfraIfIndex1, true /* IsRunning */, infraIfAddresses, 2, recvBuf, recvLen));
ncpBase.HandleReceive(recvBuf, recvLen);
VerifyOrQuit(otPlatInfraIfHasAddress(kInfraIfIndex1, &infraIfAddresses[0]));
VerifyOrQuit(otPlatInfraIfHasAddress(kInfraIfIndex1, &infraIfAddresses[1]));
VerifyOrQuit(otPlatInfraIfHasAddress(instance, kInfraIfIndex1, &infraIfAddresses[0]));
VerifyOrQuit(otPlatInfraIfHasAddress(instance, kInfraIfIndex1, &infraIfAddresses[1]));
SuccessOrQuit(
GenerateSpinelInfraIfStateFrame(kInfraIfIndex2, true /* IsRunning */, infraIfAddresses, 2, recvBuf, recvLen));
ncpBase.HandleReceive(recvBuf, recvLen);
VerifyOrQuit(!otPlatInfraIfHasAddress(kInfraIfIndex1, &infraIfAddresses[0]));
VerifyOrQuit(!otPlatInfraIfHasAddress(kInfraIfIndex1, &infraIfAddresses[1]));
VerifyOrQuit(otPlatInfraIfHasAddress(kInfraIfIndex2, &infraIfAddresses[0]));
VerifyOrQuit(otPlatInfraIfHasAddress(kInfraIfIndex2, &infraIfAddresses[1]));
VerifyOrQuit(!otPlatInfraIfHasAddress(instance, kInfraIfIndex1, &infraIfAddresses[0]));
VerifyOrQuit(!otPlatInfraIfHasAddress(instance, kInfraIfIndex1, &infraIfAddresses[1]));
VerifyOrQuit(otPlatInfraIfHasAddress(instance, kInfraIfIndex2, &infraIfAddresses[0]));
VerifyOrQuit(otPlatInfraIfHasAddress(instance, kInfraIfIndex2, &infraIfAddresses[1]));
}
} // namespace ot
+3 -3
View File
@@ -478,14 +478,14 @@ OT_TOOL_WEAK otLinkMetrics otPlatRadioGetEnhAckProbingMetrics(otInstance *, cons
#if OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE
OT_TOOL_WEAK bool otPlatInfraIfHasAddress(uint32_t, const otIp6Address *) { return false; }
OT_TOOL_WEAK bool otPlatInfraIfHasAddress(otInstance *, uint32_t, const otIp6Address *) { return false; }
OT_TOOL_WEAK otError otPlatInfraIfSendIcmp6Nd(uint32_t, const otIp6Address *, const uint8_t *, uint16_t)
OT_TOOL_WEAK otError otPlatInfraIfSendIcmp6Nd(otInstance *, uint32_t, const otIp6Address *, const uint8_t *, uint16_t)
{
return OT_ERROR_FAILED;
}
OT_TOOL_WEAK otError otPlatInfraIfDiscoverNat64Prefix(uint32_t) { return OT_ERROR_FAILED; }
OT_TOOL_WEAK otError otPlatInfraIfDiscoverNat64Prefix(otInstance *, uint32_t) { return OT_ERROR_FAILED; }
#if OPENTHREAD_CONFIG_BORDER_ROUTING_DHCP6_PD_ENABLE && OPENTHREAD_CONFIG_BORDER_ROUTING_DHCP6_PD_CLIENT_ENABLE
+5 -2
View File
@@ -287,14 +287,16 @@ uint32_t otPlatAlarmMilliGetNow(void) { return sNow; }
//---------------------------------------------------------------------------------------------------------------------
// otPlatInfraIf
bool otPlatInfraIfHasAddress(uint32_t aInfraIfIndex, const otIp6Address *aAddress)
bool otPlatInfraIfHasAddress(otInstance *aInstance, uint32_t aInfraIfIndex, const otIp6Address *aAddress)
{
VerifyOrQuit(aInstance == sInstance);
VerifyOrQuit(aInfraIfIndex == kInfraIfIndex);
return AsCoreType(aAddress) == sInfraIfAddress;
}
otError otPlatInfraIfSendIcmp6Nd(uint32_t aInfraIfIndex,
otError otPlatInfraIfSendIcmp6Nd(otInstance *aInstance,
uint32_t aInfraIfIndex,
const otIp6Address *aDestAddress,
const uint8_t *aBuffer,
uint16_t aBufferLength)
@@ -305,6 +307,7 @@ otError otPlatInfraIfSendIcmp6Nd(uint32_t aInfraIfIndex,
Log("otPlatInfraIfSendIcmp6Nd(aDestAddr: %s, aBufferLength:%u)", AsCoreType(aDestAddress).ToString().AsCString(),
aBufferLength);
VerifyOrQuit(aInstance == sInstance);
VerifyOrQuit(aInfraIfIndex == kInfraIfIndex);
packet.Init(aBuffer, aBufferLength);