diff --git a/.github/.cSpellWords.txt b/.github/.cSpellWords.txt index 220d1a9816..4b9f2d5f0b 100644 --- a/.github/.cSpellWords.txt +++ b/.github/.cSpellWords.txt @@ -1280,6 +1280,7 @@ STLIDMPUSR STLIMPUOR STLNVICACTVOR STLNVICPENDOR +Storex strbt STRBT strexb diff --git a/source/FreeRTOS_ARP.c b/source/FreeRTOS_ARP.c index 6d279623d7..a9a3edfec9 100644 --- a/source/FreeRTOS_ARP.c +++ b/source/FreeRTOS_ARP.c @@ -54,35 +54,34 @@ #include "NetworkBufferManagement.h" #include "NetworkInterface.h" #include "FreeRTOS_Routing.h" -#include "FreeRTOS_ND.h" +#if ( ipconfigUSE_IPv4 != 0 ) /** @brief When the age of an entry in the ARP table reaches this value (it counts down * to zero, so this is an old entry) an ARP request will be sent to see if the * entry is still valid and can therefore be refreshed. */ -#define arpMAX_ARP_AGE_BEFORE_NEW_ARP_REQUEST ( 3U ) + #define arpMAX_ARP_AGE_BEFORE_NEW_ARP_REQUEST ( 3U ) /** @brief The time between gratuitous ARPs. */ -#ifndef arpGRATUITOUS_ARP_PERIOD - #define arpGRATUITOUS_ARP_PERIOD ( pdMS_TO_TICKS( 20000U ) ) -#endif + #ifndef arpGRATUITOUS_ARP_PERIOD + #define arpGRATUITOUS_ARP_PERIOD ( pdMS_TO_TICKS( 20000U ) ) + #endif /** @brief When there is another device which has the same IP address as the IP address * of this device, a defensive ARP request should be sent out. However, according to * RFC 5227 section 1.1, there must be a minimum interval of 10 seconds between * consecutive defensive ARP packets. */ -#ifndef arpIP_CLASH_RESET_TIMEOUT_MS - #define arpIP_CLASH_RESET_TIMEOUT_MS 10000U -#endif + #ifndef arpIP_CLASH_RESET_TIMEOUT_MS + #define arpIP_CLASH_RESET_TIMEOUT_MS 10000U + #endif /** @brief Maximum number of defensive ARPs to be sent for an ARP clash per * arpIP_CLASH_RESET_TIMEOUT_MS period. The retries are limited to one as outlined * by RFC 5227 section 2.4 part b.*/ -#ifndef arpIP_CLASH_MAX_RETRIES - #define arpIP_CLASH_MAX_RETRIES 1U -#endif + #ifndef arpIP_CLASH_MAX_RETRIES + #define arpIP_CLASH_MAX_RETRIES 1U + #endif -#if ( ipconfigUSE_IPv4 != 0 ) static void vARPProcessPacketRequest( ARPPacket_t * pxARPFrame, NetworkEndPoint_t * pxTargetEndPoint, @@ -95,25 +94,23 @@ /* * 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 ); - - static eARPLookupResult_t eARPGetCacheEntryGateWay( uint32_t * pulIPAddress, - MACAddress_t * const pxMACAddress, - struct xNetworkEndPoint ** ppxEndPoint ); + static eResolutionLookupResult_t prvCacheLookup( uint32_t ulAddressToLookup, + MACAddress_t * const pxMACAddress, + NetworkEndPoint_t ** ppxEndPoint ); -#endif /* ( ipconfigUSE_IPv4 != 0 ) */ + static eResolutionLookupResult_t eARPGetCacheEntryGateWay( uint32_t * pulIPAddress, + MACAddress_t * const pxMACAddress, + struct xNetworkEndPoint ** ppxEndPoint ); -static BaseType_t prvFindCacheEntry( const MACAddress_t * pxMACAddress, - const uint32_t ulIPAddress, - struct xNetworkEndPoint * pxEndPoint, - CacheLocation_t * pxLocation ); + static BaseType_t prvFindCacheEntry( const MACAddress_t * pxMACAddress, + const uint32_t ulIPAddress, + struct xNetworkEndPoint * pxEndPoint, + CacheLocation_t * pxLocation ); /*-----------------------------------------------------------*/ /** @brief The ARP cache. */ -_static ARPCacheRow_t xARPCache[ ipconfigARP_CACHE_ENTRIES ]; + _static ARPCacheRow_t xARPCache[ ipconfigARP_CACHE_ENTRIES ]; /* @@ -121,17 +118,15 @@ _static ARPCacheRow_t xARPCache[ ipconfigARP_CACHE_ENTRIES ]; * driver can try out a random LinkLayer IP address (169.254.x.x). It will send out a * gratuitous ARP message and, after a period of time, check the variables here below: */ -#if ( ipconfigARP_USE_CLASH_DETECTION != 0 ) - /* Becomes non-zero if another device responded to a gratuitous ARP message. */ - BaseType_t xARPHadIPClash; - /* MAC-address of the other device containing the same IP-address. */ - MACAddress_t xARPClashMacAddress; -#endif /* ipconfigARP_USE_CLASH_DETECTION */ + #if ( ipconfigARP_USE_CLASH_DETECTION != 0 ) + /* Becomes non-zero if another device responded to a gratuitous ARP message. */ + BaseType_t xARPHadIPClash; + /* MAC-address of the other device containing the same IP-address. */ + MACAddress_t xARPClashMacAddress; + #endif /* ipconfigARP_USE_CLASH_DETECTION */ /*-----------------------------------------------------------*/ -#if ( ipconfigUSE_IPv4 != 0 ) - /** @brief The time at which the last gratuitous ARP was sent. Gratuitous ARPs are used * to ensure ARP tables are up to date and to detect IP address conflicts. */ static TickType_t xLastGratuitousARPTime = 0U; @@ -257,7 +252,7 @@ _static ARPCacheRow_t xARPCache[ ipconfigARP_CACHE_ENTRIES ]; } else { - traceARP_PACKET_RECEIVED(); + iptraceARP_PACKET_RECEIVED(); /* Some extra logging while still testing. */ #if ( ipconfigHAS_DEBUG_PRINTF != 0 ) @@ -323,7 +318,7 @@ _static ARPCacheRow_t xARPCache[ ipconfigARP_CACHE_ENTRIES ]; /* The request is a Gratuitous ARP message. * Refresh the entry if it already exists. */ /* Determine the ARP cache status for the requested IP address. */ - if( eARPGetCacheEntry( &( ulSenderProtocolAddress ), &( xHardwareAddress ), &( pxCachedEndPoint ) ) == eARPCacheHit ) + if( eARPGetCacheEntry( &( ulSenderProtocolAddress ), &( xHardwareAddress ), &( pxCachedEndPoint ) ) == eResolutionCacheHit ) { /* Check if the endpoint matches with the one present in the ARP cache */ if( pxCachedEndPoint == pxTargetEndPoint ) @@ -473,8 +468,6 @@ _static ARPCacheRow_t xARPCache[ ipconfigARP_CACHE_ENTRIES ]; } /*-----------------------------------------------------------*/ -#endif /* ( ipconfigUSE_IPv4 != 0 ) */ - /** * @brief Check whether an IP address is in the ARP cache. * @@ -483,32 +476,32 @@ _static ARPCacheRow_t xARPCache[ ipconfigARP_CACHE_ENTRIES ]; * * @return When the IP-address is found: pdTRUE, else pdFALSE. */ -BaseType_t xIsIPInARPCache( uint32_t ulAddressToLookup ) -{ - BaseType_t x, xReturn = pdFALSE; - - /* Loop through each entry in the ARP cache. */ - for( x = 0; x < ipconfigARP_CACHE_ENTRIES; x++ ) + BaseType_t xIsIPInARPCache( uint32_t ulAddressToLookup ) { - /* Does this row in the ARP cache table hold an entry for the IP address - * being queried? */ - if( xARPCache[ x ].ulIPAddress == ulAddressToLookup ) - { - xReturn = pdTRUE; + BaseType_t x, xReturn = pdFALSE; - /* A matching valid entry was found. */ - if( xARPCache[ x ].ucValid == ( uint8_t ) pdFALSE ) + /* 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 ) { - /* This entry is waiting an ARP reply, so is not valid. */ - xReturn = pdFALSE; - } + xReturn = pdTRUE; + + /* A matching valid entry was found. */ + if( xARPCache[ x ].ucValid == ( uint8_t ) pdFALSE ) + { + /* This entry is waiting an ARP reply, so is not valid. */ + xReturn = pdFALSE; + } - break; + break; + } } - } - return xReturn; -} + return xReturn; + } /** * @brief Check whether a packet needs ARP resolution if it is on local subnet. If required send an ARP request. @@ -517,107 +510,37 @@ BaseType_t xIsIPInARPCache( uint32_t ulAddressToLookup ) * * @return pdTRUE if the packet needs ARP resolution, pdFALSE otherwise. */ -BaseType_t xCheckRequiresARPResolution( const NetworkBufferDescriptor_t * pxNetworkBuffer ) -{ - BaseType_t xNeedsARPResolution = pdFALSE; - - switch( uxIPHeaderSizePacket( pxNetworkBuffer ) ) + BaseType_t xCheckRequiresARPResolution( const NetworkBufferDescriptor_t * pxNetworkBuffer ) { - #if ( ipconfigUSE_IPv4 != 0 ) - case ipSIZE_OF_IPv4_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] */ - const IPPacket_t * pxIPPacket = ( ( const IPPacket_t * ) pxNetworkBuffer->pucEthernetBuffer ); - const IPHeader_t * pxIPHeader = &( pxIPPacket->xIPHeader ); - const IPV4Parameters_t * pxIPv4Settings = &( pxNetworkBuffer->pxEndPoint->ipv4_settings ); - - if( ( pxIPHeader->ulSourceIPAddress & pxIPv4Settings->ulNetMask ) == ( pxIPv4Settings->ulIPAddress & pxIPv4Settings->ulNetMask ) ) - { - /* If the IP is on the same subnet and we do not have an ARP entry already, - * then we should send out ARP for finding the MAC address. */ - if( xIsIPInARPCache( pxIPHeader->ulSourceIPAddress ) == pdFALSE ) - { - FreeRTOS_OutputARPRequest_Multi( pxNetworkBuffer->pxEndPoint, pxIPHeader->ulSourceIPAddress ); - - /* This packet needs resolution since this is on the same subnet - * but not in the ARP cache. */ - xNeedsARPResolution = pdTRUE; - } - } - - break; - } - #endif /* ( ipconfigUSE_IPv4 != 0 ) */ - - #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_debug_printf( ( "xCheckRequiresARPResolution: %pip type %s\n", - ( void * ) pxIPAddress->ucBytes, - ( eType == eIPv6_Global ) ? "Global" : - ( eType == eIPv6_LinkLocal ) ? "LinkLocal" : - ( eType == eIPv6_Loopback ) ? "Loopback" : - "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 = sizeof( ICMPPacket_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; - } - #endif /* ( ipconfigUSE_IPv6 != 0 ) */ - - default: - /* Shouldn't reach here */ - /* MISRA 16.4 Compliance */ - break; - } + BaseType_t xNeedsARPResolution = pdFALSE; + + /* 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] */ + const IPPacket_t * pxIPPacket = ( ( const IPPacket_t * ) pxNetworkBuffer->pucEthernetBuffer ); + const IPHeader_t * pxIPHeader = &( pxIPPacket->xIPHeader ); + const IPV4Parameters_t * pxIPv4Settings = &( pxNetworkBuffer->pxEndPoint->ipv4_settings ); + + configASSERT( ( pxIPPacket->xEthernetHeader.usFrameType == ipIPv4_FRAME_TYPE ) || ( pxIPPacket->xEthernetHeader.usFrameType == ipARP_FRAME_TYPE ) ); + + if( ( pxIPHeader->ulSourceIPAddress & pxIPv4Settings->ulNetMask ) == ( pxIPv4Settings->ulIPAddress & pxIPv4Settings->ulNetMask ) ) + { + /* If the IP is on the same subnet and we do not have an ARP entry already, + * then we should send out ARP for finding the MAC address. */ + if( xIsIPInARPCache( pxIPHeader->ulSourceIPAddress ) == pdFALSE ) + { + FreeRTOS_OutputARPRequest_Multi( pxNetworkBuffer->pxEndPoint, pxIPHeader->ulSourceIPAddress ); - return xNeedsARPResolution; -} + /* This packet needs resolution since this is on the same subnet + * but not in the ARP cache. */ + xNeedsARPResolution = pdTRUE; + } + } -#if ( ipconfigUSE_ARP_REMOVE_ENTRY != 0 ) + return xNeedsARPResolution; + } + + #if ( ipconfigUSE_ARP_REMOVE_ENTRY != 0 ) /** * @brief Remove an ARP cache entry that matches with .pxMACAddress. @@ -626,28 +549,28 @@ BaseType_t xCheckRequiresARPResolution( const NetworkBufferDescriptor_t * pxNetw * be removed. * @return When the entry was found and remove: the IP-address, otherwise zero. */ - uint32_t ulARPRemoveCacheEntryByMac( const MACAddress_t * pxMACAddress ) - { - BaseType_t x; - uint32_t lResult = 0; + uint32_t ulARPRemoveCacheEntryByMac( const MACAddress_t * pxMACAddress ) + { + BaseType_t x; + uint32_t lResult = 0; - configASSERT( pxMACAddress != NULL ); + configASSERT( pxMACAddress != NULL ); - /* For each entry in the ARP cache table. */ - for( x = 0; x < ipconfigARP_CACHE_ENTRIES; x++ ) - { - if( ( memcmp( xARPCache[ x ].xMACAddress.ucBytes, pxMACAddress->ucBytes, sizeof( pxMACAddress->ucBytes ) ) == 0 ) ) + /* For each entry in the ARP cache table. */ + for( x = 0; x < ipconfigARP_CACHE_ENTRIES; x++ ) { - lResult = xARPCache[ x ].ulIPAddress; - ( void ) memset( &xARPCache[ x ], 0, sizeof( xARPCache[ x ] ) ); - break; + if( ( memcmp( xARPCache[ x ].xMACAddress.ucBytes, pxMACAddress->ucBytes, sizeof( pxMACAddress->ucBytes ) ) == 0 ) ) + { + lResult = xARPCache[ x ].ulIPAddress; + ( void ) memset( &xARPCache[ x ], 0, sizeof( xARPCache[ x ] ) ); + break; + } } - } - return lResult; - } + return lResult; + } -#endif /* ipconfigUSE_ARP_REMOVE_ENTRY != 0 */ + #endif /* ipconfigUSE_ARP_REMOVE_ENTRY != 0 */ /*-----------------------------------------------------------*/ /** @@ -657,31 +580,31 @@ BaseType_t xCheckRequiresARPResolution( const NetworkBufferDescriptor_t * pxNetw * @param[in] pxMACAddress Pointer to the MAC address whose entry needs to be updated. * @param[in] ulIPAddress the IP address whose corresponding entry needs to be updated. */ -void vARPRefreshCacheEntryAge( const MACAddress_t * pxMACAddress, - const uint32_t ulIPAddress ) -{ - BaseType_t x; - - if( pxMACAddress != NULL ) + void vARPRefreshCacheEntryAge( const MACAddress_t * pxMACAddress, + const uint32_t ulIPAddress ) { - /* Loop through each entry in the ARP cache. */ - for( x = 0; x < ipconfigARP_CACHE_ENTRIES; x++ ) + BaseType_t x; + + if( pxMACAddress != NULL ) { - /* Does this line in the cache table hold an entry for the IP - * address being queried? */ - if( xARPCache[ x ].ulIPAddress == ulIPAddress ) + /* Loop through each entry in the ARP cache. */ + for( x = 0; x < ipconfigARP_CACHE_ENTRIES; x++ ) { - /* Does this cache entry have the same MAC address? */ - if( memcmp( xARPCache[ x ].xMACAddress.ucBytes, pxMACAddress->ucBytes, sizeof( pxMACAddress->ucBytes ) ) == 0 ) + /* Does this line in the cache table hold an entry for the IP + * address being queried? */ + if( xARPCache[ x ].ulIPAddress == ulIPAddress ) { - /* The IP address and the MAC matched, update this entry age. */ - xARPCache[ x ].ucAge = ( uint8_t ) ipconfigMAX_ARP_AGE; - break; + /* Does this cache entry have the same MAC address? */ + if( memcmp( xARPCache[ x ].xMACAddress.ucBytes, pxMACAddress->ucBytes, sizeof( pxMACAddress->ucBytes ) ) == 0 ) + { + /* The IP address and the MAC matched, update this entry age. */ + xARPCache[ x ].ucAge = ( uint8_t ) ipconfigMAX_ARP_AGE; + break; + } } } } } -} /*-----------------------------------------------------------*/ /** @@ -693,82 +616,82 @@ void vARPRefreshCacheEntryAge( const MACAddress_t * pxMACAddress, * is being updated. * @param[in] pxEndPoint The end-point stored in the table. */ -void vARPRefreshCacheEntry( const MACAddress_t * pxMACAddress, - const uint32_t ulIPAddress, - struct xNetworkEndPoint * pxEndPoint ) -{ - #if ( ipconfigARP_STORES_REMOTE_ADDRESSES == 0 ) - /* Only process the IP address if it is on the local network. */ - BaseType_t xAddressIsLocal = ( FreeRTOS_FindEndPointOnNetMask( ulIPAddress ) != NULL ) ? 1 : 0; /* ARP remote address. */ - - /* Only process the IP address if it matches with one of the end-points. */ - if( xAddressIsLocal != 0 ) - #else - - /* If ipconfigARP_STORES_REMOTE_ADDRESSES is non-zero, IP addresses with - * a different netmask will also be stored. After when replying to a UDP - * message from a different netmask, the IP address can be looped up and a - * reply sent. This option is useful for systems with multiple gateways, - * the reply will surely arrive. If ipconfigARP_STORES_REMOTE_ADDRESSES is - * zero the the gateway address is the only option. */ - - if( pdTRUE ) - #endif + void vARPRefreshCacheEntry( const MACAddress_t * pxMACAddress, + const uint32_t ulIPAddress, + struct xNetworkEndPoint * pxEndPoint ) { - CacheLocation_t xLocation; - BaseType_t xReady; + #if ( ipconfigARP_STORES_REMOTE_ADDRESSES == 0 ) + /* Only process the IP address if it is on the local network. */ + BaseType_t xAddressIsLocal = ( FreeRTOS_FindEndPointOnNetMask( ulIPAddress ) != NULL ) ? 1 : 0; /* ARP remote address. */ + + /* Only process the IP address if it matches with one of the end-points. */ + if( xAddressIsLocal != 0 ) + #else + + /* If ipconfigARP_STORES_REMOTE_ADDRESSES is non-zero, IP addresses with + * a different netmask will also be stored. After when replying to a UDP + * message from a different netmask, the IP address can be looped up and a + * reply sent. This option is useful for systems with multiple gateways, + * the reply will surely arrive. If ipconfigARP_STORES_REMOTE_ADDRESSES is + * zero the the gateway address is the only option. */ + + if( pdTRUE ) + #endif + { + CacheLocation_t xLocation; + BaseType_t xReady; - xReady = prvFindCacheEntry( pxMACAddress, ulIPAddress, pxEndPoint, &( xLocation ) ); + xReady = prvFindCacheEntry( pxMACAddress, ulIPAddress, pxEndPoint, &( xLocation ) ); - if( xReady == pdFALSE ) - { - if( xLocation.xMacEntry >= 0 ) + if( xReady == pdFALSE ) { - xLocation.xUseEntry = xLocation.xMacEntry; + if( xLocation.xMacEntry >= 0 ) + { + xLocation.xUseEntry = xLocation.xMacEntry; - if( xLocation.xIpEntry >= 0 ) + if( xLocation.xIpEntry >= 0 ) + { + /* Both the MAC address as well as the IP address were found in + * different locations: clear the entry which matches the + * IP-address */ + ( void ) memset( &( xARPCache[ xLocation.xIpEntry ] ), 0, sizeof( ARPCacheRow_t ) ); + } + } + else if( xLocation.xIpEntry >= 0 ) { - /* Both the MAC address as well as the IP address were found in - * different locations: clear the entry which matches the - * IP-address */ - ( void ) memset( &( xARPCache[ xLocation.xIpEntry ] ), 0, sizeof( ARPCacheRow_t ) ); + /* An entry containing the IP-address was found, but it had a different MAC address */ + xLocation.xUseEntry = xLocation.xIpEntry; + } + else + { + /* No matching entry found. */ } - } - else if( xLocation.xIpEntry >= 0 ) - { - /* An entry containing the IP-address was found, but it had a different MAC address */ - xLocation.xUseEntry = xLocation.xIpEntry; - } - else - { - /* No matching entry found. */ - } - /* If the entry was not found, we use the oldest entry and set the IPaddress */ - xARPCache[ xLocation.xUseEntry ].ulIPAddress = ulIPAddress; + /* If the entry was not found, we use the oldest entry and set the IPaddress */ + xARPCache[ xLocation.xUseEntry ].ulIPAddress = ulIPAddress; - if( pxMACAddress != NULL ) - { - ( void ) memcpy( xARPCache[ xLocation.xUseEntry ].xMACAddress.ucBytes, pxMACAddress->ucBytes, sizeof( pxMACAddress->ucBytes ) ); + if( pxMACAddress != NULL ) + { + ( void ) memcpy( xARPCache[ xLocation.xUseEntry ].xMACAddress.ucBytes, pxMACAddress->ucBytes, sizeof( pxMACAddress->ucBytes ) ); - iptraceARP_TABLE_ENTRY_CREATED( ulIPAddress, ( *pxMACAddress ) ); - /* And this entry does not need immediate attention */ - xARPCache[ xLocation.xUseEntry ].ucAge = ( uint8_t ) ipconfigMAX_ARP_AGE; - xARPCache[ xLocation.xUseEntry ].ucValid = ( uint8_t ) pdTRUE; - xARPCache[ xLocation.xUseEntry ].pxEndPoint = pxEndPoint; - } - else if( xLocation.xIpEntry < 0 ) - { - xARPCache[ xLocation.xUseEntry ].ucAge = ( uint8_t ) ipconfigMAX_ARP_RETRANSMISSIONS; - xARPCache[ xLocation.xUseEntry ].ucValid = ( uint8_t ) pdFALSE; - } - else - { - /* Nothing will be stored. */ + iptraceARP_TABLE_ENTRY_CREATED( ulIPAddress, ( *pxMACAddress ) ); + /* And this entry does not need immediate attention */ + xARPCache[ xLocation.xUseEntry ].ucAge = ( uint8_t ) ipconfigMAX_ARP_AGE; + xARPCache[ xLocation.xUseEntry ].ucValid = ( uint8_t ) pdTRUE; + xARPCache[ xLocation.xUseEntry ].pxEndPoint = pxEndPoint; + } + else if( xLocation.xIpEntry < 0 ) + { + xARPCache[ xLocation.xUseEntry ].ucAge = ( uint8_t ) ipconfigMAX_ARP_RETRANSMISSIONS; + xARPCache[ xLocation.xUseEntry ].ucValid = ( uint8_t ) pdFALSE; + } + else + { + /* Nothing will be stored. */ + } } } } -} /*-----------------------------------------------------------*/ /** @@ -779,118 +702,118 @@ void vARPRefreshCacheEntry( const MACAddress_t * pxMACAddress, * @param[in] pxEndPoint The end-point that will stored in the table. * @param[out] pxLocation The results of this search are written in this struct. */ -static BaseType_t prvFindCacheEntry( const MACAddress_t * pxMACAddress, - const uint32_t ulIPAddress, - struct xNetworkEndPoint * pxEndPoint, - CacheLocation_t * pxLocation ) -{ - BaseType_t x = 0; - uint8_t ucMinAgeFound = 0U; - BaseType_t xReturn = pdFALSE; - - #if ( ipconfigARP_STORES_REMOTE_ADDRESSES != 0 ) - BaseType_t xAddressIsLocal = ( FreeRTOS_FindEndPointOnNetMask( ulIPAddress ) != NULL ) ? 1 : 0; /* ARP remote address. */ - #endif + static BaseType_t prvFindCacheEntry( const MACAddress_t * pxMACAddress, + const uint32_t ulIPAddress, + struct xNetworkEndPoint * pxEndPoint, + CacheLocation_t * pxLocation ) + { + BaseType_t x = 0; + uint8_t ucMinAgeFound = 0U; + BaseType_t xReturn = pdFALSE; - /* Start with the maximum possible number. */ - ucMinAgeFound--; + #if ( ipconfigARP_STORES_REMOTE_ADDRESSES != 0 ) + BaseType_t xAddressIsLocal = ( FreeRTOS_FindEndPointOnNetMask( ulIPAddress ) != NULL ) ? 1 : 0; /* ARP remote address. */ + #endif - pxLocation->xIpEntry = -1; - pxLocation->xMacEntry = -1; - pxLocation->xUseEntry = 0; + /* Start with the maximum possible number. */ + ucMinAgeFound--; - /* For each entry in the ARP cache table. */ - for( x = 0; x < ipconfigARP_CACHE_ENTRIES; x++ ) - { - BaseType_t xMatchingMAC = pdFALSE; + pxLocation->xIpEntry = -1; + pxLocation->xMacEntry = -1; + pxLocation->xUseEntry = 0; - if( pxMACAddress != NULL ) + /* For each entry in the ARP cache table. */ + for( x = 0; x < ipconfigARP_CACHE_ENTRIES; x++ ) { - if( memcmp( xARPCache[ x ].xMACAddress.ucBytes, pxMACAddress->ucBytes, sizeof( pxMACAddress->ucBytes ) ) == 0 ) - { - xMatchingMAC = pdTRUE; - } - } + BaseType_t xMatchingMAC = pdFALSE; - /* Does this line in the cache table hold an entry for the IP - * address being queried? */ - if( xARPCache[ x ].ulIPAddress == ulIPAddress ) - { - if( pxMACAddress == NULL ) + if( pxMACAddress != NULL ) { - /* In case the parameter pxMACAddress is NULL, an entry will be reserved to - * indicate that there is an outstanding ARP request, This entry will have - * "ucValid == pdFALSE". */ - pxLocation->xIpEntry = x; - break; + if( memcmp( xARPCache[ x ].xMACAddress.ucBytes, pxMACAddress->ucBytes, sizeof( pxMACAddress->ucBytes ) ) == 0 ) + { + xMatchingMAC = pdTRUE; + } } - /* See if the MAC-address also matches. */ - if( xMatchingMAC != pdFALSE ) + /* Does this line in the cache table hold an entry for the IP + * address being queried? */ + if( xARPCache[ x ].ulIPAddress == ulIPAddress ) { - /* This function will be called for each received packet - * This is by far the most common path. */ - xARPCache[ x ].ucAge = ( uint8_t ) ipconfigMAX_ARP_AGE; - xARPCache[ x ].ucValid = ( uint8_t ) pdTRUE; - xARPCache[ x ].pxEndPoint = pxEndPoint; - /* Indicate to the caller that the entry is updated. */ - xReturn = pdTRUE; - break; - } + if( pxMACAddress == NULL ) + { + /* In case the parameter pxMACAddress is NULL, an entry will be reserved to + * indicate that there is an outstanding ARP request, This entry will have + * "ucValid == pdFALSE". */ + pxLocation->xIpEntry = x; + break; + } - /* Found an entry containing ulIPAddress, but the MAC address - * doesn't match. Might be an entry with ucValid=pdFALSE, waiting - * for an ARP reply. Still want to see if there is match with the - * given MAC address.ucBytes. If found, either of the two entries - * must be cleared. */ - pxLocation->xIpEntry = x; - } - else if( xMatchingMAC != pdFALSE ) - { - /* Found an entry with the given MAC-address, but the IP-address - * is different. Continue looping to find a possible match with - * ulIPAddress. */ - #if ( ipconfigARP_STORES_REMOTE_ADDRESSES != 0 ) + /* See if the MAC-address also matches. */ + if( xMatchingMAC != pdFALSE ) + { + /* This function will be called for each received packet + * This is by far the most common path. */ + xARPCache[ x ].ucAge = ( uint8_t ) ipconfigMAX_ARP_AGE; + xARPCache[ x ].ucValid = ( uint8_t ) pdTRUE; + xARPCache[ x ].pxEndPoint = pxEndPoint; + /* Indicate to the caller that the entry is updated. */ + xReturn = pdTRUE; + break; + } + + /* Found an entry containing ulIPAddress, but the MAC address + * doesn't match. Might be an entry with ucValid=pdFALSE, waiting + * for an ARP reply. Still want to see if there is match with the + * given MAC address.ucBytes. If found, either of the two entries + * must be cleared. */ + pxLocation->xIpEntry = x; + } + else if( xMatchingMAC != pdFALSE ) { - /* If ARP stores the MAC address of IP addresses outside the - * network, than the MAC address of the gateway should not be - * overwritten. */ - BaseType_t xOtherIsLocal = ( FreeRTOS_FindEndPointOnNetMask( xARPCache[ x ].ulIPAddress ) != NULL ) ? 1 : 0; /* ARP remote address. */ + /* Found an entry with the given MAC-address, but the IP-address + * is different. Continue looping to find a possible match with + * ulIPAddress. */ + #if ( ipconfigARP_STORES_REMOTE_ADDRESSES != 0 ) + { + /* If ARP stores the MAC address of IP addresses outside the + * network, than the MAC address of the gateway should not be + * overwritten. */ + BaseType_t xOtherIsLocal = ( FreeRTOS_FindEndPointOnNetMask( xARPCache[ x ].ulIPAddress ) != NULL ) ? 1 : 0; /* ARP remote address. */ - if( xAddressIsLocal == xOtherIsLocal ) + if( xAddressIsLocal == xOtherIsLocal ) + { + pxLocation->xMacEntry = x; + } + } + #else /* if ( ipconfigARP_STORES_REMOTE_ADDRESSES != 0 ) */ { pxLocation->xMacEntry = x; } + #endif /* if ( ipconfigARP_STORES_REMOTE_ADDRESSES != 0 ) */ } - #else /* if ( ipconfigARP_STORES_REMOTE_ADDRESSES != 0 ) */ + + /* _HT_ + * Shouldn't we test for xARPCache[ x ].ucValid == pdFALSE here ? */ + else if( xARPCache[ x ].ucAge < ucMinAgeFound ) { - pxLocation->xMacEntry = x; + /* As the table is traversed, remember the table row that + * contains the oldest entry (the lowest age count, as ages are + * decremented to zero) so the row can be re-used if this function + * needs to add an entry that does not already exist. */ + ucMinAgeFound = xARPCache[ x ].ucAge; + pxLocation->xUseEntry = x; } - #endif /* if ( ipconfigARP_STORES_REMOTE_ADDRESSES != 0 ) */ - } - - /* _HT_ - * Shouldn't we test for xARPCache[ x ].ucValid == pdFALSE here ? */ - else if( xARPCache[ x ].ucAge < ucMinAgeFound ) - { - /* As the table is traversed, remember the table row that - * contains the oldest entry (the lowest age count, as ages are - * decremented to zero) so the row can be re-used if this function - * needs to add an entry that does not already exist. */ - ucMinAgeFound = xARPCache[ x ].ucAge; - pxLocation->xUseEntry = x; - } - else - { - /* Nothing happens to this cache entry for now. */ - } - } /* for( x = 0; x < ipconfigARP_CACHE_ENTRIES; x++ ) */ + else + { + /* Nothing happens to this cache entry for now. */ + } + } /* for( x = 0; x < ipconfigARP_CACHE_ENTRIES; x++ ) */ - return xReturn; -} + return xReturn; + } /*-----------------------------------------------------------*/ -#if ( ipconfigUSE_ARP_REVERSED_LOOKUP == 1 ) + #if ( ipconfigUSE_ARP_REVERSED_LOOKUP == 1 ) /** * @brief Retrieve an entry from the cache table @@ -898,51 +821,49 @@ static BaseType_t prvFindCacheEntry( const MACAddress_t * pxMACAddress, * @param[in] pxMACAddress The MAC-address of the entry of interest. * @param[out] pulIPAddress set to the IP-address found, or unchanged when not found. * - * @return Either eARPCacheMiss or eARPCacheHit. + * @return Either eResolutionCacheMiss or eResolutionCacheHit. */ - eARPLookupResult_t eARPGetCacheEntryByMac( const MACAddress_t * const pxMACAddress, - uint32_t * pulIPAddress, - struct xNetworkInterface ** ppxInterface ) - { - BaseType_t x; - eARPLookupResult_t eReturn = eARPCacheMiss; - - configASSERT( pxMACAddress != NULL ); - configASSERT( pulIPAddress != NULL ); - - if( ppxInterface != NULL ) + eResolutionLookupResult_t eARPGetCacheEntryByMac( const MACAddress_t * const pxMACAddress, + uint32_t * pulIPAddress, + struct xNetworkInterface ** ppxInterface ) { - *( ppxInterface ) = NULL; - } + BaseType_t x; + eResolutionLookupResult_t eReturn = eResolutionCacheMiss; - /* 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 MAC - * address being searched? */ - if( memcmp( pxMACAddress->ucBytes, xARPCache[ x ].xMACAddress.ucBytes, sizeof( MACAddress_t ) ) == 0 ) + configASSERT( pxMACAddress != NULL ); + configASSERT( pulIPAddress != NULL ); + + if( ppxInterface != NULL ) { - *pulIPAddress = xARPCache[ x ].ulIPAddress; + *( ppxInterface ) = NULL; + } - if( ( ppxInterface != NULL ) && - ( xARPCache[ x ].pxEndPoint != NULL ) ) + /* 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 MAC + * address being searched? */ + if( memcmp( pxMACAddress->ucBytes, xARPCache[ x ].xMACAddress.ucBytes, sizeof( MACAddress_t ) ) == 0 ) { - *( ppxInterface ) = xARPCache[ x ].pxEndPoint->pxNetworkInterface; - } + *pulIPAddress = xARPCache[ x ].ulIPAddress; - eReturn = eARPCacheHit; - break; + if( ( ppxInterface != NULL ) && + ( xARPCache[ x ].pxEndPoint != NULL ) ) + { + *( ppxInterface ) = xARPCache[ x ].pxEndPoint->pxNetworkInterface; + } + + eReturn = eResolutionCacheHit; + break; + } } - } - return eReturn; - } -#endif /* ipconfigUSE_ARP_REVERSED_LOOKUP */ + return eReturn; + } + #endif /* ipconfigUSE_ARP_REVERSED_LOOKUP */ /*-----------------------------------------------------------*/ -#if ( ipconfigUSE_IPv4 != 0 ) - /** * @brief Look for ulIPAddress in the ARP cache. * @@ -952,17 +873,17 @@ static BaseType_t prvFindCacheEntry( const MACAddress_t * pxMACAddress, * @param[out] ppxEndPoint Pointer to the end-point of the gateway will be stored. * * @return If the IP address exists, copy the associated MAC address into pxMACAddress, - * refresh the ARP cache entry's age, and return eARPCacheHit. If the IP - * address does not exist in the ARP cache return eARPCacheMiss. If the packet + * refresh the ARP cache entry's age, and return eResolutionCacheHit. If the IP + * address does not exist in the ARP cache return eResolutionCacheMiss. If the packet * cannot be sent for any reason (maybe DHCP is still in process, or the * addressing needs a gateway but there isn't a gateway defined) then return - * eCantSendPacket. + * eResolutionFailed. */ - eARPLookupResult_t eARPGetCacheEntry( uint32_t * pulIPAddress, - MACAddress_t * const pxMACAddress, - struct xNetworkEndPoint ** ppxEndPoint ) + eResolutionLookupResult_t eARPGetCacheEntry( uint32_t * pulIPAddress, + MACAddress_t * const pxMACAddress, + struct xNetworkEndPoint ** ppxEndPoint ) { - eARPLookupResult_t eReturn = eCantSendPacket; + eResolutionLookupResult_t eReturn = eResolutionFailed; uint32_t ulAddressToLookup; NetworkEndPoint_t * pxEndPoint = NULL; @@ -981,7 +902,7 @@ static BaseType_t prvFindCacheEntry( const MACAddress_t * pxMACAddress, /* For multi-cast, use the first IPv4 end-point. */ ( void ) memcpy( pxMACAddress->ucBytes, pxEndPoint->xMACAddress.ucBytes, sizeof( pxMACAddress->ucBytes ) ); *( ppxEndPoint ) = pxEndPoint; - eReturn = eARPCacheHit; + eReturn = eResolutionCacheHit; } } else if( xIsIPv4Multicast( ulAddressToLookup ) != 0 ) @@ -999,7 +920,7 @@ static BaseType_t prvFindCacheEntry( const MACAddress_t * pxMACAddress, { /* For multi-cast, use the first IPv4 end-point. */ *( ppxEndPoint ) = pxEndPoint; - eReturn = eARPCacheHit; + eReturn = eResolutionCacheHit; break; } } @@ -1015,7 +936,7 @@ static BaseType_t prvFindCacheEntry( const MACAddress_t * pxMACAddress, *( ppxEndPoint ) = pxEndPoint; } - eReturn = eARPCacheHit; + eReturn = eResolutionCacheHit; } else { @@ -1034,11 +955,11 @@ 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 ) + static eResolutionLookupResult_t eARPGetCacheEntryGateWay( uint32_t * pulIPAddress, + MACAddress_t * const pxMACAddress, + struct xNetworkEndPoint ** ppxEndPoint ) { - eARPLookupResult_t eReturn = eARPCacheMiss; + eResolutionLookupResult_t eReturn = eResolutionCacheMiss; uint32_t ulAddressToLookup = *( pulIPAddress ); NetworkEndPoint_t * pxEndPoint; uint32_t ulOriginal = *pulIPAddress; @@ -1053,7 +974,7 @@ static BaseType_t prvFindCacheEntry( const MACAddress_t * pxMACAddress, #if ( ipconfigARP_STORES_REMOTE_ADDRESSES == 1 ) eReturn = prvCacheLookup( ulAddressToLookup, pxMACAddress, ppxEndPoint ); - if( eReturn == eARPCacheHit ) + if( eReturn == eResolutionCacheHit ) { /* The stack is configured to store 'remote IP addresses', i.e. addresses * belonging to a different the netmask. prvCacheLookup() returned a hit, so @@ -1086,24 +1007,24 @@ static BaseType_t prvFindCacheEntry( const MACAddress_t * pxMACAddress, } #if ( ipconfigARP_STORES_REMOTE_ADDRESSES == 1 ) - if( eReturn == eARPCacheMiss ) + if( eReturn == eResolutionCacheMiss ) #endif { if( ulAddressToLookup == 0U ) { /* The address is not on the local network, and there is not a * router. */ - eReturn = eCantSendPacket; + eReturn = eResolutionFailed; } else { eReturn = prvCacheLookup( ulAddressToLookup, pxMACAddress, ppxEndPoint ); - if( ( eReturn != eARPCacheHit ) || ( ulOriginal != ulAddressToLookup ) ) + if( ( eReturn != eResolutionCacheHit ) || ( ulOriginal != ulAddressToLookup ) ) { FreeRTOS_debug_printf( ( "ARP %xip %s using %xip\n", ( unsigned ) FreeRTOS_ntohl( ulOriginal ), - ( eReturn == eARPCacheHit ) ? "hit" : "miss", + ( eReturn == eResolutionCacheHit ) ? "hit" : "miss", ( unsigned ) FreeRTOS_ntohl( ulAddressToLookup ) ) ); } @@ -1126,15 +1047,15 @@ static BaseType_t prvFindCacheEntry( const MACAddress_t * pxMACAddress, * the IP address will be stored. * @param[in,out] ppxEndPoint a pointer to the end-point will be stored. * - * @return When the IP-address is found: eARPCacheHit, when not found: eARPCacheMiss, - * and when waiting for a ARP reply: eCantSendPacket. + * @return When the IP-address is found: eResolutionCacheHit, when not found: eResolutionCacheMiss, + * and when waiting for a ARP reply: eResolutionFailed. */ - static eARPLookupResult_t prvCacheLookup( uint32_t ulAddressToLookup, - MACAddress_t * const pxMACAddress, - NetworkEndPoint_t ** ppxEndPoint ) + static eResolutionLookupResult_t prvCacheLookup( uint32_t ulAddressToLookup, + MACAddress_t * const pxMACAddress, + NetworkEndPoint_t ** ppxEndPoint ) { BaseType_t x; - eARPLookupResult_t eReturn = eARPCacheMiss; + eResolutionLookupResult_t eReturn = eResolutionCacheMiss; /* Loop through each entry in the ARP cache. */ for( x = 0; x < ipconfigARP_CACHE_ENTRIES; x++ ) @@ -1147,7 +1068,7 @@ static BaseType_t prvFindCacheEntry( const MACAddress_t * pxMACAddress, if( xARPCache[ x ].ucValid == ( uint8_t ) pdFALSE ) { /* This entry is waiting an ARP reply, so is not valid. */ - eReturn = eCantSendPacket; + eReturn = eResolutionFailed; } else { @@ -1155,7 +1076,7 @@ static BaseType_t prvFindCacheEntry( const MACAddress_t * pxMACAddress, ( 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; + eReturn = eResolutionCacheHit; } break; @@ -1226,25 +1147,9 @@ static BaseType_t prvFindCacheEntry( const MACAddress_t * pxMACAddress, { if( ( pxEndPoint->bits.bEndPointUp != pdFALSE_UNSIGNED ) && ( pxEndPoint->ipv4_settings.ulIPAddress != 0U ) ) { - /* Case default is never toggled because IPv6 flag can be TRUE or FALSE */ - switch( pxEndPoint->bits.bIPv6 ) /* LCOV_EXCL_BR_LINE */ + if( pxEndPoint->bits.bIPv6 == pdFALSE_UNSIGNED ) /* LCOV_EXCL_BR_LINE */ { - #if ( ipconfigUSE_IPv4 != 0 ) - case pdFALSE_UNSIGNED: - FreeRTOS_OutputARPRequest_Multi( pxEndPoint, pxEndPoint->ipv4_settings.ulIPAddress ); - break; - #endif /* ( ipconfigUSE_IPv4 != 0 ) */ - - #if ( ipconfigUSE_IPv6 != 0 ) - case pdTRUE_UNSIGNED: - FreeRTOS_OutputAdvertiseIPv6( pxEndPoint ); - break; - #endif /* ( ipconfigUSE_IPv6 != 0 ) */ - - default: /* LCOV_EXCL_LINE */ - /* Shouldn't reach here */ - /* MISRA 16.4 Compliance */ - break; /* LCOV_EXCL_LINE */ + FreeRTOS_OutputARPRequest_Multi( pxEndPoint, pxEndPoint->ipv4_settings.ulIPAddress ); } } @@ -1380,7 +1285,7 @@ static BaseType_t prvFindCacheEntry( const MACAddress_t * pxMACAddress, BaseType_t xResult = -pdFREERTOS_ERRNO_EADDRNOTAVAIL; TimeOut_t xTimeOut; MACAddress_t xMACAddress; - eARPLookupResult_t xLookupResult; + eResolutionLookupResult_t xLookupResult; NetworkEndPoint_t * pxEndPoint; size_t uxSendCount = ipconfigMAX_ARP_RETRANSMISSIONS; uint32_t ulIPAddressCopy = ulIPAddress; @@ -1390,7 +1295,7 @@ static BaseType_t prvFindCacheEntry( const MACAddress_t * pxMACAddress, xLookupResult = eARPGetCacheEntry( &( ulIPAddressCopy ), &( xMACAddress ), &( pxEndPoint ) ); - if( xLookupResult == eARPCacheMiss ) + if( xLookupResult == eResolutionCacheMiss ) { const TickType_t uxSleepTime = pdMS_TO_TICKS( 250U ); @@ -1406,7 +1311,7 @@ static BaseType_t prvFindCacheEntry( const MACAddress_t * pxMACAddress, xLookupResult = eARPGetCacheEntry( &( ulIPAddressCopy ), &( xMACAddress ), &( pxEndPoint ) ); if( ( xTaskCheckForTimeOut( &( xTimeOut ), &( uxTicksToWait ) ) == pdTRUE ) || - ( xLookupResult != eARPCacheMiss ) ) + ( xLookupResult != eResolutionCacheMiss ) ) { break; } @@ -1416,7 +1321,7 @@ static BaseType_t prvFindCacheEntry( const MACAddress_t * pxMACAddress, } } - if( xLookupResult == eARPCacheHit ) + if( xLookupResult == eResolutionCacheHit ) { xResult = 0; } @@ -1425,8 +1330,6 @@ static BaseType_t prvFindCacheEntry( const MACAddress_t * pxMACAddress, } /*-----------------------------------------------------------*/ - - /** * @brief Generate an ARP request packet by copying various constant details to * the buffer. @@ -1512,60 +1415,60 @@ static BaseType_t prvFindCacheEntry( const MACAddress_t * pxMACAddress, } /*-----------------------------------------------------------*/ -#endif /* ( ipconfigUSE_IPv4 != 0 ) */ - /** * @brief A call to this function will clear the ARP cache. * @param[in] pxEndPoint only clean entries with this end-point, or when NULL, * clear the entire ARP cache. */ -void FreeRTOS_ClearARP( const struct xNetworkEndPoint * pxEndPoint ) -{ - if( pxEndPoint != NULL ) + void FreeRTOS_ClearARP( const struct xNetworkEndPoint * pxEndPoint ) { - BaseType_t x; - - for( x = 0; x < ipconfigARP_CACHE_ENTRIES; x++ ) + if( pxEndPoint != NULL ) { - if( xARPCache[ x ].pxEndPoint == pxEndPoint ) + BaseType_t x; + + for( x = 0; x < ipconfigARP_CACHE_ENTRIES; x++ ) { - ( void ) memset( &( xARPCache[ x ] ), 0, sizeof( ARPCacheRow_t ) ); + if( xARPCache[ x ].pxEndPoint == pxEndPoint ) + { + ( void ) memset( &( xARPCache[ x ] ), 0, sizeof( ARPCacheRow_t ) ); + } } } + else + { + ( void ) memset( xARPCache, 0, sizeof( xARPCache ) ); + } } - else - { - ( void ) memset( xARPCache, 0, sizeof( xARPCache ) ); - } -} /*-----------------------------------------------------------*/ -#if ( ipconfigHAS_PRINTF != 0 ) || ( ipconfigHAS_DEBUG_PRINTF != 0 ) - - void FreeRTOS_PrintARPCache( void ) - { - BaseType_t x, xCount = 0; + #if ( ipconfigHAS_PRINTF != 0 ) || ( ipconfigHAS_DEBUG_PRINTF != 0 ) - /* Loop through each entry in the ARP cache. */ - for( x = 0; x < ipconfigARP_CACHE_ENTRIES; x++ ) + void FreeRTOS_PrintARPCache( void ) { - if( ( xARPCache[ x ].ulIPAddress != 0U ) && ( xARPCache[ x ].ucAge > ( uint8_t ) 0U ) ) + BaseType_t x, xCount = 0; + + /* Loop through each entry in the ARP cache. */ + for( x = 0; x < ipconfigARP_CACHE_ENTRIES; x++ ) { - /* See if the MAC-address also matches, and we're all happy */ - FreeRTOS_printf( ( "ARP %2d: %3u - %16xip : %02x:%02x:%02x : %02x:%02x:%02x\n", - ( int ) x, - xARPCache[ x ].ucAge, - ( unsigned ) FreeRTOS_ntohl( xARPCache[ x ].ulIPAddress ), - xARPCache[ x ].xMACAddress.ucBytes[ 0 ], - xARPCache[ x ].xMACAddress.ucBytes[ 1 ], - xARPCache[ x ].xMACAddress.ucBytes[ 2 ], - xARPCache[ x ].xMACAddress.ucBytes[ 3 ], - xARPCache[ x ].xMACAddress.ucBytes[ 4 ], - xARPCache[ x ].xMACAddress.ucBytes[ 5 ] ) ); - xCount++; + if( ( xARPCache[ x ].ulIPAddress != 0U ) && ( xARPCache[ x ].ucAge > ( uint8_t ) 0U ) ) + { + /* See if the MAC-address also matches, and we're all happy */ + FreeRTOS_printf( ( "ARP %2d: %3u - %16xip : %02x:%02x:%02x : %02x:%02x:%02x\n", + ( int ) x, + xARPCache[ x ].ucAge, + ( unsigned ) FreeRTOS_ntohl( xARPCache[ x ].ulIPAddress ), + xARPCache[ x ].xMACAddress.ucBytes[ 0 ], + xARPCache[ x ].xMACAddress.ucBytes[ 1 ], + xARPCache[ x ].xMACAddress.ucBytes[ 2 ], + xARPCache[ x ].xMACAddress.ucBytes[ 3 ], + xARPCache[ x ].xMACAddress.ucBytes[ 4 ], + xARPCache[ x ].xMACAddress.ucBytes[ 5 ] ) ); + xCount++; + } } + + FreeRTOS_printf( ( "Arp has %ld entries\n", xCount ) ); } + #endif /* ( ipconfigHAS_PRINTF != 0 ) || ( ipconfigHAS_DEBUG_PRINTF != 0 ) */ - FreeRTOS_printf( ( "Arp has %ld entries\n", xCount ) ); - } -#endif /* ( ipconfigHAS_PRINTF != 0 ) || ( ipconfigHAS_DEBUG_PRINTF != 0 ) */ +#endif /* ( ipconfigUSE_IPv4 != 0 ) */ diff --git a/source/FreeRTOS_DHCP.c b/source/FreeRTOS_DHCP.c index bd1793349e..819d2c59e0 100644 --- a/source/FreeRTOS_DHCP.c +++ b/source/FreeRTOS_DHCP.c @@ -813,7 +813,6 @@ /* DHCP failed, the default configured IP-address will be used. Now * call vIPNetworkUpCalls() to send the network-up event and start the ARP * timer. */ - vIPNetworkUpCalls( pxEndPoint ); /* Close socket to ensure packets don't queue on it. */ diff --git a/source/FreeRTOS_DHCPv6.c b/source/FreeRTOS_DHCPv6.c index 4d637b4257..6bf6fc50a0 100644 --- a/source/FreeRTOS_DHCPv6.c +++ b/source/FreeRTOS_DHCPv6.c @@ -50,17 +50,12 @@ #include "FreeRTOS_DHCPv6.h" #include "FreeRTOS_DNS.h" #include "NetworkBufferManagement.h" -#include "FreeRTOS_ARP.h" #include "FreeRTOS_Sockets.h" #include "FreeRTOS_IP_Private.h" #include "FreeRTOS_IP_Timers.h" - #include "FreeRTOS_BitConfig.h" - #include "FreeRTOS_Routing.h" -#include "FreeRTOS_ND.h" - /* Timer parameters */ #ifndef dhcpINITIAL_DHCP_TX_PERIOD /** @brief DHCP timer period in ms */ @@ -531,7 +526,7 @@ static void vDHCPv6ProcessEndPoint_HandleReply( NetworkEndPoint_t * pxEndPoint, /* DHCP failed, the default configured IP-address will be used * Now call vIPNetworkUpCalls() to send the network-up event and - * start the ARP timer. */ + * start the Address Resolution timer. */ vIPNetworkUpCalls( pxEndPoint ); } /*-----------------------------------------------------------*/ @@ -823,8 +818,8 @@ static void vDHCPv6ProcessEndPoint( BaseType_t xReset, prvCloseDHCPv6Socket( pxEndPoint ); /* DHCP failed, the default configured IP-address will be used. Now - * call vIPNetworkUpCalls() to send the network-up event and start the ARP - * timer. */ + * call vIPNetworkUpCalls() to send the network-up event and start the + * Address Resolution timer. */ vIPNetworkUpCalls( pxEndPoint ); } } diff --git a/source/FreeRTOS_ICMP.c b/source/FreeRTOS_ICMP.c index 75e51bb79b..062922d5d3 100644 --- a/source/FreeRTOS_ICMP.c +++ b/source/FreeRTOS_ICMP.c @@ -46,7 +46,6 @@ #include "FreeRTOS_IP_Private.h" #include "FreeRTOS_ICMP.h" #include "FreeRTOS_Sockets.h" -#include "FreeRTOS_ARP.h" #include "FreeRTOS_UDP_IP.h" #include "FreeRTOS_DHCP.h" #include "NetworkInterface.h" diff --git a/source/FreeRTOS_IP.c b/source/FreeRTOS_IP.c index d1da106648..fded8c8516 100644 --- a/source/FreeRTOS_IP.c +++ b/source/FreeRTOS_IP.c @@ -49,6 +49,7 @@ #include "FreeRTOS_Sockets.h" #include "FreeRTOS_IP_Private.h" #include "FreeRTOS_ARP.h" +#include "FreeRTOS_ND.h" #include "FreeRTOS_UDP_IP.h" #include "FreeRTOS_DHCP.h" #if ( ipconfigUSE_DHCPv6 == 1 ) @@ -58,12 +59,12 @@ #include "NetworkBufferManagement.h" #include "FreeRTOS_DNS.h" #include "FreeRTOS_Routing.h" -#include "FreeRTOS_ND.h" /** @brief Time delay between repeated attempts to initialise the network hardware. */ #ifndef ipINITIALISATION_RETRY_DELAY #define ipINITIALISATION_RETRY_DELAY ( pdMS_TO_TICKS( 3000U ) ) #endif + #if ( ipconfigUSE_TCP_MEM_STATS != 0 ) #include "tcp_mem_stats.h" #endif @@ -73,16 +74,12 @@ #define ipARP_RESOLUTION_MAX_DELAY ( pdMS_TO_TICKS( 2000U ) ) #endif -#ifndef iptraceIP_TASK_STARTING - #define iptraceIP_TASK_STARTING() do {} while( ipFALSE_BOOL ) /**< Empty definition in case iptraceIP_TASK_STARTING is not defined. */ +/** @brief Maximum time to wait for a ND resolution while holding a packet. */ +#ifndef ipND_RESOLUTION_MAX_DELAY + #define ipND_RESOLUTION_MAX_DELAY ( pdMS_TO_TICKS( 2000U ) ) #endif -#if ( ( ipconfigUSE_TCP == 1 ) && !defined( ipTCP_TIMER_PERIOD_MS ) ) - /** @brief When initialising the TCP timer, give it an initial time-out of 1 second. */ - #define ipTCP_TIMER_PERIOD_MS ( 1000U ) -#endif - -/** @brief Defines how often the ARP timer callback function is executed. The time is +/** @brief Defines how often the ARP resolution timer callback function is executed. The time is * shorter in the Windows simulator as simulated time is not real time. */ #ifndef ipARP_TIMER_PERIOD_MS #ifdef _WINDOWS_ @@ -92,6 +89,25 @@ #endif #endif +/** @brief Defines how often the ND resolution timer callback function is executed. The time is + * shorter in the Windows simulator as simulated time is not real time. */ +#ifndef ipND_TIMER_PERIOD_MS + #ifdef _WINDOWS_ + #define ipND_TIMER_PERIOD_MS ( 500U ) /* For windows simulator builds. */ + #else + #define ipND_TIMER_PERIOD_MS ( 10000U ) + #endif +#endif + +#if ( ( ipconfigUSE_TCP == 1 ) && !defined( ipTCP_TIMER_PERIOD_MS ) ) + /** @brief When initialising the TCP timer, give it an initial time-out of 1 second. */ + #define ipTCP_TIMER_PERIOD_MS ( 1000U ) +#endif + +#ifndef iptraceIP_TASK_STARTING + #define iptraceIP_TASK_STARTING() do {} while( ipFALSE_BOOL ) /**< Empty definition in case iptraceIP_TASK_STARTING is not defined. */ +#endif + /** @brief The frame type field in the Ethernet header must have a value greater than 0x0600. * If the configuration option ipconfigFILTER_OUT_NON_ETHERNET_II_FRAMES is enabled, the stack * will discard packets with a frame type value less than or equal to 0x0600. @@ -107,7 +123,14 @@ static void prvIPTask_CheckPendingEvents( void ); /*-----------------------------------------------------------*/ /** @brief The pointer to buffer with packet waiting for ARP resolution. */ -NetworkBufferDescriptor_t * pxARPWaitingNetworkBuffer = NULL; +#if ipconfigIS_ENABLED( ipconfigUSE_IPv4 ) + NetworkBufferDescriptor_t * pxARPWaitingNetworkBuffer = NULL; +#endif + +/** @brief The pointer to buffer with packet waiting for ND resolution. */ +#if ipconfigIS_ENABLED( ipconfigUSE_IPv6 ) + NetworkBufferDescriptor_t * pxNDWaitingNetworkBuffer = NULL; +#endif /*-----------------------------------------------------------*/ @@ -238,7 +261,7 @@ static void prvProcessIPEventsAndTimers( void ) ipconfigWATCHDOG_TIMER(); - /* Check the ARP, DHCP and TCP timers to see if there is any periodic + /* Check the Resolution, DHCP and TCP timers to see if there is any periodic * or timeout processing to perform. */ vCheckNetworkTimers(); @@ -294,15 +317,17 @@ static void prvProcessIPEventsAndTimers( void ) break; case eARPTimerEvent: - /* The ARP timer has expired, process the ARP cache. */ - #if ( ipconfigUSE_IPv4 != 0 ) + /* The ARP Resolution timer has expired, process the cache. */ + #if ipconfigIS_ENABLED( ipconfigUSE_IPv4 ) vARPAgeCache(); #endif /* ( ipconfigUSE_IPv4 != 0 ) */ + break; - #if ( ipconfigUSE_IPv6 != 0 ) + case eNDTimerEvent: + /* The ND Resolution timer has expired, process the cache. */ + #if ipconfigIS_ENABLED( ipconfigUSE_IPv6 ) vNDAgeCache(); #endif /* ( ipconfigUSE_IPv6 != 0 ) */ - break; case eSocketBindEvent: @@ -493,8 +518,15 @@ static void prvIPTask_Initialise( void ) } #endif - /* Mark the timer as inactive since we are not waiting on any ARP resolution as of now. */ - vIPSetARPResolutionTimerEnableState( pdFALSE ); + #if ipconfigIS_ENABLED( ipconfigUSE_IPv4 ) + /* Mark the ARP timer as inactive since we are not waiting on any resolution as of now. */ + vIPSetARPResolutionTimerEnableState( pdFALSE ); + #endif + + #if ipconfigIS_ENABLED( ipconfigUSE_IPv6 ) + /* Mark the ND timer as inactive since we are not waiting on any resolution as of now. */ + vIPSetNDResolutionTimerEnableState( pdFALSE ); + #endif #if ( ( ipconfigDNS_USE_CALLBACKS != 0 ) && ( ipconfigUSE_DNS != 0 ) ) { @@ -648,7 +680,18 @@ void vIPNetworkUpCalls( struct xNetworkEndPoint * pxEndPoint ) #endif /* ipconfigDNS_USE_CALLBACKS != 0 */ /* Set remaining time to 0 so it will become active immediately. */ - vARPTimerReload( pdMS_TO_TICKS( ipARP_TIMER_PERIOD_MS ) ); + if( pxEndPoint->bits.bIPv6 == pdTRUE_UNSIGNED ) + { + #if ipconfigIS_ENABLED( ipconfigUSE_IPv6 ) + vNDTimerReload( pdMS_TO_TICKS( ipND_TIMER_PERIOD_MS ) ); + #endif + } + else + { + #if ipconfigIS_ENABLED( ipconfigUSE_IPv4 ) + vARPTimerReload( pdMS_TO_TICKS( ipARP_TIMER_PERIOD_MS ) ); + #endif + } } /*-----------------------------------------------------------*/ @@ -1718,7 +1761,7 @@ static void prvProcessEthernetPacket( NetworkBufferDescriptor_t * const pxNetwor case eReturnEthernetFrame: /* The Ethernet frame will have been updated (maybe it was - * an ARP request or a PING request?) and should be sent back to + * a resolution request or a PING request?) and should be sent back to * its source. */ vReturnEthernetFrame( pxNetworkBuffer, pdTRUE ); @@ -1732,21 +1775,54 @@ static void prvProcessEthernetPacket( NetworkBufferDescriptor_t * const pxNetwor * yet. */ break; - case eWaitingARPResolution: + case eWaitingResolution: + + if( ( pxEthernetHeader->usFrameType == ipIPv4_FRAME_TYPE ) || ( pxEthernetHeader->usFrameType == ipARP_FRAME_TYPE ) ) + { + #if ipconfigIS_ENABLED( ipconfigUSE_IPv4 ) + if( pxARPWaitingNetworkBuffer == NULL ) + { + pxARPWaitingNetworkBuffer = pxNetworkBuffer; + vIPTimerStartARPResolution( ipARP_RESOLUTION_MAX_DELAY ); + + iptraceDELAYED_ARP_REQUEST_STARTED(); + } + else + #endif /* if ipconfigIS_ENABLED( ipconfigUSE_IPv4 ) */ + { + /* We are already waiting on one resolution. This frame will be dropped. */ + vReleaseNetworkBufferAndDescriptor( pxNetworkBuffer ); + + iptraceDELAYED_ARP_BUFFER_FULL(); + } - if( pxARPWaitingNetworkBuffer == NULL ) + break; + } + else if( pxEthernetHeader->usFrameType == ipIPv6_FRAME_TYPE ) { - pxARPWaitingNetworkBuffer = pxNetworkBuffer; - vIPTimerStartARPResolution( ipARP_RESOLUTION_MAX_DELAY ); + #if ipconfigIS_ENABLED( ipconfigUSE_IPv6 ) + if( pxNDWaitingNetworkBuffer == NULL ) + { + pxNDWaitingNetworkBuffer = pxNetworkBuffer; + vIPTimerStartNDResolution( ipND_RESOLUTION_MAX_DELAY ); + + iptraceDELAYED_ND_REQUEST_STARTED(); + } + else + #endif /* if ipconfigIS_ENABLED( ipconfigUSE_IPv6 ) */ + { + /* We are already waiting on one resolution. This frame will be dropped. */ + vReleaseNetworkBufferAndDescriptor( pxNetworkBuffer ); - iptraceDELAYED_ARP_REQUEST_STARTED(); + iptraceDELAYED_ND_BUFFER_FULL(); + } + + break; } else { - /* We are already waiting on one ARP resolution. This frame will be dropped. */ + /* Unknown frame type, drop the packet. */ vReleaseNetworkBufferAndDescriptor( pxNetworkBuffer ); - - iptraceDELAYED_ARP_BUFFER_FULL(); } break; @@ -1775,7 +1851,7 @@ static void prvProcessEthernetPacket( NetworkBufferDescriptor_t * const pxNetwor static eFrameProcessingResult_t prvProcessUDPPacket( NetworkBufferDescriptor_t * const pxNetworkBuffer ) { eFrameProcessingResult_t eReturn = eReleaseBuffer; - BaseType_t xIsWaitingARPResolution = pdFALSE; + BaseType_t xIsWaitingResolution = pdFALSE; /* The IP packet contained a UDP frame. */ /* MISRA Ref 11.3.1 [Misaligned access] */ /* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */ @@ -1847,16 +1923,16 @@ static eFrameProcessingResult_t prvProcessUDPPacket( NetworkBufferDescriptor_t * * implementation. */ if( xProcessReceivedUDPPacket( pxNetworkBuffer, pxUDPHeader->usDestinationPort, - &( xIsWaitingARPResolution ) ) == pdPASS ) + &( xIsWaitingResolution ) ) == pdPASS ) { eReturn = eFrameConsumed; } else { - /* Is this packet to be set aside for ARP resolution. */ - if( xIsWaitingARPResolution == pdTRUE ) + /* Is this packet to be set aside for resolution. */ + if( xIsWaitingResolution == pdTRUE ) { - eReturn = eWaitingARPResolution; + eReturn = eWaitingResolution; } } } @@ -2014,21 +2090,21 @@ static eFrameProcessingResult_t prvProcessIPPacket( const IPPacket_t * pxIPPacke /* coverity[const] */ if( eReturn != eReleaseBuffer ) { - /* Add the IP and MAC addresses to the ARP table if they are not + /* Add the IP and MAC addresses to the cache if they are not * already there - otherwise refresh the age of the existing * entry. */ if( ucProtocol != ( uint8_t ) ipPROTOCOL_UDP ) { - if( xCheckRequiresARPResolution( pxNetworkBuffer ) == pdTRUE ) + if( xCheckRequiresResolution( pxNetworkBuffer ) == pdTRUE ) { - eReturn = eWaitingARPResolution; + eReturn = eWaitingResolution; } else { - /* Refresh the ARP cache with the IP/MAC-address of the received + /* Refresh the cache with the IP/MAC-address of the received * packet. For UDP packets, this will be done later in * xProcessReceivedUDPPacket(), as soon as it's know that the message - * will be handled. This will prevent the ARP cache getting + * will be handled. This will prevent the cache getting * overwritten with the IP address of useless broadcast packets. */ /* Case default is never toggled because eReturn is not eProcessBuffer in previous step. */ switch( pxIPPacket->xEthernetHeader.usFrameType ) /* LCOV_EXCL_BR_LINE */ @@ -2054,7 +2130,7 @@ static eFrameProcessingResult_t prvProcessIPPacket( const IPPacket_t * pxIPPacke } } - if( eReturn != eWaitingARPResolution ) + if( eReturn != eWaitingResolution ) { switch( ucProtocol ) { @@ -2171,7 +2247,7 @@ void vReturnEthernetFrame( NetworkBufferDescriptor_t * pxNetworkBuffer, #if ( ipconfigUSE_IPv4 != 0 ) MACAddress_t xMACAddress; - eARPLookupResult_t eResult; + eResolutionLookupResult_t eResult; uint32_t ulDestinationIPAddress = 0U; #endif /* ( ipconfigUSE_IPv4 != 0 ) */ @@ -2219,7 +2295,7 @@ void vReturnEthernetFrame( NetworkBufferDescriptor_t * pxNetworkBuffer, * address. */ eResult = eARPGetCacheEntry( &ulDestinationIPAddress, &xMACAddress, &( pxNetworkBuffer->pxEndPoint ) ); - if( eResult == eARPCacheHit ) + if( eResult == eResolutionCacheHit ) { /* Best case scenario - an address is found, use it. */ pvCopySource = &xMACAddress; @@ -2235,7 +2311,7 @@ void vReturnEthernetFrame( NetworkBufferDescriptor_t * pxNetworkBuffer, case ipIPv6_FRAME_TYPE: case ipARP_FRAME_TYPE: default: - /* In case of ARP frame, just swap the source and destination MAC addresses. */ + /* Just swap the source and destination MAC addresses. */ pvCopySource = &( pxIPPacket->xEthernetHeader.xSourceAddress ); break; } @@ -2262,7 +2338,7 @@ void vReturnEthernetFrame( NetworkBufferDescriptor_t * pxNetworkBuffer, { IPStackEvent_t xSendEvent; - /* Send a message to the IP-task to send this ARP packet. */ + /* Send a message to the IP-task to send this packet. */ xSendEvent.eEventType = eNetworkTxEvent; xSendEvent.pvData = pxNetworkBuffer; diff --git a/source/FreeRTOS_IP_Timers.c b/source/FreeRTOS_IP_Timers.c index 09b2bd6b39..2edf0c6759 100644 --- a/source/FreeRTOS_IP_Timers.c +++ b/source/FreeRTOS_IP_Timers.c @@ -47,10 +47,10 @@ #include "FreeRTOS_IP_Utils.h" #include "FreeRTOS_Sockets.h" #include "FreeRTOS_IP_Private.h" -#include "FreeRTOS_ARP.h" -#include "FreeRTOS_ND.h" #include "FreeRTOS_UDP_IP.h" #include "FreeRTOS_DHCP.h" +#include "FreeRTOS_ARP.h" +#include "FreeRTOS_ND.h" #include "NetworkInterface.h" #include "NetworkBufferManagement.h" #include "FreeRTOS_Routing.h" @@ -94,13 +94,24 @@ static void prvIPTimerReload( IPTimer_t * pxTimer, * regular basis */ +#if ipconfigIS_ENABLED( ipconfigUSE_IPv4 ) + /** @brief Timer to limit the maximum time a packet should be stored while * awaiting an ARP resolution. */ -static IPTimer_t xARPResolutionTimer; + static IPTimer_t xARPResolutionTimer; /** @brief ARP timer, to check its table entries. */ -static IPTimer_t xARPTimer; + static IPTimer_t xARPTimer; +#endif +#if ipconfigIS_ENABLED( ipconfigUSE_IPv6 ) + +/** @brief Timer to limit the maximum time a packet should be stored while + * awaiting an ND resolution. */ + static IPTimer_t xNDResolutionTimer; +/** @brief ND timer, to check its table entries. */ + static IPTimer_t xNDTimer; +#endif #if ( ipconfigUSE_TCP != 0 ) /** @brief TCP timer, to check for timeouts, resends. */ static IPTimer_t xTCPTimer; @@ -137,13 +148,25 @@ TickType_t xCalculateSleepTime( void ) * time in any other timers that are active. */ uxMaximumSleepTime = ipconfigMAX_IP_TASK_SLEEP_TIME; - if( xARPTimer.bActive != pdFALSE_UNSIGNED ) - { - if( xARPTimer.ulRemainingTime < uxMaximumSleepTime ) + #if ipconfigIS_ENABLED( ipconfigUSE_IPv4 ) + if( xARPTimer.bActive != pdFALSE_UNSIGNED ) { - uxMaximumSleepTime = xARPTimer.ulRemainingTime; + if( xARPTimer.ulRemainingTime < uxMaximumSleepTime ) + { + uxMaximumSleepTime = xARPTimer.ulRemainingTime; + } } - } + #endif + + #if ipconfigIS_ENABLED( ipconfigUSE_IPv6 ) + if( xNDTimer.bActive != pdFALSE_UNSIGNED ) + { + if( xNDTimer.ulRemainingTime < uxMaximumSleepTime ) + { + uxMaximumSleepTime = xNDTimer.ulRemainingTime; + } + } + #endif #if ( ipconfigUSE_DHCP == 1 ) || ( ipconfigUSE_RA == 1 ) { @@ -193,7 +216,7 @@ TickType_t xCalculateSleepTime( void ) /*-----------------------------------------------------------*/ /** - * @brief Check the network timers (ARP/DHCP/DNS/TCP) and if they are + * @brief Check the network timers (ARP/ND/DHCP/DNS/TCP) and if they are * expired, send an event to the IP-Task. */ /* MISRA Ref 8.9.1 [File scoped variables] */ @@ -204,30 +227,59 @@ void vCheckNetworkTimers( void ) { NetworkInterface_t * pxInterface; - /* Is it time for ARP processing? */ - if( prvIPTimerCheck( &xARPTimer ) != pdFALSE ) - { - ( void ) xSendEventToIPTask( eARPTimerEvent ); - } + #if ipconfigIS_ENABLED( ipconfigUSE_IPv4 ) + /* Is it time for ARP processing? */ + if( prvIPTimerCheck( &xARPTimer ) != pdFALSE ) + { + ( void ) xSendEventToIPTask( eARPTimerEvent ); + } - /* Is the ARP resolution timer expired? */ - if( prvIPTimerCheck( &xARPResolutionTimer ) != pdFALSE ) - { - if( pxARPWaitingNetworkBuffer != NULL ) + /* Is the ARP resolution timer expired? */ + if( prvIPTimerCheck( &xARPResolutionTimer ) != pdFALSE ) { - /* Disable the ARP resolution timer. */ - vIPSetARPResolutionTimerEnableState( pdFALSE ); + if( pxARPWaitingNetworkBuffer != NULL ) + { + /* Disable the ARP resolution timer. */ + vIPSetARPResolutionTimerEnableState( pdFALSE ); - /* We have waited long enough for the ARP response. Now, free the network - * buffer. */ - vReleaseNetworkBufferAndDescriptor( pxARPWaitingNetworkBuffer ); + /* We have waited long enough for the ARP response. Now, free the network + * buffer. */ + vReleaseNetworkBufferAndDescriptor( pxARPWaitingNetworkBuffer ); - /* Clear the pointer. */ - pxARPWaitingNetworkBuffer = NULL; + /* Clear the pointer. */ + pxARPWaitingNetworkBuffer = NULL; - iptraceDELAYED_ARP_TIMER_EXPIRED(); + iptraceDELAYED_ARP_TIMER_EXPIRED(); + } } - } + #endif /* if ipconfigIS_ENABLED( ipconfigUSE_IPv4 ) */ + + #if ipconfigIS_ENABLED( ipconfigUSE_IPv6 ) + /* Is it time for ND processing? */ + if( prvIPTimerCheck( &xNDTimer ) != pdFALSE ) + { + ( void ) xSendEventToIPTask( eNDTimerEvent ); + } + + /* Is the ND resolution timer expired? */ + if( prvIPTimerCheck( &xNDResolutionTimer ) != pdFALSE ) + { + if( pxNDWaitingNetworkBuffer != NULL ) + { + /* Disable the ND resolution timer. */ + vIPSetNDResolutionTimerEnableState( pdFALSE ); + + /* We have waited long enough for the ND response. Now, free the network + * buffer. */ + vReleaseNetworkBufferAndDescriptor( pxNDWaitingNetworkBuffer ); + + /* Clear the pointer. */ + pxNDWaitingNetworkBuffer = NULL; + + iptraceDELAYED_ND_TIMER_EXPIRED(); + } + } + #endif /* if ipconfigIS_ENABLED( ipconfigUSE_IPv6 ) */ #if ( ipconfigUSE_DHCP == 1 ) || ( ipconfigUSE_RA == 1 ) { @@ -360,15 +412,32 @@ static void prvIPTimerStart( IPTimer_t * pxTimer, } /*-----------------------------------------------------------*/ +#if ipconfigIS_ENABLED( ipconfigUSE_IPv4 ) + /** * @brief Start an ARP Resolution timer. * * @param[in] xTime Time to be loaded into the ARP Resolution timer. */ -void vIPTimerStartARPResolution( TickType_t xTime ) -{ - prvIPTimerStart( &( xARPResolutionTimer ), xTime ); -} + void vIPTimerStartARPResolution( TickType_t xTime ) + { + prvIPTimerStart( &( xARPResolutionTimer ), xTime ); + } +#endif +/*-----------------------------------------------------------*/ + +#if ipconfigIS_ENABLED( ipconfigUSE_IPv6 ) + +/** + * @brief Start an ND Resolution timer. + * + * @param[in] xTime Time to be loaded into the ND Resolution timer. + */ + void vIPTimerStartNDResolution( TickType_t xTime ) + { + prvIPTimerStart( &( xNDResolutionTimer ), xTime ); + } +#endif /*-----------------------------------------------------------*/ /** @@ -399,16 +468,32 @@ static void prvIPTimerReload( IPTimer_t * pxTimer, #endif /*-----------------------------------------------------------*/ +#if ipconfigIS_ENABLED( ipconfigUSE_IPv4 ) + /** * @brief Sets the reload time of the ARP timer and restarts it. * * @param[in] xTime Time to be reloaded into the ARP timer. */ -void vARPTimerReload( TickType_t xTime ) -{ - prvIPTimerReload( &xARPTimer, xTime ); -} + void vARPTimerReload( TickType_t xTime ) + { + prvIPTimerReload( &xARPTimer, xTime ); + } +#endif +/*-----------------------------------------------------------*/ + +#if ipconfigIS_ENABLED( ipconfigUSE_IPv6 ) +/** + * @brief Sets the reload time of the ND timer and restarts it. + * + * @param[in] xTime Time to be reloaded into the ND timer. + */ + void vNDTimerReload( TickType_t xTime ) + { + prvIPTimerReload( &xNDTimer, xTime ); + } +#endif /*-----------------------------------------------------------*/ #if ( ipconfigDNS_USE_CALLBACKS != 0 ) @@ -520,40 +605,82 @@ static BaseType_t prvIPTimerCheck( IPTimer_t * pxTimer ) #endif /* if ( ipconfigUSE_TCP == 1 ) */ /*-----------------------------------------------------------*/ +#if ipconfigIS_ENABLED( ipconfigUSE_IPv4 ) + /** * @brief Enable/disable the ARP timer. * * @param[in] xEnableState pdTRUE - enable timer; pdFALSE - disable timer. */ -void vIPSetARPTimerEnableState( BaseType_t xEnableState ) -{ - if( xEnableState != pdFALSE ) + void vIPSetARPTimerEnableState( BaseType_t xEnableState ) { - xARPTimer.bActive = pdTRUE_UNSIGNED; + if( xEnableState != pdFALSE ) + { + xARPTimer.bActive = pdTRUE_UNSIGNED; + } + else + { + xARPTimer.bActive = pdFALSE_UNSIGNED; + } } - else + /*-----------------------------------------------------------*/ + +/** + * @brief Enable or disable the ARP resolution timer. + * + * @param[in] xEnableState pdTRUE if the timer must be enabled, pdFALSE otherwise. + */ + void vIPSetARPResolutionTimerEnableState( BaseType_t xEnableState ) { - xARPTimer.bActive = pdFALSE_UNSIGNED; + if( xEnableState != pdFALSE ) + { + xARPResolutionTimer.bActive = pdTRUE_UNSIGNED; + } + else + { + xARPResolutionTimer.bActive = pdFALSE_UNSIGNED; + } } -} +#endif /* if ipconfigIS_ENABLED( ipconfigUSE_IPv4 ) */ /*-----------------------------------------------------------*/ +#if ipconfigIS_ENABLED( ipconfigUSE_IPv6 ) + /** - * @brief Enable or disable the ARP resolution timer. + * @brief Enable/disable the ND timer. * - * @param[in] xEnableState pdTRUE if the timer must be enabled, pdFALSE otherwise. + * @param[in] xEnableState pdTRUE - enable timer; pdFALSE - disable timer. */ -void vIPSetARPResolutionTimerEnableState( BaseType_t xEnableState ) -{ - if( xEnableState != pdFALSE ) + void vIPSetNDTimerEnableState( BaseType_t xEnableState ) { - xARPResolutionTimer.bActive = pdTRUE_UNSIGNED; + if( xEnableState != pdFALSE ) + { + xNDTimer.bActive = pdTRUE_UNSIGNED; + } + else + { + xNDTimer.bActive = pdFALSE_UNSIGNED; + } } - else + /*-----------------------------------------------------------*/ + +/** + * @brief Enable or disable the ND resolution timer. + * + * @param[in] xEnableState pdTRUE if the timer must be enabled, pdFALSE otherwise. + */ + void vIPSetNDResolutionTimerEnableState( BaseType_t xEnableState ) { - xARPResolutionTimer.bActive = pdFALSE_UNSIGNED; + if( xEnableState != pdFALSE ) + { + xNDResolutionTimer.bActive = pdTRUE_UNSIGNED; + } + else + { + xNDResolutionTimer.bActive = pdFALSE_UNSIGNED; + } } -} +#endif /* if ipconfigIS_ENABLED( ipconfigUSE_IPv6 ) */ /*-----------------------------------------------------------*/ #if ( ipconfigUSE_DHCP == 1 ) || ( ipconfigUSE_RA == 1 ) || ( ipconfigUSE_DHCPv6 == 1 ) diff --git a/source/FreeRTOS_IP_Utils.c b/source/FreeRTOS_IP_Utils.c index b2d36f5195..f7491c6390 100644 --- a/source/FreeRTOS_IP_Utils.c +++ b/source/FreeRTOS_IP_Utils.c @@ -48,13 +48,13 @@ #include "FreeRTOS_Sockets.h" #include "FreeRTOS_IP_Private.h" #include "FreeRTOS_ARP.h" +#include "FreeRTOS_ND.h" #include "FreeRTOS_UDP_IP.h" #include "FreeRTOS_DHCP.h" #include "NetworkInterface.h" #include "NetworkBufferManagement.h" #include "FreeRTOS_DNS.h" #include "FreeRTOS_Routing.h" -#include "FreeRTOS_ND.h" /*-----------------------------------------------------------*/ /* Used to ensure the structure packing is having the desired effect. The @@ -822,8 +822,13 @@ void prvProcessNetworkDownEvent( struct xNetworkInterface * pxInterface ) configASSERT( pxInterface != NULL ); configASSERT( pxInterface->pfInitialise != NULL ); - /* Stop the ARP timer while there is no network. */ - vIPSetARPTimerEnableState( pdFALSE ); + /* Stop the Address Resolution timer while there is no network. */ + #if ipconfigIS_ENABLED( ipconfigUSE_IPv4 ) + vIPSetARPTimerEnableState( pdFALSE ); + #endif + #if ipconfigIS_ENABLED( ipconfigUSE_IPv6 ) + vIPSetNDTimerEnableState( pdFALSE ); + #endif /* The first network down event is generated by the IP stack itself to * initialise the network hardware, so do not call the network down event @@ -866,10 +871,17 @@ void prvProcessNetworkDownEvent( struct xNetworkInterface * pxInterface ) } #endif /* ipconfigUSE_NETWORK_EVENT_HOOK */ - /* Per the ARP Cache Validation section of https://tools.ietf.org/html/rfc1122 - * treat network down as a "delivery problem" and flush the ARP cache for this - * interface. */ - FreeRTOS_ClearARP( pxEndPoint ); + #if ipconfigIS_ENABLED( ipconfigUSE_IPv4 ) + + /* Per the ARP Cache Validation section of https://tools.ietf.org/html/rfc1122 + * treat network down as a "delivery problem" and flush the ARP cache for this + * interface. */ + FreeRTOS_ClearARP( pxEndPoint ); + #endif + + #if ipconfigIS_ENABLED( ipconfigUSE_IPv6 ) + FreeRTOS_ClearND( pxEndPoint ); + #endif #if ( ipconfigUSE_DHCP == 1 ) if( END_POINT_USES_DHCP( pxEndPoint ) ) diff --git a/source/FreeRTOS_ND.c b/source/FreeRTOS_ND.c index d5c55e478e..62d100ed66 100644 --- a/source/FreeRTOS_ND.c +++ b/source/FreeRTOS_ND.c @@ -41,7 +41,6 @@ #include "FreeRTOS_IP.h" #include "FreeRTOS_Sockets.h" #include "FreeRTOS_IP_Private.h" -#include "FreeRTOS_ARP.h" #include "FreeRTOS_UDP_IP.h" #include "FreeRTOS_Routing.h" #include "FreeRTOS_ND.h" @@ -79,14 +78,14 @@ const uint8_t pcLOCAL_ALL_NODES_MULTICAST_MAC[ ipMAC_ADDRESS_LENGTH_BYTES ] = { 0x33U, 0x33U, 0x00U, 0x00U, 0x00U, 0x01U }; /** @brief See if the MAC-address can be resolved because it is a multi-cast address. */ - static eARPLookupResult_t prvMACResolve( const IPv6_Address_t * pxAddressToLookup, - MACAddress_t * const pxMACAddress, - NetworkEndPoint_t ** ppxEndPoint ); + static eResolutionLookupResult_t prvMACResolve( const IPv6_Address_t * pxAddressToLookup, + MACAddress_t * const pxMACAddress, + NetworkEndPoint_t ** ppxEndPoint ); /** @brief Lookup an MAC address in the ND cache from the IP address. */ - static eARPLookupResult_t prvNDCacheLookup( const IPv6_Address_t * pxAddressToLookup, - MACAddress_t * const pxMACAddress, - NetworkEndPoint_t ** ppxEndPoint ); + static eResolutionLookupResult_t prvNDCacheLookup( const IPv6_Address_t * pxAddressToLookup, + MACAddress_t * const pxMACAddress, + NetworkEndPoint_t ** ppxEndPoint ); #if ( ipconfigHAS_PRINTF == 1 ) static const char * pcMessageType( BaseType_t xType ); @@ -98,6 +97,10 @@ /** @brief The ND cache. */ static NDCacheRow_t xNDCache[ ipconfigND_CACHE_ENTRIES ]; +/** @brief The time at which the last unsolicited ND was sent. Unsolicited NDs are used + * to ensure ND tables are up to date and to detect IP address conflicts. */ + static TickType_t xLastUnsolicitedNDTime = 0U; + /*-----------------------------------------------------------*/ /* @@ -141,13 +144,13 @@ * @param[out] pxMACAddress The resulting MAC-address is stored here. * @param[out] ppxEndPoint A pointer to an end-point pointer where the end-point will be stored. * - * @return An enum, either eARPCacheHit or eARPCacheMiss. + * @return An enum, either eResolutionCacheHit or eResolutionCacheMiss. */ - static eARPLookupResult_t prvMACResolve( const IPv6_Address_t * pxAddressToLookup, - MACAddress_t * const pxMACAddress, - NetworkEndPoint_t ** ppxEndPoint ) + static eResolutionLookupResult_t prvMACResolve( const IPv6_Address_t * pxAddressToLookup, + MACAddress_t * const pxMACAddress, + NetworkEndPoint_t ** ppxEndPoint ) { - eARPLookupResult_t eReturn; + eResolutionLookupResult_t eReturn; /* Mostly used multi-cast address is ff02::. */ if( xIsIPv6AllowedMulticast( pxAddressToLookup ) != pdFALSE ) @@ -159,12 +162,12 @@ *ppxEndPoint = pxFindLocalEndpoint(); } - eReturn = eARPCacheHit; + eReturn = eResolutionCacheHit; } else { /* Not a multicast IP address. */ - eReturn = eARPCacheMiss; + eReturn = eResolutionCacheMiss; } return eReturn; @@ -179,30 +182,30 @@ * @param[out] pxMACAddress The MAC-address found. * @param[out] ppxEndPoint A pointer to a pointer to an end-point, where the end-point will be stored. * - * @return An enum which says whether the address was found: eARPCacheHit or eARPCacheMiss. + * @return An enum which says whether the address was found: eResolutionCacheHit or eResolutionCacheMiss. */ - eARPLookupResult_t eNDGetCacheEntry( IPv6_Address_t * pxIPAddress, - MACAddress_t * const pxMACAddress, - struct xNetworkEndPoint ** ppxEndPoint ) + eResolutionLookupResult_t eNDGetCacheEntry( IPv6_Address_t * pxIPAddress, + MACAddress_t * const pxMACAddress, + struct xNetworkEndPoint ** ppxEndPoint ) { - eARPLookupResult_t eReturn; + eResolutionLookupResult_t eReturn; NetworkEndPoint_t * pxEndPoint; /* Multi-cast addresses can be resolved immediately. */ eReturn = prvMACResolve( pxIPAddress, pxMACAddress, ppxEndPoint ); - if( eReturn == eARPCacheMiss ) + if( eReturn == eResolutionCacheMiss ) { /* See if the IP-address has an entry in the cache. */ eReturn = prvNDCacheLookup( pxIPAddress, pxMACAddress, ppxEndPoint ); } - if( eReturn == eARPCacheMiss ) + if( eReturn == eResolutionCacheMiss ) { FreeRTOS_printf( ( "eNDGetCacheEntry: lookup %pip miss\n", ( void * ) pxIPAddress->ucBytes ) ); } - if( eReturn == eARPCacheMiss ) + if( eReturn == eResolutionCacheMiss ) { IPv6_Type_t eIPType = xIPv6_GetIPType( pxIPAddress ); @@ -237,7 +240,7 @@ } FreeRTOS_printf( ( "eNDGetCacheEntry: LinkLocal %pip \"%s\"\n", ( void * ) pxIPAddress->ucBytes, - ( eReturn == eARPCacheHit ) ? "hit" : "miss" ) ); + ( eReturn == eResolutionCacheHit ) ? "hit" : "miss" ) ); } else { @@ -282,7 +285,7 @@ { BaseType_t x; BaseType_t xFreeEntry = -1, xEntryFound = -1; - uint16_t xOldestValue = ipconfigMAX_ARP_AGE + 1; + uint16_t xOldestValue = ipconfigMAX_ND_AGE + 1; BaseType_t xOldestEntry = 0; /* For each entry in the ND cache table. */ @@ -305,10 +308,10 @@ /* Entry is valid but the IP-address doesn't match. */ /* Keep track of the oldest entry in case we need to overwrite it. The problem we are trying to avoid is - * that there may be a queued packet in pxARPWaitingNetworkBuffer and we may have just received the + * that there may be a queued packet in pxNDWaitingNetworkBuffer and we may have just received the * neighbor advertisement needed for that packet. If we don't store this network advertisement in cache, - * the parting of the frame from pxARPWaitingNetworkBuffer will cause the sending of neighbor solicitation - * and stores the frame in pxARPWaitingNetworkBuffer. This becomes a vicious circle with thousands of + * the parting of the frame from pxNDWaitingNetworkBuffer will cause the sending of neighbor solicitation + * and stores the frame in pxNDWaitingNetworkBuffer. This becomes a vicious circle with thousands of * neighbor solicitation/advertisement packets going back and forth because the ND cache is full. * Overwriting the oldest cache entry is not a fool-proof solution, but it's something. */ if( xNDCache[ x ].ucAge < xOldestValue ) @@ -340,7 +343,7 @@ /* Copy the MAC-address. */ ( void ) memcpy( xNDCache[ xEntryFound ].xMACAddress.ucBytes, pxMACAddress->ucBytes, sizeof( MACAddress_t ) ); xNDCache[ xEntryFound ].pxEndPoint = pxEndPoint; - xNDCache[ xEntryFound ].ucAge = ( uint8_t ) ipconfigMAX_ARP_AGE; + xNDCache[ xEntryFound ].ucAge = ( uint8_t ) ipconfigMAX_ND_AGE; xNDCache[ xEntryFound ].ucValid = ( uint8_t ) pdTRUE; } /*-----------------------------------------------------------*/ @@ -414,11 +417,28 @@ /*-----------------------------------------------------------*/ /** - * @brief Clear the Neighbour Discovery cache. + * @brief A call to this function will clear the ND cache. + * @param[in] pxEndPoint only clean entries with this end-point, or when NULL, + * clear the entire ND cache. */ - void FreeRTOS_ClearND( void ) + void FreeRTOS_ClearND( const struct xNetworkEndPoint * pxEndPoint ) { - ( void ) memset( xNDCache, 0, sizeof( xNDCache ) ); + if( pxEndPoint != NULL ) + { + BaseType_t x; + + for( x = 0; x < ipconfigND_CACHE_ENTRIES; x++ ) + { + if( xNDCache[ x ].pxEndPoint == pxEndPoint ) + { + ( void ) memset( &( xNDCache[ x ] ), 0, sizeof( NDCacheRow_t ) ); + } + } + } + else + { + ( void ) memset( xNDCache, 0, sizeof( xNDCache ) ); + } } /*-----------------------------------------------------------*/ @@ -429,14 +449,14 @@ * @param[out] pxMACAddress The resulting MAC-address will be stored here. * @param[out] ppxEndPoint A pointer to a pointer to an end-point, where the end-point will be stored. * - * @return An enum: either eARPCacheHit or eARPCacheMiss. + * @return An enum: either eResolutionCacheHit or eResolutionCacheMiss. */ - static eARPLookupResult_t prvNDCacheLookup( const IPv6_Address_t * pxAddressToLookup, - MACAddress_t * const pxMACAddress, - NetworkEndPoint_t ** ppxEndPoint ) + static eResolutionLookupResult_t prvNDCacheLookup( const IPv6_Address_t * pxAddressToLookup, + MACAddress_t * const pxMACAddress, + NetworkEndPoint_t ** ppxEndPoint ) { BaseType_t x; - eARPLookupResult_t eReturn = eARPCacheMiss; + eResolutionLookupResult_t eReturn = eResolutionCacheMiss; /* For each entry in the ND cache table. */ for( x = 0; x < ipconfigND_CACHE_ENTRIES; x++ ) @@ -448,7 +468,7 @@ else if( memcmp( xNDCache[ x ].xIPAddress.ucBytes, pxAddressToLookup->ucBytes, ipSIZE_OF_IPv6_ADDRESS ) == 0 ) { ( void ) memcpy( pxMACAddress->ucBytes, xNDCache[ x ].xMACAddress.ucBytes, sizeof( MACAddress_t ) ); - eReturn = eARPCacheHit; + eReturn = eResolutionCacheHit; if( ppxEndPoint != NULL ) { @@ -472,7 +492,7 @@ } } - if( eReturn == eARPCacheMiss ) + if( eReturn == eResolutionCacheMiss ) { FreeRTOS_printf( ( "prvNDCacheLookup %pip Miss\n", ( void * ) pxAddressToLookup->ucBytes ) ); @@ -518,7 +538,7 @@ } } - FreeRTOS_printf( ( "Arp has %ld entries\n", xCount ) ); + FreeRTOS_printf( ( "ND has %ld entries\n", xCount ) ); } #endif /* ( ipconfigHAS_PRINTF != 0 ) || ( ipconfigHAS_DEBUG_PRINTF != 0 ) */ @@ -907,7 +927,7 @@ /*-----------------------------------------------------------*/ /** - * @brief When a neighbour advertisement has been received, check if 'pxARPWaitingNetworkBuffer' + * @brief When a neighbour advertisement has been received, check if 'pxNDWaitingNetworkBuffer' * was waiting for this new address look-up. If so, feed it to the IP-task as a new * incoming packet. */ @@ -916,7 +936,7 @@ /* 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] */ - const IPPacket_IPv6_t * pxIPPacket = ( ( IPPacket_IPv6_t * ) pxARPWaitingNetworkBuffer->pucEthernetBuffer ); + const IPPacket_IPv6_t * pxIPPacket = ( ( IPPacket_IPv6_t * ) pxNDWaitingNetworkBuffer->pucEthernetBuffer ); const IPHeader_IPv6_t * pxIPHeader = &( pxIPPacket->xIPHeader ); if( memcmp( pxIPv6Address->ucBytes, pxIPHeader->xSourceAddress.ucBytes, ipSIZE_OF_IPv6_ADDRESS ) == 0 ) @@ -924,24 +944,24 @@ IPStackEvent_t xEventMessage; const TickType_t xDontBlock = ( TickType_t ) 0; - FreeRTOS_printf( ( "Waiting done\n" ) ); + FreeRTOS_debug_printf( ( "ND resolution waiting done\n" ) ); xEventMessage.eEventType = eNetworkRxEvent; - xEventMessage.pvData = ( void * ) pxARPWaitingNetworkBuffer; + xEventMessage.pvData = ( void * ) pxNDWaitingNetworkBuffer; if( xSendEventStructToIPTask( &xEventMessage, xDontBlock ) != pdPASS ) { /* Failed to send the message, so release the network buffer. */ - vReleaseNetworkBufferAndDescriptor( BUFFER_FROM_WHERE_CALL( 140 ) pxARPWaitingNetworkBuffer ); + vReleaseNetworkBufferAndDescriptor( BUFFER_FROM_WHERE_CALL( 140 ) pxNDWaitingNetworkBuffer ); } /* Clear the buffer. */ - pxARPWaitingNetworkBuffer = NULL; + pxNDWaitingNetworkBuffer = NULL; - /* Found an ARP resolution, disable ARP resolution timer. */ - vIPSetARPResolutionTimerEnableState( pdFALSE ); + /* Found an ND resolution, disable ND resolution timer. */ + vIPSetNDResolutionTimerEnableState( pdFALSE ); - iptrace_DELAYED_ARP_REQUEST_REPLIED(); + iptrace_DELAYED_ND_REQUEST_REPLIED(); } } /*-----------------------------------------------------------*/ @@ -1121,8 +1141,8 @@ vReceiveNA( pxNetworkBuffer ); #endif - if( ( pxARPWaitingNetworkBuffer != NULL ) && - ( uxIPHeaderSizePacket( pxARPWaitingNetworkBuffer ) == ipSIZE_OF_IPv6_HEADER ) ) + if( ( pxNDWaitingNetworkBuffer != NULL ) && + ( uxIPHeaderSizePacket( pxNDWaitingNetworkBuffer ) == ipSIZE_OF_IPv6_HEADER ) ) { prvCheckWaitingBuffer( &( pxICMPHeader_IPv6->xIPv6Address ) ); } @@ -1314,4 +1334,87 @@ return xResult; } /*-----------------------------------------------------------*/ + +/** + * @brief Check whether a packet needs ND resolution if it is on local subnet. If required send an ND Solicitation. + * + * @param[in] pxNetworkBuffer The network buffer with the packet to be checked. + * + * @return pdTRUE if the packet needs ND resolution, pdFALSE otherwise. + */ + BaseType_t xCheckRequiresNDResolution( const NetworkBufferDescriptor_t * pxNetworkBuffer ) + { + BaseType_t xNeedsNDResolution = pdFALSE; + + /* 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; + + configASSERT( pxIPPacket->xEthernetHeader.usFrameType == ipIPv6_FRAME_TYPE ); + + if( ( ucNextHeader == ipPROTOCOL_TCP ) || + ( ucNextHeader == ipPROTOCOL_UDP ) ) + { + IPv6_Type_t eType = xIPv6_GetIPType( ( const IPv6_Address_t * ) pxIPAddress ); + FreeRTOS_debug_printf( ( "xCheckRequiresNDResolution: %pip type %s\n", + ( void * ) pxIPAddress->ucBytes, + ( eType == eIPv6_Global ) ? "Global" : + ( eType == eIPv6_LinkLocal ) ? "LinkLocal" : + ( eType == eIPv6_Loopback ) ? "Loopback" : + "other" ) ); + + if( eType == eIPv6_LinkLocal ) + { + MACAddress_t xMACAddress; + NetworkEndPoint_t * pxEndPoint; + eResolutionLookupResult_t eResult; + char pcName[ 80 ]; + + ( void ) memset( &( pcName ), 0, sizeof( pcName ) ); + eResult = eNDGetCacheEntry( pxIPAddress, &xMACAddress, &pxEndPoint ); + FreeRTOS_printf( ( "xCheckRequiresNDResolution: eResult %s with EP %s\n", ( eResult == eResolutionCacheMiss ) ? "Miss" : ( eResult == eResolutionCacheHit ) ? "Hit" : "Error", pcEndpointName( pxEndPoint, pcName, sizeof pcName ) ) ); + + if( eResult == eResolutionCacheMiss ) + { + NetworkBufferDescriptor_t * pxTempBuffer; + size_t uxNeededSize; + + uxNeededSize = sizeof( ICMPPacket_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 ); + } + + xNeedsNDResolution = pdTRUE; + } + } + } + + return xNeedsNDResolution; + } + +/*-----------------------------------------------------------*/ + +/** + * @brief Send an unsolicited ND packet to allow this node to announce the IP-MAC + * mapping to the entire network. + */ + void vNDSendUnsolicited( void ) + { + /* Setting xLastUnsolicitedNDTime to 0 will force an unsolicited ND the next + * time vNDAgeCache() is called. */ + xLastUnsolicitedNDTime = ( TickType_t ) 0; + + /* Let the IP-task call vARPAgeCache(). */ + ( void ) xSendEventToIPTask( eNDTimerEvent ); + } +/*-----------------------------------------------------------*/ #endif /* ipconfigUSE_IPv6 */ diff --git a/source/FreeRTOS_RA.c b/source/FreeRTOS_RA.c index 446dfae98c..a9ef1fc8b0 100644 --- a/source/FreeRTOS_RA.c +++ b/source/FreeRTOS_RA.c @@ -42,7 +42,6 @@ #include "FreeRTOS_Sockets.h" #include "FreeRTOS_IP_Private.h" #include "FreeRTOS_IP_Timers.h" -#include "FreeRTOS_ARP.h" #include "FreeRTOS_UDP_IP.h" #include "FreeRTOS_Routing.h" #include "FreeRTOS_ND.h" @@ -509,7 +508,7 @@ } /* Now call vIPNetworkUpCalls() to send the network-up event and - * start the ARP timer. */ + * start the Resolution timer. */ vIPNetworkUpCalls( pxEndPoint ); } } diff --git a/source/FreeRTOS_Routing.c b/source/FreeRTOS_Routing.c index 800a933098..7be5751936 100644 --- a/source/FreeRTOS_Routing.c +++ b/source/FreeRTOS_Routing.c @@ -41,6 +41,7 @@ #include "FreeRTOS_Sockets.h" #include "FreeRTOS_IP_Private.h" #include "FreeRTOS_ARP.h" +#include "FreeRTOS_ND.h" #include "FreeRTOS_UDP_IP.h" #include "FreeRTOS_DHCP.h" #include "NetworkBufferManagement.h" @@ -1507,3 +1508,38 @@ struct xIPv6_Couple } /*-----------------------------------------------------------*/ #endif /* ( ( ipconfigHAS_PRINTF != 0 ) || ( ipconfigHAS_DEBUG_PRINTF != 0 ) ) */ + +/** + * @brief Check whether a packet needs resolution if it is on local subnet. If required send a request. + * + * @param[in] pxNetworkBuffer The network buffer with the packet to be checked. + * + * @return pdTRUE if the packet needs resolution, pdFALSE otherwise. + */ +BaseType_t xCheckRequiresResolution( const NetworkBufferDescriptor_t * pxNetworkBuffer ) +{ + BaseType_t xNeedsResolution = pdFALSE; + + switch( uxIPHeaderSizePacket( pxNetworkBuffer ) ) + { + #if ( ipconfigUSE_IPv4 != 0 ) + case ipSIZE_OF_IPv4_HEADER: + xNeedsResolution = xCheckRequiresARPResolution( pxNetworkBuffer ); + break; + #endif /* ( ipconfigUSE_IPv4 != 0 ) */ + + #if ( ipconfigUSE_IPv6 != 0 ) + case ipSIZE_OF_IPv6_HEADER: + xNeedsResolution = xCheckRequiresNDResolution( pxNetworkBuffer ); + break; + #endif /* ( ipconfigUSE_IPv6 != 0 ) */ + + default: + /* Shouldn't reach here */ + /* MISRA 16.4 Compliance */ + break; + } + + return xNeedsResolution; +} +/*-----------------------------------------------------------*/ diff --git a/source/FreeRTOS_TCP_IP.c b/source/FreeRTOS_TCP_IP.c index dafbf3c0a4..6ba71a33f2 100644 --- a/source/FreeRTOS_TCP_IP.c +++ b/source/FreeRTOS_TCP_IP.c @@ -54,7 +54,6 @@ #include "FreeRTOS_DHCP.h" #include "NetworkInterface.h" #include "NetworkBufferManagement.h" -#include "FreeRTOS_ARP.h" #include "FreeRTOS_TCP_Reception.h" #include "FreeRTOS_TCP_Transmission.h" @@ -647,7 +646,7 @@ } else { - /* Still in the ARP phase: check every half second. */ + /* Still in the Resolution phase: check every half second. */ ulDelayMs = 500U; } diff --git a/source/FreeRTOS_TCP_IP_IPv4.c b/source/FreeRTOS_TCP_IP_IPv4.c index 9ccb729014..39552cc3c8 100644 --- a/source/FreeRTOS_TCP_IP_IPv4.c +++ b/source/FreeRTOS_TCP_IP_IPv4.c @@ -53,7 +53,6 @@ #include "FreeRTOS_DHCP.h" #include "NetworkInterface.h" #include "NetworkBufferManagement.h" -#include "FreeRTOS_ARP.h" #include "FreeRTOS_TCP_Reception.h" #include "FreeRTOS_TCP_Transmission.h" diff --git a/source/FreeRTOS_TCP_IP_IPv6.c b/source/FreeRTOS_TCP_IP_IPv6.c index f9b2dd75f7..acb24fda13 100644 --- a/source/FreeRTOS_TCP_IP_IPv6.c +++ b/source/FreeRTOS_TCP_IP_IPv6.c @@ -53,7 +53,6 @@ #include "FreeRTOS_DHCP.h" #include "NetworkInterface.h" #include "NetworkBufferManagement.h" -#include "FreeRTOS_ARP.h" #include "FreeRTOS_TCP_Reception.h" #include "FreeRTOS_TCP_Transmission.h" diff --git a/source/FreeRTOS_TCP_Reception.c b/source/FreeRTOS_TCP_Reception.c index d50069e55e..4f1003a67c 100644 --- a/source/FreeRTOS_TCP_Reception.c +++ b/source/FreeRTOS_TCP_Reception.c @@ -51,7 +51,6 @@ #include "FreeRTOS_DHCP.h" #include "NetworkInterface.h" #include "NetworkBufferManagement.h" -#include "FreeRTOS_ARP.h" #include "FreeRTOS_TCP_Transmission.h" #include "FreeRTOS_TCP_Reception.h" diff --git a/source/FreeRTOS_TCP_State_Handling.c b/source/FreeRTOS_TCP_State_Handling.c index ecf55bae06..6376af4367 100644 --- a/source/FreeRTOS_TCP_State_Handling.c +++ b/source/FreeRTOS_TCP_State_Handling.c @@ -51,7 +51,6 @@ #include "FreeRTOS_DHCP.h" #include "NetworkInterface.h" #include "NetworkBufferManagement.h" -#include "FreeRTOS_ARP.h" #include "FreeRTOS_TCP_Reception.h" #include "FreeRTOS_TCP_Transmission.h" diff --git a/source/FreeRTOS_TCP_State_Handling_IPv4.c b/source/FreeRTOS_TCP_State_Handling_IPv4.c index d7da55d499..8ccae1883a 100644 --- a/source/FreeRTOS_TCP_State_Handling_IPv4.c +++ b/source/FreeRTOS_TCP_State_Handling_IPv4.c @@ -51,7 +51,6 @@ #include "FreeRTOS_DHCP.h" #include "NetworkInterface.h" #include "NetworkBufferManagement.h" -#include "FreeRTOS_ARP.h" #include "FreeRTOS_TCP_Reception.h" #include "FreeRTOS_TCP_Transmission.h" diff --git a/source/FreeRTOS_TCP_State_Handling_IPv6.c b/source/FreeRTOS_TCP_State_Handling_IPv6.c index d13211a02f..40ed8ca8aa 100644 --- a/source/FreeRTOS_TCP_State_Handling_IPv6.c +++ b/source/FreeRTOS_TCP_State_Handling_IPv6.c @@ -51,7 +51,6 @@ #include "FreeRTOS_DHCP.h" #include "NetworkInterface.h" #include "NetworkBufferManagement.h" -#include "FreeRTOS_ARP.h" #include "FreeRTOS_TCP_Reception.h" #include "FreeRTOS_TCP_Transmission.h" diff --git a/source/FreeRTOS_TCP_Transmission.c b/source/FreeRTOS_TCP_Transmission.c index 306528c6e2..3b0abe63f7 100644 --- a/source/FreeRTOS_TCP_Transmission.c +++ b/source/FreeRTOS_TCP_Transmission.c @@ -52,7 +52,6 @@ #include "FreeRTOS_IP_Private.h" #include "NetworkInterface.h" #include "NetworkBufferManagement.h" -#include "FreeRTOS_ARP.h" #include "FreeRTOSIPConfigDefaults.h" #include "FreeRTOS_TCP_IP.h" @@ -66,10 +65,7 @@ static BaseType_t prvTCPMakeSurePrepared( FreeRTOS_Socket_t * pxSocket ); -/* - * Let ARP look-up the MAC-address of the peer and initialise the first SYN - * packet. - */ +/* Resolve the MAC-address of the peer and initialise the first SYN packet. */ static BaseType_t prvTCPPrepareConnect( FreeRTOS_Socket_t * pxSocket ); #if ipconfigIS_ENABLED( ipconfigUSE_TCP_WIN ) @@ -92,7 +88,7 @@ { if( prvTCPPrepareConnect( pxSocket ) != pdTRUE ) { - /* The preparation of a connection ( ARP resolution ) is not yet ready. */ + /* The preparation of a connection ( resolution ) is not yet ready. */ xReturn = pdFALSE; } } @@ -480,8 +476,7 @@ /*-----------------------------------------------------------*/ /** - * @brief Let ARP look-up the MAC-address of the peer and initialise the first SYN - * packet. + * @brief Resolve the MAC-address of the peer and initialise the first SYN packet. * * @param[in] pxSocket The socket owning the TCP connection. The first packet shall * be created in this socket. @@ -490,9 +485,9 @@ * Else pdFALSE. * * @note Connecting sockets have a special state: eCONNECT_SYN. In this phase, - * the Ethernet address of the target will be found using ARP. In case the - * target IP address is not within the netmask, the hardware address of the - * gateway will be used. + * the Ethernet address of the target will be found through address resolution. + * In case the target IP address is not within the netmask, the hardware address + * of the gateway will be used. */ static BaseType_t prvTCPPrepareConnect( FreeRTOS_Socket_t * pxSocket ) { diff --git a/source/FreeRTOS_TCP_Transmission_IPv4.c b/source/FreeRTOS_TCP_Transmission_IPv4.c index 2b2492957b..f341b09ac1 100644 --- a/source/FreeRTOS_TCP_Transmission_IPv4.c +++ b/source/FreeRTOS_TCP_Transmission_IPv4.c @@ -99,7 +99,7 @@ void prvTCPReturnPacket_IPV4( FreeRTOS_Socket_t * pxSocket, void * pvCopyDest = NULL; const size_t uxIPHeaderSize = ipSIZE_OF_IPv4_HEADER; uint32_t ulDestinationIPAddress; - eARPLookupResult_t eResult; + eResolutionLookupResult_t eResult; NetworkEndPoint_t * pxEndPoint = NULL; do @@ -235,7 +235,7 @@ void prvTCPReturnPacket_IPV4( FreeRTOS_Socket_t * pxSocket, eResult = eARPGetCacheEntry( &ulDestinationIPAddress, &xMACAddress, &pxEndPoint ); - if( eResult == eARPCacheHit ) + if( eResult == eResolutionCacheHit ) { pvCopySource = &xMACAddress; pxNetworkBuffer->pxEndPoint = pxEndPoint; @@ -332,7 +332,7 @@ BaseType_t prvTCPPrepareConnect_IPV4( FreeRTOS_Socket_t * pxSocket ) { TCPPacket_t * pxTCPPacket; IPHeader_t * pxIPHeader; - eARPLookupResult_t eReturned; + eResolutionLookupResult_t eReturned; uint32_t ulRemoteIP; MACAddress_t xEthAddress; BaseType_t xReturn = pdTRUE; @@ -351,11 +351,11 @@ BaseType_t prvTCPPrepareConnect_IPV4( FreeRTOS_Socket_t * pxSocket ) switch( eReturned ) { - case eARPCacheHit: /* An ARP table lookup found a valid entry. */ - break; /* We can now prepare the SYN packet. */ + case eResolutionCacheHit: /* An ARP table lookup found a valid entry. */ + break; /* We can now prepare the SYN packet. */ - case eARPCacheMiss: /* An ARP table lookup did not find a valid entry. */ - case eCantSendPacket: /* There is no IP address, or an ARP is still in progress. */ + case eResolutionCacheMiss: /* An ARP table lookup did not find a valid entry. */ + case eResolutionFailed: /* There is no IP address, or an ARP is still in progress. */ default: /* Count the number of times it could not find the ARP address. */ pxSocket->u.xTCP.ucRepCount++; diff --git a/source/FreeRTOS_TCP_Transmission_IPv6.c b/source/FreeRTOS_TCP_Transmission_IPv6.c index 125da5acfa..1a3cc36209 100644 --- a/source/FreeRTOS_TCP_Transmission_IPv6.c +++ b/source/FreeRTOS_TCP_Transmission_IPv6.c @@ -52,7 +52,6 @@ #include "FreeRTOS_IP_Private.h" #include "NetworkInterface.h" #include "NetworkBufferManagement.h" -#include "FreeRTOS_ARP.h" #include "FreeRTOSIPConfigDefaults.h" #include "FreeRTOS_ND.h" @@ -151,7 +150,7 @@ void prvTCPReturnPacket_IPV6( FreeRTOS_Socket_t * pxSocket, if( pxNetworkBuffer != NULL ) /* LCOV_EXCL_BR_LINE the 2nd branch will never be reached */ #endif { - eARPLookupResult_t eResult; + eResolutionLookupResult_t eResult; NetworkInterface_t * pxInterface; configASSERT( pxNetworkBuffer->pucEthernetBuffer != NULL ); @@ -236,7 +235,7 @@ void prvTCPReturnPacket_IPV6( FreeRTOS_Socket_t * pxSocket, eResult = eNDGetCacheEntry( &xDestinationIPAddress, &xMACAddress, &( pxNetworkBuffer->pxEndPoint ) ); - if( eResult == eARPCacheHit ) + if( eResult == eResolutionCacheHit ) { pvCopySource = &xMACAddress; } @@ -301,7 +300,7 @@ void prvTCPReturnPacket_IPV6( FreeRTOS_Socket_t * pxSocket, /*-----------------------------------------------------------*/ /** - * @brief Let ARP look-up the MAC-address of the peer and initialise the first SYN + * @brief Let ND look-up the MAC-address of the peer and initialise the first SYN * packet. * * @param[in] pxSocket The socket owning the TCP connection. The first packet shall @@ -311,7 +310,7 @@ void prvTCPReturnPacket_IPV6( FreeRTOS_Socket_t * pxSocket, * Else pdFALSE. * * @note Connecting sockets have a special state: eCONNECT_SYN. In this phase, - * the Ethernet address of the target will be found using ARP. In case the + * the Ethernet address of the target will be found using ND. In case the * target IP address is not within the netmask, the hardware address of the * gateway will be used. */ @@ -319,7 +318,7 @@ BaseType_t prvTCPPrepareConnect_IPV6( FreeRTOS_Socket_t * pxSocket ) { TCPPacket_IPv6_t * pxTCPPacket = NULL; IPHeader_IPv6_t * pxIPHeader = NULL; - eARPLookupResult_t eReturned; + eResolutionLookupResult_t eReturned; IP_Address_t xRemoteIP; MACAddress_t xEthAddress; BaseType_t xReturn = pdTRUE; @@ -352,13 +351,13 @@ BaseType_t prvTCPPrepareConnect_IPV6( FreeRTOS_Socket_t * pxSocket ) switch( eReturned ) { - case eARPCacheHit: /* An ARP table lookup found a valid entry. */ - break; /* We can now prepare the SYN packet. */ + case eResolutionCacheHit: /* An ND table lookup found a valid entry. */ + break; /* We can now prepare the SYN packet. */ - case eARPCacheMiss: /* An ARP table lookup did not find a valid entry. */ - case eCantSendPacket: /* There is no IP address, or an ARP is still in progress. */ + case eResolutionCacheMiss: /* An ND table lookup did not find a valid entry. */ + case eResolutionFailed: /* There is no IP address, or an ND is still in progress. */ default: - /* Count the number of times it could not find the ARP address. */ + /* Count the number of times it could not find the ND address. */ pxSocket->u.xTCP.ucRepCount++; FreeRTOS_printf( ( "Looking up %pip with%s end-point\n", ( void * ) xRemoteIP.xIP_IPv6.ucBytes, ( pxEndPoint != NULL ) ? "" : "out" ) ); diff --git a/source/FreeRTOS_UDP_IP.c b/source/FreeRTOS_UDP_IP.c index d5ea687a73..4321b64e8e 100644 --- a/source/FreeRTOS_UDP_IP.c +++ b/source/FreeRTOS_UDP_IP.c @@ -48,10 +48,8 @@ #include "FreeRTOS_Sockets.h" #include "FreeRTOS_IP_Private.h" #include "FreeRTOS_UDP_IP.h" -#include "FreeRTOS_ARP.h" #include "FreeRTOS_DNS.h" #include "FreeRTOS_DHCP.h" -#include "FreeRTOS_ND.h" #include "FreeRTOS_IP_Utils.h" #include "NetworkInterface.h" #include "NetworkBufferManagement.h" @@ -62,7 +60,7 @@ /** * @brief Process the generated UDP packet and do other checks before sending the - * packet such as ARP cache check and address resolution. + * packet such as cache check and address resolution. * * @param[in] pxNetworkBuffer The network buffer carrying the packet. */ @@ -104,14 +102,14 @@ void vProcessGeneratedUDPPacket( NetworkBufferDescriptor_t * const pxNetworkBuff * * @param[in] pxNetworkBuffer The network buffer carrying the UDP packet. * @param[in] usPort The port number on which this packet was received. - * @param[out] pxIsWaitingForARPResolution If the packet is awaiting ARP resolution, + * @param[out] pxIsWaitingForResolution If the packet is awaiting resolution, * this pointer will be set to pdTRUE. pdFALSE otherwise. * * @return pdPASS in case the UDP packet could be processed. Else pdFAIL is returned. */ BaseType_t xProcessReceivedUDPPacket( NetworkBufferDescriptor_t * pxNetworkBuffer, uint16_t usPort, - BaseType_t * pxIsWaitingForARPResolution ) + BaseType_t * pxIsWaitingForResolution ) { /* Returning pdPASS means that the packet was consumed, released. */ BaseType_t xReturn = pdFAIL; @@ -132,13 +130,13 @@ BaseType_t xProcessReceivedUDPPacket( NetworkBufferDescriptor_t * pxNetworkBuffe #if ( ipconfigUSE_IPv4 != 0 ) case ipIPv4_FRAME_TYPE: xReturn = xProcessReceivedUDPPacket_IPv4( pxNetworkBuffer, - usPort, pxIsWaitingForARPResolution ); + usPort, pxIsWaitingForResolution ); break; #endif #if ( ipconfigUSE_IPv6 != 0 ) case ipIPv6_FRAME_TYPE: xReturn = xProcessReceivedUDPPacket_IPv6( pxNetworkBuffer, - usPort, pxIsWaitingForARPResolution ); + usPort, pxIsWaitingForResolution ); break; #endif default: diff --git a/source/FreeRTOS_UDP_IPv4.c b/source/FreeRTOS_UDP_IPv4.c index ac601d52d0..2fceed8a95 100644 --- a/source/FreeRTOS_UDP_IPv4.c +++ b/source/FreeRTOS_UDP_IPv4.c @@ -76,7 +76,7 @@ void vProcessGeneratedUDPPacket_IPv4( NetworkBufferDescriptor_t * const pxNetwor { UDPPacket_t * pxUDPPacket; IPHeader_t * pxIPHeader; - eARPLookupResult_t eReturned; + eResolutionLookupResult_t eReturned; uint32_t ulIPAddress = pxNetworkBuffer->xIPAddress.ulIP_IPv4; NetworkEndPoint_t * pxEndPoint = pxNetworkBuffer->pxEndPoint; size_t uxPayloadSize; @@ -110,9 +110,9 @@ void vProcessGeneratedUDPPacket_IPv4( NetworkBufferDescriptor_t * const pxNetwor pxNetworkBuffer->pxEndPoint = pxEndPoint; } - if( eReturned != eCantSendPacket ) + if( eReturned != eResolutionFailed ) { - if( eReturned == eARPCacheHit ) + if( eReturned == eResolutionCacheHit ) { /* Part of the Ethernet and IP headers are always constant when sending an IPv4 * UDP packet. This array defines the constant parts, allowing this part of the @@ -261,7 +261,7 @@ void vProcessGeneratedUDPPacket_IPv4( NetworkBufferDescriptor_t * const pxNetwor } #endif /* if ( ipconfigDRIVER_INCLUDED_TX_IP_CHECKSUM == 0 ) */ } - else if( eReturned == eARPCacheMiss ) + else if( eReturned == eResolutionCacheMiss ) { /* Add an entry to the ARP table with a null hardware address. * This allows the ARP timer to know that an ARP reply is @@ -278,7 +278,7 @@ void vProcessGeneratedUDPPacket_IPv4( NetworkBufferDescriptor_t * const pxNetwor if( pxNetworkBuffer->pxEndPoint == NULL ) { - eReturned = eCantSendPacket; + eReturned = eResolutionFailed; } else { @@ -290,11 +290,11 @@ void vProcessGeneratedUDPPacket_IPv4( NetworkBufferDescriptor_t * const pxNetwor { /* The lookup indicated that an ARP request has already been * sent out for the queried IP address. */ - eReturned = eCantSendPacket; + eReturned = eResolutionFailed; } } - if( eReturned != eCantSendPacket ) + if( eReturned != eResolutionFailed ) { /* The network driver is responsible for freeing the network buffer * after the packet has been sent. */ diff --git a/source/FreeRTOS_UDP_IPv6.c b/source/FreeRTOS_UDP_IPv6.c index 80762bd9ca..1efd1927a1 100644 --- a/source/FreeRTOS_UDP_IPv6.c +++ b/source/FreeRTOS_UDP_IPv6.c @@ -48,7 +48,6 @@ #include "FreeRTOS_Sockets.h" #include "FreeRTOS_IP_Private.h" #include "FreeRTOS_UDP_IP.h" -#include "FreeRTOS_ARP.h" #include "FreeRTOS_DNS.h" #include "FreeRTOS_DHCP.h" #include "FreeRTOS_ND.h" @@ -114,18 +113,18 @@ static NetworkEndPoint_t * pxGetEndpoint( BaseType_t xIPType, /** * @brief This function is called in case the IP-address was not found, - * i.e. in the cache 'eARPCacheMiss' was returned. - * Either an ARP request or a Neighbour solicitation will be emitted. + * i.e. in the cache 'eResolutionCacheMiss' was returned. + * A Neighbour solicitation will be emitted. * * @param[in] pxNetworkBuffer The network buffer carrying the UDP or ICMP packet. * * @param[out] pxLostBuffer The pointee will be set to true in case the network packet got released * ( the ownership was taken ). */ -static eARPLookupResult_t prvStartLookup( NetworkBufferDescriptor_t * const pxNetworkBuffer, - BaseType_t * pxLostBuffer ) +static eResolutionLookupResult_t prvStartLookup( NetworkBufferDescriptor_t * const pxNetworkBuffer, + BaseType_t * pxLostBuffer ) { - eARPLookupResult_t eReturned = eARPCacheMiss; + eResolutionLookupResult_t eReturned = eResolutionCacheMiss; FreeRTOS_printf( ( "Looking up %pip with%s end-point\n", ( void * ) pxNetworkBuffer->xIPAddress.xIP_IPv6.ucBytes, @@ -154,7 +153,7 @@ static eARPLookupResult_t prvStartLookup( NetworkBufferDescriptor_t * const pxNe /** * @brief Process the generated UDP packet and do other checks before sending the - * packet such as ARP cache check and address resolution. + * packet such as ND cache check and address resolution. * * @param[in] pxNetworkBuffer The network buffer carrying the packet. */ @@ -162,7 +161,7 @@ void vProcessGeneratedUDPPacket_IPv6( NetworkBufferDescriptor_t * const pxNetwor { UDPPacket_IPv6_t * pxUDPPacket_IPv6; IPHeader_IPv6_t * pxIPHeader_IPv6; - eARPLookupResult_t eReturned; + eResolutionLookupResult_t eReturned; size_t uxPayloadSize; /* memcpy() helper variables for MISRA Rule 21.15 compliance*/ NetworkInterface_t * pxInterface = NULL; @@ -199,9 +198,9 @@ void vProcessGeneratedUDPPacket_IPv6( NetworkBufferDescriptor_t * const pxNetwor eReturned = eNDGetCacheEntry( &( pxNetworkBuffer->xIPAddress.xIP_IPv6 ), &( pxUDPPacket_IPv6->xEthernetHeader.xDestinationAddress ), &( pxEndPoint ) ); - if( eReturned != eCantSendPacket ) + if( eReturned != eResolutionFailed ) { - if( eReturned == eARPCacheHit ) + if( eReturned == eResolutionCacheHit ) { #if ( ipconfigDRIVER_INCLUDED_TX_IP_CHECKSUM == 0 ) uint8_t ucSocketOptions; @@ -298,7 +297,7 @@ void vProcessGeneratedUDPPacket_IPv6( NetworkBufferDescriptor_t * const pxNetwor } #endif /* if ( ipconfigDRIVER_INCLUDED_TX_IP_CHECKSUM == 0 ) */ } - else if( eReturned == eARPCacheMiss ) + else if( eReturned == eResolutionCacheMiss ) { if( pxEndPoint != NULL ) { @@ -309,17 +308,17 @@ void vProcessGeneratedUDPPacket_IPv6( NetworkBufferDescriptor_t * const pxNetwor } else { - /* The lookup indicated that an ARP request has already been + /* The lookup indicated that an ND Solicitation has already been * sent out for the queried IP address. */ - eReturned = eCantSendPacket; + eReturned = eResolutionFailed; } } if( xLostBuffer == pdTRUE ) { - /* An ND solicitation or ARP request has been sent. */ + /* An ND solicitation has been sent. */ } - else if( eReturned != eCantSendPacket ) + else if( eReturned != eResolutionFailed ) { /* The network driver is responsible for freeing the network buffer * after the packet has been sent. */ @@ -373,14 +372,14 @@ void vProcessGeneratedUDPPacket_IPv6( NetworkBufferDescriptor_t * const pxNetwor * * @param[in] pxNetworkBuffer The network buffer carrying the UDP packet. * @param[in] usPort The port number on which this packet was received. - * @param[out] pxIsWaitingForARPResolution If the packet is awaiting ARP resolution, + * @param[out] pxIsWaitingForNDResolution If the packet is awaiting ND resolution, * this pointer will be set to pdTRUE. pdFALSE otherwise. * * @return pdPASS in case the UDP packet could be processed. Else pdFAIL is returned. */ BaseType_t xProcessReceivedUDPPacket_IPv6( NetworkBufferDescriptor_t * pxNetworkBuffer, uint16_t usPort, - BaseType_t * pxIsWaitingForARPResolution ) + BaseType_t * pxIsWaitingForNDResolution ) { /* Returning pdPASS means that the packet was consumed, released. */ BaseType_t xReturn = pdPASS; @@ -390,7 +389,7 @@ BaseType_t xProcessReceivedUDPPacket_IPv6( NetworkBufferDescriptor_t * pxNetwork configASSERT( pxNetworkBuffer != NULL ); configASSERT( pxNetworkBuffer->pucEthernetBuffer != NULL ); - /* When refreshing the ARP/ND cache with received UDP packets we must be + /* When refreshing the ND cache with received UDP packets we must be * careful; hundreds of broadcast messages may pass and if we're not * handling them, no use to fill the cache with those IP addresses. */ @@ -402,7 +401,7 @@ BaseType_t xProcessReceivedUDPPacket_IPv6( NetworkBufferDescriptor_t * pxNetwork /* Caller must check for minimum packet size. */ pxSocket = pxUDPSocketLookup( usPort ); - *pxIsWaitingForARPResolution = pdFALSE; + *pxIsWaitingForNDResolution = pdFALSE; do { @@ -419,10 +418,10 @@ BaseType_t xProcessReceivedUDPPacket_IPv6( NetworkBufferDescriptor_t * pxNetwork if( pxSocket != NULL ) { - if( xCheckRequiresARPResolution( pxNetworkBuffer ) == pdTRUE ) + if( xCheckRequiresNDResolution( pxNetworkBuffer ) == pdTRUE ) { - /* Mark this packet as waiting for ARP resolution. */ - *pxIsWaitingForARPResolution = pdTRUE; + /* Mark this packet as waiting for ND resolution. */ + *pxIsWaitingForNDResolution = pdTRUE; /* Return a fail to show that the frame will not be processed right now. */ xReturn = pdFAIL; diff --git a/source/include/FreeRTOSIPConfigDefaults.h b/source/include/FreeRTOSIPConfigDefaults.h index 6bf290c915..77ae9e9c8c 100644 --- a/source/include/FreeRTOSIPConfigDefaults.h +++ b/source/include/FreeRTOSIPConfigDefaults.h @@ -254,31 +254,6 @@ /*---------------------------------------------------------------------------*/ -/* - * ipconfigND_CACHE_ENTRIES - * - * Type: size_t - * Unit: length of NDCacheRow_t array - * Minimum: 1 - * - * Maximum number of entries in the Neighbour Discovery cache of IPv6 addresses - * & MAC addresses - */ - -#ifndef ipconfigND_CACHE_ENTRIES - #define ipconfigND_CACHE_ENTRIES ( 24 ) -#endif - -#if ( ipconfigND_CACHE_ENTRIES < 1 ) - #error ipconfigND_CACHE_ENTRIES must be at least 1 -#endif - -#if ( ipconfigND_CACHE_ENTRIES > SIZE_MAX ) - #error ipconfigND_CACHE_ENTRIES overflows a size_t -#endif - -/*---------------------------------------------------------------------------*/ - /* * ipconfigUSE_RA * @@ -2942,6 +2917,74 @@ STATIC_ASSERT( ipconfigDNS_SEND_BLOCK_TIME_TICKS <= portMAX_DELAY ); /*===========================================================================*/ /*---------------------------------------------------------------------------*/ /*===========================================================================*/ +/* ND CONFIG */ +/*===========================================================================*/ + +/*---------------------------------------------------------------------------*/ + +/* + * ipconfigND_CACHE_ENTRIES + * + * Type: size_t + * Unit: length of NDCacheRow_t array + * Minimum: 1 + * + * Maximum number of entries in the Neighbour Discovery cache of IPv6 addresses + * & MAC addresses + */ + +#ifndef ipconfigND_CACHE_ENTRIES + #define ipconfigND_CACHE_ENTRIES ( 24 ) +#endif + +#if ( ipconfigND_CACHE_ENTRIES < 1 ) + #error ipconfigND_CACHE_ENTRIES must be at least 1 +#endif + +#if ( ipconfigND_CACHE_ENTRIES > SIZE_MAX ) + #error ipconfigND_CACHE_ENTRIES overflows a size_t +#endif + +/*---------------------------------------------------------------------------*/ + +/* + * ipconfigMAX_ND_AGE + * + * Type: uint8_t + * Unit: decaseconds + * Minimum: 0 + * + * Defines the maximum time between an entry in the ND table being created or + * refreshed and the entry being removed because it is stale. New ND requests + * are sent for ND cache entries that are nearing their maximum age. + * The maximum age of an entry in the ND cache table can be + * calculated as 'ipND_TIMER_PERIOD_MS' x 'ipconfigMAX_ND_AGE'. + * + * Units are derived from ipND_TIMER_PERIOD_MS, which is 10000 ms or 10 sec. + * So, a value of 150 is equal to 1500 seconds. + */ + +#ifndef ipconfigMAX_ND_AGE + #define ipconfigMAX_ND_AGE ( 150 ) +#endif + +#if ( ipconfigMAX_ND_AGE < 0 ) + #error ipconfigMAX_ND_AGE must be at least 0 +#endif + +#if ( ipconfigMAX_ND_AGE > UINT8_MAX ) + #error ipconfigMAX_ND_AGE overflows a uint8_t +#endif + +/*---------------------------------------------------------------------------*/ + +/*===========================================================================*/ +/* ND CONFIG */ +/*===========================================================================*/ +/*---------------------------------------------------------------------------*/ +/*===========================================================================*/ +/*---------------------------------------------------------------------------*/ +/*===========================================================================*/ /* ICMP CONFIG */ /*===========================================================================*/ diff --git a/source/include/FreeRTOS_ARP.h b/source/include/FreeRTOS_ARP.h index 21357b799b..e01ece18a2 100644 --- a/source/include/FreeRTOS_ARP.h +++ b/source/include/FreeRTOS_ARP.h @@ -33,6 +33,7 @@ #include "FreeRTOSIPConfigDefaults.h" #include "FreeRTOS_IP.h" +#include "FreeRTOS_Routing.h" /* *INDENT-OFF* */ #ifdef __cplusplus @@ -62,13 +63,6 @@ typedef struct xARP_CACHE_TABLE_ROW * pxEndPoint; /**< The end-point on which the MAC address was last seen. */ } ARPCacheRow_t; -typedef enum -{ - eARPCacheMiss = 0, /* 0 An ARP table lookup did not find a valid entry. */ - eARPCacheHit, /* 1 An ARP table lookup found a valid entry. */ - eCantSendPacket /* 2 There is no IP address, or an ARP is still in progress, so the packet cannot be sent. */ -} eARPLookupResult_t; - /** @brief A structure used internally in FreeRTOS_ARP.c. * It is used as a parameter for the function prvFindCacheEntry().*/ typedef struct xCacheLocation @@ -91,9 +85,6 @@ void vARPRefreshCacheEntryAge( const MACAddress_t * pxMACAddress, * cache table then add it - replacing the oldest current entry if there is not * a free space available. */ -/*void vARPRefreshCacheEntry( const MACAddress_t * pxMACAddress, */ -/* const uint32_t ulIPAddress ); */ - void vARPRefreshCacheEntry( const MACAddress_t * pxMACAddress, const uint32_t ulIPAddress, struct xNetworkEndPoint * pxEndPoint ); @@ -123,38 +114,35 @@ BaseType_t xCheckRequiresARPResolution( const NetworkBufferDescriptor_t * pxNetw /* * Look for ulIPAddress in the ARP cache. If the IP address exists, copy the * associated MAC address into pxMACAddress, refresh the ARP cache entry's - * age, and return eARPCacheHit. If the IP address does not exist in the ARP - * cache return eARPCacheMiss. If the packet cannot be sent for any reason + * age, and return eResolutionCacheHit. If the IP address does not exist in the ARP + * cache return eResolutionCacheMiss. If the packet cannot be sent for any reason * (maybe DHCP is still in process, or the addressing needs a gateway but there - * isn't a gateway defined) then return eCantSendPacket. + * isn't a gateway defined) then return eResolutionFailed. */ -eARPLookupResult_t eARPGetCacheEntry( uint32_t * pulIPAddress, - MACAddress_t * const pxMACAddress, - struct xNetworkEndPoint ** ppxEndPoint ); +eResolutionLookupResult_t eARPGetCacheEntry( uint32_t * pulIPAddress, + MACAddress_t * const pxMACAddress, + struct xNetworkEndPoint ** ppxEndPoint ); #if ( ipconfigUSE_ARP_REVERSED_LOOKUP != 0 ) /* Lookup an IP-address if only the MAC-address is known */ - eARPLookupResult_t eARPGetCacheEntryByMac( const MACAddress_t * const pxMACAddress, - uint32_t * pulIPAddress, - struct xNetworkInterface ** ppxInterface ); + eResolutionLookupResult_t eARPGetCacheEntryByMac( const MACAddress_t * const pxMACAddress, + uint32_t * pulIPAddress, + struct xNetworkInterface ** ppxInterface ); #endif -#if ( ipconfigUSE_IPv4 != 0 ) - /* * Reduce the age count in each entry within the ARP cache. An entry is no * longer considered valid and is deleted if its age reaches zero. */ - void vARPAgeCache( void ); +void vARPAgeCache( void ); /* * After DHCP is ready and when changing IP address, force a quick send of our new IP * address */ - void vARPSendGratuitous( void ); -#endif /* ( ipconfigUSE_IPv4 != 0 ) */ +void vARPSendGratuitous( void ); /* * Send out an ARP request for the IP address contained in pxNetworkBuffer, and @@ -171,9 +159,20 @@ void FreeRTOS_OutputARPRequest( uint32_t ulIPAddress ); void FreeRTOS_OutputARPRequest_Multi( NetworkEndPoint_t * pxEndPoint, uint32_t ulIPAddress ); +/* xARPWaitResolution checks if an IPv4 address is already known. If not + * it may send an ARP request and wait for a reply. This function will + * only be called from an application. */ +BaseType_t xARPWaitResolution( uint32_t ulIPAddress, + TickType_t uxTicksToWait ); + /* Clear all entries in the ARp cache. */ void FreeRTOS_ClearARP( const struct xNetworkEndPoint * pxEndPoint ); +/* Show all valid ARP entries */ +#if ( ipconfigHAS_PRINTF != 0 ) || ( ipconfigHAS_DEBUG_PRINTF != 0 ) + void FreeRTOS_PrintARPCache( void ); +#endif + /* *INDENT-OFF* */ #ifdef __cplusplus } /* extern "C" */ diff --git a/source/include/FreeRTOS_DNS_Cache.h b/source/include/FreeRTOS_DNS_Cache.h index 2dd6b19a30..f94442217f 100644 --- a/source/include/FreeRTOS_DNS_Cache.h +++ b/source/include/FreeRTOS_DNS_Cache.h @@ -43,7 +43,7 @@ */ typedef struct xDNS_CACHE_TABLE_ROW { - IPv46_Address_t xAddresses[ ipconfigDNS_CACHE_ADDRESSES_PER_ENTRY ]; /*!< The IP address(es) of an ARP cache entry. */ + IPv46_Address_t xAddresses[ ipconfigDNS_CACHE_ADDRESSES_PER_ENTRY ]; /*!< The IP address(es) of a DNS cache entry. */ char pcName[ ipconfigDNS_CACHE_NAME_LENGTH ]; /*!< The name of the host */ uint32_t ulTTL; /*!< Time-to-Live (in seconds) from the DNS server. */ uint32_t ulTimeWhenAddedInSeconds; /*!< time at which the entry was added */ diff --git a/source/include/FreeRTOS_IP.h b/source/include/FreeRTOS_IP.h index 20688c780d..ecd12a1c94 100644 --- a/source/include/FreeRTOS_IP.h +++ b/source/include/FreeRTOS_IP.h @@ -407,12 +407,6 @@ void FreeRTOS_UpdateMACAddress( const uint8_t ucMACAddress[ ipMAC_ADDRESS_LENGTH uint16_t usIdentifier ); #endif -/* xARPWaitResolution checks if an IPv4 address is already known. If not - * it may send an ARP request and wait for a reply. This function will - * only be called from an application. */ -BaseType_t xARPWaitResolution( uint32_t ulIPAddress, - TickType_t uxTicksToWait ); - BaseType_t FreeRTOS_IsNetworkUp( void ); #if ( ipconfigCHECK_IP_QUEUE_SPACE != 0 ) @@ -455,10 +449,11 @@ BaseType_t xIsNetworkDownEventPending( void ); * be defined in a user module. */ BaseType_t xApplicationGetRandomNumber( uint32_t * pulNumber ); -/** @brief The pointer to buffer with packet waiting for ARP resolution. This variable - * is defined in FreeRTOS_IP.c. - * This pointer is for internal use only. */ +/** @brief The pointers to buffers with packet waiting for resolution. These variables + * are defined in FreeRTOS_IP.c. + * These pointers are for internal use only. */ extern NetworkBufferDescriptor_t * pxARPWaitingNetworkBuffer; +extern NetworkBufferDescriptor_t * pxNDWaitingNetworkBuffer; #if ( ipconfigENABLE_BACKWARD_COMPATIBILITY == 1 ) #define xIPStackEvent_t IPStackEvent_t diff --git a/source/include/FreeRTOS_IP_Private.h b/source/include/FreeRTOS_IP_Private.h index b594582fc9..cd5afb8c01 100644 --- a/source/include/FreeRTOS_IP_Private.h +++ b/source/include/FreeRTOS_IP_Private.h @@ -65,7 +65,7 @@ typedef enum eFrameProcessingResult eProcessBuffer, /* An Ethernet frame has a valid address - continue process its contents. */ eReturnEthernetFrame, /* The Ethernet frame contains an ARP or ICMP packet that can be returned to its source. */ eFrameConsumed, /* Processing the Ethernet packet contents resulted in the payload being sent to the stack. */ - eWaitingARPResolution /* Frame is awaiting ARP resolution. */ + eWaitingResolution /* Frame is awaiting resolution. */ } eFrameProcessingResult_t; typedef enum @@ -75,16 +75,17 @@ typedef enum eNetworkRxEvent, /* 1: The network interface has queued a received Ethernet frame. */ eNetworkTxEvent, /* 2: Let the IP-task send a network packet. */ eARPTimerEvent, /* 3: The ARP timer expired. */ - eStackTxEvent, /* 4: The software stack has queued a packet to transmit. */ - eDHCPEvent, /* 5: Process the DHCP state machine. */ - eTCPTimerEvent, /* 6: See if any TCP socket needs attention. */ - eTCPAcceptEvent, /* 7: Client API FreeRTOS_accept() waiting for client connections. */ - eTCPNetStat, /* 8: IP-task is asked to produce a netstat listing. */ - eSocketBindEvent, /* 9: Send a message to the IP-task to bind a socket to a port. */ - eSocketCloseEvent, /*10: Send a message to the IP-task to close a socket. */ - eSocketSelectEvent, /*11: Send a message to the IP-task for select(). */ - eSocketSignalEvent, /*12: A socket must be signalled. */ - eSocketSetDeleteEvent /*13: A socket set must be deleted. */ + eNDTimerEvent, /* 4: The ND timer expired. */ + eStackTxEvent, /* 5: The software stack has queued a packet to transmit. */ + eDHCPEvent, /* 6: Process the DHCP state machine. */ + eTCPTimerEvent, /* 7: See if any TCP socket needs attention. */ + eTCPAcceptEvent, /* 8: Client API FreeRTOS_accept() waiting for client connections. */ + eTCPNetStat, /* 9: IP-task is asked to produce a netstat listing. */ + eSocketBindEvent, /*10: Send a message to the IP-task to bind a socket to a port. */ + eSocketCloseEvent, /*11: Send a message to the IP-task to close a socket. */ + eSocketSelectEvent, /*12: Send a message to the IP-task for select(). */ + eSocketSignalEvent, /*13: A socket must be signalled. */ + eSocketSetDeleteEvent /*14: A socket set must be deleted. */ } eIPEvent_t; /** @@ -437,23 +438,6 @@ uint16_t usGenerateChecksum( uint16_t usSum, /* Socket related private functions. */ -/* - * The caller must ensure that pxNetworkBuffer->xDataLength is the UDP packet - * payload size (excluding packet headers) and that the packet in pucEthernetBuffer - * is at least the size of UDPPacket_t. - */ -BaseType_t xProcessReceivedUDPPacket( NetworkBufferDescriptor_t * pxNetworkBuffer, - uint16_t usPort, - BaseType_t * pxIsWaitingForARPResolution ); - -BaseType_t xProcessReceivedUDPPacket_IPv4( NetworkBufferDescriptor_t * pxNetworkBuffer, - uint16_t usPort, - BaseType_t * pxIsWaitingForARPResolution ); - -BaseType_t xProcessReceivedUDPPacket_IPv6( NetworkBufferDescriptor_t * pxNetworkBuffer, - uint16_t usPort, - BaseType_t * pxIsWaitingForARPResolution ); - /* * Initialize the socket list data structures for TCP and UDP. */ @@ -859,7 +843,7 @@ BaseType_t xIsCallingFromIPTask( void ); #endif /* ipconfigSUPPORT_SELECT_FUNCTION */ -/* Send the network-up event and start the ARP timer. */ +/* Send the network-up event and start the ARP/ND timers. */ void vIPNetworkUpCalls( struct xNetworkEndPoint * pxEndPoint ); /* Mark whether all interfaces are up or at least one interface is down. */ diff --git a/source/include/FreeRTOS_IP_Timers.h b/source/include/FreeRTOS_IP_Timers.h index 8d7a84e263..3f23ffe34c 100644 --- a/source/include/FreeRTOS_IP_Timers.h +++ b/source/include/FreeRTOS_IP_Timers.h @@ -48,7 +48,6 @@ #include "FreeRTOS_IP.h" #include "FreeRTOS_Sockets.h" #include "FreeRTOS_IP_Private.h" -#include "FreeRTOS_ARP.h" #include "FreeRTOS_UDP_IP.h" #include "FreeRTOS_DHCP.h" #include "NetworkInterface.h" @@ -62,7 +61,7 @@ /* *INDENT-ON* */ /* - * Checks the ARP, DHCP and TCP timers to see if any periodic or timeout + * Checks the ARP, ND, DHCP and TCP timers to see if any periodic or timeout * processing is required. */ void vCheckNetworkTimers( void ); @@ -74,24 +73,55 @@ void vCheckNetworkTimers( void ); TickType_t xCalculateSleepTime( void ); /* - * Start an ARP Resolution timer. + * Enable/disable the TCP timer. + */ +void vIPSetTCPTimerExpiredState( BaseType_t xExpiredState ); + +#if ipconfigIS_ENABLED( ipconfigUSE_IPv4 ) + +/** + * Sets the reload time of an ARP timer and restarts it. */ -void vIPTimerStartARPResolution( TickType_t xTime ); + void vARPTimerReload( TickType_t xTime ); /* - * Enable/disable the TCP timer. + * Start an ARP Resolution timer. */ -void vIPSetTCPTimerExpiredState( BaseType_t xExpiredState ); + void vIPTimerStartARPResolution( TickType_t xTime ); /* * Enable/disable the ARP timer. */ -void vIPSetARPTimerEnableState( BaseType_t xEnableState ); + void vIPSetARPTimerEnableState( BaseType_t xEnableState ); /* * Enable or disable the ARP resolution timer. */ -void vIPSetARPResolutionTimerEnableState( BaseType_t xEnableState ); + void vIPSetARPResolutionTimerEnableState( BaseType_t xEnableState ); +#endif /* if ipconfigIS_ENABLED( ipconfigUSE_IPv4 ) */ + +#if ipconfigIS_ENABLED( ipconfigUSE_IPv6 ) + +/** + * Sets the reload time of an ND timer and restarts it. + */ + void vNDTimerReload( TickType_t xTime ); + +/* + * Start an ND Resolution timer. + */ + void vIPTimerStartNDResolution( TickType_t xTime ); + +/* + * Enable/disable the ND timer. + */ + void vIPSetNDTimerEnableState( BaseType_t xEnableState ); + +/* + * Enable or disable the ARP resolution timer. + */ + void vIPSetNDResolutionTimerEnableState( BaseType_t xEnableState ); +#endif /* if ipconfigIS_ENABLED( ipconfigUSE_IPv6 ) */ #if ( ipconfigUSE_DHCP == 1 ) || ( ipconfigUSE_RA == 1 ) @@ -113,11 +143,6 @@ void vIPSetARPResolutionTimerEnableState( BaseType_t xEnableState ); void vIPSetDNSTimerEnableState( BaseType_t xEnableState ); #endif /* ipconfigDNS_USE_CALLBACKS != 0 */ -/** - * Sets the reload time of an ARP timer and restarts it. - */ -void vARPTimerReload( TickType_t xTime ); - /** * Sets the reload time of an TCP timer and restarts it. */ diff --git a/source/include/FreeRTOS_IP_Utils.h b/source/include/FreeRTOS_IP_Utils.h index 301f149055..6f8cd07b67 100644 --- a/source/include/FreeRTOS_IP_Utils.h +++ b/source/include/FreeRTOS_IP_Utils.h @@ -47,7 +47,6 @@ /* FreeRTOS+TCP includes. */ #include "FreeRTOS_IP.h" #include "FreeRTOS_Sockets.h" -#include "FreeRTOS_Routing.h" #include "FreeRTOS_IP_Private.h" #include "FreeRTOS_UDP_IP.h" #include "FreeRTOS_DHCP.h" @@ -66,6 +65,7 @@ /* Forward declaration. */ struct xNetworkInterface; +struct xNetworkEndPoint; #if ( ( ipconfigUSE_DHCPv6 == 1 ) || ( ipconfigUSE_DHCP == 1 ) || ( ipconfigUSE_RA == 1 ) ) diff --git a/source/include/FreeRTOS_IPv4.h b/source/include/FreeRTOS_IPv4.h index 8a9d59320a..7197ab9f00 100644 --- a/source/include/FreeRTOS_IPv4.h +++ b/source/include/FreeRTOS_IPv4.h @@ -81,12 +81,6 @@ uint32_t FreeRTOS_GetDNSServerAddress( void ); uint32_t FreeRTOS_GetNetmask( void ); uint32_t FreeRTOS_GetIPAddress( void ); -/* Show all valid ARP entries - */ -#if ( ipconfigHAS_PRINTF != 0 ) || ( ipconfigHAS_DEBUG_PRINTF != 0 ) - void FreeRTOS_PrintARPCache( void ); -#endif - /* Return pdTRUE if the IPv4 address is a multicast address. */ BaseType_t xIsIPv4Multicast( uint32_t ulIPAddress ); diff --git a/source/include/FreeRTOS_IPv6.h b/source/include/FreeRTOS_IPv6.h index 0706a7dac4..ea2d9dbcae 100644 --- a/source/include/FreeRTOS_IPv6.h +++ b/source/include/FreeRTOS_IPv6.h @@ -107,8 +107,6 @@ BaseType_t xIsIPv6Loopback( const IPv6_Address_t * pxAddress ); eFrameProcessingResult_t eHandleIPv6ExtensionHeaders( NetworkBufferDescriptor_t * const pxNetworkBuffer, BaseType_t xDoRemove ); -extern void FreeRTOS_ClearND( void ); - /* Check whether this IPv6 address is an allowed multicast address or not. */ BaseType_t xIsIPv6AllowedMulticast( const IPv6_Address_t * pxIPAddress ); diff --git a/source/include/FreeRTOS_ND.h b/source/include/FreeRTOS_ND.h index d0f1685313..e6119f05c1 100644 --- a/source/include/FreeRTOS_ND.h +++ b/source/include/FreeRTOS_ND.h @@ -32,7 +32,7 @@ #include "FreeRTOSIPConfig.h" #include "FreeRTOSIPConfigDefaults.h" -#include "FreeRTOS_ARP.h" +#include "FreeRTOS_Routing.h" /* *INDENT-OFF* */ #ifdef __cplusplus @@ -88,14 +88,14 @@ * * @note Look for ulIPAddress in the ND cache. If the IP address exists, copy the * associated MAC address into pxMACAddress, refresh the ND cache entry's - * age, and return eARPCacheHit. If the IP address does not exist in the ND - * cache return eARPCacheMiss. If the packet cannot be sent for any reason + * age, and return eResolutionCacheHit. If the IP address does not exist in the ND + * cache return eResolutionCacheMiss. If the packet cannot be sent for any reason * (maybe DHCP is still in process, or the addressing needs a gateway but there - * isn't a gateway defined) then return eCantSendPacket. + * isn't a gateway defined) then return eResolutionFailed. */ - eARPLookupResult_t eNDGetCacheEntry( IPv6_Address_t * pxIPAddress, - MACAddress_t * const pxMACAddress, - struct xNetworkEndPoint ** ppxEndPoint ); + eResolutionLookupResult_t eNDGetCacheEntry( IPv6_Address_t * pxIPAddress, + MACAddress_t * const pxMACAddress, + struct xNetworkEndPoint ** ppxEndPoint ); /** * @brief Reduce the age counter in each entry within the ND cache. An entry is no @@ -204,8 +204,16 @@ void FreeRTOS_PrintNDCache( void ); #endif + BaseType_t xCheckRequiresNDResolution( const NetworkBufferDescriptor_t * pxNetworkBuffer ); + +/* Clear all entries in the ND cache. */ + void FreeRTOS_ClearND( const struct xNetworkEndPoint * pxEndPoint ); + + void vNDSendUnsolicited( void ); + extern const uint8_t pcLOCAL_ALL_NODES_MULTICAST_IP[ ipSIZE_OF_IPv6_ADDRESS ]; extern const uint8_t pcLOCAL_ALL_NODES_MULTICAST_MAC[ ipMAC_ADDRESS_LENGTH_BYTES ]; + #endif /* ipconfigUSE_IPv6 != 0 */ diff --git a/source/include/FreeRTOS_Routing.h b/source/include/FreeRTOS_Routing.h index 106db7f915..dc45a0d674 100644 --- a/source/include/FreeRTOS_Routing.h +++ b/source/include/FreeRTOS_Routing.h @@ -371,6 +371,15 @@ IPv6_Type_t xIPv6_GetIPType( const IPv6_Address_t * pxAddress ); #endif + BaseType_t xCheckRequiresResolution( const NetworkBufferDescriptor_t * pxNetworkBuffer ); + + typedef enum + { + eResolutionCacheMiss = 0, /* 0 A cache lookup did not find a valid entry. */ + eResolutionCacheHit, /* 1 A cache lookup found a valid entry. */ + eResolutionFailed /* 2 There is no IP address, or a resolution is still in progress, so the packet cannot be sent. */ + } eResolutionLookupResult_t; + #ifdef __cplusplus } /* extern "C" */ #endif diff --git a/source/include/FreeRTOS_TCP_Transmission.h b/source/include/FreeRTOS_TCP_Transmission.h index df8f4824be..1e48fbc30a 100644 --- a/source/include/FreeRTOS_TCP_Transmission.h +++ b/source/include/FreeRTOS_TCP_Transmission.h @@ -97,7 +97,7 @@ void prvTCPReturn_SetEndPoint( const FreeRTOS_Socket_t * pxSocket, BaseType_t prvTCPPrepareConnect_IPV4( FreeRTOS_Socket_t * pxSocket ); /* - * Let ARP look-up the MAC-address of the peer and initialise the first SYN + * Let ND look-up the MAC-address of the peer and initialise the first SYN * packet. */ BaseType_t prvTCPPrepareConnect_IPV6( FreeRTOS_Socket_t * pxSocket ); diff --git a/source/include/FreeRTOS_UDP_IP.h b/source/include/FreeRTOS_UDP_IP.h index 0285aaebbe..c1a6f35443 100644 --- a/source/include/FreeRTOS_UDP_IP.h +++ b/source/include/FreeRTOS_UDP_IP.h @@ -44,11 +44,26 @@ */ void vProcessGeneratedUDPPacket( NetworkBufferDescriptor_t * const pxNetworkBuffer ); -/* - * _HT_ added in order to avoid warnings while testing. */ void vProcessGeneratedUDPPacket_IPv4( NetworkBufferDescriptor_t * const pxNetworkBuffer ); void vProcessGeneratedUDPPacket_IPv6( NetworkBufferDescriptor_t * const pxNetworkBuffer ); +/* + * The caller must ensure that pxNetworkBuffer->xDataLength is the UDP packet + * payload size (excluding packet headers) and that the packet in pucEthernetBuffer + * is at least the size of UDPPacket_t. + */ +BaseType_t xProcessReceivedUDPPacket( NetworkBufferDescriptor_t * pxNetworkBuffer, + uint16_t usPort, + BaseType_t * pxIsWaitingForResolution ); + +BaseType_t xProcessReceivedUDPPacket_IPv4( NetworkBufferDescriptor_t * pxNetworkBuffer, + uint16_t usPort, + BaseType_t * pxIsWaitingForARPResolution ); + +BaseType_t xProcessReceivedUDPPacket_IPv6( NetworkBufferDescriptor_t * pxNetworkBuffer, + uint16_t usPort, + BaseType_t * pxIsWaitingForNDResolution ); + /* *INDENT-OFF* */ #ifdef __cplusplus } /* extern "C" */ diff --git a/source/include/IPTraceMacroDefaults.h b/source/include/IPTraceMacroDefaults.h index 802525d77a..fe3ec8aa2f 100644 --- a/source/include/IPTraceMacroDefaults.h +++ b/source/include/IPTraceMacroDefaults.h @@ -129,7 +129,7 @@ * [re]connecting. * eNetworkRxEvent - The network interface has queued a received Ethernet * frame. - * eARPTimerEvent - The ARP timer expired. + * eARPTimerEvent - The Resolution timer expired. * eStackTxEvent - The software stack has queued a packet to transmit. * eDHCPEvent - Process the DHCP state machine. * @@ -418,13 +418,13 @@ /*---------------------------------------------------------------------------*/ /* - * traceARP_PACKET_RECEIVED + * iptraceARP_PACKET_RECEIVED * * Called when an ARP packet is received, even if the local network node is not * involved in the ARP transaction. */ -#ifndef traceARP_PACKET_RECEIVED - #define traceARP_PACKET_RECEIVED() +#ifndef iptraceARP_PACKET_RECEIVED + #define iptraceARP_PACKET_RECEIVED() #endif /*---------------------------------------------------------------------------*/ @@ -587,6 +587,81 @@ /*===========================================================================*/ /*---------------------------------------------------------------------------*/ /*===========================================================================*/ +/* ND TRACE MACROS */ +/*===========================================================================*/ + +/*---------------------------------------------------------------------------*/ + +/* + * iptraceND_TABLE_ENTRY_EXPIRED + */ +#ifndef iptraceND_TABLE_ENTRY_EXPIRED + #define iptraceND_TABLE_ENTRY_EXPIRED( pxIPAddress ) +#endif + +/*---------------------------------------------------------------------------*/ + +/* + * iptraceND_TABLE_ENTRY_WILL_EXPIRE + */ +#ifndef iptraceND_TABLE_ENTRY_WILL_EXPIRE + #define iptraceND_TABLE_ENTRY_WILL_EXPIRE( pxIPAddress ) +#endif + +/*---------------------------------------------------------------------------*/ + +/* + * iptraceDELAYED_ND_BUFFER_FULL + * + * A packet has come in from an unknown IPv6 address. An ND request has been + * sent, but the queue is still filled with a different packet. + */ +#ifndef iptraceDELAYED_ND_BUFFER_FULL + #define iptraceDELAYED_ND_BUFFER_FULL() +#endif + +/*---------------------------------------------------------------------------*/ + +/* + * iptrace_DELAYED_ND_REQUEST_REPLIED + */ +#ifndef iptrace_DELAYED_ND_REQUEST_REPLIED + #define iptrace_DELAYED_ND_REQUEST_REPLIED() +#endif + +/*---------------------------------------------------------------------------*/ + +/* + * iptraceDELAYED_ND_REQUEST_STARTED + * + * A packet came in from an unknown IPv6 address. An ND request has been sent + * and the network buffer is stored for processing later. + */ +#ifndef iptraceDELAYED_ND_REQUEST_STARTED + #define iptraceDELAYED_ND_REQUEST_STARTED() +#endif + +/*---------------------------------------------------------------------------*/ + +/* + * iptraceDELAYED_ND_TIMER_EXPIRED + * + * A packet was stored for delayed processing, but there is no ND reply. The + * network buffer will be released without being processed. + */ +#ifndef iptraceDELAYED_ND_TIMER_EXPIRED + #define iptraceDELAYED_ND_TIMER_EXPIRED() +#endif + +/*---------------------------------------------------------------------------*/ + +/*===========================================================================*/ +/* ND TRACE MACROS */ +/*===========================================================================*/ +/*---------------------------------------------------------------------------*/ +/*===========================================================================*/ +/*---------------------------------------------------------------------------*/ +/*===========================================================================*/ /* DHCP TRACE MACROS */ /*===========================================================================*/ @@ -715,36 +790,6 @@ /*===========================================================================*/ /*---------------------------------------------------------------------------*/ /*===========================================================================*/ -/* NDP TRACE MACROS */ -/*===========================================================================*/ - -/*---------------------------------------------------------------------------*/ - -/* - * iptraceND_TABLE_ENTRY_EXPIRED - */ -#ifndef iptraceND_TABLE_ENTRY_EXPIRED - #define iptraceND_TABLE_ENTRY_EXPIRED( pxIPAddress ) -#endif - -/*---------------------------------------------------------------------------*/ - -/* - * iptraceND_TABLE_ENTRY_WILL_EXPIRE - */ -#ifndef iptraceND_TABLE_ENTRY_WILL_EXPIRE - #define iptraceND_TABLE_ENTRY_WILL_EXPIRE( pxIPAddress ) -#endif - -/*---------------------------------------------------------------------------*/ - -/*===========================================================================*/ -/* NDP TRACE MACROS */ -/*===========================================================================*/ -/*---------------------------------------------------------------------------*/ -/*===========================================================================*/ -/*---------------------------------------------------------------------------*/ -/*===========================================================================*/ /* ROUTER ADVERTISEMENT TRACE MACROS */ /*===========================================================================*/ diff --git a/test/build-combination/Common/main.c b/test/build-combination/Common/main.c index f2617a1d26..f904ad5a7e 100644 --- a/test/build-combination/Common/main.c +++ b/test/build-combination/Common/main.c @@ -38,6 +38,7 @@ #include "FreeRTOS_IP.h" #include "FreeRTOS_Sockets.h" #include "FreeRTOS_DHCP.h" +#include "FreeRTOS_Routing.h" #include #include diff --git a/test/cbmc/proofs/ARP/ARPProcessPacket/ARPProcessPacket_harness.c b/test/cbmc/proofs/ARP/ARPProcessPacket/ARPProcessPacket_harness.c index f9cd7798ad..b170e22cbf 100644 --- a/test/cbmc/proofs/ARP/ARPProcessPacket/ARPProcessPacket_harness.c +++ b/test/cbmc/proofs/ARP/ARPProcessPacket/ARPProcessPacket_harness.c @@ -46,11 +46,11 @@ void FreeRTOS_OutputARPRequest_Multi( NetworkEndPoint_t * pxEndPoint, } /* This function is proved elsewhere hence stubbing it out */ -eARPLookupResult_t eARPGetCacheEntry( uint32_t * pulIPAddress, - MACAddress_t * const pxMACAddress, - struct xNetworkEndPoint ** ppxEndPoint ) +eResolutionLookupResult_t eARPGetCacheEntry( uint32_t * pulIPAddress, + MACAddress_t * const pxMACAddress, + struct xNetworkEndPoint ** ppxEndPoint ) { - eARPLookupResult_t eReturn; + eResolutionLookupResult_t eReturn; __CPROVER_assert( pulIPAddress != NULL, "pulIPAddress cannot be NULL." ); __CPROVER_assert( pxMACAddress != NULL, "pxMACAddress cannot be NULL." ); diff --git a/test/cbmc/proofs/ARP/xCheckRequiresARPResolution/xCheckRequiresARPResolution_harness.c b/test/cbmc/proofs/ARP/xCheckRequiresARPResolution/xCheckRequiresARPResolution_harness.c index 99c8c5051a..fb92dfd72e 100644 --- a/test/cbmc/proofs/ARP/xCheckRequiresARPResolution/xCheckRequiresARPResolution_harness.c +++ b/test/cbmc/proofs/ARP/xCheckRequiresARPResolution/xCheckRequiresARPResolution_harness.c @@ -55,11 +55,11 @@ IPv6_Type_t xIPv6_GetIPType( const IPv6_Address_t * pxAddress ) } /* Abstraction of eNDGetCacheEntry. */ -eARPLookupResult_t eNDGetCacheEntry( IPv6_Address_t * pxIPAddress, - MACAddress_t * const pxMACAddress, - struct xNetworkEndPoint ** ppxEndPoint ) +eResolutionLookupResult_t eNDGetCacheEntry( IPv6_Address_t * pxIPAddress, + MACAddress_t * const pxMACAddress, + struct xNetworkEndPoint ** ppxEndPoint ) { - eARPLookupResult_t xReturn; + eResolutionLookupResult_t xReturn; __CPROVER_assert( __CPROVER_r_ok( pxIPAddress, sizeof( IPv6_Address_t ) ), "pxIPAddress must be readable" ); __CPROVER_assert( __CPROVER_w_ok( pxMACAddress, sizeof( MACAddress_t ) ), "pxMACAddress must be writeable" ); @@ -89,19 +89,11 @@ void harness() size_t xBufferLength; NetworkBufferDescriptor_t * pxNetworkBuffer; IPPacket_t * pxIPPacket; + IPHeader_t * pxIPHeader; - /* IPv4/IPv6 header size are different. To make sure buffer size is enough, - * determine the test case is for IPv4 or IPv6 at the beginning. */ - xIsIPv6 = nondet_bool(); - - if( xIsIPv6 ) - { - __CPROVER_assume( ( xBufferLength >= sizeof( IPPacket_IPv6_t ) ) && ( xBufferLength < ipconfigNETWORK_MTU ) ); - } - else - { - __CPROVER_assume( ( xBufferLength >= sizeof( IPPacket_t ) ) && ( xBufferLength < ipconfigNETWORK_MTU ) ); - } + /* Make sure buffer size is enough, xCheckRequiresARPResolution is only called for + * IPv4 packets hence the minimum size should be sizeof( IPPacket_t ) */ + __CPROVER_assume( ( xBufferLength >= sizeof( IPPacket_t ) ) && ( xBufferLength < ipconfigNETWORK_MTU ) ); pxNetworkBuffer = ( NetworkBufferDescriptor_t * ) safeMalloc( sizeof( NetworkBufferDescriptor_t ) ); __CPROVER_assume( pxNetworkBuffer != NULL ); @@ -111,6 +103,14 @@ void harness() pxNetworkBuffer->pucEthernetBuffer = safeMalloc( xBufferLength ); __CPROVER_assume( pxNetworkBuffer->pucEthernetBuffer != NULL ); + /* Its asserted in the code that xCheckRequiresARPResolution is only called on IPv4 frame types */ + + /* See assertion: configASSERT( ( pxIPPacket->xEthernetHeader.usFrameType == ipIPv4_FRAME_TYPE ) || ( pxIPPacket->xEthernetHeader.usFrameType == ipARP_FRAME_TYPE ) ); + * in xCheckRequiresARPResolution() */ + pxIPPacket = ( ( const IPPacket_t * ) pxNetworkBuffer->pucEthernetBuffer ); + pxIPHeader = &( pxIPPacket->xIPHeader ); + __CPROVER_assume( pxIPPacket->xEthernetHeader.usFrameType == ipIPv4_FRAME_TYPE ); + pxNetworkBuffer->pxEndPoint = ( NetworkEndPoint_t * ) safeMalloc( sizeof( NetworkEndPoint_t ) ); __CPROVER_assume( pxNetworkBuffer->pxEndPoint != NULL ); diff --git a/test/cbmc/proofs/ND/prvProcessICMPMessage_IPv6/ProcessICMPMessage_IPv6_harness.c b/test/cbmc/proofs/ND/prvProcessICMPMessage_IPv6/ProcessICMPMessage_IPv6_harness.c index 0b02ac8ed2..8fdbc87a71 100644 --- a/test/cbmc/proofs/ND/prvProcessICMPMessage_IPv6/ProcessICMPMessage_IPv6_harness.c +++ b/test/cbmc/proofs/ND/prvProcessICMPMessage_IPv6/ProcessICMPMessage_IPv6_harness.c @@ -156,7 +156,7 @@ void harness() * which is validated only when bIPv6 is set*/ __CPROVER_assume( ( pxNetworkBuffer->pxEndPoint != NULL ) && ( pxNetworkBuffer->pxEndPoint->bits.bIPv6 == pdTRUE_UNSIGNED ) ); - /* Non deterministically determine whether the pxARPWaitingNetworkBuffer will + /* Non deterministically determine whether the pxNDWaitingNetworkBuffer will * point to some valid data or will it be NULL. */ if( nondet_bool() ) { @@ -167,7 +167,7 @@ void harness() pxLocalARPWaitingNetworkBuffer = pxGetNetworkBufferWithDescriptor( usEthernetBufferSize, 0 ); /* Since this pointer is maintained by the IP-task, either the pointer - * pxARPWaitingNetworkBuffer will be NULL or pxLocalARPWaitingNetworkBuffer.pucEthernetBuffer + * pxNDWaitingNetworkBuffer will be NULL or pxLocalARPWaitingNetworkBuffer.pucEthernetBuffer * will be non-NULL. */ __CPROVER_assume( pxLocalARPWaitingNetworkBuffer != NULL ); __CPROVER_assume( pxLocalARPWaitingNetworkBuffer->pucEthernetBuffer != NULL ); @@ -176,11 +176,11 @@ void harness() /* Add matching data length to the network buffer descriptor. */ pxLocalARPWaitingNetworkBuffer->xDataLength = usEthernetBufferSize; - pxARPWaitingNetworkBuffer = pxLocalARPWaitingNetworkBuffer; + pxNDWaitingNetworkBuffer = pxLocalARPWaitingNetworkBuffer; } else { - pxARPWaitingNetworkBuffer = NULL; + pxNDWaitingNetworkBuffer = NULL; } prvProcessICMPMessage_IPv6( pxNetworkBuffer ); diff --git a/test/cbmc/proofs/ND/prvReturnICMP_IPv6/ReturnICMP_IPv6_harness.c b/test/cbmc/proofs/ND/prvReturnICMP_IPv6/ReturnICMP_IPv6_harness.c index e0340a76cd..597734285c 100644 --- a/test/cbmc/proofs/ND/prvReturnICMP_IPv6/ReturnICMP_IPv6_harness.c +++ b/test/cbmc/proofs/ND/prvReturnICMP_IPv6/ReturnICMP_IPv6_harness.c @@ -161,7 +161,7 @@ void harness() __CPROVER_assume( ( pxNetworkBuffer->pxEndPoint != NULL ) && ( pxNetworkBuffer->pxEndPoint->bits.bIPv6 == pdTRUE_UNSIGNED ) ); - /* Initializing pxARPWaitingNetworkBuffer */ + /* Initializing pxNDWaitingNetworkBuffer */ /* The packet must at least be as big as an IPv6 Packet. The size is not * checked in the function as the pointer is stored by the IP-task itself @@ -170,7 +170,7 @@ void harness() pxLocalARPWaitingNetworkBuffer = pxGetNetworkBufferWithDescriptor( usEthernetBufferSize, 0 ); /* Since this pointer is maintained by the IP-task, either the pointer - * pxARPWaitingNetworkBuffer will be NULL or pxLocalARPWaitingNetworkBuffer.pucEthernetBuffer + * pxNDWaitingNetworkBuffer will be NULL or pxLocalARPWaitingNetworkBuffer.pucEthernetBuffer * will be non-NULL. */ __CPROVER_assume( pxLocalARPWaitingNetworkBuffer != NULL ); __CPROVER_assume( pxLocalARPWaitingNetworkBuffer->pucEthernetBuffer != NULL ); @@ -179,7 +179,7 @@ void harness() /* Add matching data length to the network buffer descriptor. */ pxLocalARPWaitingNetworkBuffer->xDataLength = usEthernetBufferSize; - pxARPWaitingNetworkBuffer = pxLocalARPWaitingNetworkBuffer; + pxNDWaitingNetworkBuffer = pxLocalARPWaitingNetworkBuffer; prvProcessICMPMessage_IPv6( pxNetworkBuffer ); } diff --git a/test/cbmc/proofs/TCP/prvTCPReturnPacket/TCPReturnPacket_harness.c b/test/cbmc/proofs/TCP/prvTCPReturnPacket/TCPReturnPacket_harness.c index 9f03585c39..1e5d4dbc35 100644 --- a/test/cbmc/proofs/TCP/prvTCPReturnPacket/TCPReturnPacket_harness.c +++ b/test/cbmc/proofs/TCP/prvTCPReturnPacket/TCPReturnPacket_harness.c @@ -173,18 +173,18 @@ uint16_t usGenerateChecksum( uint16_t usSum, } /* This function has been tested separately. Therefore, we assume that the implementation is correct. */ -eARPLookupResult_t eARPGetCacheEntry( uint32_t * pulIPAddress, - MACAddress_t * const pxMACAddress, - struct xNetworkEndPoint ** ppxEndPoint ) +eResolutionLookupResult_t eARPGetCacheEntry( uint32_t * pulIPAddress, + MACAddress_t * const pxMACAddress, + struct xNetworkEndPoint ** ppxEndPoint ) { /* Assume random ARP lookup result. */ - eARPLookupResult_t eReturn; + eResolutionLookupResult_t eReturn; /* Make sure NULL pointers are not passed as arguments. */ __CPROVER_assert( pulIPAddress != NULL, "The pulIPAddress cannot be NULL" ); __CPROVER_assert( pxMACAddress != NULL, "The pxMACAddress cannot be NULL" ); - if( eReturn == eARPCacheHit ) + if( eReturn == eResolutionCacheHit ) { /* If its a cache hit, update ppxEndPoint with a valid endpoint. */ struct xNetworkEndPoint * pxEndPoint = ( NetworkEndPoint_t * ) safeMalloc( sizeof( NetworkEndPoint_t ) ); diff --git a/test/cbmc/proofs/TCP/prvTCPReturnPacket_IPv6/TCPReturnPacket_IPv6_harness.c b/test/cbmc/proofs/TCP/prvTCPReturnPacket_IPv6/TCPReturnPacket_IPv6_harness.c index d768af7c38..a51fa8ef0c 100644 --- a/test/cbmc/proofs/TCP/prvTCPReturnPacket_IPv6/TCPReturnPacket_IPv6_harness.c +++ b/test/cbmc/proofs/TCP/prvTCPReturnPacket_IPv6/TCPReturnPacket_IPv6_harness.c @@ -96,11 +96,11 @@ void prvTCPReturnPacket_IPV4( FreeRTOS_Socket_t * pxSocket, } /* Abstraction of eNDGetCacheEntry. */ -eARPLookupResult_t eNDGetCacheEntry( IPv6_Address_t * pxIPAddress, - MACAddress_t * const pxMACAddress, - struct xNetworkEndPoint ** ppxEndPoint ) +eResolutionLookupResult_t eNDGetCacheEntry( IPv6_Address_t * pxIPAddress, + MACAddress_t * const pxMACAddress, + struct xNetworkEndPoint ** ppxEndPoint ) { - eARPLookupResult_t xReturn; + eResolutionLookupResult_t xReturn; __CPROVER_assert( __CPROVER_r_ok( pxIPAddress, sizeof( IPv6_Address_t ) ), "pxIPAddress must be readable" ); __CPROVER_assert( __CPROVER_w_ok( pxMACAddress, sizeof( MACAddress_t ) ), "pxMACAddress must be writeable" ); diff --git a/test/cbmc/proofs/UDP/vProcessGeneratedUDPPacket/vProcessGeneratedUDPPacket_harness.c b/test/cbmc/proofs/UDP/vProcessGeneratedUDPPacket/vProcessGeneratedUDPPacket_harness.c index 5d8239d8a4..1ff6cf86be 100644 --- a/test/cbmc/proofs/UDP/vProcessGeneratedUDPPacket/vProcessGeneratedUDPPacket_harness.c +++ b/test/cbmc/proofs/UDP/vProcessGeneratedUDPPacket/vProcessGeneratedUDPPacket_harness.c @@ -69,13 +69,13 @@ void vARPGenerateRequestPacket( NetworkBufferDescriptor_t * const pxNetworkBuffe /* This function has been tested separately. Therefore, we assume that the implementation is correct. */ -eARPLookupResult_t eARPGetCacheEntry( uint32_t * pulIPAddress, - MACAddress_t * const pxMACAddress ) +eResolutionLookupResult_t eARPGetCacheEntry( uint32_t * pulIPAddress, + MACAddress_t * const pxMACAddress ) { __CPROVER_assert( pulIPAddress != NULL, "pulIPAddress cannot be NULL" ); __CPROVER_assert( pxMACAddress != NULL, "pxMACAddress cannot be NULL" ); - eARPLookupResult_t eResult; + eResolutionLookupResult_t eResult; return eResult; } diff --git a/test/cbmc/proofs/UDP/vProcessGeneratedUDPPacket_IPv6/vProcessGeneratedUDPPacket_IPv6_harness.c b/test/cbmc/proofs/UDP/vProcessGeneratedUDPPacket_IPv6/vProcessGeneratedUDPPacket_IPv6_harness.c index 000fb49a9a..f4e7d9e971 100644 --- a/test/cbmc/proofs/UDP/vProcessGeneratedUDPPacket_IPv6/vProcessGeneratedUDPPacket_IPv6_harness.c +++ b/test/cbmc/proofs/UDP/vProcessGeneratedUDPPacket_IPv6/vProcessGeneratedUDPPacket_IPv6_harness.c @@ -48,11 +48,11 @@ uint16_t usGenerateProtocolChecksum( const uint8_t * const pucEthernetBuffer, } /* This function has been tested separately. Therefore, we assume that the implementation is correct. */ -eARPLookupResult_t eNDGetCacheEntry( IPv6_Address_t * pxIPAddress, - MACAddress_t * const pxMACAddress, - struct xNetworkEndPoint ** ppxEndPoint ) +eResolutionLookupResult_t eNDGetCacheEntry( IPv6_Address_t * pxIPAddress, + MACAddress_t * const pxMACAddress, + struct xNetworkEndPoint ** ppxEndPoint ) { - eARPLookupResult_t eResult; + eResolutionLookupResult_t eResult; __CPROVER_assert( pxIPAddress != NULL, "pxIPAddress cannot be NULL" ); __CPROVER_assert( pxMACAddress != NULL, "pxMACAddress cannot be NULL" ); diff --git a/test/cbmc/proofs/parsing/ProcessIPPacket/ProcessIPPacket_harness.c b/test/cbmc/proofs/parsing/ProcessIPPacket/ProcessIPPacket_harness.c index 5b926e4c48..add375d180 100644 --- a/test/cbmc/proofs/parsing/ProcessIPPacket/ProcessIPPacket_harness.c +++ b/test/cbmc/proofs/parsing/ProcessIPPacket/ProcessIPPacket_harness.c @@ -42,12 +42,14 @@ BaseType_t xGetExtensionOrder( uint8_t ucProtocol, return xIsExtensionHeader( ucProtocol ); } -BaseType_t xCheckRequiresARPResolution( const NetworkBufferDescriptor_t * pxNetworkBuffer ) +BaseType_t xCheckRequiresResolution( const NetworkBufferDescriptor_t * pxNetworkBuffer ) { BaseType_t xReturn; __CPROVER_assert( pxNetworkBuffer != NULL, "pxNetworkBuffer cannot be NULL" ); __CPROVER_assert( __CPROVER_r_ok( pxNetworkBuffer->pucEthernetBuffer, pxNetworkBuffer->xDataLength ), "Data in pxNetworkBuffer must be readable" ); + + return xReturn; } void vARPRefreshCacheEntryAge( const MACAddress_t * pxMACAddress, diff --git a/test/cbmc/proofs/parsing/ProcessReceivedUDPPacket_IPv6/ProcessReceivedUDPPacket_IPv6_harness.c b/test/cbmc/proofs/parsing/ProcessReceivedUDPPacket_IPv6/ProcessReceivedUDPPacket_IPv6_harness.c index 5737bb359a..aef236b617 100644 --- a/test/cbmc/proofs/parsing/ProcessReceivedUDPPacket_IPv6/ProcessReceivedUDPPacket_IPv6_harness.c +++ b/test/cbmc/proofs/parsing/ProcessReceivedUDPPacket_IPv6/ProcessReceivedUDPPacket_IPv6_harness.c @@ -43,11 +43,12 @@ FreeRTOS_Socket_t * pxUDPSocketLookup( UBaseType_t uxLocalPort ) } /* This proof was done before. Hence we assume it to be correct here. */ -BaseType_t xCheckRequiresARPResolution( NetworkBufferDescriptor_t * pxNetworkBuffer ) +BaseType_t xCheckRequiresNDResolution( const NetworkBufferDescriptor_t * pxNetworkBuffer ) { BaseType_t xReturn; - __CPROVER_assume( ( xReturn == pdTRUE ) || ( xReturn == pdFALSE ) ); + __CPROVER_assert( pxNetworkBuffer != NULL, "pxNetworkBuffer cannot be NULL" ); + __CPROVER_assert( __CPROVER_r_ok( pxNetworkBuffer->pucEthernetBuffer, pxNetworkBuffer->xDataLength ), "Data in pxNetworkBuffer must be readable" ); return xReturn; } @@ -95,6 +96,7 @@ void harness() pxNetworkBuffer->pucEthernetBuffer = safeMalloc( sizeof( UDPPacket_IPv6_t ) ); pxNetworkBuffer->pxEndPoint = &xEndpoint; + pxNetworkBuffer->xDataLength = sizeof( UDPPacket_IPv6_t ); /* The ethernet buffer must be valid. */ __CPROVER_assume( pxNetworkBuffer->pucEthernetBuffer != NULL ); diff --git a/test/unit-test/CMakeLists.txt b/test/unit-test/CMakeLists.txt index cac757688e..e3e9bcfaf0 100644 --- a/test/unit-test/CMakeLists.txt +++ b/test/unit-test/CMakeLists.txt @@ -146,6 +146,7 @@ foreach( file ${TCP_INCLUDES} ) -UFreeRTOS_htonl -D__COVERITY__ -DTEST + -DipconfigIS_ENABLED -DipconfigUSE_IPv6 -DipconfigUSE_RA -I ${MODULE_ROOT_DIR}/tools/CMock/vendor/unity/src @@ -165,6 +166,7 @@ foreach( file ${TCP_INCLUDES} ) -UFreeRTOS_htonl -D__COVERITY__ -DTEST + -DipconfigIS_ENABLED -I ${MODULE_ROOT_DIR}/tools/CMock/vendor/unity/src -I ${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include -I ${UNIT_TEST_DIR}/ConfigFiles diff --git a/test/unit-test/FreeRTOS_ARP/FreeRTOS_ARP_utest.c b/test/unit-test/FreeRTOS_ARP/FreeRTOS_ARP_utest.c index 106520eb79..c6b41eb1b6 100644 --- a/test/unit-test/FreeRTOS_ARP/FreeRTOS_ARP_utest.c +++ b/test/unit-test/FreeRTOS_ARP/FreeRTOS_ARP_utest.c @@ -1076,6 +1076,7 @@ void test_eARPProcessPacket_Reply_SenderAndTargetSame( void ) vResetARPClashCounter(); xEndPoint.bits.bEndPointUp = pdTRUE_UNSIGNED; + xEndPoint.bits.bIPv6 = pdFALSE_UNSIGNED; xNetworkBuffer.pucEthernetBuffer = ( uint8_t * ) pxARPFrame; xNetworkBuffer.xDataLength = sizeof( ARPPacket_t ); xNetworkBuffer.pxEndPoint = &xEndPoint; @@ -1468,6 +1469,8 @@ void test_xCheckRequiresARPResolution_NotOnLocalNetwork( void ) IPPacket_t * pxIPPacket = ( ( IPPacket_t * ) pxNetworkBuffer->pucEthernetBuffer ); IPHeader_t * pxIPHeader = &( pxIPPacket->xIPHeader ); + pxIPPacket->xEthernetHeader.usFrameType = ipIPv4_FRAME_TYPE; + xEndPoint.ipv4_settings.ulIPAddress = 0xABCD1234; xEndPoint.ipv4_settings.ulNetMask = 0xFFFFFF00; @@ -1497,6 +1500,8 @@ void test_xCheckRequiresARPResolution_NotOnLocalNetwork_InvalidHeader( void ) IPPacket_t * pxIPPacket = ( ( IPPacket_t * ) pxNetworkBuffer->pucEthernetBuffer ); IPHeader_t * pxIPHeader = &( pxIPPacket->xIPHeader ); + pxIPPacket->xEthernetHeader.usFrameType = ipARP_FRAME_TYPE; + xEndPoint.ipv4_settings.ulIPAddress = 0xABCD1234; xEndPoint.ipv4_settings.ulNetMask = 0xFFFFFF00; @@ -1526,6 +1531,8 @@ void test_xCheckRequiresARPResolution_NotOnLocalNetwork_IPv6( void ) IPPacket_t * pxIPPacket = ( ( IPPacket_t * ) pxNetworkBuffer->pucEthernetBuffer ); IPHeader_t * pxIPHeader = &( pxIPPacket->xIPHeader ); + pxIPPacket->xEthernetHeader.usFrameType = ipIPv4_FRAME_TYPE; + xEndPoint.ipv4_settings.ulIPAddress = 0xABCD1234; xEndPoint.ipv4_settings.ulNetMask = 0xFFFFFF00; @@ -1539,57 +1546,6 @@ void test_xCheckRequiresARPResolution_NotOnLocalNetwork_IPv6( void ) xResult = xCheckRequiresARPResolution( pxNetworkBuffer ); TEST_ASSERT_EQUAL( pdFALSE, xResult ); - /* =================================================== */ - - IPPacket_IPv6_t * pxIPPacket_V6 = ( ( IPPacket_IPv6_t * ) pxNetworkBuffer->pucEthernetBuffer ); - IPHeader_IPv6_t * pxIPHeader_V6 = &( pxIPPacket_V6->xIPHeader ); - IPv6_Address_t * pxIPAddress = &( pxIPHeader_V6->xSourceAddress ); - pxIPHeader_V6->ucNextHeader = ipPROTOCOL_TCP; - - xIPv6_GetIPType_ExpectAnyArgsAndReturn( eIPv6_LinkLocal ); - eNDGetCacheEntry_ExpectAnyArgsAndReturn( eARPCacheHit ); - - xResult = xCheckRequiresARPResolution( pxNetworkBuffer ); - - TEST_ASSERT_EQUAL( pdFALSE, xResult ); - /* =================================================== */ - - pxIPHeader_V6->ucNextHeader = ipPROTOCOL_UDP; - - xIPv6_GetIPType_ExpectAnyArgsAndReturn( eIPv6_LinkLocal ); - eNDGetCacheEntry_ExpectAnyArgsAndReturn( eARPCacheHit ); - - xResult = xCheckRequiresARPResolution( pxNetworkBuffer ); - - TEST_ASSERT_EQUAL( pdFALSE, xResult ); - /* =================================================== */ - - xIPv6_GetIPType_ExpectAnyArgsAndReturn( eIPv6_LinkLocal ); - eNDGetCacheEntry_ExpectAnyArgsAndReturn( eARPCacheMiss ); - NetworkBufferDescriptor_t xTempBuffer = { 0 }; - pxGetNetworkBufferWithDescriptor_ExpectAnyArgsAndReturn( &xTempBuffer ); - vNDSendNeighbourSolicitation_Expect( &xTempBuffer, pxIPAddress ); - - xResult = xCheckRequiresARPResolution( pxNetworkBuffer ); - - TEST_ASSERT_EQUAL( pdTRUE, xResult ); - /* =================================================== */ - - xIPv6_GetIPType_ExpectAnyArgsAndReturn( eIPv6_LinkLocal ); - eNDGetCacheEntry_ExpectAnyArgsAndReturn( eARPCacheMiss ); - pxGetNetworkBufferWithDescriptor_ExpectAnyArgsAndReturn( NULL ); - - xResult = xCheckRequiresARPResolution( pxNetworkBuffer ); - - TEST_ASSERT_EQUAL( pdTRUE, xResult ); - /* =================================================== */ - - xIPv6_GetIPType_ExpectAnyArgsAndReturn( eIPv6_SiteLocal ); - - xResult = xCheckRequiresARPResolution( pxNetworkBuffer ); - - TEST_ASSERT_EQUAL( pdFALSE, xResult ); - /* =================================================== */ } void test_xCheckRequiresARPResolution_OnLocalNetwork_NotInCache( void ) @@ -1607,6 +1563,8 @@ void test_xCheckRequiresARPResolution_OnLocalNetwork_NotInCache( void ) IPPacket_t * pxIPPacket = ( ( IPPacket_t * ) pxNetworkBuffer->pucEthernetBuffer ); IPHeader_t * pxIPHeader = &( pxIPPacket->xIPHeader ); + pxIPPacket->xEthernetHeader.usFrameType = ipIPv4_FRAME_TYPE; + xEndPoint.ipv4_settings.ulIPAddress = 0xABCD1234; xEndPoint.ipv4_settings.ulNetMask = 0xFFFFFF00; @@ -1648,6 +1606,8 @@ void test_xCheckRequiresARPResolution_OnLocalNetwork_InCache( void ) IPPacket_t * pxIPPacket = ( ( IPPacket_t * ) pxNetworkBuffer->pucEthernetBuffer ); IPHeader_t * pxIPHeader = &( pxIPPacket->xIPHeader ); + pxIPPacket->xEthernetHeader.usFrameType = ipIPv4_FRAME_TYPE; + xEndPoint.ipv4_settings.ulIPAddress = 0xABCD1234; xEndPoint.ipv4_settings.ulNetMask = 0xFFFFFF00; @@ -1670,6 +1630,26 @@ void test_xCheckRequiresARPResolution_OnLocalNetwork_InCache( void ) TEST_ASSERT_EQUAL( pdFALSE, xResult ); } +/** + * @brief Trigger assertion when Ethernet frame type is not IPv6 while calling xCheckRequiresARPResolution. + */ +void test_xCheckRequiresARPResolution_AssertInvalidFrameType( void ) +{ + struct xNetworkEndPoint xEndPoint = { 0 }; + NetworkBufferDescriptor_t xNetworkBuffer, * pxNetworkBuffer; + uint8_t ucEthernetBuffer[ ipconfigNETWORK_MTU ]; + BaseType_t xResult; + + pxNetworkBuffer = &xNetworkBuffer; + pxNetworkBuffer->pxEndPoint = &xEndPoint; + pxNetworkBuffer->pucEthernetBuffer = ucEthernetBuffer; + IPPacket_t * pxIPPacket = ( ( IPPacket_t * ) pxNetworkBuffer->pucEthernetBuffer ); + IPHeader_t * pxIPHeader = &( pxIPPacket->xIPHeader ); + + pxIPPacket->xEthernetHeader.usFrameType = ipIPv6_FRAME_TYPE; + + catch_assert( xCheckRequiresARPResolution( pxNetworkBuffer ) ); +} void test_ulARPRemoveCacheEntryByMac_NoMatch( void ) { @@ -1978,7 +1958,7 @@ void test_vARPRefreshCacheEntry_IPAndMACInDifferentLocations1( void ) void test_eARPGetCacheEntryByMac_catchAssert( void ) { uint32_t ulIPAddress = 0x12345678, ulEntryToTest; - eARPLookupResult_t eResult; + eResolutionLookupResult_t eResult; MACAddress_t xMACAddress = { 0x22, 0x22, 0x22, 0x22, 0x22, 0x22 }; int i; struct xNetworkInterface * xInterface; @@ -1991,7 +1971,7 @@ void test_eARPGetCacheEntryByMac_catchAssert( void ) void test_eARPGetCacheEntryByMac_NullInterface( void ) { uint32_t ulIPAddress = 0x12345678, ulEntryToTest; - eARPLookupResult_t eResult; + eResolutionLookupResult_t eResult; MACAddress_t xMACAddress = { 0x22, 0x22, 0x22, 0x22, 0x22, 0x22 }; int i; struct xNetworkInterface * xInterface; @@ -2005,7 +1985,7 @@ void test_eARPGetCacheEntryByMac_NullInterface( void ) } eResult = eARPGetCacheEntryByMac( &xMACAddress, &ulIPAddress, NULL ); - TEST_ASSERT_EQUAL( eARPCacheMiss, eResult ); + TEST_ASSERT_EQUAL( eResolutionCacheMiss, eResult ); TEST_ASSERT_EQUAL( 0x12345678, ulIPAddress ); /* =================================================== */ } @@ -2013,10 +1993,10 @@ void test_eARPGetCacheEntryByMac_NullInterface( void ) void test_eARPGetCacheEntryByMac_NoMatchingEntries( void ) { uint32_t ulIPAddress = 0x12345678, ulEntryToTest; - eARPLookupResult_t eResult; + eResolutionLookupResult_t eResult; MACAddress_t xMACAddress = { 0x22, 0x22, 0x22, 0x22, 0x22, 0x22 }; int i; - struct xNetworkInterface * xInterface; + NetworkInterface_t xInterface, * pxInterface = &xInterface; /* =================================================== */ /* Make sure no entry matches. */ @@ -2026,8 +2006,8 @@ void test_eARPGetCacheEntryByMac_NoMatchingEntries( void ) memset( xARPCache[ i ].xMACAddress.ucBytes, 0x11, sizeof( xMACAddress.ucBytes ) ); } - eResult = eARPGetCacheEntryByMac( &xMACAddress, &ulIPAddress, &xInterface ); - TEST_ASSERT_EQUAL( eARPCacheMiss, eResult ); + eResult = eARPGetCacheEntryByMac( &xMACAddress, &ulIPAddress, &pxInterface ); + TEST_ASSERT_EQUAL( eResolutionCacheMiss, eResult ); TEST_ASSERT_EQUAL( 0x12345678, ulIPAddress ); /* =================================================== */ } @@ -2035,11 +2015,11 @@ void test_eARPGetCacheEntryByMac_NoMatchingEntries( void ) void test_eARPGetCacheEntryByMac_OneMatchingEntry( void ) { uint32_t ulIPAddress = 0x12345678, ulEntryToTest; - eARPLookupResult_t eResult; + eResolutionLookupResult_t eResult; MACAddress_t xMACAddress = { 0x22, 0x22, 0x22, 0x22, 0x22, 0x22 }; int i; NetworkEndPoint_t xNetworkEndPoint = { 0 }; - NetworkInterface_t xInterface, * pxInterface = NULL; + NetworkInterface_t xInterface, * pxInterface = &xInterface; xNetworkEndPoint.pxNetworkInterface = &xInterface; @@ -2056,17 +2036,17 @@ void test_eARPGetCacheEntryByMac_OneMatchingEntry( void ) memset( xARPCache[ ulEntryToTest ].xMACAddress.ucBytes, 0x22, sizeof( xMACAddress.ucBytes ) ); xARPCache[ ulEntryToTest ].ulIPAddress = 0xAABBCCEE; eResult = eARPGetCacheEntryByMac( &xMACAddress, &ulIPAddress, &pxInterface ); - TEST_ASSERT_EQUAL( eARPCacheHit, eResult ); + TEST_ASSERT_EQUAL( eResolutionCacheHit, eResult ); TEST_ASSERT_EQUAL( xARPCache[ ulEntryToTest ].ulIPAddress, ulIPAddress ); TEST_ASSERT_EQUAL( &xInterface, pxInterface ); /* =================================================== */ eResult = eARPGetCacheEntryByMac( &xMACAddress, &ulIPAddress, NULL ); - TEST_ASSERT_EQUAL( eARPCacheHit, eResult ); + TEST_ASSERT_EQUAL( eResolutionCacheHit, eResult ); TEST_ASSERT_EQUAL( xARPCache[ ulEntryToTest ].ulIPAddress, ulIPAddress ); /* =================================================== */ xARPCache[ ulEntryToTest ].pxEndPoint = NULL; eResult = eARPGetCacheEntryByMac( &xMACAddress, &ulIPAddress, &pxInterface ); - TEST_ASSERT_EQUAL( eARPCacheHit, eResult ); + TEST_ASSERT_EQUAL( eResolutionCacheHit, eResult ); TEST_ASSERT_EQUAL( xARPCache[ ulEntryToTest ].ulIPAddress, ulIPAddress ); /* =================================================== */ } @@ -2086,7 +2066,7 @@ void test_eARPGetCacheEntry_IPMatchesBroadcastAddr( void ) { uint32_t ulIPAddress; MACAddress_t xMACAddress; - eARPLookupResult_t eResult; + eResolutionLookupResult_t eResult; uint32_t ulSavedGatewayAddress; struct xNetworkEndPoint * pxEndPoint, xEndPoint; @@ -2099,7 +2079,7 @@ void test_eARPGetCacheEntry_IPMatchesBroadcastAddr( void ) FreeRTOS_FindEndPointOnNetMask_ExpectAnyArgsAndReturn( &xEndPoint ); eResult = eARPGetCacheEntry( &ulIPAddress, &xMACAddress, &pxEndPoint ); - TEST_ASSERT_EQUAL_MESSAGE( eARPCacheHit, eResult, "Test 3" ); + TEST_ASSERT_EQUAL_MESSAGE( eResolutionCacheHit, eResult, "Test 3" ); TEST_ASSERT_EQUAL( pxEndPoint, &xEndPoint ); TEST_ASSERT_EQUAL_MEMORY_MESSAGE( &xBroadcastMACAddress, &xMACAddress, sizeof( xMACAddress ), "Test 3" ); /* =================================================== */ @@ -2109,7 +2089,7 @@ void test_eARPGetCacheEntry_IPMatchesBroadcastAddr_NullEndPointOnNetMask( void ) { uint32_t ulIPAddress; MACAddress_t xMACAddress; - eARPLookupResult_t eResult; + eResolutionLookupResult_t eResult; uint32_t ulSavedGatewayAddress; struct xNetworkEndPoint * pxEndPoint, xEndPoint; @@ -2122,7 +2102,7 @@ void test_eARPGetCacheEntry_IPMatchesBroadcastAddr_NullEndPointOnNetMask( void ) FreeRTOS_FindEndPointOnNetMask_ExpectAnyArgsAndReturn( NULL ); eResult = eARPGetCacheEntry( &ulIPAddress, &xMACAddress, &pxEndPoint ); - TEST_ASSERT_EQUAL( eARPCacheHit, eResult ); + TEST_ASSERT_EQUAL( eResolutionCacheHit, eResult ); TEST_ASSERT_NOT_EQUAL( pxEndPoint, &xEndPoint ); /* =================================================== */ } @@ -2131,7 +2111,7 @@ void test_eARPGetCacheEntry_MultiCastAddr( void ) { uint32_t ulIPAddress; MACAddress_t xMACAddress; - eARPLookupResult_t eResult; + eResolutionLookupResult_t eResult; uint32_t ulSavedGatewayAddress; struct xNetworkEndPoint * pxEndPoint, xEndPoint; @@ -2145,7 +2125,7 @@ void test_eARPGetCacheEntry_MultiCastAddr( void ) eResult = eARPGetCacheEntry( &ulIPAddress, &xMACAddress, &pxEndPoint ); - TEST_ASSERT_EQUAL( eCantSendPacket, eResult ); + TEST_ASSERT_EQUAL( eResolutionFailed, eResult ); TEST_ASSERT_NOT_EQUAL( pxEndPoint, &xEndPoint ); /* =================================================== */ @@ -2159,7 +2139,7 @@ void test_eARPGetCacheEntry_MultiCastAddr( void ) eResult = eARPGetCacheEntry( &ulIPAddress, &xMACAddress, &pxEndPoint ); - TEST_ASSERT_EQUAL( eCantSendPacket, eResult ); + TEST_ASSERT_EQUAL( eResolutionFailed, eResult ); TEST_ASSERT_NOT_EQUAL( pxEndPoint, &xEndPoint ); /* =================================================== */ } @@ -2168,7 +2148,7 @@ void test_eARPGetCacheEntry_IPMatchesOtherBroadcastAddr( void ) { uint32_t ulIPAddress; MACAddress_t xMACAddress; - eARPLookupResult_t eResult; + eResolutionLookupResult_t eResult; uint32_t ulSavedGatewayAddress; struct xNetworkInterface * xInterface; struct xNetworkEndPoint * pxEndPoint, xEndPoint; @@ -2181,7 +2161,7 @@ void test_eARPGetCacheEntry_IPMatchesOtherBroadcastAddr( void ) xIsIPv4Multicast_ExpectAndReturn( ulIPAddress, 0UL ); FreeRTOS_FindEndPointOnNetMask_ExpectAnyArgsAndReturn( &xEndPoint ); eResult = eARPGetCacheEntry( &ulIPAddress, &xMACAddress, &pxEndPoint ); - TEST_ASSERT_EQUAL_MESSAGE( eARPCacheHit, eResult, "Test 3" ); + TEST_ASSERT_EQUAL_MESSAGE( eResolutionCacheHit, eResult, "Test 3" ); TEST_ASSERT_EQUAL_MEMORY_MESSAGE( &xBroadcastMACAddress, &xMACAddress, sizeof( xMACAddress ), "Test 3" ); TEST_ASSERT_EQUAL( pxEndPoint, &xEndPoint ); /* =================================================== */ @@ -2191,7 +2171,7 @@ void test_eARPGetCacheEntry_MatchingInvalidEntry( void ) { uint32_t ulIPAddress; MACAddress_t xMACAddress; - eARPLookupResult_t eResult; + eResolutionLookupResult_t eResult; uint32_t ulSavedGatewayAddress; struct xNetworkInterface * xInterface; struct xNetworkEndPoint * pxEndPoint, xEndPoint; @@ -2212,7 +2192,7 @@ void test_eARPGetCacheEntry_MatchingInvalidEntry( void ) FreeRTOS_FindEndPointOnNetMask_ExpectAnyArgsAndReturn( NULL ); FreeRTOS_FindGateWay_ExpectAnyArgsAndReturn( &xEndPoint ); eResult = eARPGetCacheEntry( &ulIPAddress, &xMACAddress, &pxEndPoint ); - TEST_ASSERT_EQUAL_MESSAGE( eCantSendPacket, eResult, "Test 6" ); + TEST_ASSERT_EQUAL_MESSAGE( eResolutionFailed, eResult, "Test 6" ); TEST_ASSERT_EQUAL( pxEndPoint, &xEndPoint ); /* =================================================== */ } @@ -2221,7 +2201,7 @@ void test_eARPGetCacheEntry_MatchingValidEntry( void ) { uint32_t ulIPAddress; MACAddress_t xMACAddress; - eARPLookupResult_t eResult; + eResolutionLookupResult_t eResult; uint32_t ulSavedGatewayAddress; struct xNetworkInterface * xInterface; struct xNetworkEndPoint * pxEndPoint, xEndPoint; @@ -2242,7 +2222,7 @@ void test_eARPGetCacheEntry_MatchingValidEntry( void ) FreeRTOS_FindEndPointOnNetMask_ExpectAnyArgsAndReturn( NULL ); FreeRTOS_FindGateWay_ExpectAnyArgsAndReturn( &xEndPoint ); eResult = eARPGetCacheEntry( &ulIPAddress, &xMACAddress, &pxEndPoint ); - TEST_ASSERT_EQUAL_MESSAGE( eARPCacheHit, eResult, "Test 7" ); + TEST_ASSERT_EQUAL_MESSAGE( eResolutionCacheHit, eResult, "Test 7" ); TEST_ASSERT_EQUAL_MEMORY_MESSAGE( &xARPCache[ 1 ].xMACAddress, &xMACAddress, sizeof( xMACAddress ), "Test 7" ); TEST_ASSERT_NOT_EQUAL( pxEndPoint, &xEndPoint ); /* =================================================== */ @@ -2252,7 +2232,7 @@ void test_eARPGetCacheEntry_GatewayAddressZero( void ) { uint32_t ulIPAddress; MACAddress_t xMACAddress; - eARPLookupResult_t eResult; + eResolutionLookupResult_t eResult; uint32_t ulSavedGatewayAddress; struct xNetworkInterface * xInterface; struct xNetworkEndPoint * pxEndPoint, xEndPoint; @@ -2276,7 +2256,7 @@ void test_eARPGetCacheEntry_GatewayAddressZero( void ) FreeRTOS_FindGateWay_ExpectAnyArgsAndReturn( NULL ); eResult = eARPGetCacheEntry( &ulIPAddress, &xMACAddress, &pxEndPoint ); - TEST_ASSERT_EQUAL_MESSAGE( eCantSendPacket, eResult, "Test 9" ); + TEST_ASSERT_EQUAL_MESSAGE( eResolutionFailed, eResult, "Test 9" ); /* =================================================== */ } @@ -2284,7 +2264,7 @@ void test_eARPGetCacheEntry_AddressNotOnLocalAddress( void ) { uint32_t ulIPAddress; MACAddress_t xMACAddress; - eARPLookupResult_t eResult; + eResolutionLookupResult_t eResult; uint32_t ulSavedGatewayAddress; struct xNetworkInterface * xInterface; struct xNetworkEndPoint * pxEndPoint, xEndPoint; @@ -2303,7 +2283,7 @@ void test_eARPGetCacheEntry_AddressNotOnLocalAddress( void ) FreeRTOS_FindEndPointOnNetMask_ExpectAnyArgsAndReturn( NULL ); FreeRTOS_FindGateWay_ExpectAnyArgsAndReturn( NULL ); eResult = eARPGetCacheEntry( &ulIPAddress, &xMACAddress, &pxEndPoint ); - TEST_ASSERT_EQUAL_MESSAGE( eCantSendPacket, eResult, "Test 11" ); + TEST_ASSERT_EQUAL_MESSAGE( eResolutionFailed, eResult, "Test 11" ); TEST_ASSERT_NOT_EQUAL( pxEndPoint, &xEndPoint ); /* =================================================== */ } @@ -2312,7 +2292,7 @@ void test_eARPGetCacheEntry_NoCacheHit( void ) { uint32_t ulIPAddress; MACAddress_t xMACAddress; - eARPLookupResult_t eResult; + eResolutionLookupResult_t eResult; uint32_t ulSavedGatewayAddress; struct xNetworkInterface * xInterface; struct xNetworkEndPoint * pxEndPoint, xEndPoint; @@ -2342,7 +2322,7 @@ void test_eARPGetCacheEntry_NoCacheHit( void ) FreeRTOS_FindEndPointOnNetMask_ExpectAnyArgsAndReturn( NULL ); eResult = eARPGetCacheEntry( &ulIPAddress, &xMACAddress, &pxEndPoint ); xNetworkAddressing.ulGatewayAddress = ulSavedGatewayAddress; - TEST_ASSERT_EQUAL( eARPCacheHit, eResult ); + TEST_ASSERT_EQUAL( eResolutionCacheHit, eResult ); TEST_ASSERT_NOT_EQUAL( pxEndPoint, &xEndPoint ); /* =================================================== */ } @@ -2356,7 +2336,7 @@ void test_eARPGetCacheEntry_LoopbackAddress( void ) uint32_t ulIPAddress; MACAddress_t xMACAddress = { 0 }; MACAddress_t xMACAddressExp = { 0 }; - eARPLookupResult_t eResult; + eResolutionLookupResult_t eResult; uint32_t ulSavedGatewayAddress; struct xNetworkInterface * xInterface; struct xNetworkEndPoint * pxEndPoint, xEndPoint; @@ -2383,7 +2363,7 @@ void test_eARPGetCacheEntry_LoopbackAddress( void ) FreeRTOS_FindEndPointOnIP_IPv4_ExpectAnyArgsAndReturn( NULL ); xIsIPv4Loopback_ExpectAndReturn( ulIPAddress, 1UL ); eResult = eARPGetCacheEntry( &ulIPAddress, &xMACAddress, &pxEndPoint ); - TEST_ASSERT_EQUAL( eCantSendPacket, eResult ); + TEST_ASSERT_EQUAL( eResolutionFailed, eResult ); TEST_ASSERT_NOT_EQUAL( pxEndPoint, &xEndPoint ); TEST_ASSERT_EQUAL_MEMORY( xMACAddressExp.ucBytes, xMACAddress.ucBytes, sizeof( MACAddress_t ) ); /* =================================================== */ @@ -2398,7 +2378,7 @@ void test_eARPGetCacheEntry_LoopbackAddress_ValidLPEndpoint( void ) uint32_t ulIPAddress; MACAddress_t xMACAddress = { 0 }; MACAddress_t xMACAddressExp = { 0x11, 0x22, 0x33, 0x11, 0x22, 0x33 }; - eARPLookupResult_t eResult; + eResolutionLookupResult_t eResult; uint32_t ulSavedGatewayAddress; struct xNetworkInterface * xInterface; struct xNetworkEndPoint * pxEndPoint, xEndPoint; @@ -2426,7 +2406,7 @@ void test_eARPGetCacheEntry_LoopbackAddress_ValidLPEndpoint( void ) FreeRTOS_FindEndPointOnIP_IPv4_ExpectAnyArgsAndReturn( &xEndPoint ); xIsIPv4Loopback_ExpectAndReturn( ulIPAddress, 1UL ); eResult = eARPGetCacheEntry( &ulIPAddress, &xMACAddress, &pxEndPoint ); - TEST_ASSERT_EQUAL( eARPCacheHit, eResult ); + TEST_ASSERT_EQUAL( eResolutionCacheHit, eResult ); TEST_ASSERT_EQUAL( pxEndPoint, &xEndPoint ); TEST_ASSERT_EQUAL_MEMORY( xMACAddressExp.ucBytes, xMACAddress.ucBytes, sizeof( MACAddress_t ) ); /* =================================================== */ @@ -2733,7 +2713,7 @@ void test_xARPWaitResolution_PrivateFunctionReturnsHit( void ) /* Make the resolution pass without any attempt by making - * eARPGetCacheEntry return eARPCacheHit. */ + * eARPGetCacheEntry return eResolutionCacheHit. */ /* =================================================== */ /* Assertion on calling from IP-task */ xEndPoint.bits.bIPv6 = pdFALSE_UNSIGNED; diff --git a/test/unit-test/FreeRTOS_IP/FreeRTOS_IP_utest.c b/test/unit-test/FreeRTOS_IP/FreeRTOS_IP_utest.c index 1e4469d6ab..f6fa11343b 100644 --- a/test/unit-test/FreeRTOS_IP/FreeRTOS_IP_utest.c +++ b/test/unit-test/FreeRTOS_IP/FreeRTOS_IP_utest.c @@ -492,6 +492,7 @@ void test_prvIPTask( void ) /* In prvIPTask_Initialise. */ vTCPTimerReload_ExpectAnyArgs(); vIPSetARPResolutionTimerEnableState_Expect( pdFALSE ); + vIPSetNDResolutionTimerEnableState_Expect( pdFALSE ); vDNSInitialise_Ignore(); FreeRTOS_dnsclear_Ignore(); @@ -533,6 +534,7 @@ void test_prvIPTask_NetworkDown( void ) /* In prvIPTask_Initialise. */ vTCPTimerReload_ExpectAnyArgs(); vIPSetARPResolutionTimerEnableState_Expect( pdFALSE ); + vIPSetNDResolutionTimerEnableState_Expect( pdFALSE ); vDNSInitialise_Ignore(); FreeRTOS_dnsclear_Ignore(); @@ -731,7 +733,7 @@ void test_prvProcessIPEventsAndTimers_eNetworkRxEvent_NullEndPoint( void ) /** * @brief test_prvProcessIPEventsAndTimers_eARPTimerEvent - * Check if prvProcessIPEventsAndTimers() updates the cache for ARP/ND when timeout event triggered. + * Check if prvProcessIPEventsAndTimers() updates the cache for ARP when timeout event triggered. */ void test_prvProcessIPEventsAndTimers_eARPTimerEvent( void ) { @@ -746,6 +748,26 @@ void test_prvProcessIPEventsAndTimers_eARPTimerEvent( void ) xQueueReceive_ExpectAnyArgsAndReturn( pdTRUE ); xQueueReceive_ReturnMemThruPtr_pvBuffer( &xReceivedEvent, sizeof( xReceivedEvent ) ); vARPAgeCache_Expect(); + + prvProcessIPEventsAndTimers(); +} + +/** + * @brief test_prvProcessIPEventsAndTimers_eNDTimerEvent + * Check if prvProcessIPEventsAndTimers() updates the cache for ND when timeout event triggered. + */ +void test_prvProcessIPEventsAndTimers_eNDTimerEvent( void ) +{ + IPStackEvent_t xReceivedEvent; + + xReceivedEvent.eEventType = eNDTimerEvent; + xReceivedEvent.pvData = NULL; + + /* prvProcessIPEventsAndTimers */ + vCheckNetworkTimers_Expect(); + xCalculateSleepTime_ExpectAndReturn( 0 ); + xQueueReceive_ExpectAnyArgsAndReturn( pdTRUE ); + xQueueReceive_ReturnMemThruPtr_pvBuffer( &xReceivedEvent, sizeof( xReceivedEvent ) ); vNDAgeCache_Expect(); prvProcessIPEventsAndTimers(); @@ -2116,7 +2138,7 @@ void test_prvProcessEthernetPacket_ARPFrameType2( void ) /** * @brief test_prvProcessEthernetPacket_ARPFrameType_WaitingARPResolution - * To validate the flow to handle ARP packets but eARPProcessPacket() returns eWaitingARPResolution + * To validate the flow to handle ARP packets but eARPProcessPacket() returns eWaitingResolution * without pxARPWaitingNetworkBuffer. */ void test_prvProcessEthernetPacket_ARPFrameType_WaitingARPResolution( void ) @@ -2141,7 +2163,7 @@ void test_prvProcessEthernetPacket_ARPFrameType_WaitingARPResolution( void ) pxEthernetHeader->usFrameType = ipARP_FRAME_TYPE; - eARPProcessPacket_ExpectAndReturn( pxNetworkBuffer, eWaitingARPResolution ); + eARPProcessPacket_ExpectAndReturn( pxNetworkBuffer, eWaitingResolution ); vIPTimerStartARPResolution_ExpectAnyArgs(); @@ -2150,7 +2172,7 @@ void test_prvProcessEthernetPacket_ARPFrameType_WaitingARPResolution( void ) /** * @brief test_prvProcessEthernetPacket_ARPFrameType_WaitingARPResolution2 - * To validate the flow to handle ARP packets but eARPProcessPacket() returns eWaitingARPResolution + * To validate the flow to handle ARP packets but eARPProcessPacket() returns eWaitingResolution * with pxARPWaitingNetworkBuffer. */ void test_prvProcessEthernetPacket_ARPFrameType_WaitingARPResolution2( void ) @@ -2175,7 +2197,7 @@ void test_prvProcessEthernetPacket_ARPFrameType_WaitingARPResolution2( void ) pxEthernetHeader->usFrameType = ipARP_FRAME_TYPE; - eARPProcessPacket_ExpectAndReturn( pxNetworkBuffer, eWaitingARPResolution ); + eARPProcessPacket_ExpectAndReturn( pxNetworkBuffer, eWaitingResolution ); vReleaseNetworkBufferAndDescriptor_Expect( pxNetworkBuffer ); @@ -2365,6 +2387,122 @@ void test_prvProcessEthernetPacket_InterfaceNull( void ) prvProcessEthernetPacket( pxNetworkBuffer ); } +/** + * @brief test_prvProcessEthernetPacket_IPv4FrameType_NeedARPResolution + * To validate the flow to handle IPv4 packets and it needs ARP resolution. + * But we already have one ARP packet pending so that buffer got released + * at the end. + */ +void test_prvProcessEthernetPacket_IPv4FrameType_NeedARPResolution( void ) +{ + NetworkBufferDescriptor_t xNetworkBuffer; + NetworkBufferDescriptor_t * pxNetworkBuffer = &xNetworkBuffer; + uint8_t ucEthernetBuffer[ ipconfigTCP_MSS ] = { 0 }; + EthernetHeader_t * pxEthernetHeader; + IPPacket_t * pxIPPacket; + IPHeader_t * pxIPHeader; + struct xNetworkInterface xInterface; + NetworkEndPoint_t xNetworkEndPoint = { 0 }; + + pxNetworkBuffer->xDataLength = ipconfigTCP_MSS - ipIP_TYPE_OFFSET; + pxNetworkBuffer->pucEthernetBuffer = ucEthernetBuffer + ipIP_TYPE_OFFSET; + pxNetworkBuffer->pxInterface = &xInterface; + pxNetworkBuffer->pxEndPoint = &xNetworkEndPoint; + + pxEthernetHeader = ( EthernetHeader_t * ) pxNetworkBuffer->pucEthernetBuffer; + pxEthernetHeader->usFrameType = ipIPv4_FRAME_TYPE; + + pxIPPacket = ( IPPacket_t * ) pxNetworkBuffer->pucEthernetBuffer; + pxIPHeader = &( pxIPPacket->xIPHeader ); + pxIPHeader->ucVersionHeaderLength = 0x45; + + pxARPWaitingNetworkBuffer = ( NetworkBufferDescriptor_t * ) 0x1234ABCD; + + prvAllowIPPacketIPv4_ExpectAndReturn( pxIPPacket, pxNetworkBuffer, ( pxIPHeader->ucVersionHeaderLength & 0x0FU ) << 2, eProcessBuffer ); + xCheckRequiresResolution_ExpectAndReturn( pxNetworkBuffer, pdTRUE ); + vReleaseNetworkBufferAndDescriptor_Expect( pxNetworkBuffer ); + + prvProcessEthernetPacket( pxNetworkBuffer ); +} + +/** + * @brief test_prvProcessEthernetPacket_IPv6FrameType_NeedNDResolution + * To validate the flow to handle IPv4 packets and it needs ND resolution. + * But we already have one ND packet pending so that buffer got released + * at the end. + */ +void test_prvProcessEthernetPacket_IPv6FrameType_NeedNDResolution( void ) +{ + NetworkBufferDescriptor_t xNetworkBuffer; + NetworkBufferDescriptor_t * pxNetworkBuffer = &xNetworkBuffer; + uint8_t ucEthernetBuffer[ ipconfigTCP_MSS ] = { 0 }; + EthernetHeader_t * pxEthernetHeader; + IPPacket_IPv6_t * pxIPv6Packet; + IPHeader_IPv6_t * pxIPv6Header; + struct xNetworkInterface xInterface; + NetworkEndPoint_t xNetworkEndPoint = { 0 }; + + pxNetworkBuffer->xDataLength = ipconfigTCP_MSS - ipIP_TYPE_OFFSET; + pxNetworkBuffer->pucEthernetBuffer = ucEthernetBuffer + ipIP_TYPE_OFFSET; + pxNetworkBuffer->pxInterface = &xInterface; + pxNetworkBuffer->pxEndPoint = &xNetworkEndPoint; + + pxEthernetHeader = ( EthernetHeader_t * ) pxNetworkBuffer->pucEthernetBuffer; + pxEthernetHeader->usFrameType = ipIPv6_FRAME_TYPE; + + pxIPv6Packet = ( IPPacket_IPv6_t * ) pxNetworkBuffer->pucEthernetBuffer; + pxIPv6Header = &( pxIPv6Packet->xIPHeader ); + pxIPv6Header->ucNextHeader = ipPROTOCOL_TCP; + + pxNDWaitingNetworkBuffer = ( NetworkBufferDescriptor_t * ) 0x1234ABCD; + + prvAllowIPPacketIPv6_ExpectAndReturn( pxIPv6Header, pxNetworkBuffer, ipSIZE_OF_IPv6_HEADER, eProcessBuffer ); + xGetExtensionOrder_ExpectAndReturn( ipPROTOCOL_TCP, 0, -1 ); + xCheckRequiresResolution_ExpectAndReturn( pxNetworkBuffer, pdTRUE ); + vReleaseNetworkBufferAndDescriptor_Expect( pxNetworkBuffer ); + + prvProcessEthernetPacket( pxNetworkBuffer ); +} + +/** + * @brief test_prvProcessEthernetPacket_IPv6FrameType_NeedNDResolution2 + * To validate the flow to handle IPv6 packets and it needs ND resolution. + * And we don't have any pending ND packet. + */ +void test_prvProcessEthernetPacket_IPv6FrameType_NeedNDResolution2( void ) +{ + NetworkBufferDescriptor_t xNetworkBuffer; + NetworkBufferDescriptor_t * pxNetworkBuffer = &xNetworkBuffer; + uint8_t ucEthernetBuffer[ ipconfigTCP_MSS ] = { 0 }; + EthernetHeader_t * pxEthernetHeader; + IPPacket_IPv6_t * pxIPv6Packet; + IPHeader_IPv6_t * pxIPv6Header; + struct xNetworkInterface xInterface; + NetworkEndPoint_t xNetworkEndPoint = { 0 }; + + pxNetworkBuffer->xDataLength = ipconfigTCP_MSS - ipIP_TYPE_OFFSET; + pxNetworkBuffer->pucEthernetBuffer = ucEthernetBuffer + ipIP_TYPE_OFFSET; + pxNetworkBuffer->pxInterface = &xInterface; + pxNetworkBuffer->pxEndPoint = &xNetworkEndPoint; + + pxEthernetHeader = ( EthernetHeader_t * ) pxNetworkBuffer->pucEthernetBuffer; + pxEthernetHeader->usFrameType = ipIPv6_FRAME_TYPE; + + pxIPv6Packet = ( IPPacket_IPv6_t * ) pxNetworkBuffer->pucEthernetBuffer; + pxIPv6Header = &( pxIPv6Packet->xIPHeader ); + pxIPv6Header->ucNextHeader = ipPROTOCOL_TCP; + + pxNDWaitingNetworkBuffer = NULL; + + prvAllowIPPacketIPv6_ExpectAndReturn( pxIPv6Header, pxNetworkBuffer, ipSIZE_OF_IPv6_HEADER, eProcessBuffer ); + xGetExtensionOrder_ExpectAndReturn( ipPROTOCOL_TCP, 0, -1 ); + xCheckRequiresResolution_ExpectAndReturn( pxNetworkBuffer, pdTRUE ); + vIPTimerStartNDResolution_ExpectAnyArgs(); + + prvProcessEthernetPacket( pxNetworkBuffer ); + + TEST_ASSERT_EQUAL_PTR( pxNetworkBuffer, pxNDWaitingNetworkBuffer ); +} /** * @brief test_prvProcessIPPacket_HeaderLengthSmaller @@ -2485,11 +2623,11 @@ void test_prvProcessIPPacket_ValidHeader_ARPResolutionReqd( void ) pxIPHeader->ucVersionHeaderLength = 0x45; prvAllowIPPacketIPv4_ExpectAndReturn( pxIPPacket, pxNetworkBuffer, ( pxIPHeader->ucVersionHeaderLength & 0x0FU ) << 2, eProcessBuffer ); - xCheckRequiresARPResolution_ExpectAndReturn( pxNetworkBuffer, pdTRUE ); + xCheckRequiresResolution_ExpectAndReturn( pxNetworkBuffer, pdTRUE ); eResult = prvProcessIPPacket( pxIPPacket, pxNetworkBuffer ); - TEST_ASSERT_EQUAL( eWaitingARPResolution, eResult ); + TEST_ASSERT_EQUAL( eWaitingResolution, eResult ); } /** @@ -2523,7 +2661,7 @@ void test_prvProcessIPPacket_ARPResolutionNotReqd_InvalidProt( void ) prvAllowIPPacketIPv4_ExpectAndReturn( pxIPPacket, pxNetworkBuffer, ( pxIPHeader->ucVersionHeaderLength & 0x0FU ) << 2, eProcessBuffer ); prvCheckIP4HeaderOptions_ExpectAndReturn( pxNetworkBuffer, eProcessBuffer ); - xCheckRequiresARPResolution_ExpectAndReturn( pxNetworkBuffer, pdFALSE ); + xCheckRequiresResolution_ExpectAndReturn( pxNetworkBuffer, pdFALSE ); vARPRefreshCacheEntryAge_ExpectAnyArgs(); eResult = prvProcessIPPacket( pxIPPacket, pxNetworkBuffer ); @@ -2562,7 +2700,7 @@ void test_prvProcessIPPacket_ARPResolutionNotReqd_ICMPRelease( void ) prvAllowIPPacketIPv4_ExpectAndReturn( pxIPPacket, pxNetworkBuffer, ( pxIPHeader->ucVersionHeaderLength & 0x0FU ) << 2, eProcessBuffer ); prvCheckIP4HeaderOptions_ExpectAndReturn( pxNetworkBuffer, eProcessBuffer ); - xCheckRequiresARPResolution_ExpectAndReturn( pxNetworkBuffer, pdFALSE ); + xCheckRequiresResolution_ExpectAndReturn( pxNetworkBuffer, pdFALSE ); vARPRefreshCacheEntryAge_ExpectAnyArgs(); ProcessICMPPacket_ExpectAndReturn( pxNetworkBuffer, eReleaseBuffer ); @@ -2602,7 +2740,7 @@ void test_prvProcessIPPacket_ARPResolutionNotReqd_ICMPProcess( void ) prvAllowIPPacketIPv4_ExpectAndReturn( pxIPPacket, pxNetworkBuffer, ( pxIPHeader->ucVersionHeaderLength & 0x0FU ) << 2, eProcessBuffer ); prvCheckIP4HeaderOptions_ExpectAndReturn( pxNetworkBuffer, eProcessBuffer ); - xCheckRequiresARPResolution_ExpectAndReturn( pxNetworkBuffer, pdFALSE ); + xCheckRequiresResolution_ExpectAndReturn( pxNetworkBuffer, pdFALSE ); vARPRefreshCacheEntryAge_ExpectAnyArgs(); ProcessICMPPacket_ExpectAndReturn( pxNetworkBuffer, eProcessBuffer ); @@ -2825,12 +2963,12 @@ void test_prvProcessIPPacket_ARPResolutionReqd_UDP( void ) prvAllowIPPacketIPv4_ExpectAndReturn( pxIPPacket, pxNetworkBuffer, ( pxIPHeader->ucVersionHeaderLength & 0x0FU ) << 2, eProcessBuffer ); xProcessReceivedUDPPacket_ExpectAndReturn( pxNetworkBuffer, pxUDPPacket->xUDPHeader.usDestinationPort, NULL, pdFAIL ); - xProcessReceivedUDPPacket_IgnoreArg_pxIsWaitingForARPResolution(); - xProcessReceivedUDPPacket_ReturnThruPtr_pxIsWaitingForARPResolution( &xReturnValue ); + xProcessReceivedUDPPacket_IgnoreArg_pxIsWaitingForResolution(); + xProcessReceivedUDPPacket_ReturnThruPtr_pxIsWaitingForResolution( &xReturnValue ); eResult = prvProcessIPPacket( pxIPPacket, pxNetworkBuffer ); - TEST_ASSERT_EQUAL( eWaitingARPResolution, eResult ); + TEST_ASSERT_EQUAL( eWaitingResolution, eResult ); TEST_ASSERT_EQUAL( FreeRTOS_ntohs( pxUDPPacket->xUDPHeader.usLength ) - sizeof( UDPHeader_t ) + sizeof( UDPPacket_t ), pxNetworkBuffer->xDataLength ); TEST_ASSERT_EQUAL( pxNetworkBuffer->usPort, pxUDPPacket->xUDPHeader.usSourcePort ); TEST_ASSERT_EQUAL( pxNetworkBuffer->xIPAddress.ulIP_IPv4, pxUDPPacket->xIPHeader.ulSourceIPAddress ); @@ -2876,12 +3014,12 @@ void test_prvProcessIPPacket_ARPResolutionReqd_UDP1( void ) prvAllowIPPacketIPv4_ExpectAndReturn( pxIPPacket, pxNetworkBuffer, ( pxIPHeader->ucVersionHeaderLength & 0x0FU ) << 2, eProcessBuffer ); xProcessReceivedUDPPacket_ExpectAndReturn( pxNetworkBuffer, pxUDPPacket->xUDPHeader.usDestinationPort, NULL, pdFAIL ); - xProcessReceivedUDPPacket_IgnoreArg_pxIsWaitingForARPResolution(); - xProcessReceivedUDPPacket_ReturnThruPtr_pxIsWaitingForARPResolution( &xReturnValue ); + xProcessReceivedUDPPacket_IgnoreArg_pxIsWaitingForResolution(); + xProcessReceivedUDPPacket_ReturnThruPtr_pxIsWaitingForResolution( &xReturnValue ); eResult = prvProcessIPPacket( pxIPPacket, pxNetworkBuffer ); - TEST_ASSERT_EQUAL( eWaitingARPResolution, eResult ); + TEST_ASSERT_EQUAL( eWaitingResolution, eResult ); TEST_ASSERT_EQUAL( pxNetworkBuffer->usPort, pxUDPPacket->xUDPHeader.usSourcePort ); TEST_ASSERT_EQUAL( pxNetworkBuffer->xIPAddress.ulIP_IPv4, pxUDPPacket->xIPHeader.ulSourceIPAddress ); } @@ -2919,7 +3057,7 @@ void test_prvProcessIPPacket_TCP( void ) pxIPPacket->xIPHeader.ucProtocol = ipPROTOCOL_TCP; prvAllowIPPacketIPv4_ExpectAndReturn( pxIPPacket, pxNetworkBuffer, ( pxIPHeader->ucVersionHeaderLength & 0x0FU ) << 2, eProcessBuffer ); - xCheckRequiresARPResolution_ExpectAndReturn( pxNetworkBuffer, pdFALSE ); + xCheckRequiresResolution_ExpectAndReturn( pxNetworkBuffer, pdFALSE ); vARPRefreshCacheEntryAge_ExpectAnyArgs(); xProcessReceivedTCPPacket_ExpectAndReturn( pxNetworkBuffer, pdPASS ); @@ -2962,7 +3100,7 @@ void test_prvProcessIPPacket_TCPProcessFail( void ) pxIPPacket->xIPHeader.ucProtocol = ipPROTOCOL_TCP; prvAllowIPPacketIPv4_ExpectAndReturn( pxIPPacket, pxNetworkBuffer, ( pxIPHeader->ucVersionHeaderLength & 0x0FU ) << 2, eProcessBuffer ); - xCheckRequiresARPResolution_ExpectAndReturn( pxNetworkBuffer, pdFALSE ); + xCheckRequiresResolution_ExpectAndReturn( pxNetworkBuffer, pdFALSE ); vARPRefreshCacheEntryAge_ExpectAnyArgs(); xProcessReceivedTCPPacket_ExpectAndReturn( pxNetworkBuffer, pdFAIL ); @@ -3306,7 +3444,7 @@ void test_prvProcessIPPacket_TCP_IPv6_HappyPath( void ) prvAllowIPPacketIPv6_ExpectAndReturn( pxIPHeader, pxNetworkBuffer, ipSIZE_OF_IPv6_HEADER, eProcessBuffer ); xGetExtensionOrder_ExpectAndReturn( ipPROTOCOL_TCP, 0U, 0 ); - xCheckRequiresARPResolution_ExpectAndReturn( pxNetworkBuffer, pdFALSE ); + xCheckRequiresResolution_ExpectAndReturn( pxNetworkBuffer, pdFALSE ); vNDRefreshCacheEntry_Ignore(); xProcessReceivedTCPPacket_ExpectAnyArgsAndReturn( pdPASS ); @@ -3356,11 +3494,11 @@ void test_prvProcessIPPacket_TCP_IPv6_ARPResolution( void ) prvAllowIPPacketIPv6_ExpectAndReturn( pxIPHeader, pxNetworkBuffer, ipSIZE_OF_IPv6_HEADER, eProcessBuffer ); xGetExtensionOrder_ExpectAndReturn( ipPROTOCOL_TCP, 0U, 0 ); - xCheckRequiresARPResolution_ExpectAndReturn( pxNetworkBuffer, pdTRUE ); + xCheckRequiresResolution_ExpectAndReturn( pxNetworkBuffer, pdTRUE ); eResult = prvProcessIPPacket( ( IPPacket_t * ) pxIPPacket, pxNetworkBuffer ); - TEST_ASSERT_EQUAL( eWaitingARPResolution, eResult ); + TEST_ASSERT_EQUAL( eWaitingResolution, eResult ); } /** @@ -3403,7 +3541,7 @@ void test_prvProcessIPPacket_ICMP_IPv6_HappyPath( void ) prvAllowIPPacketIPv6_ExpectAndReturn( pxIPHeader, pxNetworkBuffer, ipSIZE_OF_IPv6_HEADER, eProcessBuffer ); xGetExtensionOrder_ExpectAndReturn( ipPROTOCOL_ICMP_IPv6, 0U, 0 ); - xCheckRequiresARPResolution_ExpectAndReturn( pxNetworkBuffer, pdFALSE ); + xCheckRequiresResolution_ExpectAndReturn( pxNetworkBuffer, pdFALSE ); vNDRefreshCacheEntry_Ignore(); prvProcessICMPMessage_IPv6_ExpectAnyArgsAndReturn( eReleaseBuffer ); @@ -4232,7 +4370,15 @@ static void prvIPNetworkUpCalls_Generic( const uint8_t * pucAddress, vApplicationIPNetworkEventHook_Multi_Expect( eNetworkUp, &xEndPoint ); vDNSInitialise_Expect(); - vARPTimerReload_Expect( pdMS_TO_TICKS( 10000 ) ); + + if( xEndPoint.bits.bIPv6 == pdTRUE_UNSIGNED ) + { + vNDTimerReload_Expect( pdMS_TO_TICKS( 10000 ) ); + } + else + { + vARPTimerReload_Expect( pdMS_TO_TICKS( 10000 ) ); + } vIPNetworkUpCalls( &xEndPoint ); diff --git a/test/unit-test/FreeRTOS_IP_DiffConfig/FreeRTOS_IP_DiffConfig_utest.c b/test/unit-test/FreeRTOS_IP_DiffConfig/FreeRTOS_IP_DiffConfig_utest.c index 9a530d1ec8..b9dce4a0b0 100644 --- a/test/unit-test/FreeRTOS_IP_DiffConfig/FreeRTOS_IP_DiffConfig_utest.c +++ b/test/unit-test/FreeRTOS_IP_DiffConfig/FreeRTOS_IP_DiffConfig_utest.c @@ -383,7 +383,7 @@ void test_vReturnEthernetFrame_DuplicationSuccess( void ) FreeRTOS_FindEndPointOnNetMask_IgnoreAndReturn( pxEndPoint ); - eARPGetCacheEntry_ExpectAnyArgsAndReturn( eARPCacheMiss ); + eARPGetCacheEntry_ExpectAnyArgsAndReturn( eResolutionCacheMiss ); xIsCallingFromIPTask_ExpectAndReturn( pdTRUE ); @@ -438,7 +438,7 @@ void test_vReturnEthernetFrame_DuplicationSuccessCacheHit( void ) FreeRTOS_FindEndPointOnNetMask_IgnoreAndReturn( pxEndPoint ); - eARPGetCacheEntry_ExpectAnyArgsAndReturn( eARPCacheHit ); + eARPGetCacheEntry_ExpectAnyArgsAndReturn( eResolutionCacheHit ); eARPGetCacheEntry_ReturnMemThruPtr_pxMACAddress( &xCacheMACAddress, sizeof( MACAddress_t ) ); xIsCallingFromIPTask_ExpectAndReturn( pdTRUE ); diff --git a/test/unit-test/FreeRTOS_IP_DiffConfig3/FreeRTOSIPConfig.h b/test/unit-test/FreeRTOS_IP_DiffConfig3/FreeRTOSIPConfig.h index a95e7d9927..9454ff172a 100644 --- a/test/unit-test/FreeRTOS_IP_DiffConfig3/FreeRTOSIPConfig.h +++ b/test/unit-test/FreeRTOS_IP_DiffConfig3/FreeRTOSIPConfig.h @@ -263,7 +263,7 @@ * because the packet will already have been passed into the stack). If the * Ethernet driver does all the necessary filtering in hardware then software * filtering can be removed by using a value other than 1 or 0. */ -#define ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES 1 +#define ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES 0 /* When ipconfigETHERNET_DRIVER_FILTERS_PACKETS is enabled, the network * interface will inspect the incoming packets to see if they can be @@ -348,4 +348,6 @@ #define ipconfigIP_PASS_PACKETS_WITH_IP_OPTIONS ( 0 ) #define ipconfigZERO_COPY_TX_DRIVER ( 1 ) +#define ipconfigPROCESS_CUSTOM_ETHERNET_FRAMES ( 1 ) + #endif /* FREERTOS_IP_CONFIG_H */ diff --git a/test/unit-test/FreeRTOS_IP_DiffConfig3/FreeRTOS_IP_DiffConfig3_utest.c b/test/unit-test/FreeRTOS_IP_DiffConfig3/FreeRTOS_IP_DiffConfig3_utest.c index 8fac597cf6..492831170d 100644 --- a/test/unit-test/FreeRTOS_IP_DiffConfig3/FreeRTOS_IP_DiffConfig3_utest.c +++ b/test/unit-test/FreeRTOS_IP_DiffConfig3/FreeRTOS_IP_DiffConfig3_utest.c @@ -46,6 +46,8 @@ #include "mock_FreeRTOS_IP_Timers.h" #include "mock_FreeRTOS_DHCP.h" #include "mock_FreeRTOS_DHCPv6.h" +#include "mock_NetworkBufferManagement.h" +#include "mock_FreeRTOS_Routing.h" #include "FreeRTOS_IP.h" @@ -84,6 +86,14 @@ void tearDown( void ) /* ======================== Stub Callback Functions ========================= */ +eFrameProcessingResult_t eApplicationProcessCustomFrameHook( NetworkBufferDescriptor_t * const pxNetworkBuffer ) +{ + ( void ) ( pxNetworkBuffer ); + + /* Force hook function to return waiting resultion for unknown Ethernet frame type. */ + return eWaitingResolution; +} + /* ============================== Test Cases ============================== */ /** @@ -179,3 +189,60 @@ void test_prvProcessIPEventsAndTimers_eDHCPEvent_RA( void ) prvProcessIPEventsAndTimers(); } + +/** + * @brief test_prvProcessEthernetPacket_UnknownFrameType_NeedResolution + * But we release the network buffer because the frame type is unknown. + */ +void test_prvProcessEthernetPacket_UnknownFrameType_NeedResolution( void ) +{ + NetworkBufferDescriptor_t xNetworkBuffer; + NetworkBufferDescriptor_t * pxNetworkBuffer = &xNetworkBuffer; + uint8_t ucEthernetBuffer[ ipconfigTCP_MSS ] = { 0 }; + EthernetHeader_t * pxEthernetHeader; + IPPacket_IPv6_t * pxIPv6Packet; + IPHeader_IPv6_t * pxIPv6Header; + struct xNetworkInterface xInterface; + NetworkEndPoint_t xNetworkEndPoint = { 0 }; + + pxNetworkBuffer->xDataLength = ipconfigTCP_MSS; + pxNetworkBuffer->pucEthernetBuffer = ucEthernetBuffer; + pxNetworkBuffer->pxInterface = &xInterface; + pxNetworkBuffer->pxEndPoint = &xNetworkEndPoint; + + pxEthernetHeader = ( EthernetHeader_t * ) pxNetworkBuffer->pucEthernetBuffer; + pxEthernetHeader->usFrameType = 0xFFFF; + + vReleaseNetworkBufferAndDescriptor_Expect( pxNetworkBuffer ); + + prvProcessEthernetPacket( pxNetworkBuffer ); +} + +/** + * @brief test_prvProcessEthernetPacket_UnknownFrameType_NeedResolution + * But we release the network buffer because the frame type is unknown. + */ +void test_prvProcessEthernetPacket_IPv4FrameType_CheckFrameFail( void ) +{ + NetworkBufferDescriptor_t xNetworkBuffer; + NetworkBufferDescriptor_t * pxNetworkBuffer = &xNetworkBuffer; + uint8_t ucEthernetBuffer[ ipconfigTCP_MSS ] = { 0 }; + EthernetHeader_t * pxEthernetHeader; + IPPacket_IPv6_t * pxIPv6Packet; + IPHeader_IPv6_t * pxIPv6Header; + struct xNetworkInterface xInterface; + NetworkEndPoint_t xNetworkEndPoint = { 0 }; + + pxNetworkBuffer->xDataLength = ipconfigTCP_MSS; + pxNetworkBuffer->pucEthernetBuffer = ucEthernetBuffer; + pxNetworkBuffer->pxInterface = &xInterface; + pxNetworkBuffer->pxEndPoint = &xNetworkEndPoint; + + pxEthernetHeader = ( EthernetHeader_t * ) pxNetworkBuffer->pucEthernetBuffer; + pxEthernetHeader->usFrameType = ipIPv4_FRAME_TYPE; + + FreeRTOS_FindEndPointOnMAC_ExpectAndReturn( &pxEthernetHeader->xDestinationAddress, NULL, NULL ); + vReleaseNetworkBufferAndDescriptor_Expect( pxNetworkBuffer ); + + prvProcessEthernetPacket( pxNetworkBuffer ); +} diff --git a/test/unit-test/FreeRTOS_IP_Timers/FreeRTOS_IP_Timers_stubs.c b/test/unit-test/FreeRTOS_IP_Timers/FreeRTOS_IP_Timers_stubs.c index 2674e64080..11feca0715 100644 --- a/test/unit-test/FreeRTOS_IP_Timers/FreeRTOS_IP_Timers_stubs.c +++ b/test/unit-test/FreeRTOS_IP_Timers/FreeRTOS_IP_Timers_stubs.c @@ -43,6 +43,7 @@ volatile BaseType_t xInsideInterrupt = pdFALSE; NetworkBufferDescriptor_t * pxARPWaitingNetworkBuffer; +NetworkBufferDescriptor_t * pxNDWaitingNetworkBuffer; struct xNetworkEndPoint * pxNetworkEndPoints; struct xNetworkInterface * pxNetworkInterfaces; diff --git a/test/unit-test/FreeRTOS_IP_Timers/FreeRTOS_IP_Timers_utest.c b/test/unit-test/FreeRTOS_IP_Timers/FreeRTOS_IP_Timers_utest.c index 789cf3fc3c..a261219517 100644 --- a/test/unit-test/FreeRTOS_IP_Timers/FreeRTOS_IP_Timers_utest.c +++ b/test/unit-test/FreeRTOS_IP_Timers/FreeRTOS_IP_Timers_utest.c @@ -65,6 +65,7 @@ void prvIPTimerStart( IPTimer_t * pxTimer, BaseType_t prvIPTimerCheck( IPTimer_t * pxTimer ); extern IPTimer_t xARPTimer; +extern IPTimer_t xNDTimer; #if ( ipconfigUSE_TCP != 0 ) /** @brief TCP timer, to check for timeouts, resends. */ extern IPTimer_t xTCPTimer; @@ -75,6 +76,7 @@ extern IPTimer_t xARPTimer; #endif extern IPTimer_t xARPResolutionTimer; +extern IPTimer_t xNDResolutionTimer; extern BaseType_t xAllNetworksUp; extern IPTimer_t xNetworkTimer; @@ -96,9 +98,11 @@ void setUp( void ) /* Reset all timers. */ memset( &xARPTimer, 0, sizeof( IPTimer_t ) ); + memset( &xNDTimer, 0, sizeof( IPTimer_t ) ); memset( &xDNSTimer, 0, sizeof( IPTimer_t ) ); memset( &xTCPTimer, 0, sizeof( IPTimer_t ) ); memset( &xARPResolutionTimer, 0, sizeof( IPTimer_t ) ); + memset( &xNDResolutionTimer, 0, sizeof( IPTimer_t ) ); memset( &xNetworkTimer, 0, sizeof( IPTimer_t ) ); } @@ -119,6 +123,7 @@ void test_xCalculateSleepTime_AllTimersInactive( void ) TickType_t uxTicks; xARPTimer.bActive = pdFALSE; + xNDTimer.bActive = pdFALSE; pxNetworkEndPoints->xDHCP_RATimer.bActive = pdFALSE; xDNSTimer.bActive = pdFALSE; xTCPTimer.bActive = pdFALSE; @@ -138,14 +143,16 @@ void test_xCalculateSleepTime_AllTimersActive_AllTimesGreater( void ) TickType_t uxTicks; xARPTimer.bActive = pdTRUE; + xNDTimer.bActive = pdTRUE; pxNetworkEndPoints->xDHCP_RATimer.bActive = pdTRUE; xDNSTimer.bActive = pdTRUE; xTCPTimer.bActive = pdTRUE; xARPTimer.ulRemainingTime = ipconfigMAX_IP_TASK_SLEEP_TIME; - pxNetworkEndPoints->xDHCP_RATimer.ulRemainingTime = ipconfigMAX_IP_TASK_SLEEP_TIME + 1; - xTCPTimer.ulRemainingTime = ipconfigMAX_IP_TASK_SLEEP_TIME + 2; - xDNSTimer.ulRemainingTime = ipconfigMAX_IP_TASK_SLEEP_TIME + 3; + xNDTimer.ulRemainingTime = ipconfigMAX_IP_TASK_SLEEP_TIME + 1; + pxNetworkEndPoints->xDHCP_RATimer.ulRemainingTime = ipconfigMAX_IP_TASK_SLEEP_TIME + 2; + xTCPTimer.ulRemainingTime = ipconfigMAX_IP_TASK_SLEEP_TIME + 3; + xDNSTimer.ulRemainingTime = ipconfigMAX_IP_TASK_SLEEP_TIME + 4; uxTicks = xCalculateSleepTime(); @@ -162,11 +169,39 @@ void test_xCalculateSleepTime_AllTimersActive_AllTimesGreaterExceptARP( void ) TickType_t uxTicks; xARPTimer.bActive = pdTRUE; + xNDTimer.bActive = pdTRUE; pxNetworkEndPoints->xDHCP_RATimer.bActive = pdTRUE; xDNSTimer.bActive = pdTRUE; xTCPTimer.bActive = pdTRUE; xARPTimer.ulRemainingTime = ipconfigMAX_IP_TASK_SLEEP_TIME - 10; + xNDTimer.ulRemainingTime = ipconfigMAX_IP_TASK_SLEEP_TIME; + pxNetworkEndPoints->xDHCP_RATimer.ulRemainingTime = ipconfigMAX_IP_TASK_SLEEP_TIME; + xTCPTimer.ulRemainingTime = ipconfigMAX_IP_TASK_SLEEP_TIME; + xDNSTimer.ulRemainingTime = ipconfigMAX_IP_TASK_SLEEP_TIME; + + uxTicks = xCalculateSleepTime(); + + TEST_ASSERT_EQUAL( ipconfigMAX_IP_TASK_SLEEP_TIME - 10, uxTicks ); +} + +/** + * @brief test_xCalculateSleepTime_AllTimersActive_AllTimesGreaterExceptND + * To validate if xCalculateSleepTime() returns the shortest remaining time + * of all active timers. In this case, ND timer has the shortest remaining time. + */ +void test_xCalculateSleepTime_AllTimersActive_AllTimesGreaterExceptND( void ) +{ + TickType_t uxTicks; + + xARPTimer.bActive = pdTRUE; + xNDTimer.bActive = pdTRUE; + pxNetworkEndPoints->xDHCP_RATimer.bActive = pdTRUE; + xDNSTimer.bActive = pdTRUE; + xTCPTimer.bActive = pdTRUE; + + xARPTimer.ulRemainingTime = ipconfigMAX_IP_TASK_SLEEP_TIME; + xNDTimer.ulRemainingTime = ipconfigMAX_IP_TASK_SLEEP_TIME - 10; pxNetworkEndPoints->xDHCP_RATimer.ulRemainingTime = ipconfigMAX_IP_TASK_SLEEP_TIME; xTCPTimer.ulRemainingTime = ipconfigMAX_IP_TASK_SLEEP_TIME; xDNSTimer.ulRemainingTime = ipconfigMAX_IP_TASK_SLEEP_TIME; @@ -191,11 +226,13 @@ void test_xCalculateSleepTime_AllTimersActive_AllTimesGreaterExceptDHCP( void ) pxNetworkEndPoints = pxEndpoint; xARPTimer.bActive = pdTRUE; + xNDTimer.bActive = pdTRUE; pxEndpoint->xDHCP_RATimer.bActive = pdTRUE; xDNSTimer.bActive = pdTRUE; xTCPTimer.bActive = pdTRUE; xARPTimer.ulRemainingTime = ipconfigMAX_IP_TASK_SLEEP_TIME; + xNDTimer.ulRemainingTime = ipconfigMAX_IP_TASK_SLEEP_TIME; pxEndpoint->xDHCP_RATimer.ulRemainingTime = ipconfigMAX_IP_TASK_SLEEP_TIME - 10; xTCPTimer.ulRemainingTime = ipconfigMAX_IP_TASK_SLEEP_TIME; xDNSTimer.ulRemainingTime = ipconfigMAX_IP_TASK_SLEEP_TIME; @@ -215,11 +252,13 @@ void test_xCalculateSleepTime_AllTimersActive_AllTimesGreaterExceptTCP( void ) TickType_t uxTicks; xARPTimer.bActive = pdTRUE; + xNDTimer.bActive = pdTRUE; pxNetworkEndPoints->xDHCP_RATimer.bActive = pdTRUE; xDNSTimer.bActive = pdTRUE; xTCPTimer.bActive = pdTRUE; xARPTimer.ulRemainingTime = ipconfigMAX_IP_TASK_SLEEP_TIME; + xNDTimer.ulRemainingTime = ipconfigMAX_IP_TASK_SLEEP_TIME; pxNetworkEndPoints->xDHCP_RATimer.ulRemainingTime = ipconfigMAX_IP_TASK_SLEEP_TIME; xTCPTimer.ulRemainingTime = ipconfigMAX_IP_TASK_SLEEP_TIME - 10; xDNSTimer.ulRemainingTime = ipconfigMAX_IP_TASK_SLEEP_TIME; @@ -239,11 +278,13 @@ void test_xCalculateSleepTime_AllTimersActive_AllTimesGreaterExceptDNS( void ) TickType_t uxTicks; xARPTimer.bActive = pdTRUE; + xNDTimer.bActive = pdTRUE; pxNetworkEndPoints->xDHCP_RATimer.bActive = pdTRUE; xDNSTimer.bActive = pdTRUE; xTCPTimer.bActive = pdTRUE; xARPTimer.ulRemainingTime = ipconfigMAX_IP_TASK_SLEEP_TIME; + xNDTimer.ulRemainingTime = ipconfigMAX_IP_TASK_SLEEP_TIME; pxNetworkEndPoints->xDHCP_RATimer.ulRemainingTime = ipconfigMAX_IP_TASK_SLEEP_TIME; xTCPTimer.ulRemainingTime = ipconfigMAX_IP_TASK_SLEEP_TIME; xDNSTimer.ulRemainingTime = ipconfigMAX_IP_TASK_SLEEP_TIME - 10; @@ -295,6 +336,7 @@ void test_xCalculateSleepTime_MultipleDHCPTimers( void ) void test_vCheckNetworkTimers_AllTimersDisabled( void ) { xARPTimer.bActive = pdFALSE; + xNDTimer.bActive = pdFALSE; pxNetworkEndPoints->xDHCP_RATimer.bActive = pdFALSE; xDNSTimer.bActive = pdFALSE; xTCPTimer.bActive = pdFALSE; @@ -315,6 +357,7 @@ void test_vCheckNetworkTimers_AllTimersDisabled( void ) void test_vCheckNetworkTimers_ARPTimerActiveAndExpired( void ) { xARPTimer.bActive = pdTRUE; + xNDTimer.bActive = pdFALSE; pxNetworkEndPoints->xDHCP_RATimer.bActive = pdFALSE; xDNSTimer.bActive = pdFALSE; xTCPTimer.bActive = pdFALSE; @@ -342,10 +385,12 @@ void test_vCheckNetworkTimers_ARPTimerActiveAndExpired( void ) void test_vCheckNetworkTimers_ARPResolutionTimerActiveAndExpiredNullBuffer( void ) { xARPTimer.bActive = pdFALSE; + xNDTimer.bActive = pdFALSE; pxNetworkEndPoints->xDHCP_RATimer.bActive = pdFALSE; xDNSTimer.bActive = pdFALSE; xTCPTimer.bActive = pdFALSE; xARPResolutionTimer.bActive = pdTRUE; + xNDResolutionTimer.bActive = pdFALSE; xARPResolutionTimer.bExpired = pdTRUE; @@ -372,10 +417,12 @@ void test_vCheckNetworkTimers_ARPResolutionTimerActiveAndExpiredNullBuffer( void void test_vCheckNetworkTimers_ARPResolutionTimerActiveAndExpired( void ) { xARPTimer.bActive = pdFALSE; + xNDTimer.bActive = pdFALSE; pxNetworkEndPoints->xDHCP_RATimer.bActive = pdFALSE; xDNSTimer.bActive = pdFALSE; xTCPTimer.bActive = pdFALSE; xARPResolutionTimer.bActive = pdTRUE; + xNDResolutionTimer.bActive = pdFALSE; xARPResolutionTimer.bExpired = pdTRUE; @@ -397,6 +444,100 @@ void test_vCheckNetworkTimers_ARPResolutionTimerActiveAndExpired( void ) TEST_ASSERT_EQUAL_PTR( NULL, pxARPWaitingNetworkBuffer ); } +/** + * @brief test_vCheckNetworkTimers_NDTimerActiveAndExpired + * To validate if vCheckNetworkTimers() handles ND timer expired event as expected. + */ +void test_vCheckNetworkTimers_NDTimerActiveAndExpired( void ) +{ + xARPTimer.bActive = pdFALSE; + xNDTimer.bActive = pdTRUE; + pxNetworkEndPoints->xDHCP_RATimer.bActive = pdFALSE; + xDNSTimer.bActive = pdFALSE; + xTCPTimer.bActive = pdFALSE; + + xNDTimer.bExpired = pdTRUE; + + vTaskSetTimeOutState_Expect( &( xNDTimer.xTimeOut ) ); + + xSendEventToIPTask_ExpectAndReturn( eNDTimerEvent, pdTRUE ); + + uxQueueMessagesWaiting_ExpectAnyArgsAndReturn( pdTRUE ); + + vSocketCloseNextTime_Expect( NULL ); + + vSocketListenNextTime_Expect( NULL ); + + vCheckNetworkTimers(); +} + +/** + * @brief test_vCheckNetworkTimers_NDResolutionTimerActiveAndExpiredNullBuffer + * To validate if vCheckNetworkTimers() handles ND resolution timer expired event as expected. + * And there is no buffer waiting for ND reply. + */ +void test_vCheckNetworkTimers_NDResolutionTimerActiveAndExpiredNullBuffer( void ) +{ + xARPTimer.bActive = pdFALSE; + xNDTimer.bActive = pdFALSE; + pxNetworkEndPoints->xDHCP_RATimer.bActive = pdFALSE; + xDNSTimer.bActive = pdFALSE; + xTCPTimer.bActive = pdFALSE; + xARPResolutionTimer.bActive = pdFALSE; + xNDResolutionTimer.bActive = pdTRUE; + + xNDResolutionTimer.bExpired = pdTRUE; + + pxNDWaitingNetworkBuffer = NULL; + + vTaskSetTimeOutState_Expect( &( xNDResolutionTimer.xTimeOut ) ); + + uxQueueMessagesWaiting_ExpectAnyArgsAndReturn( pdTRUE ); + + vSocketCloseNextTime_Expect( NULL ); + + vSocketListenNextTime_Expect( NULL ); + + vCheckNetworkTimers(); + + TEST_ASSERT_EQUAL( pdTRUE, xNDResolutionTimer.bExpired ); +} + +/** + * @brief test_vCheckNetworkTimers_NDResolutionTimerActiveAndExpired + * To validate if vCheckNetworkTimers() handles ND resolution timer expired event as expected. + * And there is a buffer waiting for ND reply. + */ +void test_vCheckNetworkTimers_NDResolutionTimerActiveAndExpired( void ) +{ + xARPTimer.bActive = pdFALSE; + xNDTimer.bActive = pdFALSE; + pxNetworkEndPoints->xDHCP_RATimer.bActive = pdFALSE; + xDNSTimer.bActive = pdFALSE; + xTCPTimer.bActive = pdFALSE; + xARPResolutionTimer.bActive = pdFALSE; + xNDResolutionTimer.bActive = pdTRUE; + + xNDResolutionTimer.bExpired = pdTRUE; + + pxNDWaitingNetworkBuffer = ( NetworkBufferDescriptor_t * ) 0x1234ABCD; + + vTaskSetTimeOutState_Expect( &( xNDResolutionTimer.xTimeOut ) ); + + vReleaseNetworkBufferAndDescriptor_Expect( pxNDWaitingNetworkBuffer ); + + uxQueueMessagesWaiting_ExpectAnyArgsAndReturn( pdTRUE ); + + vSocketCloseNextTime_Expect( NULL ); + + vSocketListenNextTime_Expect( NULL ); + + vCheckNetworkTimers(); + + TEST_ASSERT_EQUAL( pdFALSE_UNSIGNED, xNDResolutionTimer.bActive ); + TEST_ASSERT_EQUAL_PTR( NULL, pxNDWaitingNetworkBuffer ); +} + /** * @brief test_vCheckNetworkTimers_DHCPTimerActiveAndExpired * To validate if vCheckNetworkTimers() handles DHCP timer expired event as expected. @@ -404,10 +545,12 @@ void test_vCheckNetworkTimers_ARPResolutionTimerActiveAndExpired( void ) void test_vCheckNetworkTimers_DHCPTimerActiveAndExpired( void ) { xARPTimer.bActive = pdFALSE; + xNDTimer.bActive = pdFALSE; pxNetworkEndPoints->xDHCP_RATimer.bActive = pdTRUE; xDNSTimer.bActive = pdFALSE; xTCPTimer.bActive = pdFALSE; xARPResolutionTimer.bActive = pdFALSE; + xNDResolutionTimer.bActive = pdFALSE; pxNetworkEndPoints->xDHCP_RATimer.bExpired = pdTRUE; @@ -454,10 +597,12 @@ void test_vCheckNetworkTimers_DHCPv6TimerActiveAndExpired( void ) void test_vCheckNetworkTimers_RATimerActiveAndExpired( void ) { xARPTimer.bActive = pdFALSE; + xNDTimer.bActive = pdFALSE; pxNetworkEndPoints->xDHCP_RATimer.bActive = pdTRUE; xDNSTimer.bActive = pdFALSE; xTCPTimer.bActive = pdFALSE; xARPResolutionTimer.bActive = pdFALSE; + xNDResolutionTimer.bActive = pdFALSE; pxNetworkEndPoints->xDHCP_RATimer.bExpired = pdTRUE; pxNetworkEndPoints->bits.bIPv6 = pdTRUE; @@ -486,10 +631,12 @@ void test_vCheckNetworkTimers_DNSTimerActiveAndExpired( void ) NetworkEndPoint_t xEndPoint = { 0 }; xARPTimer.bActive = pdFALSE; + xNDTimer.bActive = pdFALSE; pxNetworkEndPoints->xDHCP_RATimer.bActive = pdFALSE; xDNSTimer.bActive = pdTRUE; xTCPTimer.bActive = pdFALSE; xARPResolutionTimer.bActive = pdFALSE; + xNDResolutionTimer.bActive = pdFALSE; xDNSTimer.bExpired = pdTRUE; @@ -624,10 +771,12 @@ void test_vCheckNetworkTimers_NetworkInterfacesAlreadyUp( void ) void test_vCheckNetworkTimers_AllTimersInactivePendingMessages( void ) { xARPTimer.bActive = pdFALSE; + xNDTimer.bActive = pdFALSE; pxNetworkEndPoints->xDHCP_RATimer.bActive = pdFALSE; xDNSTimer.bActive = pdFALSE; xTCPTimer.bActive = pdFALSE; xARPResolutionTimer.bActive = pdFALSE; + xNDResolutionTimer.bActive = pdFALSE; uxQueueMessagesWaiting_ExpectAnyArgsAndReturn( pdTRUE ); @@ -646,10 +795,12 @@ void test_vCheckNetworkTimers_AllTimersInactivePendingMessages( void ) void test_vCheckNetworkTimers_AllTimersInactive_2( void ) { xARPTimer.bActive = pdFALSE; + xNDTimer.bActive = pdFALSE; pxNetworkEndPoints->xDHCP_RATimer.bActive = pdFALSE; xDNSTimer.bActive = pdFALSE; xTCPTimer.bActive = pdFALSE; xARPResolutionTimer.bActive = pdFALSE; + xNDResolutionTimer.bActive = pdFALSE; uxQueueMessagesWaiting_ExpectAnyArgsAndReturn( pdFALSE ); @@ -724,7 +875,25 @@ void test_vIPTimerStartARPResolution( void ) } /** - * @brief test_vIPTimerStartARPResolution + * @brief test_vIPTimerStartNDResolution + * To validate if vIPTimerStartNDResolution() activate the ND resolution timer + * with zero time. Timer must be expired after calling. + */ +void test_vIPTimerStartNDResolution( void ) +{ + TickType_t xTime = 0x00; + + vTaskSetTimeOutState_Expect( &xNDResolutionTimer.xTimeOut ); + + vIPTimerStartNDResolution( xTime ); + + TEST_ASSERT_EQUAL( xTime, xNDResolutionTimer.ulRemainingTime ); + TEST_ASSERT_EQUAL( pdTRUE, xNDResolutionTimer.bActive ); + TEST_ASSERT_EQUAL( pdTRUE, xNDResolutionTimer.bExpired ); +} + +/** + * @brief test_vTCPTimerReload * To validate if vTCPTimerReload() activate the TCP timer with non-zero time. */ void test_vTCPTimerReload( void ) @@ -759,6 +928,24 @@ void test_vARPTimerReload( void ) TEST_ASSERT_EQUAL( pdFALSE, xARPTimer.bExpired ); } +/** + * @brief test_vNDTimerReload + * To validate if vNDTimerReload() activate the ND timer with non-zero time. + */ +void test_vNDTimerReload( void ) +{ + TickType_t xTime = 0x12A; + + vTaskSetTimeOutState_Expect( &xNDTimer.xTimeOut ); + + vNDTimerReload( xTime ); + + TEST_ASSERT_EQUAL( 0x12A, xNDTimer.ulReloadTime ); + TEST_ASSERT_EQUAL( xTime, xNDTimer.ulRemainingTime ); + TEST_ASSERT_EQUAL( pdTRUE, xNDTimer.bActive ); + TEST_ASSERT_EQUAL( pdFALSE, xNDTimer.bExpired ); +} + /** * @brief test_vDHCP_RATimerReload * To validate if vTCPTimerReload() activate the DHCP timer with non-zero time. @@ -986,6 +1173,60 @@ void test_vIPSetARPResolutionTimerEnableState_True( void ) TEST_ASSERT_EQUAL( xEnableState, xARPResolutionTimer.bActive ); } +/** + * @brief test_vIPSetNDTimerEnableState_False + * To validate if vIPSetNDTimerEnableState() sets ND timer to non expired state. + */ +void test_vIPSetNDTimerEnableState_False( void ) +{ + BaseType_t xEnableState = pdFALSE; + + vIPSetNDTimerEnableState( xEnableState ); + + TEST_ASSERT_EQUAL( xEnableState, xNDTimer.bActive ); +} + +/** + * @brief test_vIPSetNDTimerEnableState_True + * To validate if vIPSetNDTimerEnableState() sets ND timer to expired state. + */ +void test_vIPSetNDTimerEnableState_True( void ) +{ + BaseType_t xEnableState = pdTRUE; + + vIPSetNDTimerEnableState( xEnableState ); + + TEST_ASSERT_EQUAL( xEnableState, xNDTimer.bActive ); +} + +/** + * @brief test_vIPSetNDResolutionTimerEnableState_False + * To validate if vIPSetNDResolutionTimerEnableState() sets ND resolution timer + * to non expired state. + */ +void test_vIPSetNDResolutionTimerEnableState_False( void ) +{ + BaseType_t xEnableState = pdFALSE; + + vIPSetNDResolutionTimerEnableState( xEnableState ); + + TEST_ASSERT_EQUAL( xEnableState, xNDResolutionTimer.bActive ); +} + +/** + * @brief test_vIPSetNDResolutionTimerEnableState_True + * To validate if vIPSetNDResolutionTimerEnableState() sets ND resolution timer + * to expired state. + */ +void test_vIPSetNDResolutionTimerEnableState_True( void ) +{ + BaseType_t xEnableState = pdTRUE; + + vIPSetNDResolutionTimerEnableState( xEnableState ); + + TEST_ASSERT_EQUAL( xEnableState, xNDResolutionTimer.bActive ); +} + /** * @brief test_vIPSetDHCP_RATimerEnableState_False * To validate if vIPSetDHCP_RATimerEnableState() sets DHCP timer 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 8ac617f937..22b4b97fc4 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 @@ -47,6 +47,7 @@ #include "mock_FreeRTOS_IP_Private.h" #include "mock_FreeRTOS_IP_Timers.h" #include "mock_FreeRTOS_ARP.h" +#include "mock_FreeRTOS_ND.h" #include "mock_FreeRTOS_DHCP.h" #include "mock_FreeRTOS_DHCPv6.h" #include "mock_FreeRTOS_Routing.h" @@ -489,11 +490,13 @@ void test_prvProcessNetworkDownEvent_Pass( void ) xEndPoint.bits.bCallDownHook = pdFALSE_UNSIGNED; vIPSetARPTimerEnableState_Expect( pdFALSE ); + vIPSetNDTimerEnableState_Expect( pdFALSE ); FreeRTOS_FirstEndPoint_IgnoreAndReturn( &xEndPoint ); FreeRTOS_NextEndPoint_IgnoreAndReturn( NULL ); FreeRTOS_ClearARP_ExpectAnyArgs(); + FreeRTOS_ClearND_ExpectAnyArgs(); vDHCPStop_Expect( &xEndPoint ); @@ -504,6 +507,7 @@ void test_prvProcessNetworkDownEvent_Pass( void ) /* Run again to trigger a different path in the code. */ vIPSetARPTimerEnableState_Expect( pdFALSE ); + vIPSetNDTimerEnableState_Expect( pdFALSE ); FreeRTOS_FirstEndPoint_IgnoreAndReturn( &xEndPoint ); FreeRTOS_NextEndPoint_IgnoreAndReturn( NULL ); @@ -511,6 +515,7 @@ void test_prvProcessNetworkDownEvent_Pass( void ) vApplicationIPNetworkEventHook_Multi_Expect( eNetworkDown, &xEndPoint ); FreeRTOS_ClearARP_Expect( &xEndPoint ); + FreeRTOS_ClearND_Expect( &xEndPoint ); vDHCPStop_Expect( &xEndPoint ); @@ -535,11 +540,13 @@ void test_prvProcessNetworkDownEvent_Fail( void ) xEndPoint.bits.bWantDHCP = pdFALSE_UNSIGNED; vIPSetARPTimerEnableState_Expect( pdFALSE ); + vIPSetNDTimerEnableState_Expect( pdFALSE ); FreeRTOS_FirstEndPoint_IgnoreAndReturn( &xEndPoint ); FreeRTOS_NextEndPoint_IgnoreAndReturn( NULL ); FreeRTOS_ClearARP_Expect( &xEndPoint ); + FreeRTOS_ClearND_Expect( &xEndPoint ); vIPNetworkUpCalls_Expect( &xEndPoint ); @@ -586,11 +593,13 @@ void test_prvProcessNetworkDownEvent_InterfaceInitFail( void ) xEndPoint.bits.bCallDownHook = pdFALSE_UNSIGNED; vIPSetARPTimerEnableState_Expect( pdFALSE ); + vIPSetNDTimerEnableState_Expect( pdFALSE ); FreeRTOS_FirstEndPoint_IgnoreAndReturn( &xEndPoint ); FreeRTOS_NextEndPoint_IgnoreAndReturn( NULL ); FreeRTOS_ClearARP_ExpectAnyArgs(); + FreeRTOS_ClearND_ExpectAnyArgs(); vDHCPStop_Expect( &xEndPoint ); @@ -616,6 +625,7 @@ void test_prvProcessNetworkDownEvent_PassDHCPv6( void ) xEndPoint.bits.bCallDownHook = pdFALSE_UNSIGNED; vIPSetARPTimerEnableState_Expect( pdFALSE ); + vIPSetNDTimerEnableState_Expect( pdFALSE ); FreeRTOS_FirstEndPoint_IgnoreAndReturn( &xEndPoint ); @@ -628,6 +638,7 @@ void test_prvProcessNetworkDownEvent_PassDHCPv6( void ) FreeRTOS_NextEndPoint_IgnoreAndReturn( NULL ); FreeRTOS_ClearARP_ExpectAnyArgs(); + FreeRTOS_ClearND_ExpectAnyArgs(); vDHCPv6Stop_Expect( &xEndPoint ); @@ -653,6 +664,7 @@ void test_prvProcessNetworkDownEvent_PassRA( void ) xEndPoint.bits.bCallDownHook = pdFALSE_UNSIGNED; vIPSetARPTimerEnableState_Expect( pdFALSE ); + vIPSetNDTimerEnableState_Expect( pdFALSE ); FreeRTOS_FirstEndPoint_IgnoreAndReturn( &xEndPoint ); @@ -665,6 +677,7 @@ void test_prvProcessNetworkDownEvent_PassRA( void ) FreeRTOS_NextEndPoint_IgnoreAndReturn( NULL ); FreeRTOS_ClearARP_ExpectAnyArgs(); + FreeRTOS_ClearND_ExpectAnyArgs(); vIPSetDHCP_RATimerEnableState_Expect( &xEndPoint, pdFALSE ); @@ -692,6 +705,7 @@ void test_prvProcessNetworkDownEvent_PassStaticIP( void ) memcpy( xEndPoint.ipv6_defaults.xIPAddress.ucBytes, xIPv6Address.ucBytes, ipSIZE_OF_IPv6_ADDRESS ); vIPSetARPTimerEnableState_Expect( pdFALSE ); + vIPSetNDTimerEnableState_Expect( pdFALSE ); FreeRTOS_FirstEndPoint_IgnoreAndReturn( &xEndPoint ); @@ -704,6 +718,7 @@ void test_prvProcessNetworkDownEvent_PassStaticIP( void ) FreeRTOS_NextEndPoint_IgnoreAndReturn( NULL ); FreeRTOS_ClearARP_ExpectAnyArgs(); + FreeRTOS_ClearND_ExpectAnyArgs(); vIPNetworkUpCalls_Expect( &xEndPoint ); @@ -3187,6 +3202,7 @@ static void prvProcessNetworkDownEvent_Generic( const uint8_t * pucAddress, } vIPSetARPTimerEnableState_Expect( pdFALSE ); + vIPSetNDTimerEnableState_Expect( pdFALSE ); FreeRTOS_FirstEndPoint_IgnoreAndReturn( &xEndPoint ); @@ -3200,6 +3216,7 @@ static void prvProcessNetworkDownEvent_Generic( const uint8_t * pucAddress, FreeRTOS_ClearARP_Expect( &xEndPoint ); + FreeRTOS_ClearND_Expect( &xEndPoint ); vIPNetworkUpCalls_Expect( &xEndPoint ); diff --git a/test/unit-test/FreeRTOS_IP_Utils/ut.cmake b/test/unit-test/FreeRTOS_IP_Utils/ut.cmake index 8c5f73078b..70d93eed9f 100644 --- a/test/unit-test/FreeRTOS_IP_Utils/ut.cmake +++ b/test/unit-test/FreeRTOS_IP_Utils/ut.cmake @@ -18,6 +18,7 @@ list(APPEND mock_list "${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IP_Private.h" "${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IP_Timers.h" "${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_ARP.h" + "${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_ND.h" "${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_DHCP.h" "${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_DHCPv6.h" "${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_Routing.h" diff --git a/test/unit-test/FreeRTOS_ND/FreeRTOS_ND_stubs.c b/test/unit-test/FreeRTOS_ND/FreeRTOS_ND_stubs.c index caf91a5a71..d5f5a35481 100644 --- a/test/unit-test/FreeRTOS_ND/FreeRTOS_ND_stubs.c +++ b/test/unit-test/FreeRTOS_ND/FreeRTOS_ND_stubs.c @@ -14,10 +14,10 @@ /* =========================== EXTERN VARIABLES =========================== */ -/** @brief The pointer to buffer with packet waiting for ARP resolution. This variable +/** @brief The pointer to buffer with packet waiting for ND resolution. This variable * is defined in FreeRTOS_IP.c. * This pointer is for internal use only. */ -NetworkBufferDescriptor_t * pxARPWaitingNetworkBuffer; +NetworkBufferDescriptor_t * pxNDWaitingNetworkBuffer; BaseType_t NetworkInterfaceOutputFunction_Stub_Called = 0; diff --git a/test/unit-test/FreeRTOS_ND/FreeRTOS_ND_utest.c b/test/unit-test/FreeRTOS_ND/FreeRTOS_ND_utest.c index 2bd43461ba..fb30cb402f 100644 --- a/test/unit-test/FreeRTOS_ND/FreeRTOS_ND_utest.c +++ b/test/unit-test/FreeRTOS_ND/FreeRTOS_ND_utest.c @@ -43,7 +43,6 @@ #include "mock_queue.h" #include "mock_event_groups.h" -#include "mock_FreeRTOS_ARP.h" #include "mock_FreeRTOS_IP.h" #include "mock_FreeRTOS_IPv6.h" #include "mock_FreeRTOS_IP_Private.h" @@ -110,7 +109,7 @@ static const MACAddress_t xDefaultMACAddress = { 0x22, 0x22, 0x22, 0x22, 0x22, 0 */ void test_eNDGetCacheEntry_MulticastEndPoint( void ) { - eARPLookupResult_t eResult; + eResolutionLookupResult_t eResult; MACAddress_t xMACAddress; IPv6_Address_t xIPAddress; NetworkEndPoint_t xEndPoint, * pxEndPoint = &xEndPoint; @@ -124,7 +123,7 @@ void test_eNDGetCacheEntry_MulticastEndPoint( void ) eResult = eNDGetCacheEntry( &xIPAddress, &xMACAddress, &pxEndPoint ); - TEST_ASSERT_EQUAL( eARPCacheHit, eResult ); + TEST_ASSERT_EQUAL( eResolutionCacheHit, eResult ); } /** @@ -134,7 +133,7 @@ void test_eNDGetCacheEntry_MulticastEndPoint( void ) void test_eNDGetCacheEntry_Multicast_ValidEndPoint( void ) { NetworkEndPoint_t xEndPoint1, xEndPoint2, xEndPoint3, * pxEndPoint = &xEndPoint1; - eARPLookupResult_t eResult; + eResolutionLookupResult_t eResult; MACAddress_t xMACAddress; IPv6_Address_t xIPAddress; @@ -154,7 +153,7 @@ void test_eNDGetCacheEntry_Multicast_ValidEndPoint( void ) eResult = eNDGetCacheEntry( &xIPAddress, &xMACAddress, &pxEndPoint ); - TEST_ASSERT_EQUAL( eARPCacheHit, eResult ); + TEST_ASSERT_EQUAL( eResolutionCacheHit, eResult ); } /** @@ -164,7 +163,7 @@ void test_eNDGetCacheEntry_Multicast_ValidEndPoint( void ) void test_eNDGetCacheEntry_Multicast_InvalidEndPoint( void ) { NetworkEndPoint_t ** ppxEndPoint = NULL; - eARPLookupResult_t eResult; + eResolutionLookupResult_t eResult; MACAddress_t xMACAddress; IPv6_Address_t xIPAddress; @@ -175,7 +174,7 @@ void test_eNDGetCacheEntry_Multicast_InvalidEndPoint( void ) eResult = eNDGetCacheEntry( &xIPAddress, &xMACAddress, ppxEndPoint ); - TEST_ASSERT_EQUAL( eARPCacheHit, eResult ); + TEST_ASSERT_EQUAL( eResolutionCacheHit, eResult ); } /** @@ -188,7 +187,7 @@ void test_eNDGetCacheEntry_NDCacheLookupHit_InvalidEndPoint( void ) MACAddress_t xMACAddress; IPv6_Address_t xIPAddress; NetworkEndPoint_t ** ppxEndPoint = NULL; - eARPLookupResult_t eResult; + eResolutionLookupResult_t eResult; BaseType_t xUseEntry = 0; xIsIPv6AllowedMulticast_ExpectAnyArgsAndReturn( pdFALSE ); @@ -202,7 +201,7 @@ void test_eNDGetCacheEntry_NDCacheLookupHit_InvalidEndPoint( void ) eResult = eNDGetCacheEntry( &xIPAddress, &xMACAddress, ppxEndPoint ); - TEST_ASSERT_EQUAL( eARPCacheHit, eResult ); + TEST_ASSERT_EQUAL( eResolutionCacheHit, eResult ); TEST_ASSERT_EQUAL_MEMORY( xMACAddress.ucBytes, xNDCache[ xUseEntry ].xMACAddress.ucBytes, sizeof( MACAddress_t ) ); } @@ -217,7 +216,7 @@ void test_eNDGetCacheEntry_NDCacheLookupHit_ValidEndPoint( void ) MACAddress_t xMACAddress; IPv6_Address_t xIPAddress; NetworkEndPoint_t * pxEndPoint, xEndPoint1, xEndPoint2; - eARPLookupResult_t eResult; + eResolutionLookupResult_t eResult; BaseType_t xUseEntry = 0; xIsIPv6AllowedMulticast_ExpectAnyArgsAndReturn( pdFALSE ); @@ -235,7 +234,7 @@ void test_eNDGetCacheEntry_NDCacheLookupHit_ValidEndPoint( void ) eResult = eNDGetCacheEntry( &xIPAddress, &xMACAddress, &pxEndPoint ); - TEST_ASSERT_EQUAL( eARPCacheHit, eResult ); + TEST_ASSERT_EQUAL( eResolutionCacheHit, eResult ); TEST_ASSERT_EQUAL_MEMORY( xMACAddress.ucBytes, xNDCache[ xUseEntry ].xMACAddress.ucBytes, sizeof( MACAddress_t ) ); TEST_ASSERT_EQUAL_MEMORY( pxEndPoint, &xEndPoint2, sizeof( NetworkEndPoint_t ) ); } @@ -247,7 +246,7 @@ void test_eNDGetCacheEntry_NDCacheLookupHit_ValidEndPoint( void ) void test_eNDGetCacheEntry_NDCacheLookupMiss_InvalidEntry( void ) { NetworkEndPoint_t * pxEndPoint, xEndPoint; - eARPLookupResult_t eResult; + eResolutionLookupResult_t eResult; BaseType_t xUseEntry = 0; MACAddress_t xMACAddress; IPv6_Address_t xIPAddress; @@ -264,7 +263,7 @@ void test_eNDGetCacheEntry_NDCacheLookupMiss_InvalidEntry( void ) eResult = eNDGetCacheEntry( &xIPAddress, &xMACAddress, &pxEndPoint ); - TEST_ASSERT_EQUAL( eARPCacheMiss, eResult ); + TEST_ASSERT_EQUAL( eResolutionCacheMiss, eResult ); } /** @@ -274,7 +273,7 @@ void test_eNDGetCacheEntry_NDCacheLookupMiss_InvalidEntry( void ) void test_eNDGetCacheEntry_NDCacheLookupMiss_InvalidEntry2( void ) { NetworkEndPoint_t ** ppxEndPoint = NULL, xEndPoint; - eARPLookupResult_t eResult; + eResolutionLookupResult_t eResult; BaseType_t xUseEntry = 0; MACAddress_t xMACAddress; IPv6_Address_t xIPAddress; @@ -290,7 +289,7 @@ void test_eNDGetCacheEntry_NDCacheLookupMiss_InvalidEntry2( void ) eResult = eNDGetCacheEntry( &xIPAddress, &xMACAddress, ppxEndPoint ); - TEST_ASSERT_EQUAL( eARPCacheMiss, eResult ); + TEST_ASSERT_EQUAL( eResolutionCacheMiss, eResult ); } /** @@ -301,7 +300,7 @@ void test_eNDGetCacheEntry_NDCacheLookupMiss_InvalidEntry2( void ) void test_eNDGetCacheEntry_NDCacheLookupMiss_NoEntry( void ) { NetworkEndPoint_t * pxEndPoint, xEndPoint; - eARPLookupResult_t eResult; + eResolutionLookupResult_t eResult; BaseType_t xUseEntry = 0; MACAddress_t xMACAddress; IPv6_Address_t xIPAddress; @@ -318,7 +317,7 @@ void test_eNDGetCacheEntry_NDCacheLookupMiss_NoEntry( void ) eResult = eNDGetCacheEntry( &xIPAddress, &xMACAddress, &pxEndPoint ); - TEST_ASSERT_EQUAL( eARPCacheMiss, eResult ); + TEST_ASSERT_EQUAL( eResolutionCacheMiss, eResult ); } /** @@ -329,7 +328,7 @@ void test_eNDGetCacheEntry_NDCacheLookupMiss_NoEntry( void ) void test_eNDGetCacheEntry_NDCacheLookupMiss_NoLinkLocal( void ) { NetworkEndPoint_t * pxEndPoint, xEndPoint; - eARPLookupResult_t eResult; + eResolutionLookupResult_t eResult; BaseType_t xUseEntry = 0; MACAddress_t xMACAddress; IPv6_Address_t xIPAddress; @@ -350,7 +349,7 @@ void test_eNDGetCacheEntry_NDCacheLookupMiss_NoLinkLocal( void ) eResult = eNDGetCacheEntry( &xIPAddress, &xMACAddress, &pxEndPoint ); - TEST_ASSERT_EQUAL( eARPCacheMiss, eResult ); + TEST_ASSERT_EQUAL( eResolutionCacheMiss, eResult ); } /** @@ -361,7 +360,7 @@ void test_eNDGetCacheEntry_NDCacheLookupMiss_NoLinkLocal( void ) void test_eNDGetCacheEntry_NDCacheLookupMiss_LinkLocal( void ) { NetworkEndPoint_t * pxEndPoint, xEndPoint; - eARPLookupResult_t eResult; + eResolutionLookupResult_t eResult; BaseType_t xUseEntry = 0; MACAddress_t xMACAddress; IPv6_Address_t xIPAddress; @@ -380,7 +379,7 @@ void test_eNDGetCacheEntry_NDCacheLookupMiss_LinkLocal( void ) eResult = eNDGetCacheEntry( &xIPAddress, &xMACAddress, &pxEndPoint ); - TEST_ASSERT_EQUAL( eARPCacheMiss, eResult ); + TEST_ASSERT_EQUAL( eResolutionCacheMiss, eResult ); } /** @@ -392,7 +391,7 @@ void test_eNDGetCacheEntry_NDCacheLookupHit_Gateway( void ) MACAddress_t xMACAddress; IPv6_Address_t xIPAddress; NetworkEndPoint_t * pxEndPoint, xEndPoint1, xEndPoint2; - eARPLookupResult_t eResult; + eResolutionLookupResult_t eResult; BaseType_t xUseEntry = 0; pxEndPoint = &xEndPoint2; @@ -412,7 +411,7 @@ void test_eNDGetCacheEntry_NDCacheLookupHit_Gateway( void ) eResult = eNDGetCacheEntry( &xIPAddress, &xMACAddress, &pxEndPoint ); - TEST_ASSERT_EQUAL( eARPCacheHit, eResult ); + TEST_ASSERT_EQUAL( eResolutionCacheHit, eResult ); TEST_ASSERT_EQUAL_MEMORY( xMACAddress.ucBytes, xNDCache[ xUseEntry ].xMACAddress.ucBytes, sizeof( MACAddress_t ) ); } @@ -425,7 +424,7 @@ void test_eNDGetCacheEntry_NDCacheLookupMiss_Gateway( void ) MACAddress_t xMACAddress; IPv6_Address_t xIPAddress; NetworkEndPoint_t * pxEndPoint, xEndPoint1, xEndPoint2; - eARPLookupResult_t eResult; + eResolutionLookupResult_t eResult; BaseType_t xUseEntry = 0; pxEndPoint = &xEndPoint2; @@ -445,7 +444,7 @@ void test_eNDGetCacheEntry_NDCacheLookupMiss_Gateway( void ) eResult = eNDGetCacheEntry( &xIPAddress, &xMACAddress, &pxEndPoint ); - TEST_ASSERT_EQUAL( eARPCacheMiss, eResult ); + TEST_ASSERT_EQUAL( eResolutionCacheMiss, eResult ); } /** @@ -456,7 +455,7 @@ void test_eNDGetCacheEntry_NDCacheLookupMiss_NoEP( void ) { MACAddress_t xMACAddress; NetworkEndPoint_t * pxEndPoint, xEndPoint; - eARPLookupResult_t eResult; + eResolutionLookupResult_t eResult; BaseType_t xUseEntry = 0; ( void ) memset( xNDCache, 0, sizeof( xNDCache ) ); @@ -474,7 +473,7 @@ void test_eNDGetCacheEntry_NDCacheLookupMiss_NoEP( void ) /* TODO: This function should take a const pointer; remove const cast when it does. */ eResult = eNDGetCacheEntry( ( IPv6_Address_t * ) &xSiteLocalIPAddress, &xMACAddress, &pxEndPoint ); - TEST_ASSERT_EQUAL( eARPCacheMiss, eResult ); + TEST_ASSERT_EQUAL( eResolutionCacheMiss, eResult ); } /** @@ -523,7 +522,7 @@ void test_vNDRefreshCacheEntry_NoMatchingEntryAdd( void ) /* Since no matching entry will be found, 0th entry will be updated to have the below details. */ vNDRefreshCacheEntry( &xMACAddress, &xIPAddress, &xEndPoint ); - TEST_ASSERT_EQUAL( xNDCache[ xUseEntry ].ucAge, ( uint8_t ) ipconfigMAX_ARP_AGE ); + TEST_ASSERT_EQUAL( xNDCache[ xUseEntry ].ucAge, ( uint8_t ) ipconfigMAX_ND_AGE ); TEST_ASSERT_EQUAL( xNDCache[ xUseEntry ].ucValid, pdTRUE ); TEST_ASSERT_EQUAL_MEMORY( xNDCache[ xUseEntry ].xIPAddress.ucBytes, xIPAddress.ucBytes, ipSIZE_OF_IPv6_ADDRESS ); TEST_ASSERT_EQUAL_MEMORY( xNDCache[ xUseEntry ].xMACAddress.ucBytes, xMACAddress.ucBytes, sizeof( MACAddress_t ) ); @@ -550,7 +549,7 @@ void test_vNDRefreshCacheEntry_MatchingEntryRefresh( void ) /* Since a matching entry is found at xUseEntry = 1st location, the entry will be refreshed.*/ vNDRefreshCacheEntry( &xMACAddress, &xIPAddress, &xEndPoint ); - TEST_ASSERT_EQUAL( xNDCache[ xUseEntry ].ucAge, ( uint8_t ) ipconfigMAX_ARP_AGE ); + TEST_ASSERT_EQUAL( xNDCache[ xUseEntry ].ucAge, ( uint8_t ) ipconfigMAX_ND_AGE ); TEST_ASSERT_EQUAL_MEMORY( xNDCache[ xUseEntry ].xMACAddress.ucBytes, xMACAddress.ucBytes, sizeof( MACAddress_t ) ); TEST_ASSERT_EQUAL_MEMORY( xNDCache[ xUseEntry ].pxEndPoint, &xEndPoint, sizeof( NetworkEndPoint_t ) ); } @@ -785,11 +784,45 @@ void test_FreeRTOS_ClearND( void ) /* Set xNDCache to non zero entries*/ ( void ) memset( xNDCache, 1, sizeof( xNDCache ) ); ( void ) memset( xTempNDCache, 0, sizeof( xTempNDCache ) ); - FreeRTOS_ClearND(); + FreeRTOS_ClearND( NULL ); TEST_ASSERT_EQUAL_MEMORY( xNDCache, xTempNDCache, sizeof( xNDCache ) ); } +/** + * @brief Clear the Neighbour Discovery cache with specific endpoint. + */ +void test_FreeRTOS_ClearND_WithEndPoint( void ) +{ + NDCacheRow_t xTempNDCache[ ipconfigND_CACHE_ENTRIES ]; + struct xNetworkEndPoint xEndPoint; + + /* Set xNDCache to non zero entries*/ + ( void ) memset( xNDCache, 1, sizeof( xNDCache ) ); + ( void ) memset( xTempNDCache, 0, sizeof( xTempNDCache ) ); + xNDCache[ 1 ].pxEndPoint = &xEndPoint; + FreeRTOS_ClearND( &xEndPoint ); + + TEST_ASSERT_EQUAL_MEMORY( &xNDCache[ 1 ], xTempNDCache, sizeof( NDCacheRow_t ) ); +} + +/** + * @brief Clear the Neighbour Discovery cache with endpoint. + * But the endpoint doesn't match any in cache. + */ +void test_FreeRTOS_ClearND_EndPointNotFound( void ) +{ + NDCacheRow_t xTempNDCache[ ipconfigND_CACHE_ENTRIES ]; + struct xNetworkEndPoint xEndPoint; + + /* Set xNDCache to non zero entries*/ + ( void ) memset( xNDCache, 1, sizeof( xNDCache ) ); + ( void ) memset( xTempNDCache, 1, sizeof( xTempNDCache ) ); + FreeRTOS_ClearND( &xEndPoint ); + + TEST_ASSERT_EQUAL_MEMORY( xTempNDCache, xNDCache, sizeof( xNDCache ) ); +} + /** * @brief Toggle happy path. */ @@ -1546,7 +1579,7 @@ void test_prvProcessICMPMessage_IPv6_NeighborSolicitation( void ) /** * @brief This function process ICMP message when message type is * ipICMP_NEIGHBOR_ADVERTISEMENT_IPv6. - * It handles case when pxARPWaitingNetworkBuffer is NULL. + * It handles case when pxNDWaitingNetworkBuffer is NULL. */ void test_prvProcessICMPMessage_IPv6_NeighborAdvertisement1( void ) { @@ -1560,7 +1593,7 @@ void test_prvProcessICMPMessage_IPv6_NeighborAdvertisement1( void ) pxNetworkBuffer->pucEthernetBuffer = ( uint8_t * ) &xICMPPacket; pxNetworkBuffer->pxEndPoint = &xEndPoint; xICMPPacket.xICMPHeaderIPv6.ucTypeOfMessage = ipICMP_NEIGHBOR_ADVERTISEMENT_IPv6; - pxARPWaitingNetworkBuffer = NULL; + pxNDWaitingNetworkBuffer = NULL; eReturn = prvProcessICMPMessage_IPv6( pxNetworkBuffer ); @@ -1580,14 +1613,14 @@ void test_prvProcessICMPMessage_IPv6_NeighborAdvertisement2( void ) ICMPHeader_IPv6_t * pxICMPHeader_IPv6 = ( ( ICMPHeader_IPv6_t * ) &( xICMPPacket.xICMPHeaderIPv6 ) ); NetworkEndPoint_t xEndPoint; eFrameProcessingResult_t eReturn; - NetworkBufferDescriptor_t xARPWaitingNetworkBuffer; + NetworkBufferDescriptor_t xNDWaitingNetworkBuffer; xEndPoint.bits.bIPv6 = pdTRUE_UNSIGNED; pxNetworkBuffer->pucEthernetBuffer = ( uint8_t * ) &xICMPPacket; pxNetworkBuffer->pxEndPoint = &xEndPoint; xICMPPacket.xICMPHeaderIPv6.ucTypeOfMessage = ipICMP_NEIGHBOR_ADVERTISEMENT_IPv6; - pxARPWaitingNetworkBuffer = &xARPWaitingNetworkBuffer; + pxNDWaitingNetworkBuffer = &xNDWaitingNetworkBuffer; uxIPHeaderSizePacket_IgnoreAndReturn( ipSIZE_OF_IPv4_HEADER ); eReturn = prvProcessICMPMessage_IPv6( pxNetworkBuffer ); @@ -1598,7 +1631,7 @@ void test_prvProcessICMPMessage_IPv6_NeighborAdvertisement2( void ) /** * @brief This function process ICMP message when message type is * ipICMP_NEIGHBOR_ADVERTISEMENT_IPv6. - * This verifies a case 'pxARPWaitingNetworkBuffer' was + * This verifies a case 'pxNDWaitingNetworkBuffer' was * not waiting for this new address look-up. */ void test_prvProcessICMPMessage_IPv6_NeighborAdvertisement3( void ) @@ -1608,12 +1641,12 @@ void test_prvProcessICMPMessage_IPv6_NeighborAdvertisement3( void ) ICMPHeader_IPv6_t * pxICMPHeader_IPv6 = ( ( ICMPHeader_IPv6_t * ) &( xICMPPacket.xICMPHeaderIPv6 ) ); NetworkEndPoint_t xEndPoint; eFrameProcessingResult_t eReturn; - NetworkBufferDescriptor_t xARPWaitingNetworkBuffer; + NetworkBufferDescriptor_t xNDWaitingNetworkBuffer; IPPacket_IPv6_t xIPPacket; IPHeader_IPv6_t * pxIPHeader = &( xIPPacket.xIPHeader ); - pxARPWaitingNetworkBuffer = &xARPWaitingNetworkBuffer; - pxARPWaitingNetworkBuffer->pucEthernetBuffer = ( uint8_t * ) &xIPPacket; + pxNDWaitingNetworkBuffer = &xNDWaitingNetworkBuffer; + pxNDWaitingNetworkBuffer->pucEthernetBuffer = ( uint8_t * ) &xIPPacket; xEndPoint.bits.bIPv6 = pdTRUE_UNSIGNED; pxNetworkBuffer->pucEthernetBuffer = ( uint8_t * ) &xICMPPacket; pxNetworkBuffer->pxEndPoint = &xEndPoint; @@ -1632,7 +1665,7 @@ void test_prvProcessICMPMessage_IPv6_NeighborAdvertisement3( void ) * ipICMP_NEIGHBOR_ADVERTISEMENT_IPv6. * This verifies a case where a packet is handled as a new * incoming IP packet when a neighbour advertisement has been received, - * and 'pxARPWaitingNetworkBuffer' was waiting for this new address look-up. + * and 'pxNDWaitingNetworkBuffer' was waiting for this new address look-up. */ void test_prvProcessICMPMessage_IPv6_NeighborAdvertisement4( void ) { @@ -1641,12 +1674,12 @@ void test_prvProcessICMPMessage_IPv6_NeighborAdvertisement4( void ) ICMPHeader_IPv6_t * pxICMPHeader_IPv6 = ( ( ICMPHeader_IPv6_t * ) &( xICMPPacket.xICMPHeaderIPv6 ) ); NetworkEndPoint_t xEndPoint; eFrameProcessingResult_t eReturn; - NetworkBufferDescriptor_t xARPWaitingNetworkBuffer; + NetworkBufferDescriptor_t xNDWaitingNetworkBuffer; IPPacket_IPv6_t xIPPacket; IPHeader_IPv6_t * pxIPHeader = &( xIPPacket.xIPHeader ); - pxARPWaitingNetworkBuffer = &xARPWaitingNetworkBuffer; - pxARPWaitingNetworkBuffer->pucEthernetBuffer = ( uint8_t * ) &xIPPacket; + pxNDWaitingNetworkBuffer = &xNDWaitingNetworkBuffer; + pxNDWaitingNetworkBuffer->pucEthernetBuffer = ( uint8_t * ) &xIPPacket; xEndPoint.bits.bIPv6 = pdTRUE_UNSIGNED; pxNetworkBuffer->pucEthernetBuffer = ( uint8_t * ) &xICMPPacket; @@ -1659,12 +1692,12 @@ void test_prvProcessICMPMessage_IPv6_NeighborAdvertisement4( void ) uxIPHeaderSizePacket_IgnoreAndReturn( ipSIZE_OF_IPv6_HEADER ); xSendEventStructToIPTask_IgnoreAndReturn( pdFAIL ); vReleaseNetworkBufferAndDescriptor_Ignore(); - vIPSetARPResolutionTimerEnableState_ExpectAnyArgs(); + vIPSetNDResolutionTimerEnableState_ExpectAnyArgs(); eReturn = prvProcessICMPMessage_IPv6( pxNetworkBuffer ); TEST_ASSERT_EQUAL( eReturn, eReleaseBuffer ); - TEST_ASSERT_EQUAL( pxARPWaitingNetworkBuffer, NULL ); + TEST_ASSERT_EQUAL( pxNDWaitingNetworkBuffer, NULL ); } /** @@ -1672,7 +1705,7 @@ void test_prvProcessICMPMessage_IPv6_NeighborAdvertisement4( void ) * ipICMP_NEIGHBOR_ADVERTISEMENT_IPv6. * This verifies a case where a packet is handled as a new * incoming IP packet when a neighbour advertisement has been received, - * and 'pxARPWaitingNetworkBuffer' was waiting for this new address look-up. + * and 'pxNDWaitingNetworkBuffer' was waiting for this new address look-up. */ void test_prvProcessICMPMessage_IPv6_NeighborAdvertisement5( void ) { @@ -1681,12 +1714,12 @@ void test_prvProcessICMPMessage_IPv6_NeighborAdvertisement5( void ) ICMPHeader_IPv6_t * pxICMPHeader_IPv6 = ( ( ICMPHeader_IPv6_t * ) &( xICMPPacket.xICMPHeaderIPv6 ) ); NetworkEndPoint_t xEndPoint; eFrameProcessingResult_t eReturn; - NetworkBufferDescriptor_t xARPWaitingNetworkBuffer; + NetworkBufferDescriptor_t xNDWaitingNetworkBuffer; IPPacket_IPv6_t xIPPacket; IPHeader_IPv6_t * pxIPHeader = &( xIPPacket.xIPHeader ); - pxARPWaitingNetworkBuffer = &xARPWaitingNetworkBuffer; - pxARPWaitingNetworkBuffer->pucEthernetBuffer = ( uint8_t * ) &xIPPacket; + pxNDWaitingNetworkBuffer = &xNDWaitingNetworkBuffer; + pxNDWaitingNetworkBuffer->pucEthernetBuffer = ( uint8_t * ) &xIPPacket; xEndPoint.bits.bIPv6 = pdTRUE_UNSIGNED; pxNetworkBuffer->pucEthernetBuffer = ( uint8_t * ) &xICMPPacket; @@ -1698,12 +1731,12 @@ void test_prvProcessICMPMessage_IPv6_NeighborAdvertisement5( void ) uxIPHeaderSizePacket_IgnoreAndReturn( ipSIZE_OF_IPv6_HEADER ); xSendEventStructToIPTask_IgnoreAndReturn( pdPASS ); - vIPSetARPResolutionTimerEnableState_ExpectAnyArgs(); + vIPSetNDResolutionTimerEnableState_ExpectAnyArgs(); eReturn = prvProcessICMPMessage_IPv6( pxNetworkBuffer ); TEST_ASSERT_EQUAL( eReturn, eReleaseBuffer ); - TEST_ASSERT_EQUAL( pxARPWaitingNetworkBuffer, NULL ); + TEST_ASSERT_EQUAL( pxNDWaitingNetworkBuffer, NULL ); } /** @@ -1887,10 +1920,15 @@ void test_FreeRTOS_CreateIPv6Address_Pass2( void ) TEST_ASSERT_EQUAL( xReturn, pdPASS ); } -void test_FreeRTOS_CreateIPv6Address_Pass3( void ) /*CHECK if needed */ +/** + * @brief Create an IPv6 address, based on a prefix. + * with the bits after the prefix having random value + * and uxPrefixLength is 128 bites. + */ +void test_FreeRTOS_CreateIPv6Address_Pass3( void ) { IPv6_Address_t xIPAddress, xPrefix; - size_t uxPrefixLength = 127; + size_t uxPrefixLength = 128; BaseType_t xDoRandom = pdTRUE, xReturn, xIndex; for( xIndex = 0; xIndex < 4; xIndex++ ) @@ -1944,3 +1982,172 @@ void test_pcMessageType_All( void ) xType = ipICMP_NEIGHBOR_ADVERTISEMENT_IPv6 + 1; ( void ) pcMessageType( xType ); } + +/** + * @brief heck if the network buffer requires resolution for different protocols. + */ +void test_xCheckIPv6RequiresResolution_Protocols( void ) +{ + struct xNetworkEndPoint xEndPoint = { 0 }; + NetworkBufferDescriptor_t xNetworkBuffer, * pxNetworkBuffer; + uint8_t ucEthernetBuffer[ ipconfigNETWORK_MTU ]; + BaseType_t xResult; + + pxNetworkBuffer = &xNetworkBuffer; + pxNetworkBuffer->pucEthernetBuffer = ucEthernetBuffer; + IPPacket_IPv6_t * pxIPPacket_V6 = ( ( IPPacket_IPv6_t * ) pxNetworkBuffer->pucEthernetBuffer ); + IPHeader_IPv6_t * pxIPHeader_V6 = &( pxIPPacket_V6->xIPHeader ); + IPv6_Address_t * pxIPAddress = &( pxIPHeader_V6->xSourceAddress ); + pxIPPacket_V6->xEthernetHeader.usFrameType = ipIPv6_FRAME_TYPE; + pxIPHeader_V6->ucNextHeader = 1; + + xResult = xCheckRequiresNDResolution( pxNetworkBuffer ); + + TEST_ASSERT_EQUAL( pdFALSE, xResult ); + + pxIPHeader_V6->ucNextHeader = ipPROTOCOL_UDP; + + xIPv6_GetIPType_ExpectAnyArgsAndReturn( eIPv6_SiteLocal ); + xResult = xCheckRequiresNDResolution( pxNetworkBuffer ); + + TEST_ASSERT_EQUAL( pdFALSE, xResult ); + + pxIPHeader_V6->ucNextHeader = ipPROTOCOL_TCP; + + xIPv6_GetIPType_ExpectAnyArgsAndReturn( eIPv6_SiteLocal ); + xResult = xCheckRequiresNDResolution( pxNetworkBuffer ); + + TEST_ASSERT_EQUAL( pdFALSE, xResult ); +} + +/** + * @brief Check if the network buffer requires resolution for addresses + * not on the local network. + */ +void test_xCheckRequiresNDResolution_TCPNotOnLocalNetwork( void ) +{ + struct xNetworkEndPoint xEndPoint = { 0 }; + NetworkBufferDescriptor_t xNetworkBuffer, * pxNetworkBuffer; + uint8_t ucEthernetBuffer[ ipconfigNETWORK_MTU ]; + BaseType_t xResult; + + pxNetworkBuffer = &xNetworkBuffer; + pxNetworkBuffer->pxEndPoint = &xEndPoint; + pxNetworkBuffer->pucEthernetBuffer = ucEthernetBuffer; + IPPacket_IPv6_t * pxIPPacket_V6 = ( ( IPPacket_IPv6_t * ) pxNetworkBuffer->pucEthernetBuffer ); + IPHeader_IPv6_t * pxIPHeader_V6 = &( pxIPPacket_V6->xIPHeader ); + IPv6_Address_t * pxIPAddress = &( pxIPHeader_V6->xSourceAddress ); + pxIPPacket_V6->xEthernetHeader.usFrameType = ipIPv6_FRAME_TYPE; + pxIPHeader_V6->ucNextHeader = ipPROTOCOL_TCP; + + xIPv6_GetIPType_ExpectAnyArgsAndReturn( eIPv6_SiteLocal ); + xResult = xCheckRequiresNDResolution( pxNetworkBuffer ); + + TEST_ASSERT_EQUAL( pdFALSE, xResult ); +} + +/** + * @brief Cache hit occurs with an IP address in the multicast case. + */ +void test_xCheckRequiresNDResolution_Hit( void ) +{ + struct xNetworkEndPoint xEndPoint = { 0 }; + NetworkBufferDescriptor_t xNetworkBuffer, * pxNetworkBuffer; + uint8_t ucEthernetBuffer[ ipconfigNETWORK_MTU ]; + BaseType_t xResult; + + ( void ) memset( xNDCache, 0, sizeof( xNDCache ) ); + + pxNetworkBuffer = &xNetworkBuffer; + pxNetworkBuffer->pxEndPoint = &xEndPoint; + pxNetworkBuffer->pucEthernetBuffer = ucEthernetBuffer; + IPPacket_IPv6_t * pxIPPacket_V6 = ( ( IPPacket_IPv6_t * ) pxNetworkBuffer->pucEthernetBuffer ); + IPHeader_IPv6_t * pxIPHeader_V6 = &( pxIPPacket_V6->xIPHeader ); + IPv6_Address_t * pxIPAddress = &( pxIPHeader_V6->xSourceAddress ); + pxIPPacket_V6->xEthernetHeader.usFrameType = ipIPv6_FRAME_TYPE; + pxIPHeader_V6->ucNextHeader = ipPROTOCOL_TCP; + + xIPv6_GetIPType_ExpectAnyArgsAndReturn( eIPv6_LinkLocal ); + xIsIPv6AllowedMulticast_ExpectAndReturn( pxIPAddress, pdTRUE ); + vSetMultiCastIPv6MacAddress_Expect( pxIPAddress, NULL ); + vSetMultiCastIPv6MacAddress_IgnoreArg_pxMACAddress(); + FreeRTOS_FirstEndPoint_ExpectAnyArgsAndReturn( NULL ); + xResult = xCheckRequiresNDResolution( pxNetworkBuffer ); + + TEST_ASSERT_EQUAL( pdFALSE, xResult ); +} + +/** + * @brief ND cache miss scenarios. + */ +void test_xCheckRequiresNDResolution_Miss( void ) +{ + struct xNetworkEndPoint xEndPoint, * pxEndPoint = &xEndPoint; + NetworkBufferDescriptor_t xNetworkBuffer, * pxNetworkBuffer; + uint8_t ucEthernetBuffer[ ipconfigNETWORK_MTU ]; + BaseType_t xResult; + + ( void ) memset( xNDCache, 0, sizeof( xNDCache ) ); + + pxNetworkBuffer = &xNetworkBuffer; + pxNetworkBuffer->pxEndPoint = &xEndPoint; + pxNetworkBuffer->pucEthernetBuffer = ucEthernetBuffer; + IPPacket_IPv6_t * pxIPPacket_V6 = ( ( IPPacket_IPv6_t * ) pxNetworkBuffer->pucEthernetBuffer ); + IPHeader_IPv6_t * pxIPHeader_V6 = &( pxIPPacket_V6->xIPHeader ); + IPv6_Address_t * pxIPAddress = &( pxIPHeader_V6->xSourceAddress ); + pxIPPacket_V6->xEthernetHeader.usFrameType = ipIPv6_FRAME_TYPE; + pxIPHeader_V6->ucNextHeader = ipPROTOCOL_TCP; + + xIPv6_GetIPType_ExpectAnyArgsAndReturn( eIPv6_LinkLocal ); + xIsIPv6AllowedMulticast_ExpectAndReturn( pxIPAddress, pdFALSE ); + xIPv6_GetIPType_ExpectAnyArgsAndReturn( eIPv6_LinkLocal ); + FreeRTOS_FindEndPointOnIP_IPv6_ExpectAnyArgsAndReturn( pxEndPoint ); + pxGetNetworkBufferWithDescriptor_ExpectAnyArgsAndReturn( pxNetworkBuffer ); + vReleaseNetworkBufferAndDescriptor_Expect( pxNetworkBuffer ); + + xResult = xCheckRequiresNDResolution( pxNetworkBuffer ); + + TEST_ASSERT_EQUAL( pdTRUE, xResult ); + + xIPv6_GetIPType_ExpectAnyArgsAndReturn( eIPv6_LinkLocal ); + xIsIPv6AllowedMulticast_ExpectAndReturn( pxIPAddress, pdFALSE ); + xIPv6_GetIPType_ExpectAnyArgsAndReturn( eIPv6_LinkLocal ); + FreeRTOS_FindEndPointOnIP_IPv6_ExpectAnyArgsAndReturn( pxEndPoint ); + pxGetNetworkBufferWithDescriptor_ExpectAnyArgsAndReturn( NULL ); + + xResult = xCheckRequiresNDResolution( pxNetworkBuffer ); + + TEST_ASSERT_EQUAL( pdTRUE, xResult ); +} + +/** + * @brief Trigger assertion when Ethernet frame type is not IPv6 while calling xCheckRequiresNDResolution. + */ +void test_xCheckRequiresNDResolution_AssertInvalidFrameType( void ) +{ + struct xNetworkEndPoint xEndPoint = { 0 }; + NetworkBufferDescriptor_t xNetworkBuffer, * pxNetworkBuffer; + uint8_t ucEthernetBuffer[ ipconfigNETWORK_MTU ]; + BaseType_t xResult; + + ( void ) memset( xNDCache, 0, sizeof( xNDCache ) ); + + pxNetworkBuffer = &xNetworkBuffer; + pxNetworkBuffer->pxEndPoint = &xEndPoint; + pxNetworkBuffer->pucEthernetBuffer = ucEthernetBuffer; + IPPacket_t * pxIPPacket = ( ( IPPacket_t * ) pxNetworkBuffer->pucEthernetBuffer ); + IPHeader_t * pxIPHeader = &( pxIPPacket->xIPHeader ); + pxIPPacket->xEthernetHeader.usFrameType = ipIPv4_FRAME_TYPE; + + catch_assert( xCheckRequiresNDResolution( pxNetworkBuffer ) ); +} + +/** + * @brief Toggle vNDSendUnsolicited. + */ +void test_vNDSendUnsolicited( void ) +{ + xSendEventToIPTask_ExpectAndReturn( eNDTimerEvent, 0 ); + + vNDSendUnsolicited(); +} diff --git a/test/unit-test/FreeRTOS_ND/ut.cmake b/test/unit-test/FreeRTOS_ND/ut.cmake index 9e113d1580..09fbf7bc21 100644 --- a/test/unit-test/FreeRTOS_ND/ut.cmake +++ b/test/unit-test/FreeRTOS_ND/ut.cmake @@ -14,7 +14,6 @@ list(APPEND mock_list "${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include/list.h" "${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include/queue.h" "${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include/event_groups.h" - "${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_ARP.h" "${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IP.h" "${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IP_Private.h" "${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IPv6.h" @@ -113,4 +112,4 @@ create_test(${utest_name} "${utest_link_list}" "${utest_dep_list}" "${test_include_directories}" - ) \ No newline at end of file + ) diff --git a/test/unit-test/FreeRTOS_RA/FreeRTOS_RA_stubs.c b/test/unit-test/FreeRTOS_RA/FreeRTOS_RA_stubs.c index 63b09a9e4c..e88ec77474 100644 --- a/test/unit-test/FreeRTOS_RA/FreeRTOS_RA_stubs.c +++ b/test/unit-test/FreeRTOS_RA/FreeRTOS_RA_stubs.c @@ -24,18 +24,18 @@ * * @note Look for ulIPAddress in the ND cache. If the IP address exists, copy the * associated MAC address into pxMACAddress, refresh the ND cache entry's - * age, and return eARPCacheHit. If the IP address does not exist in the ND - * cache return eARPCacheMiss. If the packet cannot be sent for any reason + * age, and return eResolutionCacheHit. If the IP address does not exist in the ND + * cache return eResolutionCacheMiss. If the packet cannot be sent for any reason * (maybe DHCP is still in process, or the addressing needs a gateway but there - * isn't a gateway defined) then return eCantSendPacket. + * isn't a gateway defined) then return eResolutionFailed. */ -eARPLookupResult_t eNDGetCacheEntry( IPv6_Address_t * pxIPAddress, - MACAddress_t * const pxMACAddress, - struct xNetworkEndPoint ** ppxEndPoint ) +eResolutionLookupResult_t eNDGetCacheEntry( IPv6_Address_t * pxIPAddress, + MACAddress_t * const pxMACAddress, + struct xNetworkEndPoint ** ppxEndPoint ) { memset( pxMACAddress, 0, sizeof( MACAddress_t ) ); - return eARPCacheHit; + return eResolutionCacheHit; } /** diff --git a/test/unit-test/FreeRTOS_Routing/FreeRTOS_Routing_utest.c b/test/unit-test/FreeRTOS_Routing/FreeRTOS_Routing_utest.c index 48958d45b6..0322c26790 100644 --- a/test/unit-test/FreeRTOS_Routing/FreeRTOS_Routing_utest.c +++ b/test/unit-test/FreeRTOS_Routing/FreeRTOS_Routing_utest.c @@ -43,8 +43,11 @@ #include "mock_event_groups.h" #include "mock_FreeRTOS_IP.h" +#include "mock_FreeRTOS_IP_Private.h" #include "mock_FreeRTOS_IPv6.h" #include "mock_FreeRTOS_Sockets.h" +#include "mock_FreeRTOS_ARP.h" +#include "mock_FreeRTOS_ND.h" #include "FreeRTOS_Routing.h" @@ -3671,6 +3674,50 @@ void test_FreeRTOS_MatchingEndpoint_MatchCustomFrameType() TEST_ASSERT_EQUAL( NULL, pxEndPoint ); } +void test_xCheckRequiresResolution( void ) +{ + struct xNetworkEndPoint xEndPoint = { 0 }; + NetworkBufferDescriptor_t xNetworkBuffer, * pxNetworkBuffer; + uint8_t ucEthernetBuffer[ ipconfigNETWORK_MTU ]; + BaseType_t xResult; + NetworkInterface_t xInterface; + + pxNetworkBuffer = &xNetworkBuffer; + pxNetworkBuffer->pucEthernetBuffer = ucEthernetBuffer; + + IPPacket_t * pxIPPacket = ( ( IPPacket_t * ) pxNetworkBuffer->pucEthernetBuffer ); + IPHeader_t * pxIPHeader = &( pxIPPacket->xIPHeader ); + + xEndPoint.ipv4_settings.ulIPAddress = 0xABCD1234; + + xEndPoint.ipv4_settings.ulNetMask = 0xFFFFFF00; + xNetworkBuffer.pxEndPoint = &xEndPoint; + + /* Make sure there is no match. */ + pxIPHeader->ulSourceIPAddress = ~( xEndPoint.ipv4_settings.ulIPAddress & xEndPoint.ipv4_settings.ulNetMask ); + + uxIPHeaderSizePacket_IgnoreAndReturn( ipSIZE_OF_IPv4_HEADER ); + xCheckRequiresARPResolution_IgnoreAndReturn( pdFALSE ); + + xResult = xCheckRequiresResolution( pxNetworkBuffer ); + + TEST_ASSERT_EQUAL( pdFALSE, xResult ); + + uxIPHeaderSizePacket_IgnoreAndReturn( ipSIZE_OF_IPv6_HEADER ); + xCheckRequiresNDResolution_IgnoreAndReturn( pdFALSE ); + + xResult = xCheckRequiresResolution( pxNetworkBuffer ); + + TEST_ASSERT_EQUAL( pdFALSE, xResult ); + + uxIPHeaderSizePacket_IgnoreAndReturn( 1 ); + xCheckRequiresNDResolution_IgnoreAndReturn( pdFALSE ); + + xResult = xCheckRequiresResolution( pxNetworkBuffer ); + + TEST_ASSERT_EQUAL( pdFALSE, xResult ); +} + /** * @brief Test to check if FreeRTOS_InterfaceEPInSameSubnet_IPv6 returns a matching endpoint * on the interface given to FreeRTOS_InterfaceEPInSameSubnet_IPv6 thats on the same subnet as of diff --git a/test/unit-test/FreeRTOS_Routing/ut.cmake b/test/unit-test/FreeRTOS_Routing/ut.cmake index 2ceb2a26b5..4b3d08ce03 100644 --- a/test/unit-test/FreeRTOS_Routing/ut.cmake +++ b/test/unit-test/FreeRTOS_Routing/ut.cmake @@ -19,6 +19,7 @@ list(APPEND mock_list "${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_Sockets.h" "${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IP_Private.h" "${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_ARP.h" + "${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_ND.h" "${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_UDP_IP.h" "${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_DHCP.h" "${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_DNS.h" diff --git a/test/unit-test/FreeRTOS_Routing_ConfigCompatibleWithSingle/ut.cmake b/test/unit-test/FreeRTOS_Routing_ConfigCompatibleWithSingle/ut.cmake index 1c1c75ee56..2ca840d296 100644 --- a/test/unit-test/FreeRTOS_Routing_ConfigCompatibleWithSingle/ut.cmake +++ b/test/unit-test/FreeRTOS_Routing_ConfigCompatibleWithSingle/ut.cmake @@ -20,6 +20,7 @@ list(APPEND mock_list "${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_Sockets.h" "${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IP_Private.h" "${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_ARP.h" + "${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_ND.h" "${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_UDP_IP.h" "${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_DHCP.h" "${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_DNS.h" diff --git a/test/unit-test/FreeRTOS_TCP_Transmission/FreeRTOS_TCP_Transmission_utest.c b/test/unit-test/FreeRTOS_TCP_Transmission/FreeRTOS_TCP_Transmission_utest.c index 24ceff7369..bdfae76934 100644 --- a/test/unit-test/FreeRTOS_TCP_Transmission/FreeRTOS_TCP_Transmission_utest.c +++ b/test/unit-test/FreeRTOS_TCP_Transmission/FreeRTOS_TCP_Transmission_utest.c @@ -104,7 +104,7 @@ void test_prvTCPMakeSurePrepared_NotPrepared( void ) pxSocket->u.xTCP.bits.bConnPrepared = pdFALSE; - eARPGetCacheEntry_ExpectAnyArgsAndReturn( eARPCacheHit ); + eARPGetCacheEntry_ExpectAnyArgsAndReturn( eResolutionCacheHit ); ulApplicationGetNextSequenceNumber_ExpectAnyArgsAndReturn( 1000 ); prvSocketSetMSS_ExpectAnyArgs(); xTCPWindowCreate_ExpectAnyArgsAndReturn( pdPASS ); @@ -128,7 +128,7 @@ void test_prvTCPMakeSurePrepared_Not_Ready_Error_Connect( void ) pxSocket->u.xTCP.bits.bConnPrepared = pdFALSE; - eARPGetCacheEntry_ExpectAnyArgsAndReturn( eARPCacheMiss ); + eARPGetCacheEntry_ExpectAnyArgsAndReturn( eResolutionCacheMiss ); FreeRTOS_OutputARPRequest_ExpectAnyArgs(); xResult = prvTCPMakeSurePrepared( pxSocket ); @@ -183,7 +183,7 @@ void test_prvTCPSendPacket_Syn_State( void ) FreeRTOS_min_uint32_ExpectAnyArgsAndReturn( 1000 ); usGenerateChecksum_ExpectAnyArgsAndReturn( 0x1234 ); usGenerateProtocolChecksum_ExpectAnyArgsAndReturn( 0x2345 ); - eARPGetCacheEntry_ExpectAnyArgsAndReturn( eARPCacheHit ); + eARPGetCacheEntry_ExpectAnyArgsAndReturn( eResolutionCacheHit ); eARPGetCacheEntry_ReturnThruPtr_ppxEndPoint( &pxEndPoint ); BytesSent = prvTCPSendPacket( pxSocket ); @@ -222,7 +222,7 @@ void test_prvTCPSendPacket_Syn_State_NULL_Endpoint( void ) FreeRTOS_min_uint32_ExpectAnyArgsAndReturn( 1000 ); usGenerateChecksum_ExpectAnyArgsAndReturn( 0x1234 ); usGenerateProtocolChecksum_ExpectAnyArgsAndReturn( 0x2345 ); - eARPGetCacheEntry_ExpectAnyArgsAndReturn( eARPCacheHit ); + eARPGetCacheEntry_ExpectAnyArgsAndReturn( eResolutionCacheHit ); eARPGetCacheEntry_ReturnThruPtr_ppxEndPoint( &pxEndPoint ); BytesSent = prvTCPSendPacket( pxSocket ); @@ -270,7 +270,7 @@ void test_prvTCPSendPacket_Syn_State_Not_Prepared( void ) pxSocket->u.xTCP.ucRepCount = 1; pxSocket->u.xTCP.bits.bConnPrepared = pdFALSE; - eARPGetCacheEntry_ExpectAnyArgsAndReturn( eARPCacheMiss ); + eARPGetCacheEntry_ExpectAnyArgsAndReturn( eResolutionCacheMiss ); FreeRTOS_OutputARPRequest_ExpectAnyArgs(); BytesSent = prvTCPSendPacket( pxSocket ); @@ -361,7 +361,7 @@ void test_prvTCPSendPacket_Other_State_Something_To_Send( void ) FreeRTOS_min_uint32_ExpectAnyArgsAndReturn( 1000 ); usGenerateChecksum_ExpectAnyArgsAndReturn( 0x1234 ); usGenerateProtocolChecksum_ExpectAnyArgsAndReturn( 0x2345 ); - eARPGetCacheEntry_ExpectAnyArgsAndReturn( eARPCacheHit ); + eARPGetCacheEntry_ExpectAnyArgsAndReturn( eResolutionCacheHit ); eARPGetCacheEntry_ReturnThruPtr_ppxEndPoint( &pxEndPoint ); for( RepeatCount = 1; RepeatCount < SEND_REPEATED_COUNT; RepeatCount++ ) @@ -372,7 +372,7 @@ void test_prvTCPSendPacket_Other_State_Something_To_Send( void ) FreeRTOS_min_uint32_ExpectAnyArgsAndReturn( 1000 ); usGenerateChecksum_ExpectAnyArgsAndReturn( 0x1234 ); usGenerateProtocolChecksum_ExpectAnyArgsAndReturn( 0x2345 ); - eARPGetCacheEntry_ExpectAnyArgsAndReturn( eARPCacheHit ); + eARPGetCacheEntry_ExpectAnyArgsAndReturn( eResolutionCacheHit ); eARPGetCacheEntry_ReturnThruPtr_ppxEndPoint( &pxEndPoint ); } @@ -458,7 +458,7 @@ void test_prvTCPSendRepeated_Repeat_8( void ) FreeRTOS_min_uint32_ExpectAnyArgsAndReturn( 1000 ); usGenerateChecksum_ExpectAnyArgsAndReturn( 0x1234 ); usGenerateProtocolChecksum_ExpectAnyArgsAndReturn( 0x2345 ); - eARPGetCacheEntry_ExpectAnyArgsAndReturn( eARPCacheHit ); + eARPGetCacheEntry_ExpectAnyArgsAndReturn( eResolutionCacheHit ); eARPGetCacheEntry_ReturnThruPtr_ppxEndPoint( &pxEndPoint ); } @@ -517,7 +517,7 @@ void test_prvTCPReturnPacket_Null_Buffer_Null_Rx_Stream_KL( void ) FreeRTOS_min_uint32_ExpectAnyArgsAndReturn( 500 ); usGenerateChecksum_ExpectAnyArgsAndReturn( 0x1111 ); usGenerateProtocolChecksum_ExpectAnyArgsAndReturn( 0x2222 ); - eARPGetCacheEntry_ExpectAnyArgsAndReturn( eARPCacheHit ); + eARPGetCacheEntry_ExpectAnyArgsAndReturn( eResolutionCacheHit ); eARPGetCacheEntry_ReturnThruPtr_ppxEndPoint( &pxEndPoint ); prvTCPReturnPacket( pxSocket, pxNetworkBuffer, 40, pdFALSE ); @@ -649,7 +649,7 @@ void test_prvTCPReturnPacket_Null_Socket( void ) uxIPHeaderSizePacket_IgnoreAndReturn( ipSIZE_OF_IPv4_HEADER ); usGenerateChecksum_ExpectAnyArgsAndReturn( 0x1111 ); usGenerateProtocolChecksum_ExpectAnyArgsAndReturn( 0x2222 ); - eARPGetCacheEntry_ExpectAnyArgsAndReturn( eARPCacheHit ); + eARPGetCacheEntry_ExpectAnyArgsAndReturn( eResolutionCacheHit ); eARPGetCacheEntry_ReturnThruPtr_ppxEndPoint( &pxEndPoint ); prvTCPReturnPacket( NULL, pxNetworkBuffer, 40, pdFALSE ); @@ -690,7 +690,7 @@ void test_prvTCPReturnPacket_Assert_Interface_NULL( void ) uxIPHeaderSizePacket_IgnoreAndReturn( ipSIZE_OF_IPv4_HEADER ); usGenerateChecksum_ExpectAnyArgsAndReturn( 0x1111 ); usGenerateProtocolChecksum_ExpectAnyArgsAndReturn( 0x2222 ); - eARPGetCacheEntry_ExpectAnyArgsAndReturn( eARPCacheHit ); + eARPGetCacheEntry_ExpectAnyArgsAndReturn( eResolutionCacheHit ); eARPGetCacheEntry_ReturnThruPtr_ppxEndPoint( &pxEndPoint ); @@ -729,7 +729,7 @@ void test_prvTCPReturnPacket_Assert_InterfaceOutput_NULL( void ) uxIPHeaderSizePacket_IgnoreAndReturn( ipSIZE_OF_IPv4_HEADER ); usGenerateChecksum_ExpectAnyArgsAndReturn( 0x1111 ); usGenerateProtocolChecksum_ExpectAnyArgsAndReturn( 0x2222 ); - eARPGetCacheEntry_ExpectAnyArgsAndReturn( eARPCacheHit ); + eARPGetCacheEntry_ExpectAnyArgsAndReturn( eResolutionCacheHit ); eARPGetCacheEntry_ReturnThruPtr_ppxEndPoint( &pxEndPoint ); catch_assert( prvTCPReturnPacket( NULL, pxNetworkBuffer, 40, pdFALSE ) ); @@ -769,7 +769,7 @@ void test_prvTCPReturnPacket_Null_Socket_Release_True( void ) uxIPHeaderSizePacket_IgnoreAndReturn( ipSIZE_OF_IPv4_HEADER ); usGenerateChecksum_ExpectAnyArgsAndReturn( 0x1111 ); usGenerateProtocolChecksum_ExpectAnyArgsAndReturn( 0x2222 ); - eARPGetCacheEntry_ExpectAnyArgsAndReturn( eARPCacheHit ); + eARPGetCacheEntry_ExpectAnyArgsAndReturn( eResolutionCacheHit ); eARPGetCacheEntry_ReturnThruPtr_ppxEndPoint( &pxEndPoint ); prvTCPReturnPacket( NULL, pxNetworkBuffer, 40, pdTRUE ); @@ -820,7 +820,7 @@ void test_prvTCPReturnPacket_No_KL( void ) FreeRTOS_min_uint32_ExpectAnyArgsAndReturn( 500 ); usGenerateChecksum_ExpectAnyArgsAndReturn( 0x1111 ); usGenerateProtocolChecksum_ExpectAnyArgsAndReturn( 0x2222 ); - eARPGetCacheEntry_ExpectAnyArgsAndReturn( eARPCacheHit ); + eARPGetCacheEntry_ExpectAnyArgsAndReturn( eResolutionCacheHit ); eARPGetCacheEntry_ReturnThruPtr_ppxEndPoint( &pxEndPoint ); prvTCPReturnPacket( pxSocket, pxNetworkBuffer, 40, pdFALSE ); @@ -875,7 +875,7 @@ void test_prvTCPReturnPacket_No_KL_LocalIP( void ) FreeRTOS_min_uint32_ExpectAnyArgsAndReturn( 500 ); usGenerateChecksum_ExpectAnyArgsAndReturn( 0x1111 ); usGenerateProtocolChecksum_ExpectAnyArgsAndReturn( 0x2222 ); - eARPGetCacheEntry_ExpectAnyArgsAndReturn( eARPCacheHit ); + eARPGetCacheEntry_ExpectAnyArgsAndReturn( eResolutionCacheHit ); eARPGetCacheEntry_ReturnThruPtr_ppxEndPoint( &pxEndPoint ); prvTCPReturnPacket( pxSocket, pxNetworkBuffer, 40, pdTRUE ); @@ -936,7 +936,7 @@ void test_prvTCPReturnPacket_No_KL_LocalIP_GT_Eth_Packet_Length( void ) FreeRTOS_min_uint32_ExpectAnyArgsAndReturn( 500 ); usGenerateChecksum_ExpectAnyArgsAndReturn( 0x1111 ); usGenerateProtocolChecksum_ExpectAnyArgsAndReturn( 0x2222 ); - eARPGetCacheEntry_ExpectAnyArgsAndReturn( eARPCacheHit ); + eARPGetCacheEntry_ExpectAnyArgsAndReturn( eResolutionCacheHit ); eARPGetCacheEntry_ReturnThruPtr_ppxEndPoint( &pxEndPoint ); prvTCPReturnPacket( pxSocket, pxNetworkBuffer, 1000, pdTRUE ); @@ -994,7 +994,7 @@ void test_prvTCPReturnPacket_No_KL_LocalIP_ARP_Not_Hit( void ) FreeRTOS_min_uint32_ExpectAnyArgsAndReturn( 500 ); usGenerateChecksum_ExpectAnyArgsAndReturn( 0x1111 ); usGenerateProtocolChecksum_ExpectAnyArgsAndReturn( 0x2222 ); - eARPGetCacheEntry_ExpectAnyArgsAndReturn( eARPCacheMiss ); + eARPGetCacheEntry_ExpectAnyArgsAndReturn( eResolutionCacheMiss ); prvTCPReturnPacket( pxSocket, pxNetworkBuffer, 40, pdTRUE ); TEST_ASSERT_EQUAL( 1, NetworkInterfaceOutputFunction_Stub_Called ); @@ -1047,7 +1047,7 @@ void test_prvTCPReturnPacket_No_KL_Fin_Suppress_Rx_Stop( void ) FreeRTOS_min_uint32_ExpectAnyArgsAndReturn( 500 ); usGenerateChecksum_ExpectAnyArgsAndReturn( 0x1111 ); usGenerateProtocolChecksum_ExpectAnyArgsAndReturn( 0x2222 ); - eARPGetCacheEntry_ExpectAnyArgsAndReturn( eARPCacheHit ); + eARPGetCacheEntry_ExpectAnyArgsAndReturn( eResolutionCacheHit ); eARPGetCacheEntry_ReturnThruPtr_ppxEndPoint( &pxEndPoint ); prvTCPReturnPacket( pxSocket, pxNetworkBuffer, 40, pdFALSE ); @@ -1099,7 +1099,7 @@ void test_prvTCPReturnPacket_No_KL_Fin_Not_Suppress_Low_Water( void ) FreeRTOS_min_uint32_ExpectAnyArgsAndReturn( 500 ); usGenerateChecksum_ExpectAnyArgsAndReturn( 0x1111 ); usGenerateProtocolChecksum_ExpectAnyArgsAndReturn( 0x2222 ); - eARPGetCacheEntry_ExpectAnyArgsAndReturn( eARPCacheHit ); + eARPGetCacheEntry_ExpectAnyArgsAndReturn( eResolutionCacheHit ); eARPGetCacheEntry_ReturnThruPtr_ppxEndPoint( &pxEndPoint ); prvTCPReturnPacket( pxSocket, pxNetworkBuffer, 40, pdFALSE ); @@ -1151,7 +1151,7 @@ void test_prvTCPReturnPacket_No_KL_Fin_Not_Suppress_Big_Win( void ) FreeRTOS_min_uint32_ExpectAnyArgsAndReturn( 0x10000 ); usGenerateChecksum_ExpectAnyArgsAndReturn( 0x1111 ); usGenerateProtocolChecksum_ExpectAnyArgsAndReturn( 0x2222 ); - eARPGetCacheEntry_ExpectAnyArgsAndReturn( eARPCacheHit ); + eARPGetCacheEntry_ExpectAnyArgsAndReturn( eResolutionCacheHit ); eARPGetCacheEntry_ReturnThruPtr_ppxEndPoint( &pxEndPoint ); prvTCPReturnPacket( pxSocket, pxNetworkBuffer, 40, pdFALSE ); @@ -1190,7 +1190,7 @@ void test_prvTCPPrepareConnect_Ready( void ) pxSocket->u.xTCP.bits.bConnPrepared = pdFALSE; pxSocket->bits.bIsIPv6 = pdFALSE; - eARPGetCacheEntry_ExpectAnyArgsAndReturn( eARPCacheHit ); + eARPGetCacheEntry_ExpectAnyArgsAndReturn( eResolutionCacheHit ); ulApplicationGetNextSequenceNumber_ExpectAnyArgsAndReturn( 0x11111111 ); prvSocketSetMSS_ExpectAnyArgs(); xTCPWindowCreate_ExpectAnyArgsAndReturn( pdPASS ); @@ -1212,7 +1212,7 @@ void test_prvTCPPrepareConnect_Ready_TCPWindowCreateFail( void ) pxSocket->u.xTCP.bits.bConnPrepared = pdFALSE; pxSocket->bits.bIsIPv6 = pdFALSE; - eARPGetCacheEntry_ExpectAnyArgsAndReturn( eARPCacheHit ); + eARPGetCacheEntry_ExpectAnyArgsAndReturn( eResolutionCacheHit ); ulApplicationGetNextSequenceNumber_ExpectAnyArgsAndReturn( 0x11111111 ); prvSocketSetMSS_ExpectAnyArgs(); xTCPWindowCreate_ExpectAnyArgsAndReturn( pdFAIL ); @@ -1231,7 +1231,7 @@ void test_prvTCPPrepareConnect_No_Arp_Entry( void ) pxSocket->u.xTCP.ucRepCount = 0; pxSocket->u.xTCP.bits.bConnPrepared = pdFALSE; - eARPGetCacheEntry_ExpectAnyArgsAndReturn( eARPCacheMiss ); + eARPGetCacheEntry_ExpectAnyArgsAndReturn( eResolutionCacheMiss ); FreeRTOS_OutputARPRequest_ExpectAnyArgs(); Return = prvTCPPrepareConnect( pxSocket ); @@ -1250,7 +1250,7 @@ void test_prvTCPPrepareConnect_Zero_SequenceNum( void ) pxSocket->u.xTCP.ucRepCount = 0; pxSocket->u.xTCP.bits.bConnPrepared = pdFALSE; - eARPGetCacheEntry_ExpectAnyArgsAndReturn( eARPCacheHit ); + eARPGetCacheEntry_ExpectAnyArgsAndReturn( eResolutionCacheHit ); ulApplicationGetNextSequenceNumber_ExpectAnyArgsAndReturn( 0 ); Return = prvTCPPrepareConnect( pxSocket ); @@ -2186,7 +2186,7 @@ void test_prvSendData_AckMsg_Not_Null_Small_Length( void ) FreeRTOS_min_uint32_ExpectAnyArgsAndReturn( 500 ); usGenerateChecksum_ExpectAnyArgsAndReturn( 0x1111 ); usGenerateProtocolChecksum_ExpectAnyArgsAndReturn( 0x2222 ); - eARPGetCacheEntry_ExpectAnyArgsAndReturn( eARPCacheHit ); + eARPGetCacheEntry_ExpectAnyArgsAndReturn( eResolutionCacheHit ); eARPGetCacheEntry_ReturnThruPtr_ppxEndPoint( &pxEndPoint ); BytesSent = prvSendData( pxSocket, &pxNetworkBuffer, 100, 40 ); @@ -2242,7 +2242,7 @@ void test_prvSendData_AckMsg_Not_Null_Same_NetBuffer_Syn_State( void ) FreeRTOS_min_uint32_ExpectAnyArgsAndReturn( 500 ); usGenerateChecksum_ExpectAnyArgsAndReturn( 0x1111 ); usGenerateProtocolChecksum_ExpectAnyArgsAndReturn( 0x2222 ); - eARPGetCacheEntry_ExpectAnyArgsAndReturn( eARPCacheHit ); + eARPGetCacheEntry_ExpectAnyArgsAndReturn( eResolutionCacheHit ); eARPGetCacheEntry_ReturnThruPtr_ppxEndPoint( &pxEndPoint ); BytesSent = prvSendData( pxSocket, &pxNetworkBuffer, 100, 40 ); @@ -2298,7 +2298,7 @@ void test_prvSendData_AckMsg_Not_Null_Same_NetBuffer_Syn_State_Data_To_Send( voi FreeRTOS_min_uint32_ExpectAnyArgsAndReturn( 500 ); usGenerateChecksum_ExpectAnyArgsAndReturn( 0x1111 ); usGenerateProtocolChecksum_ExpectAnyArgsAndReturn( 0x2222 ); - eARPGetCacheEntry_ExpectAnyArgsAndReturn( eARPCacheHit ); + eARPGetCacheEntry_ExpectAnyArgsAndReturn( eResolutionCacheHit ); eARPGetCacheEntry_ReturnThruPtr_ppxEndPoint( &pxEndPoint ); BytesSent = prvSendData( pxSocket, &pxNetworkBuffer, 100, 50 ); @@ -2354,7 +2354,7 @@ void test_prvSendData_AckMsg_Null_Syn_State_Data_To_Send( void ) FreeRTOS_min_uint32_ExpectAnyArgsAndReturn( 500 ); usGenerateChecksum_ExpectAnyArgsAndReturn( 0x1111 ); usGenerateProtocolChecksum_ExpectAnyArgsAndReturn( 0x2222 ); - eARPGetCacheEntry_ExpectAnyArgsAndReturn( eARPCacheHit ); + eARPGetCacheEntry_ExpectAnyArgsAndReturn( eResolutionCacheHit ); eARPGetCacheEntry_ReturnThruPtr_ppxEndPoint( &pxEndPoint ); BytesSent = prvSendData( pxSocket, &pxNetworkBuffer, 100, 50 ); @@ -2411,7 +2411,7 @@ void test_prvSendData_AckMsg_Null_Syn_State_Data_To_Send_Log( void ) FreeRTOS_min_uint32_ExpectAnyArgsAndReturn( 500 ); usGenerateChecksum_ExpectAnyArgsAndReturn( 0x1111 ); usGenerateProtocolChecksum_ExpectAnyArgsAndReturn( 0x2222 ); - eARPGetCacheEntry_ExpectAnyArgsAndReturn( eARPCacheHit ); + eARPGetCacheEntry_ExpectAnyArgsAndReturn( eResolutionCacheHit ); eARPGetCacheEntry_ReturnThruPtr_ppxEndPoint( &pxEndPoint ); BytesSent = prvSendData( pxSocket, &pxNetworkBuffer, 100, 50 ); @@ -2468,7 +2468,7 @@ void test_prvSendData_AckMsg_Null_Syn_State_Data_To_Send_Rcv_Zero( void ) FreeRTOS_min_uint32_ExpectAnyArgsAndReturn( 500 ); usGenerateChecksum_ExpectAnyArgsAndReturn( 0x1111 ); usGenerateProtocolChecksum_ExpectAnyArgsAndReturn( 0x2222 ); - eARPGetCacheEntry_ExpectAnyArgsAndReturn( eARPCacheHit ); + eARPGetCacheEntry_ExpectAnyArgsAndReturn( eResolutionCacheHit ); eARPGetCacheEntry_ReturnThruPtr_ppxEndPoint( &pxEndPoint ); BytesSent = prvSendData( pxSocket, &pxNetworkBuffer, 0, 50 ); @@ -2534,7 +2534,7 @@ void test_prvTCPSendSpecialPacketHelper( void ) uxIPHeaderSizePacket_IgnoreAndReturn( ipSIZE_OF_IPv4_HEADER ); usGenerateChecksum_ExpectAnyArgsAndReturn( 0x1111 ); usGenerateProtocolChecksum_ExpectAnyArgsAndReturn( 0x2222 ); - eARPGetCacheEntry_ExpectAnyArgsAndReturn( eARPCacheHit ); + eARPGetCacheEntry_ExpectAnyArgsAndReturn( eResolutionCacheHit ); eARPGetCacheEntry_ReturnThruPtr_ppxEndPoint( &pxEndPoint ); Return = prvTCPSendSpecialPacketHelper( pxNetworkBuffer, tcpTCP_FLAG_ACK ); @@ -2571,7 +2571,7 @@ void test_prvTCPSendSpecialPacketHelper_flagSYN( void ) uxIPHeaderSizePacket_IgnoreAndReturn( ipSIZE_OF_IPv4_HEADER ); usGenerateChecksum_ExpectAnyArgsAndReturn( 0x1111 ); usGenerateProtocolChecksum_ExpectAnyArgsAndReturn( 0x2222 ); - eARPGetCacheEntry_ExpectAnyArgsAndReturn( eARPCacheHit ); + eARPGetCacheEntry_ExpectAnyArgsAndReturn( eResolutionCacheHit ); eARPGetCacheEntry_ReturnThruPtr_ppxEndPoint( &pxEndPoint ); Return = prvTCPSendSpecialPacketHelper( pxNetworkBuffer, tcpTCP_FLAG_ACK ); @@ -2607,7 +2607,7 @@ void test_prvTCPSendChallengeAck( void ) uxIPHeaderSizePacket_IgnoreAndReturn( ipSIZE_OF_IPv4_HEADER ); usGenerateChecksum_ExpectAnyArgsAndReturn( 0x1111 ); usGenerateProtocolChecksum_ExpectAnyArgsAndReturn( 0x2222 ); - eARPGetCacheEntry_ExpectAnyArgsAndReturn( eARPCacheHit ); + eARPGetCacheEntry_ExpectAnyArgsAndReturn( eResolutionCacheHit ); eARPGetCacheEntry_ReturnThruPtr_ppxEndPoint( &pxEndPoint ); Return = prvTCPSendChallengeAck( pxNetworkBuffer ); @@ -2642,7 +2642,7 @@ void test_prvTCPSendReset( void ) uxIPHeaderSizePacket_IgnoreAndReturn( ipSIZE_OF_IPv4_HEADER ); usGenerateChecksum_ExpectAnyArgsAndReturn( 0x1111 ); usGenerateProtocolChecksum_ExpectAnyArgsAndReturn( 0x2222 ); - eARPGetCacheEntry_ExpectAnyArgsAndReturn( eARPCacheHit ); + eARPGetCacheEntry_ExpectAnyArgsAndReturn( eResolutionCacheHit ); eARPGetCacheEntry_ReturnThruPtr_ppxEndPoint( &pxEndPoint ); Return = prvTCPSendReset( pxNetworkBuffer ); diff --git a/test/unit-test/FreeRTOS_TCP_Transmission_IPv6/FreeRTOS_TCP_Transmission_IPv6_utest.c b/test/unit-test/FreeRTOS_TCP_Transmission_IPv6/FreeRTOS_TCP_Transmission_IPv6_utest.c index 243e9a1451..31c4339ce7 100644 --- a/test/unit-test/FreeRTOS_TCP_Transmission_IPv6/FreeRTOS_TCP_Transmission_IPv6_utest.c +++ b/test/unit-test/FreeRTOS_TCP_Transmission_IPv6/FreeRTOS_TCP_Transmission_IPv6_utest.c @@ -135,7 +135,7 @@ void test_prvTCPReturnPacket_IPV6_SocketNULL( void ) xDescriptor.pxEndPoint->pxNetworkInterface->pfOutput = &NetworkInterfaceOutputFunction_Stub; usGenerateProtocolChecksum_ExpectAnyArgsAndReturn( ipCORRECT_CRC ); - eNDGetCacheEntry_ExpectAnyArgsAndReturn( eARPCacheHit ); + eNDGetCacheEntry_ExpectAnyArgsAndReturn( eResolutionCacheHit ); prvTCPReturnPacket_IPV6( pxSocket, &xDescriptor, ulLen, xReleaseAfterSend ); } @@ -217,7 +217,7 @@ void test_prvTCPReturnPacket_IPV6_Assert1( void ) xSocket.pxEndPoint->pxNetworkInterface = NULL; usGenerateProtocolChecksum_ExpectAnyArgsAndReturn( ipCORRECT_CRC ); - eNDGetCacheEntry_ExpectAnyArgsAndReturn( eARPCacheHit ); + eNDGetCacheEntry_ExpectAnyArgsAndReturn( eResolutionCacheHit ); catch_assert( prvTCPReturnPacket_IPV6( &xSocket, pxDescriptor, ulLen, xReleaseAfterSend ) ); } @@ -253,7 +253,7 @@ void test_prvTCPReturnPacket_IPV6_Assert2( void ) pxIPHeader = &pxTCPPacket->xIPHeader; usGenerateProtocolChecksum_ExpectAnyArgsAndReturn( ipCORRECT_CRC ); - eNDGetCacheEntry_ExpectAnyArgsAndReturn( eARPCacheMiss ); + eNDGetCacheEntry_ExpectAnyArgsAndReturn( eResolutionCacheMiss ); catch_assert( prvTCPReturnPacket_IPV6( &xSocket, pxDescriptor, ulLen, xReleaseAfterSend ) ); } @@ -290,7 +290,7 @@ void test_prvTCPReturnPacket_IPV6_Assert3( void ) pxIPHeader = &pxTCPPacket->xIPHeader; usGenerateProtocolChecksum_ExpectAnyArgsAndReturn( ipCORRECT_CRC ); - eNDGetCacheEntry_ExpectAnyArgsAndReturn( eARPCacheHit ); + eNDGetCacheEntry_ExpectAnyArgsAndReturn( eResolutionCacheHit ); catch_assert( prvTCPReturnPacket_IPV6( &xSocket, pxDescriptor, ulLen, xReleaseAfterSend ) ); } @@ -325,7 +325,7 @@ void test_prvTCPReturnPacket_IPV6_HappyPath_ReleaseAfterSend( void ) pxDescriptor->pxEndPoint->pxNetworkInterface->pfOutput = &NetworkInterfaceOutputFunction_Stub; usGenerateProtocolChecksum_ExpectAnyArgsAndReturn( ipCORRECT_CRC ); - eNDGetCacheEntry_ExpectAnyArgsAndReturn( eARPCacheHit ); + eNDGetCacheEntry_ExpectAnyArgsAndReturn( eResolutionCacheHit ); prvTCPReturnPacket_IPV6( &xSocket, pxDescriptor, ulLen, xReleaseAfterSend ); } @@ -360,7 +360,7 @@ void test_prvTCPReturnPacket_IPV6_HappyPath_NoReleaseAfterSend( void ) pxDescriptor->pxEndPoint->pxNetworkInterface->pfOutput = &NetworkInterfaceOutputFunction_Stub; usGenerateProtocolChecksum_ExpectAnyArgsAndReturn( ipCORRECT_CRC ); - eNDGetCacheEntry_ExpectAnyArgsAndReturn( eARPCacheHit ); + eNDGetCacheEntry_ExpectAnyArgsAndReturn( eResolutionCacheHit ); prvTCPReturnPacket_IPV6( &xSocket, pxDescriptor, ulLen, xReleaseAfterSend ); } @@ -376,7 +376,7 @@ void test_prvTCPPrepareConnect_IPV6_CacheMiss_NULLEP( void ) FreeRTOS_Socket_t xSocket, * pxSocket = &xSocket; BaseType_t xReturn = pdFALSE; - eNDGetCacheEntry_ExpectAnyArgsAndReturn( eARPCacheMiss ); + eNDGetCacheEntry_ExpectAnyArgsAndReturn( eResolutionCacheMiss ); uxIPHeaderSizeSocket_ExpectAnyArgsAndReturn( ipSIZE_OF_IPv6_HEADER ); @@ -396,7 +396,7 @@ void test_prvTCPPrepareConnect_IPV6_CacheHit_NULLEP( void ) FreeRTOS_Socket_t xSocket, * pxSocket = &xSocket; BaseType_t xReturn = pdFALSE; - eNDGetCacheEntry_ExpectAnyArgsAndReturn( eARPCacheHit ); + eNDGetCacheEntry_ExpectAnyArgsAndReturn( eResolutionCacheHit ); uxIPHeaderSizeSocket_ExpectAnyArgsAndReturn( ipSIZE_OF_IPv6_HEADER ); ulApplicationGetNextSequenceNumber_ExpectAnyArgsAndReturn( 0 ); @@ -417,7 +417,7 @@ void test_prvTCPPrepareConnect_IPV6_CacheHit_RandNumFail( void ) FreeRTOS_Socket_t xSocket, * pxSocket = &xSocket; BaseType_t xReturn = pdFALSE; - eNDGetCacheEntry_ExpectAnyArgsAndReturn( eARPCacheHit ); + eNDGetCacheEntry_ExpectAnyArgsAndReturn( eResolutionCacheHit ); uxIPHeaderSizeSocket_ExpectAnyArgsAndReturn( ipSIZE_OF_IPv6_HEADER ); ulApplicationGetNextSequenceNumber_ExpectAnyArgsAndReturn( 10 ); @@ -437,7 +437,7 @@ void test_prvTCPPrepareConnect_IPV6_CantSendPacket_NULLEP( void ) FreeRTOS_Socket_t xSocket, * pxSocket = &xSocket; BaseType_t xReturn = pdFALSE; - eNDGetCacheEntry_ExpectAnyArgsAndReturn( eCantSendPacket ); + eNDGetCacheEntry_ExpectAnyArgsAndReturn( eResolutionFailed ); uxIPHeaderSizeSocket_ExpectAnyArgsAndReturn( ipSIZE_OF_IPv6_HEADER ); @@ -457,7 +457,7 @@ void test_prvTCPPrepareConnect_IPV6_CacheMiss_ValidEP( void ) BaseType_t xReturn = pdFALSE; memset( pxEndPoint, 0, sizeof( NetworkEndPoint_t ) ); - eNDGetCacheEntry_ExpectAnyArgsAndReturn( eARPCacheMiss ); + eNDGetCacheEntry_ExpectAnyArgsAndReturn( eResolutionCacheMiss ); eNDGetCacheEntry_ReturnThruPtr_ppxEndPoint( &pxEndPoint ); uxIPHeaderSizeSocket_ExpectAnyArgsAndReturn( ipSIZE_OF_IPv6_HEADER ); @@ -485,7 +485,7 @@ void test_prvTCPPrepareConnect_IPV6_DefaultCase_ValidEP( void ) memset( pxEndPoint, 0, sizeof( NetworkEndPoint_t ) ); memset( &xNetworkBuffer, 0, sizeof( NetworkBufferDescriptor_t ) ); - eNDGetCacheEntry_ExpectAnyArgsAndReturn( eCantSendPacket + 1 ); /* Default case */ + eNDGetCacheEntry_ExpectAnyArgsAndReturn( eResolutionFailed + 1 ); /* Default case */ eNDGetCacheEntry_ReturnThruPtr_ppxEndPoint( &pxEndPoint ); uxIPHeaderSizeSocket_ExpectAnyArgsAndReturn( ipSIZE_OF_IPv6_HEADER ); @@ -516,7 +516,7 @@ void test_prvTCPPrepareConnect_IPV6_HappyPath_IPv4( void ) memset( &xNetworkBuffer, 0, sizeof( NetworkBufferDescriptor_t ) ); pxSocket->bits.bIsIPv6 = 0; - eNDGetCacheEntry_ExpectAnyArgsAndReturn( eARPCacheHit ); + eNDGetCacheEntry_ExpectAnyArgsAndReturn( eResolutionCacheHit ); eNDGetCacheEntry_ReturnThruPtr_ppxEndPoint( &pxEndPoint ); uxIPHeaderSizeSocket_ExpectAnyArgsAndReturn( ipSIZE_OF_IPv4_HEADER ); @@ -545,7 +545,7 @@ void test_prvTCPPrepareConnect_IPV6_HappyPath_IPv6( void ) memset( pxEndPoint, 0, sizeof( NetworkEndPoint_t ) ); memset( &xNetworkBuffer, 0, sizeof( NetworkBufferDescriptor_t ) ); pxSocket->bits.bIsIPv6 = 1; - eNDGetCacheEntry_ExpectAnyArgsAndReturn( eARPCacheHit ); + eNDGetCacheEntry_ExpectAnyArgsAndReturn( eResolutionCacheHit ); eNDGetCacheEntry_ReturnThruPtr_ppxEndPoint( &pxEndPoint ); uxIPHeaderSizeSocket_ExpectAnyArgsAndReturn( ipSIZE_OF_IPv6_HEADER ); @@ -574,7 +574,7 @@ void test_prvTCPPrepareConnect_IPV6_CreateTCPWindowFails( void ) memset( pxEndPoint, 0, sizeof( NetworkEndPoint_t ) ); memset( &xNetworkBuffer, 0, sizeof( NetworkBufferDescriptor_t ) ); pxSocket->bits.bIsIPv6 = 1; - eNDGetCacheEntry_ExpectAnyArgsAndReturn( eARPCacheHit ); + eNDGetCacheEntry_ExpectAnyArgsAndReturn( eResolutionCacheHit ); eNDGetCacheEntry_ReturnThruPtr_ppxEndPoint( &pxEndPoint ); uxIPHeaderSizeSocket_ExpectAnyArgsAndReturn( ipSIZE_OF_IPv6_HEADER ); diff --git a/test/unit-test/FreeRTOS_UDP_IPv4/FreeRTOS_UDP_IPv4_utest.c b/test/unit-test/FreeRTOS_UDP_IPv4/FreeRTOS_UDP_IPv4_utest.c index 1df9d111a6..a41f28ae51 100644 --- a/test/unit-test/FreeRTOS_UDP_IPv4/FreeRTOS_UDP_IPv4_utest.c +++ b/test/unit-test/FreeRTOS_UDP_IPv4/FreeRTOS_UDP_IPv4_utest.c @@ -1262,7 +1262,7 @@ void test_vProcessGeneratedUDPPacket_IPv4_ICMPPingCantSend() pxICMPPacket = ( ICMPPacket_t * ) pxNetworkBuffer->pucEthernetBuffer; - eARPGetCacheEntry_ExpectAndReturn( &( pxNetworkBuffer->xIPAddress.ulIP_IPv4 ), &( pxICMPPacket->xEthernetHeader.xDestinationAddress ), NULL, eCantSendPacket ); + eARPGetCacheEntry_ExpectAndReturn( &( pxNetworkBuffer->xIPAddress.ulIP_IPv4 ), &( pxICMPPacket->xEthernetHeader.xDestinationAddress ), NULL, eResolutionFailed ); eARPGetCacheEntry_IgnoreArg_ppxEndPoint(); eARPGetCacheEntry_ReturnThruPtr_ppxEndPoint( &pxEndPoint ); eARPGetCacheEntry_IgnoreArg_pulIPAddress(); @@ -1317,7 +1317,7 @@ void test_vProcessGeneratedUDPPacket_IPv4_ICMPPingCacheHit() pxICMPPacket = ( ICMPPacket_t * ) pxNetworkBuffer->pucEthernetBuffer; - eARPGetCacheEntry_ExpectAndReturn( &( pxNetworkBuffer->xIPAddress.ulIP_IPv4 ), &( pxICMPPacket->xEthernetHeader.xDestinationAddress ), NULL, eARPCacheHit ); + eARPGetCacheEntry_ExpectAndReturn( &( pxNetworkBuffer->xIPAddress.ulIP_IPv4 ), &( pxICMPPacket->xEthernetHeader.xDestinationAddress ), NULL, eResolutionCacheHit ); eARPGetCacheEntry_IgnoreArg_ppxEndPoint(); eARPGetCacheEntry_ReturnThruPtr_ppxEndPoint( &pxEndPoint ); eARPGetCacheEntry_IgnoreArg_pulIPAddress(); @@ -1350,7 +1350,7 @@ void test_vProcessGeneratedUDPPacket_IPv4_UDPCacheHit() pxUDPPacket = ( UDPPacket_t * ) pxNetworkBuffer->pucEthernetBuffer; - eARPGetCacheEntry_ExpectAndReturn( &( pxNetworkBuffer->xIPAddress.ulIP_IPv4 ), &( pxUDPPacket->xEthernetHeader.xDestinationAddress ), NULL, eARPCacheHit ); + eARPGetCacheEntry_ExpectAndReturn( &( pxNetworkBuffer->xIPAddress.ulIP_IPv4 ), &( pxUDPPacket->xEthernetHeader.xDestinationAddress ), NULL, eResolutionCacheHit ); eARPGetCacheEntry_IgnoreArg_ppxEndPoint(); eARPGetCacheEntry_ReturnThruPtr_ppxEndPoint( &pxEndPoint ); eARPGetCacheEntry_IgnoreArg_pulIPAddress(); @@ -1390,7 +1390,7 @@ void test_vProcessGeneratedUDPPacket_IPv4_UDPCacheHitLessBufferLength() pxUDPPacket = ( UDPPacket_t * ) pxNetworkBuffer->pucEthernetBuffer; - eARPGetCacheEntry_ExpectAndReturn( &( pxNetworkBuffer->xIPAddress.ulIP_IPv4 ), &( pxUDPPacket->xEthernetHeader.xDestinationAddress ), NULL, eARPCacheHit ); + eARPGetCacheEntry_ExpectAndReturn( &( pxNetworkBuffer->xIPAddress.ulIP_IPv4 ), &( pxUDPPacket->xEthernetHeader.xDestinationAddress ), NULL, eResolutionCacheHit ); eARPGetCacheEntry_IgnoreArg_ppxEndPoint(); eARPGetCacheEntry_ReturnThruPtr_ppxEndPoint( &pxEndPoint ); eARPGetCacheEntry_IgnoreArg_pulIPAddress(); @@ -1429,7 +1429,7 @@ void test_vProcessGeneratedUDPPacket_IPv4_UDPCacheHitDiffEndPoint() pxUDPPacket = ( UDPPacket_t * ) pxNetworkBuffer->pucEthernetBuffer; - eARPGetCacheEntry_ExpectAndReturn( &( pxNetworkBuffer->xIPAddress.ulIP_IPv4 ), &( pxUDPPacket->xEthernetHeader.xDestinationAddress ), NULL, eARPCacheHit ); + eARPGetCacheEntry_ExpectAndReturn( &( pxNetworkBuffer->xIPAddress.ulIP_IPv4 ), &( pxUDPPacket->xEthernetHeader.xDestinationAddress ), NULL, eResolutionCacheHit ); eARPGetCacheEntry_IgnoreArg_ppxEndPoint(); eARPGetCacheEntry_ReturnThruPtr_ppxEndPoint( &pxDifferentEndPoint ); eARPGetCacheEntry_IgnoreArg_pulIPAddress(); @@ -1466,7 +1466,7 @@ void test_vProcessGeneratedUDPPacket_IPv4_UDPCacheHitLLMNR() pxUDPPacket = ( UDPPacket_t * ) pxNetworkBuffer->pucEthernetBuffer; - eARPGetCacheEntry_ExpectAndReturn( &( pxNetworkBuffer->xIPAddress.ulIP_IPv4 ), &( pxUDPPacket->xEthernetHeader.xDestinationAddress ), NULL, eARPCacheHit ); + eARPGetCacheEntry_ExpectAndReturn( &( pxNetworkBuffer->xIPAddress.ulIP_IPv4 ), &( pxUDPPacket->xEthernetHeader.xDestinationAddress ), NULL, eResolutionCacheHit ); eARPGetCacheEntry_IgnoreArg_ppxEndPoint(); eARPGetCacheEntry_ReturnThruPtr_ppxEndPoint( &pxEndPoint ); eARPGetCacheEntry_IgnoreArg_pulIPAddress(); @@ -1505,7 +1505,7 @@ void test_vProcessGeneratedUDPPacket_IPv4_UDPCacheHitMDNS() pxUDPPacket = ( UDPPacket_t * ) pxNetworkBuffer->pucEthernetBuffer; - eARPGetCacheEntry_ExpectAndReturn( &( pxNetworkBuffer->xIPAddress.ulIP_IPv4 ), &( pxUDPPacket->xEthernetHeader.xDestinationAddress ), NULL, eARPCacheHit ); + eARPGetCacheEntry_ExpectAndReturn( &( pxNetworkBuffer->xIPAddress.ulIP_IPv4 ), &( pxUDPPacket->xEthernetHeader.xDestinationAddress ), NULL, eResolutionCacheHit ); eARPGetCacheEntry_IgnoreArg_ppxEndPoint(); eARPGetCacheEntry_ReturnThruPtr_ppxEndPoint( &pxEndPoint ); eARPGetCacheEntry_IgnoreArg_pulIPAddress(); @@ -1545,7 +1545,7 @@ void test_vProcessGeneratedUDPPacket_IPv4_UDPCacheHitNoInterface() pxUDPPacket = ( UDPPacket_t * ) pxNetworkBuffer->pucEthernetBuffer; - eARPGetCacheEntry_ExpectAndReturn( &( pxNetworkBuffer->xIPAddress.ulIP_IPv4 ), &( pxUDPPacket->xEthernetHeader.xDestinationAddress ), NULL, eARPCacheHit ); + eARPGetCacheEntry_ExpectAndReturn( &( pxNetworkBuffer->xIPAddress.ulIP_IPv4 ), &( pxUDPPacket->xEthernetHeader.xDestinationAddress ), NULL, eResolutionCacheHit ); eARPGetCacheEntry_IgnoreArg_ppxEndPoint(); eARPGetCacheEntry_ReturnThruPtr_ppxEndPoint( &pxEndPoint ); eARPGetCacheEntry_IgnoreArg_pulIPAddress(); @@ -1584,7 +1584,7 @@ void test_vProcessGeneratedUDPPacket_IPv4_UDPCacheHitInterfaceNoOutput() pxUDPPacket = ( UDPPacket_t * ) pxNetworkBuffer->pucEthernetBuffer; - eARPGetCacheEntry_ExpectAndReturn( &( pxNetworkBuffer->xIPAddress.ulIP_IPv4 ), &( pxUDPPacket->xEthernetHeader.xDestinationAddress ), NULL, eARPCacheHit ); + eARPGetCacheEntry_ExpectAndReturn( &( pxNetworkBuffer->xIPAddress.ulIP_IPv4 ), &( pxUDPPacket->xEthernetHeader.xDestinationAddress ), NULL, eResolutionCacheHit ); eARPGetCacheEntry_IgnoreArg_ppxEndPoint(); eARPGetCacheEntry_ReturnThruPtr_ppxEndPoint( &pxEndPoint ); eARPGetCacheEntry_IgnoreArg_pulIPAddress(); @@ -1618,7 +1618,7 @@ void test_vProcessGeneratedUDPPacket_IPv4_UDPCacheHitNoEndPoint() pxUDPPacket = ( UDPPacket_t * ) pxNetworkBuffer->pucEthernetBuffer; - eARPGetCacheEntry_ExpectAndReturn( &( pxNetworkBuffer->xIPAddress.ulIP_IPv4 ), &( pxUDPPacket->xEthernetHeader.xDestinationAddress ), NULL, eARPCacheHit ); + eARPGetCacheEntry_ExpectAndReturn( &( pxNetworkBuffer->xIPAddress.ulIP_IPv4 ), &( pxUDPPacket->xEthernetHeader.xDestinationAddress ), NULL, eResolutionCacheHit ); eARPGetCacheEntry_IgnoreArg_ppxEndPoint(); eARPGetCacheEntry_ReturnThruPtr_ppxEndPoint( &pxEndPoint ); eARPGetCacheEntry_IgnoreArg_pulIPAddress(); @@ -1652,7 +1652,7 @@ void test_vProcessGeneratedUDPPacket_IPv4_UDPCacheMissEndPointFound() pxUDPPacket = ( UDPPacket_t * ) pxNetworkBuffer->pucEthernetBuffer; - eARPGetCacheEntry_ExpectAndReturn( &( pxNetworkBuffer->xIPAddress.ulIP_IPv4 ), &( pxUDPPacket->xEthernetHeader.xDestinationAddress ), NULL, eARPCacheMiss ); + eARPGetCacheEntry_ExpectAndReturn( &( pxNetworkBuffer->xIPAddress.ulIP_IPv4 ), &( pxUDPPacket->xEthernetHeader.xDestinationAddress ), NULL, eResolutionCacheMiss ); eARPGetCacheEntry_IgnoreArg_ppxEndPoint(); eARPGetCacheEntry_ReturnThruPtr_ppxEndPoint( &pxEndPointNull ); eARPGetCacheEntry_IgnoreArg_pulIPAddress(); @@ -1684,7 +1684,7 @@ void test_vProcessGeneratedUDPPacket_IPv4_UDPCacheMissEndPointNotFound() pxUDPPacket = ( UDPPacket_t * ) pxNetworkBuffer->pucEthernetBuffer; - eARPGetCacheEntry_ExpectAndReturn( &( pxNetworkBuffer->xIPAddress.ulIP_IPv4 ), &( pxUDPPacket->xEthernetHeader.xDestinationAddress ), NULL, eARPCacheMiss ); + eARPGetCacheEntry_ExpectAndReturn( &( pxNetworkBuffer->xIPAddress.ulIP_IPv4 ), &( pxUDPPacket->xEthernetHeader.xDestinationAddress ), NULL, eResolutionCacheMiss ); eARPGetCacheEntry_IgnoreArg_ppxEndPoint(); eARPGetCacheEntry_ReturnThruPtr_ppxEndPoint( &pxEndPointNull ); eARPGetCacheEntry_IgnoreArg_pulIPAddress(); diff --git a/test/unit-test/FreeRTOS_UDP_IPv6/FreeRTOS_UDP_IPv6_utest.c b/test/unit-test/FreeRTOS_UDP_IPv6/FreeRTOS_UDP_IPv6_utest.c index ec887f2e3e..4c1cc683a2 100644 --- a/test/unit-test/FreeRTOS_UDP_IPv6/FreeRTOS_UDP_IPv6_utest.c +++ b/test/unit-test/FreeRTOS_UDP_IPv6/FreeRTOS_UDP_IPv6_utest.c @@ -504,7 +504,7 @@ void test_xProcessReceivedUDPPacket_IPv6_SocketNeedND() pxUDPv6Packet->xUDPHeader.usDestinationPort = usDestPortNetworkEndian; pxUDPSocketLookup_ExpectAndReturn( usDestPortNetworkEndian, &xSocket ); - xCheckRequiresARPResolution_ExpectAndReturn( &xNetworkBuffer, pdTRUE ); + xCheckRequiresNDResolution_ExpectAndReturn( &xNetworkBuffer, pdTRUE ); xReturn = xProcessReceivedUDPPacket_IPv6( &xNetworkBuffer, usDestPortNetworkEndian, &xIsWaitingForARPResolution ); @@ -545,7 +545,7 @@ void test_xProcessReceivedUDPPacket_IPv6_SocketRecvHandlerFail() xSocket.u.xUDP.pxHandleReceive = xStubUDPReceiveHandler_Fail; pxUDPSocketLookup_ExpectAndReturn( usDestPortNetworkEndian, &xSocket ); - xCheckRequiresARPResolution_ExpectAndReturn( &xNetworkBuffer, pdFALSE ); + xCheckRequiresNDResolution_ExpectAndReturn( &xNetworkBuffer, pdFALSE ); vNDRefreshCacheEntry_Ignore(); uxIPHeaderSizePacket_ExpectAndReturn( &xNetworkBuffer, ipSIZE_OF_IPv6_HEADER ); @@ -587,7 +587,7 @@ void test_xProcessReceivedUDPPacket_IPv6_UDPListBufferFull() xSocket.u.xUDP.pxHandleReceive = xStubUDPReceiveHandler_Pass; pxUDPSocketLookup_ExpectAndReturn( usDestPortNetworkEndian, &xSocket ); - xCheckRequiresARPResolution_ExpectAndReturn( &xNetworkBuffer, pdFALSE ); + xCheckRequiresNDResolution_ExpectAndReturn( &xNetworkBuffer, pdFALSE ); vNDRefreshCacheEntry_Ignore(); uxIPHeaderSizePacket_ExpectAndReturn( &xNetworkBuffer, ipSIZE_OF_IPv6_HEADER ); @@ -635,7 +635,7 @@ void test_xProcessReceivedUDPPacket_IPv6_Pass() xSocket.u.xUDP.pxHandleReceive = NULL; pxUDPSocketLookup_ExpectAndReturn( usDestPortNetworkEndian, &xSocket ); - xCheckRequiresARPResolution_ExpectAndReturn( &xNetworkBuffer, pdFALSE ); + xCheckRequiresNDResolution_ExpectAndReturn( &xNetworkBuffer, pdFALSE ); vNDRefreshCacheEntry_Ignore(); uxIPHeaderSizePacket_ExpectAndReturn( &xNetworkBuffer, ipSIZE_OF_IPv6_HEADER ); @@ -702,7 +702,7 @@ void test_xProcessReceivedUDPPacket_IPv6_PassNoEventGroup() xSocket.xEventGroup = NULL; pxUDPSocketLookup_ExpectAndReturn( usDestPortNetworkEndian, &xSocket ); - xCheckRequiresARPResolution_ExpectAndReturn( &xNetworkBuffer, pdFALSE ); + xCheckRequiresNDResolution_ExpectAndReturn( &xNetworkBuffer, pdFALSE ); vNDRefreshCacheEntry_Ignore(); uxIPHeaderSizePacket_ExpectAndReturn( &xNetworkBuffer, ipSIZE_OF_IPv6_HEADER ); @@ -767,7 +767,7 @@ void test_xProcessReceivedUDPPacket_IPv6_PassNoSelectBit() xSocket.xEventGroup = xEventGroup; pxUDPSocketLookup_ExpectAndReturn( usDestPortNetworkEndian, &xSocket ); - xCheckRequiresARPResolution_ExpectAndReturn( &xNetworkBuffer, pdFALSE ); + xCheckRequiresNDResolution_ExpectAndReturn( &xNetworkBuffer, pdFALSE ); vNDRefreshCacheEntry_Ignore(); uxIPHeaderSizePacket_ExpectAndReturn( &xNetworkBuffer, ipSIZE_OF_IPv6_HEADER ); @@ -831,7 +831,7 @@ void test_xProcessReceivedUDPPacket_IPv6_PassNoSelectSet() xSocket.xEventGroup = xEventGroup; pxUDPSocketLookup_ExpectAndReturn( usDestPortNetworkEndian, &xSocket ); - xCheckRequiresARPResolution_ExpectAndReturn( &xNetworkBuffer, pdFALSE ); + xCheckRequiresNDResolution_ExpectAndReturn( &xNetworkBuffer, pdFALSE ); vNDRefreshCacheEntry_Ignore(); uxIPHeaderSizePacket_ExpectAndReturn( &xNetworkBuffer, ipSIZE_OF_IPv6_HEADER ); @@ -893,7 +893,7 @@ void test_xProcessReceivedUDPPacket_IPv6_PassNoSem() xSocket.xEventGroup = xEventGroup; pxUDPSocketLookup_ExpectAndReturn( usDestPortNetworkEndian, &xSocket ); - xCheckRequiresARPResolution_ExpectAndReturn( &xNetworkBuffer, pdFALSE ); + xCheckRequiresNDResolution_ExpectAndReturn( &xNetworkBuffer, pdFALSE ); vNDRefreshCacheEntry_Ignore(); uxIPHeaderSizePacket_ExpectAndReturn( &xNetworkBuffer, ipSIZE_OF_IPv6_HEADER ); @@ -956,7 +956,7 @@ void test_xProcessReceivedUDPPacket_IPv6_PassNoDHCP() xSocket.xEventGroup = xEventGroup; pxUDPSocketLookup_ExpectAndReturn( usDestPortNetworkEndian, &xSocket ); - xCheckRequiresARPResolution_ExpectAndReturn( &xNetworkBuffer, pdFALSE ); + xCheckRequiresNDResolution_ExpectAndReturn( &xNetworkBuffer, pdFALSE ); vNDRefreshCacheEntry_Ignore(); uxIPHeaderSizePacket_ExpectAndReturn( &xNetworkBuffer, ipSIZE_OF_IPv6_HEADER ); @@ -1002,7 +1002,7 @@ void test_vProcessGeneratedUDPPacket_IPv6_ICMPPingCantSend() pxICMPv6Packet = ( ICMPPacket_IPv6_t * ) pxNetworkBuffer->pucEthernetBuffer; - eNDGetCacheEntry_ExpectAndReturn( &( pxNetworkBuffer->xIPAddress.xIP_IPv6 ), &( pxICMPv6Packet->xEthernetHeader.xDestinationAddress ), NULL, eCantSendPacket ); + eNDGetCacheEntry_ExpectAndReturn( &( pxNetworkBuffer->xIPAddress.xIP_IPv6 ), &( pxICMPv6Packet->xEthernetHeader.xDestinationAddress ), NULL, eResolutionFailed ); eNDGetCacheEntry_IgnoreArg_ppxEndPoint(); eNDGetCacheEntry_ReturnThruPtr_ppxEndPoint( &pxEndPoint ); vReleaseNetworkBufferAndDescriptor_Expect( pxNetworkBuffer ); @@ -1055,7 +1055,7 @@ void test_vProcessGeneratedUDPPacket_IPv6_ICMPPingCacheHit() pxICMPv6Packet = ( ICMPPacket_IPv6_t * ) pxNetworkBuffer->pucEthernetBuffer; - eNDGetCacheEntry_ExpectAndReturn( &( pxNetworkBuffer->xIPAddress.xIP_IPv6 ), &( pxICMPv6Packet->xEthernetHeader.xDestinationAddress ), NULL, eARPCacheHit ); + eNDGetCacheEntry_ExpectAndReturn( &( pxNetworkBuffer->xIPAddress.xIP_IPv6 ), &( pxICMPv6Packet->xEthernetHeader.xDestinationAddress ), NULL, eResolutionCacheHit ); eNDGetCacheEntry_IgnoreArg_ppxEndPoint(); eNDGetCacheEntry_ReturnThruPtr_ppxEndPoint( &pxEndPoint ); usGenerateProtocolChecksum_ExpectAndReturn( pxNetworkBuffer->pucEthernetBuffer, pxNetworkBuffer->xDataLength, pdTRUE, ipCORRECT_CRC ); @@ -1086,7 +1086,7 @@ void test_vProcessGeneratedUDPPacket_IPv6_UDPv6CacheHit() pxUDPv6Packet = ( UDPPacket_IPv6_t * ) pxNetworkBuffer->pucEthernetBuffer; - eNDGetCacheEntry_ExpectAndReturn( &( pxNetworkBuffer->xIPAddress.xIP_IPv6 ), &( pxUDPv6Packet->xEthernetHeader.xDestinationAddress ), NULL, eARPCacheHit ); + eNDGetCacheEntry_ExpectAndReturn( &( pxNetworkBuffer->xIPAddress.xIP_IPv6 ), &( pxUDPv6Packet->xEthernetHeader.xDestinationAddress ), NULL, eResolutionCacheHit ); eNDGetCacheEntry_IgnoreArg_ppxEndPoint(); eNDGetCacheEntry_ReturnThruPtr_ppxEndPoint( &pxEndPoint ); usGenerateProtocolChecksum_ExpectAndReturn( pxNetworkBuffer->pucEthernetBuffer, pxNetworkBuffer->xDataLength, pdTRUE, ipCORRECT_CRC ); @@ -1126,7 +1126,7 @@ void test_vProcessGeneratedUDPPacket_IPv6_UDPv6CacheHitLessBufferLength() pxUDPv6Packet = ( UDPPacket_IPv6_t * ) pxNetworkBuffer->pucEthernetBuffer; - eNDGetCacheEntry_ExpectAndReturn( &( pxNetworkBuffer->xIPAddress.xIP_IPv6 ), &( pxUDPv6Packet->xEthernetHeader.xDestinationAddress ), NULL, eARPCacheHit ); + eNDGetCacheEntry_ExpectAndReturn( &( pxNetworkBuffer->xIPAddress.xIP_IPv6 ), &( pxUDPv6Packet->xEthernetHeader.xDestinationAddress ), NULL, eResolutionCacheHit ); eNDGetCacheEntry_IgnoreArg_ppxEndPoint(); eNDGetCacheEntry_ReturnThruPtr_ppxEndPoint( &pxEndPoint ); usGenerateProtocolChecksum_ExpectAndReturn( pxNetworkBuffer->pucEthernetBuffer, pxNetworkBuffer->xDataLength, pdTRUE, ipCORRECT_CRC ); @@ -1161,7 +1161,7 @@ void test_vProcessGeneratedUDPPacket_IPv6_UDPv6CacheHitNoEndPoint() pxUDPv6Packet = ( UDPPacket_IPv6_t * ) pxNetworkBuffer->pucEthernetBuffer; - eNDGetCacheEntry_ExpectAndReturn( &( pxNetworkBuffer->xIPAddress.xIP_IPv6 ), &( pxUDPv6Packet->xEthernetHeader.xDestinationAddress ), NULL, eARPCacheHit ); + eNDGetCacheEntry_ExpectAndReturn( &( pxNetworkBuffer->xIPAddress.xIP_IPv6 ), &( pxUDPv6Packet->xEthernetHeader.xDestinationAddress ), NULL, eResolutionCacheHit ); eNDGetCacheEntry_IgnoreArg_ppxEndPoint(); eNDGetCacheEntry_ReturnThruPtr_ppxEndPoint( &pxEndPoint ); vReleaseNetworkBufferAndDescriptor_Expect( pxNetworkBuffer ); @@ -1195,7 +1195,7 @@ void test_vProcessGeneratedUDPPacket_IPv6_UDPv6CacheMissBothGlobal() pxUDPv6Packet = ( UDPPacket_IPv6_t * ) pxNetworkBuffer->pucEthernetBuffer; - eNDGetCacheEntry_ExpectAndReturn( &( pxNetworkBuffer->xIPAddress.xIP_IPv6 ), &( pxUDPv6Packet->xEthernetHeader.xDestinationAddress ), NULL, eARPCacheMiss ); + eNDGetCacheEntry_ExpectAndReturn( &( pxNetworkBuffer->xIPAddress.xIP_IPv6 ), &( pxUDPv6Packet->xEthernetHeader.xDestinationAddress ), NULL, eResolutionCacheMiss ); eNDGetCacheEntry_IgnoreArg_ppxEndPoint(); eNDGetCacheEntry_ReturnThruPtr_ppxEndPoint( &pxEndPointNull ); xIPv6_GetIPType_ExpectAndReturn( &( pxNetworkBuffer->xIPAddress.xIP_IPv6 ), eIPv6_Global ); @@ -1227,7 +1227,7 @@ void test_vProcessGeneratedUDPPacket_IPv6_UDPv6CacheMissButEndPointFound() pxUDPv6Packet = ( UDPPacket_IPv6_t * ) pxNetworkBuffer->pucEthernetBuffer; - eNDGetCacheEntry_ExpectAndReturn( &( pxNetworkBuffer->xIPAddress.xIP_IPv6 ), &( pxUDPv6Packet->xEthernetHeader.xDestinationAddress ), NULL, eARPCacheMiss ); + eNDGetCacheEntry_ExpectAndReturn( &( pxNetworkBuffer->xIPAddress.xIP_IPv6 ), &( pxUDPv6Packet->xEthernetHeader.xDestinationAddress ), NULL, eResolutionCacheMiss ); eNDGetCacheEntry_IgnoreArg_ppxEndPoint(); eNDGetCacheEntry_ReturnThruPtr_ppxEndPoint( &pxEndPoint ); @@ -1255,7 +1255,7 @@ void test_vProcessGeneratedUDPPacket_IPv6_UDPv6CacheMissDifferentIPType() pxUDPv6Packet = ( UDPPacket_IPv6_t * ) pxNetworkBuffer->pucEthernetBuffer; - eNDGetCacheEntry_ExpectAndReturn( &( pxNetworkBuffer->xIPAddress.xIP_IPv6 ), &( pxUDPv6Packet->xEthernetHeader.xDestinationAddress ), NULL, eARPCacheMiss ); + eNDGetCacheEntry_ExpectAndReturn( &( pxNetworkBuffer->xIPAddress.xIP_IPv6 ), &( pxUDPv6Packet->xEthernetHeader.xDestinationAddress ), NULL, eResolutionCacheMiss ); eNDGetCacheEntry_IgnoreArg_ppxEndPoint(); eNDGetCacheEntry_ReturnThruPtr_ppxEndPoint( &pxEndPointNull ); xIPv6_GetIPType_ExpectAndReturn( &( pxNetworkBuffer->xIPAddress.xIP_IPv6 ), eIPv6_LinkLocal ); @@ -1288,7 +1288,7 @@ void test_vProcessGeneratedUDPPacket_IPv6_UDPv6CacheMissDifferentIPType2() pxUDPv6Packet = ( UDPPacket_IPv6_t * ) pxNetworkBuffer->pucEthernetBuffer; - eNDGetCacheEntry_ExpectAndReturn( &( pxNetworkBuffer->xIPAddress.xIP_IPv6 ), &( pxUDPv6Packet->xEthernetHeader.xDestinationAddress ), NULL, eARPCacheMiss ); + eNDGetCacheEntry_ExpectAndReturn( &( pxNetworkBuffer->xIPAddress.xIP_IPv6 ), &( pxUDPv6Packet->xEthernetHeader.xDestinationAddress ), NULL, eResolutionCacheMiss ); eNDGetCacheEntry_IgnoreArg_ppxEndPoint(); eNDGetCacheEntry_ReturnThruPtr_ppxEndPoint( &pxEndPointNull ); xIPv6_GetIPType_ExpectAndReturn( &( pxNetworkBuffer->xIPAddress.xIP_IPv6 ), eIPv6_Global ); diff --git a/tools/tcp_utilities/http_client_test.c b/tools/tcp_utilities/http_client_test.c index 1cfb00662a..cd43fe43ab 100644 --- a/tools/tcp_utilities/http_client_test.c +++ b/tools/tcp_utilities/http_client_test.c @@ -381,7 +381,7 @@ else #endif /* if ( ipconfigUSE_IPv6 != 0 ) */ { - pxEndPoint = FreeRTOS_FindEndPointOnNetMask( pxAddress->sin_address.ulIP_IPv4, 9999 ); + pxEndPoint = FreeRTOS_FindEndPointOnNetMask( pxAddress->sin_address.ulIP_IPv4 ); if( pxEndPoint != NULL ) { diff --git a/tools/tcp_utilities/plus_tcp_demo_cli.c b/tools/tcp_utilities/plus_tcp_demo_cli.c index 278ba0e7a3..37e00e72b4 100644 --- a/tools/tcp_utilities/plus_tcp_demo_cli.c +++ b/tools/tcp_utilities/plus_tcp_demo_cli.c @@ -279,21 +279,21 @@ static void handle_ifconfig( char * pcBuffer ) } /*-----------------------------------------------------------*/ -static const char * pcARPReturnType( eARPLookupResult_t eResult ) +static const char * pcARPReturnType( eResolutionLookupResult_t eResult ) { const char * pcReturn = "Unknown"; switch( eResult ) { - case eARPCacheMiss: + case eResolutionCacheMiss: pcReturn = "Miss"; break; - case eARPCacheHit: + case eResolutionCacheHit: pcReturn = "Hit"; break; - case eCantSendPacket: + case eResolutionFailed: pcReturn = "Can not send"; break; } @@ -453,7 +453,7 @@ static void handle_arpq( char * pcBuffer ) { CommandOptions_t xOptions; char * ptr = pcBuffer; - eARPLookupResult_t eResult = eARPCacheMiss; + eResolutionLookupResult_t eResult = eResolutionCacheMiss; uint32_t ulIPAddress; uint32_t ulLookUpIP; MACAddress_t xMACAddress; @@ -537,7 +537,7 @@ static void handle_arpq( char * pcBuffer ) break; } - if( ( eResult == eARPCacheMiss ) && ( pxEndPoint != NULL ) ) + if( ( eResult == eResolutionCacheMiss ) && ( pxEndPoint != NULL ) ) { size_t uxNeededSize = sizeof( ARPPacket_t ); @@ -1426,7 +1426,7 @@ static void clear_caches() { FreeRTOS_dnsclear(); #if ( ipconfigUSE_IPv6 != 0 ) - FreeRTOS_ClearND(); + FreeRTOS_ClearND( NULL ); #endif /* ( ipconfigUSE_IPv6 != 0 ) */ } #endif /* ipconfigUSE_DNS_CACHE */