Add protocol error checks to preflight check

Also commented out stream transmit duration check that was causing false
positives
This commit is contained in:
Srivats P 2019-06-05 11:39:09 +05:30
parent 6817d3f870
commit 64d4b38f41
9 changed files with 106 additions and 0 deletions

View File

@ -1027,6 +1027,17 @@ out:
return cksum;
}
/*!
Returns true, if the protocol fields are incorrect or may cause
overall packet to be invalid
Error details are put in the optional INOUT param 'errors', if true.
*/
bool AbstractProtocol::hasErrors(QStringList* /*errors*/) const
{
return false;
}
// Stein's binary GCD algo - from wikipedia
quint64 AbstractProtocol::gcd(quint64 u, quint64 v)
{

View File

@ -172,6 +172,8 @@ public:
CksumType cksumType = CksumIp,
CksumScope cksumScope = CksumScopeAllProtocols) const;
virtual bool hasErrors(QStringList *errors = nullptr) const;
static quint64 lcm(quint64 u, quint64 v);
static quint64 gcd(quint64 u, quint64 v);

View File

@ -878,3 +878,27 @@ quint32 Ip4Protocol::protocolFrameCksum(int streamIndex,
return AbstractProtocol::protocolFrameCksum(streamIndex, cksumType);
}
bool Ip4Protocol::hasErrors(QStringList *errors) const
{
bool result = false;
if ((data.dst_ip() == 0)
&& (data.dst_ip_mode() == OstProto::Ip4::e_im_fixed)) {
if (errors)
*errors << QObject::tr("Frames with Destination IP 0.0.0.0 "
"are likely to be dropped");
result = true;
}
if ((data.src_ip() == 0)
&& (data.src_ip_mode() == OstProto::Ip4::e_im_fixed)) {
if (errors)
*errors << QObject::tr("Frames with Source IP 0.0.0.0 "
"may be dropped except for special cases "
"like BOOTP/DHCP");
result = true;
}
return result;
}

View File

@ -91,6 +91,7 @@ public:
virtual quint32 protocolFrameCksum(int streamIndex = 0,
CksumType cksumType = CksumIp) const;
virtual bool hasErrors(QStringList *errors = nullptr) const;
private:
OstProto::Ip4 data;
};

View File

@ -797,3 +797,25 @@ quint32 Ip6Protocol::protocolFrameCksum(int streamIndex,
return AbstractProtocol::protocolFrameCksum(streamIndex, cksumType);
}
bool Ip6Protocol::hasErrors(QStringList *errors) const
{
bool result = false;
if ((data.dst_addr_hi() == 0ULL) && (data.dst_addr_lo() == 0ULL)
&& (data.dst_addr_mode() == OstProto::Ip6::kFixed)) {
if (errors)
*errors << QObject::tr("Frames with Destination IP :: (all zeroes) "
"are likely to be dropped");
result = true;
}
if ((data.src_addr_hi() == 0ULL) && (data.src_addr_lo() == 0ULL)
&& (data.src_addr_mode() == OstProto::Ip6::kFixed)) {
if (errors)
*errors << QObject::tr("Frames with Source IP :: (all zeroes) "
"are likely to be dropped");
result = true;
}
return result;
}

View File

@ -104,6 +104,8 @@ public:
virtual quint32 protocolFrameCksum(int streamIndex = 0,
CksumType cksumType = CksumIp) const;
virtual bool hasErrors(QStringList *errors = nullptr) const;
private:
OstProto::Ip6 data;
};

View File

@ -397,3 +397,27 @@ QByteArray MacProtocol::protocolFrameValue(int streamIndex, bool /*forCksum*/,
return ba;
}
bool MacProtocol::hasErrors(QStringList *errors) const
{
bool result = false;
if ((data.dst_mac() == 0ULL)
&& (data.dst_mac_mode() != OstProto::Mac::e_mm_resolve)) {
if (errors)
*errors << QObject::tr("Frames with Destination Mac "
"00:00:00:00:00:00 are likely "
"to be dropped");
result = true;
}
if ((data.src_mac() == 0ULL)
&& (data.src_mac_mode() != OstProto::Mac::e_mm_resolve)) {
if (errors)
*errors << QObject::tr("Frames with Source Mac "
"00:00:00:00:00:00 are likely "
"to be dropped");
result = true;
}
return result;
}

View File

@ -68,6 +68,7 @@ public:
virtual QByteArray protocolFrameValue(int streamIndex = 0,
bool forCksum = false, FrameValueAttrib *attrib = nullptr) const;
virtual bool hasErrors(QStringList *errors = nullptr) const;
private:
OstProto::Mac data;
mutable bool forResolve_;

View File

@ -636,6 +636,18 @@ bool StreamBase::preflightCheck(QStringList &result) const
break;
}
ProtocolListIterator *iter = createProtocolListIterator();
while (iter->hasNext())
{
QStringList errors;
AbstractProtocol *proto = iter->next();
if (proto->hasErrors(&errors)) {
result += errors;
pass = false;
}
}
delete iter;
if (isFrameVariable()) {
if (frameVariableCount() > frameCount())
{
@ -668,6 +680,12 @@ bool StreamBase::preflightCheck(QStringList &result) const
}
}
#if 0 // see XXX note below
// XXX: This causes false positives for -
// * interleaved streams (a port property that we don't have access to)
// * pcap imported streams where each stream has only one packet
// Ideally we need to get the transmit duration for all the streams
// to perform this check
if (frameCount() < averagePacketRate() && nextWhat() != e_nw_goto_id)
{
result << QObject::tr("Only %L1 frames at the rate of "
@ -681,6 +699,7 @@ bool StreamBase::preflightCheck(QStringList &result) const
.arg(frameCount()/averagePacketRate(), 0, 'f');
pass = false;
}
#endif
return pass;
}