Skip to content

Commit

Permalink
openthread: enable SRP Client auto host address mode (#19981)
Browse files Browse the repository at this point in the history
This commit enables "auto host address mode" in SRP client. When
enabled, host IPv6 addresses are automatically set by SRP client using
all the unicast addresses on Thread netif excluding the link-local and
mesh-local addresses. If there is no valid address, then Mesh Local
EID address is added. The SRP client will automatically re-register
when/if addresses on Thread netif are updated (e.g., new addresses are
added or existing addresses are removed).
  • Loading branch information
jwhui authored and pull[bot] committed Jul 24, 2023
1 parent fc9bf1d commit 8289953
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ void GenericThreadStackManagerImpl_OpenThread<ImplClass>::_OnPlatformEvent(const
{
if (event->Type == DeviceEventType::kThreadStateChange)
{
#if CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT
#if CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT && (OPENTHREAD_API_VERSION < 218)
if (event->ThreadStateChange.AddressChanged)
{
const otSrpClientHostInfo * hostInfo = otSrpClientGetHostInfo(Impl()->OTInstance());
Expand Down Expand Up @@ -2301,7 +2301,9 @@ template <class ImplClass>
CHIP_ERROR GenericThreadStackManagerImpl_OpenThread<ImplClass>::_SetupSrpHost(const char * aHostName)
{
CHIP_ERROR error = CHIP_NO_ERROR;
#if OPENTHREAD_API_VERSION < 218
Inet::IPAddress hostAddress;
#endif

VerifyOrReturnError(mSrpClient.mIsInitialized, CHIP_ERROR_WELL_UNINITIALIZED);

Expand All @@ -2316,15 +2318,21 @@ CHIP_ERROR GenericThreadStackManagerImpl_OpenThread<ImplClass>::_SetupSrpHost(co
strcpy(mSrpClient.mHostName, aHostName);
error = MapOpenThreadError(otSrpClientSetHostName(mOTInst, mSrpClient.mHostName));
SuccessOrExit(error);

#if OPENTHREAD_API_VERSION >= 218
error = MapOpenThreadError(otSrpClientEnableAutoHostAddress(mOTInst));
#endif
}

#if OPENTHREAD_API_VERSION < 218
// Check if device has any external IPv6 assigned. If not, host will be set without IPv6 addresses
// and updated later on.
if (ThreadStackMgr().GetExternalIPv6Address(hostAddress) == CHIP_NO_ERROR)
{
memcpy(&mSrpClient.mHostAddress.mFields.m32, hostAddress.Addr, sizeof(hostAddress.Addr));
error = MapOpenThreadError(otSrpClientSetHostAddresses(mOTInst, &mSrpClient.mHostAddress, 1));
}
#endif

exit:
Impl()->UnlockThreadStack();
Expand Down

0 comments on commit 8289953

Please sign in to comment.