From d4f8d755f37bddef638e5883b8afb39bb248691b Mon Sep 17 00:00:00 2001 From: tony-josi-aws Date: Sun, 30 Apr 2023 11:16:31 +0530 Subject: [PATCH] fix formatting, guard FreeRTOS_FillEndPoint inside ipconfigUSE_IPv4 check --- source/FreeRTOS_ARP.c | 442 +++++++++--------- source/FreeRTOS_IP.c | 4 +- source/FreeRTOS_IP_Utils.c | 2 +- source/FreeRTOS_Routing.c | 70 +-- source/include/FreeRTOS_IP_Utils.h | 2 +- .../FreeRTOS_IP_Utils_utest.c | 2 +- tools/tcp_utilities/plus_tcp_demo_cli.c | 120 +++-- 7 files changed, 315 insertions(+), 327 deletions(-) diff --git a/source/FreeRTOS_ARP.c b/source/FreeRTOS_ARP.c index 2b0aefa400..b91c170c27 100644 --- a/source/FreeRTOS_ARP.c +++ b/source/FreeRTOS_ARP.c @@ -94,8 +94,8 @@ static void vARPProcessPacketReply( const ARPPacket_t * pxARPFrame, * Lookup an MAC address in the ARP cache from the IP address. */ static eARPLookupResult_t prvCacheLookup( uint32_t ulAddressToLookup, - MACAddress_t * const pxMACAddress, - NetworkEndPoint_t ** ppxEndPoint ); + MACAddress_t * const pxMACAddress, + NetworkEndPoint_t ** ppxEndPoint ); static eARPLookupResult_t eARPGetCacheEntryGateWay( uint32_t * pulIPAddress, MACAddress_t * const pxMACAddress, @@ -528,52 +528,52 @@ BaseType_t xCheckRequiresARPResolution( NetworkBufferDescriptor_t * pxNetworkBuf #if ( ipconfigUSE_IPv6 != 0 ) case ipSIZE_OF_IPv6_HEADER: { - /* MISRA Ref 11.3.1 [Misaligned access] */ - /* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */ - /* coverity[misra_c_2012_rule_11_3_violation] */ - IPPacket_IPv6_t * pxIPPacket = ( ( IPPacket_IPv6_t * ) pxNetworkBuffer->pucEthernetBuffer ); - IPHeader_IPv6_t * pxIPHeader = &( pxIPPacket->xIPHeader ); - IPv6_Address_t * pxIPAddress = &( pxIPHeader->xSourceAddress ); - uint8_t ucNextHeader = pxIPHeader->ucNextHeader; - - if( ( ucNextHeader == ipPROTOCOL_TCP ) || - ( ucNextHeader == ipPROTOCOL_UDP ) ) - { - IPv6_Type_t eType = xIPv6_GetIPType( ( const IPv6_Address_t * ) pxIPAddress ); - FreeRTOS_printf( ( "xCheckRequiresARPResolution: %pip type %s\n", pxIPAddress->ucBytes, ( eType == eIPv6_Global ) ? "Global" : ( eType == eIPv6_LinkLocal ) ? "LinkLocal" : "other" ) ); - - if( eType == eIPv6_LinkLocal ) - { - MACAddress_t xMACAddress; - NetworkEndPoint_t * pxEndPoint; - eARPLookupResult_t eResult; - char pcName[ 80 ]; - - ( void ) memset( &( pcName ), 0, sizeof( pcName ) ); - eResult = eNDGetCacheEntry( pxIPAddress, &xMACAddress, &pxEndPoint ); - FreeRTOS_printf( ( "xCheckRequiresARPResolution: eResult %s with EP %s\n", ( eResult == eARPCacheMiss ) ? "Miss" : ( eResult == eARPCacheHit ) ? "Hit" : "Error", pcEndpointName( pxEndPoint, pcName, sizeof pcName ) ) ); - - if( eResult == eARPCacheMiss ) - { - NetworkBufferDescriptor_t * pxTempBuffer; - size_t uxNeededSize; - - uxNeededSize = ipSIZE_OF_ETH_HEADER + ipSIZE_OF_IPv6_HEADER + sizeof( ICMPRouterSolicitation_IPv6_t ); - pxTempBuffer = pxGetNetworkBufferWithDescriptor( BUFFER_FROM_WHERE_CALL( 199 ) uxNeededSize, 0U ); + /* MISRA Ref 11.3.1 [Misaligned access] */ + /* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */ + /* coverity[misra_c_2012_rule_11_3_violation] */ + IPPacket_IPv6_t * pxIPPacket = ( ( IPPacket_IPv6_t * ) pxNetworkBuffer->pucEthernetBuffer ); + IPHeader_IPv6_t * pxIPHeader = &( pxIPPacket->xIPHeader ); + IPv6_Address_t * pxIPAddress = &( pxIPHeader->xSourceAddress ); + uint8_t ucNextHeader = pxIPHeader->ucNextHeader; - if( pxTempBuffer != NULL ) - { - pxTempBuffer->pxEndPoint = pxNetworkBuffer->pxEndPoint; - pxTempBuffer->pxInterface = pxNetworkBuffer->pxInterface; - vNDSendNeighbourSolicitation( pxTempBuffer, pxIPAddress ); - } + if( ( ucNextHeader == ipPROTOCOL_TCP ) || + ( ucNextHeader == ipPROTOCOL_UDP ) ) + { + IPv6_Type_t eType = xIPv6_GetIPType( ( const IPv6_Address_t * ) pxIPAddress ); + FreeRTOS_printf( ( "xCheckRequiresARPResolution: %pip type %s\n", pxIPAddress->ucBytes, ( eType == eIPv6_Global ) ? "Global" : ( eType == eIPv6_LinkLocal ) ? "LinkLocal" : "other" ) ); - xNeedsARPResolution = pdTRUE; - } - } - } + if( eType == eIPv6_LinkLocal ) + { + MACAddress_t xMACAddress; + NetworkEndPoint_t * pxEndPoint; + eARPLookupResult_t eResult; + char pcName[ 80 ]; + + ( void ) memset( &( pcName ), 0, sizeof( pcName ) ); + eResult = eNDGetCacheEntry( pxIPAddress, &xMACAddress, &pxEndPoint ); + FreeRTOS_printf( ( "xCheckRequiresARPResolution: eResult %s with EP %s\n", ( eResult == eARPCacheMiss ) ? "Miss" : ( eResult == eARPCacheHit ) ? "Hit" : "Error", pcEndpointName( pxEndPoint, pcName, sizeof pcName ) ) ); + + if( eResult == eARPCacheMiss ) + { + NetworkBufferDescriptor_t * pxTempBuffer; + size_t uxNeededSize; + + uxNeededSize = ipSIZE_OF_ETH_HEADER + ipSIZE_OF_IPv6_HEADER + sizeof( ICMPRouterSolicitation_IPv6_t ); + pxTempBuffer = pxGetNetworkBufferWithDescriptor( BUFFER_FROM_WHERE_CALL( 199 ) uxNeededSize, 0U ); + + if( pxTempBuffer != NULL ) + { + pxTempBuffer->pxEndPoint = pxNetworkBuffer->pxEndPoint; + pxTempBuffer->pxInterface = pxNetworkBuffer->pxInterface; + vNDSendNeighbourSolicitation( pxTempBuffer, pxIPAddress ); + } + + xNeedsARPResolution = pdTRUE; + } + } + } - break; + break; } #endif /* ( ipconfigUSE_IPv6 != 0 ) */ @@ -891,64 +891,64 @@ static BaseType_t prvFindCacheEntry( const MACAddress_t * pxMACAddress, * addressing needs a gateway but there isn't a gateway defined) then return * eCantSendPacket. */ - eARPLookupResult_t eARPGetCacheEntry( uint32_t * pulIPAddress, - MACAddress_t * const pxMACAddress, - struct xNetworkEndPoint ** ppxEndPoint ) - { - eARPLookupResult_t eReturn; - uint32_t ulAddressToLookup; - NetworkEndPoint_t * pxEndPoint = NULL; +eARPLookupResult_t eARPGetCacheEntry( uint32_t * pulIPAddress, + MACAddress_t * const pxMACAddress, + struct xNetworkEndPoint ** ppxEndPoint ) +{ + eARPLookupResult_t eReturn; + uint32_t ulAddressToLookup; + NetworkEndPoint_t * pxEndPoint = NULL; - configASSERT( pxMACAddress != NULL ); - configASSERT( pulIPAddress != NULL ); - configASSERT( ppxEndPoint != NULL ); + configASSERT( pxMACAddress != NULL ); + configASSERT( pulIPAddress != NULL ); + configASSERT( ppxEndPoint != NULL ); - *( ppxEndPoint ) = NULL; - ulAddressToLookup = *pulIPAddress; - pxEndPoint = FreeRTOS_FindEndPointOnIP_IPv4( ulAddressToLookup, 0 ); + *( ppxEndPoint ) = NULL; + ulAddressToLookup = *pulIPAddress; + pxEndPoint = FreeRTOS_FindEndPointOnIP_IPv4( ulAddressToLookup, 0 ); - if( xIsIPv4Multicast( ulAddressToLookup ) != 0 ) - { - /* Get the lowest 23 bits of the IP-address. */ - vSetMultiCastIPv4MacAddress( ulAddressToLookup, pxMACAddress ); + if( xIsIPv4Multicast( ulAddressToLookup ) != 0 ) + { + /* Get the lowest 23 bits of the IP-address. */ + vSetMultiCastIPv4MacAddress( ulAddressToLookup, pxMACAddress ); - eReturn = eCantSendPacket; - pxEndPoint = FreeRTOS_FirstEndPoint( NULL ); + eReturn = eCantSendPacket; + pxEndPoint = FreeRTOS_FirstEndPoint( NULL ); - for( ; - pxEndPoint != NULL; - pxEndPoint = FreeRTOS_NextEndPoint( NULL, pxEndPoint ) ) - { - if( ENDPOINT_IS_IPv4( pxEndPoint ) ) - { - /* For multi-cast, use the first IPv4 end-point. */ - *( ppxEndPoint ) = pxEndPoint; - eReturn = eARPCacheHit; - break; - } - } - } - else if( ( FreeRTOS_htonl( ulAddressToLookup ) & 0xffU ) == 0xffU ) /* Is this a broadcast address like x.x.x.255 ? */ + for( ; + pxEndPoint != NULL; + pxEndPoint = FreeRTOS_NextEndPoint( NULL, pxEndPoint ) ) { - /* This is a broadcast so it uses the broadcast MAC address. */ - ( void ) memcpy( pxMACAddress->ucBytes, xBroadcastMACAddress.ucBytes, sizeof( MACAddress_t ) ); - pxEndPoint = FreeRTOS_FindEndPointOnNetMask( ulAddressToLookup, 4 ); - - if( pxEndPoint != NULL ) + if( ENDPOINT_IS_IPv4( pxEndPoint ) ) { + /* For multi-cast, use the first IPv4 end-point. */ *( ppxEndPoint ) = pxEndPoint; + eReturn = eARPCacheHit; + break; } - - eReturn = eARPCacheHit; } - else + } + else if( ( FreeRTOS_htonl( ulAddressToLookup ) & 0xffU ) == 0xffU ) /* Is this a broadcast address like x.x.x.255 ? */ + { + /* This is a broadcast so it uses the broadcast MAC address. */ + ( void ) memcpy( pxMACAddress->ucBytes, xBroadcastMACAddress.ucBytes, sizeof( MACAddress_t ) ); + pxEndPoint = FreeRTOS_FindEndPointOnNetMask( ulAddressToLookup, 4 ); + + if( pxEndPoint != NULL ) { - eReturn = eARPGetCacheEntryGateWay( pulIPAddress, pxMACAddress, ppxEndPoint ); + *( ppxEndPoint ) = pxEndPoint; } - return eReturn; + eReturn = eARPCacheHit; + } + else + { + eReturn = eARPGetCacheEntryGateWay( pulIPAddress, pxMACAddress, ppxEndPoint ); } - /*-----------------------------------------------------------*/ + + return eReturn; +} +/*-----------------------------------------------------------*/ /** * @brief The IPv4 address is apparently a web-address. Find a gateway.. @@ -958,87 +958,87 @@ static BaseType_t prvFindCacheEntry( const MACAddress_t * pxMACAddress, * stored to the buffer provided. * @param[out] ppxEndPoint The end-point of the gateway will be copy to the pointee. */ - static eARPLookupResult_t eARPGetCacheEntryGateWay( uint32_t * pulIPAddress, - MACAddress_t * const pxMACAddress, - struct xNetworkEndPoint ** ppxEndPoint ) - { - eARPLookupResult_t eReturn = eARPCacheMiss; - uint32_t ulAddressToLookup = *( pulIPAddress ); - NetworkEndPoint_t * pxEndPoint; - uint32_t ulOrginal = *pulIPAddress; +static eARPLookupResult_t eARPGetCacheEntryGateWay( uint32_t * pulIPAddress, + MACAddress_t * const pxMACAddress, + struct xNetworkEndPoint ** ppxEndPoint ) +{ + eARPLookupResult_t eReturn = eARPCacheMiss; + uint32_t ulAddressToLookup = *( pulIPAddress ); + NetworkEndPoint_t * pxEndPoint; + uint32_t ulOrginal = *pulIPAddress; - /* It is assumed that devices with the same netmask are on the same - * LAN and don't need a gateway. */ - pxEndPoint = FreeRTOS_FindEndPointOnNetMask( ulAddressToLookup, 4 ); + /* It is assumed that devices with the same netmask are on the same + * LAN and don't need a gateway. */ + pxEndPoint = FreeRTOS_FindEndPointOnNetMask( ulAddressToLookup, 4 ); - if( pxEndPoint == NULL ) - { - /* No matching end-point is found, look for a gateway. */ - #if ( ipconfigARP_STORES_REMOTE_ADDRESSES == 1 ) - eReturn = prvCacheLookup( ulAddressToLookup, pxMACAddress, ppxEndPoint ); + if( pxEndPoint == NULL ) + { + /* No matching end-point is found, look for a gateway. */ + #if ( ipconfigARP_STORES_REMOTE_ADDRESSES == 1 ) + eReturn = prvCacheLookup( ulAddressToLookup, pxMACAddress, ppxEndPoint ); - if( eReturn == eARPCacheHit ) - { - /* The stack is configured to store 'remote IP addresses', i.e. addresses - * belonging to a different the netmask. prvCacheLookup() returned a hit, so - * the MAC address is known. */ - } - else - #endif + if( eReturn == eARPCacheHit ) { - /* The IP address is off the local network, so look up the - * hardware address of the router, if any. */ - *( ppxEndPoint ) = FreeRTOS_FindGateWay( ( BaseType_t ) ipTYPE_IPv4 ); - - if( *( ppxEndPoint ) != NULL ) - { - /* 'ipv4_settings' can be accessed safely, because 'ipTYPE_IPv4' was provided. */ - ulAddressToLookup = ( *ppxEndPoint )->ipv4_settings.ulGatewayAddress; - } - else - { - ulAddressToLookup = *pulIPAddress; - } + /* The stack is configured to store 'remote IP addresses', i.e. addresses + * belonging to a different the netmask. prvCacheLookup() returned a hit, so + * the MAC address is known. */ } - } - else - { - /* The IP address is on the local network, so lookup the requested - * IP address directly. */ - ulAddressToLookup = *pulIPAddress; - *ppxEndPoint = pxEndPoint; - } - - #if ( ipconfigARP_STORES_REMOTE_ADDRESSES == 1 ) - if( eReturn == eARPCacheMiss ) + else #endif { - if( ulAddressToLookup == 0U ) + /* The IP address is off the local network, so look up the + * hardware address of the router, if any. */ + *( ppxEndPoint ) = FreeRTOS_FindGateWay( ( BaseType_t ) ipTYPE_IPv4 ); + + if( *( ppxEndPoint ) != NULL ) { - /* The address is not on the local network, and there is not a - * router. */ - eReturn = eCantSendPacket; + /* 'ipv4_settings' can be accessed safely, because 'ipTYPE_IPv4' was provided. */ + ulAddressToLookup = ( *ppxEndPoint )->ipv4_settings.ulGatewayAddress; } else { - eReturn = prvCacheLookup( ulAddressToLookup, pxMACAddress, ppxEndPoint ); + ulAddressToLookup = *pulIPAddress; + } + } + } + else + { + /* The IP address is on the local network, so lookup the requested + * IP address directly. */ + ulAddressToLookup = *pulIPAddress; + *ppxEndPoint = pxEndPoint; + } - if( ( eReturn != eARPCacheHit ) || ( ulOrginal != ulAddressToLookup ) ) - { - FreeRTOS_debug_printf( ( "ARP %xip %s using %xip\n", - ( unsigned ) FreeRTOS_ntohl( ulOrginal ), - ( eReturn == eARPCacheHit ) ? "hit" : "miss", - ( unsigned ) FreeRTOS_ntohl( ulAddressToLookup ) ) ); - } + #if ( ipconfigARP_STORES_REMOTE_ADDRESSES == 1 ) + if( eReturn == eARPCacheMiss ) + #endif + { + if( ulAddressToLookup == 0U ) + { + /* The address is not on the local network, and there is not a + * router. */ + eReturn = eCantSendPacket; + } + else + { + eReturn = prvCacheLookup( ulAddressToLookup, pxMACAddress, ppxEndPoint ); - /* It might be that the ARP has to go to the gateway. */ - *pulIPAddress = ulAddressToLookup; + if( ( eReturn != eARPCacheHit ) || ( ulOrginal != ulAddressToLookup ) ) + { + FreeRTOS_debug_printf( ( "ARP %xip %s using %xip\n", + ( unsigned ) FreeRTOS_ntohl( ulOrginal ), + ( eReturn == eARPCacheHit ) ? "hit" : "miss", + ( unsigned ) FreeRTOS_ntohl( ulAddressToLookup ) ) ); } - } - return eReturn; + /* It might be that the ARP has to go to the gateway. */ + *pulIPAddress = ulAddressToLookup; + } } - /*-----------------------------------------------------------*/ + + return eReturn; +} +/*-----------------------------------------------------------*/ /** * @brief Lookup an IP address in the ARP cache. @@ -1053,42 +1053,42 @@ static BaseType_t prvFindCacheEntry( const MACAddress_t * pxMACAddress, * @return When the IP-address is found: eARPCacheHit, when not found: eARPCacheMiss, * and when waiting for a ARP reply: eCantSendPacket. */ - static eARPLookupResult_t prvCacheLookup( uint32_t ulAddressToLookup, - MACAddress_t * const pxMACAddress, - NetworkEndPoint_t ** ppxEndPoint ) - { - BaseType_t x; - eARPLookupResult_t eReturn = eARPCacheMiss; +static eARPLookupResult_t prvCacheLookup( uint32_t ulAddressToLookup, + MACAddress_t * const pxMACAddress, + NetworkEndPoint_t ** ppxEndPoint ) +{ + BaseType_t x; + eARPLookupResult_t eReturn = eARPCacheMiss; - /* Loop through each entry in the ARP cache. */ - for( x = 0; x < ipconfigARP_CACHE_ENTRIES; x++ ) + /* Loop through each entry in the ARP cache. */ + for( x = 0; x < ipconfigARP_CACHE_ENTRIES; x++ ) + { + /* Does this row in the ARP cache table hold an entry for the IP address + * being queried? */ + if( xARPCache[ x ].ulIPAddress == ulAddressToLookup ) { - /* Does this row in the ARP cache table hold an entry for the IP address - * being queried? */ - if( xARPCache[ x ].ulIPAddress == ulAddressToLookup ) + /* A matching valid entry was found. */ + if( xARPCache[ x ].ucValid == ( uint8_t ) pdFALSE ) { - /* A matching valid entry was found. */ - if( xARPCache[ x ].ucValid == ( uint8_t ) pdFALSE ) - { - /* This entry is waiting an ARP reply, so is not valid. */ - eReturn = eCantSendPacket; - } - else - { - /* A valid entry was found. */ - ( void ) memcpy( pxMACAddress->ucBytes, xARPCache[ x ].xMACAddress.ucBytes, sizeof( MACAddress_t ) ); - /* ppxEndPoint != NULL was tested in the only caller eARPGetCacheEntry(). */ - *( ppxEndPoint ) = xARPCache[ x ].pxEndPoint; - eReturn = eARPCacheHit; - } - - break; + /* This entry is waiting an ARP reply, so is not valid. */ + eReturn = eCantSendPacket; + } + else + { + /* A valid entry was found. */ + ( void ) memcpy( pxMACAddress->ucBytes, xARPCache[ x ].xMACAddress.ucBytes, sizeof( MACAddress_t ) ); + /* ppxEndPoint != NULL was tested in the only caller eARPGetCacheEntry(). */ + *( ppxEndPoint ) = xARPCache[ x ].pxEndPoint; + eReturn = eARPCacheHit; } - } - return eReturn; + break; + } } - /*-----------------------------------------------------------*/ + + return eReturn; +} +/*-----------------------------------------------------------*/ /** * @brief A call to this function will update (or 'Age') the ARP cache entries. @@ -1282,56 +1282,56 @@ void FreeRTOS_OutputARPRequest( uint32_t ulIPAddress ) * * @return Zero when successful. */ - BaseType_t xARPWaitResolution( uint32_t ulIPAddress, - TickType_t uxTicksToWait ) - { - BaseType_t xResult = -pdFREERTOS_ERRNO_EADDRNOTAVAIL; - TimeOut_t xTimeOut; - MACAddress_t xMACAddress; - eARPLookupResult_t xLookupResult; - NetworkEndPoint_t * pxEndPoint; - size_t uxSendCount = ipconfigMAX_ARP_RETRANSMISSIONS; - uint32_t ulIPAddressCopy = ulIPAddress; - - /* The IP-task is not supposed to call this function. */ - configASSERT( xIsCallingFromIPTask() == pdFALSE ); +BaseType_t xARPWaitResolution( uint32_t ulIPAddress, + TickType_t uxTicksToWait ) +{ + BaseType_t xResult = -pdFREERTOS_ERRNO_EADDRNOTAVAIL; + TimeOut_t xTimeOut; + MACAddress_t xMACAddress; + eARPLookupResult_t xLookupResult; + NetworkEndPoint_t * pxEndPoint; + size_t uxSendCount = ipconfigMAX_ARP_RETRANSMISSIONS; + uint32_t ulIPAddressCopy = ulIPAddress; - xLookupResult = eARPGetCacheEntry( &( ulIPAddressCopy ), &( xMACAddress ), &( pxEndPoint ) ); + /* The IP-task is not supposed to call this function. */ + configASSERT( xIsCallingFromIPTask() == pdFALSE ); - if( xLookupResult == eARPCacheMiss ) - { - const TickType_t uxSleepTime = pdMS_TO_TICKS( 250U ); + xLookupResult = eARPGetCacheEntry( &( ulIPAddressCopy ), &( xMACAddress ), &( pxEndPoint ) ); - /* We might use ipconfigMAX_ARP_RETRANSMISSIONS here. */ - vTaskSetTimeOutState( &xTimeOut ); + if( xLookupResult == eARPCacheMiss ) + { + const TickType_t uxSleepTime = pdMS_TO_TICKS( 250U ); - while( uxSendCount > 0U ) - { - FreeRTOS_OutputARPRequest( ulIPAddressCopy ); + /* We might use ipconfigMAX_ARP_RETRANSMISSIONS here. */ + vTaskSetTimeOutState( &xTimeOut ); - vTaskDelay( uxSleepTime ); + while( uxSendCount > 0U ) + { + FreeRTOS_OutputARPRequest( ulIPAddressCopy ); - xLookupResult = eARPGetCacheEntry( &( ulIPAddressCopy ), &( xMACAddress ), &( pxEndPoint ) ); + vTaskDelay( uxSleepTime ); - if( ( xTaskCheckForTimeOut( &( xTimeOut ), &( uxTicksToWait ) ) == pdTRUE ) || - ( xLookupResult != eARPCacheMiss ) ) - { - break; - } + xLookupResult = eARPGetCacheEntry( &( ulIPAddressCopy ), &( xMACAddress ), &( pxEndPoint ) ); - /* Decrement the count. */ - uxSendCount--; + if( ( xTaskCheckForTimeOut( &( xTimeOut ), &( uxTicksToWait ) ) == pdTRUE ) || + ( xLookupResult != eARPCacheMiss ) ) + { + break; } - } - if( xLookupResult == eARPCacheHit ) - { - xResult = 0; + /* Decrement the count. */ + uxSendCount--; } + } - return xResult; + if( xLookupResult == eARPCacheHit ) + { + xResult = 0; } - /*-----------------------------------------------------------*/ + + return xResult; +} +/*-----------------------------------------------------------*/ /** * @brief Generate an ARP request packet by copying various constant details to diff --git a/source/FreeRTOS_IP.c b/source/FreeRTOS_IP.c index 08c2cd1d8b..7c029a79aa 100644 --- a/source/FreeRTOS_IP.c +++ b/source/FreeRTOS_IP.c @@ -907,7 +907,7 @@ void * FreeRTOS_GetUDPPayloadBuffer_Multi( size_t uxRequestedSizeBytes, * As that bug has been repaired, there is not an urgent reason to warn. * It is better though to use the advised priority scheme. */ -#if defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 1 ) +#if defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 1 ) && ( ipconfigUSE_IPv4 != 1 ) /* Provide backward-compatibility with the earlier FreeRTOS+TCP which only had * single network interface. */ @@ -931,7 +931,7 @@ void * FreeRTOS_GetUDPPayloadBuffer_Multi( size_t uxRequestedSizeBytes, #endif /* ipconfigUSE_DHCP */ return FreeRTOS_IPInit_Multi(); } -#endif /* if defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 1 ) */ +#endif /* if defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 1 ) && ( ipconfigUSE_IPv4 != 1 ) */ /*-----------------------------------------------------------*/ /** diff --git a/source/FreeRTOS_IP_Utils.c b/source/FreeRTOS_IP_Utils.c index 76d6cdb06d..e1eaeba33d 100644 --- a/source/FreeRTOS_IP_Utils.c +++ b/source/FreeRTOS_IP_Utils.c @@ -1745,4 +1745,4 @@ BaseType_t xIsIPv4Multicast( uint32_t ulIPAddress ) return xReturn; } -/*-----------------------------------------------------------*/ \ No newline at end of file +/*-----------------------------------------------------------*/ diff --git a/source/FreeRTOS_Routing.c b/source/FreeRTOS_Routing.c index 23d93aeabd..5fd3919b70 100644 --- a/source/FreeRTOS_Routing.c +++ b/source/FreeRTOS_Routing.c @@ -71,6 +71,9 @@ struct xIPv6_Couple }; /*-----------------------------------------------------------*/ + +#if ( ipconfigUSE_IPv4 != 1 ) + /** * @brief Configure and install a new IPv4 end-point. * @@ -84,47 +87,48 @@ struct xIPv6_Couple * @param[in] ucDNSServerAddress The IP-address of a DNS server. * @param[in] ucMACAddress The MAC address of the end-point. */ -void FreeRTOS_FillEndPoint( NetworkInterface_t * pxNetworkInterface, - NetworkEndPoint_t * pxEndPoint, - const uint8_t ucIPAddress[ ipIP_ADDRESS_LENGTH_BYTES ], - const uint8_t ucNetMask[ ipIP_ADDRESS_LENGTH_BYTES ], - const uint8_t ucGatewayAddress[ ipIP_ADDRESS_LENGTH_BYTES ], - const uint8_t ucDNSServerAddress[ ipIP_ADDRESS_LENGTH_BYTES ], - const uint8_t ucMACAddress[ ipMAC_ADDRESS_LENGTH_BYTES ] ) -{ - uint32_t ulIPAddress; + void FreeRTOS_FillEndPoint( NetworkInterface_t * pxNetworkInterface, + NetworkEndPoint_t * pxEndPoint, + const uint8_t ucIPAddress[ ipIP_ADDRESS_LENGTH_BYTES ], + const uint8_t ucNetMask[ ipIP_ADDRESS_LENGTH_BYTES ], + const uint8_t ucGatewayAddress[ ipIP_ADDRESS_LENGTH_BYTES ], + const uint8_t ucDNSServerAddress[ ipIP_ADDRESS_LENGTH_BYTES ], + const uint8_t ucMACAddress[ ipMAC_ADDRESS_LENGTH_BYTES ] ) + { + uint32_t ulIPAddress; - /* Fill in and add an end-point to a network interface. - * The user must make sure that the object pointed to by 'pxEndPoint' - * will remain to exist. */ - ( void ) memset( pxEndPoint, 0, sizeof( *pxEndPoint ) ); + /* Fill in and add an end-point to a network interface. + * The user must make sure that the object pointed to by 'pxEndPoint' + * will remain to exist. */ + ( void ) memset( pxEndPoint, 0, sizeof( *pxEndPoint ) ); - ulIPAddress = FreeRTOS_inet_addr_quick( ucIPAddress[ 0 ], ucIPAddress[ 1 ], ucIPAddress[ 2 ], ucIPAddress[ 3 ] ); - pxEndPoint->ipv4_settings.ulNetMask = FreeRTOS_inet_addr_quick( ucNetMask[ 0 ], ucNetMask[ 1 ], ucNetMask[ 2 ], ucNetMask[ 3 ] ); - pxEndPoint->ipv4_settings.ulGatewayAddress = FreeRTOS_inet_addr_quick( ucGatewayAddress[ 0 ], ucGatewayAddress[ 1 ], ucGatewayAddress[ 2 ], ucGatewayAddress[ 3 ] ); - pxEndPoint->ipv4_settings.ulDNSServerAddresses[ 0 ] = FreeRTOS_inet_addr_quick( ucDNSServerAddress[ 0 ], ucDNSServerAddress[ 1 ], ucDNSServerAddress[ 2 ], ucDNSServerAddress[ 3 ] ); - pxEndPoint->ipv4_settings.ulBroadcastAddress = ulIPAddress | ~( pxEndPoint->ipv4_settings.ulNetMask ); + ulIPAddress = FreeRTOS_inet_addr_quick( ucIPAddress[ 0 ], ucIPAddress[ 1 ], ucIPAddress[ 2 ], ucIPAddress[ 3 ] ); + pxEndPoint->ipv4_settings.ulNetMask = FreeRTOS_inet_addr_quick( ucNetMask[ 0 ], ucNetMask[ 1 ], ucNetMask[ 2 ], ucNetMask[ 3 ] ); + pxEndPoint->ipv4_settings.ulGatewayAddress = FreeRTOS_inet_addr_quick( ucGatewayAddress[ 0 ], ucGatewayAddress[ 1 ], ucGatewayAddress[ 2 ], ucGatewayAddress[ 3 ] ); + pxEndPoint->ipv4_settings.ulDNSServerAddresses[ 0 ] = FreeRTOS_inet_addr_quick( ucDNSServerAddress[ 0 ], ucDNSServerAddress[ 1 ], ucDNSServerAddress[ 2 ], ucDNSServerAddress[ 3 ] ); + pxEndPoint->ipv4_settings.ulBroadcastAddress = ulIPAddress | ~( pxEndPoint->ipv4_settings.ulNetMask ); - /* Copy the current values to the default values. */ - ( void ) memcpy( &( pxEndPoint->ipv4_defaults ), &( pxEndPoint->ipv4_settings ), sizeof( pxEndPoint->ipv4_defaults ) ); + /* Copy the current values to the default values. */ + ( void ) memcpy( &( pxEndPoint->ipv4_defaults ), &( pxEndPoint->ipv4_settings ), sizeof( pxEndPoint->ipv4_defaults ) ); - /* The default IP-address will be used in case DHCP is not used, or also if DHCP has failed, or - * when the user chooses to use the default IP-address. */ - pxEndPoint->ipv4_defaults.ulIPAddress = ulIPAddress; + /* The default IP-address will be used in case DHCP is not used, or also if DHCP has failed, or + * when the user chooses to use the default IP-address. */ + pxEndPoint->ipv4_defaults.ulIPAddress = ulIPAddress; - #if ( ipconfigUSE_DHCP != 0 ) - if( pxEndPoint->bits.bWantDHCP == 0U ) - #endif - { - pxEndPoint->ipv4_settings.ulIPAddress = ulIPAddress; - } + #if ( ipconfigUSE_DHCP != 0 ) + if( pxEndPoint->bits.bWantDHCP == 0U ) + #endif + { + pxEndPoint->ipv4_settings.ulIPAddress = ulIPAddress; + } - /* The field 'ipv4_settings.ulIPAddress' will be set later on. */ + /* The field 'ipv4_settings.ulIPAddress' will be set later on. */ - ( void ) memcpy( pxEndPoint->xMACAddress.ucBytes, ucMACAddress, sizeof( pxEndPoint->xMACAddress ) ); - ( void ) FreeRTOS_AddEndPoint( pxNetworkInterface, pxEndPoint ); -} + ( void ) memcpy( pxEndPoint->xMACAddress.ucBytes, ucMACAddress, sizeof( pxEndPoint->xMACAddress ) ); + ( void ) FreeRTOS_AddEndPoint( pxNetworkInterface, pxEndPoint ); + } /*-----------------------------------------------------------*/ +#endif /* ( ipconfigUSE_IPv4 != 1 ) */ #if ( ipconfigCOMPATIBLE_WITH_SINGLE == 0 ) diff --git a/source/include/FreeRTOS_IP_Utils.h b/source/include/FreeRTOS_IP_Utils.h index 8f59e8b733..e7af5adb35 100644 --- a/source/include/FreeRTOS_IP_Utils.h +++ b/source/include/FreeRTOS_IP_Utils.h @@ -106,7 +106,7 @@ BaseType_t xIsIPv4Multicast( uint32_t ulIPAddress ); /* Set the MAC-address that belongs to a given IPv4 multi-cast address. */ void vSetMultiCastIPv4MacAddress( uint32_t ulIPAddress, MACAddress_t * pxMACAddress ); - + /* *INDENT-OFF* */ #ifdef __cplusplus } /* extern "C" */ diff --git a/test/unit-test/FreeRTOS_IP_Utils/FreeRTOS_IP_Utils_utest.c b/test/unit-test/FreeRTOS_IP_Utils/FreeRTOS_IP_Utils_utest.c index 7d1c805a91..39be27d697 100644 --- a/test/unit-test/FreeRTOS_IP_Utils/FreeRTOS_IP_Utils_utest.c +++ b/test/unit-test/FreeRTOS_IP_Utils/FreeRTOS_IP_Utils_utest.c @@ -1917,4 +1917,4 @@ void test_xIsIPv4Multicast_IsMultiCast( void ) xReturn = xIsIPv4Multicast( ulIPAddress ); TEST_ASSERT_EQUAL( pdTRUE, xReturn ); -} \ No newline at end of file +} diff --git a/tools/tcp_utilities/plus_tcp_demo_cli.c b/tools/tcp_utilities/plus_tcp_demo_cli.c index 5079e87bf7..e8d1b60071 100644 --- a/tools/tcp_utilities/plus_tcp_demo_cli.c +++ b/tools/tcp_utilities/plus_tcp_demo_cli.c @@ -534,14 +534,13 @@ static void handle_arpq( char * pcBuffer ) ulLookUpIP = ulIPAddress; xLookupAddress = xAddress; - switch(xIPType) + switch( xIPType ) { - #if ( ipconfigUSE_IPv4 != 0 ) case ipTYPE_IPv4: eResult = eARPGetCacheEntry( &ulLookUpIP, &xMACAddress, &pxEndPoint ); FreeRTOS_printf( ( "ARPGetCacheEntry returns \"%s\" Look for %xip. Found end-point: %s\n", - pcARPReturnType( eResult ), ( unsigned ) FreeRTOS_htonl( ulLookUpIP ), ( pxEndPoint != NULL ) ? "yes" : "no" ) ); + pcARPReturnType( eResult ), ( unsigned ) FreeRTOS_htonl( ulLookUpIP ), ( pxEndPoint != NULL ) ? "yes" : "no" ) ); break; #endif /* ( ipconfigUSE_IPv4 != 0 ) */ @@ -549,15 +548,14 @@ static void handle_arpq( char * pcBuffer ) case ipTYPE_IPv6: eResult = eNDGetCacheEntry( &( xLookupAddress.xIP_IPv6 ), &xMACAddress, &pxEndPoint ); FreeRTOS_printf( ( "ARPGetCacheEntry returns \"%s\" Look for %pip. Found end-point: %s\n", - pcARPReturnType( eResult ), xAddress.xIP_IPv6.ucBytes, ( pxEndPoint != NULL ) ? "yes" : "no" ) ); + pcARPReturnType( eResult ), xAddress.xIP_IPv6.ucBytes, ( pxEndPoint != NULL ) ? "yes" : "no" ) ); break; #endif /* ( ipconfigUSE_IPv6 != 0 ) */ - + default: /* MISRA 16.4 Compliance */ FreeRTOS_debug_printf( ( "handle_arpq: Undefined IP Type \n" ) ); break; - } if( ( eResult == eARPCacheMiss ) && ( pxEndPoint != NULL ) ) @@ -571,13 +569,12 @@ static void handle_arpq( char * pcBuffer ) NetworkBufferDescriptor_t * pxBuffer; - switch(xIPType) + switch( xIPType ) { - #if ( ipconfigUSE_IPv4 != 0 ) case ipTYPE_IPv4: FreeRTOS_printf( ( "handle_arpq: Looking up %xip\n", - ( unsigned ) FreeRTOS_ntohl( ulLookUpIP ) ) ); + ( unsigned ) FreeRTOS_ntohl( ulLookUpIP ) ) ); xARPWaitResolution( ulLookUpIP, 1000U ); break; @@ -597,8 +594,8 @@ static void handle_arpq( char * pcBuffer ) pxBuffer->pxEndPoint = pxEndPoint; pxBuffer->pxInterface = pxBuffer->pxEndPoint->pxNetworkInterface; FreeRTOS_printf( ( "handle_arpq: Looking up %pip with%s end-point\n", - pxBuffer->xIPAddress.xIP_IPv6.ucBytes, - ( pxBuffer->pxEndPoint != NULL ) ? "" : "out" ) ); + pxBuffer->xIPAddress.xIP_IPv6.ucBytes, + ( pxBuffer->pxEndPoint != NULL ) ? "" : "out" ) ); vNDSendNeighbourSolicitation( pxBuffer, &( pxBuffer->xIPAddress.xIP_IPv6 ) ); } @@ -608,21 +605,19 @@ static void handle_arpq( char * pcBuffer ) } break; #endif /* ( ipconfigUSE_IPv6 != 0 ) */ - + default: /* MISRA 16.4 Compliance */ FreeRTOS_debug_printf( ( "handle_arpq: Undefined IP Type \n" ) ); break; - } /* Let the IP-task do its work, and wait 500 ms. */ FreeRTOS_printf( ( "... Pause ...\n" ) ); vTaskDelay( pdMS_TO_TICKS( 500U ) ); - switch(xIPType) + switch( xIPType ) { - #if ( ipconfigUSE_IPv4 != 0 ) case ipTYPE_IPv4: eResult = eARPGetCacheEntry( &ulLookUpIP, &xMACAddress, &pxEndPoint ); @@ -634,12 +629,11 @@ static void handle_arpq( char * pcBuffer ) eResult = eNDGetCacheEntry( &( xLookupAddress.xIP_IPv6 ), &xMACAddress, &pxEndPoint ); break; #endif /* ( ipconfigUSE_IPv6 != 0 ) */ - + default: /* MISRA 16.4 Compliance */ FreeRTOS_debug_printf( ( "handle_arpq: Undefined IP Type \n" ) ); break; - } FreeRTOS_printf( ( "handle_arpq: after lookup: \"%s\"\n", @@ -1033,10 +1027,8 @@ static void handle_help( char * pcBuffer ) if( pxDNSResult != NULL ) { - - switch(xOptions.xIPVersion) + switch( xOptions.xIPVersion ) { - #if ( ipconfigUSE_IPv4 != 0 ) case 4: FreeRTOS_printf( ( "ping4 to '%s' (%xip)\n", pcHostname, ( unsigned ) FreeRTOS_ntohl( pxDNSResult->ai_addr->sin_address.ulIP_IPv4 ) ) ); @@ -1061,14 +1053,12 @@ static void handle_help( char * pcBuffer ) uxPingTimes[ 0 ] = ( TickType_t ) ullGetHighResolutionTime(); break; #endif /* ( ipconfigUSE_IPv6 != 0 ) */ - + default: /* MISRA 16.4 Compliance */ FreeRTOS_debug_printf( ( "handle_ping: Undefined IP Type \n" ) ); break; - } - } else { @@ -1446,9 +1436,8 @@ void xHandleTesting() pxResult->ai_addr = &( pxResult->xPrivateStorage.sockaddr ); - switch(xIPVersion) + switch( xIPVersion ) { - #if ( ipconfigUSE_IPv4 != 0 ) case 4: #if ( ipconfigUSE_DNS_CACHE != 0 ) @@ -1475,14 +1464,12 @@ void xHandleTesting() } break; #endif /* ( ipconfigUSE_IPv6 != 0 ) */ - + default: /* MISRA 16.4 Compliance */ FreeRTOS_debug_printf( ( "pxDNSLookup: Undefined IP Version Type \n" ) ); break; - } - } } #endif /* if ( ipconfigDNS_USE_CALLBACKS != 0 ) && ( ipconfigMULTI_INTERFACE != 0 ) */ @@ -1511,59 +1498,56 @@ void xHandleTesting() { FreeRTOS_printf( ( "vDNSEvent: family = %d\n", ( int ) pxAddrInfo->ai_family ) ); - switch(pxAddrInfo->ai_family) + switch( pxAddrInfo->ai_family ) { - #if ( ipconfigUSE_IPv4 != 0 ) case FREERTOS_AF_INET: - { - uint32_t ulIPaddress = pxAddrInfo->ai_addr->sin_address.ulIP_IPv4; - - if( ulIPaddress == 0uL ) - { - FreeRTOS_printf( ( "vDNSEvent/v4: '%s' timed out\n", pcName ) ); - } - else - { - FreeRTOS_printf( ( "vDNSEvent/v4: found '%s' on %lxip\n", pcName, FreeRTOS_ntohl( ulIPaddress ) ) ); - } - } - break; + { + uint32_t ulIPaddress = pxAddrInfo->ai_addr->sin_address.ulIP_IPv4; + + if( ulIPaddress == 0uL ) + { + FreeRTOS_printf( ( "vDNSEvent/v4: '%s' timed out\n", pcName ) ); + } + else + { + FreeRTOS_printf( ( "vDNSEvent/v4: found '%s' on %lxip\n", pcName, FreeRTOS_ntohl( ulIPaddress ) ) ); + } + } + break; #endif /* ( ipconfigUSE_IPv4 != 0 ) */ #if ( ipconfigUSE_IPv6 != 0 ) case FREERTOS_AF_INET6: - { - BaseType_t xIsEmpty = pdTRUE, xIndex; - - for( xIndex = 0; xIndex < ( BaseType_t ) ARRAY_SIZE( pxAddrInfo->ai_addr->sin_address.xIP_IPv6.ucBytes ); xIndex++ ) - { - if( pxAddrInfo->ai_addr->sin_address.xIP_IPv6.ucBytes[ xIndex ] != ( uint8_t ) 0u ) - { - xIsEmpty = pdFALSE; - break; - } - } - - if( xIsEmpty ) - { - FreeRTOS_printf( ( "vDNSEvent/v6: '%s' timed out\n", pcName ) ); - } - else - { - FreeRTOS_printf( ( "vDNSEvent/v6: found '%s' on %pip\n", pcName, pxAddrInfo->ai_addr->sin_address.xIP_IPv6.ucBytes ) ); - } - } - break; + { + BaseType_t xIsEmpty = pdTRUE, xIndex; + + for( xIndex = 0; xIndex < ( BaseType_t ) ARRAY_SIZE( pxAddrInfo->ai_addr->sin_address.xIP_IPv6.ucBytes ); xIndex++ ) + { + if( pxAddrInfo->ai_addr->sin_address.xIP_IPv6.ucBytes[ xIndex ] != ( uint8_t ) 0u ) + { + xIsEmpty = pdFALSE; + break; + } + } + + if( xIsEmpty ) + { + FreeRTOS_printf( ( "vDNSEvent/v6: '%s' timed out\n", pcName ) ); + } + else + { + FreeRTOS_printf( ( "vDNSEvent/v6: found '%s' on %pip\n", pcName, pxAddrInfo->ai_addr->sin_address.xIP_IPv6.ucBytes ) ); + } + } + break; #endif /* ( ipconfigUSE_IPv6 != 0 ) */ - + default: /* MISRA 16.4 Compliance */ FreeRTOS_debug_printf( ( "vDNSEvent: Undefined Family Type \n" ) ); break; - } - } if( xServerWorkTaskHandle != NULL )