2011-01-30 06:08:03 -06:00
|
|
|
/*
|
|
|
|
Copyright (C) 2010 Srivats P.
|
|
|
|
|
|
|
|
This file is part of "Ostinato"
|
|
|
|
|
|
|
|
This is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "pdml_p.h"
|
|
|
|
|
2011-03-12 03:46:27 -06:00
|
|
|
#include "abstractprotocol.h"
|
|
|
|
#include "pcapfileformat.h"
|
|
|
|
#include "protocolmanager.h"
|
|
|
|
#include "streambase.h"
|
|
|
|
|
2011-03-31 10:06:47 -05:00
|
|
|
#include "arp.pb.h"
|
2011-01-30 06:08:03 -06:00
|
|
|
#include "eth2.pb.h"
|
2011-03-06 07:11:08 -06:00
|
|
|
#include "dot3.pb.h"
|
2011-01-30 06:08:03 -06:00
|
|
|
#include "hexdump.pb.h"
|
2011-03-27 12:15:04 -05:00
|
|
|
#include "llc.pb.h"
|
|
|
|
#include "mac.pb.h"
|
2011-02-10 12:00:58 -06:00
|
|
|
#include "ip4.pb.h"
|
|
|
|
#include "ip6.pb.h"
|
2011-03-27 12:15:04 -05:00
|
|
|
#include "snap.pb.h"
|
|
|
|
#include "svlan.pb.h"
|
2011-02-10 12:00:58 -06:00
|
|
|
#include "tcp.pb.h"
|
2011-04-01 13:44:43 -05:00
|
|
|
#include "textproto.pb.h"
|
2011-03-31 10:34:05 -05:00
|
|
|
#include "udp.pb.h"
|
2011-03-27 12:15:04 -05:00
|
|
|
#include "vlan.pb.h"
|
2011-01-30 06:08:03 -06:00
|
|
|
|
|
|
|
#include <google/protobuf/descriptor.h>
|
|
|
|
|
|
|
|
#include <QMessageBox>
|
2011-03-27 12:15:04 -05:00
|
|
|
#include <QRegExp>
|
2011-01-30 06:08:03 -06:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
2011-03-12 03:46:27 -06:00
|
|
|
extern ProtocolManager *OstProtocolManager;
|
|
|
|
|
2011-01-30 06:08:03 -06:00
|
|
|
const int kBaseHex = 16;
|
|
|
|
|
2011-02-23 09:58:32 -06:00
|
|
|
static PdmlReader *gPdmlReader = NULL;
|
|
|
|
|
2011-01-30 06:08:03 -06:00
|
|
|
PdmlDefaultProtocol::PdmlDefaultProtocol()
|
|
|
|
{
|
|
|
|
ostProtoId_ = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
PdmlDefaultProtocol::~PdmlDefaultProtocol()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-02-18 12:02:57 -06:00
|
|
|
PdmlDefaultProtocol* PdmlDefaultProtocol::createInstance()
|
|
|
|
{
|
|
|
|
return new PdmlDefaultProtocol();
|
|
|
|
}
|
|
|
|
|
2011-01-30 06:08:03 -06:00
|
|
|
QString PdmlDefaultProtocol::pdmlProtoName() const
|
|
|
|
{
|
|
|
|
return pdmlProtoName_;
|
|
|
|
}
|
|
|
|
|
|
|
|
int PdmlDefaultProtocol::ostProtoId() const
|
|
|
|
{
|
|
|
|
return ostProtoId_;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PdmlDefaultProtocol::hasField(QString name) const
|
|
|
|
{
|
|
|
|
return fieldMap_.contains(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
int PdmlDefaultProtocol::fieldId(QString name) const
|
|
|
|
{
|
|
|
|
return fieldMap_.value(name);
|
|
|
|
}
|
|
|
|
|
2011-03-12 03:46:27 -06:00
|
|
|
void PdmlDefaultProtocol::preProtocolHandler(QString /*name*/,
|
|
|
|
const QXmlStreamAttributes& /*attributes*/,
|
2011-03-27 07:49:31 -05:00
|
|
|
int /*expectedPos*/, OstProto::Protocol* /*pbProto*/,
|
|
|
|
OstProto::Stream* /*stream*/)
|
2011-02-18 12:02:57 -06:00
|
|
|
{
|
|
|
|
return; // do nothing!
|
|
|
|
}
|
|
|
|
|
2011-03-27 07:49:31 -05:00
|
|
|
void PdmlDefaultProtocol::prematureEndHandler(int /*pos*/,
|
|
|
|
OstProto::Protocol* /*pbProto*/, OstProto::Stream* /*stream*/)
|
2011-01-30 06:08:03 -06:00
|
|
|
{
|
|
|
|
return; // do nothing!
|
|
|
|
}
|
|
|
|
|
2011-03-27 07:49:31 -05:00
|
|
|
void PdmlDefaultProtocol::postProtocolHandler(OstProto::Protocol* /*pbProto*/,
|
|
|
|
OstProto::Stream* /*stream*/)
|
2011-01-30 06:08:03 -06:00
|
|
|
{
|
|
|
|
return; // do nothing!
|
|
|
|
}
|
|
|
|
|
2011-03-24 11:28:39 -05:00
|
|
|
void PdmlDefaultProtocol::fieldHandler(QString name,
|
|
|
|
const QXmlStreamAttributes &attributes,
|
2011-03-27 07:49:31 -05:00
|
|
|
OstProto::Protocol *pbProto, OstProto::Stream *stream)
|
2011-03-24 11:28:39 -05:00
|
|
|
{
|
|
|
|
if (hasField(name))
|
|
|
|
{
|
|
|
|
QString valueHexStr = attributes.value("value").toString();
|
|
|
|
|
|
|
|
qDebug("\t(KNOWN) fieldName:%s, value:%s",
|
|
|
|
name.toAscii().constData(),
|
|
|
|
valueHexStr.toAscii().constData());
|
|
|
|
|
|
|
|
knownFieldHandler(name, valueHexStr, pbProto);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int pos = -1;
|
|
|
|
int size = -1;
|
|
|
|
|
|
|
|
if (!attributes.value("pos").isEmpty())
|
|
|
|
pos = attributes.value("pos").toString().toInt();
|
|
|
|
if (!attributes.value("size").isEmpty())
|
|
|
|
size = attributes.value("size").toString().toInt();
|
|
|
|
|
|
|
|
qDebug("\t(UNKNOWN) fieldName:%s, pos:%d, size:%d",
|
|
|
|
name.toAscii().constData(), pos, size);
|
|
|
|
|
2011-03-27 07:49:31 -05:00
|
|
|
unknownFieldHandler(name, pos, size, attributes, pbProto, stream);
|
2011-03-24 11:28:39 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PdmlDefaultProtocol::knownFieldHandler(QString name, QString valueHexStr,
|
2011-03-27 07:49:31 -05:00
|
|
|
OstProto::Protocol *pbProto)
|
2011-03-24 11:28:39 -05:00
|
|
|
{
|
2011-03-27 07:49:31 -05:00
|
|
|
const google::protobuf::Reflection *protoRefl = pbProto->GetReflection();
|
|
|
|
const google::protobuf::FieldDescriptor *extDesc =
|
|
|
|
protoRefl->FindKnownExtensionByNumber(ostProtoId());
|
|
|
|
|
|
|
|
google::protobuf::Message *msg =
|
|
|
|
protoRefl->MutableMessage(pbProto,extDesc);
|
|
|
|
|
|
|
|
const google::protobuf::Reflection *msgRefl = msg->GetReflection();
|
2011-03-24 11:28:39 -05:00
|
|
|
const google::protobuf::FieldDescriptor *fieldDesc =
|
2011-03-27 07:49:31 -05:00
|
|
|
msg->GetDescriptor()->FindFieldByNumber(fieldId(name));
|
2011-03-24 11:28:39 -05:00
|
|
|
|
|
|
|
bool isOk;
|
|
|
|
|
2011-03-27 07:49:31 -05:00
|
|
|
Q_ASSERT(fieldDesc != NULL);
|
2011-03-24 11:28:39 -05:00
|
|
|
switch(fieldDesc->cpp_type())
|
|
|
|
{
|
|
|
|
case google::protobuf::FieldDescriptor::CPPTYPE_ENUM: // TODO
|
|
|
|
case google::protobuf::FieldDescriptor::CPPTYPE_UINT32:
|
2011-03-27 07:49:31 -05:00
|
|
|
msgRefl->SetUInt32(msg, fieldDesc,
|
2011-03-24 11:28:39 -05:00
|
|
|
valueHexStr.toUInt(&isOk, kBaseHex));
|
|
|
|
break;
|
|
|
|
case google::protobuf::FieldDescriptor::CPPTYPE_UINT64:
|
2011-03-27 07:49:31 -05:00
|
|
|
msgRefl->SetUInt64(msg, fieldDesc,
|
2011-03-24 11:28:39 -05:00
|
|
|
valueHexStr.toULongLong(&isOk, kBaseHex));
|
|
|
|
break;
|
|
|
|
case google::protobuf::FieldDescriptor::CPPTYPE_STRING:
|
|
|
|
{
|
|
|
|
QByteArray hexVal = QByteArray::fromHex(valueHexStr.toUtf8());
|
|
|
|
std::string str(hexVal.constData(), hexVal.size());
|
2011-03-27 07:49:31 -05:00
|
|
|
msgRefl->SetString(msg, fieldDesc, str);
|
2011-03-24 11:28:39 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
qDebug("%s: unhandled cpptype = %d", __FUNCTION__,
|
|
|
|
fieldDesc->cpp_type());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-30 06:08:03 -06:00
|
|
|
void PdmlDefaultProtocol::unknownFieldHandler(QString name,
|
2011-02-18 12:02:57 -06:00
|
|
|
int pos, int size, const QXmlStreamAttributes &attributes,
|
2011-03-27 07:49:31 -05:00
|
|
|
OstProto::Protocol *pbProto, OstProto::Stream *stream)
|
2011-01-30 06:08:03 -06:00
|
|
|
{
|
|
|
|
return; // do nothing!
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-18 12:02:57 -06:00
|
|
|
// ---------------------------------------------------------- //
|
|
|
|
// PdmlReader //
|
|
|
|
// ---------------------------------------------------------- //
|
|
|
|
PdmlReader::PdmlReader(OstProto::StreamConfigList *streams)
|
|
|
|
{
|
2011-02-23 09:58:32 -06:00
|
|
|
gPdmlReader = this;
|
2011-03-06 07:11:08 -06:00
|
|
|
pcap_ = NULL;
|
2011-02-18 12:02:57 -06:00
|
|
|
streams_ = streams;
|
|
|
|
|
2011-03-12 03:46:27 -06:00
|
|
|
currentStream_ = NULL;
|
|
|
|
prevStream_ = NULL;
|
|
|
|
|
2011-03-17 11:30:51 -05:00
|
|
|
stop_ = NULL;
|
|
|
|
|
2011-02-18 12:02:57 -06:00
|
|
|
factory_.insert("hexdump", PdmlUnknownProtocol::createInstance);
|
|
|
|
factory_.insert("geninfo", PdmlGenInfoProtocol::createInstance);
|
|
|
|
factory_.insert("frame", PdmlFrameProtocol::createInstance);
|
2011-03-27 12:15:04 -05:00
|
|
|
|
2011-04-01 13:44:43 -05:00
|
|
|
factory_.insert("arp", PdmlArpProtocol::createInstance);
|
2011-03-24 11:28:39 -05:00
|
|
|
factory_.insert("eth", PdmlEthProtocol::createInstance);
|
2011-04-01 13:44:43 -05:00
|
|
|
factory_.insert("http", PdmlTextProtocol::createInstance);
|
|
|
|
factory_.insert("ieee8021ad", PdmlSvlanProtocol::createInstance);
|
2011-04-03 10:19:57 -05:00
|
|
|
factory_.insert("imap", PdmlTextProtocol::createInstance);
|
2011-03-24 11:28:39 -05:00
|
|
|
factory_.insert("ip", PdmlIp4Protocol::createInstance);
|
|
|
|
factory_.insert("ipv6", PdmlIp6Protocol::createInstance);
|
2011-03-27 12:15:04 -05:00
|
|
|
factory_.insert("llc", PdmlLlcProtocol::createInstance);
|
2011-04-03 03:43:57 -05:00
|
|
|
factory_.insert("nntp", PdmlTextProtocol::createInstance);
|
2011-04-03 10:19:57 -05:00
|
|
|
factory_.insert("pop", PdmlTextProtocol::createInstance);
|
2011-04-03 03:43:57 -05:00
|
|
|
factory_.insert("rtsp", PdmlTextProtocol::createInstance);
|
2011-04-03 10:19:57 -05:00
|
|
|
factory_.insert("sdp", PdmlTextProtocol::createInstance);
|
2011-04-03 03:43:57 -05:00
|
|
|
factory_.insert("sip", PdmlTextProtocol::createInstance);
|
2011-04-03 10:19:57 -05:00
|
|
|
factory_.insert("smtp", PdmlTextProtocol::createInstance);
|
2011-03-24 11:28:39 -05:00
|
|
|
factory_.insert("tcp", PdmlTcpProtocol::createInstance);
|
2011-03-31 10:34:05 -05:00
|
|
|
factory_.insert("udp", PdmlUdpProtocol::createInstance);
|
|
|
|
factory_.insert("udplite", PdmlUdpProtocol::createInstance);
|
2011-03-28 11:53:33 -05:00
|
|
|
factory_.insert("vlan", PdmlVlanProtocol::createInstance);
|
2011-02-18 12:02:57 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
PdmlReader::~PdmlReader()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-03-17 11:30:51 -05:00
|
|
|
bool PdmlReader::read(QIODevice *device, PcapFileFormat *pcap, bool *stop)
|
2011-02-18 12:02:57 -06:00
|
|
|
{
|
|
|
|
setDevice(device);
|
2011-03-06 07:11:08 -06:00
|
|
|
pcap_ = pcap;
|
2011-03-17 11:30:51 -05:00
|
|
|
stop_ = stop;
|
2011-03-24 11:28:39 -05:00
|
|
|
|
2011-02-18 12:02:57 -06:00
|
|
|
while (!atEnd())
|
|
|
|
{
|
|
|
|
readNext();
|
|
|
|
if (isStartElement())
|
|
|
|
{
|
|
|
|
if (name() == "pdml")
|
|
|
|
readPdml();
|
|
|
|
else
|
|
|
|
raiseError("Not a pdml file!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-17 11:30:51 -05:00
|
|
|
if (error() && (errorString() != "USER-CANCEL"))
|
2011-03-06 07:11:08 -06:00
|
|
|
{
|
|
|
|
qDebug("Line %lld", lineNumber());
|
|
|
|
qDebug("Col %lld", columnNumber());
|
2011-03-24 11:28:39 -05:00
|
|
|
qDebug("%s", errorString().toAscii().constData());
|
2011-03-06 07:11:08 -06:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
2011-02-18 12:02:57 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: use a temp pool to avoid a lot of new/delete
|
|
|
|
PdmlDefaultProtocol* PdmlReader::allocPdmlProtocol(QString protoName)
|
|
|
|
{
|
2011-03-24 11:28:39 -05:00
|
|
|
// If protoName is not known, we use a hexdump
|
2011-02-18 12:02:57 -06:00
|
|
|
if (!factory_.contains(protoName))
|
|
|
|
protoName = "hexdump";
|
|
|
|
|
|
|
|
return (*(factory_.value(protoName)))();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PdmlReader::freePdmlProtocol(PdmlDefaultProtocol *proto)
|
|
|
|
{
|
|
|
|
delete proto;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PdmlReader::isDontCareProto()
|
|
|
|
{
|
|
|
|
Q_ASSERT(isStartElement() && name() == "proto");
|
|
|
|
|
2011-03-24 11:28:39 -05:00
|
|
|
QStringRef protoName = attributes().value("name");
|
2011-02-18 12:02:57 -06:00
|
|
|
|
|
|
|
if (protoName.isEmpty() || (protoName == "expert"))
|
|
|
|
return true;
|
|
|
|
|
2011-03-24 11:28:39 -05:00
|
|
|
return false;
|
2011-02-18 12:02:57 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void PdmlReader::skipElement()
|
|
|
|
{
|
|
|
|
Q_ASSERT(isStartElement());
|
|
|
|
|
|
|
|
qDebug("skipping element - <%s>",
|
|
|
|
name().toString().toAscii().constData());
|
|
|
|
while (!atEnd())
|
|
|
|
{
|
|
|
|
readNext();
|
2011-03-24 11:28:39 -05:00
|
|
|
|
2011-02-18 12:02:57 -06:00
|
|
|
if (isEndElement())
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (isStartElement())
|
|
|
|
skipElement();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PdmlReader::readPdml()
|
|
|
|
{
|
|
|
|
Q_ASSERT(isStartElement() && name() == "pdml");
|
|
|
|
|
2011-02-23 09:58:32 -06:00
|
|
|
packetCount_ = 1;
|
2011-02-18 12:02:57 -06:00
|
|
|
|
|
|
|
while (!atEnd())
|
|
|
|
{
|
|
|
|
readNext();
|
2011-03-24 11:28:39 -05:00
|
|
|
|
2011-02-18 12:02:57 -06:00
|
|
|
if (isEndElement())
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (isStartElement())
|
|
|
|
{
|
|
|
|
if (name() == "packet")
|
2011-03-14 10:28:52 -05:00
|
|
|
readPacket();
|
2011-02-18 12:02:57 -06:00
|
|
|
else
|
2011-03-24 11:28:39 -05:00
|
|
|
skipElement();
|
2011-02-18 12:02:57 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-23 09:58:32 -06:00
|
|
|
void PdmlReader::readPacket()
|
|
|
|
{
|
2011-03-06 07:11:08 -06:00
|
|
|
PcapFileFormat::PcapPacketHeader pktHdr;
|
|
|
|
|
|
|
|
Q_ASSERT(isStartElement() && name() == "packet");
|
2011-02-23 09:58:32 -06:00
|
|
|
|
|
|
|
qDebug("%s: packetNum = %d", __FUNCTION__, packetCount_);
|
2011-02-18 12:02:57 -06:00
|
|
|
|
2011-03-12 03:46:27 -06:00
|
|
|
skipUntilEnd_ = false;
|
|
|
|
|
2011-03-06 07:11:08 -06:00
|
|
|
// XXX: we play dumb and convert each packet to a stream, for now
|
2011-03-12 03:46:27 -06:00
|
|
|
prevStream_ = currentStream_;
|
2011-02-18 12:02:57 -06:00
|
|
|
currentStream_ = streams_->add_stream();
|
|
|
|
currentStream_->mutable_stream_id()->set_id(packetCount_);
|
|
|
|
currentStream_->mutable_core()->set_is_enabled(true);
|
|
|
|
|
2011-03-24 11:28:39 -05:00
|
|
|
// Set to a high number; will get reset to correct value during parse
|
2011-03-12 03:46:27 -06:00
|
|
|
currentStream_->mutable_core()->set_frame_len(16384); // FIXME: Hard coding!
|
|
|
|
|
|
|
|
expPos_ = 0;
|
|
|
|
|
2011-03-06 07:11:08 -06:00
|
|
|
if (pcap_)
|
|
|
|
pcap_->readPacket(pktHdr, pktBuf_);
|
|
|
|
|
2011-02-18 12:02:57 -06:00
|
|
|
while (!atEnd())
|
|
|
|
{
|
|
|
|
readNext();
|
|
|
|
|
|
|
|
if (isEndElement())
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (isStartElement())
|
|
|
|
{
|
2011-03-12 03:46:27 -06:00
|
|
|
if (skipUntilEnd_)
|
|
|
|
skipElement();
|
|
|
|
else if (name() == "proto")
|
2011-02-18 12:02:57 -06:00
|
|
|
readProto();
|
|
|
|
else if (name() == "field")
|
|
|
|
readField(NULL, NULL); // TODO: top level field!!!!
|
|
|
|
else
|
2011-03-24 11:28:39 -05:00
|
|
|
skipElement();
|
2011-02-18 12:02:57 -06:00
|
|
|
}
|
|
|
|
}
|
2011-03-12 03:46:27 -06:00
|
|
|
|
2011-03-24 11:28:39 -05:00
|
|
|
currentStream_->mutable_core()->set_name(""); // FIXME
|
2011-03-12 03:46:27 -06:00
|
|
|
|
|
|
|
// If trailing bytes are missing, add those from the pcap
|
|
|
|
if ((expPos_ < pktBuf_.size()) && pcap_)
|
|
|
|
{
|
|
|
|
OstProto::Protocol *proto = currentStream_->add_protocol();
|
|
|
|
OstProto::HexDump *hexDump = proto->MutableExtension(
|
|
|
|
OstProto::hexDump);
|
|
|
|
|
|
|
|
proto->mutable_protocol_id()->set_id(
|
|
|
|
OstProto::Protocol::kHexDumpFieldNumber);
|
|
|
|
|
|
|
|
qDebug("adding trailing %d bytes starting from %d",
|
|
|
|
pktBuf_.size() - expPos_, expPos_);
|
|
|
|
hexDump->set_content(pktBuf_.constData() + expPos_,
|
|
|
|
pktBuf_.size() - expPos_);
|
|
|
|
hexDump->set_pad_until_end(false);
|
|
|
|
}
|
2011-02-18 12:02:57 -06:00
|
|
|
|
2011-02-23 09:58:32 -06:00
|
|
|
packetCount_++;
|
2011-03-24 11:28:39 -05:00
|
|
|
emit progress(int(characterOffset()*100/device()->size())); // in %
|
2011-03-12 03:46:27 -06:00
|
|
|
if (prevStream_)
|
|
|
|
prevStream_->mutable_control()->CopyFrom(currentStream_->control());
|
2011-03-17 11:30:51 -05:00
|
|
|
if (stop_ && *stop_)
|
|
|
|
raiseError("USER-CANCEL");
|
2011-02-23 09:58:32 -06:00
|
|
|
}
|
2011-02-18 12:02:57 -06:00
|
|
|
|
|
|
|
void PdmlReader::readProto()
|
|
|
|
{
|
|
|
|
PdmlDefaultProtocol *pdmlProto = NULL;
|
2011-03-27 07:49:31 -05:00
|
|
|
OstProto::Protocol *pbProto = NULL;
|
2011-02-18 12:02:57 -06:00
|
|
|
|
|
|
|
Q_ASSERT(isStartElement() && name() == "proto");
|
|
|
|
|
2011-03-24 11:28:39 -05:00
|
|
|
QString protoName;
|
2011-03-06 07:11:08 -06:00
|
|
|
int pos = -1;
|
2011-03-12 03:46:27 -06:00
|
|
|
int size = -1;
|
2011-02-18 12:02:57 -06:00
|
|
|
|
2011-03-24 11:28:39 -05:00
|
|
|
if (!attributes().value("name").isEmpty())
|
|
|
|
protoName = attributes().value("name").toString();
|
2011-03-06 07:11:08 -06:00
|
|
|
if (!attributes().value("pos").isEmpty())
|
|
|
|
pos = attributes().value("pos").toString().toInt();
|
2011-03-12 03:46:27 -06:00
|
|
|
if (!attributes().value("size").isEmpty())
|
|
|
|
size = attributes().value("size").toString().toInt();
|
2011-03-06 07:11:08 -06:00
|
|
|
|
2011-04-03 03:43:57 -05:00
|
|
|
qDebug("proto: %s, pos = %d, expPos_ = %d, size = %d",
|
|
|
|
protoName.toAscii().constData(), pos, expPos_, size);
|
2011-03-06 07:11:08 -06:00
|
|
|
|
|
|
|
// This is a heuristic to skip protocols which are not part of
|
|
|
|
// this frame, but of a reassembled segment spanning several frames
|
2011-03-24 11:28:39 -05:00
|
|
|
// 1. Proto starting pos is 0, but we've already seen some protocols
|
2011-03-12 03:46:27 -06:00
|
|
|
// 2. Protocol Size exceeds frame length
|
|
|
|
if (((pos == 0) && (currentStream_->protocol_size() > 0))
|
|
|
|
|| ((pos + size) > int(currentStream_->core().frame_len())))
|
2011-03-06 07:11:08 -06:00
|
|
|
{
|
|
|
|
skipElement();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-03-24 11:28:39 -05:00
|
|
|
if (isDontCareProto())
|
2011-02-18 12:02:57 -06:00
|
|
|
{
|
|
|
|
skipElement();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-03-24 11:28:39 -05:00
|
|
|
// if we detect a gap between subsequent protocols, we "fill-in"
|
2011-03-12 03:46:27 -06:00
|
|
|
// with a "hexdump" from the pcap
|
2011-03-24 11:28:39 -05:00
|
|
|
if (pos > expPos_ && pcap_)
|
2011-03-12 03:46:27 -06:00
|
|
|
{
|
2011-03-24 11:28:39 -05:00
|
|
|
appendHexDumpProto(expPos_, pos - expPos_);
|
|
|
|
expPos_ = pos;
|
2011-03-12 03:46:27 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// for unknown protocol, read a hexdump from the pcap
|
2011-03-06 07:11:08 -06:00
|
|
|
if (!factory_.contains(protoName) && pcap_)
|
|
|
|
{
|
|
|
|
int size = -1;
|
|
|
|
|
|
|
|
if (!attributes().value("size").isEmpty())
|
|
|
|
size = attributes().value("size").toString().toInt();
|
|
|
|
|
2011-03-12 03:46:27 -06:00
|
|
|
// Check if this proto is a subset of previous proto - if so, do nothing
|
|
|
|
if ((pos >= 0) && (size > 0) && ((pos + size) <= expPos_))
|
|
|
|
{
|
|
|
|
qDebug("subset proto");
|
|
|
|
skipElement();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-03-06 07:11:08 -06:00
|
|
|
if (pos >= 0 && size > 0
|
|
|
|
&& ((pos + size) <= pktBuf_.size()))
|
|
|
|
{
|
2011-03-24 11:28:39 -05:00
|
|
|
appendHexDumpProto(pos, size);
|
|
|
|
expPos_ += size;
|
2011-03-06 07:11:08 -06:00
|
|
|
|
|
|
|
skipElement();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-24 11:28:39 -05:00
|
|
|
pdmlProto = appendPdmlProto(protoName, &pbProto);
|
2011-02-18 12:02:57 -06:00
|
|
|
|
2011-03-24 11:28:39 -05:00
|
|
|
qDebug("%s: preProtocolHandler(expPos = %d)",
|
|
|
|
protoName.toAscii().constData(), expPos_);
|
2011-03-27 07:49:31 -05:00
|
|
|
pdmlProto->preProtocolHandler(protoName, attributes(), expPos_, pbProto,
|
2011-03-12 03:46:27 -06:00
|
|
|
currentStream_);
|
2011-02-18 12:02:57 -06:00
|
|
|
|
|
|
|
while (!atEnd())
|
|
|
|
{
|
|
|
|
readNext();
|
|
|
|
|
|
|
|
if (isEndElement())
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (isStartElement())
|
|
|
|
{
|
|
|
|
if (name() == "proto")
|
|
|
|
{
|
|
|
|
// an embedded proto
|
|
|
|
qDebug("embedded proto: %s\n", attributes().value("name")
|
|
|
|
.toString().toAscii().constData());
|
2011-03-24 11:28:39 -05:00
|
|
|
|
2011-02-18 12:02:57 -06:00
|
|
|
if (isDontCareProto())
|
|
|
|
{
|
|
|
|
skipElement();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2011-03-24 11:28:39 -05:00
|
|
|
// if we are in the midst of processing a protocol, we
|
|
|
|
// end it prematurely before we start processing the
|
|
|
|
// embedded protocol
|
|
|
|
//
|
|
|
|
// XXX: pdmlProto may be NULL for a sequence of embedded protos
|
2011-02-18 12:02:57 -06:00
|
|
|
if (pdmlProto)
|
|
|
|
{
|
2011-03-24 11:28:39 -05:00
|
|
|
int endPos = -1;
|
|
|
|
|
|
|
|
if (!attributes().value("pos").isEmpty())
|
|
|
|
endPos = attributes().value("pos").toString().toInt();
|
|
|
|
|
2011-03-27 07:49:31 -05:00
|
|
|
pdmlProto->prematureEndHandler(endPos, pbProto,
|
|
|
|
currentStream_);
|
|
|
|
pdmlProto->postProtocolHandler(pbProto, currentStream_);
|
2011-03-12 03:46:27 -06:00
|
|
|
|
|
|
|
StreamBase s;
|
|
|
|
s.protoDataCopyFrom(*currentStream_);
|
|
|
|
expPos_ = s.frameProtocolLength(0);
|
2011-02-18 12:02:57 -06:00
|
|
|
}
|
2011-03-24 11:28:39 -05:00
|
|
|
|
2011-02-18 12:02:57 -06:00
|
|
|
readProto();
|
2011-03-24 11:28:39 -05:00
|
|
|
|
2011-02-18 12:02:57 -06:00
|
|
|
pdmlProto = NULL;
|
|
|
|
pbProto = NULL;
|
|
|
|
}
|
|
|
|
else if (name() == "field")
|
|
|
|
{
|
2011-03-12 03:46:27 -06:00
|
|
|
if ((protoName == "fake-field-wrapper") &&
|
|
|
|
(attributes().value("name") == "tcp.segments"))
|
|
|
|
{
|
|
|
|
skipElement();
|
|
|
|
qDebug("[skipping reassembled tcp segments]");
|
|
|
|
|
|
|
|
skipUntilEnd_ = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2011-02-18 12:02:57 -06:00
|
|
|
if (pdmlProto == NULL)
|
|
|
|
{
|
2011-03-24 11:28:39 -05:00
|
|
|
pdmlProto = appendPdmlProto(protoName, &pbProto);
|
2011-02-18 12:02:57 -06:00
|
|
|
|
2011-03-24 11:28:39 -05:00
|
|
|
qDebug("%s: preProtocolHandler(expPos = %d)",
|
|
|
|
protoName.toAscii().constData(), expPos_);
|
2011-03-12 03:46:27 -06:00
|
|
|
pdmlProto->preProtocolHandler(protoName, attributes(),
|
2011-03-27 07:49:31 -05:00
|
|
|
expPos_, pbProto, currentStream_);
|
2011-02-18 12:02:57 -06:00
|
|
|
}
|
2011-03-24 11:28:39 -05:00
|
|
|
|
2011-02-18 12:02:57 -06:00
|
|
|
readField(pdmlProto, pbProto);
|
|
|
|
}
|
|
|
|
else
|
2011-03-24 11:28:39 -05:00
|
|
|
skipElement();
|
2011-02-18 12:02:57 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-24 11:28:39 -05:00
|
|
|
// Close-off current protocol
|
2011-02-18 12:02:57 -06:00
|
|
|
if (pdmlProto)
|
|
|
|
{
|
2011-03-27 07:49:31 -05:00
|
|
|
pdmlProto->postProtocolHandler(pbProto, currentStream_);
|
2011-02-18 12:02:57 -06:00
|
|
|
freePdmlProtocol(pdmlProto);
|
2011-03-12 03:46:27 -06:00
|
|
|
|
|
|
|
StreamBase s;
|
|
|
|
s.protoDataCopyFrom(*currentStream_);
|
|
|
|
expPos_ = s.frameProtocolLength(0);
|
2011-02-18 12:02:57 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PdmlReader::readField(PdmlDefaultProtocol *pdmlProto,
|
2011-03-27 07:49:31 -05:00
|
|
|
OstProto::Protocol *pbProto)
|
2011-02-18 12:02:57 -06:00
|
|
|
{
|
|
|
|
Q_ASSERT(isStartElement() && name() == "field");
|
|
|
|
|
|
|
|
// fields with "hide='yes'" are informational and should be skipped
|
|
|
|
if (attributes().value("hide") == "yes")
|
|
|
|
{
|
|
|
|
skipElement();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString fieldName = attributes().value("name").toString();
|
|
|
|
|
2011-03-24 11:28:39 -05:00
|
|
|
qDebug(" fieldName:%s", fieldName.toAscii().constData());
|
2011-02-18 12:02:57 -06:00
|
|
|
|
2011-03-24 11:28:39 -05:00
|
|
|
pdmlProto->fieldHandler(fieldName, attributes(), pbProto, currentStream_);
|
2011-02-18 12:02:57 -06:00
|
|
|
|
|
|
|
while (!atEnd())
|
|
|
|
{
|
|
|
|
readNext();
|
|
|
|
|
|
|
|
if (isEndElement())
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (isStartElement())
|
|
|
|
{
|
|
|
|
if (name() == "proto")
|
2011-04-03 10:19:57 -05:00
|
|
|
{
|
|
|
|
// Since we are in the midst of processing a protocol, we
|
|
|
|
// end it prematurely before we start processing the
|
|
|
|
// embedded protocol
|
|
|
|
//
|
|
|
|
int endPos = -1;
|
|
|
|
|
|
|
|
if (!attributes().value("pos").isEmpty())
|
|
|
|
endPos = attributes().value("pos").toString().toInt();
|
|
|
|
|
|
|
|
pdmlProto->prematureEndHandler(endPos, pbProto,
|
|
|
|
currentStream_);
|
|
|
|
pdmlProto->postProtocolHandler(pbProto, currentStream_);
|
|
|
|
|
|
|
|
StreamBase s;
|
|
|
|
s.protoDataCopyFrom(*currentStream_);
|
|
|
|
expPos_ = s.frameProtocolLength(0);
|
|
|
|
|
2011-02-18 12:02:57 -06:00
|
|
|
readProto();
|
2011-04-03 10:19:57 -05:00
|
|
|
}
|
2011-02-18 12:02:57 -06:00
|
|
|
else if (name() == "field")
|
|
|
|
readField(pdmlProto, pbProto);
|
|
|
|
else
|
2011-03-24 11:28:39 -05:00
|
|
|
skipElement();
|
2011-02-18 12:02:57 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-01-30 06:08:03 -06:00
|
|
|
|
2011-03-24 11:28:39 -05:00
|
|
|
void PdmlReader::appendHexDumpProto(int offset, int size)
|
|
|
|
{
|
|
|
|
OstProto::Protocol *proto = currentStream_->add_protocol();
|
|
|
|
OstProto::HexDump *hexDump = proto->MutableExtension(OstProto::hexDump);
|
|
|
|
|
|
|
|
proto->mutable_protocol_id()->set_id(
|
|
|
|
OstProto::Protocol::kHexDumpFieldNumber);
|
|
|
|
|
|
|
|
qDebug("filling in gap of %d bytes starting from %d", size, offset);
|
|
|
|
hexDump->set_content(pktBuf_.constData() + offset, size);
|
|
|
|
hexDump->set_pad_until_end(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
PdmlDefaultProtocol* PdmlReader::appendPdmlProto(const QString &protoName,
|
2011-03-27 07:49:31 -05:00
|
|
|
OstProto::Protocol **pbProto)
|
2011-03-24 11:28:39 -05:00
|
|
|
{
|
|
|
|
PdmlDefaultProtocol* pdmlProto = allocPdmlProtocol(protoName);
|
|
|
|
Q_ASSERT(pdmlProto != NULL);
|
|
|
|
|
|
|
|
int protoId = pdmlProto->ostProtoId();
|
|
|
|
|
|
|
|
if (protoId > 0) // Non-Base Class
|
|
|
|
{
|
|
|
|
OstProto::Protocol *proto = currentStream_->add_protocol();
|
|
|
|
|
|
|
|
proto->mutable_protocol_id()->set_id(protoId);
|
|
|
|
|
|
|
|
const google::protobuf::Reflection *msgRefl = proto->GetReflection();
|
|
|
|
const google::protobuf::FieldDescriptor *fieldDesc =
|
|
|
|
msgRefl->FindKnownExtensionByNumber(protoId);
|
|
|
|
|
|
|
|
// TODO: if !fDesc
|
|
|
|
// init default values of all fields in protocol
|
2011-03-27 07:49:31 -05:00
|
|
|
msgRefl->MutableMessage(proto, fieldDesc);
|
|
|
|
|
|
|
|
*pbProto = proto;
|
|
|
|
|
|
|
|
qDebug("%s: name = %s", __FUNCTION__,
|
|
|
|
protoName.toAscii().constData());
|
2011-03-24 11:28:39 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
*pbProto = NULL;
|
|
|
|
|
|
|
|
return pdmlProto;
|
|
|
|
}
|
|
|
|
|
2011-01-30 06:08:03 -06:00
|
|
|
|
|
|
|
// ---------------------------------------------------------- //
|
|
|
|
// PdmlUnknownProtocol //
|
|
|
|
// ---------------------------------------------------------- //
|
|
|
|
|
|
|
|
PdmlUnknownProtocol::PdmlUnknownProtocol()
|
|
|
|
{
|
2011-02-18 12:02:57 -06:00
|
|
|
pdmlProtoName_ = "";
|
2011-01-30 06:08:03 -06:00
|
|
|
ostProtoId_ = OstProto::Protocol::kHexDumpFieldNumber;
|
|
|
|
|
|
|
|
endPos_ = expPos_ = -1;
|
|
|
|
}
|
|
|
|
|
2011-02-18 12:02:57 -06:00
|
|
|
PdmlDefaultProtocol* PdmlUnknownProtocol::createInstance()
|
|
|
|
{
|
|
|
|
return new PdmlUnknownProtocol();
|
|
|
|
}
|
|
|
|
|
2011-01-30 06:08:03 -06:00
|
|
|
void PdmlUnknownProtocol::preProtocolHandler(QString name,
|
2011-03-27 07:49:31 -05:00
|
|
|
const QXmlStreamAttributes &attributes, int expectedPos,
|
|
|
|
OstProto::Protocol *pbProto, OstProto::Stream *stream)
|
2011-01-30 06:08:03 -06:00
|
|
|
{
|
|
|
|
bool isOk;
|
2011-02-10 12:00:58 -06:00
|
|
|
int size;
|
2011-02-18 12:02:57 -06:00
|
|
|
int pos = attributes.value("pos").toString().toUInt(&isOk);
|
2011-02-10 12:00:58 -06:00
|
|
|
if (!isOk)
|
2011-03-12 03:46:27 -06:00
|
|
|
{
|
|
|
|
if (expectedPos >= 0)
|
|
|
|
expPos_ = pos = expectedPos;
|
|
|
|
else
|
|
|
|
goto _skip_pos_size_proc;
|
|
|
|
}
|
2011-01-30 06:08:03 -06:00
|
|
|
|
2011-02-18 12:02:57 -06:00
|
|
|
size = attributes.value("size").toString().toUInt(&isOk);
|
2011-02-10 12:00:58 -06:00
|
|
|
if (!isOk)
|
|
|
|
goto _skip_pos_size_proc;
|
2011-01-30 06:08:03 -06:00
|
|
|
|
2011-03-06 07:11:08 -06:00
|
|
|
// If pos+size goes beyond the frame length, this is a "reassembled"
|
|
|
|
// protocol and should be skipped
|
2011-03-12 03:46:27 -06:00
|
|
|
if ((pos + size) > int(stream->core().frame_len()))
|
2011-03-06 07:11:08 -06:00
|
|
|
goto _skip_pos_size_proc;
|
|
|
|
|
2011-01-30 06:08:03 -06:00
|
|
|
expPos_ = pos;
|
|
|
|
endPos_ = expPos_ + size;
|
2011-02-10 12:00:58 -06:00
|
|
|
|
|
|
|
_skip_pos_size_proc:
|
|
|
|
OstProto::HexDump *hexDump = stream->mutable_protocol(
|
|
|
|
stream->protocol_size()-1)->MutableExtension(OstProto::hexDump);
|
|
|
|
hexDump->set_pad_until_end(false);
|
2011-01-30 06:08:03 -06:00
|
|
|
}
|
|
|
|
|
2011-03-27 07:49:31 -05:00
|
|
|
void PdmlUnknownProtocol::prematureEndHandler(int pos,
|
|
|
|
OstProto::Protocol* /*pbProto*/, OstProto::Stream* /*stream*/)
|
2011-02-18 12:02:57 -06:00
|
|
|
{
|
|
|
|
endPos_ = pos;
|
|
|
|
}
|
|
|
|
|
2011-03-27 07:49:31 -05:00
|
|
|
void PdmlUnknownProtocol::postProtocolHandler(OstProto::Protocol *pbProto,
|
|
|
|
OstProto::Stream *stream)
|
2011-01-30 06:08:03 -06:00
|
|
|
{
|
2011-03-27 07:49:31 -05:00
|
|
|
OstProto::HexDump *hexDump = pbProto->MutableExtension(OstProto::hexDump);
|
2011-01-30 06:08:03 -06:00
|
|
|
|
2011-02-10 12:00:58 -06:00
|
|
|
// Skipped field(s) at end? Pad with zero!
|
2011-01-30 06:08:03 -06:00
|
|
|
if (endPos_ > expPos_)
|
|
|
|
{
|
|
|
|
QByteArray hexVal(endPos_ - expPos_, char(0));
|
|
|
|
|
|
|
|
hexDump->mutable_content()->append(hexVal.constData(), hexVal.size());
|
|
|
|
expPos_ += hexVal.size();
|
|
|
|
}
|
|
|
|
|
2011-02-18 12:02:57 -06:00
|
|
|
qDebug(" hexdump: expPos_ = %d, endPos_ = %d\n", expPos_, endPos_);
|
2011-03-12 03:46:27 -06:00
|
|
|
|
|
|
|
// If empty for some reason, remove the protocol
|
|
|
|
if (hexDump->content().size() == 0)
|
|
|
|
stream->mutable_protocol()->RemoveLast();
|
|
|
|
|
2011-02-10 12:00:58 -06:00
|
|
|
endPos_ = expPos_ = -1;
|
2011-01-30 06:08:03 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void PdmlUnknownProtocol::unknownFieldHandler(QString name, int pos, int size,
|
2011-03-27 07:49:31 -05:00
|
|
|
const QXmlStreamAttributes &attributes,
|
|
|
|
OstProto::Protocol *pbProto, OstProto::Stream *stream)
|
2011-01-30 06:08:03 -06:00
|
|
|
{
|
2011-03-27 07:49:31 -05:00
|
|
|
OstProto::HexDump *hexDump = pbProto->MutableExtension(OstProto::hexDump);
|
2011-01-30 06:08:03 -06:00
|
|
|
|
2011-02-18 12:02:57 -06:00
|
|
|
qDebug(" hexdump: %s, pos = %d, expPos_ = %d, endPos_ = %d\n",
|
|
|
|
name.toAscii().constData(),
|
2011-02-10 12:00:58 -06:00
|
|
|
pos, expPos_, endPos_);
|
2011-01-30 06:08:03 -06:00
|
|
|
|
|
|
|
// Skipped field? Pad with zero!
|
2011-02-10 12:00:58 -06:00
|
|
|
if ((pos > expPos_) && (expPos_ < endPos_))
|
2011-01-30 06:08:03 -06:00
|
|
|
{
|
2011-03-14 10:28:52 -05:00
|
|
|
QByteArray hexVal(pos - expPos_, char(0));
|
2011-02-23 09:58:32 -06:00
|
|
|
|
2011-03-14 10:28:52 -05:00
|
|
|
hexDump->mutable_content()->append(hexVal.constData(), hexVal.size());
|
|
|
|
expPos_ += hexVal.size();
|
2011-01-30 06:08:03 -06:00
|
|
|
}
|
|
|
|
|
2011-03-24 11:28:39 -05:00
|
|
|
if (pos == expPos_)
|
2011-01-30 06:08:03 -06:00
|
|
|
{
|
2011-02-10 12:00:58 -06:00
|
|
|
QByteArray hexVal = attributes.value("unmaskedvalue").isEmpty() ?
|
2011-02-18 12:02:57 -06:00
|
|
|
QByteArray::fromHex(attributes.value("value").toString().toUtf8()) :
|
|
|
|
QByteArray::fromHex(attributes.value("unmaskedvalue").toString().toUtf8());
|
2011-01-30 06:08:03 -06:00
|
|
|
|
|
|
|
hexDump->mutable_content()->append(hexVal.constData(), hexVal.size());
|
|
|
|
expPos_ += hexVal.size();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ---------------------------------------------------------- //
|
|
|
|
// PdmlGenInfoProtocol //
|
|
|
|
// ---------------------------------------------------------- //
|
|
|
|
|
|
|
|
PdmlGenInfoProtocol::PdmlGenInfoProtocol()
|
|
|
|
{
|
|
|
|
pdmlProtoName_ = "geninfo";
|
|
|
|
}
|
|
|
|
|
2011-02-18 12:02:57 -06:00
|
|
|
PdmlDefaultProtocol* PdmlGenInfoProtocol::createInstance()
|
|
|
|
{
|
|
|
|
return new PdmlGenInfoProtocol();
|
|
|
|
}
|
|
|
|
|
2011-03-12 03:46:27 -06:00
|
|
|
#if 0 // done in frame proto
|
2011-01-30 06:08:03 -06:00
|
|
|
void PdmlGenInfoProtocol::unknownFieldHandler(QString name, int pos,
|
2011-02-18 12:02:57 -06:00
|
|
|
int size, const QXmlStreamAttributes &attributes, OstProto::Stream *stream)
|
2011-01-30 06:08:03 -06:00
|
|
|
{
|
2011-03-12 03:46:27 -06:00
|
|
|
if (name == "len")
|
|
|
|
stream->mutable_core()->set_frame_len(size+4); // TODO:check FCS
|
2011-01-30 06:08:03 -06:00
|
|
|
}
|
2011-03-12 03:46:27 -06:00
|
|
|
#endif
|
2011-01-30 06:08:03 -06:00
|
|
|
|
|
|
|
// ---------------------------------------------------------- //
|
|
|
|
// PdmlFrameProtocol //
|
|
|
|
// ---------------------------------------------------------- //
|
|
|
|
|
|
|
|
PdmlFrameProtocol::PdmlFrameProtocol()
|
|
|
|
{
|
|
|
|
pdmlProtoName_ = "frame";
|
|
|
|
}
|
|
|
|
|
2011-02-18 12:02:57 -06:00
|
|
|
PdmlDefaultProtocol* PdmlFrameProtocol::createInstance()
|
|
|
|
{
|
|
|
|
return new PdmlFrameProtocol();
|
|
|
|
}
|
|
|
|
|
2011-03-27 07:49:31 -05:00
|
|
|
void PdmlFrameProtocol::unknownFieldHandler(QString name, int pos, int size,
|
|
|
|
const QXmlStreamAttributes &attributes,
|
|
|
|
OstProto::Protocol *pbProto, OstProto::Stream *stream)
|
2011-03-12 03:46:27 -06:00
|
|
|
{
|
|
|
|
if (name == "frame.len")
|
|
|
|
{
|
|
|
|
int len = -1;
|
|
|
|
|
|
|
|
if (!attributes.value("show").isEmpty())
|
|
|
|
len = attributes.value("show").toString().toInt();
|
|
|
|
stream->mutable_core()->set_frame_len(len+4); // TODO:check FCS
|
|
|
|
}
|
|
|
|
else if (name == "frame.time_delta")
|
|
|
|
{
|
|
|
|
if (!attributes.value("show").isEmpty())
|
|
|
|
{
|
|
|
|
QString delta = attributes.value("show").toString();
|
|
|
|
int decimal = delta.indexOf('.');
|
|
|
|
|
|
|
|
if (decimal >= 0)
|
|
|
|
{
|
|
|
|
const uint kNsecsInSec = 1000000000;
|
|
|
|
uint sec = delta.left(decimal).toUInt();
|
|
|
|
uint nsec = delta.mid(decimal+1).toUInt();
|
|
|
|
uint ipg = sec*kNsecsInSec + nsec;
|
|
|
|
|
|
|
|
if (ipg)
|
|
|
|
{
|
|
|
|
stream->mutable_control()->set_packets_per_sec(
|
|
|
|
kNsecsInSec/ipg);
|
|
|
|
}
|
|
|
|
|
|
|
|
qDebug("sec.nsec = %u.%u, ipg = %u", sec, nsec, ipg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-27 12:15:04 -05:00
|
|
|
|
2011-03-29 10:47:37 -05:00
|
|
|
// ---------------------------------------------------------- //
|
|
|
|
// PdmlSvlanProtocol //
|
|
|
|
// ---------------------------------------------------------- //
|
|
|
|
|
|
|
|
PdmlSvlanProtocol::PdmlSvlanProtocol()
|
|
|
|
{
|
|
|
|
pdmlProtoName_ = "ieee8021ad";
|
|
|
|
ostProtoId_ = OstProto::Protocol::kSvlanFieldNumber;
|
|
|
|
}
|
|
|
|
|
|
|
|
PdmlDefaultProtocol* PdmlSvlanProtocol::createInstance()
|
|
|
|
{
|
|
|
|
return new PdmlSvlanProtocol();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PdmlSvlanProtocol::preProtocolHandler(QString name,
|
|
|
|
const QXmlStreamAttributes &attributes, int expectedPos,
|
|
|
|
OstProto::Protocol *pbProto, OstProto::Stream *stream)
|
|
|
|
{
|
|
|
|
OstProto::Vlan *svlan = pbProto->MutableExtension(OstProto::svlan);
|
|
|
|
|
|
|
|
svlan->set_tpid(0x88a8);
|
|
|
|
svlan->set_is_override_tpid(true);
|
|
|
|
|
|
|
|
// If a eth2 protocol precedes svlan, we remove the eth2 protocol
|
|
|
|
// 'coz the eth2.etherType is actually the svlan.tpid
|
|
|
|
//
|
|
|
|
// We assume that the current protocol is the last in the stream
|
|
|
|
int index = stream->protocol_size() - 1;
|
|
|
|
if ((index > 1)
|
|
|
|
&& (stream->protocol(index).protocol_id().id()
|
|
|
|
== OstProto::Protocol::kSvlanFieldNumber)
|
|
|
|
&& (stream->protocol(index - 1).protocol_id().id()
|
|
|
|
== OstProto::Protocol::kEth2FieldNumber))
|
|
|
|
{
|
|
|
|
stream->mutable_protocol()->SwapElements(index, index - 1);
|
|
|
|
Q_ASSERT(stream->protocol(index).protocol_id().id()
|
|
|
|
== OstProto::Protocol::kEth2FieldNumber);
|
|
|
|
stream->mutable_protocol()->RemoveLast();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PdmlSvlanProtocol::unknownFieldHandler(QString name, int pos, int size,
|
|
|
|
const QXmlStreamAttributes &attributes,
|
|
|
|
OstProto::Protocol *pbProto, OstProto::Stream *stream)
|
|
|
|
{
|
|
|
|
if ((name == "ieee8021ad.id") || (name == "ieee8021ad.svid"))
|
|
|
|
{
|
|
|
|
bool isOk;
|
|
|
|
OstProto::Vlan *svlan = pbProto->MutableExtension(OstProto::svlan);
|
|
|
|
uint tag = attributes.value("unmaskedvalue").isEmpty() ?
|
|
|
|
attributes.value("value").toString().toUInt(&isOk, kBaseHex) :
|
|
|
|
attributes.value("unmaskedvalue").toString().toUInt(&isOk,kBaseHex);
|
|
|
|
|
|
|
|
svlan->set_vlan_tag(tag);
|
|
|
|
}
|
|
|
|
else if (name == "ieee8021ad.cvid")
|
|
|
|
{
|
|
|
|
OstProto::Protocol *proto = stream->add_protocol();
|
|
|
|
|
|
|
|
proto->mutable_protocol_id()->set_id(
|
|
|
|
OstProto::Protocol::kSvlanFieldNumber);
|
|
|
|
|
|
|
|
OstProto::Vlan *svlan = proto->MutableExtension(OstProto::svlan);
|
|
|
|
|
|
|
|
svlan->set_tpid(0x88a8);
|
|
|
|
svlan->set_is_override_tpid(true);
|
|
|
|
|
|
|
|
bool isOk;
|
|
|
|
uint tag = attributes.value("unmaskedvalue").isEmpty() ?
|
|
|
|
attributes.value("value").toString().toUInt(&isOk, kBaseHex) :
|
|
|
|
attributes.value("unmaskedvalue").toString().toUInt(&isOk,kBaseHex);
|
|
|
|
|
|
|
|
svlan->set_vlan_tag(tag);
|
|
|
|
}
|
|
|
|
else if (name == "ieee8021ah.etype") // yes 'ah' not 'ad' - not a typo!
|
|
|
|
{
|
|
|
|
OstProto::Protocol *proto = stream->add_protocol();
|
|
|
|
|
|
|
|
proto->mutable_protocol_id()->set_id(
|
|
|
|
OstProto::Protocol::kEth2FieldNumber);
|
|
|
|
|
|
|
|
bool isOk;
|
|
|
|
OstProto::Eth2 *eth2 = proto->MutableExtension(OstProto::eth2);
|
|
|
|
|
|
|
|
eth2->set_type(attributes.value("value")
|
|
|
|
.toString().toUInt(&isOk, kBaseHex));
|
|
|
|
eth2->set_is_override_type(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-27 12:15:04 -05:00
|
|
|
// ---------------------------------------------------------- //
|
|
|
|
// PdmlVlanProtocol //
|
|
|
|
// ---------------------------------------------------------- //
|
|
|
|
|
|
|
|
PdmlVlanProtocol::PdmlVlanProtocol()
|
|
|
|
{
|
|
|
|
pdmlProtoName_ = "vlan";
|
|
|
|
ostProtoId_ = OstProto::Protocol::kVlanFieldNumber;
|
|
|
|
}
|
|
|
|
|
|
|
|
PdmlDefaultProtocol* PdmlVlanProtocol::createInstance()
|
|
|
|
{
|
|
|
|
return new PdmlVlanProtocol();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PdmlVlanProtocol::preProtocolHandler(QString name,
|
|
|
|
const QXmlStreamAttributes &attributes, int expectedPos,
|
|
|
|
OstProto::Protocol *pbProto, OstProto::Stream *stream)
|
|
|
|
{
|
|
|
|
OstProto::Vlan *vlan = pbProto->MutableExtension(OstProto::vlan);
|
|
|
|
|
|
|
|
vlan->set_tpid(0x8100);
|
|
|
|
vlan->set_is_override_tpid(true);
|
2011-03-28 11:53:33 -05:00
|
|
|
|
|
|
|
// If a eth2 protocol precedes vlan, we remove the eth2 protocol
|
|
|
|
// 'coz the eth2.etherType is actually the vlan.tpid
|
|
|
|
//
|
|
|
|
// We assume that the current protocol is the last in the stream
|
|
|
|
int index = stream->protocol_size() - 1;
|
|
|
|
if ((index > 1)
|
|
|
|
&& (stream->protocol(index).protocol_id().id()
|
|
|
|
== OstProto::Protocol::kVlanFieldNumber)
|
|
|
|
&& (stream->protocol(index - 1).protocol_id().id()
|
|
|
|
== OstProto::Protocol::kEth2FieldNumber))
|
|
|
|
{
|
|
|
|
stream->mutable_protocol()->SwapElements(index, index - 1);
|
|
|
|
Q_ASSERT(stream->protocol(index).protocol_id().id()
|
|
|
|
== OstProto::Protocol::kEth2FieldNumber);
|
|
|
|
stream->mutable_protocol()->RemoveLast();
|
|
|
|
}
|
2011-03-27 12:15:04 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void PdmlVlanProtocol::unknownFieldHandler(QString name, int pos, int size,
|
|
|
|
const QXmlStreamAttributes &attributes,
|
|
|
|
OstProto::Protocol *pbProto, OstProto::Stream *stream)
|
|
|
|
{
|
|
|
|
if (name == "vlan.id")
|
|
|
|
{
|
|
|
|
bool isOk;
|
|
|
|
OstProto::Vlan *vlan = pbProto->MutableExtension(OstProto::vlan);
|
|
|
|
uint tag = attributes.value("unmaskedvalue").isEmpty() ?
|
|
|
|
attributes.value("value").toString().toUInt(&isOk, kBaseHex) :
|
|
|
|
attributes.value("unmaskedvalue").toString().toUInt(&isOk,kBaseHex);
|
|
|
|
|
|
|
|
vlan->set_vlan_tag(tag);
|
|
|
|
}
|
|
|
|
else if (name == "vlan.etype")
|
|
|
|
{
|
|
|
|
OstProto::Protocol *proto = stream->add_protocol();
|
|
|
|
|
|
|
|
proto->mutable_protocol_id()->set_id(
|
|
|
|
OstProto::Protocol::kEth2FieldNumber);
|
|
|
|
|
|
|
|
bool isOk;
|
|
|
|
OstProto::Eth2 *eth2 = proto->MutableExtension(OstProto::eth2);
|
|
|
|
|
|
|
|
eth2->set_type(attributes.value("value")
|
|
|
|
.toString().toUInt(&isOk, kBaseHex));
|
|
|
|
eth2->set_is_override_type(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-30 06:08:03 -06:00
|
|
|
// ---------------------------------------------------------- //
|
|
|
|
// PdmlEthProtocol //
|
|
|
|
// ---------------------------------------------------------- //
|
|
|
|
|
|
|
|
PdmlEthProtocol::PdmlEthProtocol()
|
|
|
|
{
|
|
|
|
pdmlProtoName_ = "eth";
|
|
|
|
ostProtoId_ = OstProto::Protocol::kMacFieldNumber;
|
|
|
|
|
|
|
|
fieldMap_.insert("eth.dst", OstProto::Mac::kDstMacFieldNumber);
|
|
|
|
fieldMap_.insert("eth.src", OstProto::Mac::kSrcMacFieldNumber);
|
|
|
|
}
|
|
|
|
|
2011-02-18 12:02:57 -06:00
|
|
|
PdmlDefaultProtocol* PdmlEthProtocol::createInstance()
|
|
|
|
{
|
|
|
|
return new PdmlEthProtocol();
|
|
|
|
}
|
|
|
|
|
2011-01-30 06:08:03 -06:00
|
|
|
void PdmlEthProtocol::unknownFieldHandler(QString name, int pos, int size,
|
2011-03-27 07:49:31 -05:00
|
|
|
const QXmlStreamAttributes &attributes,
|
|
|
|
OstProto::Protocol *pbProto, OstProto::Stream *stream)
|
2011-01-30 06:08:03 -06:00
|
|
|
{
|
|
|
|
if (name == "eth.type")
|
|
|
|
{
|
2011-03-27 12:15:04 -05:00
|
|
|
bool isOk;
|
|
|
|
|
|
|
|
uint type = attributes.value("value").toString()
|
|
|
|
.toUInt(&isOk, kBaseHex);
|
|
|
|
|
2011-01-30 06:08:03 -06:00
|
|
|
OstProto::Protocol *proto = stream->add_protocol();
|
|
|
|
|
|
|
|
proto->mutable_protocol_id()->set_id(
|
|
|
|
OstProto::Protocol::kEth2FieldNumber);
|
|
|
|
|
|
|
|
OstProto::Eth2 *eth2 = proto->MutableExtension(OstProto::eth2);
|
|
|
|
|
2011-03-27 12:15:04 -05:00
|
|
|
eth2->set_type(type);
|
2011-01-30 06:08:03 -06:00
|
|
|
eth2->set_is_override_type(true);
|
|
|
|
}
|
2011-03-06 07:11:08 -06:00
|
|
|
else if (name == "eth.len")
|
|
|
|
{
|
|
|
|
OstProto::Protocol *proto = stream->add_protocol();
|
|
|
|
|
|
|
|
proto->mutable_protocol_id()->set_id(
|
|
|
|
OstProto::Protocol::kDot3FieldNumber);
|
|
|
|
|
|
|
|
OstProto::Dot3 *dot3 = proto->MutableExtension(OstProto::dot3);
|
|
|
|
|
|
|
|
bool isOk;
|
|
|
|
dot3->set_length(attributes.value("value").toString().toUInt(&isOk, kBaseHex));
|
|
|
|
dot3->set_is_override_length(true);
|
|
|
|
}
|
|
|
|
else if (name == "eth.trailer")
|
|
|
|
{
|
|
|
|
QByteArray trailer = QByteArray::fromHex(
|
|
|
|
attributes.value("value").toString().toUtf8());
|
|
|
|
|
|
|
|
stream->mutable_core()->mutable_name()->append(trailer.constData(),
|
|
|
|
trailer.size());
|
|
|
|
}
|
|
|
|
else if ((name == "eth.fcs") ||
|
|
|
|
attributes.value("show").toString().startsWith("Frame check sequence"))
|
|
|
|
{
|
|
|
|
QByteArray trailer = QByteArray::fromHex(
|
|
|
|
attributes.value("value").toString().toUtf8());
|
|
|
|
|
|
|
|
stream->mutable_core()->mutable_name()->append(trailer.constData(),
|
|
|
|
trailer.size());
|
|
|
|
}
|
2011-01-30 06:08:03 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-27 12:15:04 -05:00
|
|
|
// ---------------------------------------------------------- //
|
|
|
|
// PdmlLlcProtocol //
|
|
|
|
// ---------------------------------------------------------- //
|
|
|
|
|
|
|
|
PdmlLlcProtocol::PdmlLlcProtocol()
|
|
|
|
{
|
|
|
|
pdmlProtoName_ = "llc";
|
|
|
|
ostProtoId_ = OstProto::Protocol::kLlcFieldNumber;
|
|
|
|
|
|
|
|
fieldMap_.insert("llc.dsap", OstProto::Llc::kDsapFieldNumber);
|
|
|
|
fieldMap_.insert("llc.ssap", OstProto::Llc::kSsapFieldNumber);
|
|
|
|
fieldMap_.insert("llc.control", OstProto::Llc::kCtlFieldNumber);
|
|
|
|
}
|
|
|
|
|
|
|
|
PdmlDefaultProtocol* PdmlLlcProtocol::createInstance()
|
|
|
|
{
|
|
|
|
return new PdmlLlcProtocol();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PdmlLlcProtocol::unknownFieldHandler(QString name, int pos, int size,
|
|
|
|
const QXmlStreamAttributes &attributes,
|
|
|
|
OstProto::Protocol *pbProto, OstProto::Stream *stream)
|
|
|
|
{
|
|
|
|
if (name == "llc.oui")
|
|
|
|
{
|
|
|
|
OstProto::Protocol *proto = stream->add_protocol();
|
|
|
|
|
|
|
|
proto->mutable_protocol_id()->set_id(
|
|
|
|
OstProto::Protocol::kSnapFieldNumber);
|
|
|
|
|
|
|
|
OstProto::Snap *snap = proto->MutableExtension(OstProto::snap);
|
|
|
|
|
|
|
|
bool isOk;
|
|
|
|
snap->set_oui(attributes.value("value").toString()
|
|
|
|
.toUInt(&isOk, kBaseHex));
|
|
|
|
snap->set_is_override_oui(true);
|
|
|
|
}
|
|
|
|
else if ((name == "llc.type") || (name.contains(QRegExp("llc\\..*pid"))))
|
|
|
|
{
|
|
|
|
OstProto::Snap *snap = stream->mutable_protocol(
|
|
|
|
stream->protocol_size()-1)->MutableExtension(OstProto::snap);
|
|
|
|
|
|
|
|
bool isOk;
|
|
|
|
snap->set_type(attributes.value("value").toString()
|
|
|
|
.toUInt(&isOk, kBaseHex));
|
|
|
|
snap->set_is_override_type(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PdmlLlcProtocol::postProtocolHandler(OstProto::Protocol *pbProto,
|
|
|
|
OstProto::Stream *stream)
|
|
|
|
{
|
|
|
|
OstProto::Llc *llc = pbProto->MutableExtension(OstProto::llc);
|
|
|
|
|
|
|
|
llc->set_is_override_dsap(true);
|
|
|
|
llc->set_is_override_ssap(true);
|
|
|
|
llc->set_is_override_ctl(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-31 10:06:47 -05:00
|
|
|
// ---------------------------------------------------------- //
|
|
|
|
// PdmlArpProtocol //
|
|
|
|
// ---------------------------------------------------------- //
|
|
|
|
|
|
|
|
PdmlArpProtocol::PdmlArpProtocol()
|
|
|
|
{
|
|
|
|
pdmlProtoName_ = "arp";
|
|
|
|
ostProtoId_ = OstProto::Protocol::kArpFieldNumber;
|
|
|
|
|
|
|
|
fieldMap_.insert("arp.opcode", OstProto::Arp::kOpCodeFieldNumber);
|
|
|
|
fieldMap_.insert("arp.src.hw_mac", OstProto::Arp::kSenderHwAddrFieldNumber);
|
|
|
|
fieldMap_.insert("arp.src.proto_ipv4",
|
|
|
|
OstProto::Arp::kSenderProtoAddrFieldNumber);
|
|
|
|
fieldMap_.insert("arp.dst.hw_mac", OstProto::Arp::kTargetHwAddrFieldNumber);
|
|
|
|
fieldMap_.insert("arp.dst.proto_ipv4",
|
|
|
|
OstProto::Arp::kTargetProtoAddrFieldNumber);
|
|
|
|
}
|
|
|
|
|
|
|
|
PdmlDefaultProtocol* PdmlArpProtocol::createInstance()
|
|
|
|
{
|
|
|
|
return new PdmlArpProtocol();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-30 06:08:03 -06:00
|
|
|
// ---------------------------------------------------------- //
|
|
|
|
// PdmlIp4Protocol //
|
|
|
|
// ---------------------------------------------------------- //
|
|
|
|
|
|
|
|
PdmlIp4Protocol::PdmlIp4Protocol()
|
|
|
|
{
|
|
|
|
pdmlProtoName_ = "ip";
|
|
|
|
ostProtoId_ = OstProto::Protocol::kIp4FieldNumber;
|
|
|
|
|
2011-03-31 10:06:47 -05:00
|
|
|
fieldMap_.insert("ip.version", OstProto::Ip4::kVerHdrlenFieldNumber);
|
|
|
|
fieldMap_.insert("ip.dsfield", OstProto::Ip4::kTosFieldNumber);
|
|
|
|
fieldMap_.insert("ip.len", OstProto::Ip4::kTotlenFieldNumber);
|
|
|
|
fieldMap_.insert("ip.id", OstProto::Ip4::kIdFieldNumber);
|
|
|
|
//fieldMap_.insert("ip.flags", OstProto::Ip4::kFlagsFieldNumber);
|
|
|
|
fieldMap_.insert("ip.frag_offset", OstProto::Ip4::kFragOfsFieldNumber);
|
|
|
|
fieldMap_.insert("ip.ttl", OstProto::Ip4::kTtlFieldNumber);
|
|
|
|
fieldMap_.insert("ip.proto", OstProto::Ip4::kProtoFieldNumber);
|
|
|
|
fieldMap_.insert("ip.checksum", OstProto::Ip4::kCksumFieldNumber);
|
|
|
|
fieldMap_.insert("ip.src", OstProto::Ip4::kSrcIpFieldNumber);
|
|
|
|
fieldMap_.insert("ip.dst", OstProto::Ip4::kDstIpFieldNumber);
|
2011-01-30 06:08:03 -06:00
|
|
|
}
|
|
|
|
|
2011-02-18 12:02:57 -06:00
|
|
|
PdmlDefaultProtocol* PdmlIp4Protocol::createInstance()
|
|
|
|
{
|
|
|
|
return new PdmlIp4Protocol();
|
|
|
|
}
|
|
|
|
|
2011-01-30 06:08:03 -06:00
|
|
|
void PdmlIp4Protocol::unknownFieldHandler(QString name, int pos, int size,
|
2011-03-27 07:49:31 -05:00
|
|
|
const QXmlStreamAttributes &attributes,
|
|
|
|
OstProto::Protocol *pbProto, OstProto::Stream *stream)
|
2011-01-30 06:08:03 -06:00
|
|
|
{
|
|
|
|
bool isOk;
|
|
|
|
|
2011-03-06 07:11:08 -06:00
|
|
|
if ((name == "ip.options") ||
|
|
|
|
attributes.value("show").toString().startsWith("Options"))
|
|
|
|
{
|
|
|
|
options_ = QByteArray::fromHex(
|
|
|
|
attributes.value("value").toString().toUtf8());
|
|
|
|
}
|
|
|
|
else if (name == "ip.flags")
|
2011-01-30 06:08:03 -06:00
|
|
|
{
|
2011-03-27 07:49:31 -05:00
|
|
|
OstProto::Ip4 *ip4 = pbProto->MutableExtension(OstProto::ip4);
|
2011-01-30 06:08:03 -06:00
|
|
|
|
2011-02-18 12:02:57 -06:00
|
|
|
ip4->set_flags(attributes.value("value").toString().toUInt(&isOk, kBaseHex) >> 5);
|
2011-01-30 06:08:03 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-27 07:49:31 -05:00
|
|
|
void PdmlIp4Protocol::postProtocolHandler(OstProto::Protocol *pbProto,
|
|
|
|
OstProto::Stream *stream)
|
2011-01-30 06:08:03 -06:00
|
|
|
{
|
2011-03-27 07:49:31 -05:00
|
|
|
OstProto::Ip4 *ip4 = pbProto->MutableExtension(OstProto::ip4);
|
2011-01-30 06:08:03 -06:00
|
|
|
|
|
|
|
ip4->set_is_override_ver(true); // FIXME
|
|
|
|
ip4->set_is_override_hdrlen(true); // FIXME
|
|
|
|
ip4->set_is_override_totlen(true); // FIXME
|
|
|
|
ip4->set_is_override_proto(true); // FIXME
|
|
|
|
ip4->set_is_override_cksum(true); // FIXME
|
2011-03-06 07:11:08 -06:00
|
|
|
|
|
|
|
if (options_.size())
|
|
|
|
{
|
|
|
|
OstProto::Protocol *proto = stream->add_protocol();
|
|
|
|
|
|
|
|
proto->mutable_protocol_id()->set_id(
|
|
|
|
OstProto::Protocol::kHexDumpFieldNumber);
|
|
|
|
|
|
|
|
OstProto::HexDump *hexDump = proto->MutableExtension(OstProto::hexDump);
|
|
|
|
|
|
|
|
hexDump->mutable_content()->append(options_.constData(),
|
|
|
|
options_.size());
|
|
|
|
hexDump->set_pad_until_end(false);
|
|
|
|
options_.resize(0);
|
|
|
|
}
|
2011-01-30 06:08:03 -06:00
|
|
|
}
|
|
|
|
|
2011-02-10 12:00:58 -06:00
|
|
|
// ---------------------------------------------------------- //
|
|
|
|
// PdmlIp6Protocol //
|
|
|
|
// ---------------------------------------------------------- //
|
|
|
|
|
|
|
|
PdmlIp6Protocol::PdmlIp6Protocol()
|
|
|
|
{
|
|
|
|
pdmlProtoName_ = "ipv6";
|
|
|
|
ostProtoId_ = OstProto::Protocol::kIp6FieldNumber;
|
|
|
|
|
|
|
|
fieldMap_.insert("ipv6.version", OstProto::Ip6::kVersionFieldNumber);
|
|
|
|
fieldMap_.insert("ipv6.class", OstProto::Ip6::kTrafficClassFieldNumber);
|
|
|
|
fieldMap_.insert("ipv6.flow", OstProto::Ip6::kFlowLabelFieldNumber);
|
|
|
|
fieldMap_.insert("ipv6.plen", OstProto::Ip6::kPayloadLengthFieldNumber);
|
|
|
|
fieldMap_.insert("ipv6.nxt", OstProto::Ip6::kNextHeaderFieldNumber);
|
|
|
|
fieldMap_.insert("ipv6.hlim", OstProto::Ip6::kHopLimitFieldNumber);
|
|
|
|
|
|
|
|
// ipv6.src and ipv6.dst handled as unknown fields
|
|
|
|
}
|
|
|
|
|
2011-02-18 12:02:57 -06:00
|
|
|
PdmlDefaultProtocol* PdmlIp6Protocol::createInstance()
|
|
|
|
{
|
|
|
|
return new PdmlIp6Protocol();
|
|
|
|
}
|
|
|
|
|
2011-02-10 12:00:58 -06:00
|
|
|
void PdmlIp6Protocol::unknownFieldHandler(QString name, int pos, int size,
|
2011-03-27 07:49:31 -05:00
|
|
|
const QXmlStreamAttributes &attributes, OstProto::Protocol *pbProto,
|
|
|
|
OstProto::Stream *stream)
|
2011-02-10 12:00:58 -06:00
|
|
|
{
|
|
|
|
bool isOk;
|
|
|
|
|
|
|
|
if (name == "ipv6.src")
|
|
|
|
{
|
2011-03-27 07:49:31 -05:00
|
|
|
OstProto::Ip6 *ip6 = pbProto->MutableExtension(OstProto::ip6);
|
2011-02-18 12:02:57 -06:00
|
|
|
QString addrHexStr = attributes.value("value").toString();
|
2011-02-10 12:00:58 -06:00
|
|
|
|
|
|
|
ip6->set_src_addr_hi(addrHexStr.left(16).toULongLong(&isOk, kBaseHex));
|
|
|
|
ip6->set_src_addr_lo(addrHexStr.right(16).toULongLong(&isOk, kBaseHex));
|
|
|
|
}
|
|
|
|
else if (name == "ipv6.dst")
|
|
|
|
{
|
2011-03-27 07:49:31 -05:00
|
|
|
OstProto::Ip6 *ip6 = pbProto->MutableExtension(OstProto::ip6);
|
2011-02-18 12:02:57 -06:00
|
|
|
QString addrHexStr = attributes.value("value").toString();
|
2011-02-10 12:00:58 -06:00
|
|
|
|
|
|
|
ip6->set_dst_addr_hi(addrHexStr.left(16).toULongLong(&isOk, kBaseHex));
|
|
|
|
ip6->set_dst_addr_lo(addrHexStr.right(16).toULongLong(&isOk, kBaseHex));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-27 07:49:31 -05:00
|
|
|
void PdmlIp6Protocol::postProtocolHandler(OstProto::Protocol *pbProto,
|
|
|
|
OstProto::Stream *stream)
|
2011-02-10 12:00:58 -06:00
|
|
|
{
|
2011-03-27 07:49:31 -05:00
|
|
|
OstProto::Ip6 *ip6 = pbProto->MutableExtension(OstProto::ip6);
|
2011-02-10 12:00:58 -06:00
|
|
|
|
|
|
|
ip6->set_is_override_version(true); // FIXME
|
|
|
|
ip6->set_is_override_payload_length(true); // FIXME
|
|
|
|
ip6->set_is_override_next_header(true); // FIXME
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------- //
|
|
|
|
// PdmlTcpProtocol //
|
|
|
|
// ---------------------------------------------------------- //
|
|
|
|
|
|
|
|
PdmlTcpProtocol::PdmlTcpProtocol()
|
|
|
|
{
|
|
|
|
pdmlProtoName_ = "tcp";
|
|
|
|
ostProtoId_ = OstProto::Protocol::kTcpFieldNumber;
|
|
|
|
|
|
|
|
fieldMap_.insert("tcp.srcport", OstProto::Tcp::kSrcPortFieldNumber);
|
|
|
|
fieldMap_.insert("tcp.dstport", OstProto::Tcp::kDstPortFieldNumber);
|
|
|
|
fieldMap_.insert("tcp.seq", OstProto::Tcp::kSeqNumFieldNumber);
|
|
|
|
fieldMap_.insert("tcp.ack", OstProto::Tcp::kAckNumFieldNumber);
|
|
|
|
fieldMap_.insert("tcp.hdr_len", OstProto::Tcp::kHdrlenRsvdFieldNumber);
|
|
|
|
fieldMap_.insert("tcp.flags", OstProto::Tcp::kFlagsFieldNumber);
|
|
|
|
fieldMap_.insert("tcp.window_size", OstProto::Tcp::kWindowFieldNumber);
|
|
|
|
fieldMap_.insert("tcp.checksum", OstProto::Tcp::kCksumFieldNumber);
|
|
|
|
fieldMap_.insert("tcp.urgent_pointer", OstProto::Tcp::kUrgPtrFieldNumber);
|
|
|
|
}
|
|
|
|
|
2011-02-18 12:02:57 -06:00
|
|
|
PdmlDefaultProtocol* PdmlTcpProtocol::createInstance()
|
|
|
|
{
|
|
|
|
return new PdmlTcpProtocol();
|
|
|
|
}
|
|
|
|
|
2011-02-10 12:00:58 -06:00
|
|
|
void PdmlTcpProtocol::unknownFieldHandler(QString name, int pos, int size,
|
2011-03-27 07:49:31 -05:00
|
|
|
const QXmlStreamAttributes &attributes, OstProto::Protocol *pbProto,
|
|
|
|
OstProto::Stream *stream)
|
2011-02-10 12:00:58 -06:00
|
|
|
{
|
|
|
|
if (name == "tcp.options")
|
2011-02-18 12:02:57 -06:00
|
|
|
options_ = QByteArray::fromHex(attributes.value("value").toString().toUtf8());
|
2011-03-12 03:46:27 -06:00
|
|
|
else if (name == "")
|
2011-02-10 12:00:58 -06:00
|
|
|
{
|
2011-03-12 03:46:27 -06:00
|
|
|
if (attributes.value("show").toString().startsWith("TCP segment data"))
|
|
|
|
{
|
|
|
|
segmentData_ = QByteArray::fromHex(attributes.value("value").toString().toUtf8());
|
|
|
|
stream->mutable_core()->mutable_name()->insert(0,
|
|
|
|
segmentData_.constData(), segmentData_.size());
|
|
|
|
}
|
|
|
|
else if (attributes.value("show").toString().startsWith("Acknowledgement number"))
|
|
|
|
{
|
|
|
|
bool isOk;
|
2011-03-27 07:49:31 -05:00
|
|
|
OstProto::Tcp *tcp = pbProto->MutableExtension(OstProto::tcp);
|
2011-03-12 03:46:27 -06:00
|
|
|
|
|
|
|
tcp->set_ack_num(attributes.value("value").toString().toUInt(&isOk, kBaseHex));
|
|
|
|
}
|
2011-02-10 12:00:58 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-27 07:49:31 -05:00
|
|
|
void PdmlTcpProtocol::postProtocolHandler(OstProto::Protocol *pbProto,
|
|
|
|
OstProto::Stream *stream)
|
2011-02-10 12:00:58 -06:00
|
|
|
{
|
2011-03-27 07:49:31 -05:00
|
|
|
OstProto::Tcp *tcp = pbProto->MutableExtension(OstProto::tcp);
|
2011-02-10 12:00:58 -06:00
|
|
|
|
2011-02-18 12:02:57 -06:00
|
|
|
qDebug("Tcp: post\n");
|
|
|
|
|
2011-02-10 12:00:58 -06:00
|
|
|
tcp->set_is_override_src_port(true); // FIXME
|
|
|
|
tcp->set_is_override_dst_port(true); // FIXME
|
|
|
|
tcp->set_is_override_hdrlen(true); // FIXME
|
|
|
|
tcp->set_is_override_cksum(true); // FIXME
|
|
|
|
|
|
|
|
if (options_.size())
|
|
|
|
{
|
|
|
|
OstProto::Protocol *proto = stream->add_protocol();
|
|
|
|
|
|
|
|
proto->mutable_protocol_id()->set_id(
|
|
|
|
OstProto::Protocol::kHexDumpFieldNumber);
|
|
|
|
|
|
|
|
OstProto::HexDump *hexDump = proto->MutableExtension(OstProto::hexDump);
|
|
|
|
|
|
|
|
hexDump->mutable_content()->append(options_.constData(),
|
|
|
|
options_.size());
|
|
|
|
hexDump->set_pad_until_end(false);
|
|
|
|
options_.resize(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
if (segmentData_.size())
|
|
|
|
{
|
|
|
|
OstProto::Protocol *proto = stream->add_protocol();
|
|
|
|
|
|
|
|
proto->mutable_protocol_id()->set_id(
|
|
|
|
OstProto::Protocol::kHexDumpFieldNumber);
|
|
|
|
|
|
|
|
OstProto::HexDump *hexDump = proto->MutableExtension(OstProto::hexDump);
|
|
|
|
|
|
|
|
hexDump->mutable_content()->append(segmentData_.constData(),
|
|
|
|
segmentData_.size());
|
|
|
|
hexDump->set_pad_until_end(false);
|
|
|
|
segmentData_.resize(0);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2011-03-31 10:34:05 -05:00
|
|
|
// ---------------------------------------------------------- //
|
|
|
|
// PdmlUdpProtocol //
|
|
|
|
// ---------------------------------------------------------- //
|
|
|
|
|
|
|
|
PdmlUdpProtocol::PdmlUdpProtocol()
|
|
|
|
{
|
|
|
|
pdmlProtoName_ = "udp"; // OR udplite
|
|
|
|
ostProtoId_ = OstProto::Protocol::kUdpFieldNumber;
|
|
|
|
|
|
|
|
fieldMap_.insert("udp.srcport", OstProto::Udp::kSrcPortFieldNumber);
|
|
|
|
fieldMap_.insert("udp.dstport", OstProto::Udp::kDstPortFieldNumber);
|
|
|
|
fieldMap_.insert("udp.length", OstProto::Udp::kTotlenFieldNumber);
|
|
|
|
fieldMap_.insert("udp.checksum_coverage",
|
|
|
|
OstProto::Udp::kTotlenFieldNumber);
|
|
|
|
fieldMap_.insert("udp.checksum", OstProto::Udp::kCksumFieldNumber);
|
|
|
|
}
|
|
|
|
|
|
|
|
PdmlDefaultProtocol* PdmlUdpProtocol::createInstance()
|
|
|
|
{
|
|
|
|
return new PdmlUdpProtocol();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PdmlUdpProtocol::postProtocolHandler(OstProto::Protocol *pbProto,
|
|
|
|
OstProto::Stream *stream)
|
|
|
|
{
|
|
|
|
OstProto::Udp *udp = pbProto->MutableExtension(OstProto::udp);
|
|
|
|
|
|
|
|
qDebug("Udp: post\n");
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2011-04-01 13:44:43 -05:00
|
|
|
|
|
|
|
// ---------------------------------------------------------- //
|
|
|
|
// PdmlTextProtocol //
|
|
|
|
// ---------------------------------------------------------- //
|
|
|
|
|
|
|
|
PdmlTextProtocol::PdmlTextProtocol()
|
|
|
|
{
|
|
|
|
pdmlProtoName_ = "text";
|
|
|
|
ostProtoId_ = OstProto::Protocol::kTextProtocolFieldNumber;
|
|
|
|
}
|
|
|
|
|
|
|
|
PdmlDefaultProtocol* PdmlTextProtocol::createInstance()
|
|
|
|
{
|
|
|
|
return new PdmlTextProtocol();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PdmlTextProtocol::preProtocolHandler(QString name,
|
|
|
|
const QXmlStreamAttributes &attributes, int expectedPos,
|
|
|
|
OstProto::Protocol *pbProto, OstProto::Stream *stream)
|
|
|
|
{
|
|
|
|
bool isOk;
|
|
|
|
int size;
|
|
|
|
int pos = attributes.value("pos").toString().toUInt(&isOk);
|
|
|
|
|
|
|
|
if (!isOk)
|
|
|
|
{
|
|
|
|
if (expectedPos >= 0)
|
|
|
|
expPos_ = pos = expectedPos;
|
|
|
|
else
|
|
|
|
goto _skip_pos_size_proc;
|
|
|
|
}
|
|
|
|
|
|
|
|
size = attributes.value("size").toString().toUInt(&isOk);
|
|
|
|
if (!isOk)
|
|
|
|
goto _skip_pos_size_proc;
|
|
|
|
|
|
|
|
// If pos+size goes beyond the frame length, this is a "reassembled"
|
|
|
|
// protocol and should be skipped
|
|
|
|
if ((pos + size) > int(stream->core().frame_len()))
|
|
|
|
goto _skip_pos_size_proc;
|
|
|
|
|
|
|
|
expPos_ = pos;
|
|
|
|
endPos_ = expPos_ + size;
|
|
|
|
|
|
|
|
_skip_pos_size_proc:
|
2011-04-03 03:43:57 -05:00
|
|
|
qDebug("expPos_ = %d, endPos_ = %d", expPos_, endPos_);
|
2011-04-01 13:44:43 -05:00
|
|
|
OstProto::TextProtocol *text = pbProto->MutableExtension(
|
|
|
|
OstProto::textProtocol);
|
|
|
|
|
|
|
|
text->set_port_num(0);
|
2011-04-03 10:19:57 -05:00
|
|
|
text->set_eol(OstProto::TextProtocol::kCrLf); // by default we assume CRLF
|
2011-04-01 13:44:43 -05:00
|
|
|
|
2011-04-03 10:19:57 -05:00
|
|
|
detectEol_ = true;
|
2011-04-01 13:44:43 -05:00
|
|
|
contentType_ = kUnknownContent;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PdmlTextProtocol::unknownFieldHandler(QString name, int pos, int size,
|
|
|
|
const QXmlStreamAttributes &attributes, OstProto::Protocol *pbProto,
|
|
|
|
OstProto::Stream *stream)
|
|
|
|
{
|
2011-04-03 10:19:57 -05:00
|
|
|
_retry:
|
|
|
|
switch(contentType_)
|
|
|
|
{
|
|
|
|
case kUnknownContent:
|
|
|
|
if (name == "data")
|
|
|
|
contentType_ = kOtherContent;
|
|
|
|
else
|
|
|
|
contentType_ = kTextContent;
|
|
|
|
goto _retry;
|
|
|
|
break;
|
2011-04-01 13:44:43 -05:00
|
|
|
|
2011-04-03 10:19:57 -05:00
|
|
|
case kTextContent:
|
|
|
|
{
|
2011-04-03 03:43:57 -05:00
|
|
|
OstProto::TextProtocol *text = pbProto->MutableExtension(
|
|
|
|
OstProto::textProtocol);
|
|
|
|
|
2011-04-03 10:19:57 -05:00
|
|
|
if ((name == "data")
|
|
|
|
|| (attributes.value("show") == "HTTP chunked response"))
|
2011-04-03 03:43:57 -05:00
|
|
|
{
|
2011-04-03 10:19:57 -05:00
|
|
|
contentType_ = kOtherContent;
|
|
|
|
goto _retry;
|
2011-04-03 03:43:57 -05:00
|
|
|
}
|
|
|
|
|
2011-04-03 10:19:57 -05:00
|
|
|
if (pos < expPos_)
|
|
|
|
break;
|
2011-04-03 03:43:57 -05:00
|
|
|
|
2011-04-03 10:19:57 -05:00
|
|
|
if ((pos + size) > endPos_)
|
|
|
|
break;
|
2011-04-03 03:43:57 -05:00
|
|
|
|
2011-04-03 10:19:57 -05:00
|
|
|
if (pos > expPos_)
|
|
|
|
{
|
|
|
|
int gap = pos - expPos_;
|
|
|
|
QByteArray filler(gap, '\n');
|
2011-04-03 03:43:57 -05:00
|
|
|
|
2011-04-03 10:19:57 -05:00
|
|
|
if (text->eol() == OstProto::TextProtocol::kCrLf)
|
|
|
|
{
|
|
|
|
if (gap & 0x01) // Odd
|
|
|
|
{
|
|
|
|
filler.resize(gap/2 + 1);
|
|
|
|
filler[0]=int(' ');
|
|
|
|
}
|
|
|
|
else // Even
|
|
|
|
filler.resize(gap/2);
|
|
|
|
}
|
2011-04-01 13:44:43 -05:00
|
|
|
|
2011-04-03 10:19:57 -05:00
|
|
|
text->mutable_text()->append(filler.constData(), filler.size());
|
|
|
|
expPos_ += gap;
|
|
|
|
}
|
|
|
|
|
|
|
|
QByteArray line = QByteArray::fromHex(
|
|
|
|
attributes.value("value").toString().toUtf8());
|
2011-04-01 13:44:43 -05:00
|
|
|
|
2011-04-03 10:19:57 -05:00
|
|
|
if (detectEol_)
|
|
|
|
{
|
|
|
|
if (line.right(2) == "\r\n")
|
|
|
|
text->set_eol(OstProto::TextProtocol::kCrLf);
|
|
|
|
else if (line.right(1) == "\r")
|
|
|
|
text->set_eol(OstProto::TextProtocol::kCr);
|
|
|
|
else if (line.right(1) == "\n")
|
|
|
|
text->set_eol(OstProto::TextProtocol::kLf);
|
|
|
|
|
|
|
|
detectEol_ = false;
|
|
|
|
}
|
2011-04-01 13:44:43 -05:00
|
|
|
|
2011-04-03 10:19:57 -05:00
|
|
|
// Convert line endings to LF only - Qt reqmt that TextProto honours
|
|
|
|
line.replace("\r\n", "\n");
|
|
|
|
line.replace('\r', '\n');
|
2011-04-01 13:44:43 -05:00
|
|
|
|
2011-04-03 10:19:57 -05:00
|
|
|
text->mutable_text()->append(line.constData(), line.size());
|
|
|
|
expPos_ += size;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case kOtherContent:
|
|
|
|
// Do nothing!
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
Q_ASSERT(false);
|
|
|
|
}
|
2011-04-01 13:44:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void PdmlTextProtocol::postProtocolHandler(OstProto::Protocol *pbProto,
|
|
|
|
OstProto::Stream *stream)
|
|
|
|
{
|
|
|
|
OstProto::TextProtocol *text = pbProto->MutableExtension(
|
|
|
|
OstProto::textProtocol);
|
|
|
|
|
|
|
|
// Empty Text Content - remove ourselves
|
|
|
|
if (text->text().length() == 0)
|
|
|
|
stream->mutable_protocol()->RemoveLast();
|
|
|
|
|
|
|
|
expPos_ = endPos_ = -1;
|
2011-04-03 10:19:57 -05:00
|
|
|
detectEol_ = true;
|
2011-04-01 13:44:43 -05:00
|
|
|
contentType_ = kUnknownContent;
|
|
|
|
}
|
|
|
|
|