From 8dd510e50b842a485c37ee168b5690a8a66b83aa Mon Sep 17 00:00:00 2001 From: Hein Tibosch Date: Wed, 5 Oct 2022 15:03:38 +0800 Subject: [PATCH 1/8] IPv4/Single: Let send() stop after a protocol error --- source/FreeRTOS_Sockets.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/source/FreeRTOS_Sockets.c b/source/FreeRTOS_Sockets.c index 48579124e6..d53c9efa67 100644 --- a/source/FreeRTOS_Sockets.c +++ b/source/FreeRTOS_Sockets.c @@ -3794,8 +3794,16 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t * pxSocket ) ( void ) xEventGroupWaitBits( pxSocket->xEventGroup, ( EventBits_t ) eSOCKET_SEND | ( EventBits_t ) eSOCKET_CLOSED, pdTRUE /*xClearOnExit*/, pdFALSE /*xWaitAllBits*/, xRemainingTime ); + xByteCount = ( BaseType_t ) prvTCPSendCheck( pxSocket, uxDataLength ); + + if( xByteCount < 0 ) + { + /* In a meanwhile, the connection has dropped, stop iterating. */ + break; + } + xByteCount = ( BaseType_t ) uxStreamBufferGetSpace( pxSocket->u.xTCP.txStream ); - } + } /* while( ipTRUE_BOOL ) */ /* How much was actually sent? */ xByteCount = ( ( BaseType_t ) uxDataLength ) - xBytesLeft; From e2e34391848aea3628f086e50ce4222477d79ad2 Mon Sep 17 00:00:00 2001 From: Aniruddha Kanhere <60444055+AniruddhaKanhere@users.noreply.github.com> Date: Fri, 20 Jan 2023 14:37:49 -0800 Subject: [PATCH 2/8] Remove token need --- .github/workflows/uncrustify.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/uncrustify.yml b/.github/workflows/uncrustify.yml index 31ab98b57a..01bf905be4 100644 --- a/.github/workflows/uncrustify.yml +++ b/.github/workflows/uncrustify.yml @@ -31,7 +31,6 @@ jobs: - name: Checkout upstream repo uses: actions/checkout@v2 with: - token: ${{ secrets.PAT }} repository: ${{ steps.upstreamrepo.outputs.RemoteRepo }} ref: ${{ steps.upstreambranch.outputs.branchname }} - name: Install Uncrustify From 865bfa3dcca243b1d44776a820c54711e43522af Mon Sep 17 00:00:00 2001 From: Hein Tibosch Date: Sun, 2 Apr 2023 16:16:49 +0800 Subject: [PATCH 3/8] Repaired unit-testing --- .../FreeRTOS_Sockets/FreeRTOS_Sockets_TCP_API_utest.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/unit-test/FreeRTOS_Sockets/FreeRTOS_Sockets_TCP_API_utest.c b/test/unit-test/FreeRTOS_Sockets/FreeRTOS_Sockets_TCP_API_utest.c index 65c354681e..560335630f 100644 --- a/test/unit-test/FreeRTOS_Sockets/FreeRTOS_Sockets_TCP_API_utest.c +++ b/test/unit-test/FreeRTOS_Sockets/FreeRTOS_Sockets_TCP_API_utest.c @@ -984,6 +984,7 @@ void test_FreeRTOS_send_LessSpaceInStreamBuffer_Timeout( void ) xIsCallingFromIPTask_ExpectAndReturn( pdFALSE ); vTaskSetTimeOutState_ExpectAnyArgs(); xEventGroupWaitBits_ExpectAndReturn( xSocket.xEventGroup, eSOCKET_SEND | eSOCKET_CLOSED, pdTRUE, pdFALSE, 100, pdFALSE ); + listLIST_ITEM_CONTAINER_ExpectAnyArgsAndReturn( &xBoundTCPSocketsList ); /* Second Iteration. No space still. */ uxStreamBufferGetSpace_ExpectAndReturn( xSocket.u.xTCP.txStream, 0 ); @@ -1026,6 +1027,7 @@ void test_FreeRTOS_send_LessSpaceInStreamBuffer_EventuallySpaceAvailable( void ) xIsCallingFromIPTask_ExpectAndReturn( pdFALSE ); vTaskSetTimeOutState_ExpectAnyArgs(); xEventGroupWaitBits_ExpectAndReturn( xSocket.xEventGroup, eSOCKET_SEND | eSOCKET_CLOSED, pdTRUE, pdFALSE, 100, pdFALSE ); + listLIST_ITEM_CONTAINER_ExpectAnyArgsAndReturn( &xBoundTCPSocketsList ); /* Second Iteration. */ uxStreamBufferGetSpace_ExpectAndReturn( xSocket.u.xTCP.txStream, 20 ); @@ -1068,6 +1070,7 @@ void test_FreeRTOS_send_MultipleIterationsAndNoSuccess( void ) xIsCallingFromIPTask_ExpectAndReturn( pdFALSE ); vTaskSetTimeOutState_ExpectAnyArgs(); xEventGroupWaitBits_ExpectAndReturn( xSocket.xEventGroup, eSOCKET_SEND | eSOCKET_CLOSED, pdTRUE, pdFALSE, 100, pdFALSE ); + listLIST_ITEM_CONTAINER_ExpectAnyArgsAndReturn( &xBoundTCPSocketsList ); /* Second Iteration. */ uxStreamBufferGetSpace_ExpectAndReturn( xSocket.u.xTCP.txStream, 10 ); @@ -1078,6 +1081,7 @@ void test_FreeRTOS_send_MultipleIterationsAndNoSuccess( void ) xTaskCheckForTimeOut_ExpectAnyArgsAndReturn( pdFALSE ); xEventGroupWaitBits_ExpectAndReturn( xSocket.xEventGroup, eSOCKET_SEND | eSOCKET_CLOSED, pdTRUE, pdFALSE, 100, pdFALSE ); + listLIST_ITEM_CONTAINER_ExpectAnyArgsAndReturn( &xBoundTCPSocketsList ); /* Third iteration. No space still. */ uxStreamBufferGetSpace_ExpectAndReturn( xSocket.u.xTCP.txStream, 0 ); From 703958bf66216465619ece49b164e1257580d148 Mon Sep 17 00:00:00 2001 From: Hein Tibosch Date: Thu, 6 Apr 2023 11:31:30 +0800 Subject: [PATCH 4/8] Added the cunftion test_FreeRTOS_send_DisconnectionOccursDuringWait() --- .../FreeRTOS_Sockets_TCP_API_utest.c | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/test/unit-test/FreeRTOS_Sockets/FreeRTOS_Sockets_TCP_API_utest.c b/test/unit-test/FreeRTOS_Sockets/FreeRTOS_Sockets_TCP_API_utest.c index 560335630f..a2264dd662 100644 --- a/test/unit-test/FreeRTOS_Sockets/FreeRTOS_Sockets_TCP_API_utest.c +++ b/test/unit-test/FreeRTOS_Sockets/FreeRTOS_Sockets_TCP_API_utest.c @@ -1093,6 +1093,43 @@ void test_FreeRTOS_send_MultipleIterationsAndNoSuccess( void ) TEST_ASSERT_EQUAL( uxDataLength - 10, xReturn ); } +/* + * @brief While waiting for space, the socket gets disconnected. + */ +void test_FreeRTOS_send_DisconnectionOccursDuringWait( void ) +{ + BaseType_t xReturn; + FreeRTOS_Socket_t xSocket; + uint8_t pvBuffer[ ipconfigTCP_MSS ]; + size_t uxDataLength; + BaseType_t xFlags = 0; + StreamBuffer_t xLocalStreamBuffer; + + memset( &xSocket, 0, sizeof( xSocket ) ); + memset( pvBuffer, 0, ipconfigTCP_MSS ); + + xSocket.ucProtocol = FREERTOS_IPPROTO_TCP; + xSocket.u.xTCP.eTCPState = eESTABLISHED; + xSocket.u.xTCP.bits.bFinSent = pdFALSE_UNSIGNED; + xSocket.u.xTCP.txStream = &xLocalStreamBuffer; + xSocket.xSendBlockTime = 100; + + uxDataLength = 100; + listLIST_ITEM_CONTAINER_ExpectAnyArgsAndReturn( &xBoundTCPSocketsList ); + uxStreamBufferGetSpace_ExpectAndReturn( xSocket.u.xTCP.txStream, uxDataLength - 20 ); + uxStreamBufferAdd_ExpectAndReturn( xSocket.u.xTCP.txStream, 0U, pvBuffer, uxDataLength - 20, uxDataLength - 20 ); + xIsCallingFromIPTask_ExpectAndReturn( pdFALSE ); + xSendEventToIPTask_ExpectAndReturn( eTCPTimerEvent, pdFALSE ); + xIsCallingFromIPTask_ExpectAndReturn( pdFALSE ); + vTaskSetTimeOutState_ExpectAnyArgs(); + xEventGroupWaitBits_ExpectAndReturn( xSocket.xEventGroup, eSOCKET_SEND | eSOCKET_CLOSED, pdTRUE, pdFALSE, 100, pdFALSE ); + listLIST_ITEM_CONTAINER_ExpectAnyArgsAndReturn( NULL ); + + xReturn = FreeRTOS_send( &xSocket, pvBuffer, uxDataLength, xFlags ); + + TEST_ASSERT_EQUAL( uxDataLength - 20, xReturn ); +} + /* * @brief IP task is calling send function with a NULL buffer. Also there are 20 bytes worth of space * less in the stream buffer as the data length. From ab8745158b49435f624e8960c659ef0f55c65dcb Mon Sep 17 00:00:00 2001 From: Hein Tibosch Date: Thu, 6 Apr 2023 12:12:52 +0800 Subject: [PATCH 5/8] Added a comment for unit-test function test_FreeRTOS_send_DisconnectionOccursDuringWait() --- .../FreeRTOS_Sockets/FreeRTOS_Sockets_TCP_API_utest.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/unit-test/FreeRTOS_Sockets/FreeRTOS_Sockets_TCP_API_utest.c b/test/unit-test/FreeRTOS_Sockets/FreeRTOS_Sockets_TCP_API_utest.c index a2264dd662..8120234912 100644 --- a/test/unit-test/FreeRTOS_Sockets/FreeRTOS_Sockets_TCP_API_utest.c +++ b/test/unit-test/FreeRTOS_Sockets/FreeRTOS_Sockets_TCP_API_utest.c @@ -1123,6 +1123,9 @@ void test_FreeRTOS_send_DisconnectionOccursDuringWait( void ) xIsCallingFromIPTask_ExpectAndReturn( pdFALSE ); vTaskSetTimeOutState_ExpectAnyArgs(); xEventGroupWaitBits_ExpectAndReturn( xSocket.xEventGroup, eSOCKET_SEND | eSOCKET_CLOSED, pdTRUE, pdFALSE, 100, pdFALSE ); + + /* Let `socketSOCKET_IS_BOUND()` return false, so that prvTCPSendCheck() + * returns en error, so that the loop is stopped. */ listLIST_ITEM_CONTAINER_ExpectAnyArgsAndReturn( NULL ); xReturn = FreeRTOS_send( &xSocket, pvBuffer, uxDataLength, xFlags ); From f5fd5f59c08ccff11a186e190497c7c6dd98efd0 Mon Sep 17 00:00:00 2001 From: Hein Tibosch Date: Tue, 11 Apr 2023 21:03:34 +0800 Subject: [PATCH 6/8] Added an item to lexicon.txt --- .github/lexicon.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/lexicon.txt b/.github/lexicon.txt index 13e137c8a9..6b3eca5be7 100644 --- a/.github/lexicon.txt +++ b/.github/lexicon.txt @@ -720,6 +720,7 @@ prvtcpprepareconnect prvtcppreparesend prvtcpreturnpacket prvtcpsendchallengeack +prvtcpsendcheck prvtcpsendpacket prvtcpsendrepeated prvtcpsendreset From fbcd3ce4714fc30c246ec7d0d004ffb92d02ac23 Mon Sep 17 00:00:00 2001 From: Hein Tibosch Date: Wed, 12 Apr 2023 12:18:51 +0800 Subject: [PATCH 7/8] Restored original tcp_utilities --- .../tcp_utilities/include/tcp_dump_packets.h | 16 ++------- tools/tcp_utilities/include/tcp_mem_stats.h | 5 --- tools/tcp_utilities/include/tcp_netstat.h | 4 --- tools/tcp_utilities/tcp_dump_packets.c | 4 +-- tools/tcp_utilities/tcp_mem_stats.c | 33 ++++++++----------- tools/tcp_utilities/tcp_netstat.c | 5 ++- 6 files changed, 19 insertions(+), 48 deletions(-) diff --git a/tools/tcp_utilities/include/tcp_dump_packets.h b/tools/tcp_utilities/include/tcp_dump_packets.h index d68741507e..0f58a81dd8 100644 --- a/tools/tcp_utilities/include/tcp_dump_packets.h +++ b/tools/tcp_utilities/include/tcp_dump_packets.h @@ -25,11 +25,6 @@ * http://www.FreeRTOS.org */ -/* - * dump_packets.c - * Used in the PC/Win project to dump Ethernet packets, along with some description. - */ - #ifndef DUMP_PACKETS_H @@ -59,8 +54,7 @@ #define flag_FRAME_6 0x00020000UL #define flag_Unknown_FRAME 0x00040000UL -/** - * Structure to hold information about one dump entry. +/** @brief Structure to hold information about one dump entry. */ typedef struct xDumpEntry { @@ -69,19 +63,13 @@ typedef struct xDumpEntry size_t uxCount; /**< The count of the entry */ } DumpEntry_t; -/** - * Structure to hold information of all the entries in this data dump. - */ +/** @brief Structure to hold information of all the entries in this data dump. */ typedef struct xDumpEntries { size_t uxEntryCount; /**< The number of entries*/ DumpEntry_t xEntries[ dumpMAX_DUMP_ENTRIES ]; /**< Array of struct for all the entries */ } DumpEntries_t; -/* - * - */ - #if ( ipconfigUSE_DUMP_PACKETS != 0 ) extern void dump_packet_init( const char * pcFileName, diff --git a/tools/tcp_utilities/include/tcp_mem_stats.h b/tools/tcp_utilities/include/tcp_mem_stats.h index a84d64cc38..79a283f117 100644 --- a/tools/tcp_utilities/include/tcp_mem_stats.h +++ b/tools/tcp_utilities/include/tcp_mem_stats.h @@ -25,11 +25,6 @@ * http://www.FreeRTOS.org */ -/* - * tcp_mem_stats.h - */ - - #ifndef TCP_MEM_STATS_H #define TCP_MEM_STATS_H diff --git a/tools/tcp_utilities/include/tcp_netstat.h b/tools/tcp_utilities/include/tcp_netstat.h index 8797946461..85171543e7 100644 --- a/tools/tcp_utilities/include/tcp_netstat.h +++ b/tools/tcp_utilities/include/tcp_netstat.h @@ -25,10 +25,6 @@ * http://www.FreeRTOS.org */ -/* - * TCP_NETSTAT.c - * Some function to get a list of sockets and active port numbers. - */ #ifndef TCP_NETSTAT_H #define TCP_NETSTAT_H diff --git a/tools/tcp_utilities/tcp_dump_packets.c b/tools/tcp_utilities/tcp_dump_packets.c index cf4b014789..5819eec647 100644 --- a/tools/tcp_utilities/tcp_dump_packets.c +++ b/tools/tcp_utilities/tcp_dump_packets.c @@ -26,8 +26,8 @@ */ /* - * tcp_dump_packets.c - * Used in the PC/Win project to dump Ethernet packets, along with some description. + * @file tcp_dump_packets.c + * @brief Used in the PC/Win project to dump Ethernet packets, along with some description. * See tools/tcp_dump_packets.md for further description. */ diff --git a/tools/tcp_utilities/tcp_mem_stats.c b/tools/tcp_utilities/tcp_mem_stats.c index 7e1870f7fb..3ed5159637 100644 --- a/tools/tcp_utilities/tcp_mem_stats.c +++ b/tools/tcp_utilities/tcp_mem_stats.c @@ -26,8 +26,8 @@ */ /* - * tcp_mem_stats.c - * Used to create a CSV file with detailed information about the memory usage of FreeRTOS+TCP. + * @file tcp_mem_stats.c + * @brief To create a CSV file with detailed information about the memory usage of FreeRTOS+TCP. * See tools/tcp_mem_stats.md for further description. */ @@ -52,15 +52,8 @@ #if ( ipconfigUSE_TCP_MEM_STATS != 0 ) #ifndef ipconfigTCP_MEM_STATS_MAX_ALLOCATION - -/* Define the maximum number of objects ( memory allocations by - * the IP-stack ) that will be recorded. */ #define ipconfigTCP_MEM_STATS_MAX_ALLOCATION 128u - -/* If you don't want to see this pragma message, you can either - * remove it or define 'ipconfigTCP_MEM_STATS_MAX_ALLOCATION' in - * your freeRTOSIPConfig.h. */ - #pragma message ("ipconfigTCP_MEM_STATS_MAX_ALLOCATION undefined?") + #pragma warning "ipconfigTCP_MEM_STATS_MAX_ALLOCATION undefined?" #endif /* When a streambuffer is allocated, 4 extra bytes will be reserved. */ @@ -113,21 +106,21 @@ { /* Already added, strange. */ FreeRTOS_printf( ( "vAddAllocation: Pointer %p already added\n", pxObject ) ); - break; + return; } } - /* If the object has not been found, - * and if there is still space, add the object. */ - if( ( uxIndex == uxAllocationCount ) && - ( uxAllocationCount < ipconfigTCP_MEM_STATS_MAX_ALLOCATION ) ) + if( uxAllocationCount >= ipconfigTCP_MEM_STATS_MAX_ALLOCATION ) { - xAllocations[ uxIndex ].pxObject = pxObject; - xAllocations[ uxIndex ].xMemType = xMemType; - xAllocations[ uxIndex ].uxSize = uxSize; - xAllocations[ uxIndex ].uxNumber = uxNextObjectNumber++; - uxAllocationCount++; + /* The table is full. */ + return; } + + xAllocations[ uxIndex ].pxObject = pxObject; + xAllocations[ uxIndex ].xMemType = xMemType; + xAllocations[ uxIndex ].uxSize = uxSize; + xAllocations[ uxIndex ].uxNumber = uxNextObjectNumber++; + uxAllocationCount++; } xTaskResumeAll(); } diff --git a/tools/tcp_utilities/tcp_netstat.c b/tools/tcp_utilities/tcp_netstat.c index 602447f2a1..4de6790e30 100644 --- a/tools/tcp_utilities/tcp_netstat.c +++ b/tools/tcp_utilities/tcp_netstat.c @@ -48,8 +48,7 @@ extern List_t xBoundUDPSocketsList; extern List_t xBoundTCPSocketsList; #endif /* ipconfigUSE_TCP == 1 */ -IOCounters_t xInputCounters = { 0U }; -IOCounters_t xOutputCounters = { 0U }; +IOCounters_t xInputCounters, xOutputCounters; BaseType_t vGetMetrics( MetricsType_t * pxMetrics ) { @@ -103,7 +102,7 @@ BaseType_t vGetMetrics( MetricsType_t * pxMetrics ) size_t uxCount = pxMetrics->xTCPSocketList.uxCount; pxMetrics->xTCPSocketList.xTCPList[ uxCount ].usLocalPort = pxSocket->usLocalPort; - pxMetrics->xTCPSocketList.xTCPList[ uxCount ].ulRemoteIP = pxSocket->u.xTCP.ulRemoteIP; + pxMetrics->xTCPSocketList.xTCPList[ uxCount ].ulRemoteIP = pxSocket->u.xTCP.xRemoteIP.ulIP_IPv4; pxMetrics->xTCPSocketList.xTCPList[ uxCount ].usRemotePort = pxSocket->u.xTCP.usRemotePort; pxMetrics->xTCPSocketList.uxCount++; } From 543f56d1f386db9fe01635cac1b27fc43ffe74b8 Mon Sep 17 00:00:00 2001 From: Hein Tibosch Date: Wed, 12 Apr 2023 12:24:17 +0800 Subject: [PATCH 8/8] Restored original tcp_utilities, once more --- .../tcp_utilities/include/tcp_dump_packets.h | 16 +++++++-- tools/tcp_utilities/include/tcp_mem_stats.h | 5 +++ tools/tcp_utilities/include/tcp_netstat.h | 4 +++ tools/tcp_utilities/tcp_dump_packets.c | 4 +-- tools/tcp_utilities/tcp_mem_stats.c | 33 +++++++++++-------- tools/tcp_utilities/tcp_netstat.c | 5 +-- 6 files changed, 48 insertions(+), 19 deletions(-) diff --git a/tools/tcp_utilities/include/tcp_dump_packets.h b/tools/tcp_utilities/include/tcp_dump_packets.h index 0f58a81dd8..d68741507e 100644 --- a/tools/tcp_utilities/include/tcp_dump_packets.h +++ b/tools/tcp_utilities/include/tcp_dump_packets.h @@ -25,6 +25,11 @@ * http://www.FreeRTOS.org */ +/* + * dump_packets.c + * Used in the PC/Win project to dump Ethernet packets, along with some description. + */ + #ifndef DUMP_PACKETS_H @@ -54,7 +59,8 @@ #define flag_FRAME_6 0x00020000UL #define flag_Unknown_FRAME 0x00040000UL -/** @brief Structure to hold information about one dump entry. +/** + * Structure to hold information about one dump entry. */ typedef struct xDumpEntry { @@ -63,13 +69,19 @@ typedef struct xDumpEntry size_t uxCount; /**< The count of the entry */ } DumpEntry_t; -/** @brief Structure to hold information of all the entries in this data dump. */ +/** + * Structure to hold information of all the entries in this data dump. + */ typedef struct xDumpEntries { size_t uxEntryCount; /**< The number of entries*/ DumpEntry_t xEntries[ dumpMAX_DUMP_ENTRIES ]; /**< Array of struct for all the entries */ } DumpEntries_t; +/* + * + */ + #if ( ipconfigUSE_DUMP_PACKETS != 0 ) extern void dump_packet_init( const char * pcFileName, diff --git a/tools/tcp_utilities/include/tcp_mem_stats.h b/tools/tcp_utilities/include/tcp_mem_stats.h index 79a283f117..a84d64cc38 100644 --- a/tools/tcp_utilities/include/tcp_mem_stats.h +++ b/tools/tcp_utilities/include/tcp_mem_stats.h @@ -25,6 +25,11 @@ * http://www.FreeRTOS.org */ +/* + * tcp_mem_stats.h + */ + + #ifndef TCP_MEM_STATS_H #define TCP_MEM_STATS_H diff --git a/tools/tcp_utilities/include/tcp_netstat.h b/tools/tcp_utilities/include/tcp_netstat.h index 85171543e7..8797946461 100644 --- a/tools/tcp_utilities/include/tcp_netstat.h +++ b/tools/tcp_utilities/include/tcp_netstat.h @@ -25,6 +25,10 @@ * http://www.FreeRTOS.org */ +/* + * TCP_NETSTAT.c + * Some function to get a list of sockets and active port numbers. + */ #ifndef TCP_NETSTAT_H #define TCP_NETSTAT_H diff --git a/tools/tcp_utilities/tcp_dump_packets.c b/tools/tcp_utilities/tcp_dump_packets.c index 5819eec647..cf4b014789 100644 --- a/tools/tcp_utilities/tcp_dump_packets.c +++ b/tools/tcp_utilities/tcp_dump_packets.c @@ -26,8 +26,8 @@ */ /* - * @file tcp_dump_packets.c - * @brief Used in the PC/Win project to dump Ethernet packets, along with some description. + * tcp_dump_packets.c + * Used in the PC/Win project to dump Ethernet packets, along with some description. * See tools/tcp_dump_packets.md for further description. */ diff --git a/tools/tcp_utilities/tcp_mem_stats.c b/tools/tcp_utilities/tcp_mem_stats.c index 3ed5159637..7e1870f7fb 100644 --- a/tools/tcp_utilities/tcp_mem_stats.c +++ b/tools/tcp_utilities/tcp_mem_stats.c @@ -26,8 +26,8 @@ */ /* - * @file tcp_mem_stats.c - * @brief To create a CSV file with detailed information about the memory usage of FreeRTOS+TCP. + * tcp_mem_stats.c + * Used to create a CSV file with detailed information about the memory usage of FreeRTOS+TCP. * See tools/tcp_mem_stats.md for further description. */ @@ -52,8 +52,15 @@ #if ( ipconfigUSE_TCP_MEM_STATS != 0 ) #ifndef ipconfigTCP_MEM_STATS_MAX_ALLOCATION + +/* Define the maximum number of objects ( memory allocations by + * the IP-stack ) that will be recorded. */ #define ipconfigTCP_MEM_STATS_MAX_ALLOCATION 128u - #pragma warning "ipconfigTCP_MEM_STATS_MAX_ALLOCATION undefined?" + +/* If you don't want to see this pragma message, you can either + * remove it or define 'ipconfigTCP_MEM_STATS_MAX_ALLOCATION' in + * your freeRTOSIPConfig.h. */ + #pragma message ("ipconfigTCP_MEM_STATS_MAX_ALLOCATION undefined?") #endif /* When a streambuffer is allocated, 4 extra bytes will be reserved. */ @@ -106,21 +113,21 @@ { /* Already added, strange. */ FreeRTOS_printf( ( "vAddAllocation: Pointer %p already added\n", pxObject ) ); - return; + break; } } - if( uxAllocationCount >= ipconfigTCP_MEM_STATS_MAX_ALLOCATION ) + /* If the object has not been found, + * and if there is still space, add the object. */ + if( ( uxIndex == uxAllocationCount ) && + ( uxAllocationCount < ipconfigTCP_MEM_STATS_MAX_ALLOCATION ) ) { - /* The table is full. */ - return; + xAllocations[ uxIndex ].pxObject = pxObject; + xAllocations[ uxIndex ].xMemType = xMemType; + xAllocations[ uxIndex ].uxSize = uxSize; + xAllocations[ uxIndex ].uxNumber = uxNextObjectNumber++; + uxAllocationCount++; } - - xAllocations[ uxIndex ].pxObject = pxObject; - xAllocations[ uxIndex ].xMemType = xMemType; - xAllocations[ uxIndex ].uxSize = uxSize; - xAllocations[ uxIndex ].uxNumber = uxNextObjectNumber++; - uxAllocationCount++; } xTaskResumeAll(); } diff --git a/tools/tcp_utilities/tcp_netstat.c b/tools/tcp_utilities/tcp_netstat.c index 4de6790e30..602447f2a1 100644 --- a/tools/tcp_utilities/tcp_netstat.c +++ b/tools/tcp_utilities/tcp_netstat.c @@ -48,7 +48,8 @@ extern List_t xBoundUDPSocketsList; extern List_t xBoundTCPSocketsList; #endif /* ipconfigUSE_TCP == 1 */ -IOCounters_t xInputCounters, xOutputCounters; +IOCounters_t xInputCounters = { 0U }; +IOCounters_t xOutputCounters = { 0U }; BaseType_t vGetMetrics( MetricsType_t * pxMetrics ) { @@ -102,7 +103,7 @@ BaseType_t vGetMetrics( MetricsType_t * pxMetrics ) size_t uxCount = pxMetrics->xTCPSocketList.uxCount; pxMetrics->xTCPSocketList.xTCPList[ uxCount ].usLocalPort = pxSocket->usLocalPort; - pxMetrics->xTCPSocketList.xTCPList[ uxCount ].ulRemoteIP = pxSocket->u.xTCP.xRemoteIP.ulIP_IPv4; + pxMetrics->xTCPSocketList.xTCPList[ uxCount ].ulRemoteIP = pxSocket->u.xTCP.ulRemoteIP; pxMetrics->xTCPSocketList.xTCPList[ uxCount ].usRemotePort = pxSocket->u.xTCP.usRemotePort; pxMetrics->xTCPSocketList.uxCount++; }