[posix] allow custom implementation of otPlatInfraIfDiscoverNat64Prefix (#10566)

This commit moves the macro guard
`OPENTHREAD_POSIX_CONFIG_INFRA_IF_ENABLE` in the code so that it can
allow custom implementation of `otPlatInfraIfDiscoverNat64Prefix` when
`OPENTHREAD_POSIX_CONFIG_INFRA_IF_ENABLE` is disabled.

The use case is on Android platform. We'll not let `ot-daemon`
proactively discover the prefixes by DNS. Instead, System Server will
do the discovery of NAT64 prefix on AIL and it will notify `ot-daemon`
when the AIL NAT64 prefix is discovered/removed.
This commit is contained in:
Handa Wang
2024-08-05 16:17:11 -06:00
committed by GitHub
parent 18365adcf5
commit 05d6bd6eb3
4 changed files with 27 additions and 9 deletions
+4
View File
@@ -115,7 +115,11 @@ Error InfraIf::DiscoverNat64Prefix(void) const
{
OT_ASSERT(mInitialized);
#if OPENTHREAD_CONFIG_NAT64_BORDER_ROUTING_ENABLE
return otPlatInfraIfDiscoverNat64Prefix(mIfIndex);
#else
return kErrorNotImplemented;
#endif
}
void InfraIf::DiscoverNat64PrefixDone(uint32_t aIfIndex, const Ip6::Prefix &aPrefix)
+12 -8
View File
@@ -101,16 +101,12 @@ otError otPlatInfraIfSendIcmp6Nd(uint32_t aInfraIfIndex,
}
#endif
#if OPENTHREAD_CONFIG_NAT64_BORDER_ROUTING_ENABLE && OPENTHREAD_POSIX_CONFIG_NAT64_AIL_PREFIX_ENABLE
otError otPlatInfraIfDiscoverNat64Prefix(uint32_t aInfraIfIndex)
{
OT_UNUSED_VARIABLE(aInfraIfIndex);
#if OPENTHREAD_POSIX_CONFIG_NAT64_AIL_PREFIX_ENABLE
return ot::Posix::InfraNetif::Get().DiscoverNat64Prefix(aInfraIfIndex);
#else
return OT_ERROR_DROP;
#endif
}
#endif
bool otSysInfraIfIsRunning(void) { return ot::Posix::InfraNetif::Get().IsRunning(); }
@@ -667,12 +663,13 @@ exit:
}
#endif // OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE
#if OPENTHREAD_POSIX_CONFIG_NAT64_AIL_PREFIX_ENABLE
#if OPENTHREAD_CONFIG_NAT64_BORDER_ROUTING_ENABLE && OPENTHREAD_POSIX_CONFIG_NAT64_AIL_PREFIX_ENABLE
const char InfraNetif::kWellKnownIpv4OnlyName[] = "ipv4only.arpa";
const otIp4Address InfraNetif::kWellKnownIpv4OnlyAddress1 = {{{192, 0, 0, 170}}};
const otIp4Address InfraNetif::kWellKnownIpv4OnlyAddress2 = {{{192, 0, 0, 171}}};
const uint8_t InfraNetif::kValidNat64PrefixLength[] = {96, 64, 56, 48, 40, 32};
#ifdef __linux__
void InfraNetif::DiscoverNat64PrefixDone(union sigval sv)
{
struct gaicb *req = (struct gaicb *)sv.sival_ptr;
@@ -750,9 +747,11 @@ exit:
freeaddrinfo((struct addrinfo *)req->ar_request);
free(req);
}
#endif // #ifdef __linux__
otError InfraNetif::DiscoverNat64Prefix(uint32_t aInfraIfIndex)
{
#ifdef __linux__
otError error = OT_ERROR_NONE;
struct addrinfo *hints = nullptr;
struct gaicb *reqs[1] = {nullptr};
@@ -795,8 +794,13 @@ exit:
free(reqs[0]);
}
return error;
#else
OT_UNUSED_VARIABLE(aInfraIfIndex);
return OT_ERROR_NOT_IMPLEMENTED;
#endif // #ifdef __linux__
}
#endif // OPENTHREAD_POSIX_CONFIG_NAT64_AIL_PREFIX_ENABLE
#endif // OPENTHREAD_CONFIG_NAT64_BORDER_ROUTING_ENABLE && OPENTHREAD_POSIX_CONFIG_NAT64_AIL_PREFIX_ENABLE
#if OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE
void InfraNetif::SetInfraNetifIcmp6SocketForBorderRouting(int aIcmp6Socket)
+9 -1
View File
@@ -174,6 +174,7 @@ public:
const uint8_t *aBuffer,
uint16_t aBufferLength);
#if OPENTHREAD_CONFIG_NAT64_BORDER_ROUTING_ENABLE && OPENTHREAD_POSIX_CONFIG_NAT64_AIL_PREFIX_ENABLE
/**
* Sends an asynchronous address lookup for the well-known host name "ipv4only.arpa"
* to discover the NAT64 prefix.
@@ -185,6 +186,7 @@ public:
*
*/
otError DiscoverNat64Prefix(uint32_t aInfraIfIndex);
#endif
/**
* Gets the infrastructure network interface name.
@@ -240,12 +242,18 @@ private:
MulticastRoutingManager mMulticastRoutingManager;
#endif
bool HasLinkLocalAddress(void) const;
#ifdef __linux__
void ReceiveNetLinkMessage(void);
#endif
bool HasLinkLocalAddress(void) const;
#if OPENTHREAD_CONFIG_NAT64_BORDER_ROUTING_ENABLE && OPENTHREAD_POSIX_CONFIG_NAT64_AIL_PREFIX_ENABLE
#ifdef __linux__
static void DiscoverNat64PrefixDone(union sigval sv);
#endif // #ifdef __linux__
#endif
#if OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE
void SetInfraNetifIcmp6SocketForBorderRouting(int aIcmp6Socket);
void ReceiveIcmp6Message(void);
@@ -65,6 +65,8 @@
#define OPENTHREAD_POSIX_CONFIG_SPINEL_HDLC_INTERFACE_ENABLE 1
#define OPENTHREAD_POSIX_CONFIG_NAT64_AIL_PREFIX_ENABLE 1
// Disabled explicitly on posix `toranj` to validate the build with this config
#define OPENTHREAD_CONFIG_BORDER_ROUTING_USE_HEAP_ENABLE 0