diff --git a/include/openthread-types.h b/include/openthread-types.h index 5476aa125..92ba11e31 100644 --- a/include/openthread-types.h +++ b/include/openthread-types.h @@ -897,11 +897,13 @@ typedef struct otBufferInfo */ typedef struct otNetifAddress { - otIp6Address mAddress; ///< The IPv6 unicast address. - uint32_t mPreferredLifetime; ///< The Preferred Lifetime. - uint32_t mValidLifetime; ///< The Valid lifetime. - uint8_t mPrefixLength; ///< The Prefix length. - struct otNetifAddress *mNext; ///< A pointer to the next network interface address. + otIp6Address mAddress; ///< The IPv6 unicast address. + uint32_t mPreferredLifetime; ///< The Preferred Lifetime. + uint32_t mValidLifetime; ///< The Valid lifetime. + uint8_t mPrefixLength; ///< The Prefix length. + unsigned int mScopeOverride : 4; ///< The IPv6 scope of this address. + bool mScopeOverrideValid : 1; ///< TRUE if the mScopeOverride value is valid, FALSE othewrise. + struct otNetifAddress *mNext; ///< A pointer to the next network interface address. } otNetifAddress; /** diff --git a/src/core/net/ip6.cpp b/src/core/net/ip6.cpp index 94b9eb160..4ec4fc89a 100644 --- a/src/core/net/ip6.cpp +++ b/src/core/net/ip6.cpp @@ -993,18 +993,18 @@ const NetifUnicastAddress *Ip6::SelectSourceAddress(MessageInfo &aMessageInfo) rvalIface = candidateId; goto exit; } - else if (candidateAddr->GetScope() < rvalAddr->GetAddress().GetScope()) + else if (addr->GetScope() < rvalAddr->GetScope()) { // Rule 2: Prefer appropriate scope - if (candidateAddr->GetScope() >= destination->GetScope()) + if (addr->GetScope() >= destination->GetScope()) { rvalAddr = addr; rvalIface = candidateId; } } - else if (candidateAddr->GetScope() > rvalAddr->GetAddress().GetScope()) + else if (addr->GetScope() > rvalAddr->GetScope()) { - if (rvalAddr->GetAddress().GetScope() < destination->GetScope()) + if (rvalAddr->GetScope() < destination->GetScope()) { rvalAddr = addr; rvalIface = candidateId; diff --git a/src/core/net/netif.hpp b/src/core/net/netif.hpp index 42e0d8a16..b9ce732c0 100644 --- a/src/core/net/netif.hpp +++ b/src/core/net/netif.hpp @@ -100,6 +100,16 @@ public: */ Address &GetAddress(void) { return *static_cast
(&mAddress); } + /** + * This method returns the IPv6 scope value. + * + * @returns The IPv6 scope value. + * + */ + uint8_t GetScope(void) const { + return mScopeOverrideValid ? static_cast(mScopeOverride) : GetAddress().GetScope(); + } + /** * This method returns the next unicast address assigned to the interface. * diff --git a/src/core/thread/mle.cpp b/src/core/thread/mle.cpp index 10a1e2eda..43fc51cb9 100644 --- a/src/core/thread/mle.cpp +++ b/src/core/thread/mle.cpp @@ -105,12 +105,16 @@ Mle::Mle(ThreadNetif &aThreadNetif) : mLeaderAloc.mPrefixLength = 128; mLeaderAloc.mPreferredLifetime = 0xffffffff; mLeaderAloc.mValidLifetime = 0xffffffff; + mLeaderAloc.mScopeOverride = Ip6::Address::kRealmLocalScope; + mLeaderAloc.mScopeOverrideValid = true; // initialize Mesh Local Prefix mMeshLocal64.GetAddress().mFields.m8[0] = 0xfd; memcpy(mMeshLocal64.GetAddress().mFields.m8 + 1, mMac.GetExtendedPanId(), 5); mMeshLocal64.GetAddress().mFields.m8[6] = 0x00; mMeshLocal64.GetAddress().mFields.m8[7] = 0x00; + mMeshLocal64.mScopeOverride = Ip6::Address::kRealmLocalScope; + mMeshLocal64.mScopeOverrideValid = true; // mesh-local 64 for (int i = 8; i < 16; i++) @@ -130,6 +134,8 @@ Mle::Mle(ThreadNetif &aThreadNetif) : mMeshLocal16.mPrefixLength = 64; mMeshLocal16.mPreferredLifetime = 0xffffffff; mMeshLocal16.mValidLifetime = 0xffffffff; + mMeshLocal16.mScopeOverride = Ip6::Address::kRealmLocalScope; + mMeshLocal16.mScopeOverrideValid = true; // Store RLOC address reference in MPL module. mNetif.GetIp6().mMpl.SetMatchingAddress(mMeshLocal16.GetAddress());