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