Skip to content

Commit 8d86094

Browse files
bastien-curutchetMartin KaFai Lau
authored andcommitted
selftests/bpf: test_tunnel: Move ip6geneve tunnel test to test_progs
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) <[email protected]> Signed-off-by: Martin KaFai Lau <[email protected]> Acked-by: Stanislav Fomichev <[email protected]> Link: https://patch.msgid.link/[email protected]
1 parent d89542d commit 8d86094

File tree

2 files changed

+48
-49
lines changed

2 files changed

+48
-49
lines changed

tools/testing/selftests/bpf/prog_tests/test_tunnel.c

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@
115115
#define GENEVE_TUNL_DEV0 "geneve00"
116116
#define GENEVE_TUNL_DEV1 "geneve11"
117117

118+
#define IP6GENEVE_TUNL_DEV0 "ip6geneve00"
119+
#define IP6GENEVE_TUNL_DEV1 "ip6geneve11"
120+
118121
#define PING_ARGS "-i 0.01 -c 3 -w 10 -q"
119122

120123
static int config_device(void)
@@ -462,6 +465,22 @@ static int add_geneve_tunnel(const char *dev0, const char *dev1,
462465
return -1;
463466
}
464467

468+
static int add_ip6geneve_tunnel(const char *dev0, const char *dev1,
469+
const char *type, const char *opt)
470+
{
471+
if (!type || !opt || !dev0 || !dev1)
472+
return -1;
473+
474+
SYS(fail, "ip -n at_ns0 link add dev %s type %s id 22 %s remote %s",
475+
dev0, type, opt, IP6_ADDR1_VETH1);
476+
477+
SYS(fail, "ip link add dev %s type %s %s external", dev1, type, opt);
478+
479+
return set_ipv6_addr(dev0, dev1);
480+
fail:
481+
return -1;
482+
}
483+
465484
static int test_ping(int family, const char *addr)
466485
{
467486
SYS(fail, "%s %s %s > /dev/null", ping_command(family), PING_ARGS, addr);
@@ -999,6 +1018,34 @@ static void test_geneve_tunnel(void)
9991018
delete_tunnel(GENEVE_TUNL_DEV0, GENEVE_TUNL_DEV1);
10001019
test_tunnel_kern__destroy(skel);
10011020
}
1021+
1022+
static void test_ip6geneve_tunnel(void)
1023+
{
1024+
struct test_tunnel_kern *skel;
1025+
int set_fd, get_fd;
1026+
int err;
1027+
1028+
skel = test_tunnel_kern__open_and_load();
1029+
if (!ASSERT_OK_PTR(skel, "test_tunnel_kern__open_and_load"))
1030+
return;
1031+
1032+
err = add_ip6geneve_tunnel(IP6GENEVE_TUNL_DEV0, IP6GENEVE_TUNL_DEV1,
1033+
"geneve", "");
1034+
if (!ASSERT_OK(err, "add tunnel"))
1035+
goto done;
1036+
1037+
set_fd = bpf_program__fd(skel->progs.ip6geneve_set_tunnel);
1038+
get_fd = bpf_program__fd(skel->progs.ip6geneve_get_tunnel);
1039+
if (generic_attach(IP6GENEVE_TUNL_DEV1, get_fd, set_fd))
1040+
goto done;
1041+
1042+
ping_dev0();
1043+
ping_dev1();
1044+
done:
1045+
delete_tunnel(IP6GENEVE_TUNL_DEV0, IP6GENEVE_TUNL_DEV1);
1046+
test_tunnel_kern__destroy(skel);
1047+
}
1048+
10021049
#define RUN_TEST(name, ...) \
10031050
({ \
10041051
if (test__start_subtest(#name)) { \
@@ -1027,6 +1074,7 @@ static void *test_tunnel_run_tests(void *arg)
10271074
RUN_TEST(ip6erspan_tunnel, V1);
10281075
RUN_TEST(ip6erspan_tunnel, V2);
10291076
RUN_TEST(geneve_tunnel);
1077+
RUN_TEST(ip6geneve_tunnel);
10301078

10311079
return NULL;
10321080
}

tools/testing/selftests/bpf/test_tunnel.sh

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -64,26 +64,6 @@ config_device()
6464
ip addr add dev veth1 172.16.1.200/24
6565
}
6666

67-
add_ip6geneve_tunnel()
68-
{
69-
ip netns exec at_ns0 ip addr add ::11/96 dev veth0
70-
ip netns exec at_ns0 ip link set dev veth0 up
71-
ip addr add dev veth1 ::22/96
72-
ip link set dev veth1 up
73-
74-
# at_ns0 namespace
75-
ip netns exec at_ns0 \
76-
ip link add dev $DEV_NS type $TYPE id 22 \
77-
remote ::22 # geneve has no local option
78-
ip netns exec at_ns0 ip addr add dev $DEV_NS 10.1.1.100/24
79-
ip netns exec at_ns0 ip link set dev $DEV_NS up
80-
81-
# root namespace
82-
ip link add dev $DEV type $TYPE external
83-
ip addr add dev $DEV 10.1.1.200/24
84-
ip link set dev $DEV up
85-
}
86-
8767
add_ipip_tunnel()
8868
{
8969
# at_ns0 namespace
@@ -121,30 +101,6 @@ add_ip6tnl_tunnel()
121101
ip link set dev $DEV up
122102
}
123103

124-
test_ip6geneve()
125-
{
126-
TYPE=geneve
127-
DEV_NS=ip6geneve00
128-
DEV=ip6geneve11
129-
ret=0
130-
131-
check $TYPE
132-
config_device
133-
add_ip6geneve_tunnel
134-
attach_bpf $DEV ip6geneve_set_tunnel ip6geneve_get_tunnel
135-
ping $PING_ARG 10.1.1.100
136-
check_err $?
137-
ip netns exec at_ns0 ping $PING_ARG 10.1.1.200
138-
check_err $?
139-
cleanup
140-
141-
if [ $ret -ne 0 ]; then
142-
echo -e ${RED}"FAIL: ip6$TYPE"${NC}
143-
return 1
144-
fi
145-
echo -e ${GREEN}"PASS: ip6$TYPE"${NC}
146-
}
147-
148104
test_ipip()
149105
{
150106
TYPE=ipip
@@ -247,7 +203,6 @@ cleanup()
247203
ip link del ipip11 2> /dev/null
248204
ip link del ipip6tnl11 2> /dev/null
249205
ip link del ip6ip6tnl11 2> /dev/null
250-
ip link del ip6geneve11 2> /dev/null
251206
}
252207

253208
cleanup_exit()
@@ -283,10 +238,6 @@ bpf_tunnel_test()
283238
{
284239
local errors=0
285240

286-
echo "Testing IP6GENEVE tunnel..."
287-
test_ip6geneve
288-
errors=$(( $errors + $? ))
289-
290241
echo "Testing IPIP tunnel..."
291242
test_ipip
292243
errors=$(( $errors + $? ))

0 commit comments

Comments
 (0)