net: fix Intel prepare function for IP checksum offload

Message ID 20180919144208.17064-1-didier.pallard@6wind.com (mailing list archive)
State Accepted, archived
Delegated to: Ferruh Yigit
Headers
Series net: fix Intel prepare function for IP checksum offload |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Didier Pallard Sept. 19, 2018, 2:42 p.m. UTC
  Current Intel tx prepare function does not properly handle the
case where only IP checksum is requested, without requesting
any L4 checksum or TSO: IP checksum is not properly reset to 0
and output packet may contain invalid IP checksum.

Fixes: 4fb7e803eb1a ("ethdev: add Tx preparation")
Cc: stable@dpdk.org

Signed-off-by: Didier Pallard <didier.pallard@6wind.com>
---
 lib/librte_net/rte_net.h | 20 ++++++++------------
 1 file changed, 8 insertions(+), 12 deletions(-)
  

Comments

Ferruh Yigit Sept. 19, 2018, 5:50 p.m. UTC | #1
On 9/19/2018 3:42 PM, Didier Pallard wrote:
> Current Intel tx prepare function does not properly handle the
> case where only IP checksum is requested, without requesting
> any L4 checksum or TSO: IP checksum is not properly reset to 0
> and output packet may contain invalid IP checksum.
> 
> Fixes: 4fb7e803eb1a ("ethdev: add Tx preparation")
> Cc: stable@dpdk.org

cc'ed developer.

> 
> Signed-off-by: Didier Pallard <didier.pallard@6wind.com>
> ---
>  lib/librte_net/rte_net.h | 20 ++++++++------------
>  1 file changed, 8 insertions(+), 12 deletions(-)
> 
> diff --git a/lib/librte_net/rte_net.h b/lib/librte_net/rte_net.h
> index b6ab6e1d57b2..e59760a0a108 100644
> --- a/lib/librte_net/rte_net.h
> +++ b/lib/librte_net/rte_net.h
> @@ -122,14 +122,16 @@ rte_net_intel_cksum_flags_prepare(struct rte_mbuf *m, uint64_t ol_flags)
>  		(ol_flags & PKT_TX_OUTER_IPV6))
>  		inner_l3_offset += m->outer_l2_len + m->outer_l3_len;
>  
> -	if ((ol_flags & PKT_TX_UDP_CKSUM) == PKT_TX_UDP_CKSUM) {
> -		if (ol_flags & PKT_TX_IPV4) {
> -			ipv4_hdr = rte_pktmbuf_mtod_offset(m, struct ipv4_hdr *,
> -					inner_l3_offset);
> +	if (ol_flags & PKT_TX_IPV4) {
> +		ipv4_hdr = rte_pktmbuf_mtod_offset(m, struct ipv4_hdr *,
> +				inner_l3_offset);
>  
> -			if (ol_flags & PKT_TX_IP_CKSUM)
> -				ipv4_hdr->hdr_checksum = 0;
> +		if (ol_flags & PKT_TX_IP_CKSUM)
> +			ipv4_hdr->hdr_checksum = 0;
> +	}
>  
> +	if ((ol_flags & PKT_TX_UDP_CKSUM) == PKT_TX_UDP_CKSUM) {
> +		if (ol_flags & PKT_TX_IPV4) {
>  			udp_hdr = (struct udp_hdr *)((char *)ipv4_hdr +
>  					m->l3_len);
>  			udp_hdr->dgram_cksum = rte_ipv4_phdr_cksum(ipv4_hdr,
> @@ -146,12 +148,6 @@ rte_net_intel_cksum_flags_prepare(struct rte_mbuf *m, uint64_t ol_flags)
>  	} else if ((ol_flags & PKT_TX_TCP_CKSUM) ||
>  			(ol_flags & PKT_TX_TCP_SEG)) {
>  		if (ol_flags & PKT_TX_IPV4) {
> -			ipv4_hdr = rte_pktmbuf_mtod_offset(m, struct ipv4_hdr *,
> -					inner_l3_offset);
> -
> -			if (ol_flags & PKT_TX_IP_CKSUM)
> -				ipv4_hdr->hdr_checksum = 0;
> -
>  			/* non-TSO tcp or TSO */
>  			tcp_hdr = (struct tcp_hdr *)((char *)ipv4_hdr +
>  					m->l3_len);
>
  
Ananyev, Konstantin Sept. 20, 2018, 2:53 p.m. UTC | #2
> 
> Current Intel tx prepare function does not properly handle the
> case where only IP checksum is requested, without requesting
> any L4 checksum or TSO: IP checksum is not properly reset to 0
> and output packet may contain invalid IP checksum.
> 
> Fixes: 4fb7e803eb1a ("ethdev: add Tx preparation")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Didier Pallard <didier.pallard@6wind.com>
> ---
>  lib/librte_net/rte_net.h | 20 ++++++++------------
>  1 file changed, 8 insertions(+), 12 deletions(-)
> 
> diff --git a/lib/librte_net/rte_net.h b/lib/librte_net/rte_net.h
> index b6ab6e1d57b2..e59760a0a108 100644
> --- a/lib/librte_net/rte_net.h
> +++ b/lib/librte_net/rte_net.h
> @@ -122,14 +122,16 @@ rte_net_intel_cksum_flags_prepare(struct rte_mbuf *m, uint64_t ol_flags)
>  		(ol_flags & PKT_TX_OUTER_IPV6))
>  		inner_l3_offset += m->outer_l2_len + m->outer_l3_len;
> 
> -	if ((ol_flags & PKT_TX_UDP_CKSUM) == PKT_TX_UDP_CKSUM) {
> -		if (ol_flags & PKT_TX_IPV4) {
> -			ipv4_hdr = rte_pktmbuf_mtod_offset(m, struct ipv4_hdr *,
> -					inner_l3_offset);
> +	if (ol_flags & PKT_TX_IPV4) {
> +		ipv4_hdr = rte_pktmbuf_mtod_offset(m, struct ipv4_hdr *,
> +				inner_l3_offset);
> 
> -			if (ol_flags & PKT_TX_IP_CKSUM)
> -				ipv4_hdr->hdr_checksum = 0;
> +		if (ol_flags & PKT_TX_IP_CKSUM)
> +			ipv4_hdr->hdr_checksum = 0;
> +	}
> 
> +	if ((ol_flags & PKT_TX_UDP_CKSUM) == PKT_TX_UDP_CKSUM) {
> +		if (ol_flags & PKT_TX_IPV4) {
>  			udp_hdr = (struct udp_hdr *)((char *)ipv4_hdr +
>  					m->l3_len);
>  			udp_hdr->dgram_cksum = rte_ipv4_phdr_cksum(ipv4_hdr,
> @@ -146,12 +148,6 @@ rte_net_intel_cksum_flags_prepare(struct rte_mbuf *m, uint64_t ol_flags)
>  	} else if ((ol_flags & PKT_TX_TCP_CKSUM) ||
>  			(ol_flags & PKT_TX_TCP_SEG)) {
>  		if (ol_flags & PKT_TX_IPV4) {
> -			ipv4_hdr = rte_pktmbuf_mtod_offset(m, struct ipv4_hdr *,
> -					inner_l3_offset);
> -
> -			if (ol_flags & PKT_TX_IP_CKSUM)
> -				ipv4_hdr->hdr_checksum = 0;
> -
>  			/* non-TSO tcp or TSO */
>  			tcp_hdr = (struct tcp_hdr *)((char *)ipv4_hdr +
>  					m->l3_len);
> --
Acked-by: Konstantin Ananyev <konstantin.ananyev@intel.com>

> 2.11.0
  
Ferruh Yigit Sept. 21, 2018, 1:12 a.m. UTC | #3
On 9/20/2018 3:53 PM, Ananyev, Konstantin wrote:
> 
> 
>>
>> Current Intel tx prepare function does not properly handle the
>> case where only IP checksum is requested, without requesting
>> any L4 checksum or TSO: IP checksum is not properly reset to 0
>> and output packet may contain invalid IP checksum.
>>
>> Fixes: 4fb7e803eb1a ("ethdev: add Tx preparation")
>> Cc: stable@dpdk.org
>>
>> Signed-off-by: Didier Pallard <didier.pallard@6wind.com>
>
> Acked-by: Konstantin Ananyev <konstantin.ananyev@intel.com>

Applied to dpdk-next-net/master, thanks.
  

Patch

diff --git a/lib/librte_net/rte_net.h b/lib/librte_net/rte_net.h
index b6ab6e1d57b2..e59760a0a108 100644
--- a/lib/librte_net/rte_net.h
+++ b/lib/librte_net/rte_net.h
@@ -122,14 +122,16 @@  rte_net_intel_cksum_flags_prepare(struct rte_mbuf *m, uint64_t ol_flags)
 		(ol_flags & PKT_TX_OUTER_IPV6))
 		inner_l3_offset += m->outer_l2_len + m->outer_l3_len;
 
-	if ((ol_flags & PKT_TX_UDP_CKSUM) == PKT_TX_UDP_CKSUM) {
-		if (ol_flags & PKT_TX_IPV4) {
-			ipv4_hdr = rte_pktmbuf_mtod_offset(m, struct ipv4_hdr *,
-					inner_l3_offset);
+	if (ol_flags & PKT_TX_IPV4) {
+		ipv4_hdr = rte_pktmbuf_mtod_offset(m, struct ipv4_hdr *,
+				inner_l3_offset);
 
-			if (ol_flags & PKT_TX_IP_CKSUM)
-				ipv4_hdr->hdr_checksum = 0;
+		if (ol_flags & PKT_TX_IP_CKSUM)
+			ipv4_hdr->hdr_checksum = 0;
+	}
 
+	if ((ol_flags & PKT_TX_UDP_CKSUM) == PKT_TX_UDP_CKSUM) {
+		if (ol_flags & PKT_TX_IPV4) {
 			udp_hdr = (struct udp_hdr *)((char *)ipv4_hdr +
 					m->l3_len);
 			udp_hdr->dgram_cksum = rte_ipv4_phdr_cksum(ipv4_hdr,
@@ -146,12 +148,6 @@  rte_net_intel_cksum_flags_prepare(struct rte_mbuf *m, uint64_t ol_flags)
 	} else if ((ol_flags & PKT_TX_TCP_CKSUM) ||
 			(ol_flags & PKT_TX_TCP_SEG)) {
 		if (ol_flags & PKT_TX_IPV4) {
-			ipv4_hdr = rte_pktmbuf_mtod_offset(m, struct ipv4_hdr *,
-					inner_l3_offset);
-
-			if (ol_flags & PKT_TX_IP_CKSUM)
-				ipv4_hdr->hdr_checksum = 0;
-
 			/* non-TSO tcp or TSO */
 			tcp_hdr = (struct tcp_hdr *)((char *)ipv4_hdr +
 					m->l3_len);