mirror of
https://github.com/espressif/openthread.git
synced 2026-07-27 06:17:47 +00:00
[ip6-address] add GetLocator() and SetLocator() (#4707)
This commit is contained in:
@@ -534,7 +534,7 @@ void BorderAgent::HandleRelayTransmit(const Coap::Message &aMessage)
|
||||
messageInfo.SetSockAddr(Get<Mle::MleRouter>().GetMeshLocal16());
|
||||
messageInfo.SetPeerPort(kCoapUdpPort);
|
||||
messageInfo.SetPeerAddr(Get<Mle::MleRouter>().GetMeshLocal16());
|
||||
messageInfo.GetPeerAddr().mFields.m16[7] = HostSwap16(joinerRouterRloc);
|
||||
messageInfo.GetPeerAddr().SetLocator(joinerRouterRloc);
|
||||
|
||||
SuccessOrExit(error = Get<Coap::Coap>().SendMessage(*message, messageInfo));
|
||||
|
||||
|
||||
@@ -1041,7 +1041,7 @@ otError Commissioner::SendRelayTransmit(Message &aMessage, const Ip6::MessageInf
|
||||
aMessage.CopyTo(0, offset, aMessage.GetLength(), *message);
|
||||
|
||||
messageInfo.SetPeerAddr(Get<Mle::MleRouter>().GetMeshLocal16());
|
||||
messageInfo.GetPeerAddr().mFields.m16[7] = HostSwap16(mJoinerRloc);
|
||||
messageInfo.GetPeerAddr().SetLocator(mJoinerRloc);
|
||||
messageInfo.SetPeerPort(kCoapUdpPort);
|
||||
|
||||
SuccessOrExit(error = Get<Coap::Coap>().SendMessage(*message, messageInfo));
|
||||
|
||||
@@ -162,7 +162,7 @@ void JoinerRouter::HandleUdpReceive(Message &aMessage, const Ip6::MessageInfo &a
|
||||
|
||||
messageInfo.SetSockAddr(Get<Mle::MleRouter>().GetMeshLocal16());
|
||||
messageInfo.SetPeerAddr(Get<Mle::MleRouter>().GetMeshLocal16());
|
||||
messageInfo.GetPeerAddr().mFields.m16[7] = HostSwap16(borderAgentRloc);
|
||||
messageInfo.GetPeerAddr().SetLocator(borderAgentRloc);
|
||||
messageInfo.SetPeerPort(kCoapUdpPort);
|
||||
|
||||
SuccessOrExit(error = Get<Coap::Coap>().SendMessage(*message, messageInfo));
|
||||
|
||||
@@ -93,7 +93,7 @@ void Leader::HandlePetition(Coap::Message &aMessage, const Ip6::MessageInfo &aMe
|
||||
}
|
||||
|
||||
data.mBorderAgentLocator.Init();
|
||||
data.mBorderAgentLocator.SetBorderAgentLocator(HostSwap16(aMessageInfo.GetPeerAddr().mFields.m16[7]));
|
||||
data.mBorderAgentLocator.SetBorderAgentLocator(aMessageInfo.GetPeerAddr().GetLocator());
|
||||
|
||||
data.mCommissionerSessionId.Init();
|
||||
data.mCommissionerSessionId.SetCommissionerSessionId(++mSessionId);
|
||||
@@ -190,7 +190,7 @@ void Leader::HandleKeepAlive(Coap::Message &aMessage, const Ip6::MessageInfo &aM
|
||||
}
|
||||
else
|
||||
{
|
||||
uint16_t rloc = HostSwap16(aMessageInfo.GetPeerAddr().mFields.m16[7]);
|
||||
uint16_t rloc = aMessageInfo.GetPeerAddr().GetLocator();
|
||||
|
||||
if (borderAgentLocator->GetBorderAgentLocator() != rloc)
|
||||
{
|
||||
|
||||
@@ -284,7 +284,7 @@ otError Dhcp6Client::Solicit(uint16_t aRloc16)
|
||||
messageInfo.GetPeerAddr().mFields.m16[4] = HostSwap16(0x0000);
|
||||
messageInfo.GetPeerAddr().mFields.m16[5] = HostSwap16(0x00ff);
|
||||
messageInfo.GetPeerAddr().mFields.m16[6] = HostSwap16(0xfe00);
|
||||
messageInfo.GetPeerAddr().mFields.m16[7] = HostSwap16(aRloc16);
|
||||
messageInfo.GetPeerAddr().SetLocator(aRloc16);
|
||||
#endif
|
||||
messageInfo.SetSockAddr(Get<Mle::MleRouter>().GetMeshLocal16());
|
||||
messageInfo.mPeerPort = kDhcpServerPort;
|
||||
|
||||
@@ -39,7 +39,6 @@
|
||||
#include "common/encoding.hpp"
|
||||
#include "common/instance.hpp"
|
||||
|
||||
using ot::Encoding::BigEndian::HostSwap16;
|
||||
using ot::Encoding::BigEndian::HostSwap32;
|
||||
|
||||
namespace ot {
|
||||
|
||||
@@ -38,10 +38,13 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "common/encoding.hpp"
|
||||
#include "common/string.hpp"
|
||||
#include "mac/mac_types.hpp"
|
||||
#include "thread/mle_types.hpp"
|
||||
|
||||
using ot::Encoding::BigEndian::HostSwap16;
|
||||
|
||||
namespace ot {
|
||||
namespace Ip6 {
|
||||
|
||||
@@ -269,6 +272,24 @@ public:
|
||||
*/
|
||||
bool IsIidReserved(void) const;
|
||||
|
||||
/**
|
||||
* This method gets the IPv6 address locator.
|
||||
*
|
||||
* @returns RLOC16 or ALOC16.
|
||||
*
|
||||
*/
|
||||
uint16_t GetLocator(void) const { return HostSwap16(mFields.m16[7]); }
|
||||
|
||||
/**
|
||||
* This method sets the IPv6 address locator.
|
||||
*
|
||||
* This method only changes the last 2 bytes of the address and keeps the rest of the address as before.
|
||||
*
|
||||
* @param[in] aLocator RLOC16 or ALOC16.
|
||||
*
|
||||
*/
|
||||
void SetLocator(uint16_t aLocator) { mFields.m16[7] = HostSwap16(aLocator); }
|
||||
|
||||
/**
|
||||
* This method sets the IPv6 address prefix.
|
||||
*
|
||||
|
||||
@@ -288,7 +288,7 @@ otError Mpl::ProcessOption(Message &aMessage, const Address &aAddress, bool aIsO
|
||||
if (option.GetSeedIdLength() == OptionMpl::kSeedIdLength0)
|
||||
{
|
||||
// Retrieve MPL Seed Id from the IPv6 Source Address.
|
||||
option.SetSeedId(HostSwap16(aAddress.mFields.m16[7]));
|
||||
option.SetSeedId(aAddress.GetLocator());
|
||||
}
|
||||
|
||||
// Check if the MPL Data Message is new.
|
||||
|
||||
@@ -505,8 +505,8 @@ void AddressResolver::HandleAddressNotification(Coap::Message &aMessage, const I
|
||||
ExitNow();
|
||||
}
|
||||
|
||||
otLogInfoArp("Received address notification from 0x%04x for %s to 0x%04x",
|
||||
HostSwap16(aMessageInfo.GetPeerAddr().mFields.m16[7]), target.ToString().AsCString(), rloc16);
|
||||
otLogInfoArp("Received address notification from 0x%04x for %s to 0x%04x", aMessageInfo.GetPeerAddr().GetLocator(),
|
||||
target.ToString().AsCString(), rloc16);
|
||||
|
||||
for (int i = 0; i < kCacheEntries; i++)
|
||||
{
|
||||
@@ -702,8 +702,8 @@ void AddressResolver::HandleAddressQuery(Coap::Message &aMessage, const Ip6::Mes
|
||||
|
||||
SuccessOrExit(Tlv::ReadTlv(aMessage, ThreadTlv::kTarget, &target, sizeof(target)));
|
||||
|
||||
otLogInfoArp("Received address query from 0x%04x for target %s",
|
||||
HostSwap16(aMessageInfo.GetPeerAddr().mFields.m16[7]), target.ToString().AsCString());
|
||||
otLogInfoArp("Received address query from 0x%04x for target %s", aMessageInfo.GetPeerAddr().GetLocator(),
|
||||
target.ToString().AsCString());
|
||||
|
||||
if (Get<ThreadNetif>().IsUnicastAddress(target))
|
||||
{
|
||||
|
||||
@@ -70,7 +70,7 @@ otError Lowpan::ComputeIid(const Mac::Address &aMacAddr, const Context &aContext
|
||||
aIpAddress.mFields.m16[4] = HostSwap16(0x0000);
|
||||
aIpAddress.mFields.m16[5] = HostSwap16(0x00ff);
|
||||
aIpAddress.mFields.m16[6] = HostSwap16(0xfe00);
|
||||
aIpAddress.mFields.m16[7] = HostSwap16(aMacAddr.GetShort());
|
||||
aIpAddress.SetLocator(aMacAddr.GetShort());
|
||||
break;
|
||||
|
||||
case Mac::Address::kTypeExtended:
|
||||
@@ -113,7 +113,7 @@ otError Lowpan::CompressSourceIid(const Mac::Address &aMacAddr,
|
||||
}
|
||||
else
|
||||
{
|
||||
tmp.SetShort(HostSwap16(aIpAddr.mFields.m16[7]));
|
||||
tmp.SetShort(aIpAddr.GetLocator());
|
||||
ComputeIid(tmp, aContext, ipaddr);
|
||||
|
||||
if (memcmp(ipaddr.GetIid(), aIpAddr.GetIid(), Ip6::Address::kInterfaceIdentifierSize) == 0)
|
||||
@@ -156,7 +156,7 @@ otError Lowpan::CompressDestinationIid(const Mac::Address &aMacAddr,
|
||||
}
|
||||
else
|
||||
{
|
||||
tmp.SetShort(HostSwap16(aIpAddr.mFields.m16[7]));
|
||||
tmp.SetShort(aIpAddr.GetLocator());
|
||||
ComputeIid(tmp, aContext, ipaddr);
|
||||
|
||||
if (memcmp(ipaddr.GetIid(), aIpAddr.GetIid(), Ip6::Address::kInterfaceIdentifierSize) == 0)
|
||||
|
||||
@@ -377,11 +377,11 @@ void MeshForwarder::GetMacDestinationAddress(const Ip6::Address &aIp6Addr, Mac::
|
||||
aIp6Addr.mFields.m16[4] == HostSwap16(0x0000) && aIp6Addr.mFields.m16[5] == HostSwap16(0x00ff) &&
|
||||
aIp6Addr.mFields.m16[6] == HostSwap16(0xfe00))
|
||||
{
|
||||
aMacAddr.SetShort(HostSwap16(aIp6Addr.mFields.m16[7]));
|
||||
aMacAddr.SetShort(aIp6Addr.GetLocator());
|
||||
}
|
||||
else if (Get<Mle::MleRouter>().IsRoutingLocator(aIp6Addr))
|
||||
{
|
||||
aMacAddr.SetShort(HostSwap16(aIp6Addr.mFields.m16[7]));
|
||||
aMacAddr.SetShort(aIp6Addr.GetLocator());
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -379,13 +379,13 @@ otError MeshForwarder::UpdateIp6RouteFtd(Ip6::Header &ip6Header)
|
||||
|
||||
if (mle.IsRoutingLocator(ip6Header.GetDestination()))
|
||||
{
|
||||
uint16_t rloc16 = HostSwap16(ip6Header.GetDestination().mFields.m16[7]);
|
||||
uint16_t rloc16 = ip6Header.GetDestination().GetLocator();
|
||||
VerifyOrExit(mle.IsRouterIdValid(Mle::Mle::RouterIdFromRloc16(rloc16)), error = OT_ERROR_DROP);
|
||||
mMeshDest = rloc16;
|
||||
}
|
||||
else if (mle.IsAnycastLocator(ip6Header.GetDestination()))
|
||||
{
|
||||
uint16_t aloc16 = HostSwap16(ip6Header.GetDestination().mFields.m16[7]);
|
||||
uint16_t aloc16 = ip6Header.GetDestination().GetLocator();
|
||||
|
||||
if (aloc16 == Mle::kAloc16Leader)
|
||||
{
|
||||
|
||||
+18
-18
@@ -147,12 +147,12 @@ Mle::Mle(Instance &aInstance)
|
||||
for (size_t i = 0; i < OT_ARRAY_LENGTH(mServiceAlocs); i++)
|
||||
{
|
||||
mServiceAlocs[i].Clear();
|
||||
mServiceAlocs[i].mPrefixLength = 64;
|
||||
mServiceAlocs[i].mPreferred = true;
|
||||
mServiceAlocs[i].mValid = true;
|
||||
mServiceAlocs[i].mScopeOverride = Ip6::Address::kRealmLocalScope;
|
||||
mServiceAlocs[i].mScopeOverrideValid = true;
|
||||
mServiceAlocs[i].GetAddress().mFields.m16[7] = HostSwap16(Mac::kShortAddrInvalid);
|
||||
mServiceAlocs[i].mPrefixLength = 64;
|
||||
mServiceAlocs[i].mPreferred = true;
|
||||
mServiceAlocs[i].mValid = true;
|
||||
mServiceAlocs[i].mScopeOverride = Ip6::Address::kRealmLocalScope;
|
||||
mServiceAlocs[i].mScopeOverrideValid = true;
|
||||
mServiceAlocs[i].GetAddress().SetLocator(Mac::kShortAddrInvalid);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -927,7 +927,7 @@ void Mle::ApplyMeshLocalPrefix(void)
|
||||
|
||||
for (uint8_t i = 0; i < OT_ARRAY_LENGTH(mServiceAlocs); i++)
|
||||
{
|
||||
if (HostSwap16(mServiceAlocs[i].GetAddress().mFields.m16[7]) != Mac::kShortAddrInvalid)
|
||||
if (mServiceAlocs[i].GetAddress().GetLocator() != Mac::kShortAddrInvalid)
|
||||
{
|
||||
Get<ThreadNetif>().RemoveUnicastAddress(mServiceAlocs[i]);
|
||||
mServiceAlocs[i].GetAddress().SetPrefix(GetMeshLocalPrefix());
|
||||
@@ -994,7 +994,7 @@ void Mle::SetRloc16(uint16_t aRloc16)
|
||||
if (aRloc16 != Mac::kShortAddrInvalid)
|
||||
{
|
||||
// mesh-local 16
|
||||
mMeshLocal16.GetAddress().mFields.m16[7] = HostSwap16(aRloc16);
|
||||
mMeshLocal16.GetAddress().SetLocator(aRloc16);
|
||||
Get<ThreadNetif>().AddUnicastAddress(mMeshLocal16);
|
||||
#if OPENTHREAD_FTD
|
||||
Get<AddressResolver>().RestartAddressQueries();
|
||||
@@ -1030,7 +1030,7 @@ otError Mle::GetLeaderAddress(Ip6::Address &aAddress) const
|
||||
aAddress.mFields.m16[4] = HostSwap16(0x0000);
|
||||
aAddress.mFields.m16[5] = HostSwap16(0x00ff);
|
||||
aAddress.mFields.m16[6] = HostSwap16(0xfe00);
|
||||
aAddress.mFields.m16[7] = HostSwap16(Rloc16FromRouterId(mLeaderData.GetLeaderRouterId()));
|
||||
aAddress.SetLocator(Rloc16FromRouterId(mLeaderData.GetLeaderRouterId()));
|
||||
|
||||
exit:
|
||||
return error;
|
||||
@@ -1043,7 +1043,7 @@ otError Mle::GetAlocAddress(Ip6::Address &aAddress, uint16_t aAloc16) const
|
||||
VerifyOrExit(GetRloc16() != Mac::kShortAddrInvalid, error = OT_ERROR_DETACHED);
|
||||
|
||||
memcpy(&aAddress, &mMeshLocal16.GetAddress(), 14);
|
||||
aAddress.mFields.m16[7] = HostSwap16(aAloc16);
|
||||
aAddress.SetLocator(aAloc16);
|
||||
|
||||
exit:
|
||||
return error;
|
||||
@@ -1059,7 +1059,7 @@ otError Mle::GetServiceAloc(uint8_t aServiceId, Ip6::Address &aAddress) const
|
||||
aAddress.mFields.m16[4] = HostSwap16(0x0000);
|
||||
aAddress.mFields.m16[5] = HostSwap16(0x00ff);
|
||||
aAddress.mFields.m16[6] = HostSwap16(0xfe00);
|
||||
aAddress.mFields.m16[7] = HostSwap16(ServiceAlocFromId(aServiceId));
|
||||
aAddress.SetLocator(ServiceAlocFromId(aServiceId));
|
||||
|
||||
exit:
|
||||
return error;
|
||||
@@ -1579,13 +1579,13 @@ void Mle::UpdateServiceAlocs(void)
|
||||
// First remove all alocs which are no longer necessary, to free up space in mServiceAlocs
|
||||
for (i = 0; i < serviceAlocsLength; i++)
|
||||
{
|
||||
serviceAloc = HostSwap16(mServiceAlocs[i].GetAddress().mFields.m16[7]);
|
||||
serviceAloc = mServiceAlocs[i].GetAddress().GetLocator();
|
||||
|
||||
if ((serviceAloc != Mac::kShortAddrInvalid) &&
|
||||
(!Get<NetworkData::Leader>().ContainsService(Mle::ServiceIdFromAloc(serviceAloc), rloc)))
|
||||
{
|
||||
Get<ThreadNetif>().RemoveUnicastAddress(mServiceAlocs[i]);
|
||||
mServiceAlocs[i].GetAddress().mFields.m16[7] = HostSwap16(Mac::kShortAddrInvalid);
|
||||
mServiceAlocs[i].GetAddress().SetLocator(Mac::kShortAddrInvalid);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1594,7 +1594,7 @@ void Mle::UpdateServiceAlocs(void)
|
||||
{
|
||||
for (i = 0; i < serviceAlocsLength; i++)
|
||||
{
|
||||
serviceAloc = HostSwap16(mServiceAlocs[i].GetAddress().mFields.m16[7]);
|
||||
serviceAloc = mServiceAlocs[i].GetAddress().GetLocator();
|
||||
|
||||
if ((serviceAloc != Mac::kShortAddrInvalid) && (Mle::ServiceIdFromAloc(serviceAloc) == serviceId))
|
||||
{
|
||||
@@ -1607,7 +1607,7 @@ void Mle::UpdateServiceAlocs(void)
|
||||
// Service Aloc is not there, but it should be. Lets add it into first empty space
|
||||
for (i = 0; i < serviceAlocsLength; i++)
|
||||
{
|
||||
serviceAloc = HostSwap16(mServiceAlocs[i].GetAddress().mFields.m16[7]);
|
||||
serviceAloc = mServiceAlocs[i].GetAddress().GetLocator();
|
||||
|
||||
if (serviceAloc == Mac::kShortAddrInvalid)
|
||||
{
|
||||
@@ -3982,8 +3982,8 @@ otError Mle::CheckReachability(uint16_t aMeshSource, uint16_t aMeshDest, Ip6::He
|
||||
ExitNow(error = OT_ERROR_NONE);
|
||||
}
|
||||
|
||||
messageInfo.GetPeerAddr() = GetMeshLocal16();
|
||||
messageInfo.GetPeerAddr().mFields.m16[7] = HostSwap16(aMeshSource);
|
||||
messageInfo.GetPeerAddr() = GetMeshLocal16();
|
||||
messageInfo.GetPeerAddr().SetLocator(aMeshSource);
|
||||
|
||||
Get<Ip6::Icmp>().SendError(Ip6::IcmpHeader::kTypeDstUnreach, Ip6::IcmpHeader::kCodeDstUnreachNoRoute, messageInfo,
|
||||
aIp6Header);
|
||||
@@ -4008,7 +4008,7 @@ otError Mle::InformPreviousParent(void)
|
||||
|
||||
messageInfo.SetSockAddr(GetMeshLocal64());
|
||||
messageInfo.SetPeerAddr(GetMeshLocal16());
|
||||
messageInfo.GetPeerAddr().mFields.m16[7] = HostSwap16(mPreviousParentRloc);
|
||||
messageInfo.GetPeerAddr().SetLocator(mPreviousParentRloc);
|
||||
|
||||
SuccessOrExit(error = Get<Ip6::Ip6>().SendDatagram(*message, messageInfo, Ip6::kProtoNone));
|
||||
|
||||
|
||||
@@ -3387,7 +3387,7 @@ Neighbor *MleRouter::GetNeighbor(const Ip6::Address &aAddress)
|
||||
if (aAddress.mFields.m16[4] == HostSwap16(0x0000) && aAddress.mFields.m16[5] == HostSwap16(0x00ff) &&
|
||||
aAddress.mFields.m16[6] == HostSwap16(0xfe00))
|
||||
{
|
||||
macAddr.SetShort(HostSwap16(aAddress.mFields.m16[7]));
|
||||
macAddr.SetShort(aAddress.GetLocator());
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -3408,7 +3408,7 @@ Neighbor *MleRouter::GetNeighbor(const Ip6::Address &aAddress)
|
||||
|
||||
if (context.mContextId == kMeshLocalPrefixContextId && aAddress.mFields.m16[4] == HostSwap16(0x0000) &&
|
||||
aAddress.mFields.m16[5] == HostSwap16(0x00ff) && aAddress.mFields.m16[6] == HostSwap16(0xfe00) &&
|
||||
aAddress.mFields.m16[7] == HostSwap16(child->GetRloc16()))
|
||||
aAddress.GetLocator() == child->GetRloc16())
|
||||
{
|
||||
ExitNow(rval = child);
|
||||
}
|
||||
@@ -3424,7 +3424,7 @@ Neighbor *MleRouter::GetNeighbor(const Ip6::Address &aAddress)
|
||||
if (aAddress.mFields.m16[4] == HostSwap16(0x0000) && aAddress.mFields.m16[5] == HostSwap16(0x00ff) &&
|
||||
aAddress.mFields.m16[6] == HostSwap16(0xfe00))
|
||||
{
|
||||
rval = mRouterTable.GetNeighbor(HostSwap16(aAddress.mFields.m16[7]));
|
||||
rval = mRouterTable.GetNeighbor(aAddress.GetLocator());
|
||||
}
|
||||
|
||||
exit:
|
||||
@@ -3874,8 +3874,8 @@ otError MleRouter::CheckReachability(uint16_t aMeshSource, uint16_t aMeshDest, I
|
||||
ExitNow();
|
||||
}
|
||||
|
||||
messageInfo.GetPeerAddr() = GetMeshLocal16();
|
||||
messageInfo.GetPeerAddr().mFields.m16[7] = HostSwap16(aMeshSource);
|
||||
messageInfo.GetPeerAddr() = GetMeshLocal16();
|
||||
messageInfo.GetPeerAddr().SetLocator(aMeshSource);
|
||||
|
||||
Get<Ip6::Icmp>().SendError(Ip6::IcmpHeader::kTypeDstUnreach, Ip6::IcmpHeader::kCodeDstUnreachNoRoute, messageInfo,
|
||||
aIp6Header);
|
||||
|
||||
Reference in New Issue
Block a user