IPv4 now supports options - configured as a hex string for now; fixes #120

This commit is contained in:
Srivats P 2016-10-27 23:50:24 +05:30
parent b45720b566
commit c2f36c5cb3
5 changed files with 57 additions and 13 deletions

View File

@ -112,6 +112,7 @@ AbstractProtocol::FieldFlags Ip4Protocol::fieldFlags(int index) const
case ip4_srcAddr: case ip4_srcAddr:
case ip4_dstAddr: case ip4_dstAddr:
case ip4_options:
break; break;
case ip4_isOverrideVer: case ip4_isOverrideVer:
@ -168,7 +169,9 @@ QVariant Ip4Protocol::fieldData(int index, FieldAttrib attrib,
{ {
int hdrlen; 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) switch(attrib)
{ {
@ -205,6 +208,7 @@ QVariant Ip4Protocol::fieldData(int index, FieldAttrib attrib,
break; break;
case ip4_totLen: case ip4_totLen:
{ {
int ipLen = 20 + data.options().length();
switch(attrib) switch(attrib)
{ {
case FieldName: case FieldName:
@ -213,7 +217,7 @@ QVariant Ip4Protocol::fieldData(int index, FieldAttrib attrib,
{ {
int totlen; int totlen;
totlen = data.is_override_totlen() ? data.totlen() : totlen = data.is_override_totlen() ? data.totlen() :
(protocolFramePayloadSize(streamIndex) + 20); (protocolFramePayloadSize(streamIndex) + ipLen);
return totlen; return totlen;
} }
case FieldFrameValue: case FieldFrameValue:
@ -221,7 +225,7 @@ QVariant Ip4Protocol::fieldData(int index, FieldAttrib attrib,
QByteArray fv; QByteArray fv;
int totlen; int totlen;
totlen = data.is_override_totlen() ? data.totlen() : totlen = data.is_override_totlen() ? data.totlen() :
(protocolFramePayloadSize(streamIndex) + 20); (protocolFramePayloadSize(streamIndex) + ipLen);
fv.resize(2); fv.resize(2);
qToBigEndian((quint16) totlen, (uchar*) fv.data()); qToBigEndian((quint16) totlen, (uchar*) fv.data());
return fv; return fv;
@ -230,7 +234,7 @@ QVariant Ip4Protocol::fieldData(int index, FieldAttrib attrib,
{ {
int totlen; int totlen;
totlen = data.is_override_totlen() ? data.totlen() : totlen = data.is_override_totlen() ? data.totlen() :
(protocolFramePayloadSize(streamIndex) + 20); (protocolFramePayloadSize(streamIndex) + ipLen);
return QString("%1").arg(totlen); return QString("%1").arg(totlen);
} }
case FieldBitSize: case FieldBitSize:
@ -509,6 +513,32 @@ QVariant Ip4Protocol::fieldData(int index, FieldAttrib attrib,
} }
break; 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 // Meta fields
case ip4_isOverrideVer: case ip4_isOverrideVer:
@ -695,6 +725,16 @@ bool Ip4Protocol::setFieldData(int index, const QVariant &value,
data.set_dst_ip(dstIp); data.set_dst_ip(dstIp);
break; 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 // Meta-fields
case ip4_isOverrideVer: case ip4_isOverrideVer:

View File

@ -44,6 +44,7 @@ public:
ip4_cksum, ip4_cksum,
ip4_srcAddr, ip4_srcAddr,
ip4_dstAddr, ip4_dstAddr,
ip4_options,
// Meta-fields // Meta-fields
ip4_isOverrideVer, ip4_isOverrideVer,

View File

@ -58,7 +58,7 @@ message Ip4 {
optional uint32 dst_ip_count = 20 [default = 16]; optional uint32 dst_ip_count = 20 [default = 16];
optional fixed32 dst_ip_mask = 21 [default = 0xFFFFFF00]; optional fixed32 dst_ip_mask = 21 [default = 0xFFFFFF00];
//! \todo (LOW) IPv4 Options optional bytes options = 22;
} }
extend Protocol { extend Protocol {

View File

@ -366,14 +366,7 @@ Length (x4)</string>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLineEdit" name="leIpOptions" > <widget class="QLineEdit" name="leIpOptions" />
<property name="enabled" >
<bool>false</bool>
</property>
<property name="text" >
<string>TODO</string>
</property>
</widget>
</item> </item>
<item> <item>
<widget class="QToolButton" name="tbIpOptionsEdit" > <widget class="QToolButton" name="tbIpOptionsEdit" >

View File

@ -28,6 +28,8 @@ Ip4ConfigForm::Ip4ConfigForm(QWidget *parent)
setupUi(this); setupUi(this);
leIpVersion->setValidator(new QIntValidator(0, 15, this)); leIpVersion->setValidator(new QIntValidator(0, 15, this));
leIpOptions->setValidator(new QRegExpValidator(QRegExp("[0-9a-fA-F]*"),
this));
connect(cmbIpSrcAddrMode, SIGNAL(currentIndexChanged(int)), connect(cmbIpSrcAddrMode, SIGNAL(currentIndexChanged(int)),
this, SLOT(on_cmbIpSrcAddrMode_currentIndexChanged(int))); this, SLOT(on_cmbIpSrcAddrMode_currentIndexChanged(int)));
@ -176,6 +178,11 @@ void Ip4ConfigForm::loadWidget(AbstractProtocol *proto)
Ip4Protocol::ip4_dstAddrMask, Ip4Protocol::ip4_dstAddrMask,
AbstractProtocol::FieldValue AbstractProtocol::FieldValue
).toUInt()).toString()); ).toUInt()).toString());
leIpOptions->setText(
proto->fieldData(
Ip4Protocol::ip4_options,
AbstractProtocol::FieldValue
).toByteArray().toHex());
} }
void Ip4ConfigForm::storeWidget(AbstractProtocol *proto) void Ip4ConfigForm::storeWidget(AbstractProtocol *proto)
@ -263,6 +270,9 @@ void Ip4ConfigForm::storeWidget(AbstractProtocol *proto)
proto->setFieldData( proto->setFieldData(
Ip4Protocol::ip4_dstAddrMask, Ip4Protocol::ip4_dstAddrMask,
QHostAddress(leIpDstAddrMask->text()).toIPv4Address()); QHostAddress(leIpDstAddrMask->text()).toIPv4Address());
proto->setFieldData(
Ip4Protocol::ip4_options,
QByteArray::fromHex(QByteArray().append(leIpOptions->text())));
} }
/* /*