Add option to recalculate cksums during pcap import
Recalculate cksum is now the default. This behaviour change has been done to facilitate rewriting packet fields post PCAP import using the new Find & Replace feature. Without this any change in fields may cause incorrect checksums. The earlier rationale for retaining the checksums in the PCAP file during import was to ensure replayed packet was same as the one in the PCAP file. User now has a choice with this option.
This commit is contained in:
parent
366022552f
commit
dbdeee2a6f
@ -56,7 +56,7 @@ void PdmlIcmpProtocol::preProtocolHandler(QString name,
|
||||
else if (name == "icmpv6")
|
||||
icmp->set_icmp_version(OstProto::Icmp::kIcmp6);
|
||||
|
||||
icmp->set_is_override_checksum(true);
|
||||
icmp->set_is_override_checksum(overrideCksum_);
|
||||
|
||||
icmp->set_type(kIcmpInvalidType);
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ void PdmlIgmpProtocol::preProtocolHandler(QString /*name*/,
|
||||
OstProto::Gmp *igmp = pbProto->MutableExtension(OstProto::igmp);
|
||||
|
||||
igmp->set_is_override_rsvd_code(true);
|
||||
igmp->set_is_override_checksum(true);
|
||||
igmp->set_is_override_checksum(overrideCksum_);
|
||||
igmp->set_is_override_source_count(true);
|
||||
igmp->set_is_override_group_record_count(true);
|
||||
|
||||
|
@ -88,6 +88,6 @@ void PdmlIp4Protocol::postProtocolHandler(OstProto::Protocol *pbProto,
|
||||
ip4->set_is_override_hdrlen(true);
|
||||
ip4->set_is_override_totlen(true);
|
||||
ip4->set_is_override_proto(true);
|
||||
ip4->set_is_override_cksum(true);
|
||||
ip4->set_is_override_cksum(overrideCksum_);
|
||||
}
|
||||
|
||||
|
@ -53,7 +53,7 @@ void PdmlMldProtocol::preProtocolHandler(QString /*name*/,
|
||||
OstProto::Gmp *mld = pbProto->MutableExtension(OstProto::mld);
|
||||
|
||||
mld->set_is_override_rsvd_code(true);
|
||||
mld->set_is_override_checksum(true);
|
||||
mld->set_is_override_checksum(overrideCksum_);
|
||||
mld->set_is_override_source_count(true);
|
||||
mld->set_is_override_group_record_count(true);
|
||||
|
||||
|
@ -47,6 +47,8 @@ PcapImportOptionsDialog::PcapImportOptionsDialog(QVariantMap *options)
|
||||
options_ = options;
|
||||
|
||||
viaPdml->setChecked(options_->value("ViaPdml").toBool());
|
||||
recalculateCksums->setChecked(
|
||||
options_->value("RecalculateCksums").toBool());
|
||||
doDiff->setChecked(options_->value("DoDiff").toBool());
|
||||
|
||||
connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
|
||||
@ -59,6 +61,7 @@ PcapImportOptionsDialog::~PcapImportOptionsDialog()
|
||||
void PcapImportOptionsDialog::accept()
|
||||
{
|
||||
options_->insert("ViaPdml", viaPdml->isChecked());
|
||||
options_->insert("RecalculateCksums", recalculateCksums->isChecked());
|
||||
options_->insert("DoDiff", doDiff->isChecked());
|
||||
|
||||
QDialog::accept();
|
||||
@ -67,6 +70,7 @@ void PcapImportOptionsDialog::accept()
|
||||
PcapFileFormat::PcapFileFormat()
|
||||
{
|
||||
importOptions_.insert("ViaPdml", true);
|
||||
importOptions_.insert("RecalculateCksums", true);
|
||||
importOptions_.insert("DoDiff", true);
|
||||
|
||||
importDialog_ = NULL;
|
||||
@ -224,7 +228,7 @@ _retry:
|
||||
{
|
||||
QProcess tshark;
|
||||
QTemporaryFile pdmlFile;
|
||||
PdmlReader reader(&streams);
|
||||
PdmlReader reader(&streams, importOptions_);
|
||||
|
||||
if (!pdmlFile.open())
|
||||
{
|
||||
|
@ -7,24 +7,22 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>326</width>
|
||||
<height>93</height>
|
||||
<height>112</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>PCAP import options</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout">
|
||||
<item>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0" colspan="2">
|
||||
<widget class="QCheckBox" name="viaPdml">
|
||||
<property name="text">
|
||||
<string>Intelligent Import (via PDML)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout">
|
||||
<item>
|
||||
<widget class="QWidget" name="widget" native="true">
|
||||
<item row="1" column="0" rowspan="2">
|
||||
<widget class="QWidget" name="indentSpacing" native="true">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
@ -39,7 +37,17 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QCheckBox" name="recalculateCksums">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Recalculate Checksums</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QCheckBox" name="doDiff">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
@ -49,9 +57,7 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<item row="3" column="0" colspan="2">
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
@ -108,8 +114,8 @@
|
||||
<y>16</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>37</x>
|
||||
<y>42</y>
|
||||
<x>68</x>
|
||||
<y>71</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
@ -124,8 +130,40 @@
|
||||
<y>14</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>150</x>
|
||||
<y>34</y>
|
||||
<x>181</x>
|
||||
<y>71</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>viaPdml</sender>
|
||||
<signal>toggled(bool)</signal>
|
||||
<receiver>recalculateCksums</receiver>
|
||||
<slot>setEnabled(bool)</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>29</x>
|
||||
<y>17</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>38</x>
|
||||
<y>39</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>viaPdml</sender>
|
||||
<signal>toggled(bool)</signal>
|
||||
<receiver>recalculateCksums</receiver>
|
||||
<slot>setChecked(bool)</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>67</x>
|
||||
<y>18</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>66</x>
|
||||
<y>33</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
|
@ -102,6 +102,11 @@ int PdmlProtocol::fieldId(QString name) const
|
||||
return fieldMap_.value(name);
|
||||
}
|
||||
|
||||
void PdmlProtocol::setRecalculateCksum(bool recalculate)
|
||||
{
|
||||
overrideCksum_ = !recalculate;
|
||||
}
|
||||
|
||||
/*!
|
||||
This method is called by PdmlReader before any fields within the protocol
|
||||
are processed. All attributes associated with the 'proto' tag in the PDML
|
||||
|
@ -40,6 +40,8 @@ public:
|
||||
bool hasField(QString name) const;
|
||||
int fieldId(QString name) const;
|
||||
|
||||
void setRecalculateCksum(bool recalculate);
|
||||
|
||||
virtual void preProtocolHandler(QString name,
|
||||
const QXmlStreamAttributes &attributes, int expectedPos,
|
||||
OstProto::Protocol *pbProto, OstProto::Stream *stream);
|
||||
@ -63,6 +65,8 @@ protected:
|
||||
int ostProtoId_;
|
||||
//!< Map of PDML field names to protobuf field numbers for 'known' fields
|
||||
QMap<QString, int> fieldMap_;
|
||||
|
||||
bool overrideCksum_{true};
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -42,12 +42,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
#include "udppdml.h"
|
||||
#include "vlanpdml.h"
|
||||
|
||||
PdmlReader::PdmlReader(OstProto::StreamConfigList *streams)
|
||||
PdmlReader::PdmlReader(OstProto::StreamConfigList *streams,
|
||||
const QVariantMap &options)
|
||||
{
|
||||
//gPdmlReader = this;
|
||||
pcap_ = NULL;
|
||||
streams_ = streams;
|
||||
|
||||
recalculateCksums_ = options.value("RecalculateCksums").toBool();
|
||||
|
||||
currentStream_ = NULL;
|
||||
prevStream_ = NULL;
|
||||
|
||||
@ -353,6 +356,8 @@ void PdmlReader::readProto()
|
||||
|
||||
pdmlProto = appendPdmlProto(protoName, &pbProto);
|
||||
|
||||
pdmlProto->setRecalculateCksum(recalculateCksums_);
|
||||
|
||||
qDebug("%s: preProtocolHandler(expPos = %d)",
|
||||
qPrintable(protoName), expPos_);
|
||||
pdmlProto->preProtocolHandler(protoName, attributes(), expPos_, pbProto,
|
||||
|
@ -24,13 +24,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
|
||||
#include <QByteArray>
|
||||
#include <QXmlStreamReader>
|
||||
#include <QVariantMap>
|
||||
|
||||
class PcapFileFormat;
|
||||
class PdmlReader : public QObject, public QXmlStreamReader
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
PdmlReader(OstProto::StreamConfigList *streams);
|
||||
PdmlReader(OstProto::StreamConfigList *streams,
|
||||
const QVariantMap &options = QVariantMap());
|
||||
~PdmlReader();
|
||||
|
||||
bool read(QIODevice *device, PcapFileFormat *pcap = NULL,
|
||||
@ -64,6 +66,8 @@ private:
|
||||
PcapFileFormat *pcap_;
|
||||
QByteArray pktBuf_;
|
||||
|
||||
bool recalculateCksums_{false};
|
||||
|
||||
bool isMldSupport_;
|
||||
int packetCount_;
|
||||
int expPos_;
|
||||
|
@ -87,7 +87,9 @@ void PdmlSampleProtocol::prematureEndHandler(int /*pos*/,
|
||||
fields such as length, checksum etc. may be correct or incorrect in the
|
||||
PCAP/PDML - to retain the same value as in the PCAP/PDML and not let
|
||||
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; for cksum, use the base
|
||||
class attribute overrideCksum_ to decide - this is set based on user
|
||||
input
|
||||
*/
|
||||
void PdmlSampleProtocol::postProtocolHandler(OstProto::Protocol* /*pbProto*/,
|
||||
OstProto::Stream* /*stream*/)
|
||||
|
@ -78,7 +78,7 @@ void PdmlTcpProtocol::postProtocolHandler(OstProto::Protocol *pbProto,
|
||||
tcp->set_is_override_src_port(true);
|
||||
tcp->set_is_override_dst_port(true);
|
||||
tcp->set_is_override_hdrlen(true);
|
||||
tcp->set_is_override_cksum(true);
|
||||
tcp->set_is_override_cksum(overrideCksum_);
|
||||
|
||||
if (options_.size())
|
||||
{
|
||||
|
@ -48,6 +48,6 @@ void PdmlUdpProtocol::postProtocolHandler(OstProto::Protocol *pbProto,
|
||||
udp->set_is_override_src_port(true);
|
||||
udp->set_is_override_dst_port(true);
|
||||
udp->set_is_override_totlen(true);
|
||||
udp->set_is_override_cksum(true);
|
||||
udp->set_is_override_cksum(overrideCksum_);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user