diff --git a/common/icmppdml.cpp b/common/icmppdml.cpp index 0bff798..7850de4 100644 --- a/common/icmppdml.cpp +++ b/common/icmppdml.cpp @@ -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); } diff --git a/common/igmppdml.cpp b/common/igmppdml.cpp index 19516d7..9743eaf 100644 --- a/common/igmppdml.cpp +++ b/common/igmppdml.cpp @@ -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); diff --git a/common/ip4pdml.cpp b/common/ip4pdml.cpp index 554bd7d..d15068e 100644 --- a/common/ip4pdml.cpp +++ b/common/ip4pdml.cpp @@ -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_); } diff --git a/common/mldpdml.cpp b/common/mldpdml.cpp index b17503e..d63b600 100644 --- a/common/mldpdml.cpp +++ b/common/mldpdml.cpp @@ -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); diff --git a/common/pcapfileformat.cpp b/common/pcapfileformat.cpp index 95991fa..d1d0f69 100644 --- a/common/pcapfileformat.cpp +++ b/common/pcapfileformat.cpp @@ -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()) { diff --git a/common/pcapfileimport.ui b/common/pcapfileimport.ui index 3279b6d..c2fbf46 100644 --- a/common/pcapfileimport.ui +++ b/common/pcapfileimport.ui @@ -7,51 +7,57 @@ 0 0 326 - 93 + 112 PCAP import options - - + + Intelligent Import (via PDML) - - - - - - - 0 - 0 - - - - - 16 - 16 - - - - - - - - false - - - Do a diff after import - - - - + + + + + 0 + 0 + + + + + 16 + 16 + + + - + + + + false + + + Recalculate Checksums + + + + + + + false + + + Do a diff after import + + + + Qt::Horizontal @@ -108,8 +114,8 @@ 16 - 37 - 42 + 68 + 71 @@ -124,8 +130,40 @@ 14 - 150 - 34 + 181 + 71 + + + + + viaPdml + toggled(bool) + recalculateCksums + setEnabled(bool) + + + 29 + 17 + + + 38 + 39 + + + + + viaPdml + toggled(bool) + recalculateCksums + setChecked(bool) + + + 67 + 18 + + + 66 + 33 diff --git a/common/pdmlprotocol.cpp b/common/pdmlprotocol.cpp index 3c967e1..3330ec9 100644 --- a/common/pdmlprotocol.cpp +++ b/common/pdmlprotocol.cpp @@ -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 diff --git a/common/pdmlprotocol.h b/common/pdmlprotocol.h index 011fcb6..6561f41 100644 --- a/common/pdmlprotocol.h +++ b/common/pdmlprotocol.h @@ -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 fieldMap_; + + bool overrideCksum_{true}; }; #endif diff --git a/common/pdmlreader.cpp b/common/pdmlreader.cpp index 0bc17d1..a28706d 100644 --- a/common/pdmlreader.cpp +++ b/common/pdmlreader.cpp @@ -42,12 +42,15 @@ along with this program. If not, see #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, diff --git a/common/pdmlreader.h b/common/pdmlreader.h index 7de3918..f47d718 100644 --- a/common/pdmlreader.h +++ b/common/pdmlreader.h @@ -24,13 +24,15 @@ along with this program. If not, see #include #include +#include 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_; diff --git a/common/samplepdml.cpp b/common/samplepdml.cpp index 99b671b..3d0aa3c 100644 --- a/common/samplepdml.cpp +++ b/common/samplepdml.cpp @@ -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*/) diff --git a/common/tcppdml.cpp b/common/tcppdml.cpp index 3980b6a..0ebdd4e 100644 --- a/common/tcppdml.cpp +++ b/common/tcppdml.cpp @@ -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()) { diff --git a/common/udppdml.cpp b/common/udppdml.cpp index 0cb1685..83a62c3 100644 --- a/common/udppdml.cpp +++ b/common/udppdml.cpp @@ -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_); }