diff --git a/src/ethernetII.cpp b/src/ethernetII.cpp index 1cd731d..d14d172 100644 --- a/src/ethernetII.cpp +++ b/src/ethernetII.cpp @@ -44,6 +44,7 @@ #include "ethernetII.h" #include "packet_sender.h" #include "rawpdu.h" +#include "pppoe.h" #include "ip.h" #include "ipv6.h" #include "arp.h" @@ -152,9 +153,17 @@ bool EthernetII::matches_response(const uint8_t *ptr, uint32_t total_sz) const { void EthernetII::write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *parent) { OutputMemoryStream stream(buffer, total_sz); if (inner_pdu()) { - Constants::Ethernet::e flag = Internals::pdu_flag_to_ether_type( - inner_pdu()->pdu_type() - ); + Constants::Ethernet::e flag; + const PDUType type = inner_pdu()->pdu_type(); + // Dirty trick to sucessfully tag PPPoE session/discovery packets + if (type == PDU::PPPOE) { + const PPPoE* pppoe = static_cast(inner_pdu()); + flag = (pppoe->code() == 0) ? Constants::Ethernet::PPPOES + : Constants::Ethernet::PPPOED; + } + else { + flag = Internals::pdu_flag_to_ether_type(type); + } if (flag != Constants::Ethernet::UNKNOWN) { payload_type(static_cast(flag)); } @@ -188,4 +197,5 @@ PDU *EthernetII::recv_response(PacketSender &sender, const NetworkInterface &ifa #endif } #endif // _WIN32 -} + +} // Tins diff --git a/tests/src/pppoe.cpp b/tests/src/pppoe.cpp index 44efb65..53258b4 100644 --- a/tests/src/pppoe.cpp +++ b/tests/src/pppoe.cpp @@ -14,6 +14,7 @@ public: static const uint8_t expected_packet[]; static const uint8_t session_packet[]; static const uint8_t full_session_packet[]; + static const uint8_t full_session_packet2[]; }; const uint8_t PPPoETest::expected_packet[] = { @@ -33,6 +34,13 @@ const uint8_t PPPoETest::full_session_packet[] = { , 0, 0, 0, 0, 0, 0, 0 }; +const uint8_t PPPoETest::full_session_packet2[] = { + 255, 255, 255, 255, 255, 255, 0, 12, 41, 87, 232, 60, 136, 100, 17, + 0, 0, 0, 0, 50, 0, 87, 96, 0, 0, 0, 0, 8, 58, 1, 254, 128, 0, 0, 0, + 0, 0, 0, 2, 12, 41, 255, 254, 87, 232, 60, 255, 2, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 2, 151, 20, 88, 131, 0, 0, 0, 0 +}; + TEST_F(PPPoETest, DefaultConstructor) { PPPoE pdu; EXPECT_EQ(1, pdu.version()); @@ -69,6 +77,28 @@ TEST_F(PPPoETest, ConstructorFromFullSessionBuffer) { const RawPDU* raw = pdu.find_pdu(); ASSERT_TRUE(raw != NULL); EXPECT_EQ(21U, raw->payload_size()); + + PDU::serialization_type buffer = eth.serialize(); + EXPECT_EQ( + PDU::serialization_type( + full_session_packet, + full_session_packet + sizeof(full_session_packet) + ), + buffer + ); +} + +TEST_F(PPPoETest, ConstructorFromFullSessionBuffer2) { + EthernetII eth(full_session_packet2, sizeof(full_session_packet2)); + + PDU::serialization_type buffer = eth.serialize(); + EXPECT_EQ( + PDU::serialization_type( + full_session_packet2, + full_session_packet2 + sizeof(full_session_packet2) + ), + buffer + ); } TEST_F(PPPoETest, ConstructorFromBuffer) {