# HG changeset patch # User Tommaso Pecorella # Date 1456573017 -3600 # Parent 48d97b9d2ef242e0156ed54ab59270738aeacbfc network: (fixes #2078) Packet metadata disabling on a per-packet basis diff --git a/RELEASE_NOTES b/RELEASE_NOTES --- a/RELEASE_NOTES +++ b/RELEASE_NOTES @@ -64,6 +64,7 @@ - Bug 2003 - Missing DSSS short PLCP preamble - Bug 2041 - TCP RTO needs unit tests - Bug 2068 - Timestamp option conforms to RFC 7323 +- Bug 2078 - Packet metadata disabling on a per-packet basis - Bug 2116 - refactoring aggregation API - Bug 2120 - 802.11g networks are not compatible with 802.11b clients - Bug 2141 - TCP DataSent callback now correctly notifies sent data, without missing bytes in particular conditions diff --git a/src/internet/model/icmpv6-header.cc b/src/internet/model/icmpv6-header.cc --- a/src/internet/model/icmpv6-header.cc +++ b/src/internet/model/icmpv6-header.cc @@ -1133,6 +1133,7 @@ i.ReadNtohU32 (); i.Read (data, length); m_packet = Create (data, length); + m_packet->SetDirtyMetadata (); delete[] data; return GetSerializedSize (); diff --git a/src/network/model/packet.cc b/src/network/model/packet.cc --- a/src/network/model/packet.cc +++ b/src/network/model/packet.cc @@ -138,6 +138,7 @@ * global UID */ m_metadata (static_cast (Simulator::GetSystemId ()) << 32 | m_globalUid, 0), + m_dirtyMetadata (false), m_nixVector (0) { m_globalUid++; @@ -147,7 +148,8 @@ : m_buffer (o.m_buffer), m_byteTagList (o.m_byteTagList), m_packetTagList (o.m_packetTagList), - m_metadata (o.m_metadata) + m_metadata (o.m_metadata), + m_dirtyMetadata (o.m_dirtyMetadata) { o.m_nixVector ? m_nixVector = o.m_nixVector->Copy () : m_nixVector = 0; @@ -164,6 +166,7 @@ m_byteTagList = o.m_byteTagList; m_packetTagList = o.m_packetTagList; m_metadata = o.m_metadata; + m_dirtyMetadata = o.m_dirtyMetadata; o.m_nixVector ? m_nixVector = o.m_nixVector->Copy () : m_nixVector = 0; return *this; @@ -180,6 +183,7 @@ * global UID */ m_metadata (static_cast (Simulator::GetSystemId ()) << 32 | m_globalUid, size), + m_dirtyMetadata (false), m_nixVector (0) { m_globalUid++; @@ -189,6 +193,7 @@ m_byteTagList (), m_packetTagList (), m_metadata (0,0), + m_dirtyMetadata (false), m_nixVector (0) { NS_ASSERT (magic); @@ -206,6 +211,7 @@ * global UID */ m_metadata (static_cast (Simulator::GetSystemId ()) << 32 | m_globalUid, size), + m_dirtyMetadata (false), m_nixVector (0) { m_globalUid++; @@ -220,6 +226,7 @@ m_byteTagList (byteTagList), m_packetTagList (packetTagList), m_metadata (metadata), + m_dirtyMetadata (false), m_nixVector (0) { } @@ -247,6 +254,12 @@ m_nixVector = nixVector; } +void +Packet::SetDirtyMetadata (void) +{ + m_dirtyMetadata = true; +} + Ptr Packet::GetNixVector (void) const { @@ -271,7 +284,10 @@ NS_LOG_FUNCTION (this << header.GetInstanceTypeId ().GetName () << deserialized); m_buffer.RemoveAtStart (deserialized); m_byteTagList.Adjust (-deserialized); - m_metadata.RemoveHeader (header, deserialized); + if (!m_dirtyMetadata) + { + m_metadata.RemoveHeader (header, deserialized); + } return deserialized; } uint32_t @@ -298,7 +314,10 @@ uint32_t deserialized = trailer.Deserialize (m_buffer.End ()); NS_LOG_FUNCTION (this << trailer.GetInstanceTypeId ().GetName () << deserialized); m_buffer.RemoveAtEnd (deserialized); - m_metadata.RemoveTrailer (trailer, deserialized); + if (!m_dirtyMetadata) + { + m_metadata.RemoveTrailer (trailer, deserialized); + } return deserialized; } uint32_t @@ -752,11 +771,11 @@ size -= metaSize; - uint32_t metadataDeserialized = + uint32_t metadataDeserialized = m_metadata.Deserialize (reinterpret_cast (p), metaSize); if (!metadataDeserialized) { - // meta-data not deserialized + // meta-data not deserialized // completely return 0; } diff --git a/src/network/model/packet.h b/src/network/model/packet.h --- a/src/network/model/packet.h +++ b/src/network/model/packet.h @@ -276,6 +276,10 @@ * The input data is copied: the input * buffer is untouched. * + * If the buffer also contains headers or trailers and these + * must be later removed, it is advisable to use + * Packet::SetDirtyMetadata as well. + * * \param buffer the data to store in the packet. * \param size the size of the input buffer. */ @@ -526,6 +530,16 @@ uint32_t Serialize (uint8_t* buffer, uint32_t maxSize) const; /** + * Prevents the packet header and trailer removal from trying to + * remove also non-existent metadata. + * + * A packet with a valid header (or trailer) can be created by direct + * creation of a packet from a buffer with a proper header. + * This is typical of ICMP Destination Unreachable. + */ + void SetDirtyMetadata (void); + + /** * \brief Tag each byte included in this packet with a new byte tag. * * \param tag the new tag to add to this packet @@ -542,6 +556,7 @@ * packet). */ void AddByteTag (const Tag &tag) const; + /** * \brief Retiurns an iterator over the set of byte tags included in this packet * @@ -717,6 +732,7 @@ ByteTagList m_byteTagList; //!< the ByteTag list PacketTagList m_packetTagList; //!< the packet's Tag list PacketMetadata m_metadata; //!< the packet's metadata + bool m_dirtyMetadata; //!< the packet's metadata are not check-safe /* Please see comments above about nix-vector */ Ptr m_nixVector; //!< the packet's Nix vector