ip: fix port extraction

Replace a hard-coded constant of 64 with 56, which is a more appropriate
value for when ICMP echo request is returned in ICMP error. Previously,
the size of such message would be smaller than 64 and parsing would not
return the correct value.

Type: fix
Change-Id: I1bdf8a2a23b1e6762b64210c71927c926f4547ad
Signed-off-by: Klement Sekera <klement.sekera@gmail.com>
This commit is contained in:
Klement Sekera
2024-10-23 19:05:17 +02:00
committed by Matthew Smith
parent 3d56703027
commit 602d11019b

View File

@ -46,10 +46,9 @@ static u8 icmp_to_icmp6_updater_pointer_table[] =
* @returns Port number on success, 0 otherwise.
*/
always_inline u16
ip4_get_port (ip4_header_t * ip, u8 sender)
ip4_get_port (ip4_header_t *ip, u8 sender)
{
if (ip->ip_version_and_header_length != 0x45 ||
ip4_get_fragment_offset (ip))
if (ip->ip_version_and_header_length != 0x45 || ip4_get_fragment_offset (ip))
return 0;
if (PREDICT_TRUE ((ip->protocol == IP_PROTOCOL_TCP) ||
@ -65,7 +64,15 @@ ip4_get_port (ip4_header_t * ip, u8 sender)
{
return *((u16 *) (icmp + 1));
}
else if (clib_net_to_host_u16 (ip->length) >= 64)
/*
* Minimum length here consists of:
* - outer IP header length
* - outer ICMP header length (2*sizeof (icmp46_header_t))
* - inner IP header length
* - first 8 bytes of payload of original packet in case of ICMP error
*/
else if (clib_net_to_host_u16 (ip->length) >=
2 * sizeof (ip4_header_t) + 2 * sizeof (icmp46_header_t) + 8)
{
ip = (ip4_header_t *) (icmp + 2);
if (PREDICT_TRUE ((ip->protocol == IP_PROTOCOL_TCP) ||