From 5a82d90e4df891d06dfb649d7674aa70a019bea5 Mon Sep 17 00:00:00 2001 From: Jiacheng Guo Date: Sun, 22 Mar 2020 06:40:14 +0800 Subject: [PATCH] [netif] enhance return value of adding external addresses (#4693) This commit changes the return value of subscribing a pre-defined address when it's already subscribed. Now returns OT_ERROR_ALREADY instead of OT_ERROR_INVALID_ARGS. --- src/core/net/netif.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/core/net/netif.cpp b/src/core/net/netif.cpp index 9f6633ee7..b72ac1a06 100644 --- a/src/core/net/netif.cpp +++ b/src/core/net/netif.cpp @@ -363,6 +363,8 @@ otError Netif::SubscribeExternalMulticast(const Address &aAddress) NetifMulticastAddress &linkLocalAllRoutersAddress = static_cast( const_cast(kLinkLocalAllRoutersMulticastAddress)); + VerifyOrExit(!IsMulticastSubscribed(aAddress), error = OT_ERROR_ALREADY); + // Check that the address is not one of the fixed addresses: // LinkLocalAllRouters -> RealmLocalAllRouters -> LinkLocalAllNodes // -> RealmLocalAllNodes -> RealmLocalAllMpl. @@ -372,8 +374,6 @@ otError Netif::SubscribeExternalMulticast(const Address &aAddress) VerifyOrExit(cur->GetAddress() != aAddress, error = OT_ERROR_INVALID_ARGS); } - VerifyOrExit(!IsMulticastSubscribed(aAddress), error = OT_ERROR_ALREADY); - for (entry = &mExtMulticastAddresses[0]; entry < OT_ARRAY_END(mExtMulticastAddresses); entry++) { if (!entry->IsInUse()) @@ -482,14 +482,12 @@ otError Netif::AddExternalUnicastAddress(const NetifUnicastAddress &aAddress) otError error = OT_ERROR_NONE; NetifUnicastAddress *entry; - VerifyOrExit(!aAddress.GetAddress().IsLinkLocal(), error = OT_ERROR_INVALID_ARGS); - for (entry = mUnicastAddresses.GetHead(); entry; entry = entry->GetNext()) { if (entry->GetAddress() == aAddress.GetAddress()) { VerifyOrExit((entry >= &mExtUnicastAddresses[0]) && (entry < OT_ARRAY_END(mExtUnicastAddresses)), - error = OT_ERROR_INVALID_ARGS); + error = OT_ERROR_ALREADY); entry->mPrefixLength = aAddress.mPrefixLength; entry->mPreferred = aAddress.mPreferred; @@ -498,6 +496,8 @@ otError Netif::AddExternalUnicastAddress(const NetifUnicastAddress &aAddress) } } + VerifyOrExit(!aAddress.GetAddress().IsLinkLocal(), error = OT_ERROR_INVALID_ARGS); + for (entry = &mExtUnicastAddresses[0]; entry < OT_ARRAY_END(mExtUnicastAddresses); entry++) { if (!entry->IsInUse())