[ip6-address] helper methods to set Link-Local and RLOC/ALOC addresses (#4841)

This commit adds and uses a new method `SetToLinkLocalAddress()` in
`Ip6::Address` class which sets the address to a Link-Local IPv6
address with a given Interface Identifier (either given directly or
generated from a MAC Extended Address).

It also adds methods to set the address to a Routing/Anycast Locator
and updates methods checking RLOC/ALOC addresses. It adds a common
`IsIidLocator()` to check if the IID matches the `0000:00ff:fe00:xxxx`
pattern. More specific checks for RLOC or ALOC can be done by
`IsIidRoutingLocator()` or `IsIidAnycastLocator()`. The `Mle` and
other modules are updated to use the new/updated methods.
This commit is contained in:
Abtin Keshavarzian
2020-04-16 10:39:35 -07:00
committed by GitHub
parent b1ec563a81
commit 69c3e2eed6
14 changed files with 200 additions and 142 deletions
+1 -1
View File
@@ -497,7 +497,7 @@ Message *CoapBase::FindRelatedRequest(const Message & aResponse,
aMetadata.ReadFrom(*message);
if (((aMetadata.mDestinationAddress == aMessageInfo.GetPeerAddr()) ||
aMetadata.mDestinationAddress.IsMulticast() || aMetadata.mDestinationAddress.IsAnycastRoutingLocator()) &&
aMetadata.mDestinationAddress.IsMulticast() || aMetadata.mDestinationAddress.IsIidAnycastLocator()) &&
(aMetadata.mDestinationPort == aMessageInfo.GetPeerPort()))
{
switch (aResponse.GetType())
+1 -2
View File
@@ -339,8 +339,7 @@ otError Joiner::Connect(JoinerRouter &aRouter)
SuccessOrExit(error = Get<Mac::Mac>().SetPanChannel(aRouter.mChannel));
SuccessOrExit(error = Get<Ip6::Filter>().AddUnsecurePort(kJoinerUdpPort));
sockaddr.GetAddress().mFields.m16[0] = HostSwap16(0xfe80);
sockaddr.GetAddress().SetIid(aRouter.mExtAddr);
sockaddr.GetAddress().SetToLinkLocalAddress(aRouter.mExtAddr);
sockaddr.mPort = aRouter.mJoinerUdpPort;
SuccessOrExit(error = Get<Coap::CoapSecure>().Connect(sockaddr, Joiner::HandleSecureCoapClientConnect, this));
+1 -2
View File
@@ -213,8 +213,7 @@ void JoinerRouter::HandleRelayTransmit(Coap::Message &aMessage, const Ip6::Messa
SuccessOrExit(error = message->SetLength(length));
aMessage.CopyTo(offset, 0, length, *message);
messageInfo.mPeerAddr.mFields.m16[0] = HostSwap16(0xfe80);
memcpy(messageInfo.mPeerAddr.mFields.m8 + 8, joinerIid, 8);
messageInfo.GetPeerAddr().SetToLinkLocalAddress(joinerIid);
messageInfo.SetPeerPort(joinerPort);
SuccessOrExit(error = mSocket.SendTo(*message, messageInfo));
+1 -5
View File
@@ -280,11 +280,7 @@ otError Dhcp6Client::Solicit(uint16_t aRloc16)
#if OPENTHREAD_ENABLE_DHCP6_MULTICAST_SOLICIT
messageInfo.GetPeerAddr().SetToRealmLocalAllRoutersMulticast();
#else
messageInfo.GetPeerAddr().SetPrefix(Get<Mle::MleRouter>().GetMeshLocalPrefix());
messageInfo.GetPeerAddr().mFields.m16[4] = HostSwap16(0x0000);
messageInfo.GetPeerAddr().mFields.m16[5] = HostSwap16(0x00ff);
messageInfo.GetPeerAddr().mFields.m16[6] = HostSwap16(0xfe00);
messageInfo.GetPeerAddr().SetLocator(aRloc16);
messageInfo.GetPeerAddr().SetToRoutingLocator(Get<Mle::MleRouter>().GetMeshLocalPrefix(), aRloc16);
#endif
messageInfo.SetSockAddr(Get<Mle::MleRouter>().GetMeshLocal16());
messageInfo.mPeerPort = kDhcpServerPort;
+4 -9
View File
@@ -167,15 +167,10 @@ private:
{
mPrefix = aPrefix;
mAloc.GetAddress().SetPrefix(aMeshLocalPrefix);
mAloc.mAddress.mFields.m16[4] = HostSwap16(0x0000);
mAloc.mAddress.mFields.m16[5] = HostSwap16(0x00ff);
mAloc.mAddress.mFields.m16[6] = HostSwap16(0xfe00);
mAloc.mAddress.mFields.m8[14] = Ip6::Address::kAloc16Mask;
mAloc.mAddress.mFields.m8[15] = aContextId;
mAloc.mPrefixLength = OT_IP6_PREFIX_BITSIZE;
mAloc.mPreferred = true;
mAloc.mValid = true;
mAloc.GetAddress().SetToAnycastLocator(aMeshLocalPrefix, (Ip6::Address::kAloc16Mask << 8) + aContextId);
mAloc.mPrefixLength = OT_IP6_PREFIX_BITSIZE;
mAloc.mPreferred = true;
mAloc.mValid = true;
}
private:
+1 -3
View File
@@ -201,9 +201,7 @@ otError Icmp::HandleEchoRequest(Message &aRequestMessage, const MessageInfo &aMe
uint16_t payloadLength;
// always handle Echo Request destined for RLOC or ALOC
VerifyOrExit(ShouldHandleEchoRequest(aMessageInfo) || aMessageInfo.GetSockAddr().IsRoutingLocator() ||
aMessageInfo.GetSockAddr().IsAnycastRoutingLocator(),
OT_NOOP);
VerifyOrExit(ShouldHandleEchoRequest(aMessageInfo) || aMessageInfo.GetSockAddr().IsIidLocator(), OT_NOOP);
otLogInfoIcmp("Received Echo Request");
+5 -6
View File
@@ -1027,10 +1027,9 @@ otError Ip6::ProcessReceiveCallback(const Message & aMessage,
if (mIsReceiveIp6FilterEnabled)
{
// do not pass messages sent to an RLOC/ALOC, except Service Locator
VerifyOrExit(
(!aMessageInfo.GetSockAddr().IsRoutingLocator() && !aMessageInfo.GetSockAddr().IsAnycastRoutingLocator()) ||
aMessageInfo.GetSockAddr().IsAnycastServiceLocator(),
error = OT_ERROR_NO_ROUTE);
VerifyOrExit(!aMessageInfo.GetSockAddr().IsIidLocator() ||
aMessageInfo.GetSockAddr().IsIidAnycastServiceLocator(),
error = OT_ERROR_NO_ROUTE);
switch (aIpProto)
{
@@ -1365,7 +1364,7 @@ const NetifUnicastAddress *Ip6::SelectSourceAddress(MessageInfo &aMessageInfo)
uint8_t candidatePrefixMatched;
uint8_t overrideScope;
if (candidateAddr->IsAnycastRoutingLocator())
if (candidateAddr->IsIidAnycastLocator())
{
// Don't use anycast address as source address.
continue;
@@ -1435,7 +1434,7 @@ const NetifUnicastAddress *Ip6::SelectSourceAddress(MessageInfo &aMessageInfo)
rvalPrefixMatched = candidatePrefixMatched;
}
else if ((candidatePrefixMatched == rvalPrefixMatched) &&
(destination->IsRoutingLocator() == candidateAddr->IsRoutingLocator()))
(destination->IsIidRoutingLocator() == candidateAddr->IsIidRoutingLocator()))
{
// Additional rule: Prefer RLOC source for RLOC destination, EID source for anything else
rvalAddr = addr;
+53 -19
View File
@@ -65,6 +65,20 @@ bool Address::IsLinkLocal(void) const
return (mFields.m16[0] & HostSwap16(0xffc0)) == HostSwap16(0xfe80);
}
void Address::SetToLinkLocalAddress(const Mac::ExtAddress &aExtAddress)
{
mFields.m32[0] = HostSwap32(0xfe800000);
mFields.m32[1] = 0;
SetIid(aExtAddress);
}
void Address::SetToLinkLocalAddress(const uint8_t *aIid)
{
mFields.m32[0] = HostSwap32(0xfe800000);
mFields.m32[1] = 0;
SetIid(aIid);
}
bool Address::IsLinkLocalMulticast(void) const
{
return IsMulticast() && (GetScope() == kLinkLocalScope);
@@ -130,24 +144,6 @@ void Address::SetToRealmLocalAllMplForwarders(void)
*this = GetRealmLocalAllMplForwarders();
}
bool Address::IsRoutingLocator(void) const
{
return (mFields.m32[2] == HostSwap32(0x000000ff) && mFields.m16[6] == HostSwap16(0xfe00) &&
mFields.m8[14] < kAloc16Mask && (mFields.m8[14] & kRloc16ReservedBitMask) == 0);
}
bool Address::IsAnycastRoutingLocator(void) const
{
return (mFields.m32[2] == HostSwap32(0x000000ff) && mFields.m16[6] == HostSwap16(0xfe00) &&
mFields.m8[14] == kAloc16Mask);
}
bool Address::IsAnycastServiceLocator(void) const
{
return IsAnycastRoutingLocator() && (mFields.m8[15] >= (Mle::kAloc16ServiceStart & 0xff)) &&
(mFields.m8[15] <= (Mle::kAloc16ServiceEnd & 0xff));
}
bool Address::IsSubnetRouterAnycast(void) const
{
return (mFields.m32[2] == 0 && mFields.m32[3] == 0);
@@ -161,7 +157,31 @@ bool Address::IsReservedSubnetAnycast(void) const
bool Address::IsIidReserved(void) const
{
return IsSubnetRouterAnycast() || IsReservedSubnetAnycast() || IsAnycastRoutingLocator();
return IsSubnetRouterAnycast() || IsReservedSubnetAnycast() || IsIidAnycastLocator();
}
bool Address::IsIidLocator(void) const
{
// IID pattern 0000:00ff:fe00:xxxx
return (mFields.m32[2] == HostSwap32(0x000000ff) && mFields.m16[6] == HostSwap16(0xfe00));
}
bool Address::IsIidRoutingLocator(void) const
{
return (IsIidLocator() && (mFields.m8[14] < kAloc16Mask) && ((mFields.m8[14] & kRloc16ReservedBitMask) == 0));
}
bool Address::IsIidAnycastLocator(void) const
{
// Anycast locator range 0xfc00- 0xfcff (`kAloc16Max` is 0xfc)
return (IsIidLocator() && (mFields.m8[14] == kAloc16Mask));
}
bool Address::IsIidAnycastServiceLocator(void) const
{
uint16_t locator = GetLocator();
return (IsIidLocator() && (locator >= Mle::kAloc16ServiceStart) && (locator <= Mle::kAloc16ServiceEnd));
}
void Address::SetPrefix(const uint8_t *aPrefix, uint8_t aPrefixLength)
@@ -212,6 +232,20 @@ void Address::SetIid(const Mac::ExtAddress &aExtAddress)
addr.CopyTo(mFields.m8 + kInterfaceIdentifierOffset);
}
void Address::SetIidToLocator(uint16_t aLocator)
{
// Locator IID pattern `0000:00ff:fe00:xxxx`
mFields.m32[2] = HostSwap32(0x000000ff);
mFields.m16[6] = HostSwap16(0xfe00);
mFields.m16[7] = HostSwap16(aLocator);
}
void Address::SetToLocator(const Mle::MeshLocalPrefix &aMeshLocalPrefix, uint16_t aLocator)
{
SetPrefix(aMeshLocalPrefix);
SetIidToLocator(aLocator);
}
void Address::ToExtAddress(Mac::ExtAddress &aExtAddress) const
{
aExtAddress.Set(mFields.m8 + kInterfaceIdentifierOffset);
+105 -30
View File
@@ -137,6 +137,23 @@ public:
*/
bool IsLinkLocal(void) const;
/**
* This methods sets the IPv6 address to a Link-Local address with Interface Identifier generated from a given
* MAC Extended Address.
*
* @param[in] aExtAddress A MAC Extended Address (used to generate the IID).
*
*/
void SetToLinkLocalAddress(const Mac::ExtAddress &aExtAddress);
/**
* This methods sets the IPv6 address to a Link-Local address with a given Interface Identifier.
*
* @param[in] aIid A pointer to a buffer containing the Interface Identifier.
*
*/
void SetToLinkLocalAddress(const uint8_t *aIid);
/**
* This method indicates whether or not the IPv6 address is multicast address.
*
@@ -249,34 +266,7 @@ public:
bool IsMulticastLargerThanRealmLocal(void) const;
/**
* This method indicates whether or not the IPv6 address is a RLOC address.
*
* @retval TRUE If the IPv6 address is a RLOC address.
* @retval FALSE If the IPv6 address is not a RLOC address.
*
*/
bool IsRoutingLocator(void) const;
/**
* This method indicates whether or not the IPv6 address is an Anycast RLOC address.
*
* @retval TRUE If the IPv6 address is an Anycast RLOC address.
* @retval FALSE If the IPv6 address is not an Anycast RLOC address.
*
*/
bool IsAnycastRoutingLocator(void) const;
/**
* This method indicates whether or not the IPv6 address is an Anycast Service Locator.
*
* @retval TRUE If the IPv6 address is an Anycast Service Locator.
* @retval FALSE If the IPv6 address is not an Anycast Service Locator.
*
*/
bool IsAnycastServiceLocator(void) const;
/**
* This method indicates whether or not the IPv6 address is Subnet-Router Anycast (RFC 4291),
* This method indicates whether or not the IPv6 address is Subnet-Router Anycast (RFC 4291).
*
* @retval TRUE If the IPv6 address is a Subnet-Router Anycast address.
* @retval FALSE If the IPv6 address is not a Subnet-Router Anycast address.
@@ -285,7 +275,7 @@ public:
bool IsSubnetRouterAnycast(void) const;
/**
* This method indicates whether or not the IPv6 address is Reserved Subnet Anycast (RFC 2526),
* This method indicates whether or not the IPv6 address is Reserved Subnet Anycast (RFC 2526).
*
* @retval TRUE If the IPv6 address is a Reserved Subnet Anycast address.
* @retval FALSE If the IPv6 address is not a Reserved Subnet Anycast address.
@@ -294,7 +284,7 @@ public:
bool IsReservedSubnetAnycast(void) const;
/**
* This method indicates whether or not the IPv6 address contains Reserved IPv6 IID (RFC 5453),
* This method indicates whether or not the IPv6 address contains Reserved IPv6 IID (RFC 5453).
*
* @retval TRUE If the IPv6 address contains a reserved IPv6 IID.
* @retval FALSE If the IPv6 address does not contain a reserved IPv6 IID.
@@ -302,6 +292,55 @@ public:
*/
bool IsIidReserved(void) const;
/**
* This method indicates whether or not the Interface Identifier (IID) of the IPv6 address matches the locator
* pattern (`0000:00ff:fe00:xxxx`).
*
* @retval TRUE If the IPv6 address IID matches the locator pattern
* @retval FALSE If the IPv6 address IID does not match the locator pattern
*
*/
bool IsIidLocator(void) const;
/**
* This method indicates whether or not the IPv6 address's Interface Identifier (IID) matches a Routing Locator
* (RLOC).
*
* In addition to checking that the IID matches the locator pattern (`0000:00ff:fe00:xxxx`), this method also
* checks that the locator value is a valid RLOC16.
*
* @retval TRUE If the IPv6 address's IID matches a RLOC address.
* @retval FALSE If the IPv6 address's IID does not match a RLOC address.
*
*/
bool IsIidRoutingLocator(void) const;
/**
* This method indicates whether or not the IPv6 address's Interface Identifier (IID) matches an Anycast Locator
* (ALOC).
*
* In addition to checking that the IID matches the locator pattern (`0000:00ff:fe00:xxxx`), this method also
* checks that the locator value is any valid ALOC16 (0xfc00 - 0xfcff).
*
* @retval TRUE If the IPv6 address's IID matches a ALOC address.
* @retval FALSE If the IPv6 address's IID does not match a ALOC address.
*
*/
bool IsIidAnycastLocator(void) const;
/**
* This method indicates whether or not the IPv6 address's Interface Identifier (IID) matches a Service Anycast
* Locator (ALOC).
*
* In addition to checking that the IID matches the locator pattern (`0000:00ff:fe00:xxxx`), this method also
* checks that the locator value is a valid Service ALOC16 (0xfc10 0xfc2f).
*
* @retval TRUE If the IPv6 address's IID matches a ALOC address.
* @retval FALSE If the IPv6 address's IID does not match a ALOC address.
*
*/
bool IsIidAnycastServiceLocator(void) const;
/**
* This method gets the IPv6 address locator.
*
@@ -320,6 +359,32 @@ public:
*/
void SetLocator(uint16_t aLocator) { mFields.m16[7] = HostSwap16(aLocator); }
/**
* This method sets the IPv6 address to a Routing Locator (RLOC) IPv6 address with a given Mesh-local prefix and
* RLOC16 value.
*
* @param[in] aMeshLocalPrefix A Mesh Local Prefix.
* @param[in] aRloc16 A RLOC16 value.
*
*/
void SetToRoutingLocator(const Mle::MeshLocalPrefix &aMeshLocalPrefix, uint16_t aRloc16)
{
SetToLocator(aMeshLocalPrefix, aRloc16);
}
/**
* This method sets the IPv6 address to a Anycast Locator (ALOC) IPv6 address with a given Mesh-local prefix and
* ALOC16 value.
*
* @param[in] aMeshLocalPrefix A Mesh Local Prefix.
* @param[in] aAloc16 A ALOC16 value.
*
*/
void SetToAnycastLocator(const Mle::MeshLocalPrefix &aMeshLocalPrefix, uint16_t aAloc16)
{
SetToLocator(aMeshLocalPrefix, aAloc16);
}
/**
* This method sets the IPv6 address prefix.
*
@@ -406,6 +471,15 @@ public:
*/
void SetIid(const Mac::ExtAddress &aExtAddress);
/**
* This method sets the Interface Identifier to Routing/Anycast Locator pattern `0000:00ff:fe00:xxxx` with a given
* locator (RLOC16 or ALOC16) value.
*
* @param[in] aLocator RLOC16 or ALOC16.
*
*/
void SetIidToLocator(uint16_t aLocator);
/**
* This method converts the IPv6 Interface Identifier to an IEEE 802.15.4 Extended Address.
*
@@ -495,6 +569,7 @@ public:
private:
void SetPrefix(uint8_t aOffset, const uint8_t *aPrefix, uint8_t aPrefixLength);
void SetToLocator(const Mle::MeshLocalPrefix &aMeshLocalPrefix, uint16_t aLocator);
static const Address &GetLinkLocalAllNodesMulticast(void);
static const Address &GetLinkLocalAllRoutersMulticast(void);
+1 -4
View File
@@ -67,10 +67,7 @@ otError Lowpan::ComputeIid(const Mac::Address &aMacAddr, const Context &aContext
switch (aMacAddr.GetType())
{
case Mac::Address::kTypeShort:
aIpAddress.mFields.m16[4] = HostSwap16(0x0000);
aIpAddress.mFields.m16[5] = HostSwap16(0x00ff);
aIpAddress.mFields.m16[6] = HostSwap16(0xfe00);
aIpAddress.SetLocator(aMacAddr.GetShort());
aIpAddress.SetIidToLocator(aMacAddr.GetShort());
break;
case Mac::Address::kTypeExtended:
+1 -1
View File
@@ -669,7 +669,7 @@ void MeshForwarder::UpdateRoutes(const uint8_t * aFrame,
VerifyOrExit(!aMeshDest.IsBroadcast() && aMeshSource.IsShort(), OT_NOOP);
SuccessOrExit(GetIp6Header(aFrame, aFrameLength, aMeshSource, aMeshDest, ip6Header));
if (!ip6Header.GetSource().IsRoutingLocator() && !ip6Header.GetSource().IsAnycastRoutingLocator() &&
if (!ip6Header.GetSource().IsIidLocator() &&
Get<NetworkData::Leader>().IsOnMesh(ip6Header.GetSource()) /* only for on mesh address which may require AQ */)
{
if (Get<AddressResolver>().UpdateCacheEntry(ip6Header.GetSource(), aMeshSource.GetShort()) ==
+17 -40
View File
@@ -127,8 +127,7 @@ Mle::Mle(Instance &aInstance)
// link-local 64
mLinkLocal64.Clear();
mLinkLocal64.GetAddress().mFields.m16[0] = HostSwap16(0xfe80);
mLinkLocal64.GetAddress().SetIid(Get<Mac::Mac>().GetExtAddress());
mLinkLocal64.GetAddress().SetToLinkLocalAddress(Get<Mac::Mac>().GetExtAddress());
mLinkLocal64.mPrefixLength = 64;
mLinkLocal64.mPreferred = true;
mLinkLocal64.mValid = true;
@@ -202,15 +201,13 @@ Mle::Mle(Instance &aInstance)
// mesh-local 16
mMeshLocal16.Clear();
mMeshLocal16.GetAddress().mFields.m16[4] = HostSwap16(0x0000);
mMeshLocal16.GetAddress().mFields.m16[5] = HostSwap16(0x00ff);
mMeshLocal16.GetAddress().mFields.m16[6] = HostSwap16(0xfe00);
mMeshLocal16.mPrefixLength = MeshLocalPrefix::kLength;
mMeshLocal16.mPreferred = true;
mMeshLocal16.mValid = true;
mMeshLocal16.mScopeOverride = Ip6::Address::kRealmLocalScope;
mMeshLocal16.mScopeOverrideValid = true;
mMeshLocal16.mRloc = true;
mMeshLocal16.GetAddress().SetIidToLocator(0);
mMeshLocal16.mPrefixLength = MeshLocalPrefix::kLength;
mMeshLocal16.mPreferred = true;
mMeshLocal16.mValid = true;
mMeshLocal16.mScopeOverride = Ip6::Address::kRealmLocalScope;
mMeshLocal16.mScopeOverrideValid = true;
mMeshLocal16.mRloc = true;
// Store RLOC address reference in MPL module.
Get<Ip6::Mpl>().SetMatchingAddress(mMeshLocal16.GetAddress());
@@ -1101,11 +1098,7 @@ otError Mle::GetLeaderAddress(Ip6::Address &aAddress) const
VerifyOrExit(GetRloc16() != Mac::kShortAddrInvalid, error = OT_ERROR_DETACHED);
aAddress.SetPrefix(GetMeshLocalPrefix());
aAddress.mFields.m16[4] = HostSwap16(0x0000);
aAddress.mFields.m16[5] = HostSwap16(0x00ff);
aAddress.mFields.m16[6] = HostSwap16(0xfe00);
aAddress.SetLocator(Rloc16FromRouterId(mLeaderData.GetLeaderRouterId()));
aAddress.SetToRoutingLocator(GetMeshLocalPrefix(), Rloc16FromRouterId(mLeaderData.GetLeaderRouterId()));
exit:
return error;
@@ -1129,12 +1122,7 @@ otError Mle::GetServiceAloc(uint8_t aServiceId, Ip6::Address &aAddress) const
otError error = OT_ERROR_NONE;
VerifyOrExit(GetRloc16() != Mac::kShortAddrInvalid, error = OT_ERROR_DETACHED);
aAddress.SetPrefix(GetMeshLocalPrefix());
aAddress.mFields.m16[4] = HostSwap16(0x0000);
aAddress.mFields.m16[5] = HostSwap16(0x00ff);
aAddress.mFields.m16[6] = HostSwap16(0xfe00);
aAddress.SetLocator(ServiceAlocFromId(aServiceId));
aAddress.SetToAnycastLocator(GetMeshLocalPrefix(), ServiceAlocFromId(aServiceId));
exit:
return error;
@@ -2161,9 +2149,7 @@ otError Mle::SendChildIdRequest(void)
mParentCandidate.SetState(Neighbor::kStateValid);
destination.Clear();
destination.mFields.m16[0] = HostSwap16(0xfe80);
destination.SetIid(mParentCandidate.GetExtAddress());
destination.SetToLinkLocalAddress(mParentCandidate.GetExtAddress());
SuccessOrExit(error = SendMessage(*message, destination));
if (mAddressRegistrationMode == kAppendMeshLocalOnly)
@@ -2307,9 +2293,7 @@ void Mle::HandleMessageTransmissionTimer(void)
VerifyOrExit(mDataRequestAttempts < kMaxChildKeepAliveAttempts, BecomeDetached());
destination.Clear();
destination.mFields.m16[0] = HostSwap16(0xfe80);
destination.SetIid(mParent.GetExtAddress());
destination.SetToLinkLocalAddress(mParent.GetExtAddress());
if (SendDataRequest(destination, tlvs, sizeof(tlvs), 0) == OT_ERROR_NONE)
{
@@ -2397,9 +2381,7 @@ otError Mle::SendChildUpdateRequest(void)
break;
}
destination.Clear();
destination.mFields.m16[0] = HostSwap16(0xfe80);
destination.SetIid(mParent.GetExtAddress());
destination.SetToLinkLocalAddress(mParent.GetExtAddress());
SuccessOrExit(error = SendMessage(*message, destination));
LogMleMessage("Send Child Update Request to parent", destination);
@@ -2476,9 +2458,7 @@ otError Mle::SendChildUpdateResponse(const uint8_t *aTlvs, uint8_t aNumTlvs, con
}
}
destination.Clear();
destination.mFields.m16[0] = HostSwap16(0xfe80);
destination.SetIid(mParent.GetExtAddress());
destination.SetToLinkLocalAddress(mParent.GetExtAddress());
SuccessOrExit(error = SendMessage(*message, destination));
LogMleMessage("Send Child Update Response to parent", destination);
@@ -4082,20 +4062,17 @@ uint16_t Mle::GetNextHop(uint16_t aDestination) const
bool Mle::IsRoutingLocator(const Ip6::Address &aAddress) const
{
return memcmp(&mMeshLocal16, &aAddress, kRlocPrefixLength) == 0 &&
aAddress.mFields.m8[14] < Ip6::Address::kAloc16Mask &&
(aAddress.mFields.m8[14] & Ip6::Address::kRloc16ReservedBitMask) == 0;
return IsMeshLocalAddress(aAddress) && aAddress.IsIidRoutingLocator();
}
bool Mle::IsAnycastLocator(const Ip6::Address &aAddress) const
{
return memcmp(&mMeshLocal16, &aAddress, kRlocPrefixLength) == 0 &&
aAddress.mFields.m8[14] == Ip6::Address::kAloc16Mask;
return IsMeshLocalAddress(aAddress) && aAddress.IsIidAnycastLocator();
}
bool Mle::IsMeshLocalAddress(const Ip6::Address &aAddress) const
{
return aAddress.PrefixMatch(GetMeshLocal16()) >= MeshLocalPrefix::kLength;
return (memcmp(&GetMeshLocalPrefix(), &aAddress, MeshLocalPrefix::kSize) == 0);
}
otError Mle::CheckReachability(uint16_t aMeshDest, Ip6::Header &aIp6Header)
+8 -19
View File
@@ -523,9 +523,7 @@ otError MleRouter::SendLinkRequest(Neighbor *aNeighbor)
mChallengeTimeout = (((2 * kMaxResponseDelay) + kStateUpdatePeriod - 1) / kStateUpdatePeriod);
SuccessOrExit(error = AppendChallenge(*message, mChallenge));
destination.mFields.m8[0] = 0xff;
destination.mFields.m8[1] = 0x02;
destination.mFields.m8[15] = 2;
destination.SetToLinkLocalAllRoutersMulticast();
}
else
{
@@ -542,8 +540,7 @@ otError MleRouter::SendLinkRequest(Neighbor *aNeighbor)
SuccessOrExit(error = AppendChallenge(*message, challenge));
}
destination.mFields.m16[0] = HostSwap16(0xfe80);
destination.SetIid(aNeighbor->GetExtAddress());
destination.SetToLinkLocalAddress(aNeighbor->GetExtAddress());
}
SuccessOrExit(error = SendMessage(*message, destination));
@@ -1964,9 +1961,7 @@ void MleRouter::SendParentResponse(Child *aChild, const Challenge &aChallenge, b
SuccessOrExit(error = AppendConnectivity(*message));
SuccessOrExit(error = AppendVersion(*message));
destination.Clear();
destination.mFields.m16[0] = HostSwap16(0xfe80);
destination.SetIid(aChild->GetExtAddress());
destination.SetToLinkLocalAddress(aChild->GetExtAddress());
if (aRoutersOnlyRequest)
{
@@ -3038,9 +3033,7 @@ otError MleRouter::SendChildIdResponse(Child &aChild)
}
#endif
destination.Clear();
destination.mFields.m16[0] = HostSwap16(0xfe80);
destination.SetIid(aChild.GetExtAddress());
destination.SetToLinkLocalAddress(aChild.GetExtAddress());
SuccessOrExit(error = SendMessage(*message, destination));
LogMleMessage("Send Child ID Response", destination, aChild.GetRloc16());
@@ -3100,9 +3093,7 @@ otError MleRouter::SendChildUpdateRequest(Child &aChild)
SuccessOrExit(error = AppendChallenge(*message, aChild.GetChallenge(), aChild.GetChallengeSize()));
}
destination.Clear();
destination.mFields.m16[0] = HostSwap16(0xfe80);
destination.SetIid(aChild.GetExtAddress());
destination.SetToLinkLocalAddress(aChild.GetExtAddress());
SuccessOrExit(error = SendMessage(*message, destination));
if (aChild.IsRxOnWhenIdle())
@@ -3462,9 +3453,8 @@ Neighbor *MleRouter::GetNeighbor(const Ip6::Address &aAddress)
{
child = iter.GetChild();
if (context.mContextId == kMeshLocalPrefixContextId && aAddress.mFields.m16[4] == HostSwap16(0x0000) &&
aAddress.mFields.m16[5] == HostSwap16(0x00ff) && aAddress.mFields.m16[6] == HostSwap16(0xfe00) &&
aAddress.GetLocator() == child->GetRloc16())
if ((context.mContextId == kMeshLocalPrefixContextId) && aAddress.IsIidLocator() &&
(aAddress.GetLocator() == child->GetRloc16()))
{
ExitNow(rval = child);
}
@@ -3477,8 +3467,7 @@ Neighbor *MleRouter::GetNeighbor(const Ip6::Address &aAddress)
VerifyOrExit(context.mContextId == kMeshLocalPrefixContextId, rval = NULL);
if (aAddress.mFields.m16[4] == HostSwap16(0x0000) && aAddress.mFields.m16[5] == HostSwap16(0x00ff) &&
aAddress.mFields.m16[6] == HostSwap16(0xfe00))
if (aAddress.IsIidLocator())
{
rval = mRouterTable.GetNeighbor(aAddress.GetLocator());
}
+1 -1
View File
@@ -144,7 +144,7 @@ void Leader::HandleServerData(Coap::Message &aMessage, const Ip6::MessageInfo &a
otLogInfoNetData("Received network data registration");
VerifyOrExit(aMessageInfo.GetPeerAddr().IsRoutingLocator(), OT_NOOP);
VerifyOrExit(aMessageInfo.GetPeerAddr().IsIidRoutingLocator(), OT_NOOP);
switch (Tlv::ReadUint16Tlv(aMessage, ThreadTlv::kRloc16, rloc16))
{