Added new param 'cksumScope' in AbstractProtocol's header and payload cksum methods; this ensures that TCP/UDP checksum is now correct if preceded by a IP 4over4.

This commit is contained in:
Srivats P. 2010-04-24 19:16:39 +05:30
parent ae05037265
commit e681e1e226
2 changed files with 34 additions and 10 deletions

View File

@ -672,15 +672,19 @@ quint32 AbstractProtocol::protocolFrameCksum(int streamIndex,
}
/*!
Returns the checksum of the requested type for the protocol's header
Returns the checksum of the requested type for the protocol's header
This is useful for subclasses which needs the header's checksum e.g. TCP/UDP
require a "Pseudo-IP" checksum
require a "Pseudo-IP" checksum. The checksum is limited to the specified
scope.
Currently the default implementation supports only type CksumIpPseudo
\note The default value for cksumScope is different for
protocolFrameHeaderCksum() and protocolFramePayloadCksum()
*/
quint32 AbstractProtocol::protocolFrameHeaderCksum(int streamIndex,
CksumType cksumType) const
CksumType cksumType, CksumScope cksumScope) const
{
quint32 sum = 0;
quint16 cksum;
@ -692,15 +696,19 @@ quint32 AbstractProtocol::protocolFrameHeaderCksum(int streamIndex,
{
cksum = p->protocolFrameCksum(streamIndex, cksumType);
sum += (quint16) ~cksum;
p = p->prev;
qDebug("%s: sum = %u, cksum = %u", __FUNCTION__, sum, cksum);
if (cksumScope == CksumScopeAdjacentProtocol)
goto out;
p = p->prev;
}
if (parent)
{
cksum = parent->protocolFrameHeaderCksum(streamIndex, cksumType);
cksum = parent->protocolFrameHeaderCksum(streamIndex, cksumType,
cksumScope);
sum += (quint16) ~cksum;
}
out:
while(sum>>16)
sum = (sum & 0xFFFF) + (sum >> 16);
@ -712,12 +720,16 @@ quint32 AbstractProtocol::protocolFrameHeaderCksum(int streamIndex,
This is useful for subclasses which needs the payload's checksum e.g. TCP/UDP
require a IP checksum of the payload (to be combined with other checksums to
derive the final checksum)
derive the final checksum). The checksum is limited to the specified
scope.
Currently the default implementation supports only type CksumIp
\note The default value for cksumScope is different for
protocolFrameHeaderCksum() and protocolFramePayloadCksum()
*/
quint32 AbstractProtocol::protocolFramePayloadCksum(int streamIndex,
CksumType cksumType) const
CksumType cksumType, CksumScope cksumScope) const
{
quint32 sum = 0;
quint16 cksum;
@ -729,15 +741,19 @@ quint32 AbstractProtocol::protocolFramePayloadCksum(int streamIndex,
{
cksum = p->protocolFrameCksum(streamIndex, cksumType);
sum += (quint16) ~cksum;
if (cksumScope == CksumScopeAdjacentProtocol)
goto out;
p = p->next;
}
if (parent)
{
cksum = parent->protocolFramePayloadCksum(streamIndex, cksumType);
cksum = parent->protocolFramePayloadCksum(streamIndex, cksumType,
cksumScope);
sum += (quint16) ~cksum;
}
out:
while(sum>>16)
sum = (sum & 0xFFFF) + (sum >> 16);

View File

@ -93,6 +93,12 @@ public:
CksumMax //!< Marker for number of cksum types
};
//! Supported checksum scopes
enum CksumScope {
CksumScopeAdjacentProtocol, //!< Cksum only the adjacent protocol
CksumScopeAllProtocols, //!< Cksum over all the protocols
};
AbstractProtocol(StreamBase *stream, AbstractProtocol *parent = 0);
virtual ~AbstractProtocol();
@ -134,9 +140,11 @@ public:
virtual quint32 protocolFrameCksum(int streamIndex = 0,
CksumType cksumType = CksumIp) const;
quint32 protocolFrameHeaderCksum(int streamIndex = 0,
CksumType cksumType = CksumIp) const;
CksumType cksumType = CksumIp,
CksumScope cksumScope = CksumScopeAdjacentProtocol) const;
quint32 protocolFramePayloadCksum(int streamIndex = 0,
CksumType cksumType = CksumIp) const;
CksumType cksumType = CksumIp,
CksumScope cksumScope = CksumScopeAllProtocols) const;
virtual QWidget* configWidget() = 0;
virtual void loadConfigWidget() = 0;