Skip to content

Commit

Permalink
Fix Dot1Q serialization for non-qinq packets (#319)
Browse files Browse the repository at this point in the history
  • Loading branch information
Saxon Parker authored and mfontanini committed Dec 1, 2018
1 parent 57ac099 commit 602ada7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/ethernetII.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ void EthernetII::write_serialization(uint8_t* buffer, uint32_t total_sz) {
}
// Dirty trick: Double Dot1Q is interpreted as Dot1AD
else if (type == PDU::DOT1Q) {
flag = Internals::pdu_flag_to_ether_type(type);

if (inner_pdu()->inner_pdu()) {
const PDUType inner_type = inner_pdu()->inner_pdu()->pdu_type();
if (inner_type == PDU::DOT1Q) {
Expand Down
11 changes: 11 additions & 0 deletions tests/src/dot1q_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,17 @@ TEST_F(Dot1QTest, Serialize) {
);
}

TEST_F(Dot1QTest, SerializeCraftedPacket)
{
EthernetII pkt = EthernetII() / Dot1Q(10) / IP("192.168.1.2") / TCP(23, 45) / RawPDU("asdasdasd");
PDU::serialization_type buffer = pkt.serialize();
EXPECT_EQ(buffer[12], 0x81);
EXPECT_EQ(buffer[13], 0x00);
EthernetII pkt2(&buffer[0], buffer.size());
const Dot1Q &q1 = pkt2.rfind_pdu<Dot1Q>();
EXPECT_EQ(10, q1.id());
}

TEST_F(Dot1QTest, PayloadType) {
Dot1Q dot1;
dot1.payload_type(0x9283);
Expand Down

0 comments on commit 602ada7

Please sign in to comment.