Skip to content

Commit

Permalink
[netdata] resign active commissioner on NetData restore on leader (op…
Browse files Browse the repository at this point in the history
…enthread#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.
  • Loading branch information
abtink authored Oct 20, 2023
1 parent 6ff2778 commit c8aeeef
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/core/meshcop/meshcop_leader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ class Leader : public InstanceLocator, private NonCopyable
*/
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.
*
Expand Down
15 changes: 15 additions & 0 deletions src/core/thread/network_data_leader_ftd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1301,6 +1301,7 @@ void Leader::HandleNetworkDataRestoredAfterReset(void)
Iterator iterator = kIteratorInit;
ChangedFlags flags;
uint16_t rloc16;
uint16_t sessionId;

mWaitingForNetDataSync = false;

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit c8aeeef

Please sign in to comment.