UDP message Linux FreeRTOS not delivered

Hello.

I previously made a post in which I reported that I was unable to make a UDP socket work on Ubuntu. The problem was solved and I got a lot of help from the community, thanks to Richard and Alfred.

If you can help me again, I would be grateful. Let me explain what I want to do:

I want to open an entrance / exit gate of my laboratory using UDP, for that, I run a Java program on a Raspberry Pi that receives a message and it opens or closes.

I have a simulator for this gate and I make it available to students so that they can all use it on their own computers, for obvious reasons, it is undesirable that they all use the same real gate at the same time for testing.

I tried to use the new 10.4.0 Posix / GCC library together with the simulator on the same host to implement it, however, I was unable to make it work. Here, Alfred explains that it is not possible to make them work in the same Ubuntu Box.

I tried a Fedora virtual machine to host the simulator. To check if the connection between my machine and the virtual machine worked, I sent pings and sent UDP packets via command lines, which worked.

When I ran and modified the main_networking.c program for the example shown in:

No packages arrived at the Fedora host.

The program is below:

/*
 * FreeRTOS Kernel V10.4.0
 * Copyright (C) 2020 Amazon.com, Inc. or its affiliates.  All Rights Reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of
 * this software and associated documentation files (the "Software"), to deal in
 * the Software without restriction, including without limitation the rights to
 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
 * the Software, and to permit persons to whom the Software is furnished to do so,
 * subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 * http://www.FreeRTOS.org
 * http://aws.amazon.com/freertos
 *
 * 1 tab == 4 spaces!
 */

/*
 * This project is a cut down version of the project described on the following
 * link.  Only the simple UDP client and server and the TCP echo clients are
 * included in the build:
 * http://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/examples_FreeRTOS_simulator.html
 */

/* Standard includes. */
#include <stdio.h>
#include <time.h>
#include <unistd.h>

/* FreeRTOS includes. */
#include <FreeRTOS.h>
#include "task.h"

/* Demo application includes. */
#include "FreeRTOS_IP.h"
#include "FreeRTOS_Sockets.h"
/*#include "SimpleUDPClientAndServer.h" */
/*#include "SimpleTCPEchoServer.h" */
/*#include "TCPEchoClient_SingleTasks.h" */
/*#include "demo_logging.h" */
#include "TCPEchoClient_SingleTasks.h"

/* Simple UDP client and server task parameters. */
#define mainSIMPLE_UDP_CLIENT_SERVER_TASK_PRIORITY	  ( tskIDLE_PRIORITY )
#define mainSIMPLE_UDP_CLIENT_SERVER_PORT			  ( 5005UL )

/* Echo client task parameters - used for both TCP and UDP echo clients. */
#define mainECHO_CLIENT_TASK_STACK_SIZE				  ( configMINIMAL_STACK_SIZE * 2 )      /* Not used in the linux port. */
#define mainECHO_CLIENT_TASK_PRIORITY				  ( tskIDLE_PRIORITY + 1 )

/* Echo server task parameters. */
#define mainECHO_SERVER_TASK_STACK_SIZE				  ( configMINIMAL_STACK_SIZE * 2 )      /* Not used in the linux port. */
#define mainECHO_SERVER_TASK_PRIORITY				  ( tskIDLE_PRIORITY + 1 )

/* Define a name that will be used for LLMNR and NBNS searches. */
#define mainHOST_NAME								  "RTOSDemo"
#define mainDEVICE_NICK_NAME						  "linux_demo"

/* Set the following constants to 1 or 0 to define which tasks to include and
exclude:

mainCREATE_TCP_ECHO_TASKS_SINGLE:  When set to 1 a set of tasks are created that
send TCP echo requests to the standard echo port (port 7), then wait for and
verify the echo reply, from within the same task (Tx and Rx are performed in the
same RTOS task).  The IP address of the echo server must be configured using the
configECHO_SERVER_ADDR0 to configECHO_SERVER_ADDR3 constants in
FreeRTOSConfig.h.

*/
#define mainCREATE_TCP_ECHO_TASKS_SINGLE			  0
/*-----------------------------------------------------------*/

/*
 * Just seeds the simple pseudo random number generator.
 */
static void prvSRand( UBaseType_t ulSeed );

/*
 * Miscellaneous initialisation including preparing the logging and seeding the
 * random number generator.
 */
static void prvMiscInitialisation( void );

/* The default IP and MAC address used by the demo.  The address configuration
defined here will be used if ipconfigUSE_DHCP is 0, or if ipconfigUSE_DHCP is
1 but a DHCP server could not be contacted.  See the online documentation for
more information. */
static const uint8_t ucIPAddress[ 4 ] = { configIP_ADDR0, configIP_ADDR1, configIP_ADDR2, configIP_ADDR3 };
static const uint8_t ucNetMask[ 4 ] = { configNET_MASK0, configNET_MASK1, configNET_MASK2, configNET_MASK3 };
static const uint8_t ucGatewayAddress[ 4 ] = { configGATEWAY_ADDR0, configGATEWAY_ADDR1, configGATEWAY_ADDR2, configGATEWAY_ADDR3 };
static const uint8_t ucDNSServerAddress[ 4 ] = { configDNS_SERVER_ADDR0, configDNS_SERVER_ADDR1, configDNS_SERVER_ADDR2, configDNS_SERVER_ADDR3 };

/* Set the following constant to pdTRUE to log using the method indicated by the
name of the constant, or pdFALSE to not log using the method indicated by the
name of the constant.  Options include to standard out (xLogToStdout), to a disk
file (xLogToFile), and to a UDP port (xLogToUDP).  If xLogToUDP is set to pdTRUE
then UDP messages are sent to the IP address configured as the echo server
address (see the configECHO_SERVER_ADDR0 definitions in FreeRTOSConfig.h) and
the port number set by configPRINT_PORT in FreeRTOSConfig.h. */
const BaseType_t xLogToStdout = pdTRUE, xLogToFile = pdFALSE, xLogToUDP = pdFALSE;

/* Default MAC address configuration.  The demo creates a virtual network
connection that uses this MAC address by accessing the raw Ethernet data
to and from a real network connection on the host PC.  See the
configNETWORK_INTERFACE_TO_USE definition for information on how to configure
the real network connection to use. */
const uint8_t ucMACAddress[ 6 ] = { configMAC_ADDR0, configMAC_ADDR1, configMAC_ADDR2, configMAC_ADDR3, configMAC_ADDR4, configMAC_ADDR5 };

/* Use by the pseudo random number generator. */
static UBaseType_t ulNextRand;

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

void  main_tcp_echo_client_tasks( void )
{
const uint32_t ulLongTime_ms = pdMS_TO_TICKS( 1000UL );

	/*
	 * Instructions for using this project are provided on:
	 * http://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/examples_FreeRTOS_simulator.html
	 */

	/* Miscellaneous initialisation including preparing the logging and seeding
	the random number generator. */
	prvMiscInitialisation();

	/* Initialise the network interface.

	***NOTE*** Tasks that use the network are created in the network event hook
	when the network is connected and ready for use (see the definition of
	vApplicationIPNetworkEventHook() below).  The address values passed in here
	are used if ipconfigUSE_DHCP is set to 0, or if ipconfigUSE_DHCP is set to 1
	but a DHCP server cannot be	contacted. */
	FreeRTOS_debug_printf( ( "FreeRTOS_IPInit\n" ) );
	FreeRTOS_IPInit( ucIPAddress,
					 ucNetMask,
					 ucGatewayAddress,
					 ucDNSServerAddress,
					 ucMACAddress );

	/* Start the RTOS scheduler. */
	FreeRTOS_debug_printf( ( "vTaskStartScheduler\n" ) );
	vTaskStartScheduler();
	FreeRTOS_debug_printf( ( "Should not reach this point after scheduler\n" ) );

	/* If all is well, the scheduler will now be running, and the following
	line will never be reached.  If the following line does execute, then
	there was insufficient FreeRTOS heap memory available for the idle and/or
	timer tasks	to be created.  See the memory management section on the
	FreeRTOS web site for more details (this is standard text that is not not
	really applicable to the Linux simulator port). */
	for( ; ; )
	{
		usleep( ulLongTime_ms * 1000 );
	}
}
/*-----------------------------------------------------------*/

static void vUDPSendUsingStandardInterface( void *pvParameters )
{
Socket_t xSocket;
struct freertos_sockaddr xDestinationAddress;
uint8_t cString[ 50 ];
uint32_t ulCount = 0UL;
const TickType_t x1000ms = 1000UL / portTICK_PERIOD_MS;


   /* Send strings to port 10000 on IP address 192.168.0.50. */
   xDestinationAddress.sin_addr = FreeRTOS_inet_addr( "192.168.2.107" );
   xDestinationAddress.sin_port = FreeRTOS_htons( 5000 );

   /* Create the socket. */
   xSocket = FreeRTOS_socket( FREERTOS_AF_INET,
                              FREERTOS_SOCK_DGRAM,/*FREERTOS_SOCK_DGRAM for UDP.*/
                              FREERTOS_IPPROTO_UDP );

   /* Check the socket was created. */
   configASSERT( xSocket != FREERTOS_INVALID_SOCKET );

   /* NOTE: FreeRTOS_bind() is not called.  This will only work if
   ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND is set to 1 in FreeRTOSIPConfig.h. */

   for( ;; )
   {
       /* Create the string that is sent. */
       sprintf( cString,
                "Standard send message number %lurn",
                ulCount );

       FreeRTOS_sendto( xSocket,
                        cString,
                        strlen( cString ),
                        0,
                        &xDestinationAddress,
                        sizeof( xDestinationAddress ) );

       ulCount++;

       /* Wait until it is time to send again. */
       vTaskDelay( 1000 );
   }
}
/* Called by FreeRTOS+TCP when the network connects or disconnects.  Disconnect
events are only received if implemented in the MAC driver. */
void vApplicationIPNetworkEventHook( eIPCallbackEvent_t eNetworkEvent )
{
uint32_t ulIPAddress, ulNetMask, ulGatewayAddress, ulDNSServerAddress;
char cBuffer[ 16 ];
static BaseType_t xTasksAlreadyCreated = pdFALSE;	

	/* If the network has just come up...*/
	if( eNetworkEvent == eNetworkUp )
	{
		/* Create the tasks that use the IP stack if they have not already been
		created. */
		if( xTasksAlreadyCreated == pdFALSE )
		{

			xTaskCreate( vUDPSendUsingStandardInterface, /* The function that implements the task. */
						 "Echo0",           /* Just a text name for the task to aid debugging. */
						 configMINIMAL_STACK_SIZE,   /* The stack size is defined in FreeRTOSIPConfig.h. */
						 NULL,      /* The task parameter, not used in this case. */
						 5,    /* The priority assigned to the task is defined in FreeRTOSConfig.h. */
						 NULL );            /* The task handle is not used. */

			xTasksAlreadyCreated = pdTRUE;
		}

		/* Print out the network configuration, which may have come from a DHCP
		server. */
		FreeRTOS_GetAddressConfiguration( &ulIPAddress, &ulNetMask, &ulGatewayAddress, &ulDNSServerAddress );
		FreeRTOS_inet_ntoa( ulIPAddress, cBuffer );
		FreeRTOS_printf( ( "\r\n\r\nIP Address: %s\r\n", cBuffer ) );

		FreeRTOS_inet_ntoa( ulNetMask, cBuffer );
		FreeRTOS_printf( ( "Subnet Mask: %s\r\n", cBuffer ) );

		FreeRTOS_inet_ntoa( ulGatewayAddress, cBuffer );
		FreeRTOS_printf( ( "Gateway Address: %s\r\n", cBuffer ) );

		FreeRTOS_inet_ntoa( ulDNSServerAddress, cBuffer );
		FreeRTOS_printf( ( "DNS Server Address: %s\r\n\r\n\r\n", cBuffer ) );
	}
	else
	{
		FreeRTOS_printf( "Application idle hook network down\n" );
	}
}
/*-----------------------------------------------------------*/

UBaseType_t uxRand( void )
{
const uint32_t ulMultiplier = 0x015a4e35UL, ulIncrement = 1UL;

	/* Utility function to generate a pseudo random number. */

	ulNextRand = ( ulMultiplier * ulNextRand ) + ulIncrement;
	return( ( int ) ( ulNextRand >> 16UL ) & 0x7fffUL );
}
/*-----------------------------------------------------------*/

static void prvSRand( UBaseType_t ulSeed )
{
	/* Utility function to seed the pseudo random number generator. */
	ulNextRand = ulSeed;
}
/*-----------------------------------------------------------*/

static void prvMiscInitialisation( void )
{
time_t xTimeNow;

	/* Seed the random number generator. */
	time( &xTimeNow );
	FreeRTOS_debug_printf( ( "Seed for randomiser: %lu\n", xTimeNow ) );
	prvSRand( ( uint32_t ) xTimeNow );
	FreeRTOS_debug_printf( ( "Random numbers: %08X %08X %08X %08X\n",
							 ipconfigRAND32(),
							 ipconfigRAND32(),
							 ipconfigRAND32(),
							 ipconfigRAND32() ) );
}
/*-----------------------------------------------------------*/

#if ( ipconfigUSE_LLMNR != 0 ) || ( ipconfigUSE_NBNS != 0 ) || ( ipconfigDHCP_REGISTER_HOSTNAME == 1 )

	const char * pcApplicationHostnameHook( void )
	{
		/* Assign the name "FreeRTOS" to this network node.  This function will
		be called during the DHCP: the machine will be registered with an IP
		address plus this name. */
		return mainHOST_NAME;
	}

#endif
/*-----------------------------------------------------------*/

#if ( ipconfigUSE_LLMNR != 0 ) || ( ipconfigUSE_NBNS != 0 )

	BaseType_t xApplicationDNSQueryHook( const char *pcName )
	{
	BaseType_t xReturn;

		/* Determine if a name lookup is for this node.  Two names are given
		to this node: that returned by pcApplicationHostnameHook() and that set
		by mainDEVICE_NICK_NAME. */
		if( strcasecmp( pcName, pcApplicationHostnameHook() ) == 0 )
		{
			xReturn = pdPASS;
		}
		else if( strcasecmp( pcName, mainDEVICE_NICK_NAME ) == 0 )
		{
			xReturn = pdPASS;
		}
		else
		{
			xReturn = pdFAIL;
		}

		return xReturn;
	}

#endif /* if ( ipconfigUSE_LLMNR != 0 ) || ( ipconfigUSE_NBNS != 0 ) */

/*
 * Callback that provides the inputs necessary to generate a randomized TCP
 * Initial Sequence Number per RFC 6528.  THIS IS ONLY A DUMMY IMPLEMENTATION
 * THAT RETURNS A PSEUDO RANDOM NUMBER SO IS NOT INTENDED FOR USE IN PRODUCTION
 * SYSTEMS.
 */
extern uint32_t ulApplicationGetNextSequenceNumber( uint32_t ulSourceAddress,
													uint16_t usSourcePort,
													uint32_t ulDestinationAddress,
													uint16_t usDestinationPort )
{
	( void ) ulSourceAddress;
	( void ) usSourcePort;
	( void ) ulDestinationAddress;
	( void ) usDestinationPort;

	return uxRand();
}

/*
 * Supply a random number to FreeRTOS+TCP stack.
 * THIS IS ONLY A DUMMY IMPLEMENTATION THAT RETURNS A PSEUDO RANDOM NUMBER
 * SO IS NOT INTENDED FOR USE IN PRODUCTION SYSTEMS.
 */
BaseType_t xApplicationGetRandomNumber( uint32_t * pulNumber )
{
	*( pulNumber ) = uxRand();
	return pdTRUE;
}

The only changes to the header files were:

Address of my VBox

#define configECHO_SERVER_ADDR0 192
#define configECHO_SERVER_ADDR1 168
#define configECHO_SERVER_ADDR2 2
#define configECHO_SERVER_ADDR3 107

Local IP

#define configIP_ADDR0 127
#define configIP_ADDR1 0
#define configIP_ADDR2 0
#define configIP_ADDR3 1

Gateway

#define configGATEWAY_ADDR0 192
#define configGATEWAY_ADDR1 168
#define configGATEWAY_ADDR2 2
#define configGATEWAY_ADDR3 1

Net Mask

#define configNET_MASK0	  0
#define configNET_MASK1	  0
#define configNET_MASK2	  0
#define configNET_MASK3	 255

and some other hooks disabled

#define configUSE_IDLE_HOOK						0
#define configUSE_TICK_HOOK						0
#define configUSE_DAEMON_TASK_STARTUP_HOOK		0

Could you help me again with this problem?
Thank you.

Did you try using using a non loopback IP address for the configIP_ADDRx constants?

I’ve not used the networking on Linux, but have with the FreeRTOS Windows port (what we call the Windows Simulator, although its not really a simulator). On Windows I am able to use a virtual network card to communicate between the FreeRTOS application (running on Window) and echo servers/MQTT brokers/HTTP servers, etc. running on the same machine. To do that I

  1. Install and configure a virtual Ethernet card, normally the one that gets installed with Virtual Box.

  2. Set up different static IP addresses for the virtual card, FreeRTOS client and the server (from the private range, 192.168.0.x or 10.10.10.x) so I know all are on a compatible subnet and won’t get routed anywhere else.

  3. Make sure ipconfigUSE_DHCP is 0.

  4. Make sure the configNETWORK_CARD_TO_USE is set correctly!

See this section: https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/examples_FreeRTOS_simulator.html#static-dynamic

So in this case I’m running both the client and server on the same machine, so comms is between Windows and Windows but using a virtual network card, rather than in a virtual machine and Windows - but have no idea if that will work on Linux too.

Hi Carlos,

I have found a workaround to unblock you for now ( I haven’t used 127.0.0.1, iIreplaced it with an ip on the same subnet)
after the

FreeRTOS_sendto

add a delay,

vTaskDelay(pdMS_TO_TICKS(delay_ms));  // allow some time for the ARP response packet to arrive from the gateway

then add

FreeRTOS_sendto 

again with exactly the same parameters, it would send the packet
I know this is not perfect, but I will do some more debugging tomorrow to find a more sustainable solution.

There is also a lesser known function that starts an ARP loookup:

void FreeRTOS_OutputARPRequest( uint32_t ulIPAddress );

It does not return a result, because the request will be sent in a non-blocking way.
The result will be stored in the ARP cache table.
Make sure that the table is big enough by setting ipconfigARP_CACHE_ENTRIES.

You can poll if an IP-adddress is already known:

/* Make a copy of the IP-address. the function eARPGetCacheEntry()
may change its value by the IP-address of a gateway. */
uint32_t ulTempIP = ulIPAddress;
MACAddress_t xMACAddress;
eARPLookupResult_t xResult = eARPGetCacheEntry( &( ulTempIP ), &( xMACAddress ) );
if( xResult == eARPCacheHit )
{
    /* The IP-address is known and can be used. */
}

When we call the first FreeRTOS_sendto, we get an ARP cache miss
So we do send an ARP request for the gateway address, and when we get the ARP reply, we do not resend the original packet. Thus my solution to do a FreeRTOS_sendto again as the ARP check will cause a hit this time, and the UDP packet is sent

Thus my solution to do a FreeRTOS_sendto again as the ARP
check will cause a hit this time

That is a good solution except that the UDP packet might get delivered twice.
The test with eARPGetCacheEntry() can avoid this.

The IP-task is not allowed to do anything that is “blocking”, so it can not wait for the result of an ARP request, and deliver the UDP or ICMP/ping packet.

So you are saying there is no bug there?
Can’t we make it so that it sends the packet in just a call to FreeRTOS_sendto, by re-injecting the packet into the queue if we get a cache miss for example, or create a secondary queue that is pending arp results?

@gedeonag :

So you are saying there is no bug there?

You may call it a bug, and it is annoying to see that the first UDP- or ping-packet never arrive. The original UDP-only library already used this method.

Can’t we make it so that it sends the packet in just a call to FreeRTOS_sendto,
by re-injecting the packet into the queue if we get a cache miss for example,
or create a secondary queue that is pending arp results?

A simple solution would be to change the code of FeeeRTOS_sendto(), symbolically:

    if( address_is_known( ulIPAddress  ) == pdFALSE )
    {
        FreeRTOS_OutputARPRequest( ulIPAddress  );

        for( ;; )
        {
            if( address_is_known( ulIPAddress  ) )
            {
                break;
            }
            if( timeout_reached )
            {
                return -1;
            }

            vTaskDelay( 10U );
        }
    }

The above code is not efficient in terms of time. You would like to see that the ARP response wakes up the calling task.
But also you don’t want a lot of code or increased complexity. The function sendto() is also called by the IP-task, for instance to send DHCP packets…

What would you think ?

I think it is better,
Since the user will have to execute this code anyways, it will be providing a better customer experience by offloading the extra steps, also the experience would be similar to what lots are used to (Berkley Sockets).

All right, I will prepare a PR for this.
Hein

Here is a function that works:

BaseType_t xARPWaitResolution( uint32_t ulIPAddress, TickType_t uxTicksToWait )
{
BaseType_t xResult = -pdFREERTOS_ERRNO_EADDRNOTAVAIL;
TimeOut_t xTimeOut;
MACAddress_t xMACAddress;
eARPLookupResult_t xLookupResult;

	xLookupResult = eARPGetCacheEntry( &( ulIPAddress ), &( xMACAddress ) );

	if( xLookupResult == eARPCacheMiss )
	{
	const TickType_t uxSleepTime = pdMS_TO_TICKS( 5U );

		FreeRTOS_OutputARPRequest( ulIPAddress );
		vTaskSetTimeOutState( &xTimeOut );
		for( ;; )
		{
			xLookupResult = eARPGetCacheEntry( &( ulIPAddress ), &( xMACAddress ) );
			if( ( xTaskCheckForTimeOut( &( xTimeOut ), &( uxTicksToWait ) ) == pdTRUE ) ||
				( xLookupResult != eARPCacheMiss ) )
			{
				break;
			}
			vTaskDelay( uxSleepTime );
		}
	}
	if( xLookupResult == eARPCacheHit )
	{
		xResult = 0;
	}

	return xResult;
}
/*-----------------------------------------------------------*/

We can call it from both FreeRTOS_sendto(), and FreeRTOS_SendPingRequest().
It solves one problem, but it will make both functions slower. Some users for whom speed is essential, will not want that.
Even if the address is known, a call to eARPGetCacheEntry() is being done, which costs time.

So we can add a macro with a name like ipconfigARP_RESOLUTION_BEFORE_SENDTO ?

Could we have a racing condition with this solution?
1- task one checks ARP cache and find it full, then issues a call to send the packet
2- task two is awaken and invalidates the ARP entry, deemed too old goes back to sleep
2- task one awakens again and will get an ARP cache miss and fail to send the packet

another way is to send the actual Mac address, received from the cash hit, and don’t do a cash lookup again if the MAC address is provided, which solves the racing condition and the time penalty, what do you think?

UDP makes no delivery guarantee - so while it may be unexpected - it is not a bug.

Yeah for sure, but in this case we are not even sending the packet and without any error code,
and we will be issuing “eARPGetCacheEntry” twice (if we apply the fix, to make the usage similar to the standard Berkley sockets)

At the bare minimum, I would like to see a log message saying packet dropped because ARP got a miss, to avoid cases like that in the future

I think you can do that using the IP trace macros → “Packets dropped to generate ARP” UDP CLI (Command Line Interface for the RTOS)

Richard wrote:

UDP makes no delivery guarantee - so while it may be unexpected - it is not a bug.

Absolutely true, but like Alfred, I wonder if we can make the user experience a little better, or at least avoid new posts or complaints about this subject.

Unlike some other embedded TCP/IP stacks, when using FreeRTOS+TCP, a user task never directly executes code that affects the stack. As you know, the IP-task handles everything and it works like a state machine, handling queued messages.
So a task will not invalidate an ARP cache entry, that is up to the IP-task.

Could we have a racing condition with this solution?
1- task one checks ARP cache and find it full, then issues a call to send the packet
2- task two is awaken and invalidates the ARP entry, deemed too old goes back to sleep
2- task one awakens again and will get an ARP cache miss and fail to send the packet

I don’t think there is this risk.

By default, an ARP entry will be valid for about half an hour.

(
Every 10 seconds, the ARP-cache will be checked for old entries by the function vARPAgeCache(). The timer of each entry will be decreased. When zero, the entry becomes invalid.

#define ipARP_TIMER_PERIOD_MS    ( 10000 )   /* defined in FreeRTOS_IP.c */
#define ipconfigMAX_ARP_AGE      ( 150 )     /* defined in FreeRTOSIPConfig.h */

)

So by default, an ARP entry will expire after 1500 seconds. But as long as there is communication with the IP-address, the ARP entry will be refreshed.

The time between sending an ARP request and receiving an answer is normally less than 1 ms.
So an ARP entry won’t be invalidated because of age, before it is used.

another way is to send the actual Mac address, received from the cash hit,
and don’t do a cash lookup again if the MAC address is provided, which solves
the racing condition and the time penalty, what do you think?

Task-A cache look-up : negative
Task-A requests send an ARP request
Task-A starts a vTaskDelay( 10 ms )
IP-task receives an ARP reply, sets cache
Task-A still in vTaskDelay()
Task-A cache look-up : positive

There is another risk: a full ARP cache.

#define ipconfigARP_CACHE_ENTRIES		10

Suppose task-A does a lookup, waits 10 ms, and within those 10 me, there are 10 refreshments of ARP entries.
Is that very likely? I don’t think so. And if it might happen, it is worth increasing the value of ipconfigARP_CACHE_ENTRIES.

Conclusion: I think that adding a function like xARPWaitResolution() will be enough to avoid the problem of “dropped” UDP/ping packets…

Sorry for the delay in responding and testing the solutions.
Today I tried all of the suggested alternatives and none worked for my machine.

The next thing would be the configuration you are using, I believe there is a mismatch between the netwrok card addresses (mac, ip, subnet, route) and the configuration in the FreeRTOS configuration file.
If you could post those to compare, or if you find something mismatching, it would be great

Few observations from the configuration file you sent:
try to change the local ip from 127.0.0.1 to an external ip address, according to the gateway address in the 192.168.2.XXX area
the subnet mask looks incorrect , it should start with the higher numbers first (255.0.0.0 for example, usually for local networks it is 255.255.255.0 or something similar)

Hello David, just curious, did you get any further with it?

The last remarks by @gedeonag are very important. Can you tell the IP address of your linux system?