Skip to content

Commit 0037dba

Browse files
Fix adapter-backed PCAP writes through generic path
When protocol-specific capture adapters were enabled, protocolToLinkType() selected the adapter link type but the generic packet overload still used the legacy match-and-convert path. IEEE 802.11 therefore selected Radiotap, failed the link-type match, and aborted because no generic Radiotap converter exists. Delegate adapter-backed packet writes to the existing observation overload so the adapter creates complete prefixed records. Preserve the legacy matching and conversion behavior when either feature flag is disabled or no adapter is registered. Extend PcapRecorderIeee80211Ampdu_1 with a direct packet-overload regression that verifies the Radiotap header fields and exact payload suffix. This catches both the original abort and invalid prefix-less link-type-127 output. Validation: release and debug builds pass; the focused PcapRecorder regression passes. Both PcapRecorder tests also pass in the broader unit run, whose remaining failures match pre-existing unrelated failures.
1 parent 2cca845 commit 0037dba

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

src/inet/common/packet/recorder/PcapRecorder.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,11 @@ void PcapRecorder::writePacket(const Protocol *protocol, const PcapCaptureObserv
218218

219219
void PcapRecorder::writePacket(const Protocol *protocol, const Packet *packet, b frontOffset, b backOffset, Direction direction, NetworkInterface *networkInterface)
220220
{
221+
if (enableProtocolSpecificCaptureAdapters && enableConvertingPackets &&
222+
PcapCaptureAdapterRegistry::getInstance().findProtocolAdapter(protocol) != nullptr) {
223+
writePacket(protocol, PcapCaptureObservation(packet, direction), frontOffset, backOffset, networkInterface);
224+
return;
225+
}
221226

222227
auto pcapLinkType = protocolToLinkType(protocol);
223228
if (pcapLinkType == LINKTYPE_INVALID)

tests/unit/PcapRecorderIeee80211Ampdu_1.test

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,13 @@ class TestablePcapRecorder : public PcapRecorder
102102
enableConvertingPackets = true;
103103
writePacket(&Protocol::ieee80211Mac, PcapCaptureObservation(packet, direction), b(0), b(0), nullptr);
104104
}
105+
106+
void writeIeee80211Packet(const Packet *packet, Direction direction)
107+
{
108+
enableProtocolSpecificCaptureAdapters = true;
109+
enableConvertingPackets = true;
110+
writePacket(&Protocol::ieee80211Mac, packet, b(0), b(0), direction, nullptr);
111+
}
105112
};
106113

107114
Define_Module(TestablePcapRecorder);
@@ -167,6 +174,20 @@ REQUIRE(recorder->getIeee80211LinkType(true, true) == LINKTYPE_IEEE802_11_RADIOT
167174
auto writer = new RecordingPcapWriter();
168175
recorder->setWriter(writer);
169176

177+
const std::vector<uint8_t> packetBytes = {0x08, 0x41, 0x42, 0x43, 0x44};
178+
Packet packetOnly("packetOnly");
179+
packetOnly.insertAtBack(makeShared<BytesChunk>(packetBytes));
180+
recorder->writeIeee80211Packet(&packetOnly, DIRECTION_INBOUND);
181+
REQUIRE(writer->records.size() == 1);
182+
const auto& packetOnlyRecord = writer->records.front();
183+
REQUIRE(packetOnlyRecord.at(0) == 0); // Radiotap version
184+
REQUIRE(packetOnlyRecord.at(1) == 0); // Radiotap padding
185+
REQUIRE(readUint16(packetOnlyRecord, 2) == 12);
186+
REQUIRE(readUint32(packetOnlyRecord, 4) == ((1U << 1) | (1U << 14)));
187+
REQUIRE(packetOnlyRecord.size() == 12 + packetBytes.size());
188+
REQUIRE(std::equal(packetBytes.begin(), packetBytes.end(), packetOnlyRecord.begin() + 12));
189+
190+
writer->records.clear();
170191
const std::vector<uint8_t> firstMpdu = {0x08, 0x01, 0x02, 0x03, 0x04};
171192
const std::vector<uint8_t> secondMpdu = {0x88, 0x11, 0x12, 0x13, 0x14, 0x15};
172193
Packet aggregate("ampdu");

0 commit comments

Comments
 (0)