diff --git a/include/llc.h b/include/llc.h index 557cbc5..4297460 100644 --- a/include/llc.h +++ b/include/llc.h @@ -376,7 +376,6 @@ namespace Tins { typedef std::vector field_type; - void copy_fields(const LLC *other); void write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *parent); llchdr _header; diff --git a/include/tins.h b/include/tins.h index b52384e..d5755e6 100644 --- a/include/tins.h +++ b/include/tins.h @@ -66,5 +66,6 @@ #include "sll.h" #include "dhcpv6.h" #include "pppoe.h" +#include "stp.h" #endif // TINS_TINS_H diff --git a/src/llc.cpp b/src/llc.cpp index 0f7562a..c3e56bc 100644 --- a/src/llc.cpp +++ b/src/llc.cpp @@ -30,9 +30,8 @@ #include #include #include - -#include "pdu.h" #include "llc.h" +#include "stp.h" #include "rawpdu.h" using std::list; @@ -86,8 +85,12 @@ LLC::LLC(const uint8_t *buffer, uint32_t total_sz) { buffer += 2; total_sz -= 2; } - if(total_sz > 0) - inner_pdu(new Tins::RawPDU(buffer, total_sz)); + if(total_sz > 0) { + if(dsap() == 0x42 && ssap() == 0x42) + inner_pdu(new Tins::STP(buffer, total_sz)); + else + inner_pdu(new Tins::RawPDU(buffer, total_sz)); + } } void LLC::group(bool value) { @@ -201,6 +204,10 @@ void LLC::clear_information_fields() { void LLC::write_serialization(uint8_t *buffer, uint32_t total_sz, const Tins::PDU *parent) { assert(total_sz >= header_size()); + if(inner_pdu() && inner_pdu()->pdu_type() == PDU::STP) { + dsap(0x42); + ssap(0x42); + } std::memcpy(buffer, &_header, sizeof(_header)); buffer += sizeof(_header); switch (type()) { @@ -219,7 +226,6 @@ void LLC::write_serialization(uint8_t *buffer, uint32_t total_sz, const Tins::PD } for (list::const_iterator it = information_fields.begin(); it != information_fields.end(); it++) { - //std::memcpy(buffer, it->second, it->first); std::copy(it->begin(), it->end(), buffer); buffer += it->size(); } diff --git a/src/stp.cpp b/src/stp.cpp index cf0d166..2612718 100644 --- a/src/stp.cpp +++ b/src/stp.cpp @@ -28,6 +28,7 @@ */ #include +#include #include "stp.h" namespace Tins { @@ -86,7 +87,10 @@ void STP::fwd_delay(uint16_t new_fwd_delay) { } void STP::write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *) { - + #ifdef TINS_DEBUG + assert(total_sz >= sizeof(_header)); + #endif + std::memcpy(buffer, &_header, sizeof(_header)); } uint32_t STP::header_size() const { diff --git a/tests/src/stp.cpp b/tests/src/stp.cpp index c7da0ea..d9ed7d1 100644 --- a/tests/src/stp.cpp +++ b/tests/src/stp.cpp @@ -3,6 +3,8 @@ #include #include #include "stp.h" +#include "dot3.h" +#include "llc.h" using namespace std; using namespace Tins; @@ -15,7 +17,7 @@ public: const uint8_t STPTest::expected_packet[] = { 146, 131, 138, 146, 146, 128, 0, 0, 144, 76, 8, 23, 181, 0, 146, 131, 120, 128, 0, 0, 144, 76, 8, 23, 181, 128, 1, 15, 0, 20, 0, 2, 0, 0, - 0, 165, 165, 165, 165, 165, 165, 165, 165 + 0 }; TEST_F(STPTest, DefaultConstructor) { @@ -48,6 +50,37 @@ TEST_F(STPTest, ConstructorFromBuffer) { EXPECT_EQ(0, pdu.fwd_delay()); } +TEST_F(STPTest, ChainedPDUs) { + const uint8_t input[] = { + 1, 128, 194, 0, 0, 0, 0, 144, 76, 8, 23, 181, 0, 38, 66, 66, 3, + 0, 0, 0, 0, 0, 128, 0, 0, 144, 76, 8, 23, 181, 0, 0, 0, 0, 128, + 0, 0, 144, 76, 8, 23, 181, 128, 1, 0, 0, 20, 0, 2, 0, 0, 0 + }; + Dot3 pkt(input, sizeof(input)); + STP *stp = pkt.find_pdu(); + LLC *llc = pkt.find_pdu(); + ASSERT_TRUE(stp); + ASSERT_TRUE(llc); + EXPECT_EQ(0x8001, stp->port_id()); + EXPECT_EQ(0, stp->msg_age()); + EXPECT_EQ(20, stp->max_age()); + EXPECT_EQ(2, stp->hello_time()); + llc->dsap(0); + llc->ssap(0); + EXPECT_EQ( + PDU::serialization_type(input, input + sizeof(input)), + pkt.serialize() + ); +} + +TEST_F(STPTest, Serialize) { + STP pdu(expected_packet, sizeof(expected_packet)); + EXPECT_EQ( + PDU::serialization_type(expected_packet, expected_packet + sizeof(expected_packet)), + pdu.serialize() + ); +} + TEST_F(STPTest, ProtoID) { STP pdu; pdu.proto_id(0x9283);