Skip to content

Commit

Permalink
remove ipconfigHAS_ROUTING_STATISTICS
Browse files Browse the repository at this point in the history
  • Loading branch information
HTRamsey committed May 5, 2024
1 parent 86b16eb commit a360292
Show file tree
Hide file tree
Showing 20 changed files with 69 additions and 188 deletions.
16 changes: 8 additions & 8 deletions source/FreeRTOS_ARP.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ _static ARPCacheRow_t xARPCache[ ipconfigARP_CACHE_ENTRIES ];
/* Process received ARP frame to see if there is a clash. */
#if ( ipconfigARP_USE_CLASH_DETECTION != 0 )
{
NetworkEndPoint_t * pxSourceEndPoint = FreeRTOS_FindEndPointOnIP_IPv4( ulSenderProtocolAddress, 2 );
NetworkEndPoint_t * pxSourceEndPoint = FreeRTOS_FindEndPointOnIP_IPv4( ulSenderProtocolAddress );

if( ( pxSourceEndPoint != NULL ) && ( pxSourceEndPoint->ipv4_settings.ulIPAddress == ulSenderProtocolAddress ) )
{
Expand Down Expand Up @@ -699,7 +699,7 @@ void vARPRefreshCacheEntry( const MACAddress_t * pxMACAddress,
{
#if ( ipconfigARP_STORES_REMOTE_ADDRESSES == 0 )
/* Only process the IP address if it is on the local network. */
BaseType_t xAddressIsLocal = ( FreeRTOS_FindEndPointOnNetMask( ulIPAddress, 2 ) != NULL ) ? 1 : 0; /* ARP remote address. */
BaseType_t xAddressIsLocal = ( FreeRTOS_FindEndPointOnNetMask( ulIPAddress ) != NULL ) ? 1 : 0; /* ARP remote address. */

/* Only process the IP address if it matches with one of the end-points. */
if( xAddressIsLocal != 0 )
Expand Down Expand Up @@ -789,7 +789,7 @@ static BaseType_t prvFindCacheEntry( const MACAddress_t * pxMACAddress,
BaseType_t xReturn = pdFALSE;

#if ( ipconfigARP_STORES_REMOTE_ADDRESSES != 0 )
BaseType_t xAddressIsLocal = ( FreeRTOS_FindEndPointOnNetMask( ulIPAddress, 2 ) != NULL ) ? 1 : 0; /* ARP remote address. */
BaseType_t xAddressIsLocal = ( FreeRTOS_FindEndPointOnNetMask( ulIPAddress ) != NULL ) ? 1 : 0; /* ARP remote address. */
#endif

/* Start with the maximum possible number. */
Expand Down Expand Up @@ -855,7 +855,7 @@ static BaseType_t prvFindCacheEntry( const MACAddress_t * pxMACAddress,
/* If ARP stores the MAC address of IP addresses outside the
* network, than the MAC address of the gateway should not be
* overwritten. */
BaseType_t xOtherIsLocal = ( FreeRTOS_FindEndPointOnNetMask( xARPCache[ x ].ulIPAddress, 3 ) != NULL ) ? 1 : 0; /* ARP remote address. */
BaseType_t xOtherIsLocal = ( FreeRTOS_FindEndPointOnNetMask( xARPCache[ x ].ulIPAddress ) != NULL ) ? 1 : 0; /* ARP remote address. */

if( xAddressIsLocal == xOtherIsLocal )
{
Expand Down Expand Up @@ -972,7 +972,7 @@ static BaseType_t prvFindCacheEntry( const MACAddress_t * pxMACAddress,

*( ppxEndPoint ) = NULL;
ulAddressToLookup = *pulIPAddress;
pxEndPoint = FreeRTOS_FindEndPointOnIP_IPv4( ulAddressToLookup, 0 );
pxEndPoint = FreeRTOS_FindEndPointOnIP_IPv4( ulAddressToLookup );

if( xIsIPv4Multicast( ulAddressToLookup ) != 0 )
{
Expand All @@ -999,7 +999,7 @@ static BaseType_t prvFindCacheEntry( const MACAddress_t * pxMACAddress,
{
/* This is a broadcast so it uses the broadcast MAC address. */
( void ) memcpy( pxMACAddress->ucBytes, xBroadcastMACAddress.ucBytes, sizeof( MACAddress_t ) );
pxEndPoint = FreeRTOS_FindEndPointOnNetMask( ulAddressToLookup, 4 );
pxEndPoint = FreeRTOS_FindEndPointOnNetMask( ulAddressToLookup );

if( pxEndPoint != NULL )
{
Expand Down Expand Up @@ -1036,7 +1036,7 @@ static BaseType_t prvFindCacheEntry( const MACAddress_t * pxMACAddress,

/* It is assumed that devices with the same netmask are on the same
* LAN and don't need a gateway. */
pxEndPoint = FreeRTOS_FindEndPointOnNetMask( ulAddressToLookup, 4 );
pxEndPoint = FreeRTOS_FindEndPointOnNetMask( ulAddressToLookup );

if( pxEndPoint == NULL )
{
Expand Down Expand Up @@ -1346,7 +1346,7 @@ static BaseType_t prvFindCacheEntry( const MACAddress_t * pxMACAddress,
/* 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 );
NetworkEndPoint_t * pxEndPoint = FreeRTOS_FindEndPointOnNetMask( ulIPAddress );

if( pxEndPoint != NULL )
{
Expand Down
2 changes: 1 addition & 1 deletion source/FreeRTOS_IP.c
Original file line number Diff line number Diff line change
Expand Up @@ -2123,7 +2123,7 @@ void vReturnEthernetFrame( NetworkBufferDescriptor_t * pxNetworkBuffer,

#if ( ipconfigUSE_IPv4 != 0 )
case ipIPv4_FRAME_TYPE:
pxNetworkBuffer->pxEndPoint = FreeRTOS_FindEndPointOnNetMask( pxIPPacket->xIPHeader.ulDestinationIPAddress, 7 );
pxNetworkBuffer->pxEndPoint = FreeRTOS_FindEndPointOnNetMask( pxIPPacket->xIPHeader.ulDestinationIPAddress );
break;
#endif /* ( ipconfigUSE_IPv4 != 0 ) */

Expand Down
2 changes: 1 addition & 1 deletion source/FreeRTOS_IPv4.c
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ enum eFrameProcessingResult prvAllowIPPacketIPv4( const struct xIP_PACKET * cons
}
}
else if(
( FreeRTOS_FindEndPointOnIP_IPv4( ulDestinationIPAddress, 4 ) == NULL ) &&
( FreeRTOS_FindEndPointOnIP_IPv4( ulDestinationIPAddress ) == NULL ) &&
/* Is it an IPv4 broadcast address x.x.x.255 ? */
( ( FreeRTOS_ntohl( ulDestinationIPAddress ) & 0xffU ) != 0xffU ) &&
( xIsIPv4Multicast( ulDestinationIPAddress ) == pdFALSE ) &&
Expand Down
82 changes: 10 additions & 72 deletions source/FreeRTOS_Routing.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,6 @@ struct xIPv6_Couple

#if ( ipconfigCOMPATIBLE_WITH_SINGLE == 0 )

#if ( ipconfigHAS_ROUTING_STATISTICS == 1 )
RoutingStats_t xRoutingStatistics;
#endif

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

/**
* @brief Add a network interface to the list of interfaces. Check if the interface was
* already added in an earlier call.
Expand Down Expand Up @@ -379,29 +373,13 @@ struct xIPv6_Couple
* @brief Find the end-point which has a given IPv4 address.
*
* @param[in] ulIPAddress The IP-address of interest, or 0 if any IPv4 end-point may be returned.
* @param[in] ulWhere For maintaining routing statistics ulWhere acts as an index to the data structure
* that keep track of the number of times 'FreeRTOS_FindEndPointOnIP_IPv4()'
* has been called from a particular location. Used only if
* ipconfigHAS_ROUTING_STATISTICS is enabled.
*
* @return The end-point found or NULL.
*/
NetworkEndPoint_t * FreeRTOS_FindEndPointOnIP_IPv4( uint32_t ulIPAddress,
uint32_t ulWhere )
NetworkEndPoint_t * FreeRTOS_FindEndPointOnIP_IPv4( uint32_t ulIPAddress )
{
NetworkEndPoint_t * pxEndPoint = pxNetworkEndPoints;

#if ( ipconfigHAS_ROUTING_STATISTICS == 1 )
uint32_t ulLocationCount = ( uint32_t ) ( sizeof( xRoutingStatistics.ulLocationsIP ) / sizeof( xRoutingStatistics.ulLocationsIP[ 0 ] ) );

xRoutingStatistics.ulOnIp++;

if( ulWhere < ulLocationCount )
{
xRoutingStatistics.ulLocationsIP[ ulWhere ]++;
}
#endif /* ( ipconfigHAS_ROUTING_STATISTICS == 1 ) */

while( pxEndPoint != NULL )
{
#if ( ipconfigUSE_IPv4 != 0 )
Expand Down Expand Up @@ -456,12 +434,6 @@ struct xIPv6_Couple
{
NetworkEndPoint_t * pxEndPoint = pxNetworkEndPoints;

#if ( ipconfigHAS_ROUTING_STATISTICS == 1 )
{
xRoutingStatistics.ulOnMAC++;
}
#endif

/* If input MAC address is NULL, return NULL. */
if( pxMACAddress == NULL )
{
Expand Down Expand Up @@ -495,18 +467,12 @@ struct xIPv6_Couple
* @brief Find an end-point that handles a given IPv4-address.
*
* @param[in] ulIPAddress The IP-address for which an end-point is looked-up.
* @param[in] ulWhere For maintaining routing statistics ulWhere acts as an index to the data structure
* that keep track of the number of times 'FreeRTOS_InterfaceEndPointOnNetMask()'
* has been called from a particular location. Used only if
* ipconfigHAS_ROUTING_STATISTICS is enabled.
*
* @return An end-point that has the same network mask as the given IP-address.
*/
NetworkEndPoint_t * FreeRTOS_FindEndPointOnNetMask( uint32_t ulIPAddress,
uint32_t ulWhere )
NetworkEndPoint_t * FreeRTOS_FindEndPointOnNetMask( uint32_t ulIPAddress )
{
/* The 'ulWhere' parameter is only for debugging purposes. */
return FreeRTOS_InterfaceEndPointOnNetMask( NULL, ulIPAddress, ulWhere );
return FreeRTOS_InterfaceEndPointOnNetMask( NULL, ulIPAddress );
}
/*-----------------------------------------------------------*/

Expand All @@ -517,30 +483,13 @@ struct xIPv6_Couple
* pxInterface is NULL.
* @param[in] ulIPAddress The IP-address for which an end-point is looked-up.
*
* @param[in] ulWhere For maintaining routing statistics ulWhere acts as an index to the data structure
* that keep track of the number of times 'FreeRTOS_InterfaceEndPointOnNetMask()'
* has been called from a particular location. Used only if
* ipconfigHAS_ROUTING_STATISTICS is enabled.
*
* @return An end-point that has the same network mask as the given IP-address.
*/
NetworkEndPoint_t * FreeRTOS_InterfaceEndPointOnNetMask( const NetworkInterface_t * pxInterface,
uint32_t ulIPAddress,
uint32_t ulWhere )
uint32_t ulIPAddress )
{
NetworkEndPoint_t * pxEndPoint = pxNetworkEndPoints;

#if ( ipconfigHAS_ROUTING_STATISTICS == 1 )
uint32_t ulLocationCount = ( uint32_t ) ( sizeof( xRoutingStatistics.ulLocations ) / sizeof( xRoutingStatistics.ulLocations[ 0 ] ) );

xRoutingStatistics.ulOnNetMask++;

if( ulWhere < ulLocationCount )
{
xRoutingStatistics.ulLocations[ ulWhere ]++;
}
#endif /* ( ipconfigHAS_ROUTING_STATISTICS == 1 ) */

/* 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
Expand Down Expand Up @@ -572,8 +521,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_FindEndPointOnNetMask: No match for %xip\n",
( unsigned ) FreeRTOS_ntohl( ulIPAddress ) ) );
}

return pxEndPoint;
Expand Down Expand Up @@ -930,12 +879,6 @@ struct xIPv6_Couple
* defined end-point has the best match.
*/

#if ( ipconfigHAS_ROUTING_STATISTICS == 1 )
{
/* Some stats while developing. */
xRoutingStatistics.ulMatching++;
}
#endif
{
uint16_t usFrameType = pxPacket->xUDPPacket.xEthernetHeader.usFrameType;
IP_Address_t xIPAddressFrom;
Expand Down Expand Up @@ -1216,13 +1159,11 @@ struct xIPv6_Couple
*
* @return The end-point found or NULL.
*/
NetworkEndPoint_t * FreeRTOS_FindEndPointOnIP_IPv4( uint32_t ulIPAddress,
uint32_t ulWhere )
NetworkEndPoint_t * FreeRTOS_FindEndPointOnIP_IPv4( uint32_t ulIPAddress )
{
NetworkEndPoint_t * pxResult = NULL;

( void ) ulIPAddress;
( void ) ulWhere;

if( ( ulIPAddress == 0U ) || ( pxNetworkEndPoints->ipv4_settings.ulIPAddress == ulIPAddress ) )
{
Expand Down Expand Up @@ -1265,10 +1206,9 @@ struct xIPv6_Couple
*
* @return An end-point that has the same network mask as the given IP-address.
*/
NetworkEndPoint_t * FreeRTOS_FindEndPointOnNetMask( uint32_t ulIPAddress,
uint32_t ulWhere )
NetworkEndPoint_t * FreeRTOS_FindEndPointOnNetMask( uint32_t ulIPAddress )
{
return FreeRTOS_InterfaceEndPointOnNetMask( NULL, ulIPAddress, ulWhere );
return FreeRTOS_InterfaceEndPointOnNetMask( NULL, ulIPAddress );
}
/*-----------------------------------------------------------*/

Expand Down Expand Up @@ -1337,13 +1277,11 @@ struct xIPv6_Couple
* @return An end-point that has the same network mask as the given IP-address.
*/
NetworkEndPoint_t * FreeRTOS_InterfaceEndPointOnNetMask( const NetworkInterface_t * pxInterface,
uint32_t ulIPAddress,
uint32_t ulWhere )
uint32_t ulIPAddress )
{
NetworkEndPoint_t * pxResult = NULL;

( void ) pxInterface;
( void ) ulWhere;

if( ( ( ulIPAddress ^ pxNetworkEndPoints->ipv4_settings.ulIPAddress ) & pxNetworkEndPoints->ipv4_settings.ulNetMask ) == 0U )
{
Expand Down
2 changes: 1 addition & 1 deletion source/FreeRTOS_Sockets.c
Original file line number Diff line number Diff line change
Expand Up @@ -1821,7 +1821,7 @@ static BaseType_t prvSocketBindAdd( FreeRTOS_Socket_t * pxSocket,
#if ( ipconfigUSE_IPv4 != 0 )
if( pxAddress->sin_address.ulIP_IPv4 != FREERTOS_INADDR_ANY )
{
pxSocket->pxEndPoint = FreeRTOS_FindEndPointOnIP_IPv4( pxAddress->sin_address.ulIP_IPv4, 7 );
pxSocket->pxEndPoint = FreeRTOS_FindEndPointOnIP_IPv4( pxAddress->sin_address.ulIP_IPv4 );
}
else
#endif /* ( ipconfigUSE_IPv4 != 0 ) */
Expand Down
2 changes: 1 addition & 1 deletion source/FreeRTOS_TCP_Transmission.c
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,7 @@
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */
/* coverity[misra_c_2012_rule_11_3_violation] */
pxIPHeader = ( ( IPHeader_t * ) &( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER ] ) );
pxNetworkBuffer->pxEndPoint = FreeRTOS_FindEndPointOnNetMask( pxIPHeader->ulDestinationIPAddress, 8 );
pxNetworkBuffer->pxEndPoint = FreeRTOS_FindEndPointOnNetMask( pxIPHeader->ulDestinationIPAddress );

if( pxNetworkBuffer->pxEndPoint == NULL )
{
Expand Down
2 changes: 1 addition & 1 deletion source/FreeRTOS_UDP_IPv4.c
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ void vProcessGeneratedUDPPacket_IPv4( NetworkBufferDescriptor_t * const pxNetwor
/* 'ulIPAddress' might have become the address of the Gateway.
* Find the route again. */

pxNetworkBuffer->pxEndPoint = FreeRTOS_FindEndPointOnNetMask( pxNetworkBuffer->xIPAddress.ulIP_IPv4, 11 );
pxNetworkBuffer->pxEndPoint = FreeRTOS_FindEndPointOnNetMask( pxNetworkBuffer->xIPAddress.ulIP_IPv4 );

if( pxNetworkBuffer->pxEndPoint == NULL )
{
Expand Down
16 changes: 0 additions & 16 deletions source/include/FreeRTOSIPConfigDefaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -3056,22 +3056,6 @@ STATIC_ASSERT( ipconfigDNS_SEND_BLOCK_TIME_TICKS <= portMAX_DELAY );

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

/*
* ipconfigHAS_ROUTING_STATISTICS
*
* Type: BaseType_t ( ipconfigENABLE | ipconfigDISABLE )
*/

#ifndef ipconfigHAS_ROUTING_STATISTICS
#define ipconfigHAS_ROUTING_STATISTICS ipconfigENABLE
#endif

#if ( ( ipconfigHAS_ROUTING_STATISTICS != ipconfigDISABLE ) && ( ipconfigHAS_ROUTING_STATISTICS != ipconfigENABLE ) )
#error Invalid ipconfigHAS_ROUTING_STATISTICS configuration
#endif

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

/*===========================================================================*/
/* ROUTING CONFIG */
/*===========================================================================*/
Expand Down
26 changes: 3 additions & 23 deletions source/include/FreeRTOS_Routing.h
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,7 @@
/*
* Find the end-point with given IP-address.
*/
NetworkEndPoint_t * FreeRTOS_FindEndPointOnIP_IPv4( uint32_t ulIPAddress,
uint32_t ulWhere );
NetworkEndPoint_t * FreeRTOS_FindEndPointOnIP_IPv4( uint32_t ulIPAddress );

#if ( ipconfigUSE_IPv6 != 0 )
/* Find the end-point with given IP-address. */
Expand All @@ -283,18 +282,14 @@
/*
* Find the best fitting end-point to reach a given IP-address.
* Find an end-point whose IP-address is in the same network as the IP-address provided.
* 'ulWhere' is temporary and or debugging only.
*/
NetworkEndPoint_t * FreeRTOS_FindEndPointOnNetMask( uint32_t ulIPAddress,
uint32_t ulWhere );
NetworkEndPoint_t * FreeRTOS_FindEndPointOnNetMask( uint32_t ulIPAddress );

/*
* Find the best fitting IPv4 end-point to reach a given IP-address on a given interface
* 'ulWhere' is temporary and or debugging only.
*/
NetworkEndPoint_t * FreeRTOS_InterfaceEndPointOnNetMask( const NetworkInterface_t * pxInterface,
uint32_t ulIPAddress,
uint32_t ulWhere );
uint32_t ulIPAddress );

/*
* Finds an endpoint on the given interface which is in the same subnet as the
Expand Down Expand Up @@ -345,21 +340,6 @@
const uint8_t ucMACAddress[ ipMAC_ADDRESS_LENGTH_BYTES ] );
#endif

#if ( ipconfigHAS_ROUTING_STATISTICS == 1 )
/** @brief Some simple network statistics. */
typedef struct xRoutingStats
{
UBaseType_t ulOnIp; /**< The number of times 'FreeRTOS_FindEndPointOnIP_IPv4()' has been called. */
UBaseType_t ulOnMAC; /**< The number of times 'FreeRTOS_FindEndPointOnMAC()' has been called. */
UBaseType_t ulOnNetMask; /**< The number of times 'FreeRTOS_InterfaceEndPointOnNetMask()' has been called. */
UBaseType_t ulMatching; /**< The number of times 'FreeRTOS_MatchingEndpoint()' has been called. */
UBaseType_t ulLocations[ 14 ]; /**< The number of times 'FreeRTOS_InterfaceEndPointOnNetMask()' has been called from a particular location. */
UBaseType_t ulLocationsIP[ 8 ]; /**< The number of times 'FreeRTOS_FindEndPointOnIP_IPv4()' has been called from a particular location. */
} RoutingStats_t;

extern RoutingStats_t xRoutingStatistics;
#endif /* ( ipconfigHAS_ROUTING_STATISTICS == 1 ) */

NetworkEndPoint_t * pxGetSocketEndpoint( ConstSocket_t xSocket );
void vSetSocketEndpoint( Socket_t xSocket,
NetworkEndPoint_t * pxEndPoint );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ NetworkEndPoint_t * FreeRTOS_FindEndPointOnNetMask_IPv6( const IPv6_Address_t *

/* Stub FreeRTOS_FindEndPointOnNetMask_IPv6 as its not relevant to the
* correctness of the proof */
NetworkEndPoint_t * FreeRTOS_FindEndPointOnNetMask( uint32_t ulIPAddress,
uint32_t ulWhere )
NetworkEndPoint_t * FreeRTOS_FindEndPointOnNetMask( uint32_t ulIPAddress )
{
/* Assume at least one end-point is available */
return pxNetworkEndPoint_Temp;
Expand Down
Loading

0 comments on commit a360292

Please sign in to comment.