From c2a10ec44635f99b070fc4ca0b476ce23d5bab7f Mon Sep 17 00:00:00 2001 From: Jonathan Hui Date: Thu, 24 Jan 2019 09:04:13 -0800 Subject: [PATCH] [ip6] only allow external mcast addrs when iface is up (#3504) --- include/openthread/ip6.h | 11 ++++++----- src/core/net/netif.cpp | 2 ++ src/core/net/netif.hpp | 9 +++++---- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/include/openthread/ip6.h b/include/openthread/ip6.h index d5dc4ed36..f7cc2f292 100644 --- a/include/openthread/ip6.h +++ b/include/openthread/ip6.h @@ -252,11 +252,12 @@ OTAPI const otNetifAddress *OTCALL otIp6GetUnicastAddresses(otInstance *aInstanc * @param[in] aInstance A pointer to an OpenThread instance. * @param[in] aAddress A pointer to an IP Address. * - * @retval OT_ERROR_NONE Successfully subscribed to the Network Interface Multicast Address. - * @retval OT_ERROR_ALREADY The multicast address is already subscribed. - * @retval OT_ERROR_INVALID_ARGS The IP Address indicated by @p aAddress is invalid address. - * @retval OT_ERROR_NO_BUFS The Network Interface is already storing the maximum allowed external multicast - * addresses. + * @retval OT_ERROR_NONE Successfully subscribed to the Network Interface Multicast Address. + * @retval OT_ERROR_ALREADY The multicast address is already subscribed. + * @retval OT_ERROR_INVALID_ARGS The IP Address indicated by @p aAddress is invalid address. + * @retval OT_ERROR_INVALID_STATE The Network Interface is not up. + * @retval OT_ERROR_NO_BUFS The Network Interface is already storing the maximum allowed external multicast + * addresses. * */ otError otIp6SubscribeMulticastAddress(otInstance *aInstance, const otIp6Address *aAddress); diff --git a/src/core/net/netif.cpp b/src/core/net/netif.cpp index 17da7915e..f4d406a5c 100644 --- a/src/core/net/netif.cpp +++ b/src/core/net/netif.cpp @@ -334,6 +334,8 @@ otError Netif::SubscribeExternalMulticast(const Address &aAddress) NetifMulticastAddress *entry; size_t num = OT_ARRAY_LENGTH(mExtMulticastAddresses); + VerifyOrExit(mMulticastAddresses != NULL, error = OT_ERROR_INVALID_STATE); + if (IsMulticastSubscribed(aAddress)) { ExitNow(error = OT_ERROR_ALREADY); diff --git a/src/core/net/netif.hpp b/src/core/net/netif.hpp index ffb23c614..a7e436e83 100644 --- a/src/core/net/netif.hpp +++ b/src/core/net/netif.hpp @@ -367,10 +367,11 @@ public: * * @param[in] aAddress A reference to the multicast address. * - * @retval OT_ERROR_NONE Successfully subscribed to @p aAddress. - * @retval OT_ERROR_ALREADY The multicast address is already subscribed. - * @retval OT_ERROR_INVALID_ARGS The address indicated by @p aAddress is an internal multicast address. - * @retval OT_ERROR_NO_BUFS The maximum number of allowed external multicast addresses are already added. + * @retval OT_ERROR_NONE Successfully subscribed to @p aAddress. + * @retval OT_ERROR_ALREADY The multicast address is already subscribed. + * @retval OT_ERROR_INVALID_ARGS The address indicated by @p aAddress is an internal multicast address. + * @retval OT_ERROR_INVALID_STATE The Network Interface is not up. + * @retval OT_ERROR_NO_BUFS The maximum number of allowed external multicast addresses are already added. * */ otError SubscribeExternalMulticast(const Address &aAddress);