]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
selftests/bpf: test_tunnel: Move ip6geneve tunnel test to test_progs
authorBastien Curutchet (eBPF Foundation) <bastien.curutchet@bootlin.com>
Mon, 3 Mar 2025 08:22:56 +0000 (09:22 +0100)
committerAlexei Starovoitov <ast@kernel.org>
Sat, 15 Mar 2025 18:48:27 +0000 (11:48 -0700)
ip6geneve tunnels are tested in the test_tunnel.sh but not in the
test_progs framework.

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

Signed-off-by: Bastien Curutchet (eBPF Foundation) <bastien.curutchet@bootlin.com>
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
Acked-by: Stanislav Fomichev <sdf@fomichev.me>
Link: https://patch.msgid.link/20250303-tunnels-v2-8-8329f38f0678@bootlin.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
tools/testing/selftests/bpf/prog_tests/test_tunnel.c
tools/testing/selftests/bpf/test_tunnel.sh

index 2210a1d768362634b5baa729121c460f99244756..b5d48d4fd423a4eb1dc541e2c242943a5f3110aa 100644 (file)
 #define GENEVE_TUNL_DEV0 "geneve00"
 #define GENEVE_TUNL_DEV1 "geneve11"
 
+#define IP6GENEVE_TUNL_DEV0 "ip6geneve00"
+#define IP6GENEVE_TUNL_DEV1 "ip6geneve11"
+
 #define PING_ARGS "-i 0.01 -c 3 -w 10 -q"
 
 static int config_device(void)
@@ -462,6 +465,22 @@ fail:
        return -1;
 }
 
+static int add_ip6geneve_tunnel(const char *dev0, const char *dev1,
+                            const char *type, const char *opt)
+{
+       if (!type || !opt || !dev0 || !dev1)
+               return -1;
+
+       SYS(fail, "ip -n at_ns0 link add dev %s type %s id 22 %s remote %s",
+           dev0, type, opt, IP6_ADDR1_VETH1);
+
+       SYS(fail, "ip link add dev %s type %s %s external", dev1, type, opt);
+
+       return set_ipv6_addr(dev0, dev1);
+fail:
+       return -1;
+}
+
 static int test_ping(int family, const char *addr)
 {
        SYS(fail, "%s %s %s > /dev/null", ping_command(family), PING_ARGS, addr);
@@ -999,6 +1018,34 @@ done:
        delete_tunnel(GENEVE_TUNL_DEV0, GENEVE_TUNL_DEV1);
        test_tunnel_kern__destroy(skel);
 }
+
+static void test_ip6geneve_tunnel(void)
+{
+       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;
+
+       err = add_ip6geneve_tunnel(IP6GENEVE_TUNL_DEV0, IP6GENEVE_TUNL_DEV1,
+                                  "geneve", "");
+       if (!ASSERT_OK(err, "add tunnel"))
+               goto done;
+
+       set_fd = bpf_program__fd(skel->progs.ip6geneve_set_tunnel);
+       get_fd = bpf_program__fd(skel->progs.ip6geneve_get_tunnel);
+       if (generic_attach(IP6GENEVE_TUNL_DEV1, get_fd, set_fd))
+               goto done;
+
+       ping_dev0();
+       ping_dev1();
+done:
+       delete_tunnel(IP6GENEVE_TUNL_DEV0, IP6GENEVE_TUNL_DEV1);
+       test_tunnel_kern__destroy(skel);
+}
+
 #define RUN_TEST(name, ...)                                            \
        ({                                                              \
                if (test__start_subtest(#name)) {                       \
@@ -1027,6 +1074,7 @@ static void *test_tunnel_run_tests(void *arg)
        RUN_TEST(ip6erspan_tunnel, V1);
        RUN_TEST(ip6erspan_tunnel, V2);
        RUN_TEST(geneve_tunnel);
+       RUN_TEST(ip6geneve_tunnel);
 
        return NULL;
 }
index 7f2b1c846a72f07f578afbc9b4bb9882cabc838b..f46628f70399e2a049859709e9db9e8419e74770 100755 (executable)
@@ -64,26 +64,6 @@ config_device()
        ip addr add dev veth1 172.16.1.200/24
 }
 
-add_ip6geneve_tunnel()
-{
-       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
-       ip netns exec at_ns0 \
-               ip link add dev $DEV_NS type $TYPE id 22 \
-               remote ::22     # geneve has no local option
-       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_ipip_tunnel()
 {
        # at_ns0 namespace
@@ -121,30 +101,6 @@ add_ip6tnl_tunnel()
        ip link set dev $DEV up
 }
 
-test_ip6geneve()
-{
-       TYPE=geneve
-       DEV_NS=ip6geneve00
-       DEV=ip6geneve11
-       ret=0
-
-       check $TYPE
-       config_device
-       add_ip6geneve_tunnel
-       attach_bpf $DEV ip6geneve_set_tunnel ip6geneve_get_tunnel
-       ping $PING_ARG 10.1.1.100
-       check_err $?
-       ip netns exec at_ns0 ping $PING_ARG 10.1.1.200
-       check_err $?
-       cleanup
-
-       if [ $ret -ne 0 ]; then
-                echo -e ${RED}"FAIL: ip6$TYPE"${NC}
-                return 1
-        fi
-        echo -e ${GREEN}"PASS: ip6$TYPE"${NC}
-}
-
 test_ipip()
 {
        TYPE=ipip
@@ -247,7 +203,6 @@ cleanup()
        ip link del ipip11 2> /dev/null
        ip link del ipip6tnl11 2> /dev/null
        ip link del ip6ip6tnl11 2> /dev/null
-       ip link del ip6geneve11 2> /dev/null
 }
 
 cleanup_exit()
@@ -283,10 +238,6 @@ bpf_tunnel_test()
 {
        local errors=0
 
-       echo "Testing IP6GENEVE tunnel..."
-       test_ip6geneve
-       errors=$(( $errors + $? ))
-
        echo "Testing IPIP tunnel..."
        test_ipip
        errors=$(( $errors + $? ))