Skip to content

Commit

Permalink
internet: Fix tcp flags check to determine packet type
Browse files Browse the repository at this point in the history
(TcpHeader::ACK | TcpHeader::ECE) was not correctly tested, resulting in an uninitialized packetType value
  • Loading branch information
Gabrielcarvfer committed Oct 6, 2024
1 parent cc1a148 commit 4e642e5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
29 changes: 14 additions & 15 deletions src/internet/model/tcp-socket-base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2789,7 +2789,7 @@ TcpSocketBase::SendEmptyPacket(uint8_t flags)
Ptr<Packet> p = Create<Packet>();
TcpHeader header;
SequenceNumber32 s = m_tcb->m_nextTxSequence;
TcpPacketType_t packetType;
TcpPacketType_t packetType = INVALID;
if (flags & TcpHeader::FIN)
{
Expand All @@ -2801,26 +2801,25 @@ TcpSocketBase::SendEmptyPacket(uint8_t flags)
++s;
}
if (flags == TcpHeader::ACK)
{
packetType = TcpPacketType_t::PURE_ACK;
}
else if (flags == TcpHeader::RST)
{
packetType = TcpPacketType_t::RST;
}
else if (flags & TcpHeader::SYN)
if (flags & TcpHeader::SYN)
{
packetType = TcpPacketType_t::SYN;
if (flags & TcpHeader::ACK)
{
packetType = TcpPacketType_t::SYN_ACK;
}
else
{
packetType = TcpPacketType_t::SYN;
}
}
else if (flags & TcpHeader::ACK)
{
packetType = TcpPacketType_t::PURE_ACK;
}
if (flags & TcpHeader::RST)
{
packetType = TcpPacketType_t::RST;
}
NS_ASSERT_MSG(packetType != TcpPacketType_t::INVALID, "Invalid TCP packet type");
AddSocketTags(p, IsEct(packetType));
header.SetFlags(flags);
Expand Down Expand Up @@ -4791,7 +4790,7 @@ bool
TcpSocketBase::IsEct(TcpPacketType_t packetType) const
{
NS_LOG_FUNCTION(this << packetType);

NS_ASSERT_MSG(packetType != TcpPacketType_t::INVALID, "Invalid TCP packet type");
if (m_tcb->m_ecnState == TcpSocketState::ECN_DISABLED)
{
return false;
Expand Down
3 changes: 2 additions & 1 deletion src/internet/model/tcp-socket-base.h
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,8 @@ class TcpSocketBase : public TcpSocket
FIN,
RST,
RE_XMT,
DATA
DATA,
INVALID
};

// Set associated Node, TcpL4Protocol, RttEstimator to this socket
Expand Down

0 comments on commit 4e642e5

Please sign in to comment.