From: Robin Jarry <rjarry@redhat.com>
To: dev@dpdk.org, Stephen Hemminger <stephen@networkplumber.org>
Cc: stable@dpdk.org, Junxiao Shi <sunnylandh@gmail.com>
Subject: [PATCH dpdk] net: fix IPv4 compat and mapped checks
Date: Mon, 24 Feb 2025 15:47:26 +0100 [thread overview]
Message-ID: <20250224144725.271975-2-rjarry@redhat.com> (raw)
The RFC states that the first 96 bits should be compared, not the first
32 bits.
Add unit tests to ensure this works.
Cc: stable@dpdk.org
Fixes: 3d6d85f58c1c ("net: add utilities for well known IPv6 address types")
Reported-by: Junxiao Shi <sunnylandh@gmail.com>
Closes: https://bugs.dpdk.org/show_bug.cgi?id=1664
Signed-off-by: Robin Jarry <rjarry@redhat.com>
---
app/test/test_net_ip6.c | 26 ++++++++++++++++++++++++++
lib/net/rte_ip6.h | 4 ++--
2 files changed, 28 insertions(+), 2 deletions(-)
diff --git a/app/test/test_net_ip6.c b/app/test/test_net_ip6.c
index 9cc10b1f714f..cfc550940306 100644
--- a/app/test/test_net_ip6.c
+++ b/app/test/test_net_ip6.c
@@ -99,6 +99,8 @@ test_ipv6_addr_kind(void)
TEST_ASSERT(!rte_ipv6_addr_is_linklocal(&zero_addr), "");
TEST_ASSERT(!rte_ipv6_addr_is_loopback(&zero_addr), "");
TEST_ASSERT(!rte_ipv6_addr_is_mcast(&zero_addr), "");
+ TEST_ASSERT(rte_ipv6_addr_is_v4compat(&zero_addr), "");
+ TEST_ASSERT(!rte_ipv6_addr_is_v4mapped(&zero_addr), "");
const struct rte_ipv6_addr ucast =
RTE_IPV6(0x2a01, 0xcb00, 0x0254, 0x3300, 0x6239, 0xe1f4, 0x7a0b, 0x2371);
@@ -106,18 +108,24 @@ test_ipv6_addr_kind(void)
TEST_ASSERT(!rte_ipv6_addr_is_linklocal(&ucast), "");
TEST_ASSERT(!rte_ipv6_addr_is_loopback(&ucast), "");
TEST_ASSERT(!rte_ipv6_addr_is_mcast(&ucast), "");
+ TEST_ASSERT(!rte_ipv6_addr_is_v4compat(&ucast), "");
+ TEST_ASSERT(!rte_ipv6_addr_is_v4mapped(&ucast), "");
const struct rte_ipv6_addr mcast = RTE_IPV6(0xff01, 0, 0, 0, 0, 0, 0, 1);
TEST_ASSERT(!rte_ipv6_addr_is_unspec(&mcast), "");
TEST_ASSERT(!rte_ipv6_addr_is_linklocal(&mcast), "");
TEST_ASSERT(!rte_ipv6_addr_is_loopback(&mcast), "");
TEST_ASSERT(rte_ipv6_addr_is_mcast(&mcast), "");
+ TEST_ASSERT(!rte_ipv6_addr_is_v4compat(&mcast), "");
+ TEST_ASSERT(!rte_ipv6_addr_is_v4mapped(&mcast), "");
const struct rte_ipv6_addr lo = RTE_IPV6_ADDR_LOOPBACK;
TEST_ASSERT(!rte_ipv6_addr_is_unspec(&lo), "");
TEST_ASSERT(!rte_ipv6_addr_is_linklocal(&lo), "");
TEST_ASSERT(rte_ipv6_addr_is_loopback(&lo), "");
TEST_ASSERT(!rte_ipv6_addr_is_mcast(&lo), "");
+ TEST_ASSERT(!rte_ipv6_addr_is_v4compat(&lo), "");
+ TEST_ASSERT(!rte_ipv6_addr_is_v4mapped(&lo), "");
const struct rte_ipv6_addr local =
RTE_IPV6(0xfe80, 0, 0, 0, 0x5a84, 0xc52c, 0x6aef, 0x4639);
@@ -125,6 +133,24 @@ test_ipv6_addr_kind(void)
TEST_ASSERT(rte_ipv6_addr_is_linklocal(&local), "");
TEST_ASSERT(!rte_ipv6_addr_is_loopback(&local), "");
TEST_ASSERT(!rte_ipv6_addr_is_mcast(&local), "");
+ TEST_ASSERT(!rte_ipv6_addr_is_v4compat(&local), "");
+ TEST_ASSERT(!rte_ipv6_addr_is_v4mapped(&local), "");
+
+ const struct rte_ipv6_addr v4compat = RTE_IPV6(0, 0, 0, 0, 0, 0, 0xc0a8, 0x0001);
+ TEST_ASSERT(!rte_ipv6_addr_is_unspec(&v4compat), "");
+ TEST_ASSERT(!rte_ipv6_addr_is_linklocal(&v4compat), "");
+ TEST_ASSERT(!rte_ipv6_addr_is_loopback(&v4compat), "");
+ TEST_ASSERT(!rte_ipv6_addr_is_mcast(&v4compat), "");
+ TEST_ASSERT(rte_ipv6_addr_is_v4compat(&v4compat), "");
+ TEST_ASSERT(!rte_ipv6_addr_is_v4mapped(&v4compat), "");
+
+ const struct rte_ipv6_addr v4mapped = RTE_IPV6(0, 0, 0, 0, 0, 0xffff, 0xc0a8, 0x0001);
+ TEST_ASSERT(!rte_ipv6_addr_is_unspec(&v4mapped), "");
+ TEST_ASSERT(!rte_ipv6_addr_is_linklocal(&v4mapped), "");
+ TEST_ASSERT(!rte_ipv6_addr_is_loopback(&v4mapped), "");
+ TEST_ASSERT(!rte_ipv6_addr_is_mcast(&v4mapped), "");
+ TEST_ASSERT(!rte_ipv6_addr_is_v4compat(&v4mapped), "");
+ TEST_ASSERT(rte_ipv6_addr_is_v4mapped(&v4mapped), "");
return TEST_SUCCESS;
}
diff --git a/lib/net/rte_ip6.h b/lib/net/rte_ip6.h
index 92558a124a00..98bcac3f4dff 100644
--- a/lib/net/rte_ip6.h
+++ b/lib/net/rte_ip6.h
@@ -307,7 +307,7 @@ static inline bool
rte_ipv6_addr_is_v4compat(const struct rte_ipv6_addr *ip)
{
const struct rte_ipv6_addr unspec = RTE_IPV6_ADDR_UNSPEC;
- return rte_ipv6_addr_eq_prefix(ip, &unspec, 32) && !rte_ipv6_addr_is_loopback(ip);
+ return rte_ipv6_addr_eq_prefix(ip, &unspec, 96) && !rte_ipv6_addr_is_loopback(ip);
}
#define RTE_IPV6_ADDR_PREFIX_V4MAPPED RTE_IPV6(0, 0, 0, 0, 0, 0xffff, 0, 0)
@@ -325,7 +325,7 @@ static inline bool
rte_ipv6_addr_is_v4mapped(const struct rte_ipv6_addr *ip)
{
const struct rte_ipv6_addr prefix = RTE_IPV6_ADDR_PREFIX_V4MAPPED;
- return rte_ipv6_addr_eq_prefix(ip, &prefix, 32);
+ return rte_ipv6_addr_eq_prefix(ip, &prefix, 96);
}
/**
--
2.48.1
reply other threads:[~2025-02-24 14:47 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20250224144725.271975-2-rjarry@redhat.com \
--to=rjarry@redhat.com \
--cc=dev@dpdk.org \
--cc=stable@dpdk.org \
--cc=stephen@networkplumber.org \
--cc=sunnylandh@gmail.com \
/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).