Commit ea60b6a5 authored by Bastien Curutchet (eBPF Foundation)'s avatar Bastien Curutchet (eBPF Foundation) Committed by Alexei Starovoitov
Browse files

selftests/bpf: test_tunnel: Move ip6erspan tunnel test to test_progs



ip6erspan tunnels are tested in the test_tunnel.sh but not in the
test_progs framework.

Add a new test in test_progs to test ip6erspan tunnels. It uses the same
network topology and the same BPF programs than the script.
Remove test_ip6erspan() from the script.

Signed-off-by: default avatarBastien Curutchet (eBPF Foundation) <bastien.curutchet@bootlin.com>
Signed-off-by: default avatarMartin KaFai Lau <martin.lau@kernel.org>
Acked-by: default avatarStanislav Fomichev <sdf@fomichev.me>
Link: https://patch.msgid.link/20250303-tunnels-v2-6-8329f38f0678@bootlin.com


Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
parent cadb08a4
Loading
Loading
Loading
Loading
+41 −0
Original line number Diff line number Diff line
@@ -109,6 +109,9 @@
#define ERSPAN_TUNL_DEV0 "erspan00"
#define ERSPAN_TUNL_DEV1 "erspan11"

#define IP6ERSPAN_TUNL_DEV0 "ip6erspan00"
#define IP6ERSPAN_TUNL_DEV1 "ip6erspan11"

#define PING_ARGS "-i 0.01 -c 3 -w 10 -q"

static int config_device(void)
@@ -916,6 +919,42 @@ static void test_erspan_tunnel(enum erspan_test test)
	test_tunnel_kern__destroy(skel);
}

static void test_ip6erspan_tunnel(enum erspan_test test)
{
	struct test_tunnel_kern *skel;
	int set_fd, get_fd;
	int err;

	skel = test_tunnel_kern__open_and_load();
	if (!ASSERT_OK_PTR(skel, "test_tunnel_kern__open_and_load"))
		return;

	switch (test) {
	case V1:
		err = add_ipv6_tunnel(IP6ERSPAN_TUNL_DEV0, IP6ERSPAN_TUNL_DEV1,
				      "ip6erspan", "seq key 2 erspan_ver 1 erspan 123");
		break;
	case V2:
		err = add_ipv6_tunnel(IP6ERSPAN_TUNL_DEV0, IP6ERSPAN_TUNL_DEV1,
				      "ip6erspan",
				      "seq key 2 erspan_ver 2 erspan_dir egress erspan_hwid 7");
		break;
	}
	if (!ASSERT_OK(err, "add tunnel"))
		goto done;

	set_fd = bpf_program__fd(skel->progs.ip4ip6erspan_set_tunnel);
	get_fd = bpf_program__fd(skel->progs.ip4ip6erspan_get_tunnel);
	if (generic_attach(IP6ERSPAN_TUNL_DEV1, get_fd, set_fd))
		goto done;

	ping6_veth0();
	ping_dev1();
done:
	delete_tunnel(IP6ERSPAN_TUNL_DEV0, IP6ERSPAN_TUNL_DEV1);
	test_tunnel_kern__destroy(skel);
}

#define RUN_TEST(name, ...)						\
	({								\
		if (test__start_subtest(#name)) {			\
@@ -941,6 +980,8 @@ static void *test_tunnel_run_tests(void *arg)
	RUN_TEST(ip6gre_tunnel, IP6GRETAP);
	RUN_TEST(erspan_tunnel, V1);
	RUN_TEST(erspan_tunnel, V2);
	RUN_TEST(ip6erspan_tunnel, V1);
	RUN_TEST(ip6erspan_tunnel, V2);

	return NULL;
}
+0 −58
Original line number Diff line number Diff line
@@ -64,36 +64,6 @@ config_device()
	ip addr add dev veth1 172.16.1.200/24
}

add_ip6erspan_tunnel()
{

	# assign ipv6 address
	ip netns exec at_ns0 ip addr add ::11/96 dev veth0
	ip netns exec at_ns0 ip link set dev veth0 up
	ip addr add dev veth1 ::22/96
	ip link set dev veth1 up

	# at_ns0 namespace
	if [ "$1" == "v1" ]; then
		ip netns exec at_ns0 \
		ip link add dev $DEV_NS type $TYPE seq key 2 \
		local ::11 remote ::22 \
		erspan_ver 1 erspan 123
	else
		ip netns exec at_ns0 \
		ip link add dev $DEV_NS type $TYPE seq key 2 \
		local ::11 remote ::22 \
		erspan_ver 2 erspan_dir egress erspan_hwid 7
	fi
	ip netns exec at_ns0 ip addr add dev $DEV_NS 10.1.1.100/24
	ip netns exec at_ns0 ip link set dev $DEV_NS up

	# root namespace
	ip link add dev $DEV type $TYPE external
	ip addr add dev $DEV 10.1.1.200/24
	ip link set dev $DEV up
}

add_geneve_tunnel()
{
	# at_ns0 namespace
@@ -166,29 +136,6 @@ add_ip6tnl_tunnel()
	ip link set dev $DEV up
}

test_ip6erspan()
{
	TYPE=ip6erspan
	DEV_NS=ip6erspan00
	DEV=ip6erspan11
	ret=0

	check $TYPE
	config_device
	add_ip6erspan_tunnel $1
	attach_bpf $DEV ip4ip6erspan_set_tunnel ip4ip6erspan_get_tunnel
	ping6 $PING_ARG ::11
	ip netns exec at_ns0 ping $PING_ARG 10.1.1.200
	check_err $?
	cleanup

	if [ $ret -ne 0 ]; then
                echo -e ${RED}"FAIL: $TYPE"${NC}
                return 1
        fi
        echo -e ${GREEN}"PASS: $TYPE"${NC}
}

test_geneve()
{
	TYPE=geneve
@@ -341,7 +288,6 @@ cleanup()
	ip link del ip6ip6tnl11 2> /dev/null
	ip link del geneve11 2> /dev/null
	ip link del ip6geneve11 2> /dev/null
	ip link del ip6erspan11 2> /dev/null
}

cleanup_exit()
@@ -378,10 +324,6 @@ bpf_tunnel_test()
{
	local errors=0

	echo "Testing IP6ERSPAN tunnel..."
	test_ip6erspan v2
	errors=$(( $errors + $? ))

	echo "Testing GENEVE tunnel..."
	test_geneve
	errors=$(( $errors + $? ))