mirror of
https://github.com/FreeRTOS/FreeRTOS-Kernel.git
synced 2025-12-23 11:09:28 -05:00
Coverity + MISRA compliance
Modified code to conform to the MISRA directives more closely.
This commit is contained in:
parent
fa74f7dccf
commit
4a1148d15b
1 changed files with 56 additions and 23 deletions
|
|
@ -85,9 +85,16 @@ static TickType_t xLastGratuitousARPTime = ( TickType_t ) 0;
|
|||
MACAddress_t xARPClashMacAddress;
|
||||
#endif /* ipconfigARP_USE_CLASH_DETECTION */
|
||||
|
||||
|
||||
/* Part of the Ethernet and ARP headers are always constant when sending an IPv4
|
||||
ARP packet. This array defines the constant parts, allowing this part of the
|
||||
packet to be filled in using a simple memcpy() instead of individual writes. */
|
||||
|
||||
/* MISRA c2012 rule 8.9 violation: "xDefaultPartARPPacketHeader" should be defined at block
|
||||
* scope.
|
||||
* Rule has been relaxed since this is a configuration parameter. And this location provides
|
||||
* more readability.
|
||||
*/
|
||||
static const uint8_t xDefaultPartARPPacketHeader[] =
|
||||
{
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* Ethernet destination address. */
|
||||
|
|
@ -114,7 +121,7 @@ uint32_t ulTargetProtocolAddress, ulSenderProtocolAddress;
|
|||
pxARPHeader = &( pxARPFrame->xARPHeader );
|
||||
|
||||
/* The field ulSenderProtocolAddress is badly aligned, copy byte-by-byte. */
|
||||
memcpy( ( void *)&( ulSenderProtocolAddress ), ( void * )pxARPHeader->ucSenderProtocolAddress, sizeof( ulSenderProtocolAddress ) );
|
||||
( void ) memcpy( ( void *)&( ulSenderProtocolAddress ), ( void * )pxARPHeader->ucSenderProtocolAddress, sizeof( ulSenderProtocolAddress ) );
|
||||
/* The field ulTargetProtocolAddress is well-aligned, a 32-bits copy. */
|
||||
ulTargetProtocolAddress = pxARPHeader->ulTargetProtocolAddress;
|
||||
|
||||
|
|
@ -144,17 +151,17 @@ uint32_t ulTargetProtocolAddress, ulSenderProtocolAddress;
|
|||
{
|
||||
/* A double IP address is detected! */
|
||||
/* Give the sources MAC address the value of the broadcast address, will be swapped later */
|
||||
memcpy( pxARPFrame->xEthernetHeader.xSourceAddress.ucBytes, xBroadcastMACAddress.ucBytes, sizeof( xBroadcastMACAddress ) );
|
||||
memset( pxARPHeader->xTargetHardwareAddress.ucBytes, '\0', sizeof( MACAddress_t ) );
|
||||
( void ) memcpy( pxARPFrame->xEthernetHeader.xSourceAddress.ucBytes, xBroadcastMACAddress.ucBytes, sizeof( xBroadcastMACAddress ) );
|
||||
( void ) memset( pxARPHeader->xTargetHardwareAddress.ucBytes, (int)'\0', sizeof( MACAddress_t ) );
|
||||
pxARPHeader->ulTargetProtocolAddress = 0UL;
|
||||
}
|
||||
else
|
||||
{
|
||||
memcpy( pxARPHeader->xTargetHardwareAddress.ucBytes, pxARPHeader->xSenderHardwareAddress.ucBytes, sizeof( MACAddress_t ) );
|
||||
( void ) memcpy( pxARPHeader->xTargetHardwareAddress.ucBytes, pxARPHeader->xSenderHardwareAddress.ucBytes, sizeof( MACAddress_t ) );
|
||||
pxARPHeader->ulTargetProtocolAddress = ulSenderProtocolAddress;
|
||||
}
|
||||
memcpy( pxARPHeader->xSenderHardwareAddress.ucBytes, ( void * ) ipLOCAL_MAC_ADDRESS, sizeof( MACAddress_t ) );
|
||||
memcpy( ( void* )pxARPHeader->ucSenderProtocolAddress, ( void* )ipLOCAL_IP_ADDRESS_POINTER, sizeof( pxARPHeader->ucSenderProtocolAddress ) );
|
||||
( void ) memcpy( pxARPHeader->xSenderHardwareAddress.ucBytes, ( void * ) ipLOCAL_MAC_ADDRESS, sizeof( MACAddress_t ) );
|
||||
( void ) memcpy( ( void* )pxARPHeader->ucSenderProtocolAddress, ( void* )ipLOCAL_IP_ADDRESS_POINTER, sizeof( pxARPHeader->ucSenderProtocolAddress ) );
|
||||
|
||||
eReturn = eReturnEthernetFrame;
|
||||
}
|
||||
|
|
@ -169,7 +176,7 @@ uint32_t ulTargetProtocolAddress, ulSenderProtocolAddress;
|
|||
if( ulSenderProtocolAddress == *ipLOCAL_IP_ADDRESS_POINTER )
|
||||
{
|
||||
xARPHadIPClash = pdTRUE;
|
||||
memcpy( xARPClashMacAddress.ucBytes, pxARPHeader->xSenderHardwareAddress.ucBytes, sizeof( xARPClashMacAddress.ucBytes ) );
|
||||
( void ) memcpy( xARPClashMacAddress.ucBytes, pxARPHeader->xSenderHardwareAddress.ucBytes, sizeof( xARPClashMacAddress.ucBytes ) );
|
||||
}
|
||||
}
|
||||
#endif /* ipconfigARP_USE_CLASH_DETECTION */
|
||||
|
|
@ -198,7 +205,7 @@ uint32_t ulTargetProtocolAddress, ulSenderProtocolAddress;
|
|||
if( ( memcmp( xARPCache[ x ].xMACAddress.ucBytes, pxMACAddress->ucBytes, sizeof( pxMACAddress->ucBytes ) ) == 0 ) )
|
||||
{
|
||||
lResult = xARPCache[ x ].ulIPAddress;
|
||||
memset( &xARPCache[ x ], '\0', sizeof( xARPCache[ x ] ) );
|
||||
( void ) memset( &xARPCache[ x ], '\0', sizeof( xARPCache[ x ] ) );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -222,7 +229,7 @@ uint8_t ucMinAgeFound = 0U;
|
|||
Unless: when '*ipLOCAL_IP_ADDRESS_POINTER' equals zero, the IP-address
|
||||
and netmask are still unknown. */
|
||||
if( ( ( ulIPAddress & xNetworkAddressing.ulNetMask ) == ( ( *ipLOCAL_IP_ADDRESS_POINTER ) & xNetworkAddressing.ulNetMask ) ) ||
|
||||
( *ipLOCAL_IP_ADDRESS_POINTER == 0ul ) )
|
||||
( *ipLOCAL_IP_ADDRESS_POINTER == 0UL ) )
|
||||
#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
|
||||
|
|
@ -261,6 +268,8 @@ uint8_t ucMinAgeFound = 0U;
|
|||
optimisation. */
|
||||
xARPCache[ x ].ucAge = ( uint8_t ) ipconfigMAX_ARP_AGE;
|
||||
xARPCache[ x ].ucValid = ( uint8_t ) pdTRUE;
|
||||
|
||||
/* MISRA rule 15.5 relaxed for readability of code */
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -302,6 +311,10 @@ uint8_t ucMinAgeFound = 0U;
|
|||
ucMinAgeFound = xARPCache[ x ].ucAge;
|
||||
xUseEntry = x;
|
||||
}
|
||||
else /* Added to supress MISRA rule 15.7 voilation */
|
||||
{
|
||||
/* Do nothing */
|
||||
}
|
||||
}
|
||||
|
||||
if( xMacEntry >= 0 )
|
||||
|
|
@ -313,7 +326,8 @@ uint8_t ucMinAgeFound = 0U;
|
|||
/* Both the MAC address as well as the IP address were found in
|
||||
different locations: clear the entry which matches the
|
||||
IP-address */
|
||||
memset( &xARPCache[ xIpEntry ], '\0', sizeof( xARPCache[ xIpEntry ] ) );
|
||||
/* Silence MISRA warning about unused return value */
|
||||
( void ) memset( &xARPCache[ xIpEntry ], (int)'\0', sizeof( xARPCache[ xIpEntry ] ) );
|
||||
}
|
||||
}
|
||||
else if( xIpEntry >= 0 )
|
||||
|
|
@ -321,13 +335,17 @@ uint8_t ucMinAgeFound = 0U;
|
|||
/* An entry containing the IP-address was found, but it had a different MAC address */
|
||||
xUseEntry = xIpEntry;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Do nothing! xUseEntry retains its value */
|
||||
}
|
||||
|
||||
/* If the entry was not found, we use the oldest entry and set the IPaddress */
|
||||
xARPCache[ xUseEntry ].ulIPAddress = ulIPAddress;
|
||||
|
||||
if( pxMACAddress != NULL )
|
||||
{
|
||||
memcpy( xARPCache[ xUseEntry ].xMACAddress.ucBytes, pxMACAddress->ucBytes, sizeof( pxMACAddress->ucBytes ) );
|
||||
( void ) memcpy( xARPCache[ xUseEntry ].xMACAddress.ucBytes, pxMACAddress->ucBytes, sizeof( pxMACAddress->ucBytes ) );
|
||||
|
||||
iptraceARP_TABLE_ENTRY_CREATED( ulIPAddress, (*pxMACAddress) );
|
||||
/* And this entry does not need immediate attention */
|
||||
|
|
@ -339,6 +357,10 @@ uint8_t ucMinAgeFound = 0U;
|
|||
xARPCache[ xUseEntry ].ucAge = ( uint8_t ) ipconfigMAX_ARP_RETRANSMISSIONS;
|
||||
xARPCache[ xUseEntry ].ucValid = ( uint8_t ) pdFALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Control should not get here */
|
||||
}
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
|
@ -377,7 +399,7 @@ uint32_t ulAddressToLookup;
|
|||
if( *pulIPAddress == ipLLMNR_IP_ADDR ) /* Is in network byte order. */
|
||||
{
|
||||
/* The LLMNR IP-address has a fixed virtual MAC address. */
|
||||
memcpy( pxMACAddress->ucBytes, xLLMNR_MacAdress.ucBytes, sizeof( MACAddress_t ) );
|
||||
( void ) memcpy( pxMACAddress->ucBytes, xLLMNR_MacAdress.ucBytes, sizeof( MACAddress_t ) );
|
||||
eReturn = eARPCacheHit;
|
||||
}
|
||||
else
|
||||
|
|
@ -386,7 +408,7 @@ uint32_t ulAddressToLookup;
|
|||
( *pulIPAddress == xNetworkAddressing.ulBroadcastAddress ) )/* Or a local broadcast address, eg 192.168.1.255? */
|
||||
{
|
||||
/* This is a broadcast so uses the broadcast MAC address. */
|
||||
memcpy( pxMACAddress->ucBytes, xBroadcastMACAddress.ucBytes, sizeof( MACAddress_t ) );
|
||||
( void ) memcpy( pxMACAddress->ucBytes, xBroadcastMACAddress.ucBytes, sizeof( MACAddress_t ) );
|
||||
eReturn = eARPCacheHit;
|
||||
}
|
||||
else if( *ipLOCAL_IP_ADDRESS_POINTER == 0UL )
|
||||
|
|
@ -479,7 +501,7 @@ eARPLookupResult_t eReturn = eARPCacheMiss;
|
|||
else
|
||||
{
|
||||
/* A valid entry was found. */
|
||||
memcpy( pxMACAddress->ucBytes, xARPCache[ x ].xMACAddress.ucBytes, sizeof( MACAddress_t ) );
|
||||
( void ) memcpy( pxMACAddress->ucBytes, xARPCache[ x ].xMACAddress.ucBytes, sizeof( MACAddress_t ) );
|
||||
eReturn = eARPCacheHit;
|
||||
}
|
||||
break;
|
||||
|
|
@ -549,7 +571,7 @@ void vARPSendGratuitous( void )
|
|||
xLastGratuitousARPTime = ( TickType_t ) 0;
|
||||
|
||||
/* Let the IP-task call vARPAgeCache(). */
|
||||
xSendEventToIPTask( eARPTimerEvent );
|
||||
( void ) xSendEventToIPTask( eARPTimerEvent );
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
|
@ -583,7 +605,7 @@ NetworkBufferDescriptor_t *pxNetworkBuffer;
|
|||
if( xIsCallingFromIPTask() != 0 )
|
||||
{
|
||||
/* Only the IP-task is allowed to call this function directly. */
|
||||
xNetworkInterfaceOutput( pxNetworkBuffer, pdTRUE );
|
||||
( void ) xNetworkInterfaceOutput( pxNetworkBuffer, pdTRUE );
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -608,7 +630,7 @@ ARPPacket_t *pxARPPacket;
|
|||
/* Buffer allocation ensures that buffers always have space
|
||||
for an ARP packet. See buffer allocation implementations 1
|
||||
and 2 under portable/BufferManagement. */
|
||||
configASSERT( pxNetworkBuffer );
|
||||
configASSERT( pxNetworkBuffer != NULL );
|
||||
configASSERT( pxNetworkBuffer->xDataLength >= sizeof(ARPPacket_t) );
|
||||
|
||||
pxARPPacket = ( ARPPacket_t * ) pxNetworkBuffer->pucEthernetBuffer;
|
||||
|
|
@ -624,11 +646,16 @@ ARPPacket_t *pxARPPacket;
|
|||
xARPHeader.usOperation;
|
||||
xARPHeader.xTargetHardwareAddress;
|
||||
*/
|
||||
memcpy( ( void * ) pxARPPacket, ( void * ) xDefaultPartARPPacketHeader, sizeof( xDefaultPartARPPacketHeader ) );
|
||||
memcpy( ( void * ) pxARPPacket->xEthernetHeader.xSourceAddress.ucBytes , ( void * ) ipLOCAL_MAC_ADDRESS, ( size_t ) ipMAC_ADDRESS_LENGTH_BYTES );
|
||||
memcpy( ( void * ) pxARPPacket->xARPHeader.xSenderHardwareAddress.ucBytes, ( void * ) ipLOCAL_MAC_ADDRESS, ( size_t ) ipMAC_ADDRESS_LENGTH_BYTES );
|
||||
|
||||
memcpy( ( void* )pxARPPacket->xARPHeader.ucSenderProtocolAddress, ( void* )ipLOCAL_IP_ADDRESS_POINTER, sizeof( pxARPPacket->xARPHeader.ucSenderProtocolAddress ) );
|
||||
/* Casting xDefaultPartARPPacketHeader as ("const" void*). Else it would
|
||||
* be a MISRA c2012 rule 11.18 violation.
|
||||
* Also, for rule 21.15 regarding using same pointer-to-x types for memcpy,
|
||||
* below is done intentionally here and thus the rule is relaxed */
|
||||
( void ) memcpy( ( void * ) pxARPPacket, (const void * ) xDefaultPartARPPacketHeader, sizeof( xDefaultPartARPPacketHeader ) );
|
||||
( void ) memcpy( ( void * ) pxARPPacket->xEthernetHeader.xSourceAddress.ucBytes , ( void * ) ipLOCAL_MAC_ADDRESS, ( size_t ) ipMAC_ADDRESS_LENGTH_BYTES );
|
||||
( void ) memcpy( ( void * ) pxARPPacket->xARPHeader.xSenderHardwareAddress.ucBytes, ( void * ) ipLOCAL_MAC_ADDRESS, ( size_t ) ipMAC_ADDRESS_LENGTH_BYTES );
|
||||
|
||||
( void ) memcpy( ( void* )pxARPPacket->xARPHeader.ucSenderProtocolAddress, ( void* )ipLOCAL_IP_ADDRESS_POINTER, sizeof( pxARPPacket->xARPHeader.ucSenderProtocolAddress ) );
|
||||
pxARPPacket->xARPHeader.ulTargetProtocolAddress = pxNetworkBuffer->ulIPAddress;
|
||||
|
||||
pxNetworkBuffer->xDataLength = sizeof( ARPPacket_t );
|
||||
|
|
@ -639,12 +666,18 @@ ARPPacket_t *pxARPPacket;
|
|||
|
||||
void FreeRTOS_ClearARP( void )
|
||||
{
|
||||
memset( xARPCache, '\0', sizeof( xARPCache ) );
|
||||
/* Function requires the second argument to be an int.
|
||||
*
|
||||
* MISRA rule 17.7 relaxed. The return value is not
|
||||
* required to be used. Also improves readability */
|
||||
( void ) memset( xARPCache, (int)'\0', sizeof( xARPCache ) );
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
#if( ipconfigHAS_PRINTF != 0 ) || ( ipconfigHAS_DEBUG_PRINTF != 0 )
|
||||
|
||||
/* MISRA c 2012 rule 8.7 relaxed since this function can be
|
||||
* called from external location when debugging is enabled */
|
||||
void FreeRTOS_PrintARPCache( void )
|
||||
{
|
||||
BaseType_t x, xCount = 0;
|
||||
|
|
@ -652,7 +685,7 @@ void FreeRTOS_ClearARP( void )
|
|||
/* Loop through each entry in the ARP cache. */
|
||||
for( x = 0; x < ipconfigARP_CACHE_ENTRIES; x++ )
|
||||
{
|
||||
if( ( xARPCache[ x ].ulIPAddress != 0ul ) && ( xARPCache[ x ].ucAge > 0U ) )
|
||||
if( ( xARPCache[ x ].ulIPAddress != 0UL ) && ( xARPCache[ x ].ucAge > 0U ) )
|
||||
{
|
||||
/* See if the MAC-address also matches, and we're all happy */
|
||||
FreeRTOS_printf( ( "Arp %2ld: %3u - %16lxip : %02x:%02x:%02x : %02x:%02x:%02x\n",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue