Skip to content

Commit 0e657d7

Browse files
authored
Fix #2109: Recognize LLC payload in SLL2. (#2111)
* Add LLC parsing to SLL2. * Replace hardcoded protocol type value. * Update docs. * Add small test for LLC parse. * Fix typo. * Change enum to constexpr value. * Cleanup unused includes.
1 parent fe0124f commit 0e657d7

6 files changed

Lines changed: 29 additions & 0 deletions

File tree

Packet++/src/Sll2Layer.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,17 @@
99
#include "VlanLayer.h"
1010
#include "PPPoELayer.h"
1111
#include "MplsLayer.h"
12+
#include "LLCLayer.h"
1213
#include "EndianPortable.h"
1314

1415
namespace pcpp
1516
{
17+
namespace
18+
{
19+
/// @brief Exclusive Sll2 value indicating 802.2 LLC header payload.
20+
constexpr uint16_t Sll2ProtoTypeLLC = 0x0004;
21+
} // namespace
22+
1623
Sll2Layer::Sll2Layer(uint32_t interfaceIndex, uint16_t ARPHRDType, uint8_t packetType)
1724
{
1825
const size_t headerLen = sizeof(sll2_header);
@@ -103,6 +110,11 @@ namespace pcpp
103110
constructNextLayer<MplsLayer>(payload, payloadLen);
104111
break;
105112
}
113+
case Sll2ProtoTypeLLC:
114+
{
115+
tryConstructNextLayerWithFallback<LLCLayer, PayloadLayer>(payload, payloadLen);
116+
break;
117+
}
106118
default:
107119
{
108120
constructNextLayer<PayloadLayer>(payload, payloadLen);
@@ -131,6 +143,9 @@ namespace pcpp
131143
case VLAN:
132144
hdr->protocol_type = htobe16(PCPP_ETHERTYPE_VLAN);
133145
break;
146+
case LLC:
147+
hdr->protocol_type = htobe16(Sll2ProtoTypeLLC);
148+
break;
134149
default:
135150
return;
136151
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
000400000000000300010206e01cfcd3b1e10000424203000002023e80004c5e0c3ec6dd00004e388000e01cfcd3b1df80020300140002000f000020202020202020
106 Bytes
Binary file not shown.

Tests/Packet++Test/TestDefinition.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ PTF_TEST_CASE(NullLoopbackTest);
140140

141141
// Implemented in Sll2Tests.cpp
142142
PTF_TEST_CASE(Sll2PacketParsingTest);
143+
PTF_TEST_CASE(Sll2ParseLLCTest);
143144
PTF_TEST_CASE(Sll2PacketCreationTest);
144145

145146
// Implemented in NflogTests.cpp

Tests/Packet++Test/Tests/Sll2Tests.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,17 @@ PTF_TEST_CASE(Sll2PacketParsingTest)
4242
PTF_ASSERT_EQUAL(macAddrRef, sll2Layer->getLinkLayerAsMacAddress());
4343
} // Sll2PacketParsingTest
4444

45+
PTF_TEST_CASE(Sll2ParseLLCTest)
46+
{
47+
pcpp_tests::utils::PacketFactory ssl2Factory(pcpp::LINKTYPE_LINUX_SLL2);
48+
auto rawPacket1 = createPacketFromHexResource("PacketExamples/Sll2PacketLLC.dat", ssl2Factory);
49+
50+
pcpp::Packet sll2Packet(rawPacket1.get());
51+
52+
PTF_ASSERT_TRUE(sll2Packet.isPacketOfType(pcpp::SLL2));
53+
PTF_ASSERT_TRUE(sll2Packet.isPacketOfType(pcpp::LLC));
54+
}
55+
4556
PTF_TEST_CASE(Sll2PacketCreationTest)
4657
{
4758
pcpp::Sll2Layer sll2Layer(20, 1, 4);

Tests/Packet++Test/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ int main(int argc, char* argv[])
265265
PTF_RUN_TEST(NullLoopbackTest, "null_loopback");
266266

267267
PTF_RUN_TEST(Sll2PacketParsingTest, "sll2");
268+
PTF_RUN_TEST(Sll2ParseLLCTest, "sll2");
268269
PTF_RUN_TEST(Sll2PacketCreationTest, "sll2");
269270

270271
PTF_RUN_TEST(NflogPacketParsingTest, "nflog");

0 commit comments

Comments
 (0)