[ip6] rename methods fully initializing an Ip6::Address/Prefix (#13169)

This commit renames several methods in `Ip6::Address`,
`Ip6::InterfaceIdentifier`, `Ip6::Prefix`, and `Ip4::Address` that
fully initialize the object from `Set...()` to `Init...()`.

This creates a clear semantic distinction in the API:
- `Init...()`: Fully (re-)initializing the object.
- `Set...()`: Modifies a specific property or a sub-component of
   the object (e.g., `SetPrefix()`,  `SetLocator()`,
   `SetSubnetId()`).

Some examples of renames include:
- `SetFromExtAddress()` -> `InitFromExtAddress()`
- `SetToLocator()` -> `InitAsLocator()`
- `SetToLinkLocalAddress()` -> `InitAsLinkLocalAddress()`
- `SetToRoutingLocator()` -> `InitAsRoutingLocator()`
- `SetToAnycastLocator()` -> `InitAsAnycastLocator()`
- `SetToIp4Mapped()` -> `InitAsIp4Mapped()`

All calls to these methods across the codebase have been updated
to reflect the new names.
This commit is contained in:
Abtin Keshavarzian
2026-05-28 20:52:05 -07:00
committed by GitHub
parent e1b34bc5bc
commit 2a2d4be953
52 changed files with 154 additions and 148 deletions
+1 -1
View File
@@ -191,7 +191,7 @@ bool otIp6IsLinkLocalUnicast(const otIp6Address *aAddress) { return AsCoreType(a
void otIp6FormLinkLocalAddressFromExtAddress(const otExtAddress *aExtAddress, otIp6Address *aAddress)
{
AsCoreType(aAddress).SetToLinkLocalAddress(AsCoreType(aExtAddress));
AsCoreType(aAddress).InitAsLinkLocalAddress(AsCoreType(aExtAddress));
}
void otIp6ExtractExtAddressFromIp6AddressIid(const otIp6Address *aAddress, otExtAddress *aExtAddress)
+1 -1
View File
@@ -142,7 +142,7 @@ otError otIp4FromIp4MappedIp6Address(const otIp6Address *aIp6Address, otIp4Addre
void otIp4ToIp4MappedIp6Address(const otIp4Address *aIp4Address, otIp6Address *aIp6Address)
{
AsCoreType(aIp6Address).SetToIp4Mapped(AsCoreType(aIp4Address));
AsCoreType(aIp6Address).InitAsIp4Mapped(AsCoreType(aIp4Address));
}
otError otIp4AddressFromString(const char *aString, otIp4Address *aAddress)
+1 -1
View File
@@ -57,7 +57,7 @@ Local::Local(Instance &aInstance)
// Primary Backbone Router Aloc
mBbrPrimaryAloc.InitAsThreadOriginMeshLocal();
mBbrPrimaryAloc.GetAddress().GetIid().SetToLocator(Mle::Aloc16::ForPrimaryBackboneRouter());
mBbrPrimaryAloc.GetAddress().GetIid().InitAsLocator(Mle::Aloc16::ForPrimaryBackboneRouter());
// All Network Backbone Routers Multicast Address.
mAllNetworkBackboneRouters.Clear();
+1 -1
View File
@@ -278,7 +278,7 @@ Error InfraIf::LinkLayerAddress::ConvertToIid(Ip6::InterfaceIdentifier &aIid) co
ExitNow(error = kErrorNotCapable);
}
aIid.SetFromExtAddress(extAddress);
aIid.InitFromExtAddress(extAddress);
exit:
return error;
+1 -1
View File
@@ -224,7 +224,7 @@ void RoutingManager::LoadOrGenerateRandomBrUlaPrefix(void)
SuccessOrAssert(randomUlaPrefix.GenerateRandomUla());
mBrUlaPrefix.Set(randomUlaPrefix);
mBrUlaPrefix.InitFrom(randomUlaPrefix);
mBrUlaPrefix.SetSubnetId(0);
mBrUlaPrefix.SetLength(kBrUlaPrefixLength);
+1 -1
View File
@@ -544,7 +544,7 @@ bool TxtData::Info::ReadOmrPrefix(const Dns::TxtEntry &aEntry, Ip6::Prefix &aPre
VerifyOrExit(length <= Ip6::Prefix::kMaxLength);
VerifyOrExit(aEntry.mValueLength >= sizeof(uint8_t) + Ip6::Prefix::SizeForLength(length));
aPrefix.Set(&aEntry.mValue[1], length);
aPrefix.InitFrom(&aEntry.mValue[1], length);
didRead = true;
exit:
+1 -1
View File
@@ -168,7 +168,7 @@ template <> void JoinerRouter::HandleTmf<kUriRelayTx>(Coap::Msg &aMsg)
SuccessOrExit(error = message->AppendBytesFromMessage(aMsg.mMessage, offsetRange));
messageInfo.GetPeerAddr().SetToLinkLocalAddress(joinerIid);
messageInfo.GetPeerAddr().InitAsLinkLocalAddress(joinerIid);
messageInfo.SetPeerPort(joinerPort);
SuccessOrExit(error = mSocket.SendTo(*message, messageInfo));
+1 -1
View File
@@ -279,7 +279,7 @@ Error Seeker::SetUpNextConnection(Ip6::SockAddr &aSockAddr)
aSockAddr.Clear();
aSockAddr.SetPort(entry.mJoinerUdpPort);
aSockAddr.GetAddress().SetToLinkLocalAddress(entry.mExtAddr);
aSockAddr.GetAddress().InitAsLinkLocalAddress(entry.mExtAddr);
exit:
return error;
+1 -1
View File
@@ -268,7 +268,7 @@ void Client::Solicit(uint16_t aRloc16)
#if OPENTHREAD_ENABLE_DHCP6_MULTICAST_SOLICIT
messageInfo.SetPeerAddr(Ip6::Address::GetRealmLocalAllRoutersMulticast());
#else
messageInfo.GetPeerAddr().SetToRoutingLocator(Get<Mle::Mle>().GetMeshLocalPrefix(), aRloc16);
messageInfo.GetPeerAddr().InitAsRoutingLocator(Get<Mle::Mle>().GetMeshLocalPrefix(), aRloc16);
#endif
messageInfo.SetSockAddr(Get<Mle::Mle>().GetMeshLocalRloc());
messageInfo.mPeerPort = kDhcpServerPort;
+1 -1
View File
@@ -402,7 +402,7 @@ Error Server::AppendIaAddressOption(Message &aMessage,
option.Init();
option.GetAddress().SetPrefix(aPrefix.mFields.m8, OT_IP6_PREFIX_BITSIZE);
option.GetAddress().GetIid().SetFromExtAddress(aClientAddress);
option.GetAddress().GetIid().InitFromExtAddress(aClientAddress);
option.SetPreferredLifetime(IaAddressOption::kDefaultPreferredLifetime);
option.SetValidLifetime(IaAddressOption::kDefaultValidLifetime);
SuccessOrExit(error = aMessage.Append(option));
+1 -1
View File
@@ -152,7 +152,7 @@ private:
mPrefix = aPrefix;
mAloc.InitAsThreadOrigin();
mAloc.GetAddress().SetToAnycastLocator(aMeshLocalPrefix, (Ip6::Address::kAloc16Mask << 8) + aContextId);
mAloc.GetAddress().InitAsAnycastLocator(aMeshLocalPrefix, (Ip6::Address::kAloc16Mask << 8) + aContextId);
mAloc.mMeshLocal = true;
}
+1 -1
View File
@@ -304,7 +304,7 @@ void IaPrefixOption::GetPrefix(Ip6::Prefix &aPrefix) const
{
uint8_t length = Min(GetPrefixLength(), Ip6::Prefix::kMaxLength);
aPrefix.Set(mPrefix.mFields.m8, length);
aPrefix.InitFrom(mPrefix.mFields.m8, length);
aPrefix.Tidy();
}
+1 -1
View File
@@ -72,7 +72,7 @@ Error Address::ExtractFromIp4MappedIp6Address(const Ip6::Address &aIp6Address)
Error error = kErrorNone;
VerifyOrExit(aIp6Address.IsIp4Mapped(), error = kErrorParse);
SetBytes(&aIp6Address.GetBytes()[12]);
InitFrom(&aIp6Address.GetBytes()[12]);
exit:
return error;
+2 -2
View File
@@ -110,12 +110,12 @@ public:
const uint8_t *GetBytes(void) const { return mFields.m8; }
/**
* Sets the IPv4 address from a given byte array.
* Initializes the IPv4 address from a given byte array.
*
* @param[in] aBuffer Pointer to an array containing the IPv4 address. `kSize` bytes from the buffer
* are copied to form the IPv4 address.
*/
void SetBytes(const uint8_t *aBuffer) { memcpy(mFields.m8, aBuffer, kSize); }
void InitFrom(const uint8_t *aBuffer) { memcpy(mFields.m8, aBuffer, kSize); }
/**
* Sets the IPv4 address from a given IPv4-mapped IPv6 address.
+11 -11
View File
@@ -48,7 +48,7 @@ Error NetworkPrefix::GenerateRandomUla(void)
return Random::Crypto::FillBuffer(&m8[1], kSize - 1);
}
Error NetworkPrefix::SetFrom(const Prefix &aPrefix)
Error NetworkPrefix::InitFrom(const Prefix &aPrefix)
{
Error error = kErrorNone;
@@ -62,7 +62,7 @@ exit:
//---------------------------------------------------------------------------------------------------------------------
// Prefix methods
void Prefix::Set(const uint8_t *aPrefix, uint8_t aLength)
void Prefix::InitFrom(const uint8_t *aPrefix, uint8_t aLength)
{
memcpy(mPrefix.mFields.m8, aPrefix, SizeForLength(aLength));
mLength = aLength;
@@ -227,9 +227,9 @@ bool InterfaceIdentifier::IsReservedSubnetAnycast(void) const
void InterfaceIdentifier::GenerateRandom(void) { SuccessOrAssert(Random::Crypto::Fill(*this)); }
void InterfaceIdentifier::SetBytes(const uint8_t *aBuffer) { memcpy(mFields.m8, aBuffer, kSize); }
void InterfaceIdentifier::InitFrom(const uint8_t *aBuffer) { memcpy(mFields.m8, aBuffer, kSize); }
void InterfaceIdentifier::SetFromExtAddress(const Mac::ExtAddress &aExtAddress)
void InterfaceIdentifier::InitFromExtAddress(const Mac::ExtAddress &aExtAddress)
{
Mac::ExtAddress addr;
@@ -238,7 +238,7 @@ void InterfaceIdentifier::SetFromExtAddress(const Mac::ExtAddress &aExtAddress)
addr.CopyTo(mFields.m8);
}
void InterfaceIdentifier::SetToLocator(uint16_t aLocator)
void InterfaceIdentifier::InitAsLocator(uint16_t aLocator)
{
// Locator IID pattern `0000:00ff:fe00:xxxx`
mFields.m32[0] = BigEndian::HostSwap32(0x000000ff);
@@ -307,14 +307,14 @@ bool Address::IsLinkLocalUnicast(void) const
return (mFields.m16[0] & BigEndian::HostSwap16(0xffc0)) == BigEndian::HostSwap16(0xfe80);
}
void Address::SetToLinkLocalAddress(const Mac::ExtAddress &aExtAddress)
void Address::InitAsLinkLocalAddress(const Mac::ExtAddress &aExtAddress)
{
mFields.m32[0] = BigEndian::HostSwap32(0xfe800000);
mFields.m32[1] = 0;
GetIid().SetFromExtAddress(aExtAddress);
GetIid().InitFromExtAddress(aExtAddress);
}
void Address::SetToLinkLocalAddress(const InterfaceIdentifier &aIid)
void Address::InitAsLinkLocalAddress(const InterfaceIdentifier &aIid)
{
mFields.m32[0] = BigEndian::HostSwap32(0xfe800000);
mFields.m32[1] = 0;
@@ -334,7 +334,7 @@ bool Address::IsIp4Mapped(void) const
return (mFields.m32[0] == 0) && (mFields.m32[1] == 0) && (mFields.m32[2] == BigEndian::HostSwap32(0xffff));
}
void Address::SetToIp4Mapped(const Ip4::Address &aIp4Address)
void Address::InitAsIp4Mapped(const Ip4::Address &aIp4Address)
{
Clear();
mFields.m16[5] = 0xffff;
@@ -385,10 +385,10 @@ void Address::SetMulticastNetworkPrefix(const uint8_t *aPrefix, uint8_t aPrefixL
mFields.m8[kMulticastNetworkPrefixLengthOffset] = aPrefixLength;
}
void Address::SetToLocator(const NetworkPrefix &aNetworkPrefix, uint16_t aLocator)
void Address::InitAsLocator(const NetworkPrefix &aNetworkPrefix, uint16_t aLocator)
{
SetPrefix(aNetworkPrefix);
GetIid().SetToLocator(aLocator);
GetIid().InitAsLocator(aLocator);
}
uint8_t Address::GetScope(void) const
+32 -32
View File
@@ -83,14 +83,14 @@ public:
Error GenerateRandomUla(void);
/**
* Sets the Network Prefix from a given `Prefix`.
* Initializes the Network Prefix from a given `Prefix`.
*
* @param[in] aPrefix The prefix to use to set the Network Prefix.
*
* @retval kErrorNone Successfully set the Network Prefix from @p aPrefix.
* @retval kErrorInvalidArgs The @p aPrefix length is not valid (must be `kLength`).
*/
Error SetFrom(const Prefix &aPrefix);
Error InitFrom(const Prefix &aPrefix);
} OT_TOOL_PACKED_END;
@@ -140,19 +140,19 @@ public:
uint8_t GetBytesSize(void) const { return SizeForLength(mLength); }
/**
* Sets the prefix.
* Initializes the prefix.
*
* @param[in] aPrefix A pointer to buffer containing the prefix bytes.
* @param[in] aLength The length or prefix in bits.
*/
void Set(const uint8_t *aPrefix, uint8_t aLength);
void InitFrom(const uint8_t *aPrefix, uint8_t aLength);
/**
* Sets the prefix from a given Network Prefix.
* Initializes the prefix from a given Network Prefix.
*
* @param[in] aNetworkPrefix A Network Prefix.
*/
void Set(const NetworkPrefix &aNetworkPrefix) { Set(aNetworkPrefix.m8, NetworkPrefix::kLength); }
void InitFrom(const NetworkPrefix &aNetworkPrefix) { InitFrom(aNetworkPrefix.m8, NetworkPrefix::kLength); }
/**
* Sets the subnet ID of the prefix.
@@ -394,27 +394,27 @@ public:
const uint8_t *GetBytes(void) const { return mFields.m8; }
/**
* Sets the Interface Identifier from a given byte array.
* Initializes the Interface Identifier from a given byte array.
*
* @param[in] aBuffer Pointer to an array containing the Interface Identifier. `kSize` bytes from the buffer
* are copied to form the Interface Identifier.
*/
void SetBytes(const uint8_t *aBuffer);
void InitFrom(const uint8_t *aBuffer);
/**
* Sets the Interface Identifier from a given IEEE 802.15.4 Extended Address.
* Initializes the Interface Identifier from a given IEEE 802.15.4 Extended Address.
*
* @param[in] aExtAddress An Extended Address.
*/
void SetFromExtAddress(const Mac::ExtAddress &aExtAddress);
void InitFromExtAddress(const Mac::ExtAddress &aExtAddress);
/**
* Sets the Interface Identifier to Routing/Anycast Locator pattern `0000:00ff:fe00:xxxx` with a given
* Initializes 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 SetToLocator(uint16_t aLocator);
void InitAsLocator(uint16_t aLocator);
/**
* Indicates whether or not the Interface Identifier matches the locator pattern `0000:00ff:fe00:xxxx`.
@@ -470,7 +470,7 @@ public:
/**
* Sets the Interface Identifier (IID) address locator field.
*
* Unlike `SetToLocator()`, this method only changes the last 2 bytes of the IID and keeps the rest of the address
* Unlike `InitAsLocator()`, this method only changes the last 2 bytes of the IID and keeps the rest of the address
* as before.
*
* @param[in] aLocator RLOC16 or ALOC16.
@@ -539,12 +539,12 @@ public:
const uint8_t *GetBytes(void) const { return mFields.m8; }
/**
* Sets the IPv6 address from a given byte array.
* Initializes the IPv6 address from a given byte array.
*
* @param[in] aBuffer Pointer to an array containing the IPv6 address. `kSize` bytes from the buffer
* are copied to form the IPv6 address.
*/
void SetBytes(const uint8_t *aBuffer) { memcpy(mFields.m8, aBuffer, kSize); }
void InitFrom(const uint8_t *aBuffer) { memcpy(mFields.m8, aBuffer, kSize); }
/**
* Indicates whether or not the IPv6 address is the Unspecified Address.
@@ -571,19 +571,19 @@ public:
bool IsLinkLocalUnicast(void) const;
/**
* Sets the IPv6 address to a Link-Local address with Interface Identifier generated from a given
* MAC Extended Address.
* Initializes the IPv6 address as 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);
void InitAsLinkLocalAddress(const Mac::ExtAddress &aExtAddress);
/**
* Sets the IPv6 address to a Link-Local address with a given Interface Identifier.
* Initializes the IPv6 address to a Link-Local address with a given Interface Identifier.
*
* @param[in] aIid An Interface Identifier.
*/
void SetToLinkLocalAddress(const InterfaceIdentifier &aIid);
void InitAsLinkLocalAddress(const InterfaceIdentifier &aIid);
/**
* Indicates whether or not the IPv6 address is multicast address.
@@ -661,27 +661,27 @@ public:
static const Address &GetRealmLocalAllMplForwarders(void);
/**
* Sets the IPv6 address to a Routing Locator (RLOC) IPv6 address with a given Network Prefix and
* RLOC16 value.
* Initializes the IPv6 address to a Routing Locator (RLOC) IPv6 address with a given Network Prefix and RLOC16
* value.
*
* @param[in] aNetworkPrefix A Network Prefix.
* @param[in] aRloc16 A RLOC16 value.
*/
void SetToRoutingLocator(const NetworkPrefix &aNetworkPrefix, uint16_t aRloc16)
void InitAsRoutingLocator(const NetworkPrefix &aNetworkPrefix, uint16_t aRloc16)
{
SetToLocator(aNetworkPrefix, aRloc16);
InitAsLocator(aNetworkPrefix, aRloc16);
}
/**
* Sets the IPv6 address to a Anycast Locator (ALOC) IPv6 address with a given Network Prefix and
* ALOC16 value.
* Initializes the IPv6 address to a Anycast Locator (ALOC) IPv6 address with a given Network Prefix and ALOC16
* value.
*
* @param[in] aNetworkPrefix A Network Prefix.
* @param[in] aAloc16 A ALOC16 value.
*/
void SetToAnycastLocator(const NetworkPrefix &aNetworkPrefix, uint16_t aAloc16)
void InitAsAnycastLocator(const NetworkPrefix &aNetworkPrefix, uint16_t aAloc16)
{
SetToLocator(aNetworkPrefix, aAloc16);
InitAsLocator(aNetworkPrefix, aAloc16);
}
/**
@@ -697,11 +697,11 @@ public:
bool IsIp4Mapped(void) const;
/**
* Sets the IPv6 address to follow the IPv4-mapped IPv6 address for a given IPv4 address.
* Initializes the IPv6 address to follow the IPv4-mapped IPv6 address for a given IPv4 address.
*
* @param[in] aIp4Address An IPv4 address.
*/
void SetToIp4Mapped(const Ip4::Address &aIp4Address);
void InitAsIp4Mapped(const Ip4::Address &aIp4Address);
/**
* Returns the Network Prefix of the IPv6 address (most significant 64 bits of the address).
@@ -719,7 +719,7 @@ public:
* @param[in] aLength The length of prefix in bits.
* @param[out] aPrefix A reference to a prefix to output the fetched prefix.
*/
void GetPrefix(uint8_t aLength, Prefix &aPrefix) const { aPrefix.Set(mFields.m8, aLength); }
void GetPrefix(uint8_t aLength, Prefix &aPrefix) const { aPrefix.InitFrom(mFields.m8, aLength); }
/**
* Indicates whether the IPv6 address matches a given prefix.
@@ -908,7 +908,7 @@ private:
static constexpr uint8_t kMulticastNetworkPrefixLengthOffset = 3; // Prefix-Based Multicast Address (RFC3306)
static constexpr uint8_t kMulticastNetworkPrefixOffset = 4; // Prefix-Based Multicast Address (RFC3306)
void SetToLocator(const NetworkPrefix &aNetworkPrefix, uint16_t aLocator);
void InitAsLocator(const NetworkPrefix &aNetworkPrefix, uint16_t aLocator);
void ToString(StringWriter &aWriter) const;
void AppendHexWords(StringWriter &aWriter, uint8_t aLength) const;
+1 -1
View File
@@ -7242,7 +7242,7 @@ void Core::Ip4AddrCache::ProcessResponseRecord(const Message &aMessage, uint16_t
SuccessOrExit(aMessage.Read(aRecordOffset, aRecord));
VerifyOrExit(aRecord.GetLength() >= sizeof(Ip4::Address));
address.SetToIp4Mapped(aRecord.GetAddress());
address.InitAsIp4Mapped(aRecord.GetAddress());
AddNewResponseAddress(address, aRecord.GetTtl(), aRecord.GetClass() & kClassCacheFlushFlag);
+3 -3
View File
@@ -96,7 +96,7 @@ void PrefixInfoOption::SetPrefix(const Prefix &aPrefix)
mPrefix = AsCoreType(&aPrefix.mPrefix);
}
void PrefixInfoOption::GetPrefix(Prefix &aPrefix) const { aPrefix.Set(mPrefix.GetBytes(), mPrefixLength); }
void PrefixInfoOption::GetPrefix(Prefix &aPrefix) const { aPrefix.InitFrom(mPrefix.GetBytes(), mPrefixLength); }
bool PrefixInfoOption::IsValid(void) const
{
@@ -131,7 +131,7 @@ void RouteInfoOption::SetPrefix(const Prefix &aPrefix)
memcpy(GetPrefixBytes(), aPrefix.GetBytes(), aPrefix.GetBytesSize());
}
void RouteInfoOption::GetPrefix(Prefix &aPrefix) const { aPrefix.Set(GetPrefixBytes(), mPrefixLength); }
void RouteInfoOption::GetPrefix(Prefix &aPrefix) const { aPrefix.InitFrom(GetPrefixBytes(), mPrefixLength); }
bool RouteInfoOption::IsValid(void) const
{
@@ -234,7 +234,7 @@ Error Nat64PrefixOption::GetPrefix(Prefix &aPrefix) const
VerifyOrExit(prefixLengthCode < GetArrayLength(kPrefixLengths), error = kErrorParse);
aPrefix.Set(mPrefixMsb, kPrefixLengths[prefixLengthCode]);
aPrefix.InitFrom(mPrefixMsb, kPrefixLengths[prefixLengthCode]);
exit:
return error;
+1 -1
View File
@@ -103,7 +103,7 @@ void Agent::UpdateService(void)
uint16_t aloc16 = Mle::Aloc16::FromNdAgentContextId(lowpanContext.GetContextId());
mAloc.InitAsThreadOrigin();
mAloc.GetAddress().SetToAnycastLocator(Get<Mle::Mle>().GetMeshLocalPrefix(), aloc16);
mAloc.GetAddress().InitAsAnycastLocator(Get<Mle::Mle>().GetMeshLocalPrefix(), aloc16);
mAloc.mMeshLocal = true;
Get<ThreadNetif>().AddUnicastAddress(mAloc);
ExitNow();
+1 -1
View File
@@ -439,7 +439,7 @@ Error Slaac::GenerateIid(Netif::UnicastAddress &aAddress, uint8_t &aDadCounter)
sha256.Update(secretKey);
sha256.Finish(hash);
aAddress.GetAddress().GetIid().SetBytes(hash.GetBytes());
aAddress.GetAddress().GetIid().InitFrom(hash.GetBytes());
// If the IID is reserved, try again with a new dadCounter
if (aAddress.GetAddress().GetIid().IsReserved())
+1 -1
View File
@@ -786,7 +786,7 @@ template <> void AddressResolver::HandleTmf<kUriAddressError>(Coap::Msg &aMsg)
if (child.RemoveIp6Address(target) == kErrorNone)
{
destination.SetToRoutingLocator(Get<Mle::Mle>().GetMeshLocalPrefix(), child.GetRloc16());
destination.InitAsRoutingLocator(Get<Mle::Mle>().GetMeshLocalPrefix(), child.GetRloc16());
SendAddressError(target, meshLocalIid, destination);
ExitNow();
+2 -1
View File
@@ -498,7 +498,8 @@ void DuaManager::PerformNextRegistration(void)
}
else
{
destAddr.SetToRoutingLocator(Get<Mle::Mle>().GetMeshLocalPrefix(), Get<BackboneRouter::Leader>().GetServer16());
destAddr.InitAsRoutingLocator(Get<Mle::Mle>().GetMeshLocalPrefix(),
Get<BackboneRouter::Leader>().GetServer16());
}
SuccessOrExit(error = Get<Tmf::Agent>().SendMessageTo(*message, destAddr, HandleDuaResponse, this));
+3 -3
View File
@@ -46,7 +46,7 @@ void Context::InitForMeshLocalPrefix(Instance &aInstance)
mIsValid = true;
mCompressFlag = true;
mContextId = Mle::kMeshLocalPrefixContextId;
mPrefix.Set(aInstance.Get<Mle::Mle>().GetMeshLocalPrefix());
mPrefix.InitFrom(aInstance.Get<Mle::Mle>().GetMeshLocalPrefix());
}
void Context::InitFrom(const NetworkData::PrefixTlv &aPrefixTlv, const NetworkData::ContextTlv &aContextTlv)
@@ -87,11 +87,11 @@ Error Lowpan::ComputeIid(const Mac::Address &aMacAddr, const Context &aContext,
switch (aMacAddr.GetType())
{
case Mac::Address::kTypeShort:
aIid.SetToLocator(aMacAddr.GetShort());
aIid.InitAsLocator(aMacAddr.GetShort());
break;
case Mac::Address::kTypeExtended:
aIid.SetFromExtAddress(aMacAddr.GetExtended());
aIid.InitFromExtAddress(aMacAddr.GetExtended());
break;
default:
+1 -1
View File
@@ -558,7 +558,7 @@ void MeshForwarder::SendDestinationUnreachable(uint16_t aMeshSource, const Ip6::
{
Ip6::MessageInfo messageInfo;
messageInfo.GetPeerAddr().SetToRoutingLocator(Get<Mle::Mle>().GetMeshLocalPrefix(), aMeshSource);
messageInfo.GetPeerAddr().InitAsRoutingLocator(Get<Mle::Mle>().GetMeshLocalPrefix(), aMeshSource);
IgnoreError(Get<Ip6::Icmp>().SendError(Ip6::Icmp::Header::kTypeDstUnreach,
Ip6::Icmp::Header::kCodeDstUnreachNoRoute, messageInfo, aIp6Headers));
+20 -20
View File
@@ -109,13 +109,13 @@ Mle::Mle(Instance &aInstance)
ResetCounters();
mLinkLocalAddress.InitAsThreadOrigin();
mLinkLocalAddress.GetAddress().SetToLinkLocalAddress(Get<Mac::Mac>().GetExtAddress());
mLinkLocalAddress.GetAddress().InitAsLinkLocalAddress(Get<Mac::Mac>().GetExtAddress());
mMeshLocalEid.InitAsThreadOriginMeshLocal();
mMeshLocalEid.GetAddress().GetIid().GenerateRandom();
mMeshLocalRloc.InitAsThreadOriginMeshLocal();
mMeshLocalRloc.GetAddress().GetIid().SetToLocator(0);
mMeshLocalRloc.GetAddress().GetIid().InitAsLocator(0);
mMeshLocalRloc.mRloc = true;
mLinkLocalAllThreadNodes.InitAsThreadOrigin();
@@ -768,7 +768,7 @@ exit:
void Mle::UpdateLinkLocalAddress(void)
{
Get<ThreadNetif>().RemoveUnicastAddress(mLinkLocalAddress);
mLinkLocalAddress.GetAddress().GetIid().SetFromExtAddress(Get<Mac::Mac>().GetExtAddress());
mLinkLocalAddress.GetAddress().GetIid().InitFromExtAddress(Get<Mac::Mac>().GetExtAddress());
Get<ThreadNetif>().AddUnicastAddress(mLinkLocalAddress);
Get<Notifier>().Signal(kEventThreadLinkLocalAddrChanged);
@@ -893,22 +893,22 @@ void Mle::SetLeaderData(uint32_t aPartitionId, uint8_t aWeighting, uint8_t aLead
void Mle::GetLeaderRloc(Ip6::Address &aAddress) const
{
aAddress.SetToRoutingLocator(mMeshLocalPrefix, GetLeaderRloc16());
aAddress.InitAsRoutingLocator(mMeshLocalPrefix, GetLeaderRloc16());
}
void Mle::GetLeaderAloc(Ip6::Address &aAddress) const
{
aAddress.SetToAnycastLocator(mMeshLocalPrefix, Aloc16::ForLeader());
aAddress.InitAsAnycastLocator(mMeshLocalPrefix, Aloc16::ForLeader());
}
void Mle::GetCommissionerAloc(uint16_t aSessionId, Ip6::Address &aAddress) const
{
aAddress.SetToAnycastLocator(mMeshLocalPrefix, Aloc16::FromCommissionerSessionId(aSessionId));
aAddress.InitAsAnycastLocator(mMeshLocalPrefix, Aloc16::FromCommissionerSessionId(aSessionId));
}
void Mle::GetServiceAloc(uint8_t aServiceId, Ip6::Address &aAddress) const
{
aAddress.SetToAnycastLocator(mMeshLocalPrefix, Aloc16::FromServiceId(aServiceId));
aAddress.InitAsAnycastLocator(mMeshLocalPrefix, Aloc16::FromServiceId(aServiceId));
}
const LeaderData &Mle::GetLeaderData(void)
@@ -1125,7 +1125,7 @@ Error Mle::SendDataRequestToParent(void)
{
Ip6::Address destination;
destination.SetToLinkLocalAddress(mParent.GetExtAddress());
destination.InitAsLinkLocalAddress(mParent.GetExtAddress());
return SendDataRequest(destination);
}
@@ -1282,7 +1282,7 @@ Error Mle::SendChildUpdateRequestToParent(ChildUpdateRequestMode aMode)
SuccessOrExit(error = message->AppendAddressRegistrationTlv(addrRegMode));
}
destination.SetToLinkLocalAddress(mParent.GetExtAddress());
destination.InitAsLinkLocalAddress(mParent.GetExtAddress());
SuccessOrExit(error = message->SendTo(destination));
Log(kMessageSend, kTypeChildUpdateRequestAsChild, destination);
@@ -2680,7 +2680,7 @@ void Mle::InformPreviousParent(void)
SuccessOrExit(error = message->SetLength(0));
messageInfo.SetSockAddr(GetMeshLocalEid());
messageInfo.GetPeerAddr().SetToRoutingLocator(mMeshLocalPrefix, mPreviousParentRloc);
messageInfo.GetPeerAddr().InitAsRoutingLocator(mMeshLocalPrefix, mPreviousParentRloc);
SuccessOrExit(error = Get<Ip6::Ip6>().SendDatagram(*message, messageInfo, Ip6::kProtoNone));
@@ -3191,7 +3191,7 @@ void Mle::DelayedSender::ScheduleChildUpdateRequestToParent(uint32_t aDelay)
{
Ip6::Address destination;
destination.SetToLinkLocalAddress(Get<Mle>().mParent.GetExtAddress());
destination.InitAsLinkLocalAddress(Get<Mle>().mParent.GetExtAddress());
VerifyOrExit(!HasMatchingSchedule(kTypeChildUpdateRequestAsChild, destination));
AddSchedule(kTypeChildUpdateRequestAsChild, destination, aDelay, nullptr, 0);
@@ -3203,7 +3203,7 @@ void Mle::DelayedSender::RemoveScheduledChildUpdateRequestToParent(void)
{
Ip6::Address destination;
destination.SetToLinkLocalAddress(Get<Mle>().mParent.GetExtAddress());
destination.InitAsLinkLocalAddress(Get<Mle>().mParent.GetExtAddress());
RemoveMatchingSchedules(kTypeChildUpdateRequestAsChild, destination);
}
@@ -3213,7 +3213,7 @@ void Mle::DelayedSender::ScheduleParentResponse(const ParentResponseInfo &aInfo,
{
Ip6::Address destination;
destination.SetToLinkLocalAddress(aInfo.mChildExtAddress);
destination.InitAsLinkLocalAddress(aInfo.mChildExtAddress);
RemoveMatchingSchedules(kTypeParentResponse, destination);
AddSchedule(kTypeParentResponse, destination, aDelay, &aInfo, sizeof(aInfo));
@@ -3250,7 +3250,7 @@ void Mle::DelayedSender::ScheduleLinkRequest(const Router &aRouter, uint32_t aDe
Ip6::Address destination;
uint16_t routerRloc16;
destination.SetToLinkLocalAddress(aRouter.GetExtAddress());
destination.InitAsLinkLocalAddress(aRouter.GetExtAddress());
VerifyOrExit(!HasMatchingSchedule(kTypeLinkRequest, destination));
routerRloc16 = aRouter.GetRloc16();
@@ -3264,7 +3264,7 @@ void Mle::DelayedSender::RemoveScheduledLinkRequest(const Router &aRouter)
{
Ip6::Address destination;
destination.SetToLinkLocalAddress(aRouter.GetExtAddress());
destination.InitAsLinkLocalAddress(aRouter.GetExtAddress());
RemoveMatchingSchedules(kTypeLinkRequest, destination);
}
@@ -3272,7 +3272,7 @@ bool Mle::DelayedSender::HasAnyScheduledLinkRequest(const Router &aRouter) const
{
Ip6::Address destination;
destination.SetToLinkLocalAddress(aRouter.GetExtAddress());
destination.InitAsLinkLocalAddress(aRouter.GetExtAddress());
return HasMatchingSchedule(kTypeLinkRequest, destination);
}
@@ -3281,7 +3281,7 @@ void Mle::DelayedSender::ScheduleLinkAccept(const LinkAcceptInfo &aInfo, uint32_
{
Ip6::Address destination;
destination.SetToLinkLocalAddress(aInfo.mExtAddress);
destination.InitAsLinkLocalAddress(aInfo.mExtAddress);
RemoveMatchingSchedules(kTypeLinkAccept, destination);
AddSchedule(kTypeLinkAccept, destination, aDelay, &aInfo, sizeof(aInfo));
@@ -5044,7 +5044,7 @@ void Mle::Attacher::SendParentRequest(ParentRequestType aType)
messageToCurParent = static_cast<TxMessage *>(Get<Mle>().mSocket.CloneMessage(*message));
VerifyOrExit(messageToCurParent != nullptr, error = kErrorNoBufs);
destination.SetToLinkLocalAddress(Get<Mle>().mParent.GetExtAddress());
destination.InitAsLinkLocalAddress(Get<Mle>().mParent.GetExtAddress());
error = messageToCurParent->SendTo(destination);
if (error != kErrorNone)
@@ -5055,7 +5055,7 @@ void Mle::Attacher::SendParentRequest(ParentRequestType aType)
Log(kMessageSend, kTypeParentRequestToRouters, destination);
destination.SetToLinkLocalAddress(Get<Mle>().mParentSearch.GetSelectedParent().GetExtAddress());
destination.InitAsLinkLocalAddress(Get<Mle>().mParentSearch.GetSelectedParent().GetExtAddress());
}
else
#endif
@@ -5165,7 +5165,7 @@ Error Mle::Attacher::SendChildIdRequest(void)
message->RegisterTxCallback(HandleChildIdRequestTxDone, this);
destination.SetToLinkLocalAddress(mParentCandidate.GetExtAddress());
destination.InitAsLinkLocalAddress(mParentCandidate.GetExtAddress());
SuccessOrExit(error = message->SendTo(destination));
Log(kMessageSend,
+6 -6
View File
@@ -552,7 +552,7 @@ void Mle::ScheduleUnicastAdvertisementTo(const Router &aRouter)
{
Ip6::Address destination;
destination.SetToLinkLocalAddress(aRouter.GetExtAddress());
destination.InitAsLinkLocalAddress(aRouter.GetExtAddress());
mDelayedSender.ScheduleAdvertisement(destination, GenerateRandomDelay(kMaxUnicastAdvertisementDelay));
}
@@ -671,7 +671,7 @@ void Mle::SendLinkRequest(Router *aRouter)
SuccessOrExit(error = message->AppendChallengeTlv(challenge));
}
destination.SetToLinkLocalAddress(aRouter->GetExtAddress());
destination.InitAsLinkLocalAddress(aRouter->GetExtAddress());
aRouter->RestartLinkAcceptTimeout();
}
@@ -870,7 +870,7 @@ Error Mle::SendLinkAccept(const LinkAcceptInfo &aInfo)
}
#endif
destination.SetToLinkLocalAddress(aInfo.mExtAddress);
destination.InitAsLinkLocalAddress(aInfo.mExtAddress);
SuccessOrExit(error = message->SendTo(destination));
@@ -1809,7 +1809,7 @@ void Mle::SendParentResponse(const ParentResponseInfo &aInfo)
SuccessOrExit(error = message->AppendConnectivityTlv());
SuccessOrExit(error = message->AppendVersionTlv());
destination.SetToLinkLocalAddress(aInfo.mChildExtAddress);
destination.InitAsLinkLocalAddress(aInfo.mChildExtAddress);
SuccessOrExit(error = message->SendTo(destination));
@@ -2868,7 +2868,7 @@ Error Mle::SendChildIdResponse(Child &aChild)
}
#endif
destination.SetToLinkLocalAddress(aChild.GetExtAddress());
destination.InitAsLinkLocalAddress(aChild.GetExtAddress());
SuccessOrExit(error = message->SendTo(destination));
SetChildStateToValid(aChild);
@@ -2932,7 +2932,7 @@ Error Mle::SendChildUpdateRequestToChild(Child &aChild)
SuccessOrExit(error = message->AppendChallengeTlv(aChild.GetChallenge()));
}
destination.SetToLinkLocalAddress(aChild.GetExtAddress());
destination.InitAsLinkLocalAddress(aChild.GetExtAddress());
SuccessOrExit(error = message->SendTo(destination));
if (aChild.IsRxOnWhenIdle())
+2 -1
View File
@@ -532,7 +532,8 @@ Error Manager::SendMessage(const Ip6::Address *aAddresses,
}
else
{
destAddr.SetToRoutingLocator(Get<Mle::Mle>().GetMeshLocalPrefix(), Get<BackboneRouter::Leader>().GetServer16());
destAddr.InitAsRoutingLocator(Get<Mle::Mle>().GetMeshLocalPrefix(),
Get<BackboneRouter::Leader>().GetServer16());
}
error = Get<Tmf::Agent>().SendMessageTo(*message, destAddr, aResponseHandler, this);
+1 -1
View File
@@ -254,7 +254,7 @@ Error Server::AppendBrPrefixTlv(uint8_t aTlvType, Message &aMessage)
ExitNow();
}
IgnoreError(netPrefix.SetFrom(prefix));
IgnoreError(netPrefix.InitFrom(prefix));
exit:
return Tlv::AppendTlv(aMessage, aTlvType, &netPrefix, sizeof(netPrefix));
+3 -3
View File
@@ -158,8 +158,8 @@ Error Iterator::GetNextDnsSrpUnicastInfo(DnsSrpUnicastType aType, DnsSrpUnicastI
// contains a port number and use the RLOC as the
// IPv6 address.
aInfo.mSockAddr.GetAddress().SetToRoutingLocator(Get<Mle::Mle>().GetMeshLocalPrefix(),
mServerSubTlv->GetServer16());
aInfo.mSockAddr.GetAddress().InitAsRoutingLocator(Get<Mle::Mle>().GetMeshLocalPrefix(),
mServerSubTlv->GetServer16());
aInfo.mSockAddr.SetPort(BigEndian::ReadUint16(mServerSubTlv->GetServerData()));
aInfo.mVersion = 0;
ExitNow();
@@ -552,7 +552,7 @@ exit:
Manager::ServiceAloc::ServiceAloc(void)
{
InitAsThreadOriginMeshLocal();
GetAddress().GetIid().SetToLocator(kNotInUse);
GetAddress().GetIid().InitAsLocator(kNotInUse);
}
#endif
+1 -1
View File
@@ -656,7 +656,7 @@ public:
*
* @param[out] aPrefix An `Ip6::Prefix` to copy the Prefix from TLV into.
*/
void CopyPrefixTo(Ip6::Prefix &aPrefix) const { aPrefix.Set(GetPrefix(), GetPrefixLength()); }
void CopyPrefixTo(Ip6::Prefix &aPrefix) const { aPrefix.InitFrom(GetPrefix(), GetPrefixLength()); }
/**
* Indicates whether the Prefix from TLV is equal to a given `Ip6::Prefix`.
+4 -1
View File
@@ -81,7 +81,10 @@ public:
*
* @returns The link local IPv6 address of the peer.
*/
void GetLinkLocalIp6Address(Ip6::Address &aIp6Address) const { aIp6Address.SetToLinkLocalAddress(GetExtAddress()); }
void GetLinkLocalIp6Address(Ip6::Address &aIp6Address) const
{
aIp6Address.InitAsLinkLocalAddress(GetExtAddress());
}
/**
* Generates a new challenge value to use during a child attach.
+1 -1
View File
@@ -251,7 +251,7 @@ Error Agent::SendMessageToRloc(Message &aMessage, uint16_t aRloc16, ResponseHand
{
Ip6::MessageInfo messageInfo;
messageInfo.GetPeerAddr().SetToRoutingLocator(Get<Mle::Mle>().GetMeshLocalPrefix(), aRloc16);
messageInfo.GetPeerAddr().InitAsRoutingLocator(Get<Mle::Mle>().GetMeshLocalPrefix(), aRloc16);
PrepareMessageInfo(messageInfo);
return SendMessage(aMessage, messageInfo, aHandler, aContext);
+2 -2
View File
@@ -286,7 +286,7 @@ Error LinkMetricsManager::Subject::ConfigureEap(Instance &aInstance)
LinkMetrics::Metrics metricsFlags;
VerifyOrExit(neighbor != nullptr, error = kErrorUnknownNeighbor);
destination.SetToLinkLocalAddress(neighbor->GetExtAddress());
destination.InitAsLinkLocalAddress(neighbor->GetExtAddress());
metricsFlags.Clear();
metricsFlags.mLinkMargin = 1;
@@ -311,7 +311,7 @@ Error LinkMetricsManager::Subject::UnregisterEap(Instance &aInstance)
LinkMetrics::EnhAckFlags enhAckFlags = LinkMetrics::kEnhAckClear;
VerifyOrExit(neighbor != nullptr, error = kErrorUnknownNeighbor);
destination.SetToLinkLocalAddress(neighbor->GetExtAddress());
destination.InitAsLinkLocalAddress(neighbor->GetExtAddress());
error = aInstance.Get<LinkMetrics::Initiator>().SendMgmtRequestEnhAckProbing(destination, enhAckFlags, nullptr);
exit:
+2 -2
View File
@@ -99,7 +99,7 @@ Error MeshDiag::DiscoverTopology(const DiscoverConfig &aConfig, DiscoverCallback
continue;
}
destination.SetToRoutingLocator(Get<Mle::Mle>().GetMeshLocalPrefix(), Mle::Rloc16FromRouterId(routerId));
destination.InitAsRoutingLocator(Get<Mle::Mle>().GetMeshLocalPrefix(), Mle::Rloc16FromRouterId(routerId));
SuccessOrExit(error = Get<Client>().SendCommand(kUriDiagnosticGetRequest, Message::kPriorityLow, destination,
tlvs, tlvsLength, HandleDiagGetResponse, this));
@@ -165,7 +165,7 @@ Error MeshDiag::SendQuery(uint16_t aRloc16, const uint8_t *aTlvs, uint8_t aTlvsL
VerifyOrExit(Mle::IsRouterRloc16(aRloc16), error = kErrorInvalidArgs);
VerifyOrExit(Get<RouterTable>().IsAllocated(Mle::RouterIdFromRloc16(aRloc16)), error = kErrorNotFound);
destination.SetToRoutingLocator(Get<Mle::Mle>().GetMeshLocalPrefix(), aRloc16);
destination.InitAsRoutingLocator(Get<Mle::Mle>().GetMeshLocalPrefix(), aRloc16);
SuccessOrExit(error = Get<Client>().SendCommand(kUriDiagnosticGetQuery, Message::kPriorityNormal, destination,
aTlvs, aTlvsLength));
+2 -2
View File
@@ -279,8 +279,8 @@ void MulticastRoutingManager::ProcessMulticastRouterMessages(void)
VerifyOrExit(mrt6msg->im6_mbz == 0);
VerifyOrExit(mrt6msg->im6_msgtype == MRT6MSG_NOCACHE);
src.SetBytes(mrt6msg->im6_src.s6_addr);
dst.SetBytes(mrt6msg->im6_dst.s6_addr);
src.InitFrom(mrt6msg->im6_src.s6_addr);
dst.InitFrom(mrt6msg->im6_dst.s6_addr);
error = AddMulticastForwardingCache(src, dst, static_cast<MifIndex>(mrt6msg->im6_mif));