From 6a277399e1465427ecf3003fc7353f49bb31b739 Mon Sep 17 00:00:00 2001 From: Jonathan Hui Date: Mon, 16 Mar 2020 08:56:17 -0700 Subject: [PATCH] [dhcp6] use Ip6::Address::SetPrefix() (#4685) --- src/core/meshcop/dataset_manager_ftd.cpp | 16 ++++++++-------- src/core/net/dhcp6_client.cpp | 3 +-- src/core/net/dhcp6_server.cpp | 2 +- src/core/net/dhcp6_server.hpp | 6 +++--- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/core/meshcop/dataset_manager_ftd.cpp b/src/core/meshcop/dataset_manager_ftd.cpp index cafb1e66e..6d23326ca 100644 --- a/src/core/meshcop/dataset_manager_ftd.cpp +++ b/src/core/meshcop/dataset_manager_ftd.cpp @@ -79,13 +79,13 @@ otError DatasetManager::HandleSet(Coap::Message &aMessage, const Ip6::MessageInf StateTlv::State state = StateTlv::kReject; Dataset dataset(mLocal.GetType()); - ActiveTimestampTlv activeTimestamp; - PendingTimestampTlv pendingTimestamp; - ChannelTlv channel; - uint16_t sessionId; - otMeshLocalPrefix meshLocalPrefix; - MasterKey masterKey; - uint16_t panId; + ActiveTimestampTlv activeTimestamp; + PendingTimestampTlv pendingTimestamp; + ChannelTlv channel; + uint16_t sessionId; + Mle::MeshLocalPrefix meshLocalPrefix; + MasterKey masterKey; + uint16_t panId; activeTimestamp.SetLength(0); pendingTimestamp.SetLength(0); @@ -144,7 +144,7 @@ otError DatasetManager::HandleSet(Coap::Message &aMessage, const Ip6::MessageInf // check mesh local prefix if (Tlv::ReadTlv(aMessage, Tlv::kMeshLocalPrefix, &meshLocalPrefix, sizeof(meshLocalPrefix)) == OT_ERROR_NONE && - memcmp(&meshLocalPrefix, &Get().GetMeshLocalPrefix(), sizeof(meshLocalPrefix))) + meshLocalPrefix != Get().GetMeshLocalPrefix()) { doesAffectConnectivity = true; } diff --git a/src/core/net/dhcp6_client.cpp b/src/core/net/dhcp6_client.cpp index b39298b62..29cd50527 100644 --- a/src/core/net/dhcp6_client.cpp +++ b/src/core/net/dhcp6_client.cpp @@ -280,8 +280,7 @@ otError Dhcp6Client::Solicit(uint16_t aRloc16) messageInfo.GetPeerAddr().mFields.m16[0] = HostSwap16(0xff03); messageInfo.GetPeerAddr().mFields.m16[7] = HostSwap16(0x0002); #else - memcpy(messageInfo.GetPeerAddr().mFields.m8, Get().GetMeshLocalPrefix().m8, - sizeof(otMeshLocalPrefix)); + messageInfo.GetPeerAddr().SetPrefix(Get().GetMeshLocalPrefix()); messageInfo.GetPeerAddr().mFields.m16[4] = HostSwap16(0x0000); messageInfo.GetPeerAddr().mFields.m16[5] = HostSwap16(0x00ff); messageInfo.GetPeerAddr().mFields.m16[6] = HostSwap16(0xfe00); diff --git a/src/core/net/dhcp6_server.cpp b/src/core/net/dhcp6_server.cpp index b8eadfbac..345ec8921 100644 --- a/src/core/net/dhcp6_server.cpp +++ b/src/core/net/dhcp6_server.cpp @@ -464,7 +464,7 @@ otError Dhcp6Server::AddIaAddress(Message &aMessage, const Ip6::Address &aPrefix IaAddress option; option.Init(); - memcpy(option.GetAddress().mFields.m8, &aPrefix, OT_IP6_PREFIX_SIZE); + option.GetAddress().SetPrefix(aPrefix.mFields.m8, OT_IP6_PREFIX_BITSIZE); option.GetAddress().SetIid(*reinterpret_cast(aClientId.GetDuidLinkLayerAddress())); option.SetPreferredLifetime(OT_DHCP6_DEFAULT_PREFERRED_LIFETIME); option.SetValidLifetime(OT_DHCP6_DEFAULT_VALID_LIFETIME); diff --git a/src/core/net/dhcp6_server.hpp b/src/core/net/dhcp6_server.hpp index b2dc653eb..774e1f60d 100644 --- a/src/core/net/dhcp6_server.hpp +++ b/src/core/net/dhcp6_server.hpp @@ -163,17 +163,17 @@ private: * @param[in] aContextId The 6LoWPAN Context ID. * */ - void Set(const otIp6Prefix &aPrefix, const otMeshLocalPrefix &aMeshLocalPrefix, uint8_t aContextId) + void Set(const otIp6Prefix &aPrefix, const Mle::MeshLocalPrefix &aMeshLocalPrefix, uint8_t aContextId) { mPrefix = aPrefix; - memcpy(&mAloc.mAddress, &aMeshLocalPrefix, OT_IP6_PREFIX_SIZE); + mAloc.GetAddress().SetPrefix(aMeshLocalPrefix); mAloc.mAddress.mFields.m16[4] = HostSwap16(0x0000); mAloc.mAddress.mFields.m16[5] = HostSwap16(0x00ff); mAloc.mAddress.mFields.m16[6] = HostSwap16(0xfe00); mAloc.mAddress.mFields.m8[14] = Ip6::Address::kAloc16Mask; mAloc.mAddress.mFields.m8[15] = aContextId; - mAloc.mPrefixLength = 64; + mAloc.mPrefixLength = OT_IP6_PREFIX_BITSIZE; mAloc.mPreferred = true; mAloc.mValid = true; }