[routing-manager] ignore checksum in RA hash calculation (#10230)

This commit modifies the `CalculateHash()` method to use a zero
checksum value for RA (ICMPv6) header for both received and emitted
RA message. In prepared RA messages, the checksum is always set to
zero, and the platform layer is responsible for calculating and
updating it. For a received RA, while platforms typically zero out
the checksum after validation, this behavior isn't explicitly
required by `otPlatInfraIf` APIs. By ignoring the checksum(setting it
to zero) during hash calculation, this change ensures correct
calculation regardless of platform behavior.

This commit also updates `test_routing_manager` to intentionally
modify the checksum field in an emitted RA message before passing it
back to the OT stack. This validates the updated hash calculation
behavior.
This commit is contained in:
Abtin Keshavarzian
2024-05-14 14:28:02 -07:00
committed by GitHub
parent 83e2732bae
commit 02acc480dd
4 changed files with 37 additions and 11 deletions
+8 -2
View File
@@ -295,7 +295,8 @@ otError otPlatInfraIfSendIcmp6Nd(uint32_t aInfraIfIndex,
const uint8_t *aBuffer,
uint16_t aBufferLength)
{
Icmp6Packet packet;
Icmp6Packet packet;
Ip6::Icmp::Header *header;
Log("otPlatInfraIfSendIcmp6Nd(aDestAddr: %s, aBufferLength:%u)", AsCoreType(aDestAddress).ToString().AsCString(),
aBufferLength);
@@ -306,7 +307,9 @@ otError otPlatInfraIfSendIcmp6Nd(uint32_t aInfraIfIndex,
VerifyOrQuit(aBufferLength >= sizeof(Ip6::Icmp::Header));
switch (reinterpret_cast<const Ip6::Icmp::Header *>(aBuffer)->GetType())
header = reinterpret_cast<Ip6::Icmp::Header *>(const_cast<uint8_t *>(aBuffer));
switch (header->GetType())
{
case Ip6::Icmp::Header::kTypeRouterSolicit:
Log(" Router Solicit message");
@@ -317,6 +320,9 @@ otError otPlatInfraIfSendIcmp6Nd(uint32_t aInfraIfIndex,
Log(" Router Advertisement message");
LogRouterAdvert(packet);
ValidateRouterAdvert(packet);
// Intentionally modify the checksum field in RA Header
// before passing it back to the OT stack.
header->SetChecksum(0x1234);
otPlatInfraIfRecvIcmp6Nd(sInstance, kInfraIfIndex, &sInfraIfAddress, aBuffer, aBufferLength);
break;