From b73b124d379e2b85afc922cae288bf98fa576a82 Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Mon, 23 Oct 2023 05:19:07 -0700 Subject: [PATCH] [ip6] log checksum error from `Checksum::VerifyMessageChecksum()` (#9556) --- src/core/net/checksum.cpp | 13 ++++++++++++- src/core/net/ip6.cpp | 8 -------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/core/net/checksum.cpp b/src/core/net/checksum.cpp index df761d42921..d07f4250829 100644 --- a/src/core/net/checksum.cpp +++ b/src/core/net/checksum.cpp @@ -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; @@ -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, diff --git a/src/core/net/ip6.cpp b/src/core/net/ip6.cpp index 673217bffac..49a411b08ed 100644 --- a/src/core/net/ip6.cpp +++ b/src/core/net/ip6.cpp @@ -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: