DPDK patches and discussions
 help / color / mirror / Atom feed
From: Andrew Rybchenko <arybchenko@solarflare.com>
To: Michael Pfeiffer <michael.pfeiffer@tu-ilmenau.de>,
	Olivier Matz <olivier.matz@6wind.com>
Cc: <dev@dpdk.org>
Subject: Re: [dpdk-dev] [PATCH] net: calculate checksums for packets with IPv4 options
Date: Sat, 29 Aug 2020 14:43:14 +0300	[thread overview]
Message-ID: <ccb00dfc-be1a-6f2e-c5c2-cad61bd8458d@solarflare.com> (raw)
In-Reply-To: <20200821113210.307175-1-michael.pfeiffer@tu-ilmenau.de>

On 8/21/20 2:32 PM, Michael Pfeiffer wrote:
> Currently, rte_ipv4_cksum() and rte_ipv4_udptcp_cksum() assume all IPv4
> headers have sizeof(struct rte_ipv4_hdr) bytes. This is not true for
> those (rare) packets with IPv4 options. Thus, both IPv4 and TCP/UDP
> checksums are calculated wrong.
> 
> This patch fixes the issue by using the actual IPv4 header length from
> the packet's IHL field.
> 
> Signed-off-by: Michael Pfeiffer <michael.pfeiffer@tu-ilmenau.de>
> ---
>  lib/librte_net/rte_ip.h | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/lib/librte_net/rte_ip.h b/lib/librte_net/rte_ip.h
> index fcd1eb342..6c3ff2603 100644
> --- a/lib/librte_net/rte_ip.h
> +++ b/lib/librte_net/rte_ip.h
> @@ -269,7 +269,7 @@ static inline uint16_t
>  rte_ipv4_cksum(const struct rte_ipv4_hdr *ipv4_hdr)
>  {
>  	uint16_t cksum;
> -	cksum = rte_raw_cksum(ipv4_hdr, sizeof(struct rte_ipv4_hdr));
> +	cksum = rte_raw_cksum(ipv4_hdr, (ipv4_hdr->version_ihl & 0xf) * 4);
>  	return (uint16_t)~cksum;
>  }
>  
> @@ -311,7 +311,7 @@ rte_ipv4_phdr_cksum(const struct rte_ipv4_hdr *ipv4_hdr, uint64_t ol_flags)
>  	} else {
>  		psd_hdr.len = rte_cpu_to_be_16(
>  			(uint16_t)(rte_be_to_cpu_16(ipv4_hdr->total_length)
> -				- sizeof(struct rte_ipv4_hdr)));
> +				- ((ipv4_hdr->version_ihl & 0xf) * 4)));
>  	}
>  	return rte_raw_cksum(&psd_hdr, sizeof(psd_hdr));
>  }
> @@ -319,8 +319,8 @@ rte_ipv4_phdr_cksum(const struct rte_ipv4_hdr *ipv4_hdr, uint64_t ol_flags)
>  /**
>   * Process the IPv4 UDP or TCP checksum.
>   *
> - * The IPv4 header should not contains options. The IP and layer 4
> - * checksum must be set to 0 in the packet by the caller.
> + * The IP and layer 4 checksum must be set to 0 in the packet by
> + * the caller.
>   *
>   * @param ipv4_hdr
>   *   The pointer to the contiguous IPv4 header.
> @@ -339,7 +339,7 @@ rte_ipv4_udptcp_cksum(const struct rte_ipv4_hdr *ipv4_hdr, const void *l4_hdr)
>  	if (l3_len < sizeof(struct rte_ipv4_hdr))
>  		return 0;
>  
> -	l4_len = l3_len - sizeof(struct rte_ipv4_hdr);
> +	l4_len = l3_len - ((ipv4_hdr->version_ihl & 0xf) * 4);

Previous if condition guarantees that the result will be not
negative (and make huge l4_len), so it looks like it should be
updated as well. I think it makes sense to introduce
additional variable with calculated IPv4 header length.

>  
>  	cksum = rte_raw_cksum(l4_hdr, l4_len);
>  	cksum += rte_ipv4_phdr_cksum(ipv4_hdr, 0);
> 


  reply	other threads:[~2020-08-29 11:43 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-21 11:32 Michael Pfeiffer
2020-08-29 11:43 ` Andrew Rybchenko [this message]
2020-09-01  9:47 ` [dpdk-dev] [PATCH v2] " Michael Pfeiffer
2020-09-07  7:48   ` Andrew Rybchenko
2020-10-05 22:55   ` Thomas Monjalon
2020-10-06  2:39     ` Stephen Hemminger
2020-10-06  8:10       ` Olivier Matz
2020-10-06  9:51         ` Michael Pfeiffer
2020-10-06 15:10         ` Thomas Monjalon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ccb00dfc-be1a-6f2e-c5c2-cad61bd8458d@solarflare.com \
    --to=arybchenko@solarflare.com \
    --cc=dev@dpdk.org \
    --cc=michael.pfeiffer@tu-ilmenau.de \
    --cc=olivier.matz@6wind.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).