restore TCP option padding approach that avoids NOPs
authorTom Henderson <tomh@tomh.org>
Wed, 10 Sep 2014 15:05:57 -0700
changeset 10910 51990b91bfc8
parent 10909 5f30a86698c3
child 10911 c224a92a02a2
restore TCP option padding approach that avoids NOPs
src/internet/model/tcp-header.cc
src/internet/test/tcp-header-test.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;
   }
 
--- 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");
   }
 
   {