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