Skip to content

Commit

Permalink
net: fix TCP/UDP checksum with padding data
Browse files Browse the repository at this point in the history
[ upstream commit e55ea3d5d970dfff2989e4a1c65b76d02512bce0 ]

IEEE 802 packets may have a minimum size limit. The data fields
should be padded when necessary. In some cases, the padding data
is not zero.

In 'rte_ipv4_udptcp_cksum_mbuf()', as payload length
"mbuf->pkt_len - l4_off" is used, which includes padding and if
padding is not zero it will end up producing wrong checksum.

This patch will use IP header to get the payload size to calculate
TCP/UDP checksum.

Fixes: d178f69 ("net: add UDP/TCP checksum in mbuf segments")

Signed-off-by: Kaiwen Deng <kaiwenx.deng@intel.com>
Reviewed-by: Morten Brørup <mb@smartsharesystems.com>
  • Loading branch information
kevin-intel authored and bluca committed Mar 7, 2024
1 parent 0ceab70 commit 3dab00d
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions lib/net/rte_ip.h
Original file line number Diff line number Diff line change
Expand Up @@ -420,11 +420,14 @@ __rte_ipv4_udptcp_cksum_mbuf(const struct rte_mbuf *m,
{
uint16_t raw_cksum;
uint32_t cksum;
uint16_t len;

if (l4_off > m->pkt_len)
return 0;
if (unlikely(l4_off > m->pkt_len))
return 0; /* invalid params, return a dummy value */

len = rte_be_to_cpu_16(ipv4_hdr->total_length) - (uint16_t)rte_ipv4_hdr_len(ipv4_hdr);

if (rte_raw_cksum_mbuf(m, l4_off, m->pkt_len - l4_off, &raw_cksum))
if (rte_raw_cksum_mbuf(m, l4_off, len, &raw_cksum))
return 0;

cksum = raw_cksum + rte_ipv4_phdr_cksum(ipv4_hdr, 0);
Expand Down Expand Up @@ -650,10 +653,10 @@ __rte_ipv6_udptcp_cksum_mbuf(const struct rte_mbuf *m,
uint16_t raw_cksum;
uint32_t cksum;

if (l4_off > m->pkt_len)
return 0;
if (unlikely(l4_off > m->pkt_len))
return 0; /* invalid params, return a dummy value */

if (rte_raw_cksum_mbuf(m, l4_off, m->pkt_len - l4_off, &raw_cksum))
if (rte_raw_cksum_mbuf(m, l4_off, rte_be_to_cpu_16(ipv6_hdr->payload_len), &raw_cksum))
return 0;

cksum = raw_cksum + rte_ipv6_phdr_cksum(ipv6_hdr, 0);
Expand Down

0 comments on commit 3dab00d

Please sign in to comment.