Skip to content

Commit 520d713

Browse files
committed
Update RX sequence number after refusing TCP FIN packet.
1 parent 7c8f339 commit 520d713

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

source/FreeRTOS_TCP_State_Handling.c

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,8 @@
584584
{
585585
/* Peer is requesting to stop, see if we're really finished. */
586586
xMayClose = pdTRUE;
587+
ulIntermediateResult = ulSequenceNumber + ulReceiveLength - pxTCPWindow->rx.ulCurrentSequenceNumber;
588+
lDistance = ( int32_t ) ulIntermediateResult;
587589

588590
/* Checks are only necessary if we haven't sent a FIN yet. */
589591
if( pxSocket->u.xTCP.bits.bFinSent == pdFALSE_UNSIGNED )
@@ -601,22 +603,28 @@
601603
( int ) bRxComplete,
602604
( int ) bTxDone ) );
603605
xMayClose = pdFALSE;
604-
}
605-
else
606-
{
607-
ulIntermediateResult = ulSequenceNumber + ulReceiveLength - pxTCPWindow->rx.ulCurrentSequenceNumber;
608-
lDistance = ( int32_t ) ulIntermediateResult;
609606

610-
if( lDistance > 1 )
607+
/* This action is necessary to ensure proper handling of any subsequent packets that
608+
* may arrive after the refused FIN packet. Note that we only update it when the sequence
609+
* of FIN packet is correct. Otherwise, we wait for re-transmission. */
610+
if( lDistance == 1 )
611611
{
612-
FreeRTOS_debug_printf( ( "Refusing FIN: Rx not complete %d (cur %u high %u)\n",
613-
( int ) lDistance,
614-
( unsigned ) ( pxTCPWindow->rx.ulCurrentSequenceNumber - pxTCPWindow->rx.ulFirstSequenceNumber ),
615-
( unsigned ) ( pxTCPWindow->rx.ulHighestSequenceNumber - pxTCPWindow->rx.ulFirstSequenceNumber ) ) );
616-
617-
xMayClose = pdFALSE;
612+
pxTCPWindow->rx.ulCurrentSequenceNumber = pxTCPWindow->rx.ulFINSequenceNumber + 1U;
618613
}
619614
}
615+
else if( lDistance > 1 )
616+
{
617+
FreeRTOS_debug_printf( ( "Refusing FIN: Rx not complete %d (cur %u high %u)\n",
618+
( int ) lDistance,
619+
( unsigned ) ( pxTCPWindow->rx.ulCurrentSequenceNumber - pxTCPWindow->rx.ulFirstSequenceNumber ),
620+
( unsigned ) ( pxTCPWindow->rx.ulHighestSequenceNumber - pxTCPWindow->rx.ulFirstSequenceNumber ) ) );
621+
622+
xMayClose = pdFALSE;
623+
}
624+
else
625+
{
626+
/* Empty else marker. */
627+
}
620628
}
621629

622630
if( xTCPWindowLoggingLevel > 0 )

0 commit comments

Comments
 (0)