Skip to content

Commit cae41f7

Browse files
bastien-curutchetMartin KaFai Lau
authored andcommitted
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: 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 0ecd1e9 commit cae41f7

File tree

2 files changed

+41
-58
lines changed

2 files changed

+41
-58
lines changed

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

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@
109109
#define ERSPAN_TUNL_DEV0 "erspan00"
110110
#define ERSPAN_TUNL_DEV1 "erspan11"
111111

112+
#define IP6ERSPAN_TUNL_DEV0 "ip6erspan00"
113+
#define IP6ERSPAN_TUNL_DEV1 "ip6erspan11"
114+
112115
#define PING_ARGS "-i 0.01 -c 3 -w 10 -q"
113116

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

922+
static void test_ip6erspan_tunnel(enum erspan_test test)
923+
{
924+
struct test_tunnel_kern *skel;
925+
int set_fd, get_fd;
926+
int err;
927+
928+
skel = test_tunnel_kern__open_and_load();
929+
if (!ASSERT_OK_PTR(skel, "test_tunnel_kern__open_and_load"))
930+
return;
931+
932+
switch (test) {
933+
case V1:
934+
err = add_ipv6_tunnel(IP6ERSPAN_TUNL_DEV0, IP6ERSPAN_TUNL_DEV1,
935+
"ip6erspan", "seq key 2 erspan_ver 1 erspan 123");
936+
break;
937+
case V2:
938+
err = add_ipv6_tunnel(IP6ERSPAN_TUNL_DEV0, IP6ERSPAN_TUNL_DEV1,
939+
"ip6erspan",
940+
"seq key 2 erspan_ver 2 erspan_dir egress erspan_hwid 7");
941+
break;
942+
}
943+
if (!ASSERT_OK(err, "add tunnel"))
944+
goto done;
945+
946+
set_fd = bpf_program__fd(skel->progs.ip4ip6erspan_set_tunnel);
947+
get_fd = bpf_program__fd(skel->progs.ip4ip6erspan_get_tunnel);
948+
if (generic_attach(IP6ERSPAN_TUNL_DEV1, get_fd, set_fd))
949+
goto done;
950+
951+
ping6_veth0();
952+
ping_dev1();
953+
done:
954+
delete_tunnel(IP6ERSPAN_TUNL_DEV0, IP6ERSPAN_TUNL_DEV1);
955+
test_tunnel_kern__destroy(skel);
956+
}
957+
919958
#define RUN_TEST(name, ...) \
920959
({ \
921960
if (test__start_subtest(#name)) { \
@@ -941,6 +980,8 @@ static void *test_tunnel_run_tests(void *arg)
941980
RUN_TEST(ip6gre_tunnel, IP6GRETAP);
942981
RUN_TEST(erspan_tunnel, V1);
943982
RUN_TEST(erspan_tunnel, V2);
983+
RUN_TEST(ip6erspan_tunnel, V1);
984+
RUN_TEST(ip6erspan_tunnel, V2);
944985

945986
return NULL;
946987
}

tools/testing/selftests/bpf/test_tunnel.sh

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

67-
add_ip6erspan_tunnel()
68-
{
69-
70-
# assign ipv6 address
71-
ip netns exec at_ns0 ip addr add ::11/96 dev veth0
72-
ip netns exec at_ns0 ip link set dev veth0 up
73-
ip addr add dev veth1 ::22/96
74-
ip link set dev veth1 up
75-
76-
# at_ns0 namespace
77-
if [ "$1" == "v1" ]; then
78-
ip netns exec at_ns0 \
79-
ip link add dev $DEV_NS type $TYPE seq key 2 \
80-
local ::11 remote ::22 \
81-
erspan_ver 1 erspan 123
82-
else
83-
ip netns exec at_ns0 \
84-
ip link add dev $DEV_NS type $TYPE seq key 2 \
85-
local ::11 remote ::22 \
86-
erspan_ver 2 erspan_dir egress erspan_hwid 7
87-
fi
88-
ip netns exec at_ns0 ip addr add dev $DEV_NS 10.1.1.100/24
89-
ip netns exec at_ns0 ip link set dev $DEV_NS up
90-
91-
# root namespace
92-
ip link add dev $DEV type $TYPE external
93-
ip addr add dev $DEV 10.1.1.200/24
94-
ip link set dev $DEV up
95-
}
96-
9767
add_geneve_tunnel()
9868
{
9969
# at_ns0 namespace
@@ -166,29 +136,6 @@ add_ip6tnl_tunnel()
166136
ip link set dev $DEV up
167137
}
168138

169-
test_ip6erspan()
170-
{
171-
TYPE=ip6erspan
172-
DEV_NS=ip6erspan00
173-
DEV=ip6erspan11
174-
ret=0
175-
176-
check $TYPE
177-
config_device
178-
add_ip6erspan_tunnel $1
179-
attach_bpf $DEV ip4ip6erspan_set_tunnel ip4ip6erspan_get_tunnel
180-
ping6 $PING_ARG ::11
181-
ip netns exec at_ns0 ping $PING_ARG 10.1.1.200
182-
check_err $?
183-
cleanup
184-
185-
if [ $ret -ne 0 ]; then
186-
echo -e ${RED}"FAIL: $TYPE"${NC}
187-
return 1
188-
fi
189-
echo -e ${GREEN}"PASS: $TYPE"${NC}
190-
}
191-
192139
test_geneve()
193140
{
194141
TYPE=geneve
@@ -341,7 +288,6 @@ cleanup()
341288
ip link del ip6ip6tnl11 2> /dev/null
342289
ip link del geneve11 2> /dev/null
343290
ip link del ip6geneve11 2> /dev/null
344-
ip link del ip6erspan11 2> /dev/null
345291
}
346292

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

381-
echo "Testing IP6ERSPAN tunnel..."
382-
test_ip6erspan v2
383-
errors=$(( $errors + $? ))
384-
385327
echo "Testing GENEVE tunnel..."
386328
test_geneve
387329
errors=$(( $errors + $? ))

0 commit comments

Comments
 (0)