Skip to content

Commit

Permalink
Update RX sequence number after refusing TCP FIN packet.
Browse files Browse the repository at this point in the history
  • Loading branch information
ActoryOu committed Oct 3, 2024
1 parent 7c8f339 commit 520d713
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions source/FreeRTOS_TCP_State_Handling.c
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,8 @@
{
/* Peer is requesting to stop, see if we're really finished. */
xMayClose = pdTRUE;
ulIntermediateResult = ulSequenceNumber + ulReceiveLength - pxTCPWindow->rx.ulCurrentSequenceNumber;
lDistance = ( int32_t ) ulIntermediateResult;

/* Checks are only necessary if we haven't sent a FIN yet. */
if( pxSocket->u.xTCP.bits.bFinSent == pdFALSE_UNSIGNED )
Expand All @@ -601,22 +603,28 @@
( int ) bRxComplete,
( int ) bTxDone ) );
xMayClose = pdFALSE;
}
else
{
ulIntermediateResult = ulSequenceNumber + ulReceiveLength - pxTCPWindow->rx.ulCurrentSequenceNumber;
lDistance = ( int32_t ) ulIntermediateResult;

if( lDistance > 1 )
/* This action is necessary to ensure proper handling of any subsequent packets that
* may arrive after the refused FIN packet. Note that we only update it when the sequence
* of FIN packet is correct. Otherwise, we wait for re-transmission. */
if( lDistance == 1 )
{
FreeRTOS_debug_printf( ( "Refusing FIN: Rx not complete %d (cur %u high %u)\n",
( int ) lDistance,
( unsigned ) ( pxTCPWindow->rx.ulCurrentSequenceNumber - pxTCPWindow->rx.ulFirstSequenceNumber ),
( unsigned ) ( pxTCPWindow->rx.ulHighestSequenceNumber - pxTCPWindow->rx.ulFirstSequenceNumber ) ) );

xMayClose = pdFALSE;
pxTCPWindow->rx.ulCurrentSequenceNumber = pxTCPWindow->rx.ulFINSequenceNumber + 1U;
}
}
else if( lDistance > 1 )
{
FreeRTOS_debug_printf( ( "Refusing FIN: Rx not complete %d (cur %u high %u)\n",
( int ) lDistance,
( unsigned ) ( pxTCPWindow->rx.ulCurrentSequenceNumber - pxTCPWindow->rx.ulFirstSequenceNumber ),
( unsigned ) ( pxTCPWindow->rx.ulHighestSequenceNumber - pxTCPWindow->rx.ulFirstSequenceNumber ) ) );

xMayClose = pdFALSE;
}
else
{
/* Empty else marker. */
}
}

if( xTCPWindowLoggingLevel > 0 )
Expand Down

0 comments on commit 520d713

Please sign in to comment.