mirror of
https://github.com/espressif/openthread.git
synced 2026-09-14 13:10:08 +00:00
Apply realm-local scope to mesh-local addresses for source address selection. (#1000)
This commit is contained in:
@@ -897,11 +897,13 @@ typedef struct otBufferInfo
|
|||||||
*/
|
*/
|
||||||
typedef struct otNetifAddress
|
typedef struct otNetifAddress
|
||||||
{
|
{
|
||||||
otIp6Address mAddress; ///< The IPv6 unicast address.
|
otIp6Address mAddress; ///< The IPv6 unicast address.
|
||||||
uint32_t mPreferredLifetime; ///< The Preferred Lifetime.
|
uint32_t mPreferredLifetime; ///< The Preferred Lifetime.
|
||||||
uint32_t mValidLifetime; ///< The Valid lifetime.
|
uint32_t mValidLifetime; ///< The Valid lifetime.
|
||||||
uint8_t mPrefixLength; ///< The Prefix length.
|
uint8_t mPrefixLength; ///< The Prefix length.
|
||||||
struct otNetifAddress *mNext; ///< A pointer to the next network interface address.
|
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;
|
} otNetifAddress;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -993,18 +993,18 @@ const NetifUnicastAddress *Ip6::SelectSourceAddress(MessageInfo &aMessageInfo)
|
|||||||
rvalIface = candidateId;
|
rvalIface = candidateId;
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
else if (candidateAddr->GetScope() < rvalAddr->GetAddress().GetScope())
|
else if (addr->GetScope() < rvalAddr->GetScope())
|
||||||
{
|
{
|
||||||
// Rule 2: Prefer appropriate scope
|
// Rule 2: Prefer appropriate scope
|
||||||
if (candidateAddr->GetScope() >= destination->GetScope())
|
if (addr->GetScope() >= destination->GetScope())
|
||||||
{
|
{
|
||||||
rvalAddr = addr;
|
rvalAddr = addr;
|
||||||
rvalIface = candidateId;
|
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;
|
rvalAddr = addr;
|
||||||
rvalIface = candidateId;
|
rvalIface = candidateId;
|
||||||
|
|||||||
@@ -100,6 +100,16 @@ public:
|
|||||||
*/
|
*/
|
||||||
Address &GetAddress(void) { return *static_cast<Address *>(&mAddress); }
|
Address &GetAddress(void) { return *static_cast<Address *>(&mAddress); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method returns the IPv6 scope value.
|
||||||
|
*
|
||||||
|
* @returns The IPv6 scope value.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
uint8_t GetScope(void) const {
|
||||||
|
return mScopeOverrideValid ? static_cast<uint8_t>(mScopeOverride) : GetAddress().GetScope();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method returns the next unicast address assigned to the interface.
|
* This method returns the next unicast address assigned to the interface.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -105,12 +105,16 @@ Mle::Mle(ThreadNetif &aThreadNetif) :
|
|||||||
mLeaderAloc.mPrefixLength = 128;
|
mLeaderAloc.mPrefixLength = 128;
|
||||||
mLeaderAloc.mPreferredLifetime = 0xffffffff;
|
mLeaderAloc.mPreferredLifetime = 0xffffffff;
|
||||||
mLeaderAloc.mValidLifetime = 0xffffffff;
|
mLeaderAloc.mValidLifetime = 0xffffffff;
|
||||||
|
mLeaderAloc.mScopeOverride = Ip6::Address::kRealmLocalScope;
|
||||||
|
mLeaderAloc.mScopeOverrideValid = true;
|
||||||
|
|
||||||
// initialize Mesh Local Prefix
|
// initialize Mesh Local Prefix
|
||||||
mMeshLocal64.GetAddress().mFields.m8[0] = 0xfd;
|
mMeshLocal64.GetAddress().mFields.m8[0] = 0xfd;
|
||||||
memcpy(mMeshLocal64.GetAddress().mFields.m8 + 1, mMac.GetExtendedPanId(), 5);
|
memcpy(mMeshLocal64.GetAddress().mFields.m8 + 1, mMac.GetExtendedPanId(), 5);
|
||||||
mMeshLocal64.GetAddress().mFields.m8[6] = 0x00;
|
mMeshLocal64.GetAddress().mFields.m8[6] = 0x00;
|
||||||
mMeshLocal64.GetAddress().mFields.m8[7] = 0x00;
|
mMeshLocal64.GetAddress().mFields.m8[7] = 0x00;
|
||||||
|
mMeshLocal64.mScopeOverride = Ip6::Address::kRealmLocalScope;
|
||||||
|
mMeshLocal64.mScopeOverrideValid = true;
|
||||||
|
|
||||||
// mesh-local 64
|
// mesh-local 64
|
||||||
for (int i = 8; i < 16; i++)
|
for (int i = 8; i < 16; i++)
|
||||||
@@ -130,6 +134,8 @@ Mle::Mle(ThreadNetif &aThreadNetif) :
|
|||||||
mMeshLocal16.mPrefixLength = 64;
|
mMeshLocal16.mPrefixLength = 64;
|
||||||
mMeshLocal16.mPreferredLifetime = 0xffffffff;
|
mMeshLocal16.mPreferredLifetime = 0xffffffff;
|
||||||
mMeshLocal16.mValidLifetime = 0xffffffff;
|
mMeshLocal16.mValidLifetime = 0xffffffff;
|
||||||
|
mMeshLocal16.mScopeOverride = Ip6::Address::kRealmLocalScope;
|
||||||
|
mMeshLocal16.mScopeOverrideValid = true;
|
||||||
|
|
||||||
// Store RLOC address reference in MPL module.
|
// Store RLOC address reference in MPL module.
|
||||||
mNetif.GetIp6().mMpl.SetMatchingAddress(mMeshLocal16.GetAddress());
|
mNetif.GetIp6().mMpl.SetMatchingAddress(mMeshLocal16.GetAddress());
|
||||||
|
|||||||
Reference in New Issue
Block a user