@@ -151,10 +151,6 @@ eFrameProcessingResult_t eARPProcessPacket( const NetworkBufferDescriptor_t * px
151151 void * pvCopyDest ;
152152 NetworkEndPoint_t * pxTargetEndPoint = pxNetworkBuffer -> pxEndPoint ;
153153
154- #if ( ipconfigARP_USE_CLASH_DETECTION != 0 )
155- NetworkEndPoint_t * pxSourceEndPoint ;
156- #endif
157-
158154 /* Next defensive request must not be sent for arpIP_CLASH_RESET_TIMEOUT_MS
159155 * period. */
160156 static TickType_t uxARPClashTimeoutPeriod = pdMS_TO_TICKS ( arpIP_CLASH_RESET_TIMEOUT_MS );
@@ -241,7 +237,7 @@ eFrameProcessingResult_t eARPProcessPacket( const NetworkBufferDescriptor_t * px
241237 /* Process received ARP frame to see if there is a clash. */
242238 #if ( ipconfigARP_USE_CLASH_DETECTION != 0 )
243239 {
244- pxSourceEndPoint = FreeRTOS_FindEndPointOnIP_IPv4 ( ulSenderProtocolAddress , 2 );
240+ NetworkEndPoint_t * pxSourceEndPoint = FreeRTOS_FindEndPointOnIP_IPv4 ( ulSenderProtocolAddress , 2 );
245241
246242 if ( ( pxSourceEndPoint != NULL ) && ( pxSourceEndPoint -> ipv4_settings .ulIPAddress == ulSenderProtocolAddress ) )
247243 {
@@ -419,7 +415,8 @@ static void vARPProcessPacketReply( const ARPPacket_t * pxARPFrame,
419415 vARPRefreshCacheEntry ( & ( pxARPHeader -> xSenderHardwareAddress ), ulSenderProtocolAddress , pxTargetEndPoint );
420416 }
421417
422- if ( pxARPWaitingNetworkBuffer != NULL )
418+ if ( ( pxARPWaitingNetworkBuffer != NULL ) &&
419+ ( uxIPHeaderSizePacket ( pxARPWaitingNetworkBuffer ) == ipSIZE_OF_IPv4_HEADER ) )
423420 {
424421 /* MISRA Ref 11.3.1 [Misaligned access] */
425422/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */
@@ -499,24 +496,70 @@ BaseType_t xCheckRequiresARPResolution( const NetworkBufferDescriptor_t * pxNetw
499496{
500497 BaseType_t xNeedsARPResolution = pdFALSE ;
501498
502- /* MISRA Ref 11.3.1 [Misaligned access] */
503- /* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */
504- /* coverity[misra_c_2012_rule_11_3_violation] */
505- const IPPacket_t * pxIPPacket = ( ( IPPacket_t * ) pxNetworkBuffer -> pucEthernetBuffer );
506- const IPHeader_t * pxIPHeader = & ( pxIPPacket -> xIPHeader );
507- IPV4Parameters_t * pxIPv4Settings = & ( pxNetworkBuffer -> pxEndPoint -> ipv4_settings );
499+ if ( uxIPHeaderSizePacket ( pxNetworkBuffer ) == ipSIZE_OF_IPv6_HEADER )
500+ {
501+ const IPPacket_IPv6_t * pxIPPacket = ( ( IPPacket_IPv6_t * ) pxNetworkBuffer -> pucEthernetBuffer );
502+ const IPHeader_IPv6_t * pxIPHeader = & ( pxIPPacket -> xIPHeader );
503+ IPv6_Address_t * pxIPAddress = & ( pxIPHeader -> xSourceAddress );
504+ uint8_t ucNextHeader = pxIPHeader -> ucNextHeader ;
505+
506+ if ( ( ucNextHeader == ipPROTOCOL_TCP ) ||
507+ ( ucNextHeader == ipPROTOCOL_UDP ) )
508+ {
509+ IPv6_Type_t eType = xIPv6_GetIPType ( pxIPAddress );
510+ FreeRTOS_printf ( ( "xCheckRequiresARPResolution: %pip type %s\n" , pxIPAddress -> ucBytes , ( eType == eIPv6_Global ) ? "Global" : ( eType == eIPv6_LinkLocal ) ? "LinkLocal" : "other" ) );
511+
512+ if ( eType == eIPv6_LinkLocal )
513+ {
514+ MACAddress_t xMACAddress ;
515+ NetworkEndPoint_t * pxEndPoint ;
516+ eARPLookupResult_t eResult ;
517+ char pcName [ 80 ];
518+
519+ eResult = eNDGetCacheEntry ( pxIPAddress , & xMACAddress , & pxEndPoint );
520+ FreeRTOS_printf ( ( "xCheckRequiresARPResolution: eResult %s with EP %s\n" , ( eResult == eARPCacheMiss ) ? "Miss" : ( eResult == eARPCacheHit ) ? "Hit" : "Error" , pcEndpointName ( pxEndPoint , pcName , sizeof pcName ) ) );
521+
522+ if ( eResult == eARPCacheMiss )
523+ {
524+ NetworkBufferDescriptor_t * pxTempBuffer ;
525+ size_t uxNeededSize ;
526+
527+ uxNeededSize = ipSIZE_OF_ETH_HEADER + ipSIZE_OF_IPv6_HEADER + sizeof ( ICMPRouterSolicitation_IPv6_t );
528+ pxTempBuffer = pxGetNetworkBufferWithDescriptor ( BUFFER_FROM_WHERE_CALL ( 199 ) uxNeededSize , 0U );
508529
509- if ( ( pxIPHeader -> ulSourceIPAddress & pxIPv4Settings -> ulNetMask ) == ( pxIPv4Settings -> ulIPAddress & pxIPv4Settings -> ulNetMask ) )
530+ if ( pxTempBuffer != NULL )
531+ {
532+ pxTempBuffer -> pxEndPoint = pxNetworkBuffer -> pxEndPoint ;
533+ pxTempBuffer -> pxInterface = pxNetworkBuffer -> pxInterface ;
534+ vNDSendNeighbourSolicitation ( pxNetworkBuffer , pxIPAddress );
535+ }
536+
537+ xNeedsARPResolution = pdTRUE ;
538+ }
539+ }
540+ }
541+ }
542+ else
510543 {
511- /* If the IP is on the same subnet and we do not have an ARP entry already,
512- * then we should send out ARP for finding the MAC address. */
513- if ( xIsIPInARPCache ( pxIPHeader -> ulSourceIPAddress ) == pdFALSE )
544+ /* MISRA Ref 11.3.1 [Misaligned access] */
545+ /* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */
546+ /* coverity[misra_c_2012_rule_11_3_violation] */
547+ const IPPacket_t * pxIPPacket = ( ( IPPacket_t * ) pxNetworkBuffer -> pucEthernetBuffer );
548+ const IPHeader_t * pxIPHeader = & ( pxIPPacket -> xIPHeader );
549+ IPV4Parameters_t * pxIPv4Settings = & ( pxNetworkBuffer -> pxEndPoint -> ipv4_settings );
550+
551+ if ( ( pxIPHeader -> ulSourceIPAddress & pxIPv4Settings -> ulNetMask ) == ( pxIPv4Settings -> ulIPAddress & pxIPv4Settings -> ulNetMask ) )
514552 {
515- FreeRTOS_OutputARPRequest ( pxIPHeader -> ulSourceIPAddress );
553+ /* If the IP is on the same subnet and we do not have an ARP entry already,
554+ * then we should send out ARP for finding the MAC address. */
555+ if ( xIsIPInARPCache ( pxIPHeader -> ulSourceIPAddress ) == pdFALSE )
556+ {
557+ FreeRTOS_OutputARPRequest ( pxIPHeader -> ulSourceIPAddress );
516558
517- /* This packet needs resolution since this is on the same subnet
518- * but not in the ARP cache. */
519- xNeedsARPResolution = pdTRUE ;
559+ /* This packet needs resolution since this is on the same subnet
560+ * but not in the ARP cache. */
561+ xNeedsARPResolution = pdTRUE ;
562+ }
520563 }
521564 }
522565
0 commit comments