Netdev List
 help / color / mirror / Atom feed
From: Marcelo Mendes Spessoto Junior <marcelomspessoto@gmail.com>
To: "David S . Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Simon Horman <horms@kernel.org>, Shuah Khan <shuah@kernel.org>
Cc: netdev@vger.kernel.org, linux-kselftest@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Marcelo Mendes Spessoto Junior <marcelomspessoto@gmail.com>
Subject: [PATCH net-next v3 3/5] selftests: net: create own netns in ipv6_flowlabel_mgr
Date: Fri,  7 Aug 2026 19:09:40 -0300	[thread overview]
Message-ID: <20260807220942.421382-4-marcelomspessoto@gmail.com> (raw)
In-Reply-To: <20260807220942.421382-1-marcelomspessoto@gmail.com>

Have ipv6_flowlabel_mgr create and configure its own network
namespace (unshare(CLONE_NEWNET) + bring up lo), the same way
ipv6_fragmentation.c and icmp_rfc4884.c already do, instead of
relying on the in_netns.sh wrapper script.

The setup can then be reused across tests through fixtures and
provide isolated network environments for each test in the case
of a future adoption of kselftest_harness.

It also avoids the leak of modifications to the netns in case the
user runs the test file directly, outside the wrapper and without
the in_netns.sh file.

Signed-off-by: Marcelo Mendes Spessoto Junior <marcelomspessoto@gmail.com>
---
 tools/testing/selftests/net/ipv6_flowlabel.sh |  2 +-
 .../selftests/net/ipv6_flowlabel_mgr.c        | 28 +++++++++++++++++++
 2 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/net/ipv6_flowlabel.sh b/tools/testing/selftests/net/ipv6_flowlabel.sh
index cee95e252bee..2eeda39bf64c 100755
--- a/tools/testing/selftests/net/ipv6_flowlabel.sh
+++ b/tools/testing/selftests/net/ipv6_flowlabel.sh
@@ -8,7 +8,7 @@
 set -e
 
 echo "TEST management"
-./in_netns.sh ./ipv6_flowlabel_mgr
+./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 51541e792257..f8d8b09b9d86 100644
--- a/tools/testing/selftests/net/ipv6_flowlabel_mgr.c
+++ b/tools/testing/selftests/net/ipv6_flowlabel_mgr.c
@@ -8,11 +8,14 @@
 #include <errno.h>
 #include <limits.h>
 #include <linux/in6.h>
+#include <net/if.h>
+#include <sched.h>
 #include <stdbool.h>
 #include <stdio.h>
 #include <stdint.h>
 #include <stdlib.h>
 #include <string.h>
+#include <sys/ioctl.h>
 #include <sys/socket.h>
 #include <sys/stat.h>
 #include <sys/time.h>
@@ -306,6 +309,30 @@ static void run_tests(int fd)
 	}
 }
 
+static void setup(void)
+{
+	struct ifreq ifr = {
+		.ifr_name = "lo"
+	};
+	int ctl;
+
+	if (unshare(CLONE_NEWNET))
+		error(1, errno, "unshare");
+
+	ctl = socket(AF_LOCAL, SOCK_STREAM, 0);
+	if (ctl == -1)
+		error(1, errno, "socket");
+
+	if (ioctl(ctl, SIOCGIFFLAGS, &ifr))
+		error(1, errno, "ioctl SIOCGIFFLAGS");
+	ifr.ifr_flags |= IFF_UP;
+	if (ioctl(ctl, SIOCSIFFLAGS, &ifr))
+		error(1, errno, "ioctl: bring lo up");
+
+	if (close(ctl))
+		error(1, errno, "close");
+}
+
 static void parse_opts(int argc, char **argv)
 {
 	int c;
@@ -329,6 +356,7 @@ int main(int argc, char **argv)
 	int fd;
 
 	parse_opts(argc, argv);
+	setup();
 
 	fd = socket(PF_INET6, SOCK_DGRAM, 0);
 	if (fd == -1)
-- 
2.55.0


  parent reply	other threads:[~2026-08-07 22:10 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-07 22:09 [PATCH net-next v3 0/5] net: selftests: adjustments to ipv6_flowlabel_mgr Marcelo Mendes Spessoto Junior
2026-08-07 22:09 ` [PATCH net-next v3 1/5] selftests: net: test IPV6_FL_A_RENEW Marcelo Mendes Spessoto Junior
2026-08-07 22:09 ` [PATCH net-next v3 2/5] selftests: net: test IPV6_FL_F_REMOTE Marcelo Mendes Spessoto Junior
2026-08-07 22:09 ` Marcelo Mendes Spessoto Junior [this message]
2026-08-07 22:09 ` [PATCH net-next v3 4/5] selftests: net: test IPV6_FL_F_REFLECT Marcelo Mendes Spessoto Junior
2026-08-07 22:09 ` [PATCH net-next v3 5/5] selftests: net: adopt harness for flow label mgr Marcelo Mendes Spessoto Junior

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=20260807220942.421382-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