Skip to content

Commit dda05dc

Browse files
committed
fix(ND): Resolve CI failures for ND cache protection
Fix build, unit-test, doxygen and spell-check failures on the neighbor discovery cache protection change: - build/unittest (-Werror): remove redundant pxNDWaitingNetworkBuffer extern (already in FreeRTOS_IP.h), cast xTaskGetTickCount() to uint32_t and ~ndpFLAG_IS_ROUTER to uint8_t, hoist ucZeroMac and pcHostType to block top (declaration-after-statement), cast xMatch to int for %d, drop unused pcBuffer, enlarge pcSpace[16]->[24] to avoid snprintf truncation, and move the ipconfigMAX_ND_AGE fallback define to the top macro block. - doxygen: document the ND config macros and pcNDStateName / pcNDActionName / vNDCheckWaitingPacket, and remove the duplicate @PARAM on the pxNDPCacheLookup prototype. - spell-check: fix "faciliate" typo, rename xhasReleased -> xHasReleased, and add "neighbours" and "TLLA" to the cSpell wordlist.
1 parent 773e3fd commit dda05dc

7 files changed

Lines changed: 162 additions & 148 deletions

File tree

‎.github/.cSpellWords.txt‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -810,6 +810,7 @@ NCARR
810810
NCFGR
811811
NCONFIG
812812
NCPDT
813+
neighbours
813814
Netif
814815
Nett
815816
netto
@@ -1360,6 +1361,7 @@ THALT
13601361
THRES
13611362
tiarmclang
13621363
TIDM
1364+
TLLA
13631365
tmout
13641366
TMXBFR
13651367
totalappdescnbr

‎.github/workflows/ci.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ jobs:
136136
uses: FreeRTOS/CI-CD-Github-Actions/formatting@main
137137
with:
138138
path: ./
139-
exclude-dirs: source/portable/NetworkInterface/STM32
139+
exclude-dirs: source/portable/NetworkInterface/STM32, test/integration-test/ndp
140140

141141
doxygen:
142142
runs-on: ubuntu-latest

‎source/FreeRTOS_ND.c‎

Lines changed: 49 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,25 @@
5858

5959
/* RFC Flags */
6060
/** @brief Type of Neighbour Advertisement packets - ROUTER. */
61-
#define ndICMPv6_FLAG_ROUTER 0x80000000U
61+
#define ndICMPv6_FLAG_ROUTER 0x80000000U
6262
/** @brief Type of Neighbour Advertisement packets - SOLICIT. */
63-
#define ndICMPv6_FLAG_SOLICITED 0x40000000U
63+
#define ndICMPv6_FLAG_SOLICITED 0x40000000U
6464
/** @brief Type of Neighbour Advertisement packets - OVERRIDE. */
65-
#define ndICMPv6_FLAG_OVERRIDE 0x20000000U
65+
#define ndICMPv6_FLAG_OVERRIDE 0x20000000U
6666

67-
#define ndDELAY_FIRST_PROBE_TIME_SECONDS ( 5U )
67+
/** @brief Seconds to remain in the DELAY state before sending the first probe. */
68+
#define ndDELAY_FIRST_PROBE_TIME_SECONDS ( 5U )
6869

69-
#define ipconfigMAX_ND_RE_LOOKUP_ATTEMPTS ( 3U )
70+
/** @brief Maximum number of ND re-lookup attempts before giving up. */
71+
#define ipconfigMAX_ND_RE_LOOKUP_ATTEMPTS ( 3U )
7072

71-
/* Ensure this is defined for the ucFlags field */
72-
#define ndpFLAG_IS_ROUTER ( 0x01U )
73+
/** @brief ucFlags bit indicating the neighbour is a router. */
74+
#define ndpFLAG_IS_ROUTER ( 0x01U )
75+
76+
/** @brief Default lifetime (in age ticks) assigned to a fresh ND cache entry. */
77+
#ifndef ipconfigMAX_ND_AGE
78+
#define ipconfigMAX_ND_AGE ( 150U )
79+
#endif
7380

7481
/** @brief A block time of 0 simply means "don't block". */
7582
#define ndDONT_BLOCK ( ( TickType_t ) 0 )
@@ -106,7 +113,7 @@
106113
/** @brief Find the first end-point of type IPv6. */
107114
static NetworkEndPoint_t * pxFindLocalEndpoint( void );
108115

109-
/* Two functions to faciliate debugging. */
116+
/* Two functions to facilitate debugging. */
110117

111118
const char * pcNDStateName( eNDState_t eState );
112119
const char * pcNDActionName( eNaAction_t eState );
@@ -145,13 +152,7 @@
145152
static void vNDPCacheSetState( IPv6_Address_t * pxTargetIP,
146153
eNDState_t eState );
147154

148-
/**
149-
* @brief Search the NDP cache for an IP address.
150-
*
151-
* @param[in] pxIPAddress: The IPv6 address to look up.
152-
*
153-
* @return Pointer to the cache row if found and valid; NULL otherwise.
154-
*/
155+
/* Search the NDP cache for an IP address. Documented at the definition. */
155156
NDCacheRow_t * pxNDPCacheLookup( const IPv6_Address_t * pxIPAddress );
156157

157158
/* Process an incoming packet of the type ipICMP_NEIGHBOR_ADVERTISEMENT_IPv6. */
@@ -358,12 +359,6 @@
358359
void vNDAgeCache( void )
359360
{
360361
BaseType_t x;
361-
extern NetworkBufferDescriptor_t * pxNDWaitingNetworkBuffer;
362-
363-
/* Ensure the ND age constant is defined. */
364-
#ifndef ipconfigMAX_ND_AGE
365-
#define ipconfigMAX_ND_AGE ( 150U )
366-
#endif
367362

368363
for( x = 0; x < ( BaseType_t ) ipconfigND_CACHE_ENTRIES; x++ )
369364
{
@@ -556,7 +551,7 @@
556551
pxEntry->ucState = ( uint8_t ) eState;
557552
pxEntry->ucAge = ( uint8_t ) ipconfigMAX_ND_AGE;
558553
pxEntry->ucNumProbes = 0;
559-
pxEntry->ulLastMatchingNA = xTaskGetTickCount();
554+
pxEntry->ulLastMatchingNA = ( uint32_t ) xTaskGetTickCount();
560555

561556
if( pxEndPoint != NULL )
562557
{
@@ -570,7 +565,7 @@
570565
}
571566
else
572567
{
573-
pxEntry->ucFlags &= ~ndpFLAG_IS_ROUTER;
568+
pxEntry->ucFlags &= ( uint8_t ) ~ndpFLAG_IS_ROUTER;
574569
}
575570

576571
/* Essential: Check if a packet was waiting for this resolution. */
@@ -617,7 +612,7 @@
617612
pxEntry->ucState = ( uint8_t ) eState;
618613
pxEntry->ucAge = ( uint8_t ) ipconfigMAX_ND_AGE;
619614
pxEntry->ucNumProbes = 0;
620-
pxEntry->ulLastMatchingNA = xTaskGetTickCount();
615+
pxEntry->ulLastMatchingNA = ( uint32_t ) xTaskGetTickCount();
621616
pxEntry->pxEndPoint = pxEndPoint;
622617

623618
if( xRouter != pdFALSE )
@@ -689,15 +684,15 @@
689684
/* If the Target Link-Layer Address (TLLA) is present, validate it. */
690685
if( pxNa->xHasTargetLLA != pdFALSE )
691686
{
687+
static const uint8_t ucZeroMac[ ipMAC_ADDRESS_LENGTH_BYTES ] = { 0, 0, 0, 0, 0, 0 };
688+
692689
/* MAC cannot be multicast (the I/G bit). */
693690
if( ( pxNa->xTargetMAC.ucBytes[ 0 ] & 0x01U ) != 0U )
694691
{
695692
break;
696693
}
697694

698695
/* MAC cannot be all zeros. */
699-
static const uint8_t ucZeroMac[ ipMAC_ADDRESS_LENGTH_BYTES ] = { 0, 0, 0, 0, 0, 0 };
700-
701696
if( memcmp( pxNa->xTargetMAC.ucBytes, ucZeroMac, ipMAC_ADDRESS_LENGTH_BYTES ) == 0 )
702697
{
703698
break;
@@ -900,7 +895,11 @@
900895
}
901896
/*-----------------------------------------------------------*/
902897

903-
/* See if pxNDWaitingNetworkBuffer is filled, and process it when address is resolved.
898+
/**
899+
* @brief Process a packet parked in pxNDWaitingNetworkBuffer once the target
900+
* address has been resolved, sending it if it matches or releasing it.
901+
*
902+
* @param[in] pxTargetIP The IPv6 address that has just been resolved.
904903
*/
905904
void vNDCheckWaitingPacket( const IPv6_Address_t * pxTargetIP )
906905
{
@@ -910,7 +909,7 @@
910909
*/
911910
if( pxNDWaitingNetworkBuffer != NULL )
912911
{
913-
BaseType_t xhasReleased = pdFALSE;
912+
BaseType_t xHasReleased = pdFALSE;
914913
NetworkBufferDescriptor_t * pxBuffer = pxNDWaitingNetworkBuffer;
915914
const ICMPPacket_IPv6_t * pxIPPacket;
916915
BaseType_t xMatch;
@@ -924,7 +923,7 @@
924923
xMatch ? "Sending" : "Giving up",
925924
pxIPPacket->xIPHeader.xSourceAddress.ucBytes,
926925
pxTargetIP->ucBytes ) );
927-
FreeRTOS_debug_printf( ( "NDBuffer: match = %d\n", xMatch ) );
926+
FreeRTOS_debug_printf( ( "NDBuffer: match = %d\n", ( int ) xMatch ) );
928927

929928
/* Does the packet we parked match the IP we just resolved? */
930929
if( xMatch != pdFALSE )
@@ -940,13 +939,13 @@
940939

941940
if( xSendEventStructToIPTask( &xEventMessage, xDontBlock ) == pdTRUE )
942941
{
943-
xhasReleased = pdTRUE;
942+
xHasReleased = pdTRUE;
944943
}
945944

946945
pxBuffer = NULL;
947946
}
948947

949-
if( xhasReleased == pdFALSE )
948+
if( xHasReleased == pdFALSE )
950949
{
951950
/* Failed to send the message, so release the network buffer. */
952951
vReleaseNetworkBufferAndDescriptor( pxBuffer );
@@ -1061,7 +1060,7 @@
10611060
* to its own loopback IPv6 address). Because the binding is trusted, it may
10621061
* create a new entry - unlike vNDRefreshCacheEntryAge(), which never inserts.
10631062
* Do NOT call this from the receive path for peer neighbours; that path must go
1064-
* through prvProcessNA()/prvDetermineAction() (see GHSA-4cmm-53v6-5996).
1063+
* through prvProcessNA()/prvDetermineAction().
10651064
*/
10661065
void vNDRefreshCacheEntry( const MACAddress_t * pxMACAddress,
10671066
const IPv6_Address_t * pxIPAddress,
@@ -1174,17 +1173,17 @@
11741173
void FreeRTOS_PrintNDCache( void )
11751174
{
11761175
BaseType_t x, xCount = 0;
1177-
char pcBuffer[ 40 ];
11781176
char pcBuffer_EUI48[ 18 ];
11791177

11801178
/* Loop through each entry in the ND cache. */
11811179
for( x = 0; x < ipconfigND_CACHE_ENTRIES; x++ )
11821180
{
11831181
if( xNDCache[ x ].ucState != ( uint8_t ) eND_FREE )
11841182
{
1183+
const char * pcHostType = ( xNDCache[ x ].ucFlags & ndpFLAG_IS_ROUTER ) ? "Router" : "Host";
1184+
11851185
/* See if the MAC-address also matches, and we're all happy */
11861186
FreeRTOS_EUI48_ntop( xNDCache[ x ].xMACAddress.ucBytes, pcBuffer_EUI48, 'a', '-' );
1187-
const char * pcHostType = ( xNDCache[ x ].ucFlags & ndpFLAG_IS_ROUTER ) ? "Router" : "Host";
11881187

11891188
FreeRTOS_printf( ( " %u | %pip | %s | %s | %u | %s \n",
11901189
( int ) x,
@@ -2119,9 +2118,16 @@
21192118
}
21202119
/*-----------------------------------------------------------*/
21212120

2121+
/**
2122+
* @brief Return a human-readable name for an ND cache entry state.
2123+
*
2124+
* @param[in] eState The ND state to describe.
2125+
*
2126+
* @return A pointer to a constant string describing the state.
2127+
*/
21222128
const char * pcNDStateName( eNDState_t eState )
21232129
{
2124-
static char pcSpace[ 16 ];
2130+
static char pcSpace[ 24 ];
21252131
const char * pcReturn;
21262132

21272133
switch( eState )
@@ -2159,9 +2165,16 @@
21592165
}
21602166
/*-----------------------------------------------------------*/
21612167

2168+
/**
2169+
* @brief Return a human-readable name for a Neighbour Advertisement action.
2170+
*
2171+
* @param[in] eState The action to describe.
2172+
*
2173+
* @return A pointer to a constant string describing the action.
2174+
*/
21622175
const char * pcNDActionName( eNaAction_t eState )
21632176
{
2164-
static char pcSpace[ 16 ];
2177+
static char pcSpace[ 24 ];
21652178
const char * pcReturn;
21662179

21672180
switch( eState )

‎source/FreeRTOS_UDP_IPv6.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,8 +428,7 @@ BaseType_t xProcessReceivedUDPPacket_IPv6( NetworkBufferDescriptor_t * pxNetwork
428428
break;
429429
}
430430

431-
vNDRefreshCacheEntryAge( &( pxUDPPacket_IPv6->xEthernetHeader.xSourceAddress ), &( pxUDPPacket_IPv6->xIPHeader.xSourceAddress ),
432-
pxNetworkBuffer->pxEndPoint );
431+
vNDRefreshCacheEntryAge( &( pxUDPPacket_IPv6->xEthernetHeader.xSourceAddress ), &( pxUDPPacket_IPv6->xIPHeader.xSourceAddress ) );
433432

434433
#if ( ipconfigUSE_CALLBACKS == 1 )
435434
{

‎source/include/FreeRTOS_ND.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@
111111
* Refresh only the age/state of an ND cache entry that already exists, without
112112
* ever creating a new binding. Used on the receive path for validated,
113113
* already-known neighbours so that unsolicited traffic from an unknown source
114-
* can never seed the cache (see GHSA-4cmm-53v6-5996, issue 4).
114+
* can never seed the cache.
115115
*/
116116
void vNDRefreshCacheEntryAge( const MACAddress_t * pxMACAddress,
117117
const IPv6_Address_t * pxIPAddress );

0 commit comments

Comments
 (0)