Skip to content

Commit 1ea01a8

Browse files
bastien-curutchetMartin KaFai Lau
authored andcommitted
selftests/bpf: test_tunnel: Move ip6gre tunnel test to test_progs
ip6gre tunnels are tested in the test_tunnel.sh but not in the test_progs framework. Add a new test in test_progs to test ip6gre tunnels. It uses the same network topology and the same BPF programs than the script. Disable the IPv6 DAD feature because it can take lot of time and cause some tests to fail depending on the environment they're run on. Remove test_ip6gre() and test_ip6gretap() 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 08d20ea commit 1ea01a8

File tree

2 files changed

+104
-95
lines changed

2 files changed

+104
-95
lines changed

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

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@
7171
#define IP4_ADDR2_VETH1 "172.16.1.20"
7272
#define IP4_ADDR_TUNL_DEV0 "10.1.1.100"
7373
#define IP4_ADDR_TUNL_DEV1 "10.1.1.200"
74+
#define IP6_ADDR_TUNL_DEV0 "fc80::100"
75+
#define IP6_ADDR_TUNL_DEV1 "fc80::200"
7476

7577
#define IP6_ADDR_VETH0 "::11"
7678
#define IP6_ADDR1_VETH1 "::22"
@@ -101,6 +103,9 @@
101103
#define GRE_TUNL_DEV0 "gre00"
102104
#define GRE_TUNL_DEV1 "gre11"
103105

106+
#define IP6GRE_TUNL_DEV0 "ip6gre00"
107+
#define IP6GRE_TUNL_DEV1 "ip6gre11"
108+
104109
#define PING_ARGS "-i 0.01 -c 3 -w 10 -q"
105110

106111
static int config_device(void)
@@ -396,6 +401,43 @@ static void delete_tunnel(const char *dev0, const char *dev1)
396401
SYS_NOFAIL("ip link delete dev %s", dev1);
397402
}
398403

404+
static int set_ipv6_addr(const char *dev0, const char *dev1)
405+
{
406+
/* disable IPv6 DAD because it might take too long and fail tests */
407+
SYS(fail, "ip -n at_ns0 addr add %s/96 dev veth0 nodad", IP6_ADDR_VETH0);
408+
SYS(fail, "ip -n at_ns0 link set dev veth0 up");
409+
SYS(fail, "ip addr add %s/96 dev veth1 nodad", IP6_ADDR1_VETH1);
410+
SYS(fail, "ip link set dev veth1 up");
411+
412+
SYS(fail, "ip -n at_ns0 addr add dev %s %s/24", dev0, IP4_ADDR_TUNL_DEV0);
413+
SYS(fail, "ip -n at_ns0 addr add dev %s %s/96 nodad", dev0, IP6_ADDR_TUNL_DEV0);
414+
SYS(fail, "ip -n at_ns0 link set dev %s up", dev0);
415+
416+
SYS(fail, "ip addr add dev %s %s/24", dev1, IP4_ADDR_TUNL_DEV1);
417+
SYS(fail, "ip addr add dev %s %s/96 nodad", dev1, IP6_ADDR_TUNL_DEV1);
418+
SYS(fail, "ip link set dev %s up", dev1);
419+
return 0;
420+
fail:
421+
return 1;
422+
}
423+
424+
static int add_ipv6_tunnel(const char *dev0, const char *dev1,
425+
const char *type, const char *opt)
426+
{
427+
if (!type || !opt || !dev0 || !dev1)
428+
return -1;
429+
430+
SYS(fail, "ip -n at_ns0 link add dev %s type %s %s local %s remote %s",
431+
dev0, type, opt, IP6_ADDR_VETH0, IP6_ADDR1_VETH1);
432+
433+
SYS(fail, "ip link add dev %s type %s external", dev1, type);
434+
435+
return set_ipv6_addr(dev0, dev1);
436+
fail:
437+
return -1;
438+
}
439+
440+
399441
static int test_ping(int family, const char *addr)
400442
{
401443
SYS(fail, "%s %s %s > /dev/null", ping_command(family), PING_ARGS, addr);
@@ -423,6 +465,24 @@ static void ping_dev1(void)
423465
close_netns(nstoken);
424466
}
425467

468+
static void ping6_veth0(void)
469+
{
470+
test_ping(AF_INET6, IP6_ADDR_VETH0);
471+
}
472+
473+
static void ping6_dev1(void)
474+
{
475+
struct nstoken *nstoken;
476+
477+
/* ping from at_ns0 namespace test */
478+
nstoken = open_netns("at_ns0");
479+
if (!ASSERT_OK_PTR(nstoken, "setns"))
480+
return;
481+
482+
test_ping(AF_INET, IP6_ADDR_TUNL_DEV1);
483+
close_netns(nstoken);
484+
}
485+
426486
static int attach_tc_prog(int ifindex, int igr_fd, int egr_fd)
427487
{
428488
DECLARE_LIBBPF_OPTS(bpf_tc_hook, hook, .ifindex = ifindex,
@@ -770,6 +830,48 @@ static void test_gre_tunnel(enum gre_test test)
770830
test_tunnel_kern__destroy(skel);
771831
}
772832

833+
enum ip6gre_test {
834+
IP6GRE,
835+
IP6GRETAP
836+
};
837+
838+
static void test_ip6gre_tunnel(enum ip6gre_test test)
839+
{
840+
struct test_tunnel_kern *skel;
841+
int set_fd, get_fd;
842+
int err;
843+
844+
skel = test_tunnel_kern__open_and_load();
845+
if (!ASSERT_OK_PTR(skel, "test_tunnel_kern__open_and_load"))
846+
return;
847+
848+
switch (test) {
849+
case IP6GRE:
850+
err = add_ipv6_tunnel(IP6GRE_TUNL_DEV0, IP6GRE_TUNL_DEV1,
851+
"ip6gre", "flowlabel 0xbcdef key 2");
852+
break;
853+
case IP6GRETAP:
854+
err = add_ipv6_tunnel(IP6GRE_TUNL_DEV0, IP6GRE_TUNL_DEV1,
855+
"ip6gretap", "flowlabel 0xbcdef key 2");
856+
break;
857+
}
858+
if (!ASSERT_OK(err, "add tunnel"))
859+
goto done;
860+
861+
set_fd = bpf_program__fd(skel->progs.ip6gretap_set_tunnel);
862+
get_fd = bpf_program__fd(skel->progs.ip6gretap_get_tunnel);
863+
if (generic_attach(IP6GRE_TUNL_DEV1, get_fd, set_fd))
864+
goto done;
865+
866+
ping6_veth0();
867+
ping6_dev1();
868+
ping_dev0();
869+
ping_dev1();
870+
done:
871+
delete_tunnel(IP6GRE_TUNL_DEV0, IP6GRE_TUNL_DEV1);
872+
test_tunnel_kern__destroy(skel);
873+
}
874+
773875
#define RUN_TEST(name, ...) \
774876
({ \
775877
if (test__start_subtest(#name)) { \
@@ -791,6 +893,8 @@ static void *test_tunnel_run_tests(void *arg)
791893
RUN_TEST(gre_tunnel, GRE_NOKEY);
792894
RUN_TEST(gre_tunnel, GRETAP);
793895
RUN_TEST(gre_tunnel, GRETAP_NOKEY);
896+
RUN_TEST(ip6gre_tunnel, IP6GRE);
897+
RUN_TEST(ip6gre_tunnel, IP6GRETAP);
794898

795899
return NULL;
796900
}

tools/testing/selftests/bpf/test_tunnel.sh

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

67-
add_ip6gretap_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-
ip netns exec at_ns0 \
78-
ip link add dev $DEV_NS type $TYPE seq flowlabel 0xbcdef key 2 \
79-
local ::11 remote ::22
80-
81-
ip netns exec at_ns0 ip addr add dev $DEV_NS 10.1.1.100/24
82-
ip netns exec at_ns0 ip addr add dev $DEV_NS fc80::100/96
83-
ip netns exec at_ns0 ip link set dev $DEV_NS up
84-
85-
# root namespace
86-
ip link add dev $DEV type $TYPE external
87-
ip addr add dev $DEV 10.1.1.200/24
88-
ip addr add dev $DEV fc80::200/24
89-
ip link set dev $DEV up
90-
}
91-
9267
add_erspan_tunnel()
9368
{
9469
# at_ns0 namespace
@@ -214,65 +189,6 @@ add_ip6tnl_tunnel()
214189
ip link set dev $DEV up
215190
}
216191

217-
test_ip6gre()
218-
{
219-
TYPE=ip6gre
220-
DEV_NS=ip6gre00
221-
DEV=ip6gre11
222-
ret=0
223-
224-
check $TYPE
225-
config_device
226-
# reuse the ip6gretap function
227-
add_ip6gretap_tunnel
228-
attach_bpf $DEV ip6gretap_set_tunnel ip6gretap_get_tunnel
229-
# underlay
230-
ping6 $PING_ARG ::11
231-
# overlay: ipv4 over ipv6
232-
ip netns exec at_ns0 ping $PING_ARG 10.1.1.200
233-
ping $PING_ARG 10.1.1.100
234-
check_err $?
235-
# overlay: ipv6 over ipv6
236-
ip netns exec at_ns0 ping6 $PING_ARG fc80::200
237-
check_err $?
238-
cleanup
239-
240-
if [ $ret -ne 0 ]; then
241-
echo -e ${RED}"FAIL: $TYPE"${NC}
242-
return 1
243-
fi
244-
echo -e ${GREEN}"PASS: $TYPE"${NC}
245-
}
246-
247-
test_ip6gretap()
248-
{
249-
TYPE=ip6gretap
250-
DEV_NS=ip6gretap00
251-
DEV=ip6gretap11
252-
ret=0
253-
254-
check $TYPE
255-
config_device
256-
add_ip6gretap_tunnel
257-
attach_bpf $DEV ip6gretap_set_tunnel ip6gretap_get_tunnel
258-
# underlay
259-
ping6 $PING_ARG ::11
260-
# overlay: ipv4 over ipv6
261-
ip netns exec at_ns0 ping $PING_ARG 10.1.1.200
262-
ping $PING_ARG 10.1.1.100
263-
check_err $?
264-
# overlay: ipv6 over ipv6
265-
ip netns exec at_ns0 ping6 $PING_ARG fc80::200
266-
check_err $?
267-
cleanup
268-
269-
if [ $ret -ne 0 ]; then
270-
echo -e ${RED}"FAIL: $TYPE"${NC}
271-
return 1
272-
fi
273-
echo -e ${GREEN}"PASS: $TYPE"${NC}
274-
}
275-
276192
test_erspan()
277193
{
278194
TYPE=erspan
@@ -470,8 +386,6 @@ cleanup()
470386
ip link del ipip11 2> /dev/null
471387
ip link del ipip6tnl11 2> /dev/null
472388
ip link del ip6ip6tnl11 2> /dev/null
473-
ip link del ip6gre11 2> /dev/null
474-
ip link del ip6gretap11 2> /dev/null
475389
ip link del geneve11 2> /dev/null
476390
ip link del ip6geneve11 2> /dev/null
477391
ip link del erspan11 2> /dev/null
@@ -497,7 +411,6 @@ check()
497411

498412
enable_debug()
499413
{
500-
echo 'file ip6_gre.c +p' > /sys/kernel/debug/dynamic_debug/control
501414
echo 'file geneve.c +p' > /sys/kernel/debug/dynamic_debug/control
502415
echo 'file ipip.c +p' > /sys/kernel/debug/dynamic_debug/control
503416
}
@@ -513,14 +426,6 @@ bpf_tunnel_test()
513426
{
514427
local errors=0
515428

516-
echo "Testing IP6GRE tunnel..."
517-
test_ip6gre
518-
errors=$(( $errors + $? ))
519-
520-
echo "Testing IP6GRETAP tunnel..."
521-
test_ip6gretap
522-
errors=$(( $errors + $? ))
523-
524429
echo "Testing ERSPAN tunnel..."
525430
test_erspan v2
526431
errors=$(( $errors + $? ))

0 commit comments

Comments
 (0)