Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check minimum size of ICMPv6 packets #994

Merged
merged 18 commits into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
8128cdb
Not all ICMPv6 packets have the same minimum length
htibosch Aug 9, 2023
17b9672
More precise length checking
htibosch Aug 11, 2023
2fa9dc8
Repaired unit tests / coverage
htibosch Aug 21, 2023
8f2b658
Merge branch 'main' into Check_minimum_size_of_ICMPv6_packets
tony-josi-aws Aug 21, 2023
1ae4669
Running uncrustify
htibosch Aug 21, 2023
3c73bd3
Merge branch 'main' into Check_minimum_size_of_ICMPv6_packets
htibosch Aug 22, 2023
be89ee9
Merge branch 'main' into Check_minimum_size_of_ICMPv6_packets
ActoryOu Aug 22, 2023
67276f6
Merge branch 'main' into Check_minimum_size_of_ICMPv6_packets
kar-rahul-aws Sep 1, 2023
f0d02ee
Merge branch 'main' into Check_minimum_size_of_ICMPv6_packets
htibosch Sep 8, 2023
3c8a7bb
Merge branch 'main' into Check_minimum_size_of_ICMPv6_packets
htibosch Sep 10, 2023
937eeaf
Merge branch 'main' into Check_minimum_size_of_ICMPv6_packets
htibosch Sep 14, 2023
23ef3b6
Merge branch 'main' into Check_minimum_size_of_ICMPv6_packets
htibosch Sep 19, 2023
9d5696b
Merge branch 'main' into Check_minimum_size_of_ICMPv6_packets
htibosch Sep 19, 2023
dfc9b94
Merge branch 'main' into Check_minimum_size_of_ICMPv6_packets
htibosch Sep 22, 2023
7b0ed0a
Merge branch 'main' into Check_minimum_size_of_ICMPv6_packets
htibosch Sep 26, 2023
944f82f
Merge branch 'main' into Check_minimum_size_of_ICMPv6_packets
htibosch Oct 5, 2023
485b7d0
Merge branch 'main' into Check_minimum_size_of_ICMPv6_packets
moninom1 Oct 6, 2023
4a6aded
Merge branch 'main' into Check_minimum_size_of_ICMPv6_packets
moninom1 Oct 6, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion source/FreeRTOS_IPv6.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,29 @@ const struct xIPv6_Address FreeRTOS_in6addr_loopback = { { 0U, 0U, 0U, 0U, 0U, 0
}
else if( ucNextHeader == ( uint8_t ) ipPROTOCOL_ICMP_IPv6 )
{
uxMinimumLength = ipSIZE_OF_ETH_HEADER + ipSIZE_OF_IPv6_HEADER + uxExtHeaderLength + ipSIZE_OF_ICMPv6_HEADER;
uint8_t ucTypeOfMessage;

uxMinimumLength = ipSIZE_OF_ETH_HEADER + ipSIZE_OF_IPv6_HEADER + uxExtHeaderLength;

ucTypeOfMessage = pucEthernetBuffer[ uxMinimumLength ];

if( ( ucTypeOfMessage == ipICMP_PING_REQUEST_IPv6 ) ||
( ucTypeOfMessage == ipICMP_PING_REPLY_IPv6 ) )
{
uxMinimumLength += sizeof( ICMPEcho_IPv6_t );
}
else if( ucTypeOfMessage == ipICMP_ROUTER_SOLICITATION_IPv6 )
{
uxMinimumLength += sizeof( ICMPRouterSolicitation_IPv6_t );
}
else if( ucTypeOfMessage == ipICMP_ROUTER_ADVERTISEMENT_IPv6 )
{
uxMinimumLength += sizeof( ICMPRouterAdvertisement_IPv6_t );
}
else
{
uxMinimumLength += ipSIZE_OF_ICMPv6_HEADER;
ActoryOu marked this conversation as resolved.
Show resolved Hide resolved
}
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,10 @@ void test_prvAllowIPPacketIPv6_xCheckIPv6SizeFields_length_less_than_UDP_min_req
}

/**
* @brief test_prvAllowIPPacketIPv6_xCheckIPv6SizeFields_length_less_than_ICMP_min_requirement
* @brief test_prvAllowIPPacketIPv6_xCheckIPv6SizeFields_length_less_than_ICMP_min_requirement_1
* The buffer size is less than ICMP packet minimal requirement. Check if prvAllowIPPacketIPv6 determines to release it.
*/
void test_prvAllowIPPacketIPv6_xCheckIPv6SizeFields_length_less_than_ICMP_min_requirement()
void test_prvAllowIPPacketIPv6_xCheckIPv6SizeFields_length_less_than_ICMP_min_requirement_1()
{
eFrameProcessingResult_t eResult;
NetworkBufferDescriptor_t * pxNetworkBuffer = prvInitializeNetworkDescriptor();
Expand All @@ -241,12 +241,95 @@ void test_prvAllowIPPacketIPv6_xCheckIPv6SizeFields_length_less_than_ICMP_min_re
/* Set next header to ICMPv6 */
pxIPPacket->xIPHeader.ucNextHeader = ipPROTOCOL_ICMP_IPv6;
pxNetworkBuffer->xDataLength = ipSIZE_OF_ETH_HEADER + ipSIZE_OF_IPv6_HEADER + 1;
pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + ipSIZE_OF_IPv6_HEADER ] = ipICMP_ROUTER_SOLICITATION_IPv6;
pxIPPacket->xIPHeader.usPayloadLength = FreeRTOS_htons( 1 );

eResult = prvAllowIPPacketIPv6( &pxIPPacket->xIPHeader, pxNetworkBuffer, 0U );
TEST_ASSERT_EQUAL( eReleaseBuffer, eResult );
}

/**
* @brief test_prvAllowIPPacketIPv6_xCheckIPv6SizeFields_length_less_than_ICMP_min_requirement_2
* The buffer size is less than ICMP packet minimal requirement. Check if prvAllowIPPacketIPv6 determines to release it.
*/
void test_prvAllowIPPacketIPv6_xCheckIPv6SizeFields_length_less_than_ICMP_min_requirement_2()
{
eFrameProcessingResult_t eResult;
NetworkBufferDescriptor_t * pxNetworkBuffer = prvInitializeNetworkDescriptor();
IPPacket_IPv6_t * pxIPPacket = ( IPPacket_IPv6_t * ) pxNetworkBuffer->pucEthernetBuffer;

/* Set next header to ICMPv6 */
pxIPPacket->xIPHeader.ucNextHeader = ipPROTOCOL_ICMP_IPv6;
pxNetworkBuffer->xDataLength = ipSIZE_OF_ETH_HEADER + ipSIZE_OF_IPv6_HEADER + 1;
pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + ipSIZE_OF_IPv6_HEADER ] = ipICMP_ROUTER_ADVERTISEMENT_IPv6;
pxIPPacket->xIPHeader.usPayloadLength = FreeRTOS_htons( 1 );

eResult = prvAllowIPPacketIPv6( &pxIPPacket->xIPHeader, pxNetworkBuffer, 0U );
TEST_ASSERT_EQUAL( eReleaseBuffer, eResult );
}

/**
* @brief test_prvAllowIPPacketIPv6_xCheckIPv6SizeFields_length_less_than_ICMP_min_requirement_3
* The buffer size is less than ICMP packet minimal requirement. Check if prvAllowIPPacketIPv6 determines to release it.
*/
void test_prvAllowIPPacketIPv6_xCheckIPv6SizeFields_length_less_than_ICMP_min_requirement_3()
{
eFrameProcessingResult_t eResult;
NetworkBufferDescriptor_t * pxNetworkBuffer = prvInitializeNetworkDescriptor();
IPPacket_IPv6_t * pxIPPacket = ( IPPacket_IPv6_t * ) pxNetworkBuffer->pucEthernetBuffer;

/* Set next header to ICMPv6 */
pxIPPacket->xIPHeader.ucNextHeader = ipPROTOCOL_ICMP_IPv6;
pxNetworkBuffer->xDataLength = ipSIZE_OF_ETH_HEADER + ipSIZE_OF_IPv6_HEADER + 1;
pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + ipSIZE_OF_IPv6_HEADER ] = ipICMP_PING_REQUEST_IPv6;
pxIPPacket->xIPHeader.usPayloadLength = FreeRTOS_htons( 1 );

eResult = prvAllowIPPacketIPv6( &pxIPPacket->xIPHeader, pxNetworkBuffer, 0U );
TEST_ASSERT_EQUAL( eReleaseBuffer, eResult );
}

/**
* @brief test_prvAllowIPPacketIPv6_xCheckIPv6SizeFields_length_less_than_ICMP_min_requirement_4
* The buffer size is less than ICMP packet minimal requirement. Check if prvAllowIPPacketIPv6 determines to release it.
*/
void test_prvAllowIPPacketIPv6_xCheckIPv6SizeFields_length_less_than_ICMP_min_requirement_4()
{
eFrameProcessingResult_t eResult;
NetworkBufferDescriptor_t * pxNetworkBuffer = prvInitializeNetworkDescriptor();
IPPacket_IPv6_t * pxIPPacket = ( IPPacket_IPv6_t * ) pxNetworkBuffer->pucEthernetBuffer;

/* Set next header to ICMPv6 */
pxIPPacket->xIPHeader.ucNextHeader = ipPROTOCOL_ICMP_IPv6;
pxNetworkBuffer->xDataLength = ipSIZE_OF_ETH_HEADER + ipSIZE_OF_IPv6_HEADER + 1;
pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + ipSIZE_OF_IPv6_HEADER ] = ipICMP_PING_REPLY_IPv6;
pxIPPacket->xIPHeader.usPayloadLength = FreeRTOS_htons( 1 );

eResult = prvAllowIPPacketIPv6( &pxIPPacket->xIPHeader, pxNetworkBuffer, 0U );
TEST_ASSERT_EQUAL( eReleaseBuffer, eResult );
}

/**
* @brief test_prvAllowIPPacketIPv6_xCheckIPv6SizeFields_length_less_than_ICMP_min_requirement_5
* This is the default case for all ICMPv6 packet length testing.
* The buffer size is less than ICMP packet minimal requirement. Check if prvAllowIPPacketIPv6 determines to release it.
*/
void test_prvAllowIPPacketIPv6_xCheckIPv6SizeFields_length_less_than_ICMP_min_requirement_5()
{
eFrameProcessingResult_t eResult;
NetworkBufferDescriptor_t * pxNetworkBuffer = prvInitializeNetworkDescriptor();
IPPacket_IPv6_t * pxIPPacket = ( IPPacket_IPv6_t * ) pxNetworkBuffer->pucEthernetBuffer;

/* Set next header to ICMPv6 */
pxIPPacket->xIPHeader.ucNextHeader = ipPROTOCOL_ICMP_IPv6;
pxNetworkBuffer->xDataLength = ipSIZE_OF_ETH_HEADER + ipSIZE_OF_IPv6_HEADER + 1;
pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + ipSIZE_OF_IPv6_HEADER ] = ipICMP_NEIGHBOR_SOLICITATION_IPv6;
pxIPPacket->xIPHeader.usPayloadLength = FreeRTOS_htons( 1 );

eResult = prvAllowIPPacketIPv6( &pxIPPacket->xIPHeader, pxNetworkBuffer, 0U );
TEST_ASSERT_EQUAL( eReleaseBuffer, eResult );
}


/**
* @brief test_prvAllowIPPacketIPv6_source_unspecified_address
* Prepare a packet with unspecified address in source address.
Expand Down