Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TCP reassembly - support closing connection with FIN + RST on one side #1496

Merged
merged 12 commits into from
Sep 25, 2024

Conversation

prudens
Copy link
Contributor

@prudens prudens commented Jul 12, 2024

Add check logic code to ensure that when the client sends both FIN and RST commands, the server can also immediately close, ensuring that the entire process is in a closed state.

PTF_ASSERT_TRUE(
readPcapIntoPacketVec("PcapExamples/one_tcp_stream_fin_rst_close_packet.pcap", packetStream, errMsg));

pcpp::RawPacket lastPacket = packetStream.back();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unused?


pcpp::RawPacket lastPacket = packetStream.back();

packetStream.pop_back();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you pop the last packet?


packetStream.pop_back();

for (auto iter : packetStream)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's declare tcpReassembly before this line.

Tests/Pcap++Test/Tests/TcpReassemblyTests.cpp Outdated Show resolved Hide resolved
@@ -227,6 +227,11 @@ TcpReassembly::ReassemblyStatus TcpReassembly::reassemblePacket(Packet& tcpData)
if (tcpReassemblyData->twoSides[sideIndex].gotFinOrRst)
{
PCPP_LOG_DEBUG("Got a packet after FIN or RST were already seen on this side (" << static_cast<int>(sideIndex) << "). Ignoring this packet");
if (!tcpReassemblyData->twoSides[1 - sideIndex].gotFinOrRst && isRst)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not very familiar with this piece of code, could you explain why it's 1 - sideIndex here?

Copy link
Contributor Author

@prudens prudens Jul 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1-sideIndex is mean other side tcp stream,the sideIndex's value maybe 0 or 1.

@@ -227,6 +227,11 @@ TcpReassembly::ReassemblyStatus TcpReassembly::reassemblePacket(Packet& tcpData)
if (tcpReassemblyData->twoSides[sideIndex].gotFinOrRst)
{
PCPP_LOG_DEBUG("Got a packet after FIN or RST were already seen on this side (" << static_cast<int>(sideIndex) << "). Ignoring this packet");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's move this debug log to after the if condition?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in this commit a1f3495

Comment on lines 1276 to 1278
pcpp::TcpReassemblyConfiguration config(true, 2, 1);
pcpp::TcpReassembly tcpReassembly(tcpReassemblyMsgReadyCallback, &results, tcpReassemblyConnectionStartCallback,
tcpReassemblyConnectionEndCallback, config);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a better approach would be to call tcpReassemblyTest(packetStream, tcpReassemblyResults, true, false) and check the results:

  • Verify there is only 1 connection
  • Verify that connectionsStarted == true, connectionsEnded == false, connectionsEndedManually == false
  • Verify that the number of packets from each side is what we expect

@seladb seladb changed the title Fixes Bug#1450 TCP reassembly - support closing connection with FIN + RST on one side Jul 19, 2024
@seladb
Copy link
Owner

seladb commented Jul 29, 2024

@prudens can you please address the review comments, and also resolve the conflicts in Tests/Pcap++Test/Tests/TcpReassemblyTests.cpp?

@seladb
Copy link
Owner

seladb commented Aug 14, 2024

@prudens we added clang-format so you need to run it on your code.
Here how to install clang-format:

python3 -m pip install cmake-format clang-format==18.1.6

python3 -m pip install cmake-format clang-format==18.1.6

Copy link

codecov bot commented Aug 15, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.87%. Comparing base (bd7884b) to head (1671b7d).
Report is 1 commits behind head on dev.

Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #1496      +/-   ##
==========================================
- Coverage   82.88%   82.87%   -0.02%     
==========================================
  Files         273      273              
  Lines       46205    46220      +15     
  Branches     9492     9533      +41     
==========================================
+ Hits        38299    38305       +6     
- Misses       7050     7057       +7     
- Partials      856      858       +2     
Flag Coverage Δ
fedora40 74.34% <80.00%> (-0.04%) ⬇️
macos-12 80.86% <93.33%> (+<0.01%) ⬆️
macos-13 80.28% <93.33%> (+<0.01%) ⬆️
macos-14 80.20% <93.33%> (+<0.01%) ⬆️
mingw32 70.20% <66.66%> (-0.03%) ⬇️
mingw64 70.17% <66.66%> (-0.03%) ⬇️
npcap 84.82% <100.00%> (-0.02%) ⬇️
rhel94 74.23% <80.00%> (+<0.01%) ⬆️
ubuntu2004 57.78% <66.66%> (+<0.01%) ⬆️
ubuntu2004-zstd 57.91% <66.66%> (+<0.01%) ⬆️
ubuntu2204 74.17% <80.00%> (-0.03%) ⬇️
ubuntu2204-icpx 58.33% <66.66%> (-0.01%) ⬇️
ubuntu2404 74.42% <80.00%> (-0.03%) ⬇️
unittest 82.87% <100.00%> (-0.02%) ⬇️
windows-2019 84.86% <100.00%> (-0.01%) ⬇️
windows-2022 84.85% <100.00%> (-0.02%) ⬇️
winpcap 84.83% <100.00%> (-0.01%) ⬇️
xdp 49.11% <0.00%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@seladb seladb merged commit c0e4de6 into seladb:dev Sep 25, 2024
40 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The TcpReassembly class does not correctly handle the logic for closing connections with TCP RST commands.
3 participants