mirror of
https://github.com/espressif/openthread.git
synced 2026-06-05 21:14:49 +00:00
[icmp6] use Icmp6Header instead of Icmp::Header (#13194)
This commit updates the codebase to use the `Icmp6Header` type directly, replacing the nested `Ip6::Icmp::Header` definition. This change aligns the ICMPv6 header type definition with the conventions used for other network protocol headers and simplifies type references across the network, border router, and utility modules.
This commit is contained in:
committed by
GitHub
parent
ecd4c92465
commit
ab3c6600a0
@@ -1044,14 +1044,14 @@ void Core::HandleIcmpResponse(void *aContext,
|
||||
OT_UNUSED_VARIABLE(aMessage);
|
||||
|
||||
IcmpEchoResponseContext *context = static_cast<IcmpEchoResponseContext *>(aContext);
|
||||
const Ip6::Icmp::Header *header = AsCoreTypePtr(aIcmpHeader);
|
||||
const Ip6::Icmp6Header *header = AsCoreTypePtr(aIcmpHeader);
|
||||
const Ip6::MessageInfo *messageInfo = AsCoreTypePtr(aMessageInfo);
|
||||
|
||||
VerifyOrQuit(context != nullptr);
|
||||
VerifyOrQuit(header != nullptr);
|
||||
VerifyOrQuit(messageInfo != nullptr);
|
||||
|
||||
if ((header->GetType() == Ip6::Icmp::Header::kTypeEchoReply) && (header->GetId() == context->mIdentifier))
|
||||
if ((header->GetType() == Ip6::Icmp6Header::kTypeEchoReply) && (header->GetId() == context->mIdentifier))
|
||||
{
|
||||
context->mResponseReceived = true;
|
||||
|
||||
|
||||
@@ -247,11 +247,11 @@ void InfraIf::ProcessIcmp6Nd(const Ip6::Address &aSrcAddress, const uint8_t *aBu
|
||||
|
||||
packet.Init(aBuffer, aBufferLength);
|
||||
|
||||
VerifyOrExit(packet.GetLength() >= sizeof(Ip6::Icmp::Header));
|
||||
VerifyOrExit(packet.GetLength() >= sizeof(Ip6::Icmp6Header));
|
||||
|
||||
switch (reinterpret_cast<const Ip6::Icmp::Header *>(packet.GetBytes())->GetType())
|
||||
switch (reinterpret_cast<const Ip6::Icmp6Header *>(packet.GetBytes())->GetType())
|
||||
{
|
||||
case Ip6::Icmp::Header::kTypeRouterAdvert:
|
||||
case Ip6::Icmp6Header::kTypeRouterAdvert:
|
||||
{
|
||||
Ip6::Nd::RouterAdvert::RxMessage raMessage(packet);
|
||||
|
||||
@@ -267,12 +267,12 @@ void InfraIf::ProcessIcmp6Nd(const Ip6::Address &aSrcAddress, const uint8_t *aBu
|
||||
break;
|
||||
}
|
||||
|
||||
case Ip6::Icmp::Header::kTypeRouterSolicit:
|
||||
case Ip6::Icmp6Header::kTypeRouterSolicit:
|
||||
HandleRouterSolicitation(aSrcAddress);
|
||||
break;
|
||||
|
||||
case Ip6::Icmp::Header::kTypeNeighborAdvert:
|
||||
case Ip6::Icmp::Header::kTypeNeighborSolicit:
|
||||
case Ip6::Icmp6Header::kTypeNeighborAdvert:
|
||||
case Ip6::Icmp6Header::kTypeNeighborSolicit:
|
||||
// TODO: Handle other ND messages as needed for the simulation.
|
||||
break;
|
||||
|
||||
@@ -345,24 +345,24 @@ void InfraIf::SendEchoRequest(const Ip6::Address &aSrcAddress,
|
||||
uint16_t aPayloadSize,
|
||||
uint8_t aHopLimit)
|
||||
{
|
||||
Message *message;
|
||||
Ip6::Header ip6Header;
|
||||
Ip6::Icmp::Header icmpHeader;
|
||||
Message *message;
|
||||
Ip6::Header ip6Header;
|
||||
Ip6::Icmp6Header icmpHeader;
|
||||
|
||||
message = Get<Ip6::Ip6>().NewMessage();
|
||||
VerifyOrQuit(message != nullptr);
|
||||
|
||||
ip6Header.Clear();
|
||||
ip6Header.InitVersionTrafficClassFlow();
|
||||
ip6Header.SetPayloadLength(sizeof(Ip6::Icmp::Header) + aPayloadSize);
|
||||
ip6Header.SetPayloadLength(sizeof(Ip6::Icmp6Header) + aPayloadSize);
|
||||
ip6Header.SetNextHeader(Ip6::kProtoIcmp6);
|
||||
ip6Header.SetHopLimit(aHopLimit);
|
||||
ip6Header.SetSource(aSrcAddress);
|
||||
ip6Header.SetDestination(aDestAddress);
|
||||
|
||||
icmpHeader.Clear();
|
||||
icmpHeader.SetType(Ip6::Icmp::Header::kTypeEchoRequest);
|
||||
icmpHeader.SetCode(static_cast<Ip6::Icmp::Header::Code>(0));
|
||||
icmpHeader.SetType(Ip6::Icmp6Header::kTypeEchoRequest);
|
||||
icmpHeader.SetCode(static_cast<Ip6::Icmp6Header::Code>(0));
|
||||
icmpHeader.SetId(aIdentifier);
|
||||
icmpHeader.SetSequence(0);
|
||||
|
||||
@@ -446,10 +446,10 @@ void InfraIf::Receive(Message &aMessage)
|
||||
{
|
||||
switch (headers.GetIcmpHeader().GetType())
|
||||
{
|
||||
case Ip6::Icmp::Header::kTypeRouterAdvert:
|
||||
case Ip6::Icmp::Header::kTypeRouterSolicit:
|
||||
case Ip6::Icmp::Header::kTypeNeighborAdvert:
|
||||
case Ip6::Icmp::Header::kTypeNeighborSolicit:
|
||||
case Ip6::Icmp6Header::kTypeRouterAdvert:
|
||||
case Ip6::Icmp6Header::kTypeRouterSolicit:
|
||||
case Ip6::Icmp6Header::kTypeNeighborAdvert:
|
||||
case Ip6::Icmp6Header::kTypeNeighborSolicit:
|
||||
{
|
||||
Heap::Data payload;
|
||||
uint16_t offset = sizeof(Ip6::Header);
|
||||
@@ -462,11 +462,11 @@ void InfraIf::Receive(Message &aMessage)
|
||||
ExitNow();
|
||||
}
|
||||
|
||||
case Ip6::Icmp::Header::kTypeEchoRequest:
|
||||
case Ip6::Icmp6Header::kTypeEchoRequest:
|
||||
HandleEchoRequest(headers.GetIp6Header(), aMessage);
|
||||
ExitNow();
|
||||
|
||||
case Ip6::Icmp::Header::kTypeEchoReply:
|
||||
case Ip6::Icmp6Header::kTypeEchoReply:
|
||||
HandleEchoReply(headers.GetIp6Header(), aMessage);
|
||||
ExitNow();
|
||||
|
||||
@@ -584,10 +584,10 @@ exit:
|
||||
|
||||
void InfraIf::HandleEchoRequest(const Ip6::Header &aHeader, Message &aMessage)
|
||||
{
|
||||
Message *replyMessage;
|
||||
Ip6::Header replyHeader;
|
||||
Ip6::Icmp::Header replyIcmp;
|
||||
uint16_t payloadLen = aMessage.GetLength() - sizeof(Ip6::Header);
|
||||
Message *replyMessage;
|
||||
Ip6::Header replyHeader;
|
||||
Ip6::Icmp6Header replyIcmp;
|
||||
uint16_t payloadLen = aMessage.GetLength() - sizeof(Ip6::Header);
|
||||
|
||||
replyMessage = Get<MessagePool>().Allocate(Message::kTypeIp6);
|
||||
VerifyOrQuit(replyMessage != nullptr);
|
||||
@@ -604,7 +604,7 @@ void InfraIf::HandleEchoRequest(const Ip6::Header &aHeader, Message &aMessage)
|
||||
replyHeader.SetSource(aHeader.GetDestination());
|
||||
replyHeader.SetDestination(aHeader.GetSource());
|
||||
|
||||
replyIcmp.SetType(Ip6::Icmp::Header::kTypeEchoReply);
|
||||
replyIcmp.SetType(Ip6::Icmp6Header::kTypeEchoReply);
|
||||
replyMessage->Write(0, replyIcmp);
|
||||
|
||||
// Recalculate ICMPv6 checksum
|
||||
@@ -619,7 +619,7 @@ void InfraIf::HandleEchoRequest(const Ip6::Header &aHeader, Message &aMessage)
|
||||
|
||||
void InfraIf::HandleEchoReply(const Ip6::Header &aHeader, Message &aMessage)
|
||||
{
|
||||
Ip6::Icmp::Header icmpHeader;
|
||||
Ip6::Icmp6Header icmpHeader;
|
||||
|
||||
SuccessOrQuit(aMessage.Read(sizeof(Ip6::Header), icmpHeader));
|
||||
mEchoReplyCallback.InvokeIfSet(aHeader.GetSource(), icmpHeader.GetId(), icmpHeader.GetSequence());
|
||||
|
||||
@@ -175,7 +175,7 @@ void TestHistoryTracker(void)
|
||||
VerifyOrQuit(txRequestsFound < 3);
|
||||
uint16_t expectedSize = kPingSizes[2 - txRequestsFound];
|
||||
VerifyOrQuit(msgInfo->mIpProto == OT_IP6_PROTO_ICMP6);
|
||||
VerifyOrQuit(msgInfo->mPayloadLength == expectedSize + sizeof(Ip6::Icmp::Header));
|
||||
VerifyOrQuit(msgInfo->mPayloadLength == expectedSize + sizeof(Ip6::Icmp6Header));
|
||||
VerifyOrQuit(AsCoreType(&msgInfo->mSource.mAddress) == leader.Get<Mle::Mle>().GetMeshLocalEid());
|
||||
VerifyOrQuit(AsCoreType(&msgInfo->mDestination.mAddress) == child.Get<Mle::Mle>().GetMeshLocalEid());
|
||||
VerifyOrQuit(msgInfo->mLinkSecurity);
|
||||
@@ -199,7 +199,7 @@ void TestHistoryTracker(void)
|
||||
VerifyOrQuit(rxRequestsFound < 3);
|
||||
uint16_t expectedSize = kPingSizes[2 - rxRequestsFound];
|
||||
VerifyOrQuit(msgInfo->mIpProto == OT_IP6_PROTO_ICMP6);
|
||||
VerifyOrQuit(msgInfo->mPayloadLength == expectedSize + sizeof(Ip6::Icmp::Header));
|
||||
VerifyOrQuit(msgInfo->mPayloadLength == expectedSize + sizeof(Ip6::Icmp6Header));
|
||||
VerifyOrQuit(AsCoreType(&msgInfo->mSource.mAddress) == leader.Get<Mle::Mle>().GetMeshLocalEid());
|
||||
VerifyOrQuit(AsCoreType(&msgInfo->mDestination.mAddress) == child.Get<Mle::Mle>().GetMeshLocalEid());
|
||||
VerifyOrQuit(msgInfo->mLinkSecurity);
|
||||
|
||||
@@ -377,10 +377,10 @@ Message *PrepareIcmp6Message(Node &aNode,
|
||||
const Ip4::Address &aDstIp4Address,
|
||||
uint16_t aPayloadLen = 10)
|
||||
{
|
||||
Message *message = nullptr;
|
||||
Ip6::Prefix nat64Prefix;
|
||||
Ip6::Header ip6Header;
|
||||
Ip6::Icmp::Header icmpHeader;
|
||||
Message *message = nullptr;
|
||||
Ip6::Prefix nat64Prefix;
|
||||
Ip6::Header ip6Header;
|
||||
Ip6::Icmp6Header icmpHeader;
|
||||
|
||||
message = aNode.Get<MessagePool>().Allocate(Message::kTypeIp6);
|
||||
VerifyOrQuit(message != nullptr);
|
||||
@@ -394,12 +394,12 @@ Message *PrepareIcmp6Message(Node &aNode,
|
||||
ip6Header.GetDestination().SynthesizeFromIp4Address(nat64Prefix, aDstIp4Address);
|
||||
|
||||
ip6Header.SetNextHeader(Ip6::kProtoIcmp6);
|
||||
ip6Header.SetPayloadLength(sizeof(Ip6::Icmp::Header) + aPayloadLen);
|
||||
ip6Header.SetPayloadLength(sizeof(Ip6::Icmp6Header) + aPayloadLen);
|
||||
|
||||
SuccessOrQuit(message->Append(ip6Header));
|
||||
|
||||
icmpHeader.Clear();
|
||||
icmpHeader.SetType(Ip6::Icmp::Header::kTypeEchoRequest);
|
||||
icmpHeader.SetType(Ip6::Icmp6Header::kTypeEchoRequest);
|
||||
|
||||
SuccessOrQuit(message->Append(icmpHeader));
|
||||
|
||||
|
||||
@@ -45,10 +45,10 @@ struct NoEchoReplyContext
|
||||
|
||||
void HandleIcmpNoEchoReply(void *aContext, otMessage *, const otMessageInfo *, const otIcmp6Header *aIcmpHeader)
|
||||
{
|
||||
NoEchoReplyContext *ctx = static_cast<NoEchoReplyContext *>(aContext);
|
||||
const Ip6::Icmp::Header *header = AsCoreTypePtr(aIcmpHeader);
|
||||
NoEchoReplyContext *ctx = static_cast<NoEchoReplyContext *>(aContext);
|
||||
const Ip6::Icmp6Header *header = AsCoreTypePtr(aIcmpHeader);
|
||||
|
||||
if (header->GetType() == Ip6::Icmp::Header::kTypeEchoReply && header->GetId() == ctx->mId)
|
||||
if (header->GetType() == Ip6::Icmp6Header::kTypeEchoReply && header->GetId() == ctx->mId)
|
||||
{
|
||||
ctx->mReceived = true;
|
||||
}
|
||||
|
||||
@@ -157,10 +157,10 @@ struct IcmpResponseContext
|
||||
|
||||
static void HandleIcmpResponse(void *aContext, otMessage *, const otMessageInfo *, const otIcmp6Header *aIcmpHeader)
|
||||
{
|
||||
IcmpResponseContext *context = static_cast<IcmpResponseContext *>(aContext);
|
||||
const Ip6::Icmp::Header *header = AsCoreTypePtr(aIcmpHeader);
|
||||
IcmpResponseContext *context = static_cast<IcmpResponseContext *>(aContext);
|
||||
const Ip6::Icmp6Header *header = AsCoreTypePtr(aIcmpHeader);
|
||||
|
||||
if ((header->GetType() == Ip6::Icmp::Header::kTypeEchoReply) && (header->GetId() == context->mIdentifier))
|
||||
if ((header->GetType() == Ip6::Icmp6Header::kTypeEchoReply) && (header->GetId() == context->mIdentifier))
|
||||
{
|
||||
context->mResponseReceived = true;
|
||||
}
|
||||
|
||||
@@ -240,7 +240,7 @@ void TestUdpMessageChecksum(void)
|
||||
|
||||
void TestIcmp6MessageChecksum(void)
|
||||
{
|
||||
constexpr uint16_t kMinSize = sizeof(Ip6::Icmp::Header);
|
||||
constexpr uint16_t kMinSize = sizeof(Ip6::Icmp6Header);
|
||||
constexpr uint16_t kMaxSize = Buffer::kSize * 3 + 24;
|
||||
|
||||
const char *kSourceAddress = "fd00:feef:dccd:baab:9889:7667:5444:3223";
|
||||
@@ -252,9 +252,9 @@ void TestIcmp6MessageChecksum(void)
|
||||
|
||||
for (uint16_t size = kMinSize; size <= kMaxSize; size++)
|
||||
{
|
||||
Message *message = instance->Get<Ip6::Ip6>().NewMessage();
|
||||
Ip6::Icmp::Header icmp6Header;
|
||||
Ip6::MessageInfo messageInfo;
|
||||
Message *message = instance->Get<Ip6::Ip6>().NewMessage();
|
||||
Ip6::Icmp6Header icmp6Header;
|
||||
Ip6::MessageInfo messageInfo;
|
||||
|
||||
VerifyOrQuit(message != nullptr, "Ip6::NewMesssage() failed");
|
||||
SuccessOrQuit(message->SetLength(size));
|
||||
|
||||
@@ -302,8 +302,8 @@ otError otPlatInfraIfSendIcmp6Nd(otInstance *aInstance,
|
||||
const uint8_t *aBuffer,
|
||||
uint16_t aBufferLength)
|
||||
{
|
||||
Icmp6Packet packet;
|
||||
Ip6::Icmp::Header *header;
|
||||
Icmp6Packet packet;
|
||||
Ip6::Icmp6Header *header;
|
||||
|
||||
Log("otPlatInfraIfSendIcmp6Nd(aDestAddr: %s, aBufferLength:%u)", AsCoreType(aDestAddress).ToString().AsCString(),
|
||||
aBufferLength);
|
||||
@@ -313,19 +313,19 @@ otError otPlatInfraIfSendIcmp6Nd(otInstance *aInstance,
|
||||
|
||||
packet.Init(aBuffer, aBufferLength);
|
||||
|
||||
VerifyOrQuit(aBufferLength >= sizeof(Ip6::Icmp::Header));
|
||||
VerifyOrQuit(aBufferLength >= sizeof(Ip6::Icmp6Header));
|
||||
|
||||
header = reinterpret_cast<Ip6::Icmp::Header *>(const_cast<uint8_t *>(aBuffer));
|
||||
header = reinterpret_cast<Ip6::Icmp6Header *>(const_cast<uint8_t *>(aBuffer));
|
||||
|
||||
switch (header->GetType())
|
||||
{
|
||||
case Ip6::Icmp::Header::kTypeRouterSolicit:
|
||||
case Ip6::Icmp6Header::kTypeRouterSolicit:
|
||||
Log(" Router Solicit message");
|
||||
sRsEmitted = true;
|
||||
otPlatInfraIfRecvIcmp6Nd(sInstance, kInfraIfIndex, &sInfraIfAddress, aBuffer, aBufferLength);
|
||||
break;
|
||||
|
||||
case Ip6::Icmp::Header::kTypeRouterAdvert:
|
||||
case Ip6::Icmp6Header::kTypeRouterAdvert:
|
||||
Log(" Router Advertisement message");
|
||||
LogRouterAdvert(packet);
|
||||
ValidateRouterAdvert(packet);
|
||||
@@ -335,7 +335,7 @@ otError otPlatInfraIfSendIcmp6Nd(otInstance *aInstance,
|
||||
otPlatInfraIfRecvIcmp6Nd(sInstance, kInfraIfIndex, &sInfraIfAddress, aBuffer, aBufferLength);
|
||||
break;
|
||||
|
||||
case Ip6::Icmp::Header::kTypeNeighborSolicit:
|
||||
case Ip6::Icmp6Header::kTypeNeighborSolicit:
|
||||
{
|
||||
const Ip6::Nd::NeighborSolicitHeader *nsMsg =
|
||||
reinterpret_cast<const Ip6::Nd::NeighborSolicitHeader *>(packet.GetBytes());
|
||||
|
||||
Reference in New Issue
Block a user