mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-08-29 17:30:01 -04:00
selftests: net: create own netns in ipv6_flowlabel_mgr
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> Link: https://patch.msgid.link/20260807220942.421382-4-marcelomspessoto@gmail.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
committed by
Jakub Kicinski
parent
39dd045c15
commit
03df0d155b
@@ -8,7 +8,7 @@
|
||||
set -e
|
||||
|
||||
echo "TEST management"
|
||||
./in_netns.sh ./ipv6_flowlabel_mgr
|
||||
./ipv6_flowlabel_mgr
|
||||
|
||||
echo "TEST datapath"
|
||||
./in_netns.sh \
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user