From 875bfd2d88ba4db64d7055aa5f8580f6db31dcdc Mon Sep 17 00:00:00 2001 From: Rahul Kar <118818625+kar-rahul-aws@users.noreply.github.com> Date: Thu, 26 Sep 2024 09:21:16 +0530 Subject: [PATCH 1/2] Fix missing parameters error in ATSAM4E (#1192) * Fix Missing parameters error in ATSAM4E --- .../NetworkInterface/ATSAM4E/NetworkInterface.c | 10 ++++++---- source/portable/NetworkInterface/ATSAM4E/gmac.c | 5 +++-- .../NetworkInterface/DriverSAM/NetworkInterface.c | 2 +- source/portable/NetworkInterface/DriverSAM/gmac_SAM.h | 2 +- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/source/portable/NetworkInterface/ATSAM4E/NetworkInterface.c b/source/portable/NetworkInterface/ATSAM4E/NetworkInterface.c index 48a7b5bab..96ee3c48f 100644 --- a/source/portable/NetworkInterface/ATSAM4E/NetworkInterface.c +++ b/source/portable/NetworkInterface/ATSAM4E/NetworkInterface.c @@ -88,7 +88,8 @@ static BaseType_t xGMACWaitLS( TickType_t xMaxTime ); #if ( ipconfigDRIVER_INCLUDED_TX_IP_CHECKSUM == 1 ) && ( ipconfigHAS_TX_CRC_OFFLOADING == 0 ) - void vGMACGenerateChecksum( uint8_t * apBuffer ); + void vGMACGenerateChecksum( uint8_t * pucBuffer, + size_t uxLength ); #endif /* @@ -405,9 +406,10 @@ static BaseType_t xGMACWaitLS( TickType_t xMaxTime ) /*#if( ipconfigDRIVER_INCLUDED_TX_IP_CHECKSUM == 1 ) && ( ipconfigHAS_TX_CRC_OFFLOADING == 0 ) */ -void vGMACGenerateChecksum( uint8_t * apBuffer ) +void vGMACGenerateChecksum( uint8_t * pucBuffer, + size_t uxLength ) { - ProtocolPacket_t * xProtPacket = ( ProtocolPacket_t * ) apBuffer; + ProtocolPacket_t * xProtPacket = ( ProtocolPacket_t * ) pucBuffer; if( xProtPacket->xTCPPacket.xEthernetHeader.usFrameType == ipIPv4_FRAME_TYPE ) { @@ -419,7 +421,7 @@ void vGMACGenerateChecksum( uint8_t * apBuffer ) pxIPHeader->usHeaderChecksum = ~FreeRTOS_htons( pxIPHeader->usHeaderChecksum ); /* Calculate the TCP checksum for an outgoing packet. */ - usGenerateProtocolChecksum( ( uint8_t * ) apBuffer, pdTRUE ); + usGenerateProtocolChecksum( ( uint8_t * ) pucBuffer, uxLength, pdTRUE ); } } diff --git a/source/portable/NetworkInterface/ATSAM4E/gmac.c b/source/portable/NetworkInterface/ATSAM4E/gmac.c index 7322ec5a0..b79c16248 100644 --- a/source/portable/NetworkInterface/ATSAM4E/gmac.c +++ b/source/portable/NetworkInterface/ATSAM4E/gmac.c @@ -642,7 +642,8 @@ uint32_t gmac_dev_read( gmac_device_t * p_gmac_dev, } -extern void vGMACGenerateChecksum( uint8_t * apBuffer ); +extern void vGMACGenerateChecksum( uint8_t * pucBuffer, + size_t uxLength ); /** * \brief Send ulLength bytes from pcFrom. This copies the buffer to one of the @@ -715,7 +716,7 @@ uint32_t gmac_dev_write( gmac_device_t * p_gmac_dev, memcpy( ( void * ) p_tx_td->addr, p_buffer, ul_size ); } #endif /* ipconfigZERO_COPY_TX_DRIVER */ - vGMACGenerateChecksum( ( uint8_t * ) p_tx_td->addr ); + vGMACGenerateChecksum( ( uint8_t * ) p_tx_td->addr, ( size_t ) ul_size ); } #if ( GMAC_USES_TX_CALLBACK != 0 ) diff --git a/source/portable/NetworkInterface/DriverSAM/NetworkInterface.c b/source/portable/NetworkInterface/DriverSAM/NetworkInterface.c index 88679b7a7..8a837dd35 100644 --- a/source/portable/NetworkInterface/DriverSAM/NetworkInterface.c +++ b/source/portable/NetworkInterface/DriverSAM/NetworkInterface.c @@ -161,7 +161,7 @@ static BaseType_t xPHY_Write( BaseType_t xAddress, uint32_t ulValue ); #if ( ipconfigDRIVER_INCLUDED_TX_IP_CHECKSUM == 1 ) && ( ipconfigHAS_TX_CRC_OFFLOADING == 0 ) - void vGMACGenerateChecksum( uint8_t * apBuffer, + void vGMACGenerateChecksum( uint8_t * pucBuffer, size_t uxLength ); #endif diff --git a/source/portable/NetworkInterface/DriverSAM/gmac_SAM.h b/source/portable/NetworkInterface/DriverSAM/gmac_SAM.h index 0f6a3e9ca..abe420607 100644 --- a/source/portable/NetworkInterface/DriverSAM/gmac_SAM.h +++ b/source/portable/NetworkInterface/DriverSAM/gmac_SAM.h @@ -1539,7 +1539,7 @@ /* The SAM4E has problems offloading checksums for transmission. * The SAME70 does not set the CRC for ICMP packets (ping). */ - extern void vGMACGenerateChecksum( uint8_t * apBuffer, + extern void vGMACGenerateChecksum( uint8_t * pucBuffer, size_t uxLength ); /*/ @cond 0 */ From fa073ea3413205efc103f46b26217e2a2a6436c9 Mon Sep 17 00:00:00 2001 From: AlfaSegato <48479067+AlfaSegato@users.noreply.github.com> Date: Mon, 30 Sep 2024 07:58:50 +0200 Subject: [PATCH 2/2] do not let through unicast packets on inactive endpoints (#1186) * do not let through unicast packets on inactive endpoints * Modified test_FreeRTOS_FindEndPointOnIP_IPv4_ZeroAddressEndpoint() * Fix unit tests * Fix link verification check --------- Co-authored-by: Tony Josi --- source/FreeRTOS_IPv4.c | 4 +--- source/FreeRTOS_Routing.c | 1 - .../NetworkInterface/RX/NetworkInterface.c | 2 +- .../NetworkInterface/RX/ether_callback.c | 2 +- .../FreeRTOS_IPv4/FreeRTOS_IPv4_utest.c | 3 --- .../FreeRTOS_Routing/FreeRTOS_Routing_utest.c | 20 +++++++++++++------ 6 files changed, 17 insertions(+), 15 deletions(-) diff --git a/source/FreeRTOS_IPv4.c b/source/FreeRTOS_IPv4.c index bd8ab1919..e5e5e48d5 100644 --- a/source/FreeRTOS_IPv4.c +++ b/source/FreeRTOS_IPv4.c @@ -321,9 +321,7 @@ enum eFrameProcessingResult prvAllowIPPacketIPv4( const struct xIP_PACKET * cons ( FreeRTOS_FindEndPointOnIP_IPv4( ulDestinationIPAddress ) == NULL ) && /* Is it an IPv4 broadcast address x.x.x.255 ? */ ( ( FreeRTOS_ntohl( ulDestinationIPAddress ) & 0xffU ) != 0xffU ) && - ( xIsIPv4Multicast( ulDestinationIPAddress ) == pdFALSE ) && - /* Or (during DHCP negotiation) we have no IP-address yet? */ - ( FreeRTOS_IsNetworkUp() != pdFALSE ) ) + ( xIsIPv4Multicast( ulDestinationIPAddress ) == pdFALSE ) ) { /* Packet is not for this node, release it */ eReturn = eReleaseBuffer; diff --git a/source/FreeRTOS_Routing.c b/source/FreeRTOS_Routing.c index 6d89ed186..800a93309 100644 --- a/source/FreeRTOS_Routing.c +++ b/source/FreeRTOS_Routing.c @@ -388,7 +388,6 @@ struct xIPv6_Couple #endif { if( ( ulIPAddress == 0U ) || - ( pxEndPoint->ipv4_settings.ulIPAddress == 0U ) || ( pxEndPoint->ipv4_settings.ulIPAddress == ulIPAddress ) ) { break; diff --git a/source/portable/NetworkInterface/RX/NetworkInterface.c b/source/portable/NetworkInterface/RX/NetworkInterface.c index 1c3874173..516da7b45 100644 --- a/source/portable/NetworkInterface/RX/NetworkInterface.c +++ b/source/portable/NetworkInterface/RX/NetworkInterface.c @@ -12,7 +12,7 @@ * Renesas reserves the right, without notice, to make changes to this software and to discontinue the availability of * this software. By using this software, you agree to the additional terms and conditions found by accessing the * following link: -* http://www.renesas.com/disclaimer +* https://www.renesas.com/en/document/oth/disclaimer8 * * Copyright (C) 2020 Renesas Electronics Corporation. All rights reserved. ***********************************************************************************************************************/ diff --git a/source/portable/NetworkInterface/RX/ether_callback.c b/source/portable/NetworkInterface/RX/ether_callback.c index dc54e0e31..b5c15fa34 100644 --- a/source/portable/NetworkInterface/RX/ether_callback.c +++ b/source/portable/NetworkInterface/RX/ether_callback.c @@ -12,7 +12,7 @@ * Renesas reserves the right, without notice, to make changes to this software and to discontinue the availability of * this software. By using this software, you agree to the additional terms and conditions found by accessing the * following link: -* http://www.renesas.com/disclaimer +* https://www.renesas.com/en/document/oth/disclaimer8 * * Copyright (C) 2015 Renesas Electronics Corporation. All rights reserved. ***********************************************************************************************************************/ diff --git a/test/unit-test/FreeRTOS_IPv4/FreeRTOS_IPv4_utest.c b/test/unit-test/FreeRTOS_IPv4/FreeRTOS_IPv4_utest.c index d758655ef..d571040a9 100644 --- a/test/unit-test/FreeRTOS_IPv4/FreeRTOS_IPv4_utest.c +++ b/test/unit-test/FreeRTOS_IPv4/FreeRTOS_IPv4_utest.c @@ -262,7 +262,6 @@ void test_prvAllowIPPacketIPv4_NotMatchingIP( void ) pxIPHeader->ulDestinationIPAddress = pxEndpoint->ipv4_settings.ulIPAddress + 1; FreeRTOS_FindEndPointOnIP_IPv4_ExpectAnyArgsAndReturn( NULL ); /* From prvAllowIPPacketIPv4() */ - FreeRTOS_IsNetworkUp_ExpectAndReturn( pdTRUE ); eResult = prvAllowIPPacketIPv4( pxIPPacket, pxNetworkBuffer, uxHeaderLength ); @@ -417,7 +416,6 @@ void test_prvAllowIPPacketIPv4_SourceIPBrdCast_NoLocalIP( void ) FreeRTOS_FindEndPointOnIP_IPv4_ExpectAnyArgsAndReturn( NULL ); /* From prvAllowIPPacketIPv4() */ - FreeRTOS_IsNetworkUp_ExpectAndReturn( pdFALSE ); eResult = prvAllowIPPacketIPv4( pxIPPacket, pxNetworkBuffer, uxHeaderLength ); @@ -455,7 +453,6 @@ void test_prvAllowIPPacketIPv4_DestMACBrdCast_DestIPUnicast( void ) FreeRTOS_FindEndPointOnIP_IPv4_ExpectAnyArgsAndReturn( NULL ); /* From prvAllowIPPacketIPv4() */ - FreeRTOS_IsNetworkUp_ExpectAndReturn( pdTRUE ); eResult = prvAllowIPPacketIPv4( pxIPPacket, pxNetworkBuffer, uxHeaderLength ); diff --git a/test/unit-test/FreeRTOS_Routing/FreeRTOS_Routing_utest.c b/test/unit-test/FreeRTOS_Routing/FreeRTOS_Routing_utest.c index 8887519ba..48958d45b 100644 --- a/test/unit-test/FreeRTOS_Routing/FreeRTOS_Routing_utest.c +++ b/test/unit-test/FreeRTOS_Routing/FreeRTOS_Routing_utest.c @@ -1440,11 +1440,15 @@ void test_FreeRTOS_FindEndPointOnIP_IPv4_AnyEndpoint( void ) * pxNetworkEndPoints is a global variable using in FreeRTOS_Routing as link list head of all endpoints. * * Test step: - * - Create 1 endpoint with IP address 0 and add it to the list. - * - Call FreeRTOS_FindEndPointOnIP_IPv4 to query with IPV4_DEFAULT_ADDRESS. + * - Create 1 endpoint with IP address 0xAB12CD34 and add it to the list. + * - Call FreeRTOS_FindEndPointOnIP_IPv4 to query with 0xAB12CD34. * - Check if returned endpoint is same. - * - Call FreeRTOS_FindEndPointOnIP_IPv4 to query with IPV4_DEFAULT_GATEWAY. + * - Call FreeRTOS_FindEndPointOnIP_IPv4 to query with 0. * - Check if returned endpoint is same. + * - Call FreeRTOS_FindEndPointOnIP_IPv4 to query with IPV4_DEFAULT_ADDRESS. + * - Check if returned endpoint is NULL. + * - Call FreeRTOS_FindEndPointOnIP_IPv4 to query with IPV4_DEFAULT_GATEWAY. + * - Check if returned endpoint is NULL. */ void test_FreeRTOS_FindEndPointOnIP_IPv4_ZeroAddressEndpoint( void ) { @@ -1452,13 +1456,17 @@ void test_FreeRTOS_FindEndPointOnIP_IPv4_ZeroAddressEndpoint( void ) NetworkEndPoint_t * pxEndPoint = NULL; memset( &xEndPoint, 0, sizeof( NetworkEndPoint_t ) ); - xEndPoint.ipv4_settings.ulIPAddress = 0; + xEndPoint.ipv4_settings.ulIPAddress = 0xAB12CD34; pxNetworkEndPoints = &xEndPoint; - pxEndPoint = FreeRTOS_FindEndPointOnIP_IPv4( IPV4_DEFAULT_ADDRESS ); + pxEndPoint = FreeRTOS_FindEndPointOnIP_IPv4( 0xAB12CD34 ); TEST_ASSERT_EQUAL( &xEndPoint, pxEndPoint ); - pxEndPoint = FreeRTOS_FindEndPointOnIP_IPv4( IPV4_DEFAULT_GATEWAY ); + pxEndPoint = FreeRTOS_FindEndPointOnIP_IPv4( 0 ); TEST_ASSERT_EQUAL( &xEndPoint, pxEndPoint ); + pxEndPoint = FreeRTOS_FindEndPointOnIP_IPv4( IPV4_DEFAULT_ADDRESS ); + TEST_ASSERT_EQUAL( NULL, pxEndPoint ); + pxEndPoint = FreeRTOS_FindEndPointOnIP_IPv4( IPV4_DEFAULT_GATEWAY ); + TEST_ASSERT_EQUAL( NULL, pxEndPoint ); } /**