Skip to content

Commit

Permalink
Fix NS NA response and routing
Browse files Browse the repository at this point in the history
  • Loading branch information
tony-josi-aws committed Feb 28, 2024
1 parent e0713c6 commit 49f7bb3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 55 deletions.
16 changes: 7 additions & 9 deletions source/FreeRTOS_ND.c
Original file line number Diff line number Diff line change
Expand Up @@ -1058,16 +1058,14 @@
{
size_t uxICMPSize;
BaseType_t xCompare;
NetworkEndPoint_t * pxEndPointFound = FreeRTOS_InterfaceEndPointOnNetMask_IPv6(pxNetworkBuffer->pxInterface, &(pxICMPHeader_IPv6->xIPv6Address), 5);
NetworkEndPoint_t * pxTargetedEndPoint = pxEndPoint;
NetworkEndPoint_t * pxEndPointFound = FreeRTOS_InterfaceEndPointOnNetMask_IPv6(pxNetworkBuffer->pxInterface, &(pxICMPHeader_IPv6->xIPv6Address), 2);

if( pxEndPointFound != NULL )
{
pxEndPoint = pxEndPointFound;
pxTargetedEndPoint = pxEndPointFound;
}

pxNetworkBuffer->pxEndPoint = pxEndPoint;
pxNetworkBuffer->pxInterface = pxEndPoint->pxNetworkInterface;

uxICMPSize = sizeof( ICMPHeader_IPv6_t );
uxNeededSize = ( size_t ) ( ipSIZE_OF_ETH_HEADER + ipSIZE_OF_IPv6_HEADER + uxICMPSize );

Expand All @@ -1077,11 +1075,11 @@
break;
}

xCompare = memcmp( pxICMPHeader_IPv6->xIPv6Address.ucBytes, pxEndPoint->ipv6_settings.xIPAddress.ucBytes, ipSIZE_OF_IPv6_ADDRESS );
xCompare = memcmp( pxICMPHeader_IPv6->xIPv6Address.ucBytes, pxTargetedEndPoint->ipv6_settings.xIPAddress.ucBytes, ipSIZE_OF_IPv6_ADDRESS );

FreeRTOS_printf( ( "ND NS for %pip endpoint %pip %s\n",
( void * ) pxICMPHeader_IPv6->xIPv6Address.ucBytes,
( void * ) pxEndPoint->ipv6_settings.xIPAddress.ucBytes,
( void * ) pxNetworkBuffer->pxEndPoint->ipv6_settings.xIPAddress.ucBytes,
( xCompare == 0 ) ? "Reply" : "Ignore" ) );

if( xCompare == 0 )
Expand All @@ -1095,9 +1093,9 @@
pxICMPHeader_IPv6->ucOptionType = ndICMP_TARGET_LINK_LAYER_ADDRESS;
/* Length of option in units of 8 bytes. */
pxICMPHeader_IPv6->ucOptionLength = 1U;
( void ) memcpy( pxICMPHeader_IPv6->ucOptionBytes, pxEndPoint->xMACAddress.ucBytes, sizeof( MACAddress_t ) );
( void ) memcpy( pxICMPHeader_IPv6->ucOptionBytes, pxTargetedEndPoint->xMACAddress.ucBytes, sizeof( MACAddress_t ) );
pxICMPPacket->xIPHeader.ucHopLimit = 255U;
( void ) memcpy( pxICMPHeader_IPv6->xIPv6Address.ucBytes, pxEndPoint->ipv6_settings.xIPAddress.ucBytes, sizeof( pxICMPHeader_IPv6->xIPv6Address.ucBytes ) );
( void ) memcpy( pxICMPHeader_IPv6->xIPv6Address.ucBytes, pxTargetedEndPoint->ipv6_settings.xIPAddress.ucBytes, sizeof( pxICMPHeader_IPv6->xIPv6Address.ucBytes ) );
prvReturnICMP_IPv6( pxNetworkBuffer, uxICMPSize );
}
}
Expand Down
56 changes: 10 additions & 46 deletions source/FreeRTOS_Routing.c
Original file line number Diff line number Diff line change
Expand Up @@ -442,22 +442,7 @@ struct xIPv6_Couple
*/
NetworkEndPoint_t * FreeRTOS_FindEndPointOnIP_IPv6( const IPv6_Address_t * pxIPAddress )
{
NetworkEndPoint_t * pxEndPoint = pxNetworkEndPoints;

while( pxEndPoint != NULL )
{
if( pxEndPoint->bits.bIPv6 != pdFALSE_UNSIGNED )
{
if( xCompareIPv6_Address( &( pxEndPoint->ipv6_settings.xIPAddress ), pxIPAddress, pxEndPoint->ipv6_settings.uxPrefixLength ) == 0 )
{
break;
}
}

pxEndPoint = pxEndPoint->pxNext;
}

return pxEndPoint;
return FreeRTOS_InterfaceEndPointOnNetMask_IPv6(NULL, pxIPAddress, 1);
}
#endif /* ipconfigUSE_IPv6 */
/*-----------------------------------------------------------*/
Expand Down Expand Up @@ -609,24 +594,18 @@ struct xIPv6_Couple

/* Find the best fitting end-point to reach a given IP-address. */

/*_RB_ Presumably then a broadcast reply could go out on a different end point to that on
* which the broadcast was received - although that should not be an issue if the nodes are
* on the same LAN it could be an issue if the nodes are on separate LAN's. */

while( pxEndPoint != NULL )
{
if( ( pxInterface == NULL ) || ( pxEndPoint->pxNetworkInterface == pxInterface ) )
{
if( pxEndPoint->bits.bIPv6 != pdFALSE_UNSIGNED )

if( pxEndPoint->bits.bIPv6 != pdFALSE_UNSIGNED )
{
if( xCompareIPv6_Address( &( pxEndPoint->ipv6_settings.xIPAddress ), pxIPAddress, pxEndPoint->ipv6_settings.uxPrefixLength ) == 0 )
{
if( xCompareIPv6_Address( &( pxEndPoint->ipv6_settings.xIPAddress ), pxIPAddress, pxEndPoint->ipv6_settings.uxPrefixLength ) == 0 )
{
/* Found a match. */
break;
}
/* Found a match. */
break;
}

}
}

pxEndPoint = pxEndPoint->pxNext;
Expand All @@ -635,8 +614,8 @@ struct xIPv6_Couple
/* This was only for debugging. */
if( pxEndPoint == NULL )
{
// FreeRTOS_debug_printf( ( "FreeRTOS_FindEndPointOnNetMask[%d]: No match for %xip\n",
// ( unsigned ) ulWhere, ( unsigned ) FreeRTOS_ntohl( ulIPAddress ) ) );
FreeRTOS_debug_printf( ( "FreeRTOS_InterfaceEndPointOnNetMask_IPv6[%d]: No match for %pip\n",
( unsigned ) ulWhere, pxEndPoint->ipv6_settings.xIPAddress ) );
}

return pxEndPoint;
Expand Down Expand Up @@ -723,22 +702,7 @@ struct xIPv6_Couple
*/
NetworkEndPoint_t * FreeRTOS_FindEndPointOnNetMask_IPv6( const IPv6_Address_t * pxIPv6Address )
{
NetworkEndPoint_t * pxEndPoint = pxNetworkEndPoints;

while( pxEndPoint != NULL )
{
if( pxEndPoint->bits.bIPv6 != pdFALSE_UNSIGNED )
{
if( xCompareIPv6_Address( &( pxEndPoint->ipv6_settings.xIPAddress ), pxIPv6Address, pxEndPoint->ipv6_settings.uxPrefixLength ) == 0 )
{
break;
}
}

pxEndPoint = pxEndPoint->pxNext;
}

return pxEndPoint;
return FreeRTOS_InterfaceEndPointOnNetMask_IPv6(NULL, pxIPv6Address, 0);
}
#endif /* ipconfigUSE_IPv6 */
/*-----------------------------------------------------------*/
Expand Down

0 comments on commit 49f7bb3

Please sign in to comment.