DPDK patches and discussions
 help / color / mirror / Atom feed
* [PATCH] net: fix IPv4 cksum simple function
@ 2024-11-05  8:59 David Marchand
  2024-11-05  9:09 ` Morten Brørup
  2024-11-05 10:18 ` Bruce Richardson
  0 siblings, 2 replies; 12+ messages in thread
From: David Marchand @ 2024-11-05  8:59 UTC (permalink / raw)
  To: dev
  Cc: Stephen Hemminger, Chengwen Feng, Bruce Richardson, Morten Brørup

The new function breaks compilation with -Wcast-align.

In file included from /home/runner/work/ovs/ovs/dpdk-dir/include/rte_ip.h:9:
/home/runner/work/ovs/ovs/dpdk-dir/include/rte_ip4.h:191:10:
	error: cast from 'const uint8_t *' (aka 'const unsigned char *')
	to 'const unaligned_uint16_t *' (aka 'const unsigned short *')
	increases required alignment from 1 to 2 [-Werror,-Wcast-align]
        v16_h = (const unaligned_uint16_t *)&ipv4_hdr->version_ihl;
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Fix this by aligning rte_ipv4_hdr to two bytes, and point at the start
of the structure rather than the first field (which happens to be 1 byte
large).

Fixes: f9e1d67f237a ("net: add IPv4 cksum function for simple cases")

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 doc/guides/rel_notes/release_24_11.rst | 2 ++
 lib/net/rte_ip4.h                      | 4 ++--
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/doc/guides/rel_notes/release_24_11.rst b/doc/guides/rel_notes/release_24_11.rst
index 53a5ffebe5..d0152c558c 100644
--- a/doc/guides/rel_notes/release_24_11.rst
+++ b/doc/guides/rel_notes/release_24_11.rst
@@ -291,6 +291,8 @@ API Changes
     releases: it handles key=value and only-key cases.
   * Both ``rte_kvargs_process`` and ``rte_kvargs_process_opt`` reject a NULL ``kvlist`` parameter.
 
+* net: The IPv4 header structure ``rte_ipv4_hdr`` has been marked as two bytes aligned.
+
 * net: The ICMP message types ``RTE_IP_ICMP_ECHO_REPLY`` and ``RTE_IP_ICMP_ECHO_REQUEST``
   are marked as deprecated, and are replaced
   by ``RTE_ICMP_TYPE_ECHO_REPLY`` and ``RTE_ICMP_TYPE_ECHO_REQUEST``.
diff --git a/lib/net/rte_ip4.h b/lib/net/rte_ip4.h
index 4dd0058cc5..f9b8333332 100644
--- a/lib/net/rte_ip4.h
+++ b/lib/net/rte_ip4.h
@@ -39,7 +39,7 @@ extern "C" {
 /**
  * IPv4 Header
  */
-struct rte_ipv4_hdr {
+struct __rte_aligned(2) rte_ipv4_hdr {
 	__extension__
 	union {
 		uint8_t version_ihl;    /**< version and header length */
@@ -188,7 +188,7 @@ rte_ipv4_cksum_simple(const struct rte_ipv4_hdr *ipv4_hdr)
 	 * Compute the sum of successive 16-bit words of the IPv4 header,
 	 * skipping the checksum field of the header.
 	 */
-	v16_h = (const unaligned_uint16_t *)&ipv4_hdr->version_ihl;
+	v16_h = (const uint16_t *)ipv4_hdr;
 	ip_cksum = v16_h[0] + v16_h[1] + v16_h[2] + v16_h[3] +
 		v16_h[4] + v16_h[6] + v16_h[7] + v16_h[8] + v16_h[9];
 
-- 
2.46.2


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2024-11-06 20:23 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-11-05  8:59 [PATCH] net: fix IPv4 cksum simple function David Marchand
2024-11-05  9:09 ` Morten Brørup
2024-11-05  9:27   ` David Marchand
2024-11-05 10:20     ` Morten Brørup
2024-11-05 10:49       ` David Marchand
2024-11-05 11:02         ` Bruce Richardson
2024-11-05 11:06           ` Morten Brørup
2024-11-05 13:12           ` David Marchand
2024-11-05  9:37   ` Robin Jarry
2024-11-05  9:53     ` Morten Brørup
2024-11-06 20:22   ` David Marchand
2024-11-05 10:18 ` Bruce Richardson

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).