Skip to content

Commit

Permalink
[ip6] log checksum error from Checksum::VerifyMessageChecksum() (op…
Browse files Browse the repository at this point in the history
  • Loading branch information
abtink authored Oct 23, 2023
1 parent 28f30b3 commit b73b124
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
13 changes: 12 additions & 1 deletion src/core/net/checksum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,18 @@
#include "checksum.hpp"

#include "common/code_utils.hpp"
#include "common/log.hpp"
#include "common/message.hpp"
#include "net/icmp6.hpp"
#include "net/ip4_types.hpp"
#include "net/ip6.hpp"
#include "net/tcp6.hpp"
#include "net/udp6.hpp"

namespace ot {

RegisterLogModule("Ip6");

void Checksum::AddUint8(uint8_t aUint8)
{
uint16_t newValue = mValue;
Expand Down Expand Up @@ -147,11 +151,18 @@ void Checksum::Calculate(const Ip4::Address &aSource,

Error Checksum::VerifyMessageChecksum(const Message &aMessage, const Ip6::MessageInfo &aMessageInfo, uint8_t aIpProto)
{
Error error = kErrorNone;
Checksum checksum;

checksum.Calculate(aMessageInfo.GetPeerAddr(), aMessageInfo.GetSockAddr(), aIpProto, aMessage);

return (checksum.GetValue() == kValidRxChecksum) ? kErrorNone : kErrorDrop;
if (checksum.GetValue() != kValidRxChecksum)
{
LogNote("Bad %s checksum", Ip6::Ip6::IpProtoToString(aIpProto));
error = kErrorDrop;
}

return error;
}

void Checksum::UpdateMessageChecksum(Message &aMessage,
Expand Down
8 changes: 0 additions & 8 deletions src/core/net/ip6.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -905,18 +905,10 @@ Error Ip6::HandlePayload(Header &aIp6Header,
#if OPENTHREAD_CONFIG_TCP_ENABLE
case kProtoTcp:
error = mTcp.HandleMessage(aIp6Header, *messagePtr, aMessageInfo);
if (error == kErrorDrop)
{
LogNote("Error TCP Checksum");
}
break;
#endif
case kProtoUdp:
error = mUdp.HandleMessage(*messagePtr, aMessageInfo);
if (error == kErrorDrop)
{
LogNote("Error UDP Checksum");
}
break;

case kProtoIcmp6:
Expand Down

0 comments on commit b73b124

Please sign in to comment.