4949#include "FreeRTOS_Sockets.h"
5050#include "FreeRTOS_IP_Private.h"
5151#include "FreeRTOS_ARP.h"
52+ #include "FreeRTOS_ND.h"
5253#include "FreeRTOS_UDP_IP.h"
5354#include "FreeRTOS_DHCP.h"
5455#if ( ipconfigUSE_DHCPv6 == 1 )
5859#include "NetworkBufferManagement.h"
5960#include "FreeRTOS_DNS.h"
6061#include "FreeRTOS_Routing.h"
61- #include "FreeRTOS_ND.h"
6262
6363/** @brief Time delay between repeated attempts to initialise the network hardware. */
6464#ifndef ipINITIALISATION_RETRY_DELAY
6565 #define ipINITIALISATION_RETRY_DELAY ( pdMS_TO_TICKS( 3000U ) )
6666#endif
67+
6768#if ( ipconfigUSE_TCP_MEM_STATS != 0 )
6869 #include "tcp_mem_stats.h"
6970#endif
7374 #define ipARP_RESOLUTION_MAX_DELAY ( pdMS_TO_TICKS( 2000U ) )
7475#endif
7576
76- #ifndef iptraceIP_TASK_STARTING
77- #define iptraceIP_TASK_STARTING () do {} while( ipFALSE_BOOL ) /**< Empty definition in case iptraceIP_TASK_STARTING is not defined. */
77+ /** @brief Maximum time to wait for a ND resolution while holding a packet. */
78+ #ifndef ipND_RESOLUTION_MAX_DELAY
79+ #define ipND_RESOLUTION_MAX_DELAY ( pdMS_TO_TICKS( 2000U ) )
7880#endif
7981
80- #if ( ( ipconfigUSE_TCP == 1 ) && !defined( ipTCP_TIMER_PERIOD_MS ) )
81- /** @brief When initialising the TCP timer, give it an initial time-out of 1 second. */
82- #define ipTCP_TIMER_PERIOD_MS ( 1000U )
83- #endif
84-
85- /** @brief Defines how often the ARP timer callback function is executed. The time is
82+ /** @brief Defines how often the ARP resolution timer callback function is executed. The time is
8683 * shorter in the Windows simulator as simulated time is not real time. */
8784#ifndef ipARP_TIMER_PERIOD_MS
8885 #ifdef _WINDOWS_
9289 #endif
9390#endif
9491
92+ /** @brief Defines how often the ND resolution timer callback function is executed. The time is
93+ * shorter in the Windows simulator as simulated time is not real time. */
94+ #ifndef ipND_TIMER_PERIOD_MS
95+ #ifdef _WINDOWS_
96+ #define ipND_TIMER_PERIOD_MS ( 500U ) /* For windows simulator builds. */
97+ #else
98+ #define ipND_TIMER_PERIOD_MS ( 10000U )
99+ #endif
100+ #endif
101+
102+ #if ( ( ipconfigUSE_TCP == 1 ) && !defined( ipTCP_TIMER_PERIOD_MS ) )
103+ /** @brief When initialising the TCP timer, give it an initial time-out of 1 second. */
104+ #define ipTCP_TIMER_PERIOD_MS ( 1000U )
105+ #endif
106+
107+ #ifndef iptraceIP_TASK_STARTING
108+ #define iptraceIP_TASK_STARTING () do {} while( ipFALSE_BOOL ) /**< Empty definition in case iptraceIP_TASK_STARTING is not defined. */
109+ #endif
110+
95111/** @brief The frame type field in the Ethernet header must have a value greater than 0x0600.
96112 * If the configuration option ipconfigFILTER_OUT_NON_ETHERNET_II_FRAMES is enabled, the stack
97113 * will discard packets with a frame type value less than or equal to 0x0600.
@@ -107,7 +123,14 @@ static void prvIPTask_CheckPendingEvents( void );
107123/*-----------------------------------------------------------*/
108124
109125/** @brief The pointer to buffer with packet waiting for ARP resolution. */
110- NetworkBufferDescriptor_t * pxARPWaitingNetworkBuffer = NULL ;
126+ #if ipconfigIS_ENABLED ( ipconfigUSE_IPv4 )
127+ NetworkBufferDescriptor_t * pxARPWaitingNetworkBuffer = NULL ;
128+ #endif
129+
130+ /** @brief The pointer to buffer with packet waiting for ND resolution. */
131+ #if ipconfigIS_ENABLED ( ipconfigUSE_IPv6 )
132+ NetworkBufferDescriptor_t * pxNDWaitingNetworkBuffer = NULL ;
133+ #endif
111134
112135/*-----------------------------------------------------------*/
113136
@@ -238,7 +261,7 @@ static void prvProcessIPEventsAndTimers( void )
238261
239262 ipconfigWATCHDOG_TIMER ();
240263
241- /* Check the ARP , DHCP and TCP timers to see if there is any periodic
264+ /* Check the Resolution , DHCP and TCP timers to see if there is any periodic
242265 * or timeout processing to perform. */
243266 vCheckNetworkTimers ();
244267
@@ -294,15 +317,17 @@ static void prvProcessIPEventsAndTimers( void )
294317 break ;
295318
296319 case eARPTimerEvent :
297- /* The ARP timer has expired, process the ARP cache. */
298- #if ( ipconfigUSE_IPv4 != 0 )
320+ /* The ARP Resolution timer has expired, process the cache. */
321+ #if ipconfigIS_ENABLED ( ipconfigUSE_IPv4 )
299322 vARPAgeCache ();
300323 #endif /* ( ipconfigUSE_IPv4 != 0 ) */
324+ break ;
301325
302- #if ( ipconfigUSE_IPv6 != 0 )
326+ case eNDTimerEvent :
327+ /* The ND Resolution timer has expired, process the cache. */
328+ #if ipconfigIS_ENABLED ( ipconfigUSE_IPv6 )
303329 vNDAgeCache ();
304330 #endif /* ( ipconfigUSE_IPv6 != 0 ) */
305-
306331 break ;
307332
308333 case eSocketBindEvent :
@@ -493,8 +518,15 @@ static void prvIPTask_Initialise( void )
493518 }
494519 #endif
495520
496- /* Mark the timer as inactive since we are not waiting on any ARP resolution as of now. */
497- vIPSetARPResolutionTimerEnableState ( pdFALSE );
521+ #if ipconfigIS_ENABLED ( ipconfigUSE_IPv4 )
522+ /* Mark the ARP timer as inactive since we are not waiting on any resolution as of now. */
523+ vIPSetARPResolutionTimerEnableState ( pdFALSE );
524+ #endif
525+
526+ #if ipconfigIS_ENABLED ( ipconfigUSE_IPv6 )
527+ /* Mark the ND timer as inactive since we are not waiting on any resolution as of now. */
528+ vIPSetNDResolutionTimerEnableState ( pdFALSE );
529+ #endif
498530
499531 #if ( ( ipconfigDNS_USE_CALLBACKS != 0 ) && ( ipconfigUSE_DNS != 0 ) )
500532 {
@@ -648,7 +680,18 @@ void vIPNetworkUpCalls( struct xNetworkEndPoint * pxEndPoint )
648680 #endif /* ipconfigDNS_USE_CALLBACKS != 0 */
649681
650682 /* Set remaining time to 0 so it will become active immediately. */
651- vARPTimerReload ( pdMS_TO_TICKS ( ipARP_TIMER_PERIOD_MS ) );
683+ if ( pxEndPoint -> bits .bIPv6 == pdTRUE_UNSIGNED )
684+ {
685+ #if ipconfigIS_ENABLED ( ipconfigUSE_IPv6 )
686+ vNDTimerReload ( pdMS_TO_TICKS ( ipND_TIMER_PERIOD_MS ) );
687+ #endif
688+ }
689+ else
690+ {
691+ #if ipconfigIS_ENABLED ( ipconfigUSE_IPv4 )
692+ vARPTimerReload ( pdMS_TO_TICKS ( ipARP_TIMER_PERIOD_MS ) );
693+ #endif
694+ }
652695}
653696/*-----------------------------------------------------------*/
654697
@@ -1718,7 +1761,7 @@ static void prvProcessEthernetPacket( NetworkBufferDescriptor_t * const pxNetwor
17181761 case eReturnEthernetFrame :
17191762
17201763 /* The Ethernet frame will have been updated (maybe it was
1721- * an ARP request or a PING request?) and should be sent back to
1764+ * a resolution request or a PING request?) and should be sent back to
17221765 * its source. */
17231766 vReturnEthernetFrame ( pxNetworkBuffer , pdTRUE );
17241767
@@ -1732,21 +1775,54 @@ static void prvProcessEthernetPacket( NetworkBufferDescriptor_t * const pxNetwor
17321775 * yet. */
17331776 break ;
17341777
1735- case eWaitingARPResolution :
1778+ case eWaitingResolution :
1779+
1780+ if ( ( pxEthernetHeader -> usFrameType == ipIPv4_FRAME_TYPE ) || ( pxEthernetHeader -> usFrameType == ipARP_FRAME_TYPE ) )
1781+ {
1782+ #if ipconfigIS_ENABLED ( ipconfigUSE_IPv4 )
1783+ if ( pxARPWaitingNetworkBuffer == NULL )
1784+ {
1785+ pxARPWaitingNetworkBuffer = pxNetworkBuffer ;
1786+ vIPTimerStartARPResolution ( ipARP_RESOLUTION_MAX_DELAY );
1787+
1788+ iptraceDELAYED_ARP_REQUEST_STARTED ();
1789+ }
1790+ else
1791+ #endif /* if ipconfigIS_ENABLED( ipconfigUSE_IPv4 ) */
1792+ {
1793+ /* We are already waiting on one resolution. This frame will be dropped. */
1794+ vReleaseNetworkBufferAndDescriptor ( pxNetworkBuffer );
1795+
1796+ iptraceDELAYED_ARP_BUFFER_FULL ();
1797+ }
17361798
1737- if ( pxARPWaitingNetworkBuffer == NULL )
1799+ break ;
1800+ }
1801+ else if ( pxEthernetHeader -> usFrameType == ipIPv6_FRAME_TYPE )
17381802 {
1739- pxARPWaitingNetworkBuffer = pxNetworkBuffer ;
1740- vIPTimerStartARPResolution ( ipARP_RESOLUTION_MAX_DELAY );
1803+ #if ipconfigIS_ENABLED ( ipconfigUSE_IPv6 )
1804+ if ( pxNDWaitingNetworkBuffer == NULL )
1805+ {
1806+ pxNDWaitingNetworkBuffer = pxNetworkBuffer ;
1807+ vIPTimerStartNDResolution ( ipND_RESOLUTION_MAX_DELAY );
1808+
1809+ iptraceDELAYED_ND_REQUEST_STARTED ();
1810+ }
1811+ else
1812+ #endif /* if ipconfigIS_ENABLED( ipconfigUSE_IPv6 ) */
1813+ {
1814+ /* We are already waiting on one resolution. This frame will be dropped. */
1815+ vReleaseNetworkBufferAndDescriptor ( pxNetworkBuffer );
17411816
1742- iptraceDELAYED_ARP_REQUEST_STARTED ();
1817+ iptraceDELAYED_ND_BUFFER_FULL ();
1818+ }
1819+
1820+ break ;
17431821 }
17441822 else
17451823 {
1746- /* We are already waiting on one ARP resolution. This frame will be dropped . */
1824+ /* Unknown frame type, drop the packet . */
17471825 vReleaseNetworkBufferAndDescriptor ( pxNetworkBuffer );
1748-
1749- iptraceDELAYED_ARP_BUFFER_FULL ();
17501826 }
17511827
17521828 break ;
@@ -1775,7 +1851,7 @@ static void prvProcessEthernetPacket( NetworkBufferDescriptor_t * const pxNetwor
17751851static eFrameProcessingResult_t prvProcessUDPPacket ( NetworkBufferDescriptor_t * const pxNetworkBuffer )
17761852{
17771853 eFrameProcessingResult_t eReturn = eReleaseBuffer ;
1778- BaseType_t xIsWaitingARPResolution = pdFALSE ;
1854+ BaseType_t xIsWaitingResolution = pdFALSE ;
17791855 /* The IP packet contained a UDP frame. */
17801856 /* MISRA Ref 11.3.1 [Misaligned access] */
17811857 /* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */
@@ -1847,16 +1923,16 @@ static eFrameProcessingResult_t prvProcessUDPPacket( NetworkBufferDescriptor_t *
18471923 * implementation. */
18481924 if ( xProcessReceivedUDPPacket ( pxNetworkBuffer ,
18491925 pxUDPHeader -> usDestinationPort ,
1850- & ( xIsWaitingARPResolution ) ) == pdPASS )
1926+ & ( xIsWaitingResolution ) ) == pdPASS )
18511927 {
18521928 eReturn = eFrameConsumed ;
18531929 }
18541930 else
18551931 {
1856- /* Is this packet to be set aside for ARP resolution. */
1857- if ( xIsWaitingARPResolution == pdTRUE )
1932+ /* Is this packet to be set aside for resolution. */
1933+ if ( xIsWaitingResolution == pdTRUE )
18581934 {
1859- eReturn = eWaitingARPResolution ;
1935+ eReturn = eWaitingResolution ;
18601936 }
18611937 }
18621938 }
@@ -2014,21 +2090,21 @@ static eFrameProcessingResult_t prvProcessIPPacket( const IPPacket_t * pxIPPacke
20142090 /* coverity[const] */
20152091 if ( eReturn != eReleaseBuffer )
20162092 {
2017- /* Add the IP and MAC addresses to the ARP table if they are not
2093+ /* Add the IP and MAC addresses to the cache if they are not
20182094 * already there - otherwise refresh the age of the existing
20192095 * entry. */
20202096 if ( ucProtocol != ( uint8_t ) ipPROTOCOL_UDP )
20212097 {
2022- if ( xCheckRequiresARPResolution ( pxNetworkBuffer ) == pdTRUE )
2098+ if ( xCheckRequiresResolution ( pxNetworkBuffer ) == pdTRUE )
20232099 {
2024- eReturn = eWaitingARPResolution ;
2100+ eReturn = eWaitingResolution ;
20252101 }
20262102 else
20272103 {
2028- /* Refresh the ARP cache with the IP/MAC-address of the received
2104+ /* Refresh the cache with the IP/MAC-address of the received
20292105 * packet. For UDP packets, this will be done later in
20302106 * xProcessReceivedUDPPacket(), as soon as it's know that the message
2031- * will be handled. This will prevent the ARP cache getting
2107+ * will be handled. This will prevent the cache getting
20322108 * overwritten with the IP address of useless broadcast packets. */
20332109 /* Case default is never toggled because eReturn is not eProcessBuffer in previous step. */
20342110 switch ( pxIPPacket -> xEthernetHeader .usFrameType ) /* LCOV_EXCL_BR_LINE */
@@ -2054,7 +2130,7 @@ static eFrameProcessingResult_t prvProcessIPPacket( const IPPacket_t * pxIPPacke
20542130 }
20552131 }
20562132
2057- if ( eReturn != eWaitingARPResolution )
2133+ if ( eReturn != eWaitingResolution )
20582134 {
20592135 switch ( ucProtocol )
20602136 {
@@ -2171,7 +2247,7 @@ void vReturnEthernetFrame( NetworkBufferDescriptor_t * pxNetworkBuffer,
21712247
21722248 #if ( ipconfigUSE_IPv4 != 0 )
21732249 MACAddress_t xMACAddress ;
2174- eARPLookupResult_t eResult ;
2250+ eResolutionLookupResult_t eResult ;
21752251 uint32_t ulDestinationIPAddress = 0U ;
21762252 #endif /* ( ipconfigUSE_IPv4 != 0 ) */
21772253
@@ -2219,7 +2295,7 @@ void vReturnEthernetFrame( NetworkBufferDescriptor_t * pxNetworkBuffer,
22192295 * address. */
22202296 eResult = eARPGetCacheEntry ( & ulDestinationIPAddress , & xMACAddress , & ( pxNetworkBuffer -> pxEndPoint ) );
22212297
2222- if ( eResult == eARPCacheHit )
2298+ if ( eResult == eResolutionCacheHit )
22232299 {
22242300 /* Best case scenario - an address is found, use it. */
22252301 pvCopySource = & xMACAddress ;
@@ -2235,7 +2311,7 @@ void vReturnEthernetFrame( NetworkBufferDescriptor_t * pxNetworkBuffer,
22352311 case ipIPv6_FRAME_TYPE :
22362312 case ipARP_FRAME_TYPE :
22372313 default :
2238- /* In case of ARP frame, just swap the source and destination MAC addresses. */
2314+ /* Just swap the source and destination MAC addresses. */
22392315 pvCopySource = & ( pxIPPacket -> xEthernetHeader .xSourceAddress );
22402316 break ;
22412317 }
@@ -2262,7 +2338,7 @@ void vReturnEthernetFrame( NetworkBufferDescriptor_t * pxNetworkBuffer,
22622338 {
22632339 IPStackEvent_t xSendEvent ;
22642340
2265- /* Send a message to the IP-task to send this ARP packet. */
2341+ /* Send a message to the IP-task to send this packet. */
22662342 xSendEvent .eEventType = eNetworkTxEvent ;
22672343 xSendEvent .pvData = pxNetworkBuffer ;
22682344
0 commit comments