Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Packet++/header/TcpReassembly.h
Original file line number Diff line number Diff line change
Expand Up @@ -404,9 +404,11 @@ namespace pcpp
uint32_t sequence;
size_t dataLength;
uint8_t* data;
uint32_t flowKey;
bool isFin;
std::chrono::time_point<std::chrono::high_resolution_clock> timestamp;

TcpFragment() : sequence(0), dataLength(0), data(nullptr)
TcpFragment() : sequence(0), dataLength(0), data(nullptr), flowKey(0), isFin(false)
{}
~TcpFragment()
{
Expand Down
47 changes: 34 additions & 13 deletions Packet++/src/TcpReassembly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,10 @@ namespace pcpp
return Ignore_PacketOfClosedFlow;
}

// handle FIN/RST packets that don't contain additional TCP data
if (isFinOrRst && tcpPayloadSize == 0)
// handle RST packets that don't contain additional TCP data
if (isRst && tcpPayloadSize == 0)
{
PCPP_LOG_DEBUG("Got FIN or RST packet without data on side " << sideIndex);
PCPP_LOG_DEBUG("Got RST packet without data on side " << sideIndex);

handleFinOrRst(tcpReassemblyData, sideIndex, flowKey, isRst);
return FIN_RSTWithNoData;
Expand Down Expand Up @@ -441,27 +441,36 @@ namespace pcpp
{
PCPP_LOG_DEBUG("Payload length is 0, doing nothing");

// handle case where this packet is FIN or RST
if (isFinOrRst)
// handle case where this packet is RST
if (isRst)
{
handleFinOrRst(tcpReassemblyData, sideIndex, flowKey, isRst);
status = FIN_RSTWithNoData;
return status;
}
else

if(!isFin)
{
status = Ignore_PacketWithNoData;
}

return status;
return status;
}
}

// create a new TcpFragment, copy the TCP data to it and add this packet to the the out-of-order packet list
TcpFragment* newTcpFrag = new TcpFragment();
newTcpFrag->data = new uint8_t[tcpPayloadSize];

if(tcpPayloadSize)
{
newTcpFrag->data = new uint8_t[tcpPayloadSize];
memcpy(newTcpFrag->data, tcpLayer->getLayerPayload(), tcpPayloadSize);
}

newTcpFrag->dataLength = tcpPayloadSize;
newTcpFrag->sequence = sequence;
newTcpFrag->timestamp = currTime;
memcpy(newTcpFrag->data, tcpLayer->getLayerPayload(), tcpPayloadSize);
newTcpFrag->isFin = isFin;
newTcpFrag->flowKey = flowKey;

tcpReassemblyData->twoSides[sideIndex].tcpFragmentList.pushBack(newTcpFrag);

PCPP_LOG_DEBUG("Found out-of-order packet and added a new TCP fragment with size "
Expand All @@ -476,8 +485,8 @@ namespace pcpp
checkOutOfOrderFragments(tcpReassemblyData, sideIndex, false);
}

// handle case where this packet is FIN or RST
if (isFinOrRst)
// handle case where this packet is RST
if (isRst)
{
handleFinOrRst(tcpReassemblyData, sideIndex, flowKey, isRst);
}
Expand Down Expand Up @@ -580,6 +589,12 @@ namespace pcpp

foundSomething = true;

if(curTcpFrag->isFin)
{
PCPP_LOG_DEBUG("handle saved FIN flag on sequence match");
handleFinOrRst(tcpReassemblyData, sideIndex, curTcpFrag->flowKey, false);
}

continue;
}

Expand Down Expand Up @@ -616,6 +631,12 @@ namespace pcpp
}

foundSomething = true;

if(curTcpFrag->isFin)
{
PCPP_LOG_DEBUG("handle saved FIN flag on lower sequence");
handleFinOrRst(tcpReassemblyData, sideIndex, curTcpFrag->flowKey, false);
}
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions Tests/ExamplesTest/expected_output/x509_pcap_extract.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Packet count: 7451
TLS messages: 7229
TLS messages: 7216
TLS Flows: 334
TLS handshake messages: 1086
TLS handshake messages: 1085
Certificates parsed: 31
Certificates failed parsing: 0
Incomplete Certificates: 104
103 changes: 0 additions & 103 deletions Tests/Pcap++Test/PcapExamples/one_http_stream_fin2_output2.txt

This file was deleted.

4 changes: 2 additions & 2 deletions Tests/Pcap++Test/Tests/TcpReassemblyTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -721,13 +721,13 @@ PTF_TEST_CASE(TestTcpReassemblyWithFIN_RST)
tcpReassemblyTest(packetStream, tcpReassemblyResults, true, false);

PTF_ASSERT_EQUAL(stats.size(), 1);
PTF_ASSERT_EQUAL(stats.begin()->second.numOfDataPackets, 5);
PTF_ASSERT_EQUAL(stats.begin()->second.numOfDataPackets, 6);
PTF_ASSERT_EQUAL(stats.begin()->second.numOfMessagesFromSide[0], 1);
PTF_ASSERT_EQUAL(stats.begin()->second.numOfMessagesFromSide[1], 1);
PTF_ASSERT_TRUE(stats.begin()->second.connectionsStarted);
PTF_ASSERT_TRUE(stats.begin()->second.connectionsEnded);
PTF_ASSERT_FALSE(stats.begin()->second.connectionsEndedManually);
expectedReassemblyData = readFileIntoString(std::string("PcapExamples/one_http_stream_fin2_output2.txt"));
expectedReassemblyData = readFileIntoString(std::string("PcapExamples/one_http_stream_fin2_output.txt"));
PTF_ASSERT_EQUAL(expectedReassemblyData, stats.begin()->second.reassembledData);
} // TestTcpReassemblyWithFIN_RST

Expand Down