Skip to content

Commit

Permalink
[ip6] fix constant name style and simplify filtering of ICMP types (#…
Browse files Browse the repository at this point in the history
…9512)

This commit contains smaller changes in `Ip6` class:
- Rename constant `kForwardIcmpTypes` to follow naming convention
- Simplify how it it used to filter which ICMP types are forwarded
  to Thread mesh.
  • Loading branch information
abtink committed Oct 11, 2023
1 parent 0d0655d commit 57ef721
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/core/net/ip6.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@

using IcmpType = ot::Ip6::Icmp::Header::Type;

static const IcmpType sForwardICMPTypes[] = {
static const IcmpType kForwardIcmpTypes[] = {
IcmpType::kTypeDstUnreach, IcmpType::kTypePacketToBig, IcmpType::kTypeTimeExceeded,
IcmpType::kTypeParameterProblem, IcmpType::kTypeEchoRequest, IcmpType::kTypeEchoReply,
};
Expand Down Expand Up @@ -1258,8 +1258,6 @@ Error Ip6::HandleDatagram(Message &aMessage, const void *aLinkMessageInfo, bool

if (forwardThread)
{
uint8_t hopLimit;

if (aMessage.IsOriginThreadNetif())
{
VerifyOrExit(Get<Mle::Mle>().IsRouterOrLeader());
Expand All @@ -1268,24 +1266,26 @@ Error Ip6::HandleDatagram(Message &aMessage, const void *aLinkMessageInfo, bool

VerifyOrExit(header.GetHopLimit() > 0, error = kErrorDrop);

hopLimit = header.GetHopLimit();
aMessage.Write(Header::kHopLimitFieldOffset, hopLimit);
aMessage.Write<uint8_t>(Header::kHopLimitFieldOffset, header.GetHopLimit());

if (nextHeader == kProtoIcmp6)
{
uint8_t icmpType;
bool isAllowedType = false;

SuccessOrExit(error = aMessage.Read(aMessage.GetOffset(), icmpType));
for (IcmpType type : sForwardICMPTypes)

error = kErrorDrop;

for (IcmpType type : kForwardIcmpTypes)
{
if (icmpType == type)
{
isAllowedType = true;
error = kErrorNone;
break;
}
}
VerifyOrExit(isAllowedType, error = kErrorDrop);

SuccessOrExit(error);
}

if (aMessage.IsOriginHostUntrusted() && (nextHeader == kProtoUdp))
Expand Down

0 comments on commit 57ef721

Please sign in to comment.