Skip to content

Commit

Permalink
Do not call xBadIPv4Loopback() when IPv4 is not enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
htibosch committed Sep 8, 2023
1 parent 2422335 commit 9104b2e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 39 deletions.
17 changes: 10 additions & 7 deletions source/FreeRTOS_IP.c
Original file line number Diff line number Diff line change
Expand Up @@ -1715,13 +1715,16 @@ static eFrameProcessingResult_t prvProcessUDPPacket( NetworkBufferDescriptor_t *
{
eReturn = eReleaseBuffer;
}
else if( ( pxUDPPacket->xEthernetHeader.usFrameType == ipIPv4_FRAME_TYPE ) &&
( xBadIPv4Loopback( &( pxUDPPacket->xIPHeader ) ) != pdFALSE ) )
{
/* The local loopback addresses must never appear outside a host. See RFC 1122
* section 3.2.1.3. */
eReturn = eReleaseBuffer;
}

#if ( ipconfigUSE_IPv4 != 0 )
else if( ( pxUDPPacket->xEthernetHeader.usFrameType == ipIPv4_FRAME_TYPE ) &&
( xBadIPv4Loopback( &( pxUDPPacket->xIPHeader ) ) != pdFALSE ) )
{
/* The local loopback addresses must never appear outside a host. See RFC 1122
* section 3.2.1.3. */
eReturn = eReleaseBuffer;
}
#endif
else if( ( pxNetworkBuffer->xDataLength >= uxMinSize ) &&
( uxLength >= sizeof( UDPHeader_t ) ) )
{
Expand Down
64 changes: 32 additions & 32 deletions source/FreeRTOS_Routing.c
Original file line number Diff line number Diff line change
Expand Up @@ -1432,47 +1432,47 @@ struct xIPv6_Couple
* @returns The IP type of the given address.
*/
#if ( ipconfigUSE_IPv6 != 0 )
IPv6_Type_t xIPv6_GetIPType( const IPv6_Address_t * pxAddress )
{
IPv6_Type_t eResult = eIPv6_Unknown;
BaseType_t xIndex;
static const struct xIPv6_Couple xIPCouples[] =
{
/* IP-type Mask Value */
{ eIPv6_Global, 0xE000U, 0x2000U }, /* 001 */
{ eIPv6_LinkLocal, 0xFFC0U, 0xFE80U }, /* 1111 1110 10 */
{ eIPv6_SiteLocal, 0xFFC0U, 0xFEC0U }, /* 1111 1110 11 */
{ eIPv6_Multicast, 0xFF00U, 0xFF00U }, /* 1111 1111 */
{ eIPv6_Loopback, 0xFFFFU, 0x0000U }, /* 0000 0000 ::1 */
};

if( pxAddress != NULL )
IPv6_Type_t xIPv6_GetIPType( const IPv6_Address_t * pxAddress )
{
for( xIndex = 0; xIndex < ARRAY_SIZE_X( xIPCouples ); xIndex++ )
IPv6_Type_t eResult = eIPv6_Unknown;
BaseType_t xIndex;
static const struct xIPv6_Couple xIPCouples[] =
{
uint16_t usAddress =
( uint16_t ) ( ( ( ( uint16_t ) pxAddress->ucBytes[ 0 ] ) << 8 ) |
( ( uint16_t ) pxAddress->ucBytes[ 1 ] ) );

if( xIPCouples[ xIndex ].eType == eIPv6_Loopback )
/* IP-type Mask Value */
{ eIPv6_Global, 0xE000U, 0x2000U }, /* 001 */
{ eIPv6_LinkLocal, 0xFFC0U, 0xFE80U }, /* 1111 1110 10 */
{ eIPv6_SiteLocal, 0xFFC0U, 0xFEC0U }, /* 1111 1110 11 */
{ eIPv6_Multicast, 0xFF00U, 0xFF00U }, /* 1111 1111 */
{ eIPv6_Loopback, 0xFFFFU, 0x0000U }, /* 0000 0000 ::1 */
};

if( pxAddress != NULL )
{
for( xIndex = 0; xIndex < ARRAY_SIZE_X( xIPCouples ); xIndex++ )
{
if( xIsIPv6Loopback( pxAddress ) != pdFALSE )
uint16_t usAddress =
( uint16_t ) ( ( ( ( uint16_t ) pxAddress->ucBytes[ 0 ] ) << 8 ) |
( ( uint16_t ) pxAddress->ucBytes[ 1 ] ) );

if( xIPCouples[ xIndex ].eType == eIPv6_Loopback )
{
eResult = eIPv6_Loopback;
break;
if( xIsIPv6Loopback( pxAddress ) != pdFALSE )
{
eResult = eIPv6_Loopback;
break;
}
}
}

if( ( usAddress & xIPCouples[ xIndex ].usMask ) == xIPCouples[ xIndex ].usExpected )
{
eResult = xIPCouples[ xIndex ].eType;
break;
if( ( usAddress & xIPCouples[ xIndex ].usMask ) == xIPCouples[ xIndex ].usExpected )
{
eResult = xIPCouples[ xIndex ].eType;
break;
}
}
}
}

return eResult;
}
return eResult;
}
#endif /* if ( ipconfigUSE_IPv6 != 0 ) */
/*-----------------------------------------------------------*/

Expand Down

0 comments on commit 9104b2e

Please sign in to comment.