Skip to content

Commit

Permalink
Merge branch 'main' into MAC_Filtering_PR
Browse files Browse the repository at this point in the history
  • Loading branch information
Emil Popov committed Feb 29, 2024
2 parents 363b85b + f50a76b commit e710ebe
Show file tree
Hide file tree
Showing 32 changed files with 311 additions and 371 deletions.
3 changes: 0 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,6 @@ add_compile_options(
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-extra-semi-stmt>
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-missing-noreturn>
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-cast-align>

# Suppressions required to build clean with GCC.
$<$<COMPILE_LANG_AND_ID:C,GNU>:-Wno-declaration-after-statement>
)

########################################################################
Expand Down
119 changes: 67 additions & 52 deletions source/FreeRTOS_ARP.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ _static ARPCacheRow_t xARPCache[ ipconfigARP_CACHE_ENTRIES ];
uxARPClashCounter++;

/* Send out a defensive ARP request. */
FreeRTOS_OutputARPRequest( pxTargetEndPoint->ipv4_settings.ulIPAddress );
FreeRTOS_OutputARPRequest_Multi( pxTargetEndPoint, pxTargetEndPoint->ipv4_settings.ulIPAddress );

/* Since an ARP Request for this IP was just sent, do not send a gratuitous
* ARP for arpGRATUITOUS_ARP_PERIOD. */
Expand Down Expand Up @@ -539,7 +539,7 @@ BaseType_t xCheckRequiresARPResolution( const NetworkBufferDescriptor_t * pxNetw
* then we should send out ARP for finding the MAC address. */
if( xIsIPInARPCache( pxIPHeader->ulSourceIPAddress ) == pdFALSE )
{
FreeRTOS_OutputARPRequest( pxIPHeader->ulSourceIPAddress );
FreeRTOS_OutputARPRequest_Multi( pxNetworkBuffer->pxEndPoint, pxIPHeader->ulSourceIPAddress );

/* This packet needs resolution since this is on the same subnet
* but not in the ARP cache. */
Expand Down Expand Up @@ -1222,7 +1222,7 @@ static BaseType_t prvFindCacheEntry( const MACAddress_t * pxMACAddress,
{
#if ( ipconfigUSE_IPv4 != 0 )
case pdFALSE_UNSIGNED:
FreeRTOS_OutputARPRequest( pxEndPoint->ipv4_settings.ulIPAddress );
FreeRTOS_OutputARPRequest_Multi( pxEndPoint, pxEndPoint->ipv4_settings.ulIPAddress );
break;
#endif /* ( ipconfigUSE_IPv4 != 0 ) */

Expand Down Expand Up @@ -1264,80 +1264,95 @@ static BaseType_t prvFindCacheEntry( const MACAddress_t * pxMACAddress,
/*-----------------------------------------------------------*/

/**
* @brief Create and send an ARP request packet.
* @brief Create and send an ARP request packet to given IPv4 endpoint.
*
* @param[in] pxEndPoint Endpoint through which the requests should be sent.
* @param[in] ulIPAddress A 32-bit representation of the IP-address whose
* physical (MAC) address is required.
*/
void FreeRTOS_OutputARPRequest( uint32_t ulIPAddress )
void FreeRTOS_OutputARPRequest_Multi( NetworkEndPoint_t * pxEndPoint,
uint32_t ulIPAddress )
{
NetworkBufferDescriptor_t * pxNetworkBuffer;
NetworkEndPoint_t * pxEndPoint;

/* Send an ARP request to every end-point which has the type IPv4,
* and which already has an IP-address assigned. */
for( pxEndPoint = FreeRTOS_FirstEndPoint( NULL );
pxEndPoint != NULL;
pxEndPoint = FreeRTOS_NextEndPoint( NULL, pxEndPoint ) )
if( ( pxEndPoint->bits.bIPv6 == pdFALSE_UNSIGNED ) &&
( pxEndPoint->ipv4_settings.ulIPAddress != 0U ) )
{
if( ( pxEndPoint->bits.bIPv6 == pdFALSE_UNSIGNED ) &&
( pxEndPoint->ipv4_settings.ulIPAddress != 0U ) )
/* This is called from the context of the IP event task, so a block time
* must not be used. */
pxNetworkBuffer = pxGetNetworkBufferWithDescriptor( sizeof( ARPPacket_t ), ( TickType_t ) 0U );

if( pxNetworkBuffer != NULL )
{
/* This is called from the context of the IP event task, so a block time
* must not be used. */
pxNetworkBuffer = pxGetNetworkBufferWithDescriptor( sizeof( ARPPacket_t ), ( TickType_t ) 0U );
pxNetworkBuffer->xIPAddress.ulIP_IPv4 = ulIPAddress;
pxNetworkBuffer->pxEndPoint = pxEndPoint;
pxNetworkBuffer->pxInterface = pxEndPoint->pxNetworkInterface;
vARPGenerateRequestPacket( pxNetworkBuffer );

if( pxNetworkBuffer != NULL )
#if ( ipconfigETHERNET_MINIMUM_PACKET_BYTES > 0 )
{
pxNetworkBuffer->xIPAddress.ulIP_IPv4 = ulIPAddress;
pxNetworkBuffer->pxEndPoint = pxEndPoint;
pxNetworkBuffer->pxInterface = pxEndPoint->pxNetworkInterface;
vARPGenerateRequestPacket( pxNetworkBuffer );

#if ( ipconfigETHERNET_MINIMUM_PACKET_BYTES > 0 )
if( pxNetworkBuffer->xDataLength < ( size_t ) ipconfigETHERNET_MINIMUM_PACKET_BYTES )
{
if( pxNetworkBuffer->xDataLength < ( size_t ) ipconfigETHERNET_MINIMUM_PACKET_BYTES )
{
BaseType_t xIndex;
BaseType_t xIndex;

for( xIndex = ( BaseType_t ) pxNetworkBuffer->xDataLength; xIndex < ( BaseType_t ) ipconfigETHERNET_MINIMUM_PACKET_BYTES; xIndex++ )
{
pxNetworkBuffer->pucEthernetBuffer[ xIndex ] = 0U;
}

pxNetworkBuffer->xDataLength = ( size_t ) ipconfigETHERNET_MINIMUM_PACKET_BYTES;
for( xIndex = ( BaseType_t ) pxNetworkBuffer->xDataLength; xIndex < ( BaseType_t ) ipconfigETHERNET_MINIMUM_PACKET_BYTES; xIndex++ )
{
pxNetworkBuffer->pucEthernetBuffer[ xIndex ] = 0U;
}

pxNetworkBuffer->xDataLength = ( size_t ) ipconfigETHERNET_MINIMUM_PACKET_BYTES;
}
#endif /* if( ipconfigETHERNET_MINIMUM_PACKET_BYTES > 0 ) */
}
#endif /* if( ipconfigETHERNET_MINIMUM_PACKET_BYTES > 0 ) */

if( xIsCallingFromIPTask() != pdFALSE )
{
iptraceNETWORK_INTERFACE_OUTPUT( pxNetworkBuffer->xDataLength, pxNetworkBuffer->pucEthernetBuffer );
if( xIsCallingFromIPTask() != pdFALSE )
{
iptraceNETWORK_INTERFACE_OUTPUT( pxNetworkBuffer->xDataLength, pxNetworkBuffer->pucEthernetBuffer );

/* Only the IP-task is allowed to call this function directly. */
if( pxEndPoint->pxNetworkInterface != NULL )
{
( void ) pxEndPoint->pxNetworkInterface->pfOutput( pxEndPoint->pxNetworkInterface, pxNetworkBuffer, pdTRUE );
}
}
else
/* Only the IP-task is allowed to call this function directly. */
if( pxEndPoint->pxNetworkInterface != NULL )
{
IPStackEvent_t xSendEvent;
( void ) pxEndPoint->pxNetworkInterface->pfOutput( pxEndPoint->pxNetworkInterface, pxNetworkBuffer, pdTRUE );
}
}
else
{
IPStackEvent_t xSendEvent;

/* Send a message to the IP-task to send this ARP packet. */
xSendEvent.eEventType = eNetworkTxEvent;
xSendEvent.pvData = pxNetworkBuffer;
/* Send a message to the IP-task to send this ARP packet. */
xSendEvent.eEventType = eNetworkTxEvent;
xSendEvent.pvData = pxNetworkBuffer;

if( xSendEventStructToIPTask( &xSendEvent, ( TickType_t ) portMAX_DELAY ) == pdFAIL )
{
/* Failed to send the message, so release the network buffer. */
vReleaseNetworkBufferAndDescriptor( pxNetworkBuffer );
}
if( xSendEventStructToIPTask( &xSendEvent, ( TickType_t ) portMAX_DELAY ) == pdFAIL )
{
/* Failed to send the message, so release the network buffer. */
vReleaseNetworkBufferAndDescriptor( pxNetworkBuffer );
}
}
}
}
}

/*-----------------------------------------------------------*/

/**
* @brief Create and send an ARP request packet.
*
* @param[in] ulIPAddress A 32-bit representation of the IP-address whose
* physical (MAC) address is required.
*/
void FreeRTOS_OutputARPRequest( uint32_t ulIPAddress )
{
/* Its assumed that IPv4 endpoints belonging to different physical interface
* in the system will have a different subnet, but endpoints on same interface
* may have it. */
NetworkEndPoint_t * pxEndPoint = FreeRTOS_FindEndPointOnNetMask( ulIPAddress, 12 );

if( pxEndPoint != NULL )
{
FreeRTOS_OutputARPRequest_Multi( pxEndPoint, ulIPAddress );
}
}
/*-----------------------------------------------------------*/

/**
Expand Down
39 changes: 16 additions & 23 deletions source/FreeRTOS_DHCP.c
Original file line number Diff line number Diff line change
Expand Up @@ -1378,20 +1378,14 @@
uint8_t * pucUDPPayloadBuffer = NULL;

#if ( ipconfigDHCP_REGISTER_HOSTNAME == 1 )
const char * pucHostName = pcApplicationHostnameHook();
size_t uxNameLength = 0;
const char * pucHostName = pcApplicationHostnameHook();

if( pucHostName != NULL )
{
uxNameLength = strlen( pucHostName );
}

uint8_t * pucPtr;

/* memcpy() helper variables for MISRA Rule 21.15 compliance*/
const void * pvCopySource;
void * pvCopyDest;

/* Two extra bytes for option code and length. */
uxRequiredBufferSize += ( 2U + uxNameLength );
#endif /* if ( ipconfigDHCP_REGISTER_HOSTNAME == 1 ) */
Expand All @@ -1402,6 +1396,8 @@

if( pxNetworkBuffer != NULL )
{
uint8_t * pucIPType;

/* Leave space for the UDP header. */
pucUDPPayloadBuffer = &( pxNetworkBuffer->pucEthernetBuffer[ ipUDP_PAYLOAD_OFFSET_IPv4 ] );

Expand All @@ -1410,20 +1406,16 @@
/* coverity[misra_c_2012_rule_11_3_violation] */
pxDHCPMessage = ( ( DHCPMessage_IPv4_t * ) pucUDPPayloadBuffer );

{
uint8_t * pucIPType;

/* Store the IP type at a known location.
* Later the type must be known to translate
* a payload- to a network buffer.
*/
/* Store the IP type at a known location.
* Later the type must be known to translate
* a payload- to a network buffer.
*/

/* MISRA Ref 18.4.1 [Usage of +, -, += and -= operators on expression of pointer type]. */
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-184. */
/* coverity[misra_c_2012_rule_18_4_violation] */
pucIPType = pucUDPPayloadBuffer - ipUDP_PAYLOAD_IP_TYPE_OFFSET;
*pucIPType = ipTYPE_IPv4;
}
/* MISRA Ref 18.4.1 [Usage of +, -, += and -= operators on expression of pointer type]. */
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-184. */
/* coverity[misra_c_2012_rule_18_4_violation] */
pucIPType = pucUDPPayloadBuffer - ipUDP_PAYLOAD_IP_TYPE_OFFSET;
*pucIPType = ipTYPE_IPv4;

/* Most fields need to be zero. */
( void ) memset( pxDHCPMessage, 0x00, sizeof( DHCPMessage_IPv4_t ) );
Expand Down Expand Up @@ -1455,7 +1447,7 @@
* it easier to lookup a device in a router's list of DHCP clients. */

/* Point to where the OPTION_END was stored to add data. */
pucPtr = &( pucUDPPayloadBuffer[ dhcpFIRST_OPTION_BYTE_OFFSET + ( *pxOptionsArraySize - 1U ) ] );
uint8_t * pucPtr = &( pucUDPPayloadBuffer[ dhcpFIRST_OPTION_BYTE_OFFSET + ( *pxOptionsArraySize - 1U ) ] );
pucPtr[ 0U ] = dhcpIPv4_DNS_HOSTNAME_OPTIONS_CODE;
pucPtr[ 1U ] = ( uint8_t ) uxNameLength;

Expand All @@ -1466,8 +1458,9 @@
*/
if( pucHostName != NULL )
{
pvCopySource = pucHostName;
pvCopyDest = &pucPtr[ 2U ];
/* memcpy() helper variables for MISRA Rule 21.15 compliance*/
const void * pvCopySource = pucHostName;
void * pvCopyDest = &pucPtr[ 2U ];

( void ) memcpy( pvCopyDest, pvCopySource, uxNameLength );
}
Expand Down
40 changes: 21 additions & 19 deletions source/FreeRTOS_DHCPv6.c
Original file line number Diff line number Diff line change
Expand Up @@ -1004,6 +1004,18 @@ static void prvSendDHCPMessage( NetworkEndPoint_t * pxEndPoint )

if( ucMessageType != 0U )
{
/* DHCPv6_Option_IA_for_Prefix_Delegation */
uint32_t ulIAID = 0x27fe8f95;
uint32_t ulTime_1 = 3600U;
uint32_t ulTime_2 = 5400U;

/* DHCPv6_Option_IA_Prefix */
uint32_t ulPreferredLifeTime = 4500U;
uint32_t ulPValidLifeTime = 7200U;
uint8_t ucPrefixLength = ( uint8_t ) pxEndPoint->ipv6_settings.uxPrefixLength;

struct freertos_sockaddr * pxAddress;

vBitConfig_write_8( &( xMessage ), ucMessageType ); /* 1 Solicit, 3, request */
vBitConfig_write_uc( &( xMessage ), pxDHCPMessage->ucTransactionID, 3 );

Expand Down Expand Up @@ -1040,25 +1052,15 @@ static void prvSendDHCPMessage( NetworkEndPoint_t * pxEndPoint )
}

/* DHCPv6_Option_Elapsed_Time */
vBitConfig_write_16( &( xMessage ), DHCPv6_Option_Elapsed_Time ); /* usOption; Option is 8 * / */
vBitConfig_write_16( &( xMessage ), 2U ); /* usLength; length is 2 * / */
vBitConfig_write_16( &( xMessage ), 0x0000 ); /* usTime; 00 00 : 0 ms. * / */
vBitConfig_write_16( &( xMessage ), DHCPv6_Option_Elapsed_Time ); /* usOption; Option is 8 * / */
vBitConfig_write_16( &( xMessage ), 2U ); /* usLength; length is 2 * / */
vBitConfig_write_16( &( xMessage ), 0x0000 ); /* usTime; 00 00 : 0 ms. * / */

/* DHCPv6_Option_IA_for_Prefix_Delegation */
uint32_t ulIAID = 0x27fe8f95;
uint32_t ulTime_1 = 3600U;
uint32_t ulTime_2 = 5400U;

vBitConfig_write_16( &( xMessage ), DHCPv6_Option_IA_for_Prefix_Delegation ); /* usOption; Option is 25 */
vBitConfig_write_16( &( xMessage ), 41 ); /* usLength; length is 12 + 29 = 41 */
vBitConfig_write_32( &( xMessage ), ulIAID ); /* 27 fe 8f 95. */
vBitConfig_write_32( &( xMessage ), ulTime_1 ); /* 00 00 0e 10: 3600 sec */
vBitConfig_write_32( &( xMessage ), ulTime_2 ); /* 00 00 15 18: 5400 sec */

/* DHCPv6_Option_IA_Prefix */
uint32_t ulPreferredLifeTime = 4500U;
uint32_t ulPValidLifeTime = 7200U;
uint8_t ucPrefixLength = ( uint8_t ) pxEndPoint->ipv6_settings.uxPrefixLength;
vBitConfig_write_16( &( xMessage ), DHCPv6_Option_IA_for_Prefix_Delegation ); /* usOption; Option is 25 */
vBitConfig_write_16( &( xMessage ), 41 ); /* usLength; length is 12 + 29 = 41 */
vBitConfig_write_32( &( xMessage ), ulIAID ); /* 27 fe 8f 95. */
vBitConfig_write_32( &( xMessage ), ulTime_1 ); /* 00 00 0e 10: 3600 sec */
vBitConfig_write_32( &( xMessage ), ulTime_2 ); /* 00 00 15 18: 5400 sec */

vBitConfig_write_16( &( xMessage ), DHCPv6_Option_IA_Prefix ); /* usOption Option is 26 */
vBitConfig_write_16( &( xMessage ), 25 ); /* usLength length is 25 */
Expand All @@ -1085,7 +1087,7 @@ static void prvSendDHCPMessage( NetworkEndPoint_t * pxEndPoint )
xAddress.sin_family = FREERTOS_AF_INET6;
xAddress.sin_port = FreeRTOS_htons( ipDHCPv6_SERVER_PORT );

struct freertos_sockaddr * pxAddress = &( xAddress );
pxAddress = &( xAddress );

FreeRTOS_printf( ( "DHCP Sending request %u.\n", ucMessageType ) );
( void ) FreeRTOS_sendto( EP_DHCPData.xDHCPSocket, ( const void * ) xMessage.ucContents, xMessage.uxIndex, 0, pxAddress, sizeof xAddress );
Expand Down
Loading

0 comments on commit e710ebe

Please sign in to comment.