diff --git a/source/FreeRTOS_IPv6.c b/source/FreeRTOS_IPv6.c index 33076e6e9..701f8ef2f 100644 --- a/source/FreeRTOS_IPv6.c +++ b/source/FreeRTOS_IPv6.c @@ -132,7 +132,9 @@ const struct xIPv6_Address FreeRTOS_in6addr_loopback = { { 0, 0, 0, 0, 0, 0, 0, /* Check if the complete IPv6-header plus protocol data have been transferred: */ usPayloadLength = FreeRTOS_ntohs( pxIPv6Packet->xIPHeader.usPayloadLength ); - if( uxBufferLength != ( size_t ) ( ipSIZE_OF_ETH_HEADER + ipSIZE_OF_IPv6_HEADER + ( size_t ) usPayloadLength ) ) + /* Since network interface might put some data in the network buffer, + * we allow buffer length to be greater than necessary. */ + if( uxBufferLength < ( size_t ) ( ipSIZE_OF_ETH_HEADER + ipSIZE_OF_IPv6_HEADER + ( size_t ) usPayloadLength ) ) { DEBUG_SET_TRACE_VARIABLE( xLocation, 4 ); break; diff --git a/test/unit-test/FreeRTOS_IPv6_ConfigDriverCheckChecksum/FreeRTOS_IPv6_ConfigDriverCheckChecksum_stubs.c b/test/unit-test/FreeRTOS_IPv6_ConfigDriverCheckChecksum/FreeRTOS_IPv6_ConfigDriverCheckChecksum_stubs.c index 2895fb0e6..ea4581a1f 100644 --- a/test/unit-test/FreeRTOS_IPv6_ConfigDriverCheckChecksum/FreeRTOS_IPv6_ConfigDriverCheckChecksum_stubs.c +++ b/test/unit-test/FreeRTOS_IPv6_ConfigDriverCheckChecksum/FreeRTOS_IPv6_ConfigDriverCheckChecksum_stubs.c @@ -51,6 +51,9 @@ const IPv6_Address_t xIPAddressTen = { 0x20, 0x01, 0x12, 0x34, 0x56, 0x78, 0x00, /* MAC Address for endpoint. */ const uint8_t ucMACAddress[ ipMAC_ADDRESS_LENGTH_BYTES ] = { 0xab, 0xcd, 0xef, 0x11, 0x22, 0x33 }; +/* Default payload length in this test. */ +#define TEST_DEFAULT_PROTOCOL_PAYLOAD_LENGTH ( 8U ) + /* ======================== Stub Callback Functions ========================= */ NetworkEndPoint_t * prvInitializeEndpoint() @@ -74,14 +77,14 @@ NetworkEndPoint_t * prvInitializeEndpoint() NetworkBufferDescriptor_t * prvInitializeNetworkDescriptor() { static NetworkBufferDescriptor_t xNetworkBuffer; - static uint8_t pcNetworkBuffer[ sizeof( TCPPacket_IPv6_t ) + 8U ]; + static uint8_t pcNetworkBuffer[ sizeof( TCPPacket_IPv6_t ) + TEST_DEFAULT_PROTOCOL_PAYLOAD_LENGTH ]; TCPPacket_IPv6_t * pxTCPPacket = ( TCPPacket_IPv6_t * ) pcNetworkBuffer; /* Initialize network buffer descriptor. */ memset( &xNetworkBuffer, 0, sizeof( xNetworkBuffer ) ); xNetworkBuffer.pxEndPoint = prvInitializeEndpoint(); xNetworkBuffer.pucEthernetBuffer = ( uint8_t * ) pxTCPPacket; - xNetworkBuffer.xDataLength = sizeof( TCPPacket_IPv6_t ) + 8U; + xNetworkBuffer.xDataLength = sizeof( TCPPacket_IPv6_t ) + TEST_DEFAULT_PROTOCOL_PAYLOAD_LENGTH; /* Initialize network buffer. */ memset( pcNetworkBuffer, 0, sizeof( pcNetworkBuffer ) ); @@ -93,7 +96,7 @@ NetworkBufferDescriptor_t * prvInitializeNetworkDescriptor() memcpy( pxTCPPacket->xIPHeader.xSourceAddress.ucBytes, xIPAddressTen.ucBytes, sizeof( IPv6_Address_t ) ); memcpy( pxTCPPacket->xIPHeader.xDestinationAddress.ucBytes, xIPAddressFive.ucBytes, sizeof( IPv6_Address_t ) ); pxTCPPacket->xIPHeader.ucVersionTrafficClass |= 6U << 4; - pxTCPPacket->xIPHeader.usPayloadLength = FreeRTOS_htons( sizeof( TCPHeader_t ) + 8U ); + pxTCPPacket->xIPHeader.usPayloadLength = FreeRTOS_htons( sizeof( TCPHeader_t ) + TEST_DEFAULT_PROTOCOL_PAYLOAD_LENGTH ); pxTCPPacket->xIPHeader.ucNextHeader = ipPROTOCOL_TCP; return &xNetworkBuffer; diff --git a/test/unit-test/FreeRTOS_IPv6_ConfigDriverCheckChecksum/FreeRTOS_IPv6_ConfigDriverCheckChecksum_utest.c b/test/unit-test/FreeRTOS_IPv6_ConfigDriverCheckChecksum/FreeRTOS_IPv6_ConfigDriverCheckChecksum_utest.c index 8404b9ba2..00aef5bd7 100644 --- a/test/unit-test/FreeRTOS_IPv6_ConfigDriverCheckChecksum/FreeRTOS_IPv6_ConfigDriverCheckChecksum_utest.c +++ b/test/unit-test/FreeRTOS_IPv6_ConfigDriverCheckChecksum/FreeRTOS_IPv6_ConfigDriverCheckChecksum_utest.c @@ -145,8 +145,8 @@ void test_prvAllowIPPacketIPv6_xCheckIPv6SizeFields_wrong_ip_length() NetworkBufferDescriptor_t * pxNetworkBuffer = prvInitializeNetworkDescriptor(); IPPacket_IPv6_t * pxIPPacket = ( IPPacket_IPv6_t * ) pxNetworkBuffer->pucEthernetBuffer; - /* Modify the length in IP header */ - pxIPPacket->xIPHeader.usPayloadLength = FreeRTOS_htons( sizeof( TCPHeader_t ) ); + /* Modify the length in IP header to be greater than data length. */ + pxIPPacket->xIPHeader.usPayloadLength = FreeRTOS_htons( sizeof( TCPHeader_t ) + TEST_DEFAULT_PROTOCOL_PAYLOAD_LENGTH + 1U ); eResult = prvAllowIPPacketIPv6( &pxIPPacket->xIPHeader, pxNetworkBuffer, 0U ); TEST_ASSERT_EQUAL( eReleaseBuffer, eResult );