@@ -1556,6 +1556,54 @@ void test_vNDSendNeighbourSolicitation_HappyPath( void )
15561556 ( void ) memset ( xNDCache , 0 , sizeof ( xNDCache ) );
15571557}
15581558
1559+ /**
1560+ * @brief When the cache has no slot that may be reclaimed, the solicitation still
1561+ * goes out but cannot be recorded. Nothing is learned from the advertisement
1562+ * that answers it, which is the safe outcome: better to fail to resolve than
1563+ * to accept a binding this stack cannot vouch for.
1564+ */
1565+ void test_vNDSendNeighbourSolicitation_CacheFull_NoRecord ( void )
1566+ {
1567+ IPv6_Address_t xIPAddress ;
1568+ NetworkBufferDescriptor_t xNetworkBuffer ;
1569+ ICMPPacket_IPv6_t xICMPPacket ;
1570+ NetworkEndPoint_t xEndPoint ;
1571+ BaseType_t x ;
1572+
1573+ ( void ) memset ( xNDCache , 0 , sizeof ( xNDCache ) );
1574+ ( void ) memset ( & xEndPoint , 0 , sizeof ( xEndPoint ) );
1575+ ( void ) memset ( & xNetworkBuffer , 0 , sizeof ( xNetworkBuffer ) );
1576+ xEndPoint .bits .bIPv6 = 1 ;
1577+ xNetworkBuffer .pxEndPoint = & xEndPoint ;
1578+ xNetworkBuffer .xDataLength = xHeaderSize ;
1579+ xNetworkBuffer .pucEthernetBuffer = ( uint8_t * ) & xICMPPacket ;
1580+ ( void ) memcpy ( xIPAddress .ucBytes , xDefaultIPAddress .ucBytes , ipSIZE_OF_IPv6_ADDRESS );
1581+
1582+ /* Every slot holds a router, the one kind of entry that is never reclaimed. */
1583+ for ( x = 0 ; x < ipconfigND_CACHE_ENTRIES ; x ++ )
1584+ {
1585+ xNDCache [ x ].ucState = eND_REACHABLE ;
1586+ xNDCache [ x ].ucAge = 200U ;
1587+ xNDCache [ x ].ucFlags = 0x01U ; /* ndpFLAG_IS_ROUTER */
1588+ ( void ) memcpy ( xNDCache [ x ].xIPAddress .ucBytes , xGatewayIPAddress .ucBytes , ipSIZE_OF_IPv6_ADDRESS );
1589+ xNDCache [ x ].xIPAddress .ucBytes [ 15 ] = ( uint8_t ) ( 0x60 + x );
1590+ }
1591+
1592+ usGenerateProtocolChecksum_IgnoreAndReturn ( ipCORRECT_CRC );
1593+ vReturnEthernetFrame_ExpectAnyArgs ();
1594+
1595+ vNDSendNeighbourSolicitation ( & xNetworkBuffer , & xIPAddress );
1596+
1597+ /* The cache is unchanged: no slot was taken for the solicited address. */
1598+ for ( x = 0 ; x < ipconfigND_CACHE_ENTRIES ; x ++ )
1599+ {
1600+ TEST_ASSERT_EQUAL ( xNDCache [ x ].ucState , eND_REACHABLE );
1601+ TEST_ASSERT_EQUAL ( xNDCache [ x ].xIPAddress .ucBytes [ 15 ], ( uint8_t ) ( 0x60 + x ) );
1602+ }
1603+
1604+ ( void ) memset ( xNDCache , 0 , sizeof ( xNDCache ) );
1605+ }
1606+
15591607/**
15601608 * @brief Re-transmitting a solicitation for an address that is already being
15611609 * resolved must restart its timeout rather than add a second entry, and a
@@ -3431,6 +3479,85 @@ void test_prvProcessNA_MalformedOptionZeroLength_Dropped( void )
34313479 TEST_ASSERT_EQUAL ( xNDCache [ 0 ].ucState , eND_FREE );
34323480}
34333481
3482+ /**
3483+ * @brief An NDP option that claims to be longer than the bytes the IPv6 payload
3484+ * actually leaves is malformed: walking it would read past the packet, so
3485+ * the advertisement is dropped.
3486+ */
3487+ void test_prvProcessNA_OptionLengthPastEndOfPacket_Dropped ( void )
3488+ {
3489+ NetworkBufferDescriptor_t xNetworkBuffer , * pxNetworkBuffer = & xNetworkBuffer ;
3490+ ICMPPacket_IPv6_t xICMPPacket ;
3491+ NetworkEndPoint_t xEndPoint ;
3492+ eFrameProcessingResult_t eReturn ;
3493+ MACAddress_t xNewMAC = { { 0x02 , 0x11 , 0x22 , 0x33 , 0x44 , 0x55 } };
3494+
3495+ ( void ) memset ( xNDCache , 0 , sizeof ( xNDCache ) );
3496+ ( void ) memset ( & xEndPoint , 0 , sizeof ( xEndPoint ) );
3497+ xEndPoint .bits .bIPv6 = pdTRUE_UNSIGNED ;
3498+
3499+ prvSeedSolicitedEntry ( 0 , & xDefaultIPAddress );
3500+
3501+ prvBuildNaPacket ( & xICMPPacket , ndTEST_FLAG_SOLICITED , & xDefaultIPAddress , & xNewMAC );
3502+
3503+ /* The payload leaves room for one 8-byte unit, but the option claims two. */
3504+ xICMPPacket .xICMPHeaderIPv6 .ucOptionLength = 2U ;
3505+
3506+ pxNetworkBuffer -> pucEthernetBuffer = ( uint8_t * ) & xICMPPacket ;
3507+ pxNetworkBuffer -> pxEndPoint = & xEndPoint ;
3508+ pxNetworkBuffer -> xDataLength = sizeof ( ICMPPacket_IPv6_t );
3509+ pxNDWaitingNetworkBuffer = NULL ;
3510+
3511+ eReturn = prvProcessICMPMessage_IPv6 ( pxNetworkBuffer );
3512+
3513+ TEST_ASSERT_EQUAL ( eReturn , eReleaseBuffer );
3514+ /* Dropped before the state machine: the outstanding resolution is untouched. */
3515+ TEST_ASSERT_EQUAL ( xNDCache [ 0 ].ucState , eND_INCOMPLETE );
3516+
3517+ ( void ) memset ( xNDCache , 0 , sizeof ( xNDCache ) );
3518+ }
3519+
3520+ /**
3521+ * @brief An NDP option of a type this stack does not care about must simply be
3522+ * stepped over. With only such an option present nothing is learned, so an
3523+ * outstanding resolution stays outstanding.
3524+ */
3525+ void test_prvProcessNA_NonTllaOption_SkippedAndDropped ( void )
3526+ {
3527+ NetworkBufferDescriptor_t xNetworkBuffer , * pxNetworkBuffer = & xNetworkBuffer ;
3528+ ICMPPacket_IPv6_t xICMPPacket ;
3529+ NetworkEndPoint_t xEndPoint ;
3530+ eFrameProcessingResult_t eReturn ;
3531+ MACAddress_t xNewMAC = { { 0x02 , 0x11 , 0x22 , 0x33 , 0x44 , 0x55 } };
3532+
3533+ ( void ) memset ( xNDCache , 0 , sizeof ( xNDCache ) );
3534+ ( void ) memset ( & xEndPoint , 0 , sizeof ( xEndPoint ) );
3535+ xEndPoint .bits .bIPv6 = pdTRUE_UNSIGNED ;
3536+
3537+ prvSeedSolicitedEntry ( 0 , & xDefaultIPAddress );
3538+
3539+ prvBuildNaPacket ( & xICMPPacket , ndTEST_FLAG_SOLICITED , & xDefaultIPAddress , & xNewMAC );
3540+
3541+ /* A Source Link-Layer Address option has no meaning in an advertisement. */
3542+ xICMPPacket .xICMPHeaderIPv6 .ucOptionType = ndICMP_SOURCE_LINK_LAYER_ADDRESS ;
3543+
3544+ pxNetworkBuffer -> pucEthernetBuffer = ( uint8_t * ) & xICMPPacket ;
3545+ pxNetworkBuffer -> pxEndPoint = & xEndPoint ;
3546+ pxNetworkBuffer -> xDataLength = sizeof ( ICMPPacket_IPv6_t );
3547+ pxNDWaitingNetworkBuffer = NULL ;
3548+
3549+ FreeRTOS_FirstEndPoint_IgnoreAndReturn ( NULL );
3550+
3551+ eReturn = prvProcessICMPMessage_IPv6 ( pxNetworkBuffer );
3552+
3553+ TEST_ASSERT_EQUAL ( eReturn , eReleaseBuffer );
3554+ /* No target link-layer address was found, so nothing could be learned. */
3555+ TEST_ASSERT_EQUAL ( xNDCache [ 0 ].ucState , eND_INCOMPLETE );
3556+ TEST_ASSERT_EACH_EQUAL_UINT8 ( 0 , xNDCache [ 0 ].xMACAddress .ucBytes , ipMAC_ADDRESS_LENGTH_BYTES );
3557+
3558+ ( void ) memset ( xNDCache , 0 , sizeof ( xNDCache ) );
3559+ }
3560+
34343561/**
34353562 * @brief For an existing entry, an UNSOLICITED, Override=1 NA whose MAC matches
34363563 * the cached one is a no-op (eNA_MAINTAIN): neither the MAC nor the state
0 commit comments