Skip to content

Commit 8dada70

Browse files
author
Ravi Teja Darbha
committed
Match source IP to an endpoint on same netmask
1 parent 7680800 commit 8dada70

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

source/FreeRTOS_Routing.c

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -658,10 +658,11 @@ struct xIPv6_Couple
658658
* @brief Check IP-type, IP- and MAC-address found in the network packet.
659659
*/
660660
#define rMATCH_IP_ADDR 0 /**< Find an endpoint with a matching IP-address. */
661-
#define rMATCH_IPv6_TYPE 1 /**< Find an endpoint with a matching IPv6 type (both global or non global). */
662-
#define rMATCH_MAC_ADDR 2 /**< Find an endpoint with a matching MAC-address. */
663-
#define rMATCH_IP_TYPE 3 /**< Find an endpoint with a matching IP-type, v4 or v6. */
664-
#define rMATCH_COUNT 4 /**< The number of methods. */
661+
#define rMATCH_NETMASK 1 /**< Find an endpoint with a matching NetMask. */
662+
#define rMATCH_IPv6_TYPE 2 /**< Find an endpoint with a matching IPv6 type (both global or non global). */
663+
#define rMATCH_MAC_ADDR 3 /**< Find an endpoint with a matching MAC-address. */
664+
#define rMATCH_IP_TYPE 4 /**< Find an endpoint with a matching IP-type, v4 or v6. */
665+
#define rMATCH_COUNT 5 /**< The number of methods. */
665666

666667
NetworkEndPoint_t * pxEasyFit( const NetworkInterface_t * pxNetworkInterface,
667668
const uint16_t usFrameType,
@@ -688,9 +689,9 @@ struct xIPv6_Couple
688689
{
689690
NetworkEndPoint_t * pxEndPoint;
690691
NetworkEndPoint_t * pxReturn = NULL;
691-
/* endpoints found for IP-type, IP-address, and MAC-address. */
692-
NetworkEndPoint_t * pxFound[ rMATCH_COUNT ] = { NULL, NULL, NULL, NULL };
693-
BaseType_t xCount[ rMATCH_COUNT ] = { 0, 0, 0, 0 };
692+
/* endpoints found for IP-type, IP-address, NetMask and MAC-address. */
693+
NetworkEndPoint_t * pxFound[ rMATCH_COUNT ] = { NULL, NULL, NULL, NULL, NULL };
694+
BaseType_t xCount[ rMATCH_COUNT ] = { 0, 0, 0, 0, 0 };
694695
BaseType_t xIndex;
695696
BaseType_t xIsIPv6 = ( usFrameType == ipIPv6_FRAME_TYPE ) ? pdTRUE : pdFALSE;
696697
BaseType_t xGatewayTarget = pdFALSE;
@@ -778,6 +779,11 @@ struct xIPv6_Couple
778779
pxFound[ rMATCH_IP_ADDR ] = pxEndPoint;
779780
xCount[ rMATCH_IP_ADDR ]++;
780781
}
782+
else if( FreeRTOS_InterfaceEndPointOnNetMask( pxNetworkInterface, pxIPAddressFrom->ulIP_IPv4 ) == pxEndPoint )
783+
{
784+
pxFound[ rMATCH_NETMASK ] = pxEndPoint;
785+
xCount[ rMATCH_NETMASK ]++;
786+
}
781787
else
782788
{
783789
/* do nothing, coverity happy */
@@ -912,16 +918,11 @@ struct xIPv6_Couple
912918
/* coverity[misra_c_2012_rule_11_3_violation] */
913919
const ARPPacket_t * pxARPFrame = ( const ARPPacket_t * ) pucEthernetBuffer;
914920

915-
if( pxARPFrame->xARPHeader.usOperation == ( uint16_t ) ipARP_REQUEST )
921+
if( ( pxARPFrame->xARPHeader.usOperation == ( uint16_t ) ipARP_REQUEST ) || ( pxARPFrame->xARPHeader.usOperation == ( uint16_t ) ipARP_REPLY ) )
916922
{
917923
( void ) memcpy( xIPAddressFrom.xIP_IPv6.ucBytes, pxPacket->xARPPacket.xARPHeader.ucSenderProtocolAddress, sizeof( uint32_t ) );
918924
xIPAddressTo.ulIP_IPv4 = pxPacket->xARPPacket.xARPHeader.ulTargetProtocolAddress;
919925
}
920-
else if( pxARPFrame->xARPHeader.usOperation == ( uint16_t ) ipARP_REPLY )
921-
{
922-
( void ) memcpy( xIPAddressTo.xIP_IPv6.ucBytes, pxPacket->xARPPacket.xARPHeader.ucSenderProtocolAddress, sizeof( uint32_t ) );
923-
xIPAddressFrom.ulIP_IPv4 = pxPacket->xARPPacket.xARPHeader.ulTargetProtocolAddress;
924-
}
925926
else
926927
{
927928
/* do nothing, coverity happy */

0 commit comments

Comments
 (0)