Refactor ICMP/IGMP checksums

Added a new CksumTypeIcmpIgmp and implemented it in AbstractProtocol.
This commit is contained in:
Srivats P 2021-09-05 13:04:57 +05:30
parent c710adb4d8
commit 9f70f29499
4 changed files with 26 additions and 32 deletions

View File

@ -909,7 +909,26 @@ quint32 AbstractProtocol::protocolFrameCksum(int streamIndex,
cksum = (~sum) & 0xFFFF;
break;
}
case CksumIcmpIgmp:
{
quint16 cks;
quint32 sum = 0;
cks = protocolFrameCksum(streamIndex, CksumIp);
sum += (quint16) ~cks;
cks = protocolFramePayloadCksum(streamIndex, CksumIp);
sum += (quint16) ~cks;
while(sum>>16)
sum = (sum & 0xFFFF) + (sum >> 16);
cksum = (~sum) & 0xFFFF;
break;
}
default:
qDebug("Unknown cksumType %d", cksumType);
break;
}

View File

@ -102,6 +102,7 @@ public:
CksumIp, //!< Standard IP Checksum
CksumIpPseudo, //!< Standard checksum for Pseudo-IP header
CksumTcpUdp, //!< Standard TCP/UDP checksum including pseudo-IP
CksumIcmpIgmp, //!< Standard ICMP/IGMP checksum
CksumMax //!< Marker for number of cksum types
};

View File

@ -197,24 +197,11 @@ QVariant IcmpProtocol::fieldData(int index, FieldAttrib attrib,
}
else
{
quint16 cks;
quint32 sum = 0;
cks = protocolFrameCksum(streamIndex, CksumIp);
sum += (quint16) ~cks;
cks = protocolFramePayloadCksum(streamIndex, CksumIp);
sum += (quint16) ~cks;
if (icmpVersion() == OstProto::Icmp::kIcmp6)
{
cks = protocolFrameHeaderCksum(streamIndex,
CksumIpPseudo);
sum += (quint16) ~cks;
}
while(sum>>16)
sum = (sum & 0xFFFF) + (sum >> 16);
cksum = (~sum) & 0xFFFF;
cksum = (icmpVersion() == OstProto::Icmp::kIcmp4) ?
AbstractProtocol::protocolFrameCksum(
streamIndex, CksumIcmpIgmp) :
AbstractProtocol::protocolFrameCksum(
streamIndex, CksumTcpUdp);
}
break;
default:

View File

@ -347,18 +347,5 @@ _exit:
quint16 IgmpProtocol::checksum(int streamIndex) const
{
quint16 cks;
quint32 sum = 0;
// TODO: add as a new CksumType (CksumIgmp?) and implement in AbsProto
cks = protocolFrameCksum(streamIndex, CksumIp);
sum += (quint16) ~cks;
cks = protocolFramePayloadCksum(streamIndex, CksumIp);
sum += (quint16) ~cks;
while (sum >> 16)
sum = (sum & 0xFFFF) + (sum >> 16);
cks = (~sum) & 0xFFFF;
return cks;
return AbstractProtocol::protocolFrameCksum(streamIndex, CksumIcmpIgmp);
}