Implement override checksum for GRE
This commit is contained in:
parent
60f61ed947
commit
3d6f39e84d
@ -89,8 +89,16 @@ AbstractProtocol::FieldFlags GreProtocol::fieldFlags(int index) const
|
|||||||
|
|
||||||
flags = AbstractProtocol::fieldFlags(index);
|
flags = AbstractProtocol::fieldFlags(index);
|
||||||
|
|
||||||
if (index == gre_checksum)
|
switch (index) {
|
||||||
|
case gre_checksum:
|
||||||
flags |= CksumField;
|
flags |= CksumField;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case gre_isOverrideChecksum:
|
||||||
|
flags &= ~FrameField;
|
||||||
|
flags |= MetaField;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
return flags;
|
return flags;
|
||||||
}
|
}
|
||||||
@ -218,18 +226,21 @@ QVariant GreProtocol::fieldData(int index, FieldAttrib attrib,
|
|||||||
if (attrib == FieldBitSize)
|
if (attrib == FieldBitSize)
|
||||||
return 16;
|
return 16;
|
||||||
|
|
||||||
quint32 sum = 0;
|
|
||||||
quint16 cksum;
|
quint16 cksum;
|
||||||
|
if (data.is_override_checksum()) {
|
||||||
|
cksum = data.checksum();
|
||||||
|
} else {
|
||||||
|
quint32 sum = 0;
|
||||||
|
cksum = protocolFrameCksum(streamIndex, CksumIp);
|
||||||
|
sum += (quint16) ~cksum;
|
||||||
|
cksum = protocolFramePayloadCksum(streamIndex, CksumIp);
|
||||||
|
sum += (quint16) ~cksum;
|
||||||
|
|
||||||
cksum = protocolFrameCksum(streamIndex, CksumIp);
|
while (sum >> 16)
|
||||||
sum += (quint16) ~cksum;
|
sum = (sum & 0xFFFF) + (sum >> 16);
|
||||||
cksum = protocolFramePayloadCksum(streamIndex, CksumIp);
|
|
||||||
sum += (quint16) ~cksum;
|
|
||||||
|
|
||||||
while (sum >> 16)
|
cksum = (~sum) & 0xFFFF;
|
||||||
sum = (sum & 0xFFFF) + (sum >> 16);
|
}
|
||||||
|
|
||||||
cksum = (~sum) & 0xFFFF;
|
|
||||||
|
|
||||||
switch(attrib)
|
switch(attrib)
|
||||||
{
|
{
|
||||||
@ -347,6 +358,19 @@ QVariant GreProtocol::fieldData(int index, FieldAttrib attrib,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Meta fields
|
||||||
|
case gre_isOverrideChecksum:
|
||||||
|
{
|
||||||
|
switch(attrib)
|
||||||
|
{
|
||||||
|
case FieldValue:
|
||||||
|
return data.is_override_checksum();
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
qFatal("%s: unimplemented case %d in switch", __PRETTY_FUNCTION__,
|
qFatal("%s: unimplemented case %d in switch", __PRETTY_FUNCTION__,
|
||||||
index);
|
index);
|
||||||
@ -406,6 +430,11 @@ bool GreProtocol::setFieldData(int index, const QVariant &value,
|
|||||||
data.set_checksum(csum);
|
data.set_checksum(csum);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case gre_isOverrideChecksum:
|
||||||
|
{
|
||||||
|
data.set_is_override_checksum(value.toBool());
|
||||||
|
break;
|
||||||
|
}
|
||||||
case gre_rsvd1:
|
case gre_rsvd1:
|
||||||
{
|
{
|
||||||
uint rsvd1 = value.toUInt(&isOk);
|
uint rsvd1 = value.toUInt(&isOk);
|
||||||
|
@ -58,6 +58,9 @@ public:
|
|||||||
gre_key,
|
gre_key,
|
||||||
gre_sequence,
|
gre_sequence,
|
||||||
|
|
||||||
|
// Meta Fields
|
||||||
|
gre_isOverrideChecksum,
|
||||||
|
|
||||||
gre_fieldCount
|
gre_fieldCount
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -28,9 +28,10 @@ message Gre {
|
|||||||
optional uint32 version = 3;
|
optional uint32 version = 3;
|
||||||
optional uint32 protocol_type = 4;
|
optional uint32 protocol_type = 4;
|
||||||
optional uint32 checksum = 5;
|
optional uint32 checksum = 5;
|
||||||
optional uint32 rsvd1 = 6;
|
optional bool is_override_checksum = 6;
|
||||||
optional uint32 key = 7 [default = 0x2020bad7];
|
optional uint32 rsvd1 = 7;
|
||||||
optional uint32 sequence_num = 8;
|
optional uint32 key = 8 [default = 0x2020bad7];
|
||||||
|
optional uint32 sequence_num = 9;
|
||||||
}
|
}
|
||||||
|
|
||||||
extend Protocol {
|
extend Protocol {
|
||||||
|
@ -62,9 +62,15 @@
|
|||||||
<property name="prefix">
|
<property name="prefix">
|
||||||
<string>0x</string>
|
<string>0x</string>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="minimum">
|
||||||
|
<number>-1</number>
|
||||||
|
</property>
|
||||||
<property name="maximum">
|
<property name="maximum">
|
||||||
<number>65535</number>
|
<number>65535</number>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="value">
|
||||||
|
<number>-1</number>
|
||||||
|
</property>
|
||||||
<property name="displayIntegerBase">
|
<property name="displayIntegerBase">
|
||||||
<number>16</number>
|
<number>16</number>
|
||||||
</property>
|
</property>
|
||||||
@ -167,5 +173,21 @@
|
|||||||
</hint>
|
</hint>
|
||||||
</hints>
|
</hints>
|
||||||
</connection>
|
</connection>
|
||||||
|
<connection>
|
||||||
|
<sender>hasChecksum</sender>
|
||||||
|
<signal>toggled(bool)</signal>
|
||||||
|
<receiver>checksum</receiver>
|
||||||
|
<slot>setEnabled(bool)</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>87</x>
|
||||||
|
<y>43</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>109</x>
|
||||||
|
<y>45</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
</connections>
|
</connections>
|
||||||
</ui>
|
</ui>
|
||||||
|
@ -24,6 +24,9 @@ GreConfigForm::GreConfigForm(QWidget *parent)
|
|||||||
: AbstractProtocolConfigForm(parent)
|
: AbstractProtocolConfigForm(parent)
|
||||||
{
|
{
|
||||||
setupUi(this);
|
setupUi(this);
|
||||||
|
|
||||||
|
connect(hasChecksum, SIGNAL(clicked(bool)),
|
||||||
|
this, SLOT(setAutoChecksum(bool)));
|
||||||
}
|
}
|
||||||
|
|
||||||
GreConfigForm::~GreConfigForm()
|
GreConfigForm::~GreConfigForm()
|
||||||
@ -51,9 +54,11 @@ void GreConfigForm::loadWidget(AbstractProtocol *proto)
|
|||||||
hasChecksum->setChecked(flags & GRE_FLAG_CKSUM);
|
hasChecksum->setChecked(flags & GRE_FLAG_CKSUM);
|
||||||
checksum->setValue(
|
checksum->setValue(
|
||||||
proto->fieldData(
|
proto->fieldData(
|
||||||
GreProtocol::gre_checksum,
|
GreProtocol::gre_isOverrideChecksum,
|
||||||
AbstractProtocol::FieldValue
|
AbstractProtocol::FieldValue).toBool() ?
|
||||||
).toUInt());
|
proto->fieldData(
|
||||||
|
GreProtocol::gre_checksum,
|
||||||
|
AbstractProtocol::FieldValue).toUInt() : -1);
|
||||||
|
|
||||||
hasKey->setChecked(flags & GRE_FLAG_KEY);
|
hasKey->setChecked(flags & GRE_FLAG_KEY);
|
||||||
key->setValue(
|
key->setValue(
|
||||||
@ -93,6 +98,9 @@ void GreConfigForm::storeWidget(AbstractProtocol *proto)
|
|||||||
proto->setFieldData(
|
proto->setFieldData(
|
||||||
GreProtocol::gre_checksum,
|
GreProtocol::gre_checksum,
|
||||||
checksum->value());
|
checksum->value());
|
||||||
|
proto->setFieldData(
|
||||||
|
GreProtocol::gre_isOverrideChecksum,
|
||||||
|
checksum->value() > -1 ? true: false);
|
||||||
|
|
||||||
proto->setFieldData(
|
proto->setFieldData(
|
||||||
GreProtocol::gre_key,
|
GreProtocol::gre_key,
|
||||||
@ -103,3 +111,8 @@ void GreConfigForm::storeWidget(AbstractProtocol *proto)
|
|||||||
sequence->value());
|
sequence->value());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GreConfigForm::setAutoChecksum(bool enabled)
|
||||||
|
{
|
||||||
|
if (enabled)
|
||||||
|
checksum->setValue(-1); // auto
|
||||||
|
}
|
||||||
|
@ -36,6 +36,9 @@ public:
|
|||||||
|
|
||||||
virtual void loadWidget(AbstractProtocol *proto);
|
virtual void loadWidget(AbstractProtocol *proto);
|
||||||
virtual void storeWidget(AbstractProtocol *proto);
|
virtual void storeWidget(AbstractProtocol *proto);
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void setAutoChecksum(bool enabled);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -91,9 +91,14 @@ void PdmlGreProtocol::prematureEndHandler(int /*pos*/,
|
|||||||
Ostinato recalculate these, you can set the is_override_length,
|
Ostinato recalculate these, you can set the is_override_length,
|
||||||
is_override_cksum meta-fields to true here
|
is_override_cksum meta-fields to true here
|
||||||
*/
|
*/
|
||||||
void PdmlGreProtocol::postProtocolHandler(OstProto::Protocol* /*pbProto*/,
|
void PdmlGreProtocol::postProtocolHandler(OstProto::Protocol* pbProto,
|
||||||
OstProto::Stream* /*stream*/)
|
OstProto::Stream* /*stream*/)
|
||||||
{
|
{
|
||||||
|
OstProto::Gre *gre = pbProto->MutableExtension(OstProto::gre);
|
||||||
|
|
||||||
|
qDebug("GRE: post");
|
||||||
|
|
||||||
|
gre->set_is_override_checksum(overrideCksum_);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user