From 8443885e88dbb532be822f7c396d7840bb8d3b43 Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Wed, 10 Sep 2014 15:05:57 -0700 Subject: [PATCH] restore TCP option padding approach that avoids NOPs --- src/internet/model/tcp-header.cc | 15 +++++---------- src/internet/test/tcp-header-test.cc | 8 ++++---- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/src/internet/model/tcp-header.cc b/src/internet/model/tcp-header.cc index d68888edf..2c70b82ca 100644 --- a/src/internet/model/tcp-header.cc +++ b/src/internet/model/tcp-header.cc @@ -317,7 +317,9 @@ TcpHeader::Serialize (Buffer::Iterator start) const i.WriteHtonU16 (0); i.WriteHtonU16 (m_urgentPointer); - // Serialize options if they exists + // Serialize options if they exist + // This implementation does not presently try to align options on word + // boundaries using NOP options uint32_t optionLen = 0; TcpOptionList::const_iterator op; for (op = m_options.begin (); op != m_options.end (); ++op) @@ -327,17 +329,10 @@ TcpHeader::Serialize (Buffer::Iterator start) const i.Next ((*op)->GetSerializedSize ()); } - // padding to word alignment; add NOPs as needed until last byte which is END + // padding to word alignment; add ENDs and/or pad values (they are the same) while (optionLen % 4) { - if ((optionLen % 4) == 3) - { - i.WriteU8 (TcpOption::END); - } - else - { - i.WriteU8 (TcpOption::NOP); - } + i.WriteU8 (TcpOption::END); ++optionLen; } diff --git a/src/internet/test/tcp-header-test.cc b/src/internet/test/tcp-header-test.cc index d87216f5b..2e8cc0aa1 100644 --- a/src/internet/test/tcp-header-test.cc +++ b/src/internet/test/tcp-header-test.cc @@ -265,18 +265,18 @@ TcpHeaderWithRFC793OptionTestCase::OneOptionAtTime () buffer.GetSize (), "Header not correctly serialized"); // Inserted only 1 byte NOP, and so implementation should pad; so - // the other 3 bytes should be NOP, NOP, END + // the other 3 bytes should be END, PAD, PAD (n.b. PAD is same as END) Buffer::Iterator i = buffer.Begin (); i.Next (20); uint8_t value = i.ReadU8 (); NS_TEST_ASSERT_MSG_EQ (value, TcpOption::NOP, "NOP not present at byte 1"); value = i.ReadU8 (); - NS_TEST_ASSERT_MSG_EQ (value, TcpOption::NOP, "NOP not present at byte 2"); + NS_TEST_ASSERT_MSG_EQ (value, TcpOption::END, "END not present at byte 2"); value = i.ReadU8 (); - NS_TEST_ASSERT_MSG_EQ (value, TcpOption::NOP, "NOP not present at byte 3"); + NS_TEST_ASSERT_MSG_EQ (value, TcpOption::END, "pad not present at byte 3"); value = i.ReadU8 (); - NS_TEST_ASSERT_MSG_EQ (value, TcpOption::END, "END not present at byte 4"); + NS_TEST_ASSERT_MSG_EQ (value, TcpOption::END, "pad not present at byte 4"); } {