49
49
#include "FreeRTOS_Sockets.h"
50
50
#include "FreeRTOS_IP_Private.h"
51
51
#include "FreeRTOS_ARP.h"
52
+ #include "FreeRTOS_ND.h"
52
53
#include "FreeRTOS_UDP_IP.h"
53
54
#include "FreeRTOS_DHCP.h"
54
55
#if ( ipconfigUSE_DHCPv6 == 1 )
58
59
#include "NetworkBufferManagement.h"
59
60
#include "FreeRTOS_DNS.h"
60
61
#include "FreeRTOS_Routing.h"
61
- #include "FreeRTOS_ND.h"
62
62
63
63
/** @brief Time delay between repeated attempts to initialise the network hardware. */
64
64
#ifndef ipINITIALISATION_RETRY_DELAY
65
65
#define ipINITIALISATION_RETRY_DELAY ( pdMS_TO_TICKS( 3000U ) )
66
66
#endif
67
+
67
68
#if ( ipconfigUSE_TCP_MEM_STATS != 0 )
68
69
#include "tcp_mem_stats.h"
69
70
#endif
73
74
#define ipARP_RESOLUTION_MAX_DELAY ( pdMS_TO_TICKS( 2000U ) )
74
75
#endif
75
76
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 ) )
78
80
#endif
79
81
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
86
83
* shorter in the Windows simulator as simulated time is not real time. */
87
84
#ifndef ipARP_TIMER_PERIOD_MS
88
85
#ifdef _WINDOWS_
92
89
#endif
93
90
#endif
94
91
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
+
95
111
/** @brief The frame type field in the Ethernet header must have a value greater than 0x0600.
96
112
* If the configuration option ipconfigFILTER_OUT_NON_ETHERNET_II_FRAMES is enabled, the stack
97
113
* will discard packets with a frame type value less than or equal to 0x0600.
@@ -107,7 +123,14 @@ static void prvIPTask_CheckPendingEvents( void );
107
123
/*-----------------------------------------------------------*/
108
124
109
125
/** @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
111
134
112
135
/*-----------------------------------------------------------*/
113
136
@@ -238,7 +261,7 @@ static void prvProcessIPEventsAndTimers( void )
238
261
239
262
ipconfigWATCHDOG_TIMER ();
240
263
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
242
265
* or timeout processing to perform. */
243
266
vCheckNetworkTimers ();
244
267
@@ -294,15 +317,17 @@ static void prvProcessIPEventsAndTimers( void )
294
317
break ;
295
318
296
319
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 )
299
322
vARPAgeCache ();
300
323
#endif /* ( ipconfigUSE_IPv4 != 0 ) */
324
+ break ;
301
325
302
- #if ( ipconfigUSE_IPv6 != 0 )
326
+ case eNDTimerEvent :
327
+ /* The ND Resolution timer has expired, process the cache. */
328
+ #if ipconfigIS_ENABLED ( ipconfigUSE_IPv6 )
303
329
vNDAgeCache ();
304
330
#endif /* ( ipconfigUSE_IPv6 != 0 ) */
305
-
306
331
break ;
307
332
308
333
case eSocketBindEvent :
@@ -493,8 +518,15 @@ static void prvIPTask_Initialise( void )
493
518
}
494
519
#endif
495
520
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
498
530
499
531
#if ( ( ipconfigDNS_USE_CALLBACKS != 0 ) && ( ipconfigUSE_DNS != 0 ) )
500
532
{
@@ -648,7 +680,18 @@ void vIPNetworkUpCalls( struct xNetworkEndPoint * pxEndPoint )
648
680
#endif /* ipconfigDNS_USE_CALLBACKS != 0 */
649
681
650
682
/* 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
+ }
652
695
}
653
696
/*-----------------------------------------------------------*/
654
697
@@ -1718,7 +1761,7 @@ static void prvProcessEthernetPacket( NetworkBufferDescriptor_t * const pxNetwor
1718
1761
case eReturnEthernetFrame :
1719
1762
1720
1763
/* 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
1722
1765
* its source. */
1723
1766
vReturnEthernetFrame ( pxNetworkBuffer , pdTRUE );
1724
1767
@@ -1732,21 +1775,54 @@ static void prvProcessEthernetPacket( NetworkBufferDescriptor_t * const pxNetwor
1732
1775
* yet. */
1733
1776
break ;
1734
1777
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
+ }
1736
1798
1737
- if ( pxARPWaitingNetworkBuffer == NULL )
1799
+ break ;
1800
+ }
1801
+ else if ( pxEthernetHeader -> usFrameType == ipIPv6_FRAME_TYPE )
1738
1802
{
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 );
1741
1816
1742
- iptraceDELAYED_ARP_REQUEST_STARTED ();
1817
+ iptraceDELAYED_ND_BUFFER_FULL ();
1818
+ }
1819
+
1820
+ break ;
1743
1821
}
1744
1822
else
1745
1823
{
1746
- /* We are already waiting on one ARP resolution. This frame will be dropped . */
1824
+ /* Unknown frame type, drop the packet . */
1747
1825
vReleaseNetworkBufferAndDescriptor ( pxNetworkBuffer );
1748
-
1749
- iptraceDELAYED_ARP_BUFFER_FULL ();
1750
1826
}
1751
1827
1752
1828
break ;
@@ -1775,7 +1851,7 @@ static void prvProcessEthernetPacket( NetworkBufferDescriptor_t * const pxNetwor
1775
1851
static eFrameProcessingResult_t prvProcessUDPPacket ( NetworkBufferDescriptor_t * const pxNetworkBuffer )
1776
1852
{
1777
1853
eFrameProcessingResult_t eReturn = eReleaseBuffer ;
1778
- BaseType_t xIsWaitingARPResolution = pdFALSE ;
1854
+ BaseType_t xIsWaitingResolution = pdFALSE ;
1779
1855
/* The IP packet contained a UDP frame. */
1780
1856
/* MISRA Ref 11.3.1 [Misaligned access] */
1781
1857
/* 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 *
1847
1923
* implementation. */
1848
1924
if ( xProcessReceivedUDPPacket ( pxNetworkBuffer ,
1849
1925
pxUDPHeader -> usDestinationPort ,
1850
- & ( xIsWaitingARPResolution ) ) == pdPASS )
1926
+ & ( xIsWaitingResolution ) ) == pdPASS )
1851
1927
{
1852
1928
eReturn = eFrameConsumed ;
1853
1929
}
1854
1930
else
1855
1931
{
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 )
1858
1934
{
1859
- eReturn = eWaitingARPResolution ;
1935
+ eReturn = eWaitingResolution ;
1860
1936
}
1861
1937
}
1862
1938
}
@@ -2014,21 +2090,21 @@ static eFrameProcessingResult_t prvProcessIPPacket( const IPPacket_t * pxIPPacke
2014
2090
/* coverity[const] */
2015
2091
if ( eReturn != eReleaseBuffer )
2016
2092
{
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
2018
2094
* already there - otherwise refresh the age of the existing
2019
2095
* entry. */
2020
2096
if ( ucProtocol != ( uint8_t ) ipPROTOCOL_UDP )
2021
2097
{
2022
- if ( xCheckRequiresARPResolution ( pxNetworkBuffer ) == pdTRUE )
2098
+ if ( xCheckRequiresResolution ( pxNetworkBuffer ) == pdTRUE )
2023
2099
{
2024
- eReturn = eWaitingARPResolution ;
2100
+ eReturn = eWaitingResolution ;
2025
2101
}
2026
2102
else
2027
2103
{
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
2029
2105
* packet. For UDP packets, this will be done later in
2030
2106
* 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
2032
2108
* overwritten with the IP address of useless broadcast packets. */
2033
2109
/* Case default is never toggled because eReturn is not eProcessBuffer in previous step. */
2034
2110
switch ( pxIPPacket -> xEthernetHeader .usFrameType ) /* LCOV_EXCL_BR_LINE */
@@ -2054,7 +2130,7 @@ static eFrameProcessingResult_t prvProcessIPPacket( const IPPacket_t * pxIPPacke
2054
2130
}
2055
2131
}
2056
2132
2057
- if ( eReturn != eWaitingARPResolution )
2133
+ if ( eReturn != eWaitingResolution )
2058
2134
{
2059
2135
switch ( ucProtocol )
2060
2136
{
@@ -2171,7 +2247,7 @@ void vReturnEthernetFrame( NetworkBufferDescriptor_t * pxNetworkBuffer,
2171
2247
2172
2248
#if ( ipconfigUSE_IPv4 != 0 )
2173
2249
MACAddress_t xMACAddress ;
2174
- eARPLookupResult_t eResult ;
2250
+ eResolutionLookupResult_t eResult ;
2175
2251
uint32_t ulDestinationIPAddress = 0U ;
2176
2252
#endif /* ( ipconfigUSE_IPv4 != 0 ) */
2177
2253
@@ -2219,7 +2295,7 @@ void vReturnEthernetFrame( NetworkBufferDescriptor_t * pxNetworkBuffer,
2219
2295
* address. */
2220
2296
eResult = eARPGetCacheEntry ( & ulDestinationIPAddress , & xMACAddress , & ( pxNetworkBuffer -> pxEndPoint ) );
2221
2297
2222
- if ( eResult == eARPCacheHit )
2298
+ if ( eResult == eResolutionCacheHit )
2223
2299
{
2224
2300
/* Best case scenario - an address is found, use it. */
2225
2301
pvCopySource = & xMACAddress ;
@@ -2235,7 +2311,7 @@ void vReturnEthernetFrame( NetworkBufferDescriptor_t * pxNetworkBuffer,
2235
2311
case ipIPv6_FRAME_TYPE :
2236
2312
case ipARP_FRAME_TYPE :
2237
2313
default :
2238
- /* In case of ARP frame, just swap the source and destination MAC addresses. */
2314
+ /* Just swap the source and destination MAC addresses. */
2239
2315
pvCopySource = & ( pxIPPacket -> xEthernetHeader .xSourceAddress );
2240
2316
break ;
2241
2317
}
@@ -2262,7 +2338,7 @@ void vReturnEthernetFrame( NetworkBufferDescriptor_t * pxNetworkBuffer,
2262
2338
{
2263
2339
IPStackEvent_t xSendEvent ;
2264
2340
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. */
2266
2342
xSendEvent .eEventType = eNetworkTxEvent ;
2267
2343
xSendEvent .pvData = pxNetworkBuffer ;
2268
2344
0 commit comments