Skip to content

Commit

Permalink
net/mlx5: zero UDP checksum over IPv4 in encapsulation
Browse files Browse the repository at this point in the history
[ upstream commit e407221d58ffdfd9b7c80f8e4fff99f67cdbd6e9 ]

A zero UDP csum indicates it should not be validated by the receiver.
The HW may not calculate UDP csum after encap.

The cited commit made sure the UDP csum is zero for UDP over IPv6,
mistakenly not handling UDP over IPv4. Fix it.

Fixes: bf1d7d9 ("net/mlx5: zero out UDP checksum in encapsulation")

Signed-off-by: Eli Britstein <[email protected]>
Acked-by: Suanming Mou <[email protected]>
  • Loading branch information
elibritstein authored and kevintraynor committed Nov 16, 2023
1 parent ac941d3 commit d4a1dc7
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions drivers/net/mlx5/mlx5_flow_dv.c
Original file line number Diff line number Diff line change
Expand Up @@ -4253,6 +4253,7 @@ flow_dv_zero_encap_udp_csum(void *data, struct rte_flow_error *error)
{
struct rte_ether_hdr *eth = NULL;
struct rte_vlan_hdr *vlan = NULL;
struct rte_ipv4_hdr *ipv4 = NULL;
struct rte_ipv6_hdr *ipv6 = NULL;
struct rte_udp_hdr *udp = NULL;
char *next_hdr;
Expand All @@ -4269,24 +4270,27 @@ flow_dv_zero_encap_udp_csum(void *data, struct rte_flow_error *error)
next_hdr += sizeof(struct rte_vlan_hdr);
}

/* HW calculates IPv4 csum. no need to proceed */
if (proto == RTE_ETHER_TYPE_IPV4)
return 0;

/* non IPv4/IPv6 header. not supported */
if (proto != RTE_ETHER_TYPE_IPV6) {
if (proto != RTE_ETHER_TYPE_IPV4 && proto != RTE_ETHER_TYPE_IPV6) {
return rte_flow_error_set(error, ENOTSUP,
RTE_FLOW_ERROR_TYPE_ACTION,
NULL, "Cannot offload non IPv4/IPv6");
}

ipv6 = (struct rte_ipv6_hdr *)next_hdr;

/* ignore non UDP */
if (ipv6->proto != IPPROTO_UDP)
return 0;
if (proto == RTE_ETHER_TYPE_IPV4) {
ipv4 = (struct rte_ipv4_hdr *)next_hdr;
/* ignore non UDP */
if (ipv4->next_proto_id != IPPROTO_UDP)
return 0;
udp = (struct rte_udp_hdr *)(ipv4 + 1);
} else {
ipv6 = (struct rte_ipv6_hdr *)next_hdr;
/* ignore non UDP */
if (ipv6->proto != IPPROTO_UDP)
return 0;
udp = (struct rte_udp_hdr *)(ipv6 + 1);
}

udp = (struct rte_udp_hdr *)(ipv6 + 1);
udp->dgram_cksum = 0;

return 0;
Expand Down

0 comments on commit d4a1dc7

Please sign in to comment.