mirror of
https://github.com/mfontanini/libtins
synced 2026-01-23 02:35:57 +01:00
Correctly serialize PPPoE session packets
This commit is contained in:
@@ -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<const PPPoE*>(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<uint16_t>(flag));
|
||||
}
|
||||
@@ -188,4 +197,5 @@ PDU *EthernetII::recv_response(PacketSender &sender, const NetworkInterface &ifa
|
||||
#endif
|
||||
}
|
||||
#endif // _WIN32
|
||||
}
|
||||
|
||||
} // Tins
|
||||
|
||||
@@ -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<RawPDU>();
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user