Skip to content

Commit d89542d

Browse files
bastien-curutchetMartin KaFai Lau
authored andcommitted
selftests/bpf: test_tunnel: Move geneve tunnel test to test_progs
geneve tunnels are tested in the test_tunnel.sh but not in the test_progs framework. Add a new test in test_progs to test geneve tunnels. It uses the same network topology and the same BPF programs than the script. Remove test_geneve() 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 cae41f7 commit d89542d

File tree

2 files changed

+45
-45
lines changed

2 files changed

+45
-45
lines changed

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

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@
112112
#define IP6ERSPAN_TUNL_DEV0 "ip6erspan00"
113113
#define IP6ERSPAN_TUNL_DEV1 "ip6erspan11"
114114

115+
#define GENEVE_TUNL_DEV0 "geneve00"
116+
#define GENEVE_TUNL_DEV1 "geneve11"
117+
115118
#define PING_ARGS "-i 0.01 -c 3 -w 10 -q"
116119

117120
static int config_device(void)
@@ -443,6 +446,21 @@ static int add_ipv6_tunnel(const char *dev0, const char *dev1,
443446
return -1;
444447
}
445448

449+
static int add_geneve_tunnel(const char *dev0, const char *dev1,
450+
const char *type, const char *opt)
451+
{
452+
if (!type || !opt || !dev0 || !dev1)
453+
return -1;
454+
455+
SYS(fail, "ip -n at_ns0 link add dev %s type %s id 2 %s remote %s",
456+
dev0, type, opt, IP4_ADDR1_VETH1);
457+
458+
SYS(fail, "ip link add dev %s type %s %s external", dev1, type, opt);
459+
460+
return set_ipv4_addr(dev0, dev1);
461+
fail:
462+
return -1;
463+
}
446464

447465
static int test_ping(int family, const char *addr)
448466
{
@@ -955,6 +973,32 @@ static void test_ip6erspan_tunnel(enum erspan_test test)
955973
test_tunnel_kern__destroy(skel);
956974
}
957975

976+
static void test_geneve_tunnel(void)
977+
{
978+
struct test_tunnel_kern *skel;
979+
int set_fd, get_fd;
980+
int err;
981+
982+
skel = test_tunnel_kern__open_and_load();
983+
if (!ASSERT_OK_PTR(skel, "test_tunnel_kern__open_and_load"))
984+
return;
985+
986+
err = add_geneve_tunnel(GENEVE_TUNL_DEV0, GENEVE_TUNL_DEV1,
987+
"geneve", "dstport 6081");
988+
if (!ASSERT_OK(err, "add tunnel"))
989+
goto done;
990+
991+
set_fd = bpf_program__fd(skel->progs.geneve_set_tunnel);
992+
get_fd = bpf_program__fd(skel->progs.geneve_get_tunnel);
993+
if (generic_attach(GENEVE_TUNL_DEV1, get_fd, set_fd))
994+
goto done;
995+
996+
ping_dev0();
997+
ping_dev1();
998+
done:
999+
delete_tunnel(GENEVE_TUNL_DEV0, GENEVE_TUNL_DEV1);
1000+
test_tunnel_kern__destroy(skel);
1001+
}
9581002
#define RUN_TEST(name, ...) \
9591003
({ \
9601004
if (test__start_subtest(#name)) { \
@@ -982,6 +1026,7 @@ static void *test_tunnel_run_tests(void *arg)
9821026
RUN_TEST(erspan_tunnel, V2);
9831027
RUN_TEST(ip6erspan_tunnel, V1);
9841028
RUN_TEST(ip6erspan_tunnel, V2);
1029+
RUN_TEST(geneve_tunnel);
9851030

9861031
return NULL;
9871032
}

tools/testing/selftests/bpf/test_tunnel.sh

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

67-
add_geneve_tunnel()
68-
{
69-
# at_ns0 namespace
70-
ip netns exec at_ns0 \
71-
ip link add dev $DEV_NS type $TYPE \
72-
id 2 dstport 6081 remote 172.16.1.200
73-
ip netns exec at_ns0 ip link set dev $DEV_NS up
74-
ip netns exec at_ns0 ip addr add dev $DEV_NS 10.1.1.100/24
75-
76-
# root namespace
77-
ip link add dev $DEV type $TYPE dstport 6081 external
78-
ip link set dev $DEV up
79-
ip addr add dev $DEV 10.1.1.200/24
80-
}
81-
8267
add_ip6geneve_tunnel()
8368
{
8469
ip netns exec at_ns0 ip addr add ::11/96 dev veth0
@@ -136,30 +121,6 @@ add_ip6tnl_tunnel()
136121
ip link set dev $DEV up
137122
}
138123

139-
test_geneve()
140-
{
141-
TYPE=geneve
142-
DEV_NS=geneve00
143-
DEV=geneve11
144-
ret=0
145-
146-
check $TYPE
147-
config_device
148-
add_geneve_tunnel
149-
attach_bpf $DEV geneve_set_tunnel geneve_get_tunnel
150-
ping $PING_ARG 10.1.1.100
151-
check_err $?
152-
ip netns exec at_ns0 ping $PING_ARG 10.1.1.200
153-
check_err $?
154-
cleanup
155-
156-
if [ $ret -ne 0 ]; then
157-
echo -e ${RED}"FAIL: $TYPE"${NC}
158-
return 1
159-
fi
160-
echo -e ${GREEN}"PASS: $TYPE"${NC}
161-
}
162-
163124
test_ip6geneve()
164125
{
165126
TYPE=geneve
@@ -286,7 +247,6 @@ cleanup()
286247
ip link del ipip11 2> /dev/null
287248
ip link del ipip6tnl11 2> /dev/null
288249
ip link del ip6ip6tnl11 2> /dev/null
289-
ip link del geneve11 2> /dev/null
290250
ip link del ip6geneve11 2> /dev/null
291251
}
292252

@@ -309,7 +269,6 @@ check()
309269

310270
enable_debug()
311271
{
312-
echo 'file geneve.c +p' > /sys/kernel/debug/dynamic_debug/control
313272
echo 'file ipip.c +p' > /sys/kernel/debug/dynamic_debug/control
314273
}
315274

@@ -324,10 +283,6 @@ bpf_tunnel_test()
324283
{
325284
local errors=0
326285

327-
echo "Testing GENEVE tunnel..."
328-
test_geneve
329-
errors=$(( $errors + $? ))
330-
331286
echo "Testing IP6GENEVE tunnel..."
332287
test_ip6geneve
333288
errors=$(( $errors + $? ))

0 commit comments

Comments
 (0)