From: Marcelo Mendes Spessoto Junior <marcelomspessoto@gmail.com>
To: netdev@vger.kernel.org
Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
pabeni@redhat.com, horms@kernel.org, shuah@kernel.org,
linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org,
Marcelo Mendes Spessoto Junior <marcelomspessoto@gmail.com>
Subject: [PATCH net-next v2 3/4] selftests: net: test IPV6_FL_F_REFLECT
Date: Mon, 3 Aug 2026 23:59:09 -0300 [thread overview]
Message-ID: <20260804025910.50145-4-marcelomspessoto@gmail.com> (raw)
In-Reply-To: <20260804025910.50145-1-marcelomspessoto@gmail.com>
According to source code, flowlabel_consistency must be deactivated
for the IPV6_FL_F_REFLECT flag to work. Therefore, take the following
measures: deactivate it on the wrapper .sh script, and skip this test
if it is run on an environment that does not correspond.
The previously defined tcp_listen and tcp_connect helpers were reused,
since the connection flow required for REFLECT validation is very
similar to REMOTE.
Signed-off-by: Marcelo Mendes Spessoto Junior <marcelomspessoto@gmail.com>
---
tools/testing/selftests/net/ipv6_flowlabel.sh | 3 +-
.../selftests/net/ipv6_flowlabel_mgr.c | 61 +++++++++++++++++++
2 files changed, 63 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/net/ipv6_flowlabel.sh b/tools/testing/selftests/net/ipv6_flowlabel.sh
index cee95e252bee..4c3de3a27807 100755
--- a/tools/testing/selftests/net/ipv6_flowlabel.sh
+++ b/tools/testing/selftests/net/ipv6_flowlabel.sh
@@ -8,7 +8,8 @@
set -e
echo "TEST management"
-./in_netns.sh ./ipv6_flowlabel_mgr
+./in_netns.sh \
+ sh -c 'sysctl -q -w net.ipv6.flowlabel_consistency=0 && ./ipv6_flowlabel_mgr'
echo "TEST datapath"
./in_netns.sh \
diff --git a/tools/testing/selftests/net/ipv6_flowlabel_mgr.c b/tools/testing/selftests/net/ipv6_flowlabel_mgr.c
index d482be2e9f9f..af87eec799c8 100644
--- a/tools/testing/selftests/net/ipv6_flowlabel_mgr.c
+++ b/tools/testing/selftests/net/ipv6_flowlabel_mgr.c
@@ -6,6 +6,7 @@
#include <arpa/inet.h>
#include <error.h>
#include <errno.h>
+#include <fcntl.h>
#include <limits.h>
#include <linux/in6.h>
#include <stdbool.h>
@@ -158,6 +159,22 @@ static void tcp_connect(int listener, uint32_t flowlabel, int *client, int *acce
*accepted = afd;
}
+static bool flowlabel_consistency_enabled(void)
+{
+ char buf[2] = {};
+ int fd;
+
+ fd = open("/proc/sys/net/ipv6/flowlabel_consistency", O_RDONLY);
+ if (fd == -1)
+ return true;
+
+ if (read(fd, buf, sizeof(buf) - 1) < 0)
+ buf[0] = '1';
+ close(fd);
+
+ return buf[0] != '0';
+}
+
static void run_tests(int fd)
{
int wstatus;
@@ -288,6 +305,50 @@ static void run_tests(int fd)
close(remote_cfd);
close(remote_listener);
}
+
+ if (flowlabel_consistency_enabled()) {
+ fprintf(stderr,
+ "[INFO] skip REFLECT flag validation (net.ipv6.flowlabel_consistency must be 0)\n");
+ } else {
+ struct in6_flowlabel_req reflect_query = {
+ .flr_action = IPV6_FL_A_GET,
+ };
+ struct in6_flowlabel_req reflect_off = {
+ .flr_action = IPV6_FL_A_PUT,
+ .flr_flags = IPV6_FL_F_REFLECT,
+ };
+ struct in6_flowlabel_req reflect_on = {
+ .flr_action = IPV6_FL_A_GET,
+ .flr_flags = IPV6_FL_F_REFLECT,
+ };
+ socklen_t reflect_query_len = sizeof(reflect_query);
+ int reflect_listener = tcp_listen();
+ int reflect_cfd, reflect_afd;
+
+ explain("Enable REFLECT on the listener before the client connects");
+ expect_pass(setsockopt(reflect_listener, SOL_IPV6, IPV6_FLOWLABEL_MGR,
+ &reflect_on, sizeof(reflect_on)));
+
+ tcp_connect(reflect_listener, 8, &reflect_cfd, &reflect_afd);
+
+ explain("Query the accepted socket's outgoing label, should be reflected");
+ expect_pass(getsockopt(reflect_afd, SOL_IPV6, IPV6_FLOWLABEL_MGR,
+ &reflect_query, &reflect_query_len));
+ if (ntohl(reflect_query.flr_label) != 8)
+ error(1, 0, "unexpected reflected flowlabel %u",
+ ntohl(reflect_query.flr_label));
+
+ explain("PUT+REFLECT disables reflection on the accepted socket");
+ expect_pass(setsockopt(reflect_afd, SOL_IPV6, IPV6_FLOWLABEL_MGR,
+ &reflect_off, sizeof(reflect_off)));
+ explain("cannot disable reflection twice");
+ expect_fail(setsockopt(reflect_afd, SOL_IPV6, IPV6_FLOWLABEL_MGR,
+ &reflect_off, sizeof(reflect_off)));
+
+ close(reflect_afd);
+ close(reflect_cfd);
+ close(reflect_listener);
+ }
}
static void parse_opts(int argc, char **argv)
--
2.55.0
next prev parent reply other threads:[~2026-08-04 2:59 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-04 2:59 [PATCH net-next v2 0/4] net: selftests: adjustments to ipv6_flowlabel_mgr Marcelo Mendes Spessoto Junior
2026-08-04 2:59 ` [PATCH net-next v2 1/4] selftests: net: test IPV6_FL_A_RENEW Marcelo Mendes Spessoto Junior
2026-08-06 19:22 ` Jakub Kicinski
2026-08-04 2:59 ` [PATCH net-next v2 2/4] selftests: net: test IPV6_FL_F_REMOTE Marcelo Mendes Spessoto Junior
2026-08-04 2:59 ` Marcelo Mendes Spessoto Junior [this message]
2026-08-06 19:24 ` [PATCH net-next v2 3/4] selftests: net: test IPV6_FL_F_REFLECT Jakub Kicinski
2026-08-04 2:59 ` [PATCH net-next v2 4/4] selftests: net: adopt harness for flow label mgr Marcelo Mendes Spessoto Junior
2026-08-06 19:22 ` Jakub Kicinski
2026-08-06 19:25 ` Jakub Kicinski
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=20260804025910.50145-4-marcelomspessoto@gmail.com \
--to=marcelomspessoto@gmail.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=shuah@kernel.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