130 lines
4.4 KiB
C++
130 lines
4.4 KiB
C++
/*
|
|
Copyright (C) 2021 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 "grepdml.h"
|
|
|
|
#include "gre.pb.h"
|
|
|
|
/*!
|
|
TODO : Initialize the following inherited protected members -
|
|
- ostProtoId_
|
|
- fieldMap_
|
|
|
|
ostProtoId_ is the protocol's protobuf field number as defined in
|
|
message 'Protocol' enum 'k' in file protocol.proto
|
|
|
|
fieldMap_ is a mapping of the protocol's field names as they appear
|
|
in the PDML to the protobuf field numbers for the protocol. All such
|
|
fields are classified as 'known' fields and the base class will take care
|
|
of decoding these without any help from the subclass.
|
|
|
|
Note that the PDML field names are same as the field names used in Wireshark
|
|
display filters. The full reference for these is available at -
|
|
http://www.wireshark.org/docs/dfref/
|
|
*/
|
|
PdmlGreProtocol::PdmlGreProtocol()
|
|
{
|
|
ostProtoId_ = OstProto::Protocol::kGreFieldNumber;
|
|
|
|
fieldMap_.insert("gre.proto", OstProto::Gre::kProtocolTypeFieldNumber);
|
|
fieldMap_.insert("gre.checksum", OstProto::Gre::kChecksumFieldNumber);
|
|
fieldMap_.insert("gre.offset", OstProto::Gre::kRsvd1FieldNumber);
|
|
fieldMap_.insert("gre.key", OstProto::Gre::kKeyFieldNumber);
|
|
fieldMap_.insert("gre.sequence_number", OstProto::Gre::kSequenceNumFieldNumber);
|
|
}
|
|
|
|
PdmlGreProtocol::~PdmlGreProtocol()
|
|
{
|
|
}
|
|
|
|
PdmlProtocol* PdmlGreProtocol::createInstance()
|
|
{
|
|
return new PdmlGreProtocol();
|
|
}
|
|
|
|
/*!
|
|
TODO: Use this method to do any special handling that may be required for
|
|
preprocessing a protocol before parsing/decoding the protocol's fields
|
|
*/
|
|
void PdmlGreProtocol::preProtocolHandler(QString /*name*/,
|
|
const QXmlStreamAttributes& /*attributes*/,
|
|
int /*expectedPos*/, OstProto::Protocol* /*pbProto*/,
|
|
OstProto::Stream* /*stream*/)
|
|
{
|
|
return;
|
|
}
|
|
|
|
/*!
|
|
TODO: Use this method to do any special handling or cleanup that may be
|
|
required when a protocol decode is ending prematurely
|
|
*/
|
|
void PdmlGreProtocol::prematureEndHandler(int /*pos*/,
|
|
OstProto::Protocol* /*pbProto*/, OstProto::Stream* /*stream*/)
|
|
{
|
|
return;
|
|
}
|
|
|
|
/*!
|
|
TODO: Use this method to do any special handling that may be required for
|
|
postprocessing a protocol after parsing/decoding all the protocol fields
|
|
|
|
If your protocol's protobuf has some meta-fields that should be set to
|
|
their non default values, this is a good place to do that. e.g. derived
|
|
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
|
|
*/
|
|
void PdmlGreProtocol::postProtocolHandler(OstProto::Protocol* /*pbProto*/,
|
|
OstProto::Stream* /*stream*/)
|
|
{
|
|
return;
|
|
}
|
|
|
|
/*!
|
|
TODO: Handle all 'unknown' fields using this method
|
|
|
|
You need to typically only handle frame fields or fields actually present
|
|
in the protocol on the wire. So you can safely ignore meta-fields such as
|
|
Good/Bad Checksum.
|
|
|
|
Some fields may not have a 'name' attribute, so cannot be classified as
|
|
a 'known' field. Use this method to identify such fields using other
|
|
attributes such as 'show' or 'showname' and populate the corresponding
|
|
protobuf field.
|
|
|
|
If the PDML protocol contains some fields that are not supported by Ostinato,
|
|
use a HexDump protocol as a replacement to store these bytes
|
|
*/
|
|
void PdmlGreProtocol::unknownFieldHandler(QString name,
|
|
int /*pos*/, int /*size*/, const QXmlStreamAttributes& attributes,
|
|
OstProto::Protocol* proto, OstProto::Stream* /*stream*/)
|
|
{
|
|
if (name == "gre.flags_and_version") {
|
|
bool isOk;
|
|
OstProto::Gre *gre = proto->MutableExtension(OstProto::gre);
|
|
quint16 flagsAndVersion = attributes.value("value")
|
|
.toUInt(&isOk, kBaseHex);
|
|
|
|
gre->set_flags(flagsAndVersion >> 12);
|
|
gre->set_rsvd0((flagsAndVersion & 0x0FFF) >> 3);
|
|
gre->set_version(flagsAndVersion & 0x0007);
|
|
}
|
|
}
|