From d2d644d470193ad37871431fce38666ef44bcce1 Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Wed, 9 Jul 2025 13:16:37 -0700 Subject: [PATCH] [mdns] change `SetEnabled()` to be idempotent (#11690) This commit changes the `SetEnabled()` API to return `kErrorNone` when the component is already in the requested state (enabled or disabled). Previously, the method would return `kErrorAlready` in this scenario. Making this API idempotent simplifies caller logic, as they no longer need to handle the `kErrorAlready` case. --- include/openthread/instance.h | 2 +- include/openthread/mdns.h | 2 +- src/core/net/mdns.cpp | 2 +- src/core/net/mdns.hpp | 1 - 4 files changed, 3 insertions(+), 4 deletions(-) diff --git a/include/openthread/instance.h b/include/openthread/instance.h index 364a590cb..b5e220323 100644 --- a/include/openthread/instance.h +++ b/include/openthread/instance.h @@ -52,7 +52,7 @@ extern "C" { * * @note This number versions both OpenThread platform and user APIs. */ -#define OPENTHREAD_API_VERSION (518) +#define OPENTHREAD_API_VERSION (519) /** * @addtogroup api-instance diff --git a/include/openthread/mdns.h b/include/openthread/mdns.h index 481bf20fb..b3795367e 100644 --- a/include/openthread/mdns.h +++ b/include/openthread/mdns.h @@ -170,7 +170,7 @@ typedef struct otMdnsLocalHostAddress * @param[in] aInfraIfIndex The network interface index for mDNS operation. Value is ignored when disabling * * @retval OT_ERROR_NONE Enabled or disabled the mDNS module successfully. - * @retval OT_ERROR_ALREADY mDNS is already enabled on an enable request or is already disabled on a disable request. + * @retval OT_ERROR_FAILED Failed to enable/disable mDNS. */ otError otMdnsSetEnabled(otInstance *aInstance, bool aEnable, uint32_t aInfraIfIndex); diff --git a/src/core/net/mdns.cpp b/src/core/net/mdns.cpp index 10b286d9b..7d9eacbfb 100644 --- a/src/core/net/mdns.cpp +++ b/src/core/net/mdns.cpp @@ -119,7 +119,7 @@ Error Core::SetEnabled(bool aEnable, uint32_t aInfraIfIndex, Requester aRequeste mAutoEnable = false; } - VerifyOrExit(aEnable != mIsEnabled, error = kErrorAlready); + VerifyOrExit(aEnable != mIsEnabled); mIsEnabled = aEnable; mInfraIfIndex = aInfraIfIndex; diff --git a/src/core/net/mdns.hpp b/src/core/net/mdns.hpp index 2b574a9f3..c78af1224 100644 --- a/src/core/net/mdns.hpp +++ b/src/core/net/mdns.hpp @@ -175,7 +175,6 @@ public: * @param[in] aInfraIfIndex The network interface index for mDNS operation. Value is ignored when disabling. * * @retval kErrorNone Enabled or disabled the mDNS module successfully. - * @retval kErrorAlready mDNS is already enabled on an enable request, or is already disabled on a disable request. * @retval kErrorFailed Failed to enable/disable mDNS. */ Error SetEnabled(bool aEnable, uint32_t aInfraIfIndex)