From 42825825352cbc2f01a8b59a8c254ff94fd267b8 Mon Sep 17 00:00:00 2001 From: Tom Goff Date: Thu, 12 May 2011 21:19:07 -0700 Subject: [PATCH] bug 1056: CSMA: padding not handled correctly for LLC encapsulation --- RELEASE_NOTES | 1 + src/csma/model/csma-net-device.cc | 22 ++++++++++++++++------ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/RELEASE_NOTES b/RELEASE_NOTES index 12e3e0ce6..f574a7635 100644 --- a/RELEASE_NOTES +++ b/RELEASE_NOTES @@ -72,6 +72,7 @@ since ns-3.10, in many cases referencing the Bugzilla bug number. - bug 1038 - Time::Get*Seconds () return signed integer while actually returning unsigned - bug 445 - Is the class name Scalar in nstime.h appropriate? - bug 1044 - Seconds (1e-9) creates Time that is not IsPositive () + - bug 1056 - CSMA: padding not handled correctly for LLC encapsulation Known issues ------------ diff --git a/src/csma/model/csma-net-device.cc b/src/csma/model/csma-net-device.cc index f5d018ef8..dd55fdc0f 100644 --- a/src/csma/model/csma-net-device.cc +++ b/src/csma/model/csma-net-device.cc @@ -321,6 +321,13 @@ CsmaNetDevice::AddHeader (Ptr p, Mac48Address source, Mac48Address de llc.SetType (protocolNumber); p->AddHeader (llc); + // + // This corresponds to the length interpretation of the lengthType + // field but with an LLC/SNAP header added to the payload as in + // IEEE 802.2 + // + lengthType = p->GetSize (); + // // All Ethernet frames must carry a minimum payload of 46 bytes. The // LLC SNAP header counts as part of this payload. We need to padd out @@ -335,12 +342,7 @@ CsmaNetDevice::AddHeader (Ptr p, Mac48Address source, Mac48Address de p->AddAtEnd (padd); } - // - // This corresponds to the length interpretation of the lengthType field, - // but with an LLC/SNAP header added to the payload as in IEEE 802.2 - // - lengthType = p->GetSize (); - NS_ASSERT_MSG (lengthType <= GetMtu (), + NS_ASSERT_MSG (p->GetSize () <= GetMtu (), "CsmaNetDevice::AddHeader(): 802.3 Length/Type field with LLC/SNAP: " "length interpretation must not exceed device frame size minus overhead"); } @@ -721,6 +723,14 @@ CsmaNetDevice::Receive (Ptr packet, Ptr senderDevice) // if (header.GetLengthType () <= 1500) { + NS_ASSERT (packet->GetSize () >= header.GetLengthType ()); + uint32_t padlen = packet->GetSize () - header.GetLengthType (); + NS_ASSERT (padlen <= 46); + if (padlen > 0) + { + packet->RemoveAtEnd (padlen); + } + LlcSnapHeader llc; packet->RemoveHeader (llc); protocol = llc.GetType ();