Skip to content

Commit 0c55cce

Browse files
committed
all: Fixed #932.
Changed the Gptp header lookup to use a packet dissector to avoid mishandling fragmented packets.
1 parent 0c8f9da commit 0c55cce

File tree

3 files changed

+34
-15
lines changed

3 files changed

+34
-15
lines changed

src/inet/common/packet/dissector/PacketDissector.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,14 @@ void PacketDissector::ChunkBuilder::visitChunk(const Ptr<const Chunk>& chunk, co
8383
}
8484
}
8585

86+
// ChunkFinder
87+
88+
void PacketDissector::ChunkFinder::visitChunk(const Ptr<const Chunk>& chunk, const Protocol *protocol)
89+
{
90+
if (this->protocol == protocol)
91+
this->chunk = chunk;
92+
}
93+
8694
// PduTreeBuilder
8795

8896
void PacketDissector::PduTreeBuilder::startProtocolDataUnit(const Protocol *protocol)

src/inet/common/packet/dissector/PacketDissector.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,23 @@ class INET_API PacketDissector
112112
virtual void visitChunk(const Ptr<const Chunk>& chunk, const Protocol *protocol) override;
113113
};
114114

115+
class INET_API ChunkFinder : public PacketDissector::ICallback {
116+
protected:
117+
const Protocol *protocol;
118+
Ptr<const Chunk> chunk;
119+
120+
public:
121+
ChunkFinder(const Protocol *protocol) : protocol(protocol) { }
122+
123+
const Ptr<const Chunk> getChunk() { return chunk; }
124+
125+
virtual bool shouldDissectProtocolDataUnit(const Protocol *protocol) override { return true; }
126+
virtual void startProtocolDataUnit(const Protocol *protocol) override {}
127+
virtual void endProtocolDataUnit(const Protocol *protocol) override {}
128+
virtual void markIncorrect() override {}
129+
virtual void visitChunk(const Ptr<const Chunk>& chunk, const Protocol *protocol) override;
130+
};
131+
115132
class INET_API PduTreeBuilder : public PacketDissector::ICallback {
116133
protected:
117134
bool isEndProtocolDataUnitCalled = false;

src/inet/linklayer/ieee8021as/Gptp.cc

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@
55
// University of Rostock, Germany
66
//
77

8-
#include "Gptp.h"
9-
10-
#include "GptpPacket_m.h"
8+
#include "inet/linklayer/ieee8021as/Gptp.h"
119

1210
#include "inet/clock/model/SettableClock.h"
13-
#include "inet/common/IProtocolRegistrationListener.h"
1411
#include "inet/common/clock/ClockUserModuleBase.h"
12+
#include "inet/common/IProtocolRegistrationListener.h"
13+
#include "inet/common/packet/dissector/PacketDissector.h"
1514
#include "inet/linklayer/common/InterfaceTag_m.h"
1615
#include "inet/linklayer/common/MacAddress.h"
1716
#include "inet/linklayer/common/MacAddressTag_m.h"
1817
#include "inet/linklayer/ethernet/common/Ethernet.h"
1918
#include "inet/linklayer/ethernet/common/EthernetMacHeader_m.h"
19+
#include "inet/linklayer/ieee8021as/GptpPacket_m.h"
2020
#include "inet/networklayer/common/NetworkInterface.h"
2121
#include "inet/physicallayer/wired/ethernet/EthernetPhyHeader_m.h"
2222

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

494494
const GptpBase *Gptp::extractGptpHeader(Packet *packet)
495495
{
496-
auto protocol = packet->getTag<PacketProtocolTag>()->getProtocol();
497-
if (*protocol != Protocol::ethernetPhy)
498-
return nullptr;
499-
500-
const auto& ethPhyHeader = packet->peekAtFront<physicallayer::EthernetPhyHeader>();
501-
const auto& ethMacHeader = packet->peekDataAt<EthernetMacHeader>(ethPhyHeader->getChunkLength());
502-
if (ethMacHeader->getTypeOrLength() != ETHERTYPE_GPTP)
503-
return nullptr;
504-
505-
b offset = ethPhyHeader->getChunkLength() + ethMacHeader->getChunkLength();
506-
return packet->peekDataAt<GptpBase>(offset).get();
496+
PacketDissector::ChunkFinder chunkFinder(&Protocol::gptp);
497+
PacketDissector packetDissector(ProtocolDissectorRegistry::getInstance(), chunkFinder);
498+
packetDissector.dissectPacket(packet);
499+
const auto& chunk = staticPtrCast<const GptpBase>(chunkFinder.getChunk());
500+
return chunk != nullptr ? chunk.get() : nullptr;
507501
}
508502

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

0 commit comments

Comments
 (0)