diff --git a/include/openthread/instance.h b/include/openthread/instance.h index 08b464b08..6621bb498 100644 --- a/include/openthread/instance.h +++ b/include/openthread/instance.h @@ -53,7 +53,7 @@ extern "C" { * @note This number versions both OpenThread platform and user APIs. * */ -#define OPENTHREAD_API_VERSION (12) +#define OPENTHREAD_API_VERSION (13) /** * @addtogroup api-instance diff --git a/include/openthread/ip6.h b/include/openthread/ip6.h index bb8737701..e1f99c28c 100644 --- a/include/openthread/ip6.h +++ b/include/openthread/ip6.h @@ -66,7 +66,12 @@ extern "C" { OT_TOOL_PACKED_BEGIN struct otIp6InterfaceIdentifier { - uint8_t m8[OT_IP6_IID_SIZE]; ///< The Interface Identifier of an IPv6 address. + union OT_TOOL_PACKED_FIELD + { + uint8_t m8[OT_IP6_IID_SIZE]; ///< 8-bit fields + uint16_t m16[OT_IP6_IID_SIZE / sizeof(uint16_t)]; ///< 16-bit fields + uint32_t m32[OT_IP6_IID_SIZE / sizeof(uint32_t)]; ///< 32-bit fields + } mFields; ///< The Interface Identifier accessor fields } OT_TOOL_PACKED_END; /** @@ -75,6 +80,43 @@ struct otIp6InterfaceIdentifier */ typedef struct otIp6InterfaceIdentifier otIp6InterfaceIdentifier; +/** + * @struct otIp6NetworkPrefix + * + * This structure represents the Network Prefix of an IPv6 address (most significant 64 bits of the address). + * + */ +OT_TOOL_PACKED_BEGIN +struct otIp6NetworkPrefix +{ + uint8_t m8[OT_IP6_PREFIX_SIZE]; ///< The Network Prefix. +} OT_TOOL_PACKED_END; + +/** + * This structure represents the Network Prefix of an IPv6 address (most significant 64 bits of the address). + * + */ +typedef struct otIp6NetworkPrefix otIp6NetworkPrefix; + +/** + * @struct otIp6AddressComponents + * + * This structure represents the components of an IPv6 address. + * + */ +OT_TOOL_PACKED_BEGIN +struct otIp6AddressComponents +{ + otIp6NetworkPrefix mNetworkPrefix; ///< The Network Prefix (most significant 64 bits of the address) + otIp6InterfaceIdentifier mIid; ///< The Interface Identifier (least significant 64 bits of the address) +} OT_TOOL_PACKED_END; + +/** + * This structure represents the components of an IPv6 address. + * + */ +typedef struct otIp6AddressComponents otIp6AddressComponents; + /** * @struct otIp6Address * @@ -86,10 +128,11 @@ struct otIp6Address { union OT_TOOL_PACKED_FIELD { - uint8_t m8[OT_IP6_ADDRESS_SIZE]; ///< 8-bit fields - uint16_t m16[OT_IP6_ADDRESS_SIZE / sizeof(uint16_t)]; ///< 16-bit fields - uint32_t m32[OT_IP6_ADDRESS_SIZE / sizeof(uint32_t)]; ///< 32-bit fields - } mFields; ///< IPv6 accessor fields + uint8_t m8[OT_IP6_ADDRESS_SIZE]; ///< 8-bit fields + uint16_t m16[OT_IP6_ADDRESS_SIZE / sizeof(uint16_t)]; ///< 16-bit fields + uint32_t m32[OT_IP6_ADDRESS_SIZE / sizeof(uint32_t)]; ///< 32-bit fields + otIp6AddressComponents mComponents; ///< IPv6 address components + } mFields; ///< IPv6 accessor fields } OT_TOOL_PACKED_END; /** diff --git a/src/cli/cli.cpp b/src/cli/cli.cpp index dd6649f35..86160593b 100644 --- a/src/cli/cli.cpp +++ b/src/cli/cli.cpp @@ -627,7 +627,7 @@ void Interpreter::ProcessDua(uint8_t aArgsLength, char *aArgs[]) if (iid != nullptr) { - OutputBytes(iid->m8, sizeof(otIp6InterfaceIdentifier)); + OutputBytes(iid->mFields.m8, sizeof(otIp6InterfaceIdentifier)); mServer->OutputFormat("\r\n"); } break; @@ -641,7 +641,7 @@ void Interpreter::ProcessDua(uint8_t aArgsLength, char *aArgs[]) { otIp6InterfaceIdentifier iid; - VerifyOrExit(Hex2Bin(aArgs[1], iid.m8, sizeof(otIp6InterfaceIdentifier)) == + VerifyOrExit(Hex2Bin(aArgs[1], iid.mFields.m8, sizeof(otIp6InterfaceIdentifier)) == sizeof(otIp6InterfaceIdentifier), error = OT_ERROR_INVALID_ARGS); SuccessOrExit(error = otThreadSetFixedDuaInterfaceIdentifier(mInstance, &iid)); diff --git a/src/core/backbone_router/local.cpp b/src/core/backbone_router/local.cpp index 39cc851d6..d253c4638 100644 --- a/src/core/backbone_router/local.cpp +++ b/src/core/backbone_router/local.cpp @@ -67,7 +67,7 @@ Local::Local(Instance &aInstance) mBackboneRouterPrimaryAloc.mValid = true; mBackboneRouterPrimaryAloc.mScopeOverride = Ip6::Address::kRealmLocalScope; mBackboneRouterPrimaryAloc.mScopeOverrideValid = true; - mBackboneRouterPrimaryAloc.GetAddress().SetLocator(Mle::kAloc16BackboneRouterPrimary); + mBackboneRouterPrimaryAloc.GetAddress().GetIid().SetLocator(Mle::kAloc16BackboneRouterPrimary); // All Network Backbone Routers Multicast Address. mAllNetworkBackboneRouters.Clear(); diff --git a/src/core/coap/coap.cpp b/src/core/coap/coap.cpp index 4a9370c41..9f7e27102 100644 --- a/src/core/coap/coap.cpp +++ b/src/core/coap/coap.cpp @@ -500,7 +500,8 @@ Message *CoapBase::FindRelatedRequest(const Message & aResponse, aMetadata.ReadFrom(*message); if (((aMetadata.mDestinationAddress == aMessageInfo.GetPeerAddr()) || - aMetadata.mDestinationAddress.IsMulticast() || aMetadata.mDestinationAddress.IsIidAnycastLocator()) && + aMetadata.mDestinationAddress.IsMulticast() || + aMetadata.mDestinationAddress.GetIid().IsAnycastLocator()) && (aMetadata.mDestinationPort == aMessageInfo.GetPeerPort())) { switch (aResponse.GetType()) diff --git a/src/core/common/settings.cpp b/src/core/common/settings.cpp index a19007f66..8f6d5c79f 100644 --- a/src/core/common/settings.cpp +++ b/src/core/common/settings.cpp @@ -57,12 +57,9 @@ void SettingsBase::LogNetworkInfo(const char *aAction, const NetworkInfo &aNetwo Mle::Mle::RoleToString(static_cast(aNetworkInfo.GetRole())), aNetworkInfo.GetDeviceMode(), aNetworkInfo.GetVersion(), aNetworkInfo.GetKeySequence()); - otLogInfoCore( - "Non-volatile: ... pid:0x%x, mlecntr:0x%x, maccntr:0x%x, mliid:%02x%02x%02x%02x%02x%02x%02x%02x}", - aNetworkInfo.GetPreviousPartitionId(), aNetworkInfo.GetMleFrameCounter(), aNetworkInfo.GetMacFrameCounter(), - aNetworkInfo.GetMeshLocalIid()[0], aNetworkInfo.GetMeshLocalIid()[1], aNetworkInfo.GetMeshLocalIid()[2], - aNetworkInfo.GetMeshLocalIid()[3], aNetworkInfo.GetMeshLocalIid()[4], aNetworkInfo.GetMeshLocalIid()[5], - aNetworkInfo.GetMeshLocalIid()[6], aNetworkInfo.GetMeshLocalIid()[7]); + otLogInfoCore("Non-volatile: ... pid:0x%x, mlecntr:0x%x, maccntr:0x%x, mliid:%s}", + aNetworkInfo.GetPreviousPartitionId(), aNetworkInfo.GetMleFrameCounter(), + aNetworkInfo.GetMacFrameCounter(), aNetworkInfo.GetMeshLocalIid().ToString().AsCString()); } void SettingsBase::LogParentInfo(const char *aAction, const ParentInfo &aParentInfo) const diff --git a/src/core/common/settings.hpp b/src/core/common/settings.hpp index 37b867c88..ed151d3c0 100644 --- a/src/core/common/settings.hpp +++ b/src/core/common/settings.hpp @@ -40,6 +40,7 @@ #include "common/locator.hpp" #include "common/non_copyable.hpp" #include "mac/mac_types.hpp" +#include "net/ip6_address.hpp" #include "utils/flash.hpp" #if OPENTHREAD_CONFIG_IP6_SLAAC_ENABLE #include "utils/slaac_address.hpp" @@ -338,7 +339,7 @@ public: * @returns The Mesh Local Interface Identifier. * */ - const uint8_t *GetMeshLocalIid(void) const { return mMlIid; } + const Ip6::InterfaceIdentifier &GetMeshLocalIid(void) const { return mMlIid; } /** * This method sets the Mesh Local Interface Identifier. @@ -346,7 +347,7 @@ public: * @param[in] aMeshLocalIid The Mesh Local Interface Identifier. * */ - void SetMeshLocalIid(const uint8_t *aMeshLocalIid) { memcpy(mMlIid, aMeshLocalIid, sizeof(mMlIid)); } + void SetMeshLocalIid(const Ip6::InterfaceIdentifier &aMeshLocalIid) { mMlIid = aMeshLocalIid; } /** * This method returns the Thread version. @@ -365,16 +366,16 @@ public: void SetVersion(uint16_t aVersion) { mVersion = Encoding::LittleEndian::HostSwap16(aVersion); } private: - uint8_t mRole; ///< Current Thread role. - uint8_t mDeviceMode; ///< Device mode setting. - uint16_t mRloc16; ///< RLOC16 - uint32_t mKeySequence; ///< Key Sequence - uint32_t mMleFrameCounter; ///< MLE Frame Counter - uint32_t mMacFrameCounter; ///< MAC Frame Counter - uint32_t mPreviousPartitionId; ///< PartitionId - Mac::ExtAddress mExtAddress; ///< Extended Address - uint8_t mMlIid[OT_IP6_IID_SIZE]; ///< IID from ML-EID - uint16_t mVersion; ///< Version + uint8_t mRole; ///< Current Thread role. + uint8_t mDeviceMode; ///< Device mode setting. + uint16_t mRloc16; ///< RLOC16 + uint32_t mKeySequence; ///< Key Sequence + uint32_t mMleFrameCounter; ///< MLE Frame Counter + uint32_t mMacFrameCounter; ///< MAC Frame Counter + uint32_t mPreviousPartitionId; ///< PartitionId + Mac::ExtAddress mExtAddress; ///< Extended Address + Ip6::InterfaceIdentifier mMlIid; ///< IID from ML-EID + uint16_t mVersion; ///< Version } OT_TOOL_PACKED_END; /** diff --git a/src/core/meshcop/border_agent.cpp b/src/core/meshcop/border_agent.cpp index e0952d70a..6661e7196 100644 --- a/src/core/meshcop/border_agent.cpp +++ b/src/core/meshcop/border_agent.cpp @@ -563,7 +563,7 @@ void BorderAgent::HandleRelayTransmit(const Coap::Message &aMessage) messageInfo.SetSockAddr(Get().GetMeshLocal16()); messageInfo.SetPeerPort(kCoapUdpPort); messageInfo.SetPeerAddr(Get().GetMeshLocal16()); - messageInfo.GetPeerAddr().SetLocator(joinerRouterRloc); + messageInfo.GetPeerAddr().GetIid().SetLocator(joinerRouterRloc); SuccessOrExit(error = Get().SendMessage(*message, messageInfo)); diff --git a/src/core/meshcop/commissioner.cpp b/src/core/meshcop/commissioner.cpp index 31a480e2c..032493cc0 100644 --- a/src/core/meshcop/commissioner.cpp +++ b/src/core/meshcop/commissioner.cpp @@ -121,8 +121,7 @@ void Commissioner::SignalJoinerEvent(otCommissionerJoinerEvent aEvent, const Joi } else if (aJoiner == mActiveJoiner) { - joinerId.Set(mJoinerIid.m8); - joinerId.ToggleLocal(); + mJoinerIid.ConvertToExtAddress(joinerId); } else { @@ -1048,9 +1047,7 @@ void Commissioner::HandleRelayReceive(Coap::Message &aMessage, const Ip6::Messag Joiner * joiner; mJoinerIid = joinerIid; - - receivedId.Set(mJoinerIid.m8); - receivedId.ToggleLocal(); + mJoinerIid.ConvertToExtAddress(receivedId); joiner = FindBestMatchingJoinerEntry(receivedId); VerifyOrExit(joiner != nullptr, OT_NOOP); @@ -1230,7 +1227,7 @@ otError Commissioner::SendRelayTransmit(Message &aMessage, const Ip6::MessageInf aMessage.CopyTo(0, offset, aMessage.GetLength(), *message); messageInfo.SetPeerAddr(Get().GetMeshLocal16()); - messageInfo.GetPeerAddr().SetLocator(mJoinerRloc); + messageInfo.GetPeerAddr().GetIid().SetLocator(mJoinerRloc); messageInfo.SetPeerPort(kCoapUdpPort); SuccessOrExit(error = Get().SendMessage(*message, messageInfo)); diff --git a/src/core/meshcop/joiner_router.cpp b/src/core/meshcop/joiner_router.cpp index f62ea9655..1d4b69e80 100644 --- a/src/core/meshcop/joiner_router.cpp +++ b/src/core/meshcop/joiner_router.cpp @@ -157,8 +157,8 @@ void JoinerRouter::HandleUdpReceive(Message &aMessage, const Ip6::MessageInfo &a SuccessOrExit(error = message->SetPayloadMarker()); SuccessOrExit(error = Tlv::AppendUint16Tlv(*message, Tlv::kJoinerUdpPort, aMessageInfo.GetPeerPort())); - SuccessOrExit(error = Tlv::AppendTlv(*message, Tlv::kJoinerIid, aMessageInfo.GetPeerAddr().mFields.m8 + 8, - Ip6::Address::kInterfaceIdentifierSize)); + SuccessOrExit(error = Tlv::AppendTlv(*message, Tlv::kJoinerIid, &aMessageInfo.GetPeerAddr().GetIid(), + Ip6::InterfaceIdentifier::kSize)); SuccessOrExit(error = Tlv::AppendUint16Tlv(*message, Tlv::kJoinerRouterLocator, Get().GetRloc16())); tlv.SetType(Tlv::kJoinerDtlsEncapsulation); @@ -170,7 +170,7 @@ void JoinerRouter::HandleUdpReceive(Message &aMessage, const Ip6::MessageInfo &a messageInfo.SetSockAddr(Get().GetMeshLocal16()); messageInfo.SetPeerAddr(Get().GetMeshLocal16()); - messageInfo.GetPeerAddr().SetLocator(borderAgentRloc); + messageInfo.GetPeerAddr().GetIid().SetLocator(borderAgentRloc); messageInfo.SetPeerPort(kCoapUdpPort); SuccessOrExit(error = Get().SendMessage(*message, messageInfo)); @@ -195,22 +195,22 @@ void JoinerRouter::HandleRelayTransmit(Coap::Message &aMessage, const Ip6::Messa { OT_UNUSED_VARIABLE(aMessageInfo); - otError error; - uint16_t joinerPort; - uint8_t joinerIid[Ip6::Address::kInterfaceIdentifierSize]; - Kek kek; - uint16_t offset; - uint16_t length; - Message * message = nullptr; - Message::Settings settings(Message::kNoLinkSecurity, Message::kPriorityNet); - Ip6::MessageInfo messageInfo; + otError error; + uint16_t joinerPort; + Ip6::InterfaceIdentifier joinerIid; + Kek kek; + uint16_t offset; + uint16_t length; + Message * message = nullptr; + Message::Settings settings(Message::kNoLinkSecurity, Message::kPriorityNet); + Ip6::MessageInfo messageInfo; VerifyOrExit(aMessage.IsNonConfirmable() && aMessage.GetCode() == OT_COAP_CODE_POST, error = OT_ERROR_DROP); otLogInfoMeshCoP("Received relay transmit"); SuccessOrExit(error = Tlv::FindUint16Tlv(aMessage, Tlv::kJoinerUdpPort, joinerPort)); - SuccessOrExit(error = Tlv::FindTlv(aMessage, Tlv::kJoinerIid, joinerIid, sizeof(joinerIid))); + SuccessOrExit(error = Tlv::FindTlv(aMessage, Tlv::kJoinerIid, &joinerIid, sizeof(joinerIid))); SuccessOrExit(error = Tlv::FindTlvValueOffset(aMessage, Tlv::kJoinerDtlsEncapsulation, offset, length)); diff --git a/src/core/meshcop/meshcop_leader.cpp b/src/core/meshcop/meshcop_leader.cpp index 9492f2d35..173d23389 100644 --- a/src/core/meshcop/meshcop_leader.cpp +++ b/src/core/meshcop/meshcop_leader.cpp @@ -94,7 +94,7 @@ void Leader::HandlePetition(Coap::Message &aMessage, const Ip6::MessageInfo &aMe } data.mBorderAgentLocator.Init(); - data.mBorderAgentLocator.SetBorderAgentLocator(aMessageInfo.GetPeerAddr().GetLocator()); + data.mBorderAgentLocator.SetBorderAgentLocator(aMessageInfo.GetPeerAddr().GetIid().GetLocator()); data.mCommissionerSessionId.Init(); data.mCommissionerSessionId.SetCommissionerSessionId(++mSessionId); @@ -194,7 +194,7 @@ void Leader::HandleKeepAlive(Coap::Message &aMessage, const Ip6::MessageInfo &aM } else { - uint16_t rloc = aMessageInfo.GetPeerAddr().GetLocator(); + uint16_t rloc = aMessageInfo.GetPeerAddr().GetIid().GetLocator(); if (borderAgentLocator->GetBorderAgentLocator() != rloc) { diff --git a/src/core/net/dhcp6_server.cpp b/src/core/net/dhcp6_server.cpp index 3cef3dabc..bf99652aa 100644 --- a/src/core/net/dhcp6_server.cpp +++ b/src/core/net/dhcp6_server.cpp @@ -469,7 +469,8 @@ otError Dhcp6Server::AddIaAddress(Message &aMessage, const Ip6::Address &aPrefix option.Init(); option.GetAddress().SetPrefix(aPrefix.mFields.m8, OT_IP6_PREFIX_BITSIZE); - option.GetAddress().SetIid(*reinterpret_cast(aClientId.GetDuidLinkLayerAddress())); + option.GetAddress().GetIid().SetFromExtAddress( + *reinterpret_cast(aClientId.GetDuidLinkLayerAddress())); option.SetPreferredLifetime(OT_DHCP6_DEFAULT_PREFERRED_LIFETIME); option.SetValidLifetime(OT_DHCP6_DEFAULT_VALID_LIFETIME); SuccessOrExit(error = aMessage.Append(&option, sizeof(option))); diff --git a/src/core/net/icmp6.cpp b/src/core/net/icmp6.cpp index a2ae84ab7..7eb28df58 100644 --- a/src/core/net/icmp6.cpp +++ b/src/core/net/icmp6.cpp @@ -202,7 +202,7 @@ otError Icmp::HandleEchoRequest(Message &aRequestMessage, const MessageInfo &aMe uint16_t payloadLength; // always handle Echo Request destined for RLOC or ALOC - VerifyOrExit(ShouldHandleEchoRequest(aMessageInfo) || aMessageInfo.GetSockAddr().IsIidLocator(), OT_NOOP); + VerifyOrExit(ShouldHandleEchoRequest(aMessageInfo) || aMessageInfo.GetSockAddr().GetIid().IsLocator(), OT_NOOP); otLogInfoIcmp("Received Echo Request"); diff --git a/src/core/net/ip6.cpp b/src/core/net/ip6.cpp index 74982e4c5..dbfcc95c9 100644 --- a/src/core/net/ip6.cpp +++ b/src/core/net/ip6.cpp @@ -1037,8 +1037,8 @@ otError Ip6::ProcessReceiveCallback(const Message & aMessage, if (mIsReceiveIp6FilterEnabled) { // do not pass messages sent to an RLOC/ALOC, except Service Locator - VerifyOrExit(!aMessageInfo.GetSockAddr().IsIidLocator() || - aMessageInfo.GetSockAddr().IsIidAnycastServiceLocator(), + VerifyOrExit(!aMessageInfo.GetSockAddr().GetIid().IsLocator() || + aMessageInfo.GetSockAddr().GetIid().IsAnycastServiceLocator(), error = OT_ERROR_NO_ROUTE); switch (aIpProto) @@ -1374,7 +1374,7 @@ const NetifUnicastAddress *Ip6::SelectSourceAddress(MessageInfo &aMessageInfo) uint8_t candidatePrefixMatched; uint8_t overrideScope; - if (candidateAddr->IsIidAnycastLocator()) + if (candidateAddr->GetIid().IsAnycastLocator()) { // Don't use anycast address as source address. continue; @@ -1444,7 +1444,7 @@ const NetifUnicastAddress *Ip6::SelectSourceAddress(MessageInfo &aMessageInfo) rvalPrefixMatched = candidatePrefixMatched; } else if ((candidatePrefixMatched == rvalPrefixMatched) && - (destination->IsIidRoutingLocator() == candidateAddr->IsIidRoutingLocator())) + (destination->GetIid().IsRoutingLocator() == candidateAddr->GetIid().IsRoutingLocator())) { // Additional rule: Prefer RLOC source for RLOC destination, EID source for anything else rvalAddr = addr; diff --git a/src/core/net/ip6_address.cpp b/src/core/net/ip6_address.cpp index 9744ccfb8..7b59f2899 100644 --- a/src/core/net/ip6_address.cpp +++ b/src/core/net/ip6_address.cpp @@ -38,6 +38,7 @@ #include "common/code_utils.hpp" #include "common/encoding.hpp" #include "common/instance.hpp" +#include "common/random.hpp" #include "net/netif.hpp" using ot::Encoding::BigEndian::HostSwap32; @@ -45,25 +46,115 @@ using ot::Encoding::BigEndian::HostSwap32; namespace ot { namespace Ip6 { +//--------------------------------------------------------------------------------------------------------------------- +// InterfaceIdentifier methods + bool InterfaceIdentifier::IsUnspecified(void) const { - return (m8[0] == 0 && m8[1] == 0 && m8[2] == 0 && m8[3] == 0 && m8[4] == 0 && m8[5] == 0 && m8[6] == 0 && - m8[7] == 0); + return (mFields.m32[0] == 0) && (mFields.m32[1] == 0); } bool InterfaceIdentifier::IsReserved(void) const { - Address addr; + return IsSubnetRouterAnycast() || IsReservedSubnetAnycast() || IsAnycastLocator(); +} - addr.SetIid(this->m8); - return addr.IsIidReserved(); +bool InterfaceIdentifier::IsSubnetRouterAnycast(void) const +{ + return (mFields.m32[0] == 0) && (mFields.m32[1] == 0); +} + +bool InterfaceIdentifier::IsReservedSubnetAnycast(void) const +{ + // Format of IID in a Reserved Subnet Anycast Address (RFC 2526) + // + // | 57 bits | 7 bits | + // +------------------+------------+ + // | 1111110111...111 | anycast ID | + // +------------------+------------+ + + return (mFields.m32[0] == HostSwap32(0xfdffffff) && mFields.m16[2] == HostSwap16(0xffff) && mFields.m8[6] == 0xff && + mFields.m8[7] >= 0x80); +} + +void InterfaceIdentifier::GenerateRandom(void) +{ + otError error; + + OT_UNUSED_VARIABLE(error); + + error = Random::Crypto::FillBuffer(mFields.m8, kSize); + + OT_ASSERT(error == OT_ERROR_NONE); +} + +void InterfaceIdentifier::SetBytes(const uint8_t *aBuffer) +{ + memcpy(mFields.m8, aBuffer, kSize); +} + +void InterfaceIdentifier::SetFromExtAddress(const Mac::ExtAddress &aExtAddress) +{ + Mac::ExtAddress addr; + + addr = aExtAddress; + addr.ToggleLocal(); + addr.CopyTo(mFields.m8); +} + +void InterfaceIdentifier::ConvertToExtAddress(Mac::ExtAddress &aExtAddress) const +{ + aExtAddress.Set(mFields.m8); + aExtAddress.ToggleLocal(); +} + +void InterfaceIdentifier::ConvertToMacAddress(Mac::Address &aMacAddress) const +{ + aMacAddress.SetExtended(mFields.m8); + aMacAddress.GetExtended().ToggleLocal(); +} + +void InterfaceIdentifier::SetToLocator(uint16_t aLocator) +{ + // Locator IID pattern `0000:00ff:fe00:xxxx` + mFields.m32[0] = HostSwap32(0x000000ff); + mFields.m16[2] = HostSwap16(0xfe00); + mFields.m16[3] = HostSwap16(aLocator); +} + +bool InterfaceIdentifier::IsLocator(void) const +{ + // Locator IID pattern 0000:00ff:fe00:xxxx + return (mFields.m32[0] == HostSwap32(0x000000ff) && mFields.m16[2] == HostSwap16(0xfe00)); +} + +bool InterfaceIdentifier::IsRoutingLocator(void) const +{ + return (IsLocator() && (mFields.m8[6] < kAloc16Mask) && ((mFields.m8[6] & kRloc16ReservedBitMask) == 0)); +} + +bool InterfaceIdentifier::IsAnycastLocator(void) const +{ + // Anycast locator range 0xfc00- 0xfcff (`kAloc16Mask` is 0xfc) + return (IsLocator() && (mFields.m8[6] == kAloc16Mask)); +} + +bool InterfaceIdentifier::IsAnycastServiceLocator(void) const +{ + uint16_t locator = GetLocator(); + + return (IsLocator() && (locator >= Mle::kAloc16ServiceStart) && (locator <= Mle::kAloc16ServiceEnd)); } InterfaceIdentifier::InfoString InterfaceIdentifier::ToString(void) const { - return InfoString("%02x%02x%02x%02x%02x%02x%02x%02x", m8[0], m8[1], m8[2], m8[3], m8[4], m8[5], m8[6], m8[7]); + return InfoString("%02x%02x%02x%02x%02x%02x%02x%02x", mFields.m8[0], mFields.m8[1], mFields.m8[2], mFields.m8[3], + mFields.m8[4], mFields.m8[5], mFields.m8[6], mFields.m8[7]); } +//--------------------------------------------------------------------------------------------------------------------- +// Address methods + bool Address::IsUnspecified(void) const { return (mFields.m32[0] == 0 && mFields.m32[1] == 0 && mFields.m32[2] == 0 && mFields.m32[3] == 0); @@ -83,10 +174,10 @@ void Address::SetToLinkLocalAddress(const Mac::ExtAddress &aExtAddress) { mFields.m32[0] = HostSwap32(0xfe800000); mFields.m32[1] = 0; - SetIid(aExtAddress); + GetIid().SetFromExtAddress(aExtAddress); } -void Address::SetToLinkLocalAddress(const uint8_t *aIid) +void Address::SetToLinkLocalAddress(const InterfaceIdentifier &aIid) { mFields.m32[0] = HostSwap32(0xfe800000); mFields.m32[1] = 0; @@ -158,46 +249,6 @@ void Address::SetToRealmLocalAllMplForwarders(void) *this = GetRealmLocalAllMplForwarders(); } -bool Address::IsSubnetRouterAnycast(void) const -{ - return (mFields.m32[2] == 0 && mFields.m32[3] == 0); -} - -bool Address::IsReservedSubnetAnycast(void) const -{ - return (mFields.m32[2] == HostSwap32(0xfdffffff) && mFields.m16[6] == 0xffff && mFields.m8[14] == 0xff && - mFields.m8[15] >= 0x80); -} - -bool Address::IsIidReserved(void) const -{ - return IsSubnetRouterAnycast() || IsReservedSubnetAnycast() || IsIidAnycastLocator(); -} - -bool Address::IsIidLocator(void) const -{ - // IID pattern 0000:00ff:fe00:xxxx - return (mFields.m32[2] == HostSwap32(0x000000ff) && mFields.m16[6] == HostSwap16(0xfe00)); -} - -bool Address::IsIidRoutingLocator(void) const -{ - return (IsIidLocator() && (mFields.m8[14] < kAloc16Mask) && ((mFields.m8[14] & kRloc16ReservedBitMask) == 0)); -} - -bool Address::IsIidAnycastLocator(void) const -{ - // Anycast locator range 0xfc00- 0xfcff (`kAloc16Max` is 0xfc) - return (IsIidLocator() && (mFields.m8[14] == kAloc16Mask)); -} - -bool Address::IsIidAnycastServiceLocator(void) const -{ - uint16_t locator = GetLocator(); - - return (IsIidLocator() && (locator >= Mle::kAloc16ServiceStart) && (locator <= Mle::kAloc16ServiceEnd)); -} - void Address::SetPrefix(const uint8_t *aPrefix, uint8_t aPrefixLength) { SetPrefix(0, aPrefix, aPrefixLength); @@ -217,7 +268,7 @@ void Address::SetPrefix(uint8_t aOffset, const uint8_t *aPrefix, uint8_t aPrefix uint8_t index = aOffset + bytes; uint8_t mask = ((0x80 >> (extraBits - 1)) - 1); - // `mask` has its higher (msb) `extraBits` bits as `0` and the reminaing as `1`. + // `mask` has its higher (msb) `extraBits` bits as `0` and the remaining as `1`. // Example with `extraBits` = 3: // ((0x80 >> 2) - 1) = (0b0010_0000 - 1) = 0b0001_1111 @@ -232,49 +283,10 @@ void Address::SetMulticastNetworkPrefix(const uint8_t *aPrefix, uint8_t aPrefixL mFields.m8[kMulticastNetworkPrefixLengthOffset] = aPrefixLength; } -bool Address::HasIid(const uint8_t *aIid) const -{ - return (memcmp(mFields.m8 + kInterfaceIdentifierOffset, aIid, kInterfaceIdentifierSize) == 0); -} - -void Address::SetIid(const uint8_t *aIid) -{ - memcpy(mFields.m8 + kInterfaceIdentifierOffset, aIid, kInterfaceIdentifierSize); -} - -void Address::SetIid(const Mac::ExtAddress &aExtAddress) -{ - Mac::ExtAddress addr; - - addr = aExtAddress; - addr.ToggleLocal(); - addr.CopyTo(mFields.m8 + kInterfaceIdentifierOffset); -} - -void Address::SetIidToLocator(uint16_t aLocator) -{ - // Locator IID pattern `0000:00ff:fe00:xxxx` - mFields.m32[2] = HostSwap32(0x000000ff); - mFields.m16[6] = HostSwap16(0xfe00); - mFields.m16[7] = HostSwap16(aLocator); -} - void Address::SetToLocator(const Mle::MeshLocalPrefix &aMeshLocalPrefix, uint16_t aLocator) { SetPrefix(aMeshLocalPrefix); - SetIidToLocator(aLocator); -} - -void Address::ToExtAddress(Mac::ExtAddress &aExtAddress) const -{ - aExtAddress.Set(mFields.m8 + kInterfaceIdentifierOffset); - aExtAddress.ToggleLocal(); -} - -void Address::ToExtAddress(Mac::Address &aMacAddress) const -{ - aMacAddress.SetExtended(mFields.m8 + kInterfaceIdentifierOffset); - aMacAddress.GetExtended().ToggleLocal(); + GetIid().SetToLocator(aLocator); } uint8_t Address::GetScope(void) const diff --git a/src/core/net/ip6_address.hpp b/src/core/net/ip6_address.hpp index 802a72ae7..30f5d3c6c 100644 --- a/src/core/net/ip6_address.hpp +++ b/src/core/net/ip6_address.hpp @@ -66,10 +66,13 @@ class InterfaceIdentifier : public otIp6InterfaceIdentifier, public Equatable, public Clearable { + friend class Address; + public: enum { - kInfoStringSize = 17, // Max chars for the info string (`ToString()`). + kSize = OT_IP6_IID_SIZE, ///< Size of an IPv6 Interface Identifier (in bytes). + kInfoStringSize = 17, ///< Max chars for the info string (`ToString()`). }; /** @@ -96,6 +99,147 @@ public: */ bool IsReserved(void) const; + /** + * This method indicates whether or not the Interface Identifier is Subnet-Router Anycast (RFC 4291). + * + * @retval TRUE If the Interface Identifier is a Subnet-Router Anycast address. + * @retval FALSE If the Interface Identifier is not a Subnet-Router Anycast address. + * + */ + bool IsSubnetRouterAnycast(void) const; + + /** + * This method indicates whether or not the Interface Identifier is Reserved Subnet Anycast (RFC 2526). + * + * @retval TRUE If the Interface Identifier is a Reserved Subnet Anycast address. + * @retval FALSE If the Interface Identifier is not a Reserved Subnet Anycast address. + * + */ + bool IsReservedSubnetAnycast(void) const; + + /** + * This method generates and sets the Interface Identifier to a crypto-secure random byte sequence. + * + */ + void GenerateRandom(void); + + /** + * This method gets the Interface Identifier as a pointer to a byte array. + * + * @returns A pointer to a byte array (of size `kSize`) containing the Interface Identifier. + * + */ + const uint8_t *GetBytes(void) const { return mFields.m8; } + + /** + * This method sets 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); + + /** + * This method sets the Interface Identifier from a given IEEE 802.15.4 Extended Address. + * + * @param[in] aExtAddress An Extended Address. + * + */ + void SetFromExtAddress(const Mac::ExtAddress &aExtAddress); + + /** + * This method converts the Interface Identifier to an IEEE 802.15.4 Extended Address. + * + * @param[out] aExtAddress A reference to an Extended Address where the converted address is placed. + * + */ + void ConvertToExtAddress(Mac::ExtAddress &aExtAddress) const; + + /** + * This method converts the Interface Identifier to an IEEE 802.15.4 MAC Address. + * + * @param[out] aMacAddress A reference to a MAC Address where the converted address is placed. + * + */ + void ConvertToMacAddress(Mac::Address &aMacAddress) const; + + /** + * This method sets 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); + + /** + * This method indicates whether or not the Interface Identifier matches the locator pattern `0000:00ff:fe00:xxxx`. + * + * @retval TRUE If the IID matches the locator pattern. + * @retval FALSE If the IID does not match the locator pattern. + * + */ + bool IsLocator(void) const; + + /** + * This method indicates whether or not the Interface Identifier (IID) matches a Routing Locator (RLOC). + * + * In addition to checking that the IID matches the locator pattern (`0000:00ff:fe00:xxxx`), this method also + * checks that the locator value is a valid RLOC16. + * + * @retval TRUE If the IID matches a RLOC address. + * @retval FALSE If the IID does not match a RLOC address. + * + */ + bool IsRoutingLocator(void) const; + + /** + * This method indicates whether or not the Interface Identifier (IID) matches an Anycast Locator (ALOC). + * + * In addition to checking that the IID matches the locator pattern (`0000:00ff:fe00:xxxx`), this method also + * checks that the locator value is any valid ALOC16 (0xfc00 - 0xfcff). + * + * @retval TRUE If the IID matches a ALOC address. + * @retval FALSE If the IID does not match a ALOC address. + * + */ + bool IsAnycastLocator(void) const; + + /** + * This method indicates whether or not the Interface Identifier (IID) matches a Service Anycast Locator (ALOC). + * + * In addition to checking that the IID matches the locator pattern (`0000:00ff:fe00:xxxx`), this method also + * checks that the locator value is a valid Service ALOC16 (0xfc10 – 0xfc2f). + * + * @retval TRUE If the IID matches a ALOC address. + * @retval FALSE If the IID does not match a ALOC address. + * + */ + bool IsAnycastServiceLocator(void) const; + + /** + * This method gets the Interface Identifier (IID) address locator fields. + * + * This method assumes the IID to match the locator pattern `0000:00ff:fe00:xxxx` (does not explicitly check this) + * and returns the last `uint16` portion of the IID. + * + * @returns The RLOC16 or ALOC16. + * + */ + uint16_t GetLocator(void) const { return HostSwap16(mFields.m16[3]); } + + /** + * This method 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 + * as before. + * + * @param[in] aLocator RLOC16 or ALOC16. + * + */ + void SetLocator(uint16_t aLocator) { mFields.m16[3] = HostSwap16(aLocator); } + /** * This method converts an Interface Identifier to a string. * @@ -103,6 +247,14 @@ public: * */ InfoString ToString(void) const; + +private: + enum : uint8_t + { + kAloc16Mask = 0xfc, // The mask for Aloc16. + kRloc16ReservedBitMask = 0x02, // The mask for the reserved bit of Rloc16. + }; + } OT_TOOL_PACKED_END; /** @@ -119,8 +271,7 @@ public: */ enum { - kAloc16Mask = 0xfc, ///< The mask for Aloc16. - kRloc16ReservedBitMask = 0x02, ///< The mask for the reserved bit of Rloc16. + kAloc16Mask = InterfaceIdentifier::kAloc16Mask, ///< The mask for Aloc16. }; /** @@ -129,8 +280,8 @@ public: */ enum { - kInterfaceIdentifierSize = OT_IP6_IID_SIZE, ///< Interface Identifier size in bytes. - kIp6AddressStringSize = 40, ///< Max buffer size in bytes to store an IPv6 address in string format. + kSize = OT_IP6_ADDRESS_SIZE, ///< Size of an IPv6 Address (in bytes). + kIp6AddressStringSize = 40, ///< Max buffer size in bytes to store an IPv6 address in string format. }; /** @@ -193,10 +344,10 @@ public: /** * This methods sets the IPv6 address to a Link-Local address with a given Interface Identifier. * - * @param[in] aIid A pointer to a buffer containing the Interface Identifier. + * @param[in] aIid An Interface Identifier. * */ - void SetToLinkLocalAddress(const uint8_t *aIid); + void SetToLinkLocalAddress(const InterfaceIdentifier &aIid); /** * This method indicates whether or not the IPv6 address is multicast address. @@ -309,100 +460,6 @@ public: */ bool IsMulticastLargerThanRealmLocal(void) const; - /** - * This method indicates whether or not the IPv6 address is Subnet-Router Anycast (RFC 4291). - * - * @retval TRUE If the IPv6 address is a Subnet-Router Anycast address. - * @retval FALSE If the IPv6 address is not a Subnet-Router Anycast address. - * - */ - bool IsSubnetRouterAnycast(void) const; - - /** - * This method indicates whether or not the IPv6 address is Reserved Subnet Anycast (RFC 2526). - * - * @retval TRUE If the IPv6 address is a Reserved Subnet Anycast address. - * @retval FALSE If the IPv6 address is not a Reserved Subnet Anycast address. - * - */ - bool IsReservedSubnetAnycast(void) const; - - /** - * This method indicates whether or not the IPv6 address contains Reserved IPv6 IID (RFC 5453). - * - * @retval TRUE If the IPv6 address contains a reserved IPv6 IID. - * @retval FALSE If the IPv6 address does not contain a reserved IPv6 IID. - * - */ - bool IsIidReserved(void) const; - - /** - * This method indicates whether or not the Interface Identifier (IID) of the IPv6 address matches the locator - * pattern (`0000:00ff:fe00:xxxx`). - * - * @retval TRUE If the IPv6 address IID matches the locator pattern - * @retval FALSE If the IPv6 address IID does not match the locator pattern - * - */ - bool IsIidLocator(void) const; - - /** - * This method indicates whether or not the IPv6 address's Interface Identifier (IID) matches a Routing Locator - * (RLOC). - * - * In addition to checking that the IID matches the locator pattern (`0000:00ff:fe00:xxxx`), this method also - * checks that the locator value is a valid RLOC16. - * - * @retval TRUE If the IPv6 address's IID matches a RLOC address. - * @retval FALSE If the IPv6 address's IID does not match a RLOC address. - * - */ - bool IsIidRoutingLocator(void) const; - - /** - * This method indicates whether or not the IPv6 address's Interface Identifier (IID) matches an Anycast Locator - * (ALOC). - * - * In addition to checking that the IID matches the locator pattern (`0000:00ff:fe00:xxxx`), this method also - * checks that the locator value is any valid ALOC16 (0xfc00 - 0xfcff). - * - * @retval TRUE If the IPv6 address's IID matches a ALOC address. - * @retval FALSE If the IPv6 address's IID does not match a ALOC address. - * - */ - bool IsIidAnycastLocator(void) const; - - /** - * This method indicates whether or not the IPv6 address's Interface Identifier (IID) matches a Service Anycast - * Locator (ALOC). - * - * In addition to checking that the IID matches the locator pattern (`0000:00ff:fe00:xxxx`), this method also - * checks that the locator value is a valid Service ALOC16 (0xfc10 – 0xfc2f). - * - * @retval TRUE If the IPv6 address's IID matches a ALOC address. - * @retval FALSE If the IPv6 address's IID does not match a ALOC address. - * - */ - bool IsIidAnycastServiceLocator(void) const; - - /** - * This method gets the IPv6 address locator. - * - * @returns RLOC16 or ALOC16. - * - */ - uint16_t GetLocator(void) const { return HostSwap16(mFields.m16[7]); } - - /** - * This method sets the IPv6 address locator. - * - * This method only changes the last 2 bytes of the address and keeps the rest of the address as before. - * - * @param[in] aLocator RLOC16 or ALOC16. - * - */ - void SetLocator(uint16_t aLocator) { mFields.m16[7] = HostSwap16(aLocator); } - /** * This method sets the IPv6 address to a Routing Locator (RLOC) IPv6 address with a given Mesh-local prefix and * RLOC16 value. @@ -484,91 +541,31 @@ public: } /** - * This method returns a pointer to the Interface Identifier. + * This method returns the Interface Identifier of the IPv6 address. * - * @returns A pointer to the Interface Identifier. + * @returns A reference to the Interface Identifier. * */ - const uint8_t *GetIid(void) const { return mFields.m8 + kInterfaceIdentifierOffset; } + const InterfaceIdentifier &GetIid(void) const + { + return static_cast(mFields.mComponents.mIid); + } /** - * This method returns a pointer to the Interface Identifier. + * This method returns the Interface Identifier of the IPv6 address. * - * @returns A pointer to the Interface Identifier. + * @returns A reference to the Interface Identifier. * */ - uint8_t *GetIid(void) { return mFields.m8 + kInterfaceIdentifierOffset; } - - /** - * This method indicates whether or not the IPv6 address has the specified Interface Identifier. - * - * @param[in] aIid A pointer to the Interface Identifier. - * - * @retval true If the IPv6 address has the specified Interface Identifier. - * @retval false If the IPv6 address doesn't have the specified Interface Identifier. - * - */ - bool HasIid(const uint8_t *aIid) const; - - /** - * This method indicates whether or not the IPv6 address has the specified Interface Identifier. - * - * @param[in] aIid A reference to the Interface Identifier. - * - * @retval true If the IPv6 address has the specified Interface Identifier. - * @retval false If the IPv6 address doesn't have the specified Interface Identifier. - * - */ - bool HasIid(const InterfaceIdentifier &aIid) const { return HasIid(aIid.m8); } + InterfaceIdentifier &GetIid(void) { return static_cast(mFields.mComponents.mIid); } /** * This method sets the Interface Identifier. * - * @param[in] aIid A pointer to the Interface Identifier. + * @param[in] aIid An Interface Identifier. * */ - void SetIid(const uint8_t *aIid); - - /** - * This method sets the Interface Identifier. - * - * @param[in] aIid A reference to the Interface Identifier. - * - */ - void SetIid(const InterfaceIdentifier &aIid) { SetIid(aIid.m8); } - - /** - * This method sets the Interface Identifier. - * - * @param[in] aExtAddress A reference to the extended address. - * - */ - void SetIid(const Mac::ExtAddress &aExtAddress); - - /** - * This method sets 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 SetIidToLocator(uint16_t aLocator); - - /** - * This method converts the IPv6 Interface Identifier to an IEEE 802.15.4 Extended Address. - * - * @param[out] aExtAddress A reference to the extended address. - * - */ - void ToExtAddress(Mac::ExtAddress &aExtAddress) const; - - /** - * This method converts the IPv6 Interface Identifier to an IEEE 802.15.4 MAC Address. - * - * @param[out] aMacAddress A reference to the MAC address. - * - */ - void ToExtAddress(Mac::Address &aMacAddress) const; + void SetIid(const InterfaceIdentifier &aIid) { GetIid() = aIid; } /** * This method returns the IPv6 address scope. @@ -631,7 +628,6 @@ private: enum { - kInterfaceIdentifierOffset = 8, ///< Interface Identifier offset in bytes. kIp4AddressSize = 4, ///< Size of the IPv4 address. kMulticastNetworkPrefixLengthOffset = 3, ///< Prefix-Based Multicast Address (RFC3306). kMulticastNetworkPrefixOffset = 4, ///< Prefix-Based Multicast Address (RFC3306). diff --git a/src/core/thread/address_resolver.cpp b/src/core/thread/address_resolver.cpp index baa74bcfd..b982fe2f8 100644 --- a/src/core/thread/address_resolver.cpp +++ b/src/core/thread/address_resolver.cpp @@ -569,18 +569,18 @@ void AddressResolver::HandleAddressNotification(void *aContext, otMessage *aMess void AddressResolver::HandleAddressNotification(Coap::Message &aMessage, const Ip6::MessageInfo &aMessageInfo) { - Ip6::Address target; - uint8_t meshLocalIid[Ip6::Address::kInterfaceIdentifierSize]; - uint16_t rloc16; - uint32_t lastTransactionTime; - CacheEntryList *list; - CacheEntry * entry; - CacheEntry * prev; + Ip6::Address target; + Ip6::InterfaceIdentifier meshLocalIid; + uint16_t rloc16; + uint32_t lastTransactionTime; + CacheEntryList * list; + CacheEntry * entry; + CacheEntry * prev; VerifyOrExit(aMessage.IsConfirmable() && aMessage.GetCode() == OT_COAP_CODE_POST, OT_NOOP); SuccessOrExit(Tlv::FindTlv(aMessage, ThreadTlv::kTarget, &target, sizeof(target))); - SuccessOrExit(Tlv::FindTlv(aMessage, ThreadTlv::kMeshLocalEid, meshLocalIid, sizeof(meshLocalIid))); + SuccessOrExit(Tlv::FindTlv(aMessage, ThreadTlv::kMeshLocalEid, &meshLocalIid, sizeof(meshLocalIid))); SuccessOrExit(Tlv::FindUint16Tlv(aMessage, ThreadTlv::kRloc16, rloc16)); switch (Tlv::FindUint32Tlv(aMessage, ThreadTlv::kLastTransactionTime, lastTransactionTime)) @@ -594,8 +594,8 @@ void AddressResolver::HandleAddressNotification(Coap::Message &aMessage, const I ExitNow(); } - otLogInfoArp("Received address notification from 0x%04x for %s to 0x%04x", aMessageInfo.GetPeerAddr().GetLocator(), - target.ToString().AsCString(), rloc16); + otLogInfoArp("Received address notification from 0x%04x for %s to 0x%04x", + aMessageInfo.GetPeerAddr().GetIid().GetLocator(), target.ToString().AsCString(), rloc16); entry = FindCacheEntry(target, list, prev); VerifyOrExit(entry != nullptr, OT_NOOP); @@ -609,7 +609,7 @@ void AddressResolver::HandleAddressNotification(Coap::Message &aMessage, const I // by more than one device. Try to resolve the duplicate // address by sending an Address Error message. - VerifyOrExit(entry->HasMeshLocalIid(meshLocalIid), SendAddressError(target, meshLocalIid, nullptr)); + VerifyOrExit(entry->GetMeshLocalIid() == meshLocalIid, SendAddressError(target, meshLocalIid, nullptr)); VerifyOrExit(lastTransactionTime < entry->GetLastTransactionTime(), OT_NOOP); } @@ -635,9 +635,9 @@ exit: return; } -void AddressResolver::SendAddressError(const Ip6::Address &aTarget, - const uint8_t * aMeshLocalIid, - const Ip6::Address *aDestination) +void AddressResolver::SendAddressError(const Ip6::Address & aTarget, + const Ip6::InterfaceIdentifier &aMeshLocalIid, + const Ip6::Address * aDestination) { otError error; Coap::Message * message; @@ -650,8 +650,7 @@ void AddressResolver::SendAddressError(const Ip6::Address &aTarget, SuccessOrExit(error = message->SetPayloadMarker()); SuccessOrExit(error = Tlv::AppendTlv(*message, ThreadTlv::kTarget, &aTarget, sizeof(aTarget))); - SuccessOrExit(error = Tlv::AppendTlv(*message, ThreadTlv::kMeshLocalEid, aMeshLocalIid, - Ip6::Address::kInterfaceIdentifierSize)); + SuccessOrExit(error = Tlv::AppendTlv(*message, ThreadTlv::kMeshLocalEid, &aMeshLocalIid, sizeof(aMeshLocalIid))); if (aDestination == nullptr) { @@ -690,11 +689,11 @@ void AddressResolver::HandleAddressError(void *aContext, otMessage *aMessage, co void AddressResolver::HandleAddressError(Coap::Message &aMessage, const Ip6::MessageInfo &aMessageInfo) { - otError error = OT_ERROR_NONE; - Ip6::Address target; - uint8_t meshLocalIid[Ip6::Address::kInterfaceIdentifierSize]; - Mac::ExtAddress macAddr; - Ip6::Address destination; + otError error = OT_ERROR_NONE; + Ip6::Address target; + Ip6::InterfaceIdentifier meshLocalIid; + Mac::ExtAddress extAddr; + Ip6::Address destination; VerifyOrExit(aMessage.GetCode() == OT_COAP_CODE_POST, error = OT_ERROR_DROP); @@ -709,13 +708,12 @@ void AddressResolver::HandleAddressError(Coap::Message &aMessage, const Ip6::Mes } SuccessOrExit(error = Tlv::FindTlv(aMessage, ThreadTlv::kTarget, &target, sizeof(target))); - SuccessOrExit(error = Tlv::FindTlv(aMessage, ThreadTlv::kMeshLocalEid, meshLocalIid, sizeof(meshLocalIid))); + SuccessOrExit(error = Tlv::FindTlv(aMessage, ThreadTlv::kMeshLocalEid, &meshLocalIid, sizeof(meshLocalIid))); for (const Ip6::NetifUnicastAddress *address = Get().GetUnicastAddresses(); address; address = address->GetNext()) { - if (address->GetAddress() == target && - memcmp(Get().GetMeshLocal64().GetIid(), meshLocalIid, sizeof(meshLocalIid))) + if (address->GetAddress() == target && Get().GetMeshLocal64().GetIid() != meshLocalIid) { // Target EID matches address and Mesh Local EID differs Get().RemoveUnicastAddress(*address); @@ -723,8 +721,7 @@ void AddressResolver::HandleAddressError(Coap::Message &aMessage, const Ip6::Mes } } - macAddr.Set(meshLocalIid); - macAddr.ToggleLocal(); + meshLocalIid.ConvertToExtAddress(extAddr); for (ChildTable::Iterator iter(GetInstance(), Child::kInStateValid); !iter.IsDone(); iter++) { @@ -735,7 +732,7 @@ void AddressResolver::HandleAddressError(Coap::Message &aMessage, const Ip6::Mes continue; } - if (child.GetExtAddress() != macAddr) + if (child.GetExtAddress() != extAddr) { // Mesh Local EID differs, so check whether Target EID // matches a child address and if so remove it. @@ -773,7 +770,7 @@ void AddressResolver::HandleAddressQuery(Coap::Message &aMessage, const Ip6::Mes SuccessOrExit(Tlv::FindTlv(aMessage, ThreadTlv::kTarget, &target, sizeof(target))); - otLogInfoArp("Received address query from 0x%04x for target %s", aMessageInfo.GetPeerAddr().GetLocator(), + otLogInfoArp("Received address query from 0x%04x for target %s", aMessageInfo.GetPeerAddr().GetIid().GetLocator(), target.ToString().AsCString()); if (Get().HasUnicastAddress(target)) @@ -804,10 +801,10 @@ exit: return; } -void AddressResolver::SendAddressQueryResponse(const Ip6::Address &aTarget, - const uint8_t * aMeshLocalIid, - const uint32_t * aLastTransactionTime, - const Ip6::Address &aDestination) +void AddressResolver::SendAddressQueryResponse(const Ip6::Address & aTarget, + const Ip6::InterfaceIdentifier &aMeshLocalIid, + const uint32_t * aLastTransactionTime, + const Ip6::Address & aDestination) { otError error; Coap::Message * message; @@ -820,8 +817,7 @@ void AddressResolver::SendAddressQueryResponse(const Ip6::Address &aTarget, SuccessOrExit(error = message->SetPayloadMarker()); SuccessOrExit(error = Tlv::AppendTlv(*message, ThreadTlv::kTarget, &aTarget, sizeof(aTarget))); - SuccessOrExit(error = Tlv::AppendTlv(*message, ThreadTlv::kMeshLocalEid, aMeshLocalIid, - Ip6::Address::kInterfaceIdentifierSize)); + SuccessOrExit(error = Tlv::AppendTlv(*message, ThreadTlv::kMeshLocalEid, &aMeshLocalIid, sizeof(aMeshLocalIid))); SuccessOrExit(error = Tlv::AppendUint16Tlv(*message, ThreadTlv::kRloc16, Get().GetRloc16())); if (aLastTransactionTime != nullptr) @@ -1070,16 +1066,6 @@ exit: return; } -bool AddressResolver::CacheEntry::HasMeshLocalIid(const uint8_t *aIid) const -{ - return memcmp(mInfo.mCached.mMeshLocalIid, aIid, Ip6::Address::kInterfaceIdentifierSize) == 0; -} - -void AddressResolver::CacheEntry::SetMeshLocalIid(const uint8_t *aIid) -{ - memcpy(mInfo.mCached.mMeshLocalIid, aIid, Ip6::Address::kInterfaceIdentifierSize); -} - } // namespace ot #endif // OPENTHREAD_FTD diff --git a/src/core/thread/address_resolver.hpp b/src/core/thread/address_resolver.hpp index f2fa91c1c..7acfaec5a 100644 --- a/src/core/thread/address_resolver.hpp +++ b/src/core/thread/address_resolver.hpp @@ -200,9 +200,8 @@ private: Mac::ShortAddress GetRloc16(void) const { return mRloc16; } void SetRloc16(Mac::ShortAddress aRloc16) { mRloc16 = aRloc16; } - const uint8_t *GetMeshLocalIid(void) const { return mInfo.mCached.mMeshLocalIid; } - bool HasMeshLocalIid(const uint8_t *aIid) const; - void SetMeshLocalIid(const uint8_t *aIid); + const Ip6::InterfaceIdentifier &GetMeshLocalIid(void) const { return mInfo.mCached.mMeshLocalIid; } + void SetMeshLocalIid(const Ip6::InterfaceIdentifier &aIid) { mInfo.mCached.mMeshLocalIid = aIid; } uint32_t GetLastTransactionTime(void) const { return mInfo.mCached.mLastTransactionTime; } void SetLastTransactionTime(uint32_t aTime) { mInfo.mCached.mLastTransactionTime = aTime; } @@ -236,8 +235,8 @@ private: { struct { - uint32_t mLastTransactionTime; - uint8_t mMeshLocalIid[Ip6::Address::kInterfaceIdentifierSize]; + uint32_t mLastTransactionTime; + Ip6::InterfaceIdentifier mMeshLocalIid; } mCached; struct @@ -281,11 +280,13 @@ private: void RemoveCacheEntry(CacheEntry &aEntry, CacheEntryList &aList, CacheEntry *aPrevEntry, Reason aReason); otError SendAddressQuery(const Ip6::Address &aEid); - void SendAddressError(const Ip6::Address &aTarget, const uint8_t *aMeshLocalIid, const Ip6::Address *aDestination); - void SendAddressQueryResponse(const Ip6::Address &aTarget, - const uint8_t * aMeshLocalIid, - const uint32_t * aLastTransactionTimeTlv, - const Ip6::Address &aDestination); + void SendAddressError(const Ip6::Address & aTarget, + const Ip6::InterfaceIdentifier &aMeshLocalIid, + const Ip6::Address * aDestination); + void SendAddressQueryResponse(const Ip6::Address & aTarget, + const Ip6::InterfaceIdentifier &aMeshLocalIid, + const uint32_t * aLastTransactionTimeTlv, + const Ip6::Address & aDestination); static void HandleUdpReceive(void *aContext, otMessage *aMessage, const otMessageInfo *aMessageInfo); diff --git a/src/core/thread/discover_scanner.cpp b/src/core/thread/discover_scanner.cpp index 1282aa68e..31fbf4ed8 100644 --- a/src/core/thread/discover_scanner.cpp +++ b/src/core/thread/discover_scanner.cpp @@ -279,7 +279,8 @@ void DiscoverScanner::HandleDiscoveryResponse(const Message &aMessage, const Ip6 result.mChannel = linkInfo->mChannel; result.mRssi = linkInfo->mRss; result.mLqi = linkInfo->mLqi; - aMessageInfo.GetPeerAddr().ToExtAddress(*static_cast(&result.mExtAddress)); + + aMessageInfo.GetPeerAddr().GetIid().ConvertToExtAddress(static_cast(result.mExtAddress)); // Process MeshCoP TLVs while (offset < end) diff --git a/src/core/thread/dua_manager.cpp b/src/core/thread/dua_manager.cpp index 3f814b5cb..6f4c04570 100644 --- a/src/core/thread/dua_manager.cpp +++ b/src/core/thread/dua_manager.cpp @@ -147,7 +147,7 @@ void DuaManager::ClearFixedDuaInterfaceIdentifier(void) // Nothing to clear. VerifyOrExit(IsFixedDuaInterfaceIdentifierSet(), OT_NOOP); - if (GetDomainUnicastAddress().HasIid(mFixedDuaInterfaceIdentifier) && + if (GetDomainUnicastAddress().GetIid() == mFixedDuaInterfaceIdentifier && Get().HasUnicastAddress(GetDomainUnicastAddress())) { Get().RemoveUnicastAddress(mDomainUnicastAddress); diff --git a/src/core/thread/lowpan.cpp b/src/core/thread/lowpan.cpp index 9286d0d03..dbccda4d0 100644 --- a/src/core/thread/lowpan.cpp +++ b/src/core/thread/lowpan.cpp @@ -67,11 +67,11 @@ otError Lowpan::ComputeIid(const Mac::Address &aMacAddr, const Context &aContext switch (aMacAddr.GetType()) { case Mac::Address::kTypeShort: - aIpAddress.SetIidToLocator(aMacAddr.GetShort()); + aIpAddress.GetIid().SetToLocator(aMacAddr.GetShort()); break; case Mac::Address::kTypeExtended: - aIpAddress.SetIid(aMacAddr.GetExtended()); + aIpAddress.GetIid().SetFromExtAddress(aMacAddr.GetExtended()); break; default: @@ -104,16 +104,16 @@ otError Lowpan::CompressSourceIid(const Mac::Address &aMacAddr, IgnoreError(ComputeIid(aMacAddr, aContext, ipaddr)); - if (memcmp(ipaddr.GetIid(), aIpAddr.GetIid(), Ip6::Address::kInterfaceIdentifierSize) == 0) + if (ipaddr.GetIid() == aIpAddr.GetIid()) { aHcCtl |= kHcSrcAddrMode3; } else { - tmp.SetShort(aIpAddr.GetLocator()); + tmp.SetShort(aIpAddr.GetIid().GetLocator()); IgnoreError(ComputeIid(tmp, aContext, ipaddr)); - if (memcmp(ipaddr.GetIid(), aIpAddr.GetIid(), Ip6::Address::kInterfaceIdentifierSize) == 0) + if (ipaddr.GetIid() == aIpAddr.GetIid()) { aHcCtl |= kHcSrcAddrMode2; SuccessOrExit(error = buf.Write(aIpAddr.mFields.m8 + 14, 2)); @@ -121,7 +121,7 @@ otError Lowpan::CompressSourceIid(const Mac::Address &aMacAddr, else { aHcCtl |= kHcSrcAddrMode1; - SuccessOrExit(error = buf.Write(aIpAddr.GetIid(), Ip6::Address::kInterfaceIdentifierSize)); + SuccessOrExit(error = buf.Write(aIpAddr.GetIid().GetBytes(), Ip6::InterfaceIdentifier::kSize)); } } @@ -147,16 +147,16 @@ otError Lowpan::CompressDestinationIid(const Mac::Address &aMacAddr, IgnoreError(ComputeIid(aMacAddr, aContext, ipaddr)); - if (memcmp(ipaddr.GetIid(), aIpAddr.GetIid(), Ip6::Address::kInterfaceIdentifierSize) == 0) + if (ipaddr.GetIid() == aIpAddr.GetIid()) { aHcCtl |= kHcDstAddrMode3; } else { - tmp.SetShort(aIpAddr.GetLocator()); + tmp.SetShort(aIpAddr.GetIid().GetLocator()); IgnoreError(ComputeIid(tmp, aContext, ipaddr)); - if (memcmp(ipaddr.GetIid(), aIpAddr.GetIid(), Ip6::Address::kInterfaceIdentifierSize) == 0) + if (ipaddr.GetIid() == aIpAddr.GetIid()) { aHcCtl |= kHcDstAddrMode2; SuccessOrExit(error = buf.Write(aIpAddr.mFields.m8 + 14, 2)); @@ -164,7 +164,7 @@ otError Lowpan::CompressDestinationIid(const Mac::Address &aMacAddr, else { aHcCtl |= kHcDstAddrMode1; - SuccessOrExit(error = buf.Write(aIpAddr.GetIid(), Ip6::Address::kInterfaceIdentifierSize)); + SuccessOrExit(error = buf.Write(aIpAddr.GetIid().GetBytes(), Ip6::InterfaceIdentifier::kSize)); } } @@ -785,9 +785,9 @@ int Lowpan::DecompressBaseHeader(Ip6::Header & aIp6Header, break; case kHcSrcAddrMode1: - VerifyOrExit(cur + Ip6::Address::kInterfaceIdentifierSize <= end, OT_NOOP); - aIp6Header.GetSource().SetIid(cur); - cur += Ip6::Address::kInterfaceIdentifierSize; + VerifyOrExit(cur + Ip6::InterfaceIdentifier::kSize <= end, OT_NOOP); + aIp6Header.GetSource().GetIid().SetBytes(cur); + cur += Ip6::InterfaceIdentifier::kSize; break; case kHcSrcAddrMode2: @@ -830,9 +830,9 @@ int Lowpan::DecompressBaseHeader(Ip6::Header & aIp6Header, break; case kHcDstAddrMode1: - VerifyOrExit(cur + Ip6::Address::kInterfaceIdentifierSize <= end, OT_NOOP); - aIp6Header.GetDestination().SetIid(cur); - cur += Ip6::Address::kInterfaceIdentifierSize; + VerifyOrExit(cur + Ip6::InterfaceIdentifier::kSize <= end, OT_NOOP); + aIp6Header.GetDestination().GetIid().SetBytes(cur); + cur += Ip6::InterfaceIdentifier::kSize; break; case kHcDstAddrMode2: diff --git a/src/core/thread/mesh_forwarder.cpp b/src/core/thread/mesh_forwarder.cpp index 35743e3e0..4ef78ac42 100644 --- a/src/core/thread/mesh_forwarder.cpp +++ b/src/core/thread/mesh_forwarder.cpp @@ -339,7 +339,7 @@ void MeshForwarder::SetRxOnWhenIdle(bool aRxOnWhenIdle) void MeshForwarder::GetMacSourceAddress(const Ip6::Address &aIp6Addr, Mac::Address &aMacAddr) { - aIp6Addr.ToExtAddress(aMacAddr); + aIp6Addr.GetIid().ConvertToMacAddress(aMacAddr); if (aMacAddr.GetExtended() != Get().GetExtAddress()) { @@ -355,11 +355,11 @@ void MeshForwarder::GetMacDestinationAddress(const Ip6::Address &aIp6Addr, Mac:: } else if (Get().IsRoutingLocator(aIp6Addr)) { - aMacAddr.SetShort(aIp6Addr.GetLocator()); + aMacAddr.SetShort(aIp6Addr.GetIid().GetLocator()); } else { - aIp6Addr.ToExtAddress(aMacAddr); + aIp6Addr.GetIid().ConvertToMacAddress(aMacAddr); } } diff --git a/src/core/thread/mesh_forwarder_ftd.cpp b/src/core/thread/mesh_forwarder_ftd.cpp index 6482eb968..414467fda 100644 --- a/src/core/thread/mesh_forwarder_ftd.cpp +++ b/src/core/thread/mesh_forwarder_ftd.cpp @@ -416,13 +416,13 @@ otError MeshForwarder::UpdateIp6RouteFtd(Ip6::Header &ip6Header, Message &aMessa } else if (mle.IsRoutingLocator(ip6Header.GetDestination())) { - uint16_t rloc16 = ip6Header.GetDestination().GetLocator(); + uint16_t rloc16 = ip6Header.GetDestination().GetIid().GetLocator(); VerifyOrExit(mle.IsRouterIdValid(Mle::Mle::RouterIdFromRloc16(rloc16)), error = OT_ERROR_DROP); mMeshDest = rloc16; } else if (mle.IsAnycastLocator(ip6Header.GetDestination())) { - uint16_t aloc16 = ip6Header.GetDestination().GetLocator(); + uint16_t aloc16 = ip6Header.GetDestination().GetIid().GetLocator(); if (aloc16 == Mle::kAloc16Leader) { @@ -600,7 +600,7 @@ void MeshForwarder::SendDestinationUnreachable(uint16_t aMeshSource, const Messa Ip6::MessageInfo messageInfo; messageInfo.GetPeerAddr() = Get().GetMeshLocal16(); - messageInfo.GetPeerAddr().SetLocator(aMeshSource); + messageInfo.GetPeerAddr().GetIid().SetLocator(aMeshSource); IgnoreError(Get().SendError(Ip6::IcmpHeader::kTypeDstUnreach, Ip6::IcmpHeader::kCodeDstUnreachNoRoute, messageInfo, aMessage)); @@ -699,7 +699,7 @@ void MeshForwarder::UpdateRoutes(const uint8_t * aFrame, VerifyOrExit(!aMeshDest.IsBroadcast() && aMeshSource.IsShort(), OT_NOOP); SuccessOrExit(GetIp6Header(aFrame, aFrameLength, aMeshSource, aMeshDest, ip6Header)); - if (!ip6Header.GetSource().IsIidLocator() && + if (!ip6Header.GetSource().GetIid().IsLocator() && Get().IsOnMesh(ip6Header.GetSource()) /* only for on mesh address which may require AQ */) { if (Get().UpdateCacheEntry(ip6Header.GetSource(), aMeshSource.GetShort()) == diff --git a/src/core/thread/mle.cpp b/src/core/thread/mle.cpp index deb2e0c00..219197562 100644 --- a/src/core/thread/mle.cpp +++ b/src/core/thread/mle.cpp @@ -148,7 +148,7 @@ Mle::Mle(Instance &aInstance) mServiceAlocs[i].mValid = true; mServiceAlocs[i].mScopeOverride = Ip6::Address::kRealmLocalScope; mServiceAlocs[i].mScopeOverrideValid = true; - mServiceAlocs[i].GetAddress().SetLocator(Mac::kShortAddrInvalid); + mServiceAlocs[i].GetAddress().GetIid().SetLocator(Mac::kShortAddrInvalid); } #endif @@ -158,8 +158,7 @@ Mle::Mle(Instance &aInstance) // mesh-local 64 mMeshLocal64.Clear(); - IgnoreError(Random::Crypto::FillBuffer(mMeshLocal64.GetAddress().mFields.m8 + OT_IP6_PREFIX_SIZE, - OT_IP6_ADDRESS_SIZE - OT_IP6_PREFIX_SIZE)); + mMeshLocal64.GetAddress().GetIid().GenerateRandom(); mMeshLocal64.mPrefixLength = MeshLocalPrefix::kLength; mMeshLocal64.mAddressOrigin = OT_ADDRESS_ORIGIN_THREAD; @@ -170,7 +169,7 @@ Mle::Mle(Instance &aInstance) // mesh-local 16 mMeshLocal16.Clear(); - mMeshLocal16.GetAddress().SetIidToLocator(0); + mMeshLocal16.GetAddress().GetIid().SetToLocator(0); mMeshLocal16.mPrefixLength = MeshLocalPrefix::kLength; mMeshLocal16.mAddressOrigin = OT_ADDRESS_ORIGIN_THREAD; mMeshLocal16.mPreferred = true; @@ -395,8 +394,7 @@ otError Mle::Restore(void) Get().SetShortAddress(networkInfo.GetRloc16()); Get().SetExtAddress(networkInfo.GetExtAddress()); - memcpy(&mMeshLocal64.GetAddress().mFields.m8[OT_IP6_PREFIX_SIZE], networkInfo.GetMeshLocalIid(), - OT_IP6_ADDRESS_SIZE - OT_IP6_PREFIX_SIZE); + mMeshLocal64.GetAddress().SetIid(networkInfo.GetMeshLocalIid()); if (networkInfo.GetRloc16() == Mac::kShortAddrInvalid) { @@ -462,7 +460,7 @@ otError Mle::Store(void) networkInfo.SetRloc16(GetRloc16()); networkInfo.SetPreviousPartitionId(mLeaderData.GetPartitionId()); networkInfo.SetExtAddress(Get().GetExtAddress()); - networkInfo.SetMeshLocalIid(&mMeshLocal64.GetAddress().mFields.m8[OT_IP6_PREFIX_SIZE]); + networkInfo.SetMeshLocalIid(mMeshLocal64.GetAddress().GetIid()); networkInfo.SetVersion(kThreadVersion); if (IsChild()) @@ -813,7 +811,7 @@ exit: void Mle::UpdateLinkLocalAddress(void) { Get().RemoveUnicastAddress(mLinkLocal64); - mLinkLocal64.GetAddress().SetIid(Get().GetExtAddress()); + mLinkLocal64.GetAddress().GetIid().SetFromExtAddress(Get().GetExtAddress()); Get().AddUnicastAddress(mLinkLocal64); Get().Signal(kEventThreadLinkLocalAddrChanged); @@ -887,7 +885,7 @@ void Mle::ApplyMeshLocalPrefix(void) for (size_t i = 0; i < OT_ARRAY_LENGTH(mServiceAlocs); i++) { - if (mServiceAlocs[i].GetAddress().GetLocator() != Mac::kShortAddrInvalid) + if (mServiceAlocs[i].GetAddress().GetIid().GetLocator() != Mac::kShortAddrInvalid) { Get().RemoveUnicastAddress(mServiceAlocs[i]); mServiceAlocs[i].GetAddress().SetPrefix(GetMeshLocalPrefix()); @@ -934,7 +932,7 @@ void Mle::SetRloc16(uint16_t aRloc16) if (aRloc16 != Mac::kShortAddrInvalid) { // mesh-local 16 - mMeshLocal16.GetAddress().SetLocator(aRloc16); + mMeshLocal16.GetAddress().GetIid().SetLocator(aRloc16); Get().AddUnicastAddress(mMeshLocal16); #if OPENTHREAD_FTD Get().RestartAddressQueries(); @@ -981,7 +979,7 @@ otError Mle::GetLocatorAddress(Ip6::Address &aAddress, uint16_t aLocator) const VerifyOrExit(GetRloc16() != Mac::kShortAddrInvalid, error = OT_ERROR_DETACHED); memcpy(&aAddress, &mMeshLocal16.GetAddress(), 14); - aAddress.SetLocator(aLocator); + aAddress.GetIid().SetLocator(aLocator); exit: return error; @@ -1464,8 +1462,7 @@ void Mle::HandleNotifierEvents(Events aEvents) if (!Get().HasUnicastAddress(mMeshLocal64.GetAddress())) { // Mesh Local EID was removed, choose a new one and add it back - IgnoreError(Random::Crypto::FillBuffer(mMeshLocal64.GetAddress().mFields.m8 + OT_IP6_PREFIX_SIZE, - OT_IP6_ADDRESS_SIZE - OT_IP6_PREFIX_SIZE)); + mMeshLocal64.GetAddress().GetIid().GenerateRandom(); Get().AddUnicastAddress(mMeshLocal64); Get().Signal(kEventThreadMeshLocalAddrChanged); @@ -1564,13 +1561,13 @@ void Mle::UpdateServiceAlocs(void) // First remove all alocs which are no longer necessary, to free up space in mServiceAlocs for (i = 0; i < serviceAlocsLength; i++) { - serviceAloc = mServiceAlocs[i].GetAddress().GetLocator(); + serviceAloc = mServiceAlocs[i].GetAddress().GetIid().GetLocator(); if ((serviceAloc != Mac::kShortAddrInvalid) && (!Get().ContainsService(Mle::ServiceIdFromAloc(serviceAloc), rloc))) { Get().RemoveUnicastAddress(mServiceAlocs[i]); - mServiceAlocs[i].GetAddress().SetLocator(Mac::kShortAddrInvalid); + mServiceAlocs[i].GetAddress().GetIid().SetLocator(Mac::kShortAddrInvalid); } } @@ -1579,7 +1576,7 @@ void Mle::UpdateServiceAlocs(void) { for (i = 0; i < serviceAlocsLength; i++) { - serviceAloc = mServiceAlocs[i].GetAddress().GetLocator(); + serviceAloc = mServiceAlocs[i].GetAddress().GetIid().GetLocator(); if ((serviceAloc != Mac::kShortAddrInvalid) && (Mle::ServiceIdFromAloc(serviceAloc) == serviceId)) { @@ -1592,7 +1589,7 @@ void Mle::UpdateServiceAlocs(void) // Service Aloc is not there, but it should be. Lets add it into first empty space for (i = 0; i < serviceAlocsLength; i++) { - serviceAloc = mServiceAlocs[i].GetAddress().GetLocator(); + serviceAloc = mServiceAlocs[i].GetAddress().GetIid().GetLocator(); if (serviceAloc == Mac::kShortAddrInvalid) { @@ -2535,7 +2532,7 @@ void Mle::HandleUdpReceive(Message &aMessage, const Ip6::MessageInfo &aMessageIn uint32_t frameCounter; uint8_t messageTag[kMleSecurityTagSize]; uint8_t nonce[Crypto::AesCcm::kNonceSize]; - Mac::ExtAddress macAddr; + Mac::ExtAddress extAddr; Crypto::AesCcm aesCcm; uint16_t mleOffset; uint8_t buf[64]; @@ -2596,9 +2593,10 @@ void Mle::HandleUdpReceive(Message &aMessage, const Ip6::MessageInfo &aMessageIn aMessage.Read(aMessage.GetLength() - sizeof(messageTag), sizeof(messageTag), messageTag); SuccessOrExit(error = aMessage.SetLength(aMessage.GetLength() - sizeof(messageTag))); - aMessageInfo.GetPeerAddr().ToExtAddress(macAddr); + aMessageInfo.GetPeerAddr().GetIid().ConvertToExtAddress(extAddr); + frameCounter = header.GetFrameCounter(); - Crypto::AesCcm::GenerateNonce(macAddr, frameCounter, Mac::Frame::kSecEncMic32, nonce); + Crypto::AesCcm::GenerateNonce(extAddr, frameCounter, Mac::Frame::kSecEncMic32, nonce); aesCcm.SetKey(*mleKey); aesCcm.Init(sizeof(aMessageInfo.GetPeerAddr()) + sizeof(aMessageInfo.GetSockAddr()) + header.GetHeaderLength(), @@ -2639,18 +2637,18 @@ void Mle::HandleUdpReceive(Message &aMessage, const Ip6::MessageInfo &aMessageIn { case kRoleDetached: case kRoleChild: - neighbor = GetNeighbor(macAddr); + neighbor = GetNeighbor(extAddr); break; case kRoleRouter: case kRoleLeader: if (command == Header::kCommandChildIdResponse) { - neighbor = GetNeighbor(macAddr); + neighbor = GetNeighbor(extAddr); } else { - neighbor = Get().GetNeighbor(macAddr); + neighbor = Get().GetNeighbor(extAddr); } break; @@ -3166,7 +3164,7 @@ void Mle::HandleParentResponse(const Message &aMessage, const Ip6::MessageInfo & SuccessOrExit(error = ReadResponse(aMessage, response)); VerifyOrExit(response == mParentRequestChallenge, error = OT_ERROR_PARSE); - aMessageInfo.GetPeerAddr().ToExtAddress(extAddress); + aMessageInfo.GetPeerAddr().GetIid().ConvertToExtAddress(extAddress); if (IsChild() && mParent.GetExtAddress() == extAddress) { @@ -3841,12 +3839,12 @@ uint16_t Mle::GetNextHop(uint16_t aDestination) const bool Mle::IsRoutingLocator(const Ip6::Address &aAddress) const { - return IsMeshLocalAddress(aAddress) && aAddress.IsIidRoutingLocator(); + return IsMeshLocalAddress(aAddress) && aAddress.GetIid().IsRoutingLocator(); } bool Mle::IsAnycastLocator(const Ip6::Address &aAddress) const { - return IsMeshLocalAddress(aAddress) && aAddress.IsIidAnycastLocator(); + return IsMeshLocalAddress(aAddress) && aAddress.GetIid().IsAnycastLocator(); } bool Mle::IsMeshLocalAddress(const Ip6::Address &aAddress) const @@ -3887,7 +3885,7 @@ void Mle::InformPreviousParent(void) messageInfo.SetSockAddr(GetMeshLocal64()); messageInfo.SetPeerAddr(GetMeshLocal16()); - messageInfo.GetPeerAddr().SetLocator(mPreviousParentRloc); + messageInfo.GetPeerAddr().GetIid().SetLocator(mPreviousParentRloc); SuccessOrExit(error = Get().SendDatagram(*message, messageInfo, Ip6::kProtoNone)); diff --git a/src/core/thread/mle_router.cpp b/src/core/thread/mle_router.cpp index 4e70eb23b..4ae545c72 100644 --- a/src/core/thread/mle_router.cpp +++ b/src/core/thread/mle_router.cpp @@ -611,9 +611,9 @@ void MleRouter::HandleLinkRequest(const Message &aMessage, const Ip6::MessageInf case OT_ERROR_NONE: if (IsActiveRouter(sourceAddress)) { - Mac::ExtAddress macAddr; + Mac::ExtAddress extAddr; - aMessageInfo.GetPeerAddr().ToExtAddress(macAddr); + aMessageInfo.GetPeerAddr().GetIid().ConvertToExtAddress(extAddr); neighbor = mRouterTable.GetRouter(RouterIdFromRloc16(sourceAddress)); VerifyOrExit(neighbor != nullptr, error = OT_ERROR_PARSE); @@ -623,7 +623,7 @@ void MleRouter::HandleLinkRequest(const Message &aMessage, const Ip6::MessageInf { const otThreadLinkInfo *linkInfo = static_cast(aMessageInfo.GetLinkInfo()); - neighbor->SetExtAddress(macAddr); + neighbor->SetExtAddress(extAddr); neighbor->GetLinkInfo().Clear(); neighbor->GetLinkInfo().AddRss(linkInfo->mRss); neighbor->ResetLinkFailures(); @@ -632,7 +632,7 @@ void MleRouter::HandleLinkRequest(const Message &aMessage, const Ip6::MessageInf } else { - VerifyOrExit(neighbor->GetExtAddress() == macAddr, OT_NOOP); + VerifyOrExit(neighbor->GetExtAddress() == extAddr, OT_NOOP); } } @@ -818,7 +818,7 @@ otError MleRouter::HandleLinkAccept(const Message & aMessage, const otThreadLinkInfo *linkInfo = static_cast(aMessageInfo.GetLinkInfo()); Router * router; Neighbor::State neighborState; - Mac::ExtAddress macAddr; + Mac::ExtAddress extAddr; uint16_t version; Challenge response; uint16_t sourceAddress; @@ -987,8 +987,8 @@ otError MleRouter::HandleLinkAccept(const Message & aMessage, } // finish link synchronization - aMessageInfo.GetPeerAddr().ToExtAddress(macAddr); - router->SetExtAddress(macAddr); + aMessageInfo.GetPeerAddr().GetIid().ConvertToExtAddress(extAddr); + router->SetExtAddress(extAddr); router->SetRloc16(sourceAddress); router->SetLinkFrameCounter(linkFrameCounter); router->SetMleFrameCounter(mleFrameCounter); @@ -1174,7 +1174,7 @@ otError MleRouter::HandleAdvertisement(const Message & aMessage, otError error = OT_ERROR_NONE; const otThreadLinkInfo *linkInfo = static_cast(aMessageInfo.GetLinkInfo()); uint8_t linkMargin = LinkQualityInfo::ConvertRssToLinkMargin(Get().GetNoiseFloor(), linkInfo->mRss); - Mac::ExtAddress macAddr; + Mac::ExtAddress extAddr; uint16_t sourceAddress = Mac::kShortAddrInvalid; LeaderData leaderData; RouteTlv route; @@ -1183,7 +1183,7 @@ otError MleRouter::HandleAdvertisement(const Message & aMessage, uint8_t routerId; uint8_t routerCount; - aMessageInfo.GetPeerAddr().ToExtAddress(macAddr); + aMessageInfo.GetPeerAddr().GetIid().ConvertToExtAddress(extAddr); // Source Address SuccessOrExit(error = Tlv::FindUint16Tlv(aMessage, Tlv::kSourceAddress, sourceAddress)); @@ -1371,7 +1371,7 @@ otError MleRouter::HandleAdvertisement(const Message & aMessage, if (IsFullThreadDevice() && !router->IsStateValid() && !router->IsStateLinkRequest() && (mRouterTable.GetActiveLinkCount() < OPENTHREAD_CONFIG_MLE_CHILD_ROUTER_LINKS)) { - router->SetExtAddress(macAddr); + router->SetExtAddress(extAddr); router->GetLinkInfo().Clear(); router->GetLinkInfo().AddRss(linkInfo->mRss); router->ResetLinkFailures(); @@ -1418,7 +1418,7 @@ otError MleRouter::HandleAdvertisement(const Message & aMessage, if (!router->IsStateValid() && !router->IsStateLinkRequest() && (mChallengeTimeout == 0) && (linkMargin >= OPENTHREAD_CONFIG_MLE_LINK_REQUEST_MARGIN_MIN)) { - router->SetExtAddress(macAddr); + router->SetExtAddress(extAddr); router->GetLinkInfo().Clear(); router->GetLinkInfo().AddRss(linkInfo->mRss); router->ResetLinkFailures(); @@ -1601,7 +1601,7 @@ void MleRouter::HandleParentRequest(const Message &aMessage, const Ip6::MessageI { otError error = OT_ERROR_NONE; const otThreadLinkInfo *linkInfo = static_cast(aMessageInfo.GetLinkInfo()); - Mac::ExtAddress macAddr; + Mac::ExtAddress extAddr; uint16_t version; uint8_t scanMask; Challenge challenge; @@ -1642,7 +1642,7 @@ void MleRouter::HandleParentRequest(const Message &aMessage, const Ip6::MessageI // the network (because Leader would reject any further address solicit). // ==> Verified below when checking the scan mask. - aMessageInfo.GetPeerAddr().ToExtAddress(macAddr); + aMessageInfo.GetPeerAddr().GetIid().ConvertToExtAddress(extAddr); // Version SuccessOrExit(error = Tlv::FindUint16Tlv(aMessage, Tlv::kVersion, version)); @@ -1671,14 +1671,14 @@ void MleRouter::HandleParentRequest(const Message &aMessage, const Ip6::MessageI // Challenge SuccessOrExit(error = ReadChallenge(aMessage, challenge)); - child = mChildTable.FindChild(macAddr, Child::kInStateAnyExceptInvalid); + child = mChildTable.FindChild(extAddr, Child::kInStateAnyExceptInvalid); if (child == nullptr) { VerifyOrExit((child = mChildTable.GetNewChild()) != nullptr, OT_NOOP); // MAC Address - child->SetExtAddress(macAddr); + child->SetExtAddress(extAddr); child->GetLinkInfo().Clear(); child->GetLinkInfo().AddRss(linkInfo->mRss); child->ResetLinkFailures(); @@ -2079,7 +2079,7 @@ otError MleRouter::UpdateChildAddresses(const Message &aMessage, uint16_t aOffse } else { - address = *entry.GetIp6Address(); + address = entry.GetIp6Address(); } #if OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE @@ -2160,7 +2160,7 @@ void MleRouter::HandleChildIdRequest(const Message & aMessage, { otError error = OT_ERROR_NONE; const otThreadLinkInfo *linkInfo = static_cast(aMessageInfo.GetLinkInfo()); - Mac::ExtAddress macAddr; + Mac::ExtAddress extAddr; uint16_t version; Challenge response; uint32_t linkFrameCounter; @@ -2184,9 +2184,9 @@ void MleRouter::HandleChildIdRequest(const Message & aMessage, VerifyOrExit(IsAttached(), error = OT_ERROR_INVALID_STATE); // Find Child - aMessageInfo.GetPeerAddr().ToExtAddress(macAddr); + aMessageInfo.GetPeerAddr().GetIid().ConvertToExtAddress(extAddr); - child = mChildTable.FindChild(macAddr, Child::kInStateAnyExceptInvalid); + child = mChildTable.FindChild(extAddr, Child::kInStateAnyExceptInvalid); VerifyOrExit(child != nullptr, error = OT_ERROR_ALREADY); // Version @@ -2252,7 +2252,7 @@ void MleRouter::HandleChildIdRequest(const Message & aMessage, } // Remove from router table - router = mRouterTable.GetRouter(macAddr); + router = mRouterTable.GetRouter(extAddr); if (router != nullptr) { // The `router` here can be invalid @@ -2336,7 +2336,7 @@ void MleRouter::HandleChildUpdateRequest(const Message & aMessage, static const uint8_t kMaxResponseTlvs = 10; otError error = OT_ERROR_NONE; - Mac::ExtAddress macAddr; + Mac::ExtAddress extAddr; uint8_t modeBitmask; DeviceMode mode; Challenge challenge; @@ -2370,8 +2370,8 @@ void MleRouter::HandleChildUpdateRequest(const Message & aMessage, } // Find Child - aMessageInfo.GetPeerAddr().ToExtAddress(macAddr); - child = mChildTable.FindChild(macAddr, Child::kInStateAnyExceptInvalid); + aMessageInfo.GetPeerAddr().GetIid().ConvertToExtAddress(extAddr); + child = mChildTable.FindChild(extAddr, Child::kInStateAnyExceptInvalid); tlvs[tlvslength++] = Tlv::kSourceAddress; @@ -3451,15 +3451,15 @@ Neighbor *MleRouter::GetNeighbor(const Mac::Address &aAddress) Neighbor *MleRouter::GetNeighbor(const Ip6::Address &aAddress) { - Mac::Address macAddr; Lowpan::Context context; Child * child; Neighbor * rval = nullptr; if (aAddress.IsLinkLocal()) { - aAddress.ToExtAddress(macAddr); + Mac::Address macAddr; + aAddress.GetIid().ConvertToMacAddress(macAddr); ExitNow(rval = GetNeighbor(macAddr)); } @@ -3472,8 +3472,8 @@ Neighbor *MleRouter::GetNeighbor(const Ip6::Address &aAddress) { child = iter.GetChild(); - if ((context.mContextId == kMeshLocalPrefixContextId) && aAddress.IsIidLocator() && - (aAddress.GetLocator() == child->GetRloc16())) + if ((context.mContextId == kMeshLocalPrefixContextId) && aAddress.GetIid().IsLocator() && + (aAddress.GetIid().GetLocator() == child->GetRloc16())) { ExitNow(rval = child); } @@ -3486,9 +3486,9 @@ Neighbor *MleRouter::GetNeighbor(const Ip6::Address &aAddress) VerifyOrExit(context.mContextId == kMeshLocalPrefixContextId, rval = nullptr); - if (aAddress.IsIidLocator()) + if (aAddress.GetIid().IsLocator()) { - rval = mRouterTable.GetNeighbor(aAddress.GetLocator()); + rval = mRouterTable.GetNeighbor(aAddress.GetIid().GetLocator()); } exit: diff --git a/src/core/thread/mle_tlvs.hpp b/src/core/thread/mle_tlvs.hpp index cf9ef4700..bae885d07 100644 --- a/src/core/thread/mle_tlvs.hpp +++ b/src/core/thread/mle_tlvs.hpp @@ -923,28 +923,28 @@ public: void SetContextId(uint8_t aContextId) { mControl = kCompressed | aContextId; } /** - * This method returns a pointer to the IID value. + * This method returns the IID value. * - * @returns A pointer to the IID value. + * @returns The IID value. * */ - const uint8_t *GetIid(void) const { return mIid; } + const Ip6::InterfaceIdentifier &GetIid(void) const { return mIid; } /** * This method sets the IID value. * - * @param[in] aIid A pointer to the IID value. + * @param[in] aIid The IID value. * */ - void SetIid(const uint8_t *aIid) { memcpy(mIid, aIid, sizeof(mIid)); } + void SetIid(const Ip6::InterfaceIdentifier &aIid) { mIid = aIid; } /** - * This method returns a pointer to the IPv6 Address value. + * This method returns the IPv6 Address value. * - * @returns A pointer to the IPv6 Address value. + * @returns The IPv6 Address value. * */ - const Ip6::Address *GetIp6Address(void) const { return &mIp6Address; } + const Ip6::Address &GetIp6Address(void) const { return mIp6Address; } /** * This method sets the IPv6 Address value. @@ -964,8 +964,8 @@ private: uint8_t mControl; union { - uint8_t mIid[Ip6::Address::kInterfaceIdentifierSize]; - Ip6::Address mIp6Address; + Ip6::InterfaceIdentifier mIid; + Ip6::Address mIp6Address; } OT_TOOL_PACKED_FIELD; } OT_TOOL_PACKED_END; diff --git a/src/core/thread/network_data_leader_ftd.cpp b/src/core/thread/network_data_leader_ftd.cpp index 364814a6b..de07466b8 100644 --- a/src/core/thread/network_data_leader_ftd.cpp +++ b/src/core/thread/network_data_leader_ftd.cpp @@ -144,7 +144,7 @@ void Leader::HandleServerData(Coap::Message &aMessage, const Ip6::MessageInfo &a otLogInfoNetData("Received network data registration"); - VerifyOrExit(aMessageInfo.GetPeerAddr().IsIidRoutingLocator(), OT_NOOP); + VerifyOrExit(aMessageInfo.GetPeerAddr().GetIid().IsRoutingLocator(), OT_NOOP); switch (Tlv::FindUint16Tlv(aMessage, ThreadTlv::kRloc16, rloc16)) { @@ -160,7 +160,8 @@ void Leader::HandleServerData(Coap::Message &aMessage, const Ip6::MessageInfo &a if (ThreadTlv::FindTlv(aMessage, ThreadTlv::kThreadNetworkData, sizeof(networkData), networkData) == OT_ERROR_NONE) { VerifyOrExit(networkData.IsValid(), OT_NOOP); - RegisterNetworkData(aMessageInfo.GetPeerAddr().GetLocator(), networkData.GetTlvs(), networkData.GetLength()); + RegisterNetworkData(aMessageInfo.GetPeerAddr().GetIid().GetLocator(), networkData.GetTlvs(), + networkData.GetLength()); } SuccessOrExit(Get().SendEmptyAck(aMessage, aMessageInfo)); diff --git a/src/core/thread/network_diagnostic_tlvs.hpp b/src/core/thread/network_diagnostic_tlvs.hpp index 7a32704df..2d682ef8a 100644 --- a/src/core/thread/network_diagnostic_tlvs.hpp +++ b/src/core/thread/network_diagnostic_tlvs.hpp @@ -884,7 +884,7 @@ public: * @retval FALSE If the TLV does not appear to be well-formed. * */ - bool IsValid(void) const { return !IsExtended() && (GetLength() % OT_IP6_ADDRESS_SIZE == 0); } + bool IsValid(void) const { return !IsExtended() && (GetLength() % sizeof(Ip6::Address) == 0); } /** * This method returns a pointer to the IPv6 address entry. diff --git a/src/core/thread/topology.cpp b/src/core/thread/topology.cpp index 8a2b007c1..b49256f9c 100644 --- a/src/core/thread/topology.cpp +++ b/src/core/thread/topology.cpp @@ -121,37 +121,15 @@ void Child::Clear(void) void Child::ClearIp6Addresses(void) { - memset(mMeshLocalIid, 0, sizeof(mMeshLocalIid)); + mMeshLocalIid.Clear(); memset(mIp6Address, 0, sizeof(mIp6Address)); } -/** - * Determines if all elements in an array are zero. - * - * @param[in] aArray A pointer to an array of bytes. - * @param[in] aLength Array length (number of bytes). - * - * @returns TRUE if all bytes in the array are zero, FALSE otherwise. - * - */ -static bool IsAllZero(const uint8_t *aArray, uint8_t aLength) -{ - bool retval = true; - - for (; aLength != 0; aArray++, aLength--) - { - VerifyOrExit(*aArray == 0, retval = false); - } - -exit: - return retval; -} - otError Child::GetMeshLocalIp6Address(Ip6::Address &aAddress) const { otError error = OT_ERROR_NONE; - VerifyOrExit(!IsAllZero(mMeshLocalIid, sizeof(mMeshLocalIid)), error = OT_ERROR_NOT_FOUND); + VerifyOrExit(!mMeshLocalIid.IsUnspecified(), error = OT_ERROR_NOT_FOUND); aAddress.SetPrefix(Get().GetMeshLocalPrefix()); aAddress.SetIid(mMeshLocalIid); @@ -193,8 +171,8 @@ otError Child::AddIp6Address(const Ip6::Address &aAddress) if (Get().IsMeshLocalAddress(aAddress)) { - VerifyOrExit(IsAllZero(mMeshLocalIid, sizeof(mMeshLocalIid)), error = OT_ERROR_ALREADY); - memcpy(mMeshLocalIid, aAddress.GetIid(), Ip6::Address::kInterfaceIdentifierSize); + VerifyOrExit(mMeshLocalIid.IsUnspecified(), error = OT_ERROR_ALREADY); + mMeshLocalIid = aAddress.GetIid(); ExitNow(); } @@ -224,9 +202,9 @@ otError Child::RemoveIp6Address(const Ip6::Address &aAddress) if (Get().IsMeshLocalAddress(aAddress)) { - if (memcmp(aAddress.GetIid(), mMeshLocalIid, Ip6::Address::kInterfaceIdentifierSize) == 0) + if (aAddress.GetIid() == mMeshLocalIid) { - memset(mMeshLocalIid, 0, sizeof(mMeshLocalIid)); + mMeshLocalIid.Clear(); error = OT_ERROR_NONE; } @@ -265,7 +243,7 @@ bool Child::HasIp6Address(const Ip6::Address &aAddress) const if (Get().IsMeshLocalAddress(aAddress)) { - retval = (memcmp(aAddress.GetIid(), mMeshLocalIid, Ip6::Address::kInterfaceIdentifierSize) == 0); + retval = (aAddress.GetIid() == mMeshLocalIid); ExitNow(); } diff --git a/src/core/thread/topology.hpp b/src/core/thread/topology.hpp index 425a4fcbc..7599ffd0c 100644 --- a/src/core/thread/topology.hpp +++ b/src/core/thread/topology.hpp @@ -585,12 +585,12 @@ public: otError GetMeshLocalIp6Address(Ip6::Address &aAddress) const; /** - * This method returns a pointer to the Mesh Local Interface Identifier. + * This method returns the Mesh Local Interface Identifier. * - * @returns a pointer to the Mesh Local Interface Identifier. + * @returns The Mesh Local Interface Identifier. * */ - const uint8_t *GetMeshLocalIid(void) const { return mMeshLocalIid; } + const Ip6::InterfaceIdentifier &GetMeshLocalIid(void) const { return mMeshLocalIid; } /** * This method gets the next IPv6 address in the list. @@ -753,9 +753,9 @@ private: kNumIp6Addresses = OPENTHREAD_CONFIG_MLE_IP_ADDRS_PER_CHILD - 1, }; - uint8_t mNetworkDataVersion; ///< Current Network Data version - uint8_t mMeshLocalIid[Ip6::Address::kInterfaceIdentifierSize]; ///< IPv6 address IID for mesh-local address - Ip6::Address mIp6Address[kNumIp6Addresses]; ///< Registered IPv6 addresses + uint8_t mNetworkDataVersion; ///< Current Network Data version + Ip6::InterfaceIdentifier mMeshLocalIid; ///< IPv6 address IID for mesh-local address + Ip6::Address mIp6Address[kNumIp6Addresses]; ///< Registered IPv6 addresses uint32_t mTimeout; ///< Child timeout diff --git a/src/core/utils/slaac_address.cpp b/src/core/utils/slaac_address.cpp index f4d646863..4971f386b 100644 --- a/src/core/utils/slaac_address.cpp +++ b/src/core/utils/slaac_address.cpp @@ -290,7 +290,7 @@ otError Slaac::GenerateIid(Ip6::NetifUnicastAddress &aAddress, Crypto::Sha256 sha256; uint8_t hash[Crypto::Sha256::kHashSize]; - static_assert(sizeof(hash) >= Ip6::Address::kInterfaceIdentifierSize, + static_assert(sizeof(hash) >= Ip6::InterfaceIdentifier::kSize, "SHA-256 hash size is too small to use as IPv6 address IID"); GetIidSecretKey(secretKey); @@ -310,10 +310,10 @@ otError Slaac::GenerateIid(Ip6::NetifUnicastAddress &aAddress, sha256.Update(secretKey.m8, sizeof(IidSecretKey)); sha256.Finish(hash); - aAddress.GetAddress().SetIid(&hash[0]); + aAddress.GetAddress().GetIid().SetBytes(&hash[0]); // If the IID is reserved, try again with a new dadCounter - if (aAddress.GetAddress().IsIidReserved()) + if (aAddress.GetAddress().GetIid().IsReserved()) { continue; } diff --git a/tests/unit/test_child.cpp b/tests/unit/test_child.cpp index 4fed9fa85..3a14a3ce1 100644 --- a/tests/unit/test_child.cpp +++ b/tests/unit/test_child.cpp @@ -114,7 +114,10 @@ void TestChildIp6Address(void) "fd00:1234::204c:3d7c:98f6:9a1b", }; - const uint8_t meshLocalIid[] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88}; + const uint8_t meshLocalIidArray[] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88}; + Ip6::InterfaceIdentifier meshLocalIid; + + meshLocalIid.SetBytes(meshLocalIidArray); sInstance = testInitInstance(); VerifyOrQuit(sInstance != nullptr, "Null instance");