Skip to content

Commit

Permalink
all: Fixed #932.
Browse files Browse the repository at this point in the history
Changed the Gptp header lookup to use a packet dissector to avoid mishandling fragmented packets.
  • Loading branch information
levy committed Dec 20, 2024
1 parent 0c8f9da commit 0c55cce
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 15 deletions.
8 changes: 8 additions & 0 deletions src/inet/common/packet/dissector/PacketDissector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ void PacketDissector::ChunkBuilder::visitChunk(const Ptr<const Chunk>& chunk, co
}
}

// ChunkFinder

void PacketDissector::ChunkFinder::visitChunk(const Ptr<const Chunk>& chunk, const Protocol *protocol)
{
if (this->protocol == protocol)
this->chunk = chunk;
}

// PduTreeBuilder

void PacketDissector::PduTreeBuilder::startProtocolDataUnit(const Protocol *protocol)
Expand Down
17 changes: 17 additions & 0 deletions src/inet/common/packet/dissector/PacketDissector.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,23 @@ class INET_API PacketDissector
virtual void visitChunk(const Ptr<const Chunk>& chunk, const Protocol *protocol) override;
};

class INET_API ChunkFinder : public PacketDissector::ICallback {
protected:
const Protocol *protocol;
Ptr<const Chunk> chunk;

public:
ChunkFinder(const Protocol *protocol) : protocol(protocol) { }

const Ptr<const Chunk> getChunk() { return chunk; }

virtual bool shouldDissectProtocolDataUnit(const Protocol *protocol) override { return true; }
virtual void startProtocolDataUnit(const Protocol *protocol) override {}
virtual void endProtocolDataUnit(const Protocol *protocol) override {}
virtual void markIncorrect() override {}
virtual void visitChunk(const Ptr<const Chunk>& chunk, const Protocol *protocol) override;
};

class INET_API PduTreeBuilder : public PacketDissector::ICallback {
protected:
bool isEndProtocolDataUnitCalled = false;
Expand Down
24 changes: 9 additions & 15 deletions src/inet/linklayer/ieee8021as/Gptp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
// University of Rostock, Germany
//

#include "Gptp.h"

#include "GptpPacket_m.h"
#include "inet/linklayer/ieee8021as/Gptp.h"

#include "inet/clock/model/SettableClock.h"
#include "inet/common/IProtocolRegistrationListener.h"
#include "inet/common/clock/ClockUserModuleBase.h"
#include "inet/common/IProtocolRegistrationListener.h"
#include "inet/common/packet/dissector/PacketDissector.h"
#include "inet/linklayer/common/InterfaceTag_m.h"
#include "inet/linklayer/common/MacAddress.h"
#include "inet/linklayer/common/MacAddressTag_m.h"
#include "inet/linklayer/ethernet/common/Ethernet.h"
#include "inet/linklayer/ethernet/common/EthernetMacHeader_m.h"
#include "inet/linklayer/ieee8021as/GptpPacket_m.h"
#include "inet/networklayer/common/NetworkInterface.h"
#include "inet/physicallayer/wired/ethernet/EthernetPhyHeader_m.h"

Expand Down Expand Up @@ -493,17 +493,11 @@ void Gptp::processPdelayRespFollowUp(Packet *packet, const GptpPdelayRespFollowU

const GptpBase *Gptp::extractGptpHeader(Packet *packet)
{
auto protocol = packet->getTag<PacketProtocolTag>()->getProtocol();
if (*protocol != Protocol::ethernetPhy)
return nullptr;

const auto& ethPhyHeader = packet->peekAtFront<physicallayer::EthernetPhyHeader>();
const auto& ethMacHeader = packet->peekDataAt<EthernetMacHeader>(ethPhyHeader->getChunkLength());
if (ethMacHeader->getTypeOrLength() != ETHERTYPE_GPTP)
return nullptr;

b offset = ethPhyHeader->getChunkLength() + ethMacHeader->getChunkLength();
return packet->peekDataAt<GptpBase>(offset).get();
PacketDissector::ChunkFinder chunkFinder(&Protocol::gptp);
PacketDissector packetDissector(ProtocolDissectorRegistry::getInstance(), chunkFinder);
packetDissector.dissectPacket(packet);
const auto& chunk = staticPtrCast<const GptpBase>(chunkFinder.getChunk());
return chunk != nullptr ? chunk.get() : nullptr;
}

void Gptp::receiveSignal(cComponent *source, simsignal_t simSignal, cObject *obj, cObject *details)
Expand Down

0 comments on commit 0c55cce

Please sign in to comment.