diff --git a/include/openthread/instance.h b/include/openthread/instance.h index cab6333a3..8eeb08f43 100644 --- a/include/openthread/instance.h +++ b/include/openthread/instance.h @@ -53,7 +53,7 @@ extern "C" { * @note This number versions both OpenThread platform and user APIs. * */ -#define OPENTHREAD_API_VERSION (393) +#define OPENTHREAD_API_VERSION (394) /** * @addtogroup api-instance diff --git a/include/openthread/ip6.h b/include/openthread/ip6.h index cb4d12491..7f54b7376 100644 --- a/include/openthread/ip6.h +++ b/include/openthread/ip6.h @@ -479,6 +479,7 @@ typedef struct otIp6AddressInfo uint8_t mPrefixLength; ///< The prefix length of mAddress if it is a unicast address. uint8_t mScope : 4; ///< The scope of this address. bool mPreferred : 1; ///< Whether this is a preferred address. + bool mMeshLocal : 1; ///< Whether this is a mesh-local unicast/anycast address. } otIp6AddressInfo; /** diff --git a/src/core/net/netif.cpp b/src/core/net/netif.cpp index 1b739afca..3e103312b 100644 --- a/src/core/net/netif.cpp +++ b/src/core/net/netif.cpp @@ -253,6 +253,7 @@ void Netif::SignalMulticastAddressChange(AddressEvent aEvent, const MulticastAdd info.mPrefixLength = kMulticastPrefixLength; info.mScope = aAddress.GetAddress().GetScope(); info.mPreferred = false; + info.mMeshLocal = false; mAddressCallback.Invoke(&info, aEvent); } @@ -427,6 +428,7 @@ void Netif::SignalUnicastAddressChange(AddressEvent aEvent, const UnicastAddress info.mPrefixLength = aAddress.mPrefixLength; info.mScope = aAddress.GetScope(); info.mPreferred = aAddress.mPreferred; + info.mMeshLocal = aAddress.mMeshLocal; mAddressCallback.Invoke(&info, aEvent); } @@ -539,12 +541,12 @@ void Netif::ApplyNewMeshLocalPrefix(void) //--------------------------------------------------------------------------------------------------------------------- // Netif::UnicastAddress -void Netif::UnicastAddress::InitAsThreadOrigin(bool aPreferred) +void Netif::UnicastAddress::InitAsThreadOrigin(void) { Clear(); mPrefixLength = NetworkPrefix::kLength; mAddressOrigin = kOriginThread; - mPreferred = aPreferred; + mPreferred = true; mValid = true; } diff --git a/src/core/net/netif.hpp b/src/core/net/netif.hpp index 663eb218e..a736df8e4 100644 --- a/src/core/net/netif.hpp +++ b/src/core/net/netif.hpp @@ -116,10 +116,8 @@ public: * Clears and initializes the unicast address as a preferred, valid, thread-origin address with * 64-bit prefix length. * - * @param[in] aPreferred Whether to initialize as a preferred address. - * */ - void InitAsThreadOrigin(bool aPreferred = false); + void InitAsThreadOrigin(void); /** * Clears and initializes the unicast address as a valid (but not preferred), thread-origin, diff --git a/src/core/thread/mle.cpp b/src/core/thread/mle.cpp index ef5fe7efb..7eeb25dca 100644 --- a/src/core/thread/mle.cpp +++ b/src/core/thread/mle.cpp @@ -123,7 +123,7 @@ Mle::Mle(Instance &aInstance) mParentCandidate.Clear(); ResetCounters(); - mLinkLocal64.InitAsThreadOrigin(/* aPreferred */ true); + mLinkLocal64.InitAsThreadOrigin(); mLinkLocal64.GetAddress().SetToLinkLocalAddress(Get().GetExtAddress()); mMeshLocal64.InitAsThreadOriginMeshLocal(); diff --git a/src/posix/platform/netif.cpp b/src/posix/platform/netif.cpp index 4db22bf6a..d3b302497 100644 --- a/src/posix/platform/netif.cpp +++ b/src/posix/platform/netif.cpp @@ -388,7 +388,7 @@ static void UpdateUnicastLinux(otInstance *aInstance, const otIp6AddressInfo &aA AddRtAttr(&req.nh, sizeof(req), IFA_LOCAL, aAddressInfo.mAddress, sizeof(*aAddressInfo.mAddress)); - if (!aAddressInfo.mPreferred) + if (!aAddressInfo.mPreferred || aAddressInfo.mMeshLocal) { struct ifa_cacheinfo cacheinfo; @@ -456,12 +456,13 @@ static void UpdateUnicast(otInstance *aInstance, const otIp6AddressInfo &aAddres ifr6.ifra_prefixmask.sin6_family = AF_INET6; ifr6.ifra_prefixmask.sin6_len = sizeof(ifr6.ifra_prefixmask); InitNetaskWithPrefixLength(&ifr6.ifra_prefixmask.sin6_addr, aAddressInfo.mPrefixLength); - ifr6.ifra_lifetime.ia6t_vltime = ND6_INFINITE_LIFETIME; - ifr6.ifra_lifetime.ia6t_pltime = ND6_INFINITE_LIFETIME; + ifr6.ifra_lifetime.ia6t_vltime = ND6_INFINITE_LIFETIME; + ifr6.ifra_lifetime.ia6t_pltime = ND6_INFINITE_LIFETIME; #if defined(__APPLE__) - ifr6.ifra_lifetime.ia6t_expire = ND6_INFINITE_LIFETIME; - ifr6.ifra_lifetime.ia6t_preferred = (aAddressInfo.mPreferred ? ND6_INFINITE_LIFETIME : 0); + ifr6.ifra_lifetime.ia6t_expire = ND6_INFINITE_LIFETIME; + ifr6.ifra_lifetime.ia6t_preferred = + (aAddressInfo.mPreferred && !aAddressInfo.mMeshLocal ? ND6_INFINITE_LIFETIME : 0); #endif rval = ioctl(sIpFd, aIsAdded ? SIOCAIFADDR_IN6 : SIOCDIFADDR_IN6, &ifr6);