implement Packet::PeekHeader and Packet::PeekTrailer to avoid evil workarounds when receiving tcp packets.
authorMathieu Lacage <mathieu.lacage@sophia.inria.fr>
Tue Jul 01 11:00:29 2008 -0700 (19 months ago)
changeset 33648e6ac6061680
parent 3363 33d1ca2e4ba4
child 3365 6409d2460601
child 3368 95bbf601167d
child 3435 1d704c128f1f
implement Packet::PeekHeader and Packet::PeekTrailer to avoid evil workarounds when receiving tcp packets.
src/common/packet.cc
src/common/packet.h
src/internet-stack/tcp-l4-protocol.cc
     1.1 --- a/src/common/packet.cc	Tue Jul 01 10:52:11 2008 -0700
     1.2 +++ b/src/common/packet.cc	Tue Jul 01 11:00:29 2008 -0700
     1.3 @@ -199,6 +199,13 @@
     1.4    m_metadata.RemoveHeader (header, deserialized);
     1.5    return deserialized;
     1.6  }
     1.7 +uint32_t
     1.8 +Packet::PeekHeader (Header &header)
     1.9 +{
    1.10 +  NS_LOG_FUNCTION (this << &header);
    1.11 +  uint32_t deserialized = header.Deserialize (m_buffer.Begin ());
    1.12 +  return deserialized;
    1.13 +}
    1.14  void
    1.15  Packet::AddTrailer (const Trailer &trailer)
    1.16  {
    1.17 @@ -224,6 +231,13 @@
    1.18    m_metadata.RemoveTrailer (trailer, deserialized);
    1.19    return deserialized;
    1.20  }
    1.21 +uint32_t
    1.22 +Packet::PeekTrailer (Trailer &trailer)
    1.23 +{
    1.24 +  NS_LOG_FUNCTION (this << &trailer);
    1.25 +  uint32_t deserialized = trailer.Deserialize (m_buffer.End ());
    1.26 +  return deserialized;
    1.27 +}
    1.28  
    1.29  void 
    1.30  Packet::AddAtEnd (Ptr<const Packet> packet)
     2.1 --- a/src/common/packet.h	Tue Jul 01 10:52:11 2008 -0700
     2.2 +++ b/src/common/packet.h	Tue Jul 01 11:00:29 2008 -0700
     2.3 @@ -187,7 +187,7 @@
     2.4    uint32_t GetSize (void) const;
     2.5    /**
     2.6     * Add header to this packet. This method invokes the
     2.7 -   * GetSerializedSize and Serialize
     2.8 +   * Header::GetSerializedSize and Header::Serialize
     2.9     * methods to reserve space in the buffer and request the 
    2.10     * header to serialize itself in the packet buffer.
    2.11     *
    2.12 @@ -196,15 +196,23 @@
    2.13    void AddHeader (const Header & header);
    2.14    /**
    2.15     * Deserialize and remove the header from the internal buffer.
    2.16 -   * This method invokes Deserialize.
    2.17 +   * This method invokes Header::Deserialize.
    2.18     *
    2.19     * \param header a reference to the header to remove from the internal buffer.
    2.20     * \returns the number of bytes removed from the packet.
    2.21     */
    2.22    uint32_t RemoveHeader (Header &header);
    2.23    /**
    2.24 +   * Deserialize but does _not_ remove the header from the internal buffer.
    2.25 +   * This method invokes Header::Deserialize.
    2.26 +   *
    2.27 +   * \param header a reference to the header to read from the internal buffer.
    2.28 +   * \returns the number of bytes read from the packet.
    2.29 +   */  
    2.30 +  uint32_t PeekHeader (Header &header);
    2.31 +  /**
    2.32     * Add trailer to this packet. This method invokes the
    2.33 -   * GetSerializedSize and Serialize
    2.34 +   * Trailer::GetSerializedSize and Trailer::Serialize
    2.35     * methods to reserve space in the buffer and request the trailer 
    2.36     * to serialize itself in the packet buffer.
    2.37     *
    2.38 @@ -220,6 +228,14 @@
    2.39     */
    2.40    uint32_t RemoveTrailer (Trailer &trailer);
    2.41    /**
    2.42 +   * Deserialize but does _not_ remove a trailer from the internal buffer.
    2.43 +   * This method invokes the Trailer::Deserialize method.
    2.44 +   *
    2.45 +   * \param trailer a reference to the trailer to read from the internal buffer.
    2.46 +   * \returns the number of bytes read from the end of the packet.
    2.47 +   */
    2.48 +  uint32_t PeekTrailer (Trailer &trailer);
    2.49 +  /**
    2.50     * \param os output stream in which the data should be printed.
    2.51     *
    2.52     * Iterate over the tags present in this packet, and
     3.1 --- a/src/internet-stack/tcp-l4-protocol.cc	Tue Jul 01 10:52:11 2008 -0700
     3.2 +++ b/src/internet-stack/tcp-l4-protocol.cc	Tue Jul 01 11:00:29 2008 -0700
     3.3 @@ -449,13 +449,8 @@
     3.4    {
     3.5      tcpHeader.EnableChecksums();
     3.6    }
     3.7 -  /* XXX very dirty but needs this to AddHeader again because of checksum */
     3.8 -  tcpHeader.SetLength(5); /* XXX TCP without options */
     3.9 -  tcpHeader.SetPayloadSize(packet->GetSize() - tcpHeader.GetSerializedSize());
    3.10 -  tcpHeader.InitializeChecksum(source, destination, PROT_NUMBER);
    3.11  
    3.12 -  //these two do a peek, so that the packet can be forwarded up
    3.13 -  packet->RemoveHeader (tcpHeader);
    3.14 +  packet->PeekHeader (tcpHeader);
    3.15  
    3.16    NS_LOG_LOGIC("TcpL4Protocol " << this
    3.17                 << " receiving seq " << tcpHeader.GetSequenceNumber()
    3.18 @@ -469,7 +464,6 @@
    3.19      return;
    3.20    }
    3.21  
    3.22 -  packet->AddHeader (tcpHeader);
    3.23    NS_LOG_LOGIC ("TcpL4Protocol "<<this<<" received a packet");
    3.24    Ipv4EndPointDemux::EndPoints endPoints =
    3.25      m_endPoints->Lookup (destination, tcpHeader.GetDestinationPort (),