[mle] enhance RLOC and ALOC address generation (#10391)

This commit enhances the generation of RLOC and ALOC addresses in the
`Mle` class.

Methods retrieving RLOC/ALOC addresses no longer return an `Error` and
are now `void`. The previous check for a valid `GetRloc16()` value,
which returned `kErrorDetach` if unset, is removed because this
scenario only occurred before the device's initial attachment.
Post-attachment, the RLOC16 remains valid even if the device is
detached. This change simplifies the code since RLOC/ALOC address
retrieval happens after the initial attachment.

Additional enhancements include:

-   Changing the input parameter order in `GetCommissionerAloc()` to
    match `GetServiceAloc()`.
-   Using `Ip6::Address::SetToRoutingLocator()` to construct RLOC
    addresses, harmonizing address generation and improving code
    readability.
This commit is contained in:
Abtin Keshavarzian
2024-06-17 09:23:43 -07:00
committed by GitHub
parent 8a8a4d8e31
commit 5127e7e5c0
18 changed files with 63 additions and 107 deletions
+5 -6
View File
@@ -44,16 +44,16 @@ namespace Tmf {
void MessageInfo::SetSockAddrToRloc(void) { SetSockAddr(Get<Mle::MleRouter>().GetMeshLocalRloc()); }
Error MessageInfo::SetSockAddrToRlocPeerAddrToLeaderAloc(void)
void MessageInfo::SetSockAddrToRlocPeerAddrToLeaderAloc(void)
{
SetSockAddrToRloc();
return Get<Mle::MleRouter>().GetLeaderAloc(GetPeerAddr());
Get<Mle::MleRouter>().GetLeaderAloc(GetPeerAddr());
}
Error MessageInfo::SetSockAddrToRlocPeerAddrToLeaderRloc(void)
void MessageInfo::SetSockAddrToRlocPeerAddrToLeaderRloc(void)
{
SetSockAddrToRloc();
return Get<Mle::MleRouter>().GetLeaderAddress(GetPeerAddr());
Get<Mle::MleRouter>().GetLeaderRloc(GetPeerAddr());
}
void MessageInfo::SetSockAddrToRlocPeerAddrToRealmLocalAllRoutersMulticast(void)
@@ -65,8 +65,7 @@ void MessageInfo::SetSockAddrToRlocPeerAddrToRealmLocalAllRoutersMulticast(void)
void MessageInfo::SetSockAddrToRlocPeerAddrTo(uint16_t aRloc16)
{
SetSockAddrToRloc();
SetPeerAddr(Get<Mle::MleRouter>().GetMeshLocalRloc());
GetPeerAddr().GetIid().SetLocator(aRloc16);
GetPeerAddr().SetToRoutingLocator(Get<Mle::Mle>().GetMeshLocalPrefix(), aRloc16);
}
void MessageInfo::SetSockAddrToRlocPeerAddrTo(const Ip6::Address &aPeerAddress)