internet: allow peeking wrong IPv{4,6} headers (returns a zero deserialized size)

This commit is contained in:
Tommaso Pecorella
2016-02-11 21:59:47 +01:00
parent b830a39aa6
commit b6d49ca37b
3 changed files with 17 additions and 14 deletions

View File

@@ -341,8 +341,8 @@ Ipv4Header::Print (std::ostream &os) const
{
flags = "none";
}
else if (m_flags & MORE_FRAGMENTS &&
m_flags & DONT_FRAGMENT)
else if ((m_flags & MORE_FRAGMENTS) &&
(m_flags & DONT_FRAGMENT))
{
flags = "MF|DF";
}
@@ -424,10 +424,17 @@ Ipv4Header::Deserialize (Buffer::Iterator start)
{
NS_LOG_FUNCTION (this << &start);
Buffer::Iterator i = start;
uint8_t verIhl = i.ReadU8 ();
uint8_t ihl = verIhl & 0x0f;
uint16_t headerSize = ihl * 4;
NS_ASSERT ((verIhl >> 4) == 4);
if ((verIhl >> 4) != 4)
{
NS_LOG_WARN ("Trying to decode a non-IPv4 header, refusing to do it.");
return 0;
}
m_tos = i.ReadU8 ();
uint16_t size = i.ReadNtohU16 ();
m_payloadSize = size - headerSize;

View File

@@ -32,8 +32,7 @@ NS_LOG_COMPONENT_DEFINE ("Ipv6Header");
NS_OBJECT_ENSURE_REGISTERED (Ipv6Header);
Ipv6Header::Ipv6Header ()
: m_version (6),
m_trafficClass (0),
: m_trafficClass (0),
m_flowLabel (1),
m_payloadLength (0),
m_nextHeader (0),
@@ -130,8 +129,7 @@ TypeId Ipv6Header::GetInstanceTypeId (void) const
void Ipv6Header::Print (std::ostream& os) const
{
os << "("
"Version " << m_version << " "
os << "(Version 6 "
<< "Traffic class 0x" << std::hex << m_trafficClass << std::dec << " "
<< "Flow Label 0x" << std::hex << m_flowLabel << std::dec << " "
<< "Payload Length " << m_payloadLength << " "
@@ -168,9 +166,11 @@ uint32_t Ipv6Header::Deserialize (Buffer::Iterator start)
uint32_t vTcFl = 0;
vTcFl = i.ReadNtohU32 ();
m_version = vTcFl >> 28;
NS_ASSERT ((m_version) == 6);
if ((vTcFl >> 28) != 6)
{
NS_LOG_WARN ("Trying to decode a non-IPv6 header, refusing to do it.");
return 0;
}
m_trafficClass = (uint8_t)((vTcFl >> 20) & 0x000000ff);
m_flowLabel = vTcFl & 0xfff00000;

View File

@@ -184,10 +184,6 @@ public:
virtual uint32_t Deserialize (Buffer::Iterator start);
private:
/**
* \brief The version (always equal to 6).
*/
uint32_t m_version : 4;
/**
* \brief The traffic class.
*/