implement Packet::PeekHeader and Packet::PeekTrailer to avoid evil workarounds when receiving tcp packets.
This commit is contained in:
@@ -199,6 +199,13 @@ Packet::RemoveHeader (Header &header)
|
||||
m_metadata.RemoveHeader (header, deserialized);
|
||||
return deserialized;
|
||||
}
|
||||
uint32_t
|
||||
Packet::PeekHeader (Header &header)
|
||||
{
|
||||
NS_LOG_FUNCTION (this << &header);
|
||||
uint32_t deserialized = header.Deserialize (m_buffer.Begin ());
|
||||
return deserialized;
|
||||
}
|
||||
void
|
||||
Packet::AddTrailer (const Trailer &trailer)
|
||||
{
|
||||
@@ -224,6 +231,13 @@ Packet::RemoveTrailer (Trailer &trailer)
|
||||
m_metadata.RemoveTrailer (trailer, deserialized);
|
||||
return deserialized;
|
||||
}
|
||||
uint32_t
|
||||
Packet::PeekTrailer (Trailer &trailer)
|
||||
{
|
||||
NS_LOG_FUNCTION (this << &trailer);
|
||||
uint32_t deserialized = trailer.Deserialize (m_buffer.End ());
|
||||
return deserialized;
|
||||
}
|
||||
|
||||
void
|
||||
Packet::AddAtEnd (Ptr<const Packet> packet)
|
||||
|
||||
@@ -187,7 +187,7 @@ public:
|
||||
uint32_t GetSize (void) const;
|
||||
/**
|
||||
* Add header to this packet. This method invokes the
|
||||
* GetSerializedSize and Serialize
|
||||
* Header::GetSerializedSize and Header::Serialize
|
||||
* methods to reserve space in the buffer and request the
|
||||
* header to serialize itself in the packet buffer.
|
||||
*
|
||||
@@ -196,15 +196,23 @@ public:
|
||||
void AddHeader (const Header & header);
|
||||
/**
|
||||
* Deserialize and remove the header from the internal buffer.
|
||||
* This method invokes Deserialize.
|
||||
* This method invokes Header::Deserialize.
|
||||
*
|
||||
* \param header a reference to the header to remove from the internal buffer.
|
||||
* \returns the number of bytes removed from the packet.
|
||||
*/
|
||||
uint32_t RemoveHeader (Header &header);
|
||||
/**
|
||||
* Deserialize but does _not_ remove the header from the internal buffer.
|
||||
* This method invokes Header::Deserialize.
|
||||
*
|
||||
* \param header a reference to the header to read from the internal buffer.
|
||||
* \returns the number of bytes read from the packet.
|
||||
*/
|
||||
uint32_t PeekHeader (Header &header);
|
||||
/**
|
||||
* Add trailer to this packet. This method invokes the
|
||||
* GetSerializedSize and Serialize
|
||||
* Trailer::GetSerializedSize and Trailer::Serialize
|
||||
* methods to reserve space in the buffer and request the trailer
|
||||
* to serialize itself in the packet buffer.
|
||||
*
|
||||
@@ -219,6 +227,14 @@ public:
|
||||
* \returns the number of bytes removed from the end of the packet.
|
||||
*/
|
||||
uint32_t RemoveTrailer (Trailer &trailer);
|
||||
/**
|
||||
* Deserialize but does _not_ remove a trailer from the internal buffer.
|
||||
* This method invokes the Trailer::Deserialize method.
|
||||
*
|
||||
* \param trailer a reference to the trailer to read from the internal buffer.
|
||||
* \returns the number of bytes read from the end of the packet.
|
||||
*/
|
||||
uint32_t PeekTrailer (Trailer &trailer);
|
||||
/**
|
||||
* \param os output stream in which the data should be printed.
|
||||
*
|
||||
|
||||
@@ -449,13 +449,8 @@ TcpL4Protocol::Receive (Ptr<Packet> packet,
|
||||
{
|
||||
tcpHeader.EnableChecksums();
|
||||
}
|
||||
/* XXX very dirty but needs this to AddHeader again because of checksum */
|
||||
tcpHeader.SetLength(5); /* XXX TCP without options */
|
||||
tcpHeader.SetPayloadSize(packet->GetSize() - tcpHeader.GetSerializedSize());
|
||||
tcpHeader.InitializeChecksum(source, destination, PROT_NUMBER);
|
||||
|
||||
//these two do a peek, so that the packet can be forwarded up
|
||||
packet->RemoveHeader (tcpHeader);
|
||||
packet->PeekHeader (tcpHeader);
|
||||
|
||||
NS_LOG_LOGIC("TcpL4Protocol " << this
|
||||
<< " receiving seq " << tcpHeader.GetSequenceNumber()
|
||||
@@ -469,7 +464,6 @@ TcpL4Protocol::Receive (Ptr<Packet> packet,
|
||||
return;
|
||||
}
|
||||
|
||||
packet->AddHeader (tcpHeader);
|
||||
NS_LOG_LOGIC ("TcpL4Protocol "<<this<<" received a packet");
|
||||
Ipv4EndPointDemux::EndPoints endPoints =
|
||||
m_endPoints->Lookup (destination, tcpHeader.GetDestinationPort (),
|
||||
|
||||
Reference in New Issue
Block a user