# HG changeset patch # User Tom Henderson # Date 1410386757 25200 # Node ID 51990b91bfc8db7ca846e1c6bea4a4e0b9b14130 # Parent 5f30a86698c3cda61739cbe6703423de62573cb5 restore TCP option padding approach that avoids NOPs diff -r 5f30a86698c3 -r 51990b91bfc8 src/internet/model/tcp-header.cc --- a/src/internet/model/tcp-header.cc Tue Sep 09 16:15:49 2014 -0700 +++ b/src/internet/model/tcp-header.cc Wed Sep 10 15:05:57 2014 -0700 @@ -317,7 +317,9 @@ 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 @@ 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 -r 5f30a86698c3 -r 51990b91bfc8 src/internet/test/tcp-header-test.cc --- a/src/internet/test/tcp-header-test.cc Tue Sep 09 16:15:49 2014 -0700 +++ b/src/internet/test/tcp-header-test.cc Wed Sep 10 15:05:57 2014 -0700 @@ -265,18 +265,18 @@ 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"); } {