From: David Marchand <david.marchand@redhat.com>
To: dev@dpdk.org
Cc: "Stephen Hemminger" <stephen@networkplumber.org>,
"Chengwen Feng" <fengchengwen@huawei.com>,
"Bruce Richardson" <bruce.richardson@intel.com>,
"Morten Brørup" <mb@smartsharesystems.com>
Subject: [PATCH] net: fix IPv4 cksum simple function
Date: Tue, 5 Nov 2024 09:59:11 +0100 [thread overview]
Message-ID: <20241105085912.4148208-1-david.marchand@redhat.com> (raw)
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
next reply other threads:[~2024-11-05 8:59 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-05 8:59 David Marchand [this message]
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
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=20241105085912.4148208-1-david.marchand@redhat.com \
--to=david.marchand@redhat.com \
--cc=bruce.richardson@intel.com \
--cc=dev@dpdk.org \
--cc=fengchengwen@huawei.com \
--cc=mb@smartsharesystems.com \
--cc=stephen@networkplumber.org \
/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).