[netdata] resign active commissioner on NetData restore on leader (#9549)

This commit updates `HandleNetworkDataRestoredAfterReset()`, which is
called after Network Data is restored on the leader after a leader
reset and recovery.

We now resign any active Commissioner by clearing the Commissioning
Data and adopt the Session ID from the restored Network Data
Commissioning Data. This ensures that any stale Commissioning Data
is not retained in Network Data for longer after a leader reset.
This commit is contained in:
Abtin Keshavarzian
2023-10-19 17:34:26 -07:00
committed by GitHub
parent 6ff277841e
commit c8aeeefffe
2 changed files with 23 additions and 0 deletions
+8
View File
@@ -62,6 +62,14 @@ public:
*/
explicit Leader(Instance &aInstance);
/**
* Sets the session ID.
*
* @param[in] aSessionId The session ID to use.
*
*/
void SetSessionId(uint16_t aSessionId) { mSessionId = aSessionId; }
/**
* Sends a MGMT_DATASET_CHANGED message to commissioner.
*
@@ -1301,6 +1301,7 @@ void Leader::HandleNetworkDataRestoredAfterReset(void)
Iterator iterator = kIteratorInit;
ChangedFlags flags;
uint16_t rloc16;
uint16_t sessionId;
mWaitingForNetDataSync = false;
@@ -1345,6 +1346,20 @@ void Leader::HandleNetworkDataRestoredAfterReset(void)
mContextIds.ScheduleToRemove(context->GetContextId());
}
}
// Update Commissioning Data. We adopt the same session ID
// (if any) and resign active commissioner (if any) by
// clearing the Commissioning Data.
if (FindCommissioningSessionId(sessionId) == kErrorNone)
{
Get<MeshCoP::Leader>().SetSessionId(sessionId);
}
if (FindBorderAgentRloc(rloc16) == kErrorNone)
{
Get<MeshCoP::Leader>().SetEmptyCommissionerData();
}
}
void Leader::HandleTimer(void)