@@ -93,7 +93,6 @@ const struct xIPv6_Address FreeRTOS_in6addr_loopback = { { 0U, 0U, 0U, 0U, 0U, 0
9393 size_t uxBufferLength )
9494 {
9595 BaseType_t xResult = pdFAIL ;
96- uint16_t ucVersionTrafficClass ;
9796 uint16_t usPayloadLength ;
9897 uint8_t ucNextHeader ;
9998 size_t uxMinimumLength ;
@@ -116,15 +115,6 @@ const struct xIPv6_Address FreeRTOS_in6addr_loopback = { { 0U, 0U, 0U, 0U, 0U, 0
116115 break ;
117116 }
118117
119- ucVersionTrafficClass = pxIPv6Packet -> xIPHeader .ucVersionTrafficClass ;
120-
121- /* Test if the IP-version is 6. */
122- if ( ( ( ucVersionTrafficClass & ( uint8_t ) 0xF0U ) >> 4 ) != 6U )
123- {
124- DEBUG_SET_TRACE_VARIABLE ( xLocation , 2 );
125- break ;
126- }
127-
128118 /* Check if the IPv6-header is transferred. */
129119 if ( uxBufferLength < ( ipSIZE_OF_ETH_HEADER + ipSIZE_OF_IPv6_HEADER ) )
130120 {
@@ -497,6 +487,7 @@ eFrameProcessingResult_t prvAllowIPPacketIPv6( const IPHeader_IPv6_t * const pxI
497487 const IPv6_Address_t * pxDestinationIPAddress = & ( pxIPv6Header -> xDestinationAddress );
498488 const IPv6_Address_t * pxSourceIPAddress = & ( pxIPv6Header -> xSourceAddress );
499489 BaseType_t xHasUnspecifiedAddress = pdFALSE ;
490+ uint16_t ucVersionTrafficClass = pxIPv6Header -> ucVersionTrafficClass ;
500491
501492 /* Drop if packet has unspecified IPv6 address (defined in RFC4291 - sec 2.5.2)
502493 * either in source or destination address. */
@@ -506,10 +497,17 @@ eFrameProcessingResult_t prvAllowIPPacketIPv6( const IPHeader_IPv6_t * const pxI
506497 xHasUnspecifiedAddress = pdTRUE ;
507498 }
508499
500+ /* Test if the IP-version is 6. */
501+ if ( ( ( ucVersionTrafficClass & ( uint8_t ) 0xF0U ) >> 4 ) != 6U )
502+ {
503+ /* Can not handle, unknown or invalid header version. */
504+ eReturn = eReleaseBuffer ;
505+ FreeRTOS_printf ( ( "prvAllowIPPacketIPv6: drop packet, invalid header version: %u\n" , ( ucVersionTrafficClass & ( uint8_t ) 0xF0U ) >> 4 ) );
506+ }
509507 /* Is the packet for this IP address? */
510- if ( ( xHasUnspecifiedAddress == pdFALSE ) &&
511- ( pxNetworkBuffer -> pxEndPoint != NULL ) &&
512- ( memcmp ( pxDestinationIPAddress -> ucBytes , pxNetworkBuffer -> pxEndPoint -> ipv6_settings .xIPAddress .ucBytes , sizeof ( IPv6_Address_t ) ) == 0 ) )
508+ else if ( ( xHasUnspecifiedAddress == pdFALSE ) &&
509+ ( pxNetworkBuffer -> pxEndPoint != NULL ) &&
510+ ( memcmp ( pxDestinationIPAddress -> ucBytes , pxNetworkBuffer -> pxEndPoint -> ipv6_settings .xIPAddress .ucBytes , sizeof ( IPv6_Address_t ) ) == 0 ) )
513511 {
514512 eReturn = eProcessBuffer ;
515513 }
0 commit comments