Skip to content

Commit

Permalink
IPv4 now supports options - configured as a hex string for now; fixes p…
Browse files Browse the repository at this point in the history
  • Loading branch information
pstavirs committed Oct 27, 2016
1 parent 3619a9e commit 18a7bfd
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 13 deletions.
48 changes: 44 additions & 4 deletions common/ip4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ AbstractProtocol::FieldFlags Ip4Protocol::fieldFlags(int index) const

case ip4_srcAddr:
case ip4_dstAddr:
case ip4_options:
break;

case ip4_isOverrideVer:
Expand Down Expand Up @@ -168,7 +169,9 @@ QVariant Ip4Protocol::fieldData(int index, FieldAttrib attrib,
{
int hdrlen;

hdrlen = data.is_override_hdrlen() ? data.ver_hdrlen() & 0x0F : 5;
hdrlen = data.is_override_hdrlen() ?
data.ver_hdrlen() : 5 + data.options().length()/4;
hdrlen &= 0x0F;

switch(attrib)
{
Expand Down Expand Up @@ -205,6 +208,7 @@ QVariant Ip4Protocol::fieldData(int index, FieldAttrib attrib,
break;
case ip4_totLen:
{
int ipLen = 20 + data.options().length();
switch(attrib)
{
case FieldName:
Expand All @@ -213,15 +217,15 @@ QVariant Ip4Protocol::fieldData(int index, FieldAttrib attrib,
{
int totlen;
totlen = data.is_override_totlen() ? data.totlen() :
(protocolFramePayloadSize(streamIndex) + 20);
(protocolFramePayloadSize(streamIndex) + ipLen);
return totlen;
}
case FieldFrameValue:
{
QByteArray fv;
int totlen;
totlen = data.is_override_totlen() ? data.totlen() :
(protocolFramePayloadSize(streamIndex) + 20);
(protocolFramePayloadSize(streamIndex) + ipLen);
fv.resize(2);
qToBigEndian((quint16) totlen, (uchar*) fv.data());
return fv;
Expand All @@ -230,7 +234,7 @@ QVariant Ip4Protocol::fieldData(int index, FieldAttrib attrib,
{
int totlen;
totlen = data.is_override_totlen() ? data.totlen() :
(protocolFramePayloadSize(streamIndex) + 20);
(protocolFramePayloadSize(streamIndex) + ipLen);
return QString("%1").arg(totlen);
}
case FieldBitSize:
Expand Down Expand Up @@ -509,6 +513,32 @@ QVariant Ip4Protocol::fieldData(int index, FieldAttrib attrib,
}
break;
}
case ip4_options:
{
QByteArray ba;
switch(attrib)
{
case FieldValue:
case FieldFrameValue:
case FieldTextValue:
ba.append(QString().fromStdString(data.options()));
default:
break;
}
switch(attrib)
{
case FieldName:
return QString("Options");
case FieldValue:
case FieldFrameValue:
return ba;
case FieldTextValue:
return ba.toHex();
default:
break;
}
break;
}

// Meta fields
case ip4_isOverrideVer:
Expand Down Expand Up @@ -695,6 +725,16 @@ bool Ip4Protocol::setFieldData(int index, const QVariant &value,
data.set_dst_ip(dstIp);
break;
}
case ip4_options:
{
QByteArray ba = value.toByteArray();
int pad = (4 - (ba.size() % 4)) % 4;
if (pad)
ba.append(QByteArray(pad, 0));
data.set_options(ba.constData(), ba.size());
isOk = true;
break;
}

// Meta-fields
case ip4_isOverrideVer:
Expand Down
1 change: 1 addition & 0 deletions common/ip4.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class Ip4Protocol : public AbstractProtocol
ip4_cksum,
ip4_srcAddr,
ip4_dstAddr,
ip4_options,

// Meta-fields
ip4_isOverrideVer,
Expand Down
2 changes: 1 addition & 1 deletion common/ip4.proto
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ message Ip4 {
optional uint32 dst_ip_count = 20 [default = 16];
optional fixed32 dst_ip_mask = 21 [default = 0xFFFFFF00];

//! \todo (LOW) IPv4 Options
optional bytes options = 22;
}

extend Protocol {
Expand Down
9 changes: 1 addition & 8 deletions common/ip4.ui
Original file line number Diff line number Diff line change
Expand Up @@ -366,14 +366,7 @@ Length (x4)</string>
</widget>
</item>
<item>
<widget class="QLineEdit" name="leIpOptions" >
<property name="enabled" >
<bool>false</bool>
</property>
<property name="text" >
<string>TODO</string>
</property>
</widget>
<widget class="QLineEdit" name="leIpOptions" />
</item>
<item>
<widget class="QToolButton" name="tbIpOptionsEdit" >
Expand Down
10 changes: 10 additions & 0 deletions common/ip4config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ Ip4ConfigForm::Ip4ConfigForm(QWidget *parent)
setupUi(this);

leIpVersion->setValidator(new QIntValidator(0, 15, this));
leIpOptions->setValidator(new QRegExpValidator(QRegExp("[0-9a-fA-F]*"),
this));

connect(cmbIpSrcAddrMode, SIGNAL(currentIndexChanged(int)),
this, SLOT(on_cmbIpSrcAddrMode_currentIndexChanged(int)));
Expand Down Expand Up @@ -176,6 +178,11 @@ void Ip4ConfigForm::loadWidget(AbstractProtocol *proto)
Ip4Protocol::ip4_dstAddrMask,
AbstractProtocol::FieldValue
).toUInt()).toString());
leIpOptions->setText(
proto->fieldData(
Ip4Protocol::ip4_options,
AbstractProtocol::FieldValue
).toByteArray().toHex());
}

void Ip4ConfigForm::storeWidget(AbstractProtocol *proto)
Expand Down Expand Up @@ -263,6 +270,9 @@ void Ip4ConfigForm::storeWidget(AbstractProtocol *proto)
proto->setFieldData(
Ip4Protocol::ip4_dstAddrMask,
QHostAddress(leIpDstAddrMask->text()).toIPv4Address());
proto->setFieldData(
Ip4Protocol::ip4_options,
QByteArray::fromHex(QByteArray().append(leIpOptions->text())));
}

/*
Expand Down

0 comments on commit 18a7bfd

Please sign in to comment.