[mle] fixes to restoring children (#2375)

This commit makes the following fixes:
- Relax the length check in `RemoveStoredChild()`
- Remove children that do not match router ID
- Simplify restoring logic and remove `mIsRouterrestoringChildren` state var
This commit is contained in:
Jonathan Hui
2017-11-29 20:59:31 +00:00
committed by GitHub
parent ed2112a19a
commit 7eea5e6d96
2 changed files with 14 additions and 29 deletions
+14 -28
View File
@@ -75,7 +75,6 @@ MleRouter::MleRouter(Instance &aInstance):
mLeaderWeight(kLeaderWeight),
mFixedLeaderPartitionId(0),
mRouterRoleEnabled(true),
mIsRouterRestoringChildren(false),
mAddressSolicitPending(false),
mPreviousPartitionId(0),
mRouterSelectionJitter(kRouterSelectionJitter),
@@ -447,12 +446,13 @@ otError MleRouter::SetStateRouter(uint16_t aRloc16)
netif.GetIp6().GetMpl().SetTimerExpirations(kMplRouterDataMessageTimerExpirations);
netif.GetMac().SetBeaconEnabled(true);
// remove children that do not have matching RLOC16
for (int i = 0; i < mMaxChildrenAllowed; i++)
{
if (mChildren[i].GetState() == Neighbor::kStateRestored)
if (mChildren[i].IsStateValidOrRestoring() &&
GetRouterId(mChildren[i].GetRloc16()) != mRouterId)
{
mIsRouterRestoringChildren = true;
break;
RemoveNeighbor(mChildren[i]);
}
}
@@ -492,12 +492,13 @@ otError MleRouter::SetStateLeader(uint16_t aRloc16)
netif.GetIp6().GetMpl().SetTimerExpirations(kMplRouterDataMessageTimerExpirations);
netif.GetMac().SetBeaconEnabled(true);
// remove children that do not have matching RLOC16
for (int i = 0; i < mMaxChildrenAllowed; i++)
{
if (mChildren[i].GetState() == Neighbor::kStateRestored)
if (mChildren[i].IsStateValidOrRestoring() &&
GetRouterId(mChildren[i].GetRloc16()) != mRouterId)
{
mIsRouterRestoringChildren = true;
break;
RemoveNeighbor(mChildren[i]);
}
}
@@ -1867,26 +1868,6 @@ void MleRouter::HandleStateUpdateTimer(void)
break;
}
if (mIsRouterRestoringChildren)
{
bool hasRestoringChildren = false;
for (uint8_t i = 0; i < mMaxChildrenAllowed; i++)
{
if (mChildren[i].GetState() == Neighbor::kStateRestored)
{
SendChildUpdateRequest(mChildren[i]);
hasRestoringChildren = true;
}
}
// no child to restore
if (!hasRestoringChildren)
{
mIsRouterRestoringChildren = false;
}
}
// update children state
for (int i = 0; i < mMaxChildrenAllowed; i++)
{
@@ -1915,6 +1896,11 @@ void MleRouter::HandleStateUpdateTimer(void)
otLogInfoMle(GetInstance(), "Child timeout expired");
RemoveNeighbor(mChildren[i]);
}
else if ((mRole == OT_DEVICE_ROLE_ROUTER || mRole == OT_DEVICE_ROLE_LEADER) &&
(mChildren[i].GetState() == Neighbor::kStateRestored))
{
SendChildUpdateRequest(mChildren[i]);
}
}
// update router state
@@ -3690,7 +3676,7 @@ otError MleRouter::RemoveStoredChild(uint16_t aChildRloc16)
SuccessOrExit(error = otPlatSettingsGet(&GetInstance(), Settings::kKeyChildInfo, i,
reinterpret_cast<uint8_t *>(&childInfo), &length));
VerifyOrExit(length == sizeof(childInfo), error = OT_ERROR_PARSE);
VerifyOrExit(length >= sizeof(childInfo), error = OT_ERROR_PARSE);
if (childInfo.mRloc16 == aChildRloc16)
{
-1
View File
@@ -850,7 +850,6 @@ private:
uint8_t mLeaderWeight;
uint32_t mFixedLeaderPartitionId; ///< only for certification testing
bool mRouterRoleEnabled : 1;
bool mIsRouterRestoringChildren : 1;
bool mAddressSolicitPending : 1;
uint8_t mRouterId;